blob: 6faf728ee32ecc79ad146a0b909601878c8f403d [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 ));
157 set.insert(FormatInfo(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT ));
158 set.insert(FormatInfo(GL_RGBA32F, GL_RGBA, GL_FLOAT ));
159 set.insert(FormatInfo(GL_RGBA16F, GL_RGBA, GL_FLOAT ));
160 set.insert(FormatInfo(GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE ));
161 set.insert(FormatInfo(GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE ));
162 set.insert(FormatInfo(GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT ));
163 set.insert(FormatInfo(GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT ));
164 set.insert(FormatInfo(GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT ));
165 set.insert(FormatInfo(GL_RGBA32I, GL_RGBA_INTEGER, GL_INT ));
166 set.insert(FormatInfo(GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV ));
167 set.insert(FormatInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE ));
168 set.insert(FormatInfo(GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE ));
169 set.insert(FormatInfo(GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE ));
170 set.insert(FormatInfo(GL_RGB8_SNORM, GL_RGB, GL_BYTE ));
171 set.insert(FormatInfo(GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ));
172 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV ));
173 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV ));
174 set.insert(FormatInfo(GL_RGB16F, GL_RGB, GL_HALF_FLOAT ));
175 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT ));
176 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT ));
177 set.insert(FormatInfo(GL_RGB32F, GL_RGB, GL_FLOAT ));
178 set.insert(FormatInfo(GL_RGB16F, GL_RGB, GL_FLOAT ));
179 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT ));
180 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_FLOAT ));
181 set.insert(FormatInfo(GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE ));
182 set.insert(FormatInfo(GL_RGB8I, GL_RGB_INTEGER, GL_BYTE ));
183 set.insert(FormatInfo(GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT ));
184 set.insert(FormatInfo(GL_RGB16I, GL_RGB_INTEGER, GL_SHORT ));
185 set.insert(FormatInfo(GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT ));
186 set.insert(FormatInfo(GL_RGB32I, GL_RGB_INTEGER, GL_INT ));
187 set.insert(FormatInfo(GL_RG8, GL_RG, GL_UNSIGNED_BYTE ));
188 set.insert(FormatInfo(GL_RG8_SNORM, GL_RG, GL_BYTE ));
189 set.insert(FormatInfo(GL_RG16F, GL_RG, GL_HALF_FLOAT ));
190 set.insert(FormatInfo(GL_RG32F, GL_RG, GL_FLOAT ));
191 set.insert(FormatInfo(GL_RG16F, GL_RG, GL_FLOAT ));
192 set.insert(FormatInfo(GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE ));
193 set.insert(FormatInfo(GL_RG8I, GL_RG_INTEGER, GL_BYTE ));
194 set.insert(FormatInfo(GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT ));
195 set.insert(FormatInfo(GL_RG16I, GL_RG_INTEGER, GL_SHORT ));
196 set.insert(FormatInfo(GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT ));
197 set.insert(FormatInfo(GL_RG32I, GL_RG_INTEGER, GL_INT ));
198 set.insert(FormatInfo(GL_R8, GL_RED, GL_UNSIGNED_BYTE ));
199 set.insert(FormatInfo(GL_R8_SNORM, GL_RED, GL_BYTE ));
200 set.insert(FormatInfo(GL_R16F, GL_RED, GL_HALF_FLOAT ));
201 set.insert(FormatInfo(GL_R32F, GL_RED, GL_FLOAT ));
202 set.insert(FormatInfo(GL_R16F, GL_RED, GL_FLOAT ));
203 set.insert(FormatInfo(GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE ));
204 set.insert(FormatInfo(GL_R8I, GL_RED_INTEGER, GL_BYTE ));
205 set.insert(FormatInfo(GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT ));
206 set.insert(FormatInfo(GL_R16I, GL_RED_INTEGER, GL_SHORT ));
207 set.insert(FormatInfo(GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT ));
208 set.insert(FormatInfo(GL_R32I, GL_RED_INTEGER, GL_INT ));
209
210 // Unsized formats
211 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE ));
212 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ));
213 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ));
214 set.insert(FormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE ));
215 set.insert(FormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ));
216 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ));
217 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE ));
218 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE ));
219
220 // Depth stencil formats
221 set.insert(FormatInfo(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT ));
222 set.insert(FormatInfo(GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ));
223 set.insert(FormatInfo(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ));
224 set.insert(FormatInfo(GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT ));
225 set.insert(FormatInfo(GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 ));
226 set.insert(FormatInfo(GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV));
227
228 // From GL_OES_texture_float
229 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT ));
230 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT ));
231 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_FLOAT ));
232
233 // From GL_OES_texture_half_float
234 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ));
235 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT ));
236 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT ));
237
238 // From GL_EXT_texture_storage
239 // | Internal format | Format | Type |
240 // | | | |
241 set.insert(FormatInfo(GL_ALPHA8_EXT, GL_ALPHA, GL_UNSIGNED_BYTE ));
242 set.insert(FormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, GL_UNSIGNED_BYTE ));
243 set.insert(FormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ));
244 set.insert(FormatInfo(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT ));
245 set.insert(FormatInfo(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT ));
246 set.insert(FormatInfo(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT ));
247 set.insert(FormatInfo(GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT ));
248 set.insert(FormatInfo(GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT ));
249 set.insert(FormatInfo(GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ));
250
251 set.insert(FormatInfo(GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
252 set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT));
253 set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
254 set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT));
255 set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
256
257 // From GL_ANGLE_depth_texture
258 set.insert(FormatInfo(GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT_24_8_OES ));
259
260 // Compressed formats
261 // From ES 3.0.1 spec, table 3.16
262 // | Internal format | Format | Type |
263 // | | | |
264 set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE));
265 set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE));
266 set.insert(FormatInfo(GL_COMPRESSED_SIGNED_R11_EAC, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE));
267 set.insert(FormatInfo(GL_COMPRESSED_RG11_EAC, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE));
268 set.insert(FormatInfo(GL_COMPRESSED_SIGNED_RG11_EAC, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE));
269 set.insert(FormatInfo(GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE));
270 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE));
271 set.insert(FormatInfo(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE));
272 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE));
273 set.insert(FormatInfo(GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE));
274 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE));
275
276
277 // From GL_EXT_texture_compression_dxt1
278 set.insert(FormatInfo(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE));
279 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE));
280
281 // From GL_ANGLE_texture_compression_dxt3
282 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE));
283
284 // From GL_ANGLE_texture_compression_dxt5
285 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE));
286
287 return set;
288}
289
290static const ES3FormatSet &getES3FormatSet()
291{
292 static const ES3FormatSet es3FormatSet = buildES3FormatSet();
293 return es3FormatSet;
294}
295
296// Map of sizes of input types
297struct TypeInfo
298{
299 GLuint mTypeBytes;
300 bool mSpecialInterpretation;
301
302 TypeInfo()
303 : mTypeBytes(0), mSpecialInterpretation(false) { }
304
305 TypeInfo(GLuint typeBytes, bool specialInterpretation)
306 : mTypeBytes(typeBytes), mSpecialInterpretation(specialInterpretation) { }
307
308 bool operator<(const TypeInfo& other) const
309 {
310 return memcmp(this, &other, sizeof(TypeInfo)) < 0;
311 }
312};
313
314typedef std::pair<GLenum, TypeInfo> TypeInfoPair;
315typedef std::map<GLenum, TypeInfo> TypeInfoMap;
316
317static TypeInfoMap buildTypeInfoMap()
318{
319 TypeInfoMap map;
320
321 map.insert(TypeInfoPair(GL_UNSIGNED_BYTE, TypeInfo( 1, false)));
322 map.insert(TypeInfoPair(GL_BYTE, TypeInfo( 1, false)));
323 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT, TypeInfo( 2, false)));
324 map.insert(TypeInfoPair(GL_SHORT, TypeInfo( 2, false)));
325 map.insert(TypeInfoPair(GL_UNSIGNED_INT, TypeInfo( 4, false)));
326 map.insert(TypeInfoPair(GL_INT, TypeInfo( 4, false)));
327 map.insert(TypeInfoPair(GL_HALF_FLOAT, TypeInfo( 2, false)));
328 map.insert(TypeInfoPair(GL_FLOAT, TypeInfo( 4, false)));
329 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_6_5, TypeInfo( 2, true )));
330 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4, TypeInfo( 2, true )));
331 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_5_5_1, TypeInfo( 2, true )));
332 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, TypeInfo( 2, true )));
333 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, TypeInfo( 2, true )));
334 map.insert(TypeInfoPair(GL_UNSIGNED_INT_2_10_10_10_REV, TypeInfo( 4, true )));
335 map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8, TypeInfo( 4, true )));
336 map.insert(TypeInfoPair(GL_UNSIGNED_INT_10F_11F_11F_REV, TypeInfo( 4, true )));
337 map.insert(TypeInfoPair(GL_UNSIGNED_INT_5_9_9_9_REV, TypeInfo( 4, true )));
338 map.insert(TypeInfoPair(GL_FLOAT_32_UNSIGNED_INT_24_8_REV, TypeInfo( 4, true )));
339 map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8_OES, TypeInfo( 4, true )));
340
341 return map;
342}
343
344static bool getTypeInfo(GLenum type, TypeInfo *outTypeInfo)
345{
346 static const TypeInfoMap infoMap = buildTypeInfoMap();
347 TypeInfoMap::const_iterator iter = infoMap.find(type);
348 if (iter != infoMap.end())
349 {
350 if (outTypeInfo)
351 {
352 *outTypeInfo = iter->second;
353 }
354 return true;
355 }
356 else
357 {
358 return false;
359 }
360}
361
362// Information about internal formats
363typedef bool ((Context::*ContextSupportCheckMemberFunction)(void) const);
364typedef bool (*ContextSupportCheckFunction)(const Context *context);
365
366typedef bool ((rx::Renderer::*RendererSupportCheckMemberFunction)(void) const);
367typedef bool (*ContextRendererSupportCheckFunction)(const Context *context, const rx::Renderer *renderer);
368
369template <ContextSupportCheckMemberFunction func>
370bool CheckSupport(const Context *context)
371{
372 return (context->*func)();
373}
374
375template <ContextSupportCheckMemberFunction contextFunc, RendererSupportCheckMemberFunction rendererFunc>
376bool CheckSupport(const Context *context, const rx::Renderer *renderer)
377{
378 if (context)
379 {
380 return (context->*contextFunc)();
381 }
382 else if (renderer)
383 {
384 return (renderer->*rendererFunc)();
385 }
386 else
387 {
388 UNREACHABLE();
389 return false;
390 }
391}
392
393template <typename objectType>
394bool AlwaysSupported(const objectType*)
395{
396 return true;
397}
398
399template <typename objectTypeA, typename objectTypeB>
400bool AlwaysSupported(const objectTypeA*, const objectTypeB*)
401{
402 return true;
403}
404
405template <typename objectType>
406bool NeverSupported(const objectType*)
407{
408 return false;
409}
410
411template <typename objectTypeA, typename objectTypeB>
412bool NeverSupported(const objectTypeA *, const objectTypeB *)
413{
414 return false;
415}
416
417template <typename objectType>
418bool UnimplementedSupport(const objectType*)
419{
420 UNIMPLEMENTED();
421 return false;
422}
423
424template <typename objectTypeA, typename objectTypeB>
425bool UnimplementedSupport(const objectTypeA*, const objectTypeB*)
426{
427 UNIMPLEMENTED();
428 return false;
429}
430
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000431enum InternalFormatStorageType
432{
433 Unknown,
434 NormalizedFixedPoint,
435 FloatingPoint,
436 SignedInteger,
437 UnsignedInteger,
438 Compressed,
439};
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000440
441struct InternalFormatInfo
442{
443 GLuint mRedBits;
444 GLuint mGreenBits;
445 GLuint mBlueBits;
446
447 GLuint mLuminanceBits;
448
449 GLuint mAlphaBits;
450 GLuint mSharedBits;
451
452 GLuint mDepthBits;
453 GLuint mStencilBits;
454
455 GLuint mPixelBits;
456
457 GLuint mComponentCount;
458
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000459 GLuint mCompressedBlockWidth;
460 GLuint mCompressedBlockHeight;
461
462 GLenum mFormat;
463 GLenum mType;
464
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000465 InternalFormatStorageType mStorageType;
466
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000467 bool mIsSRGB;
468
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000469 ContextRendererSupportCheckFunction mIsColorRenderable;
470 ContextRendererSupportCheckFunction mIsDepthRenderable;
471 ContextRendererSupportCheckFunction mIsStencilRenderable;
472 ContextRendererSupportCheckFunction mIsTextureFilterable;
473
474 ContextSupportCheckFunction mSupportFunction;
475
476 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 +0000477 mPixelBits(0), mComponentCount(0), mCompressedBlockWidth(0), mCompressedBlockHeight(0), mFormat(GL_NONE), mType(GL_NONE),
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000478 mStorageType(Unknown), mIsSRGB(false), mIsColorRenderable(NeverSupported), mIsDepthRenderable(NeverSupported), mIsStencilRenderable(NeverSupported),
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000479 mIsTextureFilterable(NeverSupported), mSupportFunction(NeverSupported)
480 {
481 }
482
483 static InternalFormatInfo UnsizedFormat(GLenum format, ContextSupportCheckFunction supportFunction)
484 {
485 InternalFormatInfo formatInfo;
486 formatInfo.mFormat = format;
487 formatInfo.mSupportFunction = supportFunction;
488 return formatInfo;
489 }
490
491 static InternalFormatInfo RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared,
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000492 GLenum format, GLenum type, InternalFormatStorageType storageType, bool srgb,
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000493 ContextRendererSupportCheckFunction colorRenderable,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000494 ContextRendererSupportCheckFunction textureFilterable,
495 ContextSupportCheckFunction supportFunction)
496 {
497 InternalFormatInfo formatInfo;
498 formatInfo.mRedBits = red;
499 formatInfo.mGreenBits = green;
500 formatInfo.mBlueBits = blue;
501 formatInfo.mAlphaBits = alpha;
502 formatInfo.mSharedBits = shared;
503 formatInfo.mPixelBits = red + green + blue + alpha + shared;
504 formatInfo.mComponentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
505 formatInfo.mFormat = format;
506 formatInfo.mType = type;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000507 formatInfo.mStorageType = storageType;
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000508 formatInfo.mIsSRGB = srgb;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000509 formatInfo.mIsColorRenderable = colorRenderable;
510 formatInfo.mIsTextureFilterable = textureFilterable;
511 formatInfo.mSupportFunction = supportFunction;
512 return formatInfo;
513 }
514
515 static InternalFormatInfo LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type,
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000516 InternalFormatStorageType storageType,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000517 ContextSupportCheckFunction supportFunction)
518 {
519 InternalFormatInfo formatInfo;
520 formatInfo.mLuminanceBits = luminance;
521 formatInfo.mAlphaBits = alpha;
522 formatInfo.mPixelBits = luminance + alpha;
523 formatInfo.mComponentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
524 formatInfo.mFormat = format;
525 formatInfo.mType = type;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000526 formatInfo.mStorageType = storageType;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000527 formatInfo.mIsTextureFilterable = AlwaysSupported;
528 formatInfo.mSupportFunction = supportFunction;
529 return formatInfo;
530 }
531
532 static InternalFormatInfo DepthStencilFormat(GLuint depth, GLuint stencil, GLenum format, GLenum type,
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000533 InternalFormatStorageType storageType,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000534 ContextRendererSupportCheckFunction depthRenderable,
535 ContextRendererSupportCheckFunction stencilRenderable,
536 ContextSupportCheckFunction supportFunction)
537 {
538 InternalFormatInfo formatInfo;
539 formatInfo.mDepthBits = depth;
540 formatInfo.mStencilBits = stencil;
541 formatInfo.mPixelBits = depth + stencil;
542 formatInfo.mComponentCount = ((depth > 0) ? 1 : 0) + ((stencil > 0) ? 1 : 0);
543 formatInfo.mFormat = format;
544 formatInfo.mType = type;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000545 formatInfo.mStorageType = storageType;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000546 formatInfo.mIsDepthRenderable = depthRenderable;
547 formatInfo.mIsStencilRenderable = stencilRenderable;
548 formatInfo.mSupportFunction = supportFunction;
549 return formatInfo;
550 }
551
552 static InternalFormatInfo CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight,
553 GLuint compressedBlockSize, GLuint componentCount, GLenum format, GLenum type,
554 ContextSupportCheckFunction supportFunction)
555 {
556 InternalFormatInfo formatInfo;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000557 formatInfo.mCompressedBlockWidth = compressedBlockWidth;
558 formatInfo.mCompressedBlockHeight = compressedBlockHeight;
559 formatInfo.mPixelBits = compressedBlockSize;
560 formatInfo.mComponentCount = componentCount;
561 formatInfo.mFormat = format;
562 formatInfo.mType = type;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000563 formatInfo.mStorageType = Compressed;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000564 formatInfo.mIsTextureFilterable = AlwaysSupported;
565 formatInfo.mSupportFunction = supportFunction;
566 return formatInfo;
567 }
568};
569
570typedef std::pair<GLuint, InternalFormatInfo> InternalFormatInfoPair;
571typedef std::map<GLuint, InternalFormatInfo> InternalFormatInfoMap;
572
573static InternalFormatInfoMap buildES3InternalFormatInfoMap()
574{
575 InternalFormatInfoMap map;
576
577 // From ES 3.0.1 spec, table 3.12
578 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
579
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000580 // | Internal format | | R | G | B | A |S | Format | Type | Internal format | SRGB | Color | Texture | Supported |
581 // | | | | | | | | | | type | | renderable | filterable | |
582 map.insert(InternalFormatInfoPair(GL_R8, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
583 map.insert(InternalFormatInfoPair(GL_R8_SNORM, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
584 map.insert(InternalFormatInfoPair(GL_RG8, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
585 map.insert(InternalFormatInfoPair(GL_RG8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
586 map.insert(InternalFormatInfoPair(GL_RGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
587 map.insert(InternalFormatInfoPair(GL_RGB8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
588 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 )));
589 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 )));
590 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 )));
591 map.insert(InternalFormatInfoPair(GL_RGBA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
592 map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
593 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 )));
594 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 )));
595 map.insert(InternalFormatInfoPair(GL_SRGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, NormalizedFixedPoint, true, NeverSupported, AlwaysSupported, AlwaysSupported )));
596 map.insert(InternalFormatInfoPair(GL_SRGB8_ALPHA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, true, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
597 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 )));
598 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 )));
599 map.insert(InternalFormatInfoPair(GL_R8I, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
600 map.insert(InternalFormatInfoPair(GL_R8UI, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
601 map.insert(InternalFormatInfoPair(GL_R16I, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
602 map.insert(InternalFormatInfoPair(GL_R16UI, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
603 map.insert(InternalFormatInfoPair(GL_R32I, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
604 map.insert(InternalFormatInfoPair(GL_R32UI, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
605 map.insert(InternalFormatInfoPair(GL_RG8I, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
606 map.insert(InternalFormatInfoPair(GL_RG8UI, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
607 map.insert(InternalFormatInfoPair(GL_RG16I, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
608 map.insert(InternalFormatInfoPair(GL_RG16UI, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
609 map.insert(InternalFormatInfoPair(GL_RG32I, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
610 map.insert(InternalFormatInfoPair(GL_RG32UI, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
611 map.insert(InternalFormatInfoPair(GL_RGB8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, SignedInteger, false, NeverSupported, NeverSupported, AlwaysSupported )));
612 map.insert(InternalFormatInfoPair(GL_RGB8UI, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, UnsignedInteger, false, NeverSupported, NeverSupported, AlwaysSupported )));
613 map.insert(InternalFormatInfoPair(GL_RGB16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, SignedInteger, false, NeverSupported, NeverSupported, AlwaysSupported )));
614 map.insert(InternalFormatInfoPair(GL_RGB16UI, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, UnsignedInteger, false, NeverSupported, NeverSupported, AlwaysSupported )));
615 map.insert(InternalFormatInfoPair(GL_RGB32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, SignedInteger, false, NeverSupported, NeverSupported, AlwaysSupported )));
616 map.insert(InternalFormatInfoPair(GL_RGB32UI, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, UnsignedInteger, false, NeverSupported, NeverSupported, AlwaysSupported )));
617 map.insert(InternalFormatInfoPair(GL_RGBA8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
618 map.insert(InternalFormatInfoPair(GL_RGBA8UI, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
619 map.insert(InternalFormatInfoPair(GL_RGBA16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
620 map.insert(InternalFormatInfoPair(GL_RGBA16UI, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
621 map.insert(InternalFormatInfoPair(GL_RGBA32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
622 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 +0000623
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000624 map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
625 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 )));
626 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 +0000627
628 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000629 // | Internal format | | D |S | Format | Type | Internal fmt | SRGB | Color | Texture | Supported |
630 // | | | | | | | type | | renderable | filterable | |
631 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 )));
632 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 )));
633 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 )));
634 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 )));
635 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 )));
636 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 )));
637 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 )));
638 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 +0000639
640 // Depth stencil formats
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000641 // | Internal format | | D |S | Format | Type | Internal format | Color | Texture | Supported |
642 // | | | | | | | type | renderable | filterable | |
643 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NormalizedFixedPoint, AlwaysSupported, NeverSupported, AlwaysSupported)));
644 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT24, InternalFormatInfo::DepthStencilFormat(24, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NormalizedFixedPoint, AlwaysSupported, NeverSupported, AlwaysSupported)));
645 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32F,InternalFormatInfo::DepthStencilFormat(32, 0, GL_DEPTH_COMPONENT, GL_FLOAT, FloatingPoint, AlwaysSupported, NeverSupported, AlwaysSupported)));
646 map.insert(InternalFormatInfoPair(GL_DEPTH24_STENCIL8, InternalFormatInfo::DepthStencilFormat(24, 8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
647 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 +0000648
649 // Luminance alpha formats
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000650 // | Internal format | | L | A | Format | Type | Internal format | Supported |
651 // | | | | | | | type | |
652 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
653 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
654 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, FloatingPoint, AlwaysSupported)));
655 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, FloatingPoint, AlwaysSupported)));
656 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, FloatingPoint, AlwaysSupported)));
657 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, FloatingPoint, AlwaysSupported)));
658 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
659 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, FloatingPoint, AlwaysSupported)));
660 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 +0000661
662 // Unsized formats
663 // | Internal format | | Format | Supported |
664 // | | | | |
665 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported)));
666 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported)));
667 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported)));
668 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
669 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
670 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
671
672 // Compressed formats, From ES 3.0.1 spec, table 3.16
673 // | Internal format | |W |H | B |C | Format | Type | Supported |
674 // | | | | | S |C | | | |
675 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
676 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
677 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
678 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
679 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, UnimplementedSupport)));
680 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, UnimplementedSupport)));
681 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)));
682 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)));
683 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA8_ETC2_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
684 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)));
685
686 // From GL_EXT_texture_compression_dxt1
687 // | Internal format | |W |H | B |C | Format | Type | Supported |
688 // | | | | | S |C | | | |
689 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)));
690 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)));
691
692 // From GL_ANGLE_texture_compression_dxt3
693 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)));
694
695 // From GL_ANGLE_texture_compression_dxt5
696 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)));
697
698 return map;
699}
700
701static InternalFormatInfoMap buildES2InternalFormatInfoMap()
702{
703 InternalFormatInfoMap map;
704
705 // From ES 2.0.25 table 4.5
706 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
707
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000708 // | Internal format | | R | G | B | A |S | Format | Type | Internal format | SRGB | Color | Texture | Supported |
709 // | | | | | | | | | | type | | renderable | filterable | |
710 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)));
711 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)));
712 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 +0000713
714 // Extension formats
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000715 map.insert(InternalFormatInfoPair(GL_RGB8_OES, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
716 map.insert(InternalFormatInfoPair(GL_RGBA8_OES, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
717 map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
718 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)));
719 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 +0000720
721 // Floating point formats have to query the renderer for support
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000722 // | Internal format | | R | G | B | A |S | Format | Type | Internal fmt | SRGB | Color | Texture | Supported |
723 // | | | | | | | | | | type | | renderable | filterable | |
724 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>)));
725 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>)));
726 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>)));
727 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 +0000728
729 // Depth and stencil formats
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000730 // | Internal format | | D |S | Format | Type | Internal format | Color | Texture | Supported |
731 // | | | | | | | type | renderable | filterable | |
732 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES,InternalFormatInfo::DepthStencilFormat(32, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NormalizedFixedPoint, AlwaysSupported, NeverSupported, CheckSupport<&Context::supportsDepthTextures>)));
733 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>)));
734 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NormalizedFixedPoint, AlwaysSupported, NeverSupported, AlwaysSupported)));
735 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 +0000736
737 // Unsized formats
738 // | Internal format | | Format | Supported |
739 // | | | | |
740 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported)));
741 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported)));
742 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported)));
743 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
744 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
745 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
746 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, InternalFormatInfo::UnsizedFormat(GL_DEPTH_COMPONENT, AlwaysSupported)));
747 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL_OES, InternalFormatInfo::UnsizedFormat(GL_DEPTH_STENCIL_OES, AlwaysSupported)));
748
749 // Luminance alpha formats from GL_EXT_texture_storage
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000750 // | Internal format | | L | A | Format | Type | Internal format | Supported |
751 // | | | | | | | type | |
752 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
753 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
754 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, FloatingPoint, AlwaysSupported)));
755 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, FloatingPoint, AlwaysSupported)));
756 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, FloatingPoint, AlwaysSupported)));
757 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, FloatingPoint, AlwaysSupported)));
758 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
759 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, FloatingPoint, AlwaysSupported)));
760 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 +0000761
762 // From GL_EXT_texture_compression_dxt1
763 // | Internal format | |W |H | B |C |Format | Type | Supported |
764 // | | | | | S |C | | | |
765 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>)));
766 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>)));
767
768 // From GL_ANGLE_texture_compression_dxt3
769 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>)));
770
771 // From GL_ANGLE_texture_compression_dxt5
772 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>)));
773
774 return map;
775}
776
777static bool getInternalFormatInfo(GLint internalFormat, GLuint clientVersion, InternalFormatInfo *outFormatInfo)
778{
779 const InternalFormatInfoMap* map = NULL;
780
781 if (clientVersion == 2)
782 {
783 static const InternalFormatInfoMap formatMap = buildES2InternalFormatInfoMap();
784 map = &formatMap;
785 }
786 else if (clientVersion == 3)
787 {
788 static const InternalFormatInfoMap formatMap = buildES3InternalFormatInfoMap();
789 map = &formatMap;
790 }
791 else
792 {
793 UNREACHABLE();
794 }
795
796 InternalFormatInfoMap::const_iterator iter = map->find(internalFormat);
797 if (iter != map->end())
798 {
799 if (outFormatInfo)
800 {
801 *outFormatInfo = iter->second;
802 }
803 return true;
804 }
805 else
806 {
807 return false;
808 }
809}
810
811typedef std::set<GLenum> FormatSet;
812
813static FormatSet buildES2ValidFormatSet()
814{
815 static const FormatMap &formatMap = getES2FormatMap();
816
817 FormatSet set;
818
819 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
820 {
821 const FormatTypePair& formatPair = i->first;
822 set.insert(formatPair.first);
823 }
824
825 return set;
826}
827
828static FormatSet buildES3ValidFormatSet()
829{
830 static const ES3FormatSet &formatSet = getES3FormatSet();
831
832 FormatSet set;
833
834 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
835 {
836 const FormatInfo& formatInfo = *i;
837 set.insert(formatInfo.mFormat);
838 }
839
840 return set;
841}
842
843typedef std::set<GLenum> TypeSet;
844
845static TypeSet buildES2ValidTypeSet()
846{
847 static const FormatMap &formatMap = getES2FormatMap();
848
849 TypeSet set;
850
851 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
852 {
853 const FormatTypePair& formatPair = i->first;
854 set.insert(formatPair.second);
855 }
856
857 return set;
858}
859
860static TypeSet buildES3ValidTypeSet()
861{
862 static const ES3FormatSet &formatSet = getES3FormatSet();
863
864 TypeSet set;
865
866 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
867 {
868 const FormatInfo& formatInfo = *i;
869 set.insert(formatInfo.mType);
870 }
871
872 return set;
873}
874
875struct CopyConversion
876{
877 GLenum mTextureFormat;
878 GLenum mFramebufferFormat;
879
880 CopyConversion(GLenum textureFormat, GLenum framebufferFormat)
881 : mTextureFormat(textureFormat), mFramebufferFormat(framebufferFormat) { }
882
883 bool operator<(const CopyConversion& other) const
884 {
885 return memcmp(this, &other, sizeof(CopyConversion)) < 0;
886 }
887};
888
889typedef std::set<CopyConversion> CopyConversionSet;
890
891static CopyConversionSet buildValidES3CopyTexImageCombinations()
892{
893 CopyConversionSet set;
894
895 // From ES 3.0.1 spec, table 3.15
896 set.insert(CopyConversion(GL_ALPHA, GL_RGBA));
897 set.insert(CopyConversion(GL_LUMINANCE, GL_RED));
898 set.insert(CopyConversion(GL_LUMINANCE, GL_RG));
899 set.insert(CopyConversion(GL_LUMINANCE, GL_RGB));
900 set.insert(CopyConversion(GL_LUMINANCE, GL_RGBA));
901 set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_RGBA));
902 set.insert(CopyConversion(GL_RED, GL_RED));
903 set.insert(CopyConversion(GL_RED, GL_RG));
904 set.insert(CopyConversion(GL_RED, GL_RGB));
905 set.insert(CopyConversion(GL_RED, GL_RGBA));
906 set.insert(CopyConversion(GL_RG, GL_RG));
907 set.insert(CopyConversion(GL_RG, GL_RGB));
908 set.insert(CopyConversion(GL_RG, GL_RGBA));
909 set.insert(CopyConversion(GL_RGB, GL_RGB));
910 set.insert(CopyConversion(GL_RGB, GL_RGBA));
911 set.insert(CopyConversion(GL_RGBA, GL_RGBA));
912
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +0000913 set.insert(CopyConversion(GL_RED_INTEGER, GL_RED_INTEGER));
914 set.insert(CopyConversion(GL_RED_INTEGER, GL_RG_INTEGER));
915 set.insert(CopyConversion(GL_RED_INTEGER, GL_RGB_INTEGER));
916 set.insert(CopyConversion(GL_RED_INTEGER, GL_RGBA_INTEGER));
917 set.insert(CopyConversion(GL_RG_INTEGER, GL_RG_INTEGER));
918 set.insert(CopyConversion(GL_RG_INTEGER, GL_RGB_INTEGER));
919 set.insert(CopyConversion(GL_RG_INTEGER, GL_RGBA_INTEGER));
920 set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGB_INTEGER));
921 set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGBA_INTEGER));
922 set.insert(CopyConversion(GL_RGBA_INTEGER, GL_RGBA_INTEGER));
923
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000924 return set;
925}
926
927bool IsValidInternalFormat(GLint internalFormat, const Context *context)
928{
929 if (!context)
930 {
931 return false;
932 }
933
934 InternalFormatInfo internalFormatInfo;
935 if (getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
936 {
937 ASSERT(internalFormatInfo.mSupportFunction != NULL);
938 return internalFormatInfo.mSupportFunction(context);
939 }
940 else
941 {
942 return false;
943 }
944}
945
946bool IsValidFormat(GLenum format, GLuint clientVersion)
947{
948 if (clientVersion == 2)
949 {
950 static const FormatSet formatSet = buildES2ValidFormatSet();
951 return formatSet.find(format) != formatSet.end();
952 }
953 else if (clientVersion == 3)
954 {
955 static const FormatSet formatSet = buildES3ValidFormatSet();
956 return formatSet.find(format) != formatSet.end();
957 }
958 else
959 {
960 UNREACHABLE();
961 return false;
962 }
963}
964
965bool IsValidType(GLenum type, GLuint clientVersion)
966{
967 if (clientVersion == 2)
968 {
969 static const TypeSet typeSet = buildES2ValidTypeSet();
970 return typeSet.find(type) != typeSet.end();
971 }
972 else if (clientVersion == 3)
973 {
974 static const TypeSet typeSet = buildES3ValidTypeSet();
975 return typeSet.find(type) != typeSet.end();
976 }
977 else
978 {
979 UNREACHABLE();
980 return false;
981 }
982}
983
984bool IsValidFormatCombination(GLint internalFormat, GLenum format, GLenum type, GLuint clientVersion)
985{
986 if (clientVersion == 2)
987 {
988 static const FormatMap &formats = getES2FormatMap();
989 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
990
991 return (iter != formats.end()) && ((internalFormat == (GLint)type) || (internalFormat == iter->second));
992 }
993 else if (clientVersion == 3)
994 {
995 static const ES3FormatSet &formats = getES3FormatSet();
996 return formats.find(FormatInfo(internalFormat, format, type)) != formats.end();
997 }
998 else
999 {
1000 UNREACHABLE();
1001 return false;
1002 }
1003}
1004
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001005bool IsValidCopyTexImageCombination(GLenum textureInternalFormat, GLenum frameBufferInternalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001006{
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001007 InternalFormatInfo textureInternalFormatInfo;
1008 InternalFormatInfo framebufferInternalFormatInfo;
1009 if (getInternalFormatInfo(textureInternalFormat, clientVersion, &textureInternalFormatInfo) &&
1010 getInternalFormatInfo(frameBufferInternalFormat, clientVersion, &framebufferInternalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001011 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001012 if (clientVersion == 2)
1013 {
1014 UNIMPLEMENTED();
1015 return false;
1016 }
1017 else if (clientVersion == 3)
1018 {
1019 static const CopyConversionSet conversionSet = buildValidES3CopyTexImageCombinations();
1020 const CopyConversion conversion = CopyConversion(textureInternalFormatInfo.mFormat,
1021 framebufferInternalFormatInfo.mFormat);
1022 if (conversionSet.find(conversion) != conversionSet.end())
1023 {
1024 // 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 +00001025 // must both be signed or unsigned or fixed/floating point and both source and destinations
1026 // must be either both SRGB or both not SRGB
1027
1028 if (textureInternalFormatInfo.mIsSRGB != framebufferInternalFormatInfo.mIsSRGB)
1029 {
1030 return false;
1031 }
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001032
1033 if ((textureInternalFormatInfo.mStorageType == SignedInteger && framebufferInternalFormatInfo.mStorageType == SignedInteger ) ||
1034 (textureInternalFormatInfo.mStorageType == UnsignedInteger && framebufferInternalFormatInfo.mStorageType == UnsignedInteger))
1035 {
1036 return true;
1037 }
1038
1039 if ((textureInternalFormatInfo.mStorageType == NormalizedFixedPoint || textureInternalFormatInfo.mStorageType == FloatingPoint) &&
1040 (framebufferInternalFormatInfo.mStorageType == NormalizedFixedPoint || framebufferInternalFormatInfo.mStorageType == FloatingPoint))
1041 {
1042 return true;
1043 }
1044 }
1045
1046 return false;
1047 }
1048 else
1049 {
1050 UNREACHABLE();
1051 return false;
1052 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001053 }
1054 else
1055 {
1056 UNREACHABLE();
1057 return false;
1058 }
1059}
1060
1061bool IsSizedInternalFormat(GLint internalFormat, GLuint clientVersion)
1062{
1063 InternalFormatInfo internalFormatInfo;
1064 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1065 {
1066 return internalFormatInfo.mPixelBits > 0;
1067 }
1068 else
1069 {
1070 UNREACHABLE();
1071 return false;
1072 }
1073}
1074
1075GLint GetSizedInternalFormat(GLenum format, GLenum type, GLuint clientVersion)
1076{
1077 if (clientVersion == 2)
1078 {
1079 static const FormatMap &formats = getES2FormatMap();
1080 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1081 return (iter != formats.end()) ? iter->second : GL_NONE;
1082 }
1083 else if (clientVersion == 3)
1084 {
1085 static const FormatMap formats = buildES3FormatMap();
1086 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1087 return (iter != formats.end()) ? iter->second : GL_NONE;
1088 }
1089 else
1090 {
1091 UNREACHABLE();
1092 return GL_NONE;
1093 }
1094}
1095
1096GLuint GetPixelBytes(GLint internalFormat, GLuint clientVersion)
1097{
1098 InternalFormatInfo internalFormatInfo;
1099 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1100 {
1101 return internalFormatInfo.mPixelBits / 8;
1102 }
1103 else
1104 {
1105 UNREACHABLE();
1106 return 0;
1107 }
1108}
1109
1110GLuint GetAlphaBits(GLint internalFormat, GLuint clientVersion)
1111{
1112 InternalFormatInfo internalFormatInfo;
1113 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1114 {
1115 return internalFormatInfo.mAlphaBits;
1116 }
1117 else
1118 {
1119 UNREACHABLE();
1120 return 0;
1121 }
1122}
1123
1124GLuint GetRedBits(GLint internalFormat, GLuint clientVersion)
1125{
1126 InternalFormatInfo internalFormatInfo;
1127 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1128 {
1129 return internalFormatInfo.mRedBits;
1130 }
1131 else
1132 {
1133 UNREACHABLE();
1134 return 0;
1135 }
1136}
1137
1138GLuint GetGreenBits(GLint internalFormat, GLuint clientVersion)
1139{
1140 InternalFormatInfo internalFormatInfo;
1141 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1142 {
1143 return internalFormatInfo.mGreenBits;
1144 }
1145 else
1146 {
1147 UNREACHABLE();
1148 return 0;
1149 }
1150}
1151
1152GLuint GetBlueBits(GLint internalFormat, GLuint clientVersion)
1153{
1154 InternalFormatInfo internalFormatInfo;
1155 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1156 {
1157 return internalFormatInfo.mGreenBits;
1158 }
1159 else
1160 {
1161 UNREACHABLE();
1162 return 0;
1163 }
1164}
1165
1166GLuint GetLuminanceBits(GLint internalFormat, GLuint clientVersion)
1167{
1168 InternalFormatInfo internalFormatInfo;
1169 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1170 {
1171 return internalFormatInfo.mLuminanceBits;
1172 }
1173 else
1174 {
1175 UNREACHABLE();
1176 return 0;
1177 }
1178}
1179
1180GLuint GetDepthBits(GLint internalFormat, GLuint clientVersion)
1181{
1182 InternalFormatInfo internalFormatInfo;
1183 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1184 {
1185 return internalFormatInfo.mDepthBits;
1186 }
1187 else
1188 {
1189 UNREACHABLE();
1190 return 0;
1191 }
1192}
1193
1194GLuint GetStencilBits(GLint internalFormat, GLuint clientVersion)
1195{
1196 InternalFormatInfo internalFormatInfo;
1197 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1198 {
1199 return internalFormatInfo.mStencilBits;
1200 }
1201 else
1202 {
1203 UNREACHABLE();
1204 return 0;
1205 }
1206}
1207
1208GLenum GetFormat(GLint internalFormat, GLuint clientVersion)
1209{
1210 InternalFormatInfo internalFormatInfo;
1211 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1212 {
1213 return internalFormatInfo.mFormat;
1214 }
1215 else
1216 {
1217 UNREACHABLE();
1218 return GL_NONE;
1219 }
1220}
1221
1222GLenum GetType(GLint internalFormat, GLuint clientVersion)
1223{
1224 InternalFormatInfo internalFormatInfo;
1225 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1226 {
1227 return internalFormatInfo.mType;
1228 }
1229 else
1230 {
1231 UNREACHABLE();
1232 return GL_NONE;
1233 }
1234}
1235
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001236bool IsNormalizedFixedPointFormat(GLint internalFormat, GLuint clientVersion)
1237{
1238 InternalFormatInfo internalFormatInfo;
1239 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1240 {
1241 return internalFormatInfo.mStorageType == NormalizedFixedPoint;
1242 }
1243 else
1244 {
1245 UNREACHABLE();
1246 return false;
1247 }
1248}
1249
1250bool IsIntegerFormat(GLint internalFormat, GLuint clientVersion)
1251{
1252 InternalFormatInfo internalFormatInfo;
1253 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1254 {
1255 return internalFormatInfo.mStorageType == UnsignedInteger ||
1256 internalFormatInfo.mStorageType == SignedInteger;
1257 }
1258 else
1259 {
1260 UNREACHABLE();
1261 return false;
1262 }
1263}
1264
1265bool IsSignedIntegerFormat(GLint internalFormat, GLuint clientVersion)
1266{
1267 InternalFormatInfo internalFormatInfo;
1268 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1269 {
1270 return internalFormatInfo.mStorageType == SignedInteger;
1271 }
1272 else
1273 {
1274 UNREACHABLE();
1275 return false;
1276 }
1277}
1278
1279bool IsUnsignedIntegerFormat(GLint internalFormat, GLuint clientVersion)
1280{
1281 InternalFormatInfo internalFormatInfo;
1282 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1283 {
1284 return internalFormatInfo.mStorageType == UnsignedInteger;
1285 }
1286 else
1287 {
1288 UNREACHABLE();
1289 return false;
1290 }
1291}
1292
1293bool IsFloatingPointFormat(GLint internalFormat, GLuint clientVersion)
1294{
1295 InternalFormatInfo internalFormatInfo;
1296 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1297 {
1298 return internalFormatInfo.mStorageType == FloatingPoint;
1299 }
1300 else
1301 {
1302 UNREACHABLE();
1303 return false;
1304 }
1305}
1306
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +00001307bool IsSRGBFormat(GLint internalFormat, GLuint clientVersion)
1308{
1309 InternalFormatInfo internalFormatInfo;
1310 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1311 {
1312 return internalFormatInfo.mIsSRGB;
1313 }
1314 else
1315 {
1316 UNREACHABLE();
1317 return false;
1318 }
1319}
1320
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001321bool IsColorRenderingSupported(GLint internalFormat, const rx::Renderer *renderer)
1322{
1323 InternalFormatInfo internalFormatInfo;
1324 if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
1325 {
1326 return internalFormatInfo.mIsColorRenderable(NULL, renderer);
1327 }
1328 else
1329 {
1330 UNREACHABLE();
1331 return false;
1332 }
1333}
1334
1335bool IsColorRenderingSupported(GLint internalFormat, const Context *context)
1336{
1337 InternalFormatInfo internalFormatInfo;
1338 if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
1339 {
1340 return internalFormatInfo.mIsColorRenderable(context, NULL);
1341 }
1342 else
1343 {
1344 UNREACHABLE();
1345 return false;
1346 }
1347}
1348
1349bool IsTextureFilteringSupported(GLint internalFormat, const rx::Renderer *renderer)
1350{
1351 InternalFormatInfo internalFormatInfo;
1352 if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
1353 {
1354 return internalFormatInfo.mIsTextureFilterable(NULL, renderer);
1355 }
1356 else
1357 {
1358 UNREACHABLE();
1359 return false;
1360 }
1361}
1362
1363bool IsTextureFilteringSupported(GLint internalFormat, const Context *context)
1364{
1365 InternalFormatInfo internalFormatInfo;
1366 if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
1367 {
1368 return internalFormatInfo.mIsTextureFilterable(context, NULL);
1369 }
1370 else
1371 {
1372 UNREACHABLE();
1373 return false;
1374 }
1375}
1376
1377bool IsDepthRenderingSupported(GLint internalFormat, const rx::Renderer *renderer)
1378{
1379 InternalFormatInfo internalFormatInfo;
1380 if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
1381 {
1382 return internalFormatInfo.mIsDepthRenderable(NULL, renderer);
1383 }
1384 else
1385 {
1386 UNREACHABLE();
1387 return false;
1388 }
1389}
1390
1391bool IsDepthRenderingSupported(GLint internalFormat, const Context *context)
1392{
1393 InternalFormatInfo internalFormatInfo;
1394 if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
1395 {
1396 return internalFormatInfo.mIsDepthRenderable(context, NULL);
1397 }
1398 else
1399 {
1400 UNREACHABLE();
1401 return false;
1402 }
1403}
1404
1405bool IsStencilRenderingSupported(GLint internalFormat, const rx::Renderer *renderer)
1406{
1407 InternalFormatInfo internalFormatInfo;
1408 if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
1409 {
1410 return internalFormatInfo.mIsStencilRenderable(NULL, renderer);
1411 }
1412 else
1413 {
1414 UNREACHABLE();
1415 return false;
1416 }
1417}
1418
1419bool IsStencilRenderingSupported(GLint internalFormat, const Context *context)
1420{
1421 InternalFormatInfo internalFormatInfo;
1422 if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
1423 {
1424 return internalFormatInfo.mIsStencilRenderable(context, NULL);
1425 }
1426 else
1427 {
1428 UNREACHABLE();
1429 return false;
1430 }
1431}
1432
1433GLuint GetRowPitch(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLint alignment)
1434{
1435 ASSERT(alignment > 0 && isPow2(alignment));
1436 return (GetBlockSize(internalFormat, type, clientVersion, width, 1) + alignment - 1) & ~(alignment - 1);
1437}
1438
1439GLuint GetDepthPitch(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height, GLint alignment)
1440{
1441 return (GetBlockSize(internalFormat, type, clientVersion, width, height) + alignment - 1) & ~(alignment - 1);
1442}
1443
1444GLuint GetBlockSize(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height)
1445{
1446 InternalFormatInfo internalFormatInfo;
1447 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1448 {
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001449 if (internalFormatInfo.mStorageType == Compressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001450 {
1451 GLsizei numBlocksWide = (width + internalFormatInfo.mCompressedBlockWidth - 1) / internalFormatInfo.mCompressedBlockWidth;
1452 GLsizei numBlocksHight = (height + internalFormatInfo.mCompressedBlockHeight - 1) / internalFormatInfo.mCompressedBlockHeight;
1453
1454 return (internalFormatInfo.mPixelBits * numBlocksWide * numBlocksHight) / 8;
1455 }
1456 else
1457 {
1458 TypeInfo typeInfo;
1459 if (getTypeInfo(type, &typeInfo))
1460 {
1461 if (typeInfo.mSpecialInterpretation)
1462 {
1463 return typeInfo.mTypeBytes * width * height;
1464 }
1465 else
1466 {
1467 return internalFormatInfo.mComponentCount * typeInfo.mTypeBytes * width * height;
1468 }
1469 }
1470 else
1471 {
1472 UNREACHABLE();
1473 return 0;
1474 }
1475 }
1476 }
1477 else
1478 {
1479 UNREACHABLE();
1480 return 0;
1481 }
1482}
1483
1484bool IsFormatCompressed(GLint internalFormat, GLuint clientVersion)
1485{
1486 InternalFormatInfo internalFormatInfo;
1487 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1488 {
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001489 return internalFormatInfo.mStorageType == Compressed;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001490 }
1491 else
1492 {
1493 UNREACHABLE();
1494 return false;
1495 }
1496}
1497
1498GLuint GetCompressedBlockWidth(GLint internalFormat, GLuint clientVersion)
1499{
1500 InternalFormatInfo internalFormatInfo;
1501 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1502 {
1503 return internalFormatInfo.mCompressedBlockWidth;
1504 }
1505 else
1506 {
1507 UNREACHABLE();
1508 return 0;
1509 }
1510}
1511
1512GLuint GetCompressedBlockHeight(GLint internalFormat, GLuint clientVersion)
1513{
1514 InternalFormatInfo internalFormatInfo;
1515 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1516 {
1517 return internalFormatInfo.mCompressedBlockHeight;
1518 }
1519 else
1520 {
1521 UNREACHABLE();
1522 return 0;
1523 }
1524}
1525
1526}