From 983f1e6f9acb27adf4cd0d171e1e802b880a24e6 Mon Sep 17 00:00:00 2001 From: bkaradzic Date: Sun, 8 Sep 2013 23:03:14 -0700 Subject: [PATCH] GL: When using ARB_texture_swizzle don't swizzle image to BGRA8. --- examples/06-bump/bump.cpp | 2 +- examples/08-update/update.cpp | 42 ++++++++++++++++++++++------------- src/image.cpp | 2 +- src/renderer_gl.cpp | 4 ++-- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/examples/06-bump/bump.cpp b/examples/06-bump/bump.cpp index 5af2241fc..e4310bffd 100644 --- a/examples/06-bump/bump.cpp +++ b/examples/06-bump/bump.cpp @@ -338,7 +338,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::destroyFragmentShader(fsh); // Load diffuse texture. - mem = loadTexture("fieldstone-rgba.dds"); + mem = loadTexture("texture_compression_ptc22.pvr"); //fieldstone-rgba.dds"); bgfx::TextureHandle textureColor = bgfx::createTexture(mem); // Load normal texture. diff --git a/examples/08-update/update.cpp b/examples/08-update/update.cpp index f17c81233..dce4e8d31 100644 --- a/examples/08-update/update.cpp +++ b/examples/08-update/update.cpp @@ -123,6 +123,25 @@ static const bgfx::Memory* loadShader(const char* _name) return load(filePath); } +static void updateTextureCubeRectBgra8(bgfx::TextureHandle _handle, uint8_t _side, uint32_t _x, uint32_t _y, uint32_t _width, uint32_t _height, uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a = 0xff) +{ + bgfx::TextureInfo ti; + bgfx::calcTextureSize(ti, _width, _height, 1, 1, bgfx::TextureFormat::BGRA8); + + const bgfx::Memory* mem = bgfx::alloc(ti.storageSize); + uint8_t* data = (uint8_t*)mem->data; + for (uint32_t ii = 0, num = ti.storageSize*8/ti.bitsPerPixel; ii < num; ++ii) + { + data[0] = _b; + data[1] = _g; + data[2] = _r; + data[3] = _a; + data += 4; + } + + bgfx::updateTextureCube(_handle, _side, 0, _x, _y, _width, _height, mem); +} + int _main_(int /*_argc*/, char** /*_argv*/) { uint32_t width = 1280; @@ -214,6 +233,13 @@ int _main_(int /*_argc*/, char** /*_argv*/) , BGFX_TEXTURE_MIN_POINT|BGFX_TEXTURE_MAG_POINT|BGFX_TEXTURE_MIP_POINT ); + updateTextureCubeRectBgra8(textureCube, 0, 0, 0, textureSide, textureSide, 0xff, 0, 0); + updateTextureCubeRectBgra8(textureCube, 1, 0, 0, textureSide, textureSide, 0xff, 0, 0); + updateTextureCubeRectBgra8(textureCube, 2, 0, 0, textureSide, textureSide, 0xff, 0, 0); + updateTextureCubeRectBgra8(textureCube, 3, 0, 0, textureSide, textureSide, 0xff, 0, 0); + updateTextureCubeRectBgra8(textureCube, 4, 0, 0, textureSide, textureSide, 0xff, 0, 0); + updateTextureCubeRectBgra8(textureCube, 5, 0, 0, textureSide, textureSide, 0xff, 0, 0); + uint8_t rr = rand()%255; uint8_t gg = rand()%255; uint8_t bb = rand()%255; @@ -263,23 +289,9 @@ int _main_(int /*_argc*/, char** /*_argv*/) quads.push_back(face); ++hit; - bgfx::TextureInfo ti; const Pack2D& rect = face.m_rect; - bgfx::calcTextureSize(ti, rect.m_width, rect.m_height, 1, 1, bgfx::TextureFormat::BGRA8); -// updateTime = now + freq/10; - const bgfx::Memory* mem = bgfx::alloc(ti.storageSize); - uint8_t* data = (uint8_t*)mem->data; - for (uint32_t ii = 0, num = ti.storageSize*8/ti.bitsPerPixel; ii < num; ++ii) - { - data[0] = bb; - data[1] = rr; - data[2] = gg; - data[3] = 0xff; - data += 4; - } - - bgfx::updateTextureCube(textureCube, face.m_side, 0, rect.m_x, rect.m_y, rect.m_width, rect.m_height, mem); + updateTextureCubeRectBgra8(textureCube, face.m_side, rect.m_x, rect.m_y, rect.m_width, rect.m_height, 0, 0xff, 0); rr = rand()%255; gg = rand()%255; diff --git a/src/image.cpp b/src/image.cpp index 7d75f4cc8..f76dd8599 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -1221,7 +1221,7 @@ namespace bgfx default: // Decompression not implemented... Make ugly red-yellow checkerboard texture. - imageCheckerboard(_width, _height, 16, UINT32_C(0xff0000ff), UINT32_C(0xff00ffff), _dst); + imageCheckerboard(_width, _height, 16, UINT32_C(0xffff0000), UINT32_C(0xffffff00), _dst); break; } } diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index d55019da2..c7bea0b03 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -1450,7 +1450,7 @@ namespace bgfx const GLenum internalFmt = s_textureFormat[m_textureFormat].m_internalFmt; - const bool swizzle = GL_RGBA == internalFmt; + const bool swizzle = GL_RGBA == internalFmt && !s_renderCtx.m_textureSwizzleSupport; const bool convert = m_textureFormat != m_requestedFormat; const bool compressed = TextureFormat::Unknown > m_textureFormat; const uint32_t min = convert && compressed ? 4 : 1; @@ -1660,7 +1660,7 @@ namespace bgfx GLenum target = GL_TEXTURE_CUBE_MAP == m_target ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : m_target; - const bool swizzle = GL_RGBA == m_fmt; + const bool swizzle = GL_RGBA == m_fmt && !s_renderCtx.m_textureSwizzleSupport; const bool convert = m_textureFormat != m_requestedFormat; const bool compressed = TextureFormat::Unknown > m_textureFormat;