实际部分TileData
This commit is contained in:
parent
c2a751bf68
commit
b37d7c1a5b
@ -32,35 +32,35 @@ namespace hgl
|
||||
|
||||
TileData::Object **tile_object; ///<所有的Tile对象
|
||||
|
||||
int tile_width,tile_height; ///<Tile的宽和高
|
||||
int tile_count,tile_total; ///<当前Tile数量与最大数量
|
||||
int tile_rows,tile_cols; ///<贴图中可用的Tile行数和列数
|
||||
uint tile_width,tile_height; ///<Tile的宽和高
|
||||
uint tile_count,tile_max_count; ///<当前Tile数量与最大数量
|
||||
uint tile_rows,tile_cols; ///<贴图中可用的Tile行数和列数
|
||||
|
||||
protected:
|
||||
|
||||
int FindSpace(); ///<寻找一个空位
|
||||
void WriteTile(int,TileData::Object *,void *,uint,uint32,int,int); ///<写入一个Tile
|
||||
void WriteTile(int,TileData::Object *,void *,uint,VkFormat,int,int); ///<写入一个Tile
|
||||
|
||||
public:
|
||||
|
||||
int GetWidth ()const{return tile_width;} ///<取得Tile宽
|
||||
int GetHeight ()const{return tile_height;} ///<取得Tile高
|
||||
int GetCount ()const{return tile_count;} ///<取得Tile数量
|
||||
int GetMaxCount ()const{return tile_total;} ///<取得Tile最大数量
|
||||
int GetFreeCount()const{return tile_total-tile_count;} ///<取得空余Tile数量
|
||||
int GetMaxCount ()const{return tile_max_count;} ///<取得Tile最大数量
|
||||
int GetFreeCount()const{return tile_max_count-tile_count;} ///<取得空余Tile数量
|
||||
|
||||
Texture2D * GetTexture ()const{return tile_texture;} ///<取得贴图
|
||||
|
||||
public:
|
||||
|
||||
TileData(int,int,int,unsigned int);
|
||||
TileData(Texture2D *,const uint tw,const uint th);
|
||||
virtual ~TileData();
|
||||
|
||||
TileData::Object *Add(void *,unsigned int,uint32,int=-1,int=-1); ///<增加一个Tile
|
||||
TileData::Object *Add(void *,VkFormat,uint32,int=-1,int=-1); ///<增加一个Tile
|
||||
// TileData::Object *Add(Bitmap2D *,int=-1,int=-1); ///<增加一个Tile
|
||||
|
||||
bool Delete(TileData::Object *); ///<删除一个Tile
|
||||
bool Change(TileData::Object *,void *,unsigned int,uint32,int=-1,int=-1); ///<更改一个Tile的数据内容
|
||||
bool Change(TileData::Object *,void *,VkFormat,uint32,int=-1,int=-1); ///<更改一个Tile的数据内容
|
||||
void Clear(); ///<清除Tile数据
|
||||
};//class TileData
|
||||
}//namespace graph
|
||||
|
@ -11,6 +11,14 @@
|
||||
#include<hgl/graph/vulkan/VKRenderTarget.h>
|
||||
#include<hgl/graph/VertexBufferCreater.h>
|
||||
|
||||
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);
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
100
src/RenderDevice/Vulkan/VKTileData.cpp
Normal file
100
src/RenderDevice/Vulkan/VKTileData.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
#include<hgl/graph/vulkan/VKDevice.h>
|
||||
#include<hgl/graph/vulkan/VKPhysicalDevice.h>
|
||||
#include<hgl/graph/TileData.h>
|
||||
|
||||
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<total) //找到最接近最大值的
|
||||
{
|
||||
//比现在选中的更节省
|
||||
fw=tw;
|
||||
fh=th;
|
||||
|
||||
total=t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
th>>=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->color<VulkanDataType::END)
|
||||
{
|
||||
tex=CreateTexture2DColor(format,tex_width,tex_height);
|
||||
}
|
||||
else
|
||||
if(vf->depth>VulkanDataType::NONE
|
||||
&&vf->depth<VulkanDataType::END)
|
||||
{
|
||||
tex=CreateTexture2DDepth(format,tex_width,tex_height);
|
||||
}
|
||||
else
|
||||
return(nullptr);
|
||||
|
||||
return(new TileData(tex,width,height));
|
||||
}
|
||||
VK_NAMESPACE_END
|
@ -1,63 +1,88 @@
|
||||
#include<hgl/graph/TileData.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
|
||||
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)
|
||||
{
|
||||
//正好,就要这么大的
|
||||
|
||||
fw=tw;
|
||||
fh=th;
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
if(t>count) //要比要求的最大值大
|
||||
{
|
||||
if(t<total) //找到最接近最大值的
|
||||
{
|
||||
//比现在选中的更节省
|
||||
fw=tw;
|
||||
fh=th;
|
||||
|
||||
total=t;
|
||||
}
|
||||
}
|
||||
NEW_NULL_ARRAY(tile_object,TileData::Object *,tile_max_count);
|
||||
}
|
||||
|
||||
th>>=1;
|
||||
TileData::~TileData()
|
||||
{
|
||||
SAFE_CLEAR(tile_texture);
|
||||
SAFE_CLEAR_OBJECT_ARRAY(tile_object,tile_max_count);
|
||||
}
|
||||
|
||||
tw>>=1;
|
||||
int TileData::FindSpace()
|
||||
{
|
||||
if(!tile_object)return(-1);
|
||||
if(tile_count>=tile_max_count)return(-1);
|
||||
|
||||
int n=tile_max_count;
|
||||
|
||||
while(n--)
|
||||
if(!(tile_object[n]))
|
||||
return(n);
|
||||
|
||||
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();
|
||||
//}
|
||||
}
|
||||
}//void AnalyseSize
|
||||
}//namespace
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
Loading…
x
Reference in New Issue
Block a user