remove RenderablePrimitiveCreater.h, fixed auto_instance.cpp/auto_merge_material_instance.cpp examples, can RUN.
This commit is contained in:
parent
6740764f07
commit
8d3cd8d561
@ -3,7 +3,7 @@
|
|||||||
#include"VulkanAppFramework.h"
|
#include"VulkanAppFramework.h"
|
||||||
#include<hgl/math/Math.h>
|
#include<hgl/math/Math.h>
|
||||||
#include<hgl/filesystem/FileSystem.h>
|
#include<hgl/filesystem/FileSystem.h>
|
||||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
#include<hgl/graph/PrimitiveCreater.h>
|
||||||
#include<hgl/graph/VKVertexInputConfig.h>
|
#include<hgl/graph/VKVertexInputConfig.h>
|
||||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||||
#include<hgl/graph/RenderList.h>
|
#include<hgl/graph/RenderList.h>
|
||||||
@ -16,6 +16,8 @@ constexpr uint32_t SCREEN_HEIGHT=1024;
|
|||||||
|
|
||||||
constexpr uint32_t VERTEX_COUNT=3;
|
constexpr uint32_t VERTEX_COUNT=3;
|
||||||
|
|
||||||
|
constexpr uint32_t TRIANGLE_NUMBER=12;
|
||||||
|
|
||||||
constexpr float position_data[VERTEX_COUNT*2]=
|
constexpr float position_data[VERTEX_COUNT*2]=
|
||||||
{
|
{
|
||||||
0.0, 0.0,
|
0.0, 0.0,
|
||||||
@ -72,18 +74,28 @@ private:
|
|||||||
|
|
||||||
bool InitVBO()
|
bool InitVBO()
|
||||||
{
|
{
|
||||||
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
|
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||||
|
|
||||||
if(!rpc.SetVAB(VAN::Position, VF_V2F, position_data))return(false);
|
rpc.Init("Triangle",VERTEX_COUNT);
|
||||||
if(!rpc.SetVAB(VAN::Color, VF_V4UN8, color_data ))return(false);
|
|
||||||
|
|
||||||
render_obj=rpc.Create(material_instance,pipeline);
|
if(!rpc.WriteVAB(VAN::Position, VF_V2F, position_data))return(false);
|
||||||
|
if(!rpc.WriteVAB(VAN::Color, VF_V4UN8, color_data ))return(false);
|
||||||
|
|
||||||
|
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
|
||||||
|
|
||||||
if(!render_obj)
|
if(!render_obj)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
for(uint i=0;i<12;i++)
|
double rad;
|
||||||
render_root.CreateSubNode(rotate(deg2rad(30*i),Vector3f(0,0,1)),render_obj);
|
Matrix4f mat;
|
||||||
|
|
||||||
|
for(uint i=0;i<TRIANGLE_NUMBER;i++)
|
||||||
|
{
|
||||||
|
rad=deg2rad<double>((360/TRIANGLE_NUMBER)*i); //这里一定要加<float>或<float>,否则结果用int保存会出现问题
|
||||||
|
mat=rotate(rad,Vector3f(0,0,1));
|
||||||
|
|
||||||
|
render_root.CreateSubNode(mat,render_obj);
|
||||||
|
}
|
||||||
|
|
||||||
render_root.RefreshMatrix();
|
render_root.RefreshMatrix();
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#include"VulkanAppFramework.h"
|
#include"VulkanAppFramework.h"
|
||||||
#include<hgl/math/Math.h>
|
#include<hgl/math/Math.h>
|
||||||
#include<hgl/filesystem/FileSystem.h>
|
#include<hgl/filesystem/FileSystem.h>
|
||||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
|
||||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||||
#include<hgl/graph/RenderList.h>
|
#include<hgl/graph/RenderList.h>
|
||||||
#include<hgl/color/Color.h>
|
#include<hgl/color/Color.h>
|
||||||
@ -84,18 +83,28 @@ private:
|
|||||||
|
|
||||||
bool InitVBOAndRenderList()
|
bool InitVBOAndRenderList()
|
||||||
{
|
{
|
||||||
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
|
PrimitiveCreater pc(device,material->GetDefaultVIL());
|
||||||
|
|
||||||
if(!rpc.SetVAB(VAN::Position, VF_V2F, position_data))return(false);
|
if(!pc.Init("Triangle",VERTEX_COUNT))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
if(!pc.WriteVAB(VAN::Position, VF_V2F, position_data))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
Primitive *prim=pc.Create();
|
||||||
|
if(!prim)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
db->Add(prim);
|
||||||
|
|
||||||
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
|
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
|
||||||
{
|
{
|
||||||
render_obj[i].r=rpc.Create(render_obj[i].mi,pipeline);
|
render_obj[i].r=db->CreateRenderable(prim,render_obj[i].mi,pipeline);
|
||||||
|
|
||||||
if(!render_obj[i].r)
|
if(!render_obj[i].r)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
render_root.CreateSubNode(rotate(deg2rad(double(360/DRAW_OBJECT_COUNT*i)),Vector3f(0,0,1)),render_obj[i].r);
|
render_root.CreateSubNode(rotate(deg2rad<double>(double(360/DRAW_OBJECT_COUNT*i)),Vector3f(0,0,1)),render_obj[i].r);
|
||||||
}
|
}
|
||||||
|
|
||||||
render_root.RefreshMatrix();
|
render_root.RefreshMatrix();
|
||||||
|
@ -35,7 +35,7 @@ public:
|
|||||||
PrimitiveCreater(VertexDataManager *);
|
PrimitiveCreater(VertexDataManager *);
|
||||||
virtual ~PrimitiveCreater();
|
virtual ~PrimitiveCreater();
|
||||||
|
|
||||||
virtual bool Init(const AnsiString &name,const VkDeviceSize vertices_count,const VkDeviceSize index_count,IndexType it=IndexType::AUTO); ///<初始化,参数为顶点数量
|
virtual bool Init(const AnsiString &name,const VkDeviceSize vertices_count,const VkDeviceSize index_count=0,IndexType it=IndexType::AUTO); ///<初始化,参数为顶点数量
|
||||||
|
|
||||||
void Clear(); ///<清除创建器数据
|
void Clear(); ///<清除创建器数据
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include<hgl/graph/VKPipeline.h>
|
#include<hgl/graph/VKPipeline.h>
|
||||||
#include<hgl/graph/VKDescriptorSet.h>
|
#include<hgl/graph/VKDescriptorSet.h>
|
||||||
#include<hgl/graph/VKPrimitive.h>
|
#include<hgl/graph/VKPrimitive.h>
|
||||||
|
#include<hgl/graph/PrimitiveCreater.h>
|
||||||
#include<hgl/graph/VKBuffer.h>
|
#include<hgl/graph/VKBuffer.h>
|
||||||
#include<hgl/graph/VKSampler.h>
|
#include<hgl/graph/VKSampler.h>
|
||||||
#include<hgl/graph/VKTexture.h>
|
#include<hgl/graph/VKTexture.h>
|
||||||
@ -148,6 +149,7 @@ public: //Material
|
|||||||
MaterialInstance * CreateMaterialInstance(const mtl::MaterialCreateInfo *,const VILConfig *vil_cfg=nullptr);
|
MaterialInstance * CreateMaterialInstance(const mtl::MaterialCreateInfo *,const VILConfig *vil_cfg=nullptr);
|
||||||
|
|
||||||
Renderable * CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p);
|
Renderable * CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p);
|
||||||
|
Renderable * CreateRenderable(PrimitiveCreater *pc,MaterialInstance *mi,Pipeline *p);
|
||||||
|
|
||||||
Sampler * CreateSampler(VkSamplerCreateInfo *sci=nullptr);
|
Sampler * CreateSampler(VkSamplerCreateInfo *sci=nullptr);
|
||||||
Sampler * CreateSampler(Texture *);
|
Sampler * CreateSampler(Texture *);
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
#ifndef HGL_VK_RENDERABLE_PRIMITIVE_CREATER_INCLUDE
|
|
||||||
#define HGL_VK_RENDERABLE_PRIMITIVE_CREATER_INCLUDE
|
|
||||||
|
|
||||||
#include<hgl/graph/VKRenderResource.h>
|
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
|
||||||
/**
|
|
||||||
* 可绘制图元创建器
|
|
||||||
*/
|
|
||||||
class RenderablePrimitiveCreater
|
|
||||||
{
|
|
||||||
RenderResource *rr;
|
|
||||||
|
|
||||||
VkDeviceSize vertex_count;
|
|
||||||
|
|
||||||
Primitive *prim;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
RenderablePrimitiveCreater(RenderResource *_rr,const AnsiString &name,VkDeviceSize vc)
|
|
||||||
{
|
|
||||||
rr=_rr;
|
|
||||||
vertex_count=vc;
|
|
||||||
|
|
||||||
prim=rr->CreatePrimitive(name,vertex_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
VAB *SetVAB(const AnsiString &name,const VkFormat &fmt,const void *buf)
|
|
||||||
{
|
|
||||||
VAB *vab=rr->CreateVAB(fmt,vertex_count,buf);
|
|
||||||
|
|
||||||
if(!vab)
|
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
prim->SetVAB(name,vab);
|
|
||||||
return(vab);
|
|
||||||
}
|
|
||||||
|
|
||||||
IndexBuffer *SetIndex(const IndexType &it,const void *buf,const VkDeviceSize index_count)
|
|
||||||
{
|
|
||||||
IndexBuffer *ibo=rr->CreateIBO(it,index_count,buf);
|
|
||||||
|
|
||||||
if(!ibo)
|
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
prim->SetIndex(ibo,0,index_count);
|
|
||||||
return(ibo);
|
|
||||||
}
|
|
||||||
|
|
||||||
Renderable *Create(MaterialInstance *mi,Pipeline *p)
|
|
||||||
{
|
|
||||||
return rr->CreateRenderable(prim,mi,p);
|
|
||||||
}
|
|
||||||
};//class RenderablePrimitiveCreater
|
|
||||||
VK_NAMESPACE_END
|
|
||||||
#endif // HGL_VK_RENDERABLE_PRIMITIVE_CREATER_INCLUDE
|
|
@ -16,7 +16,7 @@ struct Material2DCreateConfig:public MaterialCreateConfig
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Material2DCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name,const bool &mi,const Prim &p):MaterialCreateConfig(da,name,mi,p)
|
Material2DCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name,const Prim &p):MaterialCreateConfig(da,name,p)
|
||||||
{
|
{
|
||||||
rt_output.color=1; //输出一个颜色
|
rt_output.color=1; //输出一个颜色
|
||||||
rt_output.depth=false; //不输出深度
|
rt_output.depth=false; //不输出深度
|
||||||
|
@ -17,7 +17,7 @@ struct Material3DCreateConfig:public MaterialCreateConfig
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Material3DCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name,const bool &mi,const Prim &p):MaterialCreateConfig(da,name,mi,p)
|
Material3DCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name,const Prim &p):MaterialCreateConfig(da,name,p)
|
||||||
{
|
{
|
||||||
rt_output.color=1; //输出一个颜色
|
rt_output.color=1; //输出一个颜色
|
||||||
rt_output.depth=true; //不输出深度
|
rt_output.depth=true; //不输出深度
|
||||||
|
@ -29,32 +29,35 @@ struct MaterialCreateConfig
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MaterialCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name,const bool mi,const Prim &p)
|
MaterialCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name,const Prim &p)
|
||||||
{
|
{
|
||||||
dev_attr=da;
|
dev_attr=da;
|
||||||
|
|
||||||
mtl_name=name;
|
mtl_name=name;
|
||||||
|
|
||||||
material_instance=mi;
|
material_instance=false;
|
||||||
|
|
||||||
shader_stage_flag_bit=VK_SHADER_STAGE_VERTEX_BIT|VK_SHADER_STAGE_FRAGMENT_BIT;
|
shader_stage_flag_bit=VK_SHADER_STAGE_VERTEX_BIT|VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||||
|
|
||||||
prim=p;
|
prim=p;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Comp(const MaterialCreateConfig &cfg)const
|
virtual int Comp(const MaterialCreateConfig &cfg)const
|
||||||
{
|
{
|
||||||
int off;
|
int off;
|
||||||
|
|
||||||
off=hgl_cmp(rt_output,cfg.rt_output);
|
off=material_instance-cfg.material_instance;
|
||||||
|
if(off)return(off);
|
||||||
|
|
||||||
|
off=hgl_cmp(rt_output,cfg.rt_output);
|
||||||
if(off)return(off);
|
if(off)return(off);
|
||||||
|
|
||||||
off=(int)prim-(int)cfg.prim;
|
off=(int)prim-(int)cfg.prim;
|
||||||
|
|
||||||
if(off)return(off);
|
if(off)return(off);
|
||||||
|
|
||||||
return shader_stage_flag_bit-cfg.shader_stage_flag_bit;
|
off=shader_stage_flag_bit-cfg.shader_stage_flag_bit;
|
||||||
|
|
||||||
|
return off;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompOperator(const MaterialCreateConfig &,Comp)
|
CompOperator(const MaterialCreateConfig &,Comp)
|
||||||
|
@ -219,6 +219,7 @@ void MaterialRenderList::Render(RenderItem *ri)
|
|||||||
if(!ri->vid->Comp(last_vid))
|
if(!ri->vid->Comp(last_vid))
|
||||||
{
|
{
|
||||||
last_vid=ri->vid;
|
last_vid=ri->vid;
|
||||||
|
last_dd=nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!ri->dd->Comp(last_dd))
|
if(!ri->dd->Comp(last_dd))
|
||||||
|
@ -137,7 +137,6 @@ VABAccess *PrimitiveCreater::AcquireVAB(const AnsiString &name,const VkFormat &a
|
|||||||
return vab_access;
|
return vab_access;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *PrimitiveCreater::MapIBO()
|
void *PrimitiveCreater::MapIBO()
|
||||||
{
|
{
|
||||||
if(!prim_data)return(nullptr);
|
if(!prim_data)return(nullptr);
|
||||||
|
@ -93,6 +93,30 @@ Renderable *RenderResource::CreateRenderable(Primitive *r,MaterialInstance *mi,P
|
|||||||
return ri;
|
return ri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Renderable *RenderResource::CreateRenderable(PrimitiveCreater *pc,MaterialInstance *mi,Pipeline *p)
|
||||||
|
{
|
||||||
|
if(!p||!mi||!pc)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
Primitive *prim=pc->Create();
|
||||||
|
|
||||||
|
if(!prim)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
Renderable *ri=VK_NAMESPACE::CreateRenderable(prim,mi,p);
|
||||||
|
|
||||||
|
if(ri)
|
||||||
|
{
|
||||||
|
Add(prim);
|
||||||
|
Add(ri);
|
||||||
|
|
||||||
|
return ri;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete prim;
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
Sampler *RenderResource::CreateSampler(VkSamplerCreateInfo *sci)
|
Sampler *RenderResource::CreateSampler(VkSamplerCreateInfo *sci)
|
||||||
{
|
{
|
||||||
Sampler *s=device->CreateSampler(sci);
|
Sampler *s=device->CreateSampler(sci);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user