moved relationship to RenderableInstance whose the Material and Renderable.
This commit is contained in:
parent
906662f12b
commit
884cc09259
@ -46,18 +46,19 @@ class TestApp:public VulkanApplicationFramework
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
vulkan::PipelineData * pipeline_data =nullptr;;
|
vulkan::PipelineData * pipeline_data =nullptr;;
|
||||||
|
vulkan::Renderable * render_obj =nullptr;
|
||||||
|
|
||||||
struct MP
|
struct MP
|
||||||
{
|
{
|
||||||
vulkan::Material * material =nullptr;
|
vulkan::Material * material =nullptr;
|
||||||
vulkan::Pipeline * pipeline =nullptr;
|
vulkan::Pipeline * pipeline =nullptr;
|
||||||
vulkan::Renderable * render_obj =nullptr;
|
|
||||||
}mp_normal,mp_hq;
|
}mp_normal,mp_hq;
|
||||||
|
|
||||||
struct MIR
|
struct MIR
|
||||||
{
|
{
|
||||||
MP * mp =nullptr;
|
MP * mp =nullptr;
|
||||||
vulkan::MaterialInstance * material_instance =nullptr;
|
vulkan::MaterialInstance * material_instance =nullptr;
|
||||||
|
vulkan::RenderableInstance *renderable_instance =nullptr;
|
||||||
}mir_nearest,mir_linear,mir_nearest_hq,mir_linear_hq;
|
}mir_nearest,mir_linear,mir_nearest_hq,mir_linear_hq;
|
||||||
|
|
||||||
vulkan::Texture2D * texture =nullptr;
|
vulkan::Texture2D * texture =nullptr;
|
||||||
@ -99,6 +100,18 @@ private:
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool InitRenderObject()
|
||||||
|
{
|
||||||
|
render_obj=db->CreateRenderable(VERTEX_COUNT);
|
||||||
|
if(!render_obj)return(false);
|
||||||
|
|
||||||
|
render_obj->Set(VAN::Position,vertex_buffer);
|
||||||
|
render_obj->Set(VAN::TexCoord,tex_coord_buffer);
|
||||||
|
render_obj->Set(index_buffer);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
vulkan::Sampler *InitSampler(VkFilter filter)
|
vulkan::Sampler *InitSampler(VkFilter filter)
|
||||||
{
|
{
|
||||||
VkSamplerCreateInfo sampler_create_info;
|
VkSamplerCreateInfo sampler_create_info;
|
||||||
@ -139,11 +152,6 @@ private:
|
|||||||
mp->pipeline=CreatePipeline(mp->material,pipeline_data);
|
mp->pipeline=CreatePipeline(mp->material,pipeline_data);
|
||||||
if(!mp->pipeline)return(false);
|
if(!mp->pipeline)return(false);
|
||||||
|
|
||||||
mp->render_obj=db->CreateRenderable(mp->material,VERTEX_COUNT);
|
|
||||||
mp->render_obj->Set(VAN::Position,vertex_buffer);
|
|
||||||
mp->render_obj->Set(VAN::TexCoord,tex_coord_buffer);
|
|
||||||
mp->render_obj->Set(index_buffer);
|
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,18 +176,17 @@ private:
|
|||||||
|
|
||||||
mir->mp=mp;
|
mir->mp=mp;
|
||||||
|
|
||||||
|
mir->renderable_instance=db->CreateRenderableInstance(render_obj,mir->material_instance,mp->pipeline);
|
||||||
|
|
||||||
|
if(!mir->renderable_instance)
|
||||||
|
return(false);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Add(struct MIR *mir,const Matrix4f &offset)
|
bool Add(struct MIR *mir,const Matrix4f &offset)
|
||||||
{
|
{
|
||||||
RenderableInstance *ri=db->CreateRenderableInstance(mir->mp->pipeline,
|
render_root.Add(mir->renderable_instance,offset);
|
||||||
mir->material_instance,
|
|
||||||
mir->mp->render_obj);
|
|
||||||
|
|
||||||
if(!ri)return(false);
|
|
||||||
|
|
||||||
render_root.Add(ri,offset);
|
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
@ -207,6 +214,9 @@ public:
|
|||||||
if(!InitVBO())
|
if(!InitVBO())
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
|
if(!InitRenderObject())
|
||||||
|
return(false);
|
||||||
|
|
||||||
if(!InitTexture())
|
if(!InitTexture())
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
|
@ -173,39 +173,39 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildCommandBuffer(uint32_t index,vulkan::Pipeline *p,vulkan::MaterialInstance *mi,vulkan::Renderable *r)
|
void BuildCommandBuffer(uint32_t index,vulkan::RenderableInstance *ri)
|
||||||
{
|
{
|
||||||
if(!p||!mi||!r)
|
if(!ri)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const vulkan::IndexBuffer *ib=r->GetIndexBuffer();
|
const vulkan::IndexBuffer *ib=ri->GetIndexBuffer();
|
||||||
|
|
||||||
vulkan::CommandBuffer *cb=cmd_buf[index];
|
vulkan::CommandBuffer *cb=cmd_buf[index];
|
||||||
|
|
||||||
cb->Begin();
|
cb->Begin();
|
||||||
cb->BeginRenderPass(sc_render_target->GetRenderPass(),sc_render_target->GetFramebuffer(index));
|
cb->BeginRenderPass(sc_render_target->GetRenderPass(),sc_render_target->GetFramebuffer(index));
|
||||||
cb->Bind(p);
|
cb->BindPipeline(ri->GetPipeline());
|
||||||
cb->Bind(mi->GetDescriptorSets());
|
cb->BindDescriptorSets(ri->GetDescriptorSets());
|
||||||
cb->Bind(r);
|
cb->BindVAB(ri);
|
||||||
|
|
||||||
if (ib)
|
if (ib)
|
||||||
cb->DrawIndexed(ib->GetCount());
|
cb->DrawIndexed(ib->GetCount());
|
||||||
else
|
else
|
||||||
cb->Draw(r->GetDrawCount());
|
cb->Draw(ri->GetDrawCount());
|
||||||
|
|
||||||
cb->EndRenderPass();
|
cb->EndRenderPass();
|
||||||
cb->End();
|
cb->End();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildCommandBuffer(vulkan::Pipeline *p,vulkan::MaterialInstance *mi,vulkan::Renderable *r)
|
void BuildCommandBuffer(vulkan::RenderableInstance *ri)
|
||||||
{
|
{
|
||||||
for(int32_t i=0;i<swap_chain_count;i++)
|
for(int32_t i=0;i<swap_chain_count;i++)
|
||||||
BuildCommandBuffer(i,p,mi,r);
|
BuildCommandBuffer(i,ri);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildCurrentCommandBuffer(vulkan::Pipeline *p,vulkan::MaterialInstance *mi,vulkan::Renderable *r)
|
void BuildCurrentCommandBuffer(vulkan::RenderableInstance *ri)
|
||||||
{
|
{
|
||||||
BuildCommandBuffer(sc_render_target->GetCurrentFrameIndices(),p,mi,r);
|
BuildCommandBuffer(sc_render_target->GetCurrentFrameIndices(),ri);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildCommandBuffer(uint32_t index,RenderList *rl)
|
void BuildCommandBuffer(uint32_t index,RenderList *rl)
|
||||||
|
@ -9,8 +9,6 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
namespace graph
|
namespace graph
|
||||||
{
|
{
|
||||||
class RenderableInstance;
|
|
||||||
|
|
||||||
class RenderList
|
class RenderList
|
||||||
{
|
{
|
||||||
vulkan::CommandBuffer *cmd_buf;
|
vulkan::CommandBuffer *cmd_buf;
|
||||||
@ -22,10 +20,10 @@ namespace hgl
|
|||||||
vulkan::PushConstant * last_pc;
|
vulkan::PushConstant * last_pc;
|
||||||
vulkan::Pipeline * last_pipeline;
|
vulkan::Pipeline * last_pipeline;
|
||||||
vulkan::MaterialInstance * last_mat_inst;
|
vulkan::MaterialInstance * last_mat_inst;
|
||||||
vulkan::Renderable * last_renderable;
|
vulkan::RenderableInstance *last_ri;
|
||||||
|
|
||||||
void Render(SceneNode *,RenderableInstance *);
|
void Render(SceneNode *,vulkan::RenderableInstance *);
|
||||||
void Render(SceneNode *,List<RenderableInstance *> &);
|
void Render(SceneNode *,List<vulkan::RenderableInstance *> &);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -35,7 +33,7 @@ namespace hgl
|
|||||||
last_pc=nullptr;
|
last_pc=nullptr;
|
||||||
last_pipeline=nullptr;
|
last_pipeline=nullptr;
|
||||||
last_mat_inst=nullptr;
|
last_mat_inst=nullptr;
|
||||||
last_renderable=nullptr;
|
last_ri=nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
~RenderList()=default;
|
~RenderList()=default;
|
||||||
|
@ -1,76 +0,0 @@
|
|||||||
#ifndef HGL_GRAPH_RENDERABLE_INSTANCE_INCLUDE
|
|
||||||
#define HGL_GRAPH_RENDERABLE_INSTANCE_INCLUDE
|
|
||||||
|
|
||||||
#include<hgl/graph/vulkan/VKRenderable.h>
|
|
||||||
#include<hgl/graph/vulkan/VKPipeline.h>
|
|
||||||
#include<hgl/graph/vulkan/VKDescriptorSets.h>
|
|
||||||
namespace hgl
|
|
||||||
{
|
|
||||||
namespace graph
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* 可渲染对象节点
|
|
||||||
*/
|
|
||||||
class RenderableInstance
|
|
||||||
{
|
|
||||||
vulkan::Pipeline * pipeline;
|
|
||||||
vulkan::MaterialInstance *mat_inst;
|
|
||||||
vulkan::Renderable * render_obj;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
RenderableInstance(vulkan::Pipeline *p,vulkan::MaterialInstance *mi,vulkan::Renderable *r):pipeline(p),mat_inst(mi),render_obj(r){}
|
|
||||||
virtual ~RenderableInstance()
|
|
||||||
{
|
|
||||||
//需要在这里添加删除pipeline/desc_sets/render_obj引用计数的代码
|
|
||||||
}
|
|
||||||
|
|
||||||
vulkan::Pipeline * GetPipeline (){return pipeline;}
|
|
||||||
vulkan::MaterialInstance * GetMaterialInstance (){return mat_inst;}
|
|
||||||
vulkan::Renderable * GetRenderable (){return render_obj;}
|
|
||||||
const AABB & GetBoundingBox ()const{return render_obj->GetBoundingBox();}
|
|
||||||
|
|
||||||
const int Comp(const RenderableInstance *ri)const
|
|
||||||
{
|
|
||||||
//绘制顺序:
|
|
||||||
|
|
||||||
// ARM Mali GPU : 不透明、AlphaTest、半透明
|
|
||||||
// Adreno/NV/AMD: AlphaTest、不透明、半透明
|
|
||||||
// PowerVR: 同Adreno/NV/AMD,但不透明部分可以不排序
|
|
||||||
|
|
||||||
if(pipeline->IsAlphaBlend())
|
|
||||||
{
|
|
||||||
if(!ri->pipeline->IsAlphaBlend())
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(ri->pipeline->IsAlphaBlend())
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(pipeline->IsAlphaTest())
|
|
||||||
{
|
|
||||||
if(!ri->pipeline->IsAlphaTest())
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(ri->pipeline->IsAlphaTest())
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(pipeline!=ri->pipeline)
|
|
||||||
return pipeline-ri->pipeline;
|
|
||||||
|
|
||||||
if(mat_inst!=ri->mat_inst)
|
|
||||||
return int64(mat_inst)-int64(ri->mat_inst);
|
|
||||||
|
|
||||||
return render_obj-ri->render_obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
CompOperator(const RenderableInstance *,Comp)
|
|
||||||
};//class RenderableInstance
|
|
||||||
}//namespace graph
|
|
||||||
}//namespace hgl
|
|
||||||
#endif//HGL_GRAPH_RENDERABLE_INSTANCE_INCLUDE
|
|
@ -11,7 +11,6 @@ namespace hgl
|
|||||||
class SceneNode;
|
class SceneNode;
|
||||||
struct Camera;
|
struct Camera;
|
||||||
class RenderList;
|
class RenderList;
|
||||||
class RenderableInstance;
|
|
||||||
|
|
||||||
using RenderListCompFunc=float (*)(Camera *,SceneNode *,SceneNode *); ///<渲染列表排序比较函数
|
using RenderListCompFunc=float (*)(Camera *,SceneNode *,SceneNode *); ///<渲染列表排序比较函数
|
||||||
|
|
||||||
@ -41,7 +40,7 @@ namespace hgl
|
|||||||
|
|
||||||
ObjectList<SceneNode> SubNode; ///<子节点
|
ObjectList<SceneNode> SubNode; ///<子节点
|
||||||
|
|
||||||
List<RenderableInstance *> renderable_instances; ///<可渲染实例
|
List<vulkan::RenderableInstance *> renderable_instances; ///<可渲染实例
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -75,9 +74,9 @@ namespace hgl
|
|||||||
void Add(SceneNode *n){if(n)SubNode.Add(n);} ///<增加一个子节点
|
void Add(SceneNode *n){if(n)SubNode.Add(n);} ///<增加一个子节点
|
||||||
void ClearSubNode(){SubNode.ClearData();} ///<清除子节点
|
void ClearSubNode(){SubNode.ClearData();} ///<清除子节点
|
||||||
|
|
||||||
void Add(RenderableInstance *ri){if(ri)renderable_instances.Add(ri);} ///<增加渲染实例
|
void Add(vulkan::RenderableInstance *ri){if(ri)renderable_instances.Add(ri);} ///<增加渲染实例
|
||||||
|
|
||||||
void Add(RenderableInstance *ri,const Matrix4f &mat)
|
void Add(vulkan::RenderableInstance *ri,const Matrix4f &mat)
|
||||||
{
|
{
|
||||||
SceneNode *sn=new SceneNode(mat);
|
SceneNode *sn=new SceneNode(mat);
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
if(!data||offset>=count)
|
if(!data||offset>=count)
|
||||||
{
|
{
|
||||||
LOG_HINT(OS_TEXT("VertexAttribBuffer::Get() out,offset:")+OSString::valueOf(offset));
|
LOG_HINT(OS_TEXT("VertexAttribDataAccess::Get() out,offset:")+OSString::valueOf(offset));
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
if(access)
|
if(access)
|
||||||
{
|
{
|
||||||
LOG_HINT(OS_TEXT("VertexAttribBuffer::Begin() access!=0,offset:")+OSString::valueOf(offset));
|
LOG_HINT(OS_TEXT("VertexAttribDataAccess::Begin() access!=0,offset:")+OSString::valueOf(offset));
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
if(!this->access||this->access+C*number>this->data_end)
|
if(!this->access||this->access+C*number>this->data_end)
|
||||||
{
|
{
|
||||||
LOG_HINT(OS_TEXT("VertexAttribBuffer::Write(const T *,number) out,number:")+OSString::valueOf(number));
|
LOG_HINT(OS_TEXT("VertexAttribDataAccess::Write(const T *,number) out,number:")+OSString::valueOf(number));
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ namespace hgl
|
|||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
};//class VertexAttribBuffer
|
};//class VertexAttribDataAccess
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 一元数据缓冲区
|
* 一元数据缓冲区
|
||||||
|
@ -63,6 +63,7 @@ class DescriptorSets;
|
|||||||
class VertexAttributeBinding;
|
class VertexAttributeBinding;
|
||||||
|
|
||||||
class Renderable;
|
class Renderable;
|
||||||
|
class RenderableInstance;
|
||||||
|
|
||||||
class Database;
|
class Database;
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ public:
|
|||||||
bool BeginRenderPass(VkRenderPass rp,VkFramebuffer fb);
|
bool BeginRenderPass(VkRenderPass rp,VkFramebuffer fb);
|
||||||
bool BeginRenderPass(RenderTarget *rt);
|
bool BeginRenderPass(RenderTarget *rt);
|
||||||
|
|
||||||
bool Bind(Pipeline *p)
|
bool BindPipeline(Pipeline *p)
|
||||||
{
|
{
|
||||||
if(!p)return(false);
|
if(!p)return(false);
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ public:
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Bind(DescriptorSets *dsl)
|
bool BindDescriptorSets(DescriptorSets *dsl)
|
||||||
{
|
{
|
||||||
if(!dsl)return(false);
|
if(!dsl)return(false);
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ public:
|
|||||||
|
|
||||||
void PushConstants(const void *data,const uint32_t size){vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,0,size,data);}
|
void PushConstants(const void *data,const uint32_t size){vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,0,size,data);}
|
||||||
|
|
||||||
bool Bind(Renderable *);
|
bool BindVAB(RenderableInstance *);
|
||||||
|
|
||||||
void SetViewport (uint32_t first,uint32_t count,const VkViewport *vp) {vkCmdSetViewport(cmd_buf,first,count,vp);}
|
void SetViewport (uint32_t first,uint32_t count,const VkViewport *vp) {vkCmdSetViewport(cmd_buf,first,count,vp);}
|
||||||
void SetScissor (uint32_t first,uint32_t count,const VkRect2D *sci) {vkCmdSetScissor(cmd_buf,first,count,sci);}
|
void SetScissor (uint32_t first,uint32_t count,const VkRect2D *sci) {vkCmdSetScissor(cmd_buf,first,count,sci);}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include<hgl/graph/vulkan/VKTexture.h>
|
#include<hgl/graph/vulkan/VKTexture.h>
|
||||||
#include<hgl/graph/vulkan/VKMaterialInstance.h>
|
#include<hgl/graph/vulkan/VKMaterialInstance.h>
|
||||||
#include<hgl/graph/VertexAttribData.h>
|
#include<hgl/graph/VertexAttribData.h>
|
||||||
#include<hgl/graph/RenderableInstance.h>
|
#include<hgl/graph/vulkan/VKRenderableInstance.h>
|
||||||
#include<hgl/graph/font/TextRenderable.h>
|
#include<hgl/graph/font/TextRenderable.h>
|
||||||
#include<hgl/type/ResManage.h>
|
#include<hgl/type/ResManage.h>
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
@ -103,11 +103,10 @@ public: //Material
|
|||||||
Pipeline * CreatePipeline(Material *,RenderTarget *,const OSString &,const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
Pipeline * CreatePipeline(Material *,RenderTarget *,const OSString &,const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
||||||
Pipeline * CreatePipeline(MaterialInstance *,RenderTarget *,const OSString &,const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
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(const uint32_t vertex_count=0);
|
||||||
Renderable * CreateRenderable(MaterialInstance *,const uint32_t vertex_count=0);
|
|
||||||
TextRenderable * CreateTextRenderable(Material *);
|
TextRenderable * CreateTextRenderable(Material *);
|
||||||
|
|
||||||
RenderableInstance *CreateRenderableInstance(Pipeline *p,MaterialInstance *mi,Renderable *r);
|
RenderableInstance *CreateRenderableInstance(Renderable *r,MaterialInstance *mi,Pipeline *p);
|
||||||
|
|
||||||
Sampler * CreateSampler(VkSamplerCreateInfo *sci=nullptr);
|
Sampler * CreateSampler(VkSamplerCreateInfo *sci=nullptr);
|
||||||
|
|
||||||
|
@ -62,7 +62,6 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Renderable * CreateRenderable (const uint32_t draw_count=0);
|
|
||||||
MaterialInstance * CreateInstance ();
|
MaterialInstance * CreateInstance ();
|
||||||
};//class Material
|
};//class Material
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include<hgl/graph/vulkan/VK.h>
|
#include<hgl/graph/vulkan/VK.h>
|
||||||
#include<hgl/graph/vulkan/VKBuffer.h>
|
#include<hgl/graph/vulkan/VKBuffer.h>
|
||||||
|
#include<hgl/type/Map.h>
|
||||||
#include<hgl/type/String.h>
|
#include<hgl/type/String.h>
|
||||||
#include<hgl/math/Math.h>
|
#include<hgl/math/Math.h>
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
@ -13,12 +14,18 @@ VK_NAMESPACE_BEGIN
|
|||||||
*/
|
*/
|
||||||
class Renderable
|
class Renderable
|
||||||
{
|
{
|
||||||
const VertexShaderModule *vertex_sm;
|
struct BufferData
|
||||||
|
{
|
||||||
|
VAB *buf;
|
||||||
|
VkDeviceSize offset;
|
||||||
|
|
||||||
int buf_count;
|
public:
|
||||||
VkBuffer *buf_list=nullptr;
|
|
||||||
VkDeviceSize *buf_offset=nullptr;
|
|
||||||
|
|
||||||
|
CompOperatorMemcmp(const BufferData &);
|
||||||
|
};
|
||||||
|
|
||||||
|
Map<UTF8String,BufferData> buffer_list;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
uint32_t draw_count;
|
uint32_t draw_count;
|
||||||
@ -41,16 +48,15 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Renderable(const VertexShaderModule *,const uint32_t dc=0);
|
Renderable(const uint32_t dc=0):draw_count(dc){}
|
||||||
virtual ~Renderable();
|
virtual ~Renderable()=default;
|
||||||
|
|
||||||
const uint GetRefCount()const{return ref_count;}
|
const uint GetRefCount()const{return ref_count;}
|
||||||
|
|
||||||
void SetBoundingBox(const AABB &aabb){BoundingBox=aabb;}
|
void SetBoundingBox(const AABB &aabb){BoundingBox=aabb;}
|
||||||
const AABB &GetBoundingBox()const {return BoundingBox;}
|
const AABB &GetBoundingBox()const {return BoundingBox;}
|
||||||
|
|
||||||
bool Set(const int stage_input_binding, VAB *vb,VkDeviceSize offset=0);
|
bool Set(const UTF8String &name,VAB *vb,VkDeviceSize offset=0);
|
||||||
bool Set(const AnsiString &name, VAB *vb,VkDeviceSize offset=0);
|
|
||||||
|
|
||||||
bool Set(IndexBuffer *ib,VkDeviceSize offset=0)
|
bool Set(IndexBuffer *ib,VkDeviceSize offset=0)
|
||||||
{
|
{
|
||||||
@ -72,12 +78,12 @@ public:
|
|||||||
return draw_count;
|
return draw_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int GetBufferCount ()const{return buf_count;}
|
VAB * GetVAB(const UTF8String &,VkDeviceSize *);
|
||||||
const VkBuffer * GetBuffer ()const{return buf_list;}
|
VkBuffer GetBuffer(const UTF8String &,VkDeviceSize *);
|
||||||
const VkDeviceSize * GetOffset ()const{return buf_offset;}
|
const int GetBufferCount()const{return buffer_list.GetCount();}
|
||||||
|
|
||||||
IndexBuffer * GetIndexBuffer() {return indices_buffer;}
|
IndexBuffer * GetIndexBuffer() {return indices_buffer;}
|
||||||
const VkDeviceSize GetIndexOffset()const{return indices_offset;}
|
const VkDeviceSize GetIndexBufferOffset()const {return indices_offset;}
|
||||||
};//class Renderable
|
};//class Renderable
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
#endif//HGL_GRAPH_VULKAN_RENDERABLE_INCLUDE
|
#endif//HGL_GRAPH_VULKAN_RENDERABLE_INCLUDE
|
||||||
|
92
inc/hgl/graph/vulkan/VKRenderableInstance.h
Normal file
92
inc/hgl/graph/vulkan/VKRenderableInstance.h
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
#ifndef HGL_GRAPH_RENDERABLE_INSTANCE_INCLUDE
|
||||||
|
#define HGL_GRAPH_RENDERABLE_INSTANCE_INCLUDE
|
||||||
|
|
||||||
|
#include<hgl/graph/vulkan/VKRenderable.h>
|
||||||
|
#include<hgl/graph/vulkan/VKPipeline.h>
|
||||||
|
#include<hgl/graph/vulkan/VKDescriptorSets.h>
|
||||||
|
#include<hgl/graph/vulkan/VKMaterialInstance.h>
|
||||||
|
VK_NAMESPACE_BEGIN
|
||||||
|
/**
|
||||||
|
* 可渲染对象节点
|
||||||
|
*/
|
||||||
|
class RenderableInstance
|
||||||
|
{
|
||||||
|
Pipeline * pipeline;
|
||||||
|
MaterialInstance *mat_inst;
|
||||||
|
Renderable * render_obj;
|
||||||
|
|
||||||
|
uint32_t buffer_count;
|
||||||
|
VkBuffer *buffer_list;
|
||||||
|
VkDeviceSize *buffer_size;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
friend RenderableInstance *CreateRenderableInstance(Renderable *,MaterialInstance *,Pipeline *);
|
||||||
|
|
||||||
|
RenderableInstance(Renderable *,MaterialInstance *,Pipeline *,const uint32_t,VkBuffer *,VkDeviceSize *);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual ~RenderableInstance();
|
||||||
|
|
||||||
|
vulkan::Pipeline * GetPipeline (){return pipeline;}
|
||||||
|
vulkan::MaterialInstance * GetMaterialInstance (){return mat_inst;}
|
||||||
|
vulkan::Renderable * GetRenderable (){return render_obj;}
|
||||||
|
const AABB & GetBoundingBox ()const{return render_obj->GetBoundingBox();}
|
||||||
|
|
||||||
|
const uint32_t GetBufferCount ()const{return buffer_count;}
|
||||||
|
VkBuffer * GetBuffer ()const{return buffer_list;}
|
||||||
|
VkDeviceSize * GetBufferSize ()const{return buffer_size;}
|
||||||
|
IndexBuffer * GetIndexBuffer ()const{return render_obj->GetIndexBuffer();}
|
||||||
|
const uint32_t GetIndexBufferOffset ()const{return render_obj->GetIndexBufferOffset();}
|
||||||
|
const uint32_t GetDrawCount ()const{return render_obj->GetDrawCount();}
|
||||||
|
|
||||||
|
DescriptorSets *GetDescriptorSets ()const{return mat_inst->GetDescriptorSets();}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
const int Comp(const RenderableInstance *ri)const
|
||||||
|
{
|
||||||
|
//绘制顺序:
|
||||||
|
|
||||||
|
// ARM Mali GPU : 不透明、AlphaTest、半透明
|
||||||
|
// Adreno/NV/AMD: AlphaTest、不透明、半透明
|
||||||
|
// PowerVR: 同Adreno/NV/AMD,但不透明部分可以不排序
|
||||||
|
|
||||||
|
if(pipeline->IsAlphaBlend())
|
||||||
|
{
|
||||||
|
if(!ri->pipeline->IsAlphaBlend())
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(ri->pipeline->IsAlphaBlend())
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pipeline->IsAlphaTest())
|
||||||
|
{
|
||||||
|
if(!ri->pipeline->IsAlphaTest())
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(ri->pipeline->IsAlphaTest())
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pipeline!=ri->pipeline)
|
||||||
|
return pipeline-ri->pipeline;
|
||||||
|
|
||||||
|
if(mat_inst!=ri->mat_inst)
|
||||||
|
return int64(mat_inst)-int64(ri->mat_inst);
|
||||||
|
|
||||||
|
return render_obj-ri->render_obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
CompOperator(const RenderableInstance *,Comp)
|
||||||
|
};//class RenderableInstance
|
||||||
|
|
||||||
|
RenderableInstance *CreateRenderableInstance(Renderable *,MaterialInstance *,Pipeline *);
|
||||||
|
VK_NAMESPACE_END
|
||||||
|
#endif//HGL_GRAPH_RENDERABLE_INSTANCE_INCLUDE
|
@ -80,7 +80,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
const int GetStageInputBinding(const AnsiString &name)const{return shader_resource->GetStageInputBinding(name);}
|
const int GetStageInputBinding(const AnsiString &name)const{return shader_resource->GetStageInputBinding(name);}
|
||||||
const ShaderStage * GetStageInput (const AnsiString &name)const{return shader_resource->GetStageInput(name);}
|
const ShaderStage * GetStageInput (const AnsiString &name)const{return shader_resource->GetStageInput(name);}
|
||||||
const uint GetStageInputCount () const{return shader_resource->GetStageInputCount();}
|
const uint GetStageInputCount () const{return shader_resource->GetStageInputCount();}
|
||||||
|
const ShaderStageList & GetStageInputs () const{return shader_resource->GetStageInputs();}
|
||||||
|
|
||||||
const uint32_t GetAttrCount()const{return attr_count;}
|
const uint32_t GetAttrCount()const{return attr_count;}
|
||||||
|
|
||||||
|
@ -88,8 +88,10 @@ SOURCE_GROUP("Render Pass" FILES ${VK_RENDER_PASS_SOURCE})
|
|||||||
|
|
||||||
SET(VK_RENDERABLE_SOURCE ${RD_INCLUDE_PATH}/VKVertexAttributeBinding.h
|
SET(VK_RENDERABLE_SOURCE ${RD_INCLUDE_PATH}/VKVertexAttributeBinding.h
|
||||||
${RD_INCLUDE_PATH}/VKRenderable.h
|
${RD_INCLUDE_PATH}/VKRenderable.h
|
||||||
|
${RD_INCLUDE_PATH}/VKRenderableInstance.h
|
||||||
VKVertexAttributeBinding.cpp
|
VKVertexAttributeBinding.cpp
|
||||||
VKRenderable.cpp
|
VKRenderable.cpp
|
||||||
|
VKRenderableInstance.cpp
|
||||||
VKTileData.cpp
|
VKTileData.cpp
|
||||||
VKTileFont.cpp)
|
VKTileFont.cpp)
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include<hgl/graph/vulkan/VKBuffer.h>
|
#include<hgl/graph/vulkan/VKBuffer.h>
|
||||||
#include<hgl/graph/vulkan/VKMaterial.h>
|
#include<hgl/graph/vulkan/VKMaterial.h>
|
||||||
#include<hgl/graph/vulkan/VKRenderable.h>
|
#include<hgl/graph/vulkan/VKRenderable.h>
|
||||||
|
#include<hgl/graph/vulkan/VKRenderableInstance.h>
|
||||||
#include<hgl/graph/vulkan/VKDescriptorSets.h>
|
#include<hgl/graph/vulkan/VKDescriptorSets.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
@ -102,22 +103,22 @@ bool CommandBuffer::BeginRenderPass(RenderTarget *rt)
|
|||||||
return BeginRenderPass(rt->GetRenderPass(),rt->GetFramebuffer());
|
return BeginRenderPass(rt->GetRenderPass(),rt->GetFramebuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CommandBuffer::Bind(Renderable *render_obj)
|
bool CommandBuffer::BindVAB(RenderableInstance *ri)
|
||||||
{
|
{
|
||||||
if(!render_obj)
|
if(!ri)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
const uint count=render_obj->GetBufferCount();
|
const uint count=ri->GetBufferCount();
|
||||||
|
|
||||||
if(count<=0)
|
if(count<=0)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
vkCmdBindVertexBuffers(cmd_buf,0,count,render_obj->GetBuffer(),render_obj->GetOffset());
|
vkCmdBindVertexBuffers(cmd_buf,0,count,ri->GetBuffer(),ri->GetBufferSize());
|
||||||
|
|
||||||
IndexBuffer *indices_buffer=render_obj->GetIndexBuffer();
|
IndexBuffer *indices_buffer=ri->GetIndexBuffer();
|
||||||
|
|
||||||
if(indices_buffer)
|
if(indices_buffer)
|
||||||
vkCmdBindIndexBuffer(cmd_buf,indices_buffer->GetBuffer(),render_obj->GetIndexOffset(),VkIndexType(indices_buffer->GetType()));
|
vkCmdBindIndexBuffer(cmd_buf,indices_buffer->GetBuffer(),ri->GetIndexBufferOffset(),VkIndexType(indices_buffer->GetType()));
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include<hgl/graph/vulkan/VKDatabase.h>
|
#include<hgl/graph/vulkan/VKDatabase.h>
|
||||||
#include<hgl/graph/vulkan/VKDevice.h>
|
#include<hgl/graph/vulkan/VKDevice.h>
|
||||||
#include<hgl/graph/RenderableInstance.h>
|
#include<hgl/graph/vulkan/VKRenderableInstance.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
VAB *Database::CreateVAB(VkFormat format,uint32_t count,const void *data,SharingMode sharing_mode)
|
VAB *Database::CreateVAB(VkFormat format,uint32_t count,const void *data,SharingMode sharing_mode)
|
||||||
@ -101,11 +101,11 @@ Pipeline *Database::CreatePipeline(MaterialInstance *mi,RenderTarget *rt,const O
|
|||||||
return CreatePipeline(mi->GetMaterial(),rt,filename,prim,prim_restart);
|
return CreatePipeline(mi->GetMaterial(),rt,filename,prim,prim_restart);
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderable *Database::CreateRenderable(Material *mtl,const uint32_t vertex_count)
|
Renderable *Database::CreateRenderable(const uint32_t vertex_count)
|
||||||
{
|
{
|
||||||
if(!mtl)return(nullptr);
|
if(!vertex_count)return(nullptr);
|
||||||
|
|
||||||
Renderable *ro=mtl->CreateRenderable(vertex_count);
|
Renderable *ro=new Renderable(vertex_count);
|
||||||
|
|
||||||
if(ro)
|
if(ro)
|
||||||
Add(ro);
|
Add(ro);
|
||||||
@ -113,13 +113,6 @@ Renderable *Database::CreateRenderable(Material *mtl,const uint32_t vertex_count
|
|||||||
return ro;
|
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)
|
TextRenderable *Database::CreateTextRenderable(Material *mtl)
|
||||||
{
|
{
|
||||||
if(!mtl)return(nullptr);
|
if(!mtl)return(nullptr);
|
||||||
@ -132,12 +125,12 @@ TextRenderable *Database::CreateTextRenderable(Material *mtl)
|
|||||||
return tr;
|
return tr;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderableInstance *Database::CreateRenderableInstance(Pipeline *p,MaterialInstance *mi,Renderable *r)
|
RenderableInstance *Database::CreateRenderableInstance(Renderable *r,MaterialInstance *mi,Pipeline *p)
|
||||||
{
|
{
|
||||||
if(!p||!mi||!r)
|
if(!p||!mi||!r)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
RenderableInstance *ri=new RenderableInstance(p,mi,r);
|
RenderableInstance *ri=VK_NAMESPACE::CreateRenderableInstance(r,mi,p);
|
||||||
|
|
||||||
if(ri)
|
if(ri)
|
||||||
Add(ri);
|
Add(ri);
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include<hgl/graph/vulkan/VKShaderModule.h>
|
#include<hgl/graph/vulkan/VKShaderModule.h>
|
||||||
#include<hgl/graph/vulkan/ShaderModuleMap.h>
|
#include<hgl/graph/vulkan/ShaderModuleMap.h>
|
||||||
#include<hgl/graph/vulkan/VKVertexAttributeBinding.h>
|
#include<hgl/graph/vulkan/VKVertexAttributeBinding.h>
|
||||||
#include<hgl/graph/vulkan/VKRenderable.h>
|
|
||||||
#include<hgl/graph/vulkan/VKBuffer.h>
|
#include<hgl/graph/vulkan/VKBuffer.h>
|
||||||
#include"VKDescriptorSetLayoutCreater.h"
|
#include"VKDescriptorSetLayoutCreater.h"
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
@ -154,9 +153,4 @@ DescriptorSets *Material::CreateDescriptorSets()const
|
|||||||
{
|
{
|
||||||
return dsl_creater->Create();
|
return dsl_creater->Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderable *Material::CreateRenderable(const uint32_t draw_count)
|
|
||||||
{
|
|
||||||
return(new Renderable(vertex_sm,draw_count));
|
|
||||||
}
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -3,43 +3,60 @@
|
|||||||
#include<hgl/graph/vulkan/VKShaderModule.h>
|
#include<hgl/graph/vulkan/VKShaderModule.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
Renderable::Renderable(const VertexShaderModule *vsm,const uint32_t dc)
|
//bool Renderable::Set(const int stage_input_binding,VAB *vab,VkDeviceSize offset)
|
||||||
|
//{
|
||||||
|
// if(stage_input_binding<0||stage_input_binding>=buf_count||!vab)return(false);
|
||||||
|
//
|
||||||
|
// const VkVertexInputBindingDescription *desc=vertex_sm->GetDesc(stage_input_binding);
|
||||||
|
// const VkVertexInputAttributeDescription *attr=vertex_sm->GetAttr(stage_input_binding);
|
||||||
|
//
|
||||||
|
// if(vab->GetFormat()!=attr->format)return(false);
|
||||||
|
// if(vab->GetStride()!=desc->stride)return(false);
|
||||||
|
//
|
||||||
|
// //format信息来自于shader,实际中可以不一样。但那样需要为每一个格式产生一个同样shader的material instance,不同的格式又需要不同的pipeline,我们不支持这种行为
|
||||||
|
//
|
||||||
|
// buf_list[stage_input_binding]=vab->GetBuffer();
|
||||||
|
// buf_offset[stage_input_binding]=offset;
|
||||||
|
//
|
||||||
|
// return(true);
|
||||||
|
//}
|
||||||
|
|
||||||
|
bool Renderable::Set(const UTF8String &name,VAB *vab,VkDeviceSize offset)
|
||||||
{
|
{
|
||||||
vertex_sm=vsm;
|
if(!vab)return(false);
|
||||||
draw_count=dc;
|
if(buffer_list.KeyExist(name))return(false);
|
||||||
|
|
||||||
buf_count=vertex_sm->GetAttrCount();
|
BufferData bd;
|
||||||
|
|
||||||
buf_list=hgl_zero_new<VkBuffer>(buf_count);
|
bd.buf=vab;
|
||||||
buf_offset=hgl_zero_new<VkDeviceSize>(buf_count);
|
bd.offset=offset;
|
||||||
}
|
|
||||||
|
|
||||||
Renderable::~Renderable()
|
|
||||||
{
|
|
||||||
delete[] buf_offset;
|
|
||||||
delete[] buf_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Renderable::Set(const int stage_input_binding,VAB *vab,VkDeviceSize offset)
|
|
||||||
{
|
|
||||||
if(stage_input_binding<0||stage_input_binding>=buf_count||!vab)return(false);
|
|
||||||
|
|
||||||
const VkVertexInputBindingDescription *desc=vertex_sm->GetDesc(stage_input_binding);
|
|
||||||
const VkVertexInputAttributeDescription *attr=vertex_sm->GetAttr(stage_input_binding);
|
|
||||||
|
|
||||||
if(vab->GetFormat()!=attr->format)return(false);
|
|
||||||
if(vab->GetStride()!=desc->stride)return(false);
|
|
||||||
|
|
||||||
//format信息来自于shader,实际中可以不一样。但那样需要为每一个格式产生一个同样shader的material instance,不同的格式又需要不同的pipeline,我们不支持这种行为
|
|
||||||
|
|
||||||
buf_list[stage_input_binding]=vab->GetBuffer();
|
|
||||||
buf_offset[stage_input_binding]=offset;
|
|
||||||
|
|
||||||
|
buffer_list.Add(name,bd);
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Renderable::Set(const AnsiString &name,VAB *vab,VkDeviceSize offset)
|
VAB *Renderable::GetVAB(const UTF8String &name,VkDeviceSize *offset)
|
||||||
{
|
{
|
||||||
return Set(vertex_sm->GetStageInputBinding(name),vab,offset);
|
if(!offset)return(nullptr);
|
||||||
|
if(name.IsEmpty())return(nullptr);
|
||||||
|
|
||||||
|
BufferData bd;
|
||||||
|
|
||||||
|
if(buffer_list.Get(name,bd))
|
||||||
|
{
|
||||||
|
*offset=bd.offset;
|
||||||
|
return bd.buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
VkBuffer Renderable::GetBuffer(const UTF8String &name,VkDeviceSize *offset)
|
||||||
|
{
|
||||||
|
VAB *vab=GetVAB(name,offset);
|
||||||
|
|
||||||
|
if(vab)return vab->GetBuffer();
|
||||||
|
|
||||||
|
return(VK_NULL_HANDLE);
|
||||||
}
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
71
src/RenderDevice/Vulkan/VKRenderableInstance.cpp
Normal file
71
src/RenderDevice/Vulkan/VKRenderableInstance.cpp
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
#include<hgl/graph/vulkan/VKRenderableInstance.h>
|
||||||
|
#include<hgl/graph/vulkan/VKMaterialInstance.h>
|
||||||
|
#include<hgl/graph/vulkan/VKMaterial.h>
|
||||||
|
|
||||||
|
VK_NAMESPACE_BEGIN
|
||||||
|
RenderableInstance::RenderableInstance(Renderable *r,MaterialInstance *mi,Pipeline *p,const uint32_t count,VkBuffer *bl,VkDeviceSize *bs)
|
||||||
|
{
|
||||||
|
render_obj=r;
|
||||||
|
mat_inst=mi;
|
||||||
|
pipeline=p;
|
||||||
|
|
||||||
|
buffer_count=count;
|
||||||
|
buffer_list=bl;
|
||||||
|
buffer_size=bs;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderableInstance::~RenderableInstance()
|
||||||
|
{
|
||||||
|
//需要在这里添加删除pipeline/desc_sets/render_obj引用计数的代码
|
||||||
|
|
||||||
|
delete[] buffer_list;
|
||||||
|
delete[] buffer_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderableInstance *CreateRenderableInstance(Renderable *r,MaterialInstance *mi,Pipeline *p)
|
||||||
|
{
|
||||||
|
if(!r||!mi||!p)return(nullptr);
|
||||||
|
|
||||||
|
Material *mtl=mi->GetMaterial();
|
||||||
|
|
||||||
|
if(!mtl)return(nullptr);
|
||||||
|
|
||||||
|
const VertexShaderModule *vsm=mtl->GetVertexShaderModule();
|
||||||
|
const ShaderStageList &ssl=vsm->GetStageInputs();
|
||||||
|
const int input_count=ssl.GetCount();
|
||||||
|
|
||||||
|
if(r->GetBufferCount()<input_count) //小于材质要求的数量?那自然是不行的
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
AutoDeleteArray<VkBuffer> buffer_list=new VkBuffer[input_count];
|
||||||
|
AutoDeleteArray<VkDeviceSize> buffer_size=new VkDeviceSize[input_count];
|
||||||
|
|
||||||
|
ShaderStage **ss=ssl.GetData();
|
||||||
|
|
||||||
|
VAB *vab;
|
||||||
|
const VkVertexInputBindingDescription *desc;
|
||||||
|
const VkVertexInputAttributeDescription *attr;
|
||||||
|
|
||||||
|
for(uint i=0;i<input_count;i++)
|
||||||
|
{
|
||||||
|
desc=vsm->GetDesc(i);
|
||||||
|
attr=vsm->GetAttr(i);
|
||||||
|
|
||||||
|
vab=r->GetVAB((*ss)->name,buffer_size+i);
|
||||||
|
|
||||||
|
if(!vab)return(nullptr);
|
||||||
|
|
||||||
|
if(vab->GetFormat()!=attr->format)return(nullptr);
|
||||||
|
if(vab->GetStride()!=desc->stride)return(nullptr);
|
||||||
|
|
||||||
|
buffer_list[i]=vab->GetBuffer();
|
||||||
|
|
||||||
|
++ss;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderableInstance *ri=new RenderableInstance(r,mi,p,input_count,buffer_list,buffer_size);
|
||||||
|
buffer_list.Discard();
|
||||||
|
buffer_size.Discard();
|
||||||
|
return ri;
|
||||||
|
}
|
||||||
|
VK_NAMESPACE_END
|
@ -29,7 +29,6 @@ SOURCE_GROUP("Tile" FILES ${TILE_SOURCE})
|
|||||||
SET(SCENE_GRAPH_HEADER ${ROOT_INCLUDE_PATH}/hgl/graph/Light.h
|
SET(SCENE_GRAPH_HEADER ${ROOT_INCLUDE_PATH}/hgl/graph/Light.h
|
||||||
${ROOT_INCLUDE_PATH}/hgl/graph/SceneNode.h
|
${ROOT_INCLUDE_PATH}/hgl/graph/SceneNode.h
|
||||||
${ROOT_INCLUDE_PATH}/hgl/graph/SceneOrient.h
|
${ROOT_INCLUDE_PATH}/hgl/graph/SceneOrient.h
|
||||||
${ROOT_INCLUDE_PATH}/hgl/graph/RenderableInstance.h
|
|
||||||
${ROOT_INCLUDE_PATH}/hgl/graph/RenderList.h
|
${ROOT_INCLUDE_PATH}/hgl/graph/RenderList.h
|
||||||
${ROOT_INCLUDE_PATH}/hgl/graph/InlineGeometry.h
|
${ROOT_INCLUDE_PATH}/hgl/graph/InlineGeometry.h
|
||||||
#${ROOT_INCLUDE_PATH}/hgl/graph/Mesh.h
|
#${ROOT_INCLUDE_PATH}/hgl/graph/Mesh.h
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
#include<hgl/graph/vulkan/VKRenderable.h>
|
#include<hgl/graph/vulkan/VKRenderable.h>
|
||||||
#include<hgl/graph/vulkan/VKCommandBuffer.h>
|
#include<hgl/graph/vulkan/VKCommandBuffer.h>
|
||||||
#include<hgl/graph/VertexAttribDataAccess.h>
|
#include<hgl/graph/VertexAttribDataAccess.h>
|
||||||
#include<hgl/graph/RenderableInstance.h>
|
|
||||||
#include<hgl/graph/vulkan/VKMaterialInstance.h>
|
#include<hgl/graph/vulkan/VKMaterialInstance.h>
|
||||||
|
#include<hgl/graph/vulkan/VKRenderableInstance.h>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
@ -27,13 +27,13 @@ namespace hgl
|
|||||||
// return (((Frustum *)fc)->BoxIn(node->GetWorldBoundingBox())!=Frustum::OUTSIDE);
|
// return (((Frustum *)fc)->BoxIn(node->GetWorldBoundingBox())!=Frustum::OUTSIDE);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
void RenderList::Render(SceneNode *node,RenderableInstance *ri)
|
void RenderList::Render(SceneNode *node,vulkan::RenderableInstance *ri)
|
||||||
{
|
{
|
||||||
if(last_pipeline!=ri->GetPipeline())
|
if(last_pipeline!=ri->GetPipeline())
|
||||||
{
|
{
|
||||||
last_pipeline=ri->GetPipeline();
|
last_pipeline=ri->GetPipeline();
|
||||||
|
|
||||||
cmd_buf->Bind(last_pipeline);
|
cmd_buf->BindPipeline(last_pipeline);
|
||||||
|
|
||||||
last_mat_inst=nullptr;
|
last_mat_inst=nullptr;
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
last_mat_inst=ri->GetMaterialInstance();
|
last_mat_inst=ri->GetMaterialInstance();
|
||||||
|
|
||||||
cmd_buf->Bind(last_mat_inst->GetDescriptorSets());
|
cmd_buf->BindDescriptorSets(last_mat_inst->GetDescriptorSets());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(last_pc!=node->GetPushConstant())
|
if(last_pc!=node->GetPushConstant())
|
||||||
@ -54,16 +54,14 @@ namespace hgl
|
|||||||
|
|
||||||
//更新fin_mvp
|
//更新fin_mvp
|
||||||
|
|
||||||
vulkan::Renderable *obj=ri->GetRenderable();
|
if(ri!=last_ri)
|
||||||
|
|
||||||
if(obj!=last_renderable)
|
|
||||||
{
|
{
|
||||||
cmd_buf->Bind(obj);
|
cmd_buf->BindVAB(ri);
|
||||||
|
|
||||||
last_renderable=obj;
|
last_ri=ri;
|
||||||
}
|
}
|
||||||
|
|
||||||
const vulkan::IndexBuffer *ib=obj->GetIndexBuffer();
|
const vulkan::IndexBuffer *ib=ri->GetIndexBuffer();
|
||||||
|
|
||||||
if(ib)
|
if(ib)
|
||||||
{
|
{
|
||||||
@ -71,14 +69,14 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cmd_buf->Draw(obj->GetDrawCount());
|
cmd_buf->Draw(ri->GetDrawCount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderList::Render(SceneNode *node,List<RenderableInstance *> &ri_list)
|
void RenderList::Render(SceneNode *node,List<vulkan::RenderableInstance *> &ri_list)
|
||||||
{
|
{
|
||||||
const int count=ri_list.GetCount();
|
const int count=ri_list.GetCount();
|
||||||
RenderableInstance **ri=ri_list.GetData();
|
vulkan::RenderableInstance **ri=ri_list.GetData();
|
||||||
|
|
||||||
for(int i=0;i<count;i++)
|
for(int i=0;i<count;i++)
|
||||||
{
|
{
|
||||||
@ -96,7 +94,7 @@ namespace hgl
|
|||||||
|
|
||||||
last_pipeline=nullptr;
|
last_pipeline=nullptr;
|
||||||
last_mat_inst=nullptr;
|
last_mat_inst=nullptr;
|
||||||
last_renderable=nullptr;
|
last_ri=nullptr;
|
||||||
last_pc=nullptr;
|
last_pc=nullptr;
|
||||||
|
|
||||||
const int count=scene_node_list.GetCount();
|
const int count=scene_node_list.GetCount();
|
||||||
|
@ -115,15 +115,15 @@ namespace hgl
|
|||||||
if(vab_maps.GetCount()!=si_count)
|
if(vab_maps.GetCount()!=si_count)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
vulkan::Renderable *render_obj=mtl->CreateRenderable(vertices_number);
|
vulkan::Renderable *render_obj=db->CreateRenderable(vertices_number);
|
||||||
|
|
||||||
const auto *sp=vab_maps.GetDataList();
|
const auto *sp=vab_maps.GetDataList();
|
||||||
for(uint i=0;i<si_count;i++)
|
for(uint i=0;i<si_count;i++)
|
||||||
{
|
{
|
||||||
if((*sp)->right->vab)
|
if((*sp)->right->vab)
|
||||||
render_obj->Set((*sp)->right->binding,(*sp)->right->vab);
|
render_obj->Set((*sp)->left,(*sp)->right->vab);
|
||||||
else
|
else
|
||||||
render_obj->Set((*sp)->right->binding,db->CreateVAB((*sp)->right->data));
|
render_obj->Set((*sp)->left,db->CreateVAB((*sp)->right->data));
|
||||||
|
|
||||||
++sp;
|
++sp;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
namespace graph
|
namespace graph
|
||||||
{
|
{
|
||||||
TextRenderable::TextRenderable(vulkan::Device *dev,vulkan::Material *m,uint mc):vulkan::Renderable(m->GetVertexShaderModule(),mc)
|
TextRenderable::TextRenderable(vulkan::Device *dev,vulkan::Material *m,uint mc):vulkan::Renderable(mc)
|
||||||
{
|
{
|
||||||
device=dev;
|
device=dev;
|
||||||
mtl=m;
|
mtl=m;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user