]> git.tdb.fi Git - libs/gl.git/commitdiff
Prefer sized internal formats when possible
authorMikko Rasa <tdb@tdb.fi>
Thu, 27 Oct 2016 22:13:02 +0000 (01:13 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 27 Oct 2016 22:13:02 +0000 (01:13 +0300)
source/pixelformat.cpp
source/pixelformat.h
source/texture1d.cpp
source/texture2d.cpp
source/texture3d.cpp
source/texturecube.cpp

index 99f15307d1304bf41c36c80aa7af825fd41a7171..3fdf6942c63cc606c04babdf54316330878ec1f9 100644 (file)
@@ -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)
index 8e3e6901e95d0e40c7357b3e2389429dabb14e8d..b69ad499c59c6f77ad3ae737e9c257601544996a 100644 (file)
@@ -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);
index a0ab79b943aef573e192edcc36e1e011fffb77c7..78c9ed0c54209a067c51516126b797289ddb82d4 100644 (file)
@@ -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;
index ae1afbc60cca9f0e64f05c743af38b0b64241e13..4d3dac037291137856d28a77926e9517ac9475de 100644 (file)
@@ -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;
index 8cb26e7f76713bf44932f25744aea5d31be4defd..5c9f009c0d5eb6d798a06b9a64fd783341430e38 100644 (file)
@@ -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)
index 3c6f23bd94f05443fd5e872febca8edf19555875..889d051b905e490dc9006f993a24fc476871d5c5 100644 (file)
@@ -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;