新的Vulkan Framework
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
macro(CreateProject name)
|
||||
add_executable(${name} ${ARGN})
|
||||
add_executable(${name} ${ARGN} VulkanAppFramework.h)
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
endmacro()
|
||||
|
||||
@@ -10,7 +10,7 @@ CreateProject(3.Geometry2D Geometry2D.cpp)
|
||||
CreateProject(4.Geometry3D Geometry3D.cpp)
|
||||
CreateProject(5.SceneTree SceneTree.cpp)
|
||||
|
||||
CreateProject(6.LoadModel LoadModel.cpp TGATexture.cpp AssimpLoaderMesh.h AssimpLoaderMesh.cpp)
|
||||
CreateProject(6.LoadModel LoadModel.cpp TGATexture.cpp AssimpLoaderMesh.h AssimpLoaderMesh.cpp ViewModelFramework.h)
|
||||
target_link_libraries(6.LoadModel assimp)
|
||||
|
||||
CreateProject(7.InlineGeometryScene InlineGeometryScene.cpp)
|
@@ -66,7 +66,7 @@ private:
|
||||
|
||||
rci.scope.Set(10,10,20,20);
|
||||
|
||||
ro_rectangle=CreateRectangle(db,material,&rci);
|
||||
ro_rectangle=CreateRenderableRectangle(db,material,&rci);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -76,7 +76,7 @@ private:
|
||||
rrci.radius=5;
|
||||
rrci.round_per=5;
|
||||
|
||||
ro_round_rectangle=CreateRoundRectangle(db,material,&rrci);
|
||||
ro_round_rectangle=CreateRenderableRoundRectangle(db,material,&rrci);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -90,7 +90,7 @@ private:
|
||||
|
||||
cci.field_count=8;
|
||||
|
||||
ro_circle=CreateCircle(db,material,&cci);
|
||||
ro_circle=CreateRenderableCircle(db,material,&cci);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +138,6 @@ private:
|
||||
render_root.Add(db->CreateRenderableInstance(pipeline,descriptor_sets,ro_circle));
|
||||
|
||||
render_root.ExpendToList(&render_list);
|
||||
|
||||
BuildCommandBuffer(&render_list);
|
||||
return(true);
|
||||
}
|
||||
@@ -167,10 +166,16 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int,int)override
|
||||
void Resize(int w,int h)
|
||||
{
|
||||
BuildCommandBuffer(&render_list);
|
||||
}
|
||||
|
||||
void Draw()
|
||||
{
|
||||
AcquireNextImage();
|
||||
VulkanApplicationFramework::Draw();
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
|
@@ -61,16 +61,16 @@ private:
|
||||
pgci.color.Set(0.75,0,0,1);
|
||||
pgci.side_color.Set(1,0,0,1);
|
||||
|
||||
ro_plane_grid[0]=CreatePlaneGrid(db,material,&pgci);
|
||||
ro_plane_grid[0]=CreateRenderablePlaneGrid(db,material,&pgci);
|
||||
|
||||
pgci.color.Set(0,0.75,0,1);
|
||||
pgci.side_color.Set(0,1,0,1);
|
||||
|
||||
ro_plane_grid[1]=CreatePlaneGrid(db,material,&pgci);
|
||||
ro_plane_grid[1]=CreateRenderablePlaneGrid(db,material,&pgci);
|
||||
|
||||
pgci.color.Set(0,0,0.75,1);
|
||||
pgci.side_color.Set(0,0,1,1);
|
||||
ro_plane_grid[2]=CreatePlaneGrid(db,material,&pgci);
|
||||
ro_plane_grid[2]=CreateRenderablePlaneGrid(db,material,&pgci);
|
||||
}
|
||||
|
||||
bool InitUBO()
|
||||
@@ -114,7 +114,6 @@ private:
|
||||
render_root.RefreshMatrix();
|
||||
render_root.ExpendToList(&render_list);
|
||||
|
||||
BuildCommandBuffer(&render_list);
|
||||
return(true);
|
||||
}
|
||||
|
||||
@@ -142,9 +141,9 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int,int)override
|
||||
void BuildCommandBuffer(uint32 index)
|
||||
{
|
||||
BuildCommandBuffer(&render_list);
|
||||
VulkanApplicationFramework::BuildCommandBuffer(index,&render_list);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
|
@@ -178,7 +178,6 @@ private:
|
||||
render_root.RefreshMatrix();
|
||||
render_root.ExpendToList(&render_list);
|
||||
|
||||
BuildCommandBuffer(&render_list);
|
||||
return(true);
|
||||
}
|
||||
|
||||
@@ -205,10 +204,14 @@ public:
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int,int)override
|
||||
|
||||
void BuildCommandBuffer(uint32_t index) override
|
||||
{
|
||||
BuildCommandBuffer(&render_list);
|
||||
render_root.RefreshMatrix();
|
||||
render_list.Clear();
|
||||
render_root.ExpendToList(&render_list);
|
||||
|
||||
VulkanApplicationFramework::BuildCommandBuffer(index,&render_list);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
|
@@ -58,10 +58,9 @@ private:
|
||||
|
||||
void CreateRenderObject()
|
||||
{
|
||||
//struct CubeCreateInfo cci;
|
||||
struct CubeCreateInfo cci;
|
||||
|
||||
//renderable_object=CreateCube(db,material,&cci);
|
||||
renderable_object=CreateRenderableSphere(db,material,16);
|
||||
renderable_object=CreateRenderableCube(db,material,&cci);
|
||||
}
|
||||
|
||||
bool InitUBO()
|
||||
@@ -121,8 +120,6 @@ private:
|
||||
render_root.RefreshMatrix();
|
||||
render_list.Clear();
|
||||
render_root.ExpendToList(&render_list);
|
||||
|
||||
BuildCommandBuffer(&render_list);
|
||||
return(true);
|
||||
}
|
||||
|
||||
@@ -159,15 +156,11 @@ public:
|
||||
render_root.RefreshMatrix(&rot);
|
||||
render_list.Clear();
|
||||
render_root.ExpendToList(&render_list);
|
||||
|
||||
BuildCommandBuffer(&render_list);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
|
||||
void BuildCommandBuffer(uint32 index)
|
||||
{
|
||||
CameraAppFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(&render_list);
|
||||
VulkanApplicationFramework::BuildCommandBuffer(index,&render_list);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
|
@@ -82,6 +82,8 @@ public:
|
||||
|
||||
virtual void Draw()override
|
||||
{
|
||||
const uint32_t index=AcquireNextImage();
|
||||
|
||||
camera.Refresh(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
ubo_world_matrix->Write(&camera.matrix); //д<>뻺<EFBFBD><EBBBBA><EFBFBD><EFBFBD>
|
||||
|
||||
@@ -89,9 +91,9 @@ public:
|
||||
render_list.Clear();
|
||||
render_root.ExpendToList(&render_list);
|
||||
|
||||
BuildCommandBuffer(&render_list);
|
||||
BuildCommandBuffer(index,&render_list);
|
||||
|
||||
VulkanApplicationFramework::Draw();
|
||||
SubmitDraw(index);
|
||||
|
||||
if(key_status[kbW])camera.Forward (move_speed);else
|
||||
if(key_status[kbS])camera.Backward (move_speed);else
|
||||
|
@@ -149,60 +149,91 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(vulkan::Pipeline *p,vulkan::DescriptorSets *ds,vulkan::Renderable *r)
|
||||
void BuildCommandBuffer(uint32_t index,vulkan::Pipeline *p,vulkan::DescriptorSets *ds,vulkan::Renderable *r)
|
||||
{
|
||||
if(!p||!ds||!r)
|
||||
return;
|
||||
|
||||
const vulkan::IndexBuffer *ib=r->GetIndexBuffer();
|
||||
|
||||
for(uint i=0;i<swap_chain_count;i++)
|
||||
{
|
||||
cmd_buf[i]->Begin();
|
||||
cmd_buf[i]->BeginRenderPass(device->GetRenderPass(),device->GetFramebuffer(i));
|
||||
cmd_buf[i]->Bind(p);
|
||||
cmd_buf[i]->Bind(ds);
|
||||
cmd_buf[i]->Bind(r);
|
||||
vulkan::CommandBuffer *cb=cmd_buf[index];
|
||||
|
||||
cb->Begin();
|
||||
cb->BeginRenderPass(device->GetRenderPass(),device->GetFramebuffer(index));
|
||||
cb->Bind(p);
|
||||
cb->Bind(ds);
|
||||
cb->Bind(r);
|
||||
|
||||
if (ib)
|
||||
cmd_buf[i]->DrawIndexed(ib->GetCount());
|
||||
else
|
||||
cmd_buf[i]->Draw(r->GetDrawCount());
|
||||
if (ib)
|
||||
cb->DrawIndexed(ib->GetCount());
|
||||
else
|
||||
cb->Draw(r->GetDrawCount());
|
||||
|
||||
cmd_buf[i]->EndRenderPass();
|
||||
cmd_buf[i]->End();
|
||||
}
|
||||
cb->EndRenderPass();
|
||||
cb->End();
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(vulkan::Pipeline *p,vulkan::DescriptorSets *ds,vulkan::Renderable *r)
|
||||
{
|
||||
for(uint32_t i=0;i<swap_chain_count;i++)
|
||||
BuildCommandBuffer(i,p,ds,r);
|
||||
}
|
||||
|
||||
void BuildCurrentCommandBuffer(vulkan::Pipeline *p,vulkan::DescriptorSets *ds,vulkan::Renderable *r)
|
||||
{
|
||||
BuildCommandBuffer(device->GetCurrentFrameIndices(),p,ds,r);
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(uint32_t index,RenderList *rl)
|
||||
{
|
||||
if(!rl)return;
|
||||
|
||||
vulkan::CommandBuffer *cb=cmd_buf[index];
|
||||
|
||||
cb->Begin();
|
||||
cb->BeginRenderPass(device->GetRenderPass(),device->GetFramebuffer(index));
|
||||
rl->Render(cb);
|
||||
cb->EndRenderPass();
|
||||
cb->End();
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(RenderList *rl)
|
||||
{
|
||||
if(!rl)return;
|
||||
|
||||
for(uint i=0;i<swap_chain_count;i++)
|
||||
{
|
||||
cmd_buf[i]->Begin();
|
||||
cmd_buf[i]->BeginRenderPass(device->GetRenderPass(),device->GetFramebuffer(i));
|
||||
rl->Render(cmd_buf[i]);
|
||||
cmd_buf[i]->EndRenderPass();
|
||||
cmd_buf[i]->End();
|
||||
}
|
||||
for(uint32_t i=0;i<swap_chain_count;i++)
|
||||
BuildCommandBuffer(i,rl);
|
||||
}
|
||||
|
||||
void BuildCurrentCommandBuffer(RenderList *rl)
|
||||
{
|
||||
BuildCommandBuffer(device->GetCurrentFrameIndices(),rl);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
virtual void Draw()
|
||||
int AcquireNextImage()
|
||||
{
|
||||
device->Wait();
|
||||
device->AcquireNextImage();
|
||||
if(device->Wait())
|
||||
if(device->AcquireNextImage())
|
||||
return device->GetCurrentFrameIndices();
|
||||
|
||||
uint32_t index=device->GetCurrentFrameIndices();
|
||||
return -1;
|
||||
}
|
||||
|
||||
void SubmitDraw(int index)
|
||||
{
|
||||
VkCommandBuffer cb=*cmd_buf[index];
|
||||
|
||||
device->SubmitDraw(&cb);
|
||||
device->QueuePresent();
|
||||
}
|
||||
|
||||
virtual void Draw()
|
||||
{
|
||||
int index=AcquireNextImage();
|
||||
|
||||
SubmitDraw(index);
|
||||
}
|
||||
|
||||
bool Run()
|
||||
{
|
||||
if(!win->Update())return(false);
|
||||
@@ -267,12 +298,18 @@ public:
|
||||
return desc_set->BindUBO(world_matrix_bindpoint,*ubo_world_matrix);
|
||||
}
|
||||
|
||||
virtual void BuildCommandBuffer(uint32_t index)=0;
|
||||
|
||||
virtual void Draw()override
|
||||
{
|
||||
const uint32_t index=AcquireNextImage();
|
||||
|
||||
camera.Refresh(); //更新相机矩阵
|
||||
ubo_world_matrix->Write(&camera.matrix); //写入缓冲区
|
||||
|
||||
VulkanApplicationFramework::Draw();
|
||||
BuildCommandBuffer(index);
|
||||
|
||||
SubmitDraw(index);
|
||||
|
||||
if(key_status[kbW])camera.Forward (move_speed);else
|
||||
if(key_status[kbS])camera.Backward (move_speed);else
|
||||
|
Reference in New Issue
Block a user