diff --git a/CMSceneGraph b/CMSceneGraph index fccbd425..c4f5e3d3 160000 --- a/CMSceneGraph +++ b/CMSceneGraph @@ -1 +1 @@ -Subproject commit fccbd425e23f0b82f2953313fd8bacf7a01c5379 +Subproject commit c4f5e3d339dac74cfb48f7cf17ea18e51990c709 diff --git a/example/Vulkan/Atomsphere.cpp b/example/Vulkan/Atomsphere.cpp index 0499de6a..c32a8be1 100644 --- a/example/Vulkan/Atomsphere.cpp +++ b/example/Vulkan/Atomsphere.cpp @@ -58,7 +58,7 @@ private: { ro_sphere=CreateRenderableSphere(db,material,128); } - + bool InitAtomsphereUBO(vulkan::MaterialInstance *mi,const AnsiString &sun_node_name) { atomsphere_data.position.Set(0,0.1f,-1.0f); diff --git a/example/Vulkan/DrawText.cpp b/example/Vulkan/DrawText.cpp index 186a7231..7efb9ec8 100644 --- a/example/Vulkan/DrawText.cpp +++ b/example/Vulkan/DrawText.cpp @@ -1,6 +1,3 @@ -// 2.RectanglePrimivate -// 该示例是texture_rect的进化,演示使用GeometryShader画矩形 - #include"VulkanAppFramework.h" #include #include diff --git a/inc/hgl/graph/VertexBufferCreater.h b/inc/hgl/graph/VertexBufferCreater.h index 24b49aa2..f8561a23 100644 --- a/inc/hgl/graph/VertexBufferCreater.h +++ b/inc/hgl/graph/VertexBufferCreater.h @@ -36,8 +36,8 @@ namespace hgl } virtual VkFormat GetDataType ()const=0; ///<取得数据类型 -// const uint32_t GetDataBytes ()const{return comp_stride;} ///<取得每数据字节数 -// const uint32_t GetComponent ()const{return dc_num; } ///<取数缓冲区元数据数量 + const uint32_t GetDataBytes ()const{return comp_stride;} ///<取得每数据字节数 + const uint32_t GetComponent ()const{return dc_num; } ///<取数缓冲区元数据数量 const uint32_t GetCount ()const{return count; } ///<取得数据数量 const uint32_t GetStride ()const{return stride;} ///<取得每一组数据字节数 void * GetData ()const{return mem_data;} ///<取得数据指针 diff --git a/inc/hgl/graph/shader/ShaderResource.h b/inc/hgl/graph/shader/ShaderResource.h index d49b9f12..d0c0a801 100644 --- a/inc/hgl/graph/shader/ShaderResource.h +++ b/inc/hgl/graph/shader/ShaderResource.h @@ -9,6 +9,7 @@ VK_NAMESPACE_BEGIN { AnsiString name; uint location; + uint component; VkFormat format; };//struct ShaderStage @@ -60,7 +61,8 @@ VK_NAMESPACE_BEGIN ShaderStageList &GetStageInputs(){return stage_inputs;} ShaderStageList &GetStageOutputs(){return stage_outputs;} - const int GetStageInputBinding(const AnsiString &); + const ShaderStage *GetStage(const AnsiString &)const; + const int GetStageInputBinding(const AnsiString &)const; const ShaderDescriptorList *GetDescriptorList()const{return descriptor_list;} ShaderDescriptorList *GetDescriptorList(VkDescriptorType desc_type) diff --git a/inc/hgl/graph/vulkan/VKShaderModule.h b/inc/hgl/graph/vulkan/VKShaderModule.h index 1f8bbae1..885a1015 100644 --- a/inc/hgl/graph/vulkan/VKShaderModule.h +++ b/inc/hgl/graph/vulkan/VKShaderModule.h @@ -72,6 +72,7 @@ public: * 获取输入流绑定点,需要注意的时,这里获取的binding并非是shader中的binding/location,而是绑定顺序的序列号。对应vkCmdBindVertexBuffer的缓冲区序列号 */ const int GetStageInputBinding(const AnsiString &name)const{return shader_resource->GetStageInputBinding(name);} + const ShaderStage * GetStage(const AnsiString &name)const{return shader_resource->GetStage(name);} const uint32_t GetAttrCount()const{return attr_count;} diff --git a/src/RenderDevice/Vulkan/VKBuffer.cpp b/src/RenderDevice/Vulkan/VKBuffer.cpp index f1e1aa3d..ee7cd8d6 100644 --- a/src/RenderDevice/Vulkan/VKBuffer.cpp +++ b/src/RenderDevice/Vulkan/VKBuffer.cpp @@ -1,4 +1,6 @@ #include +#include +#include VK_NAMESPACE_BEGIN Buffer::~Buffer() @@ -6,4 +8,14 @@ Buffer::~Buffer() if(buf.memory)delete buf.memory; vkDestroyBuffer(device,buf.buffer,nullptr); } + + + +VertexBufferCreater *CreateVBO(const uint32_t base_type,const uint32_t vecsize,const uint32_t vertex_count) +{ + if(vecsize==1)return(new VB1f(vertex_count));else + if(vecsize==2)return(new VB2f(vertex_count));else + if(vecsize==3)return(new VB3f(vertex_count));else + if(vecsize==4)return(new VB4f(vertex_count));else +} VK_NAMESPACE_END diff --git a/src/SceneGraph/InlineGeometry.cpp b/src/SceneGraph/InlineGeometry.cpp index c679c9a1..c405f617 100644 --- a/src/SceneGraph/InlineGeometry.cpp +++ b/src/SceneGraph/InlineGeometry.cpp @@ -21,13 +21,13 @@ namespace hgl const vulkan::VertexShaderModule *vsm=nullptr; vulkan::Renderable *render_obj=nullptr; - + int vertex_binding =-1; int color_binding =-1; int normal_binding =-1; int tangent_binding =-1; int texcoord_binding=-1; - + VERTEX_VB_FORMAT *vertex =nullptr; VB4f *color =nullptr; VB3f *normal =nullptr; @@ -41,7 +41,7 @@ namespace hgl GeometryCreater(SceneDB *sdb,vulkan::Material *m):db(sdb),mtl(m) { vsm=mtl->GetVertexShaderModule(); - + vertex_binding =vsm->GetStageInputBinding("Vertex"); color_binding =vsm->GetStageInputBinding("Color"); normal_binding =vsm->GetStageInputBinding("Normal"); @@ -102,7 +102,7 @@ namespace hgl } private: - + void Finish(int binding,VertexBufferCreater *vb) { render_obj->Set(binding,db->CreateVBO(vb)); @@ -125,11 +125,11 @@ namespace hgl if(tex_coord)Finish(texcoord_binding, tex_coord); if(ibo) - { + { ibo->Unmap(); render_obj->Set(ibo); } - + vulkan::Renderable *result=render_obj; db->Add(render_obj); @@ -148,7 +148,7 @@ namespace hgl if(!gc.Init(4)) return(nullptr); - + VB2f *vertex=gc.GetVertex(); vertex->WriteRectFan(rci->scope); @@ -173,7 +173,7 @@ namespace hgl { if(!gc.Init(4)) return(nullptr); - + VB2f *vertex=gc.GetVertex(); vertex->WriteRectFan(rci->scope); @@ -187,7 +187,7 @@ namespace hgl if(!gc.Init(rci->round_per*4)) return(nullptr); - + VB2f *vertex=gc.GetVertex(); vec2 *coord=new vec2[rci->round_per]; @@ -235,7 +235,7 @@ namespace hgl delete[] coord; } - + return gc.Finish(); } @@ -254,7 +254,7 @@ namespace hgl float x=cci->center.x+sin(hgl_ang2rad(ang))*cci->radius.x; float y=cci->center.y+cos(hgl_ang2rad(ang))*cci->radius.y; - + vertex->Write(x,y); } @@ -341,7 +341,7 @@ namespace hgl { xy_tex_coord[2]=xy_tex_coord[4]=pci->tile.x; xy_tex_coord[5]=xy_tex_coord[7]=pci->tile.y; - + tex_coord->BufferData(xy_tex_coord); } } @@ -418,10 +418,10 @@ namespace hgl } } - gc.CreateIBO16(6*2*3,indices); + gc.CreateIBO16(6*2*3,indices); return gc.Finish(); } - + template void CreateSphereIndices(T *tp,uint numberParallels,const uint numberSlices) { for (uint i = 0; i < numberParallels; i++) @@ -440,7 +440,7 @@ namespace hgl } namespace - { + { constexpr uint GLUS_VERTICES_FACTOR =4; constexpr uint GLUS_VERTICES_DIVISOR=4; constexpr uint GLUS_MAX_VERTICES =1048576; @@ -465,7 +465,7 @@ namespace hgl quaternion[2] = sinf(halfAngleRadian); quaternion[3] = cosf(halfAngleRadian); } - + void glusQuaternionGetMatrix4x4f(float matrix[16], const float quaternion[4]) { float x = quaternion[0]; @@ -493,7 +493,7 @@ namespace hgl matrix[14] = 0.0f; matrix[15] = 1.0f; } - + void glusMatrix4x4MultiplyVector3f(float result[3], const float matrix[16], const float vector[3]) { int i; @@ -535,7 +535,7 @@ namespace hgl if(!gc.Init(numberVertices)) return(nullptr); - + float *vp=gc.GetVertexPointer(); float *np=gc.GetNormalPointer(); float *tp=gc.GetTangentPointer(); @@ -548,7 +548,7 @@ namespace hgl float x = sin(angleStep * (double) i) * sin(angleStep * (double) j); float y = sin(angleStep * (double) i) * cos(angleStep * (double) j); float z = cos(angleStep * (double) i); - + *vp=x;++vp; *vp=y;++vp; *vp=z;++vp; @@ -566,7 +566,7 @@ namespace hgl *tc=tex_x;++tc; *tc=1.0f - (float) i / (float) numberParallels;++tc; - + if(tp) { // use quaternion to get the tangent vector @@ -579,7 +579,7 @@ namespace hgl } } } - + if(numberVertices<=0xffff) CreateSphereIndices(gc.CreateIBO16(numberIndices),numberParallels,numberSlices); else @@ -587,7 +587,7 @@ namespace hgl return gc.Finish(); } - + vulkan::Renderable *CreateRenderableDome(SceneDB *db,vulkan::Material *mtl,const DomeCreateInfo *dci) { GeometryCreater3D gc(db,mtl); @@ -608,10 +608,10 @@ namespace hgl if (dci->numberSlices < 3 || numberVertices > GLUS_MAX_VERTICES || numberIndices > GLUS_MAX_INDICES) return nullptr; - + if(!gc.Init(numberVertices)) return(nullptr); - + float *vp=gc.GetVertexPointer(); float *np=gc.GetNormalPointer(); float *tp=gc.GetTangentPointer(); @@ -658,7 +658,7 @@ namespace hgl } } } - + if(numberVertices<=0xffff) CreateSphereIndices(gc.CreateIBO16(numberIndices),numberParallels,dci->numberSlices); else @@ -677,7 +677,7 @@ namespace hgl // used to generate the indices uint v0, v1, v2, v3; - + for (sideCount = 0; sideCount < numberSlices; ++sideCount) { for (faceCount = 0; faceCount < numberStacks; ++faceCount) @@ -741,7 +741,7 @@ namespace hgl if(!gc.Init(numberVertices)) return(nullptr); - + float *vp=gc.GetVertexPointer(); float *np=gc.GetNormalPointer(); float *tp=gc.GetTangentPointer(); @@ -794,7 +794,7 @@ namespace hgl } } } - + if(numberVertices<=0xffff) CreateTorusIndices(gc.CreateIBO16(numberIndices),tci->numberSlices,tci->numberStacks); else @@ -871,7 +871,7 @@ namespace hgl if (cci->numberSlices < 3 || numberVertices > GLUS_MAX_VERTICES || numberIndices > GLUS_MAX_INDICES) return nullptr; - + float *vp=gc.GetVertexPointer(); float *np=gc.GetNormalPointer(); float *tp=gc.GetTangentPointer(); @@ -900,7 +900,7 @@ namespace hgl *tc = 0.0f; ++tc; *tc = 0.0f; ++tc; } - + for(uint i = 0; i < cci->numberSlices + 1; i++) { float currentAngle = angleStep * (float)i; @@ -929,7 +929,7 @@ namespace hgl *tc = 0.0f; ++tc; } } - + *vp = 0.0f; ++vp; *vp = 0.0f; ++vp; *vp = cci->halfExtend; ++vp; @@ -982,7 +982,7 @@ namespace hgl *tc = 1.0f; ++tc; } } - + for(uint i = 0; i < cci->numberSlices + 1; i++) { float currentAngle = angleStep * (float)i; @@ -1018,7 +1018,7 @@ namespace hgl sign = 1.0f; } } - + if(numberVertices<=0xffff) CreateCylinderIndices(gc.CreateIBO16(numberIndices),cci->numberSlices); else @@ -1055,7 +1055,7 @@ namespace hgl *tp = indexCounter; ++tp; *tp = indexCounter + numberSlices + 1; ++tp; *tp = indexCounter + 1; ++tp; - + *tp = indexCounter + 1; ++tp; *tp = indexCounter + numberSlices + 1; ++tp; *tp = indexCounter + numberSlices + 2; ++tp; @@ -1066,7 +1066,7 @@ namespace hgl } } }//namespace - + vulkan::Renderable *CreateRenderableCone(SceneDB *db,vulkan::Material *mtl,const ConeCreateInfo *cci) { GeometryCreater3D gc(db,mtl); @@ -1117,7 +1117,7 @@ namespace hgl *tc = 0.0f; ++tc; *tc = 0.0f; ++tc; } - + for (i = 0; i < cci->numberSlices + 1; i++) { float currentAngle = angleStep * (float)i; @@ -1180,7 +1180,7 @@ namespace hgl } } } - + if(numberVertices<=0xffff) CreateConeIndices(gc.CreateIBO16(numberIndices),cci->numberSlices,cci->numberStacks); else @@ -1219,16 +1219,16 @@ namespace hgl // Points of a cube. /* 4 5 */ const float points[]={ -0.5,-0.5, 0.5, 0.5,-0.5,0.5, 0.5,-0.5,-0.5, -0.5,-0.5,-0.5, /* *------------* */ -0.5, 0.5, 0.5, 0.5, 0.5,0.5, 0.5, 0.5,-0.5, -0.5, 0.5,-0.5}; - /* /| /| */ - /* 0/ | 1/ | */ - /* *--+---------* | */ - /* | | | | */ - /* | 7| | 6| */ - /* | *---------+--* */ - /* | / | / */ - /* |/ 2|/ */ - /* 3*------------* */ - + /* /| /| */ + /* 0/ | 1/ | */ + /* *--+---------* | */ + /* | | | | */ + /* | 7| | 6| */ + /* | *---------+--* */ + /* | / | / */ + /* |/ 2|/ */ + /* 3*------------* */ + const uint16 indices[]= { 0,1, 1,2, 2,3, 3,0, @@ -1244,7 +1244,7 @@ namespace hgl VB3f *vertex=gc.GetVertex(); if(!vertex)return(nullptr); - + if(cci->center ==Vector3f(0,0,0) &&cci->size ==Vector3f(1,1,1)) { diff --git a/src/SceneGraph/font/FontSourceWin.h b/src/SceneGraph/font/FontSourceWin.h index 51d77840..0156bd85 100644 --- a/src/SceneGraph/font/FontSourceWin.h +++ b/src/SceneGraph/font/FontSourceWin.h @@ -33,7 +33,7 @@ namespace hgl bool MakeCharBitmap(FontBitmap *,u32char) override; ///<产生字体数据 int GetLineHeight()const override{return LineHeight;} ///<取得行高 - int GetCharWidth(const u32char &) override; + int GetCharAdvWidth(const u32char &) override; };//class WinBitmapFont }//namespace graph }//namespace hgl diff --git a/src/SceneGraph/shader/ShaderResource.cpp b/src/SceneGraph/shader/ShaderResource.cpp index 4276ea3c..184314df 100644 --- a/src/SceneGraph/shader/ShaderResource.cpp +++ b/src/SceneGraph/shader/ShaderResource.cpp @@ -28,7 +28,6 @@ VK_NAMESPACE_BEGIN const uint32 total_bytes=AccessByPointer(data,uint32); int basetype; - int vec_size; int str_len; ShaderStage *ss; @@ -39,9 +38,9 @@ VK_NAMESPACE_BEGIN ss->location=*data++; basetype=*data++; - vec_size=*data++; + ss->component=*data++; - ss->format=VK_NAMESPACE::GetVulkanFormat(basetype,vec_size); + ss->format=VK_NAMESPACE::GetVulkanFormat(basetype,ss->component); str_len=*data++; ss->name.SetString((char *)data,str_len); @@ -86,7 +85,23 @@ VK_NAMESPACE_BEGIN delete[] data; } - const int ShaderResource::GetStageInputBinding(const AnsiString &name) + const ShaderStage *ShaderResource::GetStage(const AnsiString &name) const + { + const int count=stage_inputs.GetCount(); + ShaderStage **ss=stage_inputs.GetData(); + + for(int i=0;iname) + return *ss; + + ++ss; + } + + return nullptr; + } + + const int ShaderResource::GetStageInputBinding(const AnsiString &name) const { const int count=stage_inputs.GetCount(); ShaderStage **ss=stage_inputs.GetData();