diff --git a/inc/hgl/graph/TileData.h b/inc/hgl/graph/TileData.h index b28f4d45..98ff58f9 100644 --- a/inc/hgl/graph/TileData.h +++ b/inc/hgl/graph/TileData.h @@ -32,35 +32,35 @@ namespace hgl TileData::Object **tile_object; ///<所有的Tile对象 - int tile_width,tile_height; /// #include +namespace hgl +{ + namespace graph + { + class TileData; + }//namespace graph +}//namespace hgl + VK_NAMESPACE_BEGIN class Device { @@ -216,6 +224,8 @@ public: bool SubmitTexture (const VkCommandBuffer *cmd_bufs,const uint32_t count=1); ///<提交纹理处理到队列 RenderTarget *CreateRenderTarget(Framebuffer *); + + TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集 };//class Device Device *CreateRenderDevice(Instance *inst,Window *win,const PhysicalDevice *physical_device=nullptr); diff --git a/inc/hgl/graph/vulkan/VKPhysicalDevice.h b/inc/hgl/graph/vulkan/VKPhysicalDevice.h index 134967b7..f78c688c 100644 --- a/inc/hgl/graph/vulkan/VKPhysicalDevice.h +++ b/inc/hgl/graph/vulkan/VKPhysicalDevice.h @@ -88,6 +88,8 @@ public: VkFormat GetDepthFormat(bool lower_to_high=true)const; VkFormat GetDepthStencilFormat(bool lower_to_high=true)const; +public: + const uint32_t GetMaxImage1D ()const{return properties.limits.maxImageDimension1D;} const uint32_t GetMaxImage2D ()const{return properties.limits.maxImageDimension2D;} const uint32_t GetMaxImage3D ()const{return properties.limits.maxImageDimension3D;} @@ -102,7 +104,18 @@ public: const uint32_t GetMaxColorAttachments ()const{return properties.limits.maxColorAttachments;} - const void GetPointSize(float &,float &) + const void GetPointSize(float &granularity,float &min_point,float &max_point) + { + granularity =properties.limits.pointSizeGranularity; + min_point =properties.limits.pointSizeRange[0]; + max_point =properties.limits.pointSizeRange[1]; + } + const void GetLineWidth(float &granularity,float &min_width,float &max_width) + { + granularity =properties.limits.lineWidthGranularity; + min_width =properties.limits.lineWidthRange[0]; + max_width =properties.limits.lineWidthRange[1]; + } };//class PhysicalDevice VK_NAMESPACE_END diff --git a/src/RenderDevice/Vulkan/CMakeLists.txt b/src/RenderDevice/Vulkan/CMakeLists.txt index 6f9b7f8b..26e35a5a 100644 --- a/src/RenderDevice/Vulkan/CMakeLists.txt +++ b/src/RenderDevice/Vulkan/CMakeLists.txt @@ -38,7 +38,8 @@ SET(RENDER_DEVICE_VULKAN_SOURCE VKMemory.cpp VKSemaphore.cpp VKFence.cpp VKRenderable.cpp - VKSampler.cpp) + VKSampler.cpp + VKTileData.cpp) SET(RENDER_DEVICE_VULKAN_POD_SOURCE POD/VKPipelineCreateInfo.POD.cpp POD/VKTextureLoader.cpp) diff --git a/src/RenderDevice/Vulkan/VKTileData.cpp b/src/RenderDevice/Vulkan/VKTileData.cpp new file mode 100644 index 00000000..b3c95d37 --- /dev/null +++ b/src/RenderDevice/Vulkan/VKTileData.cpp @@ -0,0 +1,100 @@ +#include +#include +#include + +namespace +{ + using namespace hgl; + + void AnalyseSize(uint &fw,uint &fh,const uint w,const uint h,const uint count,const uint32_t max_texture_size) + { + int total,tw,th,t; + + fw=fh=0; + + tw=max_texture_size; + while(tw>=w) + { + th=max_texture_size; + while(th>=h) + { + t=(tw/w)*(th/h); + + if(!fw) + { + fw=tw; + fh=th; + + total=t; + } + else + { + if(t==count) + { + //正好,就要这么大的 + + fw=tw; + fh=th; + + return; + } + else + if(t>count) //要比要求的最大值大 + { + if(t>=1; + } + + tw>>=1; + } + }//void AnalyseSize +}//namespace + +VK_NAMESPACE_BEGIN +TileData *Device::CreateTileData(const VkFormat format,const uint width,const uint height,const uint count) +{ + if(!CheckVulkanFormat(format)) + return(nullptr); + + if(width<=0||height<=0||count<=0) + return(nullptr); + + const uint32_t max_2d_texture=attr->physical_device->GetMaxImage2D(); + + uint tex_width,tex_height; + + AnalyseSize(tex_width,tex_height,width,height,count,max_2d_texture); + + const VulkanFormat *vf=GetVulkanFormat(format); + + if(!vf)return(nullptr); + + Texture2D *tex=nullptr; + + if(vf->color>VulkanDataType::NONE + &&vf->colordepth>VulkanDataType::NONE + &&vf->depth +#include namespace hgl { namespace graph { - namespace + TileData::TileData(Texture2D *tt,const uint tw,const uint th) { - void AnalyseSize(int &fw,int &fh,const int w,const int h,const int count,const int max_texture_size) - { - int total,tw,th,t; + tile_texture=tt; - fw=fh=0; + tile_width=tw; + tile_height=th; - tw=max_texture_size; - while(tw>=w) - { - th=max_texture_size; - while(th>=h) - { - t=(tw/w)*(th/h); + tile_rows=tile_texture->GetHeight()/tile_height; + tile_cols=tile_texture->GetWidth()/tile_width; - if(!fw) - { - fw=tw; - fh=th; + tile_max_count=tile_rows*tile_cols; + tile_count=0; - total=t; - } - else - { - if(t==count) - { - //正好,就要这么大的 + NEW_NULL_ARRAY(tile_object,TileData::Object *,tile_max_count); + } - fw=tw; - fh=th; + TileData::~TileData() + { + SAFE_CLEAR(tile_texture); + SAFE_CLEAR_OBJECT_ARRAY(tile_object,tile_max_count); + } - return; - } - else - if(t>count) //要比要求的最大值大 - { - if(t=tile_max_count)return(-1); - total=t; - } - } - } + int n=tile_max_count; - th>>=1; - } + while(n--) + if(!(tile_object[n])) + return(n); - tw>>=1; - } - }//void AnalyseSize - }//namespace + LOG_PROBLEM(OS_TEXT("无法在Tile数据区内找到足够的空间!")); + return(-1); + } + + void TileData::WriteTile(int index,TileData::Object *obj,void *data,uint bytes,VkFormat format,int ctw,int cth) + { + int col,row; + double left,top; + + col=index%tile_cols; + row=index/tile_cols; + + left=tile_width *col; + top =tile_height*row; + + obj->index =index; + + obj->width =(ctw==-1)?tile_width:ctw; + obj->height =(cth==-1)?tile_height:cth; + + obj->fl=left/double(tile_texture->GetWidth()); + obj->ft=top /double(tile_texture->GetHeight()); + obj->fw=double(obj->width)/double(tile_texture->GetWidth()); + obj->fh=double(obj->height)/double(tile_texture->GetHeight()); + + tile_object[index]=obj; + + tile_texture->ChangeImage( left, + top, + tile_width, + tile_height, + data, + bytes, + format); + //请保留这段代码,以便未来使用时该数据时不会使用 + //{ + // vertex->Begin(index*6); + // texcoord->Begin(index*6); + + // texcoord->WriteRect(obj->fl,obj->ft,obj->fw,obj->fh); + // vertex->WriteRect(0,0,obj->width,obj->height); + + // texcoord->End(); + // vertex->End(); + //} + } }//namespace graph }//namespace hgl