]> git.tdb.fi Git - libs/gl.git/commitdiff
Support sRGB pixelformats through GL_EXT_texture_sRGB
authorMikko Rasa <tdb@tdb.fi>
Sun, 5 Jan 2014 11:47:10 +0000 (13:47 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 5 Jan 2014 12:19:25 +0000 (14:19 +0200)
extensions/ext_texture_srgb.glext [new file with mode: 0644]
scripts/maketex.py
source/pixelformat.cpp
source/pixelformat.h

diff --git a/extensions/ext_texture_srgb.glext b/extensions/ext_texture_srgb.glext
new file mode 100644 (file)
index 0000000..32fddfb
--- /dev/null
@@ -0,0 +1 @@
+extension EXT_texture_sRGB
index 04de1d38a57d51cc2e25c2ea16f8e5896481283a..4da7866e7593b2f3abdfae7eaaa8e4254cd193f1 100755 (executable)
@@ -13,7 +13,7 @@ def escape(str):
                        result += c
        return result;
 
-def make_tex(fn, filter="LINEAR", anisotropy=0, wrap=None):
+def make_tex(fn, filter="LINEAR", anisotropy=0, wrap=None, srgb=False):
        import Image
 
        img = Image.open(fn)
@@ -24,6 +24,9 @@ def make_tex(fn, filter="LINEAR", anisotropy=0, wrap=None):
        elif fmt=="L":
                fmt = "LUMINANCE"
 
+       if srgb:
+               fmt = "S"+fmt
+
        result = "storage %s %d %d;\n"%(fmt, img.size[0], img.size[1])
        result += "filter %s;\n"%filter
        if "MIPMAP" in filter:
@@ -50,6 +53,7 @@ if __name__=="__main__":
        parser.add_argument("-f", "--filter", choices=["NEAREST", "LINEAR", "MIPMAP"], default="LINEAR", help="Filtering mode")
        parser.add_argument("-a", "--anisotropy", metavar="NUMBER", help="Maximum anisotropy, 0 = disable")
        parser.add_argument("-w", "--wrap", choices=["REPEAT", "CLAMP_TO_EDGE", "MIRRORED_REPEAT"], help="Wrapping mode")
+       parser.add_argument("--srgb", action="store_const", const=True, help="Use sRGB color space")
        parser.add_argument("image")
 
        args = parser.parse_args()
@@ -62,4 +66,4 @@ if __name__=="__main__":
        if not out_fn:
                out_fn = os.path.splitext(args.image)[0]+".tex2d"
        out = file(out_fn, "w")
-       out.write(make_tex(args.image, filter, args.anisotropy, args.wrap))
+       out.write(make_tex(args.image, filter, args.anisotropy, args.wrap, args.srgb))
index 26600b33661fca3c7e73729702278f0aa4664feb..027ae88c7fe1bb7c5e11290ef5133e3c143b8d05 100644 (file)
@@ -32,10 +32,18 @@ void operator>>(const LexicalConverter &conv, PixelFormat &fmt)
                fmt = BGR;
        else if(conv.get()=="BGRA")
                fmt = BGRA;
+       else if(conv.get()=="SRGB")
+               fmt = SRGB;
+       else if(conv.get()=="SRGB_ALPHA")
+               fmt = SRGB_ALPHA;
        else if(conv.get()=="LUMINANCE")
                fmt = LUMINANCE;
        else if(conv.get()=="LUMINANCE_ALPHA")
                fmt = LUMINANCE_ALPHA;
+       else if(conv.get()=="SLUMINANCE")
+               fmt = SLUMINANCE;
+       else if(conv.get()=="SLUMINANCE_ALPHA")
+               fmt = SLUMINANCE_ALPHA;
        else
                throw lexical_error(format("conversion of '%s' to PixelFormat", conv.get()));
 }
@@ -75,16 +83,24 @@ PixelFormat get_base_pixelformat(PixelFormat pf)
        {
        case RGB8:
        case RGB16F:
-       case RGB32F: return RGB;
+       case RGB32F:
+       case SRGB:
+       case SRGB8: return RGB;
        case RGBA8:
        case RGBA16F:
-       case RGBA32F: return RGBA;
+       case RGBA32F:
+       case SRGB_ALPHA:
+       case SRGB8_ALPHA8: return RGBA;
        case LUMINANCE8:
        case LUMINANCE16F:
-       case LUMINANCE32F: return LUMINANCE;
+       case LUMINANCE32F:
+       case SLUMINANCE:
+       case SLUMINANCE8: return LUMINANCE;
        case LUMINANCE_ALPHA8:
        case LUMINANCE_ALPHA16F:
-       case LUMINANCE_ALPHA32F: return LUMINANCE_ALPHA;
+       case LUMINANCE_ALPHA32F:
+       case SLUMINANCE_ALPHA:
+       case SLUMINANCE8_ALPHA8: return LUMINANCE_ALPHA;
        default: return pf;
        }
 }
@@ -100,8 +116,10 @@ unsigned get_component_count(PixelFormat pf)
        case GREEN:
        case BLUE:
        case LUMINANCE:
+       case SLUMINANCE:
                return 1;
        case LUMINANCE_ALPHA:
+       case SLUMINANCE_ALPHA:
                return 2;
        case RGB:
        case BGR:
@@ -128,6 +146,16 @@ void require_pixelformat(PixelFormat pf)
        case LUMINANCE_ALPHA32F:
                { static Require _req(ARB_texture_float); }
                break;
+       case SRGB:
+       case SRGB8:
+       case SRGB_ALPHA:
+       case SRGB8_ALPHA8:
+       case SLUMINANCE:
+       case SLUMINANCE8:
+       case SLUMINANCE_ALPHA:
+       case SLUMINANCE8_ALPHA8:
+               { static Require _req(EXT_texture_sRGB); }
+               break;
        case BGR:
        case BGRA:
                { static Require _req(EXT_bgra); }
index c232da1e5876f838cd6db34b9ad496adfb3ae113..01f626c43882bc192b00e83051b9c7c723fcf07c 100644 (file)
@@ -6,6 +6,7 @@
 #include "gl.h"
 #include <msp/gl/extensions/arb_texture_float.h>
 #include <msp/gl/extensions/ext_bgra.h>
+#include <msp/gl/extensions/ext_texture_srgb.h>
 
 namespace Msp {
 namespace GL {
@@ -27,6 +28,10 @@ enum PixelFormat
        RGBA8           = GL_RGBA8,
        RGBA16F         = GL_RGBA16F_ARB,
        RGBA32F         = GL_RGBA32F_ARB,
+       SRGB            = GL_SRGB_EXT,
+       SRGB_ALPHA      = GL_SRGB_ALPHA_EXT,
+       SRGB8           = GL_SRGB8_EXT,
+       SRGB8_ALPHA8    = GL_SRGB8_ALPHA8_EXT,
        BGR             = GL_BGR,
        BGRA            = GL_BGRA,
        LUMINANCE       = GL_LUMINANCE,
@@ -36,7 +41,11 @@ enum PixelFormat
        LUMINANCE_ALPHA    = GL_LUMINANCE_ALPHA,
        LUMINANCE_ALPHA8   = GL_LUMINANCE8_ALPHA8,
        LUMINANCE_ALPHA16F = GL_LUMINANCE_ALPHA16F_ARB,
-       LUMINANCE_ALPHA32F = GL_LUMINANCE_ALPHA32F_ARB
+       LUMINANCE_ALPHA32F = GL_LUMINANCE_ALPHA32F_ARB,
+       SLUMINANCE         = GL_SLUMINANCE_EXT,
+       SLUMINANCE8        = GL_SLUMINANCE8_EXT,
+       SLUMINANCE_ALPHA   = GL_SLUMINANCE_ALPHA_EXT,
+       SLUMINANCE8_ALPHA8 = GL_SLUMINANCE8_ALPHA8_EXT
 };
 
 void operator>>(const LexicalConverter &, PixelFormat &);