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>
|
|
|
|
|
#include<hgl/graph/SceneDB.h>
|
|
|
|
|
#include<hgl/graph/RenderableInstance.h>
|
|
|
|
|
#include<hgl/graph/RenderList.h>
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
vulkan::Buffer *ubo_color=nullptr;
|
|
|
|
|
|
2019-05-27 22:48:01 +08:00
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
SceneNode render_root;
|
|
|
|
|
RenderList render_list;
|
|
|
|
|
|
2019-07-11 11:18:34 +08:00
|
|
|
|
struct MDP
|
|
|
|
|
{
|
2020-01-20 20:00:03 +08:00
|
|
|
|
vulkan::Material * material =nullptr;
|
|
|
|
|
vulkan::MaterialInstance * material_instance =nullptr;
|
|
|
|
|
vulkan::Pipeline * pipeline =nullptr;
|
2019-07-11 11:18:34 +08:00
|
|
|
|
}m3d,m2d;
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2019-07-11 11:18:34 +08:00
|
|
|
|
vulkan::Renderable *ro_plane_grid[3],
|
|
|
|
|
*ro_round_rectangle =nullptr;
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
2019-07-11 11:18:34 +08:00
|
|
|
|
bool InitMaterial(MDP *mdp,const OSString &vs,const OSString &fs)
|
|
|
|
|
{
|
|
|
|
|
mdp->material=shader_manage->CreateMaterial(vs,fs);
|
|
|
|
|
|
|
|
|
|
if(!mdp->material)
|
|
|
|
|
return(false);
|
|
|
|
|
|
2020-01-20 20:00:03 +08:00
|
|
|
|
mdp->material_instance=mdp->material->CreateInstance();
|
2019-07-11 11:18:34 +08:00
|
|
|
|
|
|
|
|
|
db->Add(mdp->material);
|
2020-01-20 20:00:03 +08:00
|
|
|
|
db->Add(mdp->material_instance);
|
2019-07-11 11:18:34 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InitUBO(MDP *mdp)
|
2019-05-27 22:48:01 +08:00
|
|
|
|
{
|
2020-06-12 15:53:37 +08:00
|
|
|
|
if(!mdp->material_instance->BindUBO("world",GetCameraMatrixBuffer()))
|
2019-05-27 22:48:01 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2020-01-20 20:00:03 +08:00
|
|
|
|
mdp->material_instance->Update();
|
2019-07-11 11:18:34 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InitPipeline(MDP *mdp,const VkPrimitiveTopology primitive)
|
|
|
|
|
{
|
|
|
|
|
AutoDelete<vulkan::PipelineCreater>
|
2019-07-16 20:22:29 +08:00
|
|
|
|
pipeline_creater=new vulkan::PipelineCreater(device,mdp->material,sc_render_target);
|
2019-07-11 11:18:34 +08:00
|
|
|
|
pipeline_creater->CloseCullFace();
|
|
|
|
|
pipeline_creater->Set(primitive);
|
|
|
|
|
|
|
|
|
|
mdp->pipeline=pipeline_creater->Create();
|
|
|
|
|
|
|
|
|
|
if(!mdp->pipeline)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
db->Add(mdp->pipeline);
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InitMDP(MDP *mdp,const VkPrimitiveTopology primitive,const OSString &vs,const OSString &fs)
|
|
|
|
|
{
|
|
|
|
|
if(!InitMaterial(mdp,vs,fs))
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
if(!InitUBO(mdp))
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
if(!InitPipeline(mdp,primitive))
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InitScene()
|
|
|
|
|
{
|
2020-01-20 20:00:03 +08:00
|
|
|
|
render_root.Add(db->CreateRenderableInstance(m2d.pipeline,m2d.material_instance,ro_round_rectangle));
|
2019-07-11 11:18:34 +08:00
|
|
|
|
|
2020-01-20 20:00:03 +08:00
|
|
|
|
render_root.Add(db->CreateRenderableInstance(m3d.pipeline,m3d.material_instance,ro_plane_grid[0]));
|
|
|
|
|
render_root.Add(db->CreateRenderableInstance(m3d.pipeline,m3d.material_instance,ro_plane_grid[1]),rotate(HGL_RAD_90,0,1,0));
|
|
|
|
|
render_root.Add(db->CreateRenderableInstance(m3d.pipeline,m3d.material_instance,ro_plane_grid[2]),rotate(HGL_RAD_90,1,0,0));
|
2019-07-11 11:18:34 +08:00
|
|
|
|
|
|
|
|
|
render_root.RefreshMatrix();
|
|
|
|
|
render_root.ExpendToList(&render_list);
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2019-06-11 23:14:13 +08:00
|
|
|
|
pgci.color.Set(0.75,0,0,1);
|
|
|
|
|
pgci.side_color.Set(1,0,0,1);
|
2019-05-29 21:48:56 +08:00
|
|
|
|
|
2019-07-11 11:18:34 +08:00
|
|
|
|
ro_plane_grid[0]=CreateRenderablePlaneGrid(db,m3d.material,&pgci);
|
2019-05-29 21:48:56 +08:00
|
|
|
|
|
2019-06-11 23:14:13 +08:00
|
|
|
|
pgci.color.Set(0,0.75,0,1);
|
|
|
|
|
pgci.side_color.Set(0,1,0,1);
|
2019-05-28 14:25:58 +08:00
|
|
|
|
|
2019-07-11 11:18:34 +08:00
|
|
|
|
ro_plane_grid[1]=CreateRenderablePlaneGrid(db,m3d.material,&pgci);
|
2019-05-28 14:25:58 +08:00
|
|
|
|
|
2019-06-11 23:14:13 +08:00
|
|
|
|
pgci.color.Set(0,0,0.75,1);
|
|
|
|
|
pgci.side_color.Set(0,0,1,1);
|
2019-07-11 11:18:34 +08:00
|
|
|
|
ro_plane_grid[2]=CreateRenderablePlaneGrid(db,m3d.material,&pgci);
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2019-07-11 11:18:34 +08:00
|
|
|
|
{
|
|
|
|
|
struct RoundRectangleCreateInfo rrci;
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2019-07-11 11:18:34 +08:00
|
|
|
|
rrci.scope.Set(SCREEN_WIDTH-30,10,20,20);
|
|
|
|
|
rrci.radius=5;
|
|
|
|
|
rrci.round_per=5;
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2019-07-11 11:18:34 +08:00
|
|
|
|
ro_round_rectangle=CreateRenderableRoundRectangle(db,m2d.material,&rrci);
|
|
|
|
|
}
|
2020-06-21 02:32:52 +08:00
|
|
|
|
|
|
|
|
|
camera.eye.Set(200,200,200,1.0);
|
2019-05-27 22:48:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2020-06-12 15:53:37 +08:00
|
|
|
|
if(!InitMDP(&m3d,PRIM_LINES,OS_TEXT("res/shader/PositionColor3D.vert"),
|
|
|
|
|
OS_TEXT("res/shader/VertexColor.frag")))
|
2019-05-27 22:48:01 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2020-06-12 15:53:37 +08:00
|
|
|
|
if(!InitMDP(&m2d,PRIM_TRIANGLE_FAN, OS_TEXT("res/shader/OnlyPosition.vert"),
|
|
|
|
|
OS_TEXT("res/shader/FlatColor.frag")))
|
2019-05-29 21:48:56 +08:00
|
|
|
|
return(false);
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2020-01-20 20:28:01 +08:00
|
|
|
|
{
|
|
|
|
|
color.Set(1,1,0,1);
|
|
|
|
|
ubo_color=device->CreateUBO(sizeof(Vector4f),&color);
|
|
|
|
|
|
|
|
|
|
m2d.material_instance->BindUBO("color_material",ubo_color);
|
|
|
|
|
m2d.material_instance->Update();
|
2020-06-21 02:32:52 +08:00
|
|
|
|
|
|
|
|
|
db->Add(ubo_color);
|
2020-01-20 20:28:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2019-06-18 00:48:05 +08:00
|
|
|
|
VulkanApplicationFramework::BuildCommandBuffer(index,&render_list);
|
2019-06-13 23:12:11 +08:00
|
|
|
|
}
|
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;
|
|
|
|
|
}
|