From 57a5dede7af1dbf1fa8abcc79e41ff0cae90592c Mon Sep 17 00:00:00 2001 From: hyzboy Date: Mon, 17 Jun 2019 12:17:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0INLINE=E5=87=A0=E4=BD=95?= =?UTF-8?q?=E4=BD=93=E6=B5=8B=E8=AF=95=E5=9C=BA=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/Vulkan/CMakeLists.txt | 2 + example/Vulkan/Geometry3D.cpp | 3 - example/Vulkan/InlineGeometryScene.cpp | 169 +++++++++++++++++++++++++ 3 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 example/Vulkan/InlineGeometryScene.cpp diff --git a/example/Vulkan/CMakeLists.txt b/example/Vulkan/CMakeLists.txt index 245f0a80..2b7074d9 100644 --- a/example/Vulkan/CMakeLists.txt +++ b/example/Vulkan/CMakeLists.txt @@ -12,3 +12,5 @@ CreateProject(5.SceneTree SceneTree.cpp) CreateProject(6.LoadModel LoadModel.cpp TGATexture.cpp AssimpLoaderMesh.h AssimpLoaderMesh.cpp) target_link_libraries(6.LoadModel assimp) + +CreateProject(7.InlineGeometryScene InlineGeometryScene.cpp) \ No newline at end of file diff --git a/example/Vulkan/Geometry3D.cpp b/example/Vulkan/Geometry3D.cpp index c9d88cc4..f409433a 100644 --- a/example/Vulkan/Geometry3D.cpp +++ b/example/Vulkan/Geometry3D.cpp @@ -84,8 +84,6 @@ private: bool InitPipeline() { - constexpr os_char PIPELINE_FILENAME[]=OS_TEXT("2DSolid.pipeline"); - { vulkan::PipelineCreater *pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetRenderPass(),device->GetExtent()); pipeline_creater->SetDepthTest(true); @@ -117,7 +115,6 @@ private: render_root.ExpendToList(&render_list); BuildCommandBuffer(&render_list); - return(true); } diff --git a/example/Vulkan/InlineGeometryScene.cpp b/example/Vulkan/InlineGeometryScene.cpp new file mode 100644 index 00000000..9821c5cd --- /dev/null +++ b/example/Vulkan/InlineGeometryScene.cpp @@ -0,0 +1,169 @@ +// 7.InlineGeometryScene +// 全内置几何体场景 + +#include"VulkanAppFramework.h" +#include +#include +#include +#include +#include + +using namespace hgl; +using namespace hgl::graph; + +constexpr uint32_t SCREEN_WIDTH=128; +constexpr uint32_t SCREEN_HEIGHT=128; + +class TestApp:public CameraAppFramework +{ +private: + + SceneNode render_root; + RenderList render_list; + + vulkan::Material * material =nullptr; + vulkan::DescriptorSets * descriptor_sets =nullptr; + + vulkan::Renderable *ro_plane_grid, + *ro_cube, + *ro_sphere; + + vulkan::Pipeline *pipeline_line =nullptr, + *pipeline_solid =nullptr; + +private: + + bool InitMaterial() + { + material=shader_manage->CreateMaterial(OS_TEXT("OnlyPosition3D.vert.spv"), + OS_TEXT("FlatColor.frag.spv")); + if(!material) + return(false); + + descriptor_sets=material->CreateDescriptorSets(); + + db->Add(material); + db->Add(descriptor_sets); + return(true); + } + + void CreateRenderObject() + { + { + 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=CreatePlaneGrid(db,material,&pgci); + } + + { + struct CubeCreateInfo cci; + ro_cube=CreateCube(db,material,&cci); + } + + { + ro_sphere=CreateRenderableSphere(db,material,16); + } + } + + bool InitUBO() + { + if(!InitCameraUBO(descriptor_sets,material->GetUBO("world"))) + return(false); + + descriptor_sets->Update(); + return(true); + } + + bool InitPipeline() + { + vulkan::PipelineCreater *pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetRenderPass(),device->GetExtent()); + pipeline_creater->SetDepthTest(true); + pipeline_creater->SetDepthWrite(true); + pipeline_creater->Set(PRIM_LINES); + + pipeline_line=pipeline_creater->Create(); + db->Add(pipeline_line); + + pipeline_creater->Set(PRIM_TRIANGLES); + pipeline_solid=pipeline_creater->Create(); + db->Add(pipeline_solid); + + delete pipeline_creater; + + if(!pipeline_line) + return(false); + + if(!pipeline_solid) + return(false); + + return(true); + } + + bool InitScene() + { + render_root.Add(db->CreateRenderableInstance(pipeline_line,descriptor_sets,ro_plane_grid)); + render_root.Add(db->CreateRenderableInstance(pipeline_line,descriptor_sets,ro_cube ),translate(-10,0,0)*scale(10,10,10)); + render_root.Add(db->CreateRenderableInstance(pipeline_line,descriptor_sets,ro_sphere ),translate( 10,0,0)*scale(10,10,10)); + + render_root.RefreshMatrix(); + render_root.ExpendToList(&render_list); + + BuildCommandBuffer(&render_list); + return(true); + } + +public: + + bool Init() + { + if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT)) + return(false); + + if(!InitMaterial()) + return(false); + + CreateRenderObject(); + + if(!InitUBO()) + return(false); + + if(!InitPipeline()) + return(false); + + if(!InitScene()) + return(false); + + return(true); + } + + void Resize(int,int)override + { + BuildCommandBuffer(&render_list); + } +};//class TestApp:public CameraAppFramework + +int main(int,char **) +{ + TestApp app; + + if(!app.Init()) + return(-1); + + while(app.Run()); + + return 0; +}