Browse Source

Added workaround for NVidia reporting compressed block size in bits.

Instead of bytes as per specification of glGetInternalformativ().
pull/132/head
Vladimír Vondruš 10 years ago
parent
commit
d5dae1a211
  1. 9
      src/Magnum/AbstractTexture.cpp
  2. 5
      src/Magnum/AbstractTexture.h
  3. 9
      src/Magnum/Implementation/TextureState.cpp
  4. 1
      src/Magnum/Implementation/TextureState.h
  5. 4
      src/Magnum/Implementation/driverSpecific.cpp

9
src/Magnum/AbstractTexture.cpp

@ -199,10 +199,19 @@ void AbstractTexture::bindImplementationMulti(const GLint firstTextureUnit, Cont
#ifndef MAGNUM_TARGET_GLES
Int AbstractTexture::compressedBlockDataSize(const GLenum target, const TextureFormat format) {
return (Context::current()->state().texture->compressedBlockDataSizeImplementation)(target, format);
}
Int AbstractTexture::compressedBlockDataSizeImplementationDefault(const GLenum target, const TextureFormat format) {
GLint value;
glGetInternalformativ(target, GLenum(format), GL_TEXTURE_COMPRESSED_BLOCK_SIZE, 1, &value);
return value;
}
Int AbstractTexture::compressedBlockDataSizeImplementationBitsWorkaround(const GLenum target, const TextureFormat format) {
/* NVidia (358.16) reports the value in bits instead of bytes */
return compressedBlockDataSizeImplementationDefault(target, format)/8;
}
#endif
AbstractTexture::AbstractTexture(GLenum target): _target{target}, _flags{ObjectFlag::DeleteOnDestruction} {

5
src/Magnum/AbstractTexture.h

@ -416,6 +416,11 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject {
GLenum _target;
private:
#ifndef MAGNUM_TARGET_GLES
static Int MAGNUM_LOCAL compressedBlockDataSizeImplementationDefault(GLenum target, TextureFormat format);
static Int MAGNUM_LOCAL compressedBlockDataSizeImplementationBitsWorkaround(GLenum target, TextureFormat format);
#endif
static void MAGNUM_LOCAL unbindImplementationDefault(GLint textureUnit);
#ifndef MAGNUM_TARGET_GLES
static void MAGNUM_LOCAL unbindImplementationMulti(GLint textureUnit);

9
src/Magnum/Implementation/TextureState.cpp

@ -374,6 +374,15 @@ TextureState::TextureState(Context& context, std::vector<std::string>& extension
setMaxAnisotropyImplementation = &AbstractTexture::setMaxAnisotropyImplementationExt;
} else setMaxAnisotropyImplementation = &AbstractTexture::setMaxAnisotropyImplementationNoOp;
#ifndef MAGNUM_TARGET_GLES
/* NVidia workaround for compressed block data size implementation */
if((context.detectedDriver() & Context::DetectedDriver::NVidia) &&
!context.isDriverWorkaroundDisabled("nv-compressed-block-size-in-bits"))
compressedBlockDataSizeImplementation = &AbstractTexture::compressedBlockDataSizeImplementationBitsWorkaround;
else
compressedBlockDataSizeImplementation = &AbstractTexture::compressedBlockDataSizeImplementationDefault;
#endif
/* Resize bindings array to hold all possible texture units */
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
CORRADE_INTERNAL_ASSERT(maxTextureUnits > 0);

1
src/Magnum/Implementation/TextureState.h

@ -45,6 +45,7 @@ struct TextureState {
void reset();
Int(*compressedBlockDataSizeImplementation)(GLenum, TextureFormat);
void(*unbindImplementation)(GLint);
void(*bindMultiImplementation)(GLint, Containers::ArrayView<AbstractTexture* const>);
void(AbstractTexture::*createImplementation)();

4
src/Magnum/Implementation/driverSpecific.cpp

@ -52,6 +52,10 @@ namespace {
newer GLSL version. */
"no-layout-qualifiers-on-old-glsl",
/* NVidia drivers (358.16) report compressed block size from internal
format query in bits instead of bytes */
"nv-compressed-block-size-in-bits",
/* NVidia drivers (358.16) report different compressed image size for
cubemaps based on whether the texture is immutable or not and not
based on whether I'm querying all faces (ARB_DSA) or a single face

Loading…
Cancel
Save