TGA加载增加枚举明确属性意义,清除直接手写的ID
This commit is contained in:
parent
f611b8bfd9
commit
66fee61451
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit e4f3f4fac3951822fcc93258e729bd00c7851082
|
||||
Subproject commit 64dfbbcf7b748ad6b2c29ba1a4e0841f56201436
|
@ -1 +1 @@
|
||||
Subproject commit 89aba9674ba6f70f5060dbdf28316e9f1f072cd4
|
||||
Subproject commit 86e9b1533f66f3b3b5034a12506467ebd17ab739
|
@ -7,39 +7,55 @@
|
||||
VK_NAMESPACE_BEGIN
|
||||
namespace
|
||||
{
|
||||
#pragma pack(push,1)
|
||||
struct TGAHeader
|
||||
namespace tga
|
||||
{
|
||||
uint8 id;
|
||||
uint8 color_map_type;
|
||||
uint8 image_type; // 1 colormap image ,2 true-color,3 grayscale
|
||||
|
||||
uint16 color_map_first;
|
||||
uint16 color_map_length;
|
||||
uint8 color_map_size;
|
||||
|
||||
uint16 x_origin;
|
||||
uint16 y_origin;
|
||||
|
||||
uint16 width;
|
||||
uint16 height;
|
||||
uint8 bit;
|
||||
|
||||
uint8 image_desc;
|
||||
};
|
||||
|
||||
union TGAImageDesc
|
||||
{
|
||||
//不要把此union放到上面的struct中,否则Visual C++会将此union编译成4字节。GCC无此问题
|
||||
uint8 image_desc;
|
||||
struct
|
||||
enum class ImageType:uint8
|
||||
{
|
||||
uint alpha_depth:4;
|
||||
uint reserved:1;
|
||||
uint direction:1; //0 lower-left,1 upper left
|
||||
ColorMap=1,
|
||||
TrueColor=2,
|
||||
Grayscale=3
|
||||
};
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
enum class VerticalDirection:uint
|
||||
{
|
||||
BottomToTop=0,
|
||||
TopToBottom=1
|
||||
};
|
||||
|
||||
#pragma pack(push,1)
|
||||
struct Header
|
||||
{
|
||||
uint8 id;
|
||||
uint8 color_map_type;
|
||||
ImageType image_type; // 1 colormap image ,2 true-color,3 grayscale
|
||||
|
||||
uint16 color_map_first;
|
||||
uint16 color_map_length;
|
||||
uint8 color_map_size;
|
||||
|
||||
uint16 x_origin;
|
||||
uint16 y_origin;
|
||||
|
||||
uint16 width;
|
||||
uint16 height;
|
||||
uint8 bit;
|
||||
|
||||
uint8 image_desc;
|
||||
};
|
||||
|
||||
union ImageDesc
|
||||
{
|
||||
//不要把此union放到上面的struct中,否则Visual C++会将此union编译成4字节。GCC无此问题
|
||||
uint8 image_desc;
|
||||
struct
|
||||
{
|
||||
uint alpha_depth:4;
|
||||
uint horizontal_directon:1; // 水平方向(不支持该参数)
|
||||
VerticalDirection vertical_direction:1; // 0 bottom to top,1 top to bottom
|
||||
};
|
||||
};
|
||||
#pragma pack(pop)
|
||||
}//namespace tga
|
||||
|
||||
void RGB8to565(uint16 *target,uint8 *src,uint size)
|
||||
{
|
||||
@ -97,21 +113,21 @@ Texture2D *LoadTGATexture(const OSString &filename,Device *device)
|
||||
|
||||
const int64 file_length=fis->GetSize();
|
||||
|
||||
if(file_length<=sizeof(TGAHeader))
|
||||
if(file_length<=sizeof(tga::Header))
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("[ERROR] file<")+filename+OS_TEXT("> length < sizeof(TGAHeader)."));
|
||||
LOG_ERROR(OS_TEXT("[ERROR] file<")+filename+OS_TEXT("> length < sizeof(tga::Header)."));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
TGAHeader header;
|
||||
TGAImageDesc image_desc;
|
||||
tga::Header header;
|
||||
tga::ImageDesc image_desc;
|
||||
|
||||
if(fis->Read(&header,sizeof(TGAHeader))!=sizeof(TGAHeader))
|
||||
if(fis->Read(&header,sizeof(tga::Header))!=sizeof(tga::Header))
|
||||
return(false);
|
||||
|
||||
const uint total_bytes=header.width*header.height*header.bit>>3;
|
||||
|
||||
if(file_length<sizeof(TGAHeader)+total_bytes)
|
||||
if(file_length<sizeof(tga::Header)+total_bytes)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("[ERROR] file<")+filename+OS_TEXT("> length error."));
|
||||
return(nullptr);
|
||||
@ -121,13 +137,17 @@ Texture2D *LoadTGATexture(const OSString &filename,Device *device)
|
||||
|
||||
VkFormat format=FMT_UNDEFINED;
|
||||
|
||||
if(header.image_type==2)
|
||||
if(header.image_type==tga::ImageType::TrueColor)
|
||||
{
|
||||
if(header.bit==24)format=FMT_BGRA8UN;else
|
||||
if(header.bit==32)format=FMT_BGRA8UN;
|
||||
}
|
||||
else if(header.image_type==3&&header.bit==8)
|
||||
format=FMT_R8UN;
|
||||
else
|
||||
if(header.image_type==tga::ImageType::Grayscale)
|
||||
{
|
||||
if(header.bit== 8)format=FMT_R8UN;else
|
||||
if(header.bit==16)format=FMT_R16UN;
|
||||
}
|
||||
|
||||
if(format==FMT_UNDEFINED)
|
||||
{
|
||||
@ -143,7 +163,7 @@ Texture2D *LoadTGATexture(const OSString &filename,Device *device)
|
||||
|
||||
fis->Read(pixel_data,total_bytes);
|
||||
|
||||
if(image_desc.direction==0)
|
||||
if(image_desc.vertical_direction==tga::VerticalDirection::BottomToTop)
|
||||
SwapRow((uint8 *)pixel_data,header.width*header.bit/8,header.height);
|
||||
|
||||
buf=device->CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,header.width*header.height*4);
|
||||
@ -160,7 +180,7 @@ Texture2D *LoadTGATexture(const OSString &filename,Device *device)
|
||||
|
||||
fis->Read(pixel_data,total_bytes);
|
||||
|
||||
if(image_desc.direction==0)
|
||||
if(image_desc.vertical_direction==tga::VerticalDirection::BottomToTop)
|
||||
SwapRow((uint8 *)pixel_data,header.width*header.bit/8,header.height);
|
||||
|
||||
buf->Unmap();
|
||||
@ -184,4 +204,4 @@ Texture2D *LoadTGATexture(const OSString &filename,Device *device)
|
||||
|
||||
return(tex);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
VK_NAMESPACE_END
|
||||
|
@ -33,23 +33,21 @@ VK_NAMESPACE_BEGIN
|
||||
#define FMT_RG8I VK_FORMAT_R8G8_SINT
|
||||
#define FMT_RG8s VK_FORMAT_R8G8_SRGB
|
||||
|
||||
//注:几乎任何GPU都不支持 RGB8,BGR8,RGB16 这三类格式,所以尽可能不要使用这三类格式
|
||||
#define FMT_RGB8UN VK_FORMAT_R8G8B8_UNORM /* no GPU support,don't use */
|
||||
#define FMT_RGB8SN VK_FORMAT_R8G8B8_SNORM /* no GPU support,don't use */
|
||||
#define FMT_RGB8US VK_FORMAT_R8G8B8_USCALED /* no GPU support,don't use */
|
||||
#define FMT_RGB8SS VK_FORMAT_R8G8B8_SSCALED /* no GPU support,don't use */
|
||||
#define FMT_RGB8U VK_FORMAT_R8G8B8_UINT /* no GPU support,don't use */
|
||||
#define FMT_RGB8I VK_FORMAT_R8G8B8_SINT /* no GPU support,don't use */
|
||||
#define FMT_RGB8s VK_FORMAT_R8G8B8_SRGB /* no GPU support,don't use */
|
||||
|
||||
#define FMT_RGB8UN VK_FORMAT_R8G8B8_UNORM
|
||||
#define FMT_RGB8SN VK_FORMAT_R8G8B8_SNORM
|
||||
#define FMT_RGB8US VK_FORMAT_R8G8B8_USCALED
|
||||
#define FMT_RGB8SS VK_FORMAT_R8G8B8_SSCALED
|
||||
#define FMT_RGB8U VK_FORMAT_R8G8B8_UINT
|
||||
#define FMT_RGB8I VK_FORMAT_R8G8B8_SINT
|
||||
#define FMT_RGB8s VK_FORMAT_R8G8B8_SRGB
|
||||
|
||||
#define FMT_BGR8UN VK_FORMAT_B8G8R8_UNORM
|
||||
#define FMT_BGR8SN VK_FORMAT_B8G8R8_SNORM
|
||||
#define FMT_BGR8US VK_FORMAT_B8G8R8_USCALED
|
||||
#define FMT_BGR8SS VK_FORMAT_B8G8R8_SSCALED
|
||||
#define FMT_BGR8U VK_FORMAT_B8G8R8_UINT
|
||||
#define FMT_BGR8I VK_FORMAT_B8G8R8_SINT
|
||||
#define FMT_BGR8s VK_FORMAT_B8G8R8_SRGB
|
||||
#define FMT_BGR8UN VK_FORMAT_B8G8R8_UNORM /* no GPU support,don't use */
|
||||
#define FMT_BGR8SN VK_FORMAT_B8G8R8_SNORM /* no GPU support,don't use */
|
||||
#define FMT_BGR8US VK_FORMAT_B8G8R8_USCALED /* no GPU support,don't use */
|
||||
#define FMT_BGR8SS VK_FORMAT_B8G8R8_SSCALED /* no GPU support,don't use */
|
||||
#define FMT_BGR8U VK_FORMAT_B8G8R8_UINT /* no GPU support,don't use */
|
||||
#define FMT_BGR8I VK_FORMAT_B8G8R8_SINT /* no GPU support,don't use */
|
||||
#define FMT_BGR8s VK_FORMAT_B8G8R8_SRGB /* no GPU support,don't use */
|
||||
|
||||
#define FMT_RGBA8UN VK_FORMAT_R8G8B8A8_UNORM
|
||||
#define FMT_RGBA8SN VK_FORMAT_R8G8B8A8_SNORM
|
||||
@ -105,13 +103,13 @@ VK_NAMESPACE_BEGIN
|
||||
#define FMT_RG16I VK_FORMAT_R16G16_SINT
|
||||
#define FMT_RG16F VK_FORMAT_R16G16_SFLOAT
|
||||
|
||||
#define FMT_RGB16UN VK_FORMAT_R16G16B16_UNORM
|
||||
#define FMT_RGB16SN VK_FORMAT_R16G16B16_SNORM
|
||||
#define FMT_RGB16US VK_FORMAT_R16G16B16_USCALED
|
||||
#define FMT_RGB16SS VK_FORMAT_R16G16B16_SSCALED
|
||||
#define FMT_RGB16U VK_FORMAT_R16G16B16_UINT
|
||||
#define FMT_RGB16I VK_FORMAT_R16G16B16_SINT
|
||||
#define FMT_RGB16F VK_FORMAT_R16G16B16_SFLOAT
|
||||
#define FMT_RGB16UN VK_FORMAT_R16G16B16_UNORM /* no GPU support,don't use */
|
||||
#define FMT_RGB16SN VK_FORMAT_R16G16B16_SNORM /* no GPU support,don't use */
|
||||
#define FMT_RGB16US VK_FORMAT_R16G16B16_USCALED /* no GPU support,don't use */
|
||||
#define FMT_RGB16SS VK_FORMAT_R16G16B16_SSCALED /* no GPU support,don't use */
|
||||
#define FMT_RGB16U VK_FORMAT_R16G16B16_UINT /* no GPU support,don't use */
|
||||
#define FMT_RGB16I VK_FORMAT_R16G16B16_SINT /* no GPU support,don't use */
|
||||
#define FMT_RGB16F VK_FORMAT_R16G16B16_SFLOAT /* no GPU support,don't use */
|
||||
|
||||
#define FMT_RGBA16UN VK_FORMAT_R16G16B16A16_UNORM
|
||||
#define FMT_RGBA16SN VK_FORMAT_R16G16B16A16_SNORM
|
||||
@ -199,32 +197,32 @@ VK_NAMESPACE_BEGIN
|
||||
#define FMT_EAC_RG11UN VK_FORMAT_EAC_R11G11_UNORM_BLOCK
|
||||
#define FMT_EAC_RG11SN VK_FORMAT_EAC_R11G11_SNORM_BLOCK
|
||||
|
||||
#define FMT_ASTC_4x4UN VK_FORMAT_ASTC_4x4_UNORM_BLOCK
|
||||
#define FMT_ASTC_4x4s VK_FORMAT_ASTC_4x4_SRGB_BLOCK
|
||||
#define FMT_ASTC_5x4UN VK_FORMAT_ASTC_5x4_UNORM_BLOCK
|
||||
#define FMT_ASTC_5x4s VK_FORMAT_ASTC_5x4_SRGB_BLOCK
|
||||
#define FMT_ASTC_5x5UN VK_FORMAT_ASTC_5x5_UNORM_BLOCK
|
||||
#define FMT_ASTC_5x5s VK_FORMAT_ASTC_5x5_SRGB_BLOCK
|
||||
#define FMT_ASTC_6x5UN VK_FORMAT_ASTC_6x5_UNORM_BLOCK
|
||||
#define FMT_ASTC_6x5s VK_FORMAT_ASTC_6x5_SRGB_BLOCK
|
||||
#define FMT_ASTC_6x6UN VK_FORMAT_ASTC_6x6_UNORM_BLOCK
|
||||
#define FMT_ASTC_6x6s VK_FORMAT_ASTC_6x6_SRGB_BLOCK
|
||||
#define FMT_ASTC_8x5UN VK_FORMAT_ASTC_8x5_UNORM_BLOCK
|
||||
#define FMT_ASTC_8x5s VK_FORMAT_ASTC_8x5_SRGB_BLOCK
|
||||
#define FMT_ASTC_8x6UN VK_FORMAT_ASTC_8x6_UNORM_BLOCK
|
||||
#define FMT_ASTC_8x6s VK_FORMAT_ASTC_8x6_SRGB_BLOCK
|
||||
#define FMT_ASTC_8x8UN VK_FORMAT_ASTC_8x8_UNORM_BLOCK
|
||||
#define FMT_ASTC_8x8s VK_FORMAT_ASTC_8x8_SRGB_BLOCK
|
||||
#define FMT_ASTC_10x5UN VK_FORMAT_ASTC_10x5_UNORM_BLOCK
|
||||
#define FMT_ASTC_10x5s VK_FORMAT_ASTC_10x5_SRGB_BLOCK
|
||||
#define FMT_ASTC_10x6UN VK_FORMAT_ASTC_10x6_UNORM_BLOCK
|
||||
#define FMT_ASTC_10x6s VK_FORMAT_ASTC_10x6_SRGB_BLOCK
|
||||
#define FMT_ASTC_10x8UN VK_FORMAT_ASTC_10x8_UNORM_BLOCK
|
||||
#define FMT_ASTC_10x8s VK_FORMAT_ASTC_10x8_SRGB_BLOCK
|
||||
#define FMT_ASTC_4x4UN VK_FORMAT_ASTC_4x4_UNORM_BLOCK
|
||||
#define FMT_ASTC_4x4s VK_FORMAT_ASTC_4x4_SRGB_BLOCK
|
||||
#define FMT_ASTC_5x4UN VK_FORMAT_ASTC_5x4_UNORM_BLOCK
|
||||
#define FMT_ASTC_5x4s VK_FORMAT_ASTC_5x4_SRGB_BLOCK
|
||||
#define FMT_ASTC_5x5UN VK_FORMAT_ASTC_5x5_UNORM_BLOCK
|
||||
#define FMT_ASTC_5x5s VK_FORMAT_ASTC_5x5_SRGB_BLOCK
|
||||
#define FMT_ASTC_6x5UN VK_FORMAT_ASTC_6x5_UNORM_BLOCK
|
||||
#define FMT_ASTC_6x5s VK_FORMAT_ASTC_6x5_SRGB_BLOCK
|
||||
#define FMT_ASTC_6x6UN VK_FORMAT_ASTC_6x6_UNORM_BLOCK
|
||||
#define FMT_ASTC_6x6s VK_FORMAT_ASTC_6x6_SRGB_BLOCK
|
||||
#define FMT_ASTC_8x5UN VK_FORMAT_ASTC_8x5_UNORM_BLOCK
|
||||
#define FMT_ASTC_8x5s VK_FORMAT_ASTC_8x5_SRGB_BLOCK
|
||||
#define FMT_ASTC_8x6UN VK_FORMAT_ASTC_8x6_UNORM_BLOCK
|
||||
#define FMT_ASTC_8x6s VK_FORMAT_ASTC_8x6_SRGB_BLOCK
|
||||
#define FMT_ASTC_8x8UN VK_FORMAT_ASTC_8x8_UNORM_BLOCK
|
||||
#define FMT_ASTC_8x8s VK_FORMAT_ASTC_8x8_SRGB_BLOCK
|
||||
#define FMT_ASTC_10x5UN VK_FORMAT_ASTC_10x5_UNORM_BLOCK
|
||||
#define FMT_ASTC_10x5s VK_FORMAT_ASTC_10x5_SRGB_BLOCK
|
||||
#define FMT_ASTC_10x6UN VK_FORMAT_ASTC_10x6_UNORM_BLOCK
|
||||
#define FMT_ASTC_10x6s VK_FORMAT_ASTC_10x6_SRGB_BLOCK
|
||||
#define FMT_ASTC_10x8UN VK_FORMAT_ASTC_10x8_UNORM_BLOCK
|
||||
#define FMT_ASTC_10x8s VK_FORMAT_ASTC_10x8_SRGB_BLOCK
|
||||
#define FMT_ASTC_10x10UN VK_FORMAT_ASTC_10x10_UNORM_BLOCK
|
||||
#define FMT_ASTC_10x10s VK_FORMAT_ASTC_10x10_SRGB_BLOCK
|
||||
#define FMT_ASTC_10x10s VK_FORMAT_ASTC_10x10_SRGB_BLOCK
|
||||
#define FMT_ASTC_12x10UN VK_FORMAT_ASTC_12x10_UNORM_BLOCK
|
||||
#define FMT_ASTC_12x10s VK_FORMAT_ASTC_12x10_SRGB_BLOCK
|
||||
#define FMT_ASTC_12x10s VK_FORMAT_ASTC_12x10_SRGB_BLOCK
|
||||
#define FMT_ASTC_12x12UN VK_FORMAT_ASTC_12x12_UNORM_BLOCK
|
||||
#define FMT_ASTC_12x12s VK_FORMAT_ASTC_12x12_SRGB_BLOCK
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user