ULRE/example/Vulkan/Geometry3D.cpp

165 lines
3.9 KiB
C++
Raw Normal View History

// 4.Geometry3D
2019-05-27 22:48:01 +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>
using namespace hgl;
using namespace hgl::graph;
constexpr uint32_t SCREEN_WIDTH=128;
constexpr uint32_t SCREEN_HEIGHT=128;
2019-05-27 22:48:01 +08:00
class TestApp:public CameraAppFramework
2019-05-27 22:48:01 +08:00
{
private:
SceneNode render_root;
RenderList render_list;
vulkan::Material * material =nullptr;
vulkan::DescriptorSets * descriptor_sets =nullptr;
vulkan::Renderable *ro_plane_grid[3];
2019-05-27 22:48:01 +08:00
vulkan::Pipeline * pipeline_line =nullptr;
private:
bool InitMaterial()
{
material=shader_manage->CreateMaterial(OS_TEXT("PositionColor3D.vert.spv"),
2019-05-27 22:48:01 +08:00
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;
2019-05-27 22:48:01 +08:00
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);
2019-05-27 22:48:01 +08:00
pgci.step.u=20;
pgci.step.v=20;
2019-05-27 22:48:01 +08:00
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[0]=CreatePlaneGrid(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);
pgci.color.Set(0,0,0.75,1);
pgci.side_color.Set(0,0,1,1);
ro_plane_grid[2]=CreatePlaneGrid(db,material,&pgci);
2019-05-27 22:48:01 +08:00
}
bool InitUBO()
{
if(!InitCameraUBO(descriptor_sets,material->GetUBO("world")))
return(false);
2019-05-27 22:48:01 +08:00
descriptor_sets->Update();
return(true);
}
2019-05-27 22:48:01 +08:00
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);
pipeline_creater->SetDepthWrite(true);
pipeline_creater->CloseCullFace();
pipeline_creater->Set(PRIM_LINES);
pipeline_line=pipeline_creater->Create();
if(!pipeline_line)
return(false);
2019-05-27 22:48:01 +08:00
db->Add(pipeline_line);
2019-05-27 22:48:01 +08:00
delete pipeline_creater;
}
return pipeline_line;
}
bool InitScene()
{
2019-05-29 22:56:16 +08:00
const float rad90=hgl_ang2rad(90);
render_root.Add(db->CreateRenderableInstance(pipeline_line,descriptor_sets,ro_plane_grid[0]));
2019-05-29 22:56:16 +08:00
render_root.Add(db->CreateRenderableInstance(pipeline_line,descriptor_sets,ro_plane_grid[1]),rotate(rad90,0,1,0));
render_root.Add(db->CreateRenderableInstance(pipeline_line,descriptor_sets,ro_plane_grid[2]),rotate(rad90,1,0,0));
2019-05-27 22:48:01 +08:00
render_root.RefreshMatrix();
2019-05-27 22:48:01 +08:00
render_root.ExpendToList(&render_list);
BuildCommandBuffer(&render_list);
2019-05-27 22:48:01 +08:00
return(true);
}
public:
bool Init()
{
if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
2019-05-27 22:48:01 +08:00
return(false);
if(!InitMaterial())
return(false);
CreateRenderObject();
if(!InitUBO())
return(false);
2019-05-27 22:48:01 +08:00
if(!InitPipeline())
return(false);
if(!InitScene())
return(false);
return(true);
}
void Resize(int,int)override
{
BuildCommandBuffer(&render_list);
}
};//class TestApp:public CameraAppFramework
2019-05-27 22:48:01 +08:00
int main(int,char **)
{
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
}