From 611a9fe61de11fa07b6d0f4b07ee049009389f91 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 31 May 2024 22:04:02 +0800 Subject: [PATCH] fixed draw_triangle_in_NDC sample and other about codes. --- example/Basic/draw_triangle_in_NDC.cpp | 12 +++++++----- example/LightBasic/BlinnPhongDirectionLight.cpp | 6 +++--- example/common/VulkanAppFramework.h | 2 +- inc/hgl/graph/VKCommandBuffer.h | 2 +- inc/hgl/graph/VKRenderable.h | 2 +- src/SceneGraph/Vulkan/VKCommandBufferRender.cpp | 4 ++-- src/SceneGraph/Vulkan/VKRenderable.cpp | 4 ++++ 7 files changed, 19 insertions(+), 13 deletions(-) diff --git a/example/Basic/draw_triangle_in_NDC.cpp b/example/Basic/draw_triangle_in_NDC.cpp index 27fa42d1..e6c4e833 100644 --- a/example/Basic/draw_triangle_in_NDC.cpp +++ b/example/Basic/draw_triangle_in_NDC.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include using namespace hgl; @@ -108,16 +108,18 @@ private: bool InitVBO() { - RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT); + PrimitiveCreater rpc(device,material_instance->GetVIL()); + + rpc.Init("Triangle",VERTEX_COUNT); #ifdef USE_HALF_FLOAT_POSITION Float32toFloat16(position_data_hf,position_data_float,VERTEX_COUNT*2); #endif//USE_HALF_FLOAT_POSITION - if(!rpc.SetVAB(VAN::Position, PositionFormat, position_data))return(false); - if(!rpc.SetVAB(VAN::Color, ColorFormat, color_data ))return(false); + if(!rpc.WriteVAB(VAN::Position, PositionFormat, position_data))return(false); + if(!rpc.WriteVAB(VAN::Color, ColorFormat, color_data ))return(false); - render_obj=rpc.Create(material_instance,pipeline); + render_obj=db->CreateRenderable(&rpc,material_instance,pipeline); return(render_obj); } diff --git a/example/LightBasic/BlinnPhongDirectionLight.cpp b/example/LightBasic/BlinnPhongDirectionLight.cpp index 478ca5c5..e3253983 100644 --- a/example/LightBasic/BlinnPhongDirectionLight.cpp +++ b/example/LightBasic/BlinnPhongDirectionLight.cpp @@ -32,9 +32,9 @@ constexpr const COLOR AxisColor[4]= //COLOR::Green, //Y轴颜色 //COLOR::Blue, //Z轴颜色 COLOR::White, //全局颜色 - COLOR::White, //全局颜色 - COLOR::White, //全局颜色 - COLOR::White //全局颜色 + COLOR::GhostWhite, + COLOR::BlanchedAlmond, + COLOR::AntiqueWhite }; diff --git a/example/common/VulkanAppFramework.h b/example/common/VulkanAppFramework.h index c48048d6..8dd03a5b 100644 --- a/example/common/VulkanAppFramework.h +++ b/example/common/VulkanAppFramework.h @@ -222,7 +222,7 @@ public: cb->BeginRenderPass(); cb->BindPipeline(ri->GetPipeline()); cb->BindDescriptorSets(ri->GetMaterial()); - cb->BindRenderBuffer(ri->GetDataBuffer()); + cb->BindDataBuffer(ri->GetDataBuffer()); cb->Draw(ri->GetDataBuffer(),ri->GetRenderData()); cb->EndRenderPass(); cb->End(); diff --git a/inc/hgl/graph/VKCommandBuffer.h b/inc/hgl/graph/VKCommandBuffer.h index e56537ae..175c5df2 100644 --- a/inc/hgl/graph/VKCommandBuffer.h +++ b/inc/hgl/graph/VKCommandBuffer.h @@ -176,7 +176,7 @@ public: void BindIBO(IndexBuffer *,const VkDeviceSize byte_offset=0); - bool BindRenderBuffer(const PrimitiveDataBuffer *); + bool BindDataBuffer(const PrimitiveDataBuffer *); void SetViewport (uint32_t first,uint32_t count,const VkViewport *vp) {vkCmdSetViewport(cmd_buf,first,count,vp);} void SetScissor (uint32_t first,uint32_t count,const VkRect2D *sci) {vkCmdSetScissor(cmd_buf,first,count,sci);} diff --git a/inc/hgl/graph/VKRenderable.h b/inc/hgl/graph/VKRenderable.h index cbd5fa47..0e247564 100644 --- a/inc/hgl/graph/VKRenderable.h +++ b/inc/hgl/graph/VKRenderable.h @@ -22,7 +22,7 @@ struct PrimitiveDataBuffer // 另一种是使用VDM,为了批量渲染,所有的VAB又必须对齐,所以每个VAB单独指定offset也不可行。 // 所以干脆不支持VAB的offset,只支持vertexOffset。 -// uint32_t * vab_offset; //注意:这里的offset是相对于vertex的,代表第几个顶点,不是字节偏移 + VkDeviceSize * vab_offset; //注意:这里的offset是相对于vertex的,代表第几个顶点,不是字节偏移 // IndexBuffer 同理也不再支持buffer的offset diff --git a/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp b/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp index 6aa2149f..529c43fc 100644 --- a/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp +++ b/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp @@ -140,7 +140,7 @@ void RenderCmdBuffer::BindIBO(IndexBuffer *ibo,const VkDeviceSize byte_offset) VkIndexType(ibo->GetType())); } -bool RenderCmdBuffer::BindRenderBuffer(const PrimitiveDataBuffer *pdb) +bool RenderCmdBuffer::BindDataBuffer(const PrimitiveDataBuffer *pdb) { if(!pdb) return(false); @@ -152,7 +152,7 @@ bool RenderCmdBuffer::BindRenderBuffer(const PrimitiveDataBuffer *pdb) 0, //first binding pdb->vab_count, pdb->vab_list, - nullptr); //vab byte offsets + pdb->vab_offset); //vab byte offsets if(pdb->ibo) BindIBO(pdb->ibo); diff --git a/src/SceneGraph/Vulkan/VKRenderable.cpp b/src/SceneGraph/Vulkan/VKRenderable.cpp index 785b5c77..eea25dea 100644 --- a/src/SceneGraph/Vulkan/VKRenderable.cpp +++ b/src/SceneGraph/Vulkan/VKRenderable.cpp @@ -12,6 +12,7 @@ PrimitiveDataBuffer::PrimitiveDataBuffer(const uint32_t c,IndexBuffer *ib,Vertex vab_count=c; vab_list=hgl_zero_new(vab_count); + vab_offset=hgl_zero_new(vab_count); ibo=ib; vdm=_vdm; @@ -19,6 +20,7 @@ PrimitiveDataBuffer::PrimitiveDataBuffer(const uint32_t c,IndexBuffer *ib,Vertex PrimitiveDataBuffer::~PrimitiveDataBuffer() { + delete[] vab_offset; delete[] vab_list; } @@ -34,6 +36,7 @@ const bool PrimitiveDataBuffer::Comp(const PrimitiveDataBuffer *pdb)const for(uint32_t i=0;ivab_list[i])return(false); + if(vab_offset[i]!=pdb->vab_offset[i])return(false); } if(ibo!=pdb->ibo) @@ -108,6 +111,7 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p) } pdb->vab_list[i]=vab->GetBuffer(); + pdb->vab_offset[i]=0; ++vif; }