]> git.tdb.fi Git - libs/gl.git/blob - source/pixelformat.cpp
Allocate textures attached to framebuffers automatically
[libs/gl.git] / source / pixelformat.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "except.h"
9 #include "pixelformat.h"
10
11 using namespace std;
12
13 namespace Msp {
14 namespace GL {
15
16 istream &operator>>(istream &in, PixelFormat &fmt)
17 {
18         string word;
19
20         in>>word;
21         if(word=="COLOR_INDEX")
22                 fmt = COLOR_INDEX;
23         else if(word=="STENCIL_INDEX")
24                 fmt = STENCIL_INDEX;
25         else if(word=="DEPTH_COMPONENT")
26                 fmt = DEPTH_COMPONENT;
27         else if(word=="RED")
28                 fmt = RED;
29         else if(word=="GREEN")
30                 fmt = GREEN;
31         else if(word=="BLUE")
32                 fmt = BLUE;
33         else if(word=="ALPHA")
34                 fmt = ALPHA;
35         else if(word=="RGB")
36                 fmt = RGB;
37         else if(word=="RGBA")
38                 fmt = RGBA;
39         else if(word=="BGR")
40                 fmt = BGR;
41         else if(word=="BGRA")
42                 fmt = BGRA;
43         else if(word=="LUMINANCE")
44                 fmt = LUMINANCE;
45         else if(word=="LUMINANCE_ALPHA")
46                 fmt = LUMINANCE_ALPHA;
47         else
48                 in.setstate(ios_base::failbit);
49
50         return in;
51 }
52
53 PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf)
54 {
55         switch(pf)
56         {
57         case Graphics::COLOR_INDEX: return COLOR_INDEX;
58         case Graphics::LUMINANCE: return LUMINANCE;
59         case Graphics::LUMINANCE_ALPHA: return LUMINANCE_ALPHA;
60         case Graphics::RGB: return RGB;
61         case Graphics::RGBA: return RGBA;
62         case Graphics::BGR: return BGR;
63         case Graphics::BGRA: return BGRA;
64         default: throw InvalidParameterValue("Unknown Graphics::PixelFormat");
65         }
66 }
67
68 PixelFormat get_base_pixelformat(PixelFormat pf)
69 {
70         switch(pf)
71         {
72         case RGB8:
73         case RGB16F:
74         case RGB32F: return RGB;
75         case RGBA8:
76         case RGBA16F:
77         case RGBA32F: return RGBA;
78         case LUMINANCE8:
79         case LUMINANCE16F:
80         case LUMINANCE32F: return LUMINANCE;
81         case LUMINANCE_ALPHA8:
82         case LUMINANCE_ALPHA16F:
83         case LUMINANCE_ALPHA32F: return LUMINANCE_ALPHA;
84         default: return pf;
85         }
86 }
87
88 } // namespace GL
89 } // namespace Msp