upgrade example first_triangle

This commit is contained in:
hyzboy 2020-09-20 03:59:42 +08:00
parent bb158d6105
commit 6762fd06b7
5 changed files with 19 additions and 38 deletions

2
CMCore

@ -1 +1 @@
Subproject commit 29785b9d2a7160d97c214d689f7c76f2d07b9ce5
Subproject commit 25a2605932f72286333d83a4e10e490107b0f6fd

View File

@ -8,9 +8,6 @@
using namespace hgl;
using namespace hgl::graph;
bool SaveToFile(const OSString &filename,VK_NAMESPACE::PipelineCreater *pc);
bool LoadFromFile(const OSString &filename,VK_NAMESPACE::PipelineCreater *pc);
constexpr uint32_t SCREEN_WIDTH=1280;
constexpr uint32_t SCREEN_HEIGHT=720;
@ -35,7 +32,6 @@ private:
Camera cam;
vulkan::Material * material =nullptr;
vulkan::MaterialInstance * material_instance =nullptr;
vulkan::Renderable * render_obj =nullptr;
vulkan::Buffer * ubo_world_matrix =nullptr;
@ -51,24 +47,19 @@ public:
{
SAFE_CLEAR(color_buffer);
SAFE_CLEAR(vertex_buffer);
SAFE_CLEAR(pipeline);
SAFE_CLEAR(ubo_world_matrix);
SAFE_CLEAR(render_obj);
SAFE_CLEAR(material_instance);
SAFE_CLEAR(material);
}
private:
bool InitMaterial()
{
material=shader_manage->CreateMaterial(OS_TEXT("res/shader/FlatColor.vert"),
OS_TEXT("res/shader/VertexColor.frag"));
if(!material)
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2D"));
if(!material_instance)
return(false);
render_obj=material->CreateRenderable(VERTEX_COUNT);
material_instance=material->CreateInstance();
render_obj=db->CreateRenderable(material_instance,VERTEX_COUNT);
return(true);
}
@ -81,7 +72,7 @@ private:
cam.Refresh();
ubo_world_matrix=device->CreateUBO(sizeof(WorldMatrix),&cam.matrix);
ubo_world_matrix=db->CreateUBO(sizeof(WorldMatrix),&cam.matrix);
if(!ubo_world_matrix)
return(false);
@ -96,33 +87,15 @@ private:
vertex_buffer =device->CreateVAB(FMT_RG32F, VERTEX_COUNT,vertex_data);
color_buffer =device->CreateVAB(FMT_RGB32F, VERTEX_COUNT,color_data);
if(!render_obj->Set("Vertex", vertex_buffer))return(false);
if(!render_obj->Set("Color", color_buffer))return(false);
if(!render_obj->Set(VAN::Position, vertex_buffer))return(false);
if(!render_obj->Set(VAN::Color, color_buffer))return(false);
return(true);
}
bool InitPipeline()
{
constexpr os_char PIPELINE_FILENAME[]=OS_TEXT("2DSolid.pipeline");
{
AutoDelete<vulkan::PipelineCreater>
pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target);
pipeline_creater->CloseCullFace();
pipeline_creater->Set(Prim::Triangles);
SaveToFile(PIPELINE_FILENAME,pipeline_creater);
}
{
void *data;
uint size=filesystem::LoadFileToMemory(PIPELINE_FILENAME,(void **)&data);
AutoDelete<vulkan::PipelineCreater> pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target,(uchar *)data,size);
pipeline=pipeline_creater->Create();
}
pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
return pipeline;
}

View File

@ -102,6 +102,7 @@ public: //Material
Pipeline * CreatePipeline(MaterialInstance *,RenderTarget *,const OSString &,const Prim &prim=Prim::Triangles,const bool prim_restart=false);
Renderable * CreateRenderable(Material *,const uint32_t vertex_count=0);
Renderable * CreateRenderable(MaterialInstance *,const uint32_t vertex_count=0);
TextRenderable * CreateTextRenderable(Material *);
RenderableInstance *CreateRenderableInstance(Pipeline *p,MaterialInstance *mi,Renderable *r);

2
res

@ -1 +1 @@
Subproject commit 73d977cdbaa2ea287e49943648dbd882c1f9cfff
Subproject commit 2d7cfd18ea4bd4db7303f1d64502d3b862c927f2

View File

@ -103,6 +103,13 @@ Renderable *Database::CreateRenderable(Material *mtl,const uint32_t vertex_count
return ro;
}
Renderable *Database::CreateRenderable(MaterialInstance *mi,const uint32_t vertex_count)
{
if(!mi)return(nullptr);
return CreateRenderable(mi->GetMaterial(),vertex_count);
}
TextRenderable *Database::CreateTextRenderable(Material *mtl)
{
if(!mtl)return(nullptr);