From: Mikko Rasa Date: Thu, 27 Oct 2016 22:13:02 +0000 (+0300) Subject: Prefer sized internal formats when possible X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=49323eea600fb989d4181ccfd437ee12722ae733;p=libs%2Fgl.git Prefer sized internal formats when possible --- diff --git a/source/pixelformat.cpp b/source/pixelformat.cpp index 99f15307..3fdf6942 100644 --- a/source/pixelformat.cpp +++ b/source/pixelformat.cpp @@ -103,6 +103,27 @@ PixelFormat get_base_pixelformat(PixelFormat pf) } } +PixelFormat get_sized_pixelformat(PixelFormat pf) +{ + switch(pf) + { + case RGB: return RGB8; + case RGBA: return RGBA8; + case SRGB: return SRGB8; + case SRGB_ALPHA: return SRGB8_ALPHA8; + case LUMINANCE: return LUMINANCE8; + case SLUMINANCE: return SLUMINANCE8; + case LUMINANCE_ALPHA: return LUMINANCE8_ALPHA8; + case SLUMINANCE_ALPHA: return SLUMINANCE8_ALPHA8; + case DEPTH_COMPONENT: + if(get_gl_api()==OPENGL_ES2) + return DEPTH_COMPONENT16; + else + return DEPTH_COMPONENT32; + default: return pf; + } +} + PixelFormat get_srgb_pixelformat(PixelFormat pf) { switch(pf) diff --git a/source/pixelformat.h b/source/pixelformat.h index 8e3e6901..b69ad499 100644 --- a/source/pixelformat.h +++ b/source/pixelformat.h @@ -41,13 +41,16 @@ enum PixelFormat LUMINANCE16F = GL_LUMINANCE16F_ARB, LUMINANCE32F = GL_LUMINANCE32F_ARB, LUMINANCE_ALPHA = GL_LUMINANCE_ALPHA, - LUMINANCE_ALPHA8 = GL_LUMINANCE8_ALPHA8, + LUMINANCE8_ALPHA8 = GL_LUMINANCE8_ALPHA8, LUMINANCE_ALPHA16F = GL_LUMINANCE_ALPHA16F_ARB, LUMINANCE_ALPHA32F = GL_LUMINANCE_ALPHA32F_ARB, SLUMINANCE = GL_SLUMINANCE, SLUMINANCE8 = GL_SLUMINANCE8, SLUMINANCE_ALPHA = GL_SLUMINANCE_ALPHA, - SLUMINANCE8_ALPHA8 = GL_SLUMINANCE8_ALPHA8 + SLUMINANCE8_ALPHA8 = GL_SLUMINANCE8_ALPHA8, + + // Typo, deprecated + LUMINANCE_ALPHA8 = GL_LUMINANCE8_ALPHA8 }; void operator>>(const LexicalConverter &, PixelFormat &); @@ -56,6 +59,7 @@ PixelFormat pixelformat_from_graphics(Graphics::PixelFormat); PixelFormat storage_pixelformat_from_graphics(Graphics::PixelFormat, bool = false); PixelFormat get_base_pixelformat(PixelFormat); +PixelFormat get_sized_pixelformat(PixelFormat); PixelFormat get_srgb_pixelformat(PixelFormat); unsigned get_component_count(PixelFormat); unsigned get_component_size(PixelFormat); diff --git a/source/texture1d.cpp b/source/texture1d.cpp index a0ab79b9..78c9ed0c 100644 --- a/source/texture1d.cpp +++ b/source/texture1d.cpp @@ -23,6 +23,9 @@ void Texture1D::storage(PixelFormat fmt, unsigned wd) throw invalid_operation("Texture1D::storage"); if(wd==0) throw invalid_argument("Texture1D::storage"); + + if(MSP_sized_internal_formats) + fmt = get_sized_pixelformat(fmt); require_pixelformat(fmt); ifmt = fmt; diff --git a/source/texture2d.cpp b/source/texture2d.cpp index ae1afbc6..4d3dac03 100644 --- a/source/texture2d.cpp +++ b/source/texture2d.cpp @@ -50,6 +50,9 @@ void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht) throw invalid_operation("Texture2D::storage"); if(wd==0 || ht==0) throw invalid_argument("Texture2D::storage"); + + if(MSP_sized_internal_formats) + fmt = get_sized_pixelformat(fmt); require_pixelformat(fmt); ifmt = fmt; diff --git a/source/texture3d.cpp b/source/texture3d.cpp index 8cb26e7f..5c9f009c 100644 --- a/source/texture3d.cpp +++ b/source/texture3d.cpp @@ -37,12 +37,15 @@ void Texture3D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp) throw invalid_operation("Texture3D::storage"); if(wd==0 || ht==0 || dp==0) throw invalid_argument("Texture3D::storage"); + + if(MSP_sized_internal_formats) + fmt = get_sized_pixelformat(fmt); require_pixelformat(fmt); + ifmt = fmt; width = wd; height = ht; depth = dp; - ifmt = fmt; } void Texture3D::allocate(unsigned level) diff --git a/source/texturecube.cpp b/source/texturecube.cpp index 3c6f23bd..889d051b 100644 --- a/source/texturecube.cpp +++ b/source/texturecube.cpp @@ -37,6 +37,9 @@ void TextureCube::storage(PixelFormat fmt, unsigned sz) throw invalid_operation("TextureCube::storage"); if(sz==0) throw invalid_argument("TextureCube::storage"); + + if(MSP_sized_internal_formats) + fmt = get_sized_pixelformat(fmt); require_pixelformat(fmt); ifmt = fmt;