mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
Fixed GL compressed 3D texture.
This commit is contained in:
parent
fe1252d260
commit
956d12e5a8
2 changed files with 43 additions and 24 deletions
|
@ -41,6 +41,7 @@ GL_IMPORT(false, PFNGLCLEARCOLORPROC, glClearColor);
|
||||||
|
|
||||||
GL_IMPORT(false, PFNGLACTIVETEXTUREPROC, glActiveTexture);
|
GL_IMPORT(false, PFNGLACTIVETEXTUREPROC, glActiveTexture);
|
||||||
GL_IMPORT(false, PFNGLCOMPRESSEDTEXIMAGE2DPROC, glCompressedTexImage2D);
|
GL_IMPORT(false, PFNGLCOMPRESSEDTEXIMAGE2DPROC, glCompressedTexImage2D);
|
||||||
|
GL_IMPORT(false, PFNGLCOMPRESSEDTEXIMAGE3DPROC, glCompressedTexImage3D);
|
||||||
GL_IMPORT(false, PFNGLBINDBUFFERPROC, glBindBuffer);
|
GL_IMPORT(false, PFNGLBINDBUFFERPROC, glBindBuffer);
|
||||||
GL_IMPORT(false, PFNGLDELETEBUFFERSPROC, glDeleteBuffers);
|
GL_IMPORT(false, PFNGLDELETEBUFFERSPROC, glDeleteBuffers);
|
||||||
GL_IMPORT(false, PFNGLGENBUFFERSPROC, glGenBuffers);
|
GL_IMPORT(false, PFNGLGENBUFFERSPROC, glGenBuffers);
|
||||||
|
|
|
@ -970,9 +970,12 @@ namespace bgfx
|
||||||
void Texture::create(const Memory* _mem, uint32_t _flags)
|
void Texture::create(const Memory* _mem, uint32_t _flags)
|
||||||
{
|
{
|
||||||
Dds dds;
|
Dds dds;
|
||||||
|
uint8_t numMips = 0;
|
||||||
|
|
||||||
if (parseDds(dds, _mem) )
|
if (parseDds(dds, _mem) )
|
||||||
{
|
{
|
||||||
|
numMips = dds.m_numMips;
|
||||||
|
|
||||||
if (dds.m_cubeMap)
|
if (dds.m_cubeMap)
|
||||||
{
|
{
|
||||||
m_target = GL_TEXTURE_CUBE_MAP;
|
m_target = GL_TEXTURE_CUBE_MAP;
|
||||||
|
@ -992,20 +995,9 @@ namespace bgfx
|
||||||
BX_CHECK(0 != m_id, "Failed to generate texture id.");
|
BX_CHECK(0 != m_id, "Failed to generate texture id.");
|
||||||
GL_CHECK(glBindTexture(m_target, m_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];
|
const TextureFormatInfo& tfi = s_textureFormat[dds.m_type];
|
||||||
GLenum internalFmt = tfi.m_internalFmt;
|
GLenum internalFmt = tfi.m_internalFmt;
|
||||||
|
GLenum fmt = tfi.m_format;
|
||||||
if (!s_renderCtx.m_dxtSupport
|
|
||||||
|| TextureFormat::Unknown < dds.m_type)
|
|
||||||
{
|
|
||||||
if (internalFmt == GL_RGBA)
|
|
||||||
{
|
|
||||||
internalFmt = s_extension[Extension::EXT_texture_format_BGRA8888].m_supported ? GL_BGRA_EXT : GL_RGBA;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t* bits = (uint8_t*)g_realloc(NULL, dds.m_width*dds.m_height*tfi.m_bpp);
|
|
||||||
|
|
||||||
GLenum target = m_target;
|
GLenum target = m_target;
|
||||||
if (dds.m_cubeMap)
|
if (dds.m_cubeMap)
|
||||||
|
@ -1013,6 +1005,17 @@ namespace bgfx
|
||||||
target = GL_TEXTURE_CUBE_MAP_POSITIVE_X;
|
target = GL_TEXTURE_CUBE_MAP_POSITIVE_X;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!s_renderCtx.m_dxtSupport
|
||||||
|
|| TextureFormat::Unknown < dds.m_type)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
for (uint8_t side = 0, numSides = dds.m_cubeMap ? 6 : 1; side < numSides; ++side)
|
for (uint8_t side = 0, numSides = dds.m_cubeMap ? 6 : 1; side < numSides; ++side)
|
||||||
{
|
{
|
||||||
uint32_t width = dds.m_width;
|
uint32_t width = dds.m_width;
|
||||||
|
@ -1050,7 +1053,6 @@ namespace bgfx
|
||||||
#if BGFX_CONFIG_RENDERER_OPENGL
|
#if BGFX_CONFIG_RENDERER_OPENGL
|
||||||
if (target == GL_TEXTURE_3D)
|
if (target == GL_TEXTURE_3D)
|
||||||
{
|
{
|
||||||
|
|
||||||
GL_CHECK(glTexImage3D(target
|
GL_CHECK(glTexImage3D(target
|
||||||
, lod
|
, lod
|
||||||
, internalFmt
|
, internalFmt
|
||||||
|
@ -1058,7 +1060,7 @@ namespace bgfx
|
||||||
, height
|
, height
|
||||||
, depth
|
, depth
|
||||||
, 0
|
, 0
|
||||||
, tfi.m_format
|
, fmt
|
||||||
, tfi.m_type
|
, tfi.m_type
|
||||||
, bits
|
, bits
|
||||||
) );
|
) );
|
||||||
|
@ -1072,7 +1074,7 @@ namespace bgfx
|
||||||
, width
|
, width
|
||||||
, height
|
, height
|
||||||
, 0
|
, 0
|
||||||
, tfi.m_format
|
, fmt
|
||||||
, tfi.m_type
|
, tfi.m_type
|
||||||
, bits
|
, bits
|
||||||
) );
|
) );
|
||||||
|
@ -1104,7 +1106,24 @@ namespace bgfx
|
||||||
Mip mip;
|
Mip mip;
|
||||||
if (getRawImageData(dds, 0, ii, _mem, mip) )
|
if (getRawImageData(dds, 0, ii, _mem, mip) )
|
||||||
{
|
{
|
||||||
GL_CHECK(glCompressedTexImage2D(m_target
|
#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
|
, ii
|
||||||
, internalFmt
|
, internalFmt
|
||||||
, width
|
, width
|
||||||
|
@ -1114,6 +1133,7 @@ namespace bgfx
|
||||||
, mip.m_data
|
, mip.m_data
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
width >>= 1;
|
width >>= 1;
|
||||||
height >>= 1;
|
height >>= 1;
|
||||||
|
@ -1146,13 +1166,10 @@ namespace bgfx
|
||||||
uint8_t bpp;
|
uint8_t bpp;
|
||||||
stream.read(bpp);
|
stream.read(bpp);
|
||||||
|
|
||||||
uint8_t numMips;
|
|
||||||
stream.read(numMips);
|
stream.read(numMips);
|
||||||
|
|
||||||
stream.align(16);
|
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)
|
for (uint8_t mip = 0; mip < numMips; ++mip)
|
||||||
{
|
{
|
||||||
width = uint32_max(width, 1);
|
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_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_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) );
|
GL_CHECK(glBindTexture(m_target, 0) );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue