From aceb93c313ce0abb7351fb4d20e1e5c920fb400b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 1 Oct 2012 22:33:48 +0200 Subject: [PATCH] Distinguish dimensions (1D, 2D, 3D) from image size. --- src/BufferedImage.cpp | 6 +++--- src/BufferedImage.h | 22 +++++++++++----------- src/Framebuffer.cpp | 16 ++++++++-------- src/Framebuffer.h | 8 ++++---- src/Image.cpp | 4 ++-- src/Image.h | 30 +++++++++++++++--------------- src/ImageWrapper.h | 24 ++++++++++++------------ src/Texture.h | 4 ++-- src/Trade/ImageData.h | 18 +++++++++--------- 9 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/BufferedImage.cpp b/src/BufferedImage.cpp index 94907a60c..e40a9ab3f 100644 --- a/src/BufferedImage.cpp +++ b/src/BufferedImage.cpp @@ -17,11 +17,11 @@ namespace Magnum { -template void BufferedImage::setData(const Math::Vector& dimensions, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) { +template void BufferedImage::setData(const Math::Vector& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) { _components = components; _type = type; - _dimensions = dimensions; - _buffer.setData(Buffer::Target::PixelPack, pixelSize(_components, _type)*dimensions.product(), data, usage); + _size = size; + _buffer.setData(Buffer::Target::PixelPack, pixelSize(_components, _type)*size.product(), data, usage); } template class BufferedImage<1>; diff --git a/src/BufferedImage.h b/src/BufferedImage.h index 528284f8b..38f4ece69 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -35,9 +35,9 @@ Trade::ImageData. @see BufferedImage1D, BufferedImage2D, BufferedImage3D, Buffer @requires_gles30 (no extension providing this functionality) */ -template class BufferedImage: public AbstractImage { +template class BufferedImage: public AbstractImage { public: - const static size_t Dimensions = imageDimensions; /**< @brief Image dimension count */ + const static size_t Dimensions = dimensions; /**< @brief Image dimension count */ /** * @brief Constructor @@ -49,8 +49,8 @@ template class BufferedImage: public AbstractImage { */ inline BufferedImage(Components components, ComponentType type): AbstractImage(components, type), _buffer(Buffer::Target::PixelPack) {} - /** @brief %Image dimensions */ - inline constexpr Math::Vector dimensions() const { return _dimensions; } + /** @brief %Image size */ + inline constexpr Math::Vector size() const { return _size; } /** * @brief Data @@ -71,7 +71,7 @@ template class BufferedImage: public AbstractImage { /** * @brief Set image data - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components. Data type is detected * from passed data array. * @param data %Image data @@ -82,13 +82,13 @@ template class BufferedImage: public AbstractImage { * * @see setData(const Math::Vector&, Components, ComponentType, const GLvoid*, Buffer::Usage) */ - template inline void setData(const Math::Vector& dimensions, Components components, const T* data, Buffer::Usage usage) { - setData(dimensions, components, TypeTraits::imageType(), data, usage); + template inline void setData(const Math::Vector& size, Components components, const T* data, Buffer::Usage usage) { + setData(size, components, TypeTraits::imageType(), data, usage); } /** * @brief Set image data - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components * @param type Data type * @param data %Image data @@ -99,11 +99,11 @@ template class BufferedImage: public AbstractImage { * * @see Buffer::setData() */ - void setData(const Math::Vector& dimensions, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage); + void setData(const Math::Vector& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage); protected: - Math::Vector _dimensions; /**< @brief %Image dimensions */ - Buffer _buffer; /**< @brief %Image buffer */ + Math::Vector _size; /**< @brief %Image size */ + Buffer _buffer; /**< @brief %Image buffer */ }; #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index d0e158e08..e0cfa6303 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -42,21 +42,21 @@ void Framebuffer::mapForDraw(std::initializer_list colorAttachments) { } #endif -void Framebuffer::read(const Math::Vector2& offset, const Math::Vector2& dimensions, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image) { - char* data = new char[AbstractImage::pixelSize(components, type)*dimensions.product()]; - glReadPixels(offset.x(), offset.y(), dimensions.x(), dimensions.y(), static_cast(components), static_cast(type), data); - image->setData(dimensions, components, type, data); +void Framebuffer::read(const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image) { + char* data = new char[AbstractImage::pixelSize(components, type)*size.product()]; + glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast(components), static_cast(type), data); + image->setData(size, components, type, data); } #ifndef MAGNUM_TARGET_GLES -void Framebuffer::read(const Math::Vector2& offset, const Math::Vector2& dimensions, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage) { +void Framebuffer::read(const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage) { /* If the buffer doesn't have sufficient size, resize it */ /** @todo Explicitly reset also when buffer usage changes */ - if(image->dimensions() != dimensions || image->components() != components || image->type() != type) - image->setData(dimensions, components, type, nullptr, usage); + if(image->size() != size || image->components() != components || image->type() != type) + image->setData(size, components, type, nullptr, usage); image->buffer()->bind(Buffer::Target::PixelPack); - glReadPixels(offset.x(), offset.y(), dimensions.x(), dimensions.y(), static_cast(components), static_cast(type), nullptr); + glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast(components), static_cast(type), nullptr); } #endif diff --git a/src/Framebuffer.h b/src/Framebuffer.h index d1278ff86..1c69674d9 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -1134,7 +1134,7 @@ class MAGNUM_EXPORT Framebuffer { /** * @brief Read block of pixels from framebuffer to image * @param offset Offset in the framebuffer - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components * @param type Data type * @param image %Image where to put the data @@ -1142,13 +1142,13 @@ class MAGNUM_EXPORT Framebuffer { * @see @fn_gl{ReadPixels} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ - static void read(const Math::Vector2& offset, const Math::Vector2& dimensions, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image); + static void read(const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image); #ifndef MAGNUM_TARGET_GLES /** * @brief Read block of pixels from framebuffer to buffered image * @param offset Offset in the framebuffer - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components * @param type Data type * @param image Buffered image where to put the data @@ -1158,7 +1158,7 @@ class MAGNUM_EXPORT Framebuffer { * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ - static void read(const Math::Vector2& offset, const Math::Vector2& dimensions, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage); + static void read(const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage); #endif /*@}*/ diff --git a/src/Image.cpp b/src/Image.cpp index 2172837cd..f12b2caa7 100644 --- a/src/Image.cpp +++ b/src/Image.cpp @@ -17,11 +17,11 @@ namespace Magnum { -template void Image::setData(const Math::Vector& dimensions, Components components, ComponentType type, GLvoid* data) { +template void Image::setData(const Math::Vector& size, Components components, ComponentType type, GLvoid* data) { delete[] _data; _components = components; _type = type; - _dimensions = dimensions; + _size = size; _data = reinterpret_cast(data); } diff --git a/src/Image.h b/src/Image.h index a9268db34..37d4c820d 100644 --- a/src/Image.h +++ b/src/Image.h @@ -33,13 +33,13 @@ ImageWrapper, BufferedImage, which stores image data in GPU memory, or for example with Trade::ImageData. @see Image1D, Image2D, Image3D */ -template class Image: public AbstractImage { +template class Image: public AbstractImage { public: - const static size_t Dimensions = imageDimensions; /**< @brief Image dimension count */ + const static size_t Dimensions = dimensions; /**< @brief Image dimension count */ /** * @brief Constructor - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components. Data type is detected * from passed data array. * @param data %Image data with proper size @@ -47,11 +47,11 @@ template class Image: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - template inline Image(const Math::Vector& dimensions, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _dimensions(dimensions), _data(data) {} + template inline Image(const Math::Vector& size, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _size(size), _data(data) {} /** * @brief Constructor - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components * @param type Data type * @param data %Image data @@ -59,7 +59,7 @@ template class Image: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - inline Image(const Math::Vector& dimensions, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _dimensions(dimensions), _data(reinterpret_cast(data)) {} + inline Image(const Math::Vector& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _size(size), _data(reinterpret_cast(data)) {} /** * @brief Constructor @@ -74,8 +74,8 @@ template class Image: public AbstractImage { /** @brief Destructor */ inline ~Image() { delete[] _data; } - /** @brief %Image dimensions */ - inline constexpr const Math::Vector& dimensions() const { return _dimensions; } + /** @brief %Image size */ + inline constexpr const Math::Vector& size() const { return _size; } /** @brief Pointer to raw data */ inline void* data() { return _data; } @@ -83,7 +83,7 @@ template class Image: public AbstractImage { /** * @brief Set image data - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components. Data type is detected * from passed data array. * @param data %Image data @@ -91,13 +91,13 @@ template class Image: public AbstractImage { * Deletes previous data and replaces them with new. Note that the * data are not copied, but they are deleted on destruction. */ - template inline void setData(const Math::Vector& dimensions, Components components, T* data) { - setData(dimensions, components, TypeTraits::imageType(), data); + template inline void setData(const Math::Vector& size, Components components, T* data) { + setData(size, components, TypeTraits::imageType(), data); } /** * @brief Set image data - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components * @param type Data type * @param data %Image data @@ -105,11 +105,11 @@ template class Image: public AbstractImage { * Deletes previous data and replaces them with new. Note that the * data are not copied, but they are deleted on destruction. */ - void setData(const Math::Vector& dimensions, Components components, ComponentType type, GLvoid* data); + void setData(const Math::Vector& size, Components components, ComponentType type, GLvoid* data); protected: - Math::Vector _dimensions; /**< @brief %Image dimensions */ - char* _data; /**< @brief %Image data */ + Math::Vector _size; /**< @brief %Image size */ + char* _data; /**< @brief %Image data */ }; #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/ImageWrapper.h b/src/ImageWrapper.h index d8c0370a7..e1237e329 100644 --- a/src/ImageWrapper.h +++ b/src/ImageWrapper.h @@ -39,13 +39,13 @@ to change image properties, only data pointer. See also Image, BufferedImage and Trade::ImageData. */ -template class ImageWrapper: public AbstractImage { +template class ImageWrapper: public AbstractImage { public: - const static size_t Dimensions = imageDimensions; /**< @brief Image dimension count */ + const static size_t Dimensions = dimensions; /**< @brief Image dimension count */ /** * @brief Constructor - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components. Data type is detected * from passed data array. * @param data %Image data with proper size @@ -53,11 +53,11 @@ template class ImageWrapper: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - template inline ImageWrapper(const Math::Vector& dimensions, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _dimensions(dimensions), _data(data) {} + template inline ImageWrapper(const Math::Vector& size, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _size(size), _data(data) {} /** * @brief Constructor - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components * @param type Data type * @param data %Image data @@ -65,21 +65,21 @@ template class ImageWrapper: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - inline ImageWrapper(const Math::Vector& dimensions, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _dimensions(dimensions), _data(reinterpret_cast(data)) {} + inline ImageWrapper(const Math::Vector& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _size(size), _data(reinterpret_cast(data)) {} /** * @brief Constructor - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components * @param type Data type * * Dimensions and data pointer are set to zero, call setData() to fill * the image with data. */ - inline ImageWrapper(const Math::Vector& dimensions, Components components, ComponentType type): AbstractImage(components, type), _dimensions(dimensions), _data(nullptr) {} + inline ImageWrapper(const Math::Vector& size, Components components, ComponentType type): AbstractImage(components, type), _size(size), _data(nullptr) {} - /** @brief %Image dimensions */ - inline constexpr const Math::Vector& dimensions() const { return _dimensions; } + /** @brief %Image size */ + inline constexpr const Math::Vector& size() const { return _size; } /** @brief Pointer to raw data */ inline void* data() { return _data; } @@ -98,8 +98,8 @@ template class ImageWrapper: public AbstractImage { } protected: - Math::Vector _dimensions; /**< @brief %Image dimensions */ - char* _data; /**< @brief %Image data */ + Math::Vector _size; /**< @brief %Image size */ + char* _data; /**< @brief %Image data */ }; /** @brief One-dimensional image wrapper */ diff --git a/src/Texture.h b/src/Texture.h index ca8d54a4b..015f18cdb 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -48,9 +48,9 @@ for more information. @see Texture1D, Texture2D, Texture3D, CubeMapTexture, CubeMapTextureArray */ -template class Texture: public AbstractTexture { +template class Texture: public AbstractTexture { public: - static const size_t Dimensions = textureDimensions; /**< @brief %Texture dimension count */ + static const size_t Dimensions = dimensions; /**< @brief %Texture dimension count */ #ifdef DOXYGEN_GENERATING_OUTPUT /** diff --git a/src/Trade/ImageData.h b/src/Trade/ImageData.h index 98a4345a4..260fa8d8a 100644 --- a/src/Trade/ImageData.h +++ b/src/Trade/ImageData.h @@ -31,14 +31,14 @@ namespace Magnum { namespace Trade { Provides access to image data and additional information about data type and dimensions. Can be used in the same situations as Image and BufferedImage. */ -template class ImageData: public AbstractImage { +template class ImageData: public AbstractImage { public: - const static size_t Dimensions = imageDimensions; /**< @brief %Image dimension count */ + const static size_t Dimensions = dimensions; /**< @brief %Image dimension count */ /** * @brief Constructor * @param name %Image name - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components. Data type is detected * from passed data array. * @param data %Image data @@ -46,12 +46,12 @@ template class ImageData: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - template inline ImageData(const std::string& name, const Math::Vector& dimensions, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _name(name), _dimensions(dimensions), _data(reinterpret_cast(data)) {} + template inline ImageData(const std::string& name, const Math::Vector& size, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _name(name), _size(size), _data(reinterpret_cast(data)) {} /** * @brief Constructor * @param name %Image name - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components * @param type Data type * @param data %Image data @@ -59,7 +59,7 @@ template class ImageData: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - inline ImageData(const std::string& name, const Math::Vector& dimensions, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _name(name), _dimensions(dimensions), _data(reinterpret_cast(data)) {} + inline ImageData(const std::string& name, const Math::Vector& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _name(name), _size(size), _data(reinterpret_cast(data)) {} /** @brief Destructor */ inline ~ImageData() { delete[] _data; } @@ -67,8 +67,8 @@ template class ImageData: public AbstractImage { /** @brief %Image name */ inline std::string name() const { return _name; } - /** @brief %Image dimensions */ - inline constexpr const Math::Vector& dimensions() const { return _dimensions; } + /** @brief %Image size */ + inline constexpr const Math::Vector& size() const { return _size; } /** @brief Pointer to raw data */ inline void* data() { return _data; } @@ -76,7 +76,7 @@ template class ImageData: public AbstractImage { private: std::string _name; - Math::Vector _dimensions; + Math::Vector _size; char* _data; };