Browse Source

Ability to reset BufferImage formats without reallocating the buffer.

Will be used in various image getters to avoid overwriting previous data
in combination with pixel storage skip parameters.
pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
5ee461bdbe
  1. 15
      src/Magnum/BufferImage.cpp
  2. 8
      src/Magnum/BufferImage.h

15
src/Magnum/BufferImage.cpp

@ -28,20 +28,27 @@
namespace Magnum {
#ifndef MAGNUM_TARGET_GLES2
template<UnsignedInt dimensions> BufferImage<dimensions>::BufferImage(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}, _type{type}, _size{size}, _buffer{Buffer::TargetHint::PixelPack} {
template<UnsignedInt dimensions> BufferImage<dimensions>::BufferImage(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}, _type{type}, _size{size}, _buffer{Buffer::TargetHint::PixelPack}, _dataSize{data.size()} {
CORRADE_ASSERT(Implementation::imageDataSize(*this) <= data.size(), "BufferImage::BufferImage(): bad image data size, got" << data.size() << "but expected at least" << Implementation::imageDataSize(*this), );
_buffer.setData(data, usage);
}
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} {}
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> 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;
_type = type;
_size = size;
CORRADE_ASSERT(Implementation::imageDataSize(*this) <= data.size(), "BufferImage::setData(): bad image data size, got" << data.size() << "but expected at least" << Implementation::imageDataSize(*this), );
_buffer.setData(data, usage);
/* Keep the old storage if zero-sized nullptr buffer was passed */
if(data.data() == nullptr && data.size() == 0)
CORRADE_ASSERT(Implementation::imageDataSize(*this) <= _dataSize, "BufferImage::setData(): bad current storage size, got" << _dataSize << "but expected at least" << Implementation::imageDataSize(*this), );
else {
CORRADE_ASSERT(Implementation::imageDataSize(*this) <= data.size(), "BufferImage::setData(): bad image data size, got" << data.size() << "but expected at least" << Implementation::imageDataSize(*this), );
_buffer.setData(data, usage);
_dataSize = data.size();
}
}
template<UnsignedInt dimensions> CompressedBufferImage<dimensions>::CompressedBufferImage(

8
src/Magnum/BufferImage.h

@ -148,6 +148,9 @@ template<UnsignedInt dimensions> class BufferImage {
return Implementation::imageDataProperties<dimensions>(*this);
}
/** @brief Currently allocated data size */
std::size_t dataSize() const { return _dataSize; }
/** @brief Image buffer */
Buffer& buffer() { return _buffer; }
@ -160,7 +163,9 @@ template<UnsignedInt dimensions> class BufferImage {
* @param data Image data
* @param usage Image buffer usage
*
* Updates the image buffer with given data.
* Updates the image buffer with given data. Passing `nullptr`
* zero-sized @p data will not reallocate current storage, but expects
* that current data size is large enough for the new parameters.
* @see @ref Buffer::setData()
* @todo Make it more flexible (usable with
* @extension{ARB,buffer_storage}, avoiding relocations...)
@ -201,6 +206,7 @@ template<UnsignedInt dimensions> class BufferImage {
PixelType _type;
Math::Vector<Dimensions, Int> _size;
Buffer _buffer;
std::size_t _dataSize;
};
/** @brief One-dimensional buffer image */

Loading…
Cancel
Save