blob: 29294bbe5f1626868b63903bf45cb3d893a14dc4 [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.orgb8490f32013-05-30 00:08:00 +0000467 ContextRendererSupportCheckFunction mIsColorRenderable;
468 ContextRendererSupportCheckFunction mIsDepthRenderable;
469 ContextRendererSupportCheckFunction mIsStencilRenderable;
470 ContextRendererSupportCheckFunction mIsTextureFilterable;
471
472 ContextSupportCheckFunction mSupportFunction;
473
474 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 +0000475 mPixelBits(0), mComponentCount(0), mCompressedBlockWidth(0), mCompressedBlockHeight(0), mFormat(GL_NONE), mType(GL_NONE),
476 mStorageType(Unknown), mIsColorRenderable(NeverSupported), mIsDepthRenderable(NeverSupported), mIsStencilRenderable(NeverSupported),
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000477 mIsTextureFilterable(NeverSupported), mSupportFunction(NeverSupported)
478 {
479 }
480
481 static InternalFormatInfo UnsizedFormat(GLenum format, ContextSupportCheckFunction supportFunction)
482 {
483 InternalFormatInfo formatInfo;
484 formatInfo.mFormat = format;
485 formatInfo.mSupportFunction = supportFunction;
486 return formatInfo;
487 }
488
489 static InternalFormatInfo RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared,
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000490 GLenum format, GLenum type, InternalFormatStorageType storageType,
491 ContextRendererSupportCheckFunction colorRenderable,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000492 ContextRendererSupportCheckFunction textureFilterable,
493 ContextSupportCheckFunction supportFunction)
494 {
495 InternalFormatInfo formatInfo;
496 formatInfo.mRedBits = red;
497 formatInfo.mGreenBits = green;
498 formatInfo.mBlueBits = blue;
499 formatInfo.mAlphaBits = alpha;
500 formatInfo.mSharedBits = shared;
501 formatInfo.mPixelBits = red + green + blue + alpha + shared;
502 formatInfo.mComponentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
503 formatInfo.mFormat = format;
504 formatInfo.mType = type;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000505 formatInfo.mStorageType = storageType;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000506 formatInfo.mIsColorRenderable = colorRenderable;
507 formatInfo.mIsTextureFilterable = textureFilterable;
508 formatInfo.mSupportFunction = supportFunction;
509 return formatInfo;
510 }
511
512 static InternalFormatInfo LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type,
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000513 InternalFormatStorageType storageType,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000514 ContextSupportCheckFunction supportFunction)
515 {
516 InternalFormatInfo formatInfo;
517 formatInfo.mLuminanceBits = luminance;
518 formatInfo.mAlphaBits = alpha;
519 formatInfo.mPixelBits = luminance + alpha;
520 formatInfo.mComponentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
521 formatInfo.mFormat = format;
522 formatInfo.mType = type;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000523 formatInfo.mStorageType = storageType;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000524 formatInfo.mIsTextureFilterable = AlwaysSupported;
525 formatInfo.mSupportFunction = supportFunction;
526 return formatInfo;
527 }
528
529 static InternalFormatInfo DepthStencilFormat(GLuint depth, GLuint stencil, GLenum format, GLenum type,
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000530 InternalFormatStorageType storageType,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000531 ContextRendererSupportCheckFunction depthRenderable,
532 ContextRendererSupportCheckFunction stencilRenderable,
533 ContextSupportCheckFunction supportFunction)
534 {
535 InternalFormatInfo formatInfo;
536 formatInfo.mDepthBits = depth;
537 formatInfo.mStencilBits = stencil;
538 formatInfo.mPixelBits = depth + stencil;
539 formatInfo.mComponentCount = ((depth > 0) ? 1 : 0) + ((stencil > 0) ? 1 : 0);
540 formatInfo.mFormat = format;
541 formatInfo.mType = type;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000542 formatInfo.mStorageType = storageType;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000543 formatInfo.mIsDepthRenderable = depthRenderable;
544 formatInfo.mIsStencilRenderable = stencilRenderable;
545 formatInfo.mSupportFunction = supportFunction;
546 return formatInfo;
547 }
548
549 static InternalFormatInfo CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight,
550 GLuint compressedBlockSize, GLuint componentCount, GLenum format, GLenum type,
551 ContextSupportCheckFunction supportFunction)
552 {
553 InternalFormatInfo formatInfo;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000554 formatInfo.mCompressedBlockWidth = compressedBlockWidth;
555 formatInfo.mCompressedBlockHeight = compressedBlockHeight;
556 formatInfo.mPixelBits = compressedBlockSize;
557 formatInfo.mComponentCount = componentCount;
558 formatInfo.mFormat = format;
559 formatInfo.mType = type;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000560 formatInfo.mStorageType = Compressed;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000561 formatInfo.mIsTextureFilterable = AlwaysSupported;
562 formatInfo.mSupportFunction = supportFunction;
563 return formatInfo;
564 }
565};
566
567typedef std::pair<GLuint, InternalFormatInfo> InternalFormatInfoPair;
568typedef std::map<GLuint, InternalFormatInfo> InternalFormatInfoMap;
569
570static InternalFormatInfoMap buildES3InternalFormatInfoMap()
571{
572 InternalFormatInfoMap map;
573
574 // From ES 3.0.1 spec, table 3.12
575 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
576
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000577 // | Internal format | | R | G | B | A |S | Format | Type | Internal format | Color | Texture | Supported |
578 // | | | | | | | | | | type | renderable | filterable | |
579 map.insert(InternalFormatInfoPair(GL_R8, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
580 map.insert(InternalFormatInfoPair(GL_R8_SNORM, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, NormalizedFixedPoint, NeverSupported, AlwaysSupported, AlwaysSupported )));
581 map.insert(InternalFormatInfoPair(GL_RG8, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
582 map.insert(InternalFormatInfoPair(GL_RG8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, NormalizedFixedPoint, NeverSupported, AlwaysSupported, AlwaysSupported )));
583 map.insert(InternalFormatInfoPair(GL_RGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
584 map.insert(InternalFormatInfoPair(GL_RGB8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, NormalizedFixedPoint, NeverSupported, AlwaysSupported, AlwaysSupported )));
585 map.insert(InternalFormatInfoPair(GL_RGB565, InternalFormatInfo::RGBAFormat( 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_5_5_1, NormalizedFixedPoint, NeverSupported, AlwaysSupported, AlwaysSupported )));
586 map.insert(InternalFormatInfoPair(GL_RGBA4, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, NormalizedFixedPoint, NeverSupported, AlwaysSupported, AlwaysSupported )));
587 map.insert(InternalFormatInfoPair(GL_RGB5_A1, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
588 map.insert(InternalFormatInfoPair(GL_RGBA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
589 map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, NormalizedFixedPoint, NeverSupported, AlwaysSupported, AlwaysSupported )));
590 map.insert(InternalFormatInfoPair(GL_RGB10_A2, InternalFormatInfo::RGBAFormat(10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
591 map.insert(InternalFormatInfoPair(GL_RGB10_A2UI, InternalFormatInfo::RGBAFormat(10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, UnsignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
592 map.insert(InternalFormatInfoPair(GL_SRGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, NormalizedFixedPoint, NeverSupported, AlwaysSupported, AlwaysSupported )));
593 map.insert(InternalFormatInfoPair(GL_SRGB8_ALPHA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
594 map.insert(InternalFormatInfoPair(GL_R11F_G11F_B10F, InternalFormatInfo::RGBAFormat(11, 11, 10, 0, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, FloatingPoint, NeverSupported, AlwaysSupported, AlwaysSupported )));
595 map.insert(InternalFormatInfoPair(GL_RGB9_E5, InternalFormatInfo::RGBAFormat( 9, 9, 9, 0, 5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, FloatingPoint, NeverSupported, AlwaysSupported, AlwaysSupported )));
596 map.insert(InternalFormatInfoPair(GL_R8I, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, SignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
597 map.insert(InternalFormatInfoPair(GL_R8UI, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, UnsignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
598 map.insert(InternalFormatInfoPair(GL_R16I, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, SignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
599 map.insert(InternalFormatInfoPair(GL_R16UI, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, UnsignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
600 map.insert(InternalFormatInfoPair(GL_R32I, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, SignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
601 map.insert(InternalFormatInfoPair(GL_R32UI, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, UnsignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
602 map.insert(InternalFormatInfoPair(GL_RG8I, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, SignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
603 map.insert(InternalFormatInfoPair(GL_RG8UI, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, UnsignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
604 map.insert(InternalFormatInfoPair(GL_RG16I, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, SignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
605 map.insert(InternalFormatInfoPair(GL_RG16UI, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, UnsignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
606 map.insert(InternalFormatInfoPair(GL_RG32I, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, SignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
607 map.insert(InternalFormatInfoPair(GL_RG32UI, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, UnsignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
608 map.insert(InternalFormatInfoPair(GL_RGB8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, SignedInteger, NeverSupported, NeverSupported, AlwaysSupported )));
609 map.insert(InternalFormatInfoPair(GL_RGB8UI, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, UnsignedInteger, NeverSupported, NeverSupported, AlwaysSupported )));
610 map.insert(InternalFormatInfoPair(GL_RGB16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, SignedInteger, NeverSupported, NeverSupported, AlwaysSupported )));
611 map.insert(InternalFormatInfoPair(GL_RGB16UI, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, UnsignedInteger, NeverSupported, NeverSupported, AlwaysSupported )));
612 map.insert(InternalFormatInfoPair(GL_RGB32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, SignedInteger, NeverSupported, NeverSupported, AlwaysSupported )));
613 map.insert(InternalFormatInfoPair(GL_RGB32UI, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, UnsignedInteger, NeverSupported, NeverSupported, AlwaysSupported )));
614 map.insert(InternalFormatInfoPair(GL_RGBA8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, SignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
615 map.insert(InternalFormatInfoPair(GL_RGBA8UI, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, UnsignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
616 map.insert(InternalFormatInfoPair(GL_RGBA16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, SignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
617 map.insert(InternalFormatInfoPair(GL_RGBA16UI, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, UnsignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
618 map.insert(InternalFormatInfoPair(GL_RGBA32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, SignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
619 map.insert(InternalFormatInfoPair(GL_RGBA32UI, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, UnsignedInteger, AlwaysSupported, NeverSupported, AlwaysSupported )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000620
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000621 map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
622 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, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
623 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, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000624
625 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000626 // | Internal format | | D |S | Format | Type | Internal fmt |Color | Texture | Supported |
627 // | | | | | | | type | | filterable | |
628 map.insert(InternalFormatInfoPair(GL_R16F, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, FloatingPoint, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
629 map.insert(InternalFormatInfoPair(GL_RG16F, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, FloatingPoint, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
630 map.insert(InternalFormatInfoPair(GL_RGB16F, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, FloatingPoint, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
631 map.insert(InternalFormatInfoPair(GL_RGBA16F, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, FloatingPoint, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
632 map.insert(InternalFormatInfoPair(GL_R32F, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, FloatingPoint, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
633 map.insert(InternalFormatInfoPair(GL_RG32F, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, FloatingPoint, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
634 map.insert(InternalFormatInfoPair(GL_RGB32F, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, FloatingPoint, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
635 map.insert(InternalFormatInfoPair(GL_RGBA32F, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, FloatingPoint, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000636
637 // Depth stencil formats
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000638 // | Internal format | | D |S | Format | Type | Internal format | Color | Texture | Supported |
639 // | | | | | | | type | renderable | filterable | |
640 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NormalizedFixedPoint, AlwaysSupported, NeverSupported, AlwaysSupported)));
641 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT24, InternalFormatInfo::DepthStencilFormat(24, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NormalizedFixedPoint, AlwaysSupported, NeverSupported, AlwaysSupported)));
642 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32F,InternalFormatInfo::DepthStencilFormat(32, 0, GL_DEPTH_COMPONENT, GL_FLOAT, FloatingPoint, AlwaysSupported, NeverSupported, AlwaysSupported)));
643 map.insert(InternalFormatInfoPair(GL_DEPTH24_STENCIL8, InternalFormatInfo::DepthStencilFormat(24, 8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
644 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 +0000645
646 // Luminance alpha formats
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000647 // | Internal format | | L | A | Format | Type | Internal format | Supported |
648 // | | | | | | | type | |
649 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
650 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
651 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, FloatingPoint, AlwaysSupported)));
652 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, FloatingPoint, AlwaysSupported)));
653 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, FloatingPoint, AlwaysSupported)));
654 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, FloatingPoint, AlwaysSupported)));
655 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
656 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, FloatingPoint, AlwaysSupported)));
657 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 +0000658
659 // Unsized formats
660 // | Internal format | | Format | Supported |
661 // | | | | |
662 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported)));
663 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported)));
664 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported)));
665 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
666 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
667 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
668
669 // Compressed formats, From ES 3.0.1 spec, table 3.16
670 // | Internal format | |W |H | B |C | Format | Type | Supported |
671 // | | | | | S |C | | | |
672 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
673 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
674 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
675 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
676 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, UnimplementedSupport)));
677 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, UnimplementedSupport)));
678 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)));
679 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)));
680 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA8_ETC2_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
681 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)));
682
683 // From GL_EXT_texture_compression_dxt1
684 // | Internal format | |W |H | B |C | Format | Type | Supported |
685 // | | | | | S |C | | | |
686 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)));
687 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)));
688
689 // From GL_ANGLE_texture_compression_dxt3
690 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)));
691
692 // From GL_ANGLE_texture_compression_dxt5
693 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)));
694
695 return map;
696}
697
698static InternalFormatInfoMap buildES2InternalFormatInfoMap()
699{
700 InternalFormatInfoMap map;
701
702 // From ES 2.0.25 table 4.5
703 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
704
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000705 // | Internal format | | R | G | B | A |S | Format | Type | Internal format | Color | Texture | Supported |
706 // | | | | | | | | | | type | renderable | filterable | |
707 map.insert(InternalFormatInfoPair(GL_RGBA4, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
708 map.insert(InternalFormatInfoPair(GL_RGB5_A1, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
709 map.insert(InternalFormatInfoPair(GL_RGB565, InternalFormatInfo::RGBAFormat( 5, 6, 5, 0, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_6_5, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000710
711 // Extension formats
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000712 map.insert(InternalFormatInfoPair(GL_RGB8_OES, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
713 map.insert(InternalFormatInfoPair(GL_RGBA8_OES, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
714 map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
715 map.insert(InternalFormatInfoPair(GL_BGRA4_ANGLEX, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4, NormalizedFixedPoint, NeverSupported, AlwaysSupported, AlwaysSupported)));
716 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, NeverSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000717
718 // Floating point formats have to query the renderer for support
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000719 // | Internal format | | R | G | B | A |S | Format | Type | Internal fmt | Color | Texture | Supported |
720 // | | | | | | | | | | type | renderable | filterable | |
721 map.insert(InternalFormatInfoPair(GL_RGB16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT_OES, FloatingPoint, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, CheckSupport<&Context::supportsFloat16Textures>)));
722 map.insert(InternalFormatInfoPair(GL_RGB32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, FloatingPoint, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, CheckSupport<&Context::supportsFloat32Textures>)));
723 map.insert(InternalFormatInfoPair(GL_RGBA16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT_OES, FloatingPoint, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, CheckSupport<&Context::supportsFloat16Textures>)));
724 map.insert(InternalFormatInfoPair(GL_RGBA32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, FloatingPoint, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, CheckSupport<&Context::supportsFloat32Textures>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000725
726 // Depth and stencil formats
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000727 // | Internal format | | D |S | Format | Type | Internal format | Color | Texture | Supported |
728 // | | | | | | | type | renderable | filterable | |
729 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES,InternalFormatInfo::DepthStencilFormat(32, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NormalizedFixedPoint, AlwaysSupported, NeverSupported, CheckSupport<&Context::supportsDepthTextures>)));
730 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>)));
731 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NormalizedFixedPoint, AlwaysSupported, NeverSupported, AlwaysSupported)));
732 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 +0000733
734 // Unsized formats
735 // | Internal format | | Format | Supported |
736 // | | | | |
737 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported)));
738 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported)));
739 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported)));
740 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
741 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
742 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
743 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, InternalFormatInfo::UnsizedFormat(GL_DEPTH_COMPONENT, AlwaysSupported)));
744 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL_OES, InternalFormatInfo::UnsizedFormat(GL_DEPTH_STENCIL_OES, AlwaysSupported)));
745
746 // Luminance alpha formats from GL_EXT_texture_storage
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000747 // | Internal format | | L | A | Format | Type | Internal format | Supported |
748 // | | | | | | | type | |
749 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
750 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
751 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, FloatingPoint, AlwaysSupported)));
752 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, FloatingPoint, AlwaysSupported)));
753 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, FloatingPoint, AlwaysSupported)));
754 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, FloatingPoint, AlwaysSupported)));
755 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
756 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, FloatingPoint, AlwaysSupported)));
757 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 +0000758
759 // From GL_EXT_texture_compression_dxt1
760 // | Internal format | |W |H | B |C |Format | Type | Supported |
761 // | | | | | S |C | | | |
762 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>)));
763 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>)));
764
765 // From GL_ANGLE_texture_compression_dxt3
766 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>)));
767
768 // From GL_ANGLE_texture_compression_dxt5
769 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>)));
770
771 return map;
772}
773
774static bool getInternalFormatInfo(GLint internalFormat, GLuint clientVersion, InternalFormatInfo *outFormatInfo)
775{
776 const InternalFormatInfoMap* map = NULL;
777
778 if (clientVersion == 2)
779 {
780 static const InternalFormatInfoMap formatMap = buildES2InternalFormatInfoMap();
781 map = &formatMap;
782 }
783 else if (clientVersion == 3)
784 {
785 static const InternalFormatInfoMap formatMap = buildES3InternalFormatInfoMap();
786 map = &formatMap;
787 }
788 else
789 {
790 UNREACHABLE();
791 }
792
793 InternalFormatInfoMap::const_iterator iter = map->find(internalFormat);
794 if (iter != map->end())
795 {
796 if (outFormatInfo)
797 {
798 *outFormatInfo = iter->second;
799 }
800 return true;
801 }
802 else
803 {
804 return false;
805 }
806}
807
808typedef std::set<GLenum> FormatSet;
809
810static FormatSet buildES2ValidFormatSet()
811{
812 static const FormatMap &formatMap = getES2FormatMap();
813
814 FormatSet set;
815
816 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
817 {
818 const FormatTypePair& formatPair = i->first;
819 set.insert(formatPair.first);
820 }
821
822 return set;
823}
824
825static FormatSet buildES3ValidFormatSet()
826{
827 static const ES3FormatSet &formatSet = getES3FormatSet();
828
829 FormatSet set;
830
831 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
832 {
833 const FormatInfo& formatInfo = *i;
834 set.insert(formatInfo.mFormat);
835 }
836
837 return set;
838}
839
840typedef std::set<GLenum> TypeSet;
841
842static TypeSet buildES2ValidTypeSet()
843{
844 static const FormatMap &formatMap = getES2FormatMap();
845
846 TypeSet set;
847
848 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
849 {
850 const FormatTypePair& formatPair = i->first;
851 set.insert(formatPair.second);
852 }
853
854 return set;
855}
856
857static TypeSet buildES3ValidTypeSet()
858{
859 static const ES3FormatSet &formatSet = getES3FormatSet();
860
861 TypeSet set;
862
863 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
864 {
865 const FormatInfo& formatInfo = *i;
866 set.insert(formatInfo.mType);
867 }
868
869 return set;
870}
871
872struct CopyConversion
873{
874 GLenum mTextureFormat;
875 GLenum mFramebufferFormat;
876
877 CopyConversion(GLenum textureFormat, GLenum framebufferFormat)
878 : mTextureFormat(textureFormat), mFramebufferFormat(framebufferFormat) { }
879
880 bool operator<(const CopyConversion& other) const
881 {
882 return memcmp(this, &other, sizeof(CopyConversion)) < 0;
883 }
884};
885
886typedef std::set<CopyConversion> CopyConversionSet;
887
888static CopyConversionSet buildValidES3CopyTexImageCombinations()
889{
890 CopyConversionSet set;
891
892 // From ES 3.0.1 spec, table 3.15
893 set.insert(CopyConversion(GL_ALPHA, GL_RGBA));
894 set.insert(CopyConversion(GL_LUMINANCE, GL_RED));
895 set.insert(CopyConversion(GL_LUMINANCE, GL_RG));
896 set.insert(CopyConversion(GL_LUMINANCE, GL_RGB));
897 set.insert(CopyConversion(GL_LUMINANCE, GL_RGBA));
898 set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_RGBA));
899 set.insert(CopyConversion(GL_RED, GL_RED));
900 set.insert(CopyConversion(GL_RED, GL_RG));
901 set.insert(CopyConversion(GL_RED, GL_RGB));
902 set.insert(CopyConversion(GL_RED, GL_RGBA));
903 set.insert(CopyConversion(GL_RG, GL_RG));
904 set.insert(CopyConversion(GL_RG, GL_RGB));
905 set.insert(CopyConversion(GL_RG, GL_RGBA));
906 set.insert(CopyConversion(GL_RGB, GL_RGB));
907 set.insert(CopyConversion(GL_RGB, GL_RGBA));
908 set.insert(CopyConversion(GL_RGBA, GL_RGBA));
909
910 return set;
911}
912
913bool IsValidInternalFormat(GLint internalFormat, const Context *context)
914{
915 if (!context)
916 {
917 return false;
918 }
919
920 InternalFormatInfo internalFormatInfo;
921 if (getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
922 {
923 ASSERT(internalFormatInfo.mSupportFunction != NULL);
924 return internalFormatInfo.mSupportFunction(context);
925 }
926 else
927 {
928 return false;
929 }
930}
931
932bool IsValidFormat(GLenum format, GLuint clientVersion)
933{
934 if (clientVersion == 2)
935 {
936 static const FormatSet formatSet = buildES2ValidFormatSet();
937 return formatSet.find(format) != formatSet.end();
938 }
939 else if (clientVersion == 3)
940 {
941 static const FormatSet formatSet = buildES3ValidFormatSet();
942 return formatSet.find(format) != formatSet.end();
943 }
944 else
945 {
946 UNREACHABLE();
947 return false;
948 }
949}
950
951bool IsValidType(GLenum type, GLuint clientVersion)
952{
953 if (clientVersion == 2)
954 {
955 static const TypeSet typeSet = buildES2ValidTypeSet();
956 return typeSet.find(type) != typeSet.end();
957 }
958 else if (clientVersion == 3)
959 {
960 static const TypeSet typeSet = buildES3ValidTypeSet();
961 return typeSet.find(type) != typeSet.end();
962 }
963 else
964 {
965 UNREACHABLE();
966 return false;
967 }
968}
969
970bool IsValidFormatCombination(GLint internalFormat, GLenum format, GLenum type, GLuint clientVersion)
971{
972 if (clientVersion == 2)
973 {
974 static const FormatMap &formats = getES2FormatMap();
975 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
976
977 return (iter != formats.end()) && ((internalFormat == (GLint)type) || (internalFormat == iter->second));
978 }
979 else if (clientVersion == 3)
980 {
981 static const ES3FormatSet &formats = getES3FormatSet();
982 return formats.find(FormatInfo(internalFormat, format, type)) != formats.end();
983 }
984 else
985 {
986 UNREACHABLE();
987 return false;
988 }
989}
990
991bool IsValidCopyTexImageCombination(GLenum textureFormat, GLenum frameBufferFormat, GLuint clientVersion)
992{
993 if (clientVersion == 2)
994 {
995 UNIMPLEMENTED();
996 return false;
997 }
998 else if (clientVersion == 3)
999 {
1000 static const CopyConversionSet conversionSet = buildValidES3CopyTexImageCombinations();
1001 return conversionSet.find(CopyConversion(textureFormat, frameBufferFormat)) != conversionSet.end();
1002 }
1003 else
1004 {
1005 UNREACHABLE();
1006 return false;
1007 }
1008}
1009
1010bool IsSizedInternalFormat(GLint internalFormat, GLuint clientVersion)
1011{
1012 InternalFormatInfo internalFormatInfo;
1013 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1014 {
1015 return internalFormatInfo.mPixelBits > 0;
1016 }
1017 else
1018 {
1019 UNREACHABLE();
1020 return false;
1021 }
1022}
1023
1024GLint GetSizedInternalFormat(GLenum format, GLenum type, GLuint clientVersion)
1025{
1026 if (clientVersion == 2)
1027 {
1028 static const FormatMap &formats = getES2FormatMap();
1029 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1030 return (iter != formats.end()) ? iter->second : GL_NONE;
1031 }
1032 else if (clientVersion == 3)
1033 {
1034 static const FormatMap formats = buildES3FormatMap();
1035 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1036 return (iter != formats.end()) ? iter->second : GL_NONE;
1037 }
1038 else
1039 {
1040 UNREACHABLE();
1041 return GL_NONE;
1042 }
1043}
1044
1045GLuint GetPixelBytes(GLint internalFormat, GLuint clientVersion)
1046{
1047 InternalFormatInfo internalFormatInfo;
1048 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1049 {
1050 return internalFormatInfo.mPixelBits / 8;
1051 }
1052 else
1053 {
1054 UNREACHABLE();
1055 return 0;
1056 }
1057}
1058
1059GLuint GetAlphaBits(GLint internalFormat, GLuint clientVersion)
1060{
1061 InternalFormatInfo internalFormatInfo;
1062 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1063 {
1064 return internalFormatInfo.mAlphaBits;
1065 }
1066 else
1067 {
1068 UNREACHABLE();
1069 return 0;
1070 }
1071}
1072
1073GLuint GetRedBits(GLint internalFormat, GLuint clientVersion)
1074{
1075 InternalFormatInfo internalFormatInfo;
1076 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1077 {
1078 return internalFormatInfo.mRedBits;
1079 }
1080 else
1081 {
1082 UNREACHABLE();
1083 return 0;
1084 }
1085}
1086
1087GLuint GetGreenBits(GLint internalFormat, GLuint clientVersion)
1088{
1089 InternalFormatInfo internalFormatInfo;
1090 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1091 {
1092 return internalFormatInfo.mGreenBits;
1093 }
1094 else
1095 {
1096 UNREACHABLE();
1097 return 0;
1098 }
1099}
1100
1101GLuint GetBlueBits(GLint internalFormat, GLuint clientVersion)
1102{
1103 InternalFormatInfo internalFormatInfo;
1104 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1105 {
1106 return internalFormatInfo.mGreenBits;
1107 }
1108 else
1109 {
1110 UNREACHABLE();
1111 return 0;
1112 }
1113}
1114
1115GLuint GetLuminanceBits(GLint internalFormat, GLuint clientVersion)
1116{
1117 InternalFormatInfo internalFormatInfo;
1118 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1119 {
1120 return internalFormatInfo.mLuminanceBits;
1121 }
1122 else
1123 {
1124 UNREACHABLE();
1125 return 0;
1126 }
1127}
1128
1129GLuint GetDepthBits(GLint internalFormat, GLuint clientVersion)
1130{
1131 InternalFormatInfo internalFormatInfo;
1132 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1133 {
1134 return internalFormatInfo.mDepthBits;
1135 }
1136 else
1137 {
1138 UNREACHABLE();
1139 return 0;
1140 }
1141}
1142
1143GLuint GetStencilBits(GLint internalFormat, GLuint clientVersion)
1144{
1145 InternalFormatInfo internalFormatInfo;
1146 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1147 {
1148 return internalFormatInfo.mStencilBits;
1149 }
1150 else
1151 {
1152 UNREACHABLE();
1153 return 0;
1154 }
1155}
1156
1157GLenum GetFormat(GLint internalFormat, GLuint clientVersion)
1158{
1159 InternalFormatInfo internalFormatInfo;
1160 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1161 {
1162 return internalFormatInfo.mFormat;
1163 }
1164 else
1165 {
1166 UNREACHABLE();
1167 return GL_NONE;
1168 }
1169}
1170
1171GLenum GetType(GLint internalFormat, GLuint clientVersion)
1172{
1173 InternalFormatInfo internalFormatInfo;
1174 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1175 {
1176 return internalFormatInfo.mType;
1177 }
1178 else
1179 {
1180 UNREACHABLE();
1181 return GL_NONE;
1182 }
1183}
1184
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001185bool IsNormalizedFixedPointFormat(GLint internalFormat, GLuint clientVersion)
1186{
1187 InternalFormatInfo internalFormatInfo;
1188 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1189 {
1190 return internalFormatInfo.mStorageType == NormalizedFixedPoint;
1191 }
1192 else
1193 {
1194 UNREACHABLE();
1195 return false;
1196 }
1197}
1198
1199bool IsIntegerFormat(GLint internalFormat, GLuint clientVersion)
1200{
1201 InternalFormatInfo internalFormatInfo;
1202 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1203 {
1204 return internalFormatInfo.mStorageType == UnsignedInteger ||
1205 internalFormatInfo.mStorageType == SignedInteger;
1206 }
1207 else
1208 {
1209 UNREACHABLE();
1210 return false;
1211 }
1212}
1213
1214bool IsSignedIntegerFormat(GLint internalFormat, GLuint clientVersion)
1215{
1216 InternalFormatInfo internalFormatInfo;
1217 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1218 {
1219 return internalFormatInfo.mStorageType == SignedInteger;
1220 }
1221 else
1222 {
1223 UNREACHABLE();
1224 return false;
1225 }
1226}
1227
1228bool IsUnsignedIntegerFormat(GLint internalFormat, GLuint clientVersion)
1229{
1230 InternalFormatInfo internalFormatInfo;
1231 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1232 {
1233 return internalFormatInfo.mStorageType == UnsignedInteger;
1234 }
1235 else
1236 {
1237 UNREACHABLE();
1238 return false;
1239 }
1240}
1241
1242bool IsFloatingPointFormat(GLint internalFormat, GLuint clientVersion)
1243{
1244 InternalFormatInfo internalFormatInfo;
1245 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1246 {
1247 return internalFormatInfo.mStorageType == FloatingPoint;
1248 }
1249 else
1250 {
1251 UNREACHABLE();
1252 return false;
1253 }
1254}
1255
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001256bool IsColorRenderingSupported(GLint internalFormat, const rx::Renderer *renderer)
1257{
1258 InternalFormatInfo internalFormatInfo;
1259 if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
1260 {
1261 return internalFormatInfo.mIsColorRenderable(NULL, renderer);
1262 }
1263 else
1264 {
1265 UNREACHABLE();
1266 return false;
1267 }
1268}
1269
1270bool IsColorRenderingSupported(GLint internalFormat, const Context *context)
1271{
1272 InternalFormatInfo internalFormatInfo;
1273 if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
1274 {
1275 return internalFormatInfo.mIsColorRenderable(context, NULL);
1276 }
1277 else
1278 {
1279 UNREACHABLE();
1280 return false;
1281 }
1282}
1283
1284bool IsTextureFilteringSupported(GLint internalFormat, const rx::Renderer *renderer)
1285{
1286 InternalFormatInfo internalFormatInfo;
1287 if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
1288 {
1289 return internalFormatInfo.mIsTextureFilterable(NULL, renderer);
1290 }
1291 else
1292 {
1293 UNREACHABLE();
1294 return false;
1295 }
1296}
1297
1298bool IsTextureFilteringSupported(GLint internalFormat, const Context *context)
1299{
1300 InternalFormatInfo internalFormatInfo;
1301 if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
1302 {
1303 return internalFormatInfo.mIsTextureFilterable(context, NULL);
1304 }
1305 else
1306 {
1307 UNREACHABLE();
1308 return false;
1309 }
1310}
1311
1312bool IsDepthRenderingSupported(GLint internalFormat, const rx::Renderer *renderer)
1313{
1314 InternalFormatInfo internalFormatInfo;
1315 if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
1316 {
1317 return internalFormatInfo.mIsDepthRenderable(NULL, renderer);
1318 }
1319 else
1320 {
1321 UNREACHABLE();
1322 return false;
1323 }
1324}
1325
1326bool IsDepthRenderingSupported(GLint internalFormat, const Context *context)
1327{
1328 InternalFormatInfo internalFormatInfo;
1329 if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
1330 {
1331 return internalFormatInfo.mIsDepthRenderable(context, NULL);
1332 }
1333 else
1334 {
1335 UNREACHABLE();
1336 return false;
1337 }
1338}
1339
1340bool IsStencilRenderingSupported(GLint internalFormat, const rx::Renderer *renderer)
1341{
1342 InternalFormatInfo internalFormatInfo;
1343 if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
1344 {
1345 return internalFormatInfo.mIsStencilRenderable(NULL, renderer);
1346 }
1347 else
1348 {
1349 UNREACHABLE();
1350 return false;
1351 }
1352}
1353
1354bool IsStencilRenderingSupported(GLint internalFormat, const Context *context)
1355{
1356 InternalFormatInfo internalFormatInfo;
1357 if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
1358 {
1359 return internalFormatInfo.mIsStencilRenderable(context, NULL);
1360 }
1361 else
1362 {
1363 UNREACHABLE();
1364 return false;
1365 }
1366}
1367
1368GLuint GetRowPitch(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLint alignment)
1369{
1370 ASSERT(alignment > 0 && isPow2(alignment));
1371 return (GetBlockSize(internalFormat, type, clientVersion, width, 1) + alignment - 1) & ~(alignment - 1);
1372}
1373
1374GLuint GetDepthPitch(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height, GLint alignment)
1375{
1376 return (GetBlockSize(internalFormat, type, clientVersion, width, height) + alignment - 1) & ~(alignment - 1);
1377}
1378
1379GLuint GetBlockSize(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height)
1380{
1381 InternalFormatInfo internalFormatInfo;
1382 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1383 {
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001384 if (internalFormatInfo.mStorageType == Compressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001385 {
1386 GLsizei numBlocksWide = (width + internalFormatInfo.mCompressedBlockWidth - 1) / internalFormatInfo.mCompressedBlockWidth;
1387 GLsizei numBlocksHight = (height + internalFormatInfo.mCompressedBlockHeight - 1) / internalFormatInfo.mCompressedBlockHeight;
1388
1389 return (internalFormatInfo.mPixelBits * numBlocksWide * numBlocksHight) / 8;
1390 }
1391 else
1392 {
1393 TypeInfo typeInfo;
1394 if (getTypeInfo(type, &typeInfo))
1395 {
1396 if (typeInfo.mSpecialInterpretation)
1397 {
1398 return typeInfo.mTypeBytes * width * height;
1399 }
1400 else
1401 {
1402 return internalFormatInfo.mComponentCount * typeInfo.mTypeBytes * width * height;
1403 }
1404 }
1405 else
1406 {
1407 UNREACHABLE();
1408 return 0;
1409 }
1410 }
1411 }
1412 else
1413 {
1414 UNREACHABLE();
1415 return 0;
1416 }
1417}
1418
1419bool IsFormatCompressed(GLint internalFormat, GLuint clientVersion)
1420{
1421 InternalFormatInfo internalFormatInfo;
1422 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1423 {
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001424 return internalFormatInfo.mStorageType == Compressed;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001425 }
1426 else
1427 {
1428 UNREACHABLE();
1429 return false;
1430 }
1431}
1432
1433GLuint GetCompressedBlockWidth(GLint internalFormat, GLuint clientVersion)
1434{
1435 InternalFormatInfo internalFormatInfo;
1436 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1437 {
1438 return internalFormatInfo.mCompressedBlockWidth;
1439 }
1440 else
1441 {
1442 UNREACHABLE();
1443 return 0;
1444 }
1445}
1446
1447GLuint GetCompressedBlockHeight(GLint internalFormat, GLuint clientVersion)
1448{
1449 InternalFormatInfo internalFormatInfo;
1450 if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1451 {
1452 return internalFormatInfo.mCompressedBlockHeight;
1453 }
1454 else
1455 {
1456 UNREACHABLE();
1457 return 0;
1458 }
1459}
1460
1461}