diff --git a/src/Magnum/BufferImage.cpp b/src/Magnum/BufferImage.cpp index 0bef6d859..97f670cab 100644 --- a/src/Magnum/BufferImage.cpp +++ b/src/Magnum/BufferImage.cpp @@ -25,6 +25,8 @@ #include "BufferImage.h" +#include "Magnum/PixelFormat.h" + namespace Magnum { #ifndef MAGNUM_TARGET_GLES2 @@ -39,6 +41,8 @@ template BufferImage::BufferImage(const Pixe template BufferImage::BufferImage(const PixelStorage storage, const PixelFormat format, const PixelType type): _storage{storage}, _format{format}, _type{type}, _buffer{Buffer::TargetHint::PixelPack}, _dataSize{0} {} +template BufferImage::BufferImage(NoCreateT) noexcept: _format{PixelFormat::RGBA}, _type{PixelType::UnsignedByte}, _buffer{NoCreate}, _dataSize{} {} + template void BufferImage::setData(const PixelStorage storage, const PixelFormat format, const PixelType type, const VectorTypeFor& size, Containers::ArrayView const data, const BufferUsage usage) { _storage = storage; _format = format; @@ -88,6 +92,8 @@ template CompressedBufferImage::CompressedBu #endif _format{}, _buffer{Buffer::TargetHint::PixelPack}, _dataSize{} {} +template CompressedBufferImage::CompressedBufferImage(NoCreateT) noexcept: _format{}, _buffer{NoCreate}, _dataSize{} {} + template void CompressedBufferImage::setData( #ifndef MAGNUM_TARGET_GLES const CompressedPixelStorage storage, diff --git a/src/Magnum/BufferImage.h b/src/Magnum/BufferImage.h index a77e865ce..7e626edcf 100644 --- a/src/Magnum/BufferImage.h +++ b/src/Magnum/BufferImage.h @@ -128,6 +128,17 @@ template class BufferImage { */ /*implicit*/ BufferImage(PixelFormat format, PixelType type): BufferImage{{}, format, type} {} + /** + * @brief Construct without creating the underlying OpenGL object + * + * The constructed instance is equivalent to moved-from state with + * @ref PixelFormat::RGBA and @ref PixelType::UnsignedByte. Useful in + * cases where you will overwrite the instance later anyway. Move + * another object over it to make it useful. + * @see @ref BufferImage(), @ref wrap() + */ + explicit BufferImage(NoCreateT) noexcept; + /** @brief Copying is not allowed */ BufferImage(const BufferImage&) = delete; @@ -348,6 +359,16 @@ template class CompressedBufferImage { */ /*implicit*/ CompressedBufferImage(); + /** + * @brief Construct without creating the underlying OpenGL object + * + * The constructed instance is equivalent to moved-from state. Useful + * in cases where you will overwrite the instance later anyway. Move + * another object over it to make it useful. + * @see @ref BufferImage(), @ref wrap() + */ + explicit CompressedBufferImage(NoCreateT) noexcept; + /** @brief Copying is not allowed */ CompressedBufferImage(const CompressedBufferImage&) = delete; diff --git a/src/Magnum/Test/BufferImageGLTest.cpp b/src/Magnum/Test/BufferImageGLTest.cpp index 5220c2840..d156622a7 100644 --- a/src/Magnum/Test/BufferImageGLTest.cpp +++ b/src/Magnum/Test/BufferImageGLTest.cpp @@ -36,6 +36,8 @@ struct BufferImageGLTest: OpenGLTester { void construct(); void constructCompressed(); + void constructNoCreate(); + void constructNoCreateCompressed(); void constructBuffer(); void constructBufferCompressed(); void constructCopy(); @@ -53,6 +55,8 @@ struct BufferImageGLTest: OpenGLTester { BufferImageGLTest::BufferImageGLTest() { addTests({&BufferImageGLTest::construct, &BufferImageGLTest::constructCompressed, + &BufferImageGLTest::constructNoCreate, + &BufferImageGLTest::constructNoCreateCompressed, &BufferImageGLTest::constructBuffer, &BufferImageGLTest::constructBufferCompressed, &BufferImageGLTest::constructCopy, @@ -119,6 +123,28 @@ void BufferImageGLTest::constructCompressed() { #endif } +void BufferImageGLTest::constructNoCreate() { + { + BufferImage2D image{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(image.buffer().id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} + +void BufferImageGLTest::constructNoCreateCompressed() { + { + CompressedBufferImage2D image{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(image.buffer().id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} + void BufferImageGLTest::constructBuffer() { const char data[] = { 'a', 'b', 'c' }; Buffer buffer;