blob: 75529986d1d5f55e71ec1d182e6e7139818ed15a [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
1025 // must both be signed or unsigned or fixed/floating point
1026
1027 if ((textureInternalFormatInfo.mStorageType == SignedInteger && framebufferInternalFormatInfo.mStorageType == SignedInteger ) ||
1028 (textureInternalFormatInfo.mStorageType == UnsignedInteger && framebufferInternalFormatInfo.mStorageType == UnsignedInteger))
1029 {
1030 return true;
1031 }
1032
1033 if ((textureInternalFormatInfo.mStorageType == NormalizedFixedPoint || textureInternalFormatInfo.mStorageType == FloatingPoint) &&
1034 (framebufferInternalFormatInfo.mStorageType == NormalizedFixedPoint || framebufferInternalFormatInfo.mStorageType == FloatingPoint))
1035 {
1036 return true;
1037 }
1038 }
1039
1040 return false;
1041 }
1042 else
1043 {
1044 UNREACHABLE();
1045 return false;
1046 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001047 }
1048 else
1049 {
1050 UNREACHABLE();
1051 return false;
1052 }
1053}
1054
1055bool IsSizedInternalFormat(GLint internalFormat, GLuint clientVersion)
1056{
1057 InternalFormatInfo internalFormatInfo;
1058 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1059 {
1060 return internalFormatInfo.mPixelBits > 0;
1061 }
1062 else
1063 {
1064 UNREACHABLE();
1065 return false;
1066 }
1067}
1068
1069GLint GetSizedInternalFormat(GLenum format, GLenum type, GLuint clientVersion)
1070{
1071 if (clientVersion == 2)
1072 {
1073 static const FormatMap &formats = getES2FormatMap();
1074 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1075 return (iter != formats.end()) ? iter->second : GL_NONE;
1076 }
1077 else if (clientVersion == 3)
1078 {
1079 static const FormatMap formats = buildES3FormatMap();
1080 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1081 return (iter != formats.end()) ? iter->second : GL_NONE;
1082 }
1083 else
1084 {
1085 UNREACHABLE();
1086 return GL_NONE;
1087 }
1088}
1089
1090GLuint GetPixelBytes(GLint internalFormat, GLuint clientVersion)
1091{
1092 InternalFormatInfo internalFormatInfo;
1093 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1094 {
1095 return internalFormatInfo.mPixelBits / 8;
1096 }
1097 else
1098 {
1099 UNREACHABLE();
1100 return 0;
1101 }
1102}
1103
1104GLuint GetAlphaBits(GLint internalFormat, GLuint clientVersion)
1105{
1106 InternalFormatInfo internalFormatInfo;
1107 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1108 {
1109 return internalFormatInfo.mAlphaBits;
1110 }
1111 else
1112 {
1113 UNREACHABLE();
1114 return 0;
1115 }
1116}
1117
1118GLuint GetRedBits(GLint internalFormat, GLuint clientVersion)
1119{
1120 InternalFormatInfo internalFormatInfo;
1121 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1122 {
1123 return internalFormatInfo.mRedBits;
1124 }
1125 else
1126 {
1127 UNREACHABLE();
1128 return 0;
1129 }
1130}
1131
1132GLuint GetGreenBits(GLint internalFormat, GLuint clientVersion)
1133{
1134 InternalFormatInfo internalFormatInfo;
1135 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1136 {
1137 return internalFormatInfo.mGreenBits;
1138 }
1139 else
1140 {
1141 UNREACHABLE();
1142 return 0;
1143 }
1144}
1145
1146GLuint GetBlueBits(GLint internalFormat, GLuint clientVersion)
1147{
1148 InternalFormatInfo internalFormatInfo;
1149 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1150 {
1151 return internalFormatInfo.mGreenBits;
1152 }
1153 else
1154 {
1155 UNREACHABLE();
1156 return 0;
1157 }
1158}
1159
1160GLuint GetLuminanceBits(GLint internalFormat, GLuint clientVersion)
1161{
1162 InternalFormatInfo internalFormatInfo;
1163 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1164 {
1165 return internalFormatInfo.mLuminanceBits;
1166 }
1167 else
1168 {
1169 UNREACHABLE();
1170 return 0;
1171 }
1172}
1173
1174GLuint GetDepthBits(GLint internalFormat, GLuint clientVersion)
1175{
1176 InternalFormatInfo internalFormatInfo;
1177 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1178 {
1179 return internalFormatInfo.mDepthBits;
1180 }
1181 else
1182 {
1183 UNREACHABLE();
1184 return 0;
1185 }
1186}
1187
1188GLuint GetStencilBits(GLint internalFormat, GLuint clientVersion)
1189{
1190 InternalFormatInfo internalFormatInfo;
1191 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1192 {
1193 return internalFormatInfo.mStencilBits;
1194 }
1195 else
1196 {
1197 UNREACHABLE();
1198 return 0;
1199 }
1200}
1201
1202GLenum GetFormat(GLint internalFormat, GLuint clientVersion)
1203{
1204 InternalFormatInfo internalFormatInfo;
1205 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1206 {
1207 return internalFormatInfo.mFormat;
1208 }
1209 else
1210 {
1211 UNREACHABLE();
1212 return GL_NONE;
1213 }
1214}
1215
1216GLenum GetType(GLint internalFormat, GLuint clientVersion)
1217{
1218 InternalFormatInfo internalFormatInfo;
1219 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1220 {
1221 return internalFormatInfo.mType;
1222 }
1223 else
1224 {
1225 UNREACHABLE();
1226 return GL_NONE;
1227 }
1228}
1229
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001230bool IsNormalizedFixedPointFormat(GLint internalFormat, GLuint clientVersion)
1231{
1232 InternalFormatInfo internalFormatInfo;
1233 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1234 {
1235 return internalFormatInfo.mStorageType == NormalizedFixedPoint;
1236 }
1237 else
1238 {
1239 UNREACHABLE();
1240 return false;
1241 }
1242}
1243
1244bool IsIntegerFormat(GLint internalFormat, GLuint clientVersion)
1245{
1246 InternalFormatInfo internalFormatInfo;
1247 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1248 {
1249 return internalFormatInfo.mStorageType == UnsignedInteger ||
1250 internalFormatInfo.mStorageType == SignedInteger;
1251 }
1252 else
1253 {
1254 UNREACHABLE();
1255 return false;
1256 }
1257}
1258
1259bool IsSignedIntegerFormat(GLint internalFormat, GLuint clientVersion)
1260{
1261 InternalFormatInfo internalFormatInfo;
1262 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1263 {
1264 return internalFormatInfo.mStorageType == SignedInteger;
1265 }
1266 else
1267 {
1268 UNREACHABLE();
1269 return false;
1270 }
1271}
1272
1273bool IsUnsignedIntegerFormat(GLint internalFormat, GLuint clientVersion)
1274{
1275 InternalFormatInfo internalFormatInfo;
1276 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1277 {
1278 return internalFormatInfo.mStorageType == UnsignedInteger;
1279 }
1280 else
1281 {
1282 UNREACHABLE();
1283 return false;
1284 }
1285}
1286
1287bool IsFloatingPointFormat(GLint internalFormat, GLuint clientVersion)
1288{
1289 InternalFormatInfo internalFormatInfo;
1290 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1291 {
1292 return internalFormatInfo.mStorageType == FloatingPoint;
1293 }
1294 else
1295 {
1296 UNREACHABLE();
1297 return false;
1298 }
1299}
1300
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +00001301bool IsSRGBFormat(GLint internalFormat, GLuint clientVersion)
1302{
1303 InternalFormatInfo internalFormatInfo;
1304 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1305 {
1306 return internalFormatInfo.mIsSRGB;
1307 }
1308 else
1309 {
1310 UNREACHABLE();
1311 return false;
1312 }
1313}
1314
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001315bool IsColorRenderingSupported(GLint internalFormat, const rx::Renderer *renderer)
1316{
1317 InternalFormatInfo internalFormatInfo;
1318 if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
1319 {
1320 return internalFormatInfo.mIsColorRenderable(NULL, renderer);
1321 }
1322 else
1323 {
1324 UNREACHABLE();
1325 return false;
1326 }
1327}
1328
1329bool IsColorRenderingSupported(GLint internalFormat, const Context *context)
1330{
1331 InternalFormatInfo internalFormatInfo;
1332 if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
1333 {
1334 return internalFormatInfo.mIsColorRenderable(context, NULL);
1335 }
1336 else
1337 {
1338 UNREACHABLE();
1339 return false;
1340 }
1341}
1342
1343bool IsTextureFilteringSupported(GLint internalFormat, const rx::Renderer *renderer)
1344{
1345 InternalFormatInfo internalFormatInfo;
1346 if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
1347 {
1348 return internalFormatInfo.mIsTextureFilterable(NULL, renderer);
1349 }
1350 else
1351 {
1352 UNREACHABLE();
1353 return false;
1354 }
1355}
1356
1357bool IsTextureFilteringSupported(GLint internalFormat, const Context *context)
1358{
1359 InternalFormatInfo internalFormatInfo;
1360 if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
1361 {
1362 return internalFormatInfo.mIsTextureFilterable(context, NULL);
1363 }
1364 else
1365 {
1366 UNREACHABLE();
1367 return false;
1368 }
1369}
1370
1371bool IsDepthRenderingSupported(GLint internalFormat, const rx::Renderer *renderer)
1372{
1373 InternalFormatInfo internalFormatInfo;
1374 if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
1375 {
1376 return internalFormatInfo.mIsDepthRenderable(NULL, renderer);
1377 }
1378 else
1379 {
1380 UNREACHABLE();
1381 return false;
1382 }
1383}
1384
1385bool IsDepthRenderingSupported(GLint internalFormat, const Context *context)
1386{
1387 InternalFormatInfo internalFormatInfo;
1388 if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
1389 {
1390 return internalFormatInfo.mIsDepthRenderable(context, NULL);
1391 }
1392 else
1393 {
1394 UNREACHABLE();
1395 return false;
1396 }
1397}
1398
1399bool IsStencilRenderingSupported(GLint internalFormat, const rx::Renderer *renderer)
1400{
1401 InternalFormatInfo internalFormatInfo;
1402 if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
1403 {
1404 return internalFormatInfo.mIsStencilRenderable(NULL, renderer);
1405 }
1406 else
1407 {
1408 UNREACHABLE();
1409 return false;
1410 }
1411}
1412
1413bool IsStencilRenderingSupported(GLint internalFormat, const Context *context)
1414{
1415 InternalFormatInfo internalFormatInfo;
1416 if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
1417 {
1418 return internalFormatInfo.mIsStencilRenderable(context, NULL);
1419 }
1420 else
1421 {
1422 UNREACHABLE();
1423 return false;
1424 }
1425}
1426
1427GLuint GetRowPitch(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLint alignment)
1428{
1429 ASSERT(alignment > 0 && isPow2(alignment));
1430 return (GetBlockSize(internalFormat, type, clientVersion, width, 1) + alignment - 1) & ~(alignment - 1);
1431}
1432
1433GLuint GetDepthPitch(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height, GLint alignment)
1434{
1435 return (GetBlockSize(internalFormat, type, clientVersion, width, height) + alignment - 1) & ~(alignment - 1);
1436}
1437
1438GLuint GetBlockSize(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height)
1439{
1440 InternalFormatInfo internalFormatInfo;
1441 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1442 {
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001443 if (internalFormatInfo.mStorageType == Compressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001444 {
1445 GLsizei numBlocksWide = (width + internalFormatInfo.mCompressedBlockWidth - 1) / internalFormatInfo.mCompressedBlockWidth;
1446 GLsizei numBlocksHight = (height + internalFormatInfo.mCompressedBlockHeight - 1) / internalFormatInfo.mCompressedBlockHeight;
1447
1448 return (internalFormatInfo.mPixelBits * numBlocksWide * numBlocksHight) / 8;
1449 }
1450 else
1451 {
1452 TypeInfo typeInfo;
1453 if (getTypeInfo(type, &typeInfo))
1454 {
1455 if (typeInfo.mSpecialInterpretation)
1456 {
1457 return typeInfo.mTypeBytes * width * height;
1458 }
1459 else
1460 {
1461 return internalFormatInfo.mComponentCount * typeInfo.mTypeBytes * width * height;
1462 }
1463 }
1464 else
1465 {
1466 UNREACHABLE();
1467 return 0;
1468 }
1469 }
1470 }
1471 else
1472 {
1473 UNREACHABLE();
1474 return 0;
1475 }
1476}
1477
1478bool IsFormatCompressed(GLint internalFormat, GLuint clientVersion)
1479{
1480 InternalFormatInfo internalFormatInfo;
1481 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1482 {
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001483 return internalFormatInfo.mStorageType == Compressed;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001484 }
1485 else
1486 {
1487 UNREACHABLE();
1488 return false;
1489 }
1490}
1491
1492GLuint GetCompressedBlockWidth(GLint internalFormat, GLuint clientVersion)
1493{
1494 InternalFormatInfo internalFormatInfo;
1495 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1496 {
1497 return internalFormatInfo.mCompressedBlockWidth;
1498 }
1499 else
1500 {
1501 UNREACHABLE();
1502 return 0;
1503 }
1504}
1505
1506GLuint GetCompressedBlockHeight(GLint internalFormat, GLuint clientVersion)
1507{
1508 InternalFormatInfo internalFormatInfo;
1509 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1510 {
1511 return internalFormatInfo.mCompressedBlockHeight;
1512 }
1513 else
1514 {
1515 UNREACHABLE();
1516 return 0;
1517 }
1518}
1519
1520}