Browse Source

Convenience *Texture::image() overloads.

Similar to Framebuffer::read(), it's now possible to get texture image
also in single statement:

    Image2D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte});

in comparison to the previous way:

    Image2D image{ColorFormat::RGBA, ColorType::UnsignedByte};
    texture.image(0, image);

The previous way is still kept in the API and not deprecated, as it
might be more usable in some cases.
pull/94/head
Vladimír Vondruš 11 years ago
parent
commit
67581895e2
  1. 10
      src/Magnum/CubeMapTexture.cpp
  2. 18
      src/Magnum/CubeMapTexture.h
  3. 12
      src/Magnum/CubeMapTextureArray.cpp
  4. 18
      src/Magnum/CubeMapTextureArray.h
  5. 12
      src/Magnum/RectangleTexture.cpp
  6. 18
      src/Magnum/RectangleTexture.h
  7. 12
      src/Magnum/Test/CubeMapTextureArrayGLTest.cpp
  8. 16
      src/Magnum/Test/CubeMapTextureGLTest.cpp
  9. 12
      src/Magnum/Test/RectangleTextureGLTest.cpp
  10. 24
      src/Magnum/Test/TextureArrayGLTest.cpp
  11. 36
      src/Magnum/Test/TextureGLTest.cpp
  12. 37
      src/Magnum/Texture.cpp
  13. 18
      src/Magnum/Texture.h
  14. 17
      src/Magnum/TextureArray.cpp
  15. 18
      src/Magnum/TextureArray.h

10
src/Magnum/CubeMapTexture.cpp

@ -65,6 +65,11 @@ void CubeMapTexture::image(const Coordinate coordinate, const Int level, Image2D
image.setData(image.format(), image.type(), size, data);
}
Image2D CubeMapTexture::image(const Coordinate coordinate, const Int level, Image2D&& image) {
this->image(coordinate, level, image);
return std::move(image);
}
void CubeMapTexture::image(const Coordinate coordinate, const Int level, BufferImage2D& image, const BufferUsage usage) {
const Vector2i size = imageSize(level);
const std::size_t dataSize = image.dataSize(size);
@ -74,6 +79,11 @@ void CubeMapTexture::image(const Coordinate coordinate, const Int level, BufferI
image.buffer().bindInternal(Buffer::TargetHint::PixelPack);
(this->*Context::current()->state().texture->getCubeImageImplementation)(coordinate, level, size, image.format(), image.type(), dataSize, nullptr);
}
BufferImage2D CubeMapTexture::image(const Coordinate coordinate, const Int level, BufferImage2D&& image, const BufferUsage usage) {
this->image(coordinate, level, image, usage);
return std::move(image);
}
#endif
CubeMapTexture& CubeMapTexture::setSubImage(const Coordinate coordinate, const Int level, const Vector2i& offset, const ImageReference2D& image) {

18
src/Magnum/CubeMapTexture.h

@ -386,6 +386,15 @@ class MAGNUM_EXPORT CubeMapTexture: public AbstractTexture {
*/
void image(Coordinate coordinate, Int level, Image2D& image);
/** @overload
*
* Convenience alternative to the above, example usage:
* @code
* Image2D image = texture.image(CubeMapTexture::Coordinate::PositiveX, 0, {ColorFormat::RGBA, ColorType::UnsignedByte});
* @endcode
*/
Image2D image(Coordinate coordinate, Int level, Image2D&& image);
/**
* @copybrief Texture::image(Int, BufferImage&, BufferUsage)
*
@ -394,6 +403,15 @@ class MAGNUM_EXPORT CubeMapTexture: public AbstractTexture {
* @requires_gl Texture image queries are not available in OpenGL ES.
*/
void image(Coordinate coordinate, Int level, BufferImage2D& image, BufferUsage usage);
/** @overload
*
* Convenience alternative to the above, example usage:
* @code
* BufferImage2D image = texture.image(CubeMapTexture::Coordinate::PositiveX, 0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
* @endcode
*/
BufferImage2D image(Coordinate coordinate, Int level, BufferImage2D&& image, BufferUsage usage);
#endif
/**

12
src/Magnum/CubeMapTextureArray.cpp

@ -26,8 +26,10 @@
#include "CubeMapTextureArray.h"
#ifndef MAGNUM_TARGET_GLES
#include "Magnum/BufferImage.h"
#include "Magnum/Context.h"
#include "Magnum/Extensions.h"
#include "Magnum/Image.h"
#include "Implementation/maxTextureSize.h"
@ -41,5 +43,15 @@ Vector3i CubeMapTextureArray::maxSize() {
Implementation::maxTextureArrayLayers()};
}
Image3D CubeMapTextureArray::image(const Int level, Image3D&& image) {
this->image(level, image);
return std::move(image);
}
BufferImage3D CubeMapTextureArray::image(const Int level, BufferImage3D&& image, const BufferUsage usage) {
this->image(level, image, usage);
return std::move(image);
}
}
#endif

18
src/Magnum/CubeMapTextureArray.h

@ -328,6 +328,15 @@ class MAGNUM_EXPORT CubeMapTextureArray: public AbstractTexture {
AbstractTexture::image<3>(level, image);
}
/** @overload
*
* Convenience alternative to the above, example usage:
* @code
* Image3D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte});
* @endcode
*/
Image3D image(Int level, Image3D&& image);
/**
* @copybrief Texture::image(Int, BufferImage&, BufferUsage)
*
@ -338,6 +347,15 @@ class MAGNUM_EXPORT CubeMapTextureArray: public AbstractTexture {
AbstractTexture::image<3>(level, image, usage);
}
/** @overload
*
* Convenience alternative to the above, example usage:
* @code
* BufferImage3D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
* @endcode
*/
BufferImage3D image(Int level, BufferImage3D&& image, BufferUsage usage);
/**
* @copybrief Texture::setImage()
* @return Reference to self (for method chaining)

12
src/Magnum/RectangleTexture.cpp

@ -26,8 +26,10 @@
#include "RectangleTexture.h"
#ifndef MAGNUM_TARGET_GLES
#include "Magnum/BufferImage.h"
#include "Magnum/Context.h"
#include "Magnum/Extensions.h"
#include "Magnum/Image.h"
#include "Implementation/State.h"
#include "Implementation/TextureState.h"
@ -46,5 +48,15 @@ Vector2i RectangleTexture::maxSize() {
return Vector2i{value};
}
Image2D RectangleTexture::image(Image2D&& image) {
this->image(image);
return std::move(image);
}
BufferImage2D RectangleTexture::image(BufferImage2D&& image, const BufferUsage usage) {
this->image(image, usage);
return std::move(image);
}
}
#endif

18
src/Magnum/RectangleTexture.h

@ -260,6 +260,15 @@ class MAGNUM_EXPORT RectangleTexture: public AbstractTexture {
AbstractTexture::image<2>(0, image);
}
/** @overload
*
* Convenience alternative to the above, example usage:
* @code
* Image2D image = texture.image({ColorFormat::RGBA, ColorType::UnsignedByte});
* @endcode
*/
Image2D image(Image2D&& image);
/**
* @brief Read texture to buffer image
*
@ -270,6 +279,15 @@ class MAGNUM_EXPORT RectangleTexture: public AbstractTexture {
AbstractTexture::image<2>(0, image, usage);
}
/** @overload
*
* Convenience alternative to the above, example usage:
* @code
* BufferImage2D image = texture.image({ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
* @endcode
*/
BufferImage2D image(BufferImage2D&& image, BufferUsage usage);
/**
* @copybrief Texture::setImage()
* @return Reference to self (for method chaining)

12
src/Magnum/Test/CubeMapTextureArrayGLTest.cpp

@ -240,8 +240,7 @@ void CubeMapTextureArrayGLTest::image() {
MAGNUM_VERIFY_NO_ERROR();
Image3D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image);
Image3D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
@ -279,8 +278,7 @@ void CubeMapTextureArrayGLTest::imageBuffer() {
MAGNUM_VERIFY_NO_ERROR();
BufferImage3D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image, BufferUsage::StaticRead);
BufferImage3D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
@ -316,8 +314,7 @@ void CubeMapTextureArrayGLTest::subImage() {
MAGNUM_VERIFY_NO_ERROR();
Image3D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image);
Image3D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
@ -381,8 +378,7 @@ void CubeMapTextureArrayGLTest::subImageBuffer() {
MAGNUM_VERIFY_NO_ERROR();
BufferImage3D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image, BufferUsage::StaticRead);
BufferImage3D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();

16
src/Magnum/Test/CubeMapTextureGLTest.cpp

@ -289,8 +289,7 @@ void CubeMapTextureGLTest::image() {
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
Image2D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(CubeMapTexture::Coordinate::PositiveX, 0, image);
Image2D image = texture.image(CubeMapTexture::Coordinate::PositiveX, 0, {ColorFormat::RGBA, ColorType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
@ -314,13 +313,12 @@ void CubeMapTextureGLTest::imageBuffer() {
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
BufferImage2D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(CubeMapTexture::Coordinate::PositiveX, 0, image, BufferUsage::StaticRead);
BufferImage2D image = texture.image(CubeMapTexture::Coordinate::PositiveX, 0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i(2));
const auto imageData = image.buffer().data<UnsignedByte>();
CORRADE_COMPARE_AS(std::vector<UnsignedByte>(imageData.begin(), imageData.end()),
std::vector<UnsignedByte>(data, data+16), TestSuite::Compare::Container);
#endif
@ -343,8 +341,7 @@ void CubeMapTextureGLTest::subImage() {
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
Image2D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(CubeMapTexture::Coordinate::PositiveX, 0, image);
Image2D image = texture.image(CubeMapTexture::Coordinate::PositiveX, 0, {ColorFormat::RGBA, ColorType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
@ -375,13 +372,12 @@ void CubeMapTextureGLTest::subImageBuffer() {
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
BufferImage2D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(CubeMapTexture::Coordinate::PositiveX, 0, image, BufferUsage::StaticRead);
BufferImage2D image = texture.image(CubeMapTexture::Coordinate::PositiveX, 0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i(4));
const auto imageData = image.buffer().data<UnsignedByte>();
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,

12
src/Magnum/Test/RectangleTextureGLTest.cpp

@ -213,8 +213,7 @@ void RectangleTextureGLTest::image() {
MAGNUM_VERIFY_NO_ERROR();
Image2D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(image);
Image2D image = texture.image({ColorFormat::RGBA, ColorType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
@ -237,8 +236,7 @@ void RectangleTextureGLTest::imageBuffer() {
MAGNUM_VERIFY_NO_ERROR();
BufferImage2D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(image, BufferUsage::StaticRead);
BufferImage2D image = texture.image({ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
@ -265,8 +263,7 @@ void RectangleTextureGLTest::subImage() {
MAGNUM_VERIFY_NO_ERROR();
Image2D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(image);
Image2D image = texture.image({ColorFormat::RGBA, ColorType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
@ -296,8 +293,7 @@ void RectangleTextureGLTest::subImageBuffer() {
MAGNUM_VERIFY_NO_ERROR();
BufferImage2D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(image, BufferUsage::StaticRead);
BufferImage2D image = texture.image({ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();

24
src/Magnum/Test/TextureArrayGLTest.cpp

@ -549,8 +549,7 @@ void TextureArrayGLTest::image1D() {
MAGNUM_VERIFY_NO_ERROR();
Image2D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image);
Image2D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
@ -573,8 +572,7 @@ void TextureArrayGLTest::image1DBuffer() {
MAGNUM_VERIFY_NO_ERROR();
BufferImage2D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image, BufferUsage::StaticRead);
BufferImage2D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
@ -607,8 +605,7 @@ void TextureArrayGLTest::image2D() {
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
Image3D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image);
Image3D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
@ -640,8 +637,7 @@ void TextureArrayGLTest::image2DBuffer() {
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
BufferImage3D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image, BufferUsage::StaticRead);
BufferImage3D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
@ -670,8 +666,7 @@ void TextureArrayGLTest::subImage1D() {
MAGNUM_VERIFY_NO_ERROR();
Image2D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image);
Image2D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
@ -701,8 +696,7 @@ void TextureArrayGLTest::subImage1DBuffer() {
MAGNUM_VERIFY_NO_ERROR();
BufferImage2D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image, BufferUsage::StaticRead);
BufferImage2D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
@ -742,8 +736,7 @@ void TextureArrayGLTest::subImage2D() {
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
Image3D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image);
Image3D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
@ -797,8 +790,7 @@ void TextureArrayGLTest::subImage2DBuffer() {
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
BufferImage3D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image, BufferUsage::StaticRead);
BufferImage3D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();

36
src/Magnum/Test/TextureGLTest.cpp

@ -724,8 +724,7 @@ void TextureGLTest::image1D() {
MAGNUM_VERIFY_NO_ERROR();
Image1D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image);
Image1D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
@ -743,8 +742,7 @@ void TextureGLTest::image1DBuffer() {
MAGNUM_VERIFY_NO_ERROR();
BufferImage1D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image, BufferUsage::StaticDraw);
BufferImage1D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticDraw);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
@ -768,8 +766,7 @@ void TextureGLTest::image2D() {
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
Image2D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image);
Image2D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
@ -793,8 +790,7 @@ void TextureGLTest::image2DBuffer() {
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
BufferImage2D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image, BufferUsage::StaticRead);
BufferImage2D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
@ -828,8 +824,7 @@ void TextureGLTest::image3D() {
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
Image3D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image);
Image3D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
@ -857,8 +852,7 @@ void TextureGLTest::image3DBuffer() {
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
BufferImage3D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image, BufferUsage::StaticRead);
BufferImage3D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
@ -883,8 +877,7 @@ void TextureGLTest::subImage1D() {
MAGNUM_VERIFY_NO_ERROR();
Image1D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image);
Image1D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
@ -906,8 +899,7 @@ void TextureGLTest::subImage1DBuffer() {
MAGNUM_VERIFY_NO_ERROR();
BufferImage1D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image, BufferUsage::StaticRead);
BufferImage1D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
@ -935,8 +927,7 @@ void TextureGLTest::subImage2D() {
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
Image2D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image);
Image2D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
@ -967,8 +958,7 @@ void TextureGLTest::subImage2DBuffer() {
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
BufferImage2D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image, BufferUsage::StaticRead);
BufferImage2D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
@ -1009,8 +999,7 @@ void TextureGLTest::subImage3D() {
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
Image3D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image);
Image3D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
@ -1060,8 +1049,7 @@ void TextureGLTest::subImage3DBuffer() {
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
BufferImage3D image(ColorFormat::RGBA, ColorType::UnsignedByte);
texture.image(0, image, BufferUsage::StaticRead);
BufferImage3D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();

37
src/Magnum/Texture.cpp

@ -28,11 +28,18 @@
#include "Magnum/Context.h"
#include "Magnum/Extensions.h"
#ifndef MAGNUM_TARGET_GLES
#include "Magnum/BufferImage.h"
#include "Magnum/Image.h"
#endif
#include "Implementation/maxTextureSize.h"
#include "Implementation/State.h"
#include "Implementation/TextureState.h"
namespace Magnum { namespace Implementation {
namespace Magnum {
namespace Implementation {
template<UnsignedInt dimensions> VectorTypeFor<dimensions, Int> maxTextureSize() {
return VectorTypeFor<dimensions, Int>{Implementation::maxTextureSideSize()};
@ -51,4 +58,30 @@ template<> MAGNUM_EXPORT Vector3i maxTextureSize<3>() {
return {Vector2i(Implementation::maxTextureSideSize()), Implementation::max3DTextureDepth()};
}
}}
}
#ifndef MAGNUM_TARGET_GLES
template<UnsignedInt dimensions> Image<dimensions> Texture<dimensions>::image(const Int level, Image<dimensions>&& image) {
this->image(level, image);
return std::move(image);
}
#ifndef DOXYGEN_GENERATING_OUTPUT
template MAGNUM_EXPORT Image<1> Texture<1>::image(Int, Image<1>&&);
template MAGNUM_EXPORT Image<2> Texture<2>::image(Int, Image<2>&&);
template MAGNUM_EXPORT Image<3> Texture<3>::image(Int, Image<3>&&);
#endif
template<UnsignedInt dimensions> BufferImage<dimensions> Texture<dimensions>::image(const Int level, BufferImage<dimensions>&& image, const BufferUsage usage) {
this->image(level, image, usage);
return std::move(image);
}
#ifndef DOXYGEN_GENERATING_OUTPUT
template MAGNUM_EXPORT BufferImage<1> Texture<1>::image(Int, BufferImage<1>&&, BufferUsage);
template MAGNUM_EXPORT BufferImage<2> Texture<2>::image(Int, BufferImage<2>&&, BufferUsage);
template MAGNUM_EXPORT BufferImage<3> Texture<3>::image(Int, BufferImage<3>&&, BufferUsage);
#endif
#endif
}

18
src/Magnum/Texture.h

@ -653,6 +653,15 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
AbstractTexture::image<dimensions>(level, image);
}
/** @overload
*
* Convenience alternative to the above, example usage:
* @code
* Image2D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte});
* @endcode
*/
Image<dimensions> image(Int level, Image<dimensions>&& image);
/**
* @brief Read given mip level of texture to buffer image
* @param level Mip level
@ -667,6 +676,15 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
void image(Int level, BufferImage<dimensions>& image, BufferUsage usage) {
AbstractTexture::image<dimensions>(level, image, usage);
}
/** @overload
*
* Convenience alternative to the above, example usage:
* @code
* BufferImage2D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
* @endcode
*/
BufferImage<dimensions> image(Int level, BufferImage<dimensions>&& image, BufferUsage usage);
#endif
/**

17
src/Magnum/TextureArray.cpp

@ -29,6 +29,11 @@
#include "Magnum/Context.h"
#include "Magnum/Extensions.h"
#ifndef MAGNUM_TARGET_GLES
#include "Magnum/BufferImage.h"
#include "Magnum/Image.h"
#endif
#include "Implementation/maxTextureSize.h"
namespace Magnum {
@ -49,6 +54,18 @@ template<UnsignedInt dimensions> VectorTypeFor<dimensions+1, Int> TextureArray<d
Implementation::maxTextureArrayLayers()};
}
#ifndef MAGNUM_TARGET_GLES
template<UnsignedInt dimensions> Image<dimensions+1> TextureArray<dimensions>::image(const Int level, Image<dimensions+1>&& image) {
this->image(level, image);
return std::move(image);
}
template<UnsignedInt dimensions> BufferImage<dimensions+1> TextureArray<dimensions>::image(const Int level, BufferImage<dimensions+1>&& image, const BufferUsage usage) {
this->image(level, image, usage);
return std::move(image);
}
#endif
#ifndef MAGNUM_TARGET_GLES
template class MAGNUM_EXPORT TextureArray<1>;
#endif

18
src/Magnum/TextureArray.h

@ -357,6 +357,15 @@ template<UnsignedInt dimensions> class TextureArray: public AbstractTexture {
AbstractTexture::image<dimensions+1>(level, image);
}
/** @overload
*
* Convenience alternative to the above, example usage:
* @code
* Image3D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte});
* @endcode
*/
Image<dimensions+1> image(Int level, Image<dimensions+1>&& image);
/**
* @copybrief Texture::image(Int, BufferImage&, BufferUsage)
* @return Reference to self (for method chaining)
@ -368,6 +377,15 @@ template<UnsignedInt dimensions> class TextureArray: public AbstractTexture {
void image(Int level, BufferImage<dimensions+1>& image, BufferUsage usage) {
AbstractTexture::image<dimensions+1>(level, image, usage);
}
/** @overload
*
* Convenience alternative to the above, example usage:
* @code
* BufferImage3D image = texture.image(0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead);
* @endcode
*/
BufferImage<dimensions+1> image(Int level, BufferImage<dimensions+1>&& image, BufferUsage usage);
#endif
/**

Loading…
Cancel
Save