]> git.tdb.fi Git - libs/gl.git/blob - source/core/pixelformat.h
Initialize Texture's format to an invalid value
[libs/gl.git] / source / core / pixelformat.h
1 #ifndef MSP_GL_PIXELFORMAT_H_
2 #define MSP_GL_PIXELFORMAT_H_
3
4 #include <msp/graphics/image.h>
5 #include <msp/strings/lexicalcast.h>
6 #include "gl.h"
7 #include "datatype.h"
8
9 namespace Msp {
10 namespace GL {
11
12 /**
13 Identifies the components of a pixel, without type information.  The values
14 are bitfields laid as follows:
15
16 _grs dccc
17  │││ │  └╴Number of components
18  │││ └───╴Depth flag
19  ││└─────╴Stencil flag
20  │└──────╴Reverse order flag
21  └───────╴Grayscale flag
22
23 This information is presented for internal documentation purposes only; it is
24 inadvisable for programs to rely on it.
25 */
26 enum PixelComponents
27 {
28         RED = 0x01,
29         RG = 0x02,
30         RGB = 0x03,
31         RGBA = 0x04,
32         DEPTH_COMPONENT = 0x09,
33         STENCIL_INDEX = 0x11,
34         BGR = 0x23,
35         BGRA = 0x24,
36         LUMINANCE = 0x41,
37         LUMINANCE_ALPHA = 0x42
38 };
39
40 /**
41 Identifies a pixel format, with components and type.  The values are bitfields
42 laid as follows:
43
44 tnfg ssss cccc cccc
45 ││││    │         └╴Components (see PixelComponents)
46 ││││    └──────────╴Size of one component (bytes)
47 │││└───────────────╴Signed flag
48 ││└────────────────╴Floating-point flag
49 │└─────────────────╴Normalized flag
50 └──────────────────╴sRGB flag
51
52 This information is presented for internal documentation purposes only; it is
53 inadvisable for programs to rely on it.
54 */
55 enum PixelFormat
56 {
57         NO_PIXELFORMAT = 0,
58         R8 = 0x4100|RED,
59         R16F = 0x3200|RED,
60         R32F = 0x3400|RED,
61         RG8 = 0x4100|RG,
62         RG16F = 0x3200|RG,
63         RG32F = 0x3400|RG,
64         RGB8 = 0x4100|RGB,
65         RGB16F = 0x3200|RGB,
66         RGB32F = 0x3400|RGB,
67         RGBA8 = 0x4100|RGBA,
68         RGBA16F = 0x3200|RGBA,
69         RGBA32F = 0x3400|RGBA,
70         SRGB8 = 0xC100|RGB,
71         SRGB8_ALPHA8 = 0xC100|RGBA,
72         BGR8 = 0x4100|BGR,
73         BGRA8 = 0x4100|BGRA,
74         SBGR8 = 0xC100|BGR,
75         SBGR8_ALPHA8 = 0xC100|BGRA,
76         LUMINANCE8 = 0x4100|LUMINANCE,
77         LUMINANCE8_ALPHA8 = 0x4100|LUMINANCE_ALPHA,
78         DEPTH_COMPONENT16 = 0x4200|DEPTH_COMPONENT,
79         DEPTH_COMPONENT24 = 0x4300|DEPTH_COMPONENT,
80         DEPTH_COMPONENT32 = 0x4400|DEPTH_COMPONENT,
81         DEPTH_COMPONENT32F = 0x3400|DEPTH_COMPONENT,
82         STENCIL_INDEX8 = 0x0100|STENCIL_INDEX
83 };
84
85 void operator>>(const LexicalConverter &, PixelComponents &);
86 void operator>>(const LexicalConverter &, PixelFormat &);
87
88 PixelComponents components_from_graphics(Graphics::PixelFormat);
89 PixelFormat pixelformat_from_image(const Graphics::Image &);
90
91 PixelFormat make_pixelformat(PixelComponents, DataType, bool = false);
92 inline PixelComponents get_components(PixelFormat f) { return static_cast<PixelComponents>(f&0xFF); }
93 inline unsigned get_component_count(PixelComponents c) { return c&7; }
94 inline unsigned get_component_count(PixelFormat f) { return get_component_count(get_components(f)); }
95 inline DataType get_component_type(PixelFormat f) { return static_cast<DataType>((f&0xF00)>>8 | (f&0x3000)>>4); }
96 inline unsigned get_component_size(PixelFormat f) { return get_type_size(get_component_type(f)); }
97 inline bool is_srgb(PixelFormat f) { return f&0x8000; }
98 inline unsigned get_pixel_size(PixelFormat f) { return get_component_count(f)*get_type_size(get_component_type(f)); }
99
100 void require_pixelformat(PixelFormat);
101
102 GLenum get_gl_components(PixelComponents);
103 GLenum get_gl_pixelformat(PixelFormat);
104
105 } // namespace GL
106 } // namespace Msp
107
108 #endif