From 956d12e5a8e6b38ad695439fc2abecd6d3bfc521 Mon Sep 17 00:00:00 2001 From: bkaradzic Date: Sat, 9 Jun 2012 19:42:25 -0700 Subject: [PATCH] Fixed GL compressed 3D texture. --- src/glimports.h | 1 + src/renderer_gl.cpp | 66 ++++++++++++++++++++++++++++----------------- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/glimports.h b/src/glimports.h index 2d85f355..5e59a30b 100644 --- a/src/glimports.h +++ b/src/glimports.h @@ -41,6 +41,7 @@ GL_IMPORT(false, PFNGLCLEARCOLORPROC, glClearColor); GL_IMPORT(false, PFNGLACTIVETEXTUREPROC, glActiveTexture); GL_IMPORT(false, PFNGLCOMPRESSEDTEXIMAGE2DPROC, glCompressedTexImage2D); +GL_IMPORT(false, PFNGLCOMPRESSEDTEXIMAGE3DPROC, glCompressedTexImage3D); GL_IMPORT(false, PFNGLBINDBUFFERPROC, glBindBuffer); GL_IMPORT(false, PFNGLDELETEBUFFERSPROC, glDeleteBuffers); GL_IMPORT(false, PFNGLGENBUFFERSPROC, glGenBuffers); diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 646bd314..6f259582 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -970,9 +970,12 @@ namespace bgfx void Texture::create(const Memory* _mem, uint32_t _flags) { Dds dds; + uint8_t numMips = 0; if (parseDds(dds, _mem) ) { + numMips = dds.m_numMips; + if (dds.m_cubeMap) { m_target = GL_TEXTURE_CUBE_MAP; @@ -992,27 +995,27 @@ namespace bgfx BX_CHECK(0 != m_id, "Failed to generate texture id."); GL_CHECK(glBindTexture(m_target, m_id) ); - GL_CHECK(glTexParameteri(m_target, GL_TEXTURE_MIN_FILTER, 1 < dds.m_numMips ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR) ); - const TextureFormatInfo& tfi = s_textureFormat[dds.m_type]; GLenum internalFmt = tfi.m_internalFmt; + GLenum fmt = tfi.m_format; + + GLenum target = m_target; + if (dds.m_cubeMap) + { + target = GL_TEXTURE_CUBE_MAP_POSITIVE_X; + } if (!s_renderCtx.m_dxtSupport || TextureFormat::Unknown < dds.m_type) { - if (internalFmt == GL_RGBA) + if (GL_RGBA == internalFmt) { internalFmt = s_extension[Extension::EXT_texture_format_BGRA8888].m_supported ? GL_BGRA_EXT : GL_RGBA; + fmt = internalFmt; } uint8_t* bits = (uint8_t*)g_realloc(NULL, dds.m_width*dds.m_height*tfi.m_bpp); - GLenum target = m_target; - if (dds.m_cubeMap) - { - target = GL_TEXTURE_CUBE_MAP_POSITIVE_X; - } - for (uint8_t side = 0, numSides = dds.m_cubeMap ? 6 : 1; side < numSides; ++side) { uint32_t width = dds.m_width; @@ -1050,7 +1053,6 @@ namespace bgfx #if BGFX_CONFIG_RENDERER_OPENGL if (target == GL_TEXTURE_3D) { - GL_CHECK(glTexImage3D(target , lod , internalFmt @@ -1058,7 +1060,7 @@ namespace bgfx , height , depth , 0 - , tfi.m_format + , fmt , tfi.m_type , bits ) ); @@ -1072,7 +1074,7 @@ namespace bgfx , width , height , 0 - , tfi.m_format + , fmt , tfi.m_type , bits ) ); @@ -1104,15 +1106,33 @@ namespace bgfx Mip mip; if (getRawImageData(dds, 0, ii, _mem, mip) ) { - GL_CHECK(glCompressedTexImage2D(m_target - , ii - , internalFmt - , width - , height - , 0 - , mip.m_size - , mip.m_data - ) ); +#if BGFX_CONFIG_RENDERER_OPENGL + if (m_target == GL_TEXTURE_3D) + { + GL_CHECK(glCompressedTexImage3D(target + , ii + , internalFmt + , width + , height + , depth + , 0 + , mip.m_size + , mip.m_data + ) ); + } + else +#endif // BGFX_CONFIG_RENDERER_OPENGL + { + GL_CHECK(glCompressedTexImage2D(target+side + , ii + , internalFmt + , width + , height + , 0 + , mip.m_size + , mip.m_data + ) ); + } } width >>= 1; @@ -1146,13 +1166,10 @@ namespace bgfx uint8_t bpp; stream.read(bpp); - uint8_t numMips; stream.read(numMips); stream.align(16); - GL_CHECK(glTexParameteri(m_target, GL_TEXTURE_MIN_FILTER, 1 < numMips ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR) ); - for (uint8_t mip = 0; mip < numMips; ++mip) { width = uint32_max(width, 1); @@ -1194,6 +1211,7 @@ namespace bgfx GL_CHECK(glTexParameteri(m_target, GL_TEXTURE_MIN_FILTER, s_textureFilter[(_flags&BGFX_TEXTURE_MIN_MASK)>>BGFX_TEXTURE_MIN_SHIFT]) ); GL_CHECK(glTexParameteri(m_target, GL_TEXTURE_MAG_FILTER, s_textureFilter[(_flags&BGFX_TEXTURE_MAG_MASK)>>BGFX_TEXTURE_MAG_SHIFT]) ); + GL_CHECK(glTexParameteri(m_target, GL_TEXTURE_MIN_FILTER, 1 < numMips ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR) ); GL_CHECK(glBindTexture(m_target, 0) ); }