2019-07-11 01:07:16 +08:00
|
|
|
|
// 9.延迟渲染
|
2019-06-26 20:44:53 +08:00
|
|
|
|
// 简单的延迟渲染测试,仅一个太阳光
|
|
|
|
|
|
|
|
|
|
#include"VulkanAppFramework.h"
|
|
|
|
|
#include<hgl/filesystem/FileSystem.h>
|
|
|
|
|
#include<hgl/graph/InlineGeometry.h>
|
|
|
|
|
#include<hgl/graph/SceneDB.h>
|
|
|
|
|
#include<hgl/graph/RenderableInstance.h>
|
|
|
|
|
#include<hgl/graph/RenderList.h>
|
2019-07-03 19:45:39 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKTexture.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VKImageView.h>
|
2019-07-08 20:53:07 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKSampler.h>
|
2019-07-03 19:45:39 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKFramebuffer.h>
|
2019-06-26 20:44:53 +08:00
|
|
|
|
|
|
|
|
|
using namespace hgl;
|
|
|
|
|
using namespace hgl::graph;
|
|
|
|
|
|
2019-07-08 17:50:19 +08:00
|
|
|
|
VK_NAMESPACE_BEGIN
|
|
|
|
|
Texture2D *LoadTGATexture(const OSString &filename,Device *device);
|
|
|
|
|
VK_NAMESPACE_END
|
|
|
|
|
|
2019-06-26 20:44:53 +08:00
|
|
|
|
constexpr uint32_t SCREEN_WIDTH=128;
|
|
|
|
|
constexpr uint32_t SCREEN_HEIGHT=128;
|
|
|
|
|
|
2019-07-03 19:45:39 +08:00
|
|
|
|
using Texture2DPointer=vulkan::Texture2D *;
|
|
|
|
|
|
2019-07-05 19:56:15 +08:00
|
|
|
|
constexpr VkFormat position_candidate_format[]={FMT_RGBA32F,FMT_RGBA16F};
|
2019-07-11 22:09:22 +08:00
|
|
|
|
constexpr VkFormat color_candidate_format []={FMT_RGBA32F,
|
|
|
|
|
FMT_RGBA16F,FMT_RGB16UN,FMT_RGB16SN,
|
|
|
|
|
FMT_RGBA8UN,FMT_RGBA8SN,FMT_RGBA8U,
|
|
|
|
|
FMT_BGRA8UN,FMT_BGRA8SN,FMT_BGRA8U,
|
|
|
|
|
FMT_ABGR8UN,FMT_ABGR8SN,FMT_ABGR8U,
|
|
|
|
|
FMT_RGB565,FMT_BGR565};
|
|
|
|
|
constexpr VkFormat normal_candidate_format []={FMT_RGBA32F,
|
|
|
|
|
FMT_RGBA16F,
|
|
|
|
|
FMT_A2RGB10UN,FMT_A2RGB10SN,FMT_A2BGR10UN,
|
|
|
|
|
FMT_A2BGR10SN};
|
2019-07-05 19:56:15 +08:00
|
|
|
|
constexpr VkFormat depth_candidate_format []={FMT_D32F,FMT_D32F_S8U,FMT_X8_D24,FMT_D24UN_S8U,FMT_D16UN,FMT_D16UN_S8U};
|
|
|
|
|
|
2019-06-26 20:44:53 +08:00
|
|
|
|
class TestApp:public CameraAppFramework
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
SceneNode render_root;
|
|
|
|
|
RenderList render_list;
|
|
|
|
|
|
2019-07-03 19:45:39 +08:00
|
|
|
|
struct DeferredGBuffer
|
|
|
|
|
{
|
2019-07-10 18:04:50 +08:00
|
|
|
|
VkExtent2D extent;
|
2019-07-03 19:45:39 +08:00
|
|
|
|
vulkan::Framebuffer *framebuffer;
|
|
|
|
|
vulkan::RenderPass *renderpass;
|
|
|
|
|
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
struct
|
|
|
|
|
{
|
2019-07-04 19:49:18 +08:00
|
|
|
|
Texture2DPointer position,normal,color,depth;
|
2019-07-03 19:45:39 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Texture2DPointer texture_list[4];
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-05 17:00:49 +08:00
|
|
|
|
List<VkFormat> gbuffer_format_list;
|
2019-07-03 19:45:39 +08:00
|
|
|
|
List<vulkan::ImageView *> image_view_list;
|
|
|
|
|
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
List<VkAttachmentDescription> desc_list;
|
|
|
|
|
List<VkAttachmentReference> ref_list;
|
|
|
|
|
}attachment;
|
|
|
|
|
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
List<VkSubpassDescription> desc;
|
|
|
|
|
List<VkSubpassDependency> dependency;
|
|
|
|
|
}subpass;
|
|
|
|
|
}gbuffer;//
|
|
|
|
|
|
2019-06-26 20:44:53 +08:00
|
|
|
|
struct SubpassParam
|
|
|
|
|
{
|
2019-06-27 21:26:57 +08:00
|
|
|
|
vulkan::Material * material;
|
2019-06-26 20:44:53 +08:00
|
|
|
|
vulkan::DescriptorSets *desc_sets;
|
2019-07-12 17:33:38 +08:00
|
|
|
|
vulkan::Pipeline * pipeline_line;
|
|
|
|
|
vulkan::Pipeline * pipeline_solid;
|
2019-06-26 20:44:53 +08:00
|
|
|
|
};//
|
|
|
|
|
|
2019-06-28 20:46:32 +08:00
|
|
|
|
SubpassParam sp_gbuffer;
|
|
|
|
|
SubpassParam sp_composition;
|
2019-06-26 20:44:53 +08:00
|
|
|
|
|
2019-07-10 18:04:50 +08:00
|
|
|
|
vulkan::Renderable *ro_plane_grid,
|
|
|
|
|
*ro_cube,
|
|
|
|
|
*ro_sphere,
|
|
|
|
|
*ro_torus,
|
|
|
|
|
*ro_cylinder,
|
|
|
|
|
*ro_cone;
|
2019-07-08 17:50:19 +08:00
|
|
|
|
|
2019-07-08 19:59:34 +08:00
|
|
|
|
vulkan::Sampler * sampler=nullptr;
|
2019-07-08 17:50:19 +08:00
|
|
|
|
|
|
|
|
|
struct
|
|
|
|
|
{
|
2019-07-10 18:04:50 +08:00
|
|
|
|
Texture2DPointer color=nullptr;
|
|
|
|
|
Texture2DPointer normal=nullptr;
|
|
|
|
|
// Texture2DPointer specular=nullptr;
|
2019-07-08 17:50:19 +08:00
|
|
|
|
}texture;
|
2019-06-26 20:44:53 +08:00
|
|
|
|
|
2019-07-08 20:53:07 +08:00
|
|
|
|
vulkan::CommandBuffer *gbuffer_cmd=nullptr;
|
|
|
|
|
|
2019-07-08 19:59:34 +08:00
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
~TestApp()
|
|
|
|
|
{
|
2019-07-08 20:53:07 +08:00
|
|
|
|
SAFE_CLEAR(gbuffer_cmd);
|
2019-07-10 18:04:50 +08:00
|
|
|
|
//SAFE_CLEAR(texture.specular);
|
2019-07-08 19:59:34 +08:00
|
|
|
|
SAFE_CLEAR(texture.normal);
|
|
|
|
|
SAFE_CLEAR(texture.color);
|
|
|
|
|
SAFE_CLEAR(sampler);
|
|
|
|
|
}
|
2019-06-26 20:44:53 +08:00
|
|
|
|
private:
|
|
|
|
|
|
2019-07-05 19:56:15 +08:00
|
|
|
|
const VkFormat GetCandidateFormat(const VkFormat *fmt_list,const uint count)
|
|
|
|
|
{
|
|
|
|
|
auto pd=device->GetPhysicalDevice();
|
|
|
|
|
|
|
|
|
|
for(uint i=0;i<count;i++)
|
|
|
|
|
if(pd->IsColorAttachmentOptimal(fmt_list[i]))
|
|
|
|
|
return fmt_list[i];
|
|
|
|
|
|
|
|
|
|
for(uint i=0;i<count;i++)
|
|
|
|
|
if(pd->IsColorAttachmentLinear(fmt_list[i]))
|
|
|
|
|
return fmt_list[i];
|
|
|
|
|
|
|
|
|
|
return FMT_UNDEFINED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const VkFormat GetDepthCandidateFormat()
|
|
|
|
|
{
|
|
|
|
|
auto pd=device->GetPhysicalDevice();
|
|
|
|
|
|
|
|
|
|
for(VkFormat fmt:depth_candidate_format)
|
|
|
|
|
if(pd->IsDepthAttachmentOptimal(fmt))
|
|
|
|
|
return fmt;
|
|
|
|
|
|
|
|
|
|
for(VkFormat fmt:depth_candidate_format)
|
|
|
|
|
if(pd->IsDepthAttachmentLinear(fmt))
|
|
|
|
|
return fmt;
|
|
|
|
|
|
|
|
|
|
return FMT_UNDEFINED;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 19:45:39 +08:00
|
|
|
|
bool InitGBuffer()
|
|
|
|
|
{
|
2019-07-12 17:33:38 +08:00
|
|
|
|
gbuffer.extent.width =512;
|
|
|
|
|
gbuffer.extent.height =512;
|
2019-07-05 19:56:15 +08:00
|
|
|
|
|
|
|
|
|
//根据候选格式表选择格式
|
2019-07-10 21:48:07 +08:00
|
|
|
|
//const VkFormat position_format =GetCandidateFormat(position_candidate_format, sizeof(position_candidate_format));
|
|
|
|
|
//const VkFormat color_format =GetCandidateFormat(color_candidate_format, sizeof(color_candidate_format));
|
|
|
|
|
//const VkFormat normal_format =GetCandidateFormat(normal_candidate_format, sizeof(normal_candidate_format));
|
|
|
|
|
//const VkFormat depth_format =GetDepthCandidateFormat();
|
|
|
|
|
|
|
|
|
|
//if(position_format ==FMT_UNDEFINED
|
|
|
|
|
// ||color_format ==FMT_UNDEFINED
|
|
|
|
|
// ||normal_format ==FMT_UNDEFINED
|
|
|
|
|
// ||depth_format ==FMT_UNDEFINED)
|
|
|
|
|
// return(false);
|
|
|
|
|
|
2019-07-12 17:33:38 +08:00
|
|
|
|
const VkFormat position_format =FMT_RGBA32F;
|
|
|
|
|
const VkFormat color_format =FMT_RGBA32F;
|
|
|
|
|
const VkFormat normal_format =FMT_RGBA32F;
|
2019-07-12 01:57:18 +08:00
|
|
|
|
const VkFormat depth_format =FMT_D32F;
|
2019-07-03 19:45:39 +08:00
|
|
|
|
|
2019-07-10 18:04:50 +08:00
|
|
|
|
gbuffer.position=device->CreateAttachmentTextureColor(position_format, gbuffer.extent.width,gbuffer.extent.height);
|
|
|
|
|
gbuffer.color =device->CreateAttachmentTextureColor(color_format, gbuffer.extent.width,gbuffer.extent.height);
|
|
|
|
|
gbuffer.normal =device->CreateAttachmentTextureColor(normal_format, gbuffer.extent.width,gbuffer.extent.height);
|
|
|
|
|
gbuffer.depth =device->CreateAttachmentTextureDepth(depth_format, gbuffer.extent.width,gbuffer.extent.height);
|
2019-07-03 19:45:39 +08:00
|
|
|
|
|
|
|
|
|
for(uint i=0;i<3;i++)
|
|
|
|
|
{
|
2019-07-05 17:00:49 +08:00
|
|
|
|
gbuffer.gbuffer_format_list.Add(gbuffer.texture_list[i]->GetFormat());
|
2019-07-03 19:45:39 +08:00
|
|
|
|
gbuffer.image_view_list.Add(gbuffer.texture_list[i]->GetImageView());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!device->CreateAttachment( gbuffer.attachment.ref_list,
|
|
|
|
|
gbuffer.attachment.desc_list,
|
2019-07-05 17:00:49 +08:00
|
|
|
|
gbuffer.gbuffer_format_list,
|
2019-07-03 19:45:39 +08:00
|
|
|
|
gbuffer.depth->GetFormat()))
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
VkSubpassDescription desc;
|
|
|
|
|
|
|
|
|
|
device->CreateSubpassDescription(desc,gbuffer.attachment.ref_list);
|
|
|
|
|
|
|
|
|
|
gbuffer.subpass.desc.Add(desc);
|
|
|
|
|
|
2019-07-05 17:35:43 +08:00
|
|
|
|
device->CreateSubpassDependency(gbuffer.subpass.dependency,2); //为啥要2个还不清楚
|
2019-07-03 19:45:39 +08:00
|
|
|
|
|
|
|
|
|
gbuffer.renderpass=device->CreateRenderPass(gbuffer.attachment.desc_list,
|
|
|
|
|
gbuffer.subpass.desc,
|
|
|
|
|
gbuffer.subpass.dependency,
|
2019-07-05 17:00:49 +08:00
|
|
|
|
gbuffer.gbuffer_format_list,
|
2019-07-03 19:45:39 +08:00
|
|
|
|
gbuffer.depth->GetFormat());
|
|
|
|
|
|
|
|
|
|
if(!gbuffer.renderpass)
|
|
|
|
|
return(false);
|
|
|
|
|
|
2019-07-05 19:56:15 +08:00
|
|
|
|
gbuffer.framebuffer=vulkan::CreateFramebuffer(device,gbuffer.renderpass,gbuffer.image_view_list,gbuffer.depth->GetImageView());
|
2019-07-03 19:45:39 +08:00
|
|
|
|
|
|
|
|
|
if(!gbuffer.framebuffer)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-27 21:26:57 +08:00
|
|
|
|
bool InitSubpass(SubpassParam *sp,const OSString &vs,const OSString &fs)
|
2019-06-26 20:44:53 +08:00
|
|
|
|
{
|
2019-06-27 21:26:57 +08:00
|
|
|
|
sp->material=shader_manage->CreateMaterial(vs,fs);
|
2019-06-26 20:44:53 +08:00
|
|
|
|
|
2019-06-27 21:26:57 +08:00
|
|
|
|
if(!sp->material)
|
2019-07-05 17:00:49 +08:00
|
|
|
|
return(false);
|
2019-06-26 20:44:53 +08:00
|
|
|
|
|
2019-06-27 21:26:57 +08:00
|
|
|
|
sp->desc_sets=sp->material->CreateDescriptorSets();
|
2019-06-26 20:44:53 +08:00
|
|
|
|
|
2019-06-27 21:26:57 +08:00
|
|
|
|
db->Add(sp->material);
|
|
|
|
|
db->Add(sp->desc_sets);
|
|
|
|
|
return(true);
|
2019-06-26 20:44:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-28 20:46:32 +08:00
|
|
|
|
bool InitGBufferPipeline(SubpassParam *sp)
|
2019-06-26 20:44:53 +08:00
|
|
|
|
{
|
2019-07-10 18:04:50 +08:00
|
|
|
|
AutoDelete<vulkan::PipelineCreater> pipeline_creater=new vulkan::PipelineCreater(device,sp->material,gbuffer.renderpass,gbuffer.extent);
|
2019-06-28 20:46:32 +08:00
|
|
|
|
pipeline_creater->Set(PRIM_TRIANGLES);
|
2019-07-05 17:00:49 +08:00
|
|
|
|
|
2019-07-12 17:33:38 +08:00
|
|
|
|
sp->pipeline_solid=pipeline_creater->Create();
|
2019-06-28 20:46:32 +08:00
|
|
|
|
|
2019-07-12 17:33:38 +08:00
|
|
|
|
if(!sp->pipeline_solid)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
db->Add(sp->pipeline_solid);
|
|
|
|
|
|
|
|
|
|
pipeline_creater->CloseCullFace();
|
|
|
|
|
pipeline_creater->Set(PRIM_LINES);
|
|
|
|
|
|
|
|
|
|
sp->pipeline_line=pipeline_creater->Create();
|
|
|
|
|
|
|
|
|
|
if(!sp->pipeline_line)
|
2019-06-26 20:44:53 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2019-07-12 17:33:38 +08:00
|
|
|
|
db->Add(sp->pipeline_line);
|
2019-06-26 20:44:53 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-28 20:46:32 +08:00
|
|
|
|
bool InitCompositionPipeline(SubpassParam *sp)
|
2019-06-26 20:44:53 +08:00
|
|
|
|
{
|
2019-07-05 17:03:28 +08:00
|
|
|
|
AutoDelete<vulkan::PipelineCreater> pipeline_creater=new vulkan::PipelineCreater(device,sp->material,device->GetMainRenderPass(),device->GetExtent());
|
2019-06-28 20:46:32 +08:00
|
|
|
|
pipeline_creater->SetDepthTest(false);
|
|
|
|
|
pipeline_creater->SetDepthWrite(false);
|
2019-06-26 20:44:53 +08:00
|
|
|
|
pipeline_creater->SetCullMode(VK_CULL_MODE_NONE);
|
|
|
|
|
pipeline_creater->Set(PRIM_TRIANGLES);
|
2019-07-08 20:53:07 +08:00
|
|
|
|
|
2019-07-12 17:33:38 +08:00
|
|
|
|
sp->pipeline_solid=pipeline_creater->Create();
|
2019-07-01 17:04:02 +08:00
|
|
|
|
|
2019-07-12 17:33:38 +08:00
|
|
|
|
if(!sp->pipeline_solid)
|
2019-06-26 20:44:53 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2019-07-12 17:33:38 +08:00
|
|
|
|
db->Add(sp->pipeline_solid);
|
2019-06-26 20:44:53 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-27 21:26:57 +08:00
|
|
|
|
bool InitMaterial()
|
|
|
|
|
{
|
2019-07-10 21:21:17 +08:00
|
|
|
|
if(!InitSubpass(&sp_gbuffer, OS_TEXT("res/shader/gbuffer_opaque.vert.spv"),OS_TEXT("res/shader/gbuffer_opaque.frag.spv")))return(false);
|
|
|
|
|
//if(!InitSubpass(&sp_composition,OS_TEXT("res/shader/ds_composition.vert.spv"),OS_TEXT("res/shader/ds_composition.frag.spv")))return(false);
|
2019-06-28 20:46:32 +08:00
|
|
|
|
|
2019-07-01 17:04:02 +08:00
|
|
|
|
if(!InitGBufferPipeline(&sp_gbuffer))return(false);
|
2019-07-08 20:53:07 +08:00
|
|
|
|
//if(!InitCompositionPipeline(&sp_composition))return(false);
|
2019-07-01 17:04:02 +08:00
|
|
|
|
|
2019-07-10 21:21:17 +08:00
|
|
|
|
texture.color =vulkan::LoadTGATexture(OS_TEXT("res/image/cardboardPlainStain.tga"),device);
|
|
|
|
|
texture.normal =vulkan::LoadTGATexture(OS_TEXT("res/image/APOCWALL029_NRM.tga"),device);
|
2019-07-12 17:33:38 +08:00
|
|
|
|
//texture.normal =vulkan::LoadTGATexture(OS_TEXT("res/image/flat_normal.tga"),device);
|
2019-07-10 21:21:17 +08:00
|
|
|
|
//texture.specular=vulkan::LoadTGATexture(OS_TEXT("res/image/APOCWALL029_SPEC.tga"),device);
|
2019-07-08 19:59:34 +08:00
|
|
|
|
|
2019-07-08 18:18:35 +08:00
|
|
|
|
VkSamplerCreateInfo sampler_create_info;
|
|
|
|
|
|
|
|
|
|
sampler_create_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
|
|
|
|
|
sampler_create_info.pNext = nullptr;
|
|
|
|
|
sampler_create_info.flags = 0;
|
|
|
|
|
sampler_create_info.magFilter = VK_FILTER_LINEAR;
|
|
|
|
|
sampler_create_info.minFilter = VK_FILTER_LINEAR;
|
|
|
|
|
sampler_create_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
|
|
|
|
|
sampler_create_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
|
|
|
|
sampler_create_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
|
|
|
|
sampler_create_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
|
|
|
|
sampler_create_info.mipLodBias = 0.0f;
|
|
|
|
|
sampler_create_info.anisotropyEnable = false;
|
|
|
|
|
sampler_create_info.maxAnisotropy = 0;
|
|
|
|
|
sampler_create_info.compareEnable = false;
|
|
|
|
|
sampler_create_info.compareOp = VK_COMPARE_OP_NEVER;
|
|
|
|
|
sampler_create_info.minLod = 0.0f;
|
|
|
|
|
sampler_create_info.maxLod = 1.0f;
|
|
|
|
|
sampler_create_info.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
|
|
|
|
|
sampler_create_info.unnormalizedCoordinates = false;
|
|
|
|
|
|
|
|
|
|
sampler=device->CreateSampler(&sampler_create_info);
|
|
|
|
|
|
|
|
|
|
sp_gbuffer.desc_sets->BindSampler(sp_gbuffer.material->GetSampler("TextureColor"),texture.color,sampler);
|
|
|
|
|
sp_gbuffer.desc_sets->BindSampler(sp_gbuffer.material->GetSampler("TextureNormal"),texture.normal,sampler);
|
|
|
|
|
|
|
|
|
|
InitCameraUBO(sp_gbuffer.desc_sets,sp_gbuffer.material->GetUBO("world"));
|
2019-07-08 17:50:19 +08:00
|
|
|
|
|
2019-07-08 18:18:35 +08:00
|
|
|
|
sp_gbuffer.desc_sets->Update();
|
2019-07-01 17:04:02 +08:00
|
|
|
|
return(true);
|
2019-06-28 20:46:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CreateRenderObject(vulkan::Material *mtl)
|
|
|
|
|
{
|
2019-07-10 18:04:50 +08:00
|
|
|
|
{
|
|
|
|
|
struct PlaneGridCreateInfo pgci;
|
|
|
|
|
|
|
|
|
|
pgci.coord[0].Set(-100,-100,0);
|
|
|
|
|
pgci.coord[1].Set( 100,-100,0);
|
|
|
|
|
pgci.coord[2].Set( 100, 100,0);
|
|
|
|
|
pgci.coord[3].Set(-100, 100,0);
|
|
|
|
|
|
|
|
|
|
pgci.step.u=20;
|
|
|
|
|
pgci.step.v=20;
|
|
|
|
|
|
|
|
|
|
pgci.side_step.u=10;
|
|
|
|
|
pgci.side_step.v=10;
|
|
|
|
|
|
|
|
|
|
pgci.color.Set(0.75,0,0,1);
|
|
|
|
|
pgci.side_color.Set(1,0,0,1);
|
|
|
|
|
|
|
|
|
|
ro_plane_grid=CreateRenderablePlaneGrid(db,mtl,&pgci);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
struct CubeCreateInfo cci;
|
|
|
|
|
ro_cube=CreateRenderableCube(db,mtl,&cci);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2019-07-11 22:09:22 +08:00
|
|
|
|
ro_sphere=CreateRenderableSphere(db,mtl,64);
|
2019-07-10 18:04:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
TorusCreateInfo tci;
|
|
|
|
|
|
|
|
|
|
tci.innerRadius=50;
|
|
|
|
|
tci.outerRadius=70;
|
2019-07-08 17:50:19 +08:00
|
|
|
|
|
2019-07-10 18:04:50 +08:00
|
|
|
|
tci.numberSlices=32;
|
|
|
|
|
tci.numberStacks=16;
|
|
|
|
|
|
|
|
|
|
ro_torus=CreateRenderableTorus(db,mtl,&tci);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
CylinderCreateInfo cci;
|
|
|
|
|
|
|
|
|
|
cci.halfExtend=10;
|
|
|
|
|
cci.radius=10;
|
|
|
|
|
cci.numberSlices=16;
|
|
|
|
|
|
|
|
|
|
ro_cylinder=CreateRenderableCylinder(db,mtl,&cci);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
ConeCreateInfo cci;
|
|
|
|
|
|
|
|
|
|
cci.halfExtend=10;
|
|
|
|
|
cci.radius=10;
|
|
|
|
|
cci.numberSlices=16;
|
|
|
|
|
cci.numberStacks=1;
|
|
|
|
|
|
|
|
|
|
ro_cone=CreateRenderableCone(db,mtl,&cci);
|
|
|
|
|
}
|
2019-06-28 20:46:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InitScene(SubpassParam *sp)
|
2019-06-26 20:44:53 +08:00
|
|
|
|
{
|
2019-06-28 20:46:32 +08:00
|
|
|
|
CreateRenderObject(sp->material);
|
2019-07-12 17:33:38 +08:00
|
|
|
|
render_root.Add(db->CreateRenderableInstance(sp->pipeline_line,sp->desc_sets,ro_plane_grid));
|
|
|
|
|
render_root.Add(db->CreateRenderableInstance(sp->pipeline_solid,sp->desc_sets,ro_torus ),translate(0,0,25));
|
|
|
|
|
render_root.Add(db->CreateRenderableInstance(sp->pipeline_solid,sp->desc_sets,ro_sphere ),scale(25,25,25));
|
|
|
|
|
render_root.Add(db->CreateRenderableInstance(sp->pipeline_solid,sp->desc_sets,ro_cube ),translate(-16, 0,15)*scale(10,10,10));
|
|
|
|
|
render_root.Add(db->CreateRenderableInstance(sp->pipeline_solid,sp->desc_sets,ro_cylinder ),translate( 16, 16,10)*scale(1,1,2));
|
|
|
|
|
render_root.Add(db->CreateRenderableInstance(sp->pipeline_solid,sp->desc_sets,ro_cone ),translate( 0,-16, 0)*scale(1,1,2));
|
2019-06-26 20:44:53 +08:00
|
|
|
|
|
|
|
|
|
render_root.RefreshMatrix();
|
|
|
|
|
render_root.ExpendToList(&render_list);
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-08 20:53:07 +08:00
|
|
|
|
bool InitGBufferCommandBuffer()
|
|
|
|
|
{
|
2019-07-10 21:00:36 +08:00
|
|
|
|
gbuffer_cmd=device->CreateCommandBuffer(&gbuffer.extent,gbuffer.attachment.desc_list.GetCount());
|
2019-07-08 20:53:07 +08:00
|
|
|
|
|
|
|
|
|
if(!gbuffer_cmd)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
gbuffer_cmd->Begin();
|
|
|
|
|
if(!gbuffer_cmd->BeginRenderPass(gbuffer.renderpass,gbuffer.framebuffer))
|
|
|
|
|
return(false);
|
|
|
|
|
|
2019-07-10 18:04:50 +08:00
|
|
|
|
render_list.Render(gbuffer_cmd);
|
2019-07-08 20:53:07 +08:00
|
|
|
|
|
|
|
|
|
gbuffer_cmd->EndRenderPass();
|
|
|
|
|
gbuffer_cmd->End();
|
2019-07-10 18:04:50 +08:00
|
|
|
|
|
|
|
|
|
device->SubmitDraw(*gbuffer_cmd);
|
2019-07-08 20:53:07 +08:00
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-26 20:44:53 +08:00
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
bool Init()
|
|
|
|
|
{
|
|
|
|
|
if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
|
|
|
|
return(false);
|
|
|
|
|
|
2019-07-05 19:56:15 +08:00
|
|
|
|
if(!InitGBuffer())
|
|
|
|
|
return(false);
|
|
|
|
|
|
2019-06-26 20:44:53 +08:00
|
|
|
|
if(!InitMaterial())
|
|
|
|
|
return(false);
|
|
|
|
|
|
2019-06-28 20:46:32 +08:00
|
|
|
|
if(!InitScene(&sp_gbuffer))
|
2019-06-26 20:44:53 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2019-07-08 20:53:07 +08:00
|
|
|
|
if(!InitGBufferCommandBuffer())
|
|
|
|
|
return(false);
|
|
|
|
|
|
2019-06-26 20:44:53 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BuildCommandBuffer(uint32_t index) override
|
|
|
|
|
{
|
|
|
|
|
render_root.RefreshMatrix();
|
|
|
|
|
render_list.Clear();
|
|
|
|
|
render_root.ExpendToList(&render_list);
|
|
|
|
|
|
|
|
|
|
VulkanApplicationFramework::BuildCommandBuffer(index,&render_list);
|
|
|
|
|
}
|
|
|
|
|
};//class TestApp:public CameraAppFramework
|
|
|
|
|
|
|
|
|
|
int main(int,char **)
|
|
|
|
|
{
|
|
|
|
|
TestApp app;
|
|
|
|
|
|
|
|
|
|
if(!app.Init())
|
|
|
|
|
return(-1);
|
|
|
|
|
|
|
|
|
|
while(app.Run());
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|