support compress texture file format.
This commit is contained in:
parent
7f2c5b0a1c
commit
a5ab2edf12
@ -1 +1 @@
|
|||||||
Subproject commit 780a97d2435577b6fc6008bb656e623c5c058431
|
Subproject commit 81c18490a375fbeaa1ea99340916e44833ef6a74
|
@ -90,7 +90,7 @@ private:
|
|||||||
|
|
||||||
bool InitTileTexture()
|
bool InitTileTexture()
|
||||||
{
|
{
|
||||||
tile_data=device->CreateTileData( FMT_A1RGB5, //纹理格式,因VK不支持实时转换,所以提交的数据格式必须与此一致
|
tile_data=device->CreateTileData( FMT_BC1_RGBAUN, //纹理格式,因VK不支持实时转换,所以提交的数据格式必须与此一致
|
||||||
512,512, //TILE大小
|
512,512, //TILE大小
|
||||||
tile_list.GetCount()); //TILE需求数量
|
tile_list.GetCount()); //TILE需求数量
|
||||||
|
|
||||||
|
@ -13,20 +13,26 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
uint8 id[6]; ///<Tex2D\x1A
|
uint8 id[6]; ///<Tex2D\x1A
|
||||||
uint8 version; ///<必须为2
|
uint8 version; ///<必须为2
|
||||||
bool mipmaps;
|
uint8 mipmaps;
|
||||||
uint32 width;
|
uint32 width;
|
||||||
uint32 height;
|
uint32 height;
|
||||||
uint8 channels;
|
uint8 channels;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
const uint pixel_count()const{return width*height;}
|
||||||
|
};//struct Tex2DFileHeader
|
||||||
|
|
||||||
|
struct TexPixelFormat
|
||||||
|
{
|
||||||
char colors[4];
|
char colors[4];
|
||||||
uint8 bits[4];
|
uint8 bits[4];
|
||||||
uint8 datatype;
|
uint8 datatype;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
const uint pixel_count()const{return width*height;}
|
|
||||||
const uint pixel_bytes()const{return (bits[0]+bits[1]+bits[2]+bits[3])>>3;}
|
const uint pixel_bytes()const{return (bits[0]+bits[1]+bits[2]+bits[3])>>3;}
|
||||||
const uint total_bytes()const{return pixel_count()*pixel_bytes();}
|
};//struct TexPixelFormat
|
||||||
};//
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,6 +44,14 @@ namespace hgl
|
|||||||
|
|
||||||
Tex2DFileHeader file_header;
|
Tex2DFileHeader file_header;
|
||||||
|
|
||||||
|
union
|
||||||
|
{
|
||||||
|
TexPixelFormat pixel_format;
|
||||||
|
uint16 compress_format;
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32 total_bytes;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual void *OnBegin(uint32)=0;
|
virtual void *OnBegin(uint32)=0;
|
||||||
|
@ -37,8 +37,6 @@ namespace hgl
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
uint pixel_bytes; ///<单个象素字节数
|
|
||||||
|
|
||||||
Texture2D *tile_texture; ///<TileData所用的纹理对象
|
Texture2D *tile_texture; ///<TileData所用的纹理对象
|
||||||
|
|
||||||
ObjectPool<TileObject> to_pool; ///<Tile对象池
|
ObjectPool<TileObject> to_pool; ///<Tile对象池
|
||||||
|
2
res
2
res
@ -1 +1 @@
|
|||||||
Subproject commit 89ec7b496644d38d5baf52b9fe98f74cc79ffa01
|
Subproject commit 134fa86c091b40a890c64d7052af8c21d01c209e
|
@ -54,24 +54,24 @@ namespace
|
|||||||
|
|
||||||
constexpr uint PixelFormatCount=sizeof(pf_list)/sizeof(PixelFormat);
|
constexpr uint PixelFormatCount=sizeof(pf_list)/sizeof(PixelFormat);
|
||||||
|
|
||||||
const VkFormat GetVulkanFormat(const Tex2DFileHeader &fh)
|
const VkFormat GetVulkanFormat(const int channels,const TexPixelFormat &tpf)
|
||||||
{
|
{
|
||||||
const PixelFormat *pf=pf_list;
|
const PixelFormat *pf=pf_list;
|
||||||
|
|
||||||
for(uint i=0;i<PixelFormatCount;i++,++pf)
|
for(uint i=0;i<PixelFormatCount;i++,++pf)
|
||||||
{
|
{
|
||||||
if(fh.channels!=pf->channels)continue;
|
if(channels!=pf->channels)continue;
|
||||||
if(fh.datatype!=(uint8)pf->type)continue;
|
if(tpf.datatype!=(uint8)pf->type)continue;
|
||||||
|
|
||||||
if(fh.colors[0]!=pf->colors[0])continue;
|
if(tpf.colors[0]!=pf->colors[0])continue;
|
||||||
if(fh.colors[1]!=pf->colors[1])continue;
|
if(tpf.colors[1]!=pf->colors[1])continue;
|
||||||
if(fh.colors[2]!=pf->colors[2])continue;
|
if(tpf.colors[2]!=pf->colors[2])continue;
|
||||||
if(fh.colors[3]!=pf->colors[3])continue;
|
if(tpf.colors[3]!=pf->colors[3])continue;
|
||||||
|
|
||||||
if(fh.bits[0]!=pf->bits[0])continue;
|
if(tpf.bits[0]!=pf->bits[0])continue;
|
||||||
if(fh.bits[1]!=pf->bits[1])continue;
|
if(tpf.bits[1]!=pf->bits[1])continue;
|
||||||
if(fh.bits[2]!=pf->bits[2])continue;
|
if(tpf.bits[2]!=pf->bits[2])continue;
|
||||||
if(fh.bits[3]!=pf->bits[3])continue;
|
if(tpf.bits[3]!=pf->bits[3])continue;
|
||||||
|
|
||||||
return pf->format;
|
return pf->format;
|
||||||
}
|
}
|
||||||
@ -107,10 +107,33 @@ namespace
|
|||||||
|
|
||||||
void *OnBegin(uint32 total_bytes) override
|
void *OnBegin(uint32 total_bytes) override
|
||||||
{
|
{
|
||||||
|
constexpr VkFormat CompressFormatList[]=
|
||||||
|
{
|
||||||
|
FMT_BC1_RGBUN,
|
||||||
|
FMT_BC1_RGBAUN,
|
||||||
|
FMT_BC2UN,
|
||||||
|
FMT_BC3UN,
|
||||||
|
FMT_BC4UN,
|
||||||
|
FMT_BC5UN,
|
||||||
|
FMT_BC6UF,
|
||||||
|
FMT_BC6SF,
|
||||||
|
FMT_BC7UN
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr size_t CompressFormatCount=sizeof(CompressFormatList)/sizeof(VkFormat);
|
||||||
|
|
||||||
SAFE_CLEAR(buf);
|
SAFE_CLEAR(buf);
|
||||||
SAFE_CLEAR(tex);
|
SAFE_CLEAR(tex);
|
||||||
|
|
||||||
format=GetVulkanFormat(file_header);
|
if(file_header.channels==0)
|
||||||
|
{
|
||||||
|
if(compress_format<0||compress_format>=CompressFormatCount)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
format=CompressFormatList[compress_format];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
format=GetVulkanFormat(file_header.channels,pixel_format);
|
||||||
|
|
||||||
if(!CheckVulkanFormat(format))
|
if(!CheckVulkanFormat(format))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
@ -17,10 +17,23 @@ namespace hgl
|
|||||||
if(file_header.version!=2)
|
if(file_header.version!=2)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
if(file_header.total_bytes()==0)
|
total_bytes=0;
|
||||||
|
|
||||||
|
if(file_header.channels==0) //压缩格式
|
||||||
|
{
|
||||||
|
if(is->Read(&compress_format,sizeof(uint16))!=sizeof(uint16))
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
const uint total_bytes=file_header.total_bytes();
|
if(is->Read(&total_bytes,sizeof(uint32))!=sizeof(uint32))
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(is->Read(&pixel_format,sizeof(TexPixelFormat))!=sizeof(TexPixelFormat))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
total_bytes=file_header.pixel_count()*pixel_format.pixel_bytes();
|
||||||
|
}
|
||||||
|
|
||||||
if(is->Available()<total_bytes)
|
if(is->Available()<total_bytes)
|
||||||
return(false);
|
return(false);
|
||||||
|
@ -48,8 +48,7 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pixel_bytes =GetStrideByFormat(tile_texture->GetFormat());
|
tile_bytes=GetImageBytes(tile_texture->GetFormat(),tile_width*tile_height);
|
||||||
tile_bytes =tile_width*tile_height*pixel_bytes;
|
|
||||||
|
|
||||||
tile_buffer=device->CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,tile_bytes*tile_max_count,nullptr);
|
tile_buffer=device->CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,tile_bytes*tile_max_count,nullptr);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user