diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 41291b6a8..89d5eeef6 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -46,6 +46,24 @@ static_assert((filter_or(NearestNeighbor, BaseLevel) == GL_NEAREST) && #undef filter_or #endif +size_t AbstractTexture::pixelSize(ColorFormat format, Type type) { + size_t size = TypeInfo::sizeOf(type); + switch(format) { + case ColorFormat::Red: + return 1*size; + case ColorFormat::RedGreen: + return 2*size; + case ColorFormat::RGB: + case ColorFormat::BGR: + return 3*size; + case ColorFormat::RGBA: + case ColorFormat::BGRA: + return 4*size; + default: + return 0; + } +} + void AbstractTexture::setMinificationFilter(Filter filter, Mipmap mipmap) { /* Only base mip level is supported on rectangle textures */ if(target == GL_TEXTURE_RECTANGLE) mipmap = Mipmap::BaseLevel; diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 2cb7d15f1..0a149e642 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -95,28 +95,43 @@ class MAGNUM_EXPORT AbstractTexture { /** @brief Internal format */ enum class InternalFormat: GLint { - Red = GL_RED, - RedGreen = GL_RG, - RGB = GL_RGB, - RGBA = GL_RGBA, - BGR = GL_BGR, - BGRA = GL_BGRA, + Red = GL_RED, /**< One-component (red channel) */ + RedGreen = GL_RG, /**< Two-component (red and green channel) */ + RGB = GL_RGB, /**< Three-component (RGB) */ + RGBA = GL_RGBA, /**< Four-component (RGBA) */ + BGR = GL_BGR, /**< Three-component (BGR) */ + BGRA = GL_BGRA, /**< Four-component (BGRA) */ + + /** Compressed red channel */ CompressedRed = GL_COMPRESSED_RED, + + /** Compressed red and green channel */ CompressedRedGreen = GL_COMPRESSED_RG, + + /** Compressed RGB */ CompressedRGB = GL_COMPRESSED_RGB, + + /** Compressed RGBA */ CompressedRGBA = GL_COMPRESSED_RGBA }; /** @brief Color format */ enum class ColorFormat: GLenum { - Red = GL_RED, - RedGreen = GL_RG, - RGB = GL_RGB, - RGBA = GL_RGBA, - BGR = GL_BGR, - BGRA = GL_BGRA + Red = GL_RED, /**< One-component (red channel) */ + RedGreen = GL_RG, /**< Two-component (red and green channel) */ + RGB = GL_RGB, /**< Three-component (RGB) */ + RGBA = GL_RGBA, /**< Four-component (RGBA) */ + BGR = GL_BGR, /**< Three-component (BGR) */ + BGRA = GL_BGRA /**< Four-component (BGRA) */ }; + /** + * @brief Pixel size (in bytes) + * @param format Color format + * @param type Data type per color channel + */ + static size_t pixelSize(ColorFormat format, Type type); + /** * @brief Constructor * @param layer %Texture layer (number between 0 and 31)