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"
17 void require_pixelformat(PixelFormat pf)
19 /* TODO These checks are only accurate for textures. On OpenGL ES some
20 formats are allowed for render buffers earlier than textures. In particular
21 it's possible to create a 16-bit depth renderbuffer on OpenGL ES 2.0 but
22 depth textures are only available with 3.0 or the OES_depth_texture
28 { static Require _req(OES_required_internalformat); }
32 { static Require _req(ARB_texture_rg); }
38 { static Require _req(ARB_texture_rg); }
39 { static Require _req(ARB_texture_float); }
45 { static Require _req(ARB_texture_float); }
49 { static Require _req(EXT_texture_sRGB); }
51 case DEPTH_COMPONENT16:
52 case DEPTH_COMPONENT24:
53 case DEPTH_COMPONENT32:
54 { static Require _req(ARB_depth_texture); }
55 { static Require _req(OES_required_internalformat); }
57 case DEPTH_COMPONENT32F:
58 { static Require _req(ARB_depth_buffer_float); }
61 { static Require _req(OES_texture_stencil8); }
64 throw invalid_argument("require_pixelformat");
68 unsigned get_gl_components(PixelComponents comp)
72 case RED: return GL_RED;
73 case RG: return GL_RG;
74 case RGB: return GL_RGB;
75 case RGBA: return GL_RGBA;
76 case DEPTH_COMPONENT: return GL_DEPTH_COMPONENT;
77 case STENCIL_INDEX: return GL_STENCIL_INDEX;
78 default: throw invalid_argument("get_gl_components");
82 unsigned get_gl_pixelformat(PixelFormat pf)
86 case R8: return GL_R8;
87 case R16F: return GL_R16F;
88 case R32F: return GL_R32F;
89 case RG8: return GL_RG8;
90 case RG16F: return GL_RG16F;
91 case RG32F: return GL_RG32F;
92 case RGB8: return GL_RGB8;
93 case RGB16F: return GL_RGB16F;
94 case RGB32F: return GL_RGB32F;
95 case RGBA8: return GL_RGBA8;
96 case RGBA16F: return GL_RGBA16F;
97 case RGBA32F: return GL_RGBA32F;
98 case SRGB8: return GL_SRGB8;
99 case SRGB8_ALPHA8: return GL_SRGB8_ALPHA8;
100 case DEPTH_COMPONENT16: return GL_DEPTH_COMPONENT16;
101 case DEPTH_COMPONENT24: return GL_DEPTH_COMPONENT24;
102 case DEPTH_COMPONENT32: return GL_DEPTH_COMPONENT32;
103 case DEPTH_COMPONENT32F: return GL_DEPTH_COMPONENT32F;
104 case STENCIL_INDEX8: return GL_STENCIL_INDEX8;
105 default: throw invalid_argument("get_gl_pixelformat");