Merge branch 'dev'

This commit is contained in:
Branimir Karadžić 2015-04-11 00:23:29 -07:00
commit 23f4c82b1a
6 changed files with 85 additions and 63 deletions

View file

@ -311,14 +311,13 @@ namespace
const bgfx::Memory* mem = NULL;
if (NULL != _rgba)
{
mem = bgfx::alloc(tex->height * pitch);
bgfx::imageSwizzleBgra8(tex->width, tex->height, pitch, _rgba, mem->data);
mem = bgfx::copy(_rgba, tex->height * pitch);
}
tex->id = bgfx::createTexture2D(tex->width
, tex->height
, 1
, NVG_TEXTURE_RGBA == _type ? bgfx::TextureFormat::BGRA8 : bgfx::TextureFormat::R8
, NVG_TEXTURE_RGBA == _type ? bgfx::TextureFormat::RGBA8 : bgfx::TextureFormat::R8
, BGFX_TEXTURE_NONE
, mem
);

View file

@ -922,6 +922,8 @@ namespace bgfx
TextureFormat::ETC2A1,
TextureFormat::PTC14,
TextureFormat::PTC14A,
TextureFormat::BGRA8, // GL doesn't support BGRA8 without extensions.
TextureFormat::RGBA8, // D3D9 doesn't support RGBA8
};
void Context::init(RendererType::Enum _type)

View file

@ -2126,6 +2126,10 @@ namespace bgfx
imageSwizzleBgra8(_width, _height, _pitch, _src, _dst);
break;
case TextureFormat::BGRA8:
memcpy(_dst, _src, _pitch*_height);
break;
default:
// Decompression not implemented... Make ugly red-yellow checkerboard texture.
imageCheckerboard(_width, _height, 16, UINT32_C(0xffff0000), UINT32_C(0xffffff00), _dst);
@ -2133,6 +2137,25 @@ namespace bgfx
}
}
void imageDecodeToRgba8(uint8_t* _dst, const uint8_t* _src, uint32_t _width, uint32_t _height, uint32_t _pitch, uint8_t _type)
{
switch (_type)
{
case TextureFormat::RGBA8:
memcpy(_dst, _src, _pitch*_height);
break;
case TextureFormat::BGRA8:
imageSwizzleBgra8(_width, _height, _pitch, _src, _dst);
break;
default:
imageDecodeToBgra8(_dst, _src, _width, _height, _pitch, _type);
imageSwizzleBgra8(_width, _height, _pitch, _dst, _dst);
break;
}
}
bool imageGetRawData(const ImageContainer& _imageContainer, uint8_t _side, uint8_t _lod, const void* _data, uint32_t _size, ImageMip& _mip)
{
uint32_t offset = _imageContainer.m_offset;

View file

@ -92,7 +92,10 @@ namespace bgfx
bool imageParse(ImageContainer& _imageContainer, const void* _data, uint32_t _size);
///
void imageDecodeToBgra8(uint8_t* _dst, const uint8_t* _src, uint32_t _width, uint32_t _height, uint32_t _srcPitch, uint8_t _type);
void imageDecodeToBgra8(uint8_t* _dst, const uint8_t* _src, uint32_t _width, uint32_t _height, uint32_t _pitch, uint8_t _type);
///
void imageDecodeToRgba8(uint8_t* _dst, const uint8_t* _src, uint32_t _width, uint32_t _height, uint32_t _pitch, uint8_t _type);
///
bool imageGetRawData(const ImageContainer& _dds, uint8_t _side, uint8_t _index, const void* _data, uint32_t _size, ImageMip& _mip);

View file

@ -219,7 +219,7 @@ namespace bgfx { namespace d3d9
{ D3DFMT_UNKNOWN }, // RG32
{ D3DFMT_G32R32F }, // RG32F
{ D3DFMT_A8R8G8B8 }, // BGRA8
{ D3DFMT_A8R8G8B8 }, // RGBA8
{ D3DFMT_UNKNOWN }, // RGBA8
{ D3DFMT_A16B16G16R16 }, // RGBA16
{ D3DFMT_A16B16G16R16F }, // RGBA16F
{ D3DFMT_UNKNOWN }, // RGBA32

View file

@ -202,30 +202,30 @@ namespace bgfx { namespace gl
{ GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_ZERO, false }, // PTC14A
{ GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_ZERO, false }, // PTC22
{ GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_ZERO, false }, // PTC24
{ GL_ZERO, GL_ZERO, GL_ZERO, true }, // Unknown
{ GL_ZERO, GL_ZERO, GL_ZERO, true }, // R1
{ GL_R8, GL_RED, GL_UNSIGNED_BYTE, true }, // R8
{ GL_R16, GL_RED, GL_UNSIGNED_SHORT, true }, // R16
{ GL_R16F, GL_RED, GL_HALF_FLOAT, true }, // R16F
{ GL_R32UI, GL_RED, GL_UNSIGNED_INT, true }, // R32
{ GL_R32F, GL_RED, GL_FLOAT, true }, // R32F
{ GL_RG8, GL_RG, GL_UNSIGNED_BYTE, true }, // RG8
{ GL_RG16, GL_RG, GL_UNSIGNED_SHORT, true }, // RG16
{ GL_RG16F, GL_RG, GL_FLOAT, true }, // RG16F
{ GL_RG32UI, GL_RG, GL_UNSIGNED_INT, true }, // RG32
{ GL_RG32F, GL_RG, GL_FLOAT, true }, // RG32F
{ GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, true }, // BGRA8
{ GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, true }, // RGBA8
{ GL_RGBA16, GL_RGBA, GL_UNSIGNED_BYTE, true }, // RGBA16
{ GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, true }, // RGBA16F
{ GL_RGBA32UI, GL_RGBA, GL_UNSIGNED_INT, true }, // RGBA32
{ GL_RGBA32F, GL_RGBA, GL_FLOAT, true }, // RGBA32F
{ GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, true }, // R5G6B5
{ GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, true }, // RGBA4
{ GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, true }, // RGB5A1
{ GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, true }, // RGB10A2
{ GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, true }, // R11G11B10F
{ GL_ZERO, GL_ZERO, GL_ZERO, true }, // UnknownDepth
{ GL_ZERO, GL_ZERO, GL_ZERO, false }, // Unknown
{ GL_ZERO, GL_ZERO, GL_ZERO, false }, // R1
{ GL_R8, GL_RED, GL_UNSIGNED_BYTE, false }, // R8
{ GL_R16, GL_RED, GL_UNSIGNED_SHORT, false }, // R16
{ GL_R16F, GL_RED, GL_HALF_FLOAT, false }, // R16F
{ GL_R32UI, GL_RED, GL_UNSIGNED_INT, false }, // R32
{ GL_R32F, GL_RED, GL_FLOAT, false }, // R32F
{ GL_RG8, GL_RG, GL_UNSIGNED_BYTE, false }, // RG8
{ GL_RG16, GL_RG, GL_UNSIGNED_SHORT, false }, // RG16
{ GL_RG16F, GL_RG, GL_FLOAT, false }, // RG16F
{ GL_RG32UI, GL_RG, GL_UNSIGNED_INT, false }, // RG32
{ GL_RG32F, GL_RG, GL_FLOAT, false }, // RG32F
{ GL_BGRA, GL_RGBA, GL_UNSIGNED_BYTE, false }, // BGRA8
{ GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, false }, // RGBA8
{ GL_RGBA16, GL_RGBA, GL_UNSIGNED_BYTE, false }, // RGBA16
{ GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, false }, // RGBA16F
{ GL_RGBA32UI, GL_RGBA, GL_UNSIGNED_INT, false }, // RGBA32
{ GL_RGBA32F, GL_RGBA, GL_FLOAT, false }, // RGBA32F
{ GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, false }, // R5G6B5
{ GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, false }, // RGBA4
{ GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, false }, // RGB5A1
{ GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, false }, // RGB10A2
{ GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, false }, // R11G11B10F
{ GL_ZERO, GL_ZERO, GL_ZERO, false }, // UnknownDepth
{ GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, false }, // D16
{ GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, false }, // D24
{ GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, false }, // D24S8
@ -1303,7 +1303,7 @@ namespace bgfx { namespace gl
if (!isTextureFormatValid(TextureFormat::BGRA8) )
{
// Revert back to RGBA if texture can't be created.
setTextureFormat(TextureFormat::BGRA8, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
setTextureFormat(TextureFormat::BGRA8, GL_BGRA, GL_BGRA, GL_UNSIGNED_BYTE);
}
}
@ -3321,21 +3321,21 @@ namespace bgfx { namespace gl
m_type = tfi.m_type;
const bool compressed = isCompressed(TextureFormat::Enum(_format) );
const bool decompress = !tfi.m_supported && compressed;
const bool convert = !tfi.m_supported;
if (decompress)
if (convert)
{
m_textureFormat = (uint8_t)TextureFormat::BGRA8;
const TextureFormatInfo& tfiBgra8 = s_textureFormat[TextureFormat::BGRA8];
m_fmt = tfiBgra8.m_fmt;
m_type = tfiBgra8.m_type;
m_textureFormat = (uint8_t)TextureFormat::RGBA8;
const TextureFormatInfo& tfiRgba8 = s_textureFormat[TextureFormat::RGBA8];
m_fmt = tfiRgba8.m_fmt;
m_type = tfiRgba8.m_type;
}
setSamplerState(_flags);
if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL)
&& TextureFormat::BGRA8 == m_textureFormat
&& GL_RGBA == m_fmt
&& TextureFormat::BGRA8 == m_requestedFormat
&& !s_textureFormat[m_requestedFormat].m_supported
&& s_renderGL->m_textureSwizzleSupport)
{
GLint swizzleMask[] = { GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA };
@ -3429,12 +3429,15 @@ namespace bgfx { namespace gl
const GLenum internalFmt = s_textureFormat[m_textureFormat].m_internalFmt;
const bool swizzle = true
&& TextureFormat::BGRA8 == m_textureFormat
&& GL_RGBA == m_fmt
&& TextureFormat::BGRA8 == m_requestedFormat
&& !s_textureFormat[m_requestedFormat].m_supported
&& !s_renderGL->m_textureSwizzleSupport
;
const bool convert = m_textureFormat != m_requestedFormat;
const bool compressed = isCompressed(TextureFormat::Enum(m_textureFormat) );
const bool compressed = isCompressed(TextureFormat::Enum(m_requestedFormat) );
const bool convert = false
|| (compressed && m_textureFormat != m_requestedFormat)
|| swizzle
;
uint32_t blockWidth = 1;
uint32_t blockHeight = 1;
@ -3455,7 +3458,7 @@ namespace bgfx { namespace gl
, 0 != (m_flags&BGFX_TEXTURE_RT_MASK) ? " (render target)" : ""
);
BX_WARN(!swizzle && !convert, "Texture %s%s%s from %s to %s."
BX_WARN(!convert, "Texture %s%s%s from %s to %s."
, swizzle ? "swizzle" : ""
, swizzle&&convert ? " and " : ""
, convert ? "convert" : ""
@ -3464,7 +3467,7 @@ namespace bgfx { namespace gl
);
uint8_t* temp = NULL;
if (convert || swizzle)
if (convert)
{
temp = (uint8_t*)BX_ALLOC(g_allocator, textureWidth*textureHeight*4);
}
@ -3503,13 +3506,7 @@ namespace bgfx { namespace gl
if (convert)
{
imageDecodeToBgra8(temp, mip.m_data, mip.m_width, mip.m_height, mip.m_width*4, mip.m_format);
data = temp;
}
if (swizzle)
{
imageSwizzleBgra8(width, height, mip.m_width*4, data, temp);
imageDecodeToRgba8(temp, mip.m_data, mip.m_width, mip.m_height, mip.m_width*4, mip.m_format);
data = temp;
}
@ -3607,20 +3604,22 @@ namespace bgfx { namespace gl
GLenum target = GL_TEXTURE_CUBE_MAP == m_target ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : m_target;
const bool swizzle = true
&& TextureFormat::BGRA8 == m_textureFormat
&& GL_RGBA == m_fmt
&& TextureFormat::BGRA8 == m_requestedFormat
&& !s_textureFormat[m_requestedFormat].m_supported
&& !s_renderGL->m_textureSwizzleSupport
;
const bool unpackRowLength = BX_IGNORE_C4127(!!BGFX_CONFIG_RENDERER_OPENGL || s_extension[Extension::EXT_unpack_subimage].m_supported);
const bool convert = m_textureFormat != m_requestedFormat;
const bool compressed = isCompressed(TextureFormat::Enum(m_textureFormat) );
const bool compressed = isCompressed(TextureFormat::Enum(m_requestedFormat) );
const bool convert = false
|| (compressed && m_textureFormat != m_requestedFormat)
|| swizzle
;
const uint32_t width = _rect.m_width;
const uint32_t height = _rect.m_height;
uint8_t* temp = NULL;
if (convert
|| swizzle
|| !unpackRowLength)
{
temp = (uint8_t*)BX_ALLOC(g_allocator, rectpitch*height);
@ -3659,17 +3658,13 @@ namespace bgfx { namespace gl
if (convert)
{
imageDecodeToBgra8(temp, data, width, height, srcpitch, m_requestedFormat);
imageDecodeToRgba8(temp, data, width, height, srcpitch, m_requestedFormat);
data = temp;
srcpitch = rectpitch;
}
if (swizzle)
{
imageSwizzleBgra8(width, height, srcpitch, data, temp);
data = temp;
}
else if (!unpackRowLength && !convert)
if (!unpackRowLength
&& !convert)
{
imageCopy(width, height, bpp, srcpitch, data, temp);
data = temp;