From 3fd9d1535d85269270b70a8ff901de484aff2624 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 2 Sep 2020 19:06:12 +0800 Subject: [PATCH] use Prim instead macros. use IndexType instead VkIndexType --- example/Vulkan/Atomsphere.cpp | 2 +- example/Vulkan/DrawText.cpp | 2 +- example/Vulkan/DrawTile.cpp | 2 +- example/Vulkan/Geometry2D.cpp | 2 +- example/Vulkan/Geometry3D.cpp | 8 ++--- example/Vulkan/HQFilterTexture.cpp | 2 +- example/Vulkan/InlineGeometryScene.cpp | 4 +-- example/Vulkan/LoadStaticMesh.cpp | 4 +-- example/Vulkan/RectanglePrimitive.cpp | 2 +- example/Vulkan/SceneTree.cpp | 2 +- example/Vulkan/VulkanAppFramework.h | 6 ++-- example/Vulkan/first_triangle.cpp | 2 +- example/Vulkan/indices_rect.cpp | 2 +- example/Vulkan/texture_rect.cpp | 2 +- inc/hgl/graph/InlineGeometry.h | 30 ++++++++-------- inc/hgl/graph/vulkan/VK.h | 8 +++++ inc/hgl/graph/vulkan/VKBuffer.h | 8 ++--- inc/hgl/graph/vulkan/VKDatabase.h | 12 +++---- inc/hgl/graph/vulkan/VKDevice.h | 18 +++++----- inc/hgl/graph/vulkan/VKPipeline.h | 4 +-- inc/hgl/graph/vulkan/VKPrimivate.h | 38 ++++++++++++--------- src/RenderDevice/Vulkan/VKCommandBuffer.cpp | 2 +- src/RenderDevice/Vulkan/VKDatabase.cpp | 2 +- src/RenderDevice/Vulkan/VKDeviceBuffer.cpp | 6 ++-- src/RenderDevice/Vulkan/VKPipeline.cpp | 8 ++--- 25 files changed, 95 insertions(+), 83 deletions(-) diff --git a/example/Vulkan/Atomsphere.cpp b/example/Vulkan/Atomsphere.cpp index 2cefa53d..b1a330f2 100644 --- a/example/Vulkan/Atomsphere.cpp +++ b/example/Vulkan/Atomsphere.cpp @@ -92,7 +92,7 @@ private: pipeline_creater->SetDepthTest(true); pipeline_creater->SetDepthWrite(true); pipeline_creater->SetCullMode(VK_CULL_MODE_NONE); - pipeline_creater->Set(PRIM_TRIANGLES); + pipeline_creater->Set(Prim::Triangles); pipeline_solid=pipeline_creater->Create(); if(!pipeline_solid) diff --git a/example/Vulkan/DrawText.cpp b/example/Vulkan/DrawText.cpp index 81de9223..baa35b7a 100644 --- a/example/Vulkan/DrawText.cpp +++ b/example/Vulkan/DrawText.cpp @@ -108,7 +108,7 @@ private: AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target); pipeline_creater->CloseCullFace(); - pipeline_creater->Set(PRIM_RECTANGLES); + pipeline_creater->Set(Prim::Rectangles); pipeline=pipeline_creater->Create(); diff --git a/example/Vulkan/DrawTile.cpp b/example/Vulkan/DrawTile.cpp index 36113787..e2b51458 100644 --- a/example/Vulkan/DrawTile.cpp +++ b/example/Vulkan/DrawTile.cpp @@ -204,7 +204,7 @@ private: AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target); pipeline_creater->CloseCullFace(); - pipeline_creater->Set(PRIM_RECTANGLES); + pipeline_creater->Set(Prim::Rectangles); pipeline=pipeline_creater->Create(); diff --git a/example/Vulkan/Geometry2D.cpp b/example/Vulkan/Geometry2D.cpp index ac5c96af..51ea0cc3 100644 --- a/example/Vulkan/Geometry2D.cpp +++ b/example/Vulkan/Geometry2D.cpp @@ -133,7 +133,7 @@ private: AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target); pipeline_creater->CloseCullFace(); - pipeline_creater->Set(PRIM_TRIANGLE_FAN); + pipeline_creater->Set(Prim::Fan); pipeline=pipeline_creater->Create(); if(!pipeline)return(false); diff --git a/example/Vulkan/Geometry3D.cpp b/example/Vulkan/Geometry3D.cpp index ae56a859..adc04a1b 100644 --- a/example/Vulkan/Geometry3D.cpp +++ b/example/Vulkan/Geometry3D.cpp @@ -59,7 +59,7 @@ private: return(true); } - bool InitPipeline(MDP *mdp,const VkPrimitiveTopology primitive) + bool InitPipeline(MDP *mdp,const Prim primitive) { AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,mdp->material,sc_render_target); @@ -75,7 +75,7 @@ private: return(true); } - bool InitMDP(MDP *mdp,const VkPrimitiveTopology primitive,const OSString &vs,const OSString &fs) + bool InitMDP(MDP *mdp,const Prim primitive,const OSString &vs,const OSString &fs) { if(!InitMaterial(mdp,vs,fs)) return(false); @@ -152,11 +152,11 @@ public: if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT)) return(false); - if(!InitMDP(&m3d,PRIM_LINES,OS_TEXT("res/shader/PositionColor3D.vert"), + if(!InitMDP(&m3d,Prim::Lines,OS_TEXT("res/shader/PositionColor3D.vert"), OS_TEXT("res/shader/VertexColor.frag"))) return(false); - if(!InitMDP(&m2d,PRIM_TRIANGLE_FAN, OS_TEXT("res/shader/OnlyPosition.vert"), + if(!InitMDP(&m2d,Prim::Fan, OS_TEXT("res/shader/OnlyPosition.vert"), OS_TEXT("res/shader/FlatColor.frag"))) return(false); diff --git a/example/Vulkan/HQFilterTexture.cpp b/example/Vulkan/HQFilterTexture.cpp index 152aad41..e92947da 100644 --- a/example/Vulkan/HQFilterTexture.cpp +++ b/example/Vulkan/HQFilterTexture.cpp @@ -155,7 +155,7 @@ private: AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,mpd->material,sc_render_target); pipeline_creater->CloseCullFace(); - pipeline_creater->Set(PRIM_TRIANGLES); + pipeline_creater->Set(Prim::Triangles); mpd->pipeline=pipeline_creater->Create(); diff --git a/example/Vulkan/InlineGeometryScene.cpp b/example/Vulkan/InlineGeometryScene.cpp index 74665306..b2d7c80d 100644 --- a/example/Vulkan/InlineGeometryScene.cpp +++ b/example/Vulkan/InlineGeometryScene.cpp @@ -149,7 +149,7 @@ private: { AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target); - pipeline_creater->Set(PRIM_LINES); + pipeline_creater->Set(Prim::Lines); pipeline_line=pipeline_creater->Create(); @@ -158,7 +158,7 @@ private: db->Add(pipeline_line); - pipeline_creater->Set(PRIM_TRIANGLES); + pipeline_creater->Set(Prim::Triangles); pipeline_creater->SetPolygonMode(VK_POLYGON_MODE_FILL); pipeline_solid=pipeline_creater->Create(); diff --git a/example/Vulkan/LoadStaticMesh.cpp b/example/Vulkan/LoadStaticMesh.cpp index db8c2c2e..2475d3f8 100644 --- a/example/Vulkan/LoadStaticMesh.cpp +++ b/example/Vulkan/LoadStaticMesh.cpp @@ -272,11 +272,11 @@ public: if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))//,model_data->bounding_box)) return(false); - if(!InitMP(&mp_solid, PRIM_TRIANGLES, OS_TEXT("res/shader/pbr_Light.vert"), + if(!InitMP(&mp_solid, Prim::Triangles, OS_TEXT("res/shader/pbr_Light.vert"), OS_TEXT("res/shader/pbr_DirectionLight.frag"))) return(false); - if(!InitMP(&mp_line, PRIM_LINES, OS_TEXT("res/shader/PositionColor3D.vert"), + if(!InitMP(&mp_line, Prim::Lines, OS_TEXT("res/shader/PositionColor3D.vert"), OS_TEXT("res/shader/VertexColor.frag"))) return(false); diff --git a/example/Vulkan/RectanglePrimitive.cpp b/example/Vulkan/RectanglePrimitive.cpp index 9eb5ef6f..4081a421 100644 --- a/example/Vulkan/RectanglePrimitive.cpp +++ b/example/Vulkan/RectanglePrimitive.cpp @@ -105,7 +105,7 @@ private: AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target); pipeline_creater->CloseCullFace(); - pipeline_creater->Set(PRIM_RECTANGLES); + pipeline_creater->Set(Prim::Rectangles); pipeline=pipeline_creater->Create(); diff --git a/example/Vulkan/SceneTree.cpp b/example/Vulkan/SceneTree.cpp index a82cb624..ad90d57a 100644 --- a/example/Vulkan/SceneTree.cpp +++ b/example/Vulkan/SceneTree.cpp @@ -104,7 +104,7 @@ private: pipeline_creater->SetDepthWrite(true); pipeline_creater->CloseCullFace(); pipeline_creater->SetPolygonMode(VK_POLYGON_MODE_FILL); - pipeline_creater->Set(PRIM_TRIANGLES); + pipeline_creater->Set(Prim::Triangles); pipeline_line=pipeline_creater->Create(); if(!pipeline_line) diff --git a/example/Vulkan/VulkanAppFramework.h b/example/Vulkan/VulkanAppFramework.h index f89a93dc..8f5831e1 100644 --- a/example/Vulkan/VulkanAppFramework.h +++ b/example/Vulkan/VulkanAppFramework.h @@ -63,9 +63,9 @@ protected: protected: - Database * db =nullptr; + vulkan::Database * db =nullptr; - bool key_status[kbRangeSize]; + bool key_status[kbRangeSize]; public: @@ -127,7 +127,7 @@ public: render_complete_semaphore =device->CreateSem(); shader_manage=device->CreateShaderModuleManage(); - db=new Database(device); + db=new vulkan::Database(device); InitCommandBuffer(); diff --git a/example/Vulkan/first_triangle.cpp b/example/Vulkan/first_triangle.cpp index fef7fdc1..5fccfe94 100644 --- a/example/Vulkan/first_triangle.cpp +++ b/example/Vulkan/first_triangle.cpp @@ -110,7 +110,7 @@ private: AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target); pipeline_creater->CloseCullFace(); - pipeline_creater->Set(PRIM_TRIANGLES); + pipeline_creater->Set(Prim::Triangles); SaveToFile(PIPELINE_FILENAME,pipeline_creater); } diff --git a/example/Vulkan/indices_rect.cpp b/example/Vulkan/indices_rect.cpp index a5166514..d9f267b9 100644 --- a/example/Vulkan/indices_rect.cpp +++ b/example/Vulkan/indices_rect.cpp @@ -111,7 +111,7 @@ private: AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target); pipeline_creater->CloseCullFace(); - pipeline_creater->Set(PRIM_TRIANGLES); + pipeline_creater->Set(Prim::Triangles); pipeline=pipeline_creater->Create(); diff --git a/example/Vulkan/texture_rect.cpp b/example/Vulkan/texture_rect.cpp index bb398fdc..d4a8cf34 100644 --- a/example/Vulkan/texture_rect.cpp +++ b/example/Vulkan/texture_rect.cpp @@ -133,7 +133,7 @@ private: AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target); pipeline_creater->CloseCullFace(); - pipeline_creater->Set(PRIM_TRIANGLES); + pipeline_creater->Set(Prim::Triangles); pipeline=pipeline_creater->Create(); diff --git a/inc/hgl/graph/InlineGeometry.h b/inc/hgl/graph/InlineGeometry.h index 109fd68f..a8f8b469 100644 --- a/inc/hgl/graph/InlineGeometry.h +++ b/inc/hgl/graph/InlineGeometry.h @@ -9,8 +9,6 @@ namespace hgl { namespace graph { - class Database; - /** * 矩形创建信息(扇形/三角形条) */ @@ -19,12 +17,12 @@ namespace hgl RectScope2f scope; };//struct RectangleCreateInfo - vulkan::Renderable *CreateRenderableRectangle(Database *db,vulkan::Material *mtl,const RectangleCreateInfo *rci); + vulkan::Renderable *CreateRenderableRectangle(vulkan::Database *db,vulkan::Material *mtl,const RectangleCreateInfo *rci); /** * 创建延迟渲染用全屏平面 */ - vulkan::Renderable *CreateRenderableGBufferComposition(Database *db,vulkan::Material *mtl); + vulkan::Renderable *CreateRenderableGBufferComposition(vulkan::Database *db,vulkan::Material *mtl); /** * 圆角矩形创建信息(扇形/线圈) @@ -35,7 +33,7 @@ namespace hgl uint32_t round_per; ///<圆角精度 };//struct RoundRectangleCreateInfo:public RectangleCreateInfo - vulkan::Renderable *CreateRenderableRoundRectangle(Database *db,vulkan::Material *mtl,const RoundRectangleCreateInfo *rci); + vulkan::Renderable *CreateRenderableRoundRectangle(vulkan::Database *db,vulkan::Material *mtl,const RoundRectangleCreateInfo *rci); /** * 圆形创建信息 @@ -50,7 +48,7 @@ namespace hgl /** * 创建一个2D圆形(扇形/线圈) */ - vulkan::Renderable *CreateRenderableCircle(Database *db,vulkan::Material *mtl,const CircleCreateInfo *rci); + vulkan::Renderable *CreateRenderableCircle(vulkan::Database *db,vulkan::Material *mtl,const CircleCreateInfo *rci); /** * 平面网格创建信息 @@ -69,7 +67,7 @@ namespace hgl /** * 创建一个平面网格(线条) */ - vulkan::Renderable *CreateRenderablePlaneGrid(Database *db,vulkan::Material *mtl,const PlaneGridCreateInfo *pgci); + vulkan::Renderable *CreateRenderablePlaneGrid(vulkan::Database *db,vulkan::Material *mtl,const PlaneGridCreateInfo *pgci); struct PlaneCreateInfo { @@ -86,7 +84,7 @@ namespace hgl /** * 创建一个平面(三角形) */ - vulkan::Renderable *CreateRenderablePlane(Database *db,vulkan::Material *mtl,const PlaneCreateInfo *pci); + vulkan::Renderable *CreateRenderablePlane(vulkan::Database *db,vulkan::Material *mtl,const PlaneCreateInfo *pci); struct CubeCreateInfo { @@ -126,17 +124,17 @@ namespace hgl /** * 创建一个立方体(三角形) */ - vulkan::Renderable *CreateRenderableCube(Database *db,vulkan::Material *mtl,const CubeCreateInfo *cci); + vulkan::Renderable *CreateRenderableCube(vulkan::Database *db,vulkan::Material *mtl,const CubeCreateInfo *cci); /** * 创建一个绑定盒(线条) */ - vulkan::Renderable *CreateRenderableBoundingBox(Database *db,vulkan::Material *mtl,const CubeCreateInfo *cci); + vulkan::Renderable *CreateRenderableBoundingBox(vulkan::Database *db,vulkan::Material *mtl,const CubeCreateInfo *cci); /** * 创建一个球心坐标为0,0,0,半径为1的球体(三角形) */ - vulkan::Renderable *CreateRenderableSphere(Database *db,vulkan::Material *mtl,const uint numberSlices); + vulkan::Renderable *CreateRenderableSphere(vulkan::Database *db,vulkan::Material *mtl,const uint numberSlices); struct DomeCreateInfo { @@ -147,7 +145,7 @@ namespace hgl /** * 创建一个穹顶(三角形) */ - vulkan::Renderable *CreateRenderableDome(Database *db,vulkan::Material *mtl, const DomeCreateInfo *); + vulkan::Renderable *CreateRenderableDome(vulkan::Database *db,vulkan::Material *mtl, const DomeCreateInfo *); struct TorusCreateInfo { @@ -161,7 +159,7 @@ namespace hgl /** * 创建一个圆环(三角形) */ - vulkan::Renderable *CreateRenderableTorus(Database *db,vulkan::Material *mtl,const TorusCreateInfo *tci); + vulkan::Renderable *CreateRenderableTorus(vulkan::Database *db,vulkan::Material *mtl,const TorusCreateInfo *tci); struct CylinderCreateInfo { @@ -173,7 +171,7 @@ namespace hgl /** * 创建一个圆柱(三角形) */ - vulkan::Renderable *CreateRenderableCylinder(Database *db,vulkan::Material *mtl,const CylinderCreateInfo *cci); + vulkan::Renderable *CreateRenderableCylinder(vulkan::Database *db,vulkan::Material *mtl,const CylinderCreateInfo *cci); struct ConeCreateInfo { @@ -186,7 +184,7 @@ namespace hgl /** * 创建一个圆锥(三角形) */ - vulkan::Renderable *CreateRenderableCone(Database *db,vulkan::Material *mtl,const ConeCreateInfo *cci); + vulkan::Renderable *CreateRenderableCone(vulkan::Database *db,vulkan::Material *mtl,const ConeCreateInfo *cci); struct AxisCreateInfo { @@ -226,7 +224,7 @@ namespace hgl /** * 创建一个坐标线(线条) */ - vulkan::Renderable *CreateRenderableAxis(Database *db,vulkan::Material *mtl,const AxisCreateInfo *aci); + vulkan::Renderable *CreateRenderableAxis(vulkan::Database *db,vulkan::Material *mtl,const AxisCreateInfo *aci); }//namespace graph };//namespace hgl #endif//HGL_GRAPH_INLINE_GEOMETRY_INCLUDE diff --git a/inc/hgl/graph/vulkan/VK.h b/inc/hgl/graph/vulkan/VK.h index 95e2e8f5..e0345542 100644 --- a/inc/hgl/graph/vulkan/VK.h +++ b/inc/hgl/graph/vulkan/VK.h @@ -61,6 +61,8 @@ class VertexAttributeBinding; class Renderable; +class Database; + enum class SharingMode { Exclusive = 0, @@ -73,6 +75,12 @@ enum ImageTiling Linear };// +enum IndexType +{ + U16=0, + U32 +}; + enum class ShaderStageBit { Vertex =VK_SHADER_STAGE_VERTEX_BIT, diff --git a/inc/hgl/graph/vulkan/VKBuffer.h b/inc/hgl/graph/vulkan/VKBuffer.h index a64d03f9..11d12b6d 100644 --- a/inc/hgl/graph/vulkan/VKBuffer.h +++ b/inc/hgl/graph/vulkan/VKBuffer.h @@ -82,14 +82,14 @@ using VAB=VertexAttribBuffer; class IndexBuffer:public Buffer { - VkIndexType index_type; + IndexType index_type; uint32_t count; private: friend class Device; - IndexBuffer(VkDevice d,const BufferData &vb,VkIndexType it,uint32_t _count):Buffer(d,vb) + IndexBuffer(VkDevice d,const BufferData &vb,IndexType it,uint32_t _count):Buffer(d,vb) { index_type=it; count=_count; @@ -99,8 +99,8 @@ public: ~IndexBuffer()=default; - const VkIndexType GetType ()const{return index_type;} - const uint32 GetCount()const{return count;} + const IndexType GetType ()const{return index_type;} + const uint32 GetCount()const{return count;} };//class IndexBuffer:public Buffer VK_NAMESPACE_END #endif//HGL_GRAPH_VULKAN_BUFFER_INCLUDE diff --git a/inc/hgl/graph/vulkan/VKDatabase.h b/inc/hgl/graph/vulkan/VKDatabase.h index 4f9b44ed..4d04477d 100644 --- a/inc/hgl/graph/vulkan/VKDatabase.h +++ b/inc/hgl/graph/vulkan/VKDatabase.h @@ -75,13 +75,13 @@ public: //Create #undef SCENE_DB_CREATE_FUNC - IndexBuffer *CreateIBO(VkIndexType index_type,uint32_t count,const void *data,SharingMode sm=SharingMode::Exclusive); - IndexBuffer *CreateIBO16(uint32_t count,const uint16 *data,SharingMode sm=SharingMode::Exclusive){return CreateIBO(VK_INDEX_TYPE_UINT16,count,(void *)data,sm);} - IndexBuffer *CreateIBO32(uint32_t count,const uint32 *data,SharingMode sm=SharingMode::Exclusive){return CreateIBO(VK_INDEX_TYPE_UINT32,count,(void *)data,sm);} + IndexBuffer *CreateIBO(IndexType index_type,uint32_t count,const void *data,SharingMode sm=SharingMode::Exclusive); + IndexBuffer *CreateIBO16(uint32_t count,const uint16 *data,SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U16,count,(void *)data,sm);} + IndexBuffer *CreateIBO32(uint32_t count,const uint32 *data,SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U32,count,(void *)data,sm);} - IndexBuffer *CreateIBO(VkIndexType index_type,uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateIBO(index_type,count,nullptr,sm);} - IndexBuffer *CreateIBO16(uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateIBO(VK_INDEX_TYPE_UINT16,count,nullptr,sm);} - IndexBuffer *CreateIBO32(uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateIBO(VK_INDEX_TYPE_UINT32,count,nullptr,sm);} + IndexBuffer *CreateIBO(IndexType index_type,uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateIBO(index_type,count,nullptr,sm);} + IndexBuffer *CreateIBO16(uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U16,count,nullptr,sm);} + IndexBuffer *CreateIBO32(uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U32,count,nullptr,sm);} MaterialInstance * CreateMaterialInstance(Material *); Renderable * CreateRenderable(Material *,const uint32_t vertex_count=0); diff --git a/inc/hgl/graph/vulkan/VKDevice.h b/inc/hgl/graph/vulkan/VKDevice.h index f3865e66..7b581277 100644 --- a/inc/hgl/graph/vulkan/VKDevice.h +++ b/inc/hgl/graph/vulkan/VKDevice.h @@ -97,13 +97,13 @@ public: //Buffer相关 VAB * CreateVAB (VkFormat format,uint32_t count, SharingMode sharing_mode=SharingMode::Exclusive){return CreateVAB(format,count,nullptr,sharing_mode);} VAB * CreateVAB (const VAD *vad, SharingMode sharing_mode=SharingMode::Exclusive){return CreateVAB(vad->GetVulkanFormat(),vad->GetCount(),vad->GetData(),sharing_mode);} - IndexBuffer * CreateIBO (VkIndexType index_type,uint32_t count,const void * data,SharingMode sharing_mode=SharingMode::Exclusive); - IndexBuffer * CreateIBO16 ( uint32_t count,const uint16 *data,SharingMode sharing_mode=SharingMode::Exclusive){return CreateIBO(VK_INDEX_TYPE_UINT16,count,(void *)data,sharing_mode);} - IndexBuffer * CreateIBO32 ( uint32_t count,const uint32 *data,SharingMode sharing_mode=SharingMode::Exclusive){return CreateIBO(VK_INDEX_TYPE_UINT32,count,(void *)data,sharing_mode);} + IndexBuffer * CreateIBO (IndexType index_type,uint32_t count,const void * data,SharingMode sharing_mode=SharingMode::Exclusive); + IndexBuffer * CreateIBO16 ( uint32_t count,const uint16 *data,SharingMode sharing_mode=SharingMode::Exclusive){return CreateIBO(IndexType::U16,count,(void *)data,sharing_mode);} + IndexBuffer * CreateIBO32 ( uint32_t count,const uint32 *data,SharingMode sharing_mode=SharingMode::Exclusive){return CreateIBO(IndexType::U32,count,(void *)data,sharing_mode);} - IndexBuffer * CreateIBO (VkIndexType index_type,uint32_t count,SharingMode sharing_mode=SharingMode::Exclusive){return CreateIBO(index_type,count,nullptr,sharing_mode);} - IndexBuffer * CreateIBO16 ( uint32_t count,SharingMode sharing_mode=SharingMode::Exclusive){return CreateIBO(VK_INDEX_TYPE_UINT16,count,nullptr,sharing_mode);} - IndexBuffer * CreateIBO32 ( uint32_t count,SharingMode sharing_mode=SharingMode::Exclusive){return CreateIBO(VK_INDEX_TYPE_UINT32,count,nullptr,sharing_mode);} + IndexBuffer * CreateIBO (IndexType index_type,uint32_t count,SharingMode sharing_mode=SharingMode::Exclusive){return CreateIBO(index_type,count,nullptr,sharing_mode);} + IndexBuffer * CreateIBO16 ( uint32_t count,SharingMode sharing_mode=SharingMode::Exclusive){return CreateIBO(IndexType::U16,count,nullptr,sharing_mode);} + IndexBuffer * CreateIBO32 ( uint32_t count,SharingMode sharing_mode=SharingMode::Exclusive){return CreateIBO(IndexType::U32,count,nullptr,sharing_mode);} #define CREATE_BUFFER_OBJECT(LargeName,type) Buffer *Create##LargeName(VkDeviceSize size,void *data,SharingMode sharing_mode=SharingMode::Exclusive){return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size,data,sharing_mode);} \ Buffer *Create##LargeName(VkDeviceSize size,SharingMode sharing_mode=SharingMode::Exclusive){return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size,nullptr,sharing_mode);} @@ -124,7 +124,7 @@ public: //Image VkImage CreateCubemap (const VkFormat format,const uint32_t width,const uint32_t height, const uint usage,const ImageTiling tiling); // VkImage CreateCubemapArray (const VkFormat format,const uint32_t width,const uint32_t height,const uint32_t count, const uint usage,const ImageTiling tiling); - void DestoryImage (VkImage); + void DestoryImage (VkImage); public: //Texture @@ -176,13 +176,13 @@ public: //Texture const VkImageAspectFlags aspectMask =VK_IMAGE_ASPECT_COLOR_BIT, const uint usage =VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT, const VkImageLayout image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, - const ImageTiling tiling =ImageTiling::Optimal); + const ImageTiling tiling =ImageTiling::Optimal); Texture2D *CreateTexture2D( const VkFormat video_format,void *data,uint32_t width,uint32_t height,uint32_t size, const VkImageAspectFlags aspectMask =VK_IMAGE_ASPECT_COLOR_BIT, const uint usage =VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT, const VkImageLayout image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, - const ImageTiling tiling =ImageTiling::Optimal); + const ImageTiling tiling =ImageTiling::Optimal); bool ChangeTexture2D(Texture2D *,Buffer *buf,const VkBufferImageCopy *,const int count); bool ChangeTexture2D(Texture2D *,Buffer *buf,const List &); diff --git a/inc/hgl/graph/vulkan/VKPipeline.h b/inc/hgl/graph/vulkan/VKPipeline.h index f881e946..23aada8f 100644 --- a/inc/hgl/graph/vulkan/VKPipeline.h +++ b/inc/hgl/graph/vulkan/VKPipeline.h @@ -78,10 +78,10 @@ class PipelineCreater public: PipelineCreater(Device *dev,const Material *,const RenderTarget *); - PipelineCreater(Device *dev,const Material *,const RenderTarget *,uchar *,uint); + PipelineCreater(Device *dev,const Material *,const RenderTarget *,uchar *data,uint size); ~PipelineCreater()=default; - bool Set(const uint prim,bool=false); + bool Set(const Prim prim,bool=false); void SetViewport( float x,float y,float w,float h){viewport.x=x;viewport.y=y;viewport.width=w;viewport.height=h;} void SetDepthRange( float min_depth,float max_depth){viewport.minDepth=min_depth;viewport.maxDepth=max_depth;} diff --git a/inc/hgl/graph/vulkan/VKPrimivate.h b/inc/hgl/graph/vulkan/VKPrimivate.h index 139ef7fc..36056f33 100644 --- a/inc/hgl/graph/vulkan/VKPrimivate.h +++ b/inc/hgl/graph/vulkan/VKPrimivate.h @@ -1,22 +1,28 @@ #ifndef HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE #define HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE -#include +#include -#define PRIM_POINTS VK_PRIMITIVE_TOPOLOGY_POINT_LIST ///<点 -#define PRIM_LINES VK_PRIMITIVE_TOPOLOGY_LINE_LIST ///<线 -#define PRIM_LINE_STRIP VK_PRIMITIVE_TOPOLOGY_LINE_STRIP ///<连续线 -#define PRIM_TRIANGLES VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST ///<三角形 -#define PRIM_TRIANGLE_STRIP VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP ///<三角形条 -#define PRIM_TRIANGLE_FAN VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN ///<扇形 -#define PRIM_LINES_ADJ VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY ///<代表一个有四个顶点的Primitive,其中第二个点与第三个点会形成线段,而第一个点与第四个点则用来提供2,3邻近点的信息. -#define PRIM_LINE_STRIP_ADJ VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY ///<与LINES_ADJACENCY类似,第一个点跟最后一个点提供信息,剩下的点则跟Line Strip一样形成线段. -#define PRIM_TRIANGLES_ADJ VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY ///<代表一个有六个顶点的Primitive,其中第1,3,5个顶点代表一个Triangle,而地2,4,6个点提供邻近信息.(由1起算) -#define PRIM_TRIANGLE_STRIP_ADJ VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY ///<4+2N个Vertices代表N个Primitive,其中1,3,5,7,9...代表原本的Triangle strip形成Triangle,而2,4,6,8,10...代表邻近提供信息的点.(由1起算) -#define PRIM_PATCHS VK_PRIMITIVE_TOPOLOGY_PATCH_LIST -#define PRIM_RECTANGLES 0x100 ///<矩形(并非原生支持。以画点形式在每个点的Position中传递Left,Top,Width,Height。在Geometry Shader中转换为2个三角形。用于2D游戏或UI) -#define PRIM_BEGIN VK_PRIMITIVE_TOPOLOGY_POINT_LIST -#define PRIM_END VK_PRIMITIVE_TOPOLOGY_PATCH_LIST -constexpr uint32_t PRIM_RANGE =PRIM_END-PRIM_BEGIN+1; +/** + * 图元类型枚举 + */ +enum class Prim +{ + Points=0, ///<点 + Lines, ///<线 + LineStrip, ///<连续线 + Triangles, ///<三角形 + TriangleStrip, ///<三角形条 + Fan, ///<扇形 + LinesAdj, ///<代表一个有四个顶点的Primitive,其中第二个点与第三个点会形成线段,而第一个点与第四个点则用来提供2,3邻近点的信息. + LineStripAdj, ///<与LINES_ADJACENCY类似,第一个点跟最后一个点提供信息,剩下的点则跟Line Strip一样形成线段. + TrianglesAdj, ///<代表一个有六个顶点的Primitive,其中第1,3,5个顶点代表一个Triangle,而地2,4,6个点提供邻近信息.(由1起算) + TriangleStripAdj, ///<4+2N个Vertices代表N个Primitive,其中1,3,5,7,9...代表原本的Triangle strip形成Triangle,而2,4,6,8,10...代表邻近提供信息的点.(由1起算) + Patchs, + + Rectangles=0x100, ///<矩形(并非原生支持。以画点形式在每个点的Position中传递Left,Top,Width,Height。在Geometry Shader中转换为2个三角形。用于2D游戏或UI) + + ENUM_CLASS_RANGE(Points,Patchs) +};// #endif//HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE diff --git a/src/RenderDevice/Vulkan/VKCommandBuffer.cpp b/src/RenderDevice/Vulkan/VKCommandBuffer.cpp index c2a4c282..1ea208ca 100644 --- a/src/RenderDevice/Vulkan/VKCommandBuffer.cpp +++ b/src/RenderDevice/Vulkan/VKCommandBuffer.cpp @@ -117,7 +117,7 @@ bool CommandBuffer::Bind(Renderable *render_obj) IndexBuffer *indices_buffer=render_obj->GetIndexBuffer(); if(indices_buffer) - vkCmdBindIndexBuffer(cmd_buf,indices_buffer->GetBuffer(),render_obj->GetIndexOffset(),indices_buffer->GetType()); + vkCmdBindIndexBuffer(cmd_buf,indices_buffer->GetBuffer(),render_obj->GetIndexOffset(),VkIndexType(indices_buffer->GetType())); return(true); } diff --git a/src/RenderDevice/Vulkan/VKDatabase.cpp b/src/RenderDevice/Vulkan/VKDatabase.cpp index 8047ac0c..8aff6c71 100644 --- a/src/RenderDevice/Vulkan/VKDatabase.cpp +++ b/src/RenderDevice/Vulkan/VKDatabase.cpp @@ -39,7 +39,7 @@ VAB *Database::CreateVAB(VkFormat format,uint32_t count,const void *data,Sharing #undef SCENE_DB_CREATE_BUFFER -IndexBuffer *Database::CreateIBO(VkIndexType index_type,uint32_t count,const void *data,SharingMode sharing_mode) +IndexBuffer *Database::CreateIBO(IndexType index_type,uint32_t count,const void *data,SharingMode sharing_mode) { IndexBuffer *buf=device->CreateIBO(index_type,count,data,sharing_mode); diff --git a/src/RenderDevice/Vulkan/VKDeviceBuffer.cpp b/src/RenderDevice/Vulkan/VKDeviceBuffer.cpp index 45842c9a..bf6e76ad 100644 --- a/src/RenderDevice/Vulkan/VKDeviceBuffer.cpp +++ b/src/RenderDevice/Vulkan/VKDeviceBuffer.cpp @@ -64,12 +64,12 @@ VAB *Device::CreateVAB(VkFormat format,uint32_t count,const void *data,SharingMo return(new VertexAttribBuffer(attr->device,buf,format,stride,count)); } -IndexBuffer *Device::CreateIBO(VkIndexType index_type,uint32_t count,const void *data,SharingMode sharing_mode) +IndexBuffer *Device::CreateIBO(IndexType index_type,uint32_t count,const void *data,SharingMode sharing_mode) { uint32_t stride; - if(index_type==VK_INDEX_TYPE_UINT16)stride=2;else - if(index_type==VK_INDEX_TYPE_UINT32)stride=4;else + if(index_type==IndexType::U16)stride=2;else + if(index_type==IndexType::U32)stride=4;else return(nullptr); const VkDeviceSize size=stride*count; diff --git a/src/RenderDevice/Vulkan/VKPipeline.cpp b/src/RenderDevice/Vulkan/VKPipeline.cpp index 28593974..54e1de5c 100644 --- a/src/RenderDevice/Vulkan/VKPipeline.cpp +++ b/src/RenderDevice/Vulkan/VKPipeline.cpp @@ -217,15 +217,15 @@ PipelineCreater::PipelineCreater(Device *dev,const Material *material,const Rend } } -bool PipelineCreater::Set(const uint topology,bool restart) +bool PipelineCreater::Set(const Prim topology,bool restart) { - if(topologyPRIM_END) - if(topology!=PRIM_RECTANGLES)return(false); + if(topologyPrim::END_RANGE) + if(topology!=Prim::Rectangles)return(false); inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; inputAssembly.pNext = nullptr; inputAssembly.flags = 0; - inputAssembly.topology = VkPrimitiveTopology(topology==PRIM_RECTANGLES?VK_PRIMITIVE_TOPOLOGY_POINT_LIST:topology); + inputAssembly.topology = VkPrimitiveTopology(topology==Prim::Rectangles?Prim::Points:topology); inputAssembly.primitiveRestartEnable = restart; pipelineInfo.pInputAssemblyState = &inputAssembly;