Browse Source

Split the OpenGL layer out, pt 12: generic sampler state.

The Sampler class was split into GL::Sampler (which is now mostly just a
placeholder for implementing OpenGL sampler objects), pairs of generic /
GL-specific SamplerFormat / GL::SamplerFormat, SamplerMipmap /
GL::SamplerMipmap, SamplerWrapping / GL::SamplerWrapping enums and the
GL-specific GL::SamplerCompareMode, GL::SamplerCompareFunction,
GL::SamplerDepthStencilMode enums.

The old Sampler class is marked as deprecated and aliases its enum to
the generic enums (or to the GL-specific ones in case the generic
versions are not available).
pull/233/head
Vladimír Vondruš 8 years ago
parent
commit
a1d2277e96
  1. 15
      doc/changelog.dox
  2. 4
      doc/platforms-ios.dox
  3. 3
      src/Magnum/CMakeLists.txt
  4. 16
      src/Magnum/GL/AbstractTexture.cpp
  5. 17
      src/Magnum/GL/AbstractTexture.h
  6. 4
      src/Magnum/GL/CMakeLists.txt
  7. 29
      src/Magnum/GL/CubeMapTexture.h
  8. 29
      src/Magnum/GL/CubeMapTextureArray.h
  9. 8
      src/Magnum/GL/GL.h
  10. 8
      src/Magnum/GL/PixelFormat.h
  11. 39
      src/Magnum/GL/RectangleTexture.h
  12. 97
      src/Magnum/GL/Sampler.cpp
  13. 576
      src/Magnum/GL/Sampler.h
  14. 2
      src/Magnum/GL/Test/CMakeLists.txt
  15. 29
      src/Magnum/GL/Test/CubeMapTextureArrayGLTest.cpp
  16. 31
      src/Magnum/GL/Test/CubeMapTextureGLTest.cpp
  17. 25
      src/Magnum/GL/Test/RectangleTextureGLTest.cpp
  18. 123
      src/Magnum/GL/Test/SamplerTest.cpp
  19. 45
      src/Magnum/GL/Test/TextureArrayGLTest.cpp
  20. 63
      src/Magnum/GL/Test/TextureGLTest.cpp
  21. 51
      src/Magnum/GL/Texture.h
  22. 29
      src/Magnum/GL/TextureArray.h
  23. 82
      src/Magnum/GL/TextureFormat.h
  24. 6
      src/Magnum/Magnum.h
  25. 77
      src/Magnum/Sampler.cpp
  26. 125
      src/Magnum/Sampler.h
  27. 1
      src/Magnum/Test/CMakeLists.txt
  28. 70
      src/Magnum/Test/SamplerTest.cpp

15
doc/changelog.dox

@ -58,6 +58,8 @@ See also:
- New @ref MeshPrimitive and @ref MeshIndexType enums containing generic
API-independent mesh primitive types and index types, together with
@ref meshIndexTypeSize() utilities
- New @ref SamplerFilter, @ref SamplerMipmap and @ref SamplerWrapping enums
containing generic API-independent texture sampler modes
@subsubsection changelog-latest-new-math Math library
@ -78,6 +80,12 @@ See also:
@ref GL::MeshPrimitive and @ref GL::MeshIndexType values. The @ref Mesh
class now has overloads accepting both types.
- New @ref Mesh::indexType() and @ref MeshView::mesh() getters
- New @ref GL::samplerFilter(), @ref GL::samplerMipmap() and
@ref GL::samplerWrapping() utilities for converting generic
@ref SamplerFilter, @ref SamplerMipmap and @ref SamplerWrapping to G
L-specific @ref GL::SamplerFilter, @ref GL::SamplerMipmap and
@ref GL::SamplerWrapping values. All texture classes now have overloads
accepting both types.
- Initial support for OpenGL ES 3.2 and OpenGL 4.6
- New OpenGL extension support:
- @extension{ARB,texture_filter_anisotropic}
@ -189,6 +197,13 @@ See also:
@ref GL::MeshIndexType and @ref meshIndexTypeSize() instead
- The `GL::Mesh::indexSize()` function is deprecated, use
@ref GL::Mesh::indexTypeSize() instead
- The `Sampler` class and the `Sampler::Filter`, `Sampler::Mipmap`,
`Sampler::Wrapping`, `Sampler::CompareMode`, `Sampler::CompareFunction` and
`Sampler::DepthStencilMode` enums are deprecated, use @ref GL::Sampler,
@ref SamplerFilter / @ref GL::SamplerFilter, @ref SamplerMipmap /
@ref GL::SamplerMipmap, @ref SamplerWrapping / @ref GL::SamplerWrapping,
@ref GL::SamplerCompareMode, @ref GL::SamplerCompareFunction and
@ref GL::SamplerDepthStencilMode instead
- Class @cpp Primitives::Capsule2D @ce and @cpp Primitives::Capsule3D @ce is
deprecated, use @ref Primitives::capsule2DWireframe(),
@ref Primitives::capsule3DSolid() and @ref Primitives::capsule3DWireframe()

4
doc/platforms-ios.dox

@ -48,8 +48,8 @@ Official Apple documentation:
@section platforms-ios-troubleshooting Troubleshooting
- GLSL @glsl texelFetch() @ce returns zero results if you have a texture with
integer type and the filtering is not @ref Sampler::Filter::Nearest. Yes,
it shouldn't matter, but it does.
integer type and the filtering is not @ref SamplerFilter::Nearest. Yes, it
shouldn't matter, but it does.
@todoc https://cmake.org/cmake/help/v3.8/prop_gbl/XCODE_EMIT_EFFECTIVE_PLATFORM_NAME.html and $<TARGET_FILE> property and https://gitlab.kitware.com/cmake/cmake/merge_requests/404, doesn't work for me on 3.10 and xcode 9.2 on Travis :/
@todoc CMake -G Xcode, testsuite integration, bundling, controlling xcode properties from cmake

3
src/Magnum/CMakeLists.txt

@ -31,6 +31,7 @@ set(Magnum_SRCS
Mesh.cpp
PixelStorage.cpp
Resource.cpp
Sampler.cpp
Timeline.cpp)
set(Magnum_GracefulAssert_SRCS
@ -51,6 +52,7 @@ set(Magnum_HEADERS
Resource.h
ResourceManager.h
ResourceManager.hpp
Sampler.h
Tags.h
Timeline.h
Types.h
@ -75,7 +77,6 @@ if(WITH_GL AND BUILD_DEPRECATED)
Renderbuffer.h
RenderbufferFormat.h
Renderer.h
Sampler.h
Shader.h
Tags.h
Texture.h

16
src/Magnum/GL/AbstractTexture.cpp

@ -393,11 +393,11 @@ void AbstractTexture::setMaxLevel(Int level) {
}
#endif
void AbstractTexture::setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap) {
void AbstractTexture::setMinificationFilter(SamplerFilter filter, SamplerMipmap mipmap) {
(this->*Context::current().state().texture->parameteriImplementation)(GL_TEXTURE_MIN_FILTER, GLint(filter)|GLint(mipmap));
}
void AbstractTexture::setMagnificationFilter(const Sampler::Filter filter) {
void AbstractTexture::setMagnificationFilter(const SamplerFilter filter) {
(this->*Context::current().state().texture->parameteriImplementation)(GL_TEXTURE_MAG_FILTER, GLint(filter));
}
@ -465,7 +465,7 @@ void AbstractTexture::setSwizzleInternal(const GLint r, const GLint g, const GLi
#endif
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
void AbstractTexture::setCompareMode(const Sampler::CompareMode mode) {
void AbstractTexture::setCompareMode(const SamplerCompareMode mode) {
(this->*Context::current().state().texture->parameteriImplementation)(
#ifndef MAGNUM_TARGET_GLES2
GL_TEXTURE_COMPARE_MODE
@ -475,7 +475,7 @@ void AbstractTexture::setCompareMode(const Sampler::CompareMode mode) {
, GLenum(mode));
}
void AbstractTexture::setCompareFunction(const Sampler::CompareFunction function) {
void AbstractTexture::setCompareFunction(const SamplerCompareFunction function) {
(this->*Context::current().state().texture->parameteriImplementation)(
#ifndef MAGNUM_TARGET_GLES2
GL_TEXTURE_COMPARE_FUNC
@ -487,7 +487,7 @@ void AbstractTexture::setCompareFunction(const Sampler::CompareFunction function
#endif
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
void AbstractTexture::setDepthStencilMode(const Sampler::DepthStencilMode mode) {
void AbstractTexture::setDepthStencilMode(const SamplerDepthStencilMode mode) {
(this->*Context::current().state().texture->parameteriImplementation)(GL_DEPTH_STENCIL_TEXTURE_MODE, GLenum(mode));
}
#endif
@ -2209,12 +2209,12 @@ void AbstractTexture::DataHelper<3>::invalidateSubImage(AbstractTexture& texture
}
#ifndef MAGNUM_TARGET_GLES
void AbstractTexture::DataHelper<1>::setWrapping(AbstractTexture& texture, const Array1D<Sampler::Wrapping>& wrapping) {
void AbstractTexture::DataHelper<1>::setWrapping(AbstractTexture& texture, const Array1D<SamplerWrapping>& wrapping) {
(texture.*Context::current().state().texture->parameteriImplementation)(GL_TEXTURE_WRAP_S, GLint(wrapping.x()));
}
#endif
void AbstractTexture::DataHelper<2>::setWrapping(AbstractTexture& texture, const Array2D<Sampler::Wrapping>& wrapping) {
void AbstractTexture::DataHelper<2>::setWrapping(AbstractTexture& texture, const Array2D<SamplerWrapping>& wrapping) {
const Implementation::TextureState& state = *Context::current().state().texture;
(texture.*state.parameteriImplementation)(GL_TEXTURE_WRAP_S, GLint(wrapping.x()));
@ -2222,7 +2222,7 @@ void AbstractTexture::DataHelper<2>::setWrapping(AbstractTexture& texture, const
}
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
void AbstractTexture::DataHelper<3>::setWrapping(AbstractTexture& texture, const Array3D<Sampler::Wrapping>& wrapping) {
void AbstractTexture::DataHelper<3>::setWrapping(AbstractTexture& texture, const Array3D<SamplerWrapping>& wrapping) {
const Implementation::TextureState& state = *Context::current().state().texture;
(texture.*state.parameteriImplementation)(GL_TEXTURE_WRAP_S, GLint(wrapping.x()));

17
src/Magnum/GL/AbstractTexture.h

@ -35,7 +35,6 @@
#include "Magnum/Tags.h"
#include "Magnum/GL/AbstractObject.h"
#include "Magnum/GL/GL.h"
#include "Magnum/GL/Sampler.h"
namespace Magnum { namespace GL {
@ -457,8 +456,8 @@ class MAGNUM_GL_EXPORT AbstractTexture: public AbstractObject {
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
void setMaxLevel(Int level);
#endif
void setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap);
void setMagnificationFilter(Sampler::Filter filter);
void setMinificationFilter(SamplerFilter filter, SamplerMipmap mipmap);
void setMagnificationFilter(SamplerFilter filter);
#ifndef MAGNUM_TARGET_GLES2
void setMinLod(Float lod);
void setMaxLod(Float lod);
@ -489,11 +488,11 @@ class MAGNUM_GL_EXPORT AbstractTexture: public AbstractObject {
#endif
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
void setCompareMode(Sampler::CompareMode mode);
void setCompareFunction(Sampler::CompareFunction function);
void setCompareMode(SamplerCompareMode mode);
void setCompareFunction(SamplerCompareFunction function);
#endif
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
void setDepthStencilMode(Sampler::DepthStencilMode mode);
void setDepthStencilMode(SamplerDepthStencilMode mode);
#endif
void invalidateImage(Int level);
void generateMipmap();
@ -727,7 +726,7 @@ template<> struct MAGNUM_GL_EXPORT AbstractTexture::DataHelper<1> {
static Math::Vector<1, GLint> compressedBlockSize(GLenum target, TextureFormat format);
static Math::Vector<1, GLint> imageSize(AbstractTexture& texture, GLint level);
static void setWrapping(AbstractTexture& texture, const Array1D<Sampler::Wrapping>& wrapping);
static void setWrapping(AbstractTexture& texture, const Array1D<SamplerWrapping>& wrapping);
static void setStorage(AbstractTexture& texture, GLsizei levels, TextureFormat internalFormat, const Math::Vector<1, GLsizei>& size);
@ -752,7 +751,7 @@ template<> struct MAGNUM_GL_EXPORT AbstractTexture::DataHelper<2> {
static Vector2i imageSize(AbstractTexture& texture, GLint level);
#endif
static void setWrapping(AbstractTexture& texture, const Array2D<Sampler::Wrapping>& wrapping);
static void setWrapping(AbstractTexture& texture, const Array2D<SamplerWrapping>& wrapping);
static void setStorage(AbstractTexture& texture, GLsizei levels, TextureFormat internalFormat, const Vector2i& size);
@ -797,7 +796,7 @@ template<> struct MAGNUM_GL_EXPORT AbstractTexture::DataHelper<3> {
static Vector3i imageSize(AbstractTexture& texture, GLint level);
#endif
static void setWrapping(AbstractTexture& texture, const Array3D<Sampler::Wrapping>& wrapping);
static void setWrapping(AbstractTexture& texture, const Array3D<SamplerWrapping>& wrapping);
static void setStorage(AbstractTexture& texture, GLsizei levels, TextureFormat internalFormat, const Vector3i& size);

4
src/Magnum/GL/CMakeLists.txt

@ -38,7 +38,6 @@ set(MagnumGL_SRCS
OpenGL.cpp
Renderbuffer.cpp
Renderer.cpp
Sampler.cpp
Shader.cpp
Texture.cpp
Version.cpp
@ -57,7 +56,8 @@ set(MagnumGL_SRCS
set(MagnumGL_GracefulAssert_SRCS
Mesh.cpp
PixelFormat.cpp)
PixelFormat.cpp
Sampler.cpp)
set(MagnumGL_HEADERS
AbstractFramebuffer.h

29
src/Magnum/GL/CubeMapTexture.h

@ -30,7 +30,9 @@
*/
#include "Magnum/Array.h"
#include "Magnum/Sampler.h"
#include "Magnum/GL/AbstractTexture.h"
#include "Magnum/GL/Sampler.h"
#include "Magnum/Math/Vector2.h"
namespace Magnum { namespace GL {
@ -261,22 +263,32 @@ class MAGNUM_GL_EXPORT CubeMapTexture: public AbstractTexture {
*
* See @ref Texture::setMinificationFilter() for more information.
*/
CubeMapTexture& setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap = Sampler::Mipmap::Base) {
CubeMapTexture& setMinificationFilter(SamplerFilter filter, SamplerMipmap mipmap = SamplerMipmap::Base) {
AbstractTexture::setMinificationFilter(filter, mipmap);
return *this;
}
/** @overload */
CubeMapTexture& setMinificationFilter(Magnum::SamplerFilter filter, Magnum::SamplerMipmap mipmap = Magnum::SamplerMipmap::Base) {
return setMinificationFilter(samplerFilter(filter), samplerMipmap(mipmap));
}
/**
* @brief @copybrief Texture::setMagnificationFilter()
* @return Reference to self (for method chaining)
*
* See @ref Texture::setMagnificationFilter() for more information.
*/
CubeMapTexture& setMagnificationFilter(Sampler::Filter filter) {
CubeMapTexture& setMagnificationFilter(SamplerFilter filter) {
AbstractTexture::setMagnificationFilter(filter);
return *this;
}
/** @overload */
CubeMapTexture& setMagnificationFilter(Magnum::SamplerFilter filter) {
return setMagnificationFilter(samplerFilter(filter));
}
#ifndef MAGNUM_TARGET_GLES2
/**
* @brief @copybrief Texture::setMinLod()
@ -330,11 +342,16 @@ class MAGNUM_GL_EXPORT CubeMapTexture: public AbstractTexture {
*
* See @ref Texture::setWrapping() for more information.
*/
CubeMapTexture& setWrapping(const Array2D<Sampler::Wrapping>& wrapping) {
CubeMapTexture& setWrapping(const Array2D<SamplerWrapping>& wrapping) {
DataHelper<2>::setWrapping(*this, wrapping);
return *this;
}
/** @overload */
CubeMapTexture& setWrapping(const Array2D<Magnum::SamplerWrapping>& wrapping) {
return setWrapping(samplerWrapping(wrapping));
}
#ifndef MAGNUM_TARGET_WEBGL
/**
* @brief @copybrief Texture::setBorderColor(const Color4&)
@ -441,7 +458,7 @@ class MAGNUM_GL_EXPORT CubeMapTexture: public AbstractTexture {
* @requires_webgl20 Depth texture comparison is not available in WebGL
* 1.0.
*/
CubeMapTexture& setCompareMode(Sampler::CompareMode mode) {
CubeMapTexture& setCompareMode(SamplerCompareMode mode) {
AbstractTexture::setCompareMode(mode);
return *this;
}
@ -456,7 +473,7 @@ class MAGNUM_GL_EXPORT CubeMapTexture: public AbstractTexture {
* @requires_webgl20 Depth texture comparison is not available in WebGL
* 1.0.
*/
CubeMapTexture& setCompareFunction(Sampler::CompareFunction function) {
CubeMapTexture& setCompareFunction(SamplerCompareFunction function) {
AbstractTexture::setCompareFunction(function);
return *this;
}
@ -473,7 +490,7 @@ class MAGNUM_GL_EXPORT CubeMapTexture: public AbstractTexture {
* and older.
* @requires_gles Stencil texturing is not available in WebGL.
*/
CubeMapTexture& setDepthStencilMode(Sampler::DepthStencilMode mode) {
CubeMapTexture& setDepthStencilMode(SamplerDepthStencilMode mode) {
AbstractTexture::setDepthStencilMode(mode);
return *this;
}

29
src/Magnum/GL/CubeMapTextureArray.h

@ -32,7 +32,9 @@
#endif
#include "Magnum/Array.h"
#include "Magnum/Sampler.h"
#include "Magnum/GL/AbstractTexture.h"
#include "Magnum/GL/Sampler.h"
#include "Magnum/Math/Vector3.h"
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
@ -228,22 +230,32 @@ class MAGNUM_GL_EXPORT CubeMapTextureArray: public AbstractTexture {
*
* See @ref Texture::setMinificationFilter() for more information.
*/
CubeMapTextureArray& setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap = Sampler::Mipmap::Base) {
CubeMapTextureArray& setMinificationFilter(SamplerFilter filter, SamplerMipmap mipmap = SamplerMipmap::Base) {
AbstractTexture::setMinificationFilter(filter, mipmap);
return *this;
}
/** @overload */
CubeMapTextureArray& setMinificationFilter(Magnum::SamplerFilter filter, Magnum::SamplerMipmap mipmap = Magnum::SamplerMipmap::Base) {
return setMinificationFilter(samplerFilter(filter), samplerMipmap(mipmap));
}
/**
* @brief @copybrief Texture::setMagnificationFilter()
* @return Reference to self (for method chaining)
*
* See @ref Texture::setMagnificationFilter() for more information.
*/
CubeMapTextureArray& setMagnificationFilter(Sampler::Filter filter) {
CubeMapTextureArray& setMagnificationFilter(SamplerFilter filter) {
AbstractTexture::setMagnificationFilter(filter);
return *this;
}
/** @overload */
CubeMapTextureArray& setMagnificationFilter(Magnum::SamplerFilter filter) {
return setMagnificationFilter(samplerFilter(filter));
}
/**
* @brief @copybrief Texture::setMinLod()
* @return Reference to self (for method chaining)
@ -287,11 +299,16 @@ class MAGNUM_GL_EXPORT CubeMapTextureArray: public AbstractTexture {
*
* See @ref Texture::setWrapping() for more information.
*/
CubeMapTextureArray& setWrapping(const Array2D<Sampler::Wrapping>& wrapping) {
CubeMapTextureArray& setWrapping(const Array2D<SamplerWrapping>& wrapping) {
DataHelper<2>::setWrapping(*this, wrapping);
return *this;
}
/** @overload */
CubeMapTextureArray& setWrapping(const Array2D<Magnum::SamplerWrapping>& wrapping) {
return setWrapping(samplerWrapping(wrapping));
}
/**
* @brief @copybrief Texture::setBorderColor(const Color4&)
* @return Reference to self (for method chaining)
@ -375,7 +392,7 @@ class MAGNUM_GL_EXPORT CubeMapTextureArray: public AbstractTexture {
*
* See @ref Texture::setCompareMode() for more information.
*/
CubeMapTextureArray& setCompareMode(Sampler::CompareMode mode) {
CubeMapTextureArray& setCompareMode(SamplerCompareMode mode) {
AbstractTexture::setCompareMode(mode);
return *this;
}
@ -386,7 +403,7 @@ class MAGNUM_GL_EXPORT CubeMapTextureArray: public AbstractTexture {
*
* See @ref Texture::setCompareFunction() for more information.
*/
CubeMapTextureArray& setCompareFunction(Sampler::CompareFunction function) {
CubeMapTextureArray& setCompareFunction(SamplerCompareFunction function) {
AbstractTexture::setCompareFunction(function);
return *this;
}
@ -398,7 +415,7 @@ class MAGNUM_GL_EXPORT CubeMapTextureArray: public AbstractTexture {
* See @ref Texture::setDepthStencilMode() for more information.
* @requires_gl43 Extension @extension{ARB,stencil_texturing}
*/
CubeMapTextureArray& setDepthStencilMode(Sampler::DepthStencilMode mode) {
CubeMapTextureArray& setDepthStencilMode(SamplerDepthStencilMode mode) {
AbstractTexture::setDepthStencilMode(mode);
return *this;
}

8
src/Magnum/GL/GL.h

@ -32,6 +32,7 @@
#include "Magnum/Types.h"
#ifndef DOXYGEN_GENERATING_OUTPUT
typedef int GLint; /* Needed for sampler enums */
typedef unsigned int GLenum; /* Needed for *Format and *Type enums */
#endif
@ -120,6 +121,13 @@ class RectangleTexture;
class Renderbuffer;
enum class RenderbufferFormat: GLenum;
enum class SamplerFilter: GLint;
enum class SamplerMipmap: GLint;
enum class SamplerWrapping: GLint;
enum class SamplerCompareMode: GLenum;
enum class SamplerCompareFunction: GLenum;
enum class SamplerDepthStencilMode: GLenum;
class Sampler;
class Shader;

8
src/Magnum/GL/PixelFormat.h

@ -408,13 +408,13 @@ enum class PixelType: GLenum {
* @requires_gles30 Extension @extension2{OES,texture_half_float,OES_texture_float}
* to use for texture reading in OpenGL ES 2.0.
* @requires_gles30 Extension @extension2{OES,texture_half_float_linear,OES_texture_float_linear}
* for filtering the texture using @ref Sampler::Filter::Linear.
* for filtering the texture using @ref SamplerFilter::Linear.
* @requires_gles32 Extension @extension{EXT,color_buffer_half_float}
* to use the texture as a render target.
* @requires_webgl20 Extension @webgl_extension{OES,texture_half_float} to
* use for texture reading in WebGL 1.0.
* @requires_webgl20 Extension @webgl_extension{OES,texture_half_float_linear}
* for filtering the texture using @ref Sampler::Filter::Linear.
* for filtering the texture using @ref SamplerFilter::Linear.
* @requires_webgl_extension Extension @webgl_extension{EXT,color_buffer_half_float}
* to use the texture as a render target.
*/
@ -431,11 +431,11 @@ enum class PixelType: GLenum {
* @requires_gles32 Extension @extension{EXT,color_half_float} to use the
* texture as a render target.
* @requires_es_extension Extension @extension{OES,texture_float_linear}
* for filtering the texture using @ref Sampler::Filter::Linear.
* for filtering the texture using @ref SamplerFilter::Linear.
* @requires_webgl20 Extension @webgl_extension{OES,texture_float} to use
* for texture reading in WebGL 1.0.
* @requires_webgl_extension Extension @webgl_extension{OES,texture_float_linear}
* for filtering the texture using @ref Sampler::Filter::Linear.
* for filtering the texture using @ref SamplerFilter::Linear.
* @requires_webgl_extension Extension @webgl_extension{WEBGL,color_buffer_float}
* in WebGL 1.0 or @webgl_extension{EXT,color_buffer_float} in WebGL
* 2.0 to use the texture as a render target.

39
src/Magnum/GL/RectangleTexture.h

@ -32,7 +32,9 @@
#endif
#include "Magnum/Array.h"
#include "Magnum/Sampler.h"
#include "Magnum/GL/AbstractTexture.h"
#include "Magnum/GL/Sampler.h"
#include "Magnum/Math/Vector2.h"
#ifndef MAGNUM_TARGET_GLES
@ -159,40 +161,55 @@ class MAGNUM_GL_EXPORT RectangleTexture: public AbstractTexture {
* @return Reference to self (for method chaining)
*
* See @ref Texture::setMinificationFilter() for more information.
* Initial value is @ref Sampler::Filter::Linear.
* Initial value is @ref SamplerFilter::Linear.
*/
RectangleTexture& setMinificationFilter(Sampler::Filter filter) {
AbstractTexture::setMinificationFilter(filter, Sampler::Mipmap::Base);
RectangleTexture& setMinificationFilter(SamplerFilter filter) {
AbstractTexture::setMinificationFilter(filter, SamplerMipmap::Base);
return *this;
}
/** @overload */
RectangleTexture& setMinificationFilter(Magnum::SamplerFilter filter) {
return setMinificationFilter(samplerFilter(filter));
}
/**
* @brief @copybrief Texture::setMagnificationFilter()
* @return Reference to self (for method chaining)
*
* See @ref Texture::setMagnificationFilter() for more information.
*/
RectangleTexture& setMagnificationFilter(Sampler::Filter filter) {
RectangleTexture& setMagnificationFilter(SamplerFilter filter) {
AbstractTexture::setMagnificationFilter(filter);
return *this;
}
/** @overload */
RectangleTexture& setMagnificationFilter(Magnum::SamplerFilter filter) {
return setMagnificationFilter(samplerFilter(filter));
}
/**
* @brief @copybrief Texture::setWrapping()
* @return Reference to self (for method chaining)
*
* Sets wrapping type for coordinates out of @f$ [ 0, size - 1 ] @f$
* range. See @ref Texture::setWrapping() for more information. Initial
* value is @ref Sampler::Wrapping::ClampToEdge.
* @attention Only @ref Sampler::Wrapping::ClampToEdge and
* @ref Sampler::Wrapping::ClampToBorder is supported on this
* value is @ref SamplerWrapping::ClampToEdge.
* @attention Only @ref SamplerWrapping::ClampToEdge and
* @ref SamplerWrapping::ClampToBorder is supported on this
* texture type.
*/
RectangleTexture& setWrapping(const Array2D<Sampler::Wrapping>& wrapping) {
RectangleTexture& setWrapping(const Array2D<SamplerWrapping>& wrapping) {
DataHelper<2>::setWrapping(*this, wrapping);
return *this;
}
/** @overload */
RectangleTexture& setWrapping(const Array2D<Magnum::SamplerWrapping>& wrapping) {
return setWrapping(samplerWrapping(wrapping));
}
/**
* @brief @copybrief Texture::setBorderColor(const Color4&)
* @return Reference to self (for method chaining)
@ -267,7 +284,7 @@ class MAGNUM_GL_EXPORT RectangleTexture: public AbstractTexture {
*
* See @ref Texture::setCompareMode() for more information.
*/
RectangleTexture& setCompareMode(Sampler::CompareMode mode) {
RectangleTexture& setCompareMode(SamplerCompareMode mode) {
AbstractTexture::setCompareMode(mode);
return *this;
}
@ -278,7 +295,7 @@ class MAGNUM_GL_EXPORT RectangleTexture: public AbstractTexture {
*
* See @ref Texture::setCompareFunction() for more information.
*/
RectangleTexture& setCompareFunction(Sampler::CompareFunction function) {
RectangleTexture& setCompareFunction(SamplerCompareFunction function) {
AbstractTexture::setCompareFunction(function);
return *this;
}
@ -290,7 +307,7 @@ class MAGNUM_GL_EXPORT RectangleTexture: public AbstractTexture {
* See @ref Texture::setDepthStencilMode() for more information.
* @requires_gl43 Extension @extension{ARB,stencil_texturing}
*/
RectangleTexture& setDepthStencilMode(Sampler::DepthStencilMode mode) {
RectangleTexture& setDepthStencilMode(SamplerDepthStencilMode mode) {
AbstractTexture::setDepthStencilMode(mode);
return *this;
}

97
src/Magnum/GL/Sampler.cpp

@ -27,6 +27,7 @@
#include <Corrade/Utility/Debug.h>
#include "Magnum/Sampler.h"
#include "Magnum/GL/Context.h"
#include "Magnum/GL/Extensions.h"
#include "Magnum/GL/Implementation/State.h"
@ -37,7 +38,7 @@ namespace Magnum { namespace GL {
/* 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))
#define filter_or(filter, mipmap) (GLint(SamplerFilter::filter)|GLint(SamplerMipmap::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) &&
@ -47,6 +48,64 @@ static_assert((filter_or(Nearest, Base) == GL_NEAREST) &&
"Unsupported constants for GL texture filtering");
#undef filter_or
namespace {
constexpr SamplerFilter FilterMapping[]{
SamplerFilter::Nearest,
SamplerFilter::Linear
};
constexpr SamplerMipmap MipmapMapping[]{
SamplerMipmap::Base,
SamplerMipmap::Nearest,
SamplerMipmap::Linear
};
constexpr SamplerWrapping WrappingMapping[]{
SamplerWrapping::Repeat,
SamplerWrapping::MirroredRepeat,
SamplerWrapping::ClampToEdge,
#ifndef MAGNUM_TARGET_WEBGL
SamplerWrapping::ClampToBorder,
#else
SamplerWrapping{},
#endif
#ifndef MAGNUM_TARGET_GLES
SamplerWrapping::MirrorClampToEdge
#else
SamplerWrapping{}
#endif
};
}
SamplerFilter samplerFilter(const Magnum::SamplerFilter filter) {
CORRADE_ASSERT(UnsignedInt(filter) < Containers::arraySize(FilterMapping),
"GL::samplerFilter(): invalid filter" << filter, {});
return FilterMapping[UnsignedInt(filter)];
}
SamplerMipmap samplerMipmap(const Magnum::SamplerMipmap mipmap) {
CORRADE_ASSERT(UnsignedInt(mipmap) < Containers::arraySize(MipmapMapping),
"GL::samplerMipmap(): invalid filter" << mipmap, {});
return MipmapMapping[UnsignedInt(mipmap)];
}
bool hasSamplerWrapping(const Magnum::SamplerWrapping wrapping) {
CORRADE_ASSERT(UnsignedInt(wrapping) < Containers::arraySize(WrappingMapping),
"GL::hasSamplerWrapping(): invalid wrapping" << wrapping, {});
return UnsignedInt(WrappingMapping[UnsignedInt(wrapping)]);
}
SamplerWrapping samplerWrapping(const Magnum::SamplerWrapping wrapping) {
CORRADE_ASSERT(UnsignedInt(wrapping) < Containers::arraySize(WrappingMapping),
"GL::samplerWrapping(): invalid wrapping" << wrapping, {});
const SamplerWrapping out = WrappingMapping[UnsignedInt(wrapping)];
CORRADE_ASSERT(UnsignedInt(out),
"GL::samplerWrapping(): wrapping" << wrapping << "is not supported on this target", {});
return out;
}
Float Sampler::maxMaxAnisotropy() {
GLfloat& value = Context::current().state().texture->maxMaxAnisotropy;
@ -65,23 +124,23 @@ Float Sampler::maxMaxAnisotropy() {
}
#ifndef DOXYGEN_GENERATING_OUTPUT
Debug& operator<<(Debug& debug, const Sampler::Filter value) {
Debug& operator<<(Debug& debug, const SamplerFilter value) {
switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case Sampler::Filter::value: return debug << "GL::Sampler::Filter::" #value;
#define _c(value) case SamplerFilter::value: return debug << "GL::SamplerFilter::" #value;
_c(Nearest)
_c(Linear)
#undef _c
/* LCOV_EXCL_STOP */
}
return debug << "GL::Sampler::Filter(" << Debug::nospace << reinterpret_cast<void*>(GLint(value)) << Debug::nospace << ")";
return debug << "GL::SamplerFilter(" << Debug::nospace << reinterpret_cast<void*>(GLint(value)) << Debug::nospace << ")";
}
Debug& operator<<(Debug& debug, const Sampler::Mipmap value) {
Debug& operator<<(Debug& debug, const SamplerMipmap value) {
switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case Sampler::Mipmap::value: return debug << "GL::Sampler::Mipmap::" #value;
#define _c(value) case SamplerMipmap::value: return debug << "GL::SamplerMipmap::" #value;
_c(Base)
_c(Nearest)
_c(Linear)
@ -89,13 +148,13 @@ Debug& operator<<(Debug& debug, const Sampler::Mipmap value) {
/* LCOV_EXCL_STOP */
}
return debug << "GL::Sampler::Mipmap(" << Debug::nospace << reinterpret_cast<void*>(GLint(value)) << Debug::nospace << ")";
return debug << "GL::SamplerMipmap(" << Debug::nospace << reinterpret_cast<void*>(GLint(value)) << Debug::nospace << ")";
}
Debug& operator<<(Debug& debug, const Sampler::Wrapping value) {
Debug& operator<<(Debug& debug, const SamplerWrapping value) {
switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case Sampler::Wrapping::value: return debug << "GL::Sampler::Wrapping::" #value;
#define _c(value) case SamplerWrapping::value: return debug << "GL::SamplerWrapping::" #value;
_c(Repeat)
_c(MirroredRepeat)
_c(ClampToEdge)
@ -109,27 +168,27 @@ Debug& operator<<(Debug& debug, const Sampler::Wrapping value) {
/* LCOV_EXCL_STOP */
}
return debug << "GL::Sampler::Wrapping(" << Debug::nospace << reinterpret_cast<void*>(GLint(value)) << Debug::nospace << ")";
return debug << "GL::SamplerWrapping(" << Debug::nospace << reinterpret_cast<void*>(GLint(value)) << Debug::nospace << ")";
}
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
Debug& operator<<(Debug& debug, const Sampler::CompareMode value) {
Debug& operator<<(Debug& debug, const SamplerCompareMode value) {
switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case Sampler::CompareMode::value: return debug << "GL::Sampler::CompareMode::" #value;
#define _c(value) case SamplerCompareMode::value: return debug << "GL::SamplerCompareMode::" #value;
_c(None)
_c(CompareRefToTexture)
#undef _c
/* LCOV_EXCL_STOP */
}
return debug << "GL::Sampler::CompareMode(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")";
return debug << "GL::SamplerCompareMode(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")";
}
Debug& operator<<(Debug& debug, const Sampler::CompareFunction value) {
Debug& operator<<(Debug& debug, const SamplerCompareFunction value) {
switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case Sampler::CompareFunction::value: return debug << "GL::Sampler::CompareFunction::" #value;
#define _c(value) case SamplerCompareFunction::value: return debug << "GL::SamplerCompareFunction::" #value;
_c(Never)
_c(Always)
_c(Less)
@ -142,22 +201,22 @@ Debug& operator<<(Debug& debug, const Sampler::CompareFunction value) {
/* LCOV_EXCL_STOP */
}
return debug << "GL::Sampler::CompareFunction(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")";
return debug << "GL::SamplerCompareFunction(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")";
}
#endif
#ifndef MAGNUM_TARGET_GLES
Debug& operator<<(Debug& debug, const Sampler::DepthStencilMode value) {
Debug& operator<<(Debug& debug, const SamplerDepthStencilMode value) {
switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case Sampler::DepthStencilMode::value: return debug << "GL::Sampler::DepthStencilMode::" #value;
#define _c(value) case SamplerDepthStencilMode::value: return debug << "GL::SamplerDepthStencilMode::" #value;
_c(DepthComponent)
_c(StencilIndex)
#undef _c
/* LCOV_EXCL_STOP */
}
return debug << "GL::Sampler::DepthStencilMode(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")";
return debug << "GL::SamplerDepthStencilMode(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")";
}
#endif
#endif

576
src/Magnum/GL/Sampler.h

@ -26,7 +26,7 @@
*/
/** @file
* @brief Class @ref Magnum::GL::Sampler
* @brief Class @ref Magnum::GL::Sampler, enum @ref Magnum::GL::SamplerFilter, @ref Magnum::GL::SamplerMipmap, @ref Magnum::GL::SamplerWrapping, @ref Magnum::GL::SamplerCompareMode, @ref Magnum::GL::SamplerCompareFunction, @ref Magnum::GL::SamplerDepthStencilMode, function @ref Magnum::GL::samplerFilter(), @ref Magnum::GL::samplerMipmap(), @ref Magnum::GL::hasSamplerWrapping(), @ref Magnum::GL::samplerWrapping()
*/
#include "Magnum/Magnum.h"
@ -36,232 +36,301 @@
namespace Magnum { namespace GL {
/**
@brief Texture sampler
@brief Texture sampler filtering
@see @ref Texture, @ref TextureArray, @ref CubeMapTexture,
@ref CubeMapTextureArray, @ref RectangleTexture
@see @ref Magnum::SamplerFilter, @ref samplerFilter(),
@ref Texture::setMinificationFilter() "*Texture::setMinificationFilter()",
@ref Texture::setMagnificationFilter() "*Texture::setMagnificationFilter()"
@m_enum_values_as_keywords
*/
class MAGNUM_GL_EXPORT Sampler {
public:
/**
* @brief Texture filtering
*
* @see @ref Texture::setMinificationFilter() "*Texture::setMinificationFilter()",
* @ref Texture::setMagnificationFilter() "*Texture::setMagnificationFilter()"
* @m_enum_values_as_keywords
*/
enum class Filter: GLint {
Nearest = GL_NEAREST, /**< Nearest neighbor filtering */
/**
* Linear interpolation filtering. Can't be used with integer
* texture formats.
* @requires_es_extension Extension @extension{OES,texture_float_linear}
* for linear interpolation of textures with
* @ref TextureFormat::Float
* @requires_webgl_extension Extensiion @webgl_extension{OES,texture_float_linear}
* for linear interpolation of textures with
* @ref TextureFormat::Float
* @requires_gles30 Extension @extension2{OES,texture_half_float_linear,OES_texture_float_linear}
* for linear interpolation of textures with
* @ref TextureFormat::HalfFloat in OpenGL ES 2.0.
* @requires_webgl20 Extension @webgl_extension{OES,texture_half_float_linear}
* for linear interpolation of textures with
* @ref TextureFormat::HalfFloat in WebGL 1.0.
*/
Linear = GL_LINEAR
};
enum class SamplerFilter: GLint {
Nearest = GL_NEAREST, /**< Nearest neighbor filtering */
/**
* Linear interpolation filtering. Can't be used with integer
* texture formats.
* @requires_es_extension Extension @extension{OES,texture_float_linear}
* for linear interpolation of textures with
* @ref TextureFormat::Float
* @requires_webgl_extension Extensiion @webgl_extension{OES,texture_float_linear}
* for linear interpolation of textures with
* @ref TextureFormat::Float
* @requires_gles30 Extension @extension2{OES,texture_half_float_linear,OES_texture_float_linear}
* for linear interpolation of textures with
* @ref TextureFormat::HalfFloat in OpenGL ES 2.0.
* @requires_webgl20 Extension @webgl_extension{OES,texture_half_float_linear}
* for linear interpolation of textures with
* @ref TextureFormat::HalfFloat in WebGL 1.0.
*/
Linear = GL_LINEAR
};
/**
* @brief Mip level selection
*
* @see @ref Texture::setMinificationFilter() "*Texture::setMinificationFilter()"
*/
enum class Mipmap: GLint {
/**
* Select base mip level
* @m_keywords{GL_NEAREST}
*/
Base = GL_NEAREST & ~GL_NEAREST,
/**
* Select nearest mip level. **Unavailable on rectangle textures.**
* @m_keywords{GL_NEAREST_MIPMAP_NEAREST}
*/
Nearest = GL_NEAREST_MIPMAP_NEAREST & ~GL_NEAREST,
/**
* Linear interpolation of nearest mip levels. **Unavailable on
* rectangle textures.**
* @m_keywords{GL_NEAREST_MIPMAP_LINEAR}
* @requires_es_extension Extension @extension{OES,texture_float_linear}
* for linear interpolation of textures with
* @ref TextureFormat::Float
* @requires_webgl_extension Extensiion @webgl_extension{OES,texture_float_linear}
* for linear interpolation of textures with
* @ref TextureFormat::Float
* @requires_gles30 Extension @extension2{OES,texture_half_float_linear,OES_texture_float_linear}
* for linear interpolation of textures with
* @ref TextureFormat::HalfFloat in OpenGL ES 2.0.
* @requires_webgl20 Extension @webgl_extension{OES,texture_half_float_linear}
* for linear interpolation of textures with
* @ref TextureFormat::HalfFloat in WebGL 1.0.
*/
Linear = GL_NEAREST_MIPMAP_LINEAR & ~GL_NEAREST
};
/**
@brief Convert generic texture sampler filter mode to OpenGL filter mode
/**
* @brief Texture wrapping
*
* @see @ref Texture::setWrapping() "*Texture::setWrapping()"
* @m_enum_values_as_keywords
*/
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_WEBGL
/**
* Clamp to border color. Coordinates out of range will be clamped
* to border color (set with
* @ref Texture::setBorderColor() "*Texture::setBorderColor()").
* @requires_gles32 Extension @extension{ANDROID,extension_pack_es31a} /
* @extension{EXT,texture_border_clamp} or
* @extension{NV,texture_border_clamp}
* @requires_gles Border clamp is not available in WebGL.
*/
#ifndef MAGNUM_TARGET_GLES
ClampToBorder = GL_CLAMP_TO_BORDER,
#else
ClampToBorder = GL_CLAMP_TO_BORDER_EXT,
#endif
#endif
#ifndef MAGNUM_TARGET_GLES
/**
* Mirror the texture once in negative coordinates and clamp to
* edge after that. **Unavailable on rectangle textures.**
* @requires_gl44 Extension @extension{ARB,texture_mirror_clamp_to_edge},
* @extension{ATI,texture_mirror_once} or @extension{EXT,texture_mirror_clamp}
* @requires_gl Only separate @ref Wrapping::MirroredRepeat or
* @ref Wrapping::ClampToEdge is available in OpenGL ES and
* WebGL.
*/
MirrorClampToEdge = GL_MIRROR_CLAMP_TO_EDGE
#endif
};
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
/**
* @brief Depth texture comparison mode
*
* @see @ref CompareFunction,
* @ref Texture::setCompareMode() "*Texture::setCompareMode()"
* @m_enum_values_as_keywords
* @requires_gles30 Extension @extension{EXT,shadow_samplers} in
* OpenGL ES 2.0.
* @requires_webgl20 Depth texture comparison is not available in WebGL
* 1.0.
*/
enum class CompareMode: GLenum {
/** Directly output the depth value */
None = GL_NONE,
/** Use output from specified @ref CompareFunction */
CompareRefToTexture =
#ifndef MAGNUM_TARGET_GLES2
GL_COMPARE_REF_TO_TEXTURE
#else
GL_COMPARE_REF_TO_TEXTURE_EXT
#endif
};
@see @ref samplerMipmap(), @ref samplerWrapping()
*/
MAGNUM_GL_EXPORT SamplerFilter samplerFilter(Magnum::SamplerFilter filter);
/**
* @brief Depth texture comparison function
*
* Comparison operator used when comparison mode is set to
* @ref CompareMode::CompareRefToTexture.
* @see @ref Texture::setCompareFunction() "*Texture::setCompareFunction()",
* @ref Texture::setCompareMode() "*Texture::setCompareMode()"
* @m_enum_values_as_keywords
* @requires_gles30 Extension @extension{EXT,shadow_samplers} in
* OpenGL ES 2.0.
* @requires_webgl20 Depth texture comparison is not available in WebGL
* 1.0.
*/
enum class CompareFunction: GLenum {
Never = GL_NEVER, /**< Always @glsl 0.0 @ce */
Always = GL_ALWAYS, /**< Always @glsl 1.0 @ce */
/**
* @glsl 1.0 @ce when texture coordinate is less than depth value,
* @glsl 0.0 @ce otherwise
*/
Less = GL_LESS,
/**
* @glsl 1.0 @ce when texture coordinate is less than or equal to depth
* value, @glsl 0.0 @ce otherwise
*/
LessOrEqual = GL_LEQUAL,
/**
* @glsl 1.0 @ce when texture coordinate is equal to depth value,
* @glsl 0.0 @ce otherwise
*/
Equal = GL_EQUAL,
/**
* @glsl 0.0 @ce when texture coordinate is equal to depth value,
* @glsl 1.0 @ce otherwise
*/
NotEqual = GL_NOTEQUAL,
/**
* @glsl 1.0 @ce when texture coordinate is greater than or equal
* to depth value, @glsl 0.0 @ce otherwise
*/
GreaterOrEqual = GL_GEQUAL,
/**
* @glsl 1.0 @ce when texture coordinate is greater than depth
* value, @glsl 0.0 @ce otherwise
*/
Greater = GL_GREATER
};
#endif
/** @debugoperatorenum{SamplerFilter} */
MAGNUM_GL_EXPORT Debug& operator<<(Debug& debug, SamplerFilter value);
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
/**
* @brief Depth/stencil texture mode
*
* @see @ref Texture::setDepthStencilMode() "*Texture::setDepthStencilMode()"
* @m_enum_values_as_keywords
* @requires_gl43 Extension @extension{ARB,stencil_texturing}
* @requires_gles31 Stencil texturing is not available in OpenGL ES 3.0
* and older.
* @requires_gles Stencil texturing is not available in WebGL.
*/
enum class DepthStencilMode: GLenum {
/** Sample depth component */
DepthComponent = GL_DEPTH_COMPONENT,
/**
@brief Texture sampler mip level selection
@see @ref Magnum::SamplerMipmap, @ref samplerMipmap(),
@ref Texture::setMinificationFilter() "*Texture::setMinificationFilter()"
*/
enum class SamplerMipmap: GLint {
/**
* Select base mip level
* @m_keywords{GL_NEAREST GL_LINEAR}
*/
Base = GL_NEAREST & ~GL_NEAREST,
/**
* Select nearest mip level. **Unavailable on rectangle textures.**
* @m_keywords{GL_NEAREST_MIPMAP_NEAREST GL_LINEAR_MIPMAP_NEAREST}
*/
Nearest = GL_NEAREST_MIPMAP_NEAREST & ~GL_NEAREST,
/**
* Linear interpolation of nearest mip levels. **Unavailable on
* rectangle textures.**
* @m_keywords{GL_NEAREST_MIPMAP_LINEAR GL_LINEAR_MIPMAP_LINEAR}
* @requires_es_extension Extension @extension{OES,texture_float_linear}
* for linear interpolation of textures with
* @ref TextureFormat::Float
* @requires_webgl_extension Extensiion @webgl_extension{OES,texture_float_linear}
* for linear interpolation of textures with
* @ref TextureFormat::Float
* @requires_gles30 Extension @extension2{OES,texture_half_float_linear,OES_texture_float_linear}
* for linear interpolation of textures with
* @ref TextureFormat::HalfFloat in OpenGL ES 2.0.
* @requires_webgl20 Extension @webgl_extension{OES,texture_half_float_linear}
* for linear interpolation of textures with
* @ref TextureFormat::HalfFloat in WebGL 1.0.
*/
Linear = GL_NEAREST_MIPMAP_LINEAR & ~GL_NEAREST
};
/**
@brief Convert generic sampler filter mode to OpenGL filter mode
@see @ref samplerFilter(), @ref samplerWrapping()
*/
MAGNUM_GL_EXPORT SamplerMipmap samplerMipmap(Magnum::SamplerMipmap mipmap);
/** @debugoperatorenum{SamplerMipmap} */
MAGNUM_GL_EXPORT Debug& operator<<(Debug& debug, SamplerMipmap value);
/**
@brief Texture sampler wrapping
@see @ref Magnum::SamplerWrapping, @ref samplerWrapping(),
@ref Texture::setWrapping() "*Texture::setWrapping()"
@m_enum_values_as_keywords
*/
enum class SamplerWrapping: 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_WEBGL
/**
* Clamp to border color. Coordinates out of range will be clamped
* to border color (set with
* @ref Texture::setBorderColor() "*Texture::setBorderColor()").
* @requires_gles32 Extension @extension{ANDROID,extension_pack_es31a} /
* @extension{EXT,texture_border_clamp} or
* @extension{NV,texture_border_clamp}
* @requires_gles Border clamp is not available in WebGL.
*/
#ifndef MAGNUM_TARGET_GLES
ClampToBorder = GL_CLAMP_TO_BORDER,
#else
ClampToBorder = GL_CLAMP_TO_BORDER_EXT,
#endif
#endif
#ifndef MAGNUM_TARGET_GLES
/**
* Mirror the texture once in negative coordinates and clamp to
* edge after that. **Unavailable on rectangle textures.**
* @requires_gl44 Extension @extension{ARB,texture_mirror_clamp_to_edge},
* @extension{ATI,texture_mirror_once} or @extension{EXT,texture_mirror_clamp}
* @requires_gl Only separate @ref Wrapping::MirroredRepeat or
* @ref Wrapping::ClampToEdge is available in OpenGL ES and
* WebGL.
*/
MirrorClampToEdge = GL_MIRROR_CLAMP_TO_EDGE
#endif
};
/**
@brief Check availability of a generic sampler wrapping mode
Some OpenGL targets don't support all generic sampler wrapping modes (for
example the @ref SamplerWrapping::MirrorClampToEdge is not available in OpenGL
ES or WebGL). Returns @cpp false @ce if current target can't support such
format, @cpp true @ce otherwise. The @p filter value is expected to be valid.
@note Support of some formats depends on presence of a particular OpenGL
extension. Such check is outside of the scope of this function and you are
expected to verify extension availability before using such format.
/** Sample stencil index (as unsigned integer texture) */
StencilIndex = GL_STENCIL_INDEX
};
@see @ref samplerFilter(), @ref samplerMipmap()
*/
MAGNUM_GL_EXPORT bool hasSamplerWrapping(Magnum::SamplerWrapping wrappomg);
/**
@brief Convert generic sampler filter mode to OpenGL filter mode
Not all generic sampler wrapping modes may be available on all targets and this
function expects that given format is available on the target. Use
@ref hasSamplerWrapping() to query availability of given mode.
@see @ref samplerFilter(), @ref samplerMipmap()
*/
MAGNUM_GL_EXPORT SamplerWrapping samplerWrapping(Magnum::SamplerWrapping wrapping);
/** @overload */
template<UnsignedInt dimensions> Array<dimensions, SamplerWrapping> samplerWrapping(const Array<dimensions, Magnum::SamplerWrapping>& wrapping) {
Array<dimensions, SamplerWrapping> out; /** @todo NoInit */
for(std::size_t i = 0; i != dimensions; ++i)
out[i] = samplerWrapping(wrapping[i]);
return out;
}
/** @debugoperatorenum{SamplerWrapping} */
MAGNUM_GL_EXPORT Debug& operator<<(Debug& debug, SamplerWrapping value);
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
/**
@brief Depth texture comparison mode
@see @ref SamplerCompareFunction,
@ref Texture::setCompareMode() "*Texture::setCompareMode()"
@m_enum_values_as_keywords
@requires_gles30 Extension @extension{EXT,shadow_samplers} in
OpenGL ES 2.0.
@requires_webgl20 Depth texture comparison is not available in WebGL
1.0.
*/
enum class SamplerCompareMode: GLenum {
/** Directly output the depth value */
None = GL_NONE,
/** Use output from specified @ref SamplerCompareFunction */
CompareRefToTexture =
#ifndef MAGNUM_TARGET_GLES2
GL_COMPARE_REF_TO_TEXTURE
#else
GL_COMPARE_REF_TO_TEXTURE_EXT
#endif
};
/** @debugoperatorenum{SamplerCompareMode} */
MAGNUM_GL_EXPORT Debug& operator<<(Debug& debug, SamplerCompareMode value);
/**
@brief Texture sampler depth comparison function
Comparison operator used when comparison mode is set to
@ref SamplerCompareMode::CompareRefToTexture.
@see @ref Texture::setCompareFunction() "*Texture::setCompareFunction()",
@ref Texture::setCompareMode() "*Texture::setCompareMode()"
@m_enum_values_as_keywords
@requires_gles30 Extension @extension{EXT,shadow_samplers} in
OpenGL ES 2.0.
@requires_webgl20 Depth texture comparison is not available in WebGL
1.0.
*/
enum class SamplerCompareFunction: GLenum {
Never = GL_NEVER, /**< Always @glsl 0.0 @ce */
Always = GL_ALWAYS, /**< Always @glsl 1.0 @ce */
/**
* @glsl 1.0 @ce when texture coordinate is less than depth value,
* @glsl 0.0 @ce otherwise
*/
Less = GL_LESS,
/**
* @glsl 1.0 @ce when texture coordinate is less than or equal to depth
* value, @glsl 0.0 @ce otherwise
*/
LessOrEqual = GL_LEQUAL,
/**
* @glsl 1.0 @ce when texture coordinate is equal to depth value,
* @glsl 0.0 @ce otherwise
*/
Equal = GL_EQUAL,
/**
* @glsl 0.0 @ce when texture coordinate is equal to depth value,
* @glsl 1.0 @ce otherwise
*/
NotEqual = GL_NOTEQUAL,
/**
* @glsl 1.0 @ce when texture coordinate is greater than or equal
* to depth value, @glsl 0.0 @ce otherwise
*/
GreaterOrEqual = GL_GEQUAL,
/**
* @glsl 1.0 @ce when texture coordinate is greater than depth
* value, @glsl 0.0 @ce otherwise
*/
Greater = GL_GREATER
};
/** @debugoperatorenum{SamplerCompareFunction} */
MAGNUM_GL_EXPORT Debug& operator<<(Debug& debug, SamplerCompareFunction value);
#endif
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
/**
@brief Texture sampler depth/stencil mode
@see @ref Texture::setDepthStencilMode() "*Texture::setDepthStencilMode()"
@m_enum_values_as_keywords
@requires_gl43 Extension @extension{ARB,stencil_texturing}
@requires_gles31 Stencil texturing is not available in OpenGL ES 3.0
and older.
@requires_gles Stencil texturing is not available in WebGL.
*/
enum class SamplerDepthStencilMode: GLenum {
/** Sample depth component */
DepthComponent = GL_DEPTH_COMPONENT,
/** Sample stencil index (as unsigned integer texture) */
StencilIndex = GL_STENCIL_INDEX
};
/** @debugoperatorenum{SamplerDepthStencilMode} */
MAGNUM_GL_EXPORT Debug& operator<<(Debug& debug, SamplerDepthStencilMode value);
#endif
/**
@brief Texture sampler
@see @ref Texture, @ref TextureArray, @ref CubeMapTexture,
@ref CubeMapTextureArray, @ref RectangleTexture
*/
class MAGNUM_GL_EXPORT Sampler {
public:
/**
* @brief Max supported max anisotropy
*
@ -273,37 +342,58 @@ class MAGNUM_GL_EXPORT Sampler {
* @m_keywords{GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT}
*/
static Float maxMaxAnisotropy();
};
/** @debugoperatorclassenum{Sampler,Sampler::Filter} */
MAGNUM_GL_EXPORT Debug& operator<<(Debug& debug, Sampler::Filter value);
/** @debugoperatorclassenum{Sampler,Sampler::Mipmap} */
MAGNUM_GL_EXPORT Debug& operator<<(Debug& debug, Sampler::Mipmap value);
/** @debugoperatorclassenum{Sampler,Sampler::Wrapping} */
MAGNUM_GL_EXPORT Debug& operator<<(Debug& debug, Sampler::Wrapping value);
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
/** @debugoperatorclassenum{Sampler,Sampler::CompareMode} */
MAGNUM_GL_EXPORT Debug& operator<<(Debug& debug, Sampler::CompareMode value);
/** @debugoperatorclassenum{Sampler,Sampler::CompareFunction} */
MAGNUM_GL_EXPORT Debug& operator<<(Debug& debug, Sampler::CompareFunction value);
#endif
#ifndef MAGNUM_TARGET_GLES
/** @debugoperatorclassenum{Sampler,Sampler::DepthStencilMode} */
MAGNUM_GL_EXPORT Debug& operator<<(Debug& debug, Sampler::DepthStencilMode value);
#endif
/* This class is currently a placeholder for GL sampler objects */
};
}
#ifdef MAGNUM_BUILD_DEPRECATED
/** @brief @copybrief GL::Sampler
* @deprecated Use @ref GL::Sampler instead.
/** @brief Texture sampler
* @deprecated Use @ref GL::Sampler, @ref SamplerFilter, @ref GL::SamplerFilter, @ref SamplerMipmap, @ref GL::SamplerMipmap, @ref SamplerWrapping, @ref GL::SamplerWrapping, @ref GL::SamplerCompareMode, @ref GL::SamplerCompareFunction or @ref GL::SamplerDepthStencilMode instead.
*/
typedef CORRADE_DEPRECATED("use GL::Sampler instead") GL::Sampler Sampler;
struct CORRADE_DEPRECATED("use GL::Sampler, SamplerFilter, GL::SamplerFilter, SamplerMipmap, GL::SamplerMipmap, SamplerWrapping, GL::SamplerWrapping, GL::SamplerCompareMode, GL::SamplerCompareFunction or GL::SamplerDepthStencilMode instead") Sampler {
/** @brief @copybrief SamplerFilter
* @deprecated Use @ref SamplerFilter or @ref GL::SamplerFilter instead.
*/
typedef CORRADE_DEPRECATED("use SamplerFilter or GL::SamplerFilter instead") SamplerFilter Filter;
/** @brief @copybrief SamplerMipmap
* @deprecated Use @ref SamplerMipmap or @ref GL::SamplerMipmap instead.
*/
typedef CORRADE_DEPRECATED("use SamplerMipmap or GL::SamplerMipmap instead") SamplerMipmap Mipmap;
/** @brief @copybrief SamplerWrapping
* @deprecated Use @ref SamplerMipmap or @ref GL::SamplerWrapping instead.
*/
typedef CORRADE_DEPRECATED("use SamplerWrapping or GL::SamplerWrapping instead") SamplerWrapping Wrapping;
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
/** @brief @copybrief GL::SamplerCompareMode
* @deprecated Use @ref GL::SamplerCompareMode instead.
*/
typedef CORRADE_DEPRECATED("use GL::SamplerCompareMode instead") GL::SamplerCompareMode CompareMode;
/** @brief @copybrief GL::SamplerCompareFunction
* @deprecated Use @ref GL::SamplerCompareFunction instead.
*/
typedef CORRADE_DEPRECATED("use GL::SamplerCompareFunction instead") GL::SamplerCompareFunction CompareFunction;
#endif
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
/** @brief @copybrief GL::SamplerDepthStencilMode
* @deprecated Use @ref GL::SamplerDepthStencilMode instead.
*/
typedef CORRADE_DEPRECATED("use GL::SamplerDepthStencilMode instead") GL::SamplerDepthStencilMode DepthStencilMode;
#endif
/** @brief @copybrief GL::Sampler::maxMaxAnisotropy()
* @deprecated Use @ref GL::Sampler::maxMaxAnisotropy() instead.
*/
static Float maxMaxAnisotropy() {
return GL::Sampler::maxMaxAnisotropy();
}
};
#endif
}

2
src/Magnum/GL/Test/CMakeLists.txt

@ -34,7 +34,7 @@ corrade_add_test(GLMeshTest MeshTest.cpp LIBRARIES MagnumGLTestLib)
corrade_add_test(GLPixelFormatTest PixelFormatTest.cpp LIBRARIES MagnumGLTestLib)
corrade_add_test(GLRendererTest RendererTest.cpp LIBRARIES MagnumGL)
corrade_add_test(GLRenderbufferTest RenderbufferTest.cpp LIBRARIES MagnumGL)
corrade_add_test(GLSamplerTest SamplerTest.cpp LIBRARIES MagnumGL)
corrade_add_test(GLSamplerTest SamplerTest.cpp LIBRARIES MagnumGLTestLib)
corrade_add_test(GLShaderTest ShaderTest.cpp LIBRARIES MagnumGL)
corrade_add_test(GLTextureTest TextureTest.cpp LIBRARIES MagnumGL)
corrade_add_test(GLVersionTest VersionTest.cpp LIBRARIES MagnumGL)

29
src/Magnum/GL/Test/CubeMapTextureArrayGLTest.cpp

@ -48,7 +48,7 @@ struct CubeMapTextureArrayGLTest: OpenGLTester {
void bind();
void bindImage();
void sampling();
template<class T> void sampling();
void samplingSRGBDecode();
void samplingBorderInteger();
void samplingSwizzle();
@ -84,6 +84,17 @@ struct CubeMapTextureArrayGLTest: OpenGLTester {
};
namespace {
struct GenericSampler {
typedef Magnum::SamplerFilter Filter;
typedef Magnum::SamplerMipmap Mipmap;
typedef Magnum::SamplerWrapping Wrapping;
};
struct GLSampler {
typedef GL::SamplerFilter Filter;
typedef GL::SamplerMipmap Mipmap;
typedef GL::SamplerWrapping Wrapping;
};
constexpr UnsignedByte Data[]{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@ -270,7 +281,8 @@ CubeMapTextureArrayGLTest::CubeMapTextureArrayGLTest() {
&CubeMapTextureArrayGLTest::bind,
&CubeMapTextureArrayGLTest::bindImage,
&CubeMapTextureArrayGLTest::sampling,
&CubeMapTextureArrayGLTest::sampling<GenericSampler>,
&CubeMapTextureArrayGLTest::sampling<GLSampler>,
&CubeMapTextureArrayGLTest::samplingSRGBDecode,
&CubeMapTextureArrayGLTest::samplingBorderInteger,
&CubeMapTextureArrayGLTest::samplingSwizzle,
@ -415,7 +427,10 @@ void CubeMapTextureArrayGLTest::bindImage() {
#endif
}
void CubeMapTextureArrayGLTest::sampling() {
template<class T> void CubeMapTextureArrayGLTest::sampling() {
setTestCaseName(std::is_same<T, GenericSampler>::value ?
"sampling<GenericSampler>" : "sampling<GLSampler>");
#ifndef MAGNUM_TARGET_GLES
if(!Context::current().isExtensionSupported<Extensions::GL::ARB::texture_cube_map_array>())
CORRADE_SKIP(Extensions::GL::ARB::texture_cube_map_array::string() + std::string(" is not supported."));
@ -425,8 +440,8 @@ void CubeMapTextureArrayGLTest::sampling() {
#endif
CubeMapTextureArray texture;
texture.setMinificationFilter(Sampler::Filter::Linear, Sampler::Mipmap::Linear)
.setMagnificationFilter(Sampler::Filter::Linear)
texture.setMinificationFilter(T::Filter::Linear, T::Mipmap::Linear)
.setMagnificationFilter(T::Filter::Linear)
.setMinLod(-750.0f)
.setMaxLod(750.0f)
#ifndef MAGNUM_TARGET_GLES
@ -435,10 +450,10 @@ void CubeMapTextureArrayGLTest::sampling() {
.setBaseLevel(1)
.setMaxLevel(750)
#ifndef MAGNUM_TARGET_GLES
.setWrapping(Sampler::Wrapping::ClampToBorder)
.setWrapping(T::Wrapping::ClampToBorder)
.setBorderColor(Color3(0.5f))
#else
.setWrapping(Sampler::Wrapping::ClampToEdge)
.setWrapping(T::Wrapping::ClampToEdge)
#endif
.setMaxAnisotropy(Sampler::maxMaxAnisotropy())
.setCompareMode(Sampler::CompareMode::CompareRefToTexture)

31
src/Magnum/GL/Test/CubeMapTextureGLTest.cpp

@ -54,7 +54,7 @@ struct CubeMapTextureGLTest: OpenGLTester {
void bindImage();
#endif
void sampling();
template<class T> void sampling();
#ifndef MAGNUM_TARGET_WEBGL
void samplingSRGBDecode();
#endif
@ -120,6 +120,17 @@ struct CubeMapTextureGLTest: OpenGLTester {
};
namespace {
struct GenericSampler {
typedef Magnum::SamplerFilter Filter;
typedef Magnum::SamplerMipmap Mipmap;
typedef Magnum::SamplerWrapping Wrapping;
};
struct GLSampler {
typedef GL::SamplerFilter Filter;
typedef GL::SamplerMipmap Mipmap;
typedef GL::SamplerWrapping Wrapping;
};
constexpr UnsignedByte Data[]{
0, 0, 0, 0, 0, 0, 0, 0,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@ -297,7 +308,8 @@ CubeMapTextureGLTest::CubeMapTextureGLTest() {
&CubeMapTextureGLTest::bindImage,
#endif
&CubeMapTextureGLTest::sampling,
&CubeMapTextureGLTest::sampling<GenericSampler>,
&CubeMapTextureGLTest::sampling<GLSampler>,
#ifndef MAGNUM_TARGET_WEBGL
&CubeMapTextureGLTest::samplingSRGBDecode,
#endif
@ -453,24 +465,27 @@ void CubeMapTextureGLTest::bindImage() {
}
#endif
void CubeMapTextureGLTest::sampling() {
template<class T> void CubeMapTextureGLTest::sampling() {
setTestCaseName(std::is_same<T, GenericSampler>::value ?
"sampling<GenericSampler>" : "sampling<GLSampler>");
CubeMapTexture texture;
texture.setMinificationFilter(Sampler::Filter::Linear, Sampler::Mipmap::Linear)
.setMagnificationFilter(Sampler::Filter::Linear)
texture.setMinificationFilter(T::Filter::Linear, T::Mipmap::Linear)
.setMagnificationFilter(T::Filter::Linear)
#ifndef MAGNUM_TARGET_GLES2
.setMinLod(-750.0f)
.setMaxLod(750.0f)
#ifndef MAGNUM_TARGET_GLES
.setLodBias(0.5f)
.setLodBias(0.5f) /* todo both types */
#endif
.setBaseLevel(1)
.setMaxLevel(750)
#endif
#ifndef MAGNUM_TARGET_GLES
.setWrapping(Sampler::Wrapping::ClampToBorder)
.setWrapping(T::Wrapping::ClampToBorder)
.setBorderColor(Color3(0.5f))
#else
.setWrapping(Sampler::Wrapping::ClampToEdge)
.setWrapping(T::Wrapping::ClampToEdge)
#endif
.setMaxAnisotropy(Sampler::maxMaxAnisotropy())
#ifndef MAGNUM_TARGET_GLES2

25
src/Magnum/GL/Test/RectangleTextureGLTest.cpp

@ -50,7 +50,7 @@ struct RectangleTextureGLTest: OpenGLTester {
void bind();
void bindImage();
void sampling();
template<class T> void sampling();
void samplingSRGBDecode();
void samplingBorderInteger();
void samplingSwizzle();
@ -76,6 +76,15 @@ struct RectangleTextureGLTest: OpenGLTester {
};
namespace {
struct GenericSampler {
typedef Magnum::SamplerFilter Filter;
typedef Magnum::SamplerWrapping Wrapping;
};
struct GLSampler {
typedef GL::SamplerFilter Filter;
typedef GL::SamplerWrapping Wrapping;
};
constexpr UnsignedByte Data[]{
0, 0, 0, 0, 0, 0, 0, 0,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@ -108,7 +117,8 @@ RectangleTextureGLTest::RectangleTextureGLTest() {
&RectangleTextureGLTest::bind,
&RectangleTextureGLTest::bindImage,
&RectangleTextureGLTest::sampling,
&RectangleTextureGLTest::sampling<GenericSampler>,
&RectangleTextureGLTest::sampling<GLSampler>,
&RectangleTextureGLTest::samplingSRGBDecode,
&RectangleTextureGLTest::samplingBorderInteger,
&RectangleTextureGLTest::samplingSwizzle,
@ -215,14 +225,17 @@ void RectangleTextureGLTest::bindImage() {
MAGNUM_VERIFY_NO_ERROR();
}
void RectangleTextureGLTest::sampling() {
template<class T> void RectangleTextureGLTest::sampling() {
setTestCaseName(std::is_same<T, GenericSampler>::value ?
"sampling<GenericSampler>" : "sampling<GLSampler>");
if(!Context::current().isExtensionSupported<Extensions::GL::ARB::texture_rectangle>())
CORRADE_SKIP(Extensions::GL::ARB::texture_rectangle::string() + std::string(" is not supported."));
RectangleTexture texture;
texture.setMinificationFilter(Sampler::Filter::Linear)
.setMagnificationFilter(Sampler::Filter::Linear)
.setWrapping(Sampler::Wrapping::ClampToBorder)
texture.setMinificationFilter(T::Filter::Linear)
.setMagnificationFilter(T::Filter::Linear)
.setWrapping(T::Wrapping::ClampToBorder)
.setBorderColor(Color3(0.5f))
.setMaxAnisotropy(Sampler::maxMaxAnisotropy())
.setCompareMode(Sampler::CompareMode::CompareRefToTexture)

123
src/Magnum/GL/Test/SamplerTest.cpp

@ -27,12 +27,21 @@
#include <Corrade/TestSuite/Tester.h>
#include "Magnum/Sampler.h"
#include "Magnum/GL/Sampler.h"
namespace Magnum { namespace Test {
namespace Magnum { namespace GL { namespace Test {
struct SamplerTest: TestSuite::Tester {
explicit SamplerTest();
void mapFilter();
void mapFilterInvalid();
void mapMipmap();
void mapMipmapInvalid();
void mapWrapping();
void mapWrappingInvalid();
void mapWrappingUnsupported();
void debugFilter();
void debugMipmap();
void debugWrapping();
@ -46,7 +55,15 @@ struct SamplerTest: TestSuite::Tester {
};
SamplerTest::SamplerTest() {
addTests({&SamplerTest::debugFilter,
addTests({&SamplerTest::mapFilter,
&SamplerTest::mapFilterInvalid,
&SamplerTest::mapMipmap,
&SamplerTest::mapMipmapInvalid,
&SamplerTest::mapWrapping,
&SamplerTest::mapWrappingInvalid,
&SamplerTest::mapWrappingUnsupported,
&SamplerTest::debugFilter,
&SamplerTest::debugMipmap,
&SamplerTest::debugWrapping,
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
@ -59,40 +76,114 @@ SamplerTest::SamplerTest() {
});
}
void SamplerTest::mapFilter() {
CORRADE_COMPARE(samplerFilter(Magnum::SamplerFilter::Nearest), SamplerFilter::Nearest);
CORRADE_COMPARE(samplerFilter(Magnum::SamplerFilter::Linear), SamplerFilter::Linear);
}
void SamplerTest::mapFilterInvalid() {
std::ostringstream out;
Error redirectError{&out};
samplerFilter(Magnum::SamplerFilter(0x123));
CORRADE_COMPARE(out.str(),
"GL::samplerFilter(): invalid filter SamplerFilter(0x123)\n");
}
void SamplerTest::mapMipmap() {
CORRADE_COMPARE(samplerMipmap(Magnum::SamplerMipmap::Base), SamplerMipmap::Base);
CORRADE_COMPARE(samplerMipmap(Magnum::SamplerMipmap::Nearest), SamplerMipmap::Nearest);
CORRADE_COMPARE(samplerMipmap(Magnum::SamplerMipmap::Linear), SamplerMipmap::Linear);
}
void SamplerTest::mapMipmapInvalid() {
std::ostringstream out;
Error redirectError{&out};
samplerMipmap(Magnum::SamplerMipmap(0x123));
CORRADE_COMPARE(out.str(),
"GL::samplerMipmap(): invalid filter SamplerMipmap(0x123)\n");
}
void SamplerTest::mapWrapping() {
CORRADE_VERIFY(hasSamplerWrapping(Magnum::SamplerWrapping::Repeat));
CORRADE_COMPARE(samplerWrapping(Magnum::SamplerWrapping::Repeat), SamplerWrapping::Repeat);
CORRADE_VERIFY(hasSamplerWrapping(Magnum::SamplerWrapping::MirroredRepeat));
CORRADE_COMPARE(samplerWrapping(Magnum::SamplerWrapping::MirroredRepeat), SamplerWrapping::MirroredRepeat);
CORRADE_VERIFY(hasSamplerWrapping(Magnum::SamplerWrapping::ClampToEdge));
CORRADE_COMPARE(samplerWrapping(Magnum::SamplerWrapping::ClampToEdge), SamplerWrapping::ClampToEdge);
#ifndef MAGNUM_TARGET_WEBGL
CORRADE_VERIFY(hasSamplerWrapping(Magnum::SamplerWrapping::ClampToBorder));
CORRADE_COMPARE(samplerWrapping(Magnum::SamplerWrapping::ClampToBorder), SamplerWrapping::ClampToBorder);
#endif
#ifndef MAGNUM_TARGET_GLES
CORRADE_VERIFY(hasSamplerWrapping(Magnum::SamplerWrapping::MirrorClampToEdge));
CORRADE_COMPARE(samplerWrapping(Magnum::SamplerWrapping::MirrorClampToEdge), SamplerWrapping::MirrorClampToEdge);
#endif
}
void SamplerTest::mapWrappingInvalid() {
std::ostringstream out;
Error redirectError{&out};
hasSamplerWrapping(Magnum::SamplerWrapping(0x123));
samplerWrapping(Magnum::SamplerWrapping(0x123));
CORRADE_COMPARE(out.str(),
"GL::hasSamplerWrapping(): invalid wrapping SamplerWrapping(0x123)\n"
"GL::samplerWrapping(): invalid wrapping SamplerWrapping(0x123)\n");
}
void SamplerTest::mapWrappingUnsupported() {
#ifndef MAGNUM_TARGET_GLES
CORRADE_SKIP("All pixel formats are supported on desktop");
#else
std::ostringstream out;
Error redirectError{&out};
samplerWrapping(Magnum::SamplerWrapping::MirrorClampToEdge);
CORRADE_COMPARE(out.str(),
"GL::samplerWrapping(): wrapping SamplerWrapping::MirrorClampToEdge is not supported on this target\n");
#endif
}
void SamplerTest::debugFilter() {
std::ostringstream out;
Debug(&out) << Sampler::Filter::Linear << Sampler::Filter(0xdead);
CORRADE_COMPARE(out.str(), "GL::Sampler::Filter::Linear GL::Sampler::Filter(0xdead)\n");
Debug(&out) << SamplerFilter::Linear << SamplerFilter(0xdead);
CORRADE_COMPARE(out.str(), "GL::SamplerFilter::Linear GL::SamplerFilter(0xdead)\n");
}
void SamplerTest::debugMipmap() {
std::ostringstream out;
Debug(&out) << Sampler::Mipmap::Base << Sampler::Mipmap(0xdead);
CORRADE_COMPARE(out.str(), "GL::Sampler::Mipmap::Base GL::Sampler::Mipmap(0xdead)\n");
Debug(&out) << SamplerMipmap::Base << SamplerMipmap(0xdead);
CORRADE_COMPARE(out.str(), "GL::SamplerMipmap::Base GL::SamplerMipmap(0xdead)\n");
}
void SamplerTest::debugWrapping() {
std::ostringstream out;
Debug(&out) << Sampler::Wrapping::ClampToEdge << Sampler::Wrapping(0xdead);
CORRADE_COMPARE(out.str(), "GL::Sampler::Wrapping::ClampToEdge GL::Sampler::Wrapping(0xdead)\n");
Debug(&out) << SamplerWrapping::ClampToEdge << SamplerWrapping(0xdead);
CORRADE_COMPARE(out.str(), "GL::SamplerWrapping::ClampToEdge GL::SamplerWrapping(0xdead)\n");
}
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
void SamplerTest::debugCompareMode() {
std::ostringstream out;
Debug(&out) << Sampler::CompareMode::CompareRefToTexture << Sampler::CompareMode(0xdead);
CORRADE_COMPARE(out.str(), "GL::Sampler::CompareMode::CompareRefToTexture GL::Sampler::CompareMode(0xdead)\n");
Debug(&out) << SamplerCompareMode::CompareRefToTexture << SamplerCompareMode(0xdead);
CORRADE_COMPARE(out.str(), "GL::SamplerCompareMode::CompareRefToTexture GL::SamplerCompareMode(0xdead)\n");
}
void SamplerTest::debugCompareFunction() {
std::ostringstream out;
Debug(&out) << Sampler::CompareFunction::GreaterOrEqual << Sampler::CompareFunction(0xdead);
CORRADE_COMPARE(out.str(), "GL::Sampler::CompareFunction::GreaterOrEqual GL::Sampler::CompareFunction(0xdead)\n");
Debug(&out) << SamplerCompareFunction::GreaterOrEqual << SamplerCompareFunction(0xdead);
CORRADE_COMPARE(out.str(), "GL::SamplerCompareFunction::GreaterOrEqual GL::SamplerCompareFunction(0xdead)\n");
}
#endif
@ -100,11 +191,11 @@ void SamplerTest::debugCompareFunction() {
void SamplerTest::debugDepthStencilMode() {
std::ostringstream out;
Debug(&out) << Sampler::DepthStencilMode::StencilIndex << Sampler::DepthStencilMode(0xdead);
CORRADE_COMPARE(out.str(), "GL::Sampler::DepthStencilMode::StencilIndex GL::Sampler::DepthStencilMode(0xdead)\n");
Debug(&out) << SamplerDepthStencilMode::StencilIndex << SamplerDepthStencilMode(0xdead);
CORRADE_COMPARE(out.str(), "GL::SamplerDepthStencilMode::StencilIndex GL::SamplerDepthStencilMode(0xdead)\n");
}
#endif
}}
}}}
CORRADE_TEST_MAIN(Magnum::Test::SamplerTest)
CORRADE_TEST_MAIN(Magnum::GL::Test::SamplerTest)

45
src/Magnum/GL/Test/TextureArrayGLTest.cpp

@ -65,9 +65,9 @@ struct TextureArrayGLTest: OpenGLTester {
#endif
#ifndef MAGNUM_TARGET_GLES
void sampling1D();
template<class T> void sampling1D();
#endif
void sampling2D();
template<class T> void sampling2D();
#ifndef MAGNUM_TARGET_GLES
void samplingSRGBDecode1D();
@ -149,6 +149,17 @@ struct TextureArrayGLTest: OpenGLTester {
};
namespace {
struct GenericSampler {
typedef Magnum::SamplerFilter Filter;
typedef Magnum::SamplerMipmap Mipmap;
typedef Magnum::SamplerWrapping Wrapping;
};
struct GLSampler {
typedef GL::SamplerFilter Filter;
typedef GL::SamplerMipmap Mipmap;
typedef GL::SamplerWrapping Wrapping;
};
#ifndef MAGNUM_TARGET_GLES
constexpr UnsignedByte Data1D[]{
0, 0, 0, 0, 0, 0, 0, 0,
@ -269,9 +280,11 @@ TextureArrayGLTest::TextureArrayGLTest() {
#endif
#ifndef MAGNUM_TARGET_GLES
&TextureArrayGLTest::sampling1D,
&TextureArrayGLTest::sampling1D<GenericSampler>,
&TextureArrayGLTest::sampling1D<GLSampler>,
#endif
&TextureArrayGLTest::sampling2D,
&TextureArrayGLTest::sampling2D<GenericSampler>,
&TextureArrayGLTest::sampling2D<GLSampler>,
#ifndef MAGNUM_TARGET_GLES
&TextureArrayGLTest::samplingSRGBDecode1D,
@ -541,19 +554,22 @@ void TextureArrayGLTest::bindImage2D() {
#endif
#ifndef MAGNUM_TARGET_GLES
void TextureArrayGLTest::sampling1D() {
template<class T> void TextureArrayGLTest::sampling1D() {
setTestCaseName(std::is_same<T, GenericSampler>::value ?
"sampling1D<GenericSampler>" : "sampling1D<GLSampler>");
if(!Context::current().isExtensionSupported<Extensions::GL::EXT::texture_array>())
CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported."));
Texture1DArray texture;
texture.setMinificationFilter(Sampler::Filter::Linear, Sampler::Mipmap::Linear)
.setMagnificationFilter(Sampler::Filter::Linear)
texture.setMinificationFilter(T::Filter::Linear, T::Mipmap::Linear)
.setMagnificationFilter(T::Filter::Linear)
.setMinLod(-750.0f)
.setMaxLod(750.0f)
.setLodBias(0.5f)
.setBaseLevel(1)
.setMaxLevel(750)
.setWrapping(Sampler::Wrapping::ClampToBorder)
.setWrapping(T::Wrapping::ClampToBorder)
.setBorderColor(Color3(0.5f))
.setMaxAnisotropy(Sampler::maxMaxAnisotropy())
.setCompareMode(Sampler::CompareMode::CompareRefToTexture)
@ -615,15 +631,18 @@ void TextureArrayGLTest::samplingDepthStencilMode1D() {
}
#endif
void TextureArrayGLTest::sampling2D() {
template<class T> void TextureArrayGLTest::sampling2D() {
setTestCaseName(std::is_same<T, GenericSampler>::value ?
"sampling2D<GenericSampler>" : "sampling2D<GLSampler>");
#ifndef MAGNUM_TARGET_GLES
if(!Context::current().isExtensionSupported<Extensions::GL::EXT::texture_array>())
CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported."));
#endif
Texture2DArray texture;
texture.setMinificationFilter(Sampler::Filter::Linear, Sampler::Mipmap::Linear)
.setMagnificationFilter(Sampler::Filter::Linear)
texture.setMinificationFilter(T::Filter::Linear, T::Mipmap::Linear)
.setMagnificationFilter(T::Filter::Linear)
#ifndef MAGNUM_TARGET_GLES2
.setMinLod(-750.0f)
.setMaxLod(750.0f)
@ -634,10 +653,10 @@ void TextureArrayGLTest::sampling2D() {
.setMaxLevel(750)
#endif
#ifndef MAGNUM_TARGET_GLES
.setWrapping(Sampler::Wrapping::ClampToBorder)
.setWrapping(T::Wrapping::ClampToBorder)
.setBorderColor(Color3(0.5f))
#else
.setWrapping(Sampler::Wrapping::ClampToEdge)
.setWrapping(T::Wrapping::ClampToEdge)
#endif
.setMaxAnisotropy(Sampler::maxMaxAnisotropy())
#ifndef MAGNUM_TARGET_GLES

63
src/Magnum/GL/Test/TextureGLTest.cpp

@ -79,11 +79,11 @@ struct TextureGLTest: OpenGLTester {
#endif
#ifndef MAGNUM_TARGET_GLES
void sampling1D();
template<class T> void sampling1D();
#endif
void sampling2D();
template<class T> void sampling2D();
#if !(defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL))
void sampling3D();
template<class T> void sampling3D();
#endif
#ifndef MAGNUM_TARGET_WEBGL
@ -232,6 +232,17 @@ struct TextureGLTest: OpenGLTester {
};
namespace {
struct GenericSampler {
typedef Magnum::SamplerFilter Filter;
typedef Magnum::SamplerMipmap Mipmap;
typedef Magnum::SamplerWrapping Wrapping;
};
struct GLSampler {
typedef GL::SamplerFilter Filter;
typedef GL::SamplerMipmap Mipmap;
typedef GL::SamplerWrapping Wrapping;
};
#ifndef MAGNUM_TARGET_GLES
constexpr UnsignedByte Data1D[]{
0, 0, 0, 0,
@ -452,11 +463,14 @@ TextureGLTest::TextureGLTest() {
#endif
#ifndef MAGNUM_TARGET_GLES
&TextureGLTest::sampling1D,
&TextureGLTest::sampling1D<GenericSampler>,
&TextureGLTest::sampling1D<GLSampler>,
#endif
&TextureGLTest::sampling2D,
&TextureGLTest::sampling2D<GenericSampler>,
&TextureGLTest::sampling2D<GLSampler>,
#if !(defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL))
&TextureGLTest::sampling3D,
&TextureGLTest::sampling3D<GenericSampler>,
&TextureGLTest::sampling3D<GLSampler>,
#endif
#ifndef MAGNUM_TARGET_WEBGL
@ -869,16 +883,19 @@ void TextureGLTest::bindImage3D() {
#endif
#ifndef MAGNUM_TARGET_GLES
void TextureGLTest::sampling1D() {
template<class T> void TextureGLTest::sampling1D() {
setTestCaseName(std::is_same<T, GenericSampler>::value ?
"sampling1D<GenericSampler>" : "sampling1D<GLSampler>");
Texture1D texture;
texture.setMinificationFilter(Sampler::Filter::Linear, Sampler::Mipmap::Linear)
.setMagnificationFilter(Sampler::Filter::Linear)
texture.setMinificationFilter(T::Filter::Linear, T::Mipmap::Linear)
.setMagnificationFilter(T::Filter::Linear)
.setMinLod(-750.0f)
.setMaxLod(750.0f)
.setLodBias(0.5f)
.setBaseLevel(1)
.setMaxLevel(750)
.setWrapping(Sampler::Wrapping::ClampToBorder)
.setWrapping(T::Wrapping::ClampToBorder)
.setBorderColor(Color3(0.5f))
.setMaxAnisotropy(Sampler::maxMaxAnisotropy())
.setCompareMode(Sampler::CompareMode::CompareRefToTexture)
@ -932,10 +949,13 @@ void TextureGLTest::samplingDepthStencilMode1D() {
}
#endif
void TextureGLTest::sampling2D() {
template<class T> void TextureGLTest::sampling2D() {
setTestCaseName(std::is_same<T, GenericSampler>::value ?
"sampling2D<GenericSampler>" : "sampling2D<GLSampler>");
Texture2D texture;
texture.setMinificationFilter(Sampler::Filter::Linear, Sampler::Mipmap::Linear)
.setMagnificationFilter(Sampler::Filter::Linear)
texture.setMinificationFilter(T::Filter::Linear, T::Mipmap::Linear)
.setMagnificationFilter(T::Filter::Linear)
#ifndef MAGNUM_TARGET_GLES2
.setMinLod(-750.0f)
.setMaxLod(750.0f)
@ -946,10 +966,10 @@ void TextureGLTest::sampling2D() {
.setMaxLevel(750)
#endif
#ifndef MAGNUM_TARGET_GLES
.setWrapping(Sampler::Wrapping::ClampToBorder)
.setWrapping(T::Wrapping::ClampToBorder)
.setBorderColor(Color3(0.5f))
#else
.setWrapping(Sampler::Wrapping::ClampToEdge)
.setWrapping(T::Wrapping::ClampToEdge)
#endif
.setMaxAnisotropy(Sampler::maxMaxAnisotropy())
#ifndef MAGNUM_TARGET_GLES2
@ -1065,15 +1085,18 @@ void TextureGLTest::samplingBorder2D() {
#endif
#if !(defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL))
void TextureGLTest::sampling3D() {
template<class T> void TextureGLTest::sampling3D() {
setTestCaseName(std::is_same<T, GenericSampler>::value ?
"sampling3D<GenericSampler>" : "sampling3D<GLSampler>");
#ifdef MAGNUM_TARGET_GLES2
if(!Context::current().isExtensionSupported<Extensions::GL::OES::texture_3D>())
CORRADE_SKIP(Extensions::GL::OES::texture_3D::string() + std::string(" is not supported."));
#endif
Texture3D texture;
texture.setMinificationFilter(Sampler::Filter::Linear, Sampler::Mipmap::Linear)
.setMagnificationFilter(Sampler::Filter::Linear)
texture.setMinificationFilter(T::Filter::Linear, T::Mipmap::Linear)
.setMagnificationFilter(T::Filter::Linear)
#ifndef MAGNUM_TARGET_GLES2
.setMinLod(-750.0f)
.setMaxLod(750.0f)
@ -1084,10 +1107,10 @@ void TextureGLTest::sampling3D() {
.setMaxLevel(750)
#endif
#ifndef MAGNUM_TARGET_GLES
.setWrapping(Sampler::Wrapping::ClampToBorder)
.setWrapping(T::Wrapping::ClampToBorder)
.setBorderColor(Color3(0.5f))
#else
.setWrapping(Sampler::Wrapping::ClampToEdge)
.setWrapping(T::Wrapping::ClampToEdge)
#endif
.setMaxAnisotropy(Sampler::maxMaxAnisotropy());

51
src/Magnum/GL/Texture.h

@ -30,8 +30,10 @@
*/
#include "Magnum/Array.h"
#include "Magnum/Sampler.h"
#include "Magnum/DimensionTraits.h"
#include "Magnum/GL/AbstractTexture.h"
#include "Magnum/GL/Sampler.h"
#include "Magnum/Math/Vector3.h"
namespace Magnum { namespace GL {
@ -328,7 +330,7 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
* @brief Set minification filter
* @param filter Filter
* @param mipmap Mipmap filtering. If set to anything else than
* @ref Sampler::Mipmap::Base, make sure textures for all mip
* @ref SamplerMipmap::Base, make sure textures for all mip
* levels are set or call @ref generateMipmap().
* @return Reference to self (for method chaining)
*
@ -336,19 +338,24 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
* texture size. If neither @extension{ARB,direct_state_access} (part
* of OpenGL 4.5) nor @extension{EXT,direct_state_access} desktop
* extension is available, the texture is bound before the operation
* (if not already). Initial value is {@ref Sampler::Filter::Nearest,
* @ref Sampler::Mipmap::Linear}.
* (if not already). Initial value is {@ref SamplerFilter::Nearest,
* @ref SamplerMipmap::Linear}.
* @see @ref setMagnificationFilter(), @ref setBaseLevel(),
* @ref setMaxLevel(), @fn_gl2_keyword{TextureParameter,TexParameter},
* @fn_gl_extension_keyword{TextureParameter,EXT,direct_state_access},
* eventually @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and
* @fn_gl_keyword{TexParameter} with @def_gl_keyword{TEXTURE_MIN_FILTER}
*/
Texture<dimensions>& setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap = Sampler::Mipmap::Base) {
Texture<dimensions>& setMinificationFilter(SamplerFilter filter, SamplerMipmap mipmap = SamplerMipmap::Base) {
AbstractTexture::setMinificationFilter(filter, mipmap);
return *this;
}
/** @overload */
Texture<dimensions>& setMinificationFilter(Magnum::SamplerFilter filter, Magnum::SamplerMipmap mipmap = Magnum::SamplerMipmap::Base) {
return setMinificationFilter(samplerFilter(filter), samplerMipmap(mipmap));
}
/**
* @brief Set magnification filter
* @param filter Filter
@ -358,17 +365,22 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
* texture size. If neither @extension{ARB,direct_state_access} (part
* of OpenGL 4.5) nor @extension{EXT,direct_state_access} desktop
* extension is available, the texture is bound before the operation
* (if not already). Initial value is @ref Sampler::Filter::Linear.
* (if not already). Initial value is @ref SamplerFilter::Linear.
* @see @ref setMinificationFilter(), @fn_gl2_keyword{TextureParameter,TexParameter},
* @fn_gl_extension_keyword{TextureParameter,EXT,direct_state_access},
* eventually @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and
* @fn_gl_keyword{TexParameter} with @def_gl_keyword{TEXTURE_MAG_FILTER}
*/
Texture<dimensions>& setMagnificationFilter(Sampler::Filter filter) {
Texture<dimensions>& setMagnificationFilter(SamplerFilter filter) {
AbstractTexture::setMagnificationFilter(filter);
return *this;
}
/** @overload */
Texture<dimensions>& setMagnificationFilter(Magnum::SamplerFilter filter) {
return setMagnificationFilter(samplerFilter(filter));
}
#ifndef MAGNUM_TARGET_GLES2
/**
* @brief Set minimum level-of-detail parameter
@ -450,24 +462,29 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
* If neither @extension{ARB,direct_state_access} (part of OpenGL 4.5)
* nor @extension{EXT,direct_state_access} desktop extension is
* available, the texture is bound before the operation (if not
* already). Initial value is @ref Sampler::Wrapping::Repeat.
* already). Initial value is @ref SamplerWrapping::Repeat.
* @see @ref setBorderColor(), @fn_gl2_keyword{TextureParameter,TexParameter},
* @fn_gl_extension_keyword{TextureParameter,EXT,direct_state_access},
* eventually @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and
* @fn_gl_keyword{TexParameter} with @def_gl_keyword{TEXTURE_WRAP_S},
* @def_gl_keyword{TEXTURE_WRAP_T}, @def_gl_keyword{TEXTURE_WRAP_R}
*/
Texture<dimensions>& setWrapping(const Array<dimensions, Sampler::Wrapping>& wrapping) {
Texture<dimensions>& setWrapping(const Array<dimensions, SamplerWrapping>& wrapping) {
DataHelper<dimensions>::setWrapping(*this, wrapping);
return *this;
}
/** @overload */
Texture<dimensions>& setWrapping(const Array<dimensions, Magnum::SamplerWrapping>& wrapping) {
return setWrapping(samplerWrapping(wrapping));
}
#ifndef MAGNUM_TARGET_WEBGL
/**
* @brief Set border color
* @return Reference to self (for method chaining)
*
* Border color when wrapping is set to @ref Sampler::Wrapping::ClampToBorder.
* Border color when wrapping is set to @ref SamplerWrapping::ClampToBorder.
* If neither @extension{ARB,direct_state_access} (part of OpenGL 4.5)
* nor @extension{EXT,direct_state_access} is available, the texture is
* bound before the operation (if not already). Initial value is
@ -492,7 +509,7 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
* @return Reference to self (for method chaining)
*
* Border color for integer textures when wrapping is set to
* @ref Sampler::Wrapping::ClampToBorder. If neither
* @ref SamplerWrapping::ClampToBorder. If neither
* @extension{ARB,direct_state_access} (part of OpenGL 4.5) nor
* @extension{EXT,direct_state_access} is available, the texture is
* bound before the operation (if not already). Initial value is
@ -616,7 +633,7 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
* If neither @extension{ARB,direct_state_access} (part of OpenGL 4.5)
* nor @extension{EXT,direct_state_access} desktop extension is
* available, the texture is bound before the operation (if not
* already). Initial value is @ref Sampler::CompareMode::None.
* already). Initial value is @ref SamplerCompareMode::None.
* @note Depth textures can be only 1D or 2D.
* @see @ref setCompareFunction(), @fn_gl2_keyword{TextureParameter,TexParameter},
* @fn_gl_extension_keyword{TextureParameter,EXT,direct_state_access},
@ -627,7 +644,7 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
* @requires_webgl20 Depth texture comparison is not available in WebGL
* 1.0.
*/
Texture<dimensions>& setCompareMode(Sampler::CompareMode mode) {
Texture<dimensions>& setCompareMode(SamplerCompareMode mode) {
AbstractTexture::setCompareMode(mode);
return *this;
}
@ -637,11 +654,11 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
* @return Reference to self (for method chaining)
*
* Comparison operator used when comparison mode is set to
* @ref Sampler::CompareMode::CompareRefToTexture. If neither
* @ref SamplerCompareMode::CompareRefToTexture. If neither
* @extension{ARB,direct_state_access} (part of OpenGL 4.5) nor
* @extension{EXT,direct_state_access} desktop extension is available,
* the texture is bound before the operation (if not already). Initial
* value is @ref Sampler::CompareFunction::LessOrEqual.
* value is @ref SamplerCompareFunction::LessOrEqual.
* @note Depth textures can be only 1D or 2D.
* @see @ref setCompareMode(), @fn_gl2_keyword{TextureParameter,TexParameter},
* @fn_gl_extension_keyword{TextureParameter,EXT,direct_state_access},
@ -652,7 +669,7 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
* @requires_webgl20 Depth texture comparison is not available in WebGL
* 1.0.
*/
Texture<dimensions>& setCompareFunction(Sampler::CompareFunction function) {
Texture<dimensions>& setCompareFunction(SamplerCompareFunction function) {
AbstractTexture::setCompareFunction(function);
return *this;
}
@ -667,7 +684,7 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
* texturing. If neither @extension{ARB,direct_state_access} (part of
* OpenGL 4.5) nor @extension{EXT,direct_state_access} is available,
* the texture is bound before the operation (if not already). Initial
* value is @ref Sampler::DepthStencilMode::DepthComponent.
* value is @ref SamplerDepthStencilMode::DepthComponent.
* @note Depth textures can be only 1D or 2D.
* @see @fn_gl2_keyword{TextureParameter,TexParameter},
* @fn_gl_extension_keyword{TextureParameter,EXT,direct_state_access},
@ -678,7 +695,7 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
* and older.
* @requires_gles Stencil texturing is not available in WebGL.
*/
Texture<dimensions>& setDepthStencilMode(Sampler::DepthStencilMode mode) {
Texture<dimensions>& setDepthStencilMode(SamplerDepthStencilMode mode) {
AbstractTexture::setDepthStencilMode(mode);
return *this;
}

29
src/Magnum/GL/TextureArray.h

@ -32,8 +32,10 @@
#endif
#include "Magnum/Array.h"
#include "Magnum/Sampler.h"
#include "Magnum/DimensionTraits.h"
#include "Magnum/GL/AbstractTexture.h"
#include "Magnum/GL/Sampler.h"
#include "Magnum/Math/Vector3.h"
#ifndef MAGNUM_TARGET_GLES2
@ -248,22 +250,32 @@ template<UnsignedInt dimensions> class TextureArray: public AbstractTexture {
*
* See @ref Texture::setMinificationFilter() for more information.
*/
TextureArray<dimensions>& setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap = Sampler::Mipmap::Base) {
TextureArray<dimensions>& setMinificationFilter(SamplerFilter filter, SamplerMipmap mipmap = SamplerMipmap::Base) {
AbstractTexture::setMinificationFilter(filter, mipmap);
return *this;
}
/** @overload */
TextureArray<dimensions>& setMinificationFilter(Magnum::SamplerFilter filter, Magnum::SamplerMipmap mipmap = Magnum::SamplerMipmap::Base) {
return setMinificationFilter(samplerFilter(filter), samplerMipmap(mipmap));
}
/**
* @brief @copybrief Texture::setMagnificationFilter()
* @return Reference to self (for method chaining)
*
* See @ref Texture::setMagnificationFilter() for more information.
*/
TextureArray<dimensions>& setMagnificationFilter(Sampler::Filter filter) {
TextureArray<dimensions>& setMagnificationFilter(SamplerFilter filter) {
AbstractTexture::setMagnificationFilter(filter);
return *this;
}
/** @overload */
TextureArray<dimensions>& setMagnificationFilter(Magnum::SamplerFilter filter) {
return setMagnificationFilter(samplerFilter(filter));
}
/**
* @brief @copybrief Texture::setMinLod()
* @return Reference to self (for method chaining)
@ -307,11 +319,16 @@ template<UnsignedInt dimensions> class TextureArray: public AbstractTexture {
*
* See @ref Texture::setWrapping() for more information.
*/
TextureArray<dimensions>& setWrapping(const Array<dimensions, Sampler::Wrapping>& wrapping) {
TextureArray<dimensions>& setWrapping(const Array<dimensions, SamplerWrapping>& wrapping) {
DataHelper<dimensions>::setWrapping(*this, wrapping);
return *this;
}
/** @overload */
TextureArray<dimensions>& setWrapping(const Array<dimensions, Magnum::SamplerWrapping>& wrapping) {
return setWrapping(samplerWrapping(wrapping));
}
#ifndef MAGNUM_TARGET_WEBGL
/**
* @brief @copybrief Texture::setBorderColor(const Color4&)
@ -403,7 +420,7 @@ template<UnsignedInt dimensions> class TextureArray: public AbstractTexture {
*
* See @ref Texture::setCompareMode() for more information.
*/
TextureArray<dimensions>& setCompareMode(Sampler::CompareMode mode) {
TextureArray<dimensions>& setCompareMode(SamplerCompareMode mode) {
AbstractTexture::setCompareMode(mode);
return *this;
}
@ -414,7 +431,7 @@ template<UnsignedInt dimensions> class TextureArray: public AbstractTexture {
*
* See @ref Texture::setCompareFunction() for more information.
*/
TextureArray<dimensions>& setCompareFunction(Sampler::CompareFunction function) {
TextureArray<dimensions>& setCompareFunction(SamplerCompareFunction function) {
AbstractTexture::setCompareFunction(function);
return *this;
}
@ -430,7 +447,7 @@ template<UnsignedInt dimensions> class TextureArray: public AbstractTexture {
* and older.
* @requires_gles Stencil texturing is not available in WebGL.
*/
TextureArray<dimensions>& setDepthStencilMode(Sampler::DepthStencilMode mode) {
TextureArray<dimensions>& setDepthStencilMode(SamplerDepthStencilMode mode) {
AbstractTexture::setDepthStencilMode(mode);
return *this;
}

82
src/Magnum/GL/TextureFormat.h

@ -284,7 +284,7 @@ enum class TextureFormat: GLenum {
#ifndef MAGNUM_TARGET_GLES2
/**
* Red component, non-normalized unsigned byte. Can't be filtered using
* @ref Sampler::Filter::Linear.
* @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{ARB,texture_rg} and @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -295,7 +295,7 @@ enum class TextureFormat: GLenum {
/**
* Red and green component, each non-normalized unsigned byte. Can't be
* filtered using @ref Sampler::Filter::Linear.
* filtered using @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{ARB,texture_rg} and @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -306,7 +306,7 @@ enum class TextureFormat: GLenum {
/**
* RGB, each component non-normalized unsigned byte. Can't be filtered
* using @ref Sampler::Filter::Linear.
* using @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -317,7 +317,7 @@ enum class TextureFormat: GLenum {
/**
* RGBA, each component non-normalized unsigned byte. Can't be filtered
* using @ref Sampler::Filter::Linear.
* using @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -328,7 +328,7 @@ enum class TextureFormat: GLenum {
/**
* Red component, non-normalized signed byte. Can't be filtered using
* @ref Sampler::Filter::Linear.
* @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{ARB,texture_rg} and @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -339,7 +339,7 @@ enum class TextureFormat: GLenum {
/**
* Red and green component, each non-normalized signed byte. Can't be
* filtered using @ref Sampler::Filter::Linear.
* filtered using @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{ARB,texture_rg} and @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -350,7 +350,7 @@ enum class TextureFormat: GLenum {
/**
* RGB, each component non-normalized signed byte. Can't be filtered using
* @ref Sampler::Filter::Linear.
* @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -361,7 +361,7 @@ enum class TextureFormat: GLenum {
/**
* RGBA, each component non-normalized signed byte. Can't be filtered using
* @ref Sampler::Filter::Linear.
* @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -372,7 +372,7 @@ enum class TextureFormat: GLenum {
/**
* Red component, non-normalized unsigned short. Can't be filtered using
* @ref Sampler::Filter::Linear.
* @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{ARB,texture_rg} and @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -383,7 +383,7 @@ enum class TextureFormat: GLenum {
/**
* Red and green component, each non-normalized unsigned short. Can't be
* filtered using @ref Sampler::Filter::Linear.
* filtered using @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{ARB,texture_rg} and @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -394,7 +394,7 @@ enum class TextureFormat: GLenum {
/**
* RGB, each component non-normalized unsigned short. Can't be filtered
* using @ref Sampler::Filter::Linear.
* using @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -405,7 +405,7 @@ enum class TextureFormat: GLenum {
/**
* RGBA, each component non-normalized unsigned short. Can't be filtered
* using @ref Sampler::Filter::Linear.
* using @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -416,7 +416,7 @@ enum class TextureFormat: GLenum {
/**
* Red component, non-normalized signed short. Can't be filtered using
* @ref Sampler::Filter::Linear.
* @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{ARB,texture_rg} and @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -427,7 +427,7 @@ enum class TextureFormat: GLenum {
/**
* Red and green component, each non-normalized signed short. Can't be
* filtered using @ref Sampler::Filter::Linear.
* filtered using @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{ARB,texture_rg} and @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -438,7 +438,7 @@ enum class TextureFormat: GLenum {
/**
* RGB, each component non-normalized signed short. Can't be filtered using
* @ref Sampler::Filter::Linear.
* @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -449,7 +449,7 @@ enum class TextureFormat: GLenum {
/**
* RGBA, each component non-normalized signed short. Can't be filtered
* using @ref Sampler::Filter::Linear.
* using @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -460,7 +460,7 @@ enum class TextureFormat: GLenum {
/**
* Red component, non-normalized unsigned int. Can't be filtered using
* @ref Sampler::Filter::Linear.
* @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{ARB,texture_rg} and @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -471,7 +471,7 @@ enum class TextureFormat: GLenum {
/**
* Red and green component, each non-normalized unsigned int. Can't be
* filtered using @ref Sampler::Filter::Linear.
* filtered using @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{ARB,texture_rg} and @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -482,7 +482,7 @@ enum class TextureFormat: GLenum {
/**
* RGB, each component non-normalized unsigned int. Can't be filtered using
* @ref Sampler::Filter::Linear.
* @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -493,7 +493,7 @@ enum class TextureFormat: GLenum {
/**
* RGBA, each component non-normalized unsigned int. Can't be filtered
* using @ref Sampler::Filter::Linear.
* using @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -504,7 +504,7 @@ enum class TextureFormat: GLenum {
/**
* Red component, non-normalized signed int. Can't be filtered using
* @ref Sampler::Filter::Linear.
* @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{ARB,texture_rg} and @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -515,7 +515,7 @@ enum class TextureFormat: GLenum {
/**
* Red and green component, each non-normalized signed int. Can't be
* filtered using @ref Sampler::Filter::Linear.
* filtered using @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{ARB,texture_rg} and @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -526,7 +526,7 @@ enum class TextureFormat: GLenum {
/**
* RGB, each component non-normalized signed int. Can't be filtered using
* @ref Sampler::Filter::Linear.
* @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -537,7 +537,7 @@ enum class TextureFormat: GLenum {
/**
* RGBA, each component non-normalized signed int. Can't be filtered using
* @ref Sampler::Filter::Linear.
* @ref SamplerFilter::Linear.
* @requires_gl30 Extension @extension{EXT,texture_integer}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.
@ -555,7 +555,7 @@ enum class TextureFormat: GLenum {
* (@extension2{OES,texture_half_float,OES_texture_float}) in OpenGL
* ES 2.0 instead.
* @requires_gles30 Extension @extension2{OES,texture_half_float_linear,OES_texture_float_linear}
* for filtering using @ref Sampler::Filter::Linear in OpenGL ES 2.0.
* for filtering using @ref SamplerFilter::Linear in OpenGL ES 2.0.
* @requires_gles32 Extension @extension{EXT,color_buffer_half_float} to
* use as a render target. Use @ref TextureFormat::R16UI or
* @ref TextureFormat::R16I instead if not available.
@ -563,7 +563,7 @@ enum class TextureFormat: GLenum {
* in combination with @ref PixelFormat::HalfFloat (@webgl_extension{OES,texture_half_float})
* in WebGL 1.0.
* @requires_webgl20 Extension @webgl_extension{OES,texture_half_float_linear}
* for filtering using @ref Sampler::Filter::Linear in WebGL 1.0.
* for filtering using @ref SamplerFilter::Linear in WebGL 1.0.
* @requires_webgl_extension Extension @webgl_extension{EXT,color_buffer_float}
* to use as a render target in WebGL 2.0; use @ref TextureFormat::R16UI
* or @ref TextureFormat::R16I instead if not available. Only three-
@ -582,7 +582,7 @@ enum class TextureFormat: GLenum {
* (@extension2{OES,texture_half_float,OES_texture_float}) in OpenGL
* ES 2.0 instead.
* @requires_gles30 Extension @extension2{OES,texture_half_float_linear,OES_texture_float_linear}
* for filtering using @ref Sampler::Filter::Linear in OpenGL ES 2.0.
* for filtering using @ref SamplerFilter::Linear in OpenGL ES 2.0.
* @requires_gles32 Extension @extension{EXT,color_buffer_half_float} to
* use as a render target in OpenGL ES. Use @ref TextureFormat::RG16UI
* or @ref TextureFormat::RG16I instead if not available.
@ -590,7 +590,7 @@ enum class TextureFormat: GLenum {
* in combination with @ref PixelFormat::HalfFloat (@webgl_extension{OES,texture_half_float})
* in WebGL 1.0 instead.
* @requires_webgl20 Extension @webgl_extension{OES,texture_half_float_linear}
* for filtering using @ref Sampler::Filter::Linear in WebGL 1.0.
* for filtering using @ref SamplerFilter::Linear in WebGL 1.0.
* @requires_webgl_extension Extension @webgl_extension{EXT,color_buffer_float}
* to use as a render target in WebGL 2.0; use @ref TextureFormat::RG16UI
* or @ref TextureFormat::RG16I instead if not available. Only three-
@ -608,12 +608,12 @@ enum class TextureFormat: GLenum {
* @ref PixelFormat::HalfFloat (@extension2{OES,texture_half_float,OES_texture_float})
* in OpenGL ES 2.0 instead.
* @requires_gles30 Extension @extension2{OES,texture_half_float_linear,OES_texture_float_linear}
* for filtering using @ref Sampler::Filter::Linear in OpenGL ES 2.0.
* for filtering using @ref SamplerFilter::Linear in OpenGL ES 2.0.
* @requires_webgl20 Use @ref TextureFormat::RGB in combination with
* @ref PixelFormat::HalfFloat (@webgl_extension{OES,texture_half_float})
* in WebGL 1.0 instead.
* @requires_webgl20 Extension @webgl_extension{OES,texture_half_float_linear}
* for filtering using @ref Sampler::Filter::Linear in WebGL 1.0.
* for filtering using @ref SamplerFilter::Linear in WebGL 1.0.
* @requires_gl Can't be used as a render target in OpenGL ES or WebGL 2.0.
* Use @ref TextureFormat::RGBA16F instead. Use @ref TextureFormat::RGB
* in combination with @ref PixelFormat::HalfFloat
@ -630,7 +630,7 @@ enum class TextureFormat: GLenum {
* @ref PixelFormat::HalfFloat (@extension2{OES,texture_half_float,OES_texture_float})
* in OpenGL ES 2.0 instead.
* @requires_gles30 Extension @extension2{OES,texture_half_float_linear,OES_texture_float_linear}
* for filtering using @ref Sampler::Filter::Linear.
* for filtering using @ref SamplerFilter::Linear.
* @requires_gles32 Extension @extension{EXT,color_buffer_half_float} to
* use as a render target in OpenGL ES. Use @ref TextureFormat::RGBA16UI
* or @ref TextureFormat::RGBA16I instead if not available.
@ -638,7 +638,7 @@ enum class TextureFormat: GLenum {
* @ref PixelFormat::HalfFloat (@webgl_extension{OES,texture_half_float})
* in WebGL 1.0 instead.
* @requires_webgl20 Extension @webgl_extension{OES,texture_half_float_linear}
* for filtering using @ref Sampler::Filter::Linear in WebGL 1.0.
* for filtering using @ref SamplerFilter::Linear in WebGL 1.0.
* @requires_webgl_extension Extension @webgl_extension{EXT,color_buffer_float}
* to use as a render target in WebGL 2.0. Use @ref TextureFormat::RGBA16UI
* or @ref TextureFormat::RGBA16I instead if not available. Use
@ -657,12 +657,12 @@ enum class TextureFormat: GLenum {
* a render target. Use @ref TextureFormat::R32UI or
* @ref TextureFormat::R32I instead if not available.
* @requires_es_extension Extension @extension{OES,texture_float_linear}
* for filtering using @ref Sampler::Filter::Linear.
* for filtering using @ref SamplerFilter::Linear.
* @requires_webgl20 Use @ref TextureFormat::Red / @ref TextureFormat::Luminance
* in combination with @ref PixelFormat::Float (@webgl_extension{OES,texture_float})
* in WebGL 1.0 instead.
* @requires_webgl_extension Extension @webgl_extension{OES,texture_float_linear}
* for filtering using @ref Sampler::Filter::Linear.
* for filtering using @ref SamplerFilter::Linear.
* @requires_webgl_extension Extension @webgl_extension{EXT,color_buffer_float}
* to use as a render target in WebGL 2.0; use @ref TextureFormat::R32UI
* or @ref TextureFormat::R32I instead if not available. Only three-
@ -682,12 +682,12 @@ enum class TextureFormat: GLenum {
* a render target. Use @ref TextureFormat::RG32UI or
* @ref TextureFormat::RG32I instead if not available.
* @requires_es_extension Extension @extension{OES,texture_float_linear}
* for filtering using @ref Sampler::Filter::Linear.
* for filtering using @ref SamplerFilter::Linear.
* @requires_webgl20 Use @ref TextureFormat::RG / @ref TextureFormat::LuminanceAlpha
* in combination with @ref PixelFormat::Float (@webgl_extension{OES,texture_float})
* in WebGL 1.0 instead.
* @requires_webgl_extension Extension @webgl_extension{OES,texture_float_linear}
* for filtering using @ref Sampler::Filter::Linear.
* for filtering using @ref SamplerFilter::Linear.
* @requires_webgl_extension Extension @webgl_extension{EXT,color_buffer_float}
* to use as a render target in WebGL 2.0; use @ref TextureFormat::RG32UI
* or @ref TextureFormat::RG32I instead if not available. Only three-
@ -704,12 +704,12 @@ enum class TextureFormat: GLenum {
* @ref PixelFormat::Float (@extension{OES,texture_float}) in OpenGL
* ES 2.0 instead.
* @requires_es_extension Extension @extension{OES,texture_float_linear}
* for filtering using @ref Sampler::Filter::Linear.
* for filtering using @ref SamplerFilter::Linear.
* @requires_webgl20 Use @ref TextureFormat::RGB in combination with
* @ref PixelFormat::Float (@webgl_extension{OES,texture_float}) in
* WebGL 1.0 instead.
* @requires_webgl_extension Extension @webgl_extension{OES,texture_float_linear}
* for filtering using @ref Sampler::Filter::Linear.
* for filtering using @ref SamplerFilter::Linear.
* @requires_gl Can't be used as a render target in OpenGL ES or WebGL 2.0.
* Use @ref TextureFormat::RGBA32F instead. Use @ref TextureFormat::RGB
* in combination with @ref PixelFormat::Float
@ -724,7 +724,7 @@ enum class TextureFormat: GLenum {
* @ref PixelFormat::Float (@extension{OES,texture_float}) in OpenGL
* ES 2.0 instead.
* @requires_es_extension Extension @extension{OES,texture_float_linear}
* for filtering using @ref Sampler::Filter::Linear.
* for filtering using @ref SamplerFilter::Linear.
* @requires_gles32 Extension @extension{EXT,color_buffer_float} to
* use as a render target in OpenGL ES. Use @ref TextureFormat::RGBA32UI
* or @ref TextureFormat::RGBA32I instead if not available.
@ -732,7 +732,7 @@ enum class TextureFormat: GLenum {
* @ref PixelFormat::Float (@webgl_extension{OES,texture_float}) in
* WebGL 1.0 instead.
* @requires_webgl_extension Extension @webgl_extension{OES,texture_float_linear}
* for filtering using @ref Sampler::Filter::Linear.
* for filtering using @ref SamplerFilter::Linear.
* @requires_webgl_extension Extension @webgl_extension{EXT,color_buffer_float}
* to use as a render target in WebGL 2.0. Use @ref TextureFormat::RGBA32UI
* or @ref TextureFormat::RGBA32I instead if not available. Use
@ -930,7 +930,7 @@ enum class TextureFormat: GLenum {
#ifndef MAGNUM_TARGET_GLES2
/**
* RGBA, non-normalized unsigned, each RGB component 10bit, alpha 2bit.
* Can't be filtered using @ref Sampler::Filter::Linear.
* Can't be filtered using @ref SamplerFilter::Linear.
* @requires_gl33 Extension @extension{ARB,texture_rgb10_a2ui}
* @requires_gles30 Only normalized integral formats are available in
* OpenGL ES 2.0.

6
src/Magnum/Magnum.h

@ -714,6 +714,10 @@ template<class T, class U = T> class Resource;
class ResourceKey;
template<class...> class ResourceManager;
enum class SamplerFilter: UnsignedInt;
enum class SamplerMipmap: UnsignedInt;
enum class SamplerWrapping: UnsignedInt;
class Timeline;
#ifdef MAGNUM_BUILD_DEPRECATED
@ -786,7 +790,7 @@ typedef CORRADE_DEPRECATED("use GL::RectangleTexture instead") GL::RectangleText
typedef CORRADE_DEPRECATED("use GL::Renderbuffer instead") GL::Renderbuffer Renderbuffer;
typedef CORRADE_DEPRECATED("use GL::RenderbufferFormat instead") GL::RenderbufferFormat RenderbufferFormat;
typedef CORRADE_DEPRECATED("use GL::Sampler instead") GL::Sampler Sampler;
struct CORRADE_DEPRECATED("use GL::Sampler, SamplerFilter, GL::SamplerFilter, SamplerMipmap, GL::SamplerMipmap, SamplerWrapping, GL::SamplerWrapping, GL::SamplerCompareMode, GL::SamplerCompareFunction or GL::SamplerDepthStencilMode instead") Sampler;
typedef CORRADE_DEPRECATED("use GL::Shader instead") GL::Shader Shader;
template<UnsignedInt dimensions> using Texture CORRADE_DEPRECATED_ALIAS("use GL::Texture instead") = GL::Texture<dimensions>;

77
src/Magnum/Sampler.cpp

@ -0,0 +1,77 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
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 <Corrade/Utility/Debug.h>
namespace Magnum {
#ifndef DOXYGEN_GENERATING_OUTPUT
Debug& operator<<(Debug& debug, const SamplerFilter value) {
switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case SamplerFilter::value: return debug << "SamplerFilter::" #value;
_c(Nearest)
_c(Linear)
#undef _c
/* LCOV_EXCL_STOP */
}
return debug << "SamplerFilter(" << Debug::nospace << reinterpret_cast<void*>(UnsignedInt(value)) << Debug::nospace << ")";
}
Debug& operator<<(Debug& debug, const SamplerMipmap value) {
switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case SamplerMipmap::value: return debug << "SamplerMipmap::" #value;
_c(Base)
_c(Nearest)
_c(Linear)
#undef _c
/* LCOV_EXCL_STOP */
}
return debug << "SamplerMipmap(" << Debug::nospace << reinterpret_cast<void*>(UnsignedInt(value)) << Debug::nospace << ")";
}
Debug& operator<<(Debug& debug, const SamplerWrapping value) {
switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case SamplerWrapping::value: return debug << "SamplerWrapping::" #value;
_c(Repeat)
_c(MirroredRepeat)
_c(ClampToEdge)
_c(ClampToBorder)
_c(MirrorClampToEdge)
#undef _c
/* LCOV_EXCL_STOP */
}
return debug << "SamplerWrapping(" << Debug::nospace << reinterpret_cast<void*>(UnsignedInt(value)) << Debug::nospace << ")";
}
#endif
}

125
src/Magnum/Sampler.h

@ -26,16 +26,131 @@
*/
/** @file
* @deprecated Use @ref Magnum/GL/Sampler.h instead.
* @brief Enum @ref Magnum::SamplerFilter, @ref Magnum::SamplerMipmap, @ref Magnum::SamplerWrapping
*/
#include "Magnum/configure.h"
#include "Magnum/Magnum.h"
#include "Magnum/visibility.h"
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL)
#include "Magnum/GL/Sampler.h"
CORRADE_DEPRECATED_FILE("use Magnum/GL/Sampler.h instead")
#else
#error use Magnum/GL/Sampler.h instead
#endif
namespace Magnum {
/**
@brief Texture sampler filtering
In case of OpenGL, corresponds to @ref GL::SamplerFilter and is convertible to
it using @ref GL::samplerFilter(). See documentation of each value for more
information about the mapping.
@see @ref SamplerMipmap, @ref SamplerWrapping
*/
enum class SamplerFilter: UnsignedInt {
/**
* Nearest neighbor filtering.
*
* Corresponds to @ref GL::SamplerFilter::Nearest.
*/
Nearest,
/**
* Linear interpolation filtering.
*
* Corresponds to @ref GL::SamplerFilter::Linear.
*/
Linear
};
/**
@brief Texture sampler mip level selection
In case of OpenGL, corresponds to @ref GL::SamplerMipmap and is convertible to
it using @ref GL::samplerMipmap(). See documentation of each value for more
information about the mapping.
@see @ref SamplerFilter, @ref SamplerWrapping
*/
enum class SamplerMipmap: UnsignedInt {
/**
* Select base mip level
*
* Corresponds to @ref GL::SamplerMipmap::Base.
*/
Base,
/**
* Select nearest mip level.
*
* Corresponds to @ref GL::SamplerMipmap::Nearest.
*/
Nearest,
/**
* Linear interpolation of nearest mip levels.
*
* Corresponds to @ref GL::SamplerMipmap::Linear.
*/
Linear
};
/**
@brief Texture sampler wrapping
In case of OpenGL, corresponds to @ref GL::SamplerWrapping and is convertible
to it using @ref GL::samplerWrapping(). See documentation of each value for
more information about the mapping. Note that not every mode is available on
all targets, use @ref GL::hasSamplerWrapping() to check for its presence.
@see @ref SamplerFilter, @ref SamplerMipmap
*/
enum class SamplerWrapping: UnsignedInt {
/**
* Repeat texture.
*
* Corresponds to @ref GL::SamplerWrapping::Repeat.
*/
Repeat,
/**
* Repeat mirrored texture.
*
* Corresponds to @ref GL::SamplerWrapping::MirroredRepeat.
*/
MirroredRepeat,
/**
* Clamp to edge. Coordinates out of the range will be clamped to
* first / last column / row in given direction.
*
* Corresponds to @ref GL::SamplerWrapping::ClampToEdge.
*/
ClampToEdge,
/**
* Clamp to border color. Coordinates out of range will be clamped
* to border color.
*
* Corresponds to @ref GL::SamplerWrapping::ClampToBorder.
*/
ClampToBorder,
/**
* Mirror the texture once in negative coordinates and clamp to
* edge after that.
*
* Corresponds to @ref GL::SamplerWrapping::MirrorClampToEdge.
*/
MirrorClampToEdge
};
/** @debugoperatorenum{SamplerFilter} */
MAGNUM_EXPORT Debug& operator<<(Debug& debug, SamplerFilter value);
/** @debugoperatorenum{SamplerMipmap} */
MAGNUM_EXPORT Debug& operator<<(Debug& debug, SamplerMipmap value);
/** @debugoperatorenum{SamplerWrapping} */
MAGNUM_EXPORT Debug& operator<<(Debug& debug, SamplerWrapping value);
}
#endif

1
src/Magnum/Test/CMakeLists.txt

@ -32,6 +32,7 @@ target_compile_definitions(PixelFormatTest PRIVATE "CORRADE_GRACEFUL_ASSERT")
corrade_add_test(PixelStorageTest PixelStorageTest.cpp LIBRARIES Magnum)
corrade_add_test(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES Magnum)
target_compile_definitions(ResourceManagerTest PRIVATE "CORRADE_GRACEFUL_ASSERT")
corrade_add_test(SamplerTest SamplerTest.cpp LIBRARIES MagnumTestLib)
add_library(ResourceManagerLocalInstanceTestLib ${SHARED_OR_STATIC} ResourceManagerLocalInstanceTestLib.cpp)
target_link_libraries(ResourceManagerLocalInstanceTestLib Magnum)

70
src/Magnum/Test/SamplerTest.cpp

@ -0,0 +1,70 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
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 <sstream>
#include <Corrade/TestSuite/Tester.h>
#include "Magnum/Sampler.h"
namespace Magnum { namespace Test {
struct SamplerTest: TestSuite::Tester {
explicit SamplerTest();
void debugFilter();
void debugMipmap();
void debugWrapping();
};
SamplerTest::SamplerTest() {
addTests({&SamplerTest::debugFilter,
&SamplerTest::debugMipmap,
&SamplerTest::debugWrapping});
}
void SamplerTest::debugFilter() {
std::ostringstream out;
Debug(&out) << SamplerFilter::Linear << SamplerFilter(0xdead);
CORRADE_COMPARE(out.str(), "SamplerFilter::Linear SamplerFilter(0xdead)\n");
}
void SamplerTest::debugMipmap() {
std::ostringstream out;
Debug(&out) << SamplerMipmap::Base << SamplerMipmap(0xdead);
CORRADE_COMPARE(out.str(), "SamplerMipmap::Base SamplerMipmap(0xdead)\n");
}
void SamplerTest::debugWrapping() {
std::ostringstream out;
Debug(&out) << SamplerWrapping::ClampToEdge << SamplerWrapping(0xdead);
CORRADE_COMPARE(out.str(), "SamplerWrapping::ClampToEdge SamplerWrapping(0xdead)\n");
}
}}
CORRADE_TEST_MAIN(Magnum::Test::SamplerTest)
Loading…
Cancel
Save