• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17 #include "GLESv2Validation.h"
18 
19 #include <sstream>
20 
21 #define LIST_VALID_TEX_INTERNALFORMATS(f) \
22     f(GL_BGRA8_EXT) \
23     f(GL_R8) \
24     f(GL_R8_SNORM) \
25     f(GL_R16F) \
26     f(GL_R32F) \
27     f(GL_R8UI) \
28     f(GL_R8I) \
29     f(GL_R16UI) \
30     f(GL_R16I) \
31     f(GL_R32UI) \
32     f(GL_R32I) \
33     f(GL_RG8) \
34     f(GL_RG8_SNORM) \
35     f(GL_RG16F) \
36     f(GL_RG32F) \
37     f(GL_RG8UI) \
38     f(GL_RG8I) \
39     f(GL_RG16UI) \
40     f(GL_RG16I) \
41     f(GL_RG32UI) \
42     f(GL_RG32I) \
43     f(GL_RGB8) \
44     f(GL_SRGB8) \
45     f(GL_RGB565) \
46     f(GL_RGB8_SNORM) \
47     f(GL_R11F_G11F_B10F) \
48     f(GL_RGB9_E5) \
49     f(GL_RGB16F) \
50     f(GL_RGB32F) \
51     f(GL_RGB8UI) \
52     f(GL_RGB8I) \
53     f(GL_RGB16UI) \
54     f(GL_RGB16I) \
55     f(GL_RGB32UI) \
56     f(GL_RGB32I) \
57     f(GL_RGBA8) \
58     f(GL_SRGB8_ALPHA8) \
59     f(GL_RGBA8_SNORM) \
60     f(GL_RGB5_A1) \
61     f(GL_RGBA4) \
62     f(GL_RGB10_A2) \
63     f(GL_RGBA16F) \
64     f(GL_RGBA32F) \
65     f(GL_RGBA8UI) \
66     f(GL_RGBA8I) \
67     f(GL_RGB10_A2UI) \
68     f(GL_RGBA16UI) \
69     f(GL_RGBA16I) \
70     f(GL_RGBA32I) \
71     f(GL_RGBA32UI) \
72     f(GL_DEPTH_COMPONENT16) \
73     f(GL_DEPTH_COMPONENT24) \
74     f(GL_DEPTH_COMPONENT32F) \
75     f(GL_DEPTH24_STENCIL8) \
76     f(GL_DEPTH32F_STENCIL8) \
77     f(GL_ETC1_RGB8_OES) \
78     f(GL_COMPRESSED_R11_EAC) \
79     f(GL_COMPRESSED_SIGNED_R11_EAC) \
80     f(GL_COMPRESSED_RG11_EAC) \
81     f(GL_COMPRESSED_SIGNED_RG11_EAC) \
82     f(GL_COMPRESSED_RGB8_ETC2) \
83     f(GL_COMPRESSED_SRGB8_ETC2) \
84     f(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2) \
85     f(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2) \
86     f(GL_COMPRESSED_RGBA8_ETC2_EAC) \
87     f(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC) \
88     f(GL_COMPRESSED_RGBA_ASTC_4x4_KHR) \
89     f(GL_COMPRESSED_RGBA_ASTC_5x4_KHR) \
90     f(GL_COMPRESSED_RGBA_ASTC_5x5_KHR) \
91     f(GL_COMPRESSED_RGBA_ASTC_6x5_KHR) \
92     f(GL_COMPRESSED_RGBA_ASTC_6x6_KHR) \
93     f(GL_COMPRESSED_RGBA_ASTC_8x5_KHR) \
94     f(GL_COMPRESSED_RGBA_ASTC_8x6_KHR) \
95     f(GL_COMPRESSED_RGBA_ASTC_8x8_KHR) \
96     f(GL_COMPRESSED_RGBA_ASTC_10x5_KHR) \
97     f(GL_COMPRESSED_RGBA_ASTC_10x6_KHR) \
98     f(GL_COMPRESSED_RGBA_ASTC_10x8_KHR) \
99     f(GL_COMPRESSED_RGBA_ASTC_10x10_KHR) \
100     f(GL_COMPRESSED_RGBA_ASTC_12x10_KHR) \
101     f(GL_COMPRESSED_RGBA_ASTC_12x12_KHR) \
102     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR) \
103     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR) \
104     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR) \
105     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR) \
106     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR) \
107     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR) \
108     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR) \
109     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR) \
110     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR) \
111     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR) \
112     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR) \
113     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR) \
114     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR) \
115     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR) \
116     f(GL_COMPRESSED_RGBA_BPTC_UNORM_EXT) \
117     f(GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT) \
118     f(GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT) \
119     f(GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT) \
120     f(GL_COMPRESSED_RGB_S3TC_DXT1_EXT) \
121     f(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) \
122     f(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT) \
123     f(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) \
124     f(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT) \
125     f(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT) \
126     f(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT) \
127     f(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT) \
128     f(GL_COMPRESSED_RED_RGTC1_EXT) \
129     f(GL_COMPRESSED_SIGNED_RED_RGTC1_EXT) \
130     f(GL_COMPRESSED_RED_GREEN_RGTC2_EXT) \
131     f(GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT)
132 
133 #define LIST_VALID_TEX_BUFFER_FORMATS(f) \
134     f(GL_R8) \
135     f(GL_R16F) \
136     f(GL_R32F) \
137     f(GL_R8I) \
138     f(GL_R16I) \
139     f(GL_R32I) \
140     f(GL_R8UI) \
141     f(GL_R16UI) \
142     f(GL_R32UI) \
143     f(GL_RG8) \
144     f(GL_RG16F) \
145     f(GL_RG32F) \
146     f(GL_RG8I) \
147     f(GL_RG16I) \
148     f(GL_RG32I) \
149     f(GL_RG8UI) \
150     f(GL_RG16UI) \
151     f(GL_RG32UI) \
152     f(GL_RGB32F) \
153     f(GL_RGB32I) \
154     f(GL_RGB32UI) \
155     f(GL_RGBA8) \
156     f(GL_RGBA16F) \
157     f(GL_RGBA32F) \
158     f(GL_RGBA8I) \
159     f(GL_RGBA16I) \
160     f(GL_RGBA32I) \
161     f(GL_RGBA8UI) \
162     f(GL_RGBA16UI) \
163     f(GL_RGBA32UI)
164 
165 
166 #define LIST_INTEGER_TEX_FORMATS(f) \
167     f(GL_RED_INTEGER) \
168     f(GL_RG_INTEGER) \
169     f(GL_RGB_INTEGER) \
170     f(GL_RGBA_INTEGER) \
171     f(GL_R8UI) \
172     f(GL_R8I) \
173     f(GL_R16UI) \
174     f(GL_R16I) \
175     f(GL_R32UI) \
176     f(GL_R32I) \
177     f(GL_RG8UI) \
178     f(GL_RG8I) \
179     f(GL_RG16UI) \
180     f(GL_RG16I) \
181     f(GL_RG32UI) \
182     f(GL_RG32I) \
183     f(GL_RGB8UI) \
184     f(GL_RGB8I) \
185     f(GL_RGB16UI) \
186     f(GL_RGB16I) \
187     f(GL_RGB32UI) \
188     f(GL_RGB32I) \
189     f(GL_RGBA8UI) \
190     f(GL_RGBA8I) \
191     f(GL_RGB10_A2UI) \
192     f(GL_RGBA16UI) \
193     f(GL_RGBA16I) \
194     f(GL_RGBA32I) \
195     f(GL_RGBA32UI) \
196 
197 #define LIST_VALID_TEXFORMAT_COMBINATIONS(f) \
198     f(GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE) \
199     f(GL_R8, GL_RED, GL_UNSIGNED_BYTE) \
200     f(GL_R8_SNORM, GL_RED, GL_BYTE) \
201     f(GL_R16F, GL_RED, GL_FLOAT) \
202     f(GL_R16F, GL_RED, GL_HALF_FLOAT) \
203     f(GL_R32F, GL_RED, GL_FLOAT) \
204     f(GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE) \
205     f(GL_R8I, GL_RED_INTEGER, GL_BYTE) \
206     f(GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT) \
207     f(GL_R16I, GL_RED_INTEGER, GL_SHORT) \
208     f(GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT) \
209     f(GL_R32I, GL_RED_INTEGER, GL_INT) \
210     f(GL_RG8, GL_RG, GL_UNSIGNED_BYTE) \
211     f(GL_RG8_SNORM, GL_RG, GL_BYTE) \
212     f(GL_RG16F, GL_RG, GL_HALF_FLOAT) \
213     f(GL_RG16F, GL_RG, GL_FLOAT) \
214     f(GL_RG32F, GL_RG, GL_FLOAT) \
215     f(GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE) \
216     f(GL_RG8I, GL_RG_INTEGER, GL_BYTE) \
217     f(GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT) \
218     f(GL_RG16I, GL_RG_INTEGER, GL_SHORT) \
219     f(GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT) \
220     f(GL_RG32I, GL_RG_INTEGER, GL_INT) \
221     f(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE) \
222     f(GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE) \
223     f(GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE) \
224     f(GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5) \
225     f(GL_RGB8_SNORM, GL_RGB, GL_BYTE) \
226     f(GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV) \
227     f(GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT) \
228     f(GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT) \
229     f(GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV) \
230     f(GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT) \
231     f(GL_RGB9_E5, GL_RGB, GL_FLOAT) \
232     f(GL_RGB16F, GL_RGB, GL_HALF_FLOAT) \
233     f(GL_RGB16F, GL_RGB, GL_FLOAT) \
234     f(GL_RGB32F, GL_RGB, GL_FLOAT) \
235     f(GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE) \
236     f(GL_RGB8I, GL_RGB_INTEGER, GL_BYTE) \
237     f(GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT) \
238     f(GL_RGB16I, GL_RGB_INTEGER, GL_SHORT) \
239     f(GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT) \
240     f(GL_RGB32I, GL_RGB_INTEGER, GL_INT) \
241     f(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE) \
242     f(GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE) \
243     f(GL_RGBA8_SNORM, GL_RGBA, GL_BYTE) \
244     f(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE) \
245     f(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1) \
246     f(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV) \
247     f(GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE) \
248     f(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4) \
249     f(GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV) \
250     f(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT) \
251     f(GL_RGBA16F, GL_RGBA, GL_FLOAT) \
252     f(GL_RGBA32F, GL_RGBA, GL_FLOAT) \
253     f(GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE) \
254     f(GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE) \
255     f(GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV) \
256     f(GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT) \
257     f(GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT) \
258     f(GL_RGBA32I, GL_RGBA_INTEGER, GL_INT) \
259     f(GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT) \
260     f(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT) \
261     f(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT) \
262     f(GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT) \
263     f(GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT) \
264     f(GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8) \
265     f(GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV) \
266     f(GL_COMPRESSED_R11_EAC, GL_RED, GL_FLOAT) \
267     f(GL_COMPRESSED_SIGNED_R11_EAC, GL_RED, GL_FLOAT) \
268     f(GL_COMPRESSED_RG11_EAC, GL_RG, GL_FLOAT) \
269     f(GL_COMPRESSED_SIGNED_RG11_EAC, GL_RG, GL_FLOAT) \
270     f(GL_COMPRESSED_RGB8_ETC2, GL_RGB, GL_UNSIGNED_BYTE) \
271     f(GL_COMPRESSED_SRGB8_ETC2, GL_RGB, GL_UNSIGNED_BYTE) \
272     f(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_RGBA, GL_UNSIGNED_BYTE) \
273     f(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_RGBA, GL_UNSIGNED_BYTE) \
274     f(GL_COMPRESSED_RGBA8_ETC2_EAC, GL_RGBA, GL_UNSIGNED_BYTE) \
275     f(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_RGBA, GL_UNSIGNED_BYTE) \
276     f(GL_COMPRESSED_RGBA_ASTC_4x4_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
277     f(GL_COMPRESSED_RGBA_ASTC_5x4_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
278     f(GL_COMPRESSED_RGBA_ASTC_5x5_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
279     f(GL_COMPRESSED_RGBA_ASTC_6x5_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
280     f(GL_COMPRESSED_RGBA_ASTC_6x6_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
281     f(GL_COMPRESSED_RGBA_ASTC_8x5_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
282     f(GL_COMPRESSED_RGBA_ASTC_8x6_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
283     f(GL_COMPRESSED_RGBA_ASTC_8x8_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
284     f(GL_COMPRESSED_RGBA_ASTC_10x5_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
285     f(GL_COMPRESSED_RGBA_ASTC_10x6_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
286     f(GL_COMPRESSED_RGBA_ASTC_10x8_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
287     f(GL_COMPRESSED_RGBA_ASTC_10x10_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
288     f(GL_COMPRESSED_RGBA_ASTC_12x10_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
289     f(GL_COMPRESSED_RGBA_ASTC_12x12_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
290     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
291     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
292     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
293     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
294     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
295     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
296     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
297     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
298     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
299     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
300     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
301     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
302     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
303     f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
304     f(GL_COMPRESSED_RGBA_BPTC_UNORM_EXT, GL_RGBA, GL_UNSIGNED_BYTE) \
305     f(GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT, GL_RGBA, GL_UNSIGNED_BYTE) \
306     f(GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT, GL_RGB, GL_UNSIGNED_BYTE) \
307     f(GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, GL_RGB, GL_UNSIGNED_BYTE) \
308     f(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_RGB, GL_UNSIGNED_BYTE) \
309     f(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_RGBA, GL_UNSIGNED_BYTE) \
310     f(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_RGBA, GL_UNSIGNED_BYTE) \
311     f(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_RGBA, GL_UNSIGNED_BYTE) \
312     f(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, GL_RGBA, GL_UNSIGNED_BYTE) \
313     f(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, GL_RGBA, GL_UNSIGNED_BYTE) \
314     f(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, GL_RGBA, GL_UNSIGNED_BYTE) \
315     f(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, GL_RGBA, GL_UNSIGNED_BYTE) \
316     f(GL_COMPRESSED_RED_RGTC1_EXT, GL_RED, GL_UNSIGNED_BYTE) \
317     f(GL_COMPRESSED_SIGNED_RED_RGTC1_EXT, GL_RED, GL_BYTE) \
318     f(GL_COMPRESSED_RED_GREEN_RGTC2_EXT, GL_RG, GL_UNSIGNED_BYTE) \
319     f(GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT, GL_RG, GL_BYTE)
320 
321 
322 
323 namespace GLESv2Validation {
324 
325 GLbitfield allBufferMapAccessFlags =
326     GL_MAP_READ_BIT | GL_MAP_WRITE_BIT |
327     GL_MAP_INVALIDATE_RANGE_BIT |
328     GL_MAP_INVALIDATE_BUFFER_BIT |
329     GL_MAP_FLUSH_EXPLICIT_BIT |
330     GL_MAP_UNSYNCHRONIZED_BIT;
331 
bufferTarget(GL2Encoder * ctx,GLenum target)332 bool bufferTarget(GL2Encoder* ctx, GLenum target) {
333     int glesMajorVersion = ctx->majorVersion();
334     int glesMinorVersion = ctx->minorVersion();
335     switch (target) {
336     case GL_ARRAY_BUFFER: // Vertex attributes
337     case GL_ELEMENT_ARRAY_BUFFER: // Vertex array indices
338         return true;
339         // GLES 3.0 buffers
340     case GL_COPY_READ_BUFFER: // Buffer copy source
341     case GL_COPY_WRITE_BUFFER: // Buffer copy destination
342     case GL_PIXEL_PACK_BUFFER: // Pixel read target
343     case GL_PIXEL_UNPACK_BUFFER: // Texture data source
344     case GL_TRANSFORM_FEEDBACK_BUFFER: // Transform feedback buffer
345     case GL_UNIFORM_BUFFER: // Uniform block storage
346         return glesMajorVersion >= 3;
347         // GLES 3.1 buffers
348     case GL_ATOMIC_COUNTER_BUFFER: // Atomic counter storage
349     case GL_DISPATCH_INDIRECT_BUFFER: // Indirect compute dispatch commands
350     case GL_DRAW_INDIRECT_BUFFER: // Indirect command arguments
351     case GL_SHADER_STORAGE_BUFFER: // Read-write storage for shader
352         return glesMajorVersion >= 3 && glesMinorVersion >= 1;
353     case GL_TEXTURE_BUFFER_OES:
354         return ctx->es32Plus() || ctx->getExtensions().textureBufferAny();
355     default:
356         return false;
357     }
358 }
359 
bufferParam(GL2Encoder * ctx,GLenum pname)360 bool bufferParam(GL2Encoder* ctx, GLenum pname) {
361     int glesMajorVersion = ctx->majorVersion();
362     switch (pname) {
363     case GL_BUFFER_SIZE:
364     case GL_BUFFER_USAGE:
365         return true;
366     case GL_BUFFER_ACCESS_FLAGS:
367     case GL_BUFFER_MAPPED:
368     case GL_BUFFER_MAP_LENGTH:
369     case GL_BUFFER_MAP_OFFSET:
370         return glesMajorVersion >= 3;
371     default:
372         return false;
373     }
374 }
375 
bufferUsage(GL2Encoder * ctx,GLenum usage)376 bool bufferUsage(GL2Encoder* ctx, GLenum usage) {
377     int glesMajorVersion = ctx->majorVersion();
378     switch(usage) {
379         case GL_STREAM_DRAW:
380         case GL_STATIC_DRAW:
381         case GL_DYNAMIC_DRAW:
382             return true;
383         case GL_STREAM_READ:
384         case GL_STATIC_READ:
385         case GL_DYNAMIC_READ:
386         case GL_STREAM_COPY:
387         case GL_STATIC_COPY:
388         case GL_DYNAMIC_COPY:
389             return glesMajorVersion >= 3;
390     }
391     return false;
392 
393 }
pixelStoreParam(GL2Encoder * ctx,GLenum param)394 bool pixelStoreParam(GL2Encoder* ctx, GLenum param) {
395     int glesMajorVersion = ctx->majorVersion();
396     switch(param) {
397     case GL_UNPACK_ALIGNMENT:
398     case GL_PACK_ALIGNMENT:
399         return true;
400     case GL_UNPACK_ROW_LENGTH:
401     case GL_UNPACK_IMAGE_HEIGHT:
402     case GL_UNPACK_SKIP_PIXELS:
403     case GL_UNPACK_SKIP_ROWS:
404     case GL_UNPACK_SKIP_IMAGES:
405     case GL_PACK_ROW_LENGTH:
406     case GL_PACK_SKIP_PIXELS:
407     case GL_PACK_SKIP_ROWS:
408         return glesMajorVersion >= 3;
409     default:
410         return false;
411     }
412 }
413 
pixelStoreValue(GLenum param,GLint value)414 bool pixelStoreValue(GLenum param, GLint value) {
415     switch(param) {
416     case GL_UNPACK_ALIGNMENT:
417     case GL_PACK_ALIGNMENT:
418         return (value == 1) || (value == 2) || (value == 4) || (value == 8);
419     case GL_UNPACK_ROW_LENGTH:
420     case GL_UNPACK_IMAGE_HEIGHT:
421     case GL_UNPACK_SKIP_PIXELS:
422     case GL_UNPACK_SKIP_ROWS:
423     case GL_UNPACK_SKIP_IMAGES:
424     case GL_PACK_ROW_LENGTH:
425     case GL_PACK_SKIP_PIXELS:
426     case GL_PACK_SKIP_ROWS:
427         return value >= 0;
428     default:
429         return false;
430     }
431 }
432 
rboFormat(GL2Encoder * ctx,GLenum internalformat)433 bool rboFormat(GL2Encoder* ctx, GLenum internalformat) {
434     int glesMajorVersion = ctx->majorVersion();
435 
436     switch (internalformat) {
437     // Funny internal formats
438     // that will cause an incomplete framebuffer
439     // attachment error pre-gles3. For dEQP,
440     // we can also just abort early here in
441     // RenderbufferStorage with a GL_INVALID_ENUM.
442     case GL_DEPTH_COMPONENT32F:
443     case GL_R8:
444     case GL_R8UI:
445     case GL_R8I:
446     case GL_R16UI:
447     case GL_R16I:
448     case GL_R32UI:
449     case GL_R32I:
450     case GL_RG8:
451     case GL_RG8UI:
452     case GL_RG8I:
453     case GL_RG16UI:
454     case GL_RG16I:
455     case GL_RG32UI:
456     case GL_RG32I:
457     case GL_SRGB8_ALPHA8:
458     case GL_RGBA8UI:
459     case GL_RGBA8I:
460     case GL_RGB10_A2:
461     case GL_RGB10_A2UI:
462     case GL_RGBA16UI:
463     case GL_RGBA16I:
464     case GL_RGBA32I:
465     case GL_RGBA32UI:
466     case GL_RGB32F:
467         return glesMajorVersion >= 3;
468         // These 4 formats are still not OK,
469         // but dEQP expects GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT or
470         // GL_FRAMEBUFFER_UNSUPPORTED if the extension is not present,
471         // not a GL_INVALID_ENUM from earlier on.
472         // So let's forward these to the rest of
473         // FBO initialization
474         // In GLES 3, these are rejected immediately if not
475         // supported.
476     case GL_R16F:
477     case GL_RG16F:
478     case GL_RGBA16F:
479     case GL_R32F:
480     case GL_RG32F:
481     case GL_RGBA32F:
482     case GL_R11F_G11F_B10F:
483         return glesMajorVersion >= 3 && ctx->hasExtension("GL_EXT_color_buffer_float");
484     case GL_RGB16F:
485         return glesMajorVersion >= 3 && ctx->hasExtension("GL_EXT_color_buffer_half_float");
486         // dEQP expects GL_FRAMEBUFFER_UNSUPPORTED or GL_FRAMEBUFFER_COMPLETE
487         // for this format
488         // These formats are OK
489     case GL_DEPTH_COMPONENT16:
490     case GL_DEPTH_COMPONENT24:
491     case GL_DEPTH_COMPONENT32_OES:
492     case GL_RGBA4:
493     case GL_RGB5_A1:
494     case GL_RGB565:
495     case GL_RGB8_OES:
496     case GL_RGBA8_OES:
497     case GL_STENCIL_INDEX8:
498     case GL_DEPTH32F_STENCIL8:
499     case GL_DEPTH24_STENCIL8_OES:
500         return true;
501         break;
502         // Everything else: still not OK,
503         // and they need the GL_INVALID_ENUM
504     }
505     return false;
506 }
507 
framebufferTarget(GL2Encoder * ctx,GLenum target)508 bool framebufferTarget(GL2Encoder* ctx, GLenum target) {
509     int glesMajorVersion = ctx->majorVersion();
510     switch (target) {
511     case GL_FRAMEBUFFER:
512         return true;
513     case GL_DRAW_FRAMEBUFFER:
514     case GL_READ_FRAMEBUFFER:
515         return glesMajorVersion >= 3;
516     }
517     return false;
518 }
519 
framebufferAttachment(GL2Encoder * ctx,GLenum attachment)520 bool framebufferAttachment(GL2Encoder* ctx, GLenum attachment) {
521     int glesMajorVersion = ctx->majorVersion();
522     switch (attachment) {
523     case GL_COLOR_ATTACHMENT0:
524     case GL_DEPTH_ATTACHMENT:
525     case GL_STENCIL_ATTACHMENT:
526         return true;
527     case GL_COLOR_ATTACHMENT1:
528     case GL_COLOR_ATTACHMENT2:
529     case GL_COLOR_ATTACHMENT3:
530     case GL_COLOR_ATTACHMENT4:
531     case GL_COLOR_ATTACHMENT5:
532     case GL_COLOR_ATTACHMENT6:
533     case GL_COLOR_ATTACHMENT7:
534     case GL_COLOR_ATTACHMENT8:
535     case GL_COLOR_ATTACHMENT9:
536     case GL_COLOR_ATTACHMENT10:
537     case GL_COLOR_ATTACHMENT11:
538     case GL_COLOR_ATTACHMENT12:
539     case GL_COLOR_ATTACHMENT13:
540     case GL_COLOR_ATTACHMENT14:
541     case GL_COLOR_ATTACHMENT15:
542     case GL_DEPTH_STENCIL_ATTACHMENT:
543         return glesMajorVersion >= 3;
544     }
545     return false;
546 }
547 
readPixelsFormat(GLenum format)548 bool readPixelsFormat(GLenum format) {
549     switch (format) {
550     case GL_RED:
551     case GL_RED_INTEGER:
552     case GL_RG:
553     case GL_RG_INTEGER:
554     case GL_RGB:
555     case GL_RGB_INTEGER:
556     case GL_RGBA:
557     case GL_RGBA_INTEGER:
558     case GL_LUMINANCE_ALPHA:
559     case GL_LUMINANCE:
560     case GL_ALPHA:
561         return true;
562     }
563     return false;
564 }
565 
readPixelsType(GLenum format)566 bool readPixelsType(GLenum format) {
567     switch (format) {
568     case GL_UNSIGNED_BYTE:
569     case GL_BYTE:
570     case GL_HALF_FLOAT:
571     case GL_FLOAT:
572     case GL_INT:
573     case GL_UNSIGNED_SHORT_5_6_5:
574     case GL_UNSIGNED_SHORT_4_4_4_4:
575     case GL_UNSIGNED_SHORT_5_5_5_1:
576     case GL_UNSIGNED_INT:
577     case GL_UNSIGNED_INT_2_10_10_10_REV:
578     case GL_UNSIGNED_INT_10F_11F_11F_REV:
579     case GL_UNSIGNED_INT_5_9_9_9_REV:
580         return true;
581     }
582     return false;
583 }
584 
pixelOp(GLenum format,GLenum type)585 bool pixelOp(GLenum format,GLenum type) {
586      switch(type) {
587      case GL_UNSIGNED_SHORT_4_4_4_4:
588      case GL_UNSIGNED_SHORT_5_5_5_1:
589          return format == GL_RGBA;
590      case GL_UNSIGNED_SHORT_5_6_5:
591          return format == GL_RGB;
592      }
593      return true;
594 }
595 
vertexAttribType(GL2Encoder * ctx,GLenum type)596 bool vertexAttribType(GL2Encoder* ctx, GLenum type)
597 {
598     int glesMajorVersion = ctx->majorVersion();
599     bool retval = false;
600     switch (type) {
601     case GL_BYTE:
602     case GL_UNSIGNED_BYTE:
603     case GL_SHORT:
604     case GL_UNSIGNED_SHORT:
605     case GL_FIXED:
606     case GL_FLOAT:
607     // The following are technically only available if certain GLES2 extensions are.
608     // However, they are supported by desktop GL3, which is a reasonable requirement
609     // for the desktop GL version. Therefore, consider them valid.
610     case GL_INT:
611     case GL_UNSIGNED_INT:
612     case GL_HALF_FLOAT_OES:
613         retval = true;
614         break;
615     case GL_HALF_FLOAT:
616     case GL_INT_2_10_10_10_REV:
617     case GL_UNSIGNED_INT_2_10_10_10_REV:
618         retval = glesMajorVersion >= 3;
619         break;
620     }
621     return retval;
622 }
623 
readPixelsFboFormatMatch(GLenum,GLenum type,GLenum fboTexType)624 bool readPixelsFboFormatMatch(GLenum, GLenum type, GLenum fboTexType) {
625 #define INVALID_TYPE_MATCH(x, y) \
626     if (type == x && fboTexType == y) return false; \
627     if (type == y && fboTexType == x) return false; \
628 
629     // These are meant to reject additional format/type mismatches
630     // not caught by underlying system.
631     INVALID_TYPE_MATCH(GL_FLOAT, GL_BYTE)
632     INVALID_TYPE_MATCH(GL_FLOAT, GL_UNSIGNED_BYTE)
633     INVALID_TYPE_MATCH(GL_FLOAT, GL_UNSIGNED_INT)
634     INVALID_TYPE_MATCH(GL_FLOAT, GL_INT)
635 
636     return true;
637 }
638 
blitFramebufferFormat(GLenum readFormat,GLenum drawFormat)639 bool blitFramebufferFormat(GLenum readFormat, GLenum drawFormat) {
640 #define INVALID_MATCH(x, y) \
641     if (readFormat == x && drawFormat == y) return false; \
642     if (readFormat == y && drawFormat == x) return false; \
643 
644     INVALID_MATCH(GL_FLOAT, GL_BYTE)
645     INVALID_MATCH(GL_FLOAT, GL_UNSIGNED_BYTE)
646     INVALID_MATCH(GL_FLOAT, GL_UNSIGNED_INT)
647     INVALID_MATCH(GL_FLOAT, GL_INT)
648     INVALID_MATCH(GL_INT, GL_UNSIGNED_BYTE);
649     INVALID_MATCH(GL_UNSIGNED_INT, GL_UNSIGNED_BYTE);
650     INVALID_MATCH(GL_INT, GL_BYTE);
651     INVALID_MATCH(GL_UNSIGNED_INT, GL_BYTE);
652     INVALID_MATCH(GL_DEPTH32F_STENCIL8, GL_DEPTH24_STENCIL8);
653 
654     return true;
655 }
656 
textureTarget(GL2Encoder * ctx,GLenum target)657 bool textureTarget(GL2Encoder* ctx, GLenum target) {
658     int glesMajorVersion = ctx->majorVersion();
659     int glesMinorVersion = ctx->minorVersion();
660     switch (target) {
661     case GL_TEXTURE_EXTERNAL_OES:
662     case GL_TEXTURE_2D:
663     case GL_TEXTURE_CUBE_MAP:
664     case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
665     case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
666     case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
667     case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
668     case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
669     case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
670         return true;
671     case GL_TEXTURE_2D_ARRAY:
672     case GL_TEXTURE_3D:
673         return glesMajorVersion >= 3;
674     case GL_TEXTURE_2D_MULTISAMPLE:
675         return glesMajorVersion >= 3 && glesMinorVersion >= 1;
676     case GL_TEXTURE_BUFFER_OES:
677         return  ctx->es32Plus() || ctx->getExtensions().textureBufferAny();
678     default:
679         break;
680     }
681     return false;
682 }
683 
textureParams(GL2Encoder * ctx,GLenum param)684 bool textureParams(GL2Encoder* ctx, GLenum param) {
685     int glesMajorVersion = ctx->majorVersion();
686     int glesMinorVersion = ctx->minorVersion();
687     switch(param) {
688     case GL_TEXTURE_MIN_FILTER:
689     case GL_TEXTURE_MAG_FILTER:
690     case GL_TEXTURE_WRAP_S:
691     case GL_TEXTURE_WRAP_T:
692     case GL_TEXTURE_MAX_ANISOTROPY_EXT:
693         return true;
694     case GL_TEXTURE_SWIZZLE_R:
695     case GL_TEXTURE_SWIZZLE_G:
696     case GL_TEXTURE_SWIZZLE_B:
697     case GL_TEXTURE_SWIZZLE_A:
698     case GL_TEXTURE_MIN_LOD:
699     case GL_TEXTURE_MAX_LOD:
700     case GL_TEXTURE_BASE_LEVEL:
701     case GL_TEXTURE_MAX_LEVEL:
702     case GL_TEXTURE_COMPARE_MODE:
703     case GL_TEXTURE_COMPARE_FUNC:
704     case GL_TEXTURE_WRAP_R:
705     case GL_TEXTURE_IMMUTABLE_FORMAT:
706     case GL_TEXTURE_IMMUTABLE_LEVELS:
707         return glesMajorVersion >= 3;
708     case GL_DEPTH_STENCIL_TEXTURE_MODE:
709         return glesMajorVersion >= 3 && glesMinorVersion >= 1;
710     default:
711         return false;
712     }
713 }
714 
samplerParams(GL2Encoder * ctx,GLenum param)715 bool samplerParams(GL2Encoder* ctx, GLenum param) {
716     (void)ctx;
717     switch(param) {
718         case GL_TEXTURE_MAX_ANISOTROPY_EXT:
719         case GL_TEXTURE_MIN_FILTER:
720         case GL_TEXTURE_MAG_FILTER:
721         case GL_TEXTURE_WRAP_S:
722         case GL_TEXTURE_WRAP_T:
723         case GL_TEXTURE_WRAP_R:
724         case GL_TEXTURE_MIN_LOD:
725         case GL_TEXTURE_MAX_LOD:
726         case GL_TEXTURE_COMPARE_MODE:
727         case GL_TEXTURE_COMPARE_FUNC:
728             return true;
729         default:
730             return false;
731     }
732 }
733 
textureParamValue(GL2Encoder * ctx,GLenum pname,GLint intval,GLfloat floatval,GLenum enumval)734 bool textureParamValue(GL2Encoder* ctx, GLenum pname, GLint intval, GLfloat floatval, GLenum enumval) {
735     (void)ctx;
736     (void)floatval;
737     switch (pname) {
738     case GL_TEXTURE_BASE_LEVEL:
739         return intval >= 0;
740     case GL_TEXTURE_COMPARE_MODE:
741         return
742             (enumval == GL_NONE) ||
743             (enumval == GL_COMPARE_REF_TO_TEXTURE);
744     case GL_TEXTURE_COMPARE_FUNC:
745         return
746             (enumval == GL_LEQUAL) ||
747             (enumval == GL_GEQUAL) ||
748             (enumval == GL_LESS) ||
749             (enumval == GL_GREATER) ||
750             (enumval == GL_EQUAL) ||
751             (enumval == GL_NOTEQUAL) ||
752             (enumval == GL_ALWAYS) ||
753             (enumval == GL_NEVER);
754     case GL_TEXTURE_MAG_FILTER:
755         return
756             (enumval == GL_NEAREST) ||
757             (enumval == GL_LINEAR);
758     case GL_TEXTURE_MAX_LEVEL:
759         return intval >= 0;
760     case GL_TEXTURE_MAX_LOD:
761         return true;
762     case GL_TEXTURE_MIN_FILTER:
763         return
764             (enumval == GL_NEAREST) ||
765             (enumval == GL_LINEAR) ||
766             (enumval == GL_NEAREST_MIPMAP_NEAREST) ||
767             (enumval == GL_NEAREST_MIPMAP_LINEAR) ||
768             (enumval == GL_LINEAR_MIPMAP_NEAREST) ||
769             (enumval == GL_LINEAR_MIPMAP_LINEAR);
770     case GL_TEXTURE_MIN_LOD:
771         return true;
772     case GL_TEXTURE_SWIZZLE_R:
773     case GL_TEXTURE_SWIZZLE_G:
774     case GL_TEXTURE_SWIZZLE_B:
775     case GL_TEXTURE_SWIZZLE_A:
776         return
777             (enumval == GL_RED) ||
778             (enumval == GL_GREEN) ||
779             (enumval == GL_BLUE) ||
780             (enumval == GL_ALPHA) ||
781             (enumval == GL_ZERO) ||
782             (enumval == GL_ONE);
783     case GL_TEXTURE_WRAP_S:
784     case GL_TEXTURE_WRAP_T:
785     case GL_TEXTURE_WRAP_R:
786         return
787             (enumval == GL_CLAMP_TO_EDGE) ||
788             (enumval == GL_REPEAT) ||
789             (enumval == GL_MIRRORED_REPEAT);
790     case GL_TEXTURE_MAX_ANISOTROPY_EXT:
791         return true;
792     case GL_TEXTURE_IMMUTABLE_FORMAT:
793     case GL_TEXTURE_IMMUTABLE_LEVELS:
794     case GL_DEPTH_STENCIL_TEXTURE_MODE:
795         return true;
796     default:
797         return true;
798     }
799 }
800 
isIntegerFormat(GLenum format)801 bool isIntegerFormat(GLenum format) {
802 
803 #define CHECK_EQUAL(x) case x: return true;
804 
805     switch (format) {
806         LIST_INTEGER_TEX_FORMATS(CHECK_EQUAL)
807 
808     default:
809         return false;
810     }
811 }
812 
isCompressedFormat(GLenum internalformat)813 bool isCompressedFormat(GLenum internalformat) {
814 #define COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(internal) \
815     case internal: \
816         return true; \
817 
818     switch (internalformat) {
819     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_R11_EAC)
820     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SIGNED_R11_EAC)
821     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_RG11_EAC)
822     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SIGNED_RG11_EAC)
823     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_RGB8_ETC2)
824     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SRGB8_ETC2)
825     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2)
826     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2)
827     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_RGBA8_ETC2_EAC)
828     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC)
829     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_RGBA_ASTC_4x4_KHR)
830     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_RGBA_ASTC_5x4_KHR)
831     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_RGBA_ASTC_5x5_KHR)
832     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_RGBA_ASTC_6x5_KHR)
833     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_RGBA_ASTC_6x6_KHR)
834     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_RGBA_ASTC_8x5_KHR)
835     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_RGBA_ASTC_8x6_KHR)
836     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_RGBA_ASTC_8x8_KHR)
837     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_RGBA_ASTC_10x5_KHR)
838     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_RGBA_ASTC_10x6_KHR)
839     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_RGBA_ASTC_10x8_KHR)
840     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_RGBA_ASTC_10x10_KHR)
841     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_RGBA_ASTC_12x10_KHR)
842     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_RGBA_ASTC_12x12_KHR)
843     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR)
844     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR)
845     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR)
846     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR)
847     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR)
848     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR)
849     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR)
850     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR)
851     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR)
852     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR)
853     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR)
854     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR)
855     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR)
856     COMPRESSED_TEX_IMAGE_IS_COMPRESSED_FORMAT_CASE(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR)
857     default:
858         break;
859     }
860     return false;
861 }
862 
supportedCompressedFormat(GL2Encoder * ctx,GLenum internalformat)863 bool supportedCompressedFormat(GL2Encoder* ctx, GLenum internalformat) {
864     int glesMajorVersion = ctx->majorVersion();
865     int glesMinorVersion = ctx->minorVersion();
866 
867 #define COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(internal) \
868     case internal: \
869         return glesMajorVersion > 1 && ctx->hasExtension("GL_KHR_texture_compression_astc_ldr"); \
870 
871 #define COMPRESSED_TEX_IMAGE_SUPPORT_CASE_BPTC(internal) \
872     case internal: \
873         return glesMajorVersion > 1 && ctx->hasExtension("GL_EXT_texture_compression_bptc"); \
874 
875 #define COMPRESSED_TEX_IMAGE_SUPPORT_CASE_S3TC(internal) \
876     case internal: \
877       return glesMajorVersion > 1 && ctx->hasExtension("GL_EXT_texture_compression_s3tc"); \
878 
879 #define COMPRESSED_TEX_IMAGE_SUPPORT_CASE_S3TC_SRGB(internal)       \
880     case internal: \
881       return glesMajorVersion > 1 && ctx->hasExtension("GL_EXT_texture_compression_s3tc") && ctx->hasExtension("GL_EXT_texture_sRGB"); \
882 
883 #define COMPRESSED_TEX_IMAGE_SUPPORT_CASE_RGTC(internal) \
884     case internal: \
885       return glesMajorVersion > 1 && ctx->hasExtension("GL_EXT_texture_compression_rgtc"); \
886 
887 #define COMPRESSED_TEX_IMAGE_SUPPORT_CASE(internal, maj, min) \
888     case internal: \
889         if (maj < 3) return true; \
890         if (glesMajorVersion < maj) return false; \
891         if (glesMinorVersion < min) return false; \
892         break; \
893 
894 #define COMPRESSED_TEX_IMAGE_NOTSUPPORTED(internal) \
895     case internal: \
896         return false ; \
897 
898     switch (internalformat) {
899     COMPRESSED_TEX_IMAGE_SUPPORT_CASE(GL_ETC1_RGB8_OES, 2, 0)
900     COMPRESSED_TEX_IMAGE_SUPPORT_CASE(GL_COMPRESSED_R11_EAC, 2, 0)
901     COMPRESSED_TEX_IMAGE_SUPPORT_CASE(GL_COMPRESSED_SIGNED_R11_EAC, 2, 0)
902     COMPRESSED_TEX_IMAGE_SUPPORT_CASE(GL_COMPRESSED_RG11_EAC, 2, 0)
903     COMPRESSED_TEX_IMAGE_SUPPORT_CASE(GL_COMPRESSED_SIGNED_RG11_EAC, 2, 0)
904     COMPRESSED_TEX_IMAGE_SUPPORT_CASE(GL_COMPRESSED_RGB8_ETC2, 2, 0)
905     COMPRESSED_TEX_IMAGE_SUPPORT_CASE(GL_COMPRESSED_SRGB8_ETC2, 2, 0)
906     COMPRESSED_TEX_IMAGE_SUPPORT_CASE(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 2, 0)
907     COMPRESSED_TEX_IMAGE_SUPPORT_CASE(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 2, 0)
908     COMPRESSED_TEX_IMAGE_SUPPORT_CASE(GL_COMPRESSED_RGBA8_ETC2_EAC, 2, 0)
909     COMPRESSED_TEX_IMAGE_SUPPORT_CASE(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, 2, 0)
910     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_RGBA_ASTC_4x4_KHR)
911     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_RGBA_ASTC_5x4_KHR)
912     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_RGBA_ASTC_5x5_KHR)
913     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_RGBA_ASTC_6x5_KHR)
914     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_RGBA_ASTC_6x6_KHR)
915     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_RGBA_ASTC_8x5_KHR)
916     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_RGBA_ASTC_8x6_KHR)
917     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_RGBA_ASTC_8x8_KHR)
918     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_RGBA_ASTC_10x5_KHR)
919     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_RGBA_ASTC_10x6_KHR)
920     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_RGBA_ASTC_10x8_KHR)
921     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_RGBA_ASTC_10x10_KHR)
922     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_RGBA_ASTC_12x10_KHR)
923     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_RGBA_ASTC_12x12_KHR)
924     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR)
925     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR)
926     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR)
927     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR)
928     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR)
929     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR)
930     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR)
931     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR)
932     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR)
933     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR)
934     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR)
935     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR)
936     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR)
937     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_ASTC(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR)
938     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_BPTC(GL_COMPRESSED_RGBA_BPTC_UNORM_EXT)
939     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_BPTC(GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT)
940     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_BPTC(GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT)
941     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_BPTC(GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT)
942     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_S3TC(GL_COMPRESSED_RGB_S3TC_DXT1_EXT)
943     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_S3TC(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)
944     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_S3TC(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT)
945     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_S3TC(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
946     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_S3TC(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT)
947     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_S3TC_SRGB(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT)
948     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_S3TC_SRGB(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT)
949     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_S3TC_SRGB(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT)
950     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_RGTC(GL_COMPRESSED_RED_RGTC1_EXT)
951     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_RGTC(GL_COMPRESSED_SIGNED_RED_RGTC1_EXT)
952     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_RGTC(GL_COMPRESSED_RED_GREEN_RGTC2_EXT)
953     COMPRESSED_TEX_IMAGE_SUPPORT_CASE_RGTC(GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT)
954     default:
955         break;
956     }
957     return false;
958 }
959 
unsizedFormat(GLenum format)960 bool unsizedFormat(GLenum format) {
961     switch (format) {
962     case GL_RED:
963     case GL_RED_INTEGER:
964     case GL_DEPTH_COMPONENT:
965     case GL_DEPTH_STENCIL:
966     case GL_RG:
967     case GL_RG_INTEGER:
968     case GL_RGB:
969     case GL_RGB_INTEGER:
970     case GL_RGBA:
971     case GL_RGBA_INTEGER:
972     case GL_ALPHA:
973     case GL_LUMINANCE:
974     case GL_LUMINANCE_ALPHA:
975         return true;
976     }
977     return false;
978 }
979 
980 // TODO: fix this
filterableTexFormat(GL2Encoder * ctx,GLenum internalformat)981 bool filterableTexFormat(GL2Encoder* ctx, GLenum internalformat) {
982     switch (internalformat) {
983     case GL_R32F:
984     case GL_RG32F:
985     case GL_RGB32F:
986     case GL_RGBA32F:
987         return ctx->hasExtension("GL_OES_texture_float");
988     case GL_R8UI:
989     case GL_R8I:
990     case GL_R16UI:
991     case GL_R16I:
992     case GL_R32UI:
993     case GL_R32I:
994     case GL_RG8UI:
995     case GL_RG8I:
996     case GL_RG16UI:
997     case GL_RG16I:
998     case GL_RG32UI:
999     case GL_RG32I:
1000     case GL_RGBA8UI:
1001     case GL_RGBA8I:
1002     case GL_RGB10_A2UI:
1003     case GL_RGBA16UI:
1004     case GL_RGBA16I:
1005     case GL_RGBA32I:
1006     case GL_RGBA32UI:
1007         return false;
1008     }
1009     return true;
1010 }
1011 
1012 
colorRenderableFormat(GL2Encoder * ctx,GLenum internalformat)1013 bool colorRenderableFormat(GL2Encoder* ctx, GLenum internalformat) {
1014     int glesMajorVersion = ctx->majorVersion();
1015     switch (internalformat) {
1016     case GL_R8:
1017     case GL_RG8:
1018     case GL_RGB8:
1019     case GL_RGB565:
1020     case GL_RGBA4:
1021     case GL_RGB5_A1:
1022     case GL_RGBA8:
1023     case GL_RGB10_A2:
1024     case GL_RGB10_A2UI:
1025     case GL_SRGB8_ALPHA8:
1026     case GL_R8I:
1027     case GL_R8UI:
1028     case GL_R16I:
1029     case GL_R16UI:
1030     case GL_R32I:
1031     case GL_R32UI:
1032     case GL_RG8I:
1033     case GL_RG8UI:
1034     case GL_RG16I:
1035     case GL_RG16UI:
1036     case GL_RG32I:
1037     case GL_RG32UI:
1038     case GL_RGBA8I:
1039     case GL_RGBA8UI:
1040     case GL_RGBA16I:
1041     case GL_RGBA16UI:
1042     case GL_RGBA32I:
1043     case GL_RGBA32UI:
1044         return true;
1045     case GL_R16F:
1046     case GL_RG16F:
1047     case GL_RGBA16F:
1048     case GL_R32F:
1049     case GL_RG32F:
1050     case GL_RGBA32F:
1051     case GL_R11F_G11F_B10F:
1052         return glesMajorVersion >= 3 && ctx->hasExtension("GL_EXT_color_buffer_float");
1053         break;
1054     case GL_RGB16F:
1055         return glesMajorVersion >= 3 && ctx->hasExtension("GL_EXT_color_buffer_half_float");
1056         break;
1057     }
1058     return false;
1059 }
1060 
depthRenderableFormat(GL2Encoder * ctx,GLenum internalformat)1061 bool depthRenderableFormat(GL2Encoder* ctx, GLenum internalformat) {
1062     switch (internalformat) {
1063     case GL_DEPTH_COMPONENT:
1064     case GL_DEPTH_STENCIL:
1065     case GL_DEPTH_COMPONENT16:
1066     case GL_DEPTH_COMPONENT24:
1067     case GL_DEPTH_COMPONENT32F:
1068     case GL_DEPTH24_STENCIL8:
1069     case GL_DEPTH32F_STENCIL8:
1070         return true;
1071     case GL_DEPTH_COMPONENT32_OES:
1072         return ctx->hasExtension("GL_OES_depth32");
1073     }
1074     return false;
1075 }
1076 
stencilRenderableFormat(GL2Encoder *,GLenum internalformat)1077 bool stencilRenderableFormat(GL2Encoder*, GLenum internalformat) {
1078     switch (internalformat) {
1079     case GL_DEPTH_STENCIL:
1080     case GL_STENCIL_INDEX8:
1081     case GL_DEPTH24_STENCIL8:
1082     case GL_DEPTH32F_STENCIL8:
1083         return true;
1084     }
1085     return false;
1086 }
1087 
isCubeMapTarget(GLenum target)1088 bool isCubeMapTarget(GLenum target) {
1089     switch (target) {
1090     case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1091     case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1092     case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1093     case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1094     case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1095     case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1096         return true;
1097     default:
1098         break;
1099     }
1100     return false;
1101 }
1102 
1103 #define LIST_VALID_TEXFORMATS(f) \
1104     f(GL_DEPTH_COMPONENT) \
1105     f(GL_DEPTH_STENCIL) \
1106     f(GL_RED) \
1107     f(GL_RED_INTEGER) \
1108     f(GL_RG) \
1109     f(GL_RGB) \
1110     f(GL_RGBA) \
1111     f(GL_RGBA_INTEGER) \
1112     f(GL_RGB_INTEGER) \
1113     f(GL_RG_INTEGER) \
1114     f(GL_BGRA_EXT) \
1115     f(GL_ALPHA) \
1116     f(GL_LUMINANCE) \
1117     f(GL_LUMINANCE_ALPHA) \
1118 
1119 #define LIST_VALID_TEXTYPES(f) \
1120     f(GL_BYTE) \
1121     f(GL_FLOAT) \
1122     f(GL_FLOAT_32_UNSIGNED_INT_24_8_REV) \
1123     f(GL_HALF_FLOAT) \
1124     f(GL_HALF_FLOAT_OES) \
1125     f(GL_INT) \
1126     f(GL_SHORT) \
1127     f(GL_UNSIGNED_BYTE) \
1128     f(GL_UNSIGNED_INT) \
1129     f(GL_UNSIGNED_INT_10F_11F_11F_REV) \
1130     f(GL_UNSIGNED_INT_2_10_10_10_REV) \
1131     f(GL_UNSIGNED_INT_24_8) \
1132     f(GL_UNSIGNED_INT_5_9_9_9_REV) \
1133     f(GL_UNSIGNED_SHORT) \
1134     f(GL_UNSIGNED_SHORT_4_4_4_4) \
1135     f(GL_UNSIGNED_SHORT_5_5_5_1) \
1136     f(GL_UNSIGNED_SHORT_5_6_5) \
1137 
pixelType(GL2Encoder * ctx,GLenum type)1138 bool pixelType(GL2Encoder* ctx, GLenum type) {
1139     int glesMajorVersion = ctx->majorVersion();
1140     if (glesMajorVersion < 3) {
1141         switch (type) {
1142         case GL_UNSIGNED_BYTE:
1143         case GL_UNSIGNED_SHORT:
1144         case GL_UNSIGNED_SHORT_5_6_5:
1145         case GL_UNSIGNED_SHORT_4_4_4_4:
1146         case GL_UNSIGNED_SHORT_5_5_5_1:
1147         case GL_UNSIGNED_INT:
1148         case GL_UNSIGNED_INT_10F_11F_11F_REV:
1149         case GL_UNSIGNED_INT_24_8:
1150         case GL_HALF_FLOAT:
1151         case GL_HALF_FLOAT_OES:
1152         case GL_FLOAT:
1153             return true;
1154         }
1155         return false;
1156     }
1157 
1158 #define GLES3_TYPE_CASE(type) \
1159     case type: \
1160 
1161     switch (type) {
1162         LIST_VALID_TEXTYPES(GLES3_TYPE_CASE)
1163             return glesMajorVersion >= 3;
1164         default:
1165             break;
1166     }
1167 
1168     return false;
1169 }
1170 
pixelFormat(GL2Encoder * ctx,GLenum format)1171 bool pixelFormat(GL2Encoder* ctx, GLenum format) {
1172     int glesMajorVersion = ctx->majorVersion();
1173     if (glesMajorVersion < 3) {
1174         switch (format) {
1175             case GL_DEPTH_COMPONENT:
1176                 // GLES3 compatible
1177                 // Required in dEQP
1178             case GL_RED:
1179             case GL_RG:
1180             case GL_DEPTH_STENCIL_OES:
1181             case GL_ALPHA:
1182             case GL_RGB:
1183             case GL_RGBA:
1184             case GL_BGRA_EXT:
1185             case GL_LUMINANCE:
1186             case GL_LUMINANCE_ALPHA:
1187                 return true;
1188         }
1189         return false;
1190     }
1191 
1192 #define GLES3_FORMAT_CASE(format) \
1193     case format:
1194 
1195     switch (format) {
1196         LIST_VALID_TEXFORMATS(GLES3_FORMAT_CASE)
1197             return glesMajorVersion >= 3;
1198         default:
1199             break;
1200     }
1201     return false;
1202 }
1203 
pixelInternalFormat(GLenum internalformat)1204 bool pixelInternalFormat(GLenum internalformat) {
1205 #define VALID_INTERNAL_FORMAT(format) \
1206     case format: \
1207         return true; \
1208 
1209     switch (internalformat) {
1210     LIST_VALID_TEX_INTERNALFORMATS(VALID_INTERNAL_FORMAT)
1211     default:
1212         break;
1213     }
1214 
1215     ALOGW("error internal format: 0x%x is invalid\n", internalformat);
1216     return false;
1217 }
1218 
1219 
textureBufferFormat(GL2Encoder * ctx,GLenum internalFormat)1220 bool textureBufferFormat(__attribute__((unused)) GL2Encoder* ctx, GLenum internalFormat) {
1221     switch(internalFormat) {
1222     LIST_VALID_TEX_BUFFER_FORMATS(VALID_INTERNAL_FORMAT)
1223     default:
1224         break;
1225     }
1226 
1227     ALOGW("error internal format: 0x%x is invalid\n", internalFormat);
1228     return false;
1229 }
1230 
pixelSizedFormat(GL2Encoder * ctx,GLenum internalformat,GLenum format,GLenum type)1231 bool pixelSizedFormat(GL2Encoder* ctx, GLenum internalformat, GLenum format, GLenum type) {
1232     int glesMajorVersion = ctx->majorVersion();
1233     if (internalformat == format) {
1234         return true;
1235     }
1236 
1237     if (glesMajorVersion < 3) {
1238         switch (format) {
1239             case GL_RED:
1240                 switch (type) {
1241                     case GL_UNSIGNED_BYTE:
1242                         return internalformat == GL_R8;
1243                     case GL_HALF_FLOAT:
1244                     case GL_FLOAT:
1245                         return internalformat == GL_R16F;
1246                     case GL_BYTE:
1247                         return internalformat == GL_R8_SNORM;
1248                     default:
1249                         return false;
1250                 }
1251                 break;
1252             case GL_RG:
1253                 switch (type) {
1254                     case GL_UNSIGNED_BYTE:
1255                         return internalformat == GL_RG8;
1256                     case GL_HALF_FLOAT:
1257                     case GL_FLOAT:
1258                         return internalformat == GL_RG16F;
1259                     default:
1260                         return false;
1261                 }
1262                 break;
1263             case GL_RGB:
1264                 switch (type) {
1265                     case GL_HALF_FLOAT:
1266                     case GL_FLOAT:
1267                         return internalformat == GL_RGB16F
1268                             || internalformat == GL_R11F_G11F_B10F;
1269                     case GL_UNSIGNED_INT_10F_11F_11F_REV:
1270                         return internalformat == GL_R11F_G11F_B10F;
1271                     default:
1272                         return internalformat == GL_RGB8 ||
1273                                internalformat == GL_RGB;
1274                 }
1275                 break;
1276             case GL_RGBA:
1277                 switch (type) {
1278                     case GL_HALF_FLOAT:
1279                     case GL_FLOAT:
1280                         return internalformat == GL_RGBA16F;
1281                     default:
1282                         return internalformat == GL_RGBA8 ||
1283                                internalformat == GL_RGBA;
1284                 }
1285                 break;
1286         }
1287     }
1288 
1289 #define VALIDATE_FORMAT_COMBINATION(x, y, z) \
1290     if (internalformat == x && format == y && type == z) return true; \
1291 
1292     LIST_VALID_TEXFORMAT_COMBINATIONS(VALIDATE_FORMAT_COMBINATION)
1293 
1294     return false;
1295 }
1296 
getCompatibleFormatTypeForInternalFormat(GLenum internalformat,GLenum * format_out,GLenum * type_out)1297 void getCompatibleFormatTypeForInternalFormat(GLenum internalformat, GLenum* format_out, GLenum* type_out) {
1298 #define RETURN_COMPATIBLE_FORMAT(x, y, z) \
1299     if (internalformat == x) { \
1300         *format_out = y; \
1301         *type_out = z; \
1302         return; \
1303     } \
1304 
1305     LIST_VALID_TEXFORMAT_COMBINATIONS(RETURN_COMPATIBLE_FORMAT)
1306 }
1307 
shaderType(GL2Encoder * ctx,GLenum type)1308 bool shaderType(GL2Encoder* ctx, GLenum type) {
1309     int glesMajorVersion = ctx->majorVersion();
1310     int glesMinorVersion = ctx->minorVersion();
1311     switch (type) {
1312     case GL_VERTEX_SHADER:
1313     case GL_FRAGMENT_SHADER:
1314         return true;
1315     case GL_COMPUTE_SHADER:
1316         return glesMajorVersion >= 3 && glesMinorVersion >= 1;
1317     }
1318     return false;
1319 }
1320 
internalFormatTarget(GL2Encoder * ctx,GLenum target)1321 bool internalFormatTarget(GL2Encoder* ctx, GLenum target) {
1322     int glesMajorVersion = ctx->majorVersion();
1323     int glesMinorVersion = ctx->minorVersion();
1324     switch (target) {
1325     case GL_RENDERBUFFER:
1326         return true;
1327     case GL_TEXTURE_2D_MULTISAMPLE:
1328         return glesMajorVersion >= 3 && glesMinorVersion >= 1;
1329     }
1330     return false;
1331 }
1332 
vertexAttribIndexRangeErrorMsg(GL2Encoder * ctx,GLuint index)1333 std::string vertexAttribIndexRangeErrorMsg(GL2Encoder* ctx, GLuint index) {
1334     std::stringstream ss;
1335     GLint maxIndex;
1336     ctx->glGetIntegerv(ctx, GL_MAX_VERTEX_ATTRIBS, &maxIndex);
1337     ss << "Invalid vertex attribute index. Wanted index: " << index << ". Max index: " << maxIndex;
1338     return ss.str();
1339 }
1340 
allowedFace(GLenum face)1341 bool allowedFace(GLenum face) {
1342     switch (face) {
1343         case GL_FRONT:
1344         case GL_BACK:
1345         case GL_FRONT_AND_BACK:
1346             return true;
1347         default:
1348             return false;
1349     }
1350 }
1351 
allowedFunc(GLenum func)1352 bool allowedFunc(GLenum func) {
1353     switch (func) {
1354         case GL_NEVER:
1355         case GL_ALWAYS:
1356         case GL_LESS:
1357         case GL_LEQUAL:
1358         case GL_EQUAL:
1359         case GL_GREATER:
1360         case GL_GEQUAL:
1361         case GL_NOTEQUAL:
1362             return true;
1363         default:
1364             return false;
1365     }
1366 }
1367 
allowedStencilOp(GLenum op)1368 bool allowedStencilOp(GLenum op) {
1369     switch (op) {
1370         case GL_KEEP:
1371         case GL_ZERO:
1372         case GL_REPLACE:
1373         case GL_INCR:
1374         case GL_DECR:
1375         case GL_INVERT:
1376         case GL_INCR_WRAP:
1377         case GL_DECR_WRAP:
1378             return true;
1379         default:
1380             return false;
1381     }
1382 }
1383 
allowedBlendEquation(GLenum eq)1384 bool allowedBlendEquation(GLenum eq) {
1385     switch (eq) {
1386         case GL_FUNC_ADD:
1387         case GL_FUNC_SUBTRACT:
1388         case GL_FUNC_REVERSE_SUBTRACT:
1389         case GL_MIN:
1390         case GL_MAX:
1391             return true;
1392         default:
1393             return false;
1394     }
1395 }
1396 
allowedBlendFunc(GLenum func)1397 bool allowedBlendFunc(GLenum func) {
1398     switch (func) {
1399         case GL_ZERO:
1400         case GL_ONE:
1401         case GL_SRC_COLOR:
1402         case GL_ONE_MINUS_SRC_COLOR:
1403         case GL_DST_COLOR:
1404         case GL_ONE_MINUS_DST_COLOR:
1405         case GL_SRC_ALPHA:
1406         case GL_ONE_MINUS_SRC_ALPHA:
1407         case GL_DST_ALPHA:
1408         case GL_ONE_MINUS_DST_ALPHA:
1409         case GL_CONSTANT_COLOR:
1410         case GL_ONE_MINUS_CONSTANT_COLOR:
1411         case GL_CONSTANT_ALPHA:
1412         case GL_ONE_MINUS_CONSTANT_ALPHA:
1413         case GL_SRC_ALPHA_SATURATE:
1414             return true;
1415         default:
1416             return false;
1417     }
1418 }
1419 
allowedCullFace(GLenum mode)1420 bool allowedCullFace(GLenum mode) {
1421     switch (mode) {
1422         case GL_FRONT:
1423         case GL_BACK:
1424         case GL_FRONT_AND_BACK:
1425             return true;
1426         default:
1427             return false;
1428     }
1429 }
1430 
allowedFrontFace(GLenum mode)1431 bool allowedFrontFace(GLenum mode) {
1432     switch (mode) {
1433         case GL_CCW:
1434         case GL_CW:
1435             return true;
1436         default:
1437             return false;
1438     }
1439 }
1440 
allowedEnable(int majorVersion,int minorVersion,GLenum cap)1441 bool allowedEnable(int majorVersion, int minorVersion, GLenum cap) {
1442     switch (cap) {
1443         case GL_CULL_FACE:
1444         case GL_POLYGON_OFFSET_FILL:
1445         case GL_SAMPLE_ALPHA_TO_COVERAGE:
1446         case GL_SAMPLE_COVERAGE:
1447         case GL_SCISSOR_TEST:
1448         case GL_STENCIL_TEST:
1449         case GL_DEPTH_TEST:
1450         case GL_BLEND:
1451         case GL_DITHER:
1452             return true;
1453         case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1454         case GL_RASTERIZER_DISCARD:
1455             return majorVersion >= 3;
1456         case GL_SAMPLE_MASK:
1457             return majorVersion >= 3 && minorVersion >= 1;
1458         default:
1459             ALOGW("error cap: 0x%x is invalid\n", cap);
1460 	    return false;
1461     }
1462 }
1463 
allowedGetShader(GLenum pname)1464 bool allowedGetShader(GLenum pname) {
1465 	switch (pname) {
1466 		case GL_SHADER_TYPE:
1467 		case GL_DELETE_STATUS:
1468 		case GL_COMPILE_STATUS:
1469 		case GL_INFO_LOG_LENGTH:
1470 		case GL_SHADER_SOURCE_LENGTH:
1471 			return true;
1472 		default:
1473 			return false;
1474 	}
1475 }
1476 
allowedShaderType(GLenum shadertype)1477 bool allowedShaderType(GLenum shadertype) {
1478 	switch (shadertype) {
1479 		case GL_VERTEX_SHADER:
1480 		case GL_FRAGMENT_SHADER:
1481             return true;
1482 		default:
1483 			return false;
1484 	}
1485 }
1486 
allowedPrecisionType(GLenum precisiontype)1487 bool allowedPrecisionType(GLenum precisiontype) {
1488 	switch (precisiontype) {
1489 		case GL_LOW_FLOAT:
1490 		case GL_MEDIUM_FLOAT:
1491 		case GL_HIGH_FLOAT:
1492 		case GL_LOW_INT:
1493 		case GL_MEDIUM_INT:
1494 		case GL_HIGH_INT:
1495             return true;
1496 		default:
1497 			return false;
1498 	}
1499 }
1500 
allowedGetProgram(int majorVersion,int minorVersion,GLenum pname)1501 bool allowedGetProgram(int majorVersion, int minorVersion, GLenum pname) {
1502     switch (pname) {
1503         case GL_DELETE_STATUS:
1504         case GL_LINK_STATUS:
1505         case GL_VALIDATE_STATUS:
1506         case GL_INFO_LOG_LENGTH:
1507         case GL_ATTACHED_SHADERS:
1508         case GL_ACTIVE_ATTRIBUTES:
1509         case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
1510         case GL_ACTIVE_UNIFORMS:
1511         case GL_ACTIVE_UNIFORM_MAX_LENGTH:
1512             return true;
1513         case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
1514         case GL_PROGRAM_BINARY_RETRIEVABLE_HINT:
1515         case GL_PROGRAM_BINARY_LENGTH:
1516         case GL_TRANSFORM_FEEDBACK_VARYINGS:
1517         case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
1518         case GL_ACTIVE_UNIFORM_BLOCKS:
1519         case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
1520             return majorVersion > 2;
1521         case GL_COMPUTE_WORK_GROUP_SIZE:
1522         case GL_PROGRAM_SEPARABLE:
1523         case GL_ACTIVE_ATOMIC_COUNTER_BUFFERS:
1524             return majorVersion > 2 && minorVersion > 0;
1525         default:
1526             return false;
1527     }
1528 }
1529 
allowedGetActiveUniforms(GLenum pname)1530 bool allowedGetActiveUniforms(GLenum pname) {
1531     switch (pname) {
1532         case GL_UNIFORM_TYPE:
1533         case GL_UNIFORM_SIZE:
1534         case GL_UNIFORM_NAME_LENGTH:
1535         case GL_UNIFORM_BLOCK_INDEX:
1536         case GL_UNIFORM_OFFSET:
1537         case GL_UNIFORM_ARRAY_STRIDE:
1538         case GL_UNIFORM_MATRIX_STRIDE:
1539         case GL_UNIFORM_IS_ROW_MAJOR:
1540             return true;
1541         default:
1542             return false;
1543     }
1544 }
1545 
allowedGetActiveUniformBlock(GLenum pname)1546 bool allowedGetActiveUniformBlock(GLenum pname) {
1547     switch (pname) {
1548         case GL_UNIFORM_BLOCK_BINDING:
1549         case GL_UNIFORM_BLOCK_DATA_SIZE:
1550         case GL_UNIFORM_BLOCK_NAME_LENGTH:
1551         case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
1552         case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
1553         case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
1554         case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
1555             return true;
1556         default:
1557             return false;
1558     }
1559 }
1560 
allowedGetVertexAttrib(GLenum pname)1561 bool allowedGetVertexAttrib(GLenum pname) {
1562     switch (pname) {
1563         case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
1564         case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
1565         case GL_VERTEX_ATTRIB_ARRAY_SIZE:
1566         case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
1567         case GL_VERTEX_ATTRIB_ARRAY_TYPE:
1568         case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
1569         case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
1570         case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
1571         case GL_VERTEX_ATTRIB_BINDING:
1572         case GL_VERTEX_ATTRIB_RELATIVE_OFFSET:
1573         case GL_CURRENT_VERTEX_ATTRIB:
1574             return true;
1575         default:
1576             return false;
1577     }
1578 }
1579 
allowedGetRenderbufferParameter(GLenum pname)1580 bool allowedGetRenderbufferParameter(GLenum pname) {
1581     switch (pname) {
1582         case GL_RENDERBUFFER_WIDTH:
1583         case GL_RENDERBUFFER_HEIGHT:
1584         case GL_RENDERBUFFER_INTERNAL_FORMAT:
1585         case GL_RENDERBUFFER_RED_SIZE:
1586         case GL_RENDERBUFFER_GREEN_SIZE:
1587         case GL_RENDERBUFFER_BLUE_SIZE:
1588         case GL_RENDERBUFFER_ALPHA_SIZE:
1589         case GL_RENDERBUFFER_DEPTH_SIZE:
1590         case GL_RENDERBUFFER_STENCIL_SIZE:
1591         case GL_RENDERBUFFER_SAMPLES:
1592             return true;
1593         default:
1594             return false;
1595     }
1596 }
1597 
allowedQueryTarget(GLenum target)1598 bool allowedQueryTarget(GLenum target) {
1599     switch (target) {
1600         case GL_ANY_SAMPLES_PASSED:
1601         case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
1602         case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
1603             return true;
1604         default:
1605             return false;
1606     }
1607 }
1608 
allowedQueryParam(GLenum pname)1609 bool allowedQueryParam(GLenum pname) {
1610     switch (pname) {
1611         case GL_CURRENT_QUERY:
1612             return true;
1613         default:
1614             return false;
1615     }
1616 }
1617 
allowedQueryObjectParam(GLenum pname)1618 bool allowedQueryObjectParam(GLenum pname) {
1619     switch (pname) {
1620         case GL_QUERY_RESULT:
1621         case GL_QUERY_RESULT_AVAILABLE:
1622             return true;
1623         default:
1624             return false;
1625     }
1626 }
1627 
allowedGetSyncParam(GLenum pname)1628 bool allowedGetSyncParam(GLenum pname) {
1629     switch (pname) {
1630         case GL_OBJECT_TYPE:
1631         case GL_SYNC_STATUS:
1632         case GL_SYNC_CONDITION:
1633         case GL_SYNC_FLAGS:
1634             return true;
1635         default:
1636             return false;
1637     }
1638 }
1639 
allowedHintTarget(GLenum target)1640 bool allowedHintTarget(GLenum target) {
1641     switch (target) {
1642         case GL_GENERATE_MIPMAP_HINT:
1643         case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
1644             return true;
1645         default:
1646             return false;
1647     }
1648 }
1649 
allowedHintMode(GLenum mode)1650 bool allowedHintMode(GLenum mode) {
1651     switch (mode) {
1652         case GL_DONT_CARE:
1653         case GL_NICEST:
1654         case GL_FASTEST:
1655             return true;
1656         default:
1657             return false;
1658     }
1659 }
1660 
1661 } // namespace GLESv2Validation
1662