Browse Source

More texture and renderbuffer internal formats supported in OpenGL ES 3.0.

vectorfields
Vladimír Vondruš 14 years ago
parent
commit
bd665cb280
  1. 27
      src/AbstractTexture.cpp
  2. 67
      src/AbstractTexture.h
  3. 25
      src/Renderbuffer.cpp
  4. 36
      src/Renderbuffer.h
  5. 8
      src/Texture.h

27
src/AbstractTexture.cpp

@ -69,8 +69,8 @@ AbstractTexture* AbstractTexture::generateMipmap() {
return this;
}
#ifndef MAGNUM_TARGET_GLES
AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components components, AbstractTexture::ComponentType type) {
#ifndef MAGNUM_TARGET_GLES
#define internalFormatSwitch(c) switch(type) { \
case ComponentType::UnsignedByte: \
internalFormat = GL_##c##8UI; break; \
@ -97,6 +97,30 @@ AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components comp
case ComponentType::NormalizedShort: \
internalFormat = GL_##c##16_SNORM; break; \
}
#else
#define internalFormatSwitch(c) switch(type) { \
case ComponentType::UnsignedByte: \
internalFormat = GL_##c##8UI; break; \
case ComponentType::Byte: \
internalFormat = GL_##c##8I; break; \
case ComponentType::UnsignedShort: \
internalFormat = GL_##c##16UI; break; \
case ComponentType::Short: \
internalFormat = GL_##c##16I; break; \
case ComponentType::UnsignedInt: \
internalFormat = GL_##c##32UI; break; \
case ComponentType::Int: \
internalFormat = GL_##c##32I; break; \
case ComponentType::Half: \
internalFormat = GL_##c##16F; break; \
case ComponentType::Float: \
internalFormat = GL_##c##32F; break; \
case ComponentType::NormalizedUnsignedByte: \
internalFormat = GL_##c##8; break; \
case ComponentType::NormalizedByte: \
internalFormat = GL_##c##8_SNORM; break; \
}
#endif
if(components == Components::Red)
internalFormatSwitch(R)
else if(components == Components::RedGreen)
@ -107,7 +131,6 @@ AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components comp
internalFormatSwitch(RGBA)
#undef internalFormatSwitch
}
#endif
#ifndef DOXYGEN_GENERATING_OUTPUT
void AbstractTexture::DataHelper<2>::setWrapping(GLenum target, const Math::Vector<2, Wrapping>& wrapping) {

67
src/AbstractTexture.h

@ -113,10 +113,10 @@ class MAGNUM_EXPORT AbstractTexture {
/** @{ @name Internal texture formats */
#ifndef MAGNUM_TARGET_GLES
/**
* @brief Color components
* @requires_gl
*
* @requires_gles30 (no extension providing this functionality)
*/
enum class Components {
/**
@ -142,7 +142,7 @@ class MAGNUM_EXPORT AbstractTexture {
*
* `NormalizedUnsignedByte` and `NormalizedUnsignedShort` are the
* main ones for general usage.
* @requires_gl
* @requires_gles30 (no extension providing this functionality)
*/
enum class ComponentType {
/**
@ -206,20 +206,23 @@ class MAGNUM_EXPORT AbstractTexture {
*/
NormalizedByte,
#ifndef MAGNUM_TARGET_GLES
/**
* Normalized unsigned short, i.e. values from range @f$ [0; 65536] @f$
* are converted to range @f$ [0.0; 1.0] @f$.
* @requires_gl
*/
NormalizedUnsignedShort,
/**
* Normalized signed short, i.e. values from range @f$ [-32768; 32767] @f$
* are converted to range @f$ [-1.0; 1.0] @f$.
* @requires_gl
* @requires_gl31 Extension @extension{EXT,texture_snorm}
*/
NormalizedShort
#endif
};
#endif
/**
* @brief Internal format
@ -228,23 +231,21 @@ class MAGNUM_EXPORT AbstractTexture {
* normalization see enums Components and ComponentType.
*/
enum class Format: GLenum {
#ifndef MAGNUM_TARGET_GLES
/**
* One-component (red channel), unsigned normalized, probably
* 8bit.
* @requires_gl
* @requires_gl30 Extension @extension{ARB,texture_rg}
* @requires_gles30 (no extension providing this functionality)
*/
Red = GL_RED,
/**
* Two-component (red and green channel), unsigned normalized,
* each component probably 8bit, 16bit total.
* @requires_gl
* @requires_gl30 Extension @extension{ARB,texture_rg}
* @requires_gles30 (no extension providing this functionality)
*/
RedGreen = GL_RG,
#endif
/**
* Three-component RGB, unsigned normalized, each component
@ -278,36 +279,36 @@ class MAGNUM_EXPORT AbstractTexture {
* @requires_gl
*/
BGRA = GL_BGRA,
#endif
/**
* Four-component sRGBA, unsigned normalized, each component
* 8bit, 32bit total.
* @requires_gl
* @requires_gles30 (no extension providing this functionality)
*/
SRGBA8 = GL_SRGB8_ALPHA8,
/**
* Three-component sRGB, unsigned normalized, each component
* 8bit, 24bit total.
* @requires_gl
* @requires_gles30 (no extension providing this functionality)
*/
SRGB8 = GL_SRGB8,
/**
* Four-component RGBA, unsigned normalized, each RGB component
* 10bit, alpha 2bit, 32bit total.
* @requires_gl
* @requires_gles30 (no extension providing this functionality)
*/
RGB10Alpha2 = GL_RGB10_A2,
/**
* Four-component RGBA, unsigned non-normalized, each RGB
* component 10bit, alpha channel 2bit, 32bit total.
* @requires_gl
* @requires_gl33 Extension @extension{ARB,texture_rgb10_a2ui}
* @requires_gles30 (no extension providing this functionality)
*/
RGB10Alpha2Unsigned = GL_RGB10_A2UI,
#endif
/**
* Four-component RGBA, unsigned normalized, each RGB component
@ -321,33 +322,29 @@ class MAGNUM_EXPORT AbstractTexture {
*/
RGBA4 = GL_RGBA4,
#ifndef MAGNUM_TARGET_GLES
/**
* Three-component RGB, float, red and green 11bit, blue 10bit,
* 32bit total.
* @requires_gl
* @requires_gl30 Extension @extension{EXT,packed_float}
* @requires_gles30 (no extension providing this functionality)
*/
RG11B10Float = GL_R11F_G11F_B10F,
#endif
/**
* Three-component RGB, unsigned normalized, red and blue 5bit,
* green 6bit, 16bit total.
*/
RGB565 = GL_RGB565
#ifndef MAGNUM_TARGET_GLES
,
RGB565 = GL_RGB565,
/**
* Three-component RGB, unsigned with exponent, each component
* 9bit, exponent 5bit, 32bit total.
* @requires_gl
* @requires_gl30 Extension @extension{EXT,texture_shared_exponent}
* @requires_gles30 (no extension providing this functionality)
*/
RGB9Exponent5 = GL_RGB9_E5,
#ifndef MAGNUM_TARGET_GLES
/**
* Compressed red channel, unsigned normalized.
* @requires_gl
@ -448,40 +445,40 @@ class MAGNUM_EXPORT AbstractTexture {
* @requires_gl
*/
DepthStencil = GL_DEPTH_STENCIL,
#endif
/**
* 16bit depth component.
* @requires_gl
* @requires_gles30 (no extension providing this functionality)
*/
Depth16 = GL_DEPTH_COMPONENT16,
/**
* 24bit depth component.
* @requires_gl
* @requires_gles30 (no extension providing this functionality)
*/
Depth24 = GL_DEPTH_COMPONENT24,
/**
* 32bit float depth component.
* @requires_gl
* @requires_gl30 Extension @extension{ARB,depth_buffer_float}
* @requires_gles30 (no extension providing this functionality)
*/
Depth32Float = GL_DEPTH_COMPONENT32F,
/**
* 24bit depth and 8bit stencil component.
* @requires_gl
* @requires_gl30 Extension @extension{EXT,packed_depth_stencil}
* @requires_gles30 (no extension providing this functionality)
*/
Depth24Stencil8 = GL_DEPTH24_STENCIL8,
/**
* 32bit float depth component and 8bit stencil component.
* @requires_gl
* @requires_gl30 Extension @extension{ARB,depth_buffer_float}
* @requires_gles30 (no extension providing this functionality)
*/
Depth32FloatStencil8 = GL_DEPTH32F_STENCIL8
#endif
};
/**
@ -502,14 +499,12 @@ class MAGNUM_EXPORT AbstractTexture {
*/
class MAGNUM_EXPORT InternalFormat {
public:
#ifndef MAGNUM_TARGET_GLES
/**
* @brief Constructor from component count and data type per component
*
* @requires_gl
* @requires_gles30 (no extension providing this functionality)
*/
InternalFormat(Components components, ComponentType type);
#endif
/** @brief Constructor from named internal format */
inline constexpr InternalFormat(Format format): internalFormat(static_cast<GLint>(format)) {}
@ -536,6 +531,7 @@ class MAGNUM_EXPORT AbstractTexture {
* @brief Max supported anisotropy
*
* @see setMaxAnisotropy(), @fn_gl{Get} with @def_gl{MAX_TEXTURE_MAX_ANISOTROPY_EXT}
* @requires_gl
* @requires_extension @extension{EXT,texture_filter_anisotropic}
*/
static GLfloat maxSupportedAnisotropy();
@ -632,6 +628,7 @@ class MAGNUM_EXPORT AbstractTexture {
* Default value is `1.0`, which means no anisotropy. Set to value
* greater than `1.0` for anisotropic filtering.
* @see maxSupportedAnisotropy(), bind(), @fn_gl{TexParameter} with @def_gl{TEXTURE_MAX_ANISOTROPY_EXT}
* @requires_gl
* @requires_extension @extension{EXT,texture_filter_anisotropic}
*/
inline AbstractTexture* setMaxAnisotropy(GLfloat anisotropy) {
@ -675,11 +672,10 @@ class MAGNUM_EXPORT AbstractTexture {
inline AbstractTexture::~AbstractTexture() { glDeleteTextures(1, &texture); }
#ifndef MAGNUM_TARGET_GLES
/** @relates AbstractTexture
@brief Convertor of component count and data type to InternalFormat
@requires_gl
@requires_gles30 (no extension providing this functionality)
*/
inline AbstractTexture::InternalFormat operator|(AbstractTexture::Components components, AbstractTexture::ComponentType type) {
return AbstractTexture::InternalFormat(components, type);
@ -691,7 +687,6 @@ inline AbstractTexture::InternalFormat operator|(AbstractTexture::Components com
inline AbstractTexture::InternalFormat operator|(AbstractTexture::ComponentType type, AbstractTexture::Components components) {
return AbstractTexture::InternalFormat(components, type);
}
#endif
#ifndef DOXYGEN_GENERATING_OUTPUT
#ifndef MAGNUM_TARGET_GLES
@ -743,19 +738,14 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> {
};
template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> {
enum class Target: GLenum {
#ifndef MAGNUM_TARGET_GLES
Texture3D = GL_TEXTURE_3D,
Texture2DArray = GL_TEXTURE_2D_ARRAY
#endif
};
#ifndef MAGNUM_TARGET_GLES
inline constexpr static Target target() { return Target::Texture3D; }
#endif
static void setWrapping(GLenum target, const Math::Vector<3, Wrapping>& wrapping);
#ifndef MAGNUM_TARGET_GLES
template<class Image> inline static typename std::enable_if<Image::Dimensions == 3, void>::type set(GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) {
glTexImage3D(target, mipLevel, internalFormat, image->dimensions()[0], image->dimensions()[1], image->dimensions()[2], 0, static_cast<GLenum>(image->components()), static_cast<GLenum>(image->type()), image->data());
}
@ -767,7 +757,6 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> {
template<class Image> inline static typename std::enable_if<Image::Dimensions == 2, void>::type setSub(GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, Image* image) {
glTexSubImage3D(target, mipLevel, offset[0], offset[1], offset[2], image->dimensions()[0], image->dimensions()[1], 1, static_cast<GLenum>(image->components()), static_cast<GLenum>(image->type()), image->data());
}
#endif
};
#endif

25
src/Renderbuffer.cpp

@ -17,8 +17,8 @@
namespace Magnum {
#ifndef MAGNUM_TARGET_GLES
Renderbuffer::InternalFormat::InternalFormat(Components components, ComponentType type) {
#ifndef MAGNUM_TARGET_GLES
#define internalFormatSwitch(c) switch(type) { \
case ComponentType::UnsignedByte: \
internalFormat = GL_##c##8UI; break; \
@ -41,6 +41,28 @@ Renderbuffer::InternalFormat::InternalFormat(Components components, ComponentTyp
case ComponentType::NormalizedUnsignedShort: \
internalFormat = GL_##c##16; break; \
}
#else
#define internalFormatSwitch(c) switch(type) { \
case ComponentType::UnsignedByte: \
internalFormat = GL_##c##8UI; break; \
case ComponentType::Byte: \
internalFormat = GL_##c##8I; break; \
case ComponentType::UnsignedShort: \
internalFormat = GL_##c##16UI; break; \
case ComponentType::Short: \
internalFormat = GL_##c##16I; break; \
case ComponentType::UnsignedInt: \
internalFormat = GL_##c##32UI; break; \
case ComponentType::Int: \
internalFormat = GL_##c##32I; break; \
case ComponentType::Half: \
internalFormat = GL_##c##16F; break; \
case ComponentType::Float: \
internalFormat = GL_##c##32F; break; \
case ComponentType::NormalizedUnsignedByte: \
internalFormat = GL_##c##8; break; \
}
#endif
if(components == Components::Red)
internalFormatSwitch(R)
else if(components == Components::RedGreen)
@ -49,6 +71,5 @@ Renderbuffer::InternalFormat::InternalFormat(Components components, ComponentTyp
internalFormatSwitch(RGBA)
#undef internalFormatSwitch
}
#endif
}

36
src/Renderbuffer.h

@ -42,12 +42,11 @@ class Renderbuffer {
public:
/** @{ @name Internal renderbuffer formats */
#ifndef MAGNUM_TARGET_GLES
/**
* @copybrief AbstractTexture::Components
*
* Like AbstractTexture::Components, without three-component RGB.
* @requires_gl
* @requires_gles30 (no extension providing this functionality)
*/
enum class Components {
Red, RedGreen, RGBA
@ -58,13 +57,16 @@ class Renderbuffer {
*
* Like AbstractTexture::ComponentType, without normalized signed
* types.
* @requires_gl
* @requires_gles30 (no extension providing this functionality)
*/
enum class ComponentType {
UnsignedByte, Byte, UnsignedShort, Short, UnsignedInt, Int, Half,
Float, NormalizedUnsignedByte, NormalizedUnsignedShort
Float, NormalizedUnsignedByte
#ifndef MAGNUM_TARGET_GLES
, NormalizedUnsignedShort
#endif
};
#endif
/**
* @copybrief AbstractTexture::Format
@ -74,23 +76,15 @@ class Renderbuffer {
* compressed formats, but with added separate stencil index.
*/
enum class Format: GLenum {
#ifndef MAGNUM_TARGET_GLES
Red = GL_RED, RedGreen = GL_RG,
#endif
RGBA = GL_RGBA,
Red = GL_RED, RedGreen = GL_RG, RGBA = GL_RGBA,
#ifndef MAGNUM_TARGET_GLES
BGRA = GL_BGRA, SRGBA = GL_SRGB8_ALPHA8,
RGB10Alpha2 = GL_RGB10_A2, RGB10AlphaUnsigned2 = GL_RGB10_A2UI,
#endif
RGB5Alpha1 = GL_RGB5_A1, RGBA4 = GL_RGBA4,
#ifndef MAGNUM_TARGET_GLES
RFloat11GFloat11BFloat10 = GL_R11F_G11F_B10F,
BGRA = GL_BGRA,
#endif
SRGBA = GL_SRGB8_ALPHA8, RGB10Alpha2 = GL_RGB10_A2,
RGB10AlphaUnsigned2 = GL_RGB10_A2UI, RGB5Alpha1 = GL_RGB5_A1,
RGBA4 = GL_RGBA4, RFloat11GFloat11BFloat10 = GL_R11F_G11F_B10F,
RGB565 = GL_RGB565,
#ifndef MAGNUM_TARGET_GLES
@ -157,10 +151,8 @@ class Renderbuffer {
/** @copydoc AbstractTexture::InternalFormat */
class MAGNUM_EXPORT InternalFormat {
public:
#ifndef MAGNUM_TARGET_GLES
/** @copydoc AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components, AbstractTexture::ComponentType) */
InternalFormat(Components components, ComponentType type);
#endif
/** @copydoc AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Format) */
inline constexpr InternalFormat(Format format): internalFormat(static_cast<GLenum>(format)) {}
@ -226,11 +218,10 @@ class Renderbuffer {
GLuint renderbuffer;
};
#ifndef MAGNUM_TARGET_GLES
/** @relates Renderbuffer
@brief Convertor of component count and data type to InternalFormat
@requires_gl
@requires_gles30 (no extension providing this functionality)
*/
inline Renderbuffer::InternalFormat operator|(Renderbuffer::Components components, Renderbuffer::ComponentType type) {
return Renderbuffer::InternalFormat(components, type);
@ -241,7 +232,6 @@ inline Renderbuffer::InternalFormat operator|(Renderbuffer::Components component
inline Renderbuffer::InternalFormat operator|(Renderbuffer::ComponentType type, Renderbuffer::Components components) {
return Renderbuffer::InternalFormat(components, type);
}
#endif
}

8
src/Texture.h

@ -69,7 +69,7 @@ template<size_t textureDimensions> class Texture: public AbstractTexture {
/**
* Three-dimensional texture
* @requires_gl
* @requires_gles30 (no extension providing this functionality)
*/
Texture3D = GL_TEXTURE_3D,
@ -82,8 +82,8 @@ template<size_t textureDimensions> class Texture: public AbstractTexture {
/**
* Two-dimensional texture array (i.e. three dimensions in total)
* @requires_gl
* @requires_gl30 Extension @extension{EXT,texture_array}
* @requires_gles30 (no extension providing this functionality)
*/
Texture2DArray = GL_TEXTURE_2D_ARRAY,
@ -186,14 +186,12 @@ typedef Texture<1> Texture1D;
/** @brief Two-dimensional texture */
typedef Texture<2> Texture2D;
#ifndef MAGNUM_TARGET_GLES
/**
@brief Three-dimensional texture
@requires_gl
@requires_gles30 (no extension providing this functionality)
*/
typedef Texture<3> Texture3D;
#endif
}

Loading…
Cancel
Save