From: Mikko Rasa Date: Sun, 5 Jan 2014 11:47:10 +0000 (+0200) Subject: Support sRGB pixelformats through GL_EXT_texture_sRGB X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=5a93cc603eef43617a10b76bc9c19a3272ac1d49 Support sRGB pixelformats through GL_EXT_texture_sRGB --- diff --git a/extensions/ext_texture_srgb.glext b/extensions/ext_texture_srgb.glext new file mode 100644 index 00000000..32fddfbd --- /dev/null +++ b/extensions/ext_texture_srgb.glext @@ -0,0 +1 @@ +extension EXT_texture_sRGB diff --git a/scripts/maketex.py b/scripts/maketex.py index 04de1d38..4da7866e 100755 --- a/scripts/maketex.py +++ b/scripts/maketex.py @@ -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)) diff --git a/source/pixelformat.cpp b/source/pixelformat.cpp index 26600b33..027ae88c 100644 --- a/source/pixelformat.cpp +++ b/source/pixelformat.cpp @@ -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); } diff --git a/source/pixelformat.h b/source/pixelformat.h index c232da1e..01f626c4 100644 --- a/source/pixelformat.h +++ b/source/pixelformat.h @@ -6,6 +6,7 @@ #include "gl.h" #include #include +#include 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 &);