GL: When using ARB_texture_swizzle don't swizzle image to BGRA8.

This commit is contained in:
bkaradzic 2013-09-08 23:03:14 -07:00
parent e97cf77c41
commit 983f1e6f9a
4 changed files with 31 additions and 19 deletions

View File

@ -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.

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;