diff --git a/example/Vulkan/Geometry2D.cpp b/example/Vulkan/Geometry2D.cpp index d37aa4b4..744300a8 100644 --- a/example/Vulkan/Geometry2D.cpp +++ b/example/Vulkan/Geometry2D.cpp @@ -4,9 +4,8 @@ // 二、试验动态合并材质渲染机制、包括普通合并与Instance #include"VulkanAppFramework.h" -#include #include -#include +#include #include 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 rm_material; ///<材质合集 - IDResManage rm_pipeline; ///<管线合集 - IDResManage rm_desc_sets; ///<描述符合集 - IDResManage 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 rm_material; ///<材质合集 +// IDResManage rm_pipeline; ///<管线合集 +// IDResManage rm_desc_sets; ///<描述符合集 +// IDResManage 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 *coord=new vec2[rci->round_per]; - - for(uint i=0;iround_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;iround_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;iround_per;i++) - { - vertex->Write(rci->scope.GetLeft() +radius-coord[i].x, - rci->scope.GetBottom()-radius+coord[i].y); - } - - //左上角 - for(uint i=0;iround_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 { diff --git a/example/Vulkan/indices_rect.cpp b/example/Vulkan/indices_rect.cpp index 7ec0fd0e..80789377 100644 --- a/example/Vulkan/indices_rect.cpp +++ b/example/Vulkan/indices_rect.cpp @@ -73,7 +73,7 @@ private: if(!material) return(false); - render_obj=material->CreateRenderable(); + render_obj=material->CreateRenderable(VERTEX_COUNT); descriptor_sets=material->CreateDescriptorSets(); return(true); } diff --git a/example/Vulkan/main.cpp b/example/Vulkan/main.cpp index f4659205..1c31f1f5 100644 --- a/example/Vulkan/main.cpp +++ b/example/Vulkan/main.cpp @@ -74,7 +74,7 @@ private: if(!material) return(false); - render_obj=material->CreateRenderable(); + render_obj=material->CreateRenderable(VERTEX_COUNT); descriptor_sets=material->CreateDescriptorSets(); return(true); } diff --git a/example/Vulkan/texture_rect.cpp b/example/Vulkan/texture_rect.cpp index 94a08319..6a491743 100644 --- a/example/Vulkan/texture_rect.cpp +++ b/example/Vulkan/texture_rect.cpp @@ -93,7 +93,7 @@ private: if(!material) return(false); - render_obj=material->CreateRenderable(); + render_obj=material->CreateRenderable(VERTEX_COUNT); desciptor_sets=material->CreateDescriptorSets(); texture=vulkan::LoadTGATexture(OS_TEXT("lena.tga"),device); diff --git a/inc/hgl/graph/InlineGeometry.h b/inc/hgl/graph/InlineGeometry.h new file mode 100644 index 00000000..016a8ec1 --- /dev/null +++ b/inc/hgl/graph/InlineGeometry.h @@ -0,0 +1,42 @@ +#ifndef HGL_GRAPH_INLINE_GEOMETRY_INCLUDE +#define HGL_GRAPH_INLINE_GEOMETRY_INCLUDE + +#include +#include +#include +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 diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index 8cfbeeb3..62da6e3f 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -18,7 +18,8 @@ Android/NativeActivitySupport.cpp) 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} UNIX/Semaphore.cpp) diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index 5b0413ee..47f83bbc 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -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/SceneOrient.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 Camera.cpp # RenderList.cpp SceneNode.cpp - SceneOrient.cpp) + SceneOrient.cpp + InlineGeometry.cpp) SOURCE_GROUP("Header Files" FILES ${SCENE_GRAPH_HEADER}) SOURCE_GROUP("Source Files" FILES ${SCENE_GRAPH_SOURCE}) diff --git a/src/SceneGraph/InlineGeometry.cpp b/src/SceneGraph/InlineGeometry.cpp new file mode 100644 index 00000000..c1ba4524 --- /dev/null +++ b/src/SceneGraph/InlineGeometry.cpp @@ -0,0 +1,121 @@ +#include +#include +#include +#include +#include +#include +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 *coord=new vec2[rci->round_per]; + + for(uint i=0;iround_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;iround_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;iround_per;i++) + { + vertex->Write(rci->scope.GetLeft() +radius-coord[i].x, + rci->scope.GetBottom()-radius+coord[i].y); + } + + //左上角 + for(uint i=0;iround_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 \ No newline at end of file