2022-06-18 18:47:08 +08:00
|
|
|
|
// <20><><EFBFBD>ĵ<F2B5A5B5><C4B5><EFBFBD><EFBFBD><EFBFBD>Ⱦ
|
|
|
|
|
// <20><>CPU<50><55><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>vertex<65><78>ȡ<EFBFBD><C8A1><EFBFBD>߶<EFBFBD>ͼ
|
|
|
|
|
|
|
|
|
|
#include"VulkanAppFramework.h"
|
|
|
|
|
#include<hgl/filesystem/FileSystem.h>
|
|
|
|
|
#include<hgl/graph/InlineGeometry.h>
|
|
|
|
|
#include<hgl/graph/VKRenderResource.h>
|
|
|
|
|
#include<hgl/graph/RenderList.h>
|
|
|
|
|
#include<hgl/graph/Camera.h>
|
|
|
|
|
|
|
|
|
|
using namespace hgl;
|
|
|
|
|
using namespace hgl::graph;
|
|
|
|
|
|
|
|
|
|
constexpr uint32_t SCREEN_WIDTH=1280;
|
|
|
|
|
constexpr uint32_t SCREEN_HEIGHT=720;
|
|
|
|
|
|
|
|
|
|
struct TerrainCreateInfo
|
|
|
|
|
{
|
|
|
|
|
uint Xcount; ///<X<><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
uint Ycount; ///<Y<><59><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
struct //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ե
|
|
|
|
|
{
|
|
|
|
|
bool top,left,right,bottom;
|
|
|
|
|
}dual;
|
|
|
|
|
};//struct TerrainCreateInfo
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
2022-06-24 17:51:05 +08:00
|
|
|
|
Primitive *CreateRenderableTerrain(RenderResource *db,const VAB *vab,const TerrainCreateInfo *tci)
|
2022-06-18 18:47:08 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class TestApp:public CameraAppFramework
|
|
|
|
|
{
|
|
|
|
|
Color4f color;
|
|
|
|
|
|
|
|
|
|
GPUBuffer *ubo_color=nullptr;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
SceneNode render_root;
|
|
|
|
|
RenderList *render_list=nullptr;
|
|
|
|
|
|
|
|
|
|
Material * material =nullptr;
|
|
|
|
|
MaterialInstance * material_instance =nullptr;
|
|
|
|
|
Pipeline * pipeline =nullptr;
|
|
|
|
|
|
2022-06-24 17:51:05 +08:00
|
|
|
|
Primitive * renderable =nullptr;
|
2022-06-18 18:47:08 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
bool InitMDP()
|
|
|
|
|
{
|
|
|
|
|
material=db->CreateMaterial(OS_TEXT("res/material/VertexColor3D"));
|
|
|
|
|
if(!material)return(false);
|
|
|
|
|
|
|
|
|
|
material_instance=db->CreateMaterialInstance(material);
|
|
|
|
|
if(!material_instance)return(false);
|
|
|
|
|
|
|
|
|
|
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D,Prim::TriangleStrip);
|
|
|
|
|
if(!pipeline)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 17:51:05 +08:00
|
|
|
|
RenderableInstance *Add(Primitive *r,const Matrix4f &mat)
|
2022-06-18 18:47:08 +08:00
|
|
|
|
{
|
|
|
|
|
RenderableInstance *ri=db->CreateRenderableInstance(r,material_instance,pipeline);
|
|
|
|
|
|
|
|
|
|
render_root.CreateSubNode(mat,ri);
|
|
|
|
|
|
|
|
|
|
return ri;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CreateRenderObject()
|
|
|
|
|
{
|
|
|
|
|
struct PlaneGridCreateInfo pgci;
|
|
|
|
|
|
|
|
|
|
pgci.coord[0]=Vector3f(-100,-100,0);
|
|
|
|
|
pgci.coord[1]=Vector3f( 100,-100,0);
|
|
|
|
|
pgci.coord[2]=Vector3f( 100, 100,0);
|
|
|
|
|
pgci.coord[3]=Vector3f(-100, 100,0);
|
|
|
|
|
|
|
|
|
|
pgci.step.x=32;
|
|
|
|
|
pgci.step.y=32;
|
|
|
|
|
|
|
|
|
|
pgci.side_step.x=8;
|
|
|
|
|
pgci.side_step.y=8;
|
|
|
|
|
|
|
|
|
|
pgci.color.Set(0.75,0.75,0.75);
|
|
|
|
|
pgci.side_color.Set(1,0,0,1);
|
|
|
|
|
|
|
|
|
|
const VAB *vab=material_instance->GetVAB();
|
|
|
|
|
|
|
|
|
|
renderable=CreateRenderablePlaneGrid(db,vab,&pgci);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InitScene()
|
|
|
|
|
{
|
|
|
|
|
RenderableInstance *ri=db->CreateRenderableInstance(renderable,material_instance,pipeline);
|
|
|
|
|
|
|
|
|
|
render_root.CreateSubNode(ri);
|
|
|
|
|
|
|
|
|
|
camera->pos=Vector3f(200,200,200);
|
|
|
|
|
camera_control->SetTarget(Vector3f(0,0,0));
|
|
|
|
|
camera_control->Refresh();
|
|
|
|
|
|
|
|
|
|
render_root.RefreshMatrix();
|
|
|
|
|
render_list->Expend(camera->info,&render_root);
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
~TestApp()
|
|
|
|
|
{
|
|
|
|
|
SAFE_CLEAR(render_list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Init()
|
|
|
|
|
{
|
|
|
|
|
if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
render_list=new RenderList(device);
|
|
|
|
|
|
|
|
|
|
if(!InitMDP())
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
CreateRenderObject();
|
|
|
|
|
|
|
|
|
|
if(!InitScene())
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BuildCommandBuffer(uint32 index)
|
|
|
|
|
{
|
|
|
|
|
render_root.RefreshMatrix();
|
|
|
|
|
render_list->Expend(GetCameraInfo(),&render_root);
|
|
|
|
|
|
|
|
|
|
VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Resize(int w,int h)override
|
|
|
|
|
{
|
|
|
|
|
CameraAppFramework::Resize(w,h);
|
|
|
|
|
|
|
|
|
|
VulkanApplicationFramework::BuildCommandBuffer(render_list);
|
|
|
|
|
}
|
|
|
|
|
};//class TestApp:public CameraAppFramework
|
|
|
|
|
|
|
|
|
|
int main(int,char **)
|
|
|
|
|
{
|
|
|
|
|
TestApp app;
|
|
|
|
|
|
|
|
|
|
if(!app.Init())
|
|
|
|
|
return(-1);
|
|
|
|
|
|
|
|
|
|
while(app.Run());
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|