增加TileData
This commit is contained in:
parent
d4bee40b78
commit
c2a751bf68
@ -1,103 +1,68 @@
|
|||||||
#ifndef HGL_GRAPH_TILE_DATA_INCLUDE
|
#ifndef HGL_GRAPH_TILE_DATA_INCLUDE
|
||||||
#define HGL_GRAPH_TILE_DATA_INCLUDE
|
#define HGL_GRAPH_TILE_DATA_INCLUDE
|
||||||
|
|
||||||
#include<hgl/graph/TextureFormat.h>
|
#include<hgl/graph/vulkan/VKTexture.h>
|
||||||
|
|
||||||
|
VK_NAMESPACE_USING
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
namespace graph
|
namespace graph
|
||||||
{
|
{
|
||||||
class Texture2D;
|
|
||||||
class Renderable;
|
|
||||||
class Bitmap2D;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TileData是一种处理将大量等同贴图的管理机制,程序会自动根据显卡最大贴图处理能力来创建尽可能符合的贴图。(注意:Tile的宽高不必是2的幂)。<br>
|
* TileData是一种处理大量等同尺寸及格式贴图的管理机制,程序会自动根据显卡最大贴图处理能力来创建尽可能符合需求的贴图。(注:Tile的大小不必符合2次幂)
|
||||||
* Tile的增加删除,程序会做自动排序,尽可能小的影响效能。
|
* Tile的增加或删除,程序会自动排序,尽可能小的减少I/O消耗。
|
||||||
*/
|
*/
|
||||||
class TileData ///Tile数据管理
|
class TileData ///Tile纹理管理
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
struct Object ///Tile对象
|
struct Object
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
double fl,ft;
|
double fl,ft,fw,fh;
|
||||||
double fw,fh;
|
|
||||||
|
|
||||||
int width,height;
|
int width,height;
|
||||||
};
|
};//struct TileObject
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Texture2D *tile_texture; ///<Tile所用贴图
|
Texture2D *tile_texture; ///<TileData所用的纹理对象
|
||||||
|
|
||||||
TileData::Object **tile_object; ///<所有Tile对象指针
|
TileData::Object **tile_object; ///<所有的Tile对象
|
||||||
|
|
||||||
int tile_width,tile_height; ///<tile的宽和高
|
int tile_width,tile_height; ///<Tile的宽和高
|
||||||
int tile_count,tile_total; ///<当前tile数量与最大数量
|
int tile_count,tile_total; ///<当前Tile数量与最大数量
|
||||||
int tile_rows,tile_cols; ///<贴图中可用的tile行数和列数
|
int tile_rows,tile_cols; ///<贴图中可用的Tile行数和列数
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
int FindSpace(); ///<寻找一个空位
|
||||||
|
void WriteTile(int,TileData::Object *,void *,uint,uint32,int,int); ///<写入一个Tile
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
int FindSpace(); ///<寻找一个空位
|
int GetWidth ()const{return tile_width;} ///<取得Tile宽
|
||||||
void WriteTile(int,TileData::Object *,void *,unsigned int,TextureSourceFormat,int,int); ///<写入一个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数量
|
||||||
|
|
||||||
|
Texture2D * GetTexture ()const{return tile_texture;} ///<取得贴图
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
int GetWidth ()const{return tile_width;} ///<取得Tile宽
|
TileData(int,int,int,unsigned int);
|
||||||
int GetHeight ()const{return tile_height;} ///<取得Tile高
|
virtual ~TileData();
|
||||||
int GetCount ()const{return tile_count;} ///<取得Tile数量
|
|
||||||
int GetMaxCount ()const{return tile_total;} ///<取得Tile最大数量
|
|
||||||
int GetFreeCount()const{return tile_total-tile_count;} ///<取得空余Tile数量
|
|
||||||
|
|
||||||
Texture2D * GetTexture ()const{return tile_texture;} ///<取得贴图
|
TileData::Object *Add(void *,unsigned int,uint32,int=-1,int=-1); ///<增加一个Tile
|
||||||
|
// TileData::Object *Add(Bitmap2D *,int=-1,int=-1); ///<增加一个Tile
|
||||||
|
|
||||||
public:
|
bool Delete(TileData::Object *); ///<删除一个Tile
|
||||||
|
bool Change(TileData::Object *,void *,unsigned int,uint32,int=-1,int=-1); ///<更改一个Tile的数据内容
|
||||||
TileData(int,int,int, TextureSourceFormat);
|
void Clear(); ///<清除Tile数据
|
||||||
virtual ~TileData();
|
|
||||||
|
|
||||||
TileData::Object *Add(void *,unsigned int,TextureSourceFormat,int=-1,int=-1); ///<增加一个Tile
|
|
||||||
|
|
||||||
bool Delete(TileData::Object *); ///<删除一个Tile
|
|
||||||
bool Change(TileData::Object *,void *,unsigned int,TextureSourceFormat,int=-1,int=-1); ///<更改一个Tile的数据内容
|
|
||||||
void Clear(); ///<清除Tile数据
|
|
||||||
};//class TileData
|
};//class TileData
|
||||||
|
|
||||||
template<typename T> class VertexBuffer2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 渲染Tile为一个2D矩形数据到顶点缓冲区上
|
|
||||||
* @param obj 要渲制的Tile对象
|
|
||||||
* @param vertex 渲染到的2d顶点坐标缓冲区
|
|
||||||
* @param tex_coord 渲染到的贴图坐标缓冲区
|
|
||||||
* @param left 显示的左边界
|
|
||||||
* @param top 显示的上边界
|
|
||||||
* @param scale_width 宽度缩放比
|
|
||||||
* @param scale_height 高度缩放比
|
|
||||||
*/
|
|
||||||
template<typename T1,typename T2>
|
|
||||||
__inline void RenderToVB2DRect( VertexBuffer2<T1> *vertex,
|
|
||||||
VertexBuffer2<T2> *tex_coord,
|
|
||||||
const TileData::Object *obj,
|
|
||||||
const float left,
|
|
||||||
const float top,
|
|
||||||
const float scale_width=1.0f,
|
|
||||||
const float scale_height=1.0f)
|
|
||||||
{
|
|
||||||
if(!obj||!vertex||!tex_coord)return;
|
|
||||||
|
|
||||||
tex_coord->WriteRect( obj->fl,
|
|
||||||
obj->ft,
|
|
||||||
obj->fw,
|
|
||||||
obj->fh);
|
|
||||||
|
|
||||||
vertex->WriteRect( left,
|
|
||||||
top,
|
|
||||||
scale_width*float(obj->width),
|
|
||||||
scale_height*float(obj->height));
|
|
||||||
}
|
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
#endif//HGL_GRAPH_TILE_DATA_INCLUDE
|
#endif//HGL_GRAPH_TILE_DATA_INCLUDE
|
||||||
|
@ -87,5 +87,22 @@ public:
|
|||||||
|
|
||||||
VkFormat GetDepthFormat(bool lower_to_high=true)const;
|
VkFormat GetDepthFormat(bool lower_to_high=true)const;
|
||||||
VkFormat GetDepthStencilFormat(bool lower_to_high=true)const;
|
VkFormat GetDepthStencilFormat(bool lower_to_high=true)const;
|
||||||
|
|
||||||
|
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;}
|
||||||
|
const uint32_t GetMaxImageCube ()const{return properties.limits.maxImageDimensionCube;}
|
||||||
|
const uint32_t GetMaxImageArrayLayers ()const{return properties.limits.maxImageArrayLayers;}
|
||||||
|
const uint32_t GetMaxUBORange ()const{return properties.limits.maxUniformBufferRange;}
|
||||||
|
const uint32_t GetMaxSSBORange ()const{return properties.limits.maxStorageBufferRange;}
|
||||||
|
const uint32_t GetMaxBoundDescriptorSets()const{return properties.limits.maxBoundDescriptorSets;}
|
||||||
|
|
||||||
|
const uint32_t GetMaxVertexInputAttributes ()const{return properties.limits.maxVertexInputAttributes;}
|
||||||
|
const uint32_t GetMaxVertexInputBindings ()const{return properties.limits.maxVertexInputBindings;}
|
||||||
|
|
||||||
|
const uint32_t GetMaxColorAttachments ()const{return properties.limits.maxColorAttachments;}
|
||||||
|
|
||||||
|
const void GetPointSize(float &,float &)
|
||||||
|
|
||||||
};//class PhysicalDevice
|
};//class PhysicalDevice
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -24,6 +24,7 @@ SET(SCENE_GRAPH_HEADER ${ROOT_INCLUDE_PATH}/hgl/graph/Light.h
|
|||||||
${ROOT_INCLUDE_PATH}/hgl/graph/RenderableInstance.h
|
${ROOT_INCLUDE_PATH}/hgl/graph/RenderableInstance.h
|
||||||
${ROOT_INCLUDE_PATH}/hgl/graph/RenderList.h
|
${ROOT_INCLUDE_PATH}/hgl/graph/RenderList.h
|
||||||
${ROOT_INCLUDE_PATH}/hgl/graph/InlineGeometry.h
|
${ROOT_INCLUDE_PATH}/hgl/graph/InlineGeometry.h
|
||||||
|
${ROOT_INCLUDE_PATH}/hgl/graph/TileData.h
|
||||||
#${ROOT_INCLUDE_PATH}/hgl/graph/Mesh.h
|
#${ROOT_INCLUDE_PATH}/hgl/graph/Mesh.h
|
||||||
#${ROOT_INCLUDE_PATH}/hgl/graph/Material.h
|
#${ROOT_INCLUDE_PATH}/hgl/graph/Material.h
|
||||||
#${ROOT_INCLUDE_PATH}/hgl/graph/Spline.h
|
#${ROOT_INCLUDE_PATH}/hgl/graph/Spline.h
|
||||||
@ -34,6 +35,7 @@ SET(SCENE_GRAPH_SOURCE RenderList.cpp
|
|||||||
SceneNode.cpp
|
SceneNode.cpp
|
||||||
SceneOrient.cpp
|
SceneOrient.cpp
|
||||||
InlineGeometry.cpp
|
InlineGeometry.cpp
|
||||||
|
TileData.cpp
|
||||||
#InlinePipeline.cpp
|
#InlinePipeline.cpp
|
||||||
#Material.cpp
|
#Material.cpp
|
||||||
#Mesh.cpp
|
#Mesh.cpp
|
||||||
|
63
src/SceneGraph/TileData.cpp
Normal file
63
src/SceneGraph/TileData.cpp
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#include<hgl/graph/TileData.h>
|
||||||
|
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
namespace graph
|
||||||
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
|
||||||
|
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
|
||||||
|
}//namespace graph
|
||||||
|
}//namespace hgl
|
Loading…
x
Reference in New Issue
Block a user