2019-06-24 20:18:01 +08:00
|
|
|
|
// 7.InlineGeometryScene
|
2019-06-17 12:17:59 +08:00
|
|
|
|
// 全内置几何体场景
|
|
|
|
|
|
|
|
|
|
#include"VulkanAppFramework.h"
|
|
|
|
|
#include<hgl/filesystem/FileSystem.h>
|
|
|
|
|
#include<hgl/graph/InlineGeometry.h>
|
2020-09-02 18:16:15 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKDatabase.h>
|
2020-09-27 20:58:25 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKRenderableInstance.h>
|
2019-06-17 12:17:59 +08:00
|
|
|
|
#include<hgl/graph/RenderList.h>
|
|
|
|
|
|
|
|
|
|
using namespace hgl;
|
|
|
|
|
using namespace hgl::graph;
|
|
|
|
|
|
2020-06-16 20:01:36 +08:00
|
|
|
|
constexpr uint32_t SCREEN_WIDTH=1280;
|
|
|
|
|
constexpr uint32_t SCREEN_HEIGHT=720;
|
2019-06-17 12:17:59 +08:00
|
|
|
|
|
|
|
|
|
class TestApp:public CameraAppFramework
|
|
|
|
|
{
|
2020-01-21 10:48:25 +08:00
|
|
|
|
Color4f color;
|
|
|
|
|
|
2019-06-17 12:17:59 +08:00
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
SceneNode render_root;
|
|
|
|
|
RenderList render_list;
|
2020-09-21 20:34:47 +08:00
|
|
|
|
|
2020-09-27 20:58:25 +08:00
|
|
|
|
vulkan::Material * material =nullptr;
|
|
|
|
|
vulkan::MaterialInstance * material_instance =nullptr;
|
|
|
|
|
|
|
|
|
|
vulkan::PipelineData * pipeline_data =nullptr;
|
|
|
|
|
vulkan::Pipeline * pipeline_line =nullptr;
|
|
|
|
|
vulkan::Pipeline * pipeline_solid =nullptr;
|
2019-06-17 12:17:59 +08:00
|
|
|
|
|
2020-01-21 10:48:25 +08:00
|
|
|
|
vulkan::Buffer * ubo_color =nullptr;
|
2019-06-17 12:17:59 +08:00
|
|
|
|
|
|
|
|
|
vulkan::Renderable *ro_plane_grid,
|
|
|
|
|
*ro_cube,
|
2019-06-17 20:25:44 +08:00
|
|
|
|
*ro_sphere,
|
|
|
|
|
*ro_dome,
|
|
|
|
|
*ro_torus,
|
|
|
|
|
*ro_cylinder,
|
|
|
|
|
*ro_cone;
|
2019-06-17 12:17:59 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
2020-09-27 20:58:25 +08:00
|
|
|
|
bool InitMaterial()
|
2019-06-17 12:17:59 +08:00
|
|
|
|
{
|
2020-09-27 20:58:25 +08:00
|
|
|
|
material=db->CreateMaterial(OS_TEXT("res/material/VertexColor3D"));
|
|
|
|
|
if(!material)return(false);
|
2020-09-21 20:34:47 +08:00
|
|
|
|
|
2020-09-27 20:58:25 +08:00
|
|
|
|
material_instance=db->CreateMaterialInstance(material);
|
|
|
|
|
if(!material_instance)return(false);
|
2019-06-17 12:17:59 +08:00
|
|
|
|
|
2020-10-16 17:24:01 +08:00
|
|
|
|
pipeline_data=vulkan::GetPipelineData(vulkan::InlinePipeline::Solid3D);
|
2020-09-27 20:58:25 +08:00
|
|
|
|
if(!pipeline_data)return(false);
|
2019-06-17 12:17:59 +08:00
|
|
|
|
|
2020-09-27 20:58:25 +08:00
|
|
|
|
pipeline_line=CreatePipeline(material,pipeline_data,Prim::Lines);
|
|
|
|
|
if(!pipeline_line)return(false);
|
|
|
|
|
|
|
|
|
|
pipeline_solid=CreatePipeline(material,pipeline_data,Prim::Triangles);
|
|
|
|
|
if(!pipeline_solid)return(false);
|
2020-09-21 20:34:47 +08:00
|
|
|
|
|
2019-06-17 12:17:59 +08:00
|
|
|
|
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;
|
|
|
|
|
|
2020-10-16 17:24:01 +08:00
|
|
|
|
pgci.color.Set(0.5,0,0,1);
|
2019-06-17 12:17:59 +08:00
|
|
|
|
pgci.side_color.Set(1,0,0,1);
|
|
|
|
|
|
2019-06-17 21:59:54 +08:00
|
|
|
|
ro_plane_grid=CreateRenderablePlaneGrid(db,material,&pgci);
|
2019-06-17 12:17:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2020-09-27 20:58:25 +08:00
|
|
|
|
struct CubeCreateInfo cci;
|
|
|
|
|
cci.has_color=true;
|
|
|
|
|
cci.color.Set(1,1,1,1);
|
2019-06-17 21:59:54 +08:00
|
|
|
|
ro_cube=CreateRenderableCube(db,material,&cci);
|
2019-06-17 12:17:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
ro_sphere=CreateRenderableSphere(db,material,16);
|
|
|
|
|
}
|
2019-06-17 20:25:44 +08:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
DomeCreateInfo dci;
|
|
|
|
|
|
|
|
|
|
dci.radius=100;
|
2019-06-17 21:59:54 +08:00
|
|
|
|
dci.numberSlices=32;
|
2019-06-17 20:25:44 +08:00
|
|
|
|
|
|
|
|
|
ro_dome=CreateRenderableDome(db,material,&dci);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
TorusCreateInfo tci;
|
|
|
|
|
|
|
|
|
|
tci.innerRadius=50;
|
|
|
|
|
tci.outerRadius=70;
|
|
|
|
|
|
|
|
|
|
tci.numberSlices=32;
|
|
|
|
|
tci.numberStacks=16;
|
|
|
|
|
|
|
|
|
|
ro_torus=CreateRenderableTorus(db,material,&tci);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
CylinderCreateInfo cci;
|
|
|
|
|
|
|
|
|
|
cci.halfExtend=10;
|
|
|
|
|
cci.radius=10;
|
|
|
|
|
cci.numberSlices=16;
|
|
|
|
|
|
|
|
|
|
ro_cylinder=CreateRenderableCylinder(db,material,&cci);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
ConeCreateInfo cci;
|
|
|
|
|
|
|
|
|
|
cci.halfExtend=10;
|
|
|
|
|
cci.radius=10;
|
|
|
|
|
cci.numberSlices=16;
|
|
|
|
|
cci.numberStacks=1;
|
|
|
|
|
|
|
|
|
|
ro_cone=CreateRenderableCone(db,material,&cci);
|
|
|
|
|
}
|
2019-06-17 12:17:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InitUBO()
|
|
|
|
|
{
|
2020-01-21 10:48:25 +08:00
|
|
|
|
color.Set(1,1,1,1);
|
|
|
|
|
|
|
|
|
|
ubo_color=device->CreateUBO(sizeof(Vector4f),&color);
|
|
|
|
|
|
|
|
|
|
db->Add(ubo_color);
|
|
|
|
|
|
|
|
|
|
material_instance->BindUBO("color_material",ubo_color);
|
|
|
|
|
|
2020-06-16 20:01:36 +08:00
|
|
|
|
if(!material_instance->BindUBO("world",GetCameraMatrixBuffer()))
|
2019-06-17 12:17:59 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2020-01-20 20:00:03 +08:00
|
|
|
|
material_instance->Update();
|
2019-06-17 12:17:59 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
2020-09-21 20:34:47 +08:00
|
|
|
|
|
2020-09-27 20:58:25 +08:00
|
|
|
|
void Add(vulkan::Renderable *r,vulkan::Pipeline *pl)
|
2020-09-21 20:34:47 +08:00
|
|
|
|
{
|
2020-09-27 20:58:25 +08:00
|
|
|
|
auto ri=db->CreateRenderableInstance(r,material_instance,pl);
|
2020-09-21 20:34:47 +08:00
|
|
|
|
|
|
|
|
|
render_root.Add(ri);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-27 20:58:25 +08:00
|
|
|
|
void Add(vulkan::Renderable *r,vulkan::Pipeline *pl,const Matrix4f &mat)
|
2020-09-21 20:34:47 +08:00
|
|
|
|
{
|
2020-09-27 20:58:25 +08:00
|
|
|
|
auto ri=db->CreateRenderableInstance(r,material_instance,pl);
|
2020-09-21 20:34:47 +08:00
|
|
|
|
|
|
|
|
|
render_root.Add(ri,mat);
|
|
|
|
|
}
|
2019-06-17 12:17:59 +08:00
|
|
|
|
|
|
|
|
|
bool InitScene()
|
|
|
|
|
{
|
2020-09-27 20:58:25 +08:00
|
|
|
|
Add(ro_plane_grid,pipeline_line);
|
|
|
|
|
// Add(ro_dome,pipeline_solid);
|
|
|
|
|
Add(ro_torus ,pipeline_solid);
|
|
|
|
|
Add(ro_cube ,pipeline_solid,translate(-10, 0, 5)*scale(10,10,10));
|
|
|
|
|
Add(ro_sphere ,pipeline_solid,translate( 10, 0, 5)*scale(10,10,10));
|
|
|
|
|
Add(ro_cylinder ,pipeline_solid,translate( 0, 16, 0));
|
|
|
|
|
Add(ro_cone ,pipeline_solid,translate( 0,-16, 0));
|
2019-06-17 12:17:59 +08:00
|
|
|
|
|
|
|
|
|
render_root.RefreshMatrix();
|
|
|
|
|
render_root.ExpendToList(&render_list);
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
bool Init()
|
|
|
|
|
{
|
|
|
|
|
if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
|
|
|
|
return(false);
|
2020-09-21 20:34:47 +08:00
|
|
|
|
|
2020-09-27 20:58:25 +08:00
|
|
|
|
if(!InitMaterial())
|
2020-09-21 20:34:47 +08:00
|
|
|
|
return(false);
|
2019-06-17 12:17:59 +08:00
|
|
|
|
|
|
|
|
|
if(!InitUBO())
|
|
|
|
|
return(false);
|
|
|
|
|
|
2020-09-27 20:58:25 +08:00
|
|
|
|
CreateRenderObject();
|
2019-06-17 12:17:59 +08:00
|
|
|
|
|
|
|
|
|
if(!InitScene())
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
2019-06-18 00:48:05 +08:00
|
|
|
|
|
|
|
|
|
void BuildCommandBuffer(uint32_t index) override
|
2019-06-17 12:17:59 +08:00
|
|
|
|
{
|
2019-06-18 00:48:05 +08:00
|
|
|
|
render_root.RefreshMatrix();
|
|
|
|
|
render_list.Clear();
|
|
|
|
|
render_root.ExpendToList(&render_list);
|
|
|
|
|
|
|
|
|
|
VulkanApplicationFramework::BuildCommandBuffer(index,&render_list);
|
2019-06-17 12:17:59 +08:00
|
|
|
|
}
|
|
|
|
|
};//class TestApp:public CameraAppFramework
|
|
|
|
|
|
|
|
|
|
int main(int,char **)
|
|
|
|
|
{
|
|
|
|
|
TestApp app;
|
|
|
|
|
|
|
|
|
|
if(!app.Init())
|
|
|
|
|
return(-1);
|
|
|
|
|
|
|
|
|
|
while(app.Run());
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|