2019-05-28 14:25:58 +08:00
|
|
|
|
// 4.Geometry3D
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
|
|
|
|
#include"VulkanAppFramework.h"
|
|
|
|
|
#include<hgl/filesystem/FileSystem.h>
|
|
|
|
|
#include<hgl/graph/InlineGeometry.h>
|
2020-10-21 12:39:22 +08:00
|
|
|
|
#include<hgl/graph/VKRenderResource.h>
|
2019-05-27 22:48:01 +08:00
|
|
|
|
#include<hgl/graph/RenderList.h>
|
2020-11-19 22:12:31 +08:00
|
|
|
|
#include<hgl/graph/Camera.h>
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
|
|
|
|
using namespace hgl;
|
|
|
|
|
using namespace hgl::graph;
|
|
|
|
|
|
2020-06-12 15:53:37 +08:00
|
|
|
|
constexpr uint32_t SCREEN_WIDTH=1280;
|
|
|
|
|
constexpr uint32_t SCREEN_HEIGHT=720;
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2019-06-15 18:07:20 +08:00
|
|
|
|
class TestApp:public CameraAppFramework
|
2019-05-27 22:48:01 +08:00
|
|
|
|
{
|
2020-01-20 20:28:01 +08:00
|
|
|
|
Color4f color;
|
|
|
|
|
|
2020-10-21 12:47:06 +08:00
|
|
|
|
GPUBuffer *ubo_color=nullptr;
|
2020-01-20 20:28:01 +08:00
|
|
|
|
|
2019-05-27 22:48:01 +08:00
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
SceneNode render_root;
|
2021-06-22 21:33:47 +08:00
|
|
|
|
RenderList *render_list=nullptr;
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2021-09-15 19:17:56 +08:00
|
|
|
|
Material * material =nullptr;
|
|
|
|
|
MaterialInstance * material_instance =nullptr;
|
|
|
|
|
Pipeline * pipeline =nullptr;
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2021-09-15 19:17:56 +08:00
|
|
|
|
Renderable * ro_plane_grid[3];
|
|
|
|
|
RenderableInstance *ri_plane_grid[3];
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
2021-09-15 19:17:56 +08:00
|
|
|
|
bool RecreatePipeline()
|
|
|
|
|
{
|
|
|
|
|
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D,Prim::Lines);
|
|
|
|
|
|
|
|
|
|
return pipeline;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InitMDP()
|
2019-07-11 11:18:34 +08:00
|
|
|
|
{
|
2021-09-15 19:17:56 +08:00
|
|
|
|
material=db->CreateMaterial(OS_TEXT("res/material/VertexColor3D"));
|
|
|
|
|
if(!material)return(false);
|
2019-07-11 11:18:34 +08:00
|
|
|
|
|
2021-09-15 19:17:56 +08:00
|
|
|
|
material_instance=db->CreateMaterialInstance(material);
|
|
|
|
|
if(!material_instance)return(false);
|
2019-07-11 11:18:34 +08:00
|
|
|
|
|
2021-09-15 19:17:56 +08:00
|
|
|
|
if(!RecreatePipeline())
|
|
|
|
|
return(false);
|
2019-07-11 11:18:34 +08:00
|
|
|
|
|
2021-06-22 21:33:47 +08:00
|
|
|
|
{
|
2021-09-15 19:17:56 +08:00
|
|
|
|
MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetType::Global);
|
2021-06-22 21:33:47 +08:00
|
|
|
|
|
|
|
|
|
if(!mp_global)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
if(!mp_global->BindUBO("g_camera",GetCameraInfoBuffer()))return(false);
|
|
|
|
|
|
|
|
|
|
mp_global->Update();
|
|
|
|
|
}
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2019-07-11 11:18:34 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
2020-09-21 20:34:47 +08:00
|
|
|
|
|
2021-09-15 19:17:56 +08:00
|
|
|
|
RenderableInstance *Add(Renderable *r,const Matrix4f &mat)
|
2019-07-11 11:18:34 +08:00
|
|
|
|
{
|
2021-09-15 19:17:56 +08:00
|
|
|
|
RenderableInstance *ri=db->CreateRenderableInstance(r,material_instance,pipeline);
|
2019-07-11 11:18:34 +08:00
|
|
|
|
|
2021-06-22 21:33:47 +08:00
|
|
|
|
render_root.CreateSubNode(mat,ri);
|
2021-09-15 19:17:56 +08:00
|
|
|
|
|
|
|
|
|
return ri;
|
2019-07-11 11:18:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-27 22:48:01 +08:00
|
|
|
|
void CreateRenderObject()
|
|
|
|
|
{
|
2019-06-11 23:14:13 +08:00
|
|
|
|
struct PlaneGridCreateInfo pgci;
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2019-06-11 23:14:13 +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
|
|
|
|
|
2019-06-11 23:14:13 +08:00
|
|
|
|
pgci.step.u=20;
|
|
|
|
|
pgci.step.v=20;
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2019-06-11 23:14:13 +08:00
|
|
|
|
pgci.side_step.u=10;
|
|
|
|
|
pgci.side_step.v=10;
|
2019-05-28 14:25:58 +08:00
|
|
|
|
|
2020-10-17 22:13:08 +08:00
|
|
|
|
pgci.color.Set(0.5,0,0,1);
|
2019-06-11 23:14:13 +08:00
|
|
|
|
pgci.side_color.Set(1,0,0,1);
|
2019-05-29 21:48:56 +08:00
|
|
|
|
|
2021-09-15 19:17:56 +08:00
|
|
|
|
ro_plane_grid[0]=CreateRenderablePlaneGrid(db,material,&pgci);
|
2019-05-29 21:48:56 +08:00
|
|
|
|
|
2020-10-17 22:13:08 +08:00
|
|
|
|
pgci.color.Set(0,0.5,0,1);
|
2019-06-11 23:14:13 +08:00
|
|
|
|
pgci.side_color.Set(0,1,0,1);
|
2019-05-28 14:25:58 +08:00
|
|
|
|
|
2021-09-15 19:17:56 +08:00
|
|
|
|
ro_plane_grid[1]=CreateRenderablePlaneGrid(db,material,&pgci);
|
2019-05-28 14:25:58 +08:00
|
|
|
|
|
2020-10-17 22:13:08 +08:00
|
|
|
|
pgci.color.Set(0,0,0.5,1);
|
2019-06-11 23:14:13 +08:00
|
|
|
|
pgci.side_color.Set(0,0,1,1);
|
2021-09-15 19:17:56 +08:00
|
|
|
|
ro_plane_grid[2]=CreateRenderablePlaneGrid(db,material,&pgci);
|
2020-06-21 02:32:52 +08:00
|
|
|
|
|
2020-11-19 22:12:31 +08:00
|
|
|
|
camera->pos.Set(200,200,200,1.0);
|
2019-05-27 22:48:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-28 12:30:44 +08:00
|
|
|
|
bool InitScene()
|
|
|
|
|
{
|
2021-09-15 19:17:56 +08:00
|
|
|
|
ri_plane_grid[0]=Add(ro_plane_grid[0],Matrix4f::identity);
|
|
|
|
|
ri_plane_grid[1]=Add(ro_plane_grid[1],rotate(HGL_RAD_90,0,1,0));
|
|
|
|
|
ri_plane_grid[2]=Add(ro_plane_grid[2],rotate(HGL_RAD_90,1,0,0));
|
2020-10-28 12:30:44 +08:00
|
|
|
|
|
|
|
|
|
render_root.RefreshMatrix();
|
2021-06-22 21:33:47 +08:00
|
|
|
|
render_list->Expend(camera->info,&render_root);
|
2020-10-28 12:30:44 +08:00
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-27 22:48:01 +08:00
|
|
|
|
public:
|
|
|
|
|
|
2021-06-22 21:33:47 +08:00
|
|
|
|
~TestApp()
|
|
|
|
|
{
|
|
|
|
|
SAFE_CLEAR(render_list);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-27 22:48:01 +08:00
|
|
|
|
bool Init()
|
|
|
|
|
{
|
2019-06-15 18:07:20 +08:00
|
|
|
|
if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
2019-05-27 22:48:01 +08:00
|
|
|
|
return(false);
|
2021-06-22 21:33:47 +08:00
|
|
|
|
|
|
|
|
|
render_list=new RenderList(device);
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2021-09-15 19:17:56 +08:00
|
|
|
|
if(!InitMDP())
|
2019-05-27 22:48:01 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2019-07-11 11:18:34 +08:00
|
|
|
|
CreateRenderObject();
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
|
|
|
|
if(!InitScene())
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
2019-06-13 23:12:11 +08:00
|
|
|
|
|
2019-06-18 00:48:05 +08:00
|
|
|
|
void BuildCommandBuffer(uint32 index)
|
2019-06-13 23:12:11 +08:00
|
|
|
|
{
|
2021-06-22 21:33:47 +08:00
|
|
|
|
VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
|
2019-06-13 23:12:11 +08:00
|
|
|
|
}
|
2021-09-15 19:17:56 +08:00
|
|
|
|
|
|
|
|
|
void Resize(int w,int h)override
|
|
|
|
|
{
|
|
|
|
|
CameraAppFramework::Resize(w,h);
|
|
|
|
|
|
|
|
|
|
RecreatePipeline();
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<3;i++)
|
|
|
|
|
ri_plane_grid[i]->UpdatePipeline(pipeline);
|
|
|
|
|
|
|
|
|
|
VulkanApplicationFramework::BuildCommandBuffer(render_list);
|
|
|
|
|
}
|
2019-06-15 18:07:20 +08:00
|
|
|
|
};//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;
|
|
|
|
|
}
|