]> git.tdb.fi Git - libs/gl.git/blobdiff - source/pixelformat.cpp
Make better use of matrix operations in Camera
[libs/gl.git] / source / pixelformat.cpp
index 4b3dade14e4a9eef0b1052d4764c8e0c4c2b8a51..26600b33661fca3c7e73729702278f0aa4664feb 100644 (file)
@@ -1,6 +1,6 @@
+#include <msp/gl/extensions/arb_texture_float.h>
+#include <msp/gl/extensions/ext_bgra.h>
 #include <msp/strings/format.h>
-#include "arb_texture_float.h"
-#include "ext_bgra.h"
 #include "pixelformat.h"
 
 using namespace std;
@@ -48,13 +48,27 @@ PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf)
        case Graphics::LUMINANCE: return LUMINANCE;
        case Graphics::LUMINANCE_ALPHA: return LUMINANCE_ALPHA;
        case Graphics::RGB: return RGB;
+       case Graphics::RGBX:
        case Graphics::RGBA: return RGBA;
        case Graphics::BGR: return BGR;
+       case Graphics::BGRX:
        case Graphics::BGRA: return BGRA;
        default: throw invalid_argument("pixelformat_from_graphics");
        }
 }
 
+PixelFormat storage_pixelformat_from_graphics(Graphics::PixelFormat pf)
+{
+       switch(pf)
+       {
+       case Graphics::RGBX:
+       case Graphics::BGR:
+       case Graphics::BGRX: return RGB;
+       case Graphics::BGRA: return RGBA;
+       default: return pixelformat_from_graphics(pf);
+       }
+}
+
 PixelFormat get_base_pixelformat(PixelFormat pf)
 {
        switch(pf)
@@ -75,6 +89,31 @@ PixelFormat get_base_pixelformat(PixelFormat pf)
        }
 }
 
+unsigned get_component_count(PixelFormat pf)
+{
+       switch(get_base_pixelformat(pf))
+       {
+       case COLOR_INDEX:
+       case STENCIL_INDEX:
+       case DEPTH_COMPONENT:
+       case RED:
+       case GREEN:
+       case BLUE:
+       case LUMINANCE:
+               return 1;
+       case LUMINANCE_ALPHA:
+               return 2;
+       case RGB:
+       case BGR:
+               return 3;
+       case RGBA:
+       case BGRA:
+               return 4;
+       default:
+               throw invalid_argument("get_pixelformat_component_count");
+       }
+}
+
 void require_pixelformat(PixelFormat pf)
 {
        switch(pf)