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
29 ComponentSwizzle get_required_swizzle(PixelComponents comp)
33 case BGR: return RGB_TO_BGR;
34 case BGRA: return RGB_TO_BGR;
35 case LUMINANCE: return R_TO_LUMINANCE;
36 case LUMINANCE_ALPHA: return RG_TO_LUMINANCE_ALPHA;
37 default: return NO_SWIZZLE;
41 void require_pixelformat(PixelFormat pf)
43 /* TODO These checks are only accurate for textures. On OpenGL ES some
44 formats are allowed for render buffers earlier than textures. In particular
45 it's possible to create a 16-bit depth renderbuffer on OpenGL ES 2.0 but
46 depth textures are only available with 3.0 or the OES_depth_texture
52 { static Require _req(OES_required_internalformat); }
56 { static Require _req(ARB_texture_rg); }
62 { static Require _req(ARB_texture_rg); }
63 { static Require _req(ARB_texture_float); }
69 { static Require _req(ARB_texture_float); }
73 { static Require _req(EXT_texture_sRGB); }
75 case DEPTH_COMPONENT16:
76 case DEPTH_COMPONENT24:
77 case DEPTH_COMPONENT32:
78 { static Require _req(ARB_depth_texture); }
79 { static Require _req(OES_required_internalformat); }
81 case DEPTH_COMPONENT32F:
82 { static Require _req(ARB_depth_buffer_float); }
85 { static Require _req(OES_texture_stencil8); }
88 throw invalid_argument("require_pixelformat");
92 unsigned get_gl_components(PixelComponents comp)
96 case RED: return GL_RED;
97 case RG: return GL_RG;
98 case RGB: return GL_RGB;
99 case RGBA: return GL_RGBA;
100 case DEPTH_COMPONENT: return GL_DEPTH_COMPONENT;
101 case STENCIL_INDEX: return GL_STENCIL_INDEX;
102 default: throw invalid_argument("get_gl_components");
106 unsigned get_gl_pixelformat(PixelFormat pf)
110 case R8: return GL_R8;
111 case R16F: return GL_R16F;
112 case R32F: return GL_R32F;
113 case RG8: return GL_RG8;
114 case RG16F: return GL_RG16F;
115 case RG32F: return GL_RG32F;
116 case RGB8: return GL_RGB8;
117 case RGB16F: return GL_RGB16F;
118 case RGB32F: return GL_RGB32F;
119 case RGBA8: return GL_RGBA8;
120 case RGBA16F: return GL_RGBA16F;
121 case RGBA32F: return GL_RGBA32F;
122 case SRGB8: return GL_SRGB8;
123 case SRGB8_ALPHA8: return GL_SRGB8_ALPHA8;
124 case DEPTH_COMPONENT16: return GL_DEPTH_COMPONENT16;
125 case DEPTH_COMPONENT24: return GL_DEPTH_COMPONENT24;
126 case DEPTH_COMPONENT32: return GL_DEPTH_COMPONENT32;
127 case DEPTH_COMPONENT32F: return GL_DEPTH_COMPONENT32F;
128 case STENCIL_INDEX8: return GL_STENCIL_INDEX8;
129 default: throw invalid_argument("get_gl_pixelformat");
133 const int *get_gl_swizzle(ComponentSwizzle swiz)
135 return swizzle_orders+4*swiz;