Compare commits
2 Commits
edaf5aa3ca
...
f9675fc1e5
Author | SHA1 | Date | |
---|---|---|---|
f9675fc1e5 | |||
92f612f675 |
@ -89,17 +89,22 @@ private:
|
||||
{VAN::Color, COLOR_DATA_FORMAT, color_data}
|
||||
});
|
||||
|
||||
return(mesh_triangle);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
if(!mesh_triangle)
|
||||
return(false);
|
||||
|
||||
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);
|
||||
|
||||
scene_root->Add(new SceneNode(mesh_triangle));
|
||||
|
||||
return(mesh_triangle);
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
@ -119,6 +124,9 @@ public:
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public WorkObject
|
||||
|
@ -122,6 +122,44 @@ namespace hgl
|
||||
graph::MaterialInstance *mi,
|
||||
graph::Pipeline *pipeline,
|
||||
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
|
||||
|
||||
/**
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
public: //事件
|
||||
|
||||
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 OnFocusGained(){} ///<焦点获得事件
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/component/RenderComponent.h>
|
||||
#include<hgl/component/SceneComponent.h>
|
||||
|
||||
COMPONENT_NAMESPACE_BEGIN
|
||||
|
||||
@ -8,11 +8,11 @@ COMPONENT_NAMESPACE_BEGIN
|
||||
* 图元组件<br>
|
||||
* 组件中的元素必须是一个可以明确描述的几何体,可以被明确标记尺寸、参与空间、物理计算等。
|
||||
*/
|
||||
class PrimitiveComponent:public RenderComponent
|
||||
class PrimitiveComponent:public SceneComponent
|
||||
{
|
||||
public:
|
||||
|
||||
using RenderComponent::RenderComponent;
|
||||
using SceneComponent::SceneComponent;
|
||||
|
||||
virtual ~PrimitiveComponent()=default;
|
||||
};//class PrimitiveComponent
|
||||
|
@ -1,17 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/component/Component.h>
|
||||
#include<hgl/component/PrimitiveComponent.h>
|
||||
|
||||
COMPONENT_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* 可渲染组件
|
||||
*/
|
||||
class RenderComponent: public Component
|
||||
class RenderComponent:public PrimitiveComponent
|
||||
{
|
||||
public:
|
||||
|
||||
using Component::Component;
|
||||
using PrimitiveComponent::PrimitiveComponent;
|
||||
virtual ~RenderComponent()=default;
|
||||
};//class RenderComponent
|
||||
|
||||
|
20
inc/hgl/component/SceneComponent.h
Normal file
20
inc/hgl/component/SceneComponent.h
Normal 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
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/component/PrimitiveComponent.h>
|
||||
#include<hgl/component/RenderComponent.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
|
||||
COMPONENT_NAMESPACE_BEGIN
|
||||
@ -45,32 +45,37 @@ public:
|
||||
|
||||
StaticMeshComponentManager()=default;
|
||||
|
||||
StaticMeshComponent *CreateStaticMeshComponent(StaticMeshComponentData *data);
|
||||
StaticMeshComponent *CreateComponent(StaticMeshComponentData *data);
|
||||
|
||||
StaticMeshComponent *CreateStaticMeshComponent(Mesh *m)
|
||||
StaticMeshComponent *CreateComponent(Mesh *m)
|
||||
{
|
||||
auto sm_cd=new StaticMeshComponentData(m);
|
||||
|
||||
return CreateStaticMeshComponent(sm_cd);
|
||||
return CreateComponent(sm_cd);
|
||||
}
|
||||
|
||||
virtual Component *CreateComponent(ComponentData *data) override;
|
||||
};//class StaticMeshComponentManager
|
||||
|
||||
class StaticMeshComponent:public PrimitiveComponent
|
||||
class StaticMeshComponent:public RenderComponent
|
||||
{
|
||||
StaticMeshComponentData *sm_data;
|
||||
|
||||
public:
|
||||
|
||||
StaticMeshComponent(StaticMeshComponentData *cd,StaticMeshComponentManager *cm)
|
||||
:PrimitiveComponent(cd,cm)
|
||||
:RenderComponent(cd,cm)
|
||||
{
|
||||
sm_data=cd;
|
||||
}
|
||||
|
||||
virtual ~StaticMeshComponent()=default;
|
||||
|
||||
static StaticMeshComponentManager *GetDefaultManager()
|
||||
{
|
||||
return StaticMeshComponentManager::GetDefaultManager();
|
||||
}
|
||||
|
||||
static constexpr const size_t StaticHashCode()
|
||||
{
|
||||
return hgl::GetTypeHash<StaticMeshComponent>();
|
||||
|
@ -109,7 +109,7 @@ public:
|
||||
MaterialRenderList(VulkanDevice *d,bool l2w,const RenderPipelineIndex &rpi);
|
||||
~MaterialRenderList();
|
||||
|
||||
void Add(SceneNode *);
|
||||
void Add(StaticMeshComponent *);
|
||||
|
||||
void SetCameraInfo(CameraInfo *ci){camera_info=ci;}
|
||||
|
||||
@ -120,6 +120,6 @@ public:
|
||||
void Render(RenderCmdBuffer *);
|
||||
|
||||
void UpdateLocalToWorld(); //刷新所有对象的LocalToWorld矩阵
|
||||
void UpdateMaterialInstance(SceneNode *);
|
||||
void UpdateMaterialInstance(StaticMeshComponent *);
|
||||
};//class MaterialRenderList
|
||||
VK_NAMESPACE_END
|
||||
|
@ -46,7 +46,7 @@ namespace hgl
|
||||
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
|
||||
|
||||
virtual void UpdateLocalToWorld(); ///<更新所有对象的变换数据
|
||||
virtual void UpdateMaterialInstance(SceneNode *); ///<有对象互换了材质实例
|
||||
virtual void UpdateMaterialInstance(StaticMeshComponent *); ///<有对象互换了材质实例
|
||||
|
||||
virtual void Clear(); ///<彻底清理
|
||||
};//class RenderList
|
||||
|
@ -9,13 +9,13 @@ namespace hgl
|
||||
{
|
||||
class Mesh;
|
||||
class MaterialInstance;
|
||||
class SceneNode;
|
||||
class StaticMeshComponent;
|
||||
|
||||
struct RenderNode:public Comparator<RenderNode>
|
||||
{
|
||||
uint index; ///<在MaterialRenderList中的索引
|
||||
|
||||
SceneNode * scene_node;
|
||||
StaticMeshComponent *sm_component; ///<静态网格组件
|
||||
|
||||
uint32 l2w_version;
|
||||
uint32 l2w_index;
|
||||
@ -27,6 +27,11 @@ namespace hgl
|
||||
|
||||
//该函数位于MaterialRenderList.cpp
|
||||
const int compare(const RenderNode &)const override;
|
||||
|
||||
public:
|
||||
|
||||
Mesh *GetMesh()const;
|
||||
MaterialInstance *GetMaterialInstance()const;
|
||||
};
|
||||
|
||||
using RenderNodeList=ArrayList<RenderNode>;
|
||||
|
@ -30,8 +30,6 @@ namespace hgl::graph
|
||||
AABB LocalBoundingBox; ///<本地坐标绑定盒
|
||||
//AABB WorldBoundingBox; ///<世界坐标绑定盒
|
||||
|
||||
Mesh *render_obj=nullptr; ///<可渲染实例
|
||||
|
||||
protected:
|
||||
|
||||
ObjectList<SceneNode> ChildNode; ///<子节点
|
||||
@ -55,9 +53,7 @@ namespace hgl::graph
|
||||
SceneNode(const SceneNode &)=delete;
|
||||
SceneNode(const SceneNode *)=delete;
|
||||
SceneNode(const SceneOrient &so ):SceneOrient(so) {}
|
||||
SceneNode( Mesh *ri ) {render_obj=ri;}
|
||||
SceneNode(const Matrix4f &mat ):SceneOrient(mat) {}
|
||||
SceneNode(const Matrix4f &mat, Mesh *ri ):SceneOrient(mat) {render_obj=ri;}
|
||||
|
||||
public:
|
||||
|
||||
@ -74,12 +70,10 @@ namespace hgl::graph
|
||||
|
||||
ChildNode.Clear();
|
||||
ComponentSet.Clear();
|
||||
render_obj=nullptr;
|
||||
}
|
||||
|
||||
const bool ChildNodeIsEmpty()const
|
||||
{
|
||||
if(render_obj)return(false);
|
||||
if(ChildNode.GetCount())return(false);
|
||||
|
||||
return(true);
|
||||
@ -89,10 +83,6 @@ namespace hgl::graph
|
||||
SceneNode * GetParent() 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)
|
||||
{
|
||||
if(!sn)
|
||||
@ -118,13 +108,32 @@ namespace hgl::graph
|
||||
|
||||
bool ComponentIsEmpty ()const{return ComponentSet.GetCount()==0;} ///<是否没有组件
|
||||
virtual int GetComponentCount ()const{return ComponentSet.GetCount();} ///<取得组件数量
|
||||
virtual void AttachComponent (Component *comp){ComponentSet.Add(comp);} ///<添加一个组件
|
||||
virtual void DetachComponent (Component *comp){ComponentSet.Delete(comp);} ///<删除一个组件
|
||||
virtual bool AttachComponent (Component *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 HasComponent (const ComponentManager *); ///<是否有指定组件管理器的组件
|
||||
virtual int GetComponents (ArrayList<Component *> &comp_list,const ComponentManager *); ///<取得所有组件
|
||||
|
||||
const SortedSet<Component *> & GetComponents ()const{return ComponentSet;}
|
||||
};//class SceneNode
|
||||
|
||||
SceneNode *Duplication(SceneNode *); ///<复制一个场景节点
|
||||
|
@ -91,6 +91,7 @@ SET(SG_RENDER_SOURCE ${SG_INCLUDE_PATH}/RenderNode.h
|
||||
${SG_INCLUDE_PATH}/RenderTask.h
|
||||
${SG_INCLUDE_PATH}/Renderer.h
|
||||
render/Renderer.cpp
|
||||
render/RenderNode.cpp
|
||||
render/RenderTask.cpp
|
||||
render/RenderList.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_FILES ${COMPONENT_INCLUDE_PATH}/Component.h
|
||||
${COMPONENT_INCLUDE_PATH}/RenderComponent.h
|
||||
${COMPONENT_INCLUDE_PATH}/SceneComponent.h
|
||||
${COMPONENT_INCLUDE_PATH}/PrimitiveComponent.h
|
||||
${COMPONENT_INCLUDE_PATH}/RenderComponent.h
|
||||
${COMPONENT_INCLUDE_PATH}/StaticMeshComponent.h
|
||||
component/Component.cpp
|
||||
component/ComponentManager.cpp
|
||||
|
@ -55,7 +55,7 @@ namespace hgl::graph
|
||||
if(!component_manager_map->contains(hash_code))
|
||||
return(nullptr);
|
||||
|
||||
//[]对于不存的会自行插入一个,所以不要把下面的.at改成[]
|
||||
//tsl::robin_map的[]对于不存在的会自行插入一个,所以不要把下面的.at改成[]
|
||||
return component_manager_map->at(hash_code);
|
||||
}
|
||||
|
||||
|
@ -17,10 +17,10 @@ Component *StaticMeshComponentManager::CreateComponent(ComponentData *data)
|
||||
{
|
||||
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);
|
||||
|
||||
|
@ -6,72 +6,11 @@
|
||||
#include<hgl/graph/VKRenderAssign.h>
|
||||
#include<hgl/util/sort/Sort.h>
|
||||
#include"RenderAssignBuffer.h"
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
#include<hgl/graph/CameraInfo.h>
|
||||
|
||||
/**
|
||||
*
|
||||
* 理论上讲,我们需要按以下顺序排序
|
||||
*
|
||||
* for(material)
|
||||
* for(pipeline)
|
||||
* for(material_instance)
|
||||
* for(vab)
|
||||
*
|
||||
*
|
||||
* 关于Indirect Command Buffer
|
||||
|
||||
建立一个大的IndirectCommandBuffer,用于存放所有的渲染指令,包括那些不能使用Indirect渲染的。
|
||||
这样就可以保证所有的渲染操作就算要切VBO,也不需要切换INDIRECT缓冲区,定位指令也很方便。
|
||||
*/
|
||||
#include<hgl/component/StaticMeshComponent.h>
|
||||
|
||||
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)
|
||||
{
|
||||
device=d;
|
||||
@ -106,13 +45,18 @@ MaterialRenderList::~MaterialRenderList()
|
||||
SAFE_CLEAR(assign_buffer);
|
||||
}
|
||||
|
||||
void MaterialRenderList::Add(SceneNode *sn)
|
||||
void MaterialRenderList::Add(StaticMeshComponent *smc)
|
||||
{
|
||||
if(!smc)
|
||||
return;
|
||||
|
||||
RenderNode rn;
|
||||
|
||||
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_index =0;
|
||||
@ -160,7 +104,7 @@ void MaterialRenderList::UpdateLocalToWorld()
|
||||
|
||||
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) //版本不对,需要更新
|
||||
{
|
||||
@ -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)
|
||||
return;
|
||||
@ -202,7 +146,7 @@ void MaterialRenderList::UpdateMaterialInstance(SceneNode *sn)
|
||||
|
||||
for(int i=0;i<node_count;i++)
|
||||
{
|
||||
if(rn->scene_node==sn)
|
||||
if(rn->sm_component==smc)
|
||||
{
|
||||
assign_buffer->UpdateMaterialInstance(rn);
|
||||
return;
|
||||
@ -270,7 +214,7 @@ void MaterialRenderList::Stat()
|
||||
ri_array.Alloc(count);
|
||||
|
||||
RenderItem *ri=ri_array.GetData();
|
||||
Mesh *ro=rn->scene_node->GetRenderable();
|
||||
Mesh *ro=rn->sm_component->GetMesh();
|
||||
|
||||
ri_count=1;
|
||||
|
||||
@ -286,7 +230,7 @@ void MaterialRenderList::Stat()
|
||||
|
||||
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_render_data==*ro->GetRenderData())
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include<hgl/graph/Mesh.h>
|
||||
#include<hgl/graph/VKRenderAssign.h>
|
||||
#include<hgl/graph/mtl/UBOCommon.h>
|
||||
#include<hgl/component/StaticMeshComponent.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
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++)
|
||||
{
|
||||
*l2wp=rn->scene_node->GetLocalToWorldMatrix();
|
||||
*l2wp=rn->sm_component->GetOwnerNode()->GetLocalToWorldMatrix();
|
||||
++l2wp;
|
||||
++rn;
|
||||
}
|
||||
@ -97,7 +98,7 @@ void RenderAssignBuffer::UpdateLocalToWorld(const RenderNodePointerList &rnp_lis
|
||||
|
||||
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;
|
||||
}
|
||||
@ -112,7 +113,7 @@ void RenderAssignBuffer::UpdateMaterialInstance(const RenderNode *rn)
|
||||
|
||||
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();
|
||||
}
|
||||
@ -152,7 +153,7 @@ void RenderAssignBuffer::StatMI(const RenderNodeList &rn_list)
|
||||
mi_set.PreAlloc(rn_list.GetCount());
|
||||
|
||||
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())
|
||||
{
|
||||
@ -220,7 +221,7 @@ void RenderAssignBuffer::WriteNode(const RenderNodeList &rn_list)
|
||||
rn->l2w_index=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;
|
||||
|
||||
++rn;
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include<hgl/graph/VKCommandBuffer.h>
|
||||
#include<hgl/graph/VKMaterial.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
#include<hgl/component/StaticMeshComponent.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
@ -22,11 +23,16 @@ namespace hgl
|
||||
{
|
||||
if(!sn)return(false);
|
||||
|
||||
Mesh *ri=sn->GetRenderable();
|
||||
|
||||
if(ri)
|
||||
for(auto component:sn->GetComponents())
|
||||
{
|
||||
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;
|
||||
|
||||
@ -36,8 +42,8 @@ namespace hgl
|
||||
|
||||
mrl_map.Add(rpi,mrl);
|
||||
}
|
||||
|
||||
mrl->Add(sn);
|
||||
|
||||
mrl->Add(smc);
|
||||
|
||||
++renderable_count;
|
||||
}
|
||||
@ -85,11 +91,11 @@ namespace hgl
|
||||
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;
|
||||
|
||||
@ -99,7 +105,7 @@ namespace hgl
|
||||
if(!mrl_map.Get(rli,mrl)) //找到对应的
|
||||
return;
|
||||
|
||||
mrl->UpdateMaterialInstance(sn);
|
||||
mrl->UpdateMaterialInstance(smc);
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@ -3,39 +3,39 @@
|
||||
|
||||
namespace hgl::graph
|
||||
{
|
||||
SceneNode *Duplication(SceneNode *src_node)
|
||||
{
|
||||
if(!src_node)
|
||||
return nullptr;
|
||||
//SceneNode *Duplication(SceneNode *src_node)
|
||||
//{
|
||||
// if(!src_node)
|
||||
// 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())
|
||||
{
|
||||
node->Add(Duplication(sn));
|
||||
}
|
||||
// for(SceneNode *sn:src_node->GetChildNode())
|
||||
// {
|
||||
// node->Add(Duplication(sn));
|
||||
// }
|
||||
|
||||
return node;
|
||||
}
|
||||
// return node;
|
||||
//}
|
||||
|
||||
void SceneNode::SetRenderable(Mesh *ri)
|
||||
{
|
||||
render_obj=ri;
|
||||
//void SceneNode::SetRenderable(Mesh *ri)
|
||||
//{
|
||||
// render_obj=ri;
|
||||
|
||||
if(render_obj)
|
||||
{
|
||||
SetBoundingBox(render_obj->GetBoundingBox());
|
||||
}
|
||||
else
|
||||
{
|
||||
BoundingBox.SetZero();
|
||||
// if(render_obj)
|
||||
// {
|
||||
// SetBoundingBox(render_obj->GetBoundingBox());
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// BoundingBox.SetZero();
|
||||
|
||||
//WorldBoundingBox=
|
||||
LocalBoundingBox=BoundingBox;
|
||||
}
|
||||
}
|
||||
// //WorldBoundingBox=
|
||||
// LocalBoundingBox=BoundingBox;
|
||||
// }
|
||||
//}
|
||||
|
||||
/**
|
||||
* 刷新矩阵变换
|
||||
|
Loading…
x
Reference in New Issue
Block a user