增加RenderPass封装
This commit is contained in:
parent
b9401d70a7
commit
bcb3a4a6be
@ -12,7 +12,11 @@ SET(VULKAN_TEST_SOURCE_FILES main.cpp
|
||||
RenderSurfaceAttribute.cpp
|
||||
RenderSurfaceCreater.cpp
|
||||
RenderSurface.cpp
|
||||
VKBuffer.cpp)
|
||||
VKBuffer.cpp
|
||||
# VKPipelineLayout.cpp
|
||||
# VKDescriptorSet.cpp
|
||||
VKRenderPass.cpp
|
||||
)
|
||||
|
||||
SET(VULKAN_TEST_HEADER_FILES VK.h
|
||||
VKInstance.h
|
||||
@ -20,6 +24,9 @@ SET(VULKAN_TEST_HEADER_FILES VK.h
|
||||
RenderSurfaceAttribute.h
|
||||
RenderSurface.h
|
||||
VKBuffer.h
|
||||
# VKPipelineLayout.h
|
||||
# VKDescriptorSet.h
|
||||
VKRenderPass.h
|
||||
Window.h)
|
||||
|
||||
SET(SHADER_FILES shader_compile.bat
|
||||
|
@ -24,7 +24,7 @@ Buffer *RenderSurface::CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize si
|
||||
|
||||
VkMemoryAllocateInfo alloc_info={};
|
||||
alloc_info.sType=VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||
alloc_info.pNext=NULL;
|
||||
alloc_info.pNext=nullptr;
|
||||
alloc_info.memoryTypeIndex=0;
|
||||
alloc_info.allocationSize=mem_reqs.size;
|
||||
|
||||
@ -75,4 +75,79 @@ CommandBuffer *RenderSurface::CreateCommandBuffer()
|
||||
return(new CommandBuffer(rsa->device,rsa->cmd_pool,cmd_buf));
|
||||
}
|
||||
|
||||
//DescriptorSet *RenderSurface::CreateDescSet(int count)
|
||||
//{
|
||||
// VkDescriptorSetAllocateInfo alloc_info[1];
|
||||
// alloc_info[0].sType=VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||
// alloc_info[0].pNext=nullptr;
|
||||
// alloc_info[0].descriptorPool=rsa->desc_pool;
|
||||
// alloc_info[0].descriptorSetCount=count;
|
||||
// alloc_info[0].pSetLayouts=desc_layout.data();
|
||||
//
|
||||
// VkDescriptorSet desc_set;
|
||||
//
|
||||
// desc_set.resize(count);
|
||||
// res=vkAllocateDescriptorSets(info.device,alloc_info,info.desc_set.data());
|
||||
//}
|
||||
|
||||
RenderPass *RenderSurface::CreateRenderPass()
|
||||
{
|
||||
VkAttachmentDescription attachments[2];
|
||||
attachments[0].format=rsa->format;
|
||||
attachments[0].samples=VK_SAMPLE_COUNT_1_BIT;
|
||||
attachments[0].loadOp=VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
attachments[0].storeOp=VK_ATTACHMENT_STORE_OP_STORE;
|
||||
attachments[0].stencilLoadOp=VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
attachments[0].stencilStoreOp=VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
attachments[0].initialLayout=VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
attachments[0].finalLayout=VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||
attachments[0].flags=0;
|
||||
|
||||
attachments[1].format=rsa->depth.format;
|
||||
attachments[1].samples=VK_SAMPLE_COUNT_1_BIT;
|
||||
attachments[1].loadOp=VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
attachments[1].storeOp=VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
attachments[1].stencilLoadOp=VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
attachments[1].stencilStoreOp=VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
attachments[1].initialLayout=VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
attachments[1].finalLayout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
attachments[1].flags=0;
|
||||
|
||||
VkAttachmentReference color_reference={};
|
||||
color_reference.attachment=0;
|
||||
color_reference.layout=VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
|
||||
VkAttachmentReference depth_reference={};
|
||||
depth_reference.attachment=1;
|
||||
depth_reference.layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
|
||||
VkSubpassDescription subpass={};
|
||||
subpass.pipelineBindPoint=VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||
subpass.flags=0;
|
||||
subpass.inputAttachmentCount=0;
|
||||
subpass.pInputAttachments=nullptr;
|
||||
subpass.colorAttachmentCount=1;
|
||||
subpass.pColorAttachments=&color_reference;
|
||||
subpass.pResolveAttachments=nullptr;
|
||||
subpass.pDepthStencilAttachment=&depth_reference;
|
||||
subpass.preserveAttachmentCount=0;
|
||||
subpass.pPreserveAttachments=nullptr;
|
||||
|
||||
VkRenderPassCreateInfo rp_info={};
|
||||
rp_info.sType=VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
||||
rp_info.pNext=nullptr;
|
||||
rp_info.attachmentCount=2;
|
||||
rp_info.pAttachments=attachments;
|
||||
rp_info.subpassCount=1;
|
||||
rp_info.pSubpasses=&subpass;
|
||||
rp_info.dependencyCount=0;
|
||||
rp_info.pDependencies=nullptr;
|
||||
|
||||
VkRenderPass render_pass;
|
||||
|
||||
if(vkCreateRenderPass(rsa->device,&rp_info,nullptr,&render_pass)!=VK_SUCCESS)
|
||||
return(nullptr);
|
||||
|
||||
return(new RenderPass(rsa->device,render_pass));
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include"RenderSurfaceAttribute.h"
|
||||
#include"VKBuffer.h"
|
||||
#include"VKCommandBuffer.h"
|
||||
//#include"VKDescriptorSet.h"
|
||||
#include"VKRenderPass.h"
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
@ -47,6 +49,10 @@ public:
|
||||
#undef CREATE_BUFFER_OBJECT
|
||||
|
||||
CommandBuffer * CreateCommandBuffer ();
|
||||
|
||||
// DescriptorSet * CreateDescSet(int);
|
||||
|
||||
RenderPass *CreateRenderPass();
|
||||
};//class RenderSurface
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_RENDER_SURFACE_INCLUDE
|
||||
|
7
example/Vulkan/VKRenderPass.cpp
Normal file
7
example/Vulkan/VKRenderPass.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include"VKRenderPass.h"
|
||||
VK_NAMESPACE_BEGIN
|
||||
RenderPass::~RenderPass()
|
||||
{
|
||||
vkDestroyRenderPass(device,render_pass,nullptr);
|
||||
}
|
||||
VK_NAMESPACE_END
|
21
example/Vulkan/VKRenderPass.h
Normal file
21
example/Vulkan/VKRenderPass.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_RENDER_PASS_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_RENDER_PASS_INCLUDE
|
||||
|
||||
#include"VK.h"
|
||||
VK_NAMESPACE_BEGIN
|
||||
class RenderPass
|
||||
{
|
||||
VkDevice device;
|
||||
VkRenderPass render_pass;
|
||||
|
||||
public:
|
||||
|
||||
RenderPass(VkDevice d,VkRenderPass rp)
|
||||
{
|
||||
device=d;
|
||||
render_pass=rp;
|
||||
}
|
||||
virtual ~RenderPass();
|
||||
};//class RenderPass
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_RENDER_PASS_INCLUDE
|
@ -20,6 +20,14 @@ int main(int,char **)
|
||||
}
|
||||
|
||||
vulkan::RenderSurface *render=inst->CreateSurface(win);
|
||||
|
||||
if(!render)
|
||||
{
|
||||
delete inst;
|
||||
delete win;
|
||||
return(-2);
|
||||
}
|
||||
|
||||
vulkan::CommandBuffer *cmd_buf=render->CreateCommandBuffer();
|
||||
|
||||
vulkan::Buffer *ubo=render->CreateUBO(1024);
|
||||
@ -32,6 +40,10 @@ int main(int,char **)
|
||||
ubo->Unmap();
|
||||
}
|
||||
|
||||
vulkan::RenderPass *rp=render->CreateRenderPass();
|
||||
|
||||
delete rp;
|
||||
|
||||
delete ubo;
|
||||
|
||||
delete cmd_buf;
|
||||
|
Loading…
x
Reference in New Issue
Block a user