From f0db90c8efbd07140380fe0239973d32232875c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 5 Jun 2013 14:35:51 +0200 Subject: [PATCH] Added ES2-only support for GL_LUMINANCE{,_ALPHA}. It is deprecated, but many ES2 implementations don't support EXT_texture_rg, thus this is the only way to have single- and two-component textures without wasting precious memory. The enum value isn't exposed on desktop OpenGL and ES3. GL_ALPHA is not supported, as it doesn't bring any new functionality (it is also single-component and thus can be interchanged with GL_LUMINANCE). --- doc/unsupported.dox | 2 -- src/AbstractImage.cpp | 6 ++++++ src/ImageFormat.cpp | 6 ++++++ src/ImageFormat.h | 24 +++++++++++++++++++++++- src/TextureFormat.h | 25 +++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 3 deletions(-) diff --git a/doc/unsupported.dox b/doc/unsupported.dox index 85a52c830..0c6efc4ec 100644 --- a/doc/unsupported.dox +++ b/doc/unsupported.dox @@ -29,8 +29,6 @@ add any performance gains, is not supported in %Magnum. @section unsupported-features Unsupported features -- Luminance texture formats (OpenGL ES) are not supported, as they are - deprecated in OpenGL ES 3.0 and not present in core desktop OpenGL. - Fixed precision data types (OpenGL ES) are not supported, as they occupy the same memory as floats and they aren't faster than floats on current hardware anymore. diff --git a/src/AbstractImage.cpp b/src/AbstractImage.cpp index 253f2ec37..0e3af2904 100644 --- a/src/AbstractImage.cpp +++ b/src/AbstractImage.cpp @@ -99,11 +99,17 @@ std::size_t AbstractImage::pixelSize(ImageFormat format, ImageType type) { case ImageFormat::Blue: case ImageFormat::GreenInteger: case ImageFormat::BlueInteger: + #endif + #ifdef MAGNUM_TARGET_GLES2 + case ImageFormat::Luminance: #endif return 1*size; case ImageFormat::RG: #ifndef MAGNUM_TARGET_GLES2 case ImageFormat::RGInteger: + #endif + #ifdef MAGNUM_TARGET_GLES2 + case ImageFormat::LuminanceAlpha: #endif return 2*size; case ImageFormat::RGB: diff --git a/src/ImageFormat.cpp b/src/ImageFormat.cpp index 014cf25eb..0d8d1fb88 100644 --- a/src/ImageFormat.cpp +++ b/src/ImageFormat.cpp @@ -37,7 +37,13 @@ Debug operator<<(Debug debug, ImageFormat value) { _c(Green) _c(Blue) #endif + #ifdef MAGNUM_TARGET_GLES2 + _c(Luminance) + #endif _c(RG) + #ifdef MAGNUM_TARGET_GLES2 + _c(LuminanceAlpha) + #endif _c(RGB) _c(RGBA) #ifndef MAGNUM_TARGET_GLES diff --git a/src/ImageFormat.h b/src/ImageFormat.h index 23b2a58f8..9420da939 100644 --- a/src/ImageFormat.h +++ b/src/ImageFormat.h @@ -68,8 +68,18 @@ enum class ImageFormat: GLenum { * available in OpenGL ES. */ Blue = GL_BLUE, + #endif - /** @todo GL_ALPHA? */ + #if defined(MAGNUM_TARGET_GLES2) || defined(DOXYGEN_GENERATING_OUTPUT) + /** + * Floating-point luminance channel. The value is used for all RGB + * channels. + * @deprecated Included for compatibility reasons only, use + * @ref Magnum::ImageFormat "ImageFormat::Red" instead. + * @requires_gles20 Not available in ES 3.0 or desktop OpenGL. Use + * @ref Magnum::ImageFormat "ImageFormat::Red" instead. + */ + Luminance = GL_LUMINANCE, #endif /** @@ -84,6 +94,18 @@ enum class ImageFormat: GLenum { RG = GL_RG_EXT, #endif + #if defined(MAGNUM_TARGET_GLES2) || defined(DOXYGEN_GENERATING_OUTPUT) + /** + * Floating-point luminance and alpha channel. First value is used for all + * RGB channels, second value is used for alpha channel. + * @deprecated Included for compatibility reasons only, use + * @ref Magnum::ImageFormat "ImageFormat::RG" instead. + * @requires_gles20 Not available in ES 3.0 or desktop OpenGL. Use + * @ref Magnum::ImageFormat "ImageFormat::RG" instead. + */ + LuminanceAlpha = GL_LUMINANCE_ALPHA, + #endif + /** * Floating-point RGB. * @requires_gl Can't be used for framebuffer reading in OpenGL ES. diff --git a/src/TextureFormat.h b/src/TextureFormat.h index 7857540f7..f27d2e864 100644 --- a/src/TextureFormat.h +++ b/src/TextureFormat.h @@ -475,7 +475,32 @@ enum class TextureFormat: GLenum { * @requires_gl Packed 8bit types are not available in OpenGL ES. */ R3B3G2 = GL_R3_G3_B2, + #endif + + #if defined(MAGNUM_TARGET_GLES2) || defined(DOXYGEN_GENERATING_OUTPUT) + /** + * Luminance, normalized unsigned, single value used for all RGB channels. + * Size implementation-dependent. + * @deprecated Included for compatibility reasons only, use + * @ref Magnum::TextureFormat "TextureFormat::R8" instead. + * @requires_gles20 Not available in ES 3.0 or desktop OpenGL. Use + * @ref Magnum::TextureFormat "TextureFormat::R8" instead. + */ + Luminance = GL_LUMINANCE, + + /** + * Floating-point luminance and alpha channel. First value is used for all + * RGB channels, second value is used for alpha channel. Size + * implementation-dependent. + * @deprecated Included for compatibility reasons only, use + * @ref Magnum::TextureFormat "TextureFormat::RG" instead. + * @requires_gles20 Not available in ES 3.0 or desktop OpenGL. Use + * @ref Magnum::TextureFormat "TextureFormat::RG" instead. + */ + LuminanceAlpha = GL_LUMINANCE_ALPHA, + #endif + #ifndef MAGNUM_TARGET_GLES /** * RGB, each component normalized unsigned 4bit. * @requires_gl Packed 12bit types are not available in OpenGL ES.