]> git.tdb.fi Git - libs/gl.git/blob - source/pixelformat.cpp
Do not store generated files in the repository
[libs/gl.git] / source / pixelformat.cpp
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"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace GL {
10
11 void operator>>(const LexicalConverter &conv, PixelFormat &fmt)
12 {
13         if(conv.get()=="COLOR_INDEX")
14                 fmt = COLOR_INDEX;
15         else if(conv.get()=="STENCIL_INDEX")
16                 fmt = STENCIL_INDEX;
17         else if(conv.get()=="DEPTH_COMPONENT")
18                 fmt = DEPTH_COMPONENT;
19         else if(conv.get()=="RED")
20                 fmt = RED;
21         else if(conv.get()=="GREEN")
22                 fmt = GREEN;
23         else if(conv.get()=="BLUE")
24                 fmt = BLUE;
25         else if(conv.get()=="ALPHA")
26                 fmt = ALPHA;
27         else if(conv.get()=="RGB")
28                 fmt = RGB;
29         else if(conv.get()=="RGBA")
30                 fmt = RGBA;
31         else if(conv.get()=="BGR")
32                 fmt = BGR;
33         else if(conv.get()=="BGRA")
34                 fmt = BGRA;
35         else if(conv.get()=="LUMINANCE")
36                 fmt = LUMINANCE;
37         else if(conv.get()=="LUMINANCE_ALPHA")
38                 fmt = LUMINANCE_ALPHA;
39         else
40                 throw lexical_error(format("conversion of '%s' to PixelFormat", conv.get()));
41 }
42
43 PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf)
44 {
45         switch(pf)
46         {
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;
51         case Graphics::RGBA: return RGBA;
52         case Graphics::BGR: return BGR;
53         case Graphics::BGRA: return BGRA;
54         default: throw invalid_argument("pixelformat_from_graphics");
55         }
56 }
57
58 PixelFormat get_base_pixelformat(PixelFormat pf)
59 {
60         switch(pf)
61         {
62         case RGB8:
63         case RGB16F:
64         case RGB32F: return RGB;
65         case RGBA8:
66         case RGBA16F:
67         case RGBA32F: return RGBA;
68         case LUMINANCE8:
69         case LUMINANCE16F:
70         case LUMINANCE32F: return LUMINANCE;
71         case LUMINANCE_ALPHA8:
72         case LUMINANCE_ALPHA16F:
73         case LUMINANCE_ALPHA32F: return LUMINANCE_ALPHA;
74         default: return pf;
75         }
76 }
77
78 void require_pixelformat(PixelFormat pf)
79 {
80         switch(pf)
81         {
82         case RGB16F:
83         case RGB32F:
84         case RGBA16F:
85         case RGBA32F:
86         case LUMINANCE16F:
87         case LUMINANCE32F:
88         case LUMINANCE_ALPHA16F:
89         case LUMINANCE_ALPHA32F:
90                 { static Require _req(ARB_texture_float); }
91                 break;
92         case BGR:
93         case BGRA:
94                 { static Require _req(EXT_bgra); }
95                 break;
96         default:
97                 break;
98         }
99 }
100
101 } // namespace GL
102 } // namespace Msp