From f31cbccbcc8bfc42acc62a24955442a343c8aecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 7 Jan 2014 16:05:45 +0100 Subject: [PATCH] Default template parameter for Buffer::data(), templated Image::data(). To have BufferImage::buffer().data() consistent with Image::data() (default is unsigned char data type, but it is possible to reinterpret the data). Saves some ugly code: Image2D image(ColorFormat::RGB, ColorType::UnsignedByte, ...); Color3ub a = reinterpret_cast(image.data())[0]; // before Color3ub b = image.data()[0]; // after --- src/Buffer.h | 4 ++-- src/Image.h | 10 ++++++++-- src/ImageReference.h | 5 +++++ src/Trade/ImageData.h | 10 ++++++++-- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/Buffer.h b/src/Buffer.h index 5c787b7a7..5b0f5dd8a 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -636,7 +636,7 @@ class MAGNUM_EXPORT Buffer: public AbstractObject { * @requires_gl %Buffer data queries are not available in OpenGL ES. * Use @ref Magnum::Buffer::map() "map()" instead. */ - template Containers::Array data(); + template Containers::Array data(); /** * @brief %Buffer subdata @@ -652,7 +652,7 @@ class MAGNUM_EXPORT Buffer: public AbstractObject { * @requires_gl %Buffer data queries are not available in OpenGL ES. * Use @ref Magnum::Buffer::map() "map()" instead. */ - template Containers::Array subData(GLintptr offset, GLsizeiptr size); + template Containers::Array subData(GLintptr offset, GLsizeiptr size); #endif /** diff --git a/src/Image.h b/src/Image.h index 9c9881e86..7af8728e0 100644 --- a/src/Image.h +++ b/src/Image.h @@ -101,8 +101,14 @@ template class Image: public AbstractImage { * * @see @ref release() */ - unsigned char* data() { return _data; } - const unsigned char* data() const { return _data; } /**< @overload */ + template T* data() { + return reinterpret_cast(_data); + } + + /** @overload */ + template const T* data() const { + return reinterpret_cast(_data); + } /** * @brief Set image data diff --git a/src/ImageReference.h b/src/ImageReference.h index d2f754e16..02bd8141f 100644 --- a/src/ImageReference.h +++ b/src/ImageReference.h @@ -79,6 +79,11 @@ template class ImageReference: public AbstractImage { /** @brief Pointer to raw data */ constexpr const unsigned char* data() const { return _data; } + /** @overload */ + template const T* data() const { + return reinterpret_cast(_data); + } + /** * @brief Set image data * @param data %Image data diff --git a/src/Trade/ImageData.h b/src/Trade/ImageData.h index 181b768bb..bc2f09dd4 100644 --- a/src/Trade/ImageData.h +++ b/src/Trade/ImageData.h @@ -91,8 +91,14 @@ template class ImageData: public AbstractImage { * * @see @ref release() */ - unsigned char* data() { return _data; } - const unsigned char* data() const { return _data; } /**< @overload */ + template T* data() { + return reinterpret_cast(_data); + } + + /** @overload */ + template const T* data() const { + return reinterpret_cast(_data); + } /** * @brief Release data storage