1 #include <msp/gl/extensions/arb_texture_float.h>
2 #include <msp/gl/extensions/ext_bgra.h>
3 #include <msp/strings/format.h>
4 #include "pixelformat.h"
11 void operator>>(const LexicalConverter &conv, PixelFormat &fmt)
13 if(conv.get()=="COLOR_INDEX")
15 else if(conv.get()=="STENCIL_INDEX")
17 else if(conv.get()=="DEPTH_COMPONENT")
18 fmt = DEPTH_COMPONENT;
19 else if(conv.get()=="RED")
21 else if(conv.get()=="GREEN")
23 else if(conv.get()=="BLUE")
25 else if(conv.get()=="ALPHA")
27 else if(conv.get()=="RGB")
29 else if(conv.get()=="RGBA")
31 else if(conv.get()=="BGR")
33 else if(conv.get()=="BGRA")
35 else if(conv.get()=="LUMINANCE")
37 else if(conv.get()=="LUMINANCE_ALPHA")
38 fmt = LUMINANCE_ALPHA;
40 throw lexical_error(format("conversion of '%s' to PixelFormat", conv.get()));
43 PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf)
47 case Graphics::COLOR_INDEX: return COLOR_INDEX;
48 case Graphics::LUMINANCE: return LUMINANCE;
49 case Graphics::LUMINANCE_ALPHA: return LUMINANCE_ALPHA;
50 case Graphics::RGB: return RGB;
52 case Graphics::RGBA: return RGBA;
53 case Graphics::BGR: return BGR;
55 case Graphics::BGRA: return BGRA;
56 default: throw invalid_argument("pixelformat_from_graphics");
60 PixelFormat storage_pixelformat_from_graphics(Graphics::PixelFormat pf)
66 case Graphics::BGRX: return RGB;
67 case Graphics::BGRA: return RGBA;
68 default: return pixelformat_from_graphics(pf);
72 PixelFormat get_base_pixelformat(PixelFormat pf)
78 case RGB32F: return RGB;
81 case RGBA32F: return RGBA;
84 case LUMINANCE32F: return LUMINANCE;
85 case LUMINANCE_ALPHA8:
86 case LUMINANCE_ALPHA16F:
87 case LUMINANCE_ALPHA32F: return LUMINANCE_ALPHA;
92 unsigned get_component_count(PixelFormat pf)
94 switch(get_base_pixelformat(pf))
104 case LUMINANCE_ALPHA:
113 throw invalid_argument("get_pixelformat_component_count");
117 void require_pixelformat(PixelFormat pf)
127 case LUMINANCE_ALPHA16F:
128 case LUMINANCE_ALPHA32F:
129 { static Require _req(ARB_texture_float); }
133 { static Require _req(EXT_bgra); }