增加InlineGeometry
This commit is contained in:
parent
d97daabbc8
commit
c912377dc3
@ -4,9 +4,8 @@
|
|||||||
// 二、试验动态合并材质渲染机制、包括普通合并与Instance
|
// 二、试验动态合并材质渲染机制、包括普通合并与Instance
|
||||||
|
|
||||||
#include"VulkanAppFramework.h"
|
#include"VulkanAppFramework.h"
|
||||||
#include<hgl/math/Math.h>
|
|
||||||
#include<hgl/filesystem/FileSystem.h>
|
#include<hgl/filesystem/FileSystem.h>
|
||||||
#include<hgl/graph/VertexBuffer.h>
|
#include<hgl/graph/InlineGeometry.h>
|
||||||
#include<hgl/type/ResManage.h>
|
#include<hgl/type/ResManage.h>
|
||||||
|
|
||||||
using namespace hgl;
|
using namespace hgl;
|
||||||
@ -23,38 +22,29 @@ struct WorldConfig
|
|||||||
Matrix4f mvp;
|
Matrix4f mvp;
|
||||||
}world;
|
}world;
|
||||||
|
|
||||||
struct RectangleCreateInfo
|
|
||||||
{
|
|
||||||
RectScope2f scope;
|
|
||||||
};
|
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
using MaterialID=int;
|
//using MaterialID=int;
|
||||||
using PipelineID=int;
|
//using PipelineID=int;
|
||||||
using DescriptorSetsID=int;
|
//using DescriptorSetsID=int;
|
||||||
using RenderableID=int;
|
//using RenderableID=int;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* 场景DB,用于管理场景内所需的所有数据
|
// * 场景DB,用于管理场景内所需的所有数据
|
||||||
*/
|
// */
|
||||||
class SceneDatabase
|
//class SceneDatabase
|
||||||
{
|
//{
|
||||||
IDResManage<MaterialID, Material> rm_material; ///<材质合集
|
// IDResManage<MaterialID, Material> rm_material; ///<材质合集
|
||||||
IDResManage<PipelineID, Pipeline> rm_pipeline; ///<管线合集
|
// IDResManage<PipelineID, Pipeline> rm_pipeline; ///<管线合集
|
||||||
IDResManage<DescriptorSetsID, DescriptorSets> rm_desc_sets; ///<描述符合集
|
// IDResManage<DescriptorSetsID, DescriptorSets> rm_desc_sets; ///<描述符合集
|
||||||
IDResManage<RenderableID, Renderable> rm_renderable; ///<可渲染对象合集
|
// IDResManage<RenderableID, Renderable> rm_renderable; ///<可渲染对象合集
|
||||||
|
//
|
||||||
public:
|
//public:
|
||||||
|
//
|
||||||
MaterialID Add(Material *mtl)
|
// MaterialID Add(Material * mtl ){return rm_material.Add(mtl);}
|
||||||
{
|
// PipelineID Add(Pipeline * p ){return rm_pipeline.Add(p);}
|
||||||
if(!mtl)return(-1);
|
// DescriptorSetsID Add(DescriptorSets *ds ){return rm_desc_sets.Add(ds);}
|
||||||
|
// RenderableID Add(Renderable * r ){return rm_renderable.Add(r);}
|
||||||
rm_material.Add(mtl);
|
//};//class SceneDatabase
|
||||||
}
|
|
||||||
|
|
||||||
PipelineID
|
|
||||||
};//class SceneDatabase
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 可渲染对象实例
|
* 可渲染对象实例
|
||||||
@ -84,17 +74,6 @@ public:
|
|||||||
// Adreno/NV/AMD: AlphaTest、不透明、半透明
|
// Adreno/NV/AMD: AlphaTest、不透明、半透明
|
||||||
// PowerVR: 同Adreno/NV/AMD,但不透明部分可以不排序
|
// PowerVR: 同Adreno/NV/AMD,但不透明部分可以不排序
|
||||||
|
|
||||||
if(pipeline->IsAlphaTest())
|
|
||||||
{
|
|
||||||
if(!ri->pipeline->IsAlphaTest())
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(ri->pipeline->IsAlphaTest())
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(pipeline->IsAlphaBlend())
|
if(pipeline->IsAlphaBlend())
|
||||||
{
|
{
|
||||||
if(!ri->pipeline->IsAlphaBlend())
|
if(!ri->pipeline->IsAlphaBlend())
|
||||||
@ -106,6 +85,17 @@ public:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(pipeline->IsAlphaTest())
|
||||||
|
{
|
||||||
|
if(!ri->pipeline->IsAlphaTest())
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(ri->pipeline->IsAlphaTest())
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if(pipeline!=ri->pipeline)
|
if(pipeline!=ri->pipeline)
|
||||||
return pipeline-ri->pipeline;
|
return pipeline-ri->pipeline;
|
||||||
|
|
||||||
@ -121,124 +111,6 @@ VK_NAMESPACE_END
|
|||||||
|
|
||||||
constexpr uint32_t VERTEX_COUNT=4;
|
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
|
class TestApp:public VulkanApplicationFramework
|
||||||
{
|
{
|
||||||
|
@ -73,7 +73,7 @@ private:
|
|||||||
if(!material)
|
if(!material)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
render_obj=material->CreateRenderable();
|
render_obj=material->CreateRenderable(VERTEX_COUNT);
|
||||||
descriptor_sets=material->CreateDescriptorSets();
|
descriptor_sets=material->CreateDescriptorSets();
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ private:
|
|||||||
if(!material)
|
if(!material)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
render_obj=material->CreateRenderable();
|
render_obj=material->CreateRenderable(VERTEX_COUNT);
|
||||||
descriptor_sets=material->CreateDescriptorSets();
|
descriptor_sets=material->CreateDescriptorSets();
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ private:
|
|||||||
if(!material)
|
if(!material)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
render_obj=material->CreateRenderable();
|
render_obj=material->CreateRenderable(VERTEX_COUNT);
|
||||||
desciptor_sets=material->CreateDescriptorSets();
|
desciptor_sets=material->CreateDescriptorSets();
|
||||||
|
|
||||||
texture=vulkan::LoadTGATexture(OS_TEXT("lena.tga"),device);
|
texture=vulkan::LoadTGATexture(OS_TEXT("lena.tga"),device);
|
||||||
|
42
inc/hgl/graph/InlineGeometry.h
Normal file
42
inc/hgl/graph/InlineGeometry.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#ifndef HGL_GRAPH_INLINE_GEOMETRY_INCLUDE
|
||||||
|
#define HGL_GRAPH_INLINE_GEOMETRY_INCLUDE
|
||||||
|
|
||||||
|
#include<hgl/graph/vulkan/VK.h>
|
||||||
|
#include<hgl/math/Vector.h>
|
||||||
|
#include<hgl/type/RectScope.h>
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
namespace graph
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 矩形创建信息
|
||||||
|
*/
|
||||||
|
struct RectangleCreateInfo
|
||||||
|
{
|
||||||
|
RectScope2f scope;
|
||||||
|
};
|
||||||
|
|
||||||
|
vulkan::Renderable *CreateRectangle(vulkan::Device *device,vulkan::Material *mtl,const RectangleCreateInfo *rci);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 圆角矩形创建信息
|
||||||
|
*/
|
||||||
|
struct RoundRectangleCreateInfo:public RectangleCreateInfo
|
||||||
|
{
|
||||||
|
float radius; //圆角半径
|
||||||
|
uint32_t round_per; //圆角精度
|
||||||
|
};
|
||||||
|
|
||||||
|
vulkan::Renderable *CreateRoundRectangle(vulkan::Device *device,vulkan::Material *mtl,const RoundRectangleCreateInfo *rci);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 圆形创建信息
|
||||||
|
*/
|
||||||
|
struct CircleCreateInfo
|
||||||
|
{
|
||||||
|
Vector2f center;
|
||||||
|
uint field_count; //分段次数
|
||||||
|
};
|
||||||
|
}//namespace graph
|
||||||
|
};//namespace hgl
|
||||||
|
#endif//HGL_GRAPH_INLINE_GEOMETRY_INCLUDE
|
@ -18,7 +18,8 @@
|
|||||||
Android/NativeActivitySupport.cpp)
|
Android/NativeActivitySupport.cpp)
|
||||||
|
|
||||||
SET(PLATFORM_FILE_SOURCE ${PLATFORM_FILE_SOURCE}
|
SET(PLATFORM_FILE_SOURCE ${PLATFORM_FILE_SOURCE}
|
||||||
Android/ProgramPath.cpp)
|
Android/ProgramPath.cpp
|
||||||
|
Android/AssetManage.cpp)
|
||||||
|
|
||||||
SET(PLATFORM_MULTI_THREAD_SOURCE ${PLATFORM_MULTI_THREAD_SOURCE}
|
SET(PLATFORM_MULTI_THREAD_SOURCE ${PLATFORM_MULTI_THREAD_SOURCE}
|
||||||
UNIX/Semaphore.cpp)
|
UNIX/Semaphore.cpp)
|
||||||
|
@ -4,13 +4,15 @@ SET(SCENE_GRAPH_HEADER ${ROOT_INCLUDE_PATH}/hgl/graph/AABox.h
|
|||||||
${ROOT_INCLUDE_PATH}/hgl/graph/SceneNode.h
|
${ROOT_INCLUDE_PATH}/hgl/graph/SceneNode.h
|
||||||
${ROOT_INCLUDE_PATH}/hgl/graph/SceneOrient.h
|
${ROOT_INCLUDE_PATH}/hgl/graph/SceneOrient.h
|
||||||
${ROOT_INCLUDE_PATH}/hgl/graph/VertexBufferCreater.h
|
${ROOT_INCLUDE_PATH}/hgl/graph/VertexBufferCreater.h
|
||||||
${ROOT_INCLUDE_PATH}/hgl/graph/VertexBuffer.h)
|
${ROOT_INCLUDE_PATH}/hgl/graph/VertexBuffer.h
|
||||||
|
${ROOT_INCLUDE_PATH}/hgl/graph/InlineGeometry.h)
|
||||||
|
|
||||||
SET(SCENE_GRAPH_SOURCE AABox.cpp
|
SET(SCENE_GRAPH_SOURCE AABox.cpp
|
||||||
Camera.cpp
|
Camera.cpp
|
||||||
# RenderList.cpp
|
# RenderList.cpp
|
||||||
SceneNode.cpp
|
SceneNode.cpp
|
||||||
SceneOrient.cpp)
|
SceneOrient.cpp
|
||||||
|
InlineGeometry.cpp)
|
||||||
|
|
||||||
SOURCE_GROUP("Header Files" FILES ${SCENE_GRAPH_HEADER})
|
SOURCE_GROUP("Header Files" FILES ${SCENE_GRAPH_HEADER})
|
||||||
SOURCE_GROUP("Source Files" FILES ${SCENE_GRAPH_SOURCE})
|
SOURCE_GROUP("Source Files" FILES ${SCENE_GRAPH_SOURCE})
|
||||||
|
121
src/SceneGraph/InlineGeometry.cpp
Normal file
121
src/SceneGraph/InlineGeometry.cpp
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
#include<hgl/graph/InlineGeometry.h>
|
||||||
|
#include<hgl/graph/VertexBuffer.h>
|
||||||
|
#include<hgl/graph/vulkan/VKDevice.h>
|
||||||
|
#include<hgl/graph/vulkan/VKMaterial.h>
|
||||||
|
#include<hgl/graph/vulkan/VKRenderable.h>
|
||||||
|
#include<hgl/graph/vulkan/VKShaderModule.h>
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
namespace graph
|
||||||
|
{
|
||||||
|
vulkan::Renderable *CreateRectangle(vulkan::Device *device,vulkan::Material *mtl,const RectangleCreateInfo *rci)
|
||||||
|
{
|
||||||
|
const vulkan::VertexShaderModule *vsm=mtl->GetVertexShaderModule();
|
||||||
|
|
||||||
|
vulkan::Renderable *render_obj=mtl->CreateRenderable(4);
|
||||||
|
|
||||||
|
const int vertex_binding=vsm->GetStageInputBinding("Vertex");
|
||||||
|
|
||||||
|
if(vertex_binding!=-1)
|
||||||
|
{
|
||||||
|
VB2f *vertex=new VB2f(4);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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(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);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete[] coord;
|
||||||
|
|
||||||
|
vertex->End();
|
||||||
|
}
|
||||||
|
|
||||||
|
render_obj=mtl->CreateRenderable(vertex->GetCount());
|
||||||
|
render_obj->Set(vertex_binding,device->CreateVBO(vertex));
|
||||||
|
|
||||||
|
delete vertex;
|
||||||
|
|
||||||
|
return render_obj;
|
||||||
|
}
|
||||||
|
}//namespace graph
|
||||||
|
}//namespace hgl
|
Loading…
x
Reference in New Issue
Block a user