Added WorkObject::CreateRenderable(...)

This commit is contained in:
hyzboy 2025-01-28 22:20:48 +08:00
parent 3c2f7ad705
commit a03770fd00
4 changed files with 50 additions and 18 deletions

View File

@ -2,7 +2,6 @@
#include<hgl/WorkManager.h>
#include<hgl/math/HalfFloat.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/PrimitiveCreater.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
#include<hgl/graph/VKMaterialInstance.h>
@ -28,6 +27,7 @@ constexpr float color_data[VERTEX_COUNT*4]=
0,0,1,1
};
class TestApp:public WorkObject
{
private:
@ -65,14 +65,11 @@ private:
bool InitVBO()
{
PrimitiveCreater rpc(GetDevice(),material_instance->GetVIL());
rpc.Init("Triangle",VERTEX_COUNT);
if(!rpc.WriteVAB(VAN::Position, VF_V2F, position_data))return(false);
if(!rpc.WriteVAB(VAN::Color, VF_V4F, color_data ))return(false);
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
render_obj=CreateRenderable("Triangle",VERTEX_COUNT,material_instance,pipeline,
{
{VAN::Position,VF_V2F,position_data},
{VAN::Color, VF_V4F,color_data}
});
return(render_obj);
}
@ -81,11 +78,6 @@ public:
TestApp(RenderFramework *rf):WorkObject()
{
Join(rf,rf->GetSwapchainRenderTarget());
}
void Join(RenderFramework *rf,IRenderTarget *rt)
{
WorkObject::Join(rf,rt);
if(!InitAutoMaterial())
return;
@ -97,8 +89,7 @@ public:
return;
}
void Tick(double)override
{}
void Tick(double)override{}
void Render(double delta_time,graph::RenderCmdBuffer *cmd)
{

View File

@ -1,6 +1,6 @@
#pragma once
#include<hgl/graph/RenderFramework.h>
#include<hgl/type/object/TickObject.h>
#include<hgl/graph/RenderFramework.h>
#include<hgl/Time.h>
//#include<iostream>
@ -60,6 +60,12 @@ namespace hgl
{
return render_pass->CreatePipeline(args...);
}
graph::Renderable *CreateRenderable( const AnsiString &name,
uint32_t vertices_count,
graph::MaterialInstance *mi,
graph::Pipeline *pipeline,
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list);
};//class WorkObject
/**

View File

@ -25,6 +25,13 @@ constexpr size_t VK_DESCRIPTOR_TYPE_END_RANGE=VK_DESCRIPTOR_TYPE_INPUT_ATTACHMEN
constexpr size_t VK_DESCRIPTOR_TYPE_RANGE_SIZE=VK_DESCRIPTOR_TYPE_END_RANGE-VK_DESCRIPTOR_TYPE_BEGIN_RANGE+1;
#endif//VK_DESCRIPTOR_TYPE_RANGE_SIZE
struct VertexAttribDataPtr
{
const char * name;
const VkFormat format;
const void * data;
};
using BindingMap =Map<AnsiString,int>;
using BindingMapArray =BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE];

View File

@ -3,7 +3,10 @@
#include<hgl/graph/module/SwapchainModule.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/VKRenderTarget.h>
#include<hgl/type/object/TickObject.h>
#include<hgl/graph/VKMaterialInstance.h>
#include<hgl/graph/PrimitiveCreater.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/PrimitiveCreater.h>
#include<hgl/Time.h>
//#include<iostream>
@ -51,4 +54,29 @@ namespace hgl
//std::cout<<"WorkObject::Render End"<<std::endl;
}
graph::Renderable *WorkObject::CreateRenderable( const AnsiString &name,
uint32_t vertices_count,
graph::MaterialInstance *mi,
graph::Pipeline *pipeline,
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list)
{
auto *pc=new graph::PrimitiveCreater(GetDevice(),mi->GetVIL());
pc->Init(name,vertices_count);
for(const auto &vad:vad_list)
{
if(!pc->WriteVAB(vad.name,vad.format,vad.data))
{
delete pc;
return(nullptr);
}
}
auto *result=db->CreateRenderable(pc,mi,pipeline);
delete pc;
return result;
}
}//namespcae hgl