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š 11 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 #ifndef MAGNUM_TARGET_GLES
Int AbstractTexture::compressedBlockDataSize(const GLenum target, const TextureFormat format) { 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; GLint value;
glGetInternalformativ(target, GLenum(format), GL_TEXTURE_COMPRESSED_BLOCK_SIZE, 1, &value); glGetInternalformativ(target, GLenum(format), GL_TEXTURE_COMPRESSED_BLOCK_SIZE, 1, &value);
return 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 #endif
AbstractTexture::AbstractTexture(GLenum target): _target{target}, _flags{ObjectFlag::DeleteOnDestruction} { 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; GLenum _target;
private: 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); static void MAGNUM_LOCAL unbindImplementationDefault(GLint textureUnit);
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
static void MAGNUM_LOCAL unbindImplementationMulti(GLint textureUnit); 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; setMaxAnisotropyImplementation = &AbstractTexture::setMaxAnisotropyImplementationExt;
} else setMaxAnisotropyImplementation = &AbstractTexture::setMaxAnisotropyImplementationNoOp; } 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 */ /* Resize bindings array to hold all possible texture units */
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits); glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
CORRADE_INTERNAL_ASSERT(maxTextureUnits > 0); CORRADE_INTERNAL_ASSERT(maxTextureUnits > 0);

1
src/Magnum/Implementation/TextureState.h

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

4
src/Magnum/Implementation/driverSpecific.cpp

@ -52,6 +52,10 @@ namespace {
newer GLSL version. */ newer GLSL version. */
"no-layout-qualifiers-on-old-glsl", "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 /* NVidia drivers (358.16) report different compressed image size for
cubemaps based on whether the texture is immutable or not and not 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 based on whether I'm querying all faces (ARB_DSA) or a single face

Loading…
Cancel
Save