Added support for RGB8* formats.

This commit is contained in:
Branimir Karadžić 2016-02-24 15:51:51 -08:00
parent 6ef7724d40
commit 5a87bb0ffe
8 changed files with 145 additions and 12 deletions

View File

@ -200,6 +200,10 @@ namespace bgfx
RG32I,
RG32U,
RG32F,
RGB8,
RGB8I,
RGB8U,
RGB8S,
RGB9E5F,
BGRA8,
RGBA8,

View File

@ -149,6 +149,10 @@ typedef enum bgfx_texture_format
BGFX_TEXTURE_FORMAT_RG32I,
BGFX_TEXTURE_FORMAT_RG32U,
BGFX_TEXTURE_FORMAT_RG32F,
BGFX_TEXTURE_FORMAT_RGB8,
BGFX_TEXTURE_FORMAT_RGB8I,
BGFX_TEXTURE_FORMAT_RGB8U,
BGFX_TEXTURE_FORMAT_RGB8S,
BGFX_TEXTURE_FORMAT_RGB9E5F,
BGFX_TEXTURE_FORMAT_BGRA8,
BGFX_TEXTURE_FORMAT_RGBA8,

View File

@ -64,6 +64,10 @@ namespace bgfx
{ 64, 1, 1, 8, 1, 1, 0, 0, uint8_t(EncodingType::Int ) }, // RG32I
{ 64, 1, 1, 8, 1, 1, 0, 0, uint8_t(EncodingType::Uint ) }, // RG32U
{ 64, 1, 1, 8, 1, 1, 0, 0, uint8_t(EncodingType::Float) }, // RG32F
{ 24, 1, 1, 3, 1, 1, 0, 0, uint8_t(EncodingType::Unorm) }, // RGB8
{ 24, 1, 1, 3, 1, 1, 0, 0, uint8_t(EncodingType::Int ) }, // RGB8I
{ 24, 1, 1, 3, 1, 1, 0, 0, uint8_t(EncodingType::Uint ) }, // RGB8U
{ 24, 1, 1, 3, 1, 1, 0, 0, uint8_t(EncodingType::Snorm) }, // RGB8S
{ 32, 1, 1, 4, 1, 1, 0, 0, uint8_t(EncodingType::Float) }, // RGB9E5F
{ 32, 1, 1, 4, 1, 1, 0, 0, uint8_t(EncodingType::Unorm) }, // BGRA8
{ 32, 1, 1, 4, 1, 1, 0, 0, uint8_t(EncodingType::Unorm) }, // RGBA8
@ -141,6 +145,10 @@ namespace bgfx
"RG32I", // RG32I
"RG32U", // RG32U
"RG32F", // RG32F
"RGB8", // RGB8
"RGB8I", // RGB8I
"RGB8U", // RGB8U
"RGB8S", // RGB8S
"RGB9E5", // RGB9E5F
"BGRA8", // BGRA8
"RGBA8", // RGBA8
@ -717,23 +725,72 @@ namespace bgfx
_dst[1] = float(src[1]);
}
// RGBA8
void packRgba8(void* _dst, const float* _src)
// RGB8
void packRgb8(void* _dst, const float* _src)
{
uint8_t* dst = (uint8_t*)_dst;
dst[0] = uint8_t(toUnorm(_src[0], 255.0f) );
dst[1] = uint8_t(toUnorm(_src[1], 255.0f) );
dst[2] = uint8_t(toUnorm(_src[2], 255.0f) );
dst[3] = uint8_t(toUnorm(_src[3], 255.0f) );
}
void unpackRgba8(float* _dst, const void* _src)
void unpackRgb8(float* _dst, const void* _src)
{
const uint8_t* src = (const uint8_t*)_src;
_dst[0] = fromUnorm(src[0], 255.0f);
_dst[1] = fromUnorm(src[1], 255.0f);
_dst[2] = fromUnorm(src[2], 255.0f);
_dst[3] = fromUnorm(src[3], 255.0f);
}
// RGB8S
void packRgb8S(void* _dst, const float* _src)
{
int8_t* dst = (int8_t*)_dst;
dst[0] = int8_t(toSnorm(_src[0], 127.0f) );
dst[1] = int8_t(toSnorm(_src[1], 127.0f) );
dst[2] = int8_t(toSnorm(_src[2], 127.0f) );
}
void unpackRgb8S(float* _dst, const void* _src)
{
const int8_t* src = (const int8_t*)_src;
_dst[0] = fromSnorm(src[0], 127.0f);
_dst[1] = fromSnorm(src[1], 127.0f);
_dst[2] = fromSnorm(src[2], 127.0f);
}
// RGB8I
void packRgb8I(void* _dst, const float* _src)
{
int8_t* dst = (int8_t*)_dst;
dst[0] = int8_t(_src[0]);
dst[1] = int8_t(_src[1]);
dst[2] = int8_t(_src[2]);
}
void unpackRgb8I(float* _dst, const void* _src)
{
const int8_t* src = (const int8_t*)_src;
_dst[0] = float(src[0]);
_dst[1] = float(src[1]);
_dst[2] = float(src[2]);
}
// RGB8U
void packRgb8U(void* _dst, const float* _src)
{
uint8_t* dst = (uint8_t*)_dst;
dst[0] = uint8_t(_src[0]);
dst[1] = uint8_t(_src[1]);
dst[2] = uint8_t(_src[2]);
}
void unpackRgb8U(float* _dst, const void* _src)
{
const uint8_t* src = (const uint8_t*)_src;
_dst[0] = float(src[0]);
_dst[1] = float(src[1]);
_dst[2] = float(src[2]);
}
// BGRA8
@ -755,6 +812,25 @@ namespace bgfx
_dst[3] = fromUnorm(src[3], 255.0f);
}
// RGBA8
void packRgba8(void* _dst, const float* _src)
{
uint8_t* dst = (uint8_t*)_dst;
dst[0] = uint8_t(toUnorm(_src[0], 255.0f) );
dst[1] = uint8_t(toUnorm(_src[1], 255.0f) );
dst[2] = uint8_t(toUnorm(_src[2], 255.0f) );
dst[3] = uint8_t(toUnorm(_src[3], 255.0f) );
}
void unpackRgba8(float* _dst, const void* _src)
{
const uint8_t* src = (const uint8_t*)_src;
_dst[0] = fromUnorm(src[0], 255.0f);
_dst[1] = fromUnorm(src[1], 255.0f);
_dst[2] = fromUnorm(src[2], 255.0f);
_dst[3] = fromUnorm(src[3], 255.0f);
}
// RGBA8S
void packRgba8S(void* _dst, const float* _src)
{
@ -1402,6 +1478,10 @@ namespace bgfx
{ packRg32I, unpackRg32I }, // RG32I
{ packRg32U, unpackRg32U }, // RG32U
{ packRg32F, unpackRg32F }, // RG32F
{ packRgb8, unpackRgb8 }, // RGB8
{ packRgb8S, unpackRgb8S }, // RGB8S
{ packRgb8I, unpackRgb8I }, // RGB8I
{ packRgb8U, unpackRgb8U }, // RGB8U
{ packRgb9E5F, unpackRgb9E5F }, // RGB9E5F
{ packBgra8, unpackBgra8 }, // BGRA8
{ packRgba8, unpackRgba8 }, // RGBA8
@ -1457,15 +1537,14 @@ namespace bgfx
}
}
void imageConvert(void* _dst, uint32_t _dstBpp, PackFn _pack, const void* _src, uint32_t _srcBpp, UnpackFn _unpack, uint32_t _width, uint32_t _height)
void imageConvert(void* _dst, uint32_t _dstBpp, PackFn _pack, const void* _src, uint32_t _srcBpp, UnpackFn _unpack, uint32_t _width, uint32_t _height, uint32_t _srcPitch)
{
const uint8_t* src = (uint8_t*)_src;
uint8_t* dst = (uint8_t*)_dst;
const uint32_t srcPitch = _width * _srcBpp / 8;
const uint32_t dstPitch = _width * _dstBpp / 8;
for (uint32_t yy = 0; yy < _height; ++yy, src += srcPitch, dst += dstPitch)
for (uint32_t yy = 0; yy < _height; ++yy, src += _srcPitch, dst += dstPitch)
{
for (uint32_t xx = 0; xx < _width; ++xx)
{
@ -1476,7 +1555,7 @@ namespace bgfx
}
}
bool imageConvert(void* _dst, TextureFormat::Enum _dstFormat, const void* _src, TextureFormat::Enum _srcFormat, uint32_t _width, uint32_t _height)
bool imageConvert(void* _dst, TextureFormat::Enum _dstFormat, const void* _src, TextureFormat::Enum _srcFormat, uint32_t _width, uint32_t _height, uint32_t _srcPitch)
{
UnpackFn unpack = s_packUnpack[_srcFormat].unpack;
PackFn pack = s_packUnpack[_dstFormat].pack;
@ -1488,7 +1567,7 @@ namespace bgfx
const uint32_t srcBpp = s_imageBlockInfo[_srcFormat].bitsPerPixel;
const uint32_t dstBpp = s_imageBlockInfo[_dstFormat].bitsPerPixel;
imageConvert(_dst, dstBpp, pack, _src, srcBpp, unpack, _width, _height);
imageConvert(_dst, dstBpp, pack, _src, srcBpp, unpack, _width, _height, _srcPitch);
return true;
}
@ -2739,6 +2818,7 @@ namespace bgfx
#define KTX_RG16_SNORM 0x8F99
#define KTX_RGB16_SNORM 0x8F9A
#define KTX_RGBA16_SNORM 0x8F9B
#define KTX_SRGB8 0x8C41
#define KTX_SRGB8_ALPHA8 0x8C43
#define KTX_RGBA32UI 0x8D70
#define KTX_RGB32UI 0x8D71
@ -2751,6 +2831,7 @@ namespace bgfx
#define KTX_RGBA16I 0x8D88
#define KTX_RGB16I 0x8D89
#define KTX_RGBA8I 0x8D8E
#define KTX_RGB8 0x8051
#define KTX_RGB8I 0x8D8F
#define KTX_RGB9_E5 0x8C3D
#define KTX_R11F_G11F_B10F 0x8C3A
@ -2832,6 +2913,10 @@ namespace bgfx
{ KTX_RG32I, KTX_ZERO, KTX_RG, KTX_INT, }, // RG32I
{ KTX_RG32UI, KTX_ZERO, KTX_RG, KTX_UNSIGNED_INT, }, // RG32U
{ KTX_RG32F, KTX_ZERO, KTX_RG, KTX_FLOAT, }, // RG32F
{ KTX_RGB8, KTX_SRGB8, KTX_RGB, KTX_UNSIGNED_BYTE, }, // RGB8
{ KTX_RGB8I, KTX_ZERO, KTX_RGB, KTX_BYTE, }, // RGB8I
{ KTX_RGB8UI, KTX_ZERO, KTX_RGB, KTX_UNSIGNED_BYTE, }, // RGB8U
{ KTX_RGB8_SNORM, KTX_ZERO, KTX_RGB, KTX_BYTE, }, // RGB8S
{ KTX_RGB9_E5, KTX_ZERO, KTX_RGB, KTX_UNSIGNED_INT_5_9_9_9_REV, }, // RGB9E5F
{ KTX_BGRA, KTX_SRGB8_ALPHA8, KTX_BGRA, KTX_UNSIGNED_BYTE, }, // BGRA8
{ KTX_RGBA8, KTX_SRGB8_ALPHA8, KTX_RGBA, KTX_UNSIGNED_BYTE, }, // RGBA8
@ -3343,7 +3428,7 @@ namespace bgfx
break;
default:
if (!imageConvert(_dst, TextureFormat::BGRA8, _src, _format, _width, _height) )
if (!imageConvert(_dst, TextureFormat::BGRA8, _src, _format, _width, _height, _pitch) )
{
// Failed to convert, just make ugly red-yellow checkerboard texture.
imageCheckerboard(_width, _height, 16, UINT32_C(0xffff0000), UINT32_C(0xffffff00), _dst);

View File

@ -101,6 +101,22 @@ namespace bgfx
void packRg8U(void* _dst, const float* _src);
void unpackRg8U(float* _dst, const void* _src);
// RGB8
void packRgb8(void* _dst, const float* _src);
void unpackRgb8(float* _dst, const void* _src);
// RGB8S
void packRgb8S(void* _dst, const float* _src);
void unpackRgb8S(float* _dst, const void* _src);
// RGB8I
void packRgb8I(void* _dst, const float* _src);
void unpackRgb8I(float* _dst, const void* _src);
// RGB8U
void packRgb8U(void* _dst, const float* _src);
void unpackRgb8U(float* _dst, const void* _src);
// RGBA8
void packRgba8(void* _dst, const float* _src);
void unpackRgba8(float* _dst, const void* _src);
@ -307,7 +323,7 @@ namespace bgfx
void imageConvert(void* _dst, uint32_t _bpp, PackFn _pack, const void* _src, UnpackFn _unpack, uint32_t _size);
///
void imageConvert(void* _dst, uint32_t _dstBpp, PackFn _pack, const void* _src, uint32_t _srcBpp, UnpackFn _unpack, uint32_t _width, uint32_t _height);
void imageConvert(void* _dst, uint32_t _dstBpp, PackFn _pack, const void* _src, uint32_t _srcBpp, UnpackFn _unpack, uint32_t _width, uint32_t _height, uint32_t _srcPitch);
///
bool imageConvert(void* _dst, TextureFormat::Enum _dstFormat, const void* _src, TextureFormat::Enum _srcFormat, uint32_t _width, uint32_t _height);

View File

@ -259,6 +259,10 @@ namespace bgfx { namespace d3d11
{ DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG32I
{ DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG32U
{ DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG32F
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB8
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB8I
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB8U
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB8S
{ DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB9E5F
{ DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_B8G8R8A8_UNORM_SRGB }, // BGRA8
{ DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB }, // RGBA8

View File

@ -221,6 +221,10 @@ namespace bgfx { namespace d3d12
{ DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG32I
{ DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG32U
{ DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG32F
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB8
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB8I
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB8U
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB8S
{ DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB9E5F
{ DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_B8G8R8A8_UNORM_SRGB }, // BGRA8
{ DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB }, // RGBA8

View File

@ -215,6 +215,10 @@ namespace bgfx { namespace d3d9
{ D3DFMT_UNKNOWN }, // RG32I
{ D3DFMT_UNKNOWN }, // RG32U
{ D3DFMT_G32R32F }, // RG32F
{ D3DFMT_UNKNOWN }, // RGB8
{ D3DFMT_UNKNOWN }, // RGB8I
{ D3DFMT_UNKNOWN }, // RGB8U
{ D3DFMT_UNKNOWN }, // RGB8S
{ D3DFMT_UNKNOWN }, // RGB9E5F
{ D3DFMT_A8R8G8B8 }, // BGRA8
{ D3DFMT_UNKNOWN }, // RGBA8

View File

@ -246,6 +246,10 @@ namespace bgfx { namespace gl
{ GL_RG32I, GL_ZERO, GL_RG, GL_INT, false }, // RG32I
{ GL_RG32UI, GL_ZERO, GL_RG, GL_UNSIGNED_INT, false }, // RG32U
{ GL_RG32F, GL_ZERO, GL_RG, GL_FLOAT, false }, // RG32F
{ GL_RGB8, GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE, }, // RGB8
{ GL_RGB8I, GL_ZERO, GL_RGB, GL_BYTE, }, // RGB8I
{ GL_RGB8UI, GL_ZERO, GL_RGB, GL_UNSIGNED_BYTE, }, // RGB8U
{ GL_RGB8_SNORM, GL_ZERO, GL_RGB, GL_BYTE, }, // RGB8S
{ GL_RGB9_E5, GL_ZERO, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, false }, // RGB9E5F
{ GL_RGBA8, GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE, false }, // BGRA8
{ GL_RGBA8, GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, false }, // RGBA8
@ -325,6 +329,10 @@ namespace bgfx { namespace gl
GL_RG32I, // RG32I
GL_RG32UI, // RG32U
GL_RG32F, // RG32F
GL_RGB8, // RGB8
GL_RGB8I, // RGB8I
GL_RGB8UI, // RGB8UI
GL_RGB8_SNORM, // RGB8S
GL_RGB9_E5, // RGB9E5F
GL_RGBA8, // BGRA8
GL_RGBA8, // RGBA8
@ -402,6 +410,10 @@ namespace bgfx { namespace gl
GL_RG32I, // RG32I
GL_RG32UI, // RG32U
GL_RG32F, // RG32F
GL_RGB8, // RGB8
GL_RGB8I, // RGB8I
GL_RGB8UI, // RGB8UI
GL_RGB8_SNORM, // RGB8S
GL_RGB9_E5, // RGB9E5F
GL_RGBA8, // BGRA8
GL_RGBA8, // RGBA8