Browse Source

Added no-op fallback for unsupported EXT_texture_filter_anisotropic.

This extension is ubiquitous, but to make users' life even easier we
now provide no-op fallback for both Sampler::maxAnisotropy() and
Texture::setMaxAnisotropy().
pull/51/head
Vladimír Vondruš 13 years ago
parent
commit
1f15ac1d92
  1. 16
      src/AbstractTexture.cpp
  2. 17
      src/AbstractTexture.h
  3. 4
      src/Sampler.cpp
  4. 5
      src/Sampler.h

16
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<void>(context);
#endif
if(context.isExtensionSupported<Extensions::GL::EXT::texture_filter_anisotropic>()) {
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();

17
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);

4
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<Extensions::GL::EXT::texture_filter_anisotropic>())
return 0.0f;
GLfloat& value = Context::current()->state().texture->maxAnisotropy;
/** @todo Re-enable when extension header is available */

5
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();

Loading…
Cancel
Save