Browse Source

Distinguish dimensions (1D, 2D, 3D) from image size.

pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
aceb93c313
  1. 6
      src/BufferedImage.cpp
  2. 22
      src/BufferedImage.h
  3. 16
      src/Framebuffer.cpp
  4. 8
      src/Framebuffer.h
  5. 4
      src/Image.cpp
  6. 30
      src/Image.h
  7. 24
      src/ImageWrapper.h
  8. 4
      src/Texture.h
  9. 18
      src/Trade/ImageData.h

6
src/BufferedImage.cpp

@ -17,11 +17,11 @@
namespace Magnum { namespace Magnum {
template<size_t imageDimensions> void BufferedImage<imageDimensions>::setData(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) { template<size_t dimensions> void BufferedImage<dimensions>::setData(const Math::Vector<Dimensions, GLsizei>& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) {
_components = components; _components = components;
_type = type; _type = type;
_dimensions = dimensions; _size = size;
_buffer.setData(Buffer::Target::PixelPack, pixelSize(_components, _type)*dimensions.product(), data, usage); _buffer.setData(Buffer::Target::PixelPack, pixelSize(_components, _type)*size.product(), data, usage);
} }
template class BufferedImage<1>; template class BufferedImage<1>;

22
src/BufferedImage.h

@ -35,9 +35,9 @@ Trade::ImageData.
@see BufferedImage1D, BufferedImage2D, BufferedImage3D, Buffer @see BufferedImage1D, BufferedImage2D, BufferedImage3D, Buffer
@requires_gles30 (no extension providing this functionality) @requires_gles30 (no extension providing this functionality)
*/ */
template<size_t imageDimensions> class BufferedImage: public AbstractImage { template<size_t dimensions> class BufferedImage: public AbstractImage {
public: public:
const static size_t Dimensions = imageDimensions; /**< @brief Image dimension count */ const static size_t Dimensions = dimensions; /**< @brief Image dimension count */
/** /**
* @brief Constructor * @brief Constructor
@ -49,8 +49,8 @@ template<size_t imageDimensions> class BufferedImage: public AbstractImage {
*/ */
inline BufferedImage(Components components, ComponentType type): AbstractImage(components, type), _buffer(Buffer::Target::PixelPack) {} inline BufferedImage(Components components, ComponentType type): AbstractImage(components, type), _buffer(Buffer::Target::PixelPack) {}
/** @brief %Image dimensions */ /** @brief %Image size */
inline constexpr Math::Vector<Dimensions, GLsizei> dimensions() const { return _dimensions; } inline constexpr Math::Vector<Dimensions, GLsizei> size() const { return _size; }
/** /**
* @brief Data * @brief Data
@ -71,7 +71,7 @@ template<size_t imageDimensions> class BufferedImage: public AbstractImage {
/** /**
* @brief Set image data * @brief Set image data
* @param dimensions %Image dimensions * @param size %Image size
* @param components Color components. Data type is detected * @param components Color components. Data type is detected
* from passed data array. * from passed data array.
* @param data %Image data * @param data %Image data
@ -82,13 +82,13 @@ template<size_t imageDimensions> class BufferedImage: public AbstractImage {
* *
* @see setData(const Math::Vector<Dimensions, GLsizei>&, Components, ComponentType, const GLvoid*, Buffer::Usage) * @see setData(const Math::Vector<Dimensions, GLsizei>&, Components, ComponentType, const GLvoid*, Buffer::Usage)
*/ */
template<class T> inline void setData(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, const T* data, Buffer::Usage usage) { template<class T> inline void setData(const Math::Vector<Dimensions, GLsizei>& size, Components components, const T* data, Buffer::Usage usage) {
setData(dimensions, components, TypeTraits<T>::imageType(), data, usage); setData(size, components, TypeTraits<T>::imageType(), data, usage);
} }
/** /**
* @brief Set image data * @brief Set image data
* @param dimensions %Image dimensions * @param size %Image size
* @param components Color components * @param components Color components
* @param type Data type * @param type Data type
* @param data %Image data * @param data %Image data
@ -99,11 +99,11 @@ template<size_t imageDimensions> class BufferedImage: public AbstractImage {
* *
* @see Buffer::setData() * @see Buffer::setData()
*/ */
void setData(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage); void setData(const Math::Vector<Dimensions, GLsizei>& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage);
protected: protected:
Math::Vector<Dimensions, GLsizei> _dimensions; /**< @brief %Image dimensions */ Math::Vector<Dimensions, GLsizei> _size; /**< @brief %Image size */
Buffer _buffer; /**< @brief %Image buffer */ Buffer _buffer; /**< @brief %Image buffer */
}; };
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT

16
src/Framebuffer.cpp

@ -42,21 +42,21 @@ void Framebuffer::mapForDraw(std::initializer_list<int> colorAttachments) {
} }
#endif #endif
void Framebuffer::read(const Math::Vector2<GLint>& offset, const Math::Vector2<GLsizei>& dimensions, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image) { void Framebuffer::read(const Math::Vector2<GLint>& offset, const Math::Vector2<GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image) {
char* data = new char[AbstractImage::pixelSize(components, type)*dimensions.product()]; char* data = new char[AbstractImage::pixelSize(components, type)*size.product()];
glReadPixels(offset.x(), offset.y(), dimensions.x(), dimensions.y(), static_cast<GLenum>(components), static_cast<GLenum>(type), data); glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast<GLenum>(components), static_cast<GLenum>(type), data);
image->setData(dimensions, components, type, data); image->setData(size, components, type, data);
} }
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
void Framebuffer::read(const Math::Vector2<GLint>& offset, const Math::Vector2<GLsizei>& dimensions, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage) { void Framebuffer::read(const Math::Vector2<GLint>& offset, const Math::Vector2<GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage) {
/* If the buffer doesn't have sufficient size, resize it */ /* If the buffer doesn't have sufficient size, resize it */
/** @todo Explicitly reset also when buffer usage changes */ /** @todo Explicitly reset also when buffer usage changes */
if(image->dimensions() != dimensions || image->components() != components || image->type() != type) if(image->size() != size || image->components() != components || image->type() != type)
image->setData(dimensions, components, type, nullptr, usage); image->setData(size, components, type, nullptr, usage);
image->buffer()->bind(Buffer::Target::PixelPack); image->buffer()->bind(Buffer::Target::PixelPack);
glReadPixels(offset.x(), offset.y(), dimensions.x(), dimensions.y(), static_cast<GLenum>(components), static_cast<GLenum>(type), nullptr); glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast<GLenum>(components), static_cast<GLenum>(type), nullptr);
} }
#endif #endif

8
src/Framebuffer.h

@ -1134,7 +1134,7 @@ class MAGNUM_EXPORT Framebuffer {
/** /**
* @brief Read block of pixels from framebuffer to image * @brief Read block of pixels from framebuffer to image
* @param offset Offset in the framebuffer * @param offset Offset in the framebuffer
* @param dimensions %Image dimensions * @param size %Image size
* @param components Color components * @param components Color components
* @param type Data type * @param type Data type
* @param image %Image where to put the data * @param image %Image where to put the data
@ -1142,13 +1142,13 @@ class MAGNUM_EXPORT Framebuffer {
* @see @fn_gl{ReadPixels} * @see @fn_gl{ReadPixels}
* @requires_gl30 Extension @extension{EXT,framebuffer_object} * @requires_gl30 Extension @extension{EXT,framebuffer_object}
*/ */
static void read(const Math::Vector2<GLint>& offset, const Math::Vector2<GLsizei>& dimensions, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image); static void read(const Math::Vector2<GLint>& offset, const Math::Vector2<GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image);
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
/** /**
* @brief Read block of pixels from framebuffer to buffered image * @brief Read block of pixels from framebuffer to buffered image
* @param offset Offset in the framebuffer * @param offset Offset in the framebuffer
* @param dimensions %Image dimensions * @param size %Image size
* @param components Color components * @param components Color components
* @param type Data type * @param type Data type
* @param image Buffered image where to put the data * @param image Buffered image where to put the data
@ -1158,7 +1158,7 @@ class MAGNUM_EXPORT Framebuffer {
* @requires_gl * @requires_gl
* @requires_gl30 Extension @extension{EXT,framebuffer_object} * @requires_gl30 Extension @extension{EXT,framebuffer_object}
*/ */
static void read(const Math::Vector2<GLint>& offset, const Math::Vector2<GLsizei>& dimensions, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage); static void read(const Math::Vector2<GLint>& offset, const Math::Vector2<GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage);
#endif #endif
/*@}*/ /*@}*/

4
src/Image.cpp

@ -17,11 +17,11 @@
namespace Magnum { namespace Magnum {
template<size_t imageDimensions> void Image<imageDimensions>::setData(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, ComponentType type, GLvoid* data) { template<size_t dimensions> void Image<dimensions>::setData(const Math::Vector<Dimensions, GLsizei>& size, Components components, ComponentType type, GLvoid* data) {
delete[] _data; delete[] _data;
_components = components; _components = components;
_type = type; _type = type;
_dimensions = dimensions; _size = size;
_data = reinterpret_cast<char*>(data); _data = reinterpret_cast<char*>(data);
} }

30
src/Image.h

@ -33,13 +33,13 @@ ImageWrapper, BufferedImage, which stores image data in GPU memory, or for
example with Trade::ImageData. example with Trade::ImageData.
@see Image1D, Image2D, Image3D @see Image1D, Image2D, Image3D
*/ */
template<size_t imageDimensions> class Image: public AbstractImage { template<size_t dimensions> class Image: public AbstractImage {
public: public:
const static size_t Dimensions = imageDimensions; /**< @brief Image dimension count */ const static size_t Dimensions = dimensions; /**< @brief Image dimension count */
/** /**
* @brief Constructor * @brief Constructor
* @param dimensions %Image dimensions * @param size %Image size
* @param components Color components. Data type is detected * @param components Color components. Data type is detected
* from passed data array. * from passed data array.
* @param data %Image data with proper size * @param data %Image data with proper size
@ -47,11 +47,11 @@ template<size_t imageDimensions> class Image: public AbstractImage {
* Note that the image data are not copied on construction, but they * Note that the image data are not copied on construction, but they
* are deleted on class destruction. * are deleted on class destruction.
*/ */
template<class T> inline Image(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, T* data): AbstractImage(components, TypeTraits<T>::imageType()), _dimensions(dimensions), _data(data) {} template<class T> inline Image(const Math::Vector<Dimensions, GLsizei>& size, Components components, T* data): AbstractImage(components, TypeTraits<T>::imageType()), _size(size), _data(data) {}
/** /**
* @brief Constructor * @brief Constructor
* @param dimensions %Image dimensions * @param size %Image size
* @param components Color components * @param components Color components
* @param type Data type * @param type Data type
* @param data %Image data * @param data %Image data
@ -59,7 +59,7 @@ template<size_t imageDimensions> class Image: public AbstractImage {
* Note that the image data are not copied on construction, but they * Note that the image data are not copied on construction, but they
* are deleted on class destruction. * are deleted on class destruction.
*/ */
inline Image(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _dimensions(dimensions), _data(reinterpret_cast<char*>(data)) {} inline Image(const Math::Vector<Dimensions, GLsizei>& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _size(size), _data(reinterpret_cast<char*>(data)) {}
/** /**
* @brief Constructor * @brief Constructor
@ -74,8 +74,8 @@ template<size_t imageDimensions> class Image: public AbstractImage {
/** @brief Destructor */ /** @brief Destructor */
inline ~Image() { delete[] _data; } inline ~Image() { delete[] _data; }
/** @brief %Image dimensions */ /** @brief %Image size */
inline constexpr const Math::Vector<Dimensions, GLsizei>& dimensions() const { return _dimensions; } inline constexpr const Math::Vector<Dimensions, GLsizei>& size() const { return _size; }
/** @brief Pointer to raw data */ /** @brief Pointer to raw data */
inline void* data() { return _data; } inline void* data() { return _data; }
@ -83,7 +83,7 @@ template<size_t imageDimensions> class Image: public AbstractImage {
/** /**
* @brief Set image data * @brief Set image data
* @param dimensions %Image dimensions * @param size %Image size
* @param components Color components. Data type is detected * @param components Color components. Data type is detected
* from passed data array. * from passed data array.
* @param data %Image data * @param data %Image data
@ -91,13 +91,13 @@ template<size_t imageDimensions> class Image: public AbstractImage {
* Deletes previous data and replaces them with new. Note that the * Deletes previous data and replaces them with new. Note that the
* data are not copied, but they are deleted on destruction. * data are not copied, but they are deleted on destruction.
*/ */
template<class T> inline void setData(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, T* data) { template<class T> inline void setData(const Math::Vector<Dimensions, GLsizei>& size, Components components, T* data) {
setData(dimensions, components, TypeTraits<T>::imageType(), data); setData(size, components, TypeTraits<T>::imageType(), data);
} }
/** /**
* @brief Set image data * @brief Set image data
* @param dimensions %Image dimensions * @param size %Image size
* @param components Color components * @param components Color components
* @param type Data type * @param type Data type
* @param data %Image data * @param data %Image data
@ -105,11 +105,11 @@ template<size_t imageDimensions> class Image: public AbstractImage {
* Deletes previous data and replaces them with new. Note that the * Deletes previous data and replaces them with new. Note that the
* data are not copied, but they are deleted on destruction. * data are not copied, but they are deleted on destruction.
*/ */
void setData(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, ComponentType type, GLvoid* data); void setData(const Math::Vector<Dimensions, GLsizei>& size, Components components, ComponentType type, GLvoid* data);
protected: protected:
Math::Vector<Dimensions, GLsizei> _dimensions; /**< @brief %Image dimensions */ Math::Vector<Dimensions, GLsizei> _size; /**< @brief %Image size */
char* _data; /**< @brief %Image data */ char* _data; /**< @brief %Image data */
}; };
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT

24
src/ImageWrapper.h

@ -39,13 +39,13 @@ to change image properties, only data pointer.
See also Image, BufferedImage and Trade::ImageData. See also Image, BufferedImage and Trade::ImageData.
*/ */
template<size_t imageDimensions> class ImageWrapper: public AbstractImage { template<size_t dimensions> class ImageWrapper: public AbstractImage {
public: public:
const static size_t Dimensions = imageDimensions; /**< @brief Image dimension count */ const static size_t Dimensions = dimensions; /**< @brief Image dimension count */
/** /**
* @brief Constructor * @brief Constructor
* @param dimensions %Image dimensions * @param size %Image size
* @param components Color components. Data type is detected * @param components Color components. Data type is detected
* from passed data array. * from passed data array.
* @param data %Image data with proper size * @param data %Image data with proper size
@ -53,11 +53,11 @@ template<size_t imageDimensions> class ImageWrapper: public AbstractImage {
* Note that the image data are not copied on construction, but they * Note that the image data are not copied on construction, but they
* are deleted on class destruction. * are deleted on class destruction.
*/ */
template<class T> inline ImageWrapper(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, T* data): AbstractImage(components, TypeTraits<T>::imageType()), _dimensions(dimensions), _data(data) {} template<class T> inline ImageWrapper(const Math::Vector<Dimensions, GLsizei>& size, Components components, T* data): AbstractImage(components, TypeTraits<T>::imageType()), _size(size), _data(data) {}
/** /**
* @brief Constructor * @brief Constructor
* @param dimensions %Image dimensions * @param size %Image size
* @param components Color components * @param components Color components
* @param type Data type * @param type Data type
* @param data %Image data * @param data %Image data
@ -65,21 +65,21 @@ template<size_t imageDimensions> class ImageWrapper: public AbstractImage {
* Note that the image data are not copied on construction, but they * Note that the image data are not copied on construction, but they
* are deleted on class destruction. * are deleted on class destruction.
*/ */
inline ImageWrapper(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _dimensions(dimensions), _data(reinterpret_cast<char*>(data)) {} inline ImageWrapper(const Math::Vector<Dimensions, GLsizei>& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _size(size), _data(reinterpret_cast<char*>(data)) {}
/** /**
* @brief Constructor * @brief Constructor
* @param dimensions %Image dimensions * @param size %Image size
* @param components Color components * @param components Color components
* @param type Data type * @param type Data type
* *
* Dimensions and data pointer are set to zero, call setData() to fill * Dimensions and data pointer are set to zero, call setData() to fill
* the image with data. * the image with data.
*/ */
inline ImageWrapper(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, ComponentType type): AbstractImage(components, type), _dimensions(dimensions), _data(nullptr) {} inline ImageWrapper(const Math::Vector<Dimensions, GLsizei>& size, Components components, ComponentType type): AbstractImage(components, type), _size(size), _data(nullptr) {}
/** @brief %Image dimensions */ /** @brief %Image size */
inline constexpr const Math::Vector<Dimensions, GLsizei>& dimensions() const { return _dimensions; } inline constexpr const Math::Vector<Dimensions, GLsizei>& size() const { return _size; }
/** @brief Pointer to raw data */ /** @brief Pointer to raw data */
inline void* data() { return _data; } inline void* data() { return _data; }
@ -98,8 +98,8 @@ template<size_t imageDimensions> class ImageWrapper: public AbstractImage {
} }
protected: protected:
Math::Vector<Dimensions, GLsizei> _dimensions; /**< @brief %Image dimensions */ Math::Vector<Dimensions, GLsizei> _size; /**< @brief %Image size */
char* _data; /**< @brief %Image data */ char* _data; /**< @brief %Image data */
}; };
/** @brief One-dimensional image wrapper */ /** @brief One-dimensional image wrapper */

4
src/Texture.h

@ -48,9 +48,9 @@ for more information.
@see Texture1D, Texture2D, Texture3D, CubeMapTexture, CubeMapTextureArray @see Texture1D, Texture2D, Texture3D, CubeMapTexture, CubeMapTextureArray
*/ */
template<size_t textureDimensions> class Texture: public AbstractTexture { template<size_t dimensions> class Texture: public AbstractTexture {
public: 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 #ifdef DOXYGEN_GENERATING_OUTPUT
/** /**

18
src/Trade/ImageData.h

@ -31,14 +31,14 @@ namespace Magnum { namespace Trade {
Provides access to image data and additional information about data type and Provides access to image data and additional information about data type and
dimensions. Can be used in the same situations as Image and BufferedImage. dimensions. Can be used in the same situations as Image and BufferedImage.
*/ */
template<size_t imageDimensions> class ImageData: public AbstractImage { template<size_t dimensions> class ImageData: public AbstractImage {
public: public:
const static size_t Dimensions = imageDimensions; /**< @brief %Image dimension count */ const static size_t Dimensions = dimensions; /**< @brief %Image dimension count */
/** /**
* @brief Constructor * @brief Constructor
* @param name %Image name * @param name %Image name
* @param dimensions %Image dimensions * @param size %Image size
* @param components Color components. Data type is detected * @param components Color components. Data type is detected
* from passed data array. * from passed data array.
* @param data %Image data * @param data %Image data
@ -46,12 +46,12 @@ template<size_t imageDimensions> class ImageData: public AbstractImage {
* Note that the image data are not copied on construction, but they * Note that the image data are not copied on construction, but they
* are deleted on class destruction. * are deleted on class destruction.
*/ */
template<class T> inline ImageData(const std::string& name, const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, T* data): AbstractImage(components, TypeTraits<T>::imageType()), _name(name), _dimensions(dimensions), _data(reinterpret_cast<char*>(data)) {} template<class T> inline ImageData(const std::string& name, const Math::Vector<Dimensions, GLsizei>& size, Components components, T* data): AbstractImage(components, TypeTraits<T>::imageType()), _name(name), _size(size), _data(reinterpret_cast<char*>(data)) {}
/** /**
* @brief Constructor * @brief Constructor
* @param name %Image name * @param name %Image name
* @param dimensions %Image dimensions * @param size %Image size
* @param components Color components * @param components Color components
* @param type Data type * @param type Data type
* @param data %Image data * @param data %Image data
@ -59,7 +59,7 @@ template<size_t imageDimensions> class ImageData: public AbstractImage {
* Note that the image data are not copied on construction, but they * Note that the image data are not copied on construction, but they
* are deleted on class destruction. * are deleted on class destruction.
*/ */
inline ImageData(const std::string& name, const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _name(name), _dimensions(dimensions), _data(reinterpret_cast<char*>(data)) {} inline ImageData(const std::string& name, const Math::Vector<Dimensions, GLsizei>& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _name(name), _size(size), _data(reinterpret_cast<char*>(data)) {}
/** @brief Destructor */ /** @brief Destructor */
inline ~ImageData() { delete[] _data; } inline ~ImageData() { delete[] _data; }
@ -67,8 +67,8 @@ template<size_t imageDimensions> class ImageData: public AbstractImage {
/** @brief %Image name */ /** @brief %Image name */
inline std::string name() const { return _name; } inline std::string name() const { return _name; }
/** @brief %Image dimensions */ /** @brief %Image size */
inline constexpr const Math::Vector<Dimensions, GLsizei>& dimensions() const { return _dimensions; } inline constexpr const Math::Vector<Dimensions, GLsizei>& size() const { return _size; }
/** @brief Pointer to raw data */ /** @brief Pointer to raw data */
inline void* data() { return _data; } inline void* data() { return _data; }
@ -76,7 +76,7 @@ template<size_t imageDimensions> class ImageData: public AbstractImage {
private: private:
std::string _name; std::string _name;
Math::Vector<Dimensions, GLsizei> _dimensions; Math::Vector<Dimensions, GLsizei> _size;
char* _data; char* _data;
}; };

Loading…
Cancel
Save