blob: 2381f4394dd6698633b5e69cecc048b49967027e [file] [log] [blame]
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001#include "precompiled.h"
2//
3// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// formatutils.cpp: Queries for GL image formats.
9
10#include "libGLESv2/formatutils.h"
11#include "libGLESv2/Context.h"
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000012#include "common/mathutil.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000013#include "libGLESv2/renderer/Renderer.h"
14
15namespace gl
16{
17
18// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the implementation
19// can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid
20// format and type combinations.
21
22typedef std::pair<GLenum, GLenum> FormatTypePair;
23typedef std::pair<FormatTypePair, GLint> FormatPair;
24typedef std::map<FormatTypePair, GLint> FormatMap;
25
26// A helper function to insert data into the D3D11LoadFunctionMap with fewer characters.
27static inline void insertFormatMapping(FormatMap *map, GLenum format, GLenum type, GLint internalFormat)
28{
29 map->insert(FormatPair(FormatTypePair(format, type), internalFormat));
30}
31
32FormatMap buildES2FormatMap()
33{
34 FormatMap map;
35
36 // | Format | Type | Internal format |
37 insertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT );
38 insertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT );
39 insertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT_OES, GL_ALPHA16F_EXT );
40
41 insertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT );
42 insertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT );
43 insertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_LUMINANCE16F_EXT );
44
45 insertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT );
46 insertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT );
47 insertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_LUMINANCE_ALPHA16F_EXT );
48
49 insertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8_OES );
50 insertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565 );
51 insertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F_EXT );
52 insertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT_OES, GL_RGB16F_EXT );
53
54 insertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8_OES );
55 insertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4 );
56 insertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1 );
57 insertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F_EXT );
58 insertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA16F_EXT );
59
60 insertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT );
61 insertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX );
62 insertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_BGR5_A1_ANGLEX );
63
64 insertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGB_S3TC_DXT1_EXT );
65 insertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT );
66 insertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE);
67 insertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE);
68
69 insertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16 );
70 insertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32_OES );
71
72 insertFormatMapping(&map, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, GL_DEPTH24_STENCIL8_OES );
73
74 return map;
75}
76
77static const FormatMap &getES2FormatMap()
78{
79 static const FormatMap es2FormatMap = buildES2FormatMap();
80 return es2FormatMap;
81}
82
83FormatMap buildES3FormatMap()
84{
85 FormatMap map;
86
87 // | Format | Type | Internal format |
88 insertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8 );
89 insertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4 );
90 insertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1 );
91 insertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F );
92 insertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F );
93
94 insertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8 );
95 insertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565 );
96 insertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F );
97 insertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT, GL_RGB16F );
98
99 insertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT );
100 insertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT );
101 insertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT );
102 insertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT);
103 insertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT );
104 insertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT );
105 insertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_LUMINANCE_ALPHA16F_EXT);
106 insertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT, GL_LUMINANCE16F_EXT );
107 insertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT, GL_ALPHA16F_EXT );
108
109 insertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT );
110 insertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX );
111 insertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_BGR5_A1_ANGLEX );
112
113 insertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16 );
114 insertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT24 );
115 insertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32F );
116
117 insertFormatMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8 );
118 insertFormatMapping(&map, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_DEPTH32F_STENCIL8 );
119
120 return map;
121}
122
123struct FormatInfo
124{
125 GLint mInternalformat;
126 GLenum mFormat;
127 GLenum mType;
128
129 FormatInfo(GLint internalformat, GLenum format, GLenum type)
130 : mInternalformat(internalformat), mFormat(format), mType(type) { }
131
132 bool operator<(const FormatInfo& other) const
133 {
134 return memcmp(this, &other, sizeof(FormatInfo)) < 0;
135 }
136};
137
138// ES3 has a specific set of permutations of internal formats, formats and types which are acceptable.
139typedef std::set<FormatInfo> ES3FormatSet;
140
141ES3FormatSet buildES3FormatSet()
142{
143 ES3FormatSet set;
144
145 // Format combinations from ES 3.0.1 spec, table 3.2
146
147 // | Internal format | Format | Type |
148 // | | | |
149 set.insert(FormatInfo(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE ));
150 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE ));
151 set.insert(FormatInfo(GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE ));
152 set.insert(FormatInfo(GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE ));
153 set.insert(FormatInfo(GL_RGBA8_SNORM, GL_RGBA, GL_BYTE ));
154 set.insert(FormatInfo(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ));
155 set.insert(FormatInfo(GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ));
156 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ));
shannonwoods@chromium.orgd03f8972013-05-30 00:17:07 +0000157 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000158 set.insert(FormatInfo(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT ));
159 set.insert(FormatInfo(GL_RGBA32F, GL_RGBA, GL_FLOAT ));
160 set.insert(FormatInfo(GL_RGBA16F, GL_RGBA, GL_FLOAT ));
161 set.insert(FormatInfo(GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE ));
162 set.insert(FormatInfo(GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE ));
163 set.insert(FormatInfo(GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT ));
164 set.insert(FormatInfo(GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT ));
165 set.insert(FormatInfo(GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT ));
166 set.insert(FormatInfo(GL_RGBA32I, GL_RGBA_INTEGER, GL_INT ));
167 set.insert(FormatInfo(GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV ));
168 set.insert(FormatInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE ));
169 set.insert(FormatInfo(GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE ));
170 set.insert(FormatInfo(GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE ));
171 set.insert(FormatInfo(GL_RGB8_SNORM, GL_RGB, GL_BYTE ));
172 set.insert(FormatInfo(GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ));
173 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV ));
174 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV ));
175 set.insert(FormatInfo(GL_RGB16F, GL_RGB, GL_HALF_FLOAT ));
176 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT ));
177 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT ));
178 set.insert(FormatInfo(GL_RGB32F, GL_RGB, GL_FLOAT ));
179 set.insert(FormatInfo(GL_RGB16F, GL_RGB, GL_FLOAT ));
180 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT ));
181 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_FLOAT ));
182 set.insert(FormatInfo(GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE ));
183 set.insert(FormatInfo(GL_RGB8I, GL_RGB_INTEGER, GL_BYTE ));
184 set.insert(FormatInfo(GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT ));
185 set.insert(FormatInfo(GL_RGB16I, GL_RGB_INTEGER, GL_SHORT ));
186 set.insert(FormatInfo(GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT ));
187 set.insert(FormatInfo(GL_RGB32I, GL_RGB_INTEGER, GL_INT ));
188 set.insert(FormatInfo(GL_RG8, GL_RG, GL_UNSIGNED_BYTE ));
189 set.insert(FormatInfo(GL_RG8_SNORM, GL_RG, GL_BYTE ));
190 set.insert(FormatInfo(GL_RG16F, GL_RG, GL_HALF_FLOAT ));
191 set.insert(FormatInfo(GL_RG32F, GL_RG, GL_FLOAT ));
192 set.insert(FormatInfo(GL_RG16F, GL_RG, GL_FLOAT ));
193 set.insert(FormatInfo(GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE ));
194 set.insert(FormatInfo(GL_RG8I, GL_RG_INTEGER, GL_BYTE ));
195 set.insert(FormatInfo(GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT ));
196 set.insert(FormatInfo(GL_RG16I, GL_RG_INTEGER, GL_SHORT ));
197 set.insert(FormatInfo(GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT ));
198 set.insert(FormatInfo(GL_RG32I, GL_RG_INTEGER, GL_INT ));
199 set.insert(FormatInfo(GL_R8, GL_RED, GL_UNSIGNED_BYTE ));
200 set.insert(FormatInfo(GL_R8_SNORM, GL_RED, GL_BYTE ));
201 set.insert(FormatInfo(GL_R16F, GL_RED, GL_HALF_FLOAT ));
202 set.insert(FormatInfo(GL_R32F, GL_RED, GL_FLOAT ));
203 set.insert(FormatInfo(GL_R16F, GL_RED, GL_FLOAT ));
204 set.insert(FormatInfo(GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE ));
205 set.insert(FormatInfo(GL_R8I, GL_RED_INTEGER, GL_BYTE ));
206 set.insert(FormatInfo(GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT ));
207 set.insert(FormatInfo(GL_R16I, GL_RED_INTEGER, GL_SHORT ));
208 set.insert(FormatInfo(GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT ));
209 set.insert(FormatInfo(GL_R32I, GL_RED_INTEGER, GL_INT ));
210
211 // Unsized formats
212 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE ));
213 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ));
214 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ));
215 set.insert(FormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE ));
216 set.insert(FormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ));
217 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ));
218 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE ));
219 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE ));
220
221 // Depth stencil formats
222 set.insert(FormatInfo(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT ));
223 set.insert(FormatInfo(GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ));
224 set.insert(FormatInfo(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ));
225 set.insert(FormatInfo(GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT ));
226 set.insert(FormatInfo(GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 ));
227 set.insert(FormatInfo(GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV));
228
229 // From GL_OES_texture_float
230 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT ));
231 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT ));
232 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_FLOAT ));
233
234 // From GL_OES_texture_half_float
235 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ));
236 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT ));
237 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT ));
238
239 // From GL_EXT_texture_storage
240 // | Internal format | Format | Type |
241 // | | | |
242 set.insert(FormatInfo(GL_ALPHA8_EXT, GL_ALPHA, GL_UNSIGNED_BYTE ));
243 set.insert(FormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, GL_UNSIGNED_BYTE ));
244 set.insert(FormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ));
245 set.insert(FormatInfo(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT ));
246 set.insert(FormatInfo(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT ));
247 set.insert(FormatInfo(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT ));
248 set.insert(FormatInfo(GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT ));
249 set.insert(FormatInfo(GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT ));
250 set.insert(FormatInfo(GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ));
251
252 set.insert(FormatInfo(GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
253 set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT));
254 set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
255 set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT));
256 set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
257
258 // From GL_ANGLE_depth_texture
259 set.insert(FormatInfo(GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT_24_8_OES ));
260
261 // Compressed formats
262 // From ES 3.0.1 spec, table 3.16
263 // | Internal format | Format | Type |
264 // | | | |
265 set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE));
266 set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE));
267 set.insert(FormatInfo(GL_COMPRESSED_SIGNED_R11_EAC, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE));
268 set.insert(FormatInfo(GL_COMPRESSED_RG11_EAC, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE));
269 set.insert(FormatInfo(GL_COMPRESSED_SIGNED_RG11_EAC, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE));
270 set.insert(FormatInfo(GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE));
271 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE));
272 set.insert(FormatInfo(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE));
273 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE));
274 set.insert(FormatInfo(GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE));
275 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE));
276
277
278 // From GL_EXT_texture_compression_dxt1
279 set.insert(FormatInfo(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE));
280 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE));
281
282 // From GL_ANGLE_texture_compression_dxt3
283 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE));
284
285 // From GL_ANGLE_texture_compression_dxt5
286 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE));
287
288 return set;
289}
290
291static const ES3FormatSet &getES3FormatSet()
292{
293 static const ES3FormatSet es3FormatSet = buildES3FormatSet();
294 return es3FormatSet;
295}
296
297// Map of sizes of input types
298struct TypeInfo
299{
300 GLuint mTypeBytes;
301 bool mSpecialInterpretation;
302
303 TypeInfo()
304 : mTypeBytes(0), mSpecialInterpretation(false) { }
305
306 TypeInfo(GLuint typeBytes, bool specialInterpretation)
307 : mTypeBytes(typeBytes), mSpecialInterpretation(specialInterpretation) { }
308
309 bool operator<(const TypeInfo& other) const
310 {
311 return memcmp(this, &other, sizeof(TypeInfo)) < 0;
312 }
313};
314
315typedef std::pair<GLenum, TypeInfo> TypeInfoPair;
316typedef std::map<GLenum, TypeInfo> TypeInfoMap;
317
318static TypeInfoMap buildTypeInfoMap()
319{
320 TypeInfoMap map;
321
322 map.insert(TypeInfoPair(GL_UNSIGNED_BYTE, TypeInfo( 1, false)));
323 map.insert(TypeInfoPair(GL_BYTE, TypeInfo( 1, false)));
324 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT, TypeInfo( 2, false)));
325 map.insert(TypeInfoPair(GL_SHORT, TypeInfo( 2, false)));
326 map.insert(TypeInfoPair(GL_UNSIGNED_INT, TypeInfo( 4, false)));
327 map.insert(TypeInfoPair(GL_INT, TypeInfo( 4, false)));
328 map.insert(TypeInfoPair(GL_HALF_FLOAT, TypeInfo( 2, false)));
329 map.insert(TypeInfoPair(GL_FLOAT, TypeInfo( 4, false)));
330 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_6_5, TypeInfo( 2, true )));
331 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4, TypeInfo( 2, true )));
332 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_5_5_1, TypeInfo( 2, true )));
333 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, TypeInfo( 2, true )));
334 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, TypeInfo( 2, true )));
335 map.insert(TypeInfoPair(GL_UNSIGNED_INT_2_10_10_10_REV, TypeInfo( 4, true )));
336 map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8, TypeInfo( 4, true )));
337 map.insert(TypeInfoPair(GL_UNSIGNED_INT_10F_11F_11F_REV, TypeInfo( 4, true )));
338 map.insert(TypeInfoPair(GL_UNSIGNED_INT_5_9_9_9_REV, TypeInfo( 4, true )));
339 map.insert(TypeInfoPair(GL_FLOAT_32_UNSIGNED_INT_24_8_REV, TypeInfo( 4, true )));
340 map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8_OES, TypeInfo( 4, true )));
341
342 return map;
343}
344
345static bool getTypeInfo(GLenum type, TypeInfo *outTypeInfo)
346{
347 static const TypeInfoMap infoMap = buildTypeInfoMap();
348 TypeInfoMap::const_iterator iter = infoMap.find(type);
349 if (iter != infoMap.end())
350 {
351 if (outTypeInfo)
352 {
353 *outTypeInfo = iter->second;
354 }
355 return true;
356 }
357 else
358 {
359 return false;
360 }
361}
362
363// Information about internal formats
364typedef bool ((Context::*ContextSupportCheckMemberFunction)(void) const);
365typedef bool (*ContextSupportCheckFunction)(const Context *context);
366
367typedef bool ((rx::Renderer::*RendererSupportCheckMemberFunction)(void) const);
368typedef bool (*ContextRendererSupportCheckFunction)(const Context *context, const rx::Renderer *renderer);
369
370template <ContextSupportCheckMemberFunction func>
371bool CheckSupport(const Context *context)
372{
373 return (context->*func)();
374}
375
376template <ContextSupportCheckMemberFunction contextFunc, RendererSupportCheckMemberFunction rendererFunc>
377bool CheckSupport(const Context *context, const rx::Renderer *renderer)
378{
379 if (context)
380 {
381 return (context->*contextFunc)();
382 }
383 else if (renderer)
384 {
385 return (renderer->*rendererFunc)();
386 }
387 else
388 {
389 UNREACHABLE();
390 return false;
391 }
392}
393
394template <typename objectType>
395bool AlwaysSupported(const objectType*)
396{
397 return true;
398}
399
400template <typename objectTypeA, typename objectTypeB>
401bool AlwaysSupported(const objectTypeA*, const objectTypeB*)
402{
403 return true;
404}
405
406template <typename objectType>
407bool NeverSupported(const objectType*)
408{
409 return false;
410}
411
412template <typename objectTypeA, typename objectTypeB>
413bool NeverSupported(const objectTypeA *, const objectTypeB *)
414{
415 return false;
416}
417
418template <typename objectType>
419bool UnimplementedSupport(const objectType*)
420{
421 UNIMPLEMENTED();
422 return false;
423}
424
425template <typename objectTypeA, typename objectTypeB>
426bool UnimplementedSupport(const objectTypeA*, const objectTypeB*)
427{
428 UNIMPLEMENTED();
429 return false;
430}
431
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000432enum InternalFormatStorageType
433{
434 Unknown,
435 NormalizedFixedPoint,
436 FloatingPoint,
437 SignedInteger,
438 UnsignedInteger,
439 Compressed,
440};
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000441
442struct InternalFormatInfo
443{
444 GLuint mRedBits;
445 GLuint mGreenBits;
446 GLuint mBlueBits;
447
448 GLuint mLuminanceBits;
449
450 GLuint mAlphaBits;
451 GLuint mSharedBits;
452
453 GLuint mDepthBits;
454 GLuint mStencilBits;
455
456 GLuint mPixelBits;
457
458 GLuint mComponentCount;
459
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000460 GLuint mCompressedBlockWidth;
461 GLuint mCompressedBlockHeight;
462
463 GLenum mFormat;
464 GLenum mType;
465
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000466 InternalFormatStorageType mStorageType;
467
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000468 bool mIsSRGB;
469
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000470 ContextRendererSupportCheckFunction mIsColorRenderable;
471 ContextRendererSupportCheckFunction mIsDepthRenderable;
472 ContextRendererSupportCheckFunction mIsStencilRenderable;
473 ContextRendererSupportCheckFunction mIsTextureFilterable;
474
475 ContextSupportCheckFunction mSupportFunction;
476
477 InternalFormatInfo() : mRedBits(0), mGreenBits(0), mBlueBits(0), mLuminanceBits(0), mAlphaBits(0), mSharedBits(0), mDepthBits(0), mStencilBits(0),
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000478 mPixelBits(0), mComponentCount(0), mCompressedBlockWidth(0), mCompressedBlockHeight(0), mFormat(GL_NONE), mType(GL_NONE),
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000479 mStorageType(Unknown), mIsSRGB(false), mIsColorRenderable(NeverSupported), mIsDepthRenderable(NeverSupported), mIsStencilRenderable(NeverSupported),
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000480 mIsTextureFilterable(NeverSupported), mSupportFunction(NeverSupported)
481 {
482 }
483
484 static InternalFormatInfo UnsizedFormat(GLenum format, ContextSupportCheckFunction supportFunction)
485 {
486 InternalFormatInfo formatInfo;
487 formatInfo.mFormat = format;
488 formatInfo.mSupportFunction = supportFunction;
489 return formatInfo;
490 }
491
492 static InternalFormatInfo RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared,
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000493 GLenum format, GLenum type, InternalFormatStorageType storageType, bool srgb,
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000494 ContextRendererSupportCheckFunction colorRenderable,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000495 ContextRendererSupportCheckFunction textureFilterable,
496 ContextSupportCheckFunction supportFunction)
497 {
498 InternalFormatInfo formatInfo;
499 formatInfo.mRedBits = red;
500 formatInfo.mGreenBits = green;
501 formatInfo.mBlueBits = blue;
502 formatInfo.mAlphaBits = alpha;
503 formatInfo.mSharedBits = shared;
504 formatInfo.mPixelBits = red + green + blue + alpha + shared;
505 formatInfo.mComponentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
506 formatInfo.mFormat = format;
507 formatInfo.mType = type;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000508 formatInfo.mStorageType = storageType;
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000509 formatInfo.mIsSRGB = srgb;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000510 formatInfo.mIsColorRenderable = colorRenderable;
511 formatInfo.mIsTextureFilterable = textureFilterable;
512 formatInfo.mSupportFunction = supportFunction;
513 return formatInfo;
514 }
515
516 static InternalFormatInfo LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type,
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000517 InternalFormatStorageType storageType,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000518 ContextSupportCheckFunction supportFunction)
519 {
520 InternalFormatInfo formatInfo;
521 formatInfo.mLuminanceBits = luminance;
522 formatInfo.mAlphaBits = alpha;
523 formatInfo.mPixelBits = luminance + alpha;
524 formatInfo.mComponentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
525 formatInfo.mFormat = format;
526 formatInfo.mType = type;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000527 formatInfo.mStorageType = storageType;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000528 formatInfo.mIsTextureFilterable = AlwaysSupported;
529 formatInfo.mSupportFunction = supportFunction;
530 return formatInfo;
531 }
532
533 static InternalFormatInfo DepthStencilFormat(GLuint depth, GLuint stencil, GLenum format, GLenum type,
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000534 InternalFormatStorageType storageType,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000535 ContextRendererSupportCheckFunction depthRenderable,
536 ContextRendererSupportCheckFunction stencilRenderable,
537 ContextSupportCheckFunction supportFunction)
538 {
539 InternalFormatInfo formatInfo;
540 formatInfo.mDepthBits = depth;
541 formatInfo.mStencilBits = stencil;
542 formatInfo.mPixelBits = depth + stencil;
543 formatInfo.mComponentCount = ((depth > 0) ? 1 : 0) + ((stencil > 0) ? 1 : 0);
544 formatInfo.mFormat = format;
545 formatInfo.mType = type;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000546 formatInfo.mStorageType = storageType;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000547 formatInfo.mIsDepthRenderable = depthRenderable;
548 formatInfo.mIsStencilRenderable = stencilRenderable;
549 formatInfo.mSupportFunction = supportFunction;
550 return formatInfo;
551 }
552
553 static InternalFormatInfo CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight,
554 GLuint compressedBlockSize, GLuint componentCount, GLenum format, GLenum type,
555 ContextSupportCheckFunction supportFunction)
556 {
557 InternalFormatInfo formatInfo;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000558 formatInfo.mCompressedBlockWidth = compressedBlockWidth;
559 formatInfo.mCompressedBlockHeight = compressedBlockHeight;
560 formatInfo.mPixelBits = compressedBlockSize;
561 formatInfo.mComponentCount = componentCount;
562 formatInfo.mFormat = format;
563 formatInfo.mType = type;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000564 formatInfo.mStorageType = Compressed;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000565 formatInfo.mIsTextureFilterable = AlwaysSupported;
566 formatInfo.mSupportFunction = supportFunction;
567 return formatInfo;
568 }
569};
570
571typedef std::pair<GLuint, InternalFormatInfo> InternalFormatInfoPair;
572typedef std::map<GLuint, InternalFormatInfo> InternalFormatInfoMap;
573
574static InternalFormatInfoMap buildES3InternalFormatInfoMap()
575{
576 InternalFormatInfoMap map;
577
578 // From ES 3.0.1 spec, table 3.12
579 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
580
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000581 // | Internal format | | R | G | B | A |S | Format | Type | Internal format | SRGB | Color | Texture | Supported |
582 // | | | | | | | | | | type | | renderable | filterable | |
583 map.insert(InternalFormatInfoPair(GL_R8, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
584 map.insert(InternalFormatInfoPair(GL_R8_SNORM, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
585 map.insert(InternalFormatInfoPair(GL_RG8, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
586 map.insert(InternalFormatInfoPair(GL_RG8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
587 map.insert(InternalFormatInfoPair(GL_RGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
588 map.insert(InternalFormatInfoPair(GL_RGB8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
589 map.insert(InternalFormatInfoPair(GL_RGB565, InternalFormatInfo::RGBAFormat( 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_5_5_1, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
590 map.insert(InternalFormatInfoPair(GL_RGBA4, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
591 map.insert(InternalFormatInfoPair(GL_RGB5_A1, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
592 map.insert(InternalFormatInfoPair(GL_RGBA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
593 map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
594 map.insert(InternalFormatInfoPair(GL_RGB10_A2, InternalFormatInfo::RGBAFormat(10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
595 map.insert(InternalFormatInfoPair(GL_RGB10_A2UI, InternalFormatInfo::RGBAFormat(10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
596 map.insert(InternalFormatInfoPair(GL_SRGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, NormalizedFixedPoint, true, NeverSupported, AlwaysSupported, AlwaysSupported )));
597 map.insert(InternalFormatInfoPair(GL_SRGB8_ALPHA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, true, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
598 map.insert(InternalFormatInfoPair(GL_R11F_G11F_B10F, InternalFormatInfo::RGBAFormat(11, 11, 10, 0, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, FloatingPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
599 map.insert(InternalFormatInfoPair(GL_RGB9_E5, InternalFormatInfo::RGBAFormat( 9, 9, 9, 0, 5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, FloatingPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
600 map.insert(InternalFormatInfoPair(GL_R8I, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
601 map.insert(InternalFormatInfoPair(GL_R8UI, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
602 map.insert(InternalFormatInfoPair(GL_R16I, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
603 map.insert(InternalFormatInfoPair(GL_R16UI, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
604 map.insert(InternalFormatInfoPair(GL_R32I, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
605 map.insert(InternalFormatInfoPair(GL_R32UI, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
606 map.insert(InternalFormatInfoPair(GL_RG8I, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
607 map.insert(InternalFormatInfoPair(GL_RG8UI, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
608 map.insert(InternalFormatInfoPair(GL_RG16I, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
609 map.insert(InternalFormatInfoPair(GL_RG16UI, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
610 map.insert(InternalFormatInfoPair(GL_RG32I, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
611 map.insert(InternalFormatInfoPair(GL_RG32UI, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
612 map.insert(InternalFormatInfoPair(GL_RGB8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, SignedInteger, false, NeverSupported, NeverSupported, AlwaysSupported )));
613 map.insert(InternalFormatInfoPair(GL_RGB8UI, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, UnsignedInteger, false, NeverSupported, NeverSupported, AlwaysSupported )));
614 map.insert(InternalFormatInfoPair(GL_RGB16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, SignedInteger, false, NeverSupported, NeverSupported, AlwaysSupported )));
615 map.insert(InternalFormatInfoPair(GL_RGB16UI, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, UnsignedInteger, false, NeverSupported, NeverSupported, AlwaysSupported )));
616 map.insert(InternalFormatInfoPair(GL_RGB32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, SignedInteger, false, NeverSupported, NeverSupported, AlwaysSupported )));
617 map.insert(InternalFormatInfoPair(GL_RGB32UI, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, UnsignedInteger, false, NeverSupported, NeverSupported, AlwaysSupported )));
618 map.insert(InternalFormatInfoPair(GL_RGBA8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
619 map.insert(InternalFormatInfoPair(GL_RGBA8UI, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
620 map.insert(InternalFormatInfoPair(GL_RGBA16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
621 map.insert(InternalFormatInfoPair(GL_RGBA16UI, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
622 map.insert(InternalFormatInfoPair(GL_RGBA32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
623 map.insert(InternalFormatInfoPair(GL_RGBA32UI, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000624
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000625 map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
626 map.insert(InternalFormatInfoPair(GL_BGRA4_ANGLEX, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
627 map.insert(InternalFormatInfoPair(GL_BGR5_A1_ANGLEX, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000628
629 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000630 // | Internal format | | D |S | Format | Type | Internal fmt | SRGB | Color | Texture | Supported |
631 // | | | | | | | type | | renderable | filterable | |
632 map.insert(InternalFormatInfoPair(GL_R16F, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
633 map.insert(InternalFormatInfoPair(GL_RG16F, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
634 map.insert(InternalFormatInfoPair(GL_RGB16F, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
635 map.insert(InternalFormatInfoPair(GL_RGBA16F, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
636 map.insert(InternalFormatInfoPair(GL_R32F, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
637 map.insert(InternalFormatInfoPair(GL_RG32F, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
638 map.insert(InternalFormatInfoPair(GL_RGB32F, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
639 map.insert(InternalFormatInfoPair(GL_RGBA32F, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000640
641 // Depth stencil formats
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000642 // | Internal format | | D |S | Format | Type | Internal format | Color | Texture | Supported |
643 // | | | | | | | type | renderable | filterable | |
644 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NormalizedFixedPoint, AlwaysSupported, NeverSupported, AlwaysSupported)));
645 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT24, InternalFormatInfo::DepthStencilFormat(24, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NormalizedFixedPoint, AlwaysSupported, NeverSupported, AlwaysSupported)));
646 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32F,InternalFormatInfo::DepthStencilFormat(32, 0, GL_DEPTH_COMPONENT, GL_FLOAT, FloatingPoint, AlwaysSupported, NeverSupported, AlwaysSupported)));
647 map.insert(InternalFormatInfoPair(GL_DEPTH24_STENCIL8, InternalFormatInfo::DepthStencilFormat(24, 8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
648 map.insert(InternalFormatInfoPair(GL_DEPTH32F_STENCIL8, InternalFormatInfo::DepthStencilFormat(32, 8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, FloatingPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000649
650 // Luminance alpha formats
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000651 // | Internal format | | L | A | Format | Type | Internal format | Supported |
652 // | | | | | | | type | |
653 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
654 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
655 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, FloatingPoint, AlwaysSupported)));
656 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, FloatingPoint, AlwaysSupported)));
657 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, FloatingPoint, AlwaysSupported)));
658 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, FloatingPoint, AlwaysSupported)));
659 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
660 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, FloatingPoint, AlwaysSupported)));
661 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat(16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, FloatingPoint, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000662
663 // Unsized formats
664 // | Internal format | | Format | Supported |
665 // | | | | |
666 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported)));
667 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported)));
668 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported)));
669 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
670 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
671 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
672
673 // Compressed formats, From ES 3.0.1 spec, table 3.16
674 // | Internal format | |W |H | B |C | Format | Type | Supported |
675 // | | | | | S |C | | | |
676 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
677 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
678 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
679 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
680 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, UnimplementedSupport)));
681 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, UnimplementedSupport)));
682 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, UnimplementedSupport)));
683 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, UnimplementedSupport)));
684 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA8_ETC2_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
685 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
686
687 // From GL_EXT_texture_compression_dxt1
688 // | Internal format | |W |H | B |C | Format | Type | Supported |
689 // | | | | | S |C | | | |
690 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, AlwaysSupported)));
691 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, AlwaysSupported)));
692
693 // From GL_ANGLE_texture_compression_dxt3
694 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, AlwaysSupported)));
695
696 // From GL_ANGLE_texture_compression_dxt5
697 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, AlwaysSupported)));
698
699 return map;
700}
701
702static InternalFormatInfoMap buildES2InternalFormatInfoMap()
703{
704 InternalFormatInfoMap map;
705
706 // From ES 2.0.25 table 4.5
707 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
708
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000709 // | Internal format | | R | G | B | A |S | Format | Type | Internal format | SRGB | Color | Texture | Supported |
710 // | | | | | | | | | | type | | renderable | filterable | |
711 map.insert(InternalFormatInfoPair(GL_RGBA4, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
712 map.insert(InternalFormatInfoPair(GL_RGB5_A1, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
713 map.insert(InternalFormatInfoPair(GL_RGB565, InternalFormatInfo::RGBAFormat( 5, 6, 5, 0, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_6_5, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000714
715 // Extension formats
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000716 map.insert(InternalFormatInfoPair(GL_RGB8_OES, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
717 map.insert(InternalFormatInfoPair(GL_RGBA8_OES, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
718 map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
719 map.insert(InternalFormatInfoPair(GL_BGRA4_ANGLEX, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported)));
720 map.insert(InternalFormatInfoPair(GL_BGR5_A1_ANGLEX, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_5_5_5_1, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000721
722 // Floating point formats have to query the renderer for support
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000723 // | Internal format | | R | G | B | A |S | Format | Type | Internal fmt | SRGB | Color | Texture | Supported |
724 // | | | | | | | | | | type | | renderable | filterable | |
725 map.insert(InternalFormatInfoPair(GL_RGB16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT_OES, FloatingPoint, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, CheckSupport<&Context::supportsFloat16Textures>)));
726 map.insert(InternalFormatInfoPair(GL_RGB32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, CheckSupport<&Context::supportsFloat32Textures>)));
727 map.insert(InternalFormatInfoPair(GL_RGBA16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT_OES, FloatingPoint, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, CheckSupport<&Context::supportsFloat16Textures>)));
728 map.insert(InternalFormatInfoPair(GL_RGBA32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, CheckSupport<&Context::supportsFloat32Textures>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000729
730 // Depth and stencil formats
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000731 // | Internal format | | D |S | Format | Type | Internal format | Color | Texture | Supported |
732 // | | | | | | | type | renderable | filterable | |
733 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES,InternalFormatInfo::DepthStencilFormat(32, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NormalizedFixedPoint, AlwaysSupported, NeverSupported, CheckSupport<&Context::supportsDepthTextures>)));
734 map.insert(InternalFormatInfoPair(GL_DEPTH24_STENCIL8_OES, InternalFormatInfo::DepthStencilFormat(24, 8, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, CheckSupport<&Context::supportsDepthTextures>)));
735 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NormalizedFixedPoint, AlwaysSupported, NeverSupported, AlwaysSupported)));
736 map.insert(InternalFormatInfoPair(GL_STENCIL_INDEX8, InternalFormatInfo::DepthStencilFormat( 0, 8, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_BYTE, NormalizedFixedPoint, NeverSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000737
738 // Unsized formats
739 // | Internal format | | Format | Supported |
740 // | | | | |
741 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported)));
742 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported)));
743 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported)));
744 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
745 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
746 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
747 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, InternalFormatInfo::UnsizedFormat(GL_DEPTH_COMPONENT, AlwaysSupported)));
748 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL_OES, InternalFormatInfo::UnsizedFormat(GL_DEPTH_STENCIL_OES, AlwaysSupported)));
749
750 // Luminance alpha formats from GL_EXT_texture_storage
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000751 // | Internal format | | L | A | Format | Type | Internal format | Supported |
752 // | | | | | | | type | |
753 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
754 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
755 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, FloatingPoint, AlwaysSupported)));
756 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, FloatingPoint, AlwaysSupported)));
757 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, FloatingPoint, AlwaysSupported)));
758 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, FloatingPoint, AlwaysSupported)));
759 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
760 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, FloatingPoint, AlwaysSupported)));
761 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat(16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, FloatingPoint, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000762
763 // From GL_EXT_texture_compression_dxt1
764 // | Internal format | |W |H | B |C |Format | Type | Supported |
765 // | | | | | S |C | | | |
766 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, CheckSupport<&Context::supportsDXT1Textures>)));
767 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, CheckSupport<&Context::supportsDXT1Textures>)));
768
769 // From GL_ANGLE_texture_compression_dxt3
770 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, CheckSupport<&Context::supportsDXT3Textures>)));
771
772 // From GL_ANGLE_texture_compression_dxt5
773 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, CheckSupport<&Context::supportsDXT5Textures>)));
774
775 return map;
776}
777
778static bool getInternalFormatInfo(GLint internalFormat, GLuint clientVersion, InternalFormatInfo *outFormatInfo)
779{
780 const InternalFormatInfoMap* map = NULL;
781
782 if (clientVersion == 2)
783 {
784 static const InternalFormatInfoMap formatMap = buildES2InternalFormatInfoMap();
785 map = &formatMap;
786 }
787 else if (clientVersion == 3)
788 {
789 static const InternalFormatInfoMap formatMap = buildES3InternalFormatInfoMap();
790 map = &formatMap;
791 }
792 else
793 {
794 UNREACHABLE();
795 }
796
797 InternalFormatInfoMap::const_iterator iter = map->find(internalFormat);
798 if (iter != map->end())
799 {
800 if (outFormatInfo)
801 {
802 *outFormatInfo = iter->second;
803 }
804 return true;
805 }
806 else
807 {
808 return false;
809 }
810}
811
812typedef std::set<GLenum> FormatSet;
813
814static FormatSet buildES2ValidFormatSet()
815{
816 static const FormatMap &formatMap = getES2FormatMap();
817
818 FormatSet set;
819
820 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
821 {
822 const FormatTypePair& formatPair = i->first;
823 set.insert(formatPair.first);
824 }
825
826 return set;
827}
828
829static FormatSet buildES3ValidFormatSet()
830{
831 static const ES3FormatSet &formatSet = getES3FormatSet();
832
833 FormatSet set;
834
835 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
836 {
837 const FormatInfo& formatInfo = *i;
838 set.insert(formatInfo.mFormat);
839 }
840
841 return set;
842}
843
844typedef std::set<GLenum> TypeSet;
845
846static TypeSet buildES2ValidTypeSet()
847{
848 static const FormatMap &formatMap = getES2FormatMap();
849
850 TypeSet set;
851
852 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
853 {
854 const FormatTypePair& formatPair = i->first;
855 set.insert(formatPair.second);
856 }
857
858 return set;
859}
860
861static TypeSet buildES3ValidTypeSet()
862{
863 static const ES3FormatSet &formatSet = getES3FormatSet();
864
865 TypeSet set;
866
867 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
868 {
869 const FormatInfo& formatInfo = *i;
870 set.insert(formatInfo.mType);
871 }
872
873 return set;
874}
875
876struct CopyConversion
877{
878 GLenum mTextureFormat;
879 GLenum mFramebufferFormat;
880
881 CopyConversion(GLenum textureFormat, GLenum framebufferFormat)
882 : mTextureFormat(textureFormat), mFramebufferFormat(framebufferFormat) { }
883
884 bool operator<(const CopyConversion& other) const
885 {
886 return memcmp(this, &other, sizeof(CopyConversion)) < 0;
887 }
888};
889
890typedef std::set<CopyConversion> CopyConversionSet;
891
892static CopyConversionSet buildValidES3CopyTexImageCombinations()
893{
894 CopyConversionSet set;
895
896 // From ES 3.0.1 spec, table 3.15
897 set.insert(CopyConversion(GL_ALPHA, GL_RGBA));
898 set.insert(CopyConversion(GL_LUMINANCE, GL_RED));
899 set.insert(CopyConversion(GL_LUMINANCE, GL_RG));
900 set.insert(CopyConversion(GL_LUMINANCE, GL_RGB));
901 set.insert(CopyConversion(GL_LUMINANCE, GL_RGBA));
902 set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_RGBA));
903 set.insert(CopyConversion(GL_RED, GL_RED));
904 set.insert(CopyConversion(GL_RED, GL_RG));
905 set.insert(CopyConversion(GL_RED, GL_RGB));
906 set.insert(CopyConversion(GL_RED, GL_RGBA));
907 set.insert(CopyConversion(GL_RG, GL_RG));
908 set.insert(CopyConversion(GL_RG, GL_RGB));
909 set.insert(CopyConversion(GL_RG, GL_RGBA));
910 set.insert(CopyConversion(GL_RGB, GL_RGB));
911 set.insert(CopyConversion(GL_RGB, GL_RGBA));
912 set.insert(CopyConversion(GL_RGBA, GL_RGBA));
913
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +0000914 set.insert(CopyConversion(GL_RED_INTEGER, GL_RED_INTEGER));
915 set.insert(CopyConversion(GL_RED_INTEGER, GL_RG_INTEGER));
916 set.insert(CopyConversion(GL_RED_INTEGER, GL_RGB_INTEGER));
917 set.insert(CopyConversion(GL_RED_INTEGER, GL_RGBA_INTEGER));
918 set.insert(CopyConversion(GL_RG_INTEGER, GL_RG_INTEGER));
919 set.insert(CopyConversion(GL_RG_INTEGER, GL_RGB_INTEGER));
920 set.insert(CopyConversion(GL_RG_INTEGER, GL_RGBA_INTEGER));
921 set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGB_INTEGER));
922 set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGBA_INTEGER));
923 set.insert(CopyConversion(GL_RGBA_INTEGER, GL_RGBA_INTEGER));
924
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000925 return set;
926}
927
928bool IsValidInternalFormat(GLint internalFormat, const Context *context)
929{
930 if (!context)
931 {
932 return false;
933 }
934
935 InternalFormatInfo internalFormatInfo;
936 if (getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
937 {
938 ASSERT(internalFormatInfo.mSupportFunction != NULL);
939 return internalFormatInfo.mSupportFunction(context);
940 }
941 else
942 {
943 return false;
944 }
945}
946
947bool IsValidFormat(GLenum format, GLuint clientVersion)
948{
949 if (clientVersion == 2)
950 {
951 static const FormatSet formatSet = buildES2ValidFormatSet();
952 return formatSet.find(format) != formatSet.end();
953 }
954 else if (clientVersion == 3)
955 {
956 static const FormatSet formatSet = buildES3ValidFormatSet();
957 return formatSet.find(format) != formatSet.end();
958 }
959 else
960 {
961 UNREACHABLE();
962 return false;
963 }
964}
965
966bool IsValidType(GLenum type, GLuint clientVersion)
967{
968 if (clientVersion == 2)
969 {
970 static const TypeSet typeSet = buildES2ValidTypeSet();
971 return typeSet.find(type) != typeSet.end();
972 }
973 else if (clientVersion == 3)
974 {
975 static const TypeSet typeSet = buildES3ValidTypeSet();
976 return typeSet.find(type) != typeSet.end();
977 }
978 else
979 {
980 UNREACHABLE();
981 return false;
982 }
983}
984
985bool IsValidFormatCombination(GLint internalFormat, GLenum format, GLenum type, GLuint clientVersion)
986{
987 if (clientVersion == 2)
988 {
989 static const FormatMap &formats = getES2FormatMap();
990 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
991
992 return (iter != formats.end()) && ((internalFormat == (GLint)type) || (internalFormat == iter->second));
993 }
994 else if (clientVersion == 3)
995 {
996 static const ES3FormatSet &formats = getES3FormatSet();
997 return formats.find(FormatInfo(internalFormat, format, type)) != formats.end();
998 }
999 else
1000 {
1001 UNREACHABLE();
1002 return false;
1003 }
1004}
1005
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001006bool IsValidCopyTexImageCombination(GLenum textureInternalFormat, GLenum frameBufferInternalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001007{
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001008 InternalFormatInfo textureInternalFormatInfo;
1009 InternalFormatInfo framebufferInternalFormatInfo;
1010 if (getInternalFormatInfo(textureInternalFormat, clientVersion, &textureInternalFormatInfo) &&
1011 getInternalFormatInfo(frameBufferInternalFormat, clientVersion, &framebufferInternalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001012 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001013 if (clientVersion == 2)
1014 {
1015 UNIMPLEMENTED();
1016 return false;
1017 }
1018 else if (clientVersion == 3)
1019 {
1020 static const CopyConversionSet conversionSet = buildValidES3CopyTexImageCombinations();
1021 const CopyConversion conversion = CopyConversion(textureInternalFormatInfo.mFormat,
1022 framebufferInternalFormatInfo.mFormat);
1023 if (conversionSet.find(conversion) != conversionSet.end())
1024 {
1025 // Section 3.8.5 of the GLES3 3.0.2 spec states that source and destination formats
shannonwoods@chromium.org96c62912013-05-30 00:17:00 +00001026 // must both be signed or unsigned or fixed/floating point and both source and destinations
1027 // must be either both SRGB or both not SRGB
1028
1029 if (textureInternalFormatInfo.mIsSRGB != framebufferInternalFormatInfo.mIsSRGB)
1030 {
1031 return false;
1032 }
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001033
1034 if ((textureInternalFormatInfo.mStorageType == SignedInteger && framebufferInternalFormatInfo.mStorageType == SignedInteger ) ||
1035 (textureInternalFormatInfo.mStorageType == UnsignedInteger && framebufferInternalFormatInfo.mStorageType == UnsignedInteger))
1036 {
1037 return true;
1038 }
1039
1040 if ((textureInternalFormatInfo.mStorageType == NormalizedFixedPoint || textureInternalFormatInfo.mStorageType == FloatingPoint) &&
1041 (framebufferInternalFormatInfo.mStorageType == NormalizedFixedPoint || framebufferInternalFormatInfo.mStorageType == FloatingPoint))
1042 {
1043 return true;
1044 }
1045 }
1046
1047 return false;
1048 }
1049 else
1050 {
1051 UNREACHABLE();
1052 return false;
1053 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001054 }
1055 else
1056 {
1057 UNREACHABLE();
1058 return false;
1059 }
1060}
1061
1062bool IsSizedInternalFormat(GLint internalFormat, GLuint clientVersion)
1063{
1064 InternalFormatInfo internalFormatInfo;
1065 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1066 {
1067 return internalFormatInfo.mPixelBits > 0;
1068 }
1069 else
1070 {
1071 UNREACHABLE();
1072 return false;
1073 }
1074}
1075
1076GLint GetSizedInternalFormat(GLenum format, GLenum type, GLuint clientVersion)
1077{
1078 if (clientVersion == 2)
1079 {
1080 static const FormatMap &formats = getES2FormatMap();
1081 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1082 return (iter != formats.end()) ? iter->second : GL_NONE;
1083 }
1084 else if (clientVersion == 3)
1085 {
1086 static const FormatMap formats = buildES3FormatMap();
1087 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1088 return (iter != formats.end()) ? iter->second : GL_NONE;
1089 }
1090 else
1091 {
1092 UNREACHABLE();
1093 return GL_NONE;
1094 }
1095}
1096
1097GLuint GetPixelBytes(GLint internalFormat, GLuint clientVersion)
1098{
1099 InternalFormatInfo internalFormatInfo;
1100 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1101 {
1102 return internalFormatInfo.mPixelBits / 8;
1103 }
1104 else
1105 {
1106 UNREACHABLE();
1107 return 0;
1108 }
1109}
1110
1111GLuint GetAlphaBits(GLint internalFormat, GLuint clientVersion)
1112{
1113 InternalFormatInfo internalFormatInfo;
1114 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1115 {
1116 return internalFormatInfo.mAlphaBits;
1117 }
1118 else
1119 {
1120 UNREACHABLE();
1121 return 0;
1122 }
1123}
1124
1125GLuint GetRedBits(GLint internalFormat, GLuint clientVersion)
1126{
1127 InternalFormatInfo internalFormatInfo;
1128 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1129 {
1130 return internalFormatInfo.mRedBits;
1131 }
1132 else
1133 {
1134 UNREACHABLE();
1135 return 0;
1136 }
1137}
1138
1139GLuint GetGreenBits(GLint internalFormat, GLuint clientVersion)
1140{
1141 InternalFormatInfo internalFormatInfo;
1142 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1143 {
1144 return internalFormatInfo.mGreenBits;
1145 }
1146 else
1147 {
1148 UNREACHABLE();
1149 return 0;
1150 }
1151}
1152
1153GLuint GetBlueBits(GLint internalFormat, GLuint clientVersion)
1154{
1155 InternalFormatInfo internalFormatInfo;
1156 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1157 {
1158 return internalFormatInfo.mGreenBits;
1159 }
1160 else
1161 {
1162 UNREACHABLE();
1163 return 0;
1164 }
1165}
1166
1167GLuint GetLuminanceBits(GLint internalFormat, GLuint clientVersion)
1168{
1169 InternalFormatInfo internalFormatInfo;
1170 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1171 {
1172 return internalFormatInfo.mLuminanceBits;
1173 }
1174 else
1175 {
1176 UNREACHABLE();
1177 return 0;
1178 }
1179}
1180
1181GLuint GetDepthBits(GLint internalFormat, GLuint clientVersion)
1182{
1183 InternalFormatInfo internalFormatInfo;
1184 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1185 {
1186 return internalFormatInfo.mDepthBits;
1187 }
1188 else
1189 {
1190 UNREACHABLE();
1191 return 0;
1192 }
1193}
1194
1195GLuint GetStencilBits(GLint internalFormat, GLuint clientVersion)
1196{
1197 InternalFormatInfo internalFormatInfo;
1198 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1199 {
1200 return internalFormatInfo.mStencilBits;
1201 }
1202 else
1203 {
1204 UNREACHABLE();
1205 return 0;
1206 }
1207}
1208
1209GLenum GetFormat(GLint internalFormat, GLuint clientVersion)
1210{
1211 InternalFormatInfo internalFormatInfo;
1212 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1213 {
1214 return internalFormatInfo.mFormat;
1215 }
1216 else
1217 {
1218 UNREACHABLE();
1219 return GL_NONE;
1220 }
1221}
1222
1223GLenum GetType(GLint internalFormat, GLuint clientVersion)
1224{
1225 InternalFormatInfo internalFormatInfo;
1226 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1227 {
1228 return internalFormatInfo.mType;
1229 }
1230 else
1231 {
1232 UNREACHABLE();
1233 return GL_NONE;
1234 }
1235}
1236
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001237bool IsNormalizedFixedPointFormat(GLint internalFormat, GLuint clientVersion)
1238{
1239 InternalFormatInfo internalFormatInfo;
1240 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1241 {
1242 return internalFormatInfo.mStorageType == NormalizedFixedPoint;
1243 }
1244 else
1245 {
1246 UNREACHABLE();
1247 return false;
1248 }
1249}
1250
1251bool IsIntegerFormat(GLint internalFormat, GLuint clientVersion)
1252{
1253 InternalFormatInfo internalFormatInfo;
1254 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1255 {
1256 return internalFormatInfo.mStorageType == UnsignedInteger ||
1257 internalFormatInfo.mStorageType == SignedInteger;
1258 }
1259 else
1260 {
1261 UNREACHABLE();
1262 return false;
1263 }
1264}
1265
1266bool IsSignedIntegerFormat(GLint internalFormat, GLuint clientVersion)
1267{
1268 InternalFormatInfo internalFormatInfo;
1269 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1270 {
1271 return internalFormatInfo.mStorageType == SignedInteger;
1272 }
1273 else
1274 {
1275 UNREACHABLE();
1276 return false;
1277 }
1278}
1279
1280bool IsUnsignedIntegerFormat(GLint internalFormat, GLuint clientVersion)
1281{
1282 InternalFormatInfo internalFormatInfo;
1283 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1284 {
1285 return internalFormatInfo.mStorageType == UnsignedInteger;
1286 }
1287 else
1288 {
1289 UNREACHABLE();
1290 return false;
1291 }
1292}
1293
1294bool IsFloatingPointFormat(GLint internalFormat, GLuint clientVersion)
1295{
1296 InternalFormatInfo internalFormatInfo;
1297 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1298 {
1299 return internalFormatInfo.mStorageType == FloatingPoint;
1300 }
1301 else
1302 {
1303 UNREACHABLE();
1304 return false;
1305 }
1306}
1307
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +00001308bool IsSRGBFormat(GLint internalFormat, GLuint clientVersion)
1309{
1310 InternalFormatInfo internalFormatInfo;
1311 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1312 {
1313 return internalFormatInfo.mIsSRGB;
1314 }
1315 else
1316 {
1317 UNREACHABLE();
1318 return false;
1319 }
1320}
1321
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001322bool IsColorRenderingSupported(GLint internalFormat, const rx::Renderer *renderer)
1323{
1324 InternalFormatInfo internalFormatInfo;
1325 if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
1326 {
1327 return internalFormatInfo.mIsColorRenderable(NULL, renderer);
1328 }
1329 else
1330 {
1331 UNREACHABLE();
1332 return false;
1333 }
1334}
1335
1336bool IsColorRenderingSupported(GLint internalFormat, const Context *context)
1337{
1338 InternalFormatInfo internalFormatInfo;
1339 if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
1340 {
1341 return internalFormatInfo.mIsColorRenderable(context, NULL);
1342 }
1343 else
1344 {
1345 UNREACHABLE();
1346 return false;
1347 }
1348}
1349
1350bool IsTextureFilteringSupported(GLint internalFormat, const rx::Renderer *renderer)
1351{
1352 InternalFormatInfo internalFormatInfo;
1353 if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
1354 {
1355 return internalFormatInfo.mIsTextureFilterable(NULL, renderer);
1356 }
1357 else
1358 {
1359 UNREACHABLE();
1360 return false;
1361 }
1362}
1363
1364bool IsTextureFilteringSupported(GLint internalFormat, const Context *context)
1365{
1366 InternalFormatInfo internalFormatInfo;
1367 if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
1368 {
1369 return internalFormatInfo.mIsTextureFilterable(context, NULL);
1370 }
1371 else
1372 {
1373 UNREACHABLE();
1374 return false;
1375 }
1376}
1377
1378bool IsDepthRenderingSupported(GLint internalFormat, const rx::Renderer *renderer)
1379{
1380 InternalFormatInfo internalFormatInfo;
1381 if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
1382 {
1383 return internalFormatInfo.mIsDepthRenderable(NULL, renderer);
1384 }
1385 else
1386 {
1387 UNREACHABLE();
1388 return false;
1389 }
1390}
1391
1392bool IsDepthRenderingSupported(GLint internalFormat, const Context *context)
1393{
1394 InternalFormatInfo internalFormatInfo;
1395 if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
1396 {
1397 return internalFormatInfo.mIsDepthRenderable(context, NULL);
1398 }
1399 else
1400 {
1401 UNREACHABLE();
1402 return false;
1403 }
1404}
1405
1406bool IsStencilRenderingSupported(GLint internalFormat, const rx::Renderer *renderer)
1407{
1408 InternalFormatInfo internalFormatInfo;
1409 if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
1410 {
1411 return internalFormatInfo.mIsStencilRenderable(NULL, renderer);
1412 }
1413 else
1414 {
1415 UNREACHABLE();
1416 return false;
1417 }
1418}
1419
1420bool IsStencilRenderingSupported(GLint internalFormat, const Context *context)
1421{
1422 InternalFormatInfo internalFormatInfo;
1423 if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
1424 {
1425 return internalFormatInfo.mIsStencilRenderable(context, NULL);
1426 }
1427 else
1428 {
1429 UNREACHABLE();
1430 return false;
1431 }
1432}
1433
1434GLuint GetRowPitch(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLint alignment)
1435{
1436 ASSERT(alignment > 0 && isPow2(alignment));
1437 return (GetBlockSize(internalFormat, type, clientVersion, width, 1) + alignment - 1) & ~(alignment - 1);
1438}
1439
1440GLuint GetDepthPitch(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height, GLint alignment)
1441{
1442 return (GetBlockSize(internalFormat, type, clientVersion, width, height) + alignment - 1) & ~(alignment - 1);
1443}
1444
1445GLuint GetBlockSize(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height)
1446{
1447 InternalFormatInfo internalFormatInfo;
1448 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1449 {
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001450 if (internalFormatInfo.mStorageType == Compressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001451 {
1452 GLsizei numBlocksWide = (width + internalFormatInfo.mCompressedBlockWidth - 1) / internalFormatInfo.mCompressedBlockWidth;
1453 GLsizei numBlocksHight = (height + internalFormatInfo.mCompressedBlockHeight - 1) / internalFormatInfo.mCompressedBlockHeight;
1454
1455 return (internalFormatInfo.mPixelBits * numBlocksWide * numBlocksHight) / 8;
1456 }
1457 else
1458 {
1459 TypeInfo typeInfo;
1460 if (getTypeInfo(type, &typeInfo))
1461 {
1462 if (typeInfo.mSpecialInterpretation)
1463 {
1464 return typeInfo.mTypeBytes * width * height;
1465 }
1466 else
1467 {
1468 return internalFormatInfo.mComponentCount * typeInfo.mTypeBytes * width * height;
1469 }
1470 }
1471 else
1472 {
1473 UNREACHABLE();
1474 return 0;
1475 }
1476 }
1477 }
1478 else
1479 {
1480 UNREACHABLE();
1481 return 0;
1482 }
1483}
1484
1485bool IsFormatCompressed(GLint internalFormat, GLuint clientVersion)
1486{
1487 InternalFormatInfo internalFormatInfo;
1488 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1489 {
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001490 return internalFormatInfo.mStorageType == Compressed;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001491 }
1492 else
1493 {
1494 UNREACHABLE();
1495 return false;
1496 }
1497}
1498
1499GLuint GetCompressedBlockWidth(GLint internalFormat, GLuint clientVersion)
1500{
1501 InternalFormatInfo internalFormatInfo;
1502 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1503 {
1504 return internalFormatInfo.mCompressedBlockWidth;
1505 }
1506 else
1507 {
1508 UNREACHABLE();
1509 return 0;
1510 }
1511}
1512
1513GLuint GetCompressedBlockHeight(GLint internalFormat, GLuint clientVersion)
1514{
1515 InternalFormatInfo internalFormatInfo;
1516 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1517 {
1518 return internalFormatInfo.mCompressedBlockHeight;
1519 }
1520 else
1521 {
1522 UNREACHABLE();
1523 return 0;
1524 }
1525}
1526
1527}