add SceneGraph/SceneTreeToRenderList.cpp, GPUDataArray.h, SceneRoot.h
This commit is contained in:
parent
ee35354d43
commit
07c761eab9
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit d065f24770fae3132012f11312495b3dc5ff3892
|
||||
Subproject commit 74f7f146ba6b79fd904f6fd47f4dbee0750831f6
|
@ -1 +1 @@
|
||||
Subproject commit 275dce7c49fd0d1b5ab61a51d18d356ddd2526d1
|
||||
Subproject commit fd6fefe93ebf844945c6366d6927447549727bf1
|
77
inc/hgl/graph/GPUDataArray.h
Normal file
77
inc/hgl/graph/GPUDataArray.h
Normal file
@ -0,0 +1,77 @@
|
||||
#ifndef HGL_GRAPH_GPU_DATA_ARRAY_INCLUDE
|
||||
#define HGL_GRAPH_GPU_DATA_ARRAY_INCLUDE
|
||||
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* GPU数据阵列
|
||||
**/
|
||||
class GPUDataArray
|
||||
{
|
||||
uint32_t alloc_count;
|
||||
uint32_t count;
|
||||
uint32_t item_size;
|
||||
|
||||
GPUBuffer * buf_gpu;
|
||||
uint8 * buf_cpu;
|
||||
|
||||
uint32_t * offset;
|
||||
|
||||
public:
|
||||
|
||||
GPUDataArray(const uint32_t s=0)
|
||||
{
|
||||
alloc_count=0;
|
||||
count=0;
|
||||
item_size=s;
|
||||
buf_gpu=nullptr;
|
||||
buf_cpu=nullptr;
|
||||
offset=nullptr;
|
||||
}
|
||||
|
||||
virtual ~GPUDataArray()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
virtual void Clear()
|
||||
{
|
||||
alloc_count=0;
|
||||
count=0;
|
||||
|
||||
if(buf_gpu)
|
||||
{
|
||||
buf_gpu->Unmap();
|
||||
delete buf_gpu;
|
||||
buf_gpu=nullptr;
|
||||
}
|
||||
|
||||
SAFE_CLEAR_ARRAY(buf_cpu);
|
||||
SAFE_CLEAR_ARRAY(offset);
|
||||
}
|
||||
|
||||
bool Init(const uint32_t c,const uint32_t s=0)
|
||||
{
|
||||
if(s
|
||||
&&item_size<=0)
|
||||
{
|
||||
if(s>HGL_SIZE_1KB*64)
|
||||
return(false);
|
||||
|
||||
item_size=s;
|
||||
}
|
||||
|
||||
count=c;
|
||||
|
||||
if(count*item_size<=0)
|
||||
return(false);
|
||||
|
||||
buf_cpu=new
|
||||
}
|
||||
};//class GPUDataArray
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_GPU_DATA_ARRAY_INCLUDE
|
@ -9,7 +9,7 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
struct L2WArrays;
|
||||
struct MVPArray;
|
||||
|
||||
class RenderList
|
||||
{
|
||||
@ -18,7 +18,9 @@ namespace hgl
|
||||
|
||||
private:
|
||||
|
||||
L2WArrays *LocalToWorld;
|
||||
Camera *camera;
|
||||
|
||||
MVPArray *mvp_array;
|
||||
|
||||
List<SceneNode *> scene_node_list;
|
||||
|
||||
@ -40,10 +42,38 @@ namespace hgl
|
||||
|
||||
void Begin ();
|
||||
void Add (SceneNode *);
|
||||
void End ();
|
||||
void End (CameraMatrix *);
|
||||
|
||||
bool Render (RenderCmdBuffer *);
|
||||
};//class RenderList
|
||||
|
||||
class SceneTreeToRenderList
|
||||
{
|
||||
GPUDevice *device;
|
||||
|
||||
public:
|
||||
|
||||
Camera * camera;
|
||||
CameraMatrix * camera_matrix;
|
||||
Frustum frustum;
|
||||
|
||||
public:
|
||||
|
||||
virtual uint32 CameraLength(SceneNode *,SceneNode *); ///<摄像机距离比较函数
|
||||
|
||||
virtual bool InFrustum(const SceneNode *,void *); ///<平截头截剪函数
|
||||
|
||||
public:
|
||||
|
||||
SceneTreeToRenderList(GPUDevice *d)
|
||||
{
|
||||
device=d;
|
||||
camera=nullptr;
|
||||
camera_matrix=nullptr;
|
||||
}
|
||||
|
||||
virtual bool Expend(RenderList *,Camera *,SceneNode *);
|
||||
};//class SceneTreeToRenderList
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_RENDER_LIST_INCLUDE
|
||||
|
@ -8,18 +8,6 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class SceneNode;
|
||||
struct Camera;
|
||||
class RenderList;
|
||||
|
||||
using RenderListCompFunc=float (*)(Camera *,SceneNode *,SceneNode *); ///<渲染列表排序比较函数
|
||||
|
||||
float CameraLengthComp(Camera *,SceneNode *,SceneNode *); ///<摄像机距离比较函数
|
||||
|
||||
using FilterSceneNodeFunc=bool (*)(const SceneNode *,void *); ///<场景节点过滤函数重定义
|
||||
|
||||
bool FrustumClipFilter(const SceneNode *,void *); ///<平截头截剪函数
|
||||
|
||||
/**
|
||||
* 场景节点数据类<br>
|
||||
* 从场景坐标变换(SceneOrient)类继承
|
||||
|
23
inc/hgl/graph/SceneRoot.h
Normal file
23
inc/hgl/graph/SceneRoot.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef HGL_GRAPH_SCENE_ROOT_INCLUDE
|
||||
#define HGL_GRAPH_SCENE_ROOT_INCLUDE
|
||||
|
||||
#include<hgl/graph/Camera.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* 场景根节点
|
||||
*/
|
||||
class SceneRoot
|
||||
{
|
||||
Camera *camera; ///<根相机
|
||||
|
||||
public:
|
||||
|
||||
|
||||
};//class SceneRoot
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_SCENE_ROOT_INCLUDE
|
@ -42,6 +42,7 @@ SET(SCENE_GRAPH_SOURCE RenderList.cpp
|
||||
SceneNode.cpp
|
||||
SceneOrient.cpp
|
||||
InlineGeometry.cpp
|
||||
SceneTreeToRenderList.cpp
|
||||
#InlinePipeline.cpp
|
||||
#Material.cpp
|
||||
#Mesh.cpp
|
||||
|
@ -12,44 +12,31 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
constexpr uint32_t L2WItemBytes=sizeof(Matrix4f); ///<单个L2W数据字节数
|
||||
|
||||
struct L2WArrays
|
||||
/**
|
||||
* MVP矩阵
|
||||
*/
|
||||
struct MVPMatrix
|
||||
{
|
||||
uint alloc_count;
|
||||
uint count;
|
||||
Matrix4f l2w; ///< Local to World
|
||||
Matrix4f inverse_l2w;
|
||||
|
||||
List<Matrix4f> items;
|
||||
GPUBuffer *buffer;
|
||||
Matrix4f *buffer_address;
|
||||
List<uint32_t> offset;
|
||||
Matrix4f mvp; ///< projection * view * local_to_world
|
||||
Matrix4f inverse_mvp;
|
||||
|
||||
public:
|
||||
|
||||
L2WArrays()
|
||||
void Set(const Matrix4f &w,const Matrix4f &vp)
|
||||
{
|
||||
alloc_count=0;
|
||||
count=0;
|
||||
buffer=nullptr;
|
||||
buffer_address=nullptr;
|
||||
}
|
||||
l2w=w;
|
||||
inverse_l2w=l2w.Inverted();
|
||||
|
||||
~L2WArrays()
|
||||
{
|
||||
if(buffer)
|
||||
{
|
||||
buffer->Unmap();
|
||||
delete buffer;
|
||||
}
|
||||
mvp=vp*l2w;
|
||||
inverse_mvp=mvp.Inverted();
|
||||
}
|
||||
};//struct MVPMatrix
|
||||
|
||||
constexpr size_t MVPMatrixBytes=sizeof(MVPMatrix);
|
||||
|
||||
void Init(const uint32_t c)
|
||||
{
|
||||
count=c;
|
||||
items.SetCount(count);
|
||||
offset.SetCount(count);
|
||||
}
|
||||
};//
|
||||
|
||||
float CameraLengthComp(Camera *cam,SceneNode *obj_one,SceneNode *obj_two)
|
||||
{
|
||||
@ -75,12 +62,12 @@ namespace hgl
|
||||
last_pipeline =nullptr;
|
||||
last_ri =nullptr;
|
||||
|
||||
LocalToWorld=new L2WArrays;
|
||||
mvp_array=new MVPArray;
|
||||
}
|
||||
|
||||
RenderList::~RenderList()
|
||||
{
|
||||
delete LocalToWorld;
|
||||
delete mvp_array;
|
||||
}
|
||||
|
||||
void RenderList::Begin()
|
||||
@ -98,58 +85,58 @@ namespace hgl
|
||||
scene_node_list.Add(node);
|
||||
}
|
||||
|
||||
void RenderList::End()
|
||||
void RenderList::End(CameraMatrix *camera_matrix)
|
||||
{
|
||||
//清0计数器
|
||||
uint32_t l2w_count=0; //local to world矩阵总数量
|
||||
uint32_t mvp_count=0; //local to world矩阵总数量
|
||||
|
||||
//统计Render
|
||||
const uint32_t count=scene_node_list.GetCount();
|
||||
|
||||
LocalToWorld->Init(count);
|
||||
mvp_array->Init(count);
|
||||
|
||||
Matrix4f *mp=LocalToWorld->items.GetData();
|
||||
uint32_t *op=LocalToWorld->offset.GetData();
|
||||
MVPMatrix *mp=mvp_array->items.GetData();
|
||||
uint32_t *op=mvp_array->offset.GetData();
|
||||
|
||||
for(SceneNode *node:scene_node_list)
|
||||
{
|
||||
const Matrix4f &mat=node->GetLocalToWorldMatrix();
|
||||
const Matrix4f &l2w=node->GetLocalToWorldMatrix();
|
||||
|
||||
if(!mat.IsIdentity())
|
||||
if(!l2w.IsIdentity())
|
||||
{
|
||||
hgl_cpy(mp,&mat);
|
||||
mp->Set(l2w,camera_matrix->vp);
|
||||
++mp;
|
||||
|
||||
*op=(l2w_count)*L2WItemBytes;
|
||||
++l2w_count;
|
||||
*op=(mvp_count)*MVPMatrixBytes;
|
||||
++mvp_count;
|
||||
}
|
||||
else
|
||||
{
|
||||
*op=l2w_count;
|
||||
*op=mvp_count;
|
||||
}
|
||||
|
||||
++op;
|
||||
}
|
||||
|
||||
if(LocalToWorld->buffer)
|
||||
if(mvp_array->buffer)
|
||||
{
|
||||
if(LocalToWorld->alloc_count<l2w_count)
|
||||
if(mvp_array->alloc_count<mvp_count)
|
||||
{
|
||||
LocalToWorld->buffer->Unmap();
|
||||
delete LocalToWorld->buffer;
|
||||
LocalToWorld->buffer=nullptr;
|
||||
// LocalToWorld->buffer_address=nullptr; //下面一定会重写,所以这一行没必要操作
|
||||
mvp_array->buffer->Unmap();
|
||||
delete mvp_array->buffer;
|
||||
mvp_array->buffer=nullptr;
|
||||
// mvp_array->buffer_address=nullptr; //下面一定会重写,所以这一行没必要操作
|
||||
}
|
||||
}
|
||||
|
||||
if(!LocalToWorld->buffer)
|
||||
if(!mvp_array->buffer)
|
||||
{
|
||||
LocalToWorld->alloc_count=power_to_2(l2w_count);
|
||||
LocalToWorld->buffer=device->CreateUBO(LocalToWorld->alloc_count*L2WItemBytes);
|
||||
LocalToWorld->buffer_address=(Matrix4f *)(LocalToWorld->buffer->Map());
|
||||
mvp_array->alloc_count=power_to_2(mvp_count);
|
||||
mvp_array->buffer=device->CreateUBO(mvp_array->alloc_count*MVPMatrixBytes);
|
||||
mvp_array->buffer_address=(MVPMatrix *)(mvp_array->buffer->Map());
|
||||
}
|
||||
|
||||
hgl_cpy(LocalToWorld->buffer_address,LocalToWorld->items.GetData(),l2w_count);
|
||||
hgl_cpy(mvp_array->buffer_address,mvp_array->items.GetData(),mvp_count);
|
||||
}
|
||||
|
||||
void RenderList::Render(SceneNode *node,RenderableInstance *ri)
|
||||
|
29
src/SceneGraph/SceneTreeToRenderList.cpp
Normal file
29
src/SceneGraph/SceneTreeToRenderList.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include<hgl/graph/RenderList.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
uint32 SceneTreeToRenderList::CameraLength(SceneNode *,SceneNode *)
|
||||
{
|
||||
}
|
||||
|
||||
bool SceneTreeToRenderList::InFrustum(const SceneNode *,void *)
|
||||
{
|
||||
}
|
||||
|
||||
bool SceneTreeToRenderList::Expend(RenderList *rl,Camera *c,SceneNode *sn)
|
||||
{
|
||||
if(!device)return(false);
|
||||
if(!rl||!c||sn)return(false);
|
||||
|
||||
camera=c;
|
||||
camera->Refresh();
|
||||
camera_matrix=&(camera->matrix);
|
||||
|
||||
//Frustum f;
|
||||
|
||||
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
Loading…
x
Reference in New Issue
Block a user