Browse Source

Moved sampler state enums into new Sampler class.

Solves another trivial choice (similar to the one with TextureFormat
etc. in 7de45c98b1), less typing and also
preparation for ARB_sampler_objects extension.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
a49d973cb0
  1. 39
      src/AbstractTexture.cpp
  2. 125
      src/AbstractTexture.h
  3. 2
      src/CMakeLists.txt
  4. 8
      src/CubeMapTexture.h
  5. 8
      src/CubeMapTextureArray.h
  6. 1
      src/Magnum.h
  7. 61
      src/Sampler.cpp
  8. 139
      src/Sampler.h
  9. 6
      src/Text/DistanceFieldGlyphCache.cpp
  10. 6
      src/Text/GlyphCache.cpp
  11. 24
      src/Texture.h

39
src/AbstractTexture.cpp

@ -78,39 +78,10 @@ AbstractTexture::SubImage3DImplementation AbstractTexture::subImage3DImplementat
AbstractTexture::InvalidateImageImplementation AbstractTexture::invalidateImageImplementation = &AbstractTexture::invalidateImageImplementationNoOp;
AbstractTexture::InvalidateSubImageImplementation AbstractTexture::invalidateSubImageImplementation = &AbstractTexture::invalidateSubImageImplementationNoOp;
/* Check correctness of binary OR in setMinificationFilter(). If nobody fucks
anything up, this assert should produce the same results on all dimensions,
thus testing only on AbstractTexture. */
#define filter_or(filter, mipmap) \
(static_cast<GLint>(AbstractTexture::Filter::filter)|static_cast<GLint>(AbstractTexture::Mipmap::mipmap))
static_assert((filter_or(Nearest, Base) == GL_NEAREST) &&
(filter_or(Nearest, Nearest) == GL_NEAREST_MIPMAP_NEAREST) &&
(filter_or(Nearest, Linear) == GL_NEAREST_MIPMAP_LINEAR) &&
(filter_or(Linear, Base) == GL_LINEAR) &&
(filter_or(Linear, Nearest) == GL_LINEAR_MIPMAP_NEAREST) &&
(filter_or(Linear, Linear) == GL_LINEAR_MIPMAP_LINEAR),
"Unsupported constants for GL texture filtering");
#undef filter_or
Int AbstractTexture::maxSupportedLayerCount() {
return Context::current()->state()->texture->maxSupportedLayerCount;
}
#ifndef MAGNUM_TARGET_GLES3
Float AbstractTexture::maxSupportedAnisotropy() {
GLfloat& value = Context::current()->state()->texture->maxSupportedAnisotropy;
/** @todo Re-enable when extension header is available */
#ifndef MAGNUM_TARGET_GLES
/* Get the value, if not already cached */
if(value == 0.0f)
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &value);
#endif
return value;
}
#endif
void AbstractTexture::destroy() {
/* Moved out */
if(!_id) return;
@ -168,9 +139,9 @@ void AbstractTexture::bindImplementationDSA(GLint layer) {
}
#endif
AbstractTexture* AbstractTexture::setMinificationFilter(Filter filter, Mipmap mipmap) {
AbstractTexture* AbstractTexture::setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap) {
#ifndef MAGNUM_TARGET_GLES
CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE || mipmap == Mipmap::Base, "AbstractTexture: rectangle textures cannot have mipmaps", this);
CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE || mipmap == Sampler::Mipmap::Base, "AbstractTexture: rectangle textures cannot have mipmaps", this);
#endif
(this->*parameteriImplementation)(GL_TEXTURE_MIN_FILTER,
@ -562,16 +533,16 @@ Vector3i AbstractTexture::DataHelper<3>::imageSize(AbstractTexture* texture, GLe
}
#endif
void AbstractTexture::DataHelper<2>::setWrapping(AbstractTexture* texture, const Array2D<Wrapping>& wrapping) {
void AbstractTexture::DataHelper<2>::setWrapping(AbstractTexture* texture, const Array2D<Sampler::Wrapping>& wrapping) {
#ifndef MAGNUM_TARGET_GLES
CORRADE_ASSERT(texture->_target != GL_TEXTURE_RECTANGLE || ((wrapping.x() == Wrapping::ClampToEdge || wrapping.x() == Wrapping::ClampToBorder) && (wrapping.y() == Wrapping::ClampToEdge || wrapping.y() == Wrapping::ClampToEdge)), "AbstractTexture: rectangle texture wrapping must either clamp to border or to edge", );
CORRADE_ASSERT(texture->_target != GL_TEXTURE_RECTANGLE || ((wrapping.x() == Sampler::Wrapping::ClampToEdge || wrapping.x() == Sampler::Wrapping::ClampToBorder) && (wrapping.y() == Sampler::Wrapping::ClampToEdge || wrapping.y() == Sampler::Wrapping::ClampToEdge)), "AbstractTexture: rectangle texture wrapping must either clamp to border or to edge", );
#endif
(texture->*parameteriImplementation)(GL_TEXTURE_WRAP_S, static_cast<GLint>(wrapping.x()));
(texture->*parameteriImplementation)(GL_TEXTURE_WRAP_T, static_cast<GLint>(wrapping.y()));
}
void AbstractTexture::DataHelper<3>::setWrapping(AbstractTexture* texture, const Array3D<Wrapping>& wrapping) {
void AbstractTexture::DataHelper<3>::setWrapping(AbstractTexture* texture, const Array3D<Sampler::Wrapping>& wrapping) {
(texture->*parameteriImplementation)(GL_TEXTURE_WRAP_S, static_cast<GLint>(wrapping.x()));
(texture->*parameteriImplementation)(GL_TEXTURE_WRAP_T, static_cast<GLint>(wrapping.y()));
#ifndef MAGNUM_TARGET_GLES

125
src/AbstractTexture.h

@ -31,10 +31,9 @@
#include "Array.h"
#ifndef MAGNUM_TARGET_GLES2
#include "Buffer.h"
#else
#include "OpenGL.h"
#endif
#include "Color.h"
#include "Sampler.h"
namespace Magnum {
@ -93,86 +92,6 @@ class MAGNUM_EXPORT AbstractTexture {
AbstractTexture& operator=(const AbstractTexture&) = delete;
public:
/**
* @brief %Texture filtering
*
* @see setMagnificationFilter() and setMinificationFilter()
*/
enum class Filter: GLint {
Nearest = GL_NEAREST, /**< Nearest neighbor filtering */
/**
* Linear interpolation filtering.
* @requires_gles30 %Extension @es_extension{OES,texture_float_linear} /
* @es_extension2{OES,texture_half_float_linear,OES_texture_float_linear}
* for linear interpolation of textures with
* @ref Magnum::TextureFormat "TextureFormat::HalfFloat" /
* @ref Magnum::TextureFormat "TextureFormat::Float" in OpenGL
* ES 2.0.
*/
Linear = GL_LINEAR
};
/**
* @brief Mip level selection
*
* @see setMinificationFilter()
*/
enum class Mipmap: GLint {
Base = GL_NEAREST & ~GL_NEAREST, /**< Select base mip level */
/**
* Select nearest mip level. **Unavailable on rectangle textures.**
*/
Nearest = GL_NEAREST_MIPMAP_NEAREST & ~GL_NEAREST,
/**
* Linear interpolation of nearest mip levels. **Unavailable on
* rectangle textures.**
* @requires_gles30 %Extension @es_extension{OES,texture_float_linear} /
* @es_extension2{OES,texture_half_float_linear,OES_texture_float_linear}
* for linear interpolation of textures with
* @ref Magnum::TextureFormat "TextureFormat::HalfFloat" /
* @ref Magnum::TextureFormat "TextureFormat::Float" in OpenGL
* ES 2.0.
*/
Linear = GL_NEAREST_MIPMAP_LINEAR & ~GL_NEAREST
};
/**
* @brief %Texture wrapping
*
* @see @ref Texture::setWrapping() "setWrapping()"
*/
enum class Wrapping: GLint {
/** Repeat texture. **Unavailable on rectangle textures.** */
Repeat = GL_REPEAT,
/**
* Repeat mirrored texture. **Unavailable on rectangle textures.**
*/
MirroredRepeat = GL_MIRRORED_REPEAT,
/**
* Clamp to edge. Coordinates out of the range will be clamped to
* first / last column / row in given direction.
*/
ClampToEdge = GL_CLAMP_TO_EDGE,
#ifndef MAGNUM_TARGET_GLES3
/**
* Clamp to border color. Coordinates out of range will be clamped
* to border color (set with setBorderColor()).
* @requires_es_extension %Extension @es_extension{NV,texture_border_clamp}
*/
#ifndef MAGNUM_TARGET_GLES
ClampToBorder = GL_CLAMP_TO_BORDER
#else
ClampToBorder = GL_CLAMP_TO_BORDER_NV
#endif
#endif
};
/**
* @brief Max supported layer count
*
@ -184,19 +103,6 @@ class MAGNUM_EXPORT AbstractTexture {
*/
static Int maxSupportedLayerCount();
#ifndef MAGNUM_TARGET_GLES3
/**
* @brief Max supported anisotropy
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls.
* @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 maxSupportedAnisotropy();
#endif
#ifndef DOXYGEN_GENERATING_OUTPUT
inline explicit AbstractTexture(GLenum target): _target(target) {
glGenTextures(1, &_id);
@ -244,17 +150,16 @@ class MAGNUM_EXPORT AbstractTexture {
* Sets filter used when the object pixel size is smaller than the
* texture size. If @extension{EXT,direct_state_access} is not
* available, the texture is bound to some layer before the operation.
* Initial value is (@ref AbstractTexture::Filter "Filter::Nearest",
* @ref AbstractTexture::Mipmap "Mipmap::Linear").
* Initial value is (@ref Sampler::Filter "Sampler::Filter::Nearest",
* @ref Sampler::Mipmap "Sampler::Mipmap::Linear").
* @attention For rectangle textures only some modes are supported,
* see @ref AbstractTexture::Filter "Filter" and
* @ref AbstractTexture::Mipmap "Mipmap" documentation for more
* information.
* see @ref Sampler::Filter "Sampler::Filter" and @ref Sampler::Mipmap "Sampler::Mipmap"
* documentation for more information.
* @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexParameter}
* or @fn_gl_extension{TextureParameter,EXT,direct_state_access}
* with @def_gl{TEXTURE_MIN_FILTER}
*/
AbstractTexture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::Base);
AbstractTexture* setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap = Sampler::Mipmap::Base);
/**
* @brief Set magnification filter
@ -264,12 +169,12 @@ class MAGNUM_EXPORT AbstractTexture {
* Sets filter used when the object pixel size is larger than largest
* texture size. If @extension{EXT,direct_state_access} is not
* available, the texture is bound to some layer before the operation.
* Initial value is @ref AbstractTexture::Filter "Filter::Linear".
* Initial value is @ref Sampler::Filter "Sampler::Filter::Linear".
* @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexParameter}
* or @fn_gl_extension{TextureParameter,EXT,direct_state_access}
* with @def_gl{TEXTURE_MAG_FILTER}
*/
inline AbstractTexture* setMagnificationFilter(Filter filter) {
inline AbstractTexture* setMagnificationFilter(Sampler::Filter filter) {
(this->*parameteriImplementation)(GL_TEXTURE_MAG_FILTER, static_cast<GLint>(filter));
return this;
}
@ -279,10 +184,10 @@ class MAGNUM_EXPORT AbstractTexture {
* @brief Set border color
* @return Pointer to self (for method chaining)
*
* Border color when @ref AbstractTexture::Wrapping "wrapping" is set
* to `ClampToBorder`. If @extension{EXT,direct_state_access} is not
* available, the texture is bound to some layer before the operation.
* Initial value is `{0.0f, 0.0f, 0.0f, 0.0f}`.
* Border color when wrapping is set to @ref Sampler::Wrapping "Sampler::Wrapping::ClampToBorder".
* If @extension{EXT,direct_state_access} is not available, the texture
* is bound to some layer before the operation. Initial value is
* `{0.0f, 0.0f, 0.0f, 0.0f}`.
* @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexParameter}
* or @fn_gl_extension{TextureParameter,EXT,direct_state_access}
* with @def_gl{TEXTURE_BORDER_COLOR}
@ -526,7 +431,7 @@ template<> struct AbstractTexture::DataHelper<1> {
static Math::Vector<1, GLint> imageSize(AbstractTexture* texture, GLenum target, GLint level);
inline static void setWrapping(AbstractTexture* texture, const Array1D<Wrapping>& wrapping) {
inline static void setWrapping(AbstractTexture* texture, const Array1D<Sampler::Wrapping>& wrapping) {
(texture->*parameteriImplementation)(GL_TEXTURE_WRAP_S, static_cast<GLint>(wrapping.x()));
}
@ -563,7 +468,7 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> {
static Vector2i imageSize(AbstractTexture* texture, GLenum target, GLint level);
#endif
static void setWrapping(AbstractTexture* texture, const Array2D<Wrapping>& wrapping);
static void setWrapping(AbstractTexture* texture, const Array2D<Sampler::Wrapping>& wrapping);
inline static void setStorage(AbstractTexture* texture, GLenum target, GLsizei levels, TextureFormat internalFormat, const Vector2i& size) {
(texture->*storage2DImplementation)(target, levels, internalFormat, size);
@ -601,7 +506,7 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> {
static Vector3i imageSize(AbstractTexture* texture, GLenum target, GLint level);
#endif
static void setWrapping(AbstractTexture* texture, const Array3D<Wrapping>& wrapping);
static void setWrapping(AbstractTexture* texture, const Array3D<Sampler::Wrapping>& wrapping);
inline static void setStorage(AbstractTexture* texture, GLenum target, GLsizei levels, TextureFormat internalFormat, const Vector3i& size) {
(texture->*storage3DImplementation)(target, levels, internalFormat, size);

2
src/CMakeLists.txt

@ -63,6 +63,7 @@ set(Magnum_SRCS
Renderbuffer.cpp
Renderer.cpp
Resource.cpp
Sampler.cpp
Shader.cpp
Timeline.cpp
@ -122,6 +123,7 @@ set(Magnum_HEADERS
Renderer.h
Resource.h
ResourceManager.h
Sampler.h
Shader.h
Swizzle.h
Texture.h

8
src/CubeMapTexture.h

@ -58,7 +58,7 @@ Image2D positiveX({256, 256}, ImageFormat::RGBA, ImageType::UnsignedByte, dataPo
// ...
CubeMapTexture texture;
texture.setMagnificationFilter(Texture2D::Filter::Linear)
texture.setMagnificationFilter(Sampler::Filter::Linear)
// ...
->setStorage(Math::log2(256)+1, TextureFormat::RGBA8, {256, 256})
->setSubImage(CubeMapTexture::Coordinate::PositiveX, 0, {}, &positiveX)
@ -100,7 +100,7 @@ class CubeMapTexture: public AbstractTexture {
*
* See Texture::setWrapping() for more information.
*/
inline CubeMapTexture* setWrapping(const Array3D<Wrapping>& wrapping) {
inline CubeMapTexture* setWrapping(const Array3D<Sampler::Wrapping>& wrapping) {
DataHelper<3>::setWrapping(this, wrapping);
return this;
}
@ -209,11 +209,11 @@ class CubeMapTexture: public AbstractTexture {
/* Overloads to remove WTF-factor from method chaining order */
#ifndef DOXYGEN_GENERATING_OUTPUT
inline CubeMapTexture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::Base) {
inline CubeMapTexture* setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap = Sampler::Mipmap::Base) {
AbstractTexture::setMinificationFilter(filter, mipmap);
return this;
}
inline CubeMapTexture* setMagnificationFilter(Filter filter) {
inline CubeMapTexture* setMagnificationFilter(Sampler::Filter filter) {
AbstractTexture::setMagnificationFilter(filter);
return this;
}

8
src/CubeMapTextureArray.h

@ -51,7 +51,7 @@ Example: array with 16 layers of cube map faces, each face consisting of six
Image3D dummy({64, 64, 16*6}, ImageFormat::RGBA, ImageType::UnsignedByte, nullptr);
CubeMapTextureArray texture;
texture.setMagnificationFilter(CubeMapTextureArray::Filter::Linear)
texture.setMagnificationFilter(Sampler::Filter::Linear)
// ...
->setStorage(Math::log2(64)+1, TextureFormat::RGBA8, {64, 64, 16});
@ -103,7 +103,7 @@ class CubeMapTextureArray: public AbstractTexture {
*
* See Texture::setWrapping() for more information.
*/
inline CubeMapTextureArray* setWrapping(const Array3D<Wrapping>& wrapping) {
inline CubeMapTextureArray* setWrapping(const Array3D<Sampler::Wrapping>& wrapping) {
DataHelper<3>::setWrapping(this, wrapping);
return this;
}
@ -239,11 +239,11 @@ class CubeMapTextureArray: public AbstractTexture {
/* Overloads to remove WTF-factor from method chaining order */
#ifndef DOXYGEN_GENERATING_OUTPUT
inline CubeMapTextureArray* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::Base) {
inline CubeMapTextureArray* setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap = Sampler::Mipmap::Base) {
AbstractTexture::setMinificationFilter(filter, mipmap);
return this;
}
inline CubeMapTextureArray* setMagnificationFilter(Filter filter) {
inline CubeMapTextureArray* setMagnificationFilter(Sampler::Filter filter) {
AbstractTexture::setMagnificationFilter(filter);
return this;
}

1
src/Magnum.h

@ -401,6 +401,7 @@ template<class T, class U = T> class Resource;
class ResourceKey;
template<class...> class ResourceManager;
class Sampler;
class Shader;
template<UnsignedInt> class Texture;

61
src/Sampler.cpp

@ -0,0 +1,61 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include "Sampler.h"
#include "Context.h"
#include "Implementation/State.h"
#include "Implementation/TextureState.h"
namespace Magnum {
/* Check correctness of binary OR in setMinificationFilter(). If nobody fucks
anything up, this assert should produce the same results on all dimensions,
thus testing only on AbstractTexture. */
#define filter_or(filter, mipmap) (GLint(Sampler::Filter::filter)|GLint(Sampler::Mipmap::mipmap))
static_assert((filter_or(Nearest, Base) == GL_NEAREST) &&
(filter_or(Nearest, Nearest) == GL_NEAREST_MIPMAP_NEAREST) &&
(filter_or(Nearest, Linear) == GL_NEAREST_MIPMAP_LINEAR) &&
(filter_or(Linear, Base) == GL_LINEAR) &&
(filter_or(Linear, Nearest) == GL_LINEAR_MIPMAP_NEAREST) &&
(filter_or(Linear, Linear) == GL_LINEAR_MIPMAP_LINEAR),
"Unsupported constants for GL texture filtering");
#undef filter_or
#ifndef MAGNUM_TARGET_GLES3
Float Sampler::maxSupportedAnisotropy() {
GLfloat& value = Context::current()->state()->texture->maxSupportedAnisotropy;
/** @todo Re-enable when extension header is available */
#ifndef MAGNUM_TARGET_GLES
/* Get the value, if not already cached */
if(value == 0.0f)
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &value);
#endif
return value;
}
#endif
}

139
src/Sampler.h

@ -0,0 +1,139 @@
#ifndef Magnum_Sampler_h
#define Magnum_Sampler_h
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/** @file
* @brief Class Magnum::Sampler
*/
#include "Types.h"
#include "OpenGL.h"
namespace Magnum {
/**
@brief %Texture sampler
@see Texture, CubeMapTexture, CubeMapTextureArray
*/
class Sampler {
public:
/**
* @brief %Texture filtering
*
* @see setMagnificationFilter() and setMinificationFilter()
*/
enum class Filter: GLint {
Nearest = GL_NEAREST, /**< Nearest neighbor filtering */
/**
* Linear interpolation filtering.
* @requires_gles30 %Extension @es_extension{OES,texture_float_linear} /
* @es_extension2{OES,texture_half_float_linear,OES_texture_float_linear}
* for linear interpolation of textures with
* @ref Magnum::TextureFormat "TextureFormat::HalfFloat" /
* @ref Magnum::TextureFormat "TextureFormat::Float" in OpenGL
* ES 2.0.
*/
Linear = GL_LINEAR
};
/**
* @brief Mip level selection
*
* @see setMinificationFilter()
*/
enum class Mipmap: GLint {
Base = GL_NEAREST & ~GL_NEAREST, /**< Select base mip level */
/**
* Select nearest mip level. **Unavailable on rectangle textures.**
*/
Nearest = GL_NEAREST_MIPMAP_NEAREST & ~GL_NEAREST,
/**
* Linear interpolation of nearest mip levels. **Unavailable on
* rectangle textures.**
* @requires_gles30 %Extension @es_extension{OES,texture_float_linear} /
* @es_extension2{OES,texture_half_float_linear,OES_texture_float_linear}
* for linear interpolation of textures with
* @ref Magnum::TextureFormat "TextureFormat::HalfFloat" /
* @ref Magnum::TextureFormat "TextureFormat::Float" in OpenGL
* ES 2.0.
*/
Linear = GL_NEAREST_MIPMAP_LINEAR & ~GL_NEAREST
};
/**
* @brief %Texture wrapping
*
* @see setWrapping()
*/
enum class Wrapping: GLint {
/** Repeat texture. **Unavailable on rectangle textures.** */
Repeat = GL_REPEAT,
/**
* Repeat mirrored texture. **Unavailable on rectangle textures.**
*/
MirroredRepeat = GL_MIRRORED_REPEAT,
/**
* Clamp to edge. Coordinates out of the range will be clamped to
* first / last column / row in given direction.
*/
ClampToEdge = GL_CLAMP_TO_EDGE,
#ifndef MAGNUM_TARGET_GLES3
/**
* Clamp to border color. Coordinates out of range will be clamped
* to border color (set with setBorderColor()).
* @requires_es_extension %Extension @es_extension{NV,texture_border_clamp}
*/
#ifndef MAGNUM_TARGET_GLES
ClampToBorder = GL_CLAMP_TO_BORDER
#else
ClampToBorder = GL_CLAMP_TO_BORDER_NV
#endif
#endif
};
#ifndef MAGNUM_TARGET_GLES3
/**
* @brief Max supported anisotropy
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls.
* @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 maxSupportedAnisotropy();
#endif
};
}
#endif

6
src/Text/DistanceFieldGlyphCache.cpp

@ -51,9 +51,9 @@ DistanceFieldGlyphCache::DistanceFieldGlyphCache(const Vector2i& originalSize, c
void DistanceFieldGlyphCache::setImage(const Vector2i& offset, Image2D* const image) {
Texture2D input;
input.setWrapping(Texture2D::Wrapping::ClampToEdge)
->setMinificationFilter(Texture2D::Filter::Linear)
->setMagnificationFilter(Texture2D::Filter::Linear)
input.setWrapping(Sampler::Wrapping::ClampToEdge)
->setMinificationFilter(Sampler::Filter::Linear)
->setMagnificationFilter(Sampler::Filter::Linear)
->setImage(0, internalFormat, image);
/* Create distance field from input texture */

6
src/Text/GlyphCache.cpp

@ -65,9 +65,9 @@ void GlyphCache::initialize(const TextureFormat internalFormat, const Vector2i&
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::texture_storage);
#endif
_texture.setWrapping(Texture2D::Wrapping::ClampToEdge)
->setMinificationFilter(Texture2D::Filter::Linear)
->setMagnificationFilter(Texture2D::Filter::Linear)
_texture.setWrapping(Sampler::Wrapping::ClampToEdge)
->setMinificationFilter(Sampler::Filter::Linear)
->setMagnificationFilter(Sampler::Filter::Linear)
->setStorage(1, internalFormat, size);
}

24
src/Texture.h

@ -49,10 +49,10 @@ void* data;
Image2D image({4096, 4096}, ImageFormat::RGBA, ImageType::UnsignedByte, data);
Texture2D texture;
texture.setMagnificationFilter(Texture2D::Filter::Linear)
->setMinificationFilter(Texture2D::Filter::Linear, Texture2D::Mipmap::Linear)
->setWrapping(Texture2D::Wrapping::ClampToEdge)
->setMaxAnisotropy(Texture2D::maxSupportedAnisotropy)
texture.setMagnificationFilter(Sampler::Filter::Linear)
->setMinificationFilter(Sampler::Filter::Linear, Texture2D::Mipmap::Linear)
->setWrapping(Sampler::Wrapping::ClampToEdge)
->setMaxAnisotropy(Sampler::maxSupportedAnisotropy())
->setStorage(Math::log2(4096)+1, TextureFormat::RGBA8, {4096, 4096})
->setSubImage(0, {}, &image)
->generateMipmap();
@ -82,7 +82,7 @@ or by passing properly sized empty Image to setImage(). Example: 2D texture
array with 16 layers of 64x64 images:
@code
Texture3D texture(Texture3D::Target::Texture2DArray);
texture.setMagnificationFilter(Texture2D::Filter::Linear)
texture.setMagnificationFilter(Sampler::Filter::Linear)
// ...
->setStorage(levels, TextureFormat::RGBA8, {64, 64,16});
@ -106,8 +106,8 @@ to constructor. In shader, the texture is used via sampler2DRect`. Unlike
`sampler2D`, which accepts coordinates between 0 and 1, `sampler2DRect`
accepts coordinates between 0 and `textureSizeInGivenDirection-1`. Note that
rectangle textures don't support mipmapping and repeating wrapping modes, see
@ref Texture::Filter "Filter", @ref Texture::Mipmap "Mipmap" and
generateMipmap() documentation for more information.
@ref Sampler::Filter "Sampler::Filter", @ref Sampler::Mipmap "Sampler::Mipmap"
and generateMipmap() documentation for more information.
@requires_gl Rectangle textures are not available in OpenGL ES.
@requires_gl31 %Extension @extension{ARB,texture_rectangle} (rectangle
@ -209,16 +209,16 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
* textures and (0, textureSizeInGivenDirection-1) for rectangle
* textures. If @extension{EXT,direct_state_access} is not available,
* the texture is bound to some layer before the operation. Initial
* value is @ref AbstractTexture::Wrapping "Wrapping::Repeat".
* value is @ref Sampler::Wrapping "Sampler::Wrapping::Repeat".
* @attention For rectangle textures only some modes are supported,
* see @ref AbstractTexture::Wrapping "Wrapping" documentation
* see @ref Sampler::Wrapping "Sampler::Wrapping" documentation
* for more information.
* @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexParameter}
* or @fn_gl_extension{TextureParameter,EXT,direct_state_access}
* with @def_gl{TEXTURE_WRAP_S}, @def_gl{TEXTURE_WRAP_T},
* @def_gl{TEXTURE_WRAP_R}
*/
inline Texture<Dimensions>* setWrapping(const Array<Dimensions, Wrapping>& wrapping) {
inline Texture<Dimensions>* setWrapping(const Array<Dimensions, Sampler::Wrapping>& wrapping) {
DataHelper<Dimensions>::setWrapping(this, wrapping);
return this;
}
@ -364,11 +364,11 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
/* Overloads to remove WTF-factor from method chaining order */
#ifndef DOXYGEN_GENERATING_OUTPUT
inline Texture<Dimensions>* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::Base) {
inline Texture<Dimensions>* setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap = Sampler::Mipmap::Base) {
AbstractTexture::setMinificationFilter(filter, mipmap);
return this;
}
inline Texture<Dimensions>* setMagnificationFilter(Filter filter) {
inline Texture<Dimensions>* setMagnificationFilter(Sampler::Filter filter) {
AbstractTexture::setMagnificationFilter(filter);
return this;
}

Loading…
Cancel
Save