2019-05-25 00:50:04 +08:00
|
|
|
|
#include<hgl/graph/RenderList.h>
|
|
|
|
|
#include<hgl/graph/Camera.h>
|
2019-05-21 21:28:33 +08:00
|
|
|
|
#include<hgl/graph/SceneNode.h>
|
2019-05-24 21:43:59 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKRenderable.h>
|
2019-05-25 00:50:04 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKCommandBuffer.h>
|
2019-05-21 21:28:33 +08:00
|
|
|
|
#include<hgl/graph/VertexBuffer.h>
|
2019-05-24 21:43:59 +08:00
|
|
|
|
#include<hgl/math/Math.h>
|
2019-05-21 21:28:33 +08:00
|
|
|
|
|
2019-05-25 00:50:04 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKRenderableInstance.h>
|
|
|
|
|
|
2019-05-21 21:28:33 +08:00
|
|
|
|
namespace hgl
|
|
|
|
|
{
|
|
|
|
|
namespace graph
|
|
|
|
|
{
|
2019-05-24 21:43:59 +08:00
|
|
|
|
float CameraLengthComp(Camera *cam,SceneNode *obj_one,SceneNode *obj_two)
|
2019-05-21 21:28:33 +08:00
|
|
|
|
{
|
|
|
|
|
if(!cam||!obj_one||!obj_two)
|
|
|
|
|
return(0);
|
|
|
|
|
|
2019-05-24 21:43:59 +08:00
|
|
|
|
return( length_squared(obj_one->GetCenter(),cam->eye)-
|
2019-05-21 21:28:33 +08:00
|
|
|
|
length_squared(obj_two->GetCenter(),cam->eye));
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-24 21:43:59 +08:00
|
|
|
|
//bool FrustumClipFilter(const SceneNode *node,void *fc)
|
|
|
|
|
//{
|
|
|
|
|
// if(!node||!fc)return(false);
|
2019-05-21 21:28:33 +08:00
|
|
|
|
|
2019-05-24 21:43:59 +08:00
|
|
|
|
// return (((Frustum *)fc)->BoxIn(node->GetWorldBoundingBox())!=Frustum::OUTSIDE);
|
|
|
|
|
//}
|
2019-05-21 21:28:33 +08:00
|
|
|
|
|
2019-05-25 00:50:04 +08:00
|
|
|
|
void RenderList::SetCamera(const Camera &cam)
|
|
|
|
|
{
|
|
|
|
|
camera=cam;
|
|
|
|
|
|
|
|
|
|
MakeCameraMatrix( &projection_matrix,
|
|
|
|
|
&modelview_matrix,
|
|
|
|
|
&camera);
|
|
|
|
|
|
|
|
|
|
mvp_matrix=projection_matrix*modelview_matrix;
|
|
|
|
|
|
|
|
|
|
CameraToFrustum(&frustum,
|
|
|
|
|
&camera);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RenderList::Render(vulkan::RenderableInstance *ri,const Matrix4f &fin_mvp)
|
2019-05-21 21:28:33 +08:00
|
|
|
|
{
|
2019-05-25 00:50:04 +08:00
|
|
|
|
if(last_pipeline!=ri->GetPipeline())
|
|
|
|
|
{
|
|
|
|
|
cmd_buf->Bind(ri->GetPipeline());
|
|
|
|
|
|
|
|
|
|
last_pipeline=ri->GetPipeline();
|
|
|
|
|
|
|
|
|
|
cmd_buf->Bind(ri->GetDescriptorSets());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(last_desc_sets!=ri->GetDescriptorSets())
|
|
|
|
|
{
|
|
|
|
|
cmd_buf->Bind(ri->GetDescriptorSets());
|
|
|
|
|
|
|
|
|
|
last_desc_sets=ri->GetDescriptorSets();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新fin_mvp
|
|
|
|
|
|
|
|
|
|
vulkan::Renderable *obj=ri->GetRenderable();
|
|
|
|
|
|
|
|
|
|
if(obj!=last_renderable)
|
|
|
|
|
{
|
|
|
|
|
cmd_buf->Bind(obj);
|
|
|
|
|
|
|
|
|
|
last_renderable=obj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const vulkan::IndexBuffer *ib=obj->GetIndexBuffer();
|
|
|
|
|
|
|
|
|
|
if(ib)
|
|
|
|
|
{
|
|
|
|
|
cmd_buf->DrawIndexed(ib->GetCount());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cmd_buf->Draw(obj->GetDrawCount());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RenderList::Render()
|
|
|
|
|
{
|
|
|
|
|
if(!cmd_buf)
|
2019-05-21 21:28:33 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2019-05-25 00:50:04 +08:00
|
|
|
|
last_pipeline=nullptr;
|
|
|
|
|
last_desc_sets=nullptr;
|
|
|
|
|
last_renderable=nullptr;
|
|
|
|
|
|
|
|
|
|
int count=SceneNodeList.GetCount();
|
|
|
|
|
const SceneNode **node=SceneNodeList.GetData();
|
2019-05-21 21:28:33 +08:00
|
|
|
|
|
|
|
|
|
for(int i=0;i<count;i++)
|
|
|
|
|
{
|
2019-05-25 00:50:04 +08:00
|
|
|
|
const Matrix4f fin_mv=modelview_matrix*(*node)->GetLocalToWorldMatrix();
|
2019-05-21 21:28:33 +08:00
|
|
|
|
|
2019-05-25 00:15:10 +08:00
|
|
|
|
int sn=(*node)->RenderableList.GetCount();
|
|
|
|
|
RenderableInstance **p=(*node)->RenderableList.GetData();
|
2019-05-21 21:28:33 +08:00
|
|
|
|
|
|
|
|
|
for(int j=0;j<sn;j++)
|
|
|
|
|
{
|
2019-05-25 00:50:04 +08:00
|
|
|
|
Render(*p,projection_matrix*fin_mv);
|
2019-05-21 21:28:33 +08:00
|
|
|
|
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
}//namespace graph
|
|
|
|
|
}//namespace hgl
|