Compare commits

...

2 Commits

18 changed files with 190 additions and 152 deletions

View File

@ -89,17 +89,22 @@ private:
{VAN::Color, COLOR_DATA_FORMAT, color_data} {VAN::Color, COLOR_DATA_FORMAT, color_data}
}); });
return(mesh_triangle);
}
bool InitScene()
{
if(!mesh_triangle)
return(false);
SceneNode *scene_root=GetSceneRoot(); ///<取得场景根节点 SceneNode *scene_root=GetSceneRoot(); ///<取得场景根节点
auto manager=StaticMeshComponentManager::GetDefaultManager(); sm_component=CreateComponent<StaticMeshComponent>(scene_root,mesh_triangle); //创建一个静态网格组件
sm_component=manager->CreateStaticMeshComponent(mesh_triangle); if(!sm_component)
return(false);
scene_root->AttachComponent(sm_component); return(true);
scene_root->Add(new SceneNode(mesh_triangle));
return(mesh_triangle);
} }
public: public:
@ -119,6 +124,9 @@ public:
if(!InitVBO()) if(!InitVBO())
return(false); return(false);
if(!InitScene())
return(false);
return(true); return(true);
} }
};//class TestApp:public WorkObject };//class TestApp:public WorkObject

View File

@ -122,6 +122,44 @@ namespace hgl
graph::MaterialInstance *mi, graph::MaterialInstance *mi,
graph::Pipeline *pipeline, graph::Pipeline *pipeline,
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list); const std::initializer_list<graph::VertexAttribDataPtr> &vad_list);
public: //Component 相关
template<typename C,typename ...ARGS>
inline C *CreateComponent(ARGS...args)
{
auto manager=C::GetDefaultManager(); //取得默认管理器
if(!manager)
{
// LOG_ERROR(OS_TEXT("CreateComponent failed, no default manager!"));
return(nullptr);
}
return manager->CreateComponent(args...); //创建组件
}
template<typename C,typename ...ARGS>
inline C *CreateComponent(graph::SceneNode *parent_node,ARGS...args)
{
if(!parent_node)
{
// LOG_ERROR(OS_TEXT("CreateComponent failed, parent node is null!"));
return(nullptr);
}
C *c=this->CreateComponent<C>(args...); //创建组件
if(!c)
{
// LOG_ERROR(OS_TEXT("CreateComponent failed, create component failed!"));
return(nullptr);
}
parent_node->AttachComponent(c); //将组件附加到父节点
return c;
}
};//class WorkObject };//class WorkObject
/** /**

View File

@ -82,7 +82,7 @@ public:
public: //事件 public: //事件
virtual void OnAttach(SceneNode *node){if(node)OwnerNode=node;} ///<附加到节点事件 virtual void OnAttach(SceneNode *node){if(node)OwnerNode=node;} ///<附加到节点事件
virtual void OnDetach(){OwnerNode=nullptr;} ///<从节点分离事件 virtual void OnDetach(SceneNode *node){OwnerNode=nullptr;} ///<从节点分离事件
virtual void OnFocusLost(){} ///<焦点丢失事件 virtual void OnFocusLost(){} ///<焦点丢失事件
virtual void OnFocusGained(){} ///<焦点获得事件 virtual void OnFocusGained(){} ///<焦点获得事件

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include<hgl/component/RenderComponent.h> #include<hgl/component/SceneComponent.h>
COMPONENT_NAMESPACE_BEGIN COMPONENT_NAMESPACE_BEGIN
@ -8,11 +8,11 @@ COMPONENT_NAMESPACE_BEGIN
* <br> * <br>
* *
*/ */
class PrimitiveComponent:public RenderComponent class PrimitiveComponent:public SceneComponent
{ {
public: public:
using RenderComponent::RenderComponent; using SceneComponent::SceneComponent;
virtual ~PrimitiveComponent()=default; virtual ~PrimitiveComponent()=default;
};//class PrimitiveComponent };//class PrimitiveComponent

View File

@ -1,17 +1,17 @@
#pragma once #pragma once
#include<hgl/component/Component.h> #include<hgl/component/PrimitiveComponent.h>
COMPONENT_NAMESPACE_BEGIN COMPONENT_NAMESPACE_BEGIN
/** /**
* *
*/ */
class RenderComponent: public Component class RenderComponent:public PrimitiveComponent
{ {
public: public:
using Component::Component; using PrimitiveComponent::PrimitiveComponent;
virtual ~RenderComponent()=default; virtual ~RenderComponent()=default;
};//class RenderComponent };//class RenderComponent

View File

@ -0,0 +1,20 @@
#pragma once
#include<hgl/component/Component.h>
COMPONENT_NAMESPACE_BEGIN
/**
* <br>
*
*/
class SceneComponent:public Component
{
public:
using Component::Component;
virtual ~SceneComponent()=default;
};//class SceneComponent
COMPONENT_NAMESPACE_END

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include<hgl/component/PrimitiveComponent.h> #include<hgl/component/RenderComponent.h>
#include<hgl/graph/Mesh.h> #include<hgl/graph/Mesh.h>
COMPONENT_NAMESPACE_BEGIN COMPONENT_NAMESPACE_BEGIN
@ -45,32 +45,37 @@ public:
StaticMeshComponentManager()=default; StaticMeshComponentManager()=default;
StaticMeshComponent *CreateStaticMeshComponent(StaticMeshComponentData *data); StaticMeshComponent *CreateComponent(StaticMeshComponentData *data);
StaticMeshComponent *CreateStaticMeshComponent(Mesh *m) StaticMeshComponent *CreateComponent(Mesh *m)
{ {
auto sm_cd=new StaticMeshComponentData(m); auto sm_cd=new StaticMeshComponentData(m);
return CreateStaticMeshComponent(sm_cd); return CreateComponent(sm_cd);
} }
virtual Component *CreateComponent(ComponentData *data) override; virtual Component *CreateComponent(ComponentData *data) override;
};//class StaticMeshComponentManager };//class StaticMeshComponentManager
class StaticMeshComponent:public PrimitiveComponent class StaticMeshComponent:public RenderComponent
{ {
StaticMeshComponentData *sm_data; StaticMeshComponentData *sm_data;
public: public:
StaticMeshComponent(StaticMeshComponentData *cd,StaticMeshComponentManager *cm) StaticMeshComponent(StaticMeshComponentData *cd,StaticMeshComponentManager *cm)
:PrimitiveComponent(cd,cm) :RenderComponent(cd,cm)
{ {
sm_data=cd; sm_data=cd;
} }
virtual ~StaticMeshComponent()=default; virtual ~StaticMeshComponent()=default;
static StaticMeshComponentManager *GetDefaultManager()
{
return StaticMeshComponentManager::GetDefaultManager();
}
static constexpr const size_t StaticHashCode() static constexpr const size_t StaticHashCode()
{ {
return hgl::GetTypeHash<StaticMeshComponent>(); return hgl::GetTypeHash<StaticMeshComponent>();

View File

@ -109,7 +109,7 @@ public:
MaterialRenderList(VulkanDevice *d,bool l2w,const RenderPipelineIndex &rpi); MaterialRenderList(VulkanDevice *d,bool l2w,const RenderPipelineIndex &rpi);
~MaterialRenderList(); ~MaterialRenderList();
void Add(SceneNode *); void Add(StaticMeshComponent *);
void SetCameraInfo(CameraInfo *ci){camera_info=ci;} void SetCameraInfo(CameraInfo *ci){camera_info=ci;}
@ -120,6 +120,6 @@ public:
void Render(RenderCmdBuffer *); void Render(RenderCmdBuffer *);
void UpdateLocalToWorld(); //刷新所有对象的LocalToWorld矩阵 void UpdateLocalToWorld(); //刷新所有对象的LocalToWorld矩阵
void UpdateMaterialInstance(SceneNode *); void UpdateMaterialInstance(StaticMeshComponent *);
};//class MaterialRenderList };//class MaterialRenderList
VK_NAMESPACE_END VK_NAMESPACE_END

View File

@ -46,7 +46,7 @@ namespace hgl
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象 virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
virtual void UpdateLocalToWorld(); ///<更新所有对象的变换数据 virtual void UpdateLocalToWorld(); ///<更新所有对象的变换数据
virtual void UpdateMaterialInstance(SceneNode *); ///<有对象互换了材质实例 virtual void UpdateMaterialInstance(StaticMeshComponent *); ///<有对象互换了材质实例
virtual void Clear(); ///<彻底清理 virtual void Clear(); ///<彻底清理
};//class RenderList };//class RenderList

View File

@ -9,13 +9,13 @@ namespace hgl
{ {
class Mesh; class Mesh;
class MaterialInstance; class MaterialInstance;
class SceneNode; class StaticMeshComponent;
struct RenderNode:public Comparator<RenderNode> struct RenderNode:public Comparator<RenderNode>
{ {
uint index; ///<在MaterialRenderList中的索引 uint index; ///<在MaterialRenderList中的索引
SceneNode * scene_node; StaticMeshComponent *sm_component; ///<静态网格组件
uint32 l2w_version; uint32 l2w_version;
uint32 l2w_index; uint32 l2w_index;
@ -27,6 +27,11 @@ namespace hgl
//该函数位于MaterialRenderList.cpp //该函数位于MaterialRenderList.cpp
const int compare(const RenderNode &)const override; const int compare(const RenderNode &)const override;
public:
Mesh *GetMesh()const;
MaterialInstance *GetMaterialInstance()const;
}; };
using RenderNodeList=ArrayList<RenderNode>; using RenderNodeList=ArrayList<RenderNode>;

View File

@ -30,8 +30,6 @@ namespace hgl::graph
AABB LocalBoundingBox; ///<本地坐标绑定盒 AABB LocalBoundingBox; ///<本地坐标绑定盒
//AABB WorldBoundingBox; ///<世界坐标绑定盒 //AABB WorldBoundingBox; ///<世界坐标绑定盒
Mesh *render_obj=nullptr; ///<可渲染实例
protected: protected:
ObjectList<SceneNode> ChildNode; ///<子节点 ObjectList<SceneNode> ChildNode; ///<子节点
@ -55,9 +53,7 @@ namespace hgl::graph
SceneNode(const SceneNode &)=delete; SceneNode(const SceneNode &)=delete;
SceneNode(const SceneNode *)=delete; SceneNode(const SceneNode *)=delete;
SceneNode(const SceneOrient &so ):SceneOrient(so) {} SceneNode(const SceneOrient &so ):SceneOrient(so) {}
SceneNode( Mesh *ri ) {render_obj=ri;}
SceneNode(const Matrix4f &mat ):SceneOrient(mat) {} SceneNode(const Matrix4f &mat ):SceneOrient(mat) {}
SceneNode(const Matrix4f &mat, Mesh *ri ):SceneOrient(mat) {render_obj=ri;}
public: public:
@ -74,12 +70,10 @@ namespace hgl::graph
ChildNode.Clear(); ChildNode.Clear();
ComponentSet.Clear(); ComponentSet.Clear();
render_obj=nullptr;
} }
const bool ChildNodeIsEmpty()const const bool ChildNodeIsEmpty()const
{ {
if(render_obj)return(false);
if(ChildNode.GetCount())return(false); if(ChildNode.GetCount())return(false);
return(true); return(true);
@ -89,10 +83,6 @@ namespace hgl::graph
SceneNode * GetParent() noexcept{return ParentNode;} SceneNode * GetParent() noexcept{return ParentNode;}
const SceneNode * GetParent()const noexcept{return ParentNode;} const SceneNode * GetParent()const noexcept{return ParentNode;}
void SetRenderable(Mesh *);
Mesh * GetRenderable() noexcept{return render_obj;}
const Mesh * GetRenderable()const noexcept{return render_obj;}
SceneNode *Add(SceneNode *sn) SceneNode *Add(SceneNode *sn)
{ {
if(!sn) if(!sn)
@ -118,13 +108,32 @@ namespace hgl::graph
bool ComponentIsEmpty ()const{return ComponentSet.GetCount()==0;} ///<是否没有组件 bool ComponentIsEmpty ()const{return ComponentSet.GetCount()==0;} ///<是否没有组件
virtual int GetComponentCount ()const{return ComponentSet.GetCount();} ///<取得组件数量 virtual int GetComponentCount ()const{return ComponentSet.GetCount();} ///<取得组件数量
virtual void AttachComponent (Component *comp){ComponentSet.Add(comp);} ///<添加一个组件 virtual bool AttachComponent (Component *comp) ///<添加一个组件
virtual void DetachComponent (Component *comp){ComponentSet.Delete(comp);} ///<删除一个组件 {
if(!comp)return(false);
if(ComponentSet.Add(comp)<0)
return(false);
comp->OnAttach(this); //调用组件的OnAttach方法
return(true);
}
virtual void DetachComponent (Component *comp) ///<删除一个组件
{
if (!comp)return;
ComponentSet.Delete(comp);
comp->OnDetach(this); //调用组件的OnDetach方法
}
bool Contains (Component *comp){return ComponentSet.Contains(comp);} ///<是否包含指定组件 bool Contains (Component *comp){return ComponentSet.Contains(comp);} ///<是否包含指定组件
bool HasComponent (const ComponentManager *); ///<是否有指定组件管理器的组件 bool HasComponent (const ComponentManager *); ///<是否有指定组件管理器的组件
virtual int GetComponents (ArrayList<Component *> &comp_list,const ComponentManager *); ///<取得所有组件 virtual int GetComponents (ArrayList<Component *> &comp_list,const ComponentManager *); ///<取得所有组件
const SortedSet<Component *> & GetComponents ()const{return ComponentSet;}
};//class SceneNode };//class SceneNode
SceneNode *Duplication(SceneNode *); ///<复制一个场景节点 SceneNode *Duplication(SceneNode *); ///<复制一个场景节点

View File

@ -91,6 +91,7 @@ SET(SG_RENDER_SOURCE ${SG_INCLUDE_PATH}/RenderNode.h
${SG_INCLUDE_PATH}/RenderTask.h ${SG_INCLUDE_PATH}/RenderTask.h
${SG_INCLUDE_PATH}/Renderer.h ${SG_INCLUDE_PATH}/Renderer.h
render/Renderer.cpp render/Renderer.cpp
render/RenderNode.cpp
render/RenderTask.cpp render/RenderTask.cpp
render/RenderList.cpp render/RenderList.cpp
render/MaterialRenderList.cpp render/MaterialRenderList.cpp
@ -297,8 +298,9 @@ SOURCE_GROUP("Vulkan\\Mesh" FILES ${VK_MESH_SOURCE})
set(COMPONENT_INCLUDE_PATH ${ROOT_INCLUDE_PATH}/hgl/component) set(COMPONENT_INCLUDE_PATH ${ROOT_INCLUDE_PATH}/hgl/component)
SET(COMPONENT_FILES ${COMPONENT_INCLUDE_PATH}/Component.h SET(COMPONENT_FILES ${COMPONENT_INCLUDE_PATH}/Component.h
${COMPONENT_INCLUDE_PATH}/RenderComponent.h ${COMPONENT_INCLUDE_PATH}/SceneComponent.h
${COMPONENT_INCLUDE_PATH}/PrimitiveComponent.h ${COMPONENT_INCLUDE_PATH}/PrimitiveComponent.h
${COMPONENT_INCLUDE_PATH}/RenderComponent.h
${COMPONENT_INCLUDE_PATH}/StaticMeshComponent.h ${COMPONENT_INCLUDE_PATH}/StaticMeshComponent.h
component/Component.cpp component/Component.cpp
component/ComponentManager.cpp component/ComponentManager.cpp

View File

@ -55,7 +55,7 @@ namespace hgl::graph
if(!component_manager_map->contains(hash_code)) if(!component_manager_map->contains(hash_code))
return(nullptr); return(nullptr);
//[]对于不存的会自行插入一个,所以不要把下面的.at改成[] //tsl::robin_map的[]对于不存的会自行插入一个,所以不要把下面的.at改成[]
return component_manager_map->at(hash_code); return component_manager_map->at(hash_code);
} }

View File

@ -17,10 +17,10 @@ Component *StaticMeshComponentManager::CreateComponent(ComponentData *data)
{ {
if(!data)return(nullptr); if(!data)return(nullptr);
return CreateStaticMeshComponent(reinterpret_cast<StaticMeshComponentData *>(data)); return CreateComponent(reinterpret_cast<StaticMeshComponentData *>(data));
} }
StaticMeshComponent *StaticMeshComponentManager::CreateStaticMeshComponent(StaticMeshComponentData *data) StaticMeshComponent *StaticMeshComponentManager::CreateComponent(StaticMeshComponentData *data)
{ {
if(!data)return(nullptr); if(!data)return(nullptr);

View File

@ -6,72 +6,11 @@
#include<hgl/graph/VKRenderAssign.h> #include<hgl/graph/VKRenderAssign.h>
#include<hgl/util/sort/Sort.h> #include<hgl/util/sort/Sort.h>
#include"RenderAssignBuffer.h" #include"RenderAssignBuffer.h"
#include<hgl/graph/VertexDataManager.h>
#include<hgl/graph/SceneNode.h> #include<hgl/graph/SceneNode.h>
#include<hgl/graph/CameraInfo.h> #include<hgl/graph/CameraInfo.h>
#include<hgl/component/StaticMeshComponent.h>
/**
*
*
*
* for(material)
* for(pipeline)
* for(material_instance)
* for(vab)
*
*
* Indirect Command Buffer
IndirectCommandBuffer使Indirect渲染的
VBOINDIRECT缓冲区便
*/
VK_NAMESPACE_BEGIN VK_NAMESPACE_BEGIN
const int RenderNode::compare(const RenderNode &other)const
{
hgl::int64 off;
hgl::graph::Mesh *ri_one=other.scene_node->GetRenderable();
hgl::graph::Mesh *ri_two=scene_node->GetRenderable();
auto *prim_one=ri_one->GetPrimitive();
auto *prim_two=ri_two->GetPrimitive();
//比较VDM
if(prim_one->GetVDM()) //有VDM
{
off=prim_one->GetVDM()
-prim_two->GetVDM();
if(off)
return off;
//比较模型
{
off=prim_one
-prim_two;
if(off)
{
off=prim_one->GetVertexOffset()-prim_two->GetVertexOffset(); //保证vertex offset小的在前面
return off;
}
}
}
//比较距离。。。。。。。。。。。。。。。。。。。。。还不知道这个是正了还是反了,等测出来确认后修改下面的返回值和这里的注释
float foff=other.to_camera_distance
-to_camera_distance;
if(foff>0)
return 1;
else
return -1;
}
MaterialRenderList::MaterialRenderList(VulkanDevice *d,bool l2w,const RenderPipelineIndex &rpi) MaterialRenderList::MaterialRenderList(VulkanDevice *d,bool l2w,const RenderPipelineIndex &rpi)
{ {
device=d; device=d;
@ -106,13 +45,18 @@ MaterialRenderList::~MaterialRenderList()
SAFE_CLEAR(assign_buffer); SAFE_CLEAR(assign_buffer);
} }
void MaterialRenderList::Add(SceneNode *sn) void MaterialRenderList::Add(StaticMeshComponent *smc)
{ {
if(!smc)
return;
RenderNode rn; RenderNode rn;
rn.index =rn_list.GetCount(); rn.index =rn_list.GetCount();
rn.scene_node =sn; rn.sm_component =smc;
SceneNode *sn=smc->GetOwnerNode(); //目前先这样处理未来改成每个Component有自己的再一次的变换矩阵
rn.l2w_version =sn->GetLocalToWorldMatrixVersion(); rn.l2w_version =sn->GetLocalToWorldMatrixVersion();
rn.l2w_index =0; rn.l2w_index =0;
@ -160,7 +104,7 @@ void MaterialRenderList::UpdateLocalToWorld()
for(int i=0;i<node_count;i++) for(int i=0;i<node_count;i++)
{ {
l2w_version=rn->scene_node->GetLocalToWorldMatrixVersion(); l2w_version=rn->sm_component->GetOwnerNode()->GetLocalToWorldMatrixVersion();
if(rn->l2w_version!=l2w_version) //版本不对,需要更新 if(rn->l2w_version!=l2w_version) //版本不对,需要更新
{ {
@ -188,9 +132,9 @@ void MaterialRenderList::UpdateLocalToWorld()
} }
} }
void MaterialRenderList::UpdateMaterialInstance(SceneNode *sn) void MaterialRenderList::UpdateMaterialInstance(StaticMeshComponent *smc)
{ {
if(!sn)return; if(!smc)return;
if(!assign_buffer) if(!assign_buffer)
return; return;
@ -202,7 +146,7 @@ void MaterialRenderList::UpdateMaterialInstance(SceneNode *sn)
for(int i=0;i<node_count;i++) for(int i=0;i<node_count;i++)
{ {
if(rn->scene_node==sn) if(rn->sm_component==smc)
{ {
assign_buffer->UpdateMaterialInstance(rn); assign_buffer->UpdateMaterialInstance(rn);
return; return;
@ -270,7 +214,7 @@ void MaterialRenderList::Stat()
ri_array.Alloc(count); ri_array.Alloc(count);
RenderItem *ri=ri_array.GetData(); RenderItem *ri=ri_array.GetData();
Mesh *ro=rn->scene_node->GetRenderable(); Mesh *ro=rn->sm_component->GetMesh();
ri_count=1; ri_count=1;
@ -286,7 +230,7 @@ void MaterialRenderList::Stat()
for(uint i=1;i<count;i++) for(uint i=1;i<count;i++)
{ {
ro=rn->scene_node->GetRenderable(); ro=rn->sm_component->GetMesh();
if(*last_data_buffer==*ro->GetDataBuffer()) if(*last_data_buffer==*ro->GetDataBuffer())
if(*last_render_data==*ro->GetRenderData()) if(*last_render_data==*ro->GetRenderData())

View File

@ -7,6 +7,7 @@
#include<hgl/graph/Mesh.h> #include<hgl/graph/Mesh.h>
#include<hgl/graph/VKRenderAssign.h> #include<hgl/graph/VKRenderAssign.h>
#include<hgl/graph/mtl/UBOCommon.h> #include<hgl/graph/mtl/UBOCommon.h>
#include<hgl/component/StaticMeshComponent.h>
VK_NAMESPACE_BEGIN VK_NAMESPACE_BEGIN
RenderAssignBuffer::RenderAssignBuffer(VulkanDevice *dev,Material *mtl) RenderAssignBuffer::RenderAssignBuffer(VulkanDevice *dev,Material *mtl)
@ -73,7 +74,7 @@ void RenderAssignBuffer::StatL2W(const RenderNodeList &rn_list)
for(int i=0;i<rn_list.GetCount();i++) for(int i=0;i<rn_list.GetCount();i++)
{ {
*l2wp=rn->scene_node->GetLocalToWorldMatrix(); *l2wp=rn->sm_component->GetOwnerNode()->GetLocalToWorldMatrix();
++l2wp; ++l2wp;
++rn; ++rn;
} }
@ -97,7 +98,7 @@ void RenderAssignBuffer::UpdateLocalToWorld(const RenderNodePointerList &rnp_lis
for(uint i=0;i<count;i++) for(uint i=0;i<count;i++)
{ {
l2wp[(*rn)->l2w_index-first]=(*rn)->scene_node->GetLocalToWorldMatrix(); l2wp[(*rn)->l2w_index-first]=(*rn)->sm_component->GetOwnerNode()->GetLocalToWorldMatrix();
++rn; ++rn;
} }
@ -112,7 +113,7 @@ void RenderAssignBuffer::UpdateMaterialInstance(const RenderNode *rn)
AssignData *adp=(AssignData *)(assign_vab->DeviceBuffer::Map(sizeof(AssignData)*rn->index,sizeof(AssignData))); AssignData *adp=(AssignData *)(assign_vab->DeviceBuffer::Map(sizeof(AssignData)*rn->index,sizeof(AssignData)));
adp->mi=mi_set.Find(rn->scene_node->GetRenderable()->GetMaterialInstance()); adp->mi=mi_set.Find(rn->sm_component->GetMesh()->GetMaterialInstance());
assign_vab->Unmap(); assign_vab->Unmap();
} }
@ -152,7 +153,7 @@ void RenderAssignBuffer::StatMI(const RenderNodeList &rn_list)
mi_set.PreAlloc(rn_list.GetCount()); mi_set.PreAlloc(rn_list.GetCount());
for(RenderNode &rn:rn_list) for(RenderNode &rn:rn_list)
mi_set.Add(rn.scene_node->GetRenderable()->GetMaterialInstance()); mi_set.Add(rn.sm_component->GetMesh()->GetMaterialInstance());
if(mi_set.GetCount()>material->GetMIMaxCount()) if(mi_set.GetCount()>material->GetMIMaxCount())
{ {
@ -220,7 +221,7 @@ void RenderAssignBuffer::WriteNode(const RenderNodeList &rn_list)
rn->l2w_index=i; rn->l2w_index=i;
adp->l2w=i; adp->l2w=i;
adp->mi=mi_set.Find(rn->scene_node->GetRenderable()->GetMaterialInstance()); adp->mi=mi_set.Find(rn->sm_component->GetMesh()->GetMaterialInstance());
++adp; ++adp;
++rn; ++rn;

View File

@ -5,6 +5,7 @@
#include<hgl/graph/VKCommandBuffer.h> #include<hgl/graph/VKCommandBuffer.h>
#include<hgl/graph/VKMaterial.h> #include<hgl/graph/VKMaterial.h>
#include<hgl/graph/Mesh.h> #include<hgl/graph/Mesh.h>
#include<hgl/component/StaticMeshComponent.h>
namespace hgl namespace hgl
{ {
@ -22,11 +23,16 @@ namespace hgl
{ {
if(!sn)return(false); if(!sn)return(false);
Mesh *ri=sn->GetRenderable(); for(auto component:sn->GetComponents())
if(ri)
{ {
RenderPipelineIndex rpi(ri->GetMaterial(),ri->GetPipeline()); if(component->GetHashCode()!=StaticMeshComponent::StaticHashCode()) //暂时只支持StaticMeshComponent
continue;
StaticMeshComponent *smc=reinterpret_cast<StaticMeshComponent *>(component);
Mesh *mesh=smc->GetMesh();
RenderPipelineIndex rpi(mesh->GetMaterial(),mesh->GetPipeline());
MaterialRenderList *mrl; MaterialRenderList *mrl;
@ -36,8 +42,8 @@ namespace hgl
mrl_map.Add(rpi,mrl); mrl_map.Add(rpi,mrl);
} }
mrl->Add(sn); mrl->Add(smc);
++renderable_count; ++renderable_count;
} }
@ -85,11 +91,11 @@ namespace hgl
mrl_map.UpdateLocalToWorld(); mrl_map.UpdateLocalToWorld();
} }
void RenderList::UpdateMaterialInstance(SceneNode *sn) void RenderList::UpdateMaterialInstance(StaticMeshComponent *smc)
{ {
if(!sn)return; if(!smc)return;
Mesh *ri=sn->GetRenderable(); Mesh *ri=smc->GetMesh();
if(!ri)return; if(!ri)return;
@ -99,7 +105,7 @@ namespace hgl
if(!mrl_map.Get(rli,mrl)) //找到对应的 if(!mrl_map.Get(rli,mrl)) //找到对应的
return; return;
mrl->UpdateMaterialInstance(sn); mrl->UpdateMaterialInstance(smc);
} }
}//namespace graph }//namespace graph
}//namespace hgl }//namespace hgl

View File

@ -3,39 +3,39 @@
namespace hgl::graph namespace hgl::graph
{ {
SceneNode *Duplication(SceneNode *src_node) //SceneNode *Duplication(SceneNode *src_node)
{ //{
if(!src_node) // if(!src_node)
return nullptr; // return nullptr;
SceneNode *node=new SceneNode(*(SceneOrient *)src_node); // SceneNode *node=new SceneNode(*(SceneOrient *)src_node);
node->SetRenderable(src_node->GetRenderable()); // node->SetRenderable(src_node->GetRenderable());
for(SceneNode *sn:src_node->GetChildNode()) // for(SceneNode *sn:src_node->GetChildNode())
{ // {
node->Add(Duplication(sn)); // node->Add(Duplication(sn));
} // }
return node; // return node;
} //}
void SceneNode::SetRenderable(Mesh *ri) //void SceneNode::SetRenderable(Mesh *ri)
{ //{
render_obj=ri; // render_obj=ri;
if(render_obj) // if(render_obj)
{ // {
SetBoundingBox(render_obj->GetBoundingBox()); // SetBoundingBox(render_obj->GetBoundingBox());
} // }
else // else
{ // {
BoundingBox.SetZero(); // BoundingBox.SetZero();
//WorldBoundingBox= // //WorldBoundingBox=
LocalBoundingBox=BoundingBox; // LocalBoundingBox=BoundingBox;
} // }
} //}
/** /**
* *