Browse Source

Image formats rework.

Renamed the enums and enum values to be consistent with OpenGL, added
integer types, fixed OpenGL ES compatibility.
pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
90ed04dc7a
  1. 114
      src/AbstractImage.cpp
  2. 411
      src/AbstractImage.h
  3. 52
      src/AbstractTexture.cpp
  4. 52
      src/AbstractTexture.h
  5. 6
      src/BufferedImage.cpp
  6. 31
      src/BufferedImage.h
  7. 16
      src/Framebuffer.cpp
  8. 12
      src/Framebuffer.h
  9. 4
      src/Image.cpp
  10. 43
      src/Image.h
  11. 27
      src/ImageWrapper.h
  12. 17
      src/Trade/ImageData.h
  13. 24
      src/TypeTraits.h

114
src/AbstractImage.cpp

@ -21,80 +21,100 @@
namespace Magnum {
std::size_t AbstractImage::pixelSize(Components format, ComponentType type) {
std::size_t AbstractImage::pixelSize(Format format, Type type) {
std::size_t size = 0;
switch(type) {
#ifndef MAGNUM_TARGET_GLES
case ComponentType::RGB332:
case ComponentType::BGR233:
return 1;
case Type::UnsignedByte:
#ifndef MAGNUM_TARGET_GLES2
case Type::Byte:
#endif
case ComponentType::RGB565:
#ifndef MAGNUM_TARGET_GLES
case ComponentType::BGR565:
size = 1; break;
case Type::UnsignedShort:
#ifndef MAGNUM_TARGET_GLES2
case Type::Short:
#endif
case Type::HalfFloat:
size = 2; break;
case Type::UnsignedInt:
#ifndef MAGNUM_TARGET_GLES2
case Type::Int:
#endif
case ComponentType::RGBA4:
case Type::Float:
size = 4; break;
#ifndef MAGNUM_TARGET_GLES
case ComponentType::ABGR4:
case Type::UnsignedByte332:
case Type::UnsignedByte233Rev:
return 1;
#endif
case ComponentType::RGB5Alpha1:
case Type::UnsignedShort565:
#ifndef MAGNUM_TARGET_GLES
case ComponentType::Alpha1BGR5:
case Type::UnsignedShort565Rev:
#endif
case Type::UnsignedShort4444:
case Type::UnsignedShort4444Rev:
case Type::UnsignedShort5551:
case Type::UnsignedShort1555Rev:
return 2;
#ifndef MAGNUM_TARGET_GLES
case ComponentType::RGBA8:
case ComponentType::ABGR8:
case ComponentType::RGB10Alpha2:
case ComponentType::Alpha2RGB10:
case ComponentType::Depth24Stencil8:
case ComponentType::B10GR11Float:
case ComponentType::Exponent5RGB9:
case Type::UnsignedInt8888:
case Type::UnsignedInt8888Rev:
case Type::UnsignedInt1010102:
#endif
case Type::UnsignedInt2101010Rev:
#ifndef MAGNUM_TARGET_GLES2
case Type::UnsignedInt10F11F11FRev:
case Type::UnsignedInt5999Rev:
#endif
case Type::UnsignedInt248:
return 4;
case ComponentType::Depth32FloatStencil8:
#ifndef MAGNUM_TARGET_GLES2
case Type::Float32UnsignedInt248Rev:
return 8;
#endif
case ComponentType::UnsignedByte:
case ComponentType::Byte:
size = 1; break;
case ComponentType::UnsignedShort:
case ComponentType::Short:
#ifndef MAGNUM_TARGET_GLES
case ComponentType::HalfFloat:
size = 2; break;
#endif
case ComponentType::UnsignedInt:
case ComponentType::Int:
case ComponentType::Float:
size = 4; break;
}
switch(format) {
case Format::Red:
#ifndef MAGNUM_TARGET_GLES2
case Format::RedInteger:
#endif
#ifndef MAGNUM_TARGET_GLES
case Components::Red:
case Components::Green:
case Components::Blue:
case Format::Green:
case Format::Blue:
case Format::GreenInteger:
case Format::BlueInteger:
#endif
return 1*size;
case Components::RedGreen:
case Format::RG:
#ifndef MAGNUM_TARGET_GLES2
case Format::RGInteger:
#endif
return 2*size;
case Format::RGB:
#ifndef MAGNUM_TARGET_GLES2
case Format::RGBInteger:
#endif
case Components::RGB:
#ifndef MAGNUM_TARGET_GLES
case Components::BGR:
case Format::BGR:
case Format::BGRInteger:
#endif
return 3*size;
case Components::RGBA:
#ifndef MAGNUM_TARGET_GLES
case Components::BGRA:
case Format::RGBA:
#ifndef MAGNUM_TARGET_GLES2
case Format::RGBAInteger:
#endif
case Format::BGRA:
#ifndef MAGNUM_TARGET_GLES2
case Format::BGRAInteger:
#endif
return 4*size;
#ifndef MAGNUM_TARGET_GLES
case Components::Depth:
case Components::StencilIndex:
case Components::DepthStencil:
/* Handled above */
case Format::DepthComponent:
case Format::StencilIndex:
case Format::DepthStencil:
CORRADE_INTERNAL_ASSERT(false);
#endif
}
return 0;

411
src/AbstractImage.h

@ -30,7 +30,8 @@ namespace Magnum {
/**
@brief Non-templated base for one-, two- or three-dimensional images
See Image, BufferedImage, Trade::ImageData documentation for more information.
See Image, ImageWrapper, BufferedImage, Trade::ImageData documentation for
more information.
*/
class MAGNUM_EXPORT AbstractImage {
AbstractImage(const AbstractImage& other) = delete;
@ -47,217 +48,377 @@ class MAGNUM_EXPORT AbstractImage {
* Texture::setData() and others).
*/
/** @brief Color components */
/** @todo Support *_INTEGER types */
enum class Components: GLenum {
#ifndef MAGNUM_TARGET_GLES
/**
* @brief Format of pixel data
*
* @todo What is allowed for FB reading and what for image
* specification?
* @see pixelSize()
*/
enum class Format: GLenum {
/**
* One-component (red channel)
* @requires_gl
* Floating-point red channel.
* @requires_gles30 %Extension @es_extension{EXT,texture_rg}
*/
#ifndef MAGNUM_TARGET_GLES2
Red = GL_RED,
#else
Red = GL_RED_EXT,
#endif
#ifndef MAGNUM_TARGET_GLES
/**
* One-component (green channel). For framebuffer reading only.
* @requires_gl
* Floating-point green channel. For framebuffer reading only.
* @requires_gl Only @ref Magnum::AbstractImage::Format "Format::Red"
* is available in OpenGL ES.
*/
Green = GL_GREEN,
/**
* One-component (green channel). For framebuffer reading only.
* @requires_gl
* Floating-point blue channel. For framebuffer reading only.
* @requires_gl Only @ref Magnum::AbstractImage::Format "Format::Red"
* is available in OpenGL ES.
*/
Blue = GL_BLUE,
#endif
/**
* Two-component (red and green channel). For texture data only.
* @requires_gl
* Floating-point red and green channel. For texture data only.
* @requires_gl30 %Extension @extension{ARB,texture_rg} and
* @extension{EXT,texture_integer}
* @requires_gles30 %Extension @es_extension{EXT,texture_rg}
*/
RedGreen = GL_RG,
#ifndef MAGNUM_TARGET_GLES2
RG = GL_RG,
#else
RG = GL_RG_EXT,
#endif
RGB = GL_RGB, /**< Three-component RGB */
RGBA = GL_RGBA /**< Four-component RGBA */
/** Floating-point RGB. */
RGB = GL_RGB,
#ifndef MAGNUM_TARGET_GLES
,
/** Floating-point RGBA. */
RGBA = GL_RGBA,
#ifndef MAGNUM_TARGET_GLES
/**
* Three-component BGR
* @requires_gl
* Floating-point BGR.
* @requires_gl Only RGB component ordering is available in OpenGL
* ES.
*/
BGR = GL_BGR,
#endif
/**
* Four-component BGRA
* @requires_gl
* Floating-point BGRA.
* @requires_es_extension %Extension @es_extension{EXT,read_format_bgra},
* for framebuffer reading, extension @es_extension{APPLE,texture_format_BGRA8888}
* for texture data.
*/
#ifndef MAGNUM_TARGET_GLES
BGRA = GL_BGRA,
#else
BGRA = GL_BGRA_EXT,
#endif
#ifndef MAGNUM_TARGET_GLES2
/**
* Integer red channel.
* @requires_gl30 %Extension @extension{EXT,texture_integer}
* @requires_gles30 Only floating-point image data are available
* in OpenGL ES 2.0.
*/
RedInteger = GL_RED_INTEGER,
/**
* Integer green channel.
* @requires_gl30 %Extension @extension{EXT,texture_integer}
* @requires_gles30 Only floating-point image data are available
* in OpenGL ES 2.0.
*/
GreenInteger = GL_GREEN_INTEGER,
/**
* Integer blue channel.
* @requires_gl30 %Extension @extension{EXT,texture_integer}
* @requires_gles30 Only floating-point image data are available
* in OpenGL ES 2.0.
*/
BlueInteger = GL_BLUE_INTEGER,
/**
* Integer red and green channel.
* @requires_gl30 %Extension @extension{ARB,texture_rg} and
* @extension{EXT,texture_integer}
* @requires_gles30 Only floating-point image data are available
* in OpenGL ES 2.0.
*/
RGInteger = GL_RG_INTEGER,
/**
* Integer RGB.
* @requires_gl30 %Extension @extension{EXT,texture_integer}
* @requires_gles30 Only floating-point image data are available
* in OpenGL ES 2.0.
*/
RGBInteger = GL_RGB_INTEGER,
/**
* Integer RGBA.
* @requires_gl30 %Extension @extension{EXT,texture_integer}
* @requires_gles30 Only floating-point image data are available
* in OpenGL ES 2.0.
*/
RGBAInteger = GL_RGBA_INTEGER,
/**
* Integer BGR.
* @requires_gl30 %Extension @extension{EXT,texture_integer}
* @requires_gles30 Only floating-point image data are available
* in OpenGL ES 2.0.
*/
BGRInteger = GL_BGR_INTEGER,
/**
* Integer BGRA.
* @requires_gl30 %Extension @extension{EXT,texture_integer}
* @requires_gles30 Only floating-point image data are available
* in OpenGL ES 2.0.
*/
BGRAInteger = GL_BGRA_INTEGER,
#endif
/**
* Depth component. For framebuffer reading only.
* @requires_gl
* @requires_gles30 %Extension @es_extension2{NV,read_depth,GL_NV_read_depth_stencil}
*/
Depth = GL_DEPTH_COMPONENT,
DepthComponent = GL_DEPTH_COMPONENT,
/**
* Stencil index. For framebuffer reading only.
* @requires_gl
* @requires_es_extension %Extension @es_extension2{NV,read_stencil,GL_NV_read_depth_stencil}
* @todo Where to get GL_STENCIL_INDEX in ES?
*/
#ifndef MAGNUM_TARGET_GLES
StencilIndex = GL_STENCIL_INDEX,
#else
StencilIndex = 0x1901,
#endif
/**
* Depth and stencil component. For framebuffer reading only.
* @requires_gl
* @requires_gl30 Extension @extension{EXT,packed_depth_stencil}
* Depth and stencil. For framebuffer reading only.
* @requires_gl30 %Extension @extension{EXT,packed_depth_stencil}
* @requires_gles30 %Extension @es_extension2{NV,read_depth_stencil,GL_NV_read_depth_stencil}
*/
#ifndef MAGNUM_TARGET_GLES2
DepthStencil = GL_DEPTH_STENCIL
#else
DepthStencil = GL_DEPTH_STENCIL_OES
#endif
};
/** @brief Data type */
enum class ComponentType: GLenum {
UnsignedByte = GL_UNSIGNED_BYTE, /**< Each component unsigned byte */
Byte = GL_BYTE, /**< Each component byte */
UnsignedShort = GL_UNSIGNED_SHORT, /**< Each component unsigned short */
Short = GL_SHORT, /**< Each component short */
UnsignedInt = GL_UNSIGNED_INT, /**< Each component unsigned int */
Int = GL_INT, /**< Each component int */
/**
* @brief Data type of pixel data
*
* @see pixelSize()
*/
enum class Type: GLenum {
/** Each component unsigned byte. */
UnsignedByte = GL_UNSIGNED_BYTE,
#ifndef MAGNUM_TARGET_GLES
#ifndef MAGNUM_TARGET_GLES2
/**
* Each component half float (16bit). For framebuffer reading only.
*
* @requires_gl
* @requires_gl30 Extension @extension{NV,half_float} / @extension{ARB,half_float_pixel}
* Each component signed byte.
* @requires_gles30 Only @ref Magnum::AbstractImage::Type "Type::UnsignedByte"
* is available in OpenGL ES 2.0.
*/
HalfFloat = GL_HALF_FLOAT,
Byte = GL_BYTE,
#endif
Float = GL_FLOAT, /**< Each component float (32bit) */
#ifndef MAGNUM_TARGET_GLES
/**
* Three-component RGB, unsigned normalized, red and green 3bit,
* blue 2bit, 8bit total.
* @requires_gl
* Each component unsigned short.
* @requires_gles30 %Extension @es_extension{OES,depth_texture}
*/
RGB332 = GL_UNSIGNED_BYTE_3_3_2,
UnsignedShort = GL_UNSIGNED_SHORT,
#ifndef MAGNUM_TARGET_GLES2
/**
* Three-component BGR, unsigned normalized, red and green 3bit,
* blue 2bit, 8bit total.
* @requires_gl
* Each component signed short.
* @requires_gles30 Only @ref Magnum::AbstractImage::Type "Type::UnsignedShort"
* is available in OpenGL ES 2.0.
*/
BGR233 = GL_UNSIGNED_BYTE_2_3_3_REV,
Short = GL_SHORT,
#endif
/**
* Three-component RGB, unsigned normalized, red and blue 5bit,
* green 6bit, 16bit total.
* Each component unsigned int.
* @requires_gles30 %Extension @es_extension{OES,depth_texture}
*/
RGB565 = GL_UNSIGNED_SHORT_5_6_5,
UnsignedInt = GL_UNSIGNED_INT,
#ifndef MAGNUM_TARGET_GLES
#ifndef MAGNUM_TARGET_GLES2
/**
* Three-component BGR, unsigned normalized, red and blue 5bit,
* green 6bit, 16bit total.
* @requires_gl
* Each component signed int.
* @requires_gles30 Only @ref Magnum::AbstractImage::Type "Type::UnsignedInt"
* is available in OpenGL ES 2.0.
*/
BGR565 = GL_UNSIGNED_SHORT_5_6_5_REV,
Int = GL_INT,
#endif
/**
* Four-component RGBA, unsigned normalized, each component 4bit,
* 16bit total.
* Each component half float. For framebuffer reading only.
* @requires_gl30 %Extension @extension{NV,half_float} / @extension{ARB,half_float_pixel}
* @requires_gles30 %Extension @es_extension{OES,texture_float},
* for texture data only.
*/
RGBA4 = GL_UNSIGNED_SHORT_4_4_4_4,
#ifndef MAGNUM_TARGET_GLES2
HalfFloat = GL_HALF_FLOAT,
#else
HalfFloat = GL_HALF_FLOAT_OES,
#endif
/**
* Each component float.
* @requires_gles30 %Extension @es_extension{OES,texture_float}
*/
Float = GL_FLOAT,
#ifndef MAGNUM_TARGET_GLES
/**
* Four-component ABGR, unsigned normalized, each component 4bit,
* 16bit total.
* @requires_gl
* RGB, unsigned byte, red and green component 3bit, blue
* component 2bit.
* @requires_gl Packed 12bit types are not available in OpenGL ES.
*/
UnsignedByte332 = GL_UNSIGNED_BYTE_3_3_2,
/**
* BGR, unsigned byte, red and green component 3bit, blue
* component 2bit.
* @requires_gl Packed 12bit types are not available in OpenGL ES.
*/
ABGR4 = GL_UNSIGNED_SHORT_4_4_4_4_REV,
UnsignedByte233Rev = GL_UNSIGNED_BYTE_2_3_3_REV,
#endif
/** RGB, unsigned byte, red and blue component 5bit, green 6bit. */
UnsignedShort565 = GL_UNSIGNED_SHORT_5_6_5,
#ifndef MAGNUM_TARGET_GLES
/**
* Four-component RGBA, unsigned normalized, each RGB component
* 5bit, alpha 1bit, 16bit total.
* BGR, unsigned short, red and blue 5bit, green 6bit.
* @requires_gl Only @ref Magnum::AbstractImage::Type "Type::RGB565"
* is available in OpenGL ES.
*/
RGB5Alpha1 = GL_UNSIGNED_SHORT_5_5_5_1
UnsignedShort565Rev = GL_UNSIGNED_SHORT_5_6_5_REV,
#endif
/** RGBA, unsigned short, each component 4bit. */
UnsignedShort4444 = GL_UNSIGNED_SHORT_4_4_4_4,
/**
* ABGR, unsigned short, each component 4bit.
* @requires_es_extension %Extension @es_extension{EXT,read_format_bgra},
* for framebuffer reading only.
*/
#ifndef MAGNUM_TARGET_GLES
,
UnsignedShort4444Rev = GL_UNSIGNED_SHORT_4_4_4_4_REV,
#else
UnsignedShort4444Rev = GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT,
#endif
/**
* RGBA, unsigned short, each RGB component 5bit, alpha component
* 1bit.
*/
UnsignedShort5551 = GL_UNSIGNED_SHORT_5_5_5_1,
/**
* Four-component ABGR, unsigned normalized, each RGB component
* 5bit, alpha 1bit, 16bit total.
* @requires_gl
* ABGR, unsigned short, each RGB component 5bit, alpha component
* 1bit.
* @requires_es_extension %Extension @es_extension{EXT,read_format_bgra},
* for framebuffer reading only.
*/
Alpha1BGR5 = GL_UNSIGNED_SHORT_1_5_5_5_REV,
#ifndef MAGNUM_TARGET_GLES
UnsignedShort1555Rev = GL_UNSIGNED_SHORT_1_5_5_5_REV,
#else
UnsignedShort1555Rev = GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT,
#endif
#ifndef MAGNUM_TARGET_GLES
/**
* Four-component RGBA, unsigned normalized, each component 8bit,
* 32bit total.
* @requires_gl
* RGBA, unsigned int, each component 8bit.
* @requires_gl Use @ref Magnum::AbstractImage::Type "Type::UnsignedByte"
* in OpenGL ES instead.
*/
RGBA8 = GL_UNSIGNED_INT_8_8_8_8,
UnsignedInt8888 = GL_UNSIGNED_INT_8_8_8_8,
/**
* Four-component ABGR, unsigned normalized, each component 8bit,
* 32bit total.
* @requires_gl
* ABGR, unsigned int, each component 8bit.
* @requires_gl Only RGBA component ordering is available in
* OpenGL ES, see @ref Magnum::AbstractImage::Format "Format::UnsignedInt8888"
* for more information.
*/
ABGR8 = GL_UNSIGNED_INT_8_8_8_8_REV,
UnsignedInt8888Rev = GL_UNSIGNED_INT_8_8_8_8_REV,
/**
* Four-component RGBA, unsigned normalized, each RGB component
* 10bit, alpha 2bit, 32bit total.
* @requires_gl
* RGBA, unsigned int, each RGB component 10bit, alpha component
* 2bit.
* @requires_gl Only @ref Magnum::AbstractImage::Type "Type::UnsignedInt2101010Rev"
* is available in OpenGL ES.
*/
RGB10Alpha2 = GL_UNSIGNED_INT_10_10_10_2,
UnsignedInt1010102 = GL_UNSIGNED_INT_10_10_10_2,
#endif
/**
* Four-component ABGR, unsigned normalized, each RGB component
* 10bit, alpha 2bit, 32bit total.
* @requires_gl
* ABGR, unsigned int, each RGB component 10bit, alpha component
* 2bit.
* @requires_gles30 %Extension @es_extension{EXT,texture_type_2_10_10_10_REV},
* for texture data only.
*/
Alpha2RGB10 = GL_UNSIGNED_INT_2_10_10_10_REV,
#ifndef MAGNUM_TARGET_GLES2
UnsignedInt2101010Rev = GL_UNSIGNED_INT_2_10_10_10_REV,
#else
UnsignedInt2101010Rev = GL_UNSIGNED_INT_2_10_10_10_REV_EXT,
#endif
#ifndef MAGNUM_TARGET_GLES2
/**
* Three-component BGR, float, red and green 11bit, blue 10bit,
* 32bit total. For framebuffer reading only.
* @requires_gl
* @requires_gl30 Extension @extension{EXT,packed_float}
* BGR, unsigned int, red and green 11bit float, blue 10bit float.
* For framebuffer reading only.
* @requires_gl30 %Extension @extension{EXT,packed_float}
* @requires_gles30 Floating-point types are not available in
* OpenGL ES 2.0.
*/
B10GR11Float = GL_UNSIGNED_INT_10F_11F_11F_REV,
UnsignedInt10F11F11FRev = GL_UNSIGNED_INT_10F_11F_11F_REV,
/**
* Three-component BGR, unsigned integers with exponent, each
* component 9bit, exponent 5bit, 32bit total. For framebuffer
* reading only.
* @requires_gl
* @requires_gl30 Extension @extension{EXT,texture_shared_exponent}
* BGR, unsigned int, each component 9bit + 5bit exponent. For
* framebuffer reading only.
* @requires_gl30 %Extension @extension{EXT,texture_shared_exponent}
* @requires_gles30 Only 8bit and 16bit types are available in
* OpenGL ES 2.0.
*/
Exponent5RGB9 = GL_UNSIGNED_INT_5_9_9_9_REV,
UnsignedInt5999Rev = GL_UNSIGNED_INT_5_9_9_9_REV,
#endif
/**
* 24bit depth and 8bit stencil component, 32bit total. For
* Unsigned int, depth component 24bit, stencil index 8bit. For
* framebuffer reading only.
* @requires_gl
* @requires_gl30 Extension @extension{EXT,packed_depth_stencil}
* @requires_gl30 %Extension @extension{EXT,packed_depth_stencil}
* @requires_gles30 %Extension @es_extension{OES,packed_depth_stencil}
*/
Depth24Stencil8 = GL_UNSIGNED_INT_24_8,
#ifdef MAGNUM_TARGET_GLES2
UnsignedInt248 = GL_UNSIGNED_INT_24_8_OES,
#else
UnsignedInt248 = GL_UNSIGNED_INT_24_8,
/**
* 32bit float depth component and 8bit stencil component, 64bit
* total. For framebuffer reading only.
* @requires_gl
* @requires_gl30 Extension @extension{ARB,depth_buffer_float}
* Float + unsigned int, depth component 32bit float, 24bit gap,
* stencil index 8bit. For framebuffer reading only.
* @requires_gl30 %Extension @extension{ARB,depth_buffer_float}
* @requires_gles30 Only @ref Magnum::AbstractImage::Type "Type::UnsignedInt248"
* is available in OpenGL ES 2.0.
*/
Depth32FloatStencil8 = GL_FLOAT_32_UNSIGNED_INT_24_8_REV
Float32UnsignedInt248Rev = GL_FLOAT_32_UNSIGNED_INT_24_8_REV
#endif
};
@ -265,30 +426,32 @@ class MAGNUM_EXPORT AbstractImage {
/**
* @brief Pixel size (in bytes)
* @param components Color components
* @param type Data type
* @param format Format of the pixel
* @param type Data type of the pixel
*/
static std::size_t pixelSize(Components components, ComponentType type);
static std::size_t pixelSize(Format format, Type type);
/**
* @brief Constructor
* @param components Color components of passed data
* @param type %Image data type
* @param format Format of pixel data
* @param type Data type of pixel data
*/
inline AbstractImage(Components components, ComponentType type): _components(components), _type(type) {}
inline AbstractImage(Format format, Type type): _format(format), _type(type) {}
/** @brief Destructor */
virtual ~AbstractImage() = 0;
/** @brief Color components */
inline Components components() const { return _components; }
/** @brief Format of pixel data */
inline Format format() const { return _format; }
/** @brief Data type */
inline ComponentType type() const { return _type; }
/** @brief Data type of pixel data */
inline Type type() const { return _type; }
#ifndef DOXYGEN_GENERATING_OUTPUT
protected:
Components _components; /**< @brief Color components */
ComponentType _type; /**< @brief Data type */
Format _format;
Type _type;
#endif
};
inline AbstractImage::~AbstractImage() {}

52
src/AbstractTexture.cpp

@ -225,90 +225,90 @@ void AbstractTexture::parameterImplementationDSA(GLenum parameter, const GLfloat
glTextureParameterfvEXT(_id, _target, parameter, values);
}
void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) {
void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) {
bindInternal();
glTexImage1D(target, mipLevel, static_cast<GLint>(internalFormat), size[0], 0, static_cast<GLenum>(components), static_cast<GLenum>(type), data);
glTexImage1D(target, mipLevel, static_cast<GLint>(internalFormat), size[0], 0, static_cast<GLenum>(format), static_cast<GLenum>(type), data);
}
void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) {
glTextureImage1DEXT(_id, target, mipLevel, GLint(internalFormat), size[0], 0, static_cast<GLenum>(components), static_cast<GLenum>(type), data);
void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) {
glTextureImage1DEXT(_id, target, mipLevel, GLint(internalFormat), size[0], 0, static_cast<GLenum>(format), static_cast<GLenum>(type), data);
}
#endif
void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) {
void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) {
bindInternal();
glTexImage2D(target, mipLevel, GLint(internalFormat), size.x(), size.y(), 0, static_cast<GLenum>(components), static_cast<GLenum>(type), data);
glTexImage2D(target, mipLevel, GLint(internalFormat), size.x(), size.y(), 0, static_cast<GLenum>(format), static_cast<GLenum>(type), data);
}
#ifndef MAGNUM_TARGET_GLES
void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) {
glTextureImage2DEXT(_id, target, mipLevel, GLint(internalFormat), size.x(), size.y(), 0, static_cast<GLenum>(components), static_cast<GLenum>(type), data);
void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) {
glTextureImage2DEXT(_id, target, mipLevel, GLint(internalFormat), size.x(), size.y(), 0, static_cast<GLenum>(format), static_cast<GLenum>(type), data);
}
#endif
void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) {
void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) {
bindInternal();
/** @todo Get some extension wrangler instead to avoid linker errors to glTexImage3D() on ES2 */
#ifndef MAGNUM_TARGET_GLES2
glTexImage3D(target, mipLevel, GLint(internalFormat), size.x(), size.y(), size.z(), 0, static_cast<GLenum>(components), static_cast<GLenum>(type), data);
glTexImage3D(target, mipLevel, GLint(internalFormat), size.x(), size.y(), size.z(), 0, static_cast<GLenum>(format), static_cast<GLenum>(type), data);
#else
static_cast<void>(target);
static_cast<void>(mipLevel);
static_cast<void>(internalFormat);
static_cast<void>(size);
static_cast<void>(components);
static_cast<void>(format);
static_cast<void>(type);
static_cast<void>(data);
#endif
}
#ifndef MAGNUM_TARGET_GLES
void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) {
glTextureImage3DEXT(_id, target, mipLevel, GLint(internalFormat), size.x(), size.y(), size.z(), 0, static_cast<GLenum>(components), static_cast<GLenum>(type), data);
void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) {
glTextureImage3DEXT(_id, target, mipLevel, GLint(internalFormat), size.x(), size.y(), size.z(), 0, static_cast<GLenum>(format), static_cast<GLenum>(type), data);
}
#endif
#ifndef MAGNUM_TARGET_GLES
void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) {
void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) {
bindInternal();
glTexSubImage1D(target, mipLevel, offset[0], size[0], static_cast<GLenum>(components), static_cast<GLenum>(type), data);
glTexSubImage1D(target, mipLevel, offset[0], size[0], static_cast<GLenum>(format), static_cast<GLenum>(type), data);
}
void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) {
glTextureSubImage1DEXT(_id, target, mipLevel, offset[0], size[0], static_cast<GLenum>(components), static_cast<GLenum>(type), data);
void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) {
glTextureSubImage1DEXT(_id, target, mipLevel, offset[0], size[0], static_cast<GLenum>(format), static_cast<GLenum>(type), data);
}
#endif
void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) {
void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) {
bindInternal();
glTexSubImage2D(target, mipLevel, offset.x(), offset.y(), size.x(), size.y(), static_cast<GLenum>(components), static_cast<GLenum>(type), data);
glTexSubImage2D(target, mipLevel, offset.x(), offset.y(), size.x(), size.y(), static_cast<GLenum>(format), static_cast<GLenum>(type), data);
}
#ifndef MAGNUM_TARGET_GLES
void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) {
glTextureSubImage2DEXT(_id, target, mipLevel, offset.x(), offset.y(), size.x(), size.y(), static_cast<GLenum>(components), static_cast<GLenum>(type), data);
void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) {
glTextureSubImage2DEXT(_id, target, mipLevel, offset.x(), offset.y(), size.x(), size.y(), static_cast<GLenum>(format), static_cast<GLenum>(type), data);
}
#endif
void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) {
void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) {
bindInternal();
/** @todo Get some extension wrangler instead to avoid linker errors to glTexSubImage3D() on ES2 */
#ifndef MAGNUM_TARGET_GLES2
glTexSubImage3D(target, mipLevel, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), static_cast<GLenum>(components), static_cast<GLenum>(type), data);
glTexSubImage3D(target, mipLevel, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), static_cast<GLenum>(format), static_cast<GLenum>(type), data);
#else
static_cast<void>(target);
static_cast<void>(mipLevel);
static_cast<void>(offset);
static_cast<void>(size);
static_cast<void>(components);
static_cast<void>(format);
static_cast<void>(type);
static_cast<void>(data);
#endif
}
#ifndef MAGNUM_TARGET_GLES
void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) {
glTextureSubImage3DEXT(_id, target, mipLevel, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), static_cast<GLenum>(components), static_cast<GLenum>(type), data);
void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) {
glTextureSubImage3DEXT(_id, target, mipLevel, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), static_cast<GLenum>(format), static_cast<GLenum>(type), data);
}
#endif

52
src/AbstractTexture.h

@ -1151,37 +1151,37 @@ class MAGNUM_EXPORT AbstractTexture {
static MAGNUM_LOCAL MipmapImplementation mipmapImplementation;
#ifndef MAGNUM_TARGET_GLES
typedef void(AbstractTexture::*Image1DImplementation)(GLenum, GLint, InternalFormat, const Math::Vector<1, GLsizei>&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*);
void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data);
void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data);
typedef void(AbstractTexture::*Image1DImplementation)(GLenum, GLint, InternalFormat, const Math::Vector<1, GLsizei>&, AbstractImage::Format, AbstractImage::Type, const GLvoid*);
void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data);
void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data);
static Image1DImplementation image1DImplementation;
#endif
typedef void(AbstractTexture::*Image2DImplementation)(GLenum, GLint, InternalFormat, const Vector2i&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*);
void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data);
void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data);
typedef void(AbstractTexture::*Image2DImplementation)(GLenum, GLint, InternalFormat, const Vector2i&, AbstractImage::Format, AbstractImage::Type, const GLvoid*);
void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data);
void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data);
static Image2DImplementation image2DImplementation;
typedef void(AbstractTexture::*Image3DImplementation)(GLenum, GLint, InternalFormat, const Vector3i&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*);
void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data);
void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data);
typedef void(AbstractTexture::*Image3DImplementation)(GLenum, GLint, InternalFormat, const Vector3i&, AbstractImage::Format, AbstractImage::Type, const GLvoid*);
void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data);
void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data);
static Image3DImplementation image3DImplementation;
#ifndef MAGNUM_TARGET_GLES
typedef void(AbstractTexture::*SubImage1DImplementation)(GLenum, GLint, const Math::Vector<1, GLint>&, const Math::Vector<1, GLsizei>&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*);
void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data);
void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data);
typedef void(AbstractTexture::*SubImage1DImplementation)(GLenum, GLint, const Math::Vector<1, GLint>&, const Math::Vector<1, GLsizei>&, AbstractImage::Format, AbstractImage::Type, const GLvoid*);
void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data);
void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data);
static SubImage1DImplementation subImage1DImplementation;
#endif
typedef void(AbstractTexture::*SubImage2DImplementation)(GLenum, GLint, const Vector2i&, const Vector2i&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*);
void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data);
void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data);
typedef void(AbstractTexture::*SubImage2DImplementation)(GLenum, GLint, const Vector2i&, const Vector2i&, AbstractImage::Format, AbstractImage::Type, const GLvoid*);
void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data);
void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data);
static SubImage2DImplementation subImage2DImplementation;
typedef void(AbstractTexture::*SubImage3DImplementation)(GLenum, GLint, const Vector3i&, const Vector3i&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*);
void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data);
void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data);
typedef void(AbstractTexture::*SubImage3DImplementation)(GLenum, GLint, const Vector3i&, const Vector3i&, AbstractImage::Format, AbstractImage::Type, const GLvoid*);
void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data);
void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data);
static SubImage3DImplementation subImage3DImplementation;
GLuint _id;
@ -1201,11 +1201,11 @@ template<> struct AbstractTexture::DataHelper<1> {
}
template<class Image> inline static typename std::enable_if<Image::Dimensions == 1, void>::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) {
(texture->*image1DImplementation)(target, mipLevel, internalFormat, image->size(), image->components(), image->type(), image->data());
(texture->*image1DImplementation)(target, mipLevel, internalFormat, image->size(), image->format(), image->type(), image->data());
}
template<class Image> inline static typename std::enable_if<Image::Dimensions == 1, void>::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, Image* image) {
(texture->*subImage1DImplementation)(target, mipLevel, offset, image->size(), image->components(), image->type(), image->data());
(texture->*subImage1DImplementation)(target, mipLevel, offset, image->size(), image->format(), image->type(), image->data());
}
};
#endif
@ -1224,15 +1224,15 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> {
static void setWrapping(AbstractTexture* texture, const Array2D<Wrapping>& wrapping);
template<class Image> inline static typename std::enable_if<Image::Dimensions == 2, void>::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) {
(texture->*image2DImplementation)(target, mipLevel, internalFormat, image->size(), image->components(), image->type(), image->data());
(texture->*image2DImplementation)(target, mipLevel, internalFormat, image->size(), image->format(), image->type(), image->data());
}
template<class Image> inline static typename std::enable_if<Image::Dimensions == 2, void>::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Vector2i& offset, Image* image) {
(texture->*subImage2DImplementation)(target, mipLevel, offset, image->size(), image->components(), image->type(), image->data());
(texture->*subImage2DImplementation)(target, mipLevel, offset, image->size(), image->format(), image->type(), image->data());
}
template<class Image> inline static typename std::enable_if<Image::Dimensions == 1, void>::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Vector2i& offset, Image* image) {
(texture->*subImage2DImplementation)(target, mipLevel, offset, Vector2i(image->size(), 1), image->components(), image->type(), image->data());
(texture->*subImage2DImplementation)(target, mipLevel, offset, Vector2i(image->size(), 1), image->format(), image->type(), image->data());
}
};
template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> {
@ -1250,15 +1250,15 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> {
static void setWrapping(AbstractTexture* texture, const Array3D<Wrapping>& wrapping);
template<class Image> inline static typename std::enable_if<Image::Dimensions == 3, void>::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) {
(texture->*image3DImplementation)(target, mipLevel, internalFormat, image->size(), image->components(), image->type(), image->data());
(texture->*image3DImplementation)(target, mipLevel, internalFormat, image->size(), image->format(), image->type(), image->data());
}
template<class Image> inline static typename std::enable_if<Image::Dimensions == 3, void>::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Vector3i& offset, Image* image) {
(texture->*subImage3DImplementation)(target, mipLevel, offset, image->size(), image->components(), image->type(), image->data());
(texture->*subImage3DImplementation)(target, mipLevel, offset, image->size(), image->format(), image->type(), image->data());
}
template<class Image> inline static typename std::enable_if<Image::Dimensions == 2, void>::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Vector3i& offset, Image* image) {
(texture->*subImage3DImplementation)(target, mipLevel, offset, Vector3i(image->size(), 1), image->components(), image->type(), image->data());
(texture->*subImage3DImplementation)(target, mipLevel, offset, Vector3i(image->size(), 1), image->format(), image->type(), image->data());
}
};
#endif

6
src/BufferedImage.cpp

@ -18,11 +18,11 @@
namespace Magnum {
#ifndef MAGNUM_TARGET_GLES2
template<std::uint8_t dimensions> void BufferedImage<dimensions>::setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) {
_components = components;
template<std::uint8_t dimensions> void BufferedImage<dimensions>::setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Format format, Type type, const GLvoid* data, Buffer::Usage usage) {
_format = format;
_type = type;
_size = size;
_buffer.setData(pixelSize(_components, _type)*size.product(), data, usage);
_buffer.setData(pixelSize(format, type)*size.product(), data, usage);
}
template class BufferedImage<1>;

31
src/BufferedImage.h

@ -33,8 +33,7 @@ namespace Magnum {
/**
@brief %Buffered image
Class for storing image data in GPU memory. Can be replaced with Image, which
stores image data in client memory, ImageWrapper, or for example with
Stores image data in GPU memory. Interchangeable with Image, ImageWrapper or
Trade::ImageData.
@see BufferedImage1D, BufferedImage2D, BufferedImage3D, Buffer
@requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0.
@ -45,13 +44,13 @@ template<std::uint8_t dimensions> class MAGNUM_EXPORT BufferedImage: public Abst
/**
* @brief Constructor
* @param components Color components
* @param type Data type
* @param format Format of pixel data
* @param type Data type of pixel data
*
* Dimensions and buffer are empty, call setData() to fill the image
* with data.
*/
inline BufferedImage(Components components, ComponentType type): AbstractImage(components, type) {
inline BufferedImage(Format format, Type type): AbstractImage(format, type) {
_buffer.setTargetHint(Buffer::Target::PixelPack);
}
@ -78,25 +77,25 @@ template<std::uint8_t dimensions> class MAGNUM_EXPORT BufferedImage: public Abst
/**
* @brief Set image data
* @param size %Image size
* @param components Color components. Data type is detected
* from passed data array.
* @param format Format of pixel data. Data type is
* detected from passed data array.
* @param data %Image data
* @param usage %Image buffer usage
*
* Updates the image buffer with given data. The data are not deleted
* after filling the buffer.
*
* @see setData(const Math::Vector<Dimensions, GLsizei>&, Components, ComponentType, const GLvoid*, Buffer::Usage)
* @see setData(const Math::Vector<Dimensions, GLsizei>&, Format, Type, const GLvoid*, Buffer::Usage)
*/
template<class T> inline void setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, const T* data, Buffer::Usage usage) {
setData(size, components, TypeTraits<T>::imageType(), data, usage);
template<class T> inline void setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Format format, const T* data, Buffer::Usage usage) {
setData(size, format, TypeTraits<T>::imageType(), data, usage);
}
/**
* @brief Set image data
* @param size %Image size
* @param components Color components
* @param type Data type
* @param format Format of pixel data
* @param type Data type of pixel data
* @param data %Image data
* @param usage %Image buffer usage
*
@ -105,11 +104,11 @@ template<std::uint8_t dimensions> class MAGNUM_EXPORT BufferedImage: public Abst
*
* @see Buffer::setData()
*/
void setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage);
void setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Format format, Type type, const GLvoid* data, Buffer::Usage usage);
protected:
Math::Vector<Dimensions, GLsizei> _size; /**< @brief %Image size */
Buffer _buffer; /**< @brief %Image buffer */
private:
Math::Vector<Dimensions, GLsizei> _size;
Buffer _buffer;
};
/** @brief One-dimensional buffered image */

16
src/Framebuffer.cpp

@ -45,21 +45,21 @@ void Framebuffer::mapForDraw(std::initializer_list<std::int8_t> colorAttachments
delete[] attachments;
}
void Framebuffer::read(const Vector2i& offset, const Vector2i& 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);
void Framebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image) {
char* data = new char[AbstractImage::pixelSize(format, type)*size.product()];
glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast<GLenum>(format), static_cast<GLenum>(type), data);
image->setData(size, format, type, data);
}
#ifndef MAGNUM_TARGET_GLES2
void Framebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage) {
void Framebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type 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->size() != size || image->components() != components || image->type() != type)
image->setData(size, components, type, nullptr, usage);
if(image->size() != size || image->format() != format || image->type() != type)
image->setData(size, format, type, nullptr, usage);
image->buffer()->bind(Buffer::Target::PixelPack);
glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast<GLenum>(components), static_cast<GLenum>(type), nullptr);
glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast<GLenum>(format), static_cast<GLenum>(type), nullptr);
}
#endif

12
src/Framebuffer.h

@ -677,22 +677,22 @@ class MAGNUM_EXPORT Framebuffer {
* @brief Read block of pixels from framebuffer to image
* @param offset Offset in the framebuffer
* @param size %Image size
* @param components Color components
* @param type Data type
* @param format Format of pixel data
* @param type Data type of pixel data
* @param image %Image where to put the data
*
* @see @fn_gl{ReadPixels}
* @requires_gl30 Extension @extension{EXT,framebuffer_object}
*/
static void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image);
static void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image);
#ifndef MAGNUM_TARGET_GLES2
/**
* @brief Read block of pixels from framebuffer to buffered image
* @param offset Offset in the framebuffer
* @param size %Image size
* @param components Color components
* @param type Data type
* @param format Format of pixel data
* @param type Data type of pixel data
* @param image Buffered image where to put the data
* @param usage %Buffer usage
*
@ -700,7 +700,7 @@ class MAGNUM_EXPORT Framebuffer {
* @requires_gl30 Extension @extension{EXT,framebuffer_object}
* @requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0.
*/
static void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage);
static void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferedImage2D* image, Buffer::Usage usage);
#endif
/*@}*/

4
src/Image.cpp

@ -17,9 +17,9 @@
namespace Magnum {
template<std::uint8_t dimensions> void Image<dimensions>::setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, ComponentType type, GLvoid* data) {
template<std::uint8_t dimensions> void Image<dimensions>::setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Format format, Type type, GLvoid* data) {
delete[] _data;
_components = components;
_format = format;
_type = type;
_size = size;
_data = reinterpret_cast<char*>(data);

43
src/Image.h

@ -29,9 +29,8 @@ namespace Magnum {
/**
@brief %Image
Class for storing image data on client memory. Can be replaced with
ImageWrapper, BufferedImage, which stores image data in GPU memory, or for
example with Trade::ImageData.
Stores image data on client memory. Interchangeable with ImageWrapper,
BufferedImage or Trade::ImageData.
@see Image1D, Image2D, Image3D
*/
template<std::uint8_t dimensions> class Image: public AbstractImage {
@ -41,36 +40,36 @@ template<std::uint8_t dimensions> class Image: public AbstractImage {
/**
* @brief Constructor
* @param size %Image size
* @param components Color components. Data type is detected
* from passed data array.
* @param format Format of pixel data. Data type is
* detected from passed data array.
* @param data %Image data with proper size
*
* Note that the image data are not copied on construction, but they
* are deleted on class destruction.
*/
template<class T> inline Image(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, T* data): AbstractImage(components, TypeTraits<T>::imageType()), _size(size), _data(data) {}
template<class T> inline Image(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Format format, T* data): AbstractImage(format, TypeTraits<T>::imageType()), _size(size), _data(data) {}
/**
* @brief Constructor
* @param size %Image size
* @param components Color components
* @param type Data type
* @param format Format of pixel data
* @param type Data type of pixel data
* @param data %Image data
*
* Note that the image data are not copied on construction, but they
* are deleted on class destruction.
*/
inline Image(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _size(size), _data(reinterpret_cast<char*>(data)) {}
inline Image(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast<char*>(data)) {}
/**
* @brief Constructor
* @param components Color components
* @param type Data type
* @param format Format of pixel data
* @param type Data type of pixel data
*
* Dimensions and data pointer are set to zero, call setData() to fill
* the image with data.
*/
inline Image(Components components, ComponentType type): AbstractImage(components, type), _data(nullptr) {}
inline Image(Format format, Type type): AbstractImage(format, type), _data(nullptr) {}
/** @brief Destructor */
inline ~Image() { delete[] _data; }
@ -85,32 +84,32 @@ template<std::uint8_t dimensions> class Image: public AbstractImage {
/**
* @brief Set image data
* @param size %Image size
* @param components Color components. Data type is detected
* from passed data array.
* @param format Format of pixel data. Data type is
* detected from passed data array.
* @param data %Image data
*
* 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 typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, T* data) {
setData(size, components, TypeTraits<T>::imageType(), data);
template<class T> inline void setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Format format, T* data) {
setData(size, format, TypeTraits<T>::imageType(), data);
}
/**
* @brief Set image data
* @param size %Image size
* @param components Color components
* @param type Data type
* @param format Format of pixel data
* @param type Data type of pixel data
* @param data %Image data
*
* Deletes previous data and replaces them with new. Note that the
* data are not copied, but they are deleted on destruction.
*/
void setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, ComponentType type, GLvoid* data);
void setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Format format, Type type, GLvoid* data);
protected:
Math::Vector<Dimensions, GLsizei> _size; /**< @brief %Image size */
char* _data; /**< @brief %Image data */
private:
Math::Vector<Dimensions, GLsizei> _size;
char* _data;
};
#ifndef DOXYGEN_GENERATING_OUTPUT

27
src/ImageWrapper.h

@ -38,7 +38,8 @@ targeted for wrapping data which are either stored in stack/constant memory
same properties for each frame, such as video stream. Thus it is not possible
to change image properties, only data pointer.
See also Image, BufferedImage and Trade::ImageData.
Interchangeable with Image, BufferedImage or Trade::ImageData.
@see ImageWrapper1D, ImageWrapper2D, ImageWrapper3D
*/
template<std::uint8_t dimensions> class ImageWrapper: public AbstractImage {
public:
@ -47,37 +48,37 @@ template<std::uint8_t dimensions> class ImageWrapper: public AbstractImage {
/**
* @brief Constructor
* @param size %Image size
* @param components Color components. Data type is detected
* from passed data array.
* @param format Format of pixel data. Data type is
* detected from passed data array.
* @param data %Image data with proper size
*
* Note that the image data are not copied on construction, but they
* are deleted on class destruction.
*/
template<class T> inline ImageWrapper(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, T* data): AbstractImage(components, TypeTraits<T>::imageType()), _size(size), _data(data) {}
template<class T> inline ImageWrapper(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Format format, T* data): AbstractImage(format, TypeTraits<T>::imageType()), _size(size), _data(data) {}
/**
* @brief Constructor
* @param size %Image size
* @param components Color components
* @param type Data type
* @param format Format of pixel data
* @param type Data type of pixel data
* @param data %Image data
*
* Note that the image data are not copied on construction, but they
* are deleted on class destruction.
*/
inline ImageWrapper(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _size(size), _data(reinterpret_cast<char*>(data)) {}
inline ImageWrapper(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast<char*>(data)) {}
/**
* @brief Constructor
* @param size %Image size
* @param components Color components
* @param type Data type
* @param format Format of pixel data
* @param type Data type of pixel data
*
* Dimensions and data pointer are set to zero, call setData() to fill
* the image with data.
*/
inline ImageWrapper(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, ComponentType type): AbstractImage(components, type), _size(size), _data(nullptr) {}
inline ImageWrapper(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Format format, Type type): AbstractImage(format, type), _size(size), _data(nullptr) {}
/** @brief %Image size */
inline typename DimensionTraits<Dimensions, GLsizei>::VectorType size() const { return _size; }
@ -98,9 +99,9 @@ template<std::uint8_t dimensions> class ImageWrapper: public AbstractImage {
_data = reinterpret_cast<char*>(data);
}
protected:
Math::Vector<Dimensions, GLsizei> _size; /**< @brief %Image size */
char* _data; /**< @brief %Image data */
private:
Math::Vector<Dimensions, GLsizei> _size;
char* _data;
};
/** @brief One-dimensional image wrapper */

17
src/Trade/ImageData.h

@ -29,8 +29,9 @@ namespace Magnum { namespace Trade {
/**
@brief %Image data
Provides access to image data and additional information about data type and
dimensions. Can be used in the same situations as Image and BufferedImage.
Access to image data provided by AbstractImporter subclasses. Interchangeable
with Image, ImageWrapper or BufferedImage.
@see ImageData1D, ImageData2D, ImageData3D
*/
template<std::uint8_t dimensions> class ImageData: public AbstractImage {
public:
@ -40,27 +41,27 @@ template<std::uint8_t dimensions> class ImageData: public AbstractImage {
* @brief Constructor
* @param name %Image name
* @param size %Image size
* @param components Color components. Data type is detected
* from passed data array.
* @param format Format of pixel data. Data type is
* detected from passed data array.
* @param data %Image data
*
* 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 typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, T* data): AbstractImage(components, TypeTraits<T>::imageType()), _name(name), _size(size), _data(reinterpret_cast<char*>(data)) {}
template<class T> inline ImageData(const std::string& name, const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Format format, T* data): AbstractImage(format, TypeTraits<T>::imageType()), _name(name), _size(size), _data(reinterpret_cast<char*>(data)) {}
/**
* @brief Constructor
* @param name %Image name
* @param size %Image size
* @param components Color components
* @param type Data type
* @param format Format of pixel data
* @param type Data type of pixel data
* @param data %Image data
*
* Note that the image data are not copied on construction, but they
* are deleted on class destruction.
*/
inline ImageData(const std::string& name, const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _name(name), _size(size), _data(reinterpret_cast<char*>(data)) {}
inline ImageData(const std::string& name, const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _name(name), _size(size), _data(reinterpret_cast<char*>(data)) {}
/** @brief Destructor */
inline ~ImageData() { delete[] _data; }

24
src/TypeTraits.h

@ -69,13 +69,13 @@ template<class T> struct TypeTraits: Math::MathTypeTraits<T> {
inline constexpr static Type indexType();
/**
* @brief OpenGL type ID for images
* @brief OpenGL type ID for pixel data
*
* Implemented only in types which can be used for image data, like
* GLubyte. This function is not present for types unusable for image data,
* like GLdouble and Matrix3.
*/
inline constexpr static AbstractImage::ComponentType imageType();
inline constexpr static AbstractImage::Type imageType();
/**
* @brief Size of plain OpenGL type
@ -182,7 +182,7 @@ template<> struct TypeTraits<GLubyte>: Math::MathTypeTraits<std::uint8_t> {
/* Can not be used for attributes */
inline constexpr static Type type() { return Type::UnsignedByte; }
inline constexpr static Type indexType() { return Type::UnsignedByte; }
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedByte; }
inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::UnsignedByte; }
inline constexpr static std::size_t size() { return sizeof(GLubyte); }
inline constexpr static std::size_t count() { return 1; }
};
@ -191,7 +191,9 @@ template<> struct TypeTraits<GLbyte>: Math::MathTypeTraits<std::int8_t> {
/* Can not be used for attributes */
inline constexpr static Type type() { return Type::Byte; }
/* Can not be used for indices */
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Byte; }
#ifndef MAGNUM_TARGET_GLES2
inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::Byte; }
#endif
inline constexpr static std::size_t size() { return sizeof(GLbyte); }
inline constexpr static std::size_t count() { return 1; }
};
@ -200,7 +202,7 @@ template<> struct TypeTraits<GLushort>: Math::MathTypeTraits<std::uint16_t> {
/* Can not be used for attributes */
inline constexpr static Type type() { return Type::UnsignedShort; }
inline constexpr static Type indexType() { return Type::UnsignedShort; }
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedShort; }
inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::UnsignedShort; }
inline constexpr static std::size_t size() { return sizeof(GLushort); }
inline constexpr static std::size_t count() { return 1; }
};
@ -209,7 +211,9 @@ template<> struct TypeTraits<GLshort>: Math::MathTypeTraits<std::int16_t> {
/* Can not be used for attributes */
inline constexpr static Type type() { return Type::Short; }
/* Can not be used for indices */
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Short; }
#ifndef MAGNUM_TARGET_GLES2
inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::Short; }
#endif
inline constexpr static std::size_t size() { return sizeof(GLshort); }
inline constexpr static std::size_t count() { return 1; }
};
@ -218,7 +222,7 @@ template<> struct TypeTraits<GLuint>: Math::MathTypeTraits<std::uint32_t> {
typedef GLuint AttributeType;
inline constexpr static Type type() { return Type::UnsignedInt; }
inline constexpr static Type indexType() { return Type::UnsignedInt; }
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedInt; }
inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::UnsignedInt; }
inline constexpr static std::size_t size() { return sizeof(GLuint); }
inline constexpr static std::size_t count() { return 1; }
};
@ -227,7 +231,9 @@ template<> struct TypeTraits<GLint>: Math::MathTypeTraits<std::int32_t> {
typedef GLint AttributeType;
inline constexpr static Type type() { return Type::Int; }
/* Can not be used for indices */
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Int; }
#ifndef MAGNUM_TARGET_GLES2
inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::Int; }
#endif
inline constexpr static std::size_t size() { return sizeof(GLint); }
inline constexpr static std::size_t count() { return 1; }
};
@ -236,7 +242,7 @@ template<> struct TypeTraits<GLfloat>: Math::MathTypeTraits<float> {
typedef GLfloat AttributeType;
inline constexpr static Type type() { return Type::Float; }
/* Can not be used for indices */
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Float; }
inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::Float; }
inline constexpr static std::size_t size() { return sizeof(GLfloat); }
inline constexpr static std::size_t count() { return 1; }
};

Loading…
Cancel
Save