Browse Source

Function for pixel size of given color format and data type per channel.

Also documented the formats a little.
pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
33e822a397
  1. 18
      src/AbstractTexture.cpp
  2. 39
      src/AbstractTexture.h

18
src/AbstractTexture.cpp

@ -46,6 +46,24 @@ static_assert((filter_or(NearestNeighbor, BaseLevel) == GL_NEAREST) &&
#undef filter_or #undef filter_or
#endif #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) { void AbstractTexture::setMinificationFilter(Filter filter, Mipmap mipmap) {
/* Only base mip level is supported on rectangle textures */ /* Only base mip level is supported on rectangle textures */
if(target == GL_TEXTURE_RECTANGLE) mipmap = Mipmap::BaseLevel; if(target == GL_TEXTURE_RECTANGLE) mipmap = Mipmap::BaseLevel;

39
src/AbstractTexture.h

@ -95,28 +95,43 @@ class MAGNUM_EXPORT AbstractTexture {
/** @brief Internal format */ /** @brief Internal format */
enum class InternalFormat: GLint { enum class InternalFormat: GLint {
Red = GL_RED, Red = GL_RED, /**< One-component (red channel) */
RedGreen = GL_RG, RedGreen = GL_RG, /**< Two-component (red and green channel) */
RGB = GL_RGB, RGB = GL_RGB, /**< Three-component (RGB) */
RGBA = GL_RGBA, RGBA = GL_RGBA, /**< Four-component (RGBA) */
BGR = GL_BGR, BGR = GL_BGR, /**< Three-component (BGR) */
BGRA = GL_BGRA, BGRA = GL_BGRA, /**< Four-component (BGRA) */
/** Compressed red channel */
CompressedRed = GL_COMPRESSED_RED, CompressedRed = GL_COMPRESSED_RED,
/** Compressed red and green channel */
CompressedRedGreen = GL_COMPRESSED_RG, CompressedRedGreen = GL_COMPRESSED_RG,
/** Compressed RGB */
CompressedRGB = GL_COMPRESSED_RGB, CompressedRGB = GL_COMPRESSED_RGB,
/** Compressed RGBA */
CompressedRGBA = GL_COMPRESSED_RGBA CompressedRGBA = GL_COMPRESSED_RGBA
}; };
/** @brief Color format */ /** @brief Color format */
enum class ColorFormat: GLenum { enum class ColorFormat: GLenum {
Red = GL_RED, Red = GL_RED, /**< One-component (red channel) */
RedGreen = GL_RG, RedGreen = GL_RG, /**< Two-component (red and green channel) */
RGB = GL_RGB, RGB = GL_RGB, /**< Three-component (RGB) */
RGBA = GL_RGBA, RGBA = GL_RGBA, /**< Four-component (RGBA) */
BGR = GL_BGR, BGR = GL_BGR, /**< Three-component (BGR) */
BGRA = GL_BGRA 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 * @brief Constructor
* @param layer %Texture layer (number between 0 and 31) * @param layer %Texture layer (number between 0 and 31)

Loading…
Cancel
Save