将cmd_buf,SceneDB转移到VulkanApplicationFramework中,以减少每个Example中的代码
This commit is contained in:
parent
029d00b28e
commit
a33d76da09
@ -29,9 +29,6 @@ class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
uint swap_chain_count=0;
|
||||
|
||||
SceneDB * db =nullptr;
|
||||
SceneNode render_root;
|
||||
RenderList render_list;
|
||||
|
||||
@ -45,16 +42,6 @@ private:
|
||||
vulkan::Buffer * ubo_mvp =nullptr;
|
||||
|
||||
vulkan::Pipeline * pipeline =nullptr;
|
||||
vulkan::CommandBuffer ** cmd_buf =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(db);
|
||||
|
||||
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -152,27 +139,7 @@ private:
|
||||
|
||||
render_root.ExpendToList(&render_list);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitCommandBuffer()
|
||||
{
|
||||
cmd_buf=hgl_zero_new<vulkan::CommandBuffer *>(swap_chain_count);
|
||||
|
||||
for(uint i=0;i<swap_chain_count;i++)
|
||||
{
|
||||
cmd_buf[i]=device->CreateCommandBuffer();
|
||||
|
||||
if(!cmd_buf[i])
|
||||
return(false);
|
||||
|
||||
cmd_buf[i]->Begin();
|
||||
cmd_buf[i]->BeginRenderPass(device->GetRenderPass(),device->GetFramebuffer(i));
|
||||
render_list.Render(cmd_buf[i]);
|
||||
cmd_buf[i]->EndRenderPass();
|
||||
cmd_buf[i]->End();
|
||||
}
|
||||
|
||||
BuildCommandBuffer(&render_list);
|
||||
return(true);
|
||||
}
|
||||
|
||||
@ -183,10 +150,6 @@ public:
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
swap_chain_count=device->GetSwapChainImageCount();
|
||||
|
||||
db=new SceneDB(device);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
@ -201,20 +164,8 @@ public:
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
if(!InitCommandBuffer())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Draw() override
|
||||
{
|
||||
const uint32_t frame_index=device->GetCurrentFrameIndices();
|
||||
|
||||
const vulkan::CommandBuffer *cb=cmd_buf[frame_index];
|
||||
|
||||
Submit(*cb);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
|
@ -10,16 +10,13 @@
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=256;
|
||||
constexpr uint32_t SCREEN_HEIGHT=256;
|
||||
constexpr uint32_t SCREEN_WIDTH=128;
|
||||
constexpr uint32_t SCREEN_HEIGHT=128;
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
uint swap_chain_count=0;
|
||||
|
||||
SceneDB * db =nullptr;
|
||||
SceneNode render_root;
|
||||
RenderList render_list;
|
||||
|
||||
@ -33,16 +30,6 @@ private:
|
||||
vulkan::Buffer * ubo_world_matrix =nullptr;
|
||||
|
||||
vulkan::Pipeline * pipeline_line =nullptr;
|
||||
vulkan::CommandBuffer ** cmd_buf =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(db);
|
||||
|
||||
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -73,34 +60,32 @@ private:
|
||||
|
||||
void CreateRenderObject()
|
||||
{
|
||||
{
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
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.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.step.u=20;
|
||||
pgci.step.v=20;
|
||||
|
||||
pgci.side_step.u=10;
|
||||
pgci.side_step.v=10;
|
||||
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);
|
||||
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]=CreatePlaneGrid(db,material,&pgci);
|
||||
|
||||
pgci.color.Set(0,0.75,0,1);
|
||||
pgci.side_color.Set(0,1,0,1);
|
||||
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]=CreatePlaneGrid(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);
|
||||
}
|
||||
pgci.color.Set(0,0,0.75,1);
|
||||
pgci.side_color.Set(0,0,1,1);
|
||||
ro_plane_grid[2]=CreatePlaneGrid(db,material,&pgci);
|
||||
}
|
||||
|
||||
bool InitUBO()
|
||||
@ -153,26 +138,7 @@ private:
|
||||
render_root.RefreshMatrix();
|
||||
render_root.ExpendToList(&render_list);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitCommandBuffer()
|
||||
{
|
||||
cmd_buf=hgl_zero_new<vulkan::CommandBuffer *>(swap_chain_count);
|
||||
|
||||
for(uint i=0;i<swap_chain_count;i++)
|
||||
{
|
||||
cmd_buf[i]=device->CreateCommandBuffer();
|
||||
|
||||
if(!cmd_buf[i])
|
||||
return(false);
|
||||
|
||||
cmd_buf[i]->Begin();
|
||||
cmd_buf[i]->BeginRenderPass(device->GetRenderPass(),device->GetFramebuffer(i));
|
||||
render_list.Render(cmd_buf[i]);
|
||||
cmd_buf[i]->EndRenderPass();
|
||||
cmd_buf[i]->End();
|
||||
}
|
||||
BuildCommandBuffer(&render_list);
|
||||
|
||||
return(true);
|
||||
}
|
||||
@ -184,10 +150,6 @@ public:
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
swap_chain_count=device->GetSwapChainImageCount();
|
||||
|
||||
db=new SceneDB(device);
|
||||
|
||||
InitCamera();
|
||||
|
||||
if(!InitMaterial())
|
||||
@ -204,20 +166,8 @@ public:
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
if(!InitCommandBuffer())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Draw() override
|
||||
{
|
||||
const uint32_t frame_index=device->GetCurrentFrameIndices();
|
||||
|
||||
const vulkan::CommandBuffer *cb=cmd_buf[frame_index];
|
||||
|
||||
Submit(*cb);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
|
@ -4,9 +4,7 @@
|
||||
#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>
|
||||
|
||||
#include"AssimpLoaderMesh.h"
|
||||
#include<hgl/graph/VertexBuffer.h>
|
||||
@ -74,6 +72,7 @@ vulkan::Renderable *CreateMeshRenderable(SceneDB *db,vulkan::Material *mtl,const
|
||||
else
|
||||
render_obj->Set(db->CreateIBO32(mesh->indices32.GetCount(),mesh->indices32.GetData()));
|
||||
|
||||
db->Add(render_obj);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
@ -81,9 +80,6 @@ class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
uint swap_chain_count=0;
|
||||
|
||||
SceneDB * db =nullptr;
|
||||
SceneNode render_root;
|
||||
RenderList render_list;
|
||||
|
||||
@ -95,21 +91,20 @@ private:
|
||||
vulkan::Buffer * ubo_world_matrix =nullptr;
|
||||
|
||||
vulkan::Pipeline * pipeline_line =nullptr;
|
||||
vulkan::CommandBuffer ** cmd_buf =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
ModelData *model_data;
|
||||
|
||||
vulkan::Renderable **mesh_renderable;
|
||||
RenderableInstance **mesh_renderable_instance;
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(db);
|
||||
|
||||
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
|
||||
delete[] mesh_renderable_instance;
|
||||
delete[] mesh_renderable;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -151,11 +146,13 @@ private:
|
||||
const uint count=model_data->mesh_data.GetCount();
|
||||
MeshData **md=model_data->mesh_data.GetData();
|
||||
|
||||
mesh_renderable=new vulkan::Renderable *[count];
|
||||
mesh_renderable =new vulkan::Renderable *[count];
|
||||
mesh_renderable_instance=new RenderableInstance *[count];
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
{
|
||||
mesh_renderable[i]=CreateMeshRenderable(db,material,*md);
|
||||
mesh_renderable_instance[i]=db->CreateRenderableInstance(pipeline_line,descriptor_sets,mesh_renderable[i]);
|
||||
++md;
|
||||
}
|
||||
}
|
||||
@ -200,7 +197,7 @@ private:
|
||||
return pipeline_line;
|
||||
}
|
||||
|
||||
void CreateRenderableInstance(SceneNode *scene_node,ModelSceneNode *model_node)
|
||||
void CreateSceneNode(SceneNode *scene_node,ModelSceneNode *model_node)
|
||||
{
|
||||
scene_node->SetLocalMatrix(model_node->local_matrix);
|
||||
|
||||
@ -210,7 +207,7 @@ private:
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
{
|
||||
scene_node->Add(db->CreateRenderableInstance(pipeline_line,descriptor_sets,mesh_renderable[*mesh_index]));
|
||||
scene_node->Add(mesh_renderable_instance[*mesh_index]);
|
||||
|
||||
++mesh_index;
|
||||
}
|
||||
@ -222,7 +219,7 @@ private:
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
{
|
||||
CreateRenderableInstance(scene_node->CreateSubNode(),*sub_model_node);
|
||||
CreateSceneNode(scene_node->CreateSubNode(),*sub_model_node);
|
||||
|
||||
++sub_model_node;
|
||||
}
|
||||
@ -231,32 +228,12 @@ private:
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
CreateRenderableInstance(&render_root,model_data->root_node);
|
||||
CreateSceneNode(&render_root,model_data->root_node);
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_root.ExpendToList(&render_list);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitCommandBuffer()
|
||||
{
|
||||
cmd_buf=hgl_zero_new<vulkan::CommandBuffer *>(swap_chain_count);
|
||||
|
||||
for(uint i=0;i<swap_chain_count;i++)
|
||||
{
|
||||
cmd_buf[i]=device->CreateCommandBuffer();
|
||||
|
||||
if(!cmd_buf[i])
|
||||
return(false);
|
||||
|
||||
cmd_buf[i]->Begin();
|
||||
cmd_buf[i]->BeginRenderPass(device->GetRenderPass(),device->GetFramebuffer(i));
|
||||
render_list.Render(cmd_buf[i]);
|
||||
cmd_buf[i]->EndRenderPass();
|
||||
cmd_buf[i]->End();
|
||||
}
|
||||
|
||||
BuildCommandBuffer(&render_list);
|
||||
return(true);
|
||||
}
|
||||
|
||||
@ -272,15 +249,9 @@ public:
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
swap_chain_count=device->GetSwapChainImageCount();
|
||||
|
||||
db=new SceneDB(device);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
CreateRenderObject();
|
||||
|
||||
InitCamera();
|
||||
|
||||
if(!InitUBO())
|
||||
@ -289,23 +260,13 @@ public:
|
||||
if(!InitPipeline())
|
||||
return(false);
|
||||
|
||||
CreateRenderObject();
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
if(!InitCommandBuffer())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Draw() override
|
||||
{
|
||||
const uint32_t frame_index=device->GetCurrentFrameIndices();
|
||||
|
||||
const vulkan::CommandBuffer *cb=cmd_buf[frame_index];
|
||||
|
||||
Submit(*cb);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -12,18 +12,15 @@
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=256;
|
||||
constexpr uint32_t SCREEN_HEIGHT=256;
|
||||
constexpr uint32_t SCREEN_WIDTH=128;
|
||||
constexpr uint32_t SCREEN_HEIGHT=128;
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
double start_time;
|
||||
double start_time;
|
||||
|
||||
uint swap_chain_count=0;
|
||||
|
||||
SceneDB * db =nullptr;
|
||||
SceneNode render_root;
|
||||
RenderList render_list;
|
||||
|
||||
@ -37,7 +34,6 @@ private:
|
||||
vulkan::Buffer * ubo_world_matrix =nullptr;
|
||||
|
||||
vulkan::Pipeline * pipeline_line =nullptr;
|
||||
vulkan::CommandBuffer ** cmd_buf =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
@ -46,12 +42,7 @@ public:
|
||||
start_time=GetDoubleTime();
|
||||
}
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(db);
|
||||
|
||||
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
|
||||
}
|
||||
~TestApp()=default;
|
||||
|
||||
private:
|
||||
|
||||
@ -150,32 +141,14 @@ private:
|
||||
cur_node->Add(ri,translate(0,0,size*n*1.01));
|
||||
}
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list.Clear();
|
||||
render_root.ExpendToList(&render_list);
|
||||
|
||||
BuildCommandBuffer(&render_list);
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitCommandBuffer()
|
||||
{
|
||||
cmd_buf=hgl_zero_new<vulkan::CommandBuffer *>(swap_chain_count);
|
||||
|
||||
for(uint i=0;i<swap_chain_count;i++)
|
||||
cmd_buf[i]=device->CreateCommandBuffer();
|
||||
|
||||
return BuildCommandBuffer();
|
||||
}
|
||||
|
||||
bool BuildCommandBuffer()
|
||||
{
|
||||
for(uint i=0;i<swap_chain_count;i++)
|
||||
{
|
||||
cmd_buf[i]->Begin();
|
||||
cmd_buf[i]->BeginRenderPass(device->GetRenderPass(),device->GetFramebuffer(i));
|
||||
render_list.Render(cmd_buf[i]);
|
||||
cmd_buf[i]->EndRenderPass();
|
||||
cmd_buf[i]->End();
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
@ -184,10 +157,6 @@ public:
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
swap_chain_count=device->GetSwapChainImageCount();
|
||||
|
||||
db=new SceneDB(device);
|
||||
|
||||
InitCamera();
|
||||
|
||||
if(!InitMaterial())
|
||||
@ -204,17 +173,12 @@ public:
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
if(!InitCommandBuffer())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Draw() override
|
||||
{
|
||||
vulkan::CommandBuffer *cb=cmd_buf[device->GetCurrentFrameIndices()];
|
||||
|
||||
Submit(*cb);
|
||||
VulkanApplicationFramework::Draw();
|
||||
|
||||
Matrix4f rot=rotate(GetDoubleTime()-start_time,camera.up_vector);
|
||||
|
||||
@ -222,7 +186,7 @@ public:
|
||||
render_list.Clear();
|
||||
render_root.ExpendToList(&render_list);
|
||||
|
||||
BuildCommandBuffer();
|
||||
BuildCommandBuffer(&render_list);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
#include<hgl/graph/vulkan/VKFormat.h>
|
||||
#include<hgl/graph/vulkan/VKFramebuffer.h>
|
||||
#include<hgl/graph/vulkan/VKMaterial.h>
|
||||
#include<hgl/graph/SceneDB.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@ -31,10 +33,23 @@ protected:
|
||||
vulkan::Device * device =nullptr;
|
||||
vulkan::ShaderModuleManage *shader_manage =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
uint32_t swap_chain_count=0;
|
||||
|
||||
vulkan::CommandBuffer ** cmd_buf =nullptr;
|
||||
|
||||
protected:
|
||||
|
||||
SceneDB * db =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
virtual ~VulkanApplicationFramework()
|
||||
{
|
||||
SAFE_CLEAR(db);
|
||||
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
|
||||
|
||||
SAFE_CLEAR(shader_manage);
|
||||
SAFE_CLEAR(win); //win中会删除device,所以必须放在instance前删除
|
||||
SAFE_CLEAR(inst);
|
||||
@ -67,9 +82,61 @@ public:
|
||||
return(false);
|
||||
|
||||
shader_manage=device->CreateShaderModuleManage();
|
||||
|
||||
swap_chain_count = device->GetSwapChainImageCount();
|
||||
{
|
||||
cmd_buf = hgl_zero_new<vulkan::CommandBuffer *>(swap_chain_count);
|
||||
|
||||
for (uint i=0;i<swap_chain_count;i++)
|
||||
cmd_buf[i]=device->CreateCommandBuffer();
|
||||
}
|
||||
|
||||
db=new SceneDB(device);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(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);
|
||||
|
||||
if (ib)
|
||||
cmd_buf[i]->DrawIndexed(ib->GetCount());
|
||||
else
|
||||
cmd_buf[i]->Draw(r->GetDrawCount());
|
||||
|
||||
cmd_buf[i]->EndRenderPass();
|
||||
cmd_buf[i]->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();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void AcquireNextFrame()
|
||||
{
|
||||
device->AcquireNextImage();
|
||||
@ -82,7 +149,14 @@ public:
|
||||
device->QueuePresent();
|
||||
}
|
||||
|
||||
virtual void Draw()=0;
|
||||
public:
|
||||
|
||||
virtual void Draw()
|
||||
{
|
||||
const vulkan::CommandBuffer *cb=cmd_buf[device->GetCurrentFrameIndices()];
|
||||
|
||||
Submit(*cb);
|
||||
}
|
||||
|
||||
bool Run()
|
||||
{
|
||||
|
@ -37,15 +37,12 @@ class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
uint swap_chain_count=0;
|
||||
|
||||
vulkan::Material * material =nullptr;
|
||||
vulkan::DescriptorSets * descriptor_sets =nullptr;
|
||||
vulkan::Renderable * render_obj =nullptr;
|
||||
vulkan::Buffer * ubo_mvp =nullptr;
|
||||
|
||||
vulkan::Pipeline * pipeline =nullptr;
|
||||
vulkan::CommandBuffer ** cmd_buf =nullptr;
|
||||
|
||||
vulkan::VertexBuffer * vertex_buffer =nullptr;
|
||||
vulkan::IndexBuffer * index_buffer =nullptr;
|
||||
@ -56,7 +53,6 @@ public:
|
||||
{
|
||||
SAFE_CLEAR(index_buffer);
|
||||
SAFE_CLEAR(vertex_buffer);
|
||||
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
|
||||
SAFE_CLEAR(pipeline);
|
||||
SAFE_CLEAR(ubo_mvp);
|
||||
SAFE_CLEAR(render_obj);
|
||||
@ -122,30 +118,6 @@ private:
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitCommandBuffer()
|
||||
{
|
||||
cmd_buf=hgl_zero_new<vulkan::CommandBuffer *>(swap_chain_count);
|
||||
|
||||
for(uint i=0;i<swap_chain_count;i++)
|
||||
{
|
||||
cmd_buf[i]=device->CreateCommandBuffer();
|
||||
|
||||
if(!cmd_buf[i])
|
||||
return(false);
|
||||
|
||||
cmd_buf[i]->Begin();
|
||||
cmd_buf[i]->BeginRenderPass(device->GetRenderPass(),device->GetFramebuffer(i));
|
||||
cmd_buf[i]->Bind(pipeline);
|
||||
cmd_buf[i]->Bind(descriptor_sets);
|
||||
cmd_buf[i]->Bind(render_obj);
|
||||
cmd_buf[i]->DrawIndexed(INDEX_COUNT);
|
||||
cmd_buf[i]->EndRenderPass();
|
||||
cmd_buf[i]->End();
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
@ -153,8 +125,6 @@ public:
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
swap_chain_count=device->GetSwapChainImageCount();
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
@ -166,20 +136,10 @@ public:
|
||||
if(!InitPipeline())
|
||||
return(false);
|
||||
|
||||
if(!InitCommandBuffer())
|
||||
return(false);
|
||||
BuildCommandBuffer(pipeline,descriptor_sets,render_obj);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Draw() override
|
||||
{
|
||||
const uint32_t frame_index=device->GetCurrentFrameIndices();
|
||||
|
||||
const vulkan::CommandBuffer *cb=cmd_buf[frame_index];
|
||||
|
||||
Submit(*cb);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
|
@ -38,15 +38,12 @@ class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
uint swap_chain_count=0;
|
||||
|
||||
vulkan::Material * material =nullptr;
|
||||
vulkan::DescriptorSets * descriptor_sets =nullptr;
|
||||
vulkan::Renderable * render_obj =nullptr;
|
||||
vulkan::Buffer * ubo_mvp =nullptr;
|
||||
|
||||
vulkan::Pipeline * pipeline =nullptr;
|
||||
vulkan::CommandBuffer ** cmd_buf =nullptr;
|
||||
|
||||
vulkan::VertexBuffer * vertex_buffer =nullptr;
|
||||
vulkan::VertexBuffer * color_buffer =nullptr;
|
||||
@ -57,7 +54,6 @@ public:
|
||||
{
|
||||
SAFE_CLEAR(color_buffer);
|
||||
SAFE_CLEAR(vertex_buffer);
|
||||
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
|
||||
SAFE_CLEAR(pipeline);
|
||||
SAFE_CLEAR(ubo_mvp);
|
||||
SAFE_CLEAR(render_obj);
|
||||
@ -136,30 +132,6 @@ private:
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitCommandBuffer()
|
||||
{
|
||||
cmd_buf=hgl_zero_new<vulkan::CommandBuffer *>(swap_chain_count);
|
||||
|
||||
for(uint i=0;i<swap_chain_count;i++)
|
||||
{
|
||||
cmd_buf[i]=device->CreateCommandBuffer();
|
||||
|
||||
if(!cmd_buf[i])
|
||||
return(false);
|
||||
|
||||
cmd_buf[i]->Begin();
|
||||
cmd_buf[i]->BeginRenderPass(device->GetRenderPass(),device->GetFramebuffer(i));
|
||||
cmd_buf[i]->Bind(pipeline);
|
||||
cmd_buf[i]->Bind(descriptor_sets);
|
||||
cmd_buf[i]->Bind(render_obj);
|
||||
cmd_buf[i]->Draw(VERTEX_COUNT);
|
||||
cmd_buf[i]->EndRenderPass();
|
||||
cmd_buf[i]->End();
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
@ -167,8 +139,6 @@ public:
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
swap_chain_count=device->GetSwapChainImageCount();
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
@ -180,20 +150,10 @@ public:
|
||||
if(!InitPipeline())
|
||||
return(false);
|
||||
|
||||
if(!InitCommandBuffer())
|
||||
return(false);
|
||||
BuildCommandBuffer(pipeline,descriptor_sets,render_obj);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Draw() override
|
||||
{
|
||||
const uint32_t frame_index=device->GetCurrentFrameIndices();
|
||||
|
||||
const vulkan::CommandBuffer *cb=cmd_buf[frame_index];
|
||||
|
||||
Submit(*cb);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
|
@ -51,17 +51,14 @@ class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
uint swap_chain_count=0;
|
||||
|
||||
vulkan::Material * material =nullptr;
|
||||
vulkan::Texture2D * texture =nullptr;
|
||||
vulkan::Sampler * sampler =nullptr;
|
||||
vulkan::DescriptorSets * desciptor_sets =nullptr;
|
||||
vulkan::DescriptorSets * descriptor_sets =nullptr;
|
||||
vulkan::Renderable * render_obj =nullptr;
|
||||
vulkan::Buffer * ubo_mvp =nullptr;
|
||||
|
||||
vulkan::Pipeline * pipeline =nullptr;
|
||||
vulkan::CommandBuffer ** cmd_buf =nullptr;
|
||||
|
||||
vulkan::VertexBuffer * vertex_buffer =nullptr;
|
||||
vulkan::VertexBuffer * tex_coord_buffer =nullptr;
|
||||
@ -74,11 +71,10 @@ public:
|
||||
SAFE_CLEAR(index_buffer);
|
||||
SAFE_CLEAR(tex_coord_buffer);
|
||||
SAFE_CLEAR(vertex_buffer);
|
||||
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
|
||||
SAFE_CLEAR(pipeline);
|
||||
SAFE_CLEAR(ubo_mvp);
|
||||
SAFE_CLEAR(render_obj);
|
||||
SAFE_CLEAR(desciptor_sets);
|
||||
SAFE_CLEAR(descriptor_sets);
|
||||
SAFE_CLEAR(sampler);
|
||||
SAFE_CLEAR(texture);
|
||||
SAFE_CLEAR(material);
|
||||
@ -94,7 +90,7 @@ private:
|
||||
return(false);
|
||||
|
||||
render_obj=material->CreateRenderable(VERTEX_COUNT);
|
||||
desciptor_sets=material->CreateDescriptorSets();
|
||||
descriptor_sets=material->CreateDescriptorSets();
|
||||
|
||||
texture=vulkan::LoadTGATexture(OS_TEXT("lena.tga"),device);
|
||||
|
||||
@ -113,9 +109,9 @@ private:
|
||||
|
||||
sampler=device->CreateSampler(&sampler_create_info);
|
||||
|
||||
desciptor_sets->BindSampler(material->GetSampler("texture_lena"),texture,sampler);
|
||||
desciptor_sets->BindUBO(material->GetUBO("world"),*ubo_mvp);
|
||||
desciptor_sets->Update();
|
||||
descriptor_sets->BindSampler(material->GetSampler("texture_lena"),texture,sampler);
|
||||
descriptor_sets->BindUBO(material->GetUBO("world"),*ubo_mvp);
|
||||
descriptor_sets->Update();
|
||||
|
||||
return(true);
|
||||
}
|
||||
@ -159,30 +155,6 @@ private:
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitCommandBuffer()
|
||||
{
|
||||
cmd_buf=hgl_zero_new<vulkan::CommandBuffer *>(swap_chain_count);
|
||||
|
||||
for(uint i=0;i<swap_chain_count;i++)
|
||||
{
|
||||
cmd_buf[i]=device->CreateCommandBuffer();
|
||||
|
||||
if(!cmd_buf[i])
|
||||
return(false);
|
||||
|
||||
cmd_buf[i]->Begin();
|
||||
cmd_buf[i]->BeginRenderPass(device->GetRenderPass(),device->GetFramebuffer(i));
|
||||
cmd_buf[i]->Bind(pipeline);
|
||||
cmd_buf[i]->Bind(desciptor_sets);
|
||||
cmd_buf[i]->Bind(render_obj);
|
||||
cmd_buf[i]->DrawIndexed(INDEX_COUNT);
|
||||
cmd_buf[i]->EndRenderPass();
|
||||
cmd_buf[i]->End();
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
@ -190,8 +162,6 @@ public:
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
swap_chain_count=device->GetSwapChainImageCount();
|
||||
|
||||
if(!InitUBO())
|
||||
return(false);
|
||||
|
||||
@ -203,20 +173,10 @@ public:
|
||||
if(!InitPipeline())
|
||||
return(false);
|
||||
|
||||
if(!InitCommandBuffer())
|
||||
return(false);
|
||||
BuildCommandBuffer(pipeline,descriptor_sets,render_obj);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Draw() override
|
||||
{
|
||||
const uint32_t frame_index=device->GetCurrentFrameIndices();
|
||||
|
||||
const vulkan::CommandBuffer *cb=cmd_buf[frame_index];
|
||||
|
||||
Submit(*cb);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
|
@ -369,6 +369,7 @@ namespace hgl
|
||||
}
|
||||
|
||||
render_obj->Set(db->CreateIBO16(6*2*3,indices));
|
||||
db->Add(render_obj);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
@ -399,6 +400,7 @@ namespace hgl
|
||||
delete vertex;
|
||||
}
|
||||
|
||||
db->Add(render_obj);
|
||||
return render_obj;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user