1 #include <msp/gl/extensions/arb_depth_buffer_float.h>
2 #include <msp/gl/extensions/arb_depth_texture.h>
3 #include <msp/gl/extensions/arb_texture_float.h>
4 #include <msp/gl/extensions/arb_texture_rg.h>
5 #include <msp/gl/extensions/ext_texture_srgb.h>
6 #include <msp/gl/extensions/oes_required_internalformat.h>
7 #include <msp/gl/extensions/oes_texture_stencil8.h>
9 #include "pixelformat.h"
10 #include "pixelformat_backend.h"
16 int swizzle_orders[] =
18 GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA,
19 GL_RED, GL_RED, GL_RED, GL_ONE,
20 GL_RED, GL_RED, GL_RED, GL_GREEN,
21 GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA,
22 GL_RED, GL_GREEN, GL_BLUE, GL_ONE
30 ComponentSwizzle get_required_swizzle(PixelComponents comp)
34 case BGR: return RGB_TO_BGR;
35 case BGRA: return RGB_TO_BGR;
36 case LUMINANCE: return R_TO_LUMINANCE;
37 case LUMINANCE_ALPHA: return RG_TO_LUMINANCE_ALPHA;
38 default: return NO_SWIZZLE;
42 void require_pixelformat(PixelFormat pf)
44 /* TODO These checks are only accurate for textures. On OpenGL ES some
45 formats are allowed for render buffers earlier than textures. In particular
46 it's possible to create a 16-bit depth renderbuffer on OpenGL ES 2.0 but
47 depth textures are only available with 3.0 or the OES_depth_texture
53 { static Require _req(OES_required_internalformat); }
57 { static Require _req(ARB_texture_rg); }
63 { static Require _req(ARB_texture_rg); }
64 { static Require _req(ARB_texture_float); }
70 { static Require _req(ARB_texture_float); }
74 { static Require _req(EXT_texture_sRGB); }
76 case DEPTH_COMPONENT16:
77 case DEPTH_COMPONENT24:
78 case DEPTH_COMPONENT32:
79 { static Require _req(ARB_depth_texture); }
80 { static Require _req(OES_required_internalformat); }
82 case DEPTH_COMPONENT32F:
83 { static Require _req(ARB_depth_buffer_float); }
86 { static Require _req(OES_texture_stencil8); }
89 throw invalid_argument("require_pixelformat");
93 unsigned get_gl_components(PixelComponents comp)
97 case RED: return GL_RED;
98 case RG: return GL_RG;
99 case RGB: return GL_RGB;
100 case RGBA: return GL_RGBA;
101 case DEPTH_COMPONENT: return GL_DEPTH_COMPONENT;
102 case STENCIL_INDEX: return GL_STENCIL_INDEX;
103 default: throw invalid_argument("get_gl_components");
107 unsigned get_gl_pixelformat(PixelFormat pf)
111 case R8: return GL_R8;
112 case R16F: return GL_R16F;
113 case R32F: return GL_R32F;
114 case RG8: return GL_RG8;
115 case RG16F: return GL_RG16F;
116 case RG32F: return GL_RG32F;
117 case RGB8: return GL_RGB8;
118 case RGB16F: return GL_RGB16F;
119 case RGB32F: return GL_RGB32F;
120 case RGBA8: return GL_RGBA8;
121 case RGBA16F: return GL_RGBA16F;
122 case RGBA32F: return GL_RGBA32F;
123 case SRGB8: return GL_SRGB8;
124 case SRGB8_ALPHA8: return GL_SRGB8_ALPHA8;
125 case DEPTH_COMPONENT16: return GL_DEPTH_COMPONENT16;
126 case DEPTH_COMPONENT24: return GL_DEPTH_COMPONENT24;
127 case DEPTH_COMPONENT32: return GL_DEPTH_COMPONENT32;
128 case DEPTH_COMPONENT32F: return GL_DEPTH_COMPONENT32F;
129 case STENCIL_INDEX8: return GL_STENCIL_INDEX8;
130 default: throw invalid_argument("get_gl_pixelformat");
134 const int *get_gl_swizzle(ComponentSwizzle swiz)
136 return swizzle_orders+4*swiz;