mirror of https://github.com/mosra/magnum.git
Browse Source
Each texture has slightly different usage requirements and having everything under one generic class is not worth the additional runtime checks and whatnot. The current way with Texture::Target enum (hopefully not too widely used) is now deprecated and will be removed in some future release. However general Texture1D/2D/3D usage is not changed in any way.pull/51/head
23 changed files with 2230 additions and 1437 deletions
@ -0,0 +1,116 @@
|
||||
#ifndef Magnum_MultisampleTexture_h |
||||
#define Magnum_MultisampleTexture_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014 |
||||
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. |
||||
*/ |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/** @file
|
||||
* @brief Class @ref Magnum::MultisampleTexture, typedef @ref Magnum::MultisampleTexture2D, @ref Magnum::MultisampleTexture2DArray |
||||
*/ |
||||
#endif |
||||
|
||||
#include "Magnum/AbstractTexture.h" |
||||
#include "Magnum/DimensionTraits.h" |
||||
#include "Magnum/Math/Vector3.h" |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
namespace Magnum { |
||||
|
||||
namespace Implementation { |
||||
template<UnsignedInt> constexpr GLenum multisampleTextureTarget(); |
||||
template<> inline constexpr GLenum multisampleTextureTarget<2>() { return GL_TEXTURE_2D_MULTISAMPLE; } |
||||
template<> inline constexpr GLenum multisampleTextureTarget<3>() { return GL_TEXTURE_2D_MULTISAMPLE_ARRAY; } |
||||
} |
||||
|
||||
/**
|
||||
@brief Mulitsample texture |
||||
|
||||
Template class for 2D mulitsample texture and 2D multisample texture array. See |
||||
also @ref AbstractTexture documentation for more information. |
||||
|
||||
@todoc Finish when fully implemented |
||||
|
||||
The texture is bound to layer specified by shader via @ref bind(). In shader, |
||||
the texture is used via `sampler2DMS`/`sampler2DMSArray`, |
||||
`isampler2DMS`/`isampler2DMSArray` or `usampler2DMS`/`usampler2DMSArray`. See |
||||
@ref AbstractShaderProgram documentation for more information about usage in |
||||
shaders. |
||||
|
||||
@requires_gl32 %Extension @extension{ARB,texture_multisample} |
||||
@requires_gl Multisample textures are not available in OpenGL ES. |
||||
|
||||
@see @ref MultisampleTexture2D, @ref MultisampleTexture2DArray, @ref Texture, |
||||
@ref TextureArray, @ref BufferTexture, @ref CubeMapTexture, |
||||
@ref CubeMapTextureArray, @ref RectangleTexture |
||||
*/ |
||||
template<UnsignedInt dimensions> class MultisampleTexture: public AbstractTexture { |
||||
public: |
||||
static const UnsignedInt Dimensions = dimensions; /**< @brief %Texture dimension count */ |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* |
||||
* Creates new OpenGL texture object. |
||||
* @see @fn_gl{GenTextures} with @def_gl{TEXTURE_2D_MULTISAMPLE} or |
||||
* @def_gl{TEXTURE_2D_MULTISAMPLE_ARRAY} |
||||
*/ |
||||
explicit MultisampleTexture(): AbstractTexture(Implementation::multisampleTextureTarget<dimensions>()) {} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/** @copydoc Texture::imageSize() */ |
||||
typename DimensionTraits<dimensions, Int>::VectorType imageSize(Int level) { |
||||
return DataHelper<dimensions>::imageSize(*this, _target, level); |
||||
} |
||||
#endif |
||||
|
||||
/** @copydoc Texture::invalidateImage() */ |
||||
void invalidateImage(Int level) { AbstractTexture::invalidateImage(level); } |
||||
|
||||
/** @copydoc Texture::invalidateSubImage() */ |
||||
void invalidateSubImage(Int level, const typename DimensionTraits<dimensions, Int>::VectorType& offset, const typename DimensionTraits<dimensions, Int>::VectorType& size) { |
||||
DataHelper<dimensions>::invalidateSubImage(*this, level, offset, size); |
||||
} |
||||
|
||||
/* Overloads to remove WTF-factor from method chaining order */ |
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
MultisampleTexture<dimensions>& setLabel(const std::string& label) { |
||||
AbstractTexture::setLabel(label); |
||||
return *this; |
||||
} |
||||
#endif |
||||
}; |
||||
|
||||
/** @brief Two-dimensional multisample texture */ |
||||
typedef MultisampleTexture<2> MultisampleTexture2D; |
||||
|
||||
/** @brief Two-dimensional multisample texture array */ |
||||
typedef MultisampleTexture<3> MultisampleTexture2DArray; |
||||
|
||||
} |
||||
#else |
||||
#error this header is available only on desktop OpenGL build |
||||
#endif |
||||
|
||||
#endif |
||||
@ -0,0 +1,323 @@
|
||||
#ifndef Magnum_RectangleTexture_h |
||||
#define Magnum_RectangleTexture_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014 |
||||
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. |
||||
*/ |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/** @file
|
||||
* @brief Class @ref Magnum::RectangleTexture |
||||
*/ |
||||
#endif |
||||
|
||||
#include "Magnum/AbstractTexture.h" |
||||
#include "Magnum/Array.h" |
||||
#include "Magnum/Math/Vector2.h" |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
namespace Magnum { |
||||
|
||||
/**
|
||||
@brief Rectangle texture |
||||
|
||||
See also @ref AbstractTexture documentation for more information. |
||||
|
||||
@section RectangleTexture-usage Usage |
||||
|
||||
Common usage is to fully configure all texture parameters and then set the |
||||
data from e.g. @ref Image2D. Example configuration: |
||||
@code |
||||
Image2D image(ColorFormat::RGBA, ColorType::UnsignedByte, {526, 137}, data); |
||||
|
||||
RectangleTexture texture; |
||||
texture.setMagnificationFilter(Sampler::Filter::Linear) |
||||
.setMinificationFilter(Sampler::Filter::Linear) |
||||
.setWrapping(Sampler::Wrapping::ClampToEdge) |
||||
.setMaxAnisotropy(Sampler::maxMaxAnisotropy()) |
||||
.setStorage(TextureFormat::RGBA8, {526, 137}) |
||||
.setSubImage({}, image); |
||||
@endcode |
||||
|
||||
The texture is bound to layer specified by shader via @ref bind(). In shader, |
||||
the texture is used via sampler2DRect`, `sampler2DRectShadow`, `isampler2DRect` |
||||
or `usampler2DRect`. See @ref AbstractShaderProgram documentation for more |
||||
information about usage in shaders. |
||||
|
||||
@requires_gl31 %Extension @extension{ARB,texture_rectangle} |
||||
@requires_gl Rectangle textures are not available in OpenGL ES. |
||||
|
||||
@see @ref Texture, @ref TextureArray, @ref BufferTexture, @ref CubeMapTexture, |
||||
@ref CubeMapTextureArray, @ref MultisampleTexture |
||||
*/ |
||||
class RectangleTexture: public AbstractTexture { |
||||
public: |
||||
/**
|
||||
* @brief Constructor |
||||
* |
||||
* Creates new OpenGL texture object. |
||||
* @see @fn_gl{GenTextures} with @def_gl{TEXTURE_RECTANGLE} |
||||
*/ |
||||
explicit RectangleTexture(): AbstractTexture(GL_TEXTURE_RECTANGLE) {} |
||||
|
||||
/**
|
||||
* @brief Set minification filter |
||||
* @param filter Filter |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* Sets filter used when the object pixel size is smaller than the |
||||
* texture size. If @extension{EXT,direct_state_access} is not |
||||
* available, the texture is bound to some layer before the operation. |
||||
* Initial value is @ref Sampler::Filter::Linear. |
||||
* @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexParameter} |
||||
* or @fn_gl_extension{TextureParameter,EXT,direct_state_access} |
||||
* with @def_gl{TEXTURE_MIN_FILTER} |
||||
*/ |
||||
RectangleTexture& setMinificationFilter(Sampler::Filter filter) { |
||||
AbstractTexture::setMinificationFilter(filter, Sampler::Mipmap::Base); |
||||
return *this; |
||||
} |
||||
|
||||
/** @copydoc Texture::setMagnificationFilter() */ |
||||
RectangleTexture& setMagnificationFilter(Sampler::Filter filter) { |
||||
AbstractTexture::setMagnificationFilter(filter); |
||||
return *this; |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/**
|
||||
* @brief %Image size |
||||
* |
||||
* The result is not cached in any way. If |
||||
* @extension{EXT,direct_state_access} is not available, the texture |
||||
* is bound to some layer before the operation. |
||||
* @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and |
||||
* @fn_gl{GetTexLevelParameter} or @fn_gl_extension{GetTextureLevelParameter,EXT,direct_state_access} |
||||
* with @def_gl{TEXTURE_WIDTH} and @def_gl{TEXTURE_HEIGHT} |
||||
* @requires_gl %Texture image queries are not available in OpenGL ES. |
||||
*/ |
||||
Vector2i imageSize() { return DataHelper<2>::imageSize(*this, _target, 0); } |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Set wrapping |
||||
* @param wrapping Wrapping type for all texture dimensions |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* Sets wrapping type for coordinates out of (0, textureSizeInGivenDirection-1) |
||||
* range for rectangle textures. If @extension{EXT,direct_state_access} |
||||
* is not available, the texture is bound to some layer before the |
||||
* operation. Initial value is @ref Sampler::Wrapping::ClampToEdge. |
||||
* @attention Only @ref Sampler::Wrapping::ClampToEdge and |
||||
* @ref Sampler::Wrapping::ClampToBorder is supported on this |
||||
* texture type. |
||||
* @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexParameter} |
||||
* or @fn_gl_extension{TextureParameter,EXT,direct_state_access} |
||||
* with @def_gl{TEXTURE_WRAP_S}, @def_gl{TEXTURE_WRAP_T}, |
||||
* @def_gl{TEXTURE_WRAP_R} |
||||
*/ |
||||
RectangleTexture& setWrapping(const Array2D<Sampler::Wrapping>& wrapping) { |
||||
DataHelper<2>::setWrapping(*this, wrapping); |
||||
return *this; |
||||
} |
||||
|
||||
/** @copydoc Texture::setBorderColor() */ |
||||
RectangleTexture& setBorderColor(const Color4& color) { |
||||
AbstractTexture::setBorderColor(color); |
||||
return *this; |
||||
} |
||||
|
||||
/** @copydoc Texture::setMaxAnisotropy() */ |
||||
RectangleTexture& setMaxAnisotropy(Float anisotropy) { |
||||
AbstractTexture::setMaxAnisotropy(anisotropy); |
||||
return *this; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Set storage |
||||
* @param internalFormat Internal format |
||||
* @param size Size |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* Specifies entire structure of a texture at once, removing the need |
||||
* for additional consistency checks and memory reallocations when |
||||
* updating the data later. After calling this function the texture |
||||
* is immutable and calling @ref setStorage() or @ref setImage() is not |
||||
* allowed. |
||||
* |
||||
* If @extension{EXT,direct_state_access} is not available, the texture |
||||
* is bound to some layer before the operation. If OpenGL 4.2, |
||||
* @extension{ARB,texture_storage}, OpenGL ES 3.0 or |
||||
* @es_extension{EXT,texture_storage} in OpenGL ES 2.0 is not |
||||
* available, the feature is emulated with @ref setImage() call. |
||||
* @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexStorage2D} |
||||
* or @fn_gl_extension{TextureStorage2D,EXT,direct_state_access}, |
||||
* eventually @fn_gl{TexImage2D} or |
||||
* @fn_gl_extension{TextureImage2D,EXT,direct_state_access}. |
||||
*/ |
||||
RectangleTexture& setStorage(TextureFormat internalFormat, const Vector2i& size) { |
||||
DataHelper<2>::setStorage(*this, _target, 1, internalFormat, size); |
||||
return *this; |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/**
|
||||
* @brief Read texture to image |
||||
* @param image %Image where to put the data |
||||
* |
||||
* %Image parameters like format and type of pixel data are taken from |
||||
* given image, image size is taken from the texture using |
||||
* @ref imageSize(). |
||||
* |
||||
* If @extension{EXT,direct_state_access} is not available, the |
||||
* texture is bound to some layer before the operation. If |
||||
* @extension{ARB,robustness} is available, the operation is protected |
||||
* from buffer overflow. However, if both @extension{EXT,direct_state_access} |
||||
* and @extension{ARB,robustness} are available, the DSA version is |
||||
* used, because it is better for performance and there isn't any |
||||
* function combining both features. |
||||
* @requires_gl %Texture image queries are not available in OpenGL ES. |
||||
* @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and |
||||
* @fn_gl{GetTexLevelParameter} or @fn_gl_extension{GetTextureLevelParameter,EXT,direct_state_access} |
||||
* with @def_gl{TEXTURE_WIDTH} and @def_gl{TEXTURE_HEIGHT}, then |
||||
* @fn_gl{GetTexImage}, @fn_gl_extension{GetTextureImage,EXT,direct_state_access} |
||||
* or @fn_gl_extension{GetnTexImage,ARB,robustness} |
||||
*/ |
||||
void image(Image2D& image) { |
||||
AbstractTexture::image<2>(_target, 0, image); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Read given mip level of texture to buffer image |
||||
* @param image %Buffer image where to put the data |
||||
* @param usage %Buffer usage |
||||
* |
||||
* See @ref image(Image2D&) for more information. |
||||
* @requires_gl %Texture image queries are not available in OpenGL ES. |
||||
*/ |
||||
void image(BufferImage2D& image, BufferUsage usage) { |
||||
AbstractTexture::image<2>(_target, 0, image, usage); |
||||
} |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Set image data |
||||
* @param internalFormat Internal format |
||||
* @param image @ref Image2D, @ref ImageReference2D or |
||||
* @ref Trade::ImageData2D |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* For better performance when calling @ref setImage() more than once |
||||
* use @ref setStorage() and @ref setSubImage() instead. |
||||
* |
||||
* If @extension{EXT,direct_state_access} is not available, the |
||||
* texture is bound to some layer before the operation. |
||||
* @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexImage2D} |
||||
* or @fn_gl_extension{TextureImage2D,EXT,direct_state_access} |
||||
*/ |
||||
RectangleTexture& setImage(TextureFormat internalFormat, const ImageReference2D& image) { |
||||
DataHelper<2>::setImage(*this, _target, 0, internalFormat, image); |
||||
return *this; |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
/** @overload */ |
||||
RectangleTexture& setImage(TextureFormat internalFormat, BufferImage2D& image) { |
||||
DataHelper<2>::setImage(*this, _target, 0, internalFormat, image); |
||||
return *this; |
||||
} |
||||
|
||||
/** @overload */ |
||||
RectangleTexture& setImage(TextureFormat internalFormat, BufferImage2D&& image) { |
||||
return setImage(internalFormat, image); |
||||
} |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Set image subdata |
||||
* @param offset Offset where to put data in the texture |
||||
* @param image @ref Image2D, @ref ImageReference2D or |
||||
* @ref Trade::ImageData2D |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* If @extension{EXT,direct_state_access} is not available, the |
||||
* texture is bound to some layer before the operation. |
||||
* @see @ref setStorage(), @ref setImage(), @fn_gl{ActiveTexture}, |
||||
* @fn_gl{BindTexture} and @fn_gl{TexSubImage2D} or |
||||
* @fn_gl_extension{TextureSubImage2D,EXT,direct_state_access} |
||||
*/ |
||||
RectangleTexture& setSubImage(const Vector2i& offset, const ImageReference2D& image) { |
||||
DataHelper<2>::setSubImage(*this, _target, 0, offset, image); |
||||
return *this; |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
/** @overload */ |
||||
RectangleTexture& setSubImage(const Vector2i& offset, BufferImage2D& image) { |
||||
DataHelper<2>::setSubImage(*this, _target, 0, offset, image); |
||||
return *this; |
||||
} |
||||
|
||||
/** @overload */ |
||||
RectangleTexture& setSubImage(const Vector2i& offset, BufferImage2D&& image) { |
||||
return setSubImage(offset, image); |
||||
} |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Invalidate texture image |
||||
* |
||||
* If running on OpenGL ES or extension @extension{ARB,invalidate_subdata} |
||||
* (part of OpenGL 4.3) is not available, this function does nothing. |
||||
* @see @ref invalidateSubImage(), @fn_gl{InvalidateTexImage} |
||||
*/ |
||||
void invalidateImage() { AbstractTexture::invalidateImage(0); } |
||||
|
||||
/**
|
||||
* @brief Invalidate texture subimage |
||||
* @param offset Offset into the texture |
||||
* @param size Size of invalidated data |
||||
* |
||||
* If running on OpenGL ES or extension @extension{ARB,invalidate_subdata} |
||||
* (part of OpenGL 4.3) is not available, this function does nothing. |
||||
* @see @ref invalidateImage(), @fn_gl{InvalidateTexSubImage} |
||||
*/ |
||||
void invalidateSubImage(const Vector2i& offset, const Vector2i& size) { |
||||
DataHelper<2>::invalidateSubImage(*this, 0, offset, size); |
||||
} |
||||
|
||||
/* Overloads to remove WTF-factor from method chaining order */ |
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
RectangleTexture& setLabel(const std::string& label) { |
||||
AbstractTexture::setLabel(label); |
||||
return *this; |
||||
} |
||||
#endif |
||||
}; |
||||
|
||||
} |
||||
#else |
||||
#error this header is available only on desktop OpenGL build |
||||
#endif |
||||
|
||||
#endif |
||||
@ -0,0 +1,212 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014 |
||||
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 <Corrade/TestSuite/Compare/Container.h> |
||||
|
||||
#include "Magnum/MultisampleTexture.h" |
||||
#include "Magnum/Test/AbstractOpenGLTester.h" |
||||
|
||||
namespace Magnum { namespace Test { |
||||
|
||||
class MultisampleTextureGLTest: public AbstractOpenGLTester { |
||||
public: |
||||
explicit MultisampleTextureGLTest(); |
||||
|
||||
void construct2D(); |
||||
void construct2DArray(); |
||||
|
||||
void storage2D(); |
||||
void storage2DArray(); |
||||
|
||||
void image2D(); |
||||
void image2DBuffer(); |
||||
void image2DArray(); |
||||
void image2DArrayBuffer(); |
||||
|
||||
void subImage2D(); |
||||
void subImage2DBuffer(); |
||||
void subImage2DArray(); |
||||
void subImage2DArrayBuffer(); |
||||
|
||||
void invalidateImage2D(); |
||||
void invalidateImage2DArray(); |
||||
|
||||
void invalidateSubImage2D(); |
||||
void invalidateSubImage2DArray(); |
||||
}; |
||||
|
||||
MultisampleTextureGLTest::MultisampleTextureGLTest() { |
||||
addTests({&MultisampleTextureGLTest::construct2D, |
||||
&MultisampleTextureGLTest::construct2DArray, |
||||
|
||||
&MultisampleTextureGLTest::storage2D, |
||||
&MultisampleTextureGLTest::storage2DArray, |
||||
|
||||
&MultisampleTextureGLTest::image2D, |
||||
&MultisampleTextureGLTest::image2DBuffer, |
||||
&MultisampleTextureGLTest::image2DArray, |
||||
&MultisampleTextureGLTest::image2DArrayBuffer, |
||||
|
||||
&MultisampleTextureGLTest::subImage2D, |
||||
&MultisampleTextureGLTest::subImage2DBuffer, |
||||
&MultisampleTextureGLTest::subImage2DArray, |
||||
&MultisampleTextureGLTest::subImage2DArrayBuffer, |
||||
|
||||
&MultisampleTextureGLTest::invalidateImage2D, |
||||
&MultisampleTextureGLTest::invalidateImage2DArray, |
||||
|
||||
&MultisampleTextureGLTest::invalidateSubImage2D, |
||||
&MultisampleTextureGLTest::invalidateSubImage2DArray}); |
||||
} |
||||
|
||||
void MultisampleTextureGLTest::construct2D() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported.")); |
||||
|
||||
{ |
||||
MultisampleTexture2D texture; |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
CORRADE_VERIFY(texture.id() > 0); |
||||
} |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
} |
||||
|
||||
void MultisampleTextureGLTest::construct2DArray() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported.")); |
||||
|
||||
{ |
||||
MultisampleTexture2DArray texture; |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
CORRADE_VERIFY(texture.id() > 0); |
||||
} |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
} |
||||
|
||||
void MultisampleTextureGLTest::storage2D() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported.")); |
||||
|
||||
CORRADE_SKIP("Not implemented yet."); |
||||
} |
||||
|
||||
void MultisampleTextureGLTest::storage2DArray() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported.")); |
||||
|
||||
CORRADE_SKIP("Not implemented yet."); |
||||
} |
||||
|
||||
void MultisampleTextureGLTest::image2D() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported.")); |
||||
|
||||
CORRADE_SKIP("Not implemented yet."); |
||||
} |
||||
|
||||
void MultisampleTextureGLTest::image2DBuffer() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported.")); |
||||
|
||||
CORRADE_SKIP("Not implemented yet."); |
||||
} |
||||
|
||||
void MultisampleTextureGLTest::image2DArray() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported.")); |
||||
|
||||
CORRADE_SKIP("Not implemented yet."); |
||||
} |
||||
|
||||
void MultisampleTextureGLTest::image2DArrayBuffer() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported.")); |
||||
|
||||
CORRADE_SKIP("Not implemented yet."); |
||||
} |
||||
|
||||
void MultisampleTextureGLTest::subImage2D() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported.")); |
||||
|
||||
CORRADE_SKIP("Not implemented yet."); |
||||
} |
||||
|
||||
void MultisampleTextureGLTest::subImage2DBuffer() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported.")); |
||||
|
||||
CORRADE_SKIP("Not implemented yet."); |
||||
} |
||||
|
||||
void MultisampleTextureGLTest::subImage2DArray() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported.")); |
||||
|
||||
CORRADE_SKIP("Not implemented yet."); |
||||
} |
||||
|
||||
void MultisampleTextureGLTest::subImage2DArrayBuffer() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported.")); |
||||
|
||||
CORRADE_SKIP("Not implemented yet."); |
||||
} |
||||
|
||||
void MultisampleTextureGLTest::invalidateImage2D() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported.")); |
||||
|
||||
CORRADE_SKIP("Multisample storage is not implemented yet."); |
||||
} |
||||
|
||||
void MultisampleTextureGLTest::invalidateImage2DArray() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported.")); |
||||
|
||||
CORRADE_SKIP("Multisample storage is not implemented yet."); |
||||
} |
||||
|
||||
void MultisampleTextureGLTest::invalidateSubImage2D() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported.")); |
||||
|
||||
CORRADE_SKIP("Multisample storage is not implemented yet."); |
||||
} |
||||
|
||||
void MultisampleTextureGLTest::invalidateSubImage2DArray() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported.")); |
||||
|
||||
CORRADE_SKIP("Multisample storage is not implemented yet."); |
||||
} |
||||
|
||||
}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Test::MultisampleTextureGLTest) |
||||
@ -0,0 +1,250 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014 |
||||
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 <Corrade/TestSuite/Compare/Container.h> |
||||
|
||||
#include "Magnum/configure.h" |
||||
#include "Magnum/BufferImage.h" |
||||
#include "Magnum/Color.h" |
||||
#include "Magnum/ColorFormat.h" |
||||
#include "Magnum/Image.h" |
||||
#include "Magnum/RectangleTexture.h" |
||||
#include "Magnum/TextureFormat.h" |
||||
#include "Magnum/Test/AbstractOpenGLTester.h" |
||||
|
||||
namespace Magnum { namespace Test { |
||||
|
||||
class TextureGLTest: public AbstractOpenGLTester { |
||||
public: |
||||
explicit TextureGLTest(); |
||||
|
||||
void construct(); |
||||
void sampling(); |
||||
void storage(); |
||||
|
||||
void image(); |
||||
void imageBuffer(); |
||||
|
||||
void subImage(); |
||||
void subImageBuffer(); |
||||
|
||||
void invalidateImage(); |
||||
void invalidateSubImage(); |
||||
}; |
||||
|
||||
TextureGLTest::TextureGLTest() { |
||||
addTests({&TextureGLTest::construct, |
||||
&TextureGLTest::sampling, |
||||
&TextureGLTest::storage, |
||||
|
||||
&TextureGLTest::image, |
||||
&TextureGLTest::imageBuffer, |
||||
|
||||
&TextureGLTest::subImage, |
||||
&TextureGLTest::subImageBuffer, |
||||
|
||||
&TextureGLTest::invalidateImage, |
||||
&TextureGLTest::invalidateSubImage}); |
||||
} |
||||
|
||||
void TextureGLTest::construct() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_rectangle>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_rectangle::string() + std::string(" is not supported.")); |
||||
|
||||
{ |
||||
RectangleTexture texture; |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
CORRADE_VERIFY(texture.id() > 0); |
||||
} |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
} |
||||
|
||||
void TextureGLTest::sampling() { |
||||
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) |
||||
.setBorderColor(Color3(0.5f)) |
||||
.setMaxAnisotropy(Sampler::maxMaxAnisotropy()); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
} |
||||
|
||||
void TextureGLTest::storage() { |
||||
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.setStorage(TextureFormat::RGBA8, Vector2i(32)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
CORRADE_COMPARE(texture.imageSize(), Vector2i(32)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
} |
||||
|
||||
void TextureGLTest::image() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_rectangle>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_rectangle::string() + std::string(" is not supported.")); |
||||
|
||||
constexpr UnsignedByte data[] = { 0x00, 0x01, 0x02, 0x03, |
||||
0x04, 0x05, 0x06, 0x07, |
||||
0x08, 0x09, 0x0a, 0x0b, |
||||
0x0c, 0x0d, 0x0e, 0x0f }; |
||||
RectangleTexture texture; |
||||
texture.setImage(TextureFormat::RGBA8, |
||||
ImageReference2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(2), data)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
Image2D image(ColorFormat::RGBA, ColorType::UnsignedByte); |
||||
texture.image(image); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
CORRADE_COMPARE(image.size(), Vector2i(2)); |
||||
CORRADE_COMPARE_AS(std::vector<UnsignedByte>(image.data(), image.data()+image.pixelSize()*image.size().product()), |
||||
std::vector<UnsignedByte>(data, data + 16), TestSuite::Compare::Container); |
||||
} |
||||
|
||||
void TextureGLTest::imageBuffer() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_rectangle>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_rectangle::string() + std::string(" is not supported.")); |
||||
|
||||
constexpr UnsignedByte data[] = { 0x00, 0x01, 0x02, 0x03, |
||||
0x04, 0x05, 0x06, 0x07, |
||||
0x08, 0x09, 0x0a, 0x0b, |
||||
0x0c, 0x0d, 0x0e, 0x0f }; |
||||
RectangleTexture texture; |
||||
texture.setImage(TextureFormat::RGBA8, |
||||
BufferImage2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(2), data, BufferUsage::StaticDraw)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
BufferImage2D image(ColorFormat::RGBA, ColorType::UnsignedByte); |
||||
texture.image(image, BufferUsage::StaticRead); |
||||
const auto imageData = image.buffer().data<UnsignedByte>(); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
CORRADE_COMPARE(image.size(), Vector2i(2)); |
||||
CORRADE_COMPARE_AS(std::vector<UnsignedByte>(imageData.begin(), imageData.end()), |
||||
std::vector<UnsignedByte>(data, data+16), TestSuite::Compare::Container); |
||||
} |
||||
|
||||
void TextureGLTest::subImage() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_rectangle>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_rectangle::string() + std::string(" is not supported.")); |
||||
|
||||
constexpr UnsignedByte zero[4*4*4] = {}; |
||||
constexpr UnsignedByte subData[] = { 0x00, 0x01, 0x02, 0x03, |
||||
0x04, 0x05, 0x06, 0x07, |
||||
0x08, 0x09, 0x0a, 0x0b, |
||||
0x0c, 0x0d, 0x0e, 0x0f }; |
||||
RectangleTexture texture; |
||||
texture.setImage(TextureFormat::RGBA8, |
||||
ImageReference2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(4), zero)); |
||||
texture.setSubImage(Vector2i(1), |
||||
ImageReference2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(2), subData)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
Image2D image(ColorFormat::RGBA, ColorType::UnsignedByte); |
||||
texture.image(image); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
CORRADE_COMPARE(image.size(), Vector2i(4)); |
||||
CORRADE_COMPARE_AS(std::vector<UnsignedByte>(image.data(), image.data()+image.pixelSize()*image.size().product()), (std::vector<UnsignedByte>{ |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
||||
}), TestSuite::Compare::Container); |
||||
} |
||||
|
||||
void TextureGLTest::subImageBuffer() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_rectangle>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::texture_rectangle::string() + std::string(" is not supported.")); |
||||
|
||||
constexpr UnsignedByte zero[4*4*4] = {}; |
||||
constexpr UnsignedByte subData[] = { 0x00, 0x01, 0x02, 0x03, |
||||
0x04, 0x05, 0x06, 0x07, |
||||
0x08, 0x09, 0x0a, 0x0b, |
||||
0x0c, 0x0d, 0x0e, 0x0f }; |
||||
RectangleTexture texture; |
||||
texture.setImage(TextureFormat::RGBA8, |
||||
ImageReference2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(4), zero)); |
||||
texture.setSubImage(Vector2i(1), |
||||
BufferImage2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(2), subData, BufferUsage::StaticDraw)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
BufferImage2D image(ColorFormat::RGBA, ColorType::UnsignedByte); |
||||
texture.image(image, BufferUsage::StaticRead); |
||||
const auto imageData = image.buffer().data<UnsignedByte>(); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
CORRADE_COMPARE(image.size(), Vector2i(4)); |
||||
CORRADE_COMPARE_AS(std::vector<UnsignedByte>(imageData.begin(), imageData.end()), (std::vector<UnsignedByte>{ |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
||||
}), TestSuite::Compare::Container); |
||||
} |
||||
|
||||
void TextureGLTest::invalidateImage() { |
||||
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.setStorage(TextureFormat::RGBA8, Vector2i(32)); |
||||
texture.invalidateImage(); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
} |
||||
|
||||
void TextureGLTest::invalidateSubImage() { |
||||
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.setStorage(TextureFormat::RGBA8, Vector2i(32)); |
||||
texture.invalidateSubImage(Vector2i(4), Vector2i(16)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
} |
||||
|
||||
}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Test::TextureGLTest) |
||||
@ -0,0 +1,683 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014 |
||||
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 <Corrade/TestSuite/Compare/Container.h> |
||||
|
||||
#include "Magnum/configure.h" |
||||
#include "Magnum/BufferImage.h" |
||||
#include "Magnum/Color.h" |
||||
#include "Magnum/ColorFormat.h" |
||||
#include "Magnum/Image.h" |
||||
#include "Magnum/TextureArray.h" |
||||
#include "Magnum/TextureFormat.h" |
||||
#include "Magnum/Test/AbstractOpenGLTester.h" |
||||
|
||||
namespace Magnum { namespace Test { |
||||
|
||||
class TextureGLTest: public AbstractOpenGLTester { |
||||
public: |
||||
explicit TextureGLTest(); |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void construct1DArray(); |
||||
#endif |
||||
void construct2DArray(); |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void sampling1DArray(); |
||||
#endif |
||||
void sampling2DArray(); |
||||
|
||||
#ifdef MAGNUM_TARGET_GLES |
||||
void samplingBorder2DArray(); |
||||
#endif |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void storage1DArray(); |
||||
#endif |
||||
void storage2DArray(); |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void image1DArray(); |
||||
void image1DArrayBuffer(); |
||||
#endif |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
void image2DArray(); |
||||
void image2DArrayBuffer(); |
||||
#endif |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void subImage1DArray(); |
||||
void subImage1DArrayBuffer(); |
||||
#endif |
||||
void subImage2DArray(); |
||||
void subImage2DArrayBuffer(); |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void generateMipmap1DArray(); |
||||
#endif |
||||
void generateMipmap2DArray(); |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void invalidateImage1DArray(); |
||||
#endif |
||||
void invalidateImage2DArray(); |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void invalidateSubImage1DArray(); |
||||
#endif |
||||
void invalidateSubImage2DArray(); |
||||
}; |
||||
|
||||
TextureGLTest::TextureGLTest() { |
||||
addTests({ |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
&TextureGLTest::construct1DArray, |
||||
#endif |
||||
&TextureGLTest::construct2DArray, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
&TextureGLTest::sampling1DArray, |
||||
#endif |
||||
&TextureGLTest::sampling2DArray, |
||||
|
||||
#ifdef MAGNUM_TARGET_GLES |
||||
&TextureGLTest::samplingBorder2DArray, |
||||
#endif |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
&TextureGLTest::storage1DArray, |
||||
#endif |
||||
&TextureGLTest::storage2DArray, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
&TextureGLTest::image1DArray, |
||||
&TextureGLTest::image1DArrayBuffer, |
||||
#endif |
||||
&TextureGLTest::image2DArray, |
||||
&TextureGLTest::image2DArrayBuffer, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
&TextureGLTest::subImage1DArray, |
||||
&TextureGLTest::subImage1DArrayBuffer, |
||||
#endif |
||||
&TextureGLTest::subImage2DArray, |
||||
&TextureGLTest::subImage2DArrayBuffer, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
&TextureGLTest::generateMipmap1DArray, |
||||
#endif |
||||
&TextureGLTest::generateMipmap2DArray, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
&TextureGLTest::invalidateImage1DArray, |
||||
#endif |
||||
&TextureGLTest::invalidateImage2DArray, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
&TextureGLTest::invalidateSubImage1DArray, |
||||
#endif |
||||
&TextureGLTest::invalidateSubImage2DArray |
||||
}); |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void TextureGLTest::construct1DArray() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::EXT::texture_array>()) |
||||
CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); |
||||
|
||||
{ |
||||
Texture1DArray texture; |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
CORRADE_VERIFY(texture.id() > 0); |
||||
} |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
} |
||||
#endif |
||||
|
||||
void TextureGLTest::construct2DArray() { |
||||
#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; |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
CORRADE_VERIFY(texture.id() > 0); |
||||
} |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void TextureGLTest::sampling1DArray() { |
||||
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) |
||||
.setWrapping(Sampler::Wrapping::ClampToBorder) |
||||
.setBorderColor(Color3(0.5f)) |
||||
.setMaxAnisotropy(Sampler::maxMaxAnisotropy()); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
} |
||||
#endif |
||||
|
||||
void TextureGLTest::sampling2DArray() { |
||||
#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) |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
.setWrapping(Sampler::Wrapping::ClampToBorder) |
||||
.setBorderColor(Color3(0.5f)) |
||||
#else |
||||
.setWrapping(Sampler::Wrapping::ClampToEdge) |
||||
#endif |
||||
.setMaxAnisotropy(Sampler::maxMaxAnisotropy()); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
} |
||||
|
||||
#ifdef MAGNUM_TARGET_GLES |
||||
void TextureGLTest::samplingBorder2DArray() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::NV::texture_border_clamp>()) |
||||
CORRADE_SKIP(Extensions::GL::NV::texture_border_clamp::string() + std::string(" is not supported.")); |
||||
|
||||
Texture2DArray texture; |
||||
texture.setWrapping(Sampler::Wrapping::ClampToBorder) |
||||
.setBorderColor(Color3(0.5f)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
} |
||||
#endif |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void TextureGLTest::storage1DArray() { |
||||
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.setStorage(5, TextureFormat::RGBA8, Vector2i(32)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
CORRADE_COMPARE(texture.imageSize(0), Vector2i(32, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(1), Vector2i(16, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(2), Vector2i( 8, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(3), Vector2i( 4, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(4), Vector2i( 2, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(5), Vector2i( 0, 0)); /* not available */ |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
} |
||||
#endif |
||||
|
||||
void TextureGLTest::storage2DArray() { |
||||
#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.setStorage(5, TextureFormat::RGBA8, Vector3i(32)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
/** @todo How to test this on ES? */ |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
CORRADE_COMPARE(texture.imageSize(0), Vector3i(32, 32, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(1), Vector3i(16, 16, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(2), Vector3i( 8, 8, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(3), Vector3i( 4, 4, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(4), Vector3i( 2, 2, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(5), Vector3i( 0, 0, 0)); /* not available */ |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
#endif |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void TextureGLTest::image1DArray() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::EXT::texture_array>()) |
||||
CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); |
||||
|
||||
constexpr UnsignedByte data[] = { 0x00, 0x01, 0x02, 0x03, |
||||
0x04, 0x05, 0x06, 0x07, |
||||
0x08, 0x09, 0x0a, 0x0b, |
||||
0x0c, 0x0d, 0x0e, 0x0f }; |
||||
Texture1DArray texture; |
||||
texture.setImage(0, TextureFormat::RGBA8, |
||||
ImageReference2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(2), data)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
Image2D image(ColorFormat::RGBA, ColorType::UnsignedByte); |
||||
texture.image(0, image); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
CORRADE_COMPARE(image.size(), Vector2i(2)); |
||||
CORRADE_COMPARE_AS(std::vector<UnsignedByte>(image.data(), image.data()+image.pixelSize()*image.size().product()), |
||||
std::vector<UnsignedByte>(data, data + 16), TestSuite::Compare::Container); |
||||
} |
||||
|
||||
void TextureGLTest::image1DArrayBuffer() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::EXT::texture_array>()) |
||||
CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); |
||||
|
||||
constexpr UnsignedByte data[] = { 0x00, 0x01, 0x02, 0x03, |
||||
0x04, 0x05, 0x06, 0x07, |
||||
0x08, 0x09, 0x0a, 0x0b, |
||||
0x0c, 0x0d, 0x0e, 0x0f }; |
||||
Texture1DArray texture; |
||||
texture.setImage(0, TextureFormat::RGBA8, |
||||
BufferImage2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(2), data, BufferUsage::StaticDraw)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
BufferImage2D image(ColorFormat::RGBA, ColorType::UnsignedByte); |
||||
texture.image(0, image, BufferUsage::StaticRead); |
||||
const auto imageData = image.buffer().data<UnsignedByte>(); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
CORRADE_COMPARE(image.size(), Vector2i(2)); |
||||
CORRADE_COMPARE_AS(std::vector<UnsignedByte>(imageData.begin(), imageData.end()), |
||||
std::vector<UnsignedByte>(data, data + 16), TestSuite::Compare::Container); |
||||
} |
||||
#endif |
||||
|
||||
void TextureGLTest::image2DArray() { |
||||
#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 |
||||
|
||||
constexpr UnsignedByte data[] = { 0x00, 0x01, 0x02, 0x03, |
||||
0x04, 0x05, 0x06, 0x07, |
||||
0x08, 0x09, 0x0a, 0x0b, |
||||
0x0c, 0x0d, 0x0e, 0x0f, |
||||
0x10, 0x11, 0x12, 0x13, |
||||
0x14, 0x15, 0x16, 0x17, |
||||
0x18, 0x19, 0x1a, 0x1b, |
||||
0x1c, 0x1d, 0x1e, 0x1f }; |
||||
Texture2DArray texture; |
||||
texture.setImage(0, TextureFormat::RGBA8, |
||||
ImageReference3D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector3i(2), data)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
/** @todo How to test this on ES? */ |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
Image3D image(ColorFormat::RGBA, ColorType::UnsignedByte); |
||||
texture.image(0, image); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
CORRADE_COMPARE(image.size(), Vector3i(2)); |
||||
CORRADE_COMPARE_AS(std::vector<UnsignedByte>(image.data(), image.data()+image.pixelSize()*image.size().product()), |
||||
std::vector<UnsignedByte>(data, data + 32), TestSuite::Compare::Container); |
||||
#endif |
||||
} |
||||
|
||||
void TextureGLTest::image2DArrayBuffer() { |
||||
#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 |
||||
|
||||
constexpr UnsignedByte data[] = { 0x00, 0x01, 0x02, 0x03, |
||||
0x04, 0x05, 0x06, 0x07, |
||||
0x08, 0x09, 0x0a, 0x0b, |
||||
0x0c, 0x0d, 0x0e, 0x0f, |
||||
0x10, 0x11, 0x12, 0x13, |
||||
0x14, 0x15, 0x16, 0x17, |
||||
0x18, 0x19, 0x1a, 0x1b, |
||||
0x1c, 0x1d, 0x1e, 0x1f }; |
||||
Texture2DArray texture; |
||||
texture.setImage(0, TextureFormat::RGBA8, |
||||
BufferImage3D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector3i(2), data, BufferUsage::StaticDraw)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
/** @todo How to test this on ES? */ |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
BufferImage3D image(ColorFormat::RGBA, ColorType::UnsignedByte); |
||||
texture.image(0, image, BufferUsage::StaticRead); |
||||
const auto imageData = image.buffer().data<UnsignedByte>(); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
CORRADE_COMPARE(image.size(), Vector3i(2)); |
||||
CORRADE_COMPARE_AS(std::vector<UnsignedByte>(imageData.begin(), imageData.end()), |
||||
std::vector<UnsignedByte>(data, data + 32), TestSuite::Compare::Container); |
||||
#endif |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void TextureGLTest::subImage1DArray() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::EXT::texture_array>()) |
||||
CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); |
||||
|
||||
constexpr UnsignedByte zero[4*4*4] = {}; |
||||
constexpr UnsignedByte subData[] = { 0x00, 0x01, 0x02, 0x03, |
||||
0x04, 0x05, 0x06, 0x07, |
||||
0x08, 0x09, 0x0a, 0x0b, |
||||
0x0c, 0x0d, 0x0e, 0x0f }; |
||||
Texture1DArray texture; |
||||
texture.setImage(0, TextureFormat::RGBA8, |
||||
ImageReference2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(4), zero)); |
||||
texture.setSubImage(0, Vector2i(1), |
||||
ImageReference2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(2), subData)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
Image2D image(ColorFormat::RGBA, ColorType::UnsignedByte); |
||||
texture.image(0, image); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
CORRADE_COMPARE(image.size(), Vector2i(4)); |
||||
CORRADE_COMPARE_AS(std::vector<UnsignedByte>(image.data(), image.data()+image.pixelSize()*image.size().product()), (std::vector<UnsignedByte>{ |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
||||
}), TestSuite::Compare::Container); |
||||
} |
||||
|
||||
void TextureGLTest::subImage1DArrayBuffer() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::EXT::texture_array>()) |
||||
CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); |
||||
|
||||
constexpr UnsignedByte zero[4*4*4] = {}; |
||||
constexpr UnsignedByte subData[] = { 0x00, 0x01, 0x02, 0x03, |
||||
0x04, 0x05, 0x06, 0x07, |
||||
0x08, 0x09, 0x0a, 0x0b, |
||||
0x0c, 0x0d, 0x0e, 0x0f }; |
||||
Texture1DArray texture; |
||||
texture.setImage(0, TextureFormat::RGBA8, |
||||
ImageReference2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(4), zero)); |
||||
texture.setSubImage(0, Vector2i(1), |
||||
BufferImage2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(2), subData, BufferUsage::StaticDraw)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
BufferImage2D image(ColorFormat::RGBA, ColorType::UnsignedByte); |
||||
texture.image(0, image, BufferUsage::StaticRead); |
||||
const auto imageData = image.buffer().data<UnsignedByte>(); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
CORRADE_COMPARE(image.size(), Vector2i(4)); |
||||
CORRADE_COMPARE_AS(std::vector<UnsignedByte>(imageData.begin(), imageData.end()), (std::vector<UnsignedByte>{ |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
||||
}), TestSuite::Compare::Container); |
||||
} |
||||
#endif |
||||
|
||||
void TextureGLTest::subImage2DArray() { |
||||
#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 |
||||
|
||||
constexpr UnsignedByte zero[4*4*4*4] = {}; |
||||
constexpr UnsignedByte subData[] = { 0x00, 0x01, 0x02, 0x03, |
||||
0x04, 0x05, 0x06, 0x07, |
||||
0x08, 0x09, 0x0a, 0x0b, |
||||
0x0c, 0x0d, 0x0e, 0x0f, |
||||
0x10, 0x11, 0x12, 0x13, |
||||
0x14, 0x15, 0x16, 0x17, |
||||
0x18, 0x19, 0x1a, 0x1b, |
||||
0x1c, 0x1d, 0x1e, 0x1f }; |
||||
Texture2DArray texture; |
||||
texture.setImage(0, TextureFormat::RGBA8, |
||||
ImageReference3D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector3i(4), zero)); |
||||
texture.setSubImage(0, Vector3i(1), |
||||
ImageReference3D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector3i(2), subData)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
/** @todo How to test this on ES? */ |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
Image3D image(ColorFormat::RGBA, ColorType::UnsignedByte); |
||||
texture.image(0, image); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
CORRADE_COMPARE(image.size(), Vector3i(4)); |
||||
CORRADE_COMPARE_AS(std::vector<UnsignedByte>(image.data(), image.data()+image.pixelSize()*image.size().product()), (std::vector<UnsignedByte>{ |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
||||
}), TestSuite::Compare::Container); |
||||
#endif |
||||
} |
||||
|
||||
void TextureGLTest::subImage2DArrayBuffer() { |
||||
#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 |
||||
|
||||
constexpr UnsignedByte zero[4*4*4*4] = {}; |
||||
constexpr UnsignedByte subData[] = { 0x00, 0x01, 0x02, 0x03, |
||||
0x04, 0x05, 0x06, 0x07, |
||||
0x08, 0x09, 0x0a, 0x0b, |
||||
0x0c, 0x0d, 0x0e, 0x0f, |
||||
0x10, 0x11, 0x12, 0x13, |
||||
0x14, 0x15, 0x16, 0x17, |
||||
0x18, 0x19, 0x1a, 0x1b, |
||||
0x1c, 0x1d, 0x1e, 0x1f }; |
||||
Texture2DArray texture; |
||||
texture.setImage(0, TextureFormat::RGBA8, |
||||
ImageReference3D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector3i(4), zero)); |
||||
texture.setSubImage(0, Vector3i(1), |
||||
BufferImage3D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector3i(2), subData, BufferUsage::StaticDraw)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
/** @todo How to test this on ES? */ |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
BufferImage3D image(ColorFormat::RGBA, ColorType::UnsignedByte); |
||||
texture.image(0, image, BufferUsage::StaticRead); |
||||
const auto imageData = image.buffer().data<UnsignedByte>(); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
CORRADE_COMPARE(image.size(), Vector3i(4)); |
||||
CORRADE_COMPARE_AS(std::vector<UnsignedByte>(imageData.begin(), imageData.end()), (std::vector<UnsignedByte>{ |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
||||
}), TestSuite::Compare::Container); |
||||
#endif |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void TextureGLTest::generateMipmap1DArray() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::framebuffer_object>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::framebuffer_object::string() + std::string(" is not supported.")); |
||||
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.setImage(0, TextureFormat::RGBA8, |
||||
ImageReference2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(32))); |
||||
|
||||
CORRADE_COMPARE(texture.imageSize(0), Vector2i(32)); |
||||
CORRADE_COMPARE(texture.imageSize(1), Vector2i( 0)); |
||||
|
||||
texture.generateMipmap(); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
CORRADE_COMPARE(texture.imageSize(0), Vector2i(32, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(1), Vector2i(16, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(2), Vector2i( 8, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(3), Vector2i( 4, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(4), Vector2i( 2, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(5), Vector2i( 1, 32)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
} |
||||
#endif |
||||
|
||||
void TextureGLTest::generateMipmap2DArray() { |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::framebuffer_object>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::framebuffer_object::string() + std::string(" is not supported.")); |
||||
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.setImage(0, TextureFormat::RGBA8, |
||||
ImageReference3D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector3i(32))); |
||||
|
||||
/** @todo How to test this on ES? */ |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
CORRADE_COMPARE(texture.imageSize(0), Vector3i(32)); |
||||
CORRADE_COMPARE(texture.imageSize(1), Vector3i( 0)); |
||||
#endif |
||||
|
||||
texture.generateMipmap(); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
CORRADE_COMPARE(texture.imageSize(0), Vector3i(32, 32, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(1), Vector3i(16, 16, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(2), Vector3i( 8, 8, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(3), Vector3i( 4, 4, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(4), Vector3i( 2, 2, 32)); |
||||
CORRADE_COMPARE(texture.imageSize(5), Vector3i( 1, 1, 32)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
#endif |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void TextureGLTest::invalidateImage1DArray() { |
||||
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.setStorage(2, TextureFormat::RGBA8, Vector2i(32)); |
||||
texture.invalidateImage(1); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
} |
||||
#endif |
||||
|
||||
void TextureGLTest::invalidateImage2DArray() { |
||||
#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.setStorage(2, TextureFormat::RGBA8, Vector3i(32)); |
||||
texture.invalidateImage(1); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void TextureGLTest::invalidateSubImage1DArray() { |
||||
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.setStorage(2, TextureFormat::RGBA8, Vector2i(32)); |
||||
texture.invalidateSubImage(1, Vector2i(2), Vector2i(8)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
} |
||||
#endif |
||||
|
||||
void TextureGLTest::invalidateSubImage2DArray() { |
||||
#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.setStorage(2, TextureFormat::RGBA8, Vector3i(32)); |
||||
texture.invalidateSubImage(1, Vector3i(2), Vector3i(8)); |
||||
|
||||
MAGNUM_VERIFY_NO_ERROR(); |
||||
} |
||||
|
||||
}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Test::TextureGLTest) |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,302 @@
|
||||
#ifndef Magnum_TextureArray_h |
||||
#define Magnum_TextureArray_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014 |
||||
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. |
||||
*/ |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
/** @file
|
||||
* @brief Class @ref Magnum::TextureArray, typedef @ref Magnum::Texture1DArray, @ref Magnum::Texture2DArray |
||||
*/ |
||||
#endif |
||||
|
||||
#include "Magnum/AbstractTexture.h" |
||||
#include "Magnum/Array.h" |
||||
#include "Magnum/DimensionTraits.h" |
||||
#include "Magnum/Math/Vector3.h" |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
namespace Magnum { |
||||
|
||||
namespace Implementation { |
||||
template<UnsignedInt> constexpr GLenum textureArrayTarget(); |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
template<> inline constexpr GLenum textureArrayTarget<1>() { return GL_TEXTURE_1D_ARRAY; } |
||||
#endif |
||||
template<> inline constexpr GLenum textureArrayTarget<2>() { return GL_TEXTURE_2D_ARRAY; } |
||||
} |
||||
|
||||
/**
|
||||
@brief %Texture array |
||||
|
||||
Template class for one- and two-dimensional texture arrays. See also |
||||
@ref AbstractTexture documentation for more information. |
||||
|
||||
@section Texture-usage Usage |
||||
|
||||
Common usage is to fully configure all texture parameters and then set the |
||||
data. Example configuration: |
||||
@code |
||||
Texture2DArray texture; |
||||
texture.setMagnificationFilter(Sampler::Filter::Linear) |
||||
.setMinificationFilter(Sampler::Filter::Linear, Sampler::Mipmap::Linear) |
||||
.setWrapping(Sampler::Wrapping::ClampToEdge) |
||||
.setMaxAnisotropy(Sampler::maxMaxAnisotropy());; |
||||
@endcode |
||||
|
||||
It is often more convenient to first allocate the memory for all layers by |
||||
calling @ref setStorage() and then specify each layer separately using |
||||
@ref setSubImage(): |
||||
@code |
||||
texture.setStorage(levels, TextureFormat::RGBA8, {64, 64, 16}); |
||||
|
||||
for(std::size_t i = 0; i != 16; ++i) { |
||||
Image3D image(ColorFormat::RGBA, ColorType::UnsignedByte, {64, 64, 1}, ...); |
||||
texture.setSubImage(0, Vector3i::zAxis(i), image); |
||||
} |
||||
@endcode |
||||
|
||||
@attention Note that default configuration (if @ref setMinificationFilter() is |
||||
not called with another value) is to use mipmaps, so be sure to either call |
||||
@ref setMinificationFilter(), explicitly specify all mip levels with |
||||
@ref setStorage() and @ref setImage() or call @ref generateMipmap(). |
||||
|
||||
The texture is bound to layer specified by shader via @ref bind(). In shader, |
||||
the texture is used via `sampler1DArray`/`sampler2DArray`, |
||||
`sampler1DArrayShadow`/`sampler1DArrayShadow`, `isampler1DArray`/`isampler2DArray` |
||||
or `usampler1DArray`/`usampler2DArray`. See @ref AbstractShaderProgram |
||||
documentation for more information about usage in shaders. |
||||
|
||||
@requires_gl30 %Extension @extension{EXT,texture_array} |
||||
@requires_gles30 %Array textures are not available in OpenGL ES 2.0. |
||||
@requires_gl 1D array textures are not available in OpenGL ES, only 2D ones. |
||||
|
||||
@see @ref Texture1DArray, @ref Texture2DArray, @ref Texture, @ref BufferTexture, |
||||
@ref CubeMapTexture, @ref CubeMapTextureArray, @ref MultisampleTexture, |
||||
@ref RectangleTexture |
||||
*/ |
||||
template<UnsignedInt dimensions> class TextureArray: public AbstractTexture { |
||||
public: |
||||
static const UnsignedInt Dimensions = dimensions; /**< @brief %Texture dimension count */ |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* |
||||
* Creates new OpenGL texture object. |
||||
* @see @fn_gl{GenTextures} with @def_gl{TEXTURE_1D_ARRAY} or @def_gl{TEXTURE_2D_ARRAY} |
||||
*/ |
||||
explicit TextureArray(): AbstractTexture(Implementation::textureArrayTarget<dimensions>()) {} |
||||
|
||||
/** @copydoc Texture::setMinificationFilter() */ |
||||
TextureArray<dimensions>& setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap = Sampler::Mipmap::Base) { |
||||
AbstractTexture::setMinificationFilter(filter, mipmap); |
||||
return *this; |
||||
} |
||||
|
||||
/** @copydoc Texture::setMagnificationFilter() */ |
||||
TextureArray<dimensions>& setMagnificationFilter(Sampler::Filter filter) { |
||||
AbstractTexture::setMagnificationFilter(filter); |
||||
return *this; |
||||
} |
||||
|
||||
/** @copydoc Texture::setWrapping() */ |
||||
TextureArray<dimensions>& setWrapping(const Array<dimensions+1, Sampler::Wrapping>& wrapping) { |
||||
DataHelper<dimensions+1>::setWrapping(*this, wrapping); |
||||
return *this; |
||||
} |
||||
|
||||
/** @copydoc Texture::setBorderColor() */ |
||||
TextureArray<dimensions>& setBorderColor(const Color4& color) { |
||||
AbstractTexture::setBorderColor(color); |
||||
return *this; |
||||
} |
||||
|
||||
/** @copydoc Texture::setMaxAnisotropy() */ |
||||
TextureArray<dimensions>& setMaxAnisotropy(Float anisotropy) { |
||||
AbstractTexture::setMaxAnisotropy(anisotropy); |
||||
return *this; |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/** @copydoc Texture::imageSize() */ |
||||
typename DimensionTraits<dimensions+1, Int>::VectorType imageSize(Int level) { |
||||
return DataHelper<dimensions+1>::imageSize(*this, _target, level); |
||||
} |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Set storage |
||||
* @param levels Mip level count |
||||
* @param internalFormat Internal format |
||||
* @param size Size of largest mip level |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* Specifies entire structure of a texture at once, removing the need |
||||
* for additional consistency checks and memory reallocations when |
||||
* updating the data later. After calling this function the texture |
||||
* is immutable and calling @ref setStorage() or @ref setImage() is not |
||||
* allowed. |
||||
* |
||||
* If @extension{EXT,direct_state_access} is not available, the texture |
||||
* is bound to some layer before the operation. If |
||||
* @extension{ARB,texture_storage} (part of OpenGL 4.2) or OpenGL ES |
||||
* 3.0 is not available, the feature is emulated with sequence of |
||||
* @ref setImage() calls. |
||||
* @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and |
||||
* @fn_gl{TexStorage2D}/@fn_gl{TexStorage3D} or |
||||
* @fn_gl_extension{TextureStorage2D,EXT,direct_state_access}/ |
||||
* @fn_gl_extension{TextureStorage3D,EXT,direct_state_access}, |
||||
* eventually @fn_gl{TexImage2D}/@fn_gl{TexImage3D} or |
||||
* @fn_gl_extension{TextureImage2D,EXT,direct_state_access}/ |
||||
* @fn_gl_extension{TextureImage3D,EXT,direct_state_access}. |
||||
*/ |
||||
TextureArray<dimensions>& setStorage(Int levels, TextureFormat internalFormat, const typename DimensionTraits<dimensions+1, Int>::VectorType& size) { |
||||
DataHelper<dimensions+1>::setStorage(*this, _target, levels, internalFormat, size); |
||||
return *this; |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/** @copydoc Texture::image(Int, Image<dimensions>&) */ |
||||
void image(Int level, Image<dimensions+1>& image) { |
||||
AbstractTexture::image<dimensions+1>(_target, level, image); |
||||
} |
||||
|
||||
/** @copydoc Texture::imate(Int, BufferImage<dimensions>&, BufferUsage) */ |
||||
void image(Int level, BufferImage<dimensions+1>& image, BufferUsage usage) { |
||||
AbstractTexture::image<dimensions+1>(_target, level, image, usage); |
||||
} |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Set image data |
||||
* @param level Mip level |
||||
* @param internalFormat Internal format |
||||
* @param image @ref Image, @ref ImageReference or |
||||
* @ref Trade::ImageData of the same dimension count |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* For better performance when generating mipmaps using |
||||
* @ref generateMipmap() or calling @ref setImage() more than once use |
||||
* @ref setStorage() and @ref setSubImage() instead. |
||||
* |
||||
* If @extension{EXT,direct_state_access} is not available, the |
||||
* texture is bound to some layer before the operation. |
||||
* @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and |
||||
* @fn_gl{TexImage2D}/@fn_gl{TexImage3D} or |
||||
* @fn_gl_extension{TextureImage2D,EXT,direct_state_access}/ |
||||
* @fn_gl_extension{TextureImage3D,EXT,direct_state_access} |
||||
*/ |
||||
TextureArray<dimensions>& setImage(Int level, TextureFormat internalFormat, const ImageReference<dimensions+1>& image) { |
||||
DataHelper<dimensions+1>::setImage(*this, _target, level, internalFormat, image); |
||||
return *this; |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
/** @overload */ |
||||
TextureArray<dimensions>& setImage(Int level, TextureFormat internalFormat, BufferImage<dimensions+1>& image) { |
||||
DataHelper<dimensions+1>::setImage(*this, _target, level, internalFormat, image); |
||||
return *this; |
||||
} |
||||
|
||||
/** @overload */ |
||||
TextureArray<dimensions>& setImage(Int level, TextureFormat internalFormat, BufferImage<dimensions+1>&& image) { |
||||
return setImage(level, internalFormat, image); |
||||
} |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Set image subdata |
||||
* @param level Mip level |
||||
* @param offset Offset where to put data in the texture |
||||
* @param image @ref Image, @ref ImageReference or |
||||
* @ref Trade::ImageData of the same dimension count |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* If @extension{EXT,direct_state_access} is not available, the |
||||
* texture is bound to some layer before the operation. |
||||
* @see @ref setStorage(), @ref setImage(), @fn_gl{ActiveTexture}, |
||||
* @fn_gl{BindTexture} and @fn_gl{TexSubImage2D}/@fn_gl{TexSubImage3D} |
||||
* or @fn_gl_extension{TextureSubImage2D,EXT,direct_state_access}/ |
||||
* @fn_gl_extension{TextureSubImage3D,EXT,direct_state_access} |
||||
*/ |
||||
TextureArray<dimensions>& setSubImage(Int level, const typename DimensionTraits<dimensions+1, Int>::VectorType& offset, const ImageReference<dimensions+1>& image) { |
||||
DataHelper<dimensions+1>::setSubImage(*this, _target, level, offset, image); |
||||
return *this; |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
/** @overload */ |
||||
TextureArray<dimensions>& setSubImage(Int level, const typename DimensionTraits<dimensions+1, Int>::VectorType& offset, BufferImage<dimensions+1>& image) { |
||||
DataHelper<dimensions+1>::setSubImage(*this, _target, level, offset, image); |
||||
return *this; |
||||
} |
||||
|
||||
/** @overload */ |
||||
TextureArray<dimensions>& setSubImage(Int level, const typename DimensionTraits<dimensions+1, Int>::VectorType& offset, BufferImage<dimensions+1>&& image) { |
||||
return setSubImage(level, offset, image); |
||||
} |
||||
#endif |
||||
|
||||
/** @copydoc Texture::generateMipmap() */ |
||||
TextureArray<dimensions>& generateMipmap() { |
||||
AbstractTexture::generateMipmap(); |
||||
return *this; |
||||
} |
||||
|
||||
/** @copydoc Texture::invalidateImage() */ |
||||
void invalidateImage(Int level) { AbstractTexture::invalidateImage(level); } |
||||
|
||||
/** @copydoc Texture::invalidateSubImage() */ |
||||
void invalidateSubImage(Int level, const typename DimensionTraits<dimensions+1, Int>::VectorType& offset, const typename DimensionTraits<dimensions+1, Int>::VectorType& size) { |
||||
DataHelper<dimensions+1>::invalidateSubImage(*this, level, offset, size); |
||||
} |
||||
|
||||
/* Overloads to remove WTF-factor from method chaining order */ |
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
TextureArray<dimensions>& setLabel(const std::string& label) { |
||||
AbstractTexture::setLabel(label); |
||||
return *this; |
||||
} |
||||
#endif |
||||
}; |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/**
|
||||
@brief One-dimensional texture array |
||||
|
||||
@requires_gl Only @ref Magnum::Texture2DArray "Texture2DArray" is available in |
||||
OpenGL ES. |
||||
*/ |
||||
typedef TextureArray<1> Texture1DArray; |
||||
#endif |
||||
|
||||
/** @brief Two-dimensional texture array */ |
||||
typedef TextureArray<2> Texture2DArray; |
||||
|
||||
} |
||||
#else |
||||
#error this header is not available on OpenGL ES 2.0 build |
||||
#endif |
||||
|
||||
#endif |
||||
Loading…
Reference in new issue