world matrix增加viewport size

This commit is contained in:
2019-07-17 04:49:49 +08:00
parent 7e3b14ce17
commit 0c20f52eb8
10 changed files with 76 additions and 36 deletions

View File

@@ -46,8 +46,7 @@ private:
struct DeferredGBuffer
{
vulkan::Semaphore *present_complete_semaphore =nullptr,
*render_complete_semaphore =nullptr;
vulkan::Semaphore *render_complete_semaphore =nullptr;
vulkan::RenderTarget *rt;
@@ -157,7 +156,6 @@ private:
gbuffer.extent.width =512;
gbuffer.extent.height =512;
gbuffer.present_complete_semaphore =device->CreateSem();
gbuffer.render_complete_semaphore =device->CreateSem();
//根据候选格式表选择格式
@@ -417,8 +415,6 @@ private:
gbuffer_cmd->EndRenderPass();
gbuffer_cmd->End();
gbuffer.rt->Submit(*gbuffer_cmd,gbuffer.present_complete_semaphore,gbuffer.render_complete_semaphore);
return(true);
}
@@ -445,11 +441,13 @@ public:
return(true);
}
virtual void SubmitDraw(int index)
{
virtual void SubmitDraw(int index) override
{
gbuffer.rt->Submit(*gbuffer_cmd,present_complete_semaphore,gbuffer.render_complete_semaphore);
VkCommandBuffer cb=*cmd_buf[index];
sc_render_target->Submit(cb,present_complete_semaphore,render_complete_semaphore);
sc_render_target->Submit(cb,gbuffer.render_complete_semaphore,render_complete_semaphore);
sc_render_target->PresentBackbuffer(render_complete_semaphore);
sc_render_target->Wait();
}

View File

@@ -10,19 +10,14 @@ using namespace hgl::graph;
constexpr uint32_t SCREEN_WIDTH=128;
constexpr uint32_t SCREEN_HEIGHT=128;
struct WorldConfig
{
Matrix4f mvp;
}world;
constexpr uint32_t VERTEX_COUNT=4;
constexpr float vertex_data[VERTEX_COUNT][2]=
{
{SCREEN_WIDTH*0.25, SCREEN_HEIGHT*0.25},
{SCREEN_WIDTH*0.75, SCREEN_HEIGHT*0.25},
{SCREEN_WIDTH*0.25, SCREEN_HEIGHT*0.75},
{SCREEN_WIDTH*0.75, SCREEN_HEIGHT*0.75}
{SCREEN_WIDTH*0, SCREEN_HEIGHT*0},
{SCREEN_WIDTH*1, SCREEN_HEIGHT*0},
{SCREEN_WIDTH*0, SCREEN_HEIGHT*1},
{SCREEN_WIDTH*1, SCREEN_HEIGHT*1}
};
constexpr uint32_t INDEX_COUNT=6;
@@ -37,6 +32,8 @@ class TestApp:public VulkanApplicationFramework
{
private:
WorldMatrix wm;
vulkan::Material * material =nullptr;
vulkan::DescriptorSets * descriptor_sets =nullptr;
vulkan::Renderable * render_obj =nullptr;
@@ -65,7 +62,7 @@ private:
bool InitMaterial()
{
material=shader_manage->CreateMaterial(OS_TEXT("res/shader/OnlyPosition.vert.spv"),
OS_TEXT("res/shader/FlatColor.frag.spv"));
OS_TEXT("res/shader/glFragCoord.frag.spv"));
if(!material)
return(false);
@@ -78,9 +75,12 @@ private:
{
const VkExtent2D extent=sc_render_target->GetExtent();
world.mvp=ortho(extent.width,extent.height);
wm.vp_size.x=extent.width;
wm.vp_size.y=extent.height;
ubo_mvp=device->CreateUBO(sizeof(WorldConfig),&world);
wm.ortho=ortho(extent.width,extent.height);
ubo_mvp=device->CreateUBO(sizeof(WorldMatrix),&wm);
if(!ubo_mvp)
return(false);

View File

@@ -14,11 +14,6 @@ bool LoadFromFile(const OSString &filename,VK_NAMESPACE::PipelineCreater *pc);
constexpr uint32_t SCREEN_WIDTH=128;
constexpr uint32_t SCREEN_HEIGHT=128;
struct WorldConfig
{
Matrix4f mvp;
}world;
constexpr uint32_t VERTEX_COUNT=3;
constexpr float vertex_data[VERTEX_COUNT][2]=
@@ -38,6 +33,8 @@ class TestApp:public VulkanApplicationFramework
{
private:
WorldMatrix wm;
vulkan::Material * material =nullptr;
vulkan::DescriptorSets * descriptor_sets =nullptr;
vulkan::Renderable * render_obj =nullptr;
@@ -79,9 +76,12 @@ private:
{
const VkExtent2D extent=sc_render_target->GetExtent();
world.mvp=ortho(extent.width,extent.height);
wm.vp_size.x=extent.width;
wm.vp_size.y=extent.height;
ubo_mvp=device->CreateUBO(sizeof(WorldConfig),&world);
wm.ortho=ortho(extent.width,extent.height);
ubo_mvp=device->CreateUBO(sizeof(WorldMatrix),&wm);
if(!ubo_mvp)
return(false);
@@ -92,7 +92,7 @@ private:
descriptor_sets->Update();
return(true);
}
void InitVBO()
{
vertex_buffer =device->CreateVBO(FMT_RG32F, VERTEX_COUNT,vertex_data);
@@ -150,8 +150,14 @@ public:
return(true);
}
void Resize(int,int)override
void Resize(int w,int h)override
{
wm.vp_size.x=w;
wm.vp_size.y=h;
wm.ortho=ortho(w,h);
ubo_mvp->Write(&wm);
BuildCommandBuffer(pipeline,descriptor_sets,render_obj);
}
};//class TestApp:public VulkanApplicationFramework