1.used uvec2/ushort2 in AssignVBO
2.completed first step then merge MI buffer
This commit is contained in:
parent
00d2677066
commit
dbe2370a44
@ -1 +1 @@
|
||||
Subproject commit 1e8268389f01b8d9c1f17f779336f68af848bf55
|
||||
Subproject commit b66d4003b11a4d4aee1df9084fc4223df1d0aa25
|
@ -12,8 +12,8 @@ endmacro()
|
||||
|
||||
CreateProject("Basic" 1st_draw_triangle_in_NDC first_triangle.cpp)
|
||||
CreateProject("Basic" 2nd_draw_triangle_use_UBO second_triangle.cpp)
|
||||
CreateProject("Basic" 3rd_draw_triangle_use_RenderList third_triangle.cpp)
|
||||
CreateProject("Basic" 4th_draw_triangle_use_MaterialInstance fourth_triangle.cpp)
|
||||
CreateProject("Basic" 3rd_AutoInstance third_triangle.cpp)
|
||||
CreateProject("Basic" 4th_AutoMergeMaterialInstance fourth_triangle.cpp)
|
||||
|
||||
#CreateProject("Basic" FragCoord FragCoordTest.cpp)
|
||||
#CreateProject("Basic" indices_rect indices_rect.cpp)
|
||||
|
@ -1,5 +1,5 @@
|
||||
// fourth_triangle
|
||||
// 该范例主要演示使用材质实例传递颜色参数绘制三角形
|
||||
// AutoMergeMaterialInstance
|
||||
// 该范例主要演示使用一个材质下的不同材质实例传递颜色参数绘制三角形,并依赖RenderList中的自动合并功能,让同一材质下所有不同材质实例的对象一次渲染完成。
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// third_triangle
|
||||
// 该范例主要演示使用场景树系统绘制多个三角形,并利用RenderList进行排序以及自动合并进行Instance渲染
|
||||
// AutoInstance
|
||||
// 该范例主要演示使用RenderList系统绘制多个三角形,并利用RenderList进行排序以及自动合并进行Instance渲染
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
|
@ -35,7 +35,7 @@ private:
|
||||
void Set(Renderable *);
|
||||
};
|
||||
|
||||
SortedSets<int> mi_id_set;
|
||||
MaterialInstanceSets mi_set;
|
||||
DataArray<RenderItem> ri_array;
|
||||
uint ri_count;
|
||||
|
||||
|
@ -22,6 +22,8 @@ namespace hgl
|
||||
};
|
||||
|
||||
using RenderNodeList=List<RenderNode>;
|
||||
|
||||
using MaterialInstanceSets=SortedSets<MaterialInstance *>; ///<材质实例集合
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_RENDER_NODE_INCLUDE
|
||||
|
@ -109,17 +109,15 @@ void MaterialRenderList::RenderItem::Set(Renderable *ri)
|
||||
|
||||
void MaterialRenderList::StatMI()
|
||||
{
|
||||
mi_id_set.Clear();
|
||||
mi_set.Clear();
|
||||
|
||||
for(RenderNode &rn:rn_list)
|
||||
mi_id_set.Add(rn.ri->GetMaterialInstance()->GetMIID());
|
||||
mi_set.Add(rn.ri->GetMaterialInstance());
|
||||
|
||||
if(mi_id_set.GetCount()>mtl->GetMIMaxCount())
|
||||
if(mi_set.GetCount()>mtl->GetMIMaxCount())
|
||||
{
|
||||
//超出最大数量了怎么办???
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void MaterialRenderList::Stat()
|
||||
@ -142,8 +140,6 @@ void MaterialRenderList::Stat()
|
||||
last_mi =ri->mi;
|
||||
last_vid =ri->vid;
|
||||
|
||||
mi_set.Add(last_mi);
|
||||
|
||||
++rn;
|
||||
|
||||
for(uint i=1;i<count;i++)
|
||||
@ -164,9 +160,6 @@ void MaterialRenderList::Stat()
|
||||
ri->count=1;
|
||||
ri->Set(rn->ri);
|
||||
|
||||
if(last_mi!=ri->mi)
|
||||
mi_set.Add(ri->mi);
|
||||
|
||||
last_pipeline =ri->pipeline;
|
||||
last_mi =ri->mi;
|
||||
last_vid =ri->vid;
|
||||
|
@ -3,21 +3,22 @@
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
#include<hgl/graph/RenderNode.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/VKRenderAssign.h>
|
||||
#include<hgl/graph/mtl/UBOCommon.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
RenderAssignBuffer::RenderAssignBuffer(GPUDevice *dev,const uint mi_total_bytes)
|
||||
RenderAssignBuffer::RenderAssignBuffer(GPUDevice *dev,const uint mi_bytes)
|
||||
{
|
||||
hgl_zero(*this);
|
||||
|
||||
device=dev;
|
||||
|
||||
if(mi_total_bytes>0)
|
||||
ubo_mi=device->CreateUBO(mi_total_bytes);
|
||||
else
|
||||
mi_data_bytes=mi_bytes;
|
||||
|
||||
ubo_mi=nullptr;
|
||||
mi_count=0;
|
||||
}
|
||||
|
||||
VkBuffer RenderAssignBuffer::GetAssignVBO()const
|
||||
@ -44,6 +45,7 @@ void RenderAssignBuffer::Clear()
|
||||
SAFE_CLEAR(vbo_assigns);
|
||||
|
||||
node_count=0;
|
||||
mi_count=0;
|
||||
}
|
||||
|
||||
void RenderAssignBuffer::Alloc(const uint nc,const uint mc)
|
||||
@ -51,21 +53,21 @@ void RenderAssignBuffer::Alloc(const uint nc,const uint mc)
|
||||
Clear();
|
||||
|
||||
{
|
||||
node_count=power_to_2(nc);
|
||||
node_count=nc;
|
||||
|
||||
ubo_l2w=device->CreateUBO(node_count*sizeof(Matrix4f));
|
||||
}
|
||||
|
||||
if(mi_data_bytes>0&&mc>0)
|
||||
{
|
||||
mi_count=mc;
|
||||
|
||||
ubo_mi=device->CreateUBO(mi_data_bytes*mi_count);
|
||||
}
|
||||
|
||||
vbo_assigns=device->CreateVBO(ASSIGN_VBO_FMT,node_count);
|
||||
}
|
||||
|
||||
bool RenderAssignBuffer::WriteMIData(void *mi_data,const uint bytes)
|
||||
{
|
||||
if(!mi_data||!bytes||!ubo_mi)return(false);
|
||||
|
||||
return ubo_mi->Write(mi_data,bytes);
|
||||
}
|
||||
|
||||
void RenderAssignBuffer::WriteNode(RenderNode *render_node,const uint count,const MaterialInstanceSets &mi_set)
|
||||
{
|
||||
RenderNode *rn;
|
||||
@ -78,7 +80,7 @@ void RenderAssignBuffer::WriteNode(RenderNode *render_node,const uint count,cons
|
||||
|
||||
for(MaterialInstance *mi:mi_set)
|
||||
{
|
||||
// memcpy(mip,mi->GetData(),mi_data_bytes);
|
||||
memcpy(mip,mi->GetMIData(),mi_data_bytes);
|
||||
mip+=mi_data_bytes;
|
||||
}
|
||||
|
||||
@ -100,8 +102,8 @@ void RenderAssignBuffer::WriteNode(RenderNode *render_node,const uint count,cons
|
||||
*idp=i;
|
||||
++idp;
|
||||
|
||||
//*idp=mi_set.Find(rn->ri->GetMaterialInstance());
|
||||
//++idp;
|
||||
*idp=mi_set.Find(rn->ri->GetMaterialInstance());
|
||||
++idp;
|
||||
|
||||
++rn;
|
||||
}
|
||||
|
@ -37,6 +37,8 @@ private:
|
||||
uint node_count; ///<渲染节点数量
|
||||
DeviceBuffer *ubo_l2w; ///<Local2World数据
|
||||
|
||||
uint32_t mi_data_bytes; ///<材质实例数据字节数
|
||||
uint32_t mi_count; ///<材质实例数量
|
||||
DeviceBuffer *ubo_mi; ///<材质实例数据
|
||||
|
||||
//Assign VBO
|
||||
@ -56,10 +58,9 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
RenderAssignBuffer(GPUDevice *dev,const uint mi_total_bytes);
|
||||
RenderAssignBuffer(GPUDevice *dev,const uint32_t mi_bytes);
|
||||
~RenderAssignBuffer(){Clear();}
|
||||
|
||||
bool WriteMIData(void *,const uint);
|
||||
void WriteNode(RenderNode *render_node,const uint count,const MaterialInstanceSets &mi_set);
|
||||
|
||||
};//struct RenderAssignBuffer
|
||||
|
Loading…
x
Reference in New Issue
Block a user