]> git.tdb.fi Git - libs/gl.git/blobdiff - source/pixelformat.cpp
Check the relevant extensions when using pixel formats
[libs/gl.git] / source / pixelformat.cpp
index d968917b25956440bf0f8f096baffec4dcba7737..4b3dade14e4a9eef0b1052d4764c8e0c4c2b8a51 100644 (file)
@@ -1,11 +1,6 @@
-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
-#include "except.h"
+#include <msp/strings/format.h>
+#include "arb_texture_float.h"
+#include "ext_bgra.h"
 #include "pixelformat.h"
 
 using namespace std;
@@ -13,41 +8,36 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-istream &operator>>(istream &in, PixelFormat &fmt)
+void operator>>(const LexicalConverter &conv, PixelFormat &fmt)
 {
-       string word;
-
-       in>>word;
-       if(word=="COLOR_INDEX")
-               fmt=COLOR_INDEX;
-       else if(word=="STENCIL_INDEX")
-               fmt=STENCIL_INDEX;
-       else if(word=="DEPTH_COMPONENT")
-               fmt=DEPTH_COMPONENT;
-       else if(word=="RED")
-               fmt=RED;
-       else if(word=="GREEN")
-               fmt=GREEN;
-       else if(word=="BLUE")
-               fmt=BLUE;
-       else if(word=="ALPHA")
-               fmt=ALPHA;
-       else if(word=="RGB")
-               fmt=RGB;
-       else if(word=="RGBA")
-               fmt=RGBA;
-       else if(word=="BGR")
-               fmt=BGR;
-       else if(word=="BGRA")
-               fmt=BGRA;
-       else if(word=="LUMINANCE")
-               fmt=LUMINANCE;
-       else if(word=="LUMINANCE_ALPHA")
-               fmt=LUMINANCE_ALPHA;
+       if(conv.get()=="COLOR_INDEX")
+               fmt = COLOR_INDEX;
+       else if(conv.get()=="STENCIL_INDEX")
+               fmt = STENCIL_INDEX;
+       else if(conv.get()=="DEPTH_COMPONENT")
+               fmt = DEPTH_COMPONENT;
+       else if(conv.get()=="RED")
+               fmt = RED;
+       else if(conv.get()=="GREEN")
+               fmt = GREEN;
+       else if(conv.get()=="BLUE")
+               fmt = BLUE;
+       else if(conv.get()=="ALPHA")
+               fmt = ALPHA;
+       else if(conv.get()=="RGB")
+               fmt = RGB;
+       else if(conv.get()=="RGBA")
+               fmt = RGBA;
+       else if(conv.get()=="BGR")
+               fmt = BGR;
+       else if(conv.get()=="BGRA")
+               fmt = BGRA;
+       else if(conv.get()=="LUMINANCE")
+               fmt = LUMINANCE;
+       else if(conv.get()=="LUMINANCE_ALPHA")
+               fmt = LUMINANCE_ALPHA;
        else
-               in.setstate(ios_base::failbit);
-
-       return in;
+               throw lexical_error(format("conversion of '%s' to PixelFormat", conv.get()));
 }
 
 PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf)
@@ -61,7 +51,50 @@ PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf)
        case Graphics::RGBA: return RGBA;
        case Graphics::BGR: return BGR;
        case Graphics::BGRA: return BGRA;
-       default: throw InvalidParameterValue("Unknown Graphics::PixelFormat");
+       default: throw invalid_argument("pixelformat_from_graphics");
+       }
+}
+
+PixelFormat get_base_pixelformat(PixelFormat pf)
+{
+       switch(pf)
+       {
+       case RGB8:
+       case RGB16F:
+       case RGB32F: return RGB;
+       case RGBA8:
+       case RGBA16F:
+       case RGBA32F: return RGBA;
+       case LUMINANCE8:
+       case LUMINANCE16F:
+       case LUMINANCE32F: return LUMINANCE;
+       case LUMINANCE_ALPHA8:
+       case LUMINANCE_ALPHA16F:
+       case LUMINANCE_ALPHA32F: return LUMINANCE_ALPHA;
+       default: return pf;
+       }
+}
+
+void require_pixelformat(PixelFormat pf)
+{
+       switch(pf)
+       {
+       case RGB16F:
+       case RGB32F:
+       case RGBA16F:
+       case RGBA32F:
+       case LUMINANCE16F:
+       case LUMINANCE32F:
+       case LUMINANCE_ALPHA16F:
+       case LUMINANCE_ALPHA32F:
+               { static Require _req(ARB_texture_float); }
+               break;
+       case BGR:
+       case BGRA:
+               { static Require _req(EXT_bgra); }
+               break;
+       default:
+               break;
        }
 }