**未完成**建立swapchain类,将VKDevice部分功能移到VKSwapchain类中
This commit is contained in:
@@ -6,19 +6,6 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/*
|
||||
* OpenGL Coordinate System Vulkan Coordinate System My Coordinate System
|
||||
*
|
||||
* /Z
|
||||
* Y| /Z / Z| /Y
|
||||
* | / / | /
|
||||
* | / *------------ | /
|
||||
* | / | X | /
|
||||
* |/ | |/
|
||||
* *------------ | *------------
|
||||
* X | Y X
|
||||
*/
|
||||
|
||||
/**
|
||||
* 摄像机类型
|
||||
*/
|
||||
|
27
inc/hgl/graph/Coordinate.h
Normal file
27
inc/hgl/graph/Coordinate.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef HGL_GRAPH_COORDINATE_INCLUDE
|
||||
#define HGL_GRAPH_COORDINATE_INCLUDE
|
||||
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/*
|
||||
* OpenGL Coordinate System Vulkan Coordinate System My Coordinate System
|
||||
*
|
||||
* /Z
|
||||
* Y| /Z / Z| /Y
|
||||
* | / / | /
|
||||
* | / *------------ | /
|
||||
* | / | X | /
|
||||
* |/ | |/
|
||||
* *------------ | *------------
|
||||
* X | Y X
|
||||
*/
|
||||
|
||||
extern Matrix4f MATRIX_FROM_OPENGL_COORDINATE; //OpenGL<47><4C><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD>ݵ<EFBFBD><DDB5>ҷ<EFBFBD><D2B7><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD>ݱ任<DDB1>þ<EFBFBD><C3BE><EFBFBD>
|
||||
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_COORDINATE_INCLUDE
|
@@ -31,9 +31,9 @@ public:
|
||||
|
||||
void SetRenderArea(const VkRect2D &ra){render_area=ra;}
|
||||
void SetViewport(const VkViewport &vp){viewport=vp;}
|
||||
void SetClearColor(int index,float r,float g,float b,float a=1.0f)
|
||||
void SetClearColor(uint32_t index,float r,float g,float b,float a=1.0f)
|
||||
{
|
||||
if(index<0||index>cv_count)return;
|
||||
if(index>=cv_count)return;
|
||||
|
||||
VkClearValue *cv=clear_values+index;
|
||||
|
||||
@@ -43,9 +43,9 @@ public:
|
||||
cv->color.float32[3]=a;
|
||||
}
|
||||
|
||||
void SetClearDepthStencil(int index,float d=1.0f,float s=0)
|
||||
void SetClearDepthStencil(uint32_t index,float d=1.0f,float s=0)
|
||||
{
|
||||
if(index<0||index>cv_count)return;
|
||||
if(index>=cv_count)return;
|
||||
|
||||
VkClearValue *cv=clear_values+index;
|
||||
|
||||
|
@@ -7,9 +7,7 @@
|
||||
#include<hgl/platform/Window.h>
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
#include<hgl/graph/vulkan/VKDeviceAttribute.h>
|
||||
#include<hgl/graph/vulkan/VKFramebuffer.h>
|
||||
#include<hgl/graph/vulkan/VKFence.h>
|
||||
#include<hgl/graph/vulkan/VKSemaphore.h>
|
||||
#include<hgl/graph/vulkan/VKSwapchain.h>
|
||||
#include<hgl/graph/VertexBufferCreater.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
@@ -17,32 +15,12 @@ class Device
|
||||
{
|
||||
DeviceAttribute *attr;
|
||||
|
||||
uint swap_chain_count;
|
||||
|
||||
Semaphore *present_complete_semaphore=nullptr,
|
||||
*render_complete_semaphore=nullptr;
|
||||
|
||||
VkPipelineStageFlags pipe_stage_flags;
|
||||
VkSubmitInfo submit_info;
|
||||
|
||||
Fence *texture_fence;
|
||||
|
||||
VkSubmitInfo texture_submit_info;
|
||||
CommandBuffer *texture_cmd_buf;
|
||||
|
||||
RenderPass *main_rp;
|
||||
|
||||
uint32_t current_frame;
|
||||
ObjectList<Framebuffer> render_frame;
|
||||
|
||||
uint32_t current_fence;
|
||||
ObjectList<Fence> fence_list;
|
||||
|
||||
VkPresentInfoKHR present_info;
|
||||
|
||||
private:
|
||||
|
||||
void RecreateDevice();
|
||||
Swapchain *swapchain;
|
||||
|
||||
private:
|
||||
|
||||
@@ -54,26 +32,23 @@ public:
|
||||
|
||||
virtual ~Device();
|
||||
|
||||
operator VkDevice () {return attr->device;}
|
||||
operator VkDevice () {return attr->device;}
|
||||
|
||||
VkSurfaceKHR GetSurface () {return attr->surface;}
|
||||
VkDevice GetDevice () {return attr->device;}
|
||||
const PhysicalDevice *GetPhysicalDevice ()const {return attr->physical_device;}
|
||||
const VkExtent2D & GetExtent ()const {return attr->swapchain_extent;}
|
||||
VkSurfaceKHR GetSurface () {return attr->surface;}
|
||||
VkDevice GetDevice () {return attr->device;}
|
||||
const PhysicalDevice * GetPhysicalDevice ()const {return attr->physical_device;}
|
||||
|
||||
VkDescriptorPool GetDescriptorPool () {return attr->desc_pool;}
|
||||
VkPipelineCache GetPipelineCache () {return attr->pipeline_cache;}
|
||||
VkDescriptorPool GetDescriptorPool () {return attr->desc_pool;}
|
||||
VkPipelineCache GetPipelineCache () {return attr->pipeline_cache;}
|
||||
|
||||
const VkFormat GetSurfaceFormat ()const {return attr->format;}
|
||||
VkQueue GetGraphicsQueue () {return attr->graphics_queue;}
|
||||
|
||||
Swapchain * GetSwapchain () {return swapchain;}
|
||||
|
||||
public:
|
||||
|
||||
const uint32_t GetSwapChainImageCount ()const {return attr->sc_texture.GetCount();}
|
||||
|
||||
RenderPass * GetMainRenderPass () {return main_rp;}
|
||||
Framebuffer * GetFramebuffer (int index) {return render_frame[index];}
|
||||
const uint32_t GetCurrentFrameIndices () {return current_frame;}
|
||||
Framebuffer * GetCurrentFramebuffer () {return render_frame[current_frame];}
|
||||
|
||||
bool Resize (uint,uint);
|
||||
bool Resize (const VkExtent2D &);
|
||||
|
||||
public: //内存相关
|
||||
|
||||
@@ -164,7 +139,7 @@ public: //material相关
|
||||
|
||||
public: //Command Buffer 相关
|
||||
|
||||
CommandBuffer * CreateCommandBuffer(const VkExtent2D *extent,const uint32_t atta_count);
|
||||
CommandBuffer * CreateCommandBuffer(const VkExtent2D &extent,const uint32_t atta_count);
|
||||
|
||||
bool CreateAttachment( List<VkAttachmentReference> &ref_list,
|
||||
List<VkAttachmentDescription> &desc_list,
|
||||
@@ -194,27 +169,6 @@ public: //Command Buffer 相关
|
||||
|
||||
Fence * CreateFence(bool);
|
||||
Semaphore * CreateSem();
|
||||
|
||||
public: //提交相关
|
||||
|
||||
bool Wait (bool wait_all=VK_TRUE,uint64_t time_out=HGL_NANO_SEC_PER_SEC*0.1); ///<等待队列完成
|
||||
|
||||
/**
|
||||
* 请求获得下一帧的索引,并将确认信息发送到指定信号
|
||||
*/
|
||||
bool AcquireNextImage (VkSemaphore); ///<请求获得下一帧的索引
|
||||
|
||||
/**
|
||||
* 提交一批绘制指令
|
||||
* @param cmd_list 绘制指令
|
||||
* @param wait_sems 指令开始前要等待的确认的信号
|
||||
* @param complete_semaphores 绘制完成后发送的信号
|
||||
*/
|
||||
bool SubmitDraw (List<VkCommandBuffer> &cmd_list,List<VkSemaphore> &wait_sems,List<VkSemaphore> &complete_semaphores); ///<提交绘制指令
|
||||
|
||||
bool SubmitTexture (const VkCommandBuffer *cmd_bufs,const uint32_t count=1); ///<提交纹理处理到队列
|
||||
|
||||
bool PresentBackbuffer (); ///<等待绘制队列完成,并将后台缓冲区呈现到前台
|
||||
};//class Device
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_RENDER_SURFACE_INCLUDE
|
||||
|
@@ -13,7 +13,6 @@ struct DeviceAttribute
|
||||
|
||||
VkSurfaceKHR surface =VK_NULL_HANDLE;
|
||||
VkSurfaceCapabilitiesKHR surface_caps;
|
||||
VkExtent2D swapchain_extent;
|
||||
|
||||
uint32_t graphics_family =ERROR_FAMILY_INDEX;
|
||||
uint32_t present_family =ERROR_FAMILY_INDEX;
|
||||
@@ -33,10 +32,6 @@ struct DeviceAttribute
|
||||
|
||||
VkDevice device =VK_NULL_HANDLE;
|
||||
VkCommandPool cmd_pool =VK_NULL_HANDLE;
|
||||
VkSwapchainKHR swap_chain =VK_NULL_HANDLE;
|
||||
|
||||
ObjectList<Texture2D> sc_texture;
|
||||
Texture2D * sc_depth =nullptr;
|
||||
|
||||
VkDescriptorPool desc_pool =VK_NULL_HANDLE;
|
||||
|
||||
@@ -49,7 +44,6 @@ public:
|
||||
|
||||
bool CheckMemoryType(uint32_t typeBits,VkMemoryPropertyFlags properties,uint32_t *typeIndex) const;
|
||||
|
||||
void ClearSwapchain();
|
||||
void Refresh();
|
||||
};//class DeviceAttribute
|
||||
VK_NAMESPACE_END
|
||||
|
82
inc/hgl/graph/vulkan/VKSwapchain.h
Normal file
82
inc/hgl/graph/vulkan/VKSwapchain.h
Normal file
@@ -0,0 +1,82 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_SWAP_CHAIN_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_SWAP_CHAIN_INCLUDE
|
||||
|
||||
#include<hgl/graph/Vulkan/VK.h>
|
||||
#include<hgl/graph/vulkan/VKFramebuffer.h>
|
||||
#include<hgl/graph/vulkan/VKFence.h>
|
||||
#include<hgl/graph/vulkan/VKSemaphore.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class Swapchain
|
||||
{
|
||||
protected:
|
||||
|
||||
Device *device;
|
||||
|
||||
VkExtent2D extent;
|
||||
|
||||
VkQueue graphics_queue =VK_NULL_HANDLE;
|
||||
VkSwapchainKHR swap_chain =VK_NULL_HANDLE;
|
||||
|
||||
uint32_t swap_chain_count;
|
||||
|
||||
ObjectList<Texture2D> sc_texture;
|
||||
Texture2D * sc_depth =nullptr;
|
||||
|
||||
protected:
|
||||
|
||||
VkPipelineStageFlags pipe_stage_flags;
|
||||
|
||||
uint32_t current_frame;
|
||||
ObjectList<Framebuffer> render_frame;
|
||||
|
||||
uint32_t current_fence;
|
||||
ObjectList<Fence> fence_list;
|
||||
|
||||
RenderPass *main_rp =nullptr;
|
||||
|
||||
Semaphore *present_complete_semaphore =nullptr,
|
||||
*render_complete_semaphore =nullptr;
|
||||
|
||||
VkSubmitInfo submit_info;
|
||||
VkPresentInfoKHR present_info;
|
||||
|
||||
public:
|
||||
|
||||
const VkExtent2D & GetExtent ()const {return extent;}
|
||||
const uint32_t GetImageCount ()const {return sc_texture.GetCount();}
|
||||
|
||||
RenderPass * GetMainRenderPass () {return main_rp;}
|
||||
Framebuffer * GetFramebuffer (int index) {return render_frame[index];}
|
||||
const uint32_t GetCurrentFrameIndices () {return current_frame;}
|
||||
Framebuffer * GetCurrentFramebuffer () {return render_frame[current_frame];}
|
||||
|
||||
public:
|
||||
|
||||
Swapchain(Device *);
|
||||
virtual ~Swapchain();
|
||||
|
||||
void Clear ();
|
||||
|
||||
void Recreate ();
|
||||
|
||||
bool Wait (bool wait_all=VK_TRUE,uint64_t time_out=HGL_NANO_SEC_PER_SEC*0.1); ///<<3C>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
/**
|
||||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ֡<D2BB><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>͵<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>ź<EFBFBD>
|
||||
*/
|
||||
bool AcquireNextImage (VkSemaphore); ///<<3C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ֡<D2BB><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
/**
|
||||
* <20>ύһ<E1BDBB><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
||||
* @param cmd_list <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
||||
* @param wait_sems ָ<>ʼǰҪ<C7B0>ȴ<EFBFBD><C8B4><EFBFBD>ȷ<EFBFBD>ϵ<EFBFBD><CFB5>ź<EFBFBD>
|
||||
* @param complete_semaphores <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD>͵<EFBFBD><CDB5>ź<EFBFBD>
|
||||
*/
|
||||
bool SubmitDraw (List<VkCommandBuffer> &cmd_list,List<VkSemaphore> &wait_sems,List<VkSemaphore> &complete_semaphores); ///<<3C>ύ<EFBFBD><E1BDBB><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
||||
|
||||
bool SubmitTexture (const VkCommandBuffer *cmd_bufs,const uint32_t count=1); ///<<3C>ύ<EFBFBD><E1BDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
bool PresentBackbuffer (); ///<<3C>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̨<EFBFBD><CCA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>ǰ̨
|
||||
};//class Swapchain
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_SWAP_CHAIN_INCLUDE
|
Reference in New Issue
Block a user