Browse Source

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

vectorfields
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 {
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;
_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>;

22
src/BufferedImage.h

@ -35,9 +35,9 @@ Trade::ImageData.
@see BufferedImage1D, BufferedImage2D, BufferedImage3D, Buffer
@requires_gles30 (no extension providing this functionality)
*/
template<size_t imageDimensions> class BufferedImage: public AbstractImage {
template<size_t dimensions> 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<size_t imageDimensions> 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, GLsizei> dimensions() const { return _dimensions; }
/** @brief %Image size */
inline constexpr Math::Vector<Dimensions, GLsizei> size() const { return _size; }
/**
* @brief Data
@ -71,7 +71,7 @@ template<size_t imageDimensions> 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<size_t imageDimensions> class BufferedImage: public AbstractImage {
*
* @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) {
setData(dimensions, components, TypeTraits<T>::imageType(), data, usage);
template<class T> inline void setData(const Math::Vector<Dimensions, GLsizei>& size, Components components, const T* data, Buffer::Usage usage) {
setData(size, components, TypeTraits<T>::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<size_t imageDimensions> class BufferedImage: public AbstractImage {
*
* @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:
Math::Vector<Dimensions, GLsizei> _dimensions; /**< @brief %Image dimensions */
Buffer _buffer; /**< @brief %Image buffer */
Math::Vector<Dimensions, GLsizei> _size; /**< @brief %Image size */
Buffer _buffer; /**< @brief %Image buffer */
};
#ifndef DOXYGEN_GENERATING_OUTPUT

16
src/Framebuffer.cpp

@ -42,21 +42,21 @@ void Framebuffer::mapForDraw(std::initializer_list<int> colorAttachments) {
}
#endif
void Framebuffer::read(const Math::Vector2<GLint>& offset, const Math::Vector2<GLsizei>& 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<GLenum>(components), static_cast<GLenum>(type), data);
image->setData(dimensions, components, type, data);
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)*size.product()];
glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast<GLenum>(components), static_cast<GLenum>(type), data);
image->setData(size, components, type, data);
}
#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 */
/** @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<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

8
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<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
/**
* @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<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
/*@}*/

4
src/Image.cpp

@ -17,11 +17,11 @@
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;
_components = components;
_type = type;
_dimensions = dimensions;
_size = size;
_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.
@see Image1D, Image2D, Image3D
*/
template<size_t imageDimensions> class Image: public AbstractImage {
template<size_t dimensions> 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<size_t imageDimensions> class Image: public AbstractImage {
* Note that the image data are not copied on construction, but they
* 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
* @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<size_t imageDimensions> 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, 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
@ -74,8 +74,8 @@ template<size_t imageDimensions> class Image: public AbstractImage {
/** @brief Destructor */
inline ~Image() { delete[] _data; }
/** @brief %Image dimensions */
inline constexpr const Math::Vector<Dimensions, GLsizei>& dimensions() const { return _dimensions; }
/** @brief %Image size */
inline constexpr const Math::Vector<Dimensions, GLsizei>& size() const { return _size; }
/** @brief Pointer to raw data */
inline void* data() { return _data; }
@ -83,7 +83,7 @@ template<size_t imageDimensions> 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<size_t imageDimensions> 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<class T> inline void setData(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, T* data) {
setData(dimensions, components, TypeTraits<T>::imageType(), data);
template<class T> inline void setData(const Math::Vector<Dimensions, GLsizei>& size, Components components, T* data) {
setData(size, components, TypeTraits<T>::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<size_t imageDimensions> 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, GLsizei>& dimensions, Components components, ComponentType type, GLvoid* data);
void setData(const Math::Vector<Dimensions, GLsizei>& size, Components components, ComponentType type, GLvoid* data);
protected:
Math::Vector<Dimensions, GLsizei> _dimensions; /**< @brief %Image dimensions */
char* _data; /**< @brief %Image data */
Math::Vector<Dimensions, GLsizei> _size; /**< @brief %Image size */
char* _data; /**< @brief %Image data */
};
#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.
*/
template<size_t imageDimensions> class ImageWrapper: public AbstractImage {
template<size_t dimensions> 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<size_t imageDimensions> class ImageWrapper: public AbstractImage {
* Note that the image data are not copied on construction, but they
* 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
* @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<size_t imageDimensions> 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, 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
* @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, 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 */
inline constexpr const Math::Vector<Dimensions, GLsizei>& dimensions() const { return _dimensions; }
/** @brief %Image size */
inline constexpr const Math::Vector<Dimensions, GLsizei>& size() const { return _size; }
/** @brief Pointer to raw data */
inline void* data() { return _data; }
@ -98,8 +98,8 @@ template<size_t imageDimensions> class ImageWrapper: public AbstractImage {
}
protected:
Math::Vector<Dimensions, GLsizei> _dimensions; /**< @brief %Image dimensions */
char* _data; /**< @brief %Image data */
Math::Vector<Dimensions, GLsizei> _size; /**< @brief %Image size */
char* _data; /**< @brief %Image data */
};
/** @brief One-dimensional image wrapper */

4
src/Texture.h

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

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
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:
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<size_t imageDimensions> class ImageData: public AbstractImage {
* Note that the image data are not copied on construction, but they
* 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
* @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<size_t imageDimensions> 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, 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 */
inline ~ImageData() { delete[] _data; }
@ -67,8 +67,8 @@ template<size_t imageDimensions> class ImageData: public AbstractImage {
/** @brief %Image name */
inline std::string name() const { return _name; }
/** @brief %Image dimensions */
inline constexpr const Math::Vector<Dimensions, GLsizei>& dimensions() const { return _dimensions; }
/** @brief %Image size */
inline constexpr const Math::Vector<Dimensions, GLsizei>& size() const { return _size; }
/** @brief Pointer to raw data */
inline void* data() { return _data; }
@ -76,7 +76,7 @@ template<size_t imageDimensions> class ImageData: public AbstractImage {
private:
std::string _name;
Math::Vector<Dimensions, GLsizei> _dimensions;
Math::Vector<Dimensions, GLsizei> _size;
char* _data;
};

Loading…
Cancel
Save