diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 3d7c33135..cae7d7049 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -45,6 +45,8 @@ AbstractTexture::ParameterfImplementation AbstractTexture::parameterfImplementat &AbstractTexture::parameterImplementationDefault; AbstractTexture::ParameterfvImplementation AbstractTexture::parameterfvImplementation = &AbstractTexture::parameterImplementationDefault; +AbstractTexture::SetMaxAnisotropyImplementation AbstractTexture::setMaxAnisotropyImplementation = + &AbstractTexture::setMaxAnisotropyImplementationNoOp; #ifndef MAGNUM_TARGET_GLES AbstractTexture::GetLevelParameterivImplementation AbstractTexture::getLevelParameterivImplementation = &AbstractTexture::getLevelParameterImplementationDefault; @@ -270,9 +272,13 @@ void AbstractTexture::initializeContextBasedFunctionality(Context& context) { storage3DImplementation = &AbstractTexture::storageImplementationDefault; } } - #else - static_cast(context); #endif + + if(context.isExtensionSupported()) { + Debug() << "AbstractTexture: using" << Extensions::GL::EXT::texture_filter_anisotropic::string() << "features"; + + setMaxAnisotropyImplementation = &AbstractTexture::setMaxAnisotropyImplementationExt; + } } ColorFormat AbstractTexture::imageFormatForInternalFormat(const TextureFormat internalFormat) { @@ -677,6 +683,12 @@ void AbstractTexture::parameterImplementationDSA(GLenum parameter, const GLfloat } #endif +void AbstractTexture::setMaxAnisotropyImplementationNoOp(GLfloat) {} + +void AbstractTexture::setMaxAnisotropyImplementationExt(GLfloat anisotropy) { + (this->*parameterfImplementation)(GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy); +} + #ifndef MAGNUM_TARGET_GLES void AbstractTexture::getLevelParameterImplementationDefault(GLenum target, GLint level, GLenum parameter, GLint* values) { bindInternal(); diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 95b4cd4b0..65fc80203 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -273,18 +273,18 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject { * @return Reference to self (for method chaining) * * Default value is `1.0f`, which means no anisotropy. Set to value - * greater than `1.0f` for anisotropic filtering. If - * @extension{EXT,direct_state_access} is not available, the texture - * is bound to some layer before the operation. + * greater than `1.0f` for anisotropic filtering. If extension + * @extension{EXT,texture_filter_anisotropic} (desktop or ES) is not + * available, this function does nothing. If + * @extension{EXT,direct_state_access} is not available, the texture is + * bound to some layer before the operation. * @see @ref Sampler::maxAnisotropy(), @fn_gl{ActiveTexture}, * @fn_gl{BindTexture} and @fn_gl{TexParameter} or * @fn_gl_extension{TextureParameter,EXT,direct_state_access} with * @def_gl{TEXTURE_MAX_ANISOTROPY_EXT} - * @requires_extension %Extension @extension{EXT,texture_filter_anisotropic} - * @requires_es_extension %Extension @es_extension2{EXT,texture_filter_anisotropic,texture_filter_anisotropic} */ AbstractTexture& setMaxAnisotropy(Float anisotropy) { - (this->*parameterfImplementation)(GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy); + (this->*setMaxAnisotropyImplementation)(anisotropy); return *this; } @@ -380,6 +380,11 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject { #endif static ParameterfvImplementation parameterfvImplementation; + typedef void(AbstractTexture::*SetMaxAnisotropyImplementation)(GLfloat); + void MAGNUM_LOCAL setMaxAnisotropyImplementationNoOp(GLfloat); + void MAGNUM_LOCAL setMaxAnisotropyImplementationExt(GLfloat anisotropy); + static SetMaxAnisotropyImplementation setMaxAnisotropyImplementation; + #ifndef MAGNUM_TARGET_GLES typedef void(AbstractTexture::*GetLevelParameterivImplementation)(GLenum, GLint, GLenum, GLint*); void MAGNUM_LOCAL getLevelParameterImplementationDefault(GLenum target, GLint level, GLenum parameter, GLint* values); diff --git a/src/Sampler.cpp b/src/Sampler.cpp index 15bfd75d0..7b8d44993 100644 --- a/src/Sampler.cpp +++ b/src/Sampler.cpp @@ -29,6 +29,7 @@ #include "Context.h" #include "Implementation/State.h" #include "Implementation/TextureState.h" +#include "Extensions.h" namespace Magnum { @@ -46,6 +47,9 @@ static_assert((filter_or(Nearest, Base) == GL_NEAREST) && #undef filter_or Float Sampler::maxAnisotropy() { + if(!Context::current()->isExtensionSupported()) + return 0.0f; + GLfloat& value = Context::current()->state().texture->maxAnisotropy; /** @todo Re-enable when extension header is available */ diff --git a/src/Sampler.h b/src/Sampler.h index 85360d4af..7ffcb055f 100644 --- a/src/Sampler.h +++ b/src/Sampler.h @@ -136,10 +136,9 @@ class MAGNUM_EXPORT Sampler { * @brief Max supported anisotropy * * The result is cached, repeated queries don't result in repeated - * OpenGL calls. + * OpenGL calls. If extension @extension{EXT,texture_filter_anisotropic} + * (desktop or ES) is not available, returns `0.0f`. * @see setMaxAnisotropy(), @fn_gl{Get} with @def_gl{MAX_TEXTURE_MAX_ANISOTROPY_EXT} - * @requires_extension %Extension @extension{EXT,texture_filter_anisotropic} - * @requires_es_extension %Extension @es_extension2{EXT,texture_filter_anisotropic,texture_filter_anisotropic} */ static Float maxAnisotropy();