增加InlineGeometry

This commit is contained in:
2019-05-24 19:28:27 +08:00
parent d97daabbc8
commit c912377dc3
8 changed files with 206 additions and 168 deletions

View File

@@ -4,9 +4,8 @@
// 二、试验动态合并材质渲染机制、包括普通合并与Instance
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/VertexBuffer.h>
#include<hgl/graph/InlineGeometry.h>
#include<hgl/type/ResManage.h>
using namespace hgl;
@@ -23,38 +22,29 @@ struct WorldConfig
Matrix4f mvp;
}world;
struct RectangleCreateInfo
{
RectScope2f scope;
};
VK_NAMESPACE_BEGIN
using MaterialID=int;
using PipelineID=int;
using DescriptorSetsID=int;
using RenderableID=int;
/**
* 场景DB用于管理场景内所需的所有数据
*/
class SceneDatabase
{
IDResManage<MaterialID, Material> rm_material; ///<材质合集
IDResManage<PipelineID, Pipeline> rm_pipeline; ///<管线合集
IDResManage<DescriptorSetsID, DescriptorSets> rm_desc_sets; ///<描述符合集
IDResManage<RenderableID, Renderable> rm_renderable; ///<可渲染对象合集
public:
MaterialID Add(Material *mtl)
{
if(!mtl)return(-1);
rm_material.Add(mtl);
}
PipelineID
};//class SceneDatabase
//using MaterialID=int;
//using PipelineID=int;
//using DescriptorSetsID=int;
//using RenderableID=int;
//
///**
// * 场景DB用于管理场景内所需的所有数据
// */
//class SceneDatabase
//{
// IDResManage<MaterialID, Material> rm_material; ///<材质合集
// IDResManage<PipelineID, Pipeline> rm_pipeline; ///<管线合集
// IDResManage<DescriptorSetsID, DescriptorSets> rm_desc_sets; ///<描述符合集
// IDResManage<RenderableID, Renderable> rm_renderable; ///<可渲染对象合集
//
//public:
//
// MaterialID Add(Material * mtl ){return rm_material.Add(mtl);}
// PipelineID Add(Pipeline * p ){return rm_pipeline.Add(p);}
// DescriptorSetsID Add(DescriptorSets *ds ){return rm_desc_sets.Add(ds);}
// RenderableID Add(Renderable * r ){return rm_renderable.Add(r);}
//};//class SceneDatabase
/**
* 可渲染对象实例
@@ -84,17 +74,6 @@ public:
// Adreno/NV/AMD: AlphaTest、不透明、半透明
// PowerVR: 同Adreno/NV/AMD但不透明部分可以不排序
if(pipeline->IsAlphaTest())
{
if(!ri->pipeline->IsAlphaTest())
return -1;
}
else
{
if(ri->pipeline->IsAlphaTest())
return 1;
}
if(pipeline->IsAlphaBlend())
{
if(!ri->pipeline->IsAlphaBlend())
@@ -106,6 +85,17 @@ public:
return -1;
}
if(pipeline->IsAlphaTest())
{
if(!ri->pipeline->IsAlphaTest())
return 1;
}
else
{
if(ri->pipeline->IsAlphaTest())
return -1;
}
if(pipeline!=ri->pipeline)
return pipeline-ri->pipeline;
@@ -121,124 +111,6 @@ VK_NAMESPACE_END
constexpr uint32_t VERTEX_COUNT=4;
vulkan::Renderable *CreateRectangle(vulkan::Device *device,vulkan::Material *mtl,const RectangleCreateInfo *rci)
{
const vulkan::VertexShaderModule *vsm=mtl->GetVertexShaderModule();
vulkan::Renderable *render_obj=mtl->CreateRenderable(VERTEX_COUNT);
const int vertex_binding=vsm->GetStageInputBinding("Vertex");
if(vertex_binding!=-1)
{
VB2f *vertex=new VB2f(VERTEX_COUNT);
vertex->Begin();
vertex->WriteRectFan(rci->scope);
vertex->End();
render_obj->Set(vertex_binding,device->CreateVBO(vertex));
delete vertex;
}
else
{
delete render_obj;
return nullptr;
}
return render_obj;
}
struct RoundRectangleCreateInfo:public RectangleCreateInfo
{
float radius; //圆角半径
uint32_t round_per; //圆角精度
};
vulkan::Renderable *CreateRoundRectangle(vulkan::Device *device,vulkan::Material *mtl,const RoundRectangleCreateInfo *rci)
{
const vulkan::VertexShaderModule *vsm=mtl->GetVertexShaderModule();
vulkan::Renderable *render_obj=nullptr;
const int vertex_binding=vsm->GetStageInputBinding("Vertex");
if(vertex_binding==-1)
return(nullptr);
VB2f *vertex=nullptr;
if(rci->radius==0||rci->round_per<=1) //这是要画矩形
{
vertex=new VB2f(4);
vertex->Begin();
vertex->WriteRectFan(rci->scope);
vertex->End();
}
else
{
float radius=rci->radius;
if(radius>rci->scope.GetWidth()/2.0f)radius=rci->scope.GetWidth()/2.0f;
if(radius>rci->scope.GetHeight()/2.0f)radius=rci->scope.GetHeight()/2.0f;
vertex=new VB2f(1+rci->round_per*4);
vertex->Begin();
vec2<float> *coord=new vec2<float>[rci->round_per];
for(uint i=0;i<rci->round_per;i++)
{
float ang=float(i)/float(rci->round_per-1)*90.0f;
float x=sin(hgl_ang2rad(ang))*radius;
float y=cos(hgl_ang2rad(ang))*radius;
coord[i].x=x;
coord[i].y=y;
//生成的是右上角的
vertex->Write( rci->scope.GetRight()-radius+x,
rci->scope.GetTop()+radius-y);
}
//右下角
for(uint i=0;i<rci->round_per;i++)
{
vertex->Write(rci->scope.GetRight() -radius+coord[rci->round_per-1-i].x,
rci->scope.GetBottom()-radius+coord[rci->round_per-1-i].y);
}
//左下角
for(uint i=0;i<rci->round_per;i++)
{
vertex->Write(rci->scope.GetLeft() +radius-coord[i].x,
rci->scope.GetBottom()-radius+coord[i].y);
}
//左上角
for(uint i=0;i<rci->round_per;i++)
{
vertex->Write(rci->scope.GetLeft() +radius-coord[rci->round_per-1-i].x,
rci->scope.GetTop() +radius-coord[rci->round_per-1-i].y);
}
vertex->Write(rci->scope.GetRight() -radius+coord[0].x,
rci->scope.GetTop() +radius-coord[0].y);
delete[] coord;
vertex->End();
}
render_obj=mtl->CreateRenderable(vertex->GetCount());
render_obj->Set(vertex_binding,device->CreateVBO(vertex));
delete vertex;
return render_obj;
}
class TestApp:public VulkanApplicationFramework
{