support B10GR11UF format

This commit is contained in:
hyzboy 2019-12-04 20:47:58 +08:00
parent bbf1007ce5
commit 55029b0742
4 changed files with 36 additions and 5 deletions

View File

@ -47,10 +47,10 @@ bool ToILType(ILuint &type,const uint8 bits,const ColorDataType cdt)
{
constexpr ILuint target_type[3][(uint)ColorDataType::END-1]=
{
//UNORM SNORM UINT SINT, USCALE,SSCALE, UFLOAT SFLOAT
{IL_UNSIGNED_BYTE, IL_BYTE, IL_UNSIGNED_BYTE, IL_BYTE, 0,0, 0, 0},
{IL_UNSIGNED_SHORT, IL_SHORT, IL_UNSIGNED_SHORT, IL_SHORT, 0,0, IL_HALF, IL_HALF},
{IL_UNSIGNED_INT, IL_INT, IL_UNSIGNED_INT, IL_INT, 0,0, IL_FLOAT, IL_FLOAT}
//UNORM SNORM UINT SINT, USCALE,SSCALE, UFLOAT SFLOAT
/* 8 */{IL_UNSIGNED_BYTE, IL_BYTE, IL_UNSIGNED_BYTE, IL_BYTE, 0,0, 0, 0},
/* 16 */{IL_UNSIGNED_SHORT, IL_SHORT, IL_UNSIGNED_SHORT, IL_SHORT, 0,0, IL_HALF, IL_HALF},
/* 32 */{IL_UNSIGNED_INT, IL_INT, IL_UNSIGNED_INT, IL_INT, 0,0, IL_FLOAT, IL_FLOAT}
};
if(bits<=8 )type=target_type[0][(uint)cdt-1];else

View File

@ -21,6 +21,25 @@ public:
}
}
// Bit depth Sign bit present Exponent bits Mantissa bits
// 32 Yes 8 23
// 16 Yes 5 10
// 11 No 5 6
// 10 No 5 5
void RGB16FtoB10GR11UF(uint32 *target,uint16 *src,uint size)
{
for(uint i=0;i<size;i++)
{
*target=((src[2]&0x7FE0)<<17)
|((src[1]&0x7FF0)<<7)
| (src[0]&0x7FF0)>>4;
++target;
src+=3;
}
}
public:
bool Write() override
@ -48,6 +67,16 @@ public:
return TextureFileCreater::Write(rgb565);
}
else if(fmt->format==ColorFormat::B10GR11UF)
{
void *origin_rgb=image->GetRGB(IL_HALF);
AutoDelete<uint32> b10gr11=new uint32[image->pixel_total()];
RGB16FtoB10GR11UF(b10gr11,(uint16 *)origin_rgb,image->pixel_total());
return TextureFileCreater::Write(b10gr11);
}
else
{
LOG_ERROR(OS_TEXT("Don't support this RGB format"));

View File

@ -46,7 +46,8 @@ namespace hgl
{ColorFormat::RGB32F, "RGB32F", 3,{'R','G','B', 0 },{32,32,32, 0},ColorDataType::SFLOAT},
{ColorFormat::RGBA32U, "RGBA32U", 4,{'R','G','B','A'},{32,32,32,32},ColorDataType::UINT},
{ColorFormat::RGBA32I, "RGBA32I", 4,{'R','G','B','A'},{32,32,32,32},ColorDataType::SINT},
{ColorFormat::RGBA32F, "RGBA32F", 4,{'R','G','B','A'},{32,32,32,32},ColorDataType::SFLOAT}
{ColorFormat::RGBA32F, "RGBA32F", 4,{'R','G','B','A'},{32,32,32,32},ColorDataType::SFLOAT},
{ColorFormat::B10GR11UF, "B10GR11UF", 3,{'B','G','R', 0 },{11,11,11, 0},ColorDataType::UFLOAT}
};
constexpr uint PixelFormatCount=sizeof(pf_list)/sizeof(PixelFormat);

View File

@ -33,6 +33,7 @@ enum class ColorFormat
RGBA32U,
RGBA32I,
RGBA32F,
B10GR11UF,
END
};//enum class ColorFormat