Browse Source

Added NoCreate {Compressed,}BufferImage constructors.

To have common API across the board.
pull/193/head
Vladimír Vondruš 9 years ago
parent
commit
f0cf36dea5
  1. 6
      src/Magnum/BufferImage.cpp
  2. 21
      src/Magnum/BufferImage.h
  3. 26
      src/Magnum/Test/BufferImageGLTest.cpp

6
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<UnsignedInt dimensions> BufferImage<dimensions>::BufferImage(const Pixe
template<UnsignedInt dimensions> BufferImage<dimensions>::BufferImage(const PixelStorage storage, const PixelFormat format, const PixelType type): _storage{storage}, _format{format}, _type{type}, _buffer{Buffer::TargetHint::PixelPack}, _dataSize{0} {}
template<UnsignedInt dimensions> BufferImage<dimensions>::BufferImage(NoCreateT) noexcept: _format{PixelFormat::RGBA}, _type{PixelType::UnsignedByte}, _buffer{NoCreate}, _dataSize{} {}
template<UnsignedInt dimensions> void BufferImage<dimensions>::setData(const PixelStorage storage, const PixelFormat format, const PixelType type, const VectorTypeFor<dimensions, Int>& size, Containers::ArrayView<const void> const data, const BufferUsage usage) {
_storage = storage;
_format = format;
@ -88,6 +92,8 @@ template<UnsignedInt dimensions> CompressedBufferImage<dimensions>::CompressedBu
#endif
_format{}, _buffer{Buffer::TargetHint::PixelPack}, _dataSize{} {}
template<UnsignedInt dimensions> CompressedBufferImage<dimensions>::CompressedBufferImage(NoCreateT) noexcept: _format{}, _buffer{NoCreate}, _dataSize{} {}
template<UnsignedInt dimensions> void CompressedBufferImage<dimensions>::setData(
#ifndef MAGNUM_TARGET_GLES
const CompressedPixelStorage storage,

21
src/Magnum/BufferImage.h

@ -128,6 +128,17 @@ template<UnsignedInt dimensions> 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<dimensions>&) = delete;
@ -348,6 +359,16 @@ template<UnsignedInt dimensions> 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<dimensions>&) = delete;

26
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;

Loading…
Cancel
Save