completed AutoMergeMaterialInstance,test ok. next step is to support texture2d array
This commit is contained in:
parent
ddb5a0b77a
commit
6820ee8c74
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit 21e59f0337a3637e646529611f84fa646cb1d9e0
|
||||
Subproject commit 072153aa9135d7de413cc9d63e3019e9853d7045
|
@ -1 +1 @@
|
||||
Subproject commit b66d4003b11a4d4aee1df9084fc4223df1d0aa25
|
||||
Subproject commit bde86e8016713480cd102693708894ab3b6bfabb
|
@ -7,6 +7,7 @@
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/color/Color.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@ -23,15 +24,7 @@ constexpr float position_data[VERTEX_COUNT*2]=
|
||||
0.1, 0.9
|
||||
};
|
||||
|
||||
constexpr float color_data[6][4]=
|
||||
{
|
||||
{1,0,0,1},
|
||||
{1,1,0,1},
|
||||
{0,1,0,1},
|
||||
{0,1,1,1},
|
||||
{0,0,1,1},
|
||||
{1,0,1,1},
|
||||
};
|
||||
constexpr uint DRAW_OBJECT_COUNT=12;
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
@ -40,8 +33,13 @@ private:
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
MaterialInstance * material_instance[6]{};
|
||||
Renderable * render_obj[6] {};
|
||||
Material * material =nullptr;
|
||||
|
||||
struct
|
||||
{
|
||||
MaterialInstance * mi;
|
||||
Renderable * r;
|
||||
}render_obj[DRAW_OBJECT_COUNT]{};
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
@ -57,42 +55,48 @@ private:
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreatePureColor2D(&cfg);
|
||||
|
||||
for(uint i=0;i<6;i++)
|
||||
{
|
||||
material_instance[i]=db->CreateMaterialInstance(mci);
|
||||
material=db->CreateMaterial(mci);
|
||||
|
||||
if(!material_instance[i])
|
||||
if(!material)
|
||||
return(false);
|
||||
|
||||
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
|
||||
{
|
||||
render_obj[i].mi=db->CreateMaterialInstance(material);
|
||||
|
||||
if(!render_obj[i].mi)
|
||||
return(false);
|
||||
|
||||
material_instance[i]->WriteMIData(color_data[i],sizeof(float)*4); //设置MaterialInstance的数据
|
||||
Color4f color=GetColor4f((COLOR)(i+int(COLOR::Blue)),1.0);
|
||||
|
||||
render_obj[i].mi->WriteMIData(color,sizeof(Color4f)); //设置MaterialInstance的数据
|
||||
}
|
||||
}
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
// pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,Prim::Triangles);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
//RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
|
||||
//if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
//
|
||||
//render_obj=rpc.Create(material_instance,pipeline);
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
|
||||
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
|
||||
{
|
||||
render_obj[i].r=rpc.Create(render_obj[i].mi,pipeline);
|
||||
|
||||
//if(!render_obj)
|
||||
// return(false);
|
||||
//
|
||||
//for(uint i=0;i<6;i++)
|
||||
//{
|
||||
// render_root.CreateSubNode(rotate(deg2rad(60*i),Vector3f(0,0,1)),render_obj);
|
||||
//}
|
||||
if(!render_obj[i].r)
|
||||
return(false);
|
||||
|
||||
//render_root.RefreshMatrix();
|
||||
render_root.CreateSubNode(rotate(deg2rad(360/DRAW_OBJECT_COUNT*i),Vector3f(0,0,1)),render_obj[i].r);
|
||||
}
|
||||
|
||||
//render_list->Expend(&render_root);
|
||||
render_root.RefreshMatrix();
|
||||
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
@ -70,13 +70,14 @@ public:
|
||||
|
||||
const bool hasSet (const DescriptorSetType &type)const;
|
||||
|
||||
const VIL * GetDefaultVIL()const;
|
||||
VIL * CreateVIL(const VILConfig *format_map=nullptr);
|
||||
bool Release(VIL *);
|
||||
const uint GetVILCount();
|
||||
|
||||
public:
|
||||
|
||||
const bool HasMI ()const{return !mi_data_bytes;}
|
||||
const bool HasMI ()const{return mi_data_bytes>0;}
|
||||
const uint32_t GetMIDataBytes ()const{return mi_data_bytes;}
|
||||
const uint32_t GetMIMaxCount ()const{return mi_max_count;}
|
||||
|
||||
|
@ -53,9 +53,13 @@ public:
|
||||
const VkExtent2D & GetGranularity()const{return granularity;}
|
||||
|
||||
public:
|
||||
|
||||
Pipeline *CreatePipeline(Material *,const VIL *,const PipelineData *, const Prim &,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(Material *,const VIL *,const InlinePipeline &, const Prim &,const bool prim_restart=false);
|
||||
|
||||
Pipeline *CreatePipeline(Material *mtl, const PipelineData *, const Prim &,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(Material *mtl, const InlinePipeline &, const Prim &,const bool prim_restart=false);
|
||||
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const Prim &,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const PipelineData *, const Prim &,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const Prim &,const bool prim_restart=false);
|
||||
|
@ -56,7 +56,7 @@ constexpr const ShaderBufferSource SBS_LocalToWorld=
|
||||
|
||||
constexpr const char MaterialInstanceStruct[]="MaterialInstance";
|
||||
|
||||
constexpr const ShaderBufferSource SBS_MaterialInstanceData=
|
||||
constexpr const ShaderBufferSource SBS_MaterialInstance=
|
||||
{
|
||||
"MaterialInstanceData",
|
||||
"mtl",
|
||||
|
@ -146,7 +146,7 @@ void MaterialRenderList::Stat()
|
||||
{
|
||||
if(last_pipeline==rn->ri->GetPipeline())
|
||||
if(last_vil==rn->ri->GetMaterialInstance()->GetVIL())
|
||||
if(last_vid==rn->ri->GetVertexInputData())
|
||||
if(last_vid->Comp(rn->ri->GetVertexInputData()))
|
||||
{
|
||||
++ri->count;
|
||||
++rn;
|
||||
|
@ -33,9 +33,9 @@ void RenderAssignBuffer::Bind(MaterialInstance *mi)const
|
||||
const uint assign_binding_count=vil->GetCount(VertexInputGroup::Assign);
|
||||
|
||||
if(assign_binding_count<=0)return;
|
||||
|
||||
|
||||
mi->BindUBO(DescriptorSetType::PerFrame,mtl::SBS_LocalToWorld.name,ubo_l2w);
|
||||
// mi->BindUBO(DescriptorSetType::PerFrame,"Assign",assign_buffer->ubo_mi);
|
||||
mi->BindUBO(DescriptorSetType::PerMaterial,mtl::SBS_MaterialInstance.name,ubo_mi);
|
||||
}
|
||||
|
||||
void RenderAssignBuffer::Clear()
|
||||
@ -91,13 +91,14 @@ void RenderAssignBuffer::WriteNode(RenderNode *render_node,const uint count,cons
|
||||
|
||||
{
|
||||
Matrix4f *tp=(hgl::Matrix4f *)(ubo_l2w->Map());
|
||||
Matrix4f *l2w=tp;
|
||||
|
||||
rn=render_node;
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
{
|
||||
*tp=rn->local_to_world;
|
||||
++tp;
|
||||
*l2w=rn->local_to_world;
|
||||
++l2w;
|
||||
|
||||
*idp=i;
|
||||
++idp;
|
||||
|
@ -6,6 +6,9 @@
|
||||
#include<hgl/type/ActiveMemoryBlockManager.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
void ReleaseVertexInput(VertexInput *vi);
|
||||
|
||||
Material::Material(const AnsiString &n)
|
||||
{
|
||||
name=n;
|
||||
@ -25,7 +28,7 @@ Material::~Material()
|
||||
{
|
||||
SAFE_CLEAR(mi_data_manager);
|
||||
|
||||
SAFE_CLEAR(vertex_input);
|
||||
ReleaseVertexInput(vertex_input);
|
||||
delete shader_maps; //不用SAFE_CLEAR是因为这个一定会有
|
||||
SAFE_CLEAR(desc_manager);
|
||||
SAFE_CLEAR(pipeline_layout_data);
|
||||
@ -44,6 +47,11 @@ const bool Material::hasSet(const DescriptorSetType &dst)const
|
||||
return desc_manager->hasSet(dst);
|
||||
}
|
||||
|
||||
const VIL *Material::GetDefaultVIL()const
|
||||
{
|
||||
return vertex_input->GetDefaultVIL();
|
||||
}
|
||||
|
||||
VIL *Material::CreateVIL(const VILConfig *format_map)
|
||||
{
|
||||
return vertex_input->CreateVIL(format_map);
|
||||
|
@ -78,6 +78,16 @@ Pipeline *RenderPass::CreatePipeline(Material *mtl,const VIL *vil,const InlinePi
|
||||
return CreatePipeline(mtl,vil,GetPipelineData(ip),prim,prim_restart);
|
||||
}
|
||||
|
||||
Pipeline *RenderPass::CreatePipeline(Material *mtl,const PipelineData *pd, const Prim &prim,const bool prim_restart)
|
||||
{
|
||||
return CreatePipeline(mtl,mtl->GetDefaultVIL(),pd,prim,prim_restart);
|
||||
}
|
||||
|
||||
Pipeline *RenderPass::CreatePipeline(Material *mtl,const InlinePipeline &ip, const Prim &prim,const bool prim_restart)
|
||||
{
|
||||
return CreatePipeline(mtl,mtl->GetDefaultVIL(),ip,prim,prim_restart);
|
||||
}
|
||||
|
||||
Pipeline *RenderPass::CreatePipeline(MaterialInstance *mi,const InlinePipeline &ip,const Prim &prim,const bool prim_restart)
|
||||
{
|
||||
if(!mi)return(nullptr);
|
||||
|
@ -124,7 +124,7 @@ Material *RenderResource::CreateMaterial(const mtl::MaterialCreateInfo *mci)
|
||||
ShaderCreateInfoVertex *vert=mci->GetVS();
|
||||
|
||||
if(vert)
|
||||
mtl->vertex_input=new VertexInput(vert->sdm->GetShaderStageIO().input);
|
||||
mtl->vertex_input=GetVertexInput(vert->sdm->GetShaderStageIO().input);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -158,12 +158,12 @@ bool MaterialCreateInfo::SetMaterialInstance(const AnsiString &glsl_codes,const
|
||||
mi_max_count=hgl_min<uint32_t>(ubo_range/data_bytes,HGL_U16_MAX);
|
||||
|
||||
mdi.AddStruct(MaterialInstanceStruct,mi_codes);
|
||||
mdi.AddStruct(SBS_MaterialInstanceData);
|
||||
mdi.AddStruct(SBS_MaterialInstance);
|
||||
|
||||
mi_ubo=new UBODescriptor();
|
||||
|
||||
mi_ubo->type=SBS_MaterialInstanceData.struct_name;
|
||||
hgl::strcpy(mi_ubo->name,DESCRIPTOR_NAME_MAX_LENGTH,SBS_MaterialInstanceData.name);
|
||||
mi_ubo->type=SBS_MaterialInstance.struct_name;
|
||||
hgl::strcpy(mi_ubo->name,DESCRIPTOR_NAME_MAX_LENGTH,SBS_MaterialInstance.name);
|
||||
mi_ubo->stage_flag=shader_stage_flag_bits;
|
||||
|
||||
mdi.AddUBO(shader_stage_flag_bits,DescriptorSetType::PerMaterial,mi_ubo);
|
||||
|
Loading…
x
Reference in New Issue
Block a user