xref: /aosp_15_r20/external/deqp/external/openglcts/modules/common/glcPackedPixelsTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * OpenGL Conformance Test Suite
3  * -----------------------------
4  *
5  * Copyright (c) 2017 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */ /*!
20  * \file glcPackedPixelsTests.cpp
21  * \brief
22  */ /*-------------------------------------------------------------------*/
23 
24 #include "glcPackedPixelsTests.hpp"
25 #include "deMath.h"
26 #include "glcMisc.hpp"
27 #include "gluContextInfo.hpp"
28 #include "gluShaderProgram.hpp"
29 #include "gluStrUtil.hpp"
30 #include "glwEnums.hpp"
31 #include "glwFunctions.hpp"
32 #include "tcuRenderTarget.hpp"
33 #include "tcuTestLog.hpp"
34 #include <algorithm>
35 #include <cstring>
36 #include <limits>
37 #include <map>
38 #include <stdio.h>
39 
40 using namespace glw;
41 using namespace glu;
42 
43 namespace glcts
44 {
45 
46 enum
47 {
48     GRADIENT_WIDTH  = 7,
49     GRADIENT_HEIGHT = 3
50 };
51 
52 enum InputOutputOperation
53 {
54     OUTPUT_GETTEXIMAGE,
55     OUTPUT_READPIXELS,
56     INPUT_TEXIMAGE,
57 };
58 
59 enum ComponentFormat
60 {
61     FORMAT_STENCIL,       // stencil, unsigned int
62     FORMAT_DEPTH,         // depth, unsigned [fp|float]
63     FORMAT_DEPTH_STENCIL, // depth+stencil, unsigned [fp|float]
64     FORMAT_COLOR,         // color, [signed|unsigned] fp
65     FORMAT_COLOR_INTEGER, // color, [signed|unsigned] int
66 };
67 
68 enum TypeStorage
69 {
70     STORAGE_UNSIGNED, // unsigned fp/int
71     STORAGE_SIGNED,   // signed fp/int
72     STORAGE_FLOAT,    // signed/unsigned float
73 };
74 
75 union InternalFormatBits
76 {
77     struct Bits
78     {
79         int red;       // red bits
80         int green;     // green bits
81         int blue;      // blue bits
82         int alpha;     // alpha bits
83         int intensity; // intensity bits
84         int luminance; // luminance bits
85         int depth;     // depth bits
86         int stencil;   // stencil bits
87         int exponent;  // shared exponent bits
88     } bits;
89     int array[9]; // all the bits
90 };
91 
92 struct PixelType
93 {
94     GLenum type;
95     int size;
96     int storage;
97     bool special;
98     bool reversed;
99     InternalFormatBits bits;
100     bool clamp;
101 };
102 
103 struct PixelFormat
104 {
105     GLenum format;                     // format name
106     int components;                    // number of components
107     int componentFormat;               // element meaning
108     GLenum attachment;                 // target buffer
109     InternalFormatBits componentOrder; // zero based element order, -1 for N/A
110 };
111 
112 enum InternalFormatSamplerType
113 {
114     SAMPLER_UNORM = 0, // unsigned normalized
115     SAMPLER_NORM,      // normalized
116     SAMPLER_UINT,      // unsigned integer
117     SAMPLER_INT,       // integer
118     SAMPLER_FLOAT      // floating-point
119 };
120 
121 enum InternalFormatFlag
122 {
123     FLAG_PACKED       = 1,                                     // packed pixel format
124     FLAG_COMPRESSED   = 2,                                     // compressed format
125     FLAG_REQ_RBO_GL42 = 4,                                     // required RBO & tex format in OpenGL 4.2
126     FLAG_REQ_RBO_ES30 = 8,                                     // required RBO & tex format in OpenGL ES 3.0
127     FLAG_REQ_RBO      = FLAG_REQ_RBO_GL42 | FLAG_REQ_RBO_ES30, // Required RBO & tex format in both
128 };
129 
130 struct InternalFormat
131 {
132     GLenum sizedFormat;
133     GLenum baseFormat;
134     GLenum format;
135     GLenum type;
136     InternalFormatSamplerType sampler;
137     InternalFormatBits bits;
138     int flags; // InternalFormatFlag
139 };
140 
141 struct EnumFormats
142 {
143     GLenum internalformat;
144     GLenum format;
145     GLenum type;
146     int size;
147     bool bRenderable;
148 };
149 
150 #define PACK_DEFAULTI (0)
151 #define PACK_DEFAULTUI (0)
152 #define PACK_DEFAULTF (-2.0f)
153 
154 static const InternalFormat coreInternalformats[] = {
155     {GL_DEPTH_COMPONENT,
156      GL_DEPTH_COMPONENT,
157      GL_DEPTH_COMPONENT,
158      GL_UNSIGNED_SHORT,
159      SAMPLER_UNORM,
160      {{0, 0, 0, 0, 0, 0, 16, 0, 0}},
161      0},
162     {GL_DEPTH_STENCIL,
163      GL_DEPTH_STENCIL,
164      GL_DEPTH_STENCIL,
165      GL_UNSIGNED_INT,
166      SAMPLER_UNORM,
167      {{0, 0, 0, 0, 0, 0, 24, 8, 0}},
168      0},
169     {GL_RED, GL_RED, GL_RED, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{8, 0, 0, 0, 0, 0, 0, 0, 0}}, 0},
170     {GL_RG, GL_RG, GL_RG, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{8, 8, 0, 0, 0, 0, 0, 0, 0}}, 0},
171     {GL_R8, GL_RED, GL_RED, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{8, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
172     {GL_R8_SNORM, GL_RED, GL_RED, GL_BYTE, SAMPLER_NORM, {{8, 0, 0, 0, 0, 0, 0, 0, 0}}, 0},
173     {GL_R16, GL_RED, GL_RED, GL_UNSIGNED_SHORT, SAMPLER_UNORM, {{16, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO_GL42},
174     {GL_R16_SNORM, GL_RED, GL_RED, GL_SHORT, SAMPLER_NORM, {{16, 0, 0, 0, 0, 0, 0, 0, 0}}, 0},
175     {GL_RG8, GL_RG, GL_RG, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{8, 8, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
176     {GL_RG8_SNORM, GL_RG, GL_RG, GL_BYTE, SAMPLER_NORM, {{8, 8, 0, 0, 0, 0, 0, 0, 0}}, 0},
177     {GL_RG16, GL_RG, GL_RG, GL_UNSIGNED_SHORT, SAMPLER_UNORM, {{16, 16, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO_GL42},
178     {GL_RG16_SNORM, GL_RG, GL_RG, GL_SHORT, SAMPLER_NORM, {{16, 16, 0, 0, 0, 0, 0, 0, 0}}, 0},
179     {GL_R3_G3_B2, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE_3_3_2, SAMPLER_UNORM, {{3, 3, 2, 0, 0, 0, 0, 0, 0}}, FLAG_PACKED},
180     {GL_RGB4, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{4, 4, 4, 0, 0, 0, 0, 0, 0}}, 0},
181     {GL_RGB5, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{5, 5, 5, 0, 0, 0, 0, 0, 0}}, 0},
182     {GL_RGB8, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{8, 8, 8, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO_ES30},
183     {GL_RGB8_SNORM, GL_RGB, GL_RGB, GL_BYTE, SAMPLER_NORM, {{8, 8, 8, 0, 0, 0, 0, 0, 0}}, 0},
184     {GL_RGB10, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT, SAMPLER_UNORM, {{10, 10, 10, 0, 0, 0, 0, 0, 0}}, 0},
185     {GL_RGB12, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT, SAMPLER_UNORM, {{12, 12, 12, 0, 0, 0, 0, 0, 0}}, 0},
186     {GL_RGB16, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT, SAMPLER_UNORM, {{16, 16, 16, 0, 0, 0, 0, 0, 0}}, 0},
187     {GL_RGB16_SNORM, GL_RGB, GL_RGB, GL_SHORT, SAMPLER_NORM, {{16, 16, 16, 0, 0, 0, 0, 0, 0}}, 0},
188     {GL_RGBA2, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{2, 2, 2, 2, 0, 0, 0, 0, 0}}, 0},
189     {GL_RGBA4,
190      GL_RGBA,
191      GL_RGBA,
192      GL_UNSIGNED_SHORT_4_4_4_4,
193      SAMPLER_UNORM,
194      {{4, 4, 4, 4, 0, 0, 0, 0, 0}},
195      FLAG_PACKED | FLAG_REQ_RBO},
196     {GL_RGB5_A1,
197      GL_RGBA,
198      GL_RGBA,
199      GL_UNSIGNED_SHORT_5_5_5_1,
200      SAMPLER_UNORM,
201      {{5, 5, 5, 1, 0, 0, 0, 0, 0}},
202      FLAG_PACKED | FLAG_REQ_RBO},
203     {GL_RGBA8, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{8, 8, 8, 8, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
204     {GL_RGBA8_SNORM, GL_RGBA, GL_RGBA, GL_BYTE, SAMPLER_NORM, {{8, 8, 8, 8, 0, 0, 0, 0, 0}}, 0},
205     {GL_RGB10_A2,
206      GL_RGBA,
207      GL_RGBA,
208      GL_UNSIGNED_INT_10_10_10_2,
209      SAMPLER_UNORM,
210      {{10, 10, 10, 2, 0, 0, 0, 0, 0}},
211      FLAG_PACKED | FLAG_REQ_RBO_GL42},
212     {GL_RGB10_A2UI,
213      GL_RGBA,
214      GL_RGBA_INTEGER,
215      GL_UNSIGNED_INT_10_10_10_2,
216      SAMPLER_UINT,
217      {{10, 10, 10, 2, 0, 0, 0, 0, 0}},
218      FLAG_PACKED | FLAG_REQ_RBO_GL42},
219     {GL_RGBA12, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT, SAMPLER_UNORM, {{12, 12, 12, 12, 0, 0, 0, 0, 0}}, 0},
220     {GL_RGBA16,
221      GL_RGBA,
222      GL_RGBA,
223      GL_UNSIGNED_SHORT,
224      SAMPLER_UNORM,
225      {{16, 16, 16, 16, 0, 0, 0, 0, 0}},
226      FLAG_REQ_RBO_GL42},
227     {GL_RGBA16_SNORM, GL_RGBA, GL_RGBA, GL_SHORT, SAMPLER_NORM, {{16, 16, 16, 16, 0, 0, 0, 0, 0}}, 0},
228     {GL_SRGB8, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{8, 8, 8, 0, 0, 0, 0, 0, 0}}, 0},
229     {GL_SRGB8_ALPHA8, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{8, 8, 8, 8, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
230     {GL_R16F, GL_RED, GL_RED, GL_HALF_FLOAT, SAMPLER_FLOAT, {{16, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO_GL42},
231     {GL_RG16F, GL_RG, GL_RG, GL_HALF_FLOAT, SAMPLER_FLOAT, {{16, 16, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO_GL42},
232     {GL_RGB16F, GL_RGB, GL_RGB, GL_HALF_FLOAT, SAMPLER_FLOAT, {{16, 16, 16, 0, 0, 0, 0, 0, 0}}, 0},
233     {GL_RGBA16F, GL_RGBA, GL_RGBA, GL_HALF_FLOAT, SAMPLER_FLOAT, {{16, 16, 16, 16, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO_GL42},
234     {GL_R32F, GL_RED, GL_RED, GL_FLOAT, SAMPLER_FLOAT, {{32, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO_GL42},
235     {GL_RG32F, GL_RG, GL_RG, GL_FLOAT, SAMPLER_FLOAT, {{32, 32, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO_GL42},
236     {GL_RGB32F, GL_RGB, GL_RGB, GL_FLOAT, SAMPLER_FLOAT, {{32, 32, 32, 0, 0, 0, 0, 0, 0}}, 0},
237     {GL_RGBA32F, GL_RGBA, GL_RGBA, GL_FLOAT, SAMPLER_FLOAT, {{32, 32, 32, 32, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO_GL42},
238     {GL_R11F_G11F_B10F,
239      GL_RGB,
240      GL_RGB,
241      GL_UNSIGNED_INT_10F_11F_11F_REV,
242      SAMPLER_FLOAT,
243      {{11, 11, 10, 0, 0, 0, 0, 0, 0}},
244      FLAG_PACKED | FLAG_REQ_RBO_GL42},
245     {GL_RGB9_E5,
246      GL_RGB,
247      GL_RGB,
248      GL_UNSIGNED_INT_5_9_9_9_REV,
249      SAMPLER_FLOAT,
250      {{9, 9, 9, 0, 0, 0, 0, 0, 5}},
251      FLAG_PACKED},
252     {GL_R8I, GL_RED, GL_RED_INTEGER, GL_BYTE, SAMPLER_INT, {{8, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
253     {GL_R8UI, GL_RED, GL_RED_INTEGER, GL_UNSIGNED_BYTE, SAMPLER_UINT, {{8, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
254     {GL_R16I, GL_RED, GL_RED_INTEGER, GL_SHORT, SAMPLER_INT, {{16, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
255     {GL_R16UI, GL_RED, GL_RED_INTEGER, GL_UNSIGNED_SHORT, SAMPLER_UINT, {{16, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
256     {GL_R32I, GL_RED, GL_RED_INTEGER, GL_INT, SAMPLER_INT, {{32, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
257     {GL_R32UI, GL_RED, GL_RED_INTEGER, GL_UNSIGNED_INT, SAMPLER_UINT, {{32, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
258     {GL_RG8I, GL_RG, GL_RG_INTEGER, GL_BYTE, SAMPLER_INT, {{8, 8, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
259     {GL_RG8UI, GL_RG, GL_RG_INTEGER, GL_UNSIGNED_BYTE, SAMPLER_UINT, {{8, 8, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
260     {GL_RG16I, GL_RG, GL_RG_INTEGER, GL_SHORT, SAMPLER_INT, {{16, 16, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
261     {GL_RG16UI, GL_RG, GL_RG_INTEGER, GL_UNSIGNED_SHORT, SAMPLER_UINT, {{16, 16, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
262     {GL_RG32I, GL_RG, GL_RG_INTEGER, GL_INT, SAMPLER_INT, {{32, 32, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
263     {GL_RG32UI, GL_RG, GL_RG_INTEGER, GL_UNSIGNED_INT, SAMPLER_UINT, {{32, 32, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
264     {GL_RGB8I, GL_RGB, GL_RGB_INTEGER, GL_BYTE, SAMPLER_INT, {{8, 8, 8, 0, 0, 0, 0, 0, 0}}, 0},
265     {GL_RGB8UI, GL_RGB, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, SAMPLER_UINT, {{8, 8, 8, 0, 0, 0, 0, 0, 0}}, 0},
266     {GL_RGB16I, GL_RGB, GL_RGB_INTEGER, GL_SHORT, SAMPLER_INT, {{16, 16, 16, 0, 0, 0, 0, 0, 0}}, 0},
267     {GL_RGB16UI, GL_RGB, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, SAMPLER_UINT, {{16, 16, 16, 0, 0, 0, 0, 0, 0}}, 0},
268     {GL_RGB32I, GL_RGB, GL_RGB_INTEGER, GL_INT, SAMPLER_INT, {{32, 32, 32, 0, 0, 0, 0, 0, 0}}, 0},
269     {GL_RGB32UI, GL_RGB, GL_RGB_INTEGER, GL_UNSIGNED_INT, SAMPLER_UINT, {{32, 32, 32, 0, 0, 0, 0, 0, 0}}, 0},
270     {GL_RGBA8I, GL_RGBA, GL_RGBA_INTEGER, GL_BYTE, SAMPLER_INT, {{8, 8, 8, 8, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
271     {GL_RGBA8UI, GL_RGBA, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, SAMPLER_UINT, {{8, 8, 8, 8, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
272     {GL_RGBA16I, GL_RGBA, GL_RGBA_INTEGER, GL_SHORT, SAMPLER_INT, {{16, 16, 16, 16, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
273     {GL_RGBA16UI,
274      GL_RGBA,
275      GL_RGBA_INTEGER,
276      GL_UNSIGNED_SHORT,
277      SAMPLER_UINT,
278      {{16, 16, 16, 16, 0, 0, 0, 0, 0}},
279      FLAG_REQ_RBO},
280     {GL_RGBA32I, GL_RGBA, GL_RGBA_INTEGER, GL_INT, SAMPLER_INT, {{32, 32, 32, 32, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
281     {GL_RGBA32UI,
282      GL_RGBA,
283      GL_RGBA_INTEGER,
284      GL_UNSIGNED_INT,
285      SAMPLER_UINT,
286      {{32, 32, 32, 32, 0, 0, 0, 0, 0}},
287      FLAG_REQ_RBO},
288     {GL_DEPTH_COMPONENT16,
289      GL_DEPTH_COMPONENT,
290      GL_DEPTH_COMPONENT,
291      GL_UNSIGNED_SHORT,
292      SAMPLER_UNORM,
293      {{0, 0, 0, 0, 0, 0, 16, 0, 0}},
294      FLAG_REQ_RBO},
295     {GL_DEPTH_COMPONENT24,
296      GL_DEPTH_COMPONENT,
297      GL_DEPTH_COMPONENT,
298      GL_UNSIGNED_INT,
299      SAMPLER_UNORM,
300      {{0, 0, 0, 0, 0, 0, 24, 0, 0}},
301      FLAG_REQ_RBO},
302     {GL_DEPTH_COMPONENT32,
303      GL_DEPTH_COMPONENT,
304      GL_DEPTH_COMPONENT,
305      GL_UNSIGNED_INT,
306      SAMPLER_UNORM,
307      {{0, 0, 0, 0, 0, 0, 32, 0, 0}},
308      0},
309     {GL_DEPTH_COMPONENT32F,
310      GL_DEPTH_COMPONENT,
311      GL_DEPTH_COMPONENT,
312      GL_FLOAT,
313      SAMPLER_FLOAT,
314      {{0, 0, 0, 0, 0, 0, 32, 0, 0}},
315      FLAG_REQ_RBO},
316     {GL_DEPTH24_STENCIL8,
317      GL_DEPTH_STENCIL,
318      GL_DEPTH_STENCIL,
319      GL_UNSIGNED_INT_24_8,
320      SAMPLER_UNORM,
321      {{0, 0, 0, 0, 0, 0, 24, 8, 0}},
322      FLAG_REQ_RBO},
323     {GL_DEPTH32F_STENCIL8,
324      GL_DEPTH_STENCIL,
325      GL_DEPTH_STENCIL,
326      GL_FLOAT_32_UNSIGNED_INT_24_8_REV,
327      SAMPLER_FLOAT,
328      {{0, 0, 0, 0, 0, 0, 32, 8, 0}},
329      FLAG_PACKED | FLAG_REQ_RBO},
330     {GL_COMPRESSED_RED,
331      GL_RED,
332      GL_RED,
333      GL_UNSIGNED_BYTE,
334      SAMPLER_UNORM,
335      {{8, 0, 0, 0, 0, 0, 0, 0, 0}},
336      FLAG_COMPRESSED},
337     {GL_COMPRESSED_RG, GL_RG, GL_RG, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{8, 8, 0, 0, 0, 0, 0, 0, 0}}, FLAG_COMPRESSED},
338     {GL_COMPRESSED_RGB,
339      GL_RGB,
340      GL_RGB,
341      GL_UNSIGNED_BYTE,
342      SAMPLER_UNORM,
343      {{8, 8, 8, 0, 0, 0, 0, 0, 0}},
344      FLAG_COMPRESSED},
345     {GL_COMPRESSED_RGBA,
346      GL_RGBA,
347      GL_RGBA,
348      GL_UNSIGNED_BYTE,
349      SAMPLER_UNORM,
350      {{8, 8, 8, 8, 0, 0, 0, 0, 0}},
351      FLAG_COMPRESSED},
352     {GL_COMPRESSED_SRGB,
353      GL_RGB,
354      GL_RGB,
355      GL_UNSIGNED_BYTE,
356      SAMPLER_UNORM,
357      {{8, 8, 8, 0, 0, 0, 0, 0, 0}},
358      FLAG_COMPRESSED},
359     {GL_COMPRESSED_SRGB_ALPHA,
360      GL_RGBA,
361      GL_RGBA,
362      GL_UNSIGNED_BYTE,
363      SAMPLER_UNORM,
364      {{8, 8, 8, 8, 0, 0, 0, 0, 0}},
365      FLAG_COMPRESSED},
366     {GL_COMPRESSED_RED_RGTC1,
367      GL_RED,
368      GL_RED,
369      GL_UNSIGNED_BYTE,
370      SAMPLER_UNORM,
371      {{8, 0, 0, 0, 0, 0, 0, 0, 0}},
372      FLAG_COMPRESSED},
373     {GL_COMPRESSED_SIGNED_RED_RGTC1,
374      GL_RED,
375      GL_RED,
376      GL_BYTE,
377      SAMPLER_NORM,
378      {{8, 0, 0, 0, 0, 0, 0, 0, 0}},
379      FLAG_COMPRESSED},
380     {GL_COMPRESSED_RG_RGTC2,
381      GL_RG,
382      GL_RG,
383      GL_UNSIGNED_BYTE,
384      SAMPLER_UNORM,
385      {{8, 8, 0, 0, 0, 0, 0, 0, 0}},
386      FLAG_COMPRESSED},
387     {GL_COMPRESSED_SIGNED_RG_RGTC2,
388      GL_RG,
389      GL_RG,
390      GL_BYTE,
391      SAMPLER_NORM,
392      {{8, 8, 0, 0, 0, 0, 0, 0, 0}},
393      FLAG_COMPRESSED},
394 };
395 
396 static InternalFormat esInternalformats[] = {
397     {GL_LUMINANCE, GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{0, 0, 0, 0, 0, 8, 0, 0, 0}}, 0},
398     {GL_ALPHA, GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{0, 0, 0, 8, 0, 0, 0, 0, 0}}, 0},
399     {GL_LUMINANCE_ALPHA,
400      GL_LUMINANCE_ALPHA,
401      GL_LUMINANCE_ALPHA,
402      GL_UNSIGNED_BYTE,
403      SAMPLER_UNORM,
404      {{0, 0, 0, 8, 0, 8, 0, 0, 0}},
405      0},
406     {GL_RGB, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{8, 8, 8, 0, 0, 0, 0, 0, 0}}, 0},
407     {GL_RGBA, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{8, 8, 8, 8, 0, 0, 0, 0, 0}}, 0},
408     {GL_R8, GL_RED, GL_RED, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{8, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
409     {GL_R8_SNORM, GL_RED, GL_RED, GL_BYTE, SAMPLER_NORM, {{8, 0, 0, 0, 0, 0, 0, 0, 0}}, 0},
410     {GL_RG8, GL_RG, GL_RG, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{8, 8, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
411     {GL_RG8_SNORM, GL_RG, GL_RG, GL_BYTE, SAMPLER_NORM, {{8, 8, 0, 0, 0, 0, 0, 0, 0}}, 0},
412     {GL_RGB8, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{8, 8, 8, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO_ES30},
413     {GL_RGB8_SNORM, GL_RGB, GL_RGB, GL_BYTE, SAMPLER_NORM, {{8, 8, 8, 0, 0, 0, 0, 0, 0}}, 0},
414     {GL_RGB565,
415      GL_RGB,
416      GL_RGB,
417      GL_UNSIGNED_SHORT_5_6_5,
418      SAMPLER_UNORM,
419      {{5, 6, 5, 0, 0, 0, 0, 0, 0}},
420      FLAG_PACKED | FLAG_REQ_RBO},
421     {GL_RGBA4,
422      GL_RGBA,
423      GL_RGBA,
424      GL_UNSIGNED_SHORT_4_4_4_4,
425      SAMPLER_UNORM,
426      {{4, 4, 4, 4, 0, 0, 0, 0, 0}},
427      FLAG_PACKED | FLAG_REQ_RBO},
428     {GL_RGB5_A1,
429      GL_RGBA,
430      GL_RGBA,
431      GL_UNSIGNED_SHORT_5_5_5_1,
432      SAMPLER_UNORM,
433      {{5, 5, 5, 1, 0, 0, 0, 0, 0}},
434      FLAG_PACKED | FLAG_REQ_RBO},
435     {GL_RGBA8, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{8, 8, 8, 8, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
436     {GL_RGBA8_SNORM, GL_RGBA, GL_RGBA, GL_BYTE, SAMPLER_NORM, {{8, 8, 8, 8, 0, 0, 0, 0, 0}}, 0},
437     {GL_RGB10_A2,
438      GL_RGBA,
439      GL_RGBA,
440      GL_UNSIGNED_INT_2_10_10_10_REV,
441      SAMPLER_UNORM,
442      {{10, 10, 10, 2, 0, 0, 0, 0, 0}},
443      FLAG_PACKED | FLAG_REQ_RBO_ES30},
444     {GL_RGB10_A2UI,
445      GL_RGBA,
446      GL_RGBA_INTEGER,
447      GL_UNSIGNED_INT_2_10_10_10_REV,
448      SAMPLER_UINT,
449      {{10, 10, 10, 2, 0, 0, 0, 0, 0}},
450      FLAG_PACKED | FLAG_REQ_RBO_ES30},
451     {GL_SRGB8, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{8, 8, 8, 0, 0, 0, 0, 0, 0}}, 0},
452     {GL_SRGB8_ALPHA8, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, SAMPLER_UNORM, {{8, 8, 8, 8, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
453     {GL_R16F, GL_RED, GL_RED, GL_HALF_FLOAT, SAMPLER_FLOAT, {{16, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO_GL42},
454     {GL_RG16F, GL_RG, GL_RG, GL_HALF_FLOAT, SAMPLER_FLOAT, {{16, 16, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO_GL42},
455     {GL_RGB16F, GL_RGB, GL_RGB, GL_HALF_FLOAT, SAMPLER_FLOAT, {{16, 16, 16, 0, 0, 0, 0, 0, 0}}, 0},
456     {GL_RGBA16F, GL_RGBA, GL_RGBA, GL_HALF_FLOAT, SAMPLER_FLOAT, {{16, 16, 16, 16, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO_GL42},
457     {GL_R32F, GL_RED, GL_RED, GL_FLOAT, SAMPLER_FLOAT, {{32, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO_GL42},
458     {GL_RG32F, GL_RG, GL_RG, GL_FLOAT, SAMPLER_FLOAT, {{32, 32, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO_GL42},
459     {GL_RGB32F, GL_RGB, GL_RGB, GL_FLOAT, SAMPLER_FLOAT, {{32, 32, 32, 0, 0, 0, 0, 0, 0}}, 0},
460     {GL_RGBA32F, GL_RGBA, GL_RGBA, GL_FLOAT, SAMPLER_FLOAT, {{32, 32, 32, 32, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO_GL42},
461     {GL_R11F_G11F_B10F,
462      GL_RGB,
463      GL_RGB,
464      GL_UNSIGNED_INT_10F_11F_11F_REV,
465      SAMPLER_FLOAT,
466      {{11, 11, 10, 0, 0, 0, 0, 0, 0}},
467      FLAG_PACKED | FLAG_REQ_RBO_GL42},
468     {GL_RGB9_E5,
469      GL_RGB,
470      GL_RGB,
471      GL_UNSIGNED_INT_5_9_9_9_REV,
472      SAMPLER_FLOAT,
473      {{9, 9, 9, 0, 0, 0, 0, 0, 5}},
474      FLAG_PACKED},
475     {GL_R8I, GL_RED, GL_RED_INTEGER, GL_BYTE, SAMPLER_INT, {{8, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
476     {GL_R8UI, GL_RED, GL_RED_INTEGER, GL_UNSIGNED_BYTE, SAMPLER_UINT, {{8, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
477     {GL_R16I, GL_RED, GL_RED_INTEGER, GL_SHORT, SAMPLER_INT, {{16, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
478     {GL_R16UI, GL_RED, GL_RED_INTEGER, GL_UNSIGNED_SHORT, SAMPLER_UINT, {{16, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
479     {GL_R32I, GL_RED, GL_RED_INTEGER, GL_INT, SAMPLER_INT, {{32, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
480     {GL_R32UI, GL_RED, GL_RED_INTEGER, GL_UNSIGNED_INT, SAMPLER_UINT, {{32, 0, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
481     {GL_RG8I, GL_RG, GL_RG_INTEGER, GL_BYTE, SAMPLER_INT, {{8, 8, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
482     {GL_RG8UI, GL_RG, GL_RG_INTEGER, GL_UNSIGNED_BYTE, SAMPLER_UINT, {{8, 8, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
483     {GL_RG16I, GL_RG, GL_RG_INTEGER, GL_SHORT, SAMPLER_INT, {{16, 16, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
484     {GL_RG16UI, GL_RG, GL_RG_INTEGER, GL_UNSIGNED_SHORT, SAMPLER_UINT, {{16, 16, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
485     {GL_RG32I, GL_RG, GL_RG_INTEGER, GL_INT, SAMPLER_INT, {{32, 32, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
486     {GL_RG32UI, GL_RG, GL_RG_INTEGER, GL_UNSIGNED_INT, SAMPLER_UINT, {{32, 32, 0, 0, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
487     {GL_RGB8I, GL_RGB, GL_RGB_INTEGER, GL_BYTE, SAMPLER_INT, {{8, 8, 8, 0, 0, 0, 0, 0, 0}}, 0},
488     {GL_RGB8UI, GL_RGB, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, SAMPLER_UINT, {{8, 8, 8, 0, 0, 0, 0, 0, 0}}, 0},
489     {GL_RGB16I, GL_RGB, GL_RGB_INTEGER, GL_SHORT, SAMPLER_INT, {{16, 16, 16, 0, 0, 0, 0, 0, 0}}, 0},
490     {GL_RGB16UI, GL_RGB, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, SAMPLER_UINT, {{16, 16, 16, 0, 0, 0, 0, 0, 0}}, 0},
491     {GL_RGB32I, GL_RGB, GL_RGB_INTEGER, GL_INT, SAMPLER_INT, {{32, 32, 32, 0, 0, 0, 0, 0, 0}}, 0},
492     {GL_RGB32UI, GL_RGB, GL_RGB_INTEGER, GL_UNSIGNED_INT, SAMPLER_UINT, {{32, 32, 32, 0, 0, 0, 0, 0, 0}}, 0},
493     {GL_RGBA8I, GL_RGBA, GL_RGBA_INTEGER, GL_BYTE, SAMPLER_INT, {{8, 8, 8, 8, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
494     {GL_RGBA8UI, GL_RGBA, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, SAMPLER_UINT, {{8, 8, 8, 8, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
495     {GL_RGBA16I, GL_RGBA, GL_RGBA_INTEGER, GL_SHORT, SAMPLER_INT, {{16, 16, 16, 16, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
496     {GL_RGBA16UI,
497      GL_RGBA,
498      GL_RGBA_INTEGER,
499      GL_UNSIGNED_SHORT,
500      SAMPLER_UINT,
501      {{16, 16, 16, 16, 0, 0, 0, 0, 0}},
502      FLAG_REQ_RBO},
503     {GL_RGBA32I, GL_RGBA, GL_RGBA_INTEGER, GL_INT, SAMPLER_INT, {{32, 32, 32, 32, 0, 0, 0, 0, 0}}, FLAG_REQ_RBO},
504     {GL_RGBA32UI,
505      GL_RGBA,
506      GL_RGBA_INTEGER,
507      GL_UNSIGNED_INT,
508      SAMPLER_UINT,
509      {{32, 32, 32, 32, 0, 0, 0, 0, 0}},
510      FLAG_REQ_RBO},
511     {GL_DEPTH_COMPONENT16,
512      GL_DEPTH_COMPONENT,
513      GL_DEPTH_COMPONENT,
514      GL_UNSIGNED_SHORT,
515      SAMPLER_UNORM,
516      {{0, 0, 0, 0, 0, 0, 16, 0, 0}},
517      FLAG_REQ_RBO},
518     {GL_DEPTH_COMPONENT24,
519      GL_DEPTH_COMPONENT,
520      GL_DEPTH_COMPONENT,
521      GL_UNSIGNED_INT,
522      SAMPLER_UNORM,
523      {{0, 0, 0, 0, 0, 0, 24, 0, 0}},
524      FLAG_REQ_RBO},
525     {GL_DEPTH_COMPONENT32F,
526      GL_DEPTH_COMPONENT,
527      GL_DEPTH_COMPONENT,
528      GL_FLOAT,
529      SAMPLER_FLOAT,
530      {{0, 0, 0, 0, 0, 0, 32, 0, 0}},
531      FLAG_REQ_RBO},
532     {GL_DEPTH24_STENCIL8,
533      GL_DEPTH_STENCIL,
534      GL_DEPTH_STENCIL,
535      GL_UNSIGNED_INT_24_8,
536      SAMPLER_UNORM,
537      {{0, 0, 0, 0, 0, 0, 24, 8, 0}},
538      FLAG_REQ_RBO},
539     {GL_DEPTH32F_STENCIL8,
540      GL_DEPTH_STENCIL,
541      GL_DEPTH_STENCIL,
542      GL_FLOAT_32_UNSIGNED_INT_24_8_REV,
543      SAMPLER_FLOAT,
544      {{0, 0, 0, 0, 0, 0, 32, 8, 0}},
545      FLAG_PACKED | FLAG_REQ_RBO},
546 };
547 
548 static const PixelFormat coreFormats[] = {
549     {GL_STENCIL_INDEX, 1, FORMAT_STENCIL, GL_STENCIL_ATTACHMENT, {{-1, -1, -1, -1, -1, -1, -1, 0, -1}}},
550     {GL_DEPTH_COMPONENT, 1, FORMAT_DEPTH, GL_DEPTH_ATTACHMENT, {{-1, -1, -1, -1, -1, -1, 0, -1, -1}}},
551     {GL_DEPTH_STENCIL, 2, FORMAT_DEPTH_STENCIL, GL_DEPTH_STENCIL_ATTACHMENT, {{-1, -1, -1, -1, -1, -1, 0, 1, -1}}},
552     {GL_RED, 1, FORMAT_COLOR, GL_COLOR_ATTACHMENT0, {{0, -1, -1, -1, -1, -1, -1, -1, -1}}},
553     {GL_GREEN, 1, FORMAT_COLOR, GL_COLOR_ATTACHMENT0, {{-1, 0, -1, -1, -1, -1, -1, -1, -1}}},
554     {GL_BLUE, 1, FORMAT_COLOR, GL_COLOR_ATTACHMENT0, {{-1, -1, 0, -1, -1, -1, -1, -1, -1}}},
555     {GL_RG, 2, FORMAT_COLOR, GL_COLOR_ATTACHMENT0, {{0, 1, -1, -1, -1, -1, -1, -1, -1}}},
556     {GL_RGB, 3, FORMAT_COLOR, GL_COLOR_ATTACHMENT0, {{0, 1, 2, -1, -1, -1, -1, -1, -1}}},
557     {GL_RGBA, 4, FORMAT_COLOR, GL_COLOR_ATTACHMENT0, {{0, 1, 2, 3, -1, -1, -1, -1, -1}}},
558     {GL_BGR, 3, FORMAT_COLOR, GL_COLOR_ATTACHMENT0, {{2, 1, 0, -1, -1, -1, -1, -1, -1}}},
559     {GL_BGRA, 4, FORMAT_COLOR, GL_COLOR_ATTACHMENT0, {{2, 1, 0, 3, -1, -1, -1, -1, -1}}},
560     {GL_RED_INTEGER, 1, FORMAT_COLOR_INTEGER, GL_COLOR_ATTACHMENT0, {{0, -1, -1, -1, -1, -1, -1, -1, -1}}},
561     {GL_GREEN_INTEGER, 1, FORMAT_COLOR_INTEGER, GL_COLOR_ATTACHMENT0, {{-1, 0, -1, -1, -1, -1, -1, -1, -1}}},
562     {GL_BLUE_INTEGER, 1, FORMAT_COLOR_INTEGER, GL_COLOR_ATTACHMENT0, {{-1, -1, 0, -1, -1, -1, -1, -1, -1}}},
563     {GL_RG_INTEGER, 2, FORMAT_COLOR_INTEGER, GL_COLOR_ATTACHMENT0, {{0, 1, -1, -1, -1, -1, -1, -1, -1}}},
564     {GL_RGB_INTEGER, 3, FORMAT_COLOR_INTEGER, GL_COLOR_ATTACHMENT0, {{0, 1, 2, -1, -1, -1, -1, -1, -1}}},
565     {GL_RGBA_INTEGER, 4, FORMAT_COLOR_INTEGER, GL_COLOR_ATTACHMENT0, {{0, 1, 2, 3, -1, -1, -1, -1, -1}}},
566     {GL_BGR_INTEGER, 3, FORMAT_COLOR_INTEGER, GL_COLOR_ATTACHMENT0, {{2, 1, 0, -1, -1, -1, -1, -1, -1}}},
567     {GL_BGRA_INTEGER, 4, FORMAT_COLOR_INTEGER, GL_COLOR_ATTACHMENT0, {{2, 1, 0, 3, -1, -1, -1, -1, -1}}},
568 };
569 
570 static const PixelFormat esFormats[] = {
571     {GL_DEPTH_COMPONENT, 1, FORMAT_DEPTH, GL_DEPTH_ATTACHMENT, {{-1, -1, -1, -1, -1, -1, 0, -1, -1}}},
572     {GL_DEPTH_STENCIL, 2, FORMAT_DEPTH_STENCIL, GL_DEPTH_STENCIL_ATTACHMENT, {{-1, -1, -1, -1, -1, -1, 0, 1, -1}}},
573     {GL_RED, 1, FORMAT_COLOR, GL_COLOR_ATTACHMENT0, {{0, -1, -1, -1, -1, -1, -1, -1, -1}}},
574     {GL_RG, 2, FORMAT_COLOR, GL_COLOR_ATTACHMENT0, {{0, 1, -1, -1, -1, -1, -1, -1, -1}}},
575     {GL_RGB, 3, FORMAT_COLOR, GL_COLOR_ATTACHMENT0, {{0, 1, 2, -1, -1, -1, -1, -1, -1}}},
576     {GL_RGBA, 4, FORMAT_COLOR, GL_COLOR_ATTACHMENT0, {{0, 1, 2, 3, -1, -1, -1, -1, -1}}},
577     {GL_LUMINANCE, 1, FORMAT_COLOR, GL_COLOR_ATTACHMENT0, {{-1, -1, -1, -1, -1, 0, -1, -1, -1}}},
578     {GL_ALPHA, 1, FORMAT_COLOR, GL_COLOR_ATTACHMENT0, {{-1, -1, -1, 0, -1, -1, -1, -1, -1}}},
579     {GL_LUMINANCE_ALPHA, 2, FORMAT_COLOR, GL_COLOR_ATTACHMENT0, {{-1, -1, -1, 1, -1, 0, -1, -1, -1}}},
580     {GL_RED_INTEGER, 1, FORMAT_COLOR_INTEGER, GL_COLOR_ATTACHMENT0, {{0, -1, -1, -1, -1, -1, -1, -1, -1}}},
581     {GL_RG_INTEGER, 2, FORMAT_COLOR_INTEGER, GL_COLOR_ATTACHMENT0, {{0, 1, -1, -1, -1, -1, -1, -1, -1}}},
582     {GL_RGB_INTEGER, 3, FORMAT_COLOR_INTEGER, GL_COLOR_ATTACHMENT0, {{0, 1, 2, -1, -1, -1, -1, -1, -1}}},
583     {GL_RGBA_INTEGER, 4, FORMAT_COLOR_INTEGER, GL_COLOR_ATTACHMENT0, {{0, 1, 2, 3, -1, -1, -1, -1, -1}}},
584 };
585 
586 static const PixelType coreTypes[] = {
587     {GL_UNSIGNED_BYTE, sizeof(GLubyte), STORAGE_UNSIGNED, false, false, {{0, 0, 0, 0, 0, 0, 0, 0, 0}}, true},
588     {GL_BYTE, sizeof(GLbyte), STORAGE_SIGNED, false, false, {{0, 0, 0, 0, 0, 0, 0, 0, 0}}, true},
589     {GL_UNSIGNED_SHORT, sizeof(GLushort), STORAGE_UNSIGNED, false, false, {{0, 0, 0, 0, 0, 0, 0, 0, 0}}, true},
590     {GL_SHORT, sizeof(GLshort), STORAGE_SIGNED, false, false, {{0, 0, 0, 0, 0, 0, 0, 0, 0}}, true},
591     {GL_UNSIGNED_INT, sizeof(GLuint), STORAGE_UNSIGNED, false, false, {{0, 0, 0, 0, 0, 0, 0, 0, 0}}, false},
592     {GL_INT, sizeof(GLint), STORAGE_SIGNED, false, false, {{0, 0, 0, 0, 0, 0, 0, 0, 0}}, false},
593     {GL_HALF_FLOAT, sizeof(GLhalf), STORAGE_FLOAT, false, false, {{0, 0, 0, 0, 0, 0, 0, 0, 0}}, false},
594     {GL_FLOAT, sizeof(GLfloat), STORAGE_FLOAT, false, false, {{0, 0, 0, 0, 0, 0, 0, 0, 0}}, false},
595     {GL_UNSIGNED_SHORT_5_6_5, sizeof(GLushort), STORAGE_UNSIGNED, true, false, {{5, 6, 5, 0, 0, 0, 0, 0, 0}}, false},
596     {GL_UNSIGNED_SHORT_4_4_4_4, sizeof(GLushort), STORAGE_UNSIGNED, true, false, {{4, 4, 4, 4, 0, 0, 0, 0, 0}}, false},
597     {GL_UNSIGNED_SHORT_5_5_5_1, sizeof(GLushort), STORAGE_UNSIGNED, true, false, {{5, 5, 5, 1, 0, 0, 0, 0, 0}}, false},
598     {GL_UNSIGNED_INT_2_10_10_10_REV,
599      sizeof(GLuint),
600      STORAGE_UNSIGNED,
601      true,
602      true,
603      {{10, 10, 10, 2, 0, 0, 0, 0, 0}},
604      false},
605     {GL_UNSIGNED_INT_24_8, sizeof(GLuint), STORAGE_UNSIGNED, true, false, {{0, 0, 0, 0, 0, 0, 24, 8, 0}}, false},
606     {GL_UNSIGNED_INT_10F_11F_11F_REV, sizeof(GLuint), STORAGE_FLOAT, true, true, {{6, 7, 7, 0, 0, 0, 0, 0, 0}}, false},
607     {GL_UNSIGNED_INT_5_9_9_9_REV, sizeof(GLuint), STORAGE_FLOAT, true, true, {{9, 9, 9, 5, 0, 0, 0, 0, 0}}, false},
608     {GL_FLOAT_32_UNSIGNED_INT_24_8_REV,
609      sizeof(GLfloat) + sizeof(GLuint),
610      STORAGE_FLOAT,
611      true,
612      true,
613      {{0, 0, 0, 0, 0, 0, 32, 8, 24}},
614      false},
615     {GL_UNSIGNED_BYTE_3_3_2, sizeof(GLubyte), STORAGE_UNSIGNED, true, false, {{3, 3, 2, 0, 0, 0, 0, 0, 0}}, false},
616     {GL_UNSIGNED_BYTE_2_3_3_REV, sizeof(GLubyte), STORAGE_UNSIGNED, true, true, {{3, 3, 2, 0, 0, 0, 0, 0, 0}}, false},
617     {GL_UNSIGNED_SHORT_5_6_5_REV, sizeof(GLushort), STORAGE_UNSIGNED, true, true, {{5, 6, 5, 0, 0, 0, 0, 0, 0}}, false},
618     {GL_UNSIGNED_SHORT_4_4_4_4_REV,
619      sizeof(GLushort),
620      STORAGE_UNSIGNED,
621      true,
622      true,
623      {{4, 4, 4, 4, 0, 0, 0, 0, 0}},
624      false},
625     {GL_UNSIGNED_SHORT_1_5_5_5_REV,
626      sizeof(GLushort),
627      STORAGE_UNSIGNED,
628      true,
629      true,
630      {{5, 5, 5, 1, 0, 0, 0, 0, 0}},
631      false},
632     {GL_UNSIGNED_INT_8_8_8_8, sizeof(GLuint), STORAGE_UNSIGNED, true, false, {{8, 8, 8, 8, 0, 0, 0, 0, 0}}, false},
633     {GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(GLuint), STORAGE_UNSIGNED, true, true, {{8, 8, 8, 8, 0, 0, 0, 0, 0}}, false},
634     {GL_UNSIGNED_INT_10_10_10_2, sizeof(GLuint), STORAGE_UNSIGNED, true, true, {{10, 10, 10, 2, 0, 0, 0, 0, 0}}, false},
635 };
636 
637 static const PixelType esTypes[] = {
638     {GL_UNSIGNED_BYTE, sizeof(GLubyte), STORAGE_UNSIGNED, false, false, {{0, 0, 0, 0, 0, 0, 0, 0, 0}}, true},
639     {GL_BYTE, sizeof(GLbyte), STORAGE_SIGNED, false, false, {{0, 0, 0, 0, 0, 0, 0, 0, 0}}, true},
640     {GL_UNSIGNED_SHORT, sizeof(GLushort), STORAGE_UNSIGNED, false, false, {{0, 0, 0, 0, 0, 0, 0, 0, 0}}, true},
641     {GL_SHORT, sizeof(GLshort), STORAGE_SIGNED, false, false, {{0, 0, 0, 0, 0, 0, 0, 0, 0}}, true},
642     {GL_UNSIGNED_INT, sizeof(GLuint), STORAGE_UNSIGNED, false, false, {{0, 0, 0, 0, 0, 0, 0, 0, 0}}, false},
643     {GL_INT, sizeof(GLint), STORAGE_SIGNED, false, false, {{0, 0, 0, 0, 0, 0, 0, 0, 0}}, false},
644     {GL_HALF_FLOAT, sizeof(GLhalf), STORAGE_FLOAT, false, false, {{0, 0, 0, 0, 0, 0, 0, 0, 0}}, false},
645     {GL_FLOAT, sizeof(GLfloat), STORAGE_FLOAT, false, false, {{0, 0, 0, 0, 0, 0, 0, 0, 0}}, false},
646     {GL_UNSIGNED_SHORT_5_6_5, sizeof(GLushort), STORAGE_UNSIGNED, true, false, {{5, 6, 5, 0, 0, 0, 0, 0, 0}}, false},
647     {GL_UNSIGNED_SHORT_4_4_4_4, sizeof(GLushort), STORAGE_UNSIGNED, true, false, {{4, 4, 4, 4, 0, 0, 0, 0, 0}}, false},
648     {GL_UNSIGNED_SHORT_5_5_5_1, sizeof(GLushort), STORAGE_UNSIGNED, true, false, {{5, 5, 5, 1, 0, 0, 0, 0, 0}}, false},
649     {GL_UNSIGNED_INT_2_10_10_10_REV,
650      sizeof(GLuint),
651      STORAGE_UNSIGNED,
652      true,
653      true,
654      {{10, 10, 10, 2, 0, 0, 0, 0, 0}},
655      false},
656     {GL_UNSIGNED_INT_24_8, sizeof(GLuint), STORAGE_UNSIGNED, true, false, {{0, 0, 0, 0, 0, 0, 24, 8, 0}}, false},
657     {GL_UNSIGNED_INT_10F_11F_11F_REV, sizeof(GLuint), STORAGE_FLOAT, true, true, {{6, 7, 7, 0, 0, 0, 0, 0, 0}}, false},
658     {GL_UNSIGNED_INT_5_9_9_9_REV, sizeof(GLuint), STORAGE_FLOAT, true, true, {{9, 9, 9, 5, 0, 0, 0, 0, 0}}, false},
659     {GL_FLOAT_32_UNSIGNED_INT_24_8_REV,
660      sizeof(GLfloat) + sizeof(GLuint),
661      STORAGE_FLOAT,
662      true,
663      true,
664      {{0, 0, 0, 0, 0, 0, 32, 8, 24}},
665      false},
666 };
667 
668 static const EnumFormats esValidFormats[] = {
669     {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, 4, true},
670     {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE, 4, true},
671     {GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE, 4, true},
672     {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, 4, true},
673     {GL_RGBA8_SNORM, GL_RGBA, GL_BYTE, 4, false},
674     {GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 2, true},
675     {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 2, true},
676     {GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, 4, true},
677     {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, 4, true},
678     {GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, 8, false},
679     {GL_RGBA32F, GL_RGBA, GL_FLOAT, 16, false},
680     {GL_RGBA16F, GL_RGBA, GL_FLOAT, 16, false},
681     {GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, 4, true},
682     {GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE, 4, true},
683     {GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, 8, true},
684     {GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT, 8, true},
685     {GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT, 16, true},
686     {GL_RGBA32I, GL_RGBA_INTEGER, GL_INT, 16, true},
687     {GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, 4, true},
688     {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, 3, true},
689     {GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE, 3, true},
690     {GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE, 3, false},
691     {GL_RGB8_SNORM, GL_RGB, GL_BYTE, 3, false},
692     {GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 2, true},
693     {GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, 4, false},
694     {GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT, 6, false},
695     {GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT, 12, false},
696     {GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, 4, false},
697     {GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT, 6, false},
698     {GL_RGB9_E5, GL_RGB, GL_FLOAT, 12, false},
699     {GL_RGB16F, GL_RGB, GL_HALF_FLOAT, 6, false},
700     {GL_RGB32F, GL_RGB, GL_FLOAT, 12, false},
701     {GL_RGB16F, GL_RGB, GL_FLOAT, 12, false},
702     {GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, 3, false},
703     {GL_RGB8I, GL_RGB_INTEGER, GL_BYTE, 3, false},
704     {GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, 6, false},
705     {GL_RGB16I, GL_RGB_INTEGER, GL_SHORT, 6, false},
706     {GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT, 12, false},
707     {GL_RGB32I, GL_RGB_INTEGER, GL_INT, 12, false},
708     {GL_RG8, GL_RG, GL_UNSIGNED_BYTE, 2, true},
709     {GL_RG8_SNORM, GL_RG, GL_BYTE, 2, false},
710     {GL_RG16F, GL_RG, GL_HALF_FLOAT, 4, false},
711     {GL_RG32F, GL_RG, GL_FLOAT, 8, false},
712     {GL_RG16F, GL_RG, GL_FLOAT, 8, false},
713     {GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE, 2, true},
714     {GL_RG8I, GL_RG_INTEGER, GL_BYTE, 2, true},
715     {GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT, 4, true},
716     {GL_RG16I, GL_RG_INTEGER, GL_SHORT, 4, true},
717     {GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT, 8, true},
718     {GL_RG32I, GL_RG_INTEGER, GL_INT, 8, true},
719     {GL_R8, GL_RED, GL_UNSIGNED_BYTE, 1, true},
720     {GL_R8_SNORM, GL_RED, GL_BYTE, 1, false},
721     {GL_R16F, GL_RED, GL_HALF_FLOAT, 2, false},
722     {GL_R32F, GL_RED, GL_FLOAT, 4, false},
723     {GL_R16F, GL_RED, GL_FLOAT, 4, false},
724     {GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE, 1, true},
725     {GL_R8I, GL_RED_INTEGER, GL_BYTE, 1, true},
726     {GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT, 2, true},
727     {GL_R16I, GL_RED_INTEGER, GL_SHORT, 2, true},
728     {GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT, 4, true},
729     {GL_R32I, GL_RED_INTEGER, GL_INT, 4, true},
730     {GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 4, true},
731     {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 4, true},
732     {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 2, true},
733     {GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, 4, true},
734     {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 4, true},
735     {GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, 8, true},
736     {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, 4, true},
737     {GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 2, true},
738     {GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 2, true},
739     {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, 3, true},
740     {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 2, true},
741     {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 2, false},
742     {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, 1, false},
743     {GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, 1, false},
744 };
745 
746 static const EnumFormats coreValidFormats[] = {
747     {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE_3_3_2, 3, true},
748     {GL_RGB_INTEGER, GL_RGB_INTEGER, GL_UNSIGNED_BYTE_3_3_2, 3, true},
749     {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE_2_3_3_REV, 3, true},
750     {GL_RGB_INTEGER, GL_RGB_INTEGER, GL_UNSIGNED_BYTE_2_3_3_REV, 3, true},
751     {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 3, true},
752     {GL_RGB_INTEGER, GL_RGB_INTEGER, GL_UNSIGNED_SHORT_5_6_5, 3, true},
753     {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV, 3, true},
754     {GL_RGB_INTEGER, GL_RGB_INTEGER, GL_UNSIGNED_SHORT_5_6_5_REV, 3, true},
755     {GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 4, true},
756     {GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4_REV, 4, true},
757     {GL_RGBA_INTEGER, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT_4_4_4_4, 4, true},
758     {GL_RGBA_INTEGER, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT_4_4_4_4_REV, 4, true},
759     {GL_BGRA, GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV, 4, true},
760     {GL_BGRA, GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4, 4, true},
761     {GL_BGRA_INTEGER, GL_BGRA_INTEGER, GL_UNSIGNED_SHORT_4_4_4_4_REV, 4, true},
762     {GL_BGRA_INTEGER, GL_BGRA_INTEGER, GL_UNSIGNED_SHORT_4_4_4_4, 4, true},
763     {GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 4, true},
764     {GL_BGRA, GL_BGRA, GL_UNSIGNED_SHORT_5_5_5_1, 4, true},
765     {GL_RGBA_INTEGER, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT_5_5_5_1, 4, true},
766     {GL_BGRA_INTEGER, GL_BGRA_INTEGER, GL_UNSIGNED_SHORT_5_5_5_1, 4, true},
767     {GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, 4, true},
768     {GL_BGRA, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, 4, true},
769     {GL_RGBA_INTEGER, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT_1_5_5_5_REV, 4, true},
770     {GL_BGRA_INTEGER, GL_BGRA_INTEGER, GL_UNSIGNED_SHORT_1_5_5_5_REV, 4, true},
771     {GL_RGBA, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, 4, true},
772     {GL_BGRA, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, 4, true},
773     {GL_RGBA_INTEGER, GL_RGBA_INTEGER, GL_UNSIGNED_INT_8_8_8_8, 4, true},
774     {GL_BGRA_INTEGER, GL_BGRA_INTEGER, GL_UNSIGNED_INT_8_8_8_8, 4, true},
775     {GL_RGBA, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 4, true},
776     {GL_BGRA, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 4, true},
777     {GL_RGBA_INTEGER, GL_RGBA_INTEGER, GL_UNSIGNED_INT_8_8_8_8_REV, 4, true},
778     {GL_BGRA_INTEGER, GL_BGRA_INTEGER, GL_UNSIGNED_INT_8_8_8_8_REV, 4, true},
779     {GL_RGBA, GL_RGBA, GL_UNSIGNED_INT_10_10_10_2, 4, true},
780     {GL_BGRA, GL_BGRA, GL_UNSIGNED_INT_10_10_10_2, 4, true},
781     {GL_RGBA_INTEGER, GL_RGBA_INTEGER, GL_UNSIGNED_INT_10_10_10_2, 4, true},
782     {GL_BGRA_INTEGER, GL_BGRA_INTEGER, GL_UNSIGNED_INT_10_10_10_2, 4, true},
783     {GL_RGBA, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, 4, true},
784     {GL_BGRA, GL_BGRA, GL_UNSIGNED_INT_2_10_10_10_REV, 4, true},
785     {GL_RGBA_INTEGER, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, 4, true},
786     {GL_BGRA_INTEGER, GL_BGRA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, 4, true},
787     {GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 2, true},
788     {GL_RGB, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, 3, true},
789     {GL_RGB, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, 4, true},
790     {GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, 2, true},
791 };
792 
793 static const EnumFormats validformats_EXT_texture_type_2_10_10_10_REV[] = {
794     {GL_RGBA, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV_EXT, 4, false},
795     {GL_RGB, GL_RGB, GL_UNSIGNED_INT_2_10_10_10_REV_EXT, 3, false}};
796 
797 // Valid combinations given by GL_EXT_texture_type_2_10_10_10_REV and
798 // GL_OES_required_internalformat extensions
799 static const EnumFormats validformats_OES_required_internalformat[] = {
800     {GL_RGB8_OES, GL_RGB, GL_UNSIGNED_INT_2_10_10_10_REV_EXT, 3, true},
801     {GL_RGB565, GL_RGB, GL_UNSIGNED_INT_2_10_10_10_REV_EXT, 4, true}};
802 
803 // Companion type for GL_FLOAT_32_UNSIGNED_INT_24_8_REV. Stencil part was
804 // not split into 24/8 to avoid any packing related issues from compiler.
805 struct F_32_UINT_24_8_REV
806 {
807     GLfloat d;
808     GLuint s;
809 };
810 
811 // custom pixel data type. holds both float and integer pixel data. memory consuming, but
812 // it is not that relavant in this case. makes comparing more reliable and flexible
813 struct FloatPixel
814 {
815     int i_r;
816     int i_g;
817     int i_b;
818     int i_a;
819     int i_d;
820     int i_s;
821 
822     unsigned int ui_r;
823     unsigned int ui_g;
824     unsigned int ui_b;
825     unsigned int ui_a;
826     unsigned int ui_d;
827     unsigned int ui_s;
828 
829     float r;
830     float g;
831     float b;
832     float a;
833     float d;
834     float s;
835 };
836 
837 static const int NUM_FLOAT_PIXEL_COUNT = sizeof(FloatPixel) / sizeof(float);
838 
839 typedef int rawIntPixel[4];
840 typedef unsigned int rawUintPixel[4];
841 typedef float rawFloatPixel[4];
842 
843 struct PackedPixelsBufferProperties
844 {
845     int elementsInGroup;      // number of elements in a group
846     int rowLength;            // number of groups in the row
847     int alignment;            // alignment (in bytes)
848     int elementSize;          // size of an element (in bytes)
849     int elementsInRow;        // row size (in elements)
850     int elementsInRowNoAlign; // row size (in elements) without alignment
851     int rowCount;             // number of rows in 2D image
852     int imagesCount;          // number of 2D images in 3D image
853     int skipPixels;           // (UN)PACK_SKIP_PIXELS
854     int skipRows;             // (UN)PACK_SKIP_ROWS
855     int skipImages;           // (UN)PACK_SKIP_IMAGES
856     int swapBytes;
857     int lsbFirst;
858 };
859 
getTypeStr(GLenum type)860 std::string getTypeStr(GLenum type)
861 {
862     // this function extends glu::getTypeStr by types used in this tests
863 
864     typedef std::map<GLenum, std::string> TypeMap;
865     static TypeMap typeMap;
866     if (typeMap.empty())
867     {
868         typeMap[GL_UNSIGNED_BYTE_3_3_2]        = "GL_UNSIGNED_BYTE_3_3_2";
869         typeMap[GL_UNSIGNED_BYTE_2_3_3_REV]    = "GL_UNSIGNED_BYTE_2_3_3_REV";
870         typeMap[GL_UNSIGNED_SHORT_5_6_5_REV]   = "GL_UNSIGNED_SHORT_5_6_5_REV";
871         typeMap[GL_UNSIGNED_SHORT_4_4_4_4_REV] = "GL_UNSIGNED_SHORT_4_4_4_4_REV";
872         typeMap[GL_UNSIGNED_SHORT_1_5_5_5_REV] = "GL_UNSIGNED_SHORT_1_5_5_5_REV";
873         typeMap[GL_UNSIGNED_INT_8_8_8_8]       = "GL_UNSIGNED_INT_8_8_8_8";
874         typeMap[GL_UNSIGNED_INT_8_8_8_8_REV]   = "GL_UNSIGNED_INT_8_8_8_8_REV";
875         typeMap[GL_UNSIGNED_INT_10_10_10_2]    = "GL_UNSIGNED_INT_10_10_10_2";
876     }
877 
878     TypeMap::iterator it = typeMap.find(type);
879     if (it == typeMap.end())
880     {
881         // if type is not in map use glu function
882         return glu::getTypeStr(type).toString();
883     }
884     return it->second;
885 }
886 
getFormatStr(GLenum format)887 std::string getFormatStr(GLenum format)
888 {
889     // this function extends glu::getTextureFormatStr by types used in this tests
890 
891     typedef std::map<GLenum, std::string> FormatMap;
892     static FormatMap formatMap;
893     if (formatMap.empty())
894     {
895         formatMap[GL_GREEN]                       = "GL_GREEN";
896         formatMap[GL_BLUE]                        = "GL_BLUE";
897         formatMap[GL_GREEN_INTEGER]               = "GL_GREEN_INTEGER";
898         formatMap[GL_BLUE_INTEGER]                = "GL_BLUE_INTEGER";
899         formatMap[GL_BGR]                         = "GL_BGR";
900         formatMap[GL_BGR_INTEGER]                 = "GL_BGR_INTEGER";
901         formatMap[GL_BGRA_INTEGER]                = "GL_BGRA_INTEGER";
902         formatMap[GL_R3_G3_B2]                    = "GL_R3_G3_B2";
903         formatMap[GL_RGB4]                        = "GL_RGB4";
904         formatMap[GL_RGB5]                        = "GL_RGB5";
905         formatMap[GL_RGB12]                       = "GL_RGB12";
906         formatMap[GL_RGBA2]                       = "GL_RGBA2";
907         formatMap[GL_RGBA12]                      = "GL_RGBA12";
908         formatMap[GL_COMPRESSED_RED]              = "GL_COMPRESSED_RED";
909         formatMap[GL_COMPRESSED_RG]               = "GL_COMPRESSED_RG";
910         formatMap[GL_COMPRESSED_RGB]              = "GL_COMPRESSED_RGB";
911         formatMap[GL_COMPRESSED_RGBA]             = "GL_COMPRESSED_RGBA";
912         formatMap[GL_COMPRESSED_SRGB]             = "GL_COMPRESSED_SRGB";
913         formatMap[GL_COMPRESSED_SRGB_ALPHA]       = "GL_COMPRESSED_SRGB_ALPHA";
914         formatMap[GL_COMPRESSED_RED_RGTC1]        = "GL_COMPRESSED_RED_RGTC1";
915         formatMap[GL_COMPRESSED_SIGNED_RED_RGTC1] = "GL_COMPRESSED_SIGNED_RED_RGTC1";
916         formatMap[GL_COMPRESSED_RG_RGTC2]         = "GL_COMPRESSED_RG_RGTC2";
917         formatMap[GL_COMPRESSED_SIGNED_RG_RGTC2]  = "GL_COMPRESSED_SIGNED_RG_RGTC2";
918         formatMap[GL_STENCIL_INDEX]               = "GL_STENCIL_INDEX";
919     }
920 
921     FormatMap::iterator it = formatMap.find(format);
922     if (it == formatMap.end())
923     {
924         // if format is not in map use glu function
925         return glu::getTextureFormatStr(format).toString();
926     }
927     return it->second;
928 }
929 
getModeStr(GLenum type)930 std::string getModeStr(GLenum type)
931 {
932     typedef std::map<GLenum, std::string> ModeMap;
933     static ModeMap modeMap;
934     if (modeMap.empty())
935     {
936         modeMap[GL_UNPACK_ROW_LENGTH]   = "GL_UNPACK_ROW_LENGTH";
937         modeMap[GL_UNPACK_SKIP_ROWS]    = "GL_UNPACK_SKIP_ROWS";
938         modeMap[GL_UNPACK_SKIP_PIXELS]  = "GL_UNPACK_SKIP_PIXELS";
939         modeMap[GL_UNPACK_ALIGNMENT]    = "GL_UNPACK_ALIGNMENT";
940         modeMap[GL_UNPACK_IMAGE_HEIGHT] = "GL_UNPACK_IMAGE_HEIGHT";
941         modeMap[GL_UNPACK_SKIP_IMAGES]  = "GL_UNPACK_SKIP_IMAGES";
942         modeMap[GL_PACK_ROW_LENGTH]     = "GL_PACK_ROW_LENGTH";
943         modeMap[GL_PACK_SKIP_ROWS]      = "GL_PACK_SKIP_ROWS";
944         modeMap[GL_PACK_SKIP_PIXELS]    = "GL_PACK_SKIP_PIXELS";
945         modeMap[GL_PACK_ALIGNMENT]      = "GL_PACK_ALIGNMENT";
946         modeMap[GL_UNPACK_SWAP_BYTES]   = "GL_UNPACK_SWAP_BYTES";
947         modeMap[GL_UNPACK_LSB_FIRST]    = "GL_UNPACK_LSB_FIRST";
948         modeMap[GL_PACK_SWAP_BYTES]     = "GL_PACK_SWAP_BYTES";
949         modeMap[GL_PACK_LSB_FIRST]      = "GL_PACK_LSB_FIRST";
950         modeMap[GL_PACK_IMAGE_HEIGHT]   = "GL_PACK_IMAGE_HEIGHT";
951         modeMap[GL_PACK_SKIP_IMAGES]    = "GL_PACK_SKIP_IMAGES";
952     }
953 
954     ModeMap::iterator it = modeMap.find(type);
955     if (it == modeMap.end())
956         TCU_FAIL("Unknown mode name");
957     return it->second;
958 }
959 
960 class RectangleTest : public deqp::TestCase
961 {
962 public:
963     RectangleTest(deqp::Context &context, std::string &name, InternalFormat internalFormat);
964     virtual ~RectangleTest();
965 
966     void resetInitialStorageModes();
967     void applyInitialStorageModes();
968     void testAllFormatsAndTypes();
969 
970     virtual tcu::TestNode::IterateResult iterate(void);
971 
972 protected:
973     void createGradient();
974     void swapBytes(int typeSize, std::vector<GLbyte> &dataBuffer);
975 
976     template <typename Type>
977     void makeGradient(Type (*unpack)(float));
978 
979     template <typename Type>
980     static Type unpackSizedComponents(float value, int s1, int s2, int s3, int s4);
981 
982     template <typename Type>
983     static Type unpackSizedComponentsRev(float value, int s1, int s2, int s3, int s4);
984 
985     static GLubyte unpack_UNSIGNED_BYTE(float value);
986     static GLbyte unpack_BYTE(float value);
987     static GLushort unpack_UNSIGNED_SHORT(float value);
988     static GLshort unpack_SHORT(float value);
989     static GLuint unpack_UNSIGNED_INT(float value);
990     static GLint unpack_INT(float value);
991     static GLhalf unpack_HALF_FLOAT(float value);
992     static GLfloat unpack_FLOAT(float value);
993     static GLubyte unpack_UNSIGNED_BYTE_3_3_2(float value);
994     static GLubyte unpack_UNSIGNED_BYTE_2_3_3_REV(float value);
995     static GLushort unpack_UNSIGNED_SHORT_5_6_5_REV(float value);
996     static GLushort unpack_UNSIGNED_SHORT_4_4_4_4_REV(float value);
997     static GLushort unpack_UNSIGNED_SHORT_1_5_5_5_REV(float value);
998     static GLuint unpack_UNSIGNED_INT_8_8_8_8(float value);
999     static GLuint unpack_UNSIGNED_INT_8_8_8_8_REV(float value);
1000     static GLuint unpack_UNSIGNED_INT_10_10_10_2(float value);
1001     static GLushort unpack_UNSIGNED_SHORT_5_6_5(float value);
1002     static GLushort unpack_UNSIGNED_SHORT_4_4_4_4(float value);
1003     static GLushort unpack_UNSIGNED_SHORT_5_5_5_1(float value);
1004     static GLuint unpack_UNSIGNED_INT_2_10_10_10_REV(float value);
1005     static GLuint unpack_UNSIGNED_INT_24_8(float value);
1006     static GLuint unpack_UNSIGNED_INT_5_9_9_9_REV(float value);
1007     static GLuint unpack_UNSIGNED_INT_10F_11F_11F_REV(float value);
1008     static F_32_UINT_24_8_REV unpack_FLOAT_32_UNSIGNED_INT_24_8_REV(float value);
1009 
1010     bool isFormatValid(const PixelFormat &format, const PixelType &type, const struct InternalFormat &internalformat,
1011                        bool checkInput, bool checkOutput, int operation) const;
1012     bool isUnsizedFormat(GLenum format) const;
1013     bool isSRGBFormat(const InternalFormat &internalFormat) const;
1014     bool isSNORMFormat(const InternalFormat &internalFormat) const;
1015     bool isCopyValid(const InternalFormat &copyInternalFormat, const InternalFormat &internalFormat) const;
1016     bool isFBOImageAttachValid(const InternalFormat &internalformat, GLenum format, GLenum type) const;
1017 
1018     const PixelFormat &getPixelFormat(GLenum format) const;
1019     const PixelType &getPixelType(GLenum type) const;
1020     const EnumFormats *getCanonicalFormat(const InternalFormat &internalformat, GLenum format, GLenum type) const;
1021     InternalFormatSamplerType getSampler(const PixelType &type, const PixelFormat &format) const;
1022 
1023     GLenum readOutputData(const PixelFormat &outputFormat, const PixelType &outputType, int operation);
1024 
1025     bool doCopy();
1026 
1027     bool doCopyInner();
1028 
1029     bool compare(GLvoid *gradient, GLvoid *data, const PixelFormat &outputFormat, const PixelType &outputType,
1030                  bool isCopy) const;
1031 
1032     void getFloatBuffer(GLvoid *gradient, int samplerIsIntUintFloat, const PixelFormat &format, const PixelType &type,
1033                         int elementCount, std::vector<FloatPixel> &result) const;
1034 
1035     void getBits(const PixelType &type, const PixelFormat &format, std::vector<int> &resultTable) const;
1036 
1037     template <typename Type>
1038     void makeBuffer(const GLvoid *gradient, const PixelFormat &format, int samplerIsIntUintFloat, int elementCount,
1039                     int componentCount, float (*pack)(Type), std::vector<FloatPixel> &result) const;
1040 
1041     template <typename Type>
1042     void makeBufferPackedInt(const GLvoid *gradient, const PixelFormat &format, int elementCount,
1043                              void (*pack)(rawIntPixel *, Type), std::vector<FloatPixel> &result) const;
1044 
1045     template <typename Type>
1046     void makeBufferPackedUint(const GLvoid *gradient, const PixelFormat &format, int elementCount,
1047                               void (*pack)(rawUintPixel *, Type), std::vector<FloatPixel> &result) const;
1048 
1049     template <typename Type>
1050     void makeBufferPackedFloat(const GLvoid *gradient, const PixelFormat &format, int elementCount,
1051                                void (*pack)(rawFloatPixel *, Type), std::vector<FloatPixel> &result) const;
1052 
1053     FloatPixel orderComponentsInt(rawIntPixel values, const PixelFormat &format) const;
1054     FloatPixel orderComponentsUint(rawUintPixel values, const PixelFormat &format) const;
1055     FloatPixel orderComponentsFloat(rawFloatPixel values, const PixelFormat &format) const;
1056 
1057     unsigned int getRealBitPrecision(int bits, bool isFloat) const;
1058 
1059     bool stripBuffer(const PackedPixelsBufferProperties &props, const GLubyte *orginalBuffer,
1060                      std::vector<GLubyte> &newBuffer, bool validate) const;
1061 
1062     int clampSignedValue(int bits, int value) const;
1063     unsigned int clampUnsignedValue(int bits, unsigned int value) const;
1064 
1065     static float pack_UNSIGNED_BYTE(GLubyte value);
1066     static float pack_BYTE(GLbyte value);
1067     static float pack_UNSIGNED_SHORT(GLushort value);
1068     static float pack_SHORT(GLshort value);
1069     static float pack_UNSIGNED_INT(GLuint value);
1070     static float pack_INT(GLint value);
1071     static float pack_HALF_FLOAT(GLhalf value);
1072     static float pack_FLOAT(GLfloat value);
1073     static void pack_UNSIGNED_BYTE_3_3_2(rawFloatPixel *values, GLubyte value);
1074     static void pack_UNSIGNED_BYTE_3_3_2_UINT(rawUintPixel *values, GLubyte value);
1075     static void pack_UNSIGNED_BYTE_3_3_2_INT(rawIntPixel *values, GLubyte value);
1076     static void pack_UNSIGNED_BYTE_2_3_3_REV(rawFloatPixel *values, GLubyte value);
1077     static void pack_UNSIGNED_BYTE_2_3_3_REV_UINT(rawUintPixel *values, GLubyte value);
1078     static void pack_UNSIGNED_BYTE_2_3_3_REV_INT(rawIntPixel *values, GLubyte value);
1079     static void pack_UNSIGNED_SHORT_5_6_5(rawFloatPixel *values, GLushort value);
1080     static void pack_UNSIGNED_SHORT_5_6_5_UINT(rawUintPixel *values, GLushort value);
1081     static void pack_UNSIGNED_SHORT_5_6_5_INT(rawIntPixel *values, GLushort value);
1082     static void pack_UNSIGNED_SHORT_5_6_5_REV(rawFloatPixel *values, GLushort value);
1083     static void pack_UNSIGNED_SHORT_5_6_5_REV_UINT(rawUintPixel *values, GLushort value);
1084     static void pack_UNSIGNED_SHORT_5_6_5_REV_INT(rawIntPixel *values, GLushort value);
1085     static void pack_UNSIGNED_SHORT_4_4_4_4(rawFloatPixel *values, GLushort value);
1086     static void pack_UNSIGNED_SHORT_4_4_4_4_UINT(rawUintPixel *values, GLushort value);
1087     static void pack_UNSIGNED_SHORT_4_4_4_4_INT(rawIntPixel *values, GLushort value);
1088     static void pack_UNSIGNED_SHORT_4_4_4_4_REV(rawFloatPixel *values, GLushort value);
1089     static void pack_UNSIGNED_SHORT_4_4_4_4_REV_UINT(rawUintPixel *values, GLushort value);
1090     static void pack_UNSIGNED_SHORT_4_4_4_4_REV_INT(rawIntPixel *values, GLushort value);
1091     static void pack_UNSIGNED_SHORT_5_5_5_1(rawFloatPixel *values, GLushort value);
1092     static void pack_UNSIGNED_SHORT_5_5_5_1_UINT(rawUintPixel *values, GLushort value);
1093     static void pack_UNSIGNED_SHORT_5_5_5_1_INT(rawIntPixel *values, GLushort value);
1094     static void pack_UNSIGNED_SHORT_1_5_5_5_REV(rawFloatPixel *values, GLushort value);
1095     static void pack_UNSIGNED_SHORT_1_5_5_5_REV_UINT(rawUintPixel *values, GLushort value);
1096     static void pack_UNSIGNED_SHORT_1_5_5_5_REV_INT(rawIntPixel *values, GLushort value);
1097     static void pack_UNSIGNED_INT_8_8_8_8(rawFloatPixel *values, GLuint value);
1098     static void pack_UNSIGNED_INT_8_8_8_8_UINT(rawUintPixel *values, GLuint value);
1099     static void pack_UNSIGNED_INT_8_8_8_8_INT(rawIntPixel *values, GLuint value);
1100     static void pack_UNSIGNED_INT_8_8_8_8_REV(rawFloatPixel *values, GLuint value);
1101     static void pack_UNSIGNED_INT_8_8_8_8_REV_UINT(rawUintPixel *values, GLuint value);
1102     static void pack_UNSIGNED_INT_8_8_8_8_REV_INT(rawIntPixel *values, GLuint value);
1103     static void pack_UNSIGNED_INT_10_10_10_2(rawFloatPixel *values, GLuint value);
1104     static void pack_UNSIGNED_INT_10_10_10_2_UINT(rawUintPixel *values, GLuint value);
1105     static void pack_UNSIGNED_INT_10_10_10_2_INT(rawIntPixel *values, GLuint value);
1106     static void pack_UNSIGNED_INT_2_10_10_10_REV(rawFloatPixel *values, GLuint value);
1107     static void pack_UNSIGNED_INT_2_10_10_10_REV_UINT(rawUintPixel *values, GLuint value);
1108     static void pack_UNSIGNED_INT_2_10_10_10_REV_INT(rawIntPixel *values, GLuint value);
1109     static void pack_UNSIGNED_INT_24_8(rawFloatPixel *values, GLuint value);
1110     static void pack_UNSIGNED_INT_10F_11F_11F_REV(rawFloatPixel *values, GLuint value);
1111     static void pack_UNSIGNED_INT_5_9_9_9_REV(rawFloatPixel *values, GLuint value);
1112     static void pack_FLOAT_32_UNSIGNED_INT_24_8_REV(rawFloatPixel *values, F_32_UINT_24_8_REV value);
1113 
1114     bool getTexImage();
1115     bool getTexImageInner(const PixelFormat &outputFormat, const PixelType &outputType);
1116 
1117     bool doRead(GLuint texture);
1118     bool readPixels(bool isCopy);
1119     bool readPixelsInner(const PixelFormat &outputFormat, const PixelType &outputType, bool isCopy);
1120 
1121 protected:
1122     const InternalFormat m_internalFormat;
1123 
1124     bool m_usePBO;
1125     GLenum m_textureTarget;
1126     PackedPixelsBufferProperties m_initialPackProperties;
1127     PackedPixelsBufferProperties m_initialUnpackProperties;
1128 
1129     std::vector<GLbyte> m_gradient;
1130     const GLubyte m_defaultFillValue;
1131 
1132 public:
1133     // debuf counters
1134     static int m_countReadPixels;
1135     static int m_countReadPixelsOK;
1136     static int m_countGetTexImage;
1137     static int m_countGetTexImageOK;
1138     static int m_countCompare;
1139     static int m_countCompareOK;
1140 
1141 private:
1142     // those attribute change multiple times during test execution
1143     PixelFormat m_inputFormat;
1144     PixelType m_inputType;
1145     InternalFormat m_copyInternalFormat;
1146     PackedPixelsBufferProperties m_packProperties;
1147     PackedPixelsBufferProperties m_unpackProperties;
1148     std::vector<GLbyte> m_outputBuffer;
1149 };
1150 
1151 int RectangleTest::m_countReadPixels    = 0;
1152 int RectangleTest::m_countReadPixelsOK  = 0;
1153 int RectangleTest::m_countGetTexImage   = 0;
1154 int RectangleTest::m_countGetTexImageOK = 0;
1155 int RectangleTest::m_countCompare       = 0;
1156 int RectangleTest::m_countCompareOK     = 0;
1157 
RectangleTest(deqp::Context & context,std::string & name,InternalFormat internalFormat)1158 RectangleTest::RectangleTest(deqp::Context &context, std::string &name, InternalFormat internalFormat)
1159     : deqp::TestCase(context, name.c_str(), "")
1160     , m_internalFormat(internalFormat)
1161     , m_usePBO(false)
1162     , m_textureTarget(GL_TEXTURE_2D)
1163     , m_defaultFillValue(0xaa)
1164 {
1165 }
1166 
~RectangleTest()1167 RectangleTest::~RectangleTest()
1168 {
1169 }
1170 
resetInitialStorageModes()1171 void RectangleTest::resetInitialStorageModes()
1172 {
1173     m_initialPackProperties.skipPixels = 0;
1174     m_initialPackProperties.skipRows   = 0;
1175     m_initialPackProperties.rowLength  = 0;
1176     m_initialPackProperties.alignment  = 4;
1177     m_initialPackProperties.rowCount   = 0;
1178     m_initialPackProperties.skipImages = 0;
1179     m_initialPackProperties.lsbFirst   = 0;
1180     m_initialPackProperties.swapBytes  = 0;
1181 
1182     m_initialUnpackProperties.skipPixels = 0;
1183     m_initialUnpackProperties.skipRows   = 0;
1184     m_initialUnpackProperties.rowLength  = 0;
1185     m_initialUnpackProperties.alignment  = 4;
1186     m_initialUnpackProperties.rowCount   = 0;
1187     m_initialUnpackProperties.skipImages = 0;
1188     m_initialUnpackProperties.lsbFirst   = 0;
1189     m_initialUnpackProperties.swapBytes  = 0;
1190 }
1191 
applyInitialStorageModes()1192 void RectangleTest::applyInitialStorageModes()
1193 {
1194     glu::RenderContext &renderContext = m_context.getRenderContext();
1195     const Functions &gl               = renderContext.getFunctions();
1196 
1197     PackedPixelsBufferProperties &up = m_initialUnpackProperties;
1198     PackedPixelsBufferProperties &pp = m_initialPackProperties;
1199 
1200     m_unpackProperties = up;
1201     m_packProperties   = pp;
1202 
1203     gl.pixelStorei(GL_PACK_ROW_LENGTH, pp.rowLength);
1204     gl.pixelStorei(GL_PACK_SKIP_ROWS, pp.skipRows);
1205     gl.pixelStorei(GL_PACK_SKIP_PIXELS, pp.skipPixels);
1206     gl.pixelStorei(GL_PACK_ALIGNMENT, pp.alignment);
1207 
1208     gl.pixelStorei(GL_UNPACK_ROW_LENGTH, up.rowLength);
1209     gl.pixelStorei(GL_UNPACK_SKIP_ROWS, up.skipRows);
1210     gl.pixelStorei(GL_UNPACK_SKIP_PIXELS, up.skipPixels);
1211     gl.pixelStorei(GL_UNPACK_ALIGNMENT, up.alignment);
1212     gl.pixelStorei(GL_UNPACK_IMAGE_HEIGHT, up.rowCount);
1213     gl.pixelStorei(GL_UNPACK_SKIP_IMAGES, up.skipImages);
1214 
1215     if (!isContextTypeES(renderContext.getType()))
1216     {
1217         gl.pixelStorei(GL_PACK_IMAGE_HEIGHT, pp.rowCount);
1218         gl.pixelStorei(GL_PACK_SKIP_IMAGES, pp.skipImages);
1219 
1220         gl.pixelStorei(GL_PACK_SWAP_BYTES, pp.swapBytes);
1221         gl.pixelStorei(GL_PACK_LSB_FIRST, pp.lsbFirst);
1222 
1223         gl.pixelStorei(GL_UNPACK_SWAP_BYTES, up.swapBytes);
1224         gl.pixelStorei(GL_UNPACK_LSB_FIRST, up.lsbFirst);
1225     }
1226 }
1227 
swapBytes(int typeSize,std::vector<GLbyte> & dataBuffer)1228 void RectangleTest::swapBytes(int typeSize, std::vector<GLbyte> &dataBuffer)
1229 {
1230     int bufferSize = static_cast<int>(dataBuffer.size());
1231     switch (typeSize)
1232     {
1233     case 1:
1234         break; // no swapping
1235     case 2:
1236     {
1237         GLushort *data = reinterpret_cast<GLushort *>(&dataBuffer[0]);
1238         for (int i = 0; i < bufferSize / 2; i++)
1239         {
1240             GLushort v = data[i];
1241             data[i]    = ((v & 0xff) << 8) + ((v & 0xff00) >> 8);
1242         }
1243         break;
1244     }
1245     case 4:
1246     case 8: // typeSize is 2 x 32bit, behaves the same this time
1247     {
1248         GLuint *data = reinterpret_cast<GLuint *>(&dataBuffer[0]);
1249         for (int i = 0; i < bufferSize / 4; i++)
1250         {
1251             GLuint v = data[i];
1252             data[i]  = ((v & 0xff) << 24) + ((v & 0xff00) << 8) + ((v & 0xff0000) >> 8) + ((v & 0xff000000) >> 24);
1253         }
1254         break;
1255     }
1256     default:
1257         TCU_FAIL("Invalid size for swapBytes");
1258     }
1259 }
1260 
getPixelFormat(GLenum format) const1261 const PixelFormat &RectangleTest::getPixelFormat(GLenum format) const
1262 {
1263     const PixelFormat *formats;
1264     int formatsCount;
1265     if (glu::isContextTypeES(m_context.getRenderContext().getType()))
1266     {
1267         formats      = esFormats;
1268         formatsCount = DE_LENGTH_OF_ARRAY(esFormats);
1269     }
1270     else
1271     {
1272         formats      = coreFormats;
1273         formatsCount = DE_LENGTH_OF_ARRAY(coreFormats);
1274     }
1275 
1276     // Look up pixel format from a GL enum
1277     for (int i = 0; i < formatsCount; i++)
1278     {
1279         if (formats[i].format == format)
1280             return formats[i];
1281     }
1282 
1283     TCU_FAIL("Unsuported format.");
1284     return formats[0];
1285 }
1286 
getPixelType(GLenum type) const1287 const PixelType &RectangleTest::getPixelType(GLenum type) const
1288 {
1289     const PixelType *types;
1290     int typesCount;
1291     if (glu::isContextTypeES(m_context.getRenderContext().getType()))
1292     {
1293         types      = esTypes;
1294         typesCount = DE_LENGTH_OF_ARRAY(esTypes);
1295     }
1296     else
1297     {
1298         types      = coreTypes;
1299         typesCount = DE_LENGTH_OF_ARRAY(coreTypes);
1300     }
1301 
1302     for (int i = 0; i < typesCount; i++)
1303     {
1304         if (types[i].type == type)
1305             return types[i];
1306     }
1307 
1308     TCU_FAIL("Unsuported type.");
1309     return types[0];
1310 }
1311 
getCanonicalFormat(const InternalFormat & internalformat,GLenum format,GLenum type) const1312 const EnumFormats *RectangleTest::getCanonicalFormat(const InternalFormat &internalformat, GLenum format,
1313                                                      GLenum type) const
1314 {
1315     // function returns a canonical format from internal format. for example
1316     // GL_RGBA16F => { GL_RGBA, GL_FLOAT }; used mostly for GLES tests
1317 
1318     if (glu::isContextTypeES(m_context.getRenderContext().getType()))
1319     {
1320         for (int i = 0; i < DE_LENGTH_OF_ARRAY(esValidFormats); ++i)
1321         {
1322             if ((esValidFormats[i].internalformat == internalformat.sizedFormat) &&
1323                 (esValidFormats[i].format == format) && (esValidFormats[i].type == type))
1324             {
1325                 return &(esValidFormats[i]);
1326             }
1327         }
1328 
1329         const glu::ContextInfo &contextInfo = m_context.getContextInfo();
1330         if (contextInfo.isExtensionSupported("GL_EXT_texture_type_2_10_10_10_REV"))
1331         {
1332             for (int i = 0; i < DE_LENGTH_OF_ARRAY(validformats_EXT_texture_type_2_10_10_10_REV); ++i)
1333             {
1334                 if (validformats_EXT_texture_type_2_10_10_10_REV[i].internalformat == internalformat.sizedFormat &&
1335                     validformats_EXT_texture_type_2_10_10_10_REV[i].format == format &&
1336                     validformats_EXT_texture_type_2_10_10_10_REV[i].type == type)
1337                 {
1338                     return &(validformats_EXT_texture_type_2_10_10_10_REV[i]);
1339                 }
1340             }
1341 
1342             if (contextInfo.isExtensionSupported("GL_OES_required_internalformat"))
1343             {
1344                 for (int i = 0; i < DE_LENGTH_OF_ARRAY(validformats_OES_required_internalformat); ++i)
1345                 {
1346                     if (validformats_OES_required_internalformat[i].internalformat == internalformat.sizedFormat &&
1347                         validformats_OES_required_internalformat[i].format == format &&
1348                         validformats_OES_required_internalformat[i].type == type)
1349                     {
1350                         return &(validformats_OES_required_internalformat[i]);
1351                     }
1352                 }
1353             }
1354         }
1355     }
1356     else
1357     {
1358         for (int i = 0; i < DE_LENGTH_OF_ARRAY(coreValidFormats); ++i)
1359         {
1360             if ((coreValidFormats[i].internalformat == internalformat.sizedFormat) &&
1361                 (coreValidFormats[i].format == format) && (coreValidFormats[i].type == type))
1362             {
1363                 return &(coreValidFormats[i]);
1364             }
1365         }
1366     }
1367 
1368     return 0;
1369 }
1370 
getSampler(const PixelType & type,const PixelFormat & format) const1371 InternalFormatSamplerType RectangleTest::getSampler(const PixelType &type, const PixelFormat &format) const
1372 {
1373     switch (type.storage)
1374     {
1375     case STORAGE_FLOAT:
1376         return SAMPLER_FLOAT;
1377 
1378     case STORAGE_UNSIGNED:
1379         if ((format.componentFormat == FORMAT_COLOR_INTEGER) || (format.componentFormat == FORMAT_STENCIL))
1380             return SAMPLER_UINT;
1381         return SAMPLER_UNORM;
1382 
1383     case STORAGE_SIGNED:
1384         if (format.componentFormat == FORMAT_COLOR_INTEGER)
1385             return SAMPLER_INT;
1386         return SAMPLER_NORM;
1387 
1388     default:
1389         TCU_FAIL("Invalid storage specifier");
1390     }
1391 }
1392 
createGradient()1393 void RectangleTest::createGradient()
1394 {
1395     switch (m_inputType.type)
1396     {
1397     case GL_UNSIGNED_BYTE:
1398         makeGradient(unpack_UNSIGNED_BYTE);
1399         break;
1400     case GL_BYTE:
1401         makeGradient<GLbyte>(unpack_BYTE);
1402         break;
1403     case GL_UNSIGNED_SHORT:
1404         makeGradient<GLushort>(unpack_UNSIGNED_SHORT);
1405         break;
1406     case GL_SHORT:
1407         makeGradient<GLshort>(unpack_SHORT);
1408         break;
1409     case GL_UNSIGNED_INT:
1410         makeGradient<GLuint>(unpack_UNSIGNED_INT);
1411         break;
1412     case GL_INT:
1413         makeGradient<GLint>(unpack_INT);
1414         break;
1415     case GL_HALF_FLOAT:
1416         makeGradient<GLhalf>(unpack_HALF_FLOAT);
1417         break;
1418     case GL_FLOAT:
1419         makeGradient<GLfloat>(unpack_FLOAT);
1420         break;
1421     case GL_UNSIGNED_SHORT_5_6_5:
1422         makeGradient<GLushort>(unpack_UNSIGNED_SHORT_5_6_5);
1423         break;
1424     case GL_UNSIGNED_SHORT_4_4_4_4:
1425         makeGradient<GLushort>(unpack_UNSIGNED_SHORT_4_4_4_4);
1426         break;
1427     case GL_UNSIGNED_SHORT_5_5_5_1:
1428         makeGradient<GLushort>(unpack_UNSIGNED_SHORT_5_5_5_1);
1429         break;
1430     case GL_UNSIGNED_INT_2_10_10_10_REV:
1431         makeGradient<GLuint>(unpack_UNSIGNED_INT_2_10_10_10_REV);
1432         break;
1433     case GL_UNSIGNED_INT_24_8:
1434         makeGradient<GLuint>(unpack_UNSIGNED_INT_24_8);
1435         break;
1436     case GL_UNSIGNED_INT_10F_11F_11F_REV:
1437         makeGradient<GLuint>(unpack_UNSIGNED_INT_10F_11F_11F_REV);
1438         break;
1439     case GL_UNSIGNED_INT_5_9_9_9_REV:
1440         makeGradient<GLuint>(unpack_UNSIGNED_INT_5_9_9_9_REV);
1441         break;
1442     case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
1443         makeGradient<F_32_UINT_24_8_REV>(unpack_FLOAT_32_UNSIGNED_INT_24_8_REV);
1444         break;
1445     case GL_UNSIGNED_BYTE_3_3_2:
1446         makeGradient<GLubyte>(unpack_UNSIGNED_BYTE_3_3_2);
1447         break;
1448     case GL_UNSIGNED_BYTE_2_3_3_REV:
1449         makeGradient<GLubyte>(unpack_UNSIGNED_BYTE_2_3_3_REV);
1450         break;
1451     case GL_UNSIGNED_SHORT_5_6_5_REV:
1452         makeGradient<GLushort>(unpack_UNSIGNED_SHORT_5_6_5_REV);
1453         break;
1454     case GL_UNSIGNED_SHORT_4_4_4_4_REV:
1455         makeGradient<GLushort>(unpack_UNSIGNED_SHORT_4_4_4_4_REV);
1456         break;
1457     case GL_UNSIGNED_SHORT_1_5_5_5_REV:
1458         makeGradient<GLushort>(unpack_UNSIGNED_SHORT_1_5_5_5_REV);
1459         break;
1460     case GL_UNSIGNED_INT_8_8_8_8:
1461         makeGradient<GLuint>(unpack_UNSIGNED_INT_8_8_8_8);
1462         break;
1463     case GL_UNSIGNED_INT_8_8_8_8_REV:
1464         makeGradient<GLuint>(unpack_UNSIGNED_INT_8_8_8_8_REV);
1465         break;
1466     case GL_UNSIGNED_INT_10_10_10_2:
1467         makeGradient<GLuint>(unpack_UNSIGNED_INT_10_10_10_2);
1468         break;
1469     default:
1470         TCU_FAIL("Unsupported type");
1471     }
1472 }
1473 
1474 template <typename Type>
makeGradient(Type (* unpack)(float))1475 void RectangleTest::makeGradient(Type (*unpack)(float))
1476 {
1477     // number of elements in a group
1478     int elementsInGroup = m_inputFormat.components;
1479     if (m_inputType.special)
1480         elementsInGroup = 1;
1481 
1482     int rowCount = m_unpackProperties.rowCount;
1483     if (rowCount == 0)
1484         rowCount = GRADIENT_HEIGHT + m_unpackProperties.skipRows;
1485 
1486     // number of groups in the row
1487     int rowLength = m_unpackProperties.rowLength;
1488     if (rowLength == 0)
1489         rowLength = GRADIENT_WIDTH + m_unpackProperties.skipPixels;
1490 
1491     int elementSize = m_inputType.size;
1492 
1493     // row size (in elements)
1494     int elementsInRowNoAlign = elementsInGroup * rowLength;
1495     int elementsInRow        = elementsInRowNoAlign;
1496     if (elementSize < m_unpackProperties.alignment)
1497     {
1498         int alignment = m_unpackProperties.alignment;
1499         elementsInRow = (int)(alignment * deFloatCeil(elementSize * elementsInGroup * rowLength / ((float)alignment))) /
1500                         elementSize;
1501     }
1502 
1503     if (m_textureTarget == GL_TEXTURE_2D)
1504         m_unpackProperties.skipImages = 0;
1505 
1506     // "depth" will be 1 + skipped image layers.
1507     // We still want to work on a 2D-ish image later.
1508     int depth = 1 + m_unpackProperties.skipImages;
1509 
1510     m_unpackProperties.elementsInGroup      = elementsInGroup;
1511     m_unpackProperties.rowCount             = rowCount;
1512     m_unpackProperties.rowLength            = rowLength;
1513     m_unpackProperties.elementSize          = elementSize;
1514     m_unpackProperties.elementsInRowNoAlign = elementsInRowNoAlign;
1515     m_unpackProperties.elementsInRow        = elementsInRow;
1516     m_unpackProperties.imagesCount          = depth;
1517 
1518     // element size * elements in row * number of rows * number of 2d images
1519     std::size_t bufferSize = elementSize * elementsInRow * rowCount * depth;
1520 
1521     m_gradient.resize(bufferSize);
1522     Type *data = reinterpret_cast<Type *>(&m_gradient[0]);
1523 
1524     std::size_t dataToSkip  = m_unpackProperties.skipImages * rowCount * elementsInRow;
1525     std::size_t index       = dataToSkip;
1526     const Type defaultValue = unpack(0.5f);
1527     std::fill(data, data + dataToSkip, defaultValue);
1528 
1529     for (int k = m_unpackProperties.skipImages; k < depth; k++)
1530     {
1531         for (int j = 0; j < rowCount; j++)
1532         {
1533             for (int i = 0; i < elementsInRow; i++)
1534             {
1535                 DE_ASSERT(index < bufferSize);
1536                 int x = i / elementsInGroup;
1537                 if ((k == depth - 1) && (m_unpackProperties.skipRows <= j) &&
1538                     (j < m_unpackProperties.skipRows + GRADIENT_HEIGHT) && (m_unpackProperties.skipPixels <= x) &&
1539                     (x < m_unpackProperties.skipPixels + GRADIENT_WIDTH))
1540                 {
1541                     float value = static_cast<float>(x - m_unpackProperties.skipPixels) / GRADIENT_WIDTH;
1542                     int channel = i - elementsInGroup * x;
1543                     value *= 1.0f - 0.25f * channel;
1544                     data[index] = unpack(value);
1545                 }
1546                 else
1547                 {
1548                     data[index] = defaultValue;
1549                 }
1550                 index++;
1551             }
1552         }
1553     }
1554 }
1555 
1556 template <typename Type>
unpackSizedComponents(float value,int s1,int s2,int s3,int s4)1557 Type RectangleTest::unpackSizedComponents(float value, int s1, int s2, int s3, int s4)
1558 {
1559     int typeBits = sizeof(Type) * 8;
1560     double v     = static_cast<double>(value);
1561     Type c1      = static_cast<Type>(v * 1.00 * ((1 << s1) - 1));
1562     Type c2      = static_cast<Type>(v * 0.75 * ((1 << s2) - 1));
1563     Type c3      = static_cast<Type>(v * 0.50 * ((1 << s3) - 1));
1564     Type c4      = static_cast<Type>(v * 0.25 * ((1 << s4) - 1));
1565     return ((c1) << (typeBits - s1)) | ((c2) << (typeBits - s1 - s2)) | ((c3) << (typeBits - s1 - s2 - s3)) |
1566            ((c4) << (typeBits - s1 - s2 - s3 - s4));
1567 }
1568 
1569 template <typename Type>
unpackSizedComponentsRev(float value,int s1,int s2,int s3,int s4)1570 Type RectangleTest::unpackSizedComponentsRev(float value, int s1, int s2, int s3, int s4)
1571 {
1572     int typeBits = sizeof(Type) * 8;
1573     double v     = static_cast<double>(value);
1574     Type c1      = static_cast<Type>(v * 1.00 * ((1 << s4) - 1));
1575     Type c2      = static_cast<Type>(v * 0.75 * ((1 << s3) - 1));
1576     Type c3      = static_cast<Type>(v * 0.50 * ((1 << s2) - 1));
1577     Type c4      = static_cast<Type>(v * 0.25 * ((1 << s1) - 1));
1578     return ((c4) << (typeBits - s1)) | ((c3) << (typeBits - s1 - s2)) | ((c2) << (typeBits - s1 - s2 - s3)) |
1579            ((c1) << (typeBits - s1 - s2 - s3 - s4));
1580 }
1581 
unpack_UNSIGNED_BYTE(float value)1582 GLubyte RectangleTest::unpack_UNSIGNED_BYTE(float value)
1583 {
1584     return static_cast<GLubyte>(value * std::numeric_limits<GLubyte>::max());
1585 }
1586 
unpack_BYTE(float value)1587 GLbyte RectangleTest::unpack_BYTE(float value)
1588 {
1589     return static_cast<GLbyte>(value * std::numeric_limits<GLbyte>::max());
1590 }
1591 
unpack_UNSIGNED_SHORT(float value)1592 GLushort RectangleTest::unpack_UNSIGNED_SHORT(float value)
1593 {
1594     return static_cast<GLushort>(value * std::numeric_limits<GLushort>::max());
1595 }
1596 
unpack_SHORT(float value)1597 GLshort RectangleTest::unpack_SHORT(float value)
1598 {
1599     return static_cast<GLshort>(value * std::numeric_limits<GLshort>::max());
1600 }
1601 
unpack_UNSIGNED_INT(float value)1602 GLuint RectangleTest::unpack_UNSIGNED_INT(float value)
1603 {
1604     return static_cast<GLuint>(value * std::numeric_limits<GLuint>::max());
1605 }
1606 
unpack_INT(float value)1607 GLint RectangleTest::unpack_INT(float value)
1608 {
1609     return static_cast<GLint>(value * std::numeric_limits<GLint>::max());
1610 }
1611 
unpack_HALF_FLOAT(float value)1612 GLhalf RectangleTest::unpack_HALF_FLOAT(float value)
1613 {
1614     return floatToHalfFloat(value);
1615 }
1616 
unpack_FLOAT(float value)1617 GLfloat RectangleTest::unpack_FLOAT(float value)
1618 {
1619     return value;
1620 }
1621 
unpack_UNSIGNED_BYTE_3_3_2(float value)1622 GLubyte RectangleTest::unpack_UNSIGNED_BYTE_3_3_2(float value)
1623 {
1624     return unpackSizedComponents<GLubyte>(value, 3, 3, 2, 0);
1625 }
1626 
unpack_UNSIGNED_BYTE_2_3_3_REV(float value)1627 GLubyte RectangleTest::unpack_UNSIGNED_BYTE_2_3_3_REV(float value)
1628 {
1629     return unpackSizedComponentsRev<GLubyte>(value, 2, 3, 3, 0);
1630 }
1631 
unpack_UNSIGNED_SHORT_5_6_5_REV(float value)1632 GLushort RectangleTest::unpack_UNSIGNED_SHORT_5_6_5_REV(float value)
1633 {
1634     return unpackSizedComponentsRev<GLushort>(value, 5, 6, 5, 0);
1635 }
1636 
unpack_UNSIGNED_SHORT_4_4_4_4_REV(float value)1637 GLushort RectangleTest::unpack_UNSIGNED_SHORT_4_4_4_4_REV(float value)
1638 {
1639     return unpackSizedComponentsRev<GLushort>(value, 4, 4, 4, 4);
1640 }
1641 
unpack_UNSIGNED_SHORT_1_5_5_5_REV(float value)1642 GLushort RectangleTest::unpack_UNSIGNED_SHORT_1_5_5_5_REV(float value)
1643 {
1644     return unpackSizedComponentsRev<GLushort>(value, 1, 5, 5, 5);
1645 }
1646 
unpack_UNSIGNED_INT_8_8_8_8(float value)1647 GLuint RectangleTest::unpack_UNSIGNED_INT_8_8_8_8(float value)
1648 {
1649     return unpackSizedComponents<GLuint>(value, 8, 8, 8, 8);
1650 }
1651 
unpack_UNSIGNED_INT_8_8_8_8_REV(float value)1652 GLuint RectangleTest::unpack_UNSIGNED_INT_8_8_8_8_REV(float value)
1653 {
1654     return unpackSizedComponentsRev<GLuint>(value, 8, 8, 8, 8);
1655 }
1656 
unpack_UNSIGNED_INT_10_10_10_2(float value)1657 GLuint RectangleTest::unpack_UNSIGNED_INT_10_10_10_2(float value)
1658 {
1659     return unpackSizedComponents<GLuint>(value, 10, 10, 10, 2);
1660 }
1661 
unpack_UNSIGNED_SHORT_5_6_5(float value)1662 GLushort RectangleTest::unpack_UNSIGNED_SHORT_5_6_5(float value)
1663 {
1664     return unpackSizedComponents<GLushort>(value, 5, 6, 5, 0);
1665 }
1666 
unpack_UNSIGNED_SHORT_4_4_4_4(float value)1667 GLushort RectangleTest::unpack_UNSIGNED_SHORT_4_4_4_4(float value)
1668 {
1669     return unpackSizedComponents<GLushort>(value, 4, 4, 4, 4);
1670 }
1671 
unpack_UNSIGNED_SHORT_5_5_5_1(float value)1672 GLushort RectangleTest::unpack_UNSIGNED_SHORT_5_5_5_1(float value)
1673 {
1674     return unpackSizedComponents<GLushort>(value, 5, 5, 5, 1);
1675 }
1676 
unpack_UNSIGNED_INT_2_10_10_10_REV(float value)1677 GLuint RectangleTest::unpack_UNSIGNED_INT_2_10_10_10_REV(float value)
1678 {
1679     return unpackSizedComponentsRev<GLuint>(value, 2, 10, 10, 10);
1680 }
1681 
unpack_UNSIGNED_INT_24_8(float value)1682 GLuint RectangleTest::unpack_UNSIGNED_INT_24_8(float value)
1683 {
1684     return unpackSizedComponents<GLuint>(value, 24, 8, 0, 0);
1685 }
1686 
unpack_UNSIGNED_INT_5_9_9_9_REV(float value)1687 GLuint RectangleTest::unpack_UNSIGNED_INT_5_9_9_9_REV(float value)
1688 {
1689     const int N     = 9;
1690     const int B     = 15;
1691     const int E_max = 31;
1692 
1693     GLfloat red   = value * 1.00f;
1694     GLfloat green = value * 0.75f;
1695     GLfloat blue  = value * 0.50f;
1696 
1697     GLfloat sharedExpMax =
1698         (deFloatPow(2.0f, (float)N) - 1.0f) / deFloatPow(2.0f, (float)N) * deFloatPow(2.0f, (float)(E_max - B));
1699 
1700     GLfloat red_c   = deFloatMax(0, deFloatMin(sharedExpMax, red));
1701     GLfloat green_c = deFloatMax(0, deFloatMin(sharedExpMax, green));
1702     GLfloat blue_c  = deFloatMax(0, deFloatMin(sharedExpMax, blue));
1703 
1704     GLfloat max_c = deFloatMax(deFloatMax(red_c, green_c), blue_c);
1705 
1706     GLfloat exp_p = deFloatMax(-B - 1, deFloatFloor(deFloatLog2(max_c))) + 1 + B;
1707 
1708     GLfloat max_s = deFloatFloor(max_c / deFloatPow(2.0f, exp_p - (float)B - (float)N) + 0.5f);
1709 
1710     GLfloat exp_s;
1711 
1712     if (0 <= max_s && max_s < deFloatPow(2.0f, (float)N))
1713         exp_s = exp_p;
1714     else
1715         exp_s = exp_p + 1;
1716 
1717     GLfloat red_s   = deFloatFloor(red_c / deFloatPow(2.0f, exp_s - (float)B - (float)N) + 0.5f);
1718     GLfloat green_s = deFloatFloor(green_c / deFloatPow(2.0f, exp_s - (float)B - (float)N) + 0.5f);
1719     GLfloat blue_s  = deFloatFloor(blue_c / deFloatPow(2.0f, exp_s - (float)B - (float)N) + 0.5f);
1720 
1721     GLuint c1 = (static_cast<GLuint>(red_s)) & 511;
1722     GLuint c2 = (static_cast<GLuint>(green_s)) & 511;
1723     GLuint c3 = (static_cast<GLuint>(blue_s)) & 511;
1724     GLuint c4 = (static_cast<GLuint>(exp_s)) & 31;
1725 
1726     return (c1) | (c2 << 9) | (c3 << 18) | (c4 << 27);
1727 }
1728 
unpack_UNSIGNED_INT_10F_11F_11F_REV(float value)1729 GLuint RectangleTest::unpack_UNSIGNED_INT_10F_11F_11F_REV(float value)
1730 {
1731     GLuint c1 = floatToUnisgnedF11(value * 1.00f);
1732     GLuint c2 = floatToUnisgnedF11(value * 0.75f);
1733     GLuint c3 = floatToUnisgnedF10(value * 0.50f);
1734     return (c3 << 22) | (c2 << 11) | (c1);
1735 }
1736 
unpack_FLOAT_32_UNSIGNED_INT_24_8_REV(float value)1737 F_32_UINT_24_8_REV RectangleTest::unpack_FLOAT_32_UNSIGNED_INT_24_8_REV(float value)
1738 {
1739     F_32_UINT_24_8_REV ret;
1740     ret.d = value;
1741     ret.s = (GLuint)(value * 255.0 * 0.75);
1742     ret.s &= 0xff;
1743     return ret;
1744 }
1745 
isFormatValid(const PixelFormat & format,const PixelType & type,const struct InternalFormat & internalformat,bool checkInput,bool checkOutput,int operation) const1746 bool RectangleTest::isFormatValid(const PixelFormat &format, const PixelType &type,
1747                                   const struct InternalFormat &internalformat, bool checkInput, bool checkOutput,
1748                                   int operation) const
1749 {
1750     glu::RenderContext &renderContext   = m_context.getRenderContext();
1751     glu::ContextType contextType        = renderContext.getType();
1752     const glu::ContextInfo &contextInfo = m_context.getContextInfo();
1753     const Functions &gl                 = renderContext.getFunctions();
1754 
1755     int i;
1756 
1757     // Test the combination of input format, input type and internalFormat
1758     if (glu::isContextTypeES(contextType))
1759     {
1760         if (checkInput)
1761         {
1762             // GLES30 has more restricted requirement on combination than GL for input
1763             for (i = 0; i < DE_LENGTH_OF_ARRAY(esValidFormats); ++i)
1764             {
1765                 if (internalformat.sizedFormat == esValidFormats[i].internalformat &&
1766                     format.format == esValidFormats[i].format && type.type == esValidFormats[i].type)
1767                 {
1768                     break;
1769                 }
1770             }
1771 
1772             if (i == DE_LENGTH_OF_ARRAY(esValidFormats))
1773             {
1774                 // Check for support of OES_texture_float extension
1775                 if (((GL_LUMINANCE_ALPHA == format.format) && (GL_LUMINANCE_ALPHA == internalformat.sizedFormat)) ||
1776                     ((GL_LUMINANCE == format.format) && (GL_LUMINANCE == internalformat.sizedFormat)) ||
1777                     ((GL_ALPHA == format.format) && (GL_ALPHA == internalformat.sizedFormat)) ||
1778                     ((GL_RGBA == format.format) && (GL_RGBA == internalformat.sizedFormat)) ||
1779                     ((GL_RGB == format.format) && (GL_RGB == internalformat.sizedFormat)))
1780                 {
1781                     if ((contextInfo.isExtensionSupported("GL_OES_texture_float") && (GL_FLOAT == type.type)) ||
1782                         (contextInfo.isExtensionSupported("GL_OES_texture_half_float") &&
1783                          (GL_HALF_FLOAT_OES == type.type)))
1784                     {
1785                         return true;
1786                     }
1787                 }
1788 
1789                 // Check for support of EXT_texture_type_2_10_10_10_REV extension
1790                 if (((GL_RGBA == format.format) && (GL_RGBA == internalformat.sizedFormat)) ||
1791                     ((GL_RGB == format.format) && (GL_RGB == internalformat.sizedFormat)))
1792                 {
1793                     if (contextInfo.isExtensionSupported("GL_EXT_texture_type_2_10_10_10_REV") &&
1794                         ((GL_UNSIGNED_INT_2_10_10_10_REV_EXT == type.type)))
1795                         return true;
1796                 }
1797 
1798                 // Check for support of NV_packed_float extension
1799                 if ((GL_RGB == format.format) && (GL_RGB == internalformat.sizedFormat))
1800                 {
1801                     if (contextInfo.isExtensionSupported("GL_NV_packed_float") &&
1802                         ((GL_UNSIGNED_INT_10F_11F_11F_REV == type.type)))
1803                         return true;
1804                 }
1805 
1806                 // Check for support of EXT_texture_type_2_10_10_10_REV and GL_OES_required_internalformat extensions
1807                 if (contextInfo.isExtensionSupported("GL_EXT_texture_type_2_10_10_10_REV") &&
1808                     contextInfo.isExtensionSupported("GL_OES_required_internalformat"))
1809                 {
1810                     for (i = 0; i < DE_LENGTH_OF_ARRAY(validformats_OES_required_internalformat); ++i)
1811                     {
1812                         if (internalformat.sizedFormat == validformats_OES_required_internalformat[i].internalformat &&
1813                             format.format == validformats_OES_required_internalformat[i].format &&
1814                             type.type == validformats_OES_required_internalformat[i].type)
1815                         {
1816                             return true;
1817                         }
1818                     }
1819                 }
1820 
1821                 return false;
1822             }
1823 
1824             if ((m_textureTarget == GL_TEXTURE_3D) &&
1825                 ((format.format == GL_DEPTH_COMPONENT) || (format.format == GL_DEPTH_STENCIL)))
1826                 return false;
1827         }
1828         else if (checkOutput)
1829         {
1830             // GLES30 has more restricted requirement on combination than GL for output
1831             // As stated in Section Reading Pixels
1832             InternalFormatSamplerType sampler = internalformat.sampler;
1833 
1834             const PixelFormat &inputFormat = getPixelFormat(internalformat.format);
1835 
1836             if (inputFormat.attachment == GL_DEPTH_ATTACHMENT && contextInfo.isExtensionSupported("GL_NV_read_depth") &&
1837                 format.format == GL_DEPTH_COMPONENT &&
1838                 ((sampler == SAMPLER_FLOAT && type.type == GL_FLOAT) ||
1839                  (sampler != SAMPLER_FLOAT && (type.type == GL_UNSIGNED_SHORT || type.type == GL_UNSIGNED_INT ||
1840                                                type.type == GL_UNSIGNED_INT_24_8))))
1841             {
1842                 return true;
1843             }
1844 
1845             if (inputFormat.attachment == GL_DEPTH_STENCIL_ATTACHMENT &&
1846                 contextInfo.isExtensionSupported("GL_NV_read_depth_stencil") &&
1847                 ((format.format == GL_DEPTH_STENCIL &&
1848                   ((sampler == SAMPLER_FLOAT && type.type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV) ||
1849                    (sampler != SAMPLER_FLOAT && type.type == GL_UNSIGNED_INT_24_8))) ||
1850                  (format.format == GL_DEPTH_COMPONENT &&
1851                   ((sampler == SAMPLER_FLOAT && type.type == GL_FLOAT) ||
1852                    (sampler != SAMPLER_FLOAT && (type.type == GL_UNSIGNED_SHORT || type.type == GL_UNSIGNED_INT ||
1853                                                  type.type == GL_UNSIGNED_INT_24_8))))))
1854             {
1855                 return true;
1856             }
1857 
1858             if (inputFormat.attachment != GL_COLOR_ATTACHMENT0)
1859             {
1860                 return false;
1861             }
1862 
1863             if ((sampler == SAMPLER_UNORM) &&
1864                 (((type.type == GL_UNSIGNED_BYTE) && (format.format == GL_RGB) &&
1865                   (internalformat.sizedFormat == GL_SRGB8)) ||
1866                  ((type.type == GL_UNSIGNED_BYTE) && (format.format == GL_RGBA) &&
1867                   (internalformat.sizedFormat == GL_SRGB8_ALPHA8))) &&
1868                 contextInfo.isExtensionSupported("GL_NV_sRGB_formats"))
1869             {
1870                 return true;
1871             }
1872 
1873             if ((sampler == SAMPLER_UNORM) && (type.type == GL_UNSIGNED_SHORT) && (format.format == GL_RGBA) &&
1874                 ((internalformat.sizedFormat == GL_R16) || (internalformat.sizedFormat == GL_RG16) ||
1875                  (internalformat.sizedFormat == GL_RGBA16)) &&
1876                 contextInfo.isExtensionSupported("GL_EXT_texture_norm16"))
1877             {
1878                 return true;
1879             }
1880 
1881             if ((sampler == SAMPLER_NORM) && (type.type == GL_SHORT) && (format.format == GL_RGBA) &&
1882                 ((internalformat.sizedFormat == GL_R16_SNORM) || (internalformat.sizedFormat == GL_RG16_SNORM) ||
1883                  (internalformat.sizedFormat == GL_RGBA16_SNORM)) &&
1884                 (contextInfo.isExtensionSupported("GL_EXT_texture_norm16") &&
1885                  contextInfo.isExtensionSupported("GL_EXT_render_snorm")))
1886             {
1887                 return true;
1888             }
1889 
1890             if ((sampler == SAMPLER_NORM) && (type.type == GL_BYTE) && (format.format == GL_RGBA) &&
1891                 ((internalformat.sizedFormat == GL_R8_SNORM) || (internalformat.sizedFormat == GL_RG8_SNORM) ||
1892                  (internalformat.sizedFormat == GL_RGBA8_SNORM)) &&
1893                 contextInfo.isExtensionSupported("GL_EXT_render_snorm"))
1894             {
1895                 return true;
1896             }
1897 
1898             GLint implementType;
1899             GLint implementFormat;
1900             gl.getIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &implementType);
1901             gl.getIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &implementFormat);
1902             GLenum err                 = gl.getError();
1903             GLenum implementTypeEnum   = static_cast<GLenum>(implementType);
1904             GLenum implementFormatEnum = static_cast<GLenum>(implementFormat);
1905 
1906             if (((sampler == SAMPLER_UNORM) && (type.type == GL_UNSIGNED_BYTE) && (format.format == GL_RGBA)) ||
1907                 ((sampler == SAMPLER_UINT) && (type.type == GL_UNSIGNED_INT) && (format.format == GL_RGBA_INTEGER)) ||
1908                 ((sampler == SAMPLER_INT) && (type.type == GL_INT) && (format.format == GL_RGBA_INTEGER)) ||
1909                 ((sampler == SAMPLER_FLOAT) && (type.type == GL_FLOAT) && (format.format == GL_RGBA)) ||
1910                 ((err == GL_NO_ERROR) && (type.type == implementTypeEnum) && (format.format == implementFormatEnum)) ||
1911                 ((internalformat.sizedFormat == GL_RGB10_A2) && (type.type == GL_UNSIGNED_INT_2_10_10_10_REV) &&
1912                  (format.format == GL_RGBA)))
1913             {
1914                 return true;
1915             }
1916             else
1917             {
1918                 return false;
1919             }
1920         }
1921     }
1922     else
1923     {
1924         if (format.format == GL_DEPTH_STENCIL)
1925         {
1926             if (type.type != GL_UNSIGNED_INT_24_8 && type.type != GL_FLOAT_32_UNSIGNED_INT_24_8_REV)
1927             {
1928                 return false;
1929             }
1930         }
1931 
1932         if ((format.componentFormat == FORMAT_COLOR_INTEGER) && (type.type == GL_FLOAT || type.type == GL_HALF_FLOAT))
1933         {
1934             return false;
1935         }
1936 
1937         if ((internalformat.baseFormat == GL_DEPTH_STENCIL || internalformat.baseFormat == GL_STENCIL_INDEX ||
1938              internalformat.baseFormat == GL_DEPTH_COMPONENT) !=
1939             (format.format == GL_DEPTH_STENCIL || format.format == GL_STENCIL_INDEX ||
1940              format.format == GL_DEPTH_COMPONENT))
1941         {
1942             return false;
1943         }
1944 
1945         if (operation == INPUT_TEXIMAGE)
1946         {
1947             if (format.format == GL_STENCIL_INDEX || internalformat.baseFormat == GL_STENCIL_INDEX)
1948             {
1949                 return false;
1950             }
1951 
1952             if ((format.format == GL_DEPTH_COMPONENT || format.format == GL_DEPTH_STENCIL) &&
1953                 !(internalformat.baseFormat == GL_DEPTH_STENCIL || internalformat.baseFormat == GL_DEPTH_COMPONENT))
1954             {
1955                 return false;
1956             }
1957         }
1958         else if (operation == OUTPUT_GETTEXIMAGE)
1959         {
1960             if ((format.format == GL_STENCIL_INDEX &&
1961                  ((internalformat.baseFormat != GL_STENCIL_INDEX && internalformat.baseFormat != GL_DEPTH_STENCIL) ||
1962                   !contextInfo.isExtensionSupported("GL_ARB_texture_stencil8"))))
1963             {
1964                 return false;
1965             }
1966 
1967             if (format.format == GL_DEPTH_STENCIL && internalformat.baseFormat != GL_DEPTH_STENCIL)
1968             {
1969                 return false;
1970             }
1971         }
1972         else if (operation == OUTPUT_READPIXELS)
1973         {
1974             if (format.format == GL_DEPTH_STENCIL && internalformat.baseFormat != GL_DEPTH_STENCIL)
1975             {
1976                 return false;
1977             }
1978 
1979             if (format.format == GL_DEPTH_COMPONENT && internalformat.baseFormat != GL_DEPTH_STENCIL &&
1980                 internalformat.baseFormat != GL_DEPTH_COMPONENT)
1981             {
1982                 return false;
1983             }
1984 
1985             if (format.format == GL_STENCIL_INDEX && internalformat.baseFormat != GL_DEPTH_STENCIL &&
1986                 internalformat.baseFormat != GL_STENCIL_INDEX)
1987             {
1988                 return false;
1989             }
1990         }
1991 
1992         if (type.special == true)
1993         {
1994             bool valid = false;
1995 
1996             for (i = 0; i < DE_LENGTH_OF_ARRAY(coreValidFormats); ++i)
1997             {
1998                 if (coreValidFormats[i].format == format.format && coreValidFormats[i].type == type.type)
1999                 {
2000                     valid = true;
2001                     break;
2002                 }
2003             }
2004 
2005             if (!valid)
2006                 return false;
2007         }
2008 
2009         if ((format.componentFormat == FORMAT_COLOR_INTEGER) &&
2010             !(internalformat.sampler == SAMPLER_INT || internalformat.sampler == SAMPLER_UINT))
2011         {
2012             return false;
2013         }
2014 
2015         if (!(format.componentFormat == FORMAT_COLOR_INTEGER) &&
2016             (internalformat.sampler == SAMPLER_INT || internalformat.sampler == SAMPLER_UINT))
2017         {
2018             return false;
2019         }
2020 
2021         if ((m_textureTarget == GL_TEXTURE_3D) &&
2022             ((internalformat.baseFormat == GL_DEPTH_COMPONENT) || (internalformat.baseFormat == GL_DEPTH_STENCIL) ||
2023              (internalformat.sizedFormat == GL_COMPRESSED_RED_RGTC1) ||
2024              (internalformat.sizedFormat == GL_COMPRESSED_SIGNED_RED_RGTC1) ||
2025              (internalformat.sizedFormat == GL_COMPRESSED_RG_RGTC2) ||
2026              (internalformat.sizedFormat == GL_COMPRESSED_SIGNED_RG_RGTC2)))
2027         {
2028             return false;
2029         }
2030     }
2031 
2032     return true;
2033 }
2034 
isUnsizedFormat(GLenum format) const2035 bool RectangleTest::isUnsizedFormat(GLenum format) const
2036 {
2037     GLenum formats[]   = {GL_RGBA, GL_RGB, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA};
2038     GLenum *formatsEnd = formats + DE_LENGTH_OF_ARRAY(formats);
2039     return (std::find(formats, formatsEnd, format) < formatsEnd);
2040 }
2041 
isSRGBFormat(const InternalFormat & internalFormat) const2042 bool RectangleTest::isSRGBFormat(const InternalFormat &internalFormat) const
2043 {
2044     return (internalFormat.sizedFormat == GL_SRGB8) || (internalFormat.sizedFormat == GL_SRGB8_ALPHA8);
2045 }
2046 
isSNORMFormat(const InternalFormat & internalFormat) const2047 bool RectangleTest::isSNORMFormat(const InternalFormat &internalFormat) const
2048 {
2049     GLenum formats[]   = {GL_R8_SNORM,  GL_RG8_SNORM,  GL_RGB8_SNORM,  GL_RGBA8_SNORM,
2050                           GL_R16_SNORM, GL_RG16_SNORM, GL_RGB16_SNORM, GL_RGBA16_SNORM};
2051     GLenum *formatsEnd = formats + DE_LENGTH_OF_ARRAY(formats);
2052     return (std::find(formats, formatsEnd, internalFormat.sizedFormat) < formatsEnd);
2053 }
2054 
isCopyValid(const InternalFormat & copyInternalFormat,const InternalFormat & internalFormat) const2055 bool RectangleTest::isCopyValid(const InternalFormat &copyInternalFormat, const InternalFormat &internalFormat) const
2056 {
2057     // check if copy between two internal formats is allowed
2058 
2059     int b1 = getPixelFormat(internalFormat.format).components;
2060     int b2 = getPixelFormat(copyInternalFormat.format).components;
2061 
2062     if (b2 > b1)
2063         return false;
2064 
2065     //Check that the types can be converted in CopyTexImage.
2066     if (((copyInternalFormat.sampler == SAMPLER_UINT) && (internalFormat.sampler != SAMPLER_UINT)) ||
2067         ((copyInternalFormat.sampler == SAMPLER_INT) && (internalFormat.sampler != SAMPLER_INT)) ||
2068         (((copyInternalFormat.sampler == SAMPLER_FLOAT) || (internalFormat.sampler == SAMPLER_UNORM) ||
2069           (copyInternalFormat.sampler == SAMPLER_NORM)) &&
2070          (!((copyInternalFormat.sampler == SAMPLER_FLOAT) || (internalFormat.sampler == SAMPLER_UNORM) ||
2071             (internalFormat.sampler == SAMPLER_NORM)))))
2072     {
2073         return false;
2074     }
2075 
2076     // Core GL is less restricted then ES - check it first
2077     if (!glu::isContextTypeES(m_context.getRenderContext().getType()))
2078     {
2079         if ((copyInternalFormat.format == GL_DEPTH_COMPONENT && internalFormat.format != GL_DEPTH_COMPONENT) ||
2080             (copyInternalFormat.format == GL_DEPTH_STENCIL && internalFormat.format != GL_DEPTH_STENCIL) ||
2081             (copyInternalFormat.format == GL_ALPHA && internalFormat.format != GL_ALPHA) ||
2082             (copyInternalFormat.format == GL_LUMINANCE && internalFormat.format != GL_LUMINANCE) ||
2083             (copyInternalFormat.format == GL_LUMINANCE_ALPHA && internalFormat.format != GL_LUMINANCE_ALPHA))
2084         {
2085             return false;
2086         }
2087 
2088         return true;
2089     }
2090 
2091     const glu::ContextInfo &contextInfo = m_context.getContextInfo();
2092 
2093     // GLES30 has more restricted requirement on glCopyTexImage2D
2094     // As stated in Table 3.15 and comment to glCopyTexImage2D
2095     if ((internalFormat.baseFormat == GL_DEPTH_COMPONENT) || (internalFormat.baseFormat == GL_DEPTH_STENCIL) ||
2096         (copyInternalFormat.baseFormat == GL_DEPTH_COMPONENT) || (copyInternalFormat.baseFormat == GL_DEPTH_STENCIL) ||
2097         ((internalFormat.baseFormat != GL_RGBA && internalFormat.baseFormat != GL_ALPHA) &&
2098          ((copyInternalFormat.baseFormat == GL_ALPHA) || (copyInternalFormat.baseFormat == GL_LUMINANCE_ALPHA))) ||
2099         ((internalFormat.baseFormat == GL_ALPHA) &&
2100          ((copyInternalFormat.baseFormat != GL_RGBA) && (copyInternalFormat.baseFormat != GL_ALPHA) &&
2101           (copyInternalFormat.baseFormat != GL_LUMINANCE_ALPHA))) ||
2102         (isSRGBFormat(internalFormat) != isSRGBFormat(copyInternalFormat)) ||
2103         // GLES30 does not define ReadPixels types for signed normalized fixed point formats in Table 3.14,
2104         // and conversions to SNORM internalformats are not allowed by Table 3.2
2105         (copyInternalFormat.sampler == SAMPLER_NORM) ||
2106         ((copyInternalFormat.sizedFormat == GL_RGB9_E5) &&
2107          (!contextInfo.isExtensionSupported("GL_APPLE_color_buffer_packed_float") &&
2108           !contextInfo.isExtensionSupported("GL_QCOM_render_shared_exponent"))))
2109     {
2110         /* Some formats are activated by extensions, check. */
2111         if (((internalFormat.baseFormat == GL_LUMINANCE && copyInternalFormat.baseFormat == GL_LUMINANCE) ||
2112              (internalFormat.baseFormat == GL_ALPHA && copyInternalFormat.baseFormat == GL_ALPHA) ||
2113              (internalFormat.baseFormat == GL_LUMINANCE_ALPHA &&
2114               (copyInternalFormat.baseFormat == GL_LUMINANCE_ALPHA || copyInternalFormat.baseFormat == GL_LUMINANCE ||
2115                copyInternalFormat.baseFormat == GL_ALPHA))) &&
2116             contextInfo.isExtensionSupported("GL_NV_render_luminance_alpha"))
2117         {
2118             return true;
2119         }
2120         else if (contextInfo.isExtensionSupported("GL_EXT_render_snorm") && isSNORMFormat(copyInternalFormat) &&
2121                  (internalFormat.sampler == copyInternalFormat.sampler) &&
2122                  (((copyInternalFormat.baseFormat == GL_RED) &&
2123                    (internalFormat.baseFormat == GL_RED || internalFormat.baseFormat == GL_RG ||
2124                     internalFormat.baseFormat == GL_RGB || internalFormat.baseFormat == GL_RGBA ||
2125                     copyInternalFormat.baseFormat == GL_LUMINANCE)) ||
2126                   ((copyInternalFormat.baseFormat == GL_RG) &&
2127                    (internalFormat.baseFormat == GL_RG || internalFormat.baseFormat == GL_RGB ||
2128                     internalFormat.baseFormat == GL_RGBA)) ||
2129                   ((copyInternalFormat.baseFormat == GL_RGB) &&
2130                    (internalFormat.baseFormat == GL_RGB || internalFormat.baseFormat == GL_RGBA)) ||
2131                   ((copyInternalFormat.baseFormat == GL_RGBA) && (internalFormat.baseFormat == GL_RGBA))))
2132         {
2133             return true;
2134         }
2135 
2136         return false;
2137     }
2138     else
2139     {
2140         if (internalFormat.sampler != copyInternalFormat.sampler)
2141         {
2142             // You can't convert between different base types, for example NORM<->FLOAT.
2143             return false;
2144         }
2145         if (!isUnsizedFormat(copyInternalFormat.sizedFormat))
2146         {
2147             if ((internalFormat.bits.bits.red && copyInternalFormat.bits.bits.red &&
2148                  internalFormat.bits.bits.red != copyInternalFormat.bits.bits.red) ||
2149                 (internalFormat.bits.bits.green && copyInternalFormat.bits.bits.green &&
2150                  internalFormat.bits.bits.green != copyInternalFormat.bits.bits.green) ||
2151                 (internalFormat.bits.bits.blue && copyInternalFormat.bits.bits.blue &&
2152                  internalFormat.bits.bits.blue != copyInternalFormat.bits.bits.blue) ||
2153                 (internalFormat.bits.bits.alpha && copyInternalFormat.bits.bits.alpha &&
2154                  internalFormat.bits.bits.alpha != copyInternalFormat.bits.bits.alpha))
2155             {
2156                 // If the destination internalFormat is sized we don't allow component size changes.
2157                 return false;
2158             }
2159         }
2160         else
2161         {
2162             if (internalFormat.sizedFormat == GL_RGB10_A2)
2163             {
2164                 // Not allowed to convert from a GL_RGB10_A2 surface.
2165                 return false;
2166             }
2167         }
2168     }
2169 
2170     return true;
2171 }
2172 
isFBOImageAttachValid(const InternalFormat & internalformat,GLenum format,GLenum type) const2173 bool RectangleTest::isFBOImageAttachValid(const InternalFormat &internalformat, GLenum format, GLenum type) const
2174 {
2175     const glu::ContextInfo &contextInfo = m_context.getContextInfo();
2176 
2177     if (glu::isContextTypeES(m_context.getRenderContext().getType()))
2178     {
2179         const EnumFormats *validFormat = getCanonicalFormat(internalformat, format, type);
2180         if (validFormat != 0)
2181         {
2182             if (!validFormat->bRenderable)
2183             {
2184                 /* Some formats are activated by extensions, check. */
2185                 if ((GL_RGBA32F == validFormat->internalformat || GL_RGBA16F == validFormat->internalformat ||
2186                      GL_RG32F == validFormat->internalformat || GL_RG16F == validFormat->internalformat ||
2187                      GL_R32F == validFormat->internalformat || GL_R16F == validFormat->internalformat ||
2188                      GL_R11F_G11F_B10F == validFormat->internalformat) &&
2189                     contextInfo.isExtensionSupported("GL_EXT_color_buffer_float"))
2190                 {
2191                     return true;
2192                 }
2193 
2194                 if ((GL_RGBA16F == validFormat->internalformat || GL_RGB16F == validFormat->internalformat ||
2195                      GL_RG16F == validFormat->internalformat || GL_R16F == validFormat->internalformat) &&
2196                     contextInfo.isExtensionSupported("GL_EXT_color_buffer_half_float"))
2197                 {
2198                     return true;
2199                 }
2200 
2201                 if ((GL_R11F_G11F_B10F == validFormat->internalformat || GL_RGB9_E5 == validFormat->internalformat) &&
2202                     contextInfo.isExtensionSupported("GL_APPLE_color_buffer_packed_float"))
2203                 {
2204                     return true;
2205                 }
2206 
2207                 if ((GL_RGB9_E5 == validFormat->internalformat) &&
2208                     contextInfo.isExtensionSupported("GL_QCOM_render_shared_exponent"))
2209                 {
2210                     return true;
2211                 }
2212 
2213                 if ((GL_LUMINANCE == validFormat->internalformat || GL_ALPHA == validFormat->internalformat ||
2214                      GL_LUMINANCE_ALPHA == validFormat->internalformat) &&
2215                     contextInfo.isExtensionSupported("GL_NV_render_luminance_alpha"))
2216                 {
2217                     return true;
2218                 }
2219 
2220                 if ((GL_SRGB8 == validFormat->internalformat) && contextInfo.isExtensionSupported("GL_NV_sRGB_formats"))
2221                 {
2222                     return true;
2223                 }
2224 
2225                 if (((GL_R8_SNORM == validFormat->internalformat) || (GL_RG8_SNORM == validFormat->internalformat) ||
2226                      (GL_RGBA8_SNORM == validFormat->internalformat) || (GL_R16_SNORM == validFormat->internalformat) ||
2227                      (GL_RG16_SNORM == validFormat->internalformat) ||
2228                      (GL_RGBA16_SNORM == validFormat->internalformat)) &&
2229                     contextInfo.isExtensionSupported("GL_EXT_render_snorm"))
2230                 {
2231                     return true;
2232                 }
2233             }
2234             return validFormat->bRenderable;
2235         }
2236         else
2237         {
2238             // Check for NV_packed_float
2239             if (GL_RGB == internalformat.sizedFormat && GL_RGB == format && GL_UNSIGNED_INT_10F_11F_11F_REV == type &&
2240                 contextInfo.isExtensionSupported("GL_NV_packed_float"))
2241             {
2242                 return true;
2243             }
2244             return false;
2245         }
2246     }
2247     else
2248     {
2249         if (format == GL_DEPTH_STENCIL && internalformat.sizedFormat != GL_DEPTH24_STENCIL8 &&
2250             internalformat.sizedFormat != GL_DEPTH32F_STENCIL8)
2251         {
2252             // We can't make a complete DEPTH_STENCIL attachment with a
2253             // texture that does not have both DEPTH and STENCIL components.
2254             return false;
2255         }
2256 
2257         GLenum colorRenderableFrmats[] = {GL_RGBA32F,    GL_RGBA32I, GL_RGBA32UI,     GL_RGBA16,
2258                                           GL_RGBA16F,    GL_RGBA16I, GL_RGBA16UI,     GL_RGBA8,
2259                                           GL_RGBA8I,     GL_RGBA8UI, GL_SRGB8_ALPHA8, GL_RGB10_A2,
2260                                           GL_RGB10_A2UI, GL_RGB5_A1, GL_RGBA4,        GL_R11F_G11F_B10F,
2261                                           GL_RGB565,     GL_RG32F,   GL_RG32I,        GL_RG32UI,
2262                                           GL_RG16,       GL_RG16F,   GL_RG16I,        GL_RG16UI,
2263                                           GL_RG8,        GL_RG8I,    GL_RG8UI,        GL_R32F,
2264                                           GL_R32I,       GL_R32UI,   GL_R16F,         GL_R16I,
2265                                           GL_R16UI,      GL_R16,     GL_R8,           GL_R8I,
2266                                           GL_R8UI};
2267         GLenum *formatsEnd             = colorRenderableFrmats + DE_LENGTH_OF_ARRAY(colorRenderableFrmats);
2268         if (std::find(colorRenderableFrmats, formatsEnd, internalformat.sizedFormat) < formatsEnd)
2269             return true;
2270 
2271         GLenum dsRenderableFormats[] = {
2272             GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT16,
2273             GL_DEPTH32F_STENCIL8,  GL_DEPTH24_STENCIL8,
2274         };
2275 
2276         formatsEnd = dsRenderableFormats + DE_LENGTH_OF_ARRAY(dsRenderableFormats);
2277         if (std::find(dsRenderableFormats, formatsEnd, internalformat.sizedFormat) < formatsEnd)
2278             return true;
2279 
2280         return false;
2281     }
2282 }
2283 
doRead(GLuint texture)2284 bool RectangleTest::doRead(GLuint texture)
2285 {
2286     glu::RenderContext &renderContext = m_context.getRenderContext();
2287     const Functions &gl               = renderContext.getFunctions();
2288 
2289     GLuint fboId;
2290     gl.genFramebuffers(1, &fboId);
2291     gl.bindFramebuffer(GL_FRAMEBUFFER, fboId);
2292     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer");
2293 
2294     bool validImageAttach = isFBOImageAttachValid(m_internalFormat, m_inputFormat.format, m_inputType.type);
2295     if (m_textureTarget == GL_TEXTURE_2D)
2296         gl.framebufferTexture2D(GL_FRAMEBUFFER, m_inputFormat.attachment, GL_TEXTURE_2D, texture, 0);
2297     else if (glu::isContextTypeES(renderContext.getType()))
2298         gl.framebufferTextureLayer(GL_FRAMEBUFFER, m_inputFormat.attachment, texture, 0, 0);
2299     else
2300         gl.framebufferTexture3D(GL_FRAMEBUFFER, m_inputFormat.attachment, GL_TEXTURE_3D, texture, 0, 0);
2301     GLenum status = gl.checkFramebufferStatus(GL_FRAMEBUFFER);
2302 
2303     bool result = true;
2304     if (status == GL_FRAMEBUFFER_COMPLETE)
2305     {
2306         if (!validImageAttach && glu::isContextTypeES(renderContext.getType()))
2307         {
2308             m_testCtx.getLog() << tcu::TestLog::Message << "FBO is complete but expected incomplete with sizedFormat: "
2309                                << getFormatStr(m_internalFormat.sizedFormat) << tcu::TestLog::EndMessage;
2310             result = false;
2311         }
2312         else
2313         {
2314             result &= readPixels(false);
2315             result &= doCopy();
2316         }
2317     }
2318     else if (validImageAttach)
2319     {
2320         m_testCtx.getLog() << tcu::TestLog::Message << "FBO is not complete but expected complete with sizedFormat: "
2321                            << getFormatStr(m_internalFormat.sizedFormat) << tcu::TestLog::EndMessage;
2322         result = false;
2323     }
2324 
2325     gl.deleteFramebuffers(1, &fboId);
2326 
2327     return result;
2328 }
2329 
readPixels(bool isCopy)2330 bool RectangleTest::readPixels(bool isCopy)
2331 {
2332     bool result = true;
2333 
2334     const PixelType *types;
2335     int typesCount;
2336     const PixelFormat *formats;
2337     int formatsCount;
2338 
2339     if (glu::isContextTypeES(m_context.getRenderContext().getType()))
2340     {
2341         types        = esTypes;
2342         typesCount   = DE_LENGTH_OF_ARRAY(esTypes);
2343         formats      = esFormats;
2344         formatsCount = DE_LENGTH_OF_ARRAY(esFormats);
2345     }
2346     else
2347     {
2348         types        = coreTypes;
2349         typesCount   = DE_LENGTH_OF_ARRAY(coreTypes);
2350         formats      = coreFormats;
2351         formatsCount = DE_LENGTH_OF_ARRAY(coreFormats);
2352     }
2353 
2354     // for each output format
2355     for (int m = 0; m < formatsCount; ++m)
2356     {
2357         const PixelFormat &outputFormat = formats[m];
2358 
2359         // for each output type
2360         for (int n = 0; n < typesCount; ++n)
2361         {
2362             const PixelType &outputType = types[n];
2363 
2364             if (isCopy)
2365             {
2366                 // continue when input format,type != canonical format,type and
2367                 // output format,type != canonical format,type
2368                 if ((outputFormat.format != m_copyInternalFormat.format ||
2369                      outputType.type != m_copyInternalFormat.type))
2370                 {
2371                     // invalid output format and type - skipping case
2372                     continue;
2373                 }
2374             }
2375             else if ((m_inputFormat.format != m_internalFormat.format || m_inputType.type != m_internalFormat.type) &&
2376                      (outputFormat.format != m_internalFormat.format || outputType.type != m_internalFormat.type))
2377             {
2378                 // invalid output format and type - skipping case
2379                 continue;
2380             }
2381 
2382             result &= readPixelsInner(outputFormat, outputType, isCopy);
2383         }
2384     }
2385 
2386     return result;
2387 }
2388 
readPixelsInner(const PixelFormat & outputFormat,const PixelType & outputType,bool isCopy)2389 bool RectangleTest::readPixelsInner(const PixelFormat &outputFormat, const PixelType &outputType, bool isCopy)
2390 {
2391     const char *copyStage = "Copy stage: ";
2392 
2393     GLenum readerror = readOutputData(outputFormat, outputType, OUTPUT_READPIXELS);
2394     if (m_outputBuffer.empty())
2395     {
2396         m_testCtx.getLog() << tcu::TestLog::Message << "No buffer allocated" << tcu::TestLog::EndMessage;
2397         return false;
2398     }
2399 
2400     m_countReadPixels++;
2401 
2402     // Check if output format is valid
2403     bool outputFormatValid = isFormatValid(outputFormat, outputType, isCopy ? m_copyInternalFormat : m_internalFormat,
2404                                            false, true, OUTPUT_READPIXELS);
2405 
2406     // Even if this is a valid glReadPixels format, we can't read non-existant components
2407     if (outputFormatValid && outputFormat.format == GL_DEPTH_STENCIL && m_inputFormat.format != GL_DEPTH_STENCIL)
2408         outputFormatValid = false;
2409 
2410     if (outputFormatValid)
2411     {
2412         if (readerror != GL_NO_ERROR)
2413         {
2414             m_testCtx.getLog() << tcu::TestLog::Message << (isCopy ? copyStage : "")
2415                                << "Valid format used but glReadPixels failed for input = ["
2416                                << getFormatStr(m_inputFormat.format) << ", " << getTypeStr(m_inputType.type)
2417                                << "] output = [" << getFormatStr(outputFormat.format) << ", "
2418                                << getTypeStr(outputType.type) << "]" << tcu::TestLog::EndMessage;
2419             return false;
2420         }
2421         else
2422         {
2423             m_countReadPixelsOK++;
2424             m_countCompare++;
2425 
2426             // compare output gradient to input gradient
2427             if (!compare(&m_gradient[0], &m_outputBuffer[0], outputFormat, outputType, isCopy))
2428             {
2429                 m_testCtx.getLog() << tcu::TestLog::Message << (isCopy ? copyStage : "")
2430                                    << "Gradient comparison failed during ReadPixels for input = ["
2431                                    << getFormatStr(m_inputFormat.format) << ", " << getTypeStr(m_inputType.type)
2432                                    << "] output = [" << getFormatStr(outputFormat.format) << ", "
2433                                    << getTypeStr(outputType.type) << "]" << tcu::TestLog::EndMessage;
2434                 return false;
2435             }
2436 
2437             m_countCompareOK++;
2438         }
2439     }
2440     else if (readerror == GL_NO_ERROR)
2441     {
2442         m_testCtx.getLog() << tcu::TestLog::Message << (isCopy ? copyStage : "")
2443                            << "Invalid format used but glReadPixels succeeded for input = ["
2444                            << getFormatStr(m_inputFormat.format) << ", " << getTypeStr(m_inputType.type)
2445                            << "] output = [" << getFormatStr(outputFormat.format) << ", " << getTypeStr(outputType.type)
2446                            << "]" << tcu::TestLog::EndMessage;
2447         return false;
2448     }
2449 
2450     return true;
2451 }
2452 
readOutputData(const PixelFormat & outputFormat,const PixelType & outputType,int operation)2453 GLenum RectangleTest::readOutputData(const PixelFormat &outputFormat, const PixelType &outputType, int operation)
2454 {
2455     // If using PBOs buffer object for GL_PIXEL_PACK_BUFFER must
2456     // be bound and not allocated before calling when using PBOs
2457 
2458     glu::RenderContext &renderContext = m_context.getRenderContext();
2459     const Functions &gl               = renderContext.getFunctions();
2460 
2461     PackedPixelsBufferProperties &props = m_packProperties;
2462     props.elementSize                   = outputType.size;
2463     props.elementsInGroup               = outputType.special ? 1 : outputFormat.components;
2464     props.rowLength            = (props.rowLength == 0) ? (GRADIENT_WIDTH + props.skipPixels) : props.rowLength;
2465     props.elementsInRowNoAlign = props.elementsInGroup * props.rowLength;
2466     props.elementsInRow        = props.elementsInRowNoAlign;
2467 
2468     if (glu::isContextTypeES(renderContext.getType()))
2469     {
2470         props.rowCount   = 0;
2471         props.skipImages = 0;
2472     }
2473     else if ((operation == OUTPUT_READPIXELS) || (m_textureTarget == GL_TEXTURE_2D))
2474         props.skipImages = 0;
2475 
2476     if (props.rowCount == 0)
2477         props.rowCount = GRADIENT_HEIGHT + props.skipRows;
2478     props.imagesCount = props.skipImages + 1;
2479     if (props.elementSize < props.alignment)
2480     {
2481         props.elementsInRow = (int)(props.alignment * deFloatCeil(props.elementSize * props.elementsInGroup *
2482                                                                   props.rowLength / ((float)props.alignment))) /
2483                               props.elementSize;
2484     }
2485 
2486     int bufferSize =
2487         props.elementSize * props.elementsInRow * props.rowCount * props.imagesCount * (props.skipImages + 1);
2488 
2489     // The output buffer allocated should be initialized to a known value. After
2490     // a pack operation, any extra memory allocated for skipping should be
2491     // verified to be the original known value, untouched by the GL.
2492     const GLubyte defaultFillValue = 0xaa;
2493     m_outputBuffer.resize(static_cast<std::size_t>(bufferSize));
2494     std::fill(m_outputBuffer.begin(), m_outputBuffer.end(), defaultFillValue);
2495 
2496     GLuint packPBO;
2497     if (m_usePBO)
2498     {
2499         gl.genBuffers(1, &packPBO);
2500         gl.bindBuffer(GL_PIXEL_PACK_BUFFER, packPBO);
2501         gl.bufferData(GL_PIXEL_PACK_BUFFER, bufferSize, &m_outputBuffer[0], GL_STATIC_READ);
2502     }
2503 
2504     GLenum readError = GL_NO_ERROR;
2505     switch (operation)
2506     {
2507     case OUTPUT_GETTEXIMAGE:
2508         gl.getTexImage(m_textureTarget, 0, outputFormat.format, outputType.type, m_usePBO ? 0 : &m_outputBuffer[0]);
2509         break;
2510 
2511     case OUTPUT_READPIXELS:
2512         if (m_inputFormat.attachment != GL_DEPTH_ATTACHMENT &&
2513             m_inputFormat.attachment != GL_DEPTH_STENCIL_ATTACHMENT &&
2514             m_inputFormat.attachment != GL_STENCIL_ATTACHMENT)
2515             gl.readBuffer(m_inputFormat.attachment);
2516 
2517         readError = gl.getError();
2518         if (readError == GL_NO_ERROR)
2519             gl.readPixels(0, 0, GRADIENT_WIDTH, GRADIENT_HEIGHT, outputFormat.format, outputType.type,
2520                           m_usePBO ? 0 : &m_outputBuffer[0]);
2521         break;
2522     }
2523 
2524     if (readError == GL_NO_ERROR)
2525         readError = gl.getError();
2526 
2527     if (m_usePBO)
2528     {
2529         if (readError == GL_NO_ERROR)
2530         {
2531             GLvoid *mappedData = gl.mapBufferRange(GL_PIXEL_PACK_BUFFER, 0, bufferSize, GL_MAP_READ_BIT);
2532             if (!mappedData)
2533                 return GL_INVALID_INDEX;
2534 
2535             std::memcpy(&m_outputBuffer[0], mappedData, bufferSize);
2536             gl.unmapBuffer(GL_PIXEL_PACK_BUFFER);
2537         }
2538 
2539         gl.bindBuffer(GL_PIXEL_PACK_BUFFER, 0);
2540         gl.deleteBuffers(1, &packPBO);
2541     }
2542 
2543     if (m_packProperties.swapBytes && (readError == GL_NO_ERROR))
2544         swapBytes(outputType.size, m_outputBuffer);
2545 
2546     return readError;
2547 }
2548 
doCopy()2549 bool RectangleTest::doCopy()
2550 {
2551     bool result = true;
2552 
2553     const InternalFormat *copyInternalFormats;
2554     int internalFormatsCount;
2555     if (glu::isContextTypeES(m_context.getRenderContext().getType()))
2556     {
2557         copyInternalFormats  = esInternalformats;
2558         internalFormatsCount = DE_LENGTH_OF_ARRAY(esInternalformats);
2559     }
2560     else
2561     {
2562         copyInternalFormats  = coreInternalformats;
2563         internalFormatsCount = DE_LENGTH_OF_ARRAY(coreInternalformats);
2564     }
2565 
2566     if ((m_inputFormat.format == m_internalFormat.format) && (m_inputType.type == m_internalFormat.type))
2567     {
2568         for (int i = 0; i < internalFormatsCount; ++i)
2569         {
2570             m_copyInternalFormat = copyInternalFormats[i];
2571             result &= doCopyInner();
2572         }
2573     }
2574 
2575     return result;
2576 }
2577 
doCopyInner()2578 bool RectangleTest::doCopyInner()
2579 {
2580     glu::RenderContext &renderContext = m_context.getRenderContext();
2581     const Functions &gl               = renderContext.getFunctions();
2582     bool result                       = true;
2583 
2584     const EnumFormats *copyFormatEnum =
2585         getCanonicalFormat(m_copyInternalFormat, m_copyInternalFormat.format, m_copyInternalFormat.type);
2586 
2587     if (copyFormatEnum != 0)
2588     {
2589         GLuint texture2;
2590         GLenum status;
2591 
2592         bool validcopy = isCopyValid(m_copyInternalFormat, m_internalFormat);
2593 
2594         gl.genTextures(1, &texture2);
2595         // Target is always GL_TEXTURE_2D
2596         gl.bindTexture(GL_TEXTURE_2D, texture2);
2597         GLenum error = gl.getError();
2598 
2599         // CopyTexImage to copy_internalformat (GL converts, but PixelStore is ignored)
2600         // Target is always GL_TEXTURE_2D
2601         gl.copyTexImage2D(GL_TEXTURE_2D, 0, m_copyInternalFormat.sizedFormat, 0, 0, GRADIENT_WIDTH, GRADIENT_HEIGHT, 0);
2602         error = gl.getError();
2603 
2604         // if this combination of copy_internalformat,internalformat is invalid
2605         if (validcopy == false)
2606         {
2607             // expect error and continue
2608             if (error != GL_NO_ERROR)
2609             {
2610                 // Invalid format used and glCopyTexImage2D failed
2611                 result = true;
2612             }
2613             else
2614             {
2615                 m_testCtx.getLog() << tcu::TestLog::Message << "Invalid format used but glCopyTexImage2D succeeded"
2616                                    << tcu::TestLog::EndMessage;
2617                 result = false;
2618             }
2619         }
2620         else // validcopy == true
2621         {
2622             // expect no error and continue
2623             if (error != GL_NO_ERROR)
2624             {
2625                 m_testCtx.getLog() << tcu::TestLog::Message << "Valid format used but glCopyTexImage2D failed"
2626                                    << tcu::TestLog::EndMessage;
2627                 result = false;
2628             }
2629             else
2630             {
2631                 if (!glu::isContextTypeES(renderContext.getType()))
2632                 {
2633                     // if GetTexImage is supported we call the
2634                     // inner function only as no loop needed
2635                     const PixelFormat &outputFormat = getPixelFormat(copyFormatEnum->format);
2636                     const PixelType &outputType     = getPixelType(copyFormatEnum->type);
2637                     result &= getTexImageInner(outputFormat, outputType);
2638                 }
2639 
2640                 GLint orginalFboId;
2641                 gl.getIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &orginalFboId);
2642                 GLU_EXPECT_NO_ERROR(gl.getError(), "getIntegerv");
2643 
2644                 GLuint fboId;
2645                 gl.genFramebuffers(1, &fboId);
2646                 gl.bindFramebuffer(GL_FRAMEBUFFER, fboId);
2647 
2648                 bool validImageAttach =
2649                     isFBOImageAttachValid(m_copyInternalFormat, copyFormatEnum->format, copyFormatEnum->type);
2650 
2651                 // attach copy_internalformat texture to FBO
2652                 // Target is always GL_TEXTURE_2D
2653                 const PixelFormat &copyFormat = getPixelFormat(copyFormatEnum->format);
2654                 gl.framebufferTexture2D(GL_FRAMEBUFFER, copyFormat.attachment, GL_TEXTURE_2D, texture2, 0);
2655                 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture2D");
2656 
2657                 status = gl.checkFramebufferStatus(GL_FRAMEBUFFER);
2658                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCheckFramebufferStatus");
2659 
2660                 // if an unsized sizedFormat was given, then implementation chosen copy format
2661                 // destination might be different than what's expected;
2662                 // we cannot continue checking since ReadPixels might not choose a compatible
2663                 // format, also the format may not be renderable as expected
2664                 if (isUnsizedFormat(m_copyInternalFormat.sizedFormat))
2665                 {
2666                     result &= true;
2667                 }
2668                 else if (status == GL_FRAMEBUFFER_COMPLETE)
2669                 {
2670                     if (validImageAttach)
2671                         result &= readPixels(true);
2672                     else
2673                     {
2674                         m_testCtx.getLog()
2675                             << tcu::TestLog::Message << "Copy FBO is complete but expected incomplete with sizedFormat "
2676                             << getFormatStr(m_copyInternalFormat.sizedFormat) << ", attachement "
2677                             << copyFormat.attachment << tcu::TestLog::EndMessage;
2678                         result = false;
2679                     }
2680                 }
2681                 else if (validImageAttach)
2682                 {
2683                     m_testCtx.getLog() << tcu::TestLog::Message
2684                                        << "Copy FBO is not complete but expected complete with sizedFormat "
2685                                        << getFormatStr(m_copyInternalFormat.sizedFormat) << ", attachement "
2686                                        << copyFormat.attachment << tcu::TestLog::EndMessage;
2687                     result = false;
2688                 }
2689 
2690                 // bind original FBO
2691                 gl.bindFramebuffer(GL_FRAMEBUFFER, orginalFboId);
2692                 gl.deleteFramebuffers(1, &fboId);
2693             }
2694         }
2695 
2696         gl.deleteTextures(1, &texture2);
2697     }
2698 
2699     return result;
2700 }
2701 
compare(GLvoid * gradient,GLvoid * data,const PixelFormat & outputFormat,const PixelType & outputType,bool isCopy) const2702 bool RectangleTest::compare(GLvoid *gradient, GLvoid *data, const PixelFormat &outputFormat,
2703                             const PixelType &outputType, bool isCopy) const
2704 {
2705     // Compares the reference gradient data to the output data
2706 
2707     int iformatSampler = m_internalFormat.sampler;
2708     int outputSampler  = getSampler(outputType, outputFormat);
2709     int inputSampler   = getSampler(m_inputType, m_inputFormat);
2710 
2711     if (isCopy)
2712         iformatSampler = m_copyInternalFormat.sampler;
2713 
2714     int samplerIsIntUintFloat = 3; // 1: INT | 2: UINT | 3: FLOAT/UNORM/NORM
2715     if (m_internalFormat.sampler == SAMPLER_INT)
2716         samplerIsIntUintFloat = 1;
2717     else if (m_internalFormat.sampler == SAMPLER_UINT)
2718         samplerIsIntUintFloat = 2;
2719 
2720     std::vector<GLubyte> gradientStrip;
2721     if (!stripBuffer(m_unpackProperties, static_cast<const GLubyte *>(gradient), gradientStrip, false))
2722         return false;
2723     std::vector<GLubyte> dataStrip;
2724     if (!stripBuffer(m_packProperties, static_cast<const GLubyte *>(data), dataStrip, true))
2725         return false;
2726 
2727     if (gradientStrip.empty() || dataStrip.empty())
2728         return false;
2729 
2730     std::vector<FloatPixel> inputBuffer;
2731     getFloatBuffer(&gradientStrip[0], samplerIsIntUintFloat, m_inputFormat, m_inputType,
2732                    GRADIENT_WIDTH * GRADIENT_HEIGHT, inputBuffer);
2733 
2734     std::vector<FloatPixel> outputBuffer;
2735     getFloatBuffer(&dataStrip[0], samplerIsIntUintFloat, outputFormat, outputType, GRADIENT_WIDTH * GRADIENT_HEIGHT,
2736                    outputBuffer);
2737 
2738     std::vector<int> inputBitTable;
2739     getBits(m_inputType, m_inputFormat, inputBitTable);
2740     std::vector<int> outputBitTable;
2741     getBits(outputType, outputFormat, outputBitTable);
2742     const int *internalformatBitTable = reinterpret_cast<const int *>(&m_internalFormat.bits);
2743     const int *copyFormatBitTable     = m_copyInternalFormat.bits.array;
2744 
2745     // make struct field iterable
2746     float *inputBufferFloat  = reinterpret_cast<float *>(&inputBuffer[0]);
2747     float *outputBufferFloat = reinterpret_cast<float *>(&outputBuffer[0]);
2748 
2749     int *inputBufferInt  = reinterpret_cast<int *>(&inputBuffer[0]);
2750     int *outputBufferInt = reinterpret_cast<int *>(&outputBuffer[0]);
2751 
2752     unsigned int *inputBufferUint  = reinterpret_cast<unsigned int *>(&inputBuffer[0]);
2753     unsigned int *outputBufferUint = reinterpret_cast<unsigned int *>(&outputBuffer[0]);
2754 
2755     for (int i = 0; i < GRADIENT_WIDTH * GRADIENT_HEIGHT; ++i)
2756     {
2757         for (int j = 0; j < NUM_FLOAT_PIXEL_COUNT / 3; ++j)
2758         {
2759             int bit1 = getRealBitPrecision(inputBitTable[j], inputSampler == SAMPLER_FLOAT);
2760             int bit2 = getRealBitPrecision(outputBitTable[j], outputSampler == SAMPLER_FLOAT);
2761             int bit3 = getRealBitPrecision(internalformatBitTable[j], iformatSampler == SAMPLER_FLOAT);
2762             int bitdiff;
2763 
2764             if (bit1 >= bit3)
2765             {
2766                 if ((inputSampler == SAMPLER_UNORM && m_internalFormat.sampler == SAMPLER_NORM))
2767                     bit3 -= 1;
2768             }
2769 
2770             if (bit2 <= bit3)
2771             {
2772                 if (outputSampler == SAMPLER_NORM && m_internalFormat.sampler == SAMPLER_UNORM)
2773                     bit2 -= 1;
2774             }
2775 
2776             if (!(m_internalFormat.flags & FLAG_REQ_RBO) && bit3 > 8 && m_internalFormat.sampler != SAMPLER_UINT &&
2777                 m_internalFormat.sampler != SAMPLER_INT)
2778             {
2779                 // If this internalFormat is not a required format there is no requirement
2780                 // that the implementation uses exactly the bit width requested. For example,
2781                 // it may substitute RGB10 for RGB12. The implementation can't make subtitutions
2782                 // for integer formats.
2783                 bit3 = 8;
2784             }
2785 
2786             bitdiff = std::min(std::min(bit1, bit2), bit3);
2787             if (isCopy)
2788             {
2789                 bitdiff = std::min(bitdiff, copyFormatBitTable[j]);
2790             }
2791 
2792             if (bitdiff > 0)
2793             {
2794                 if (samplerIsIntUintFloat == 1) // 1: INT
2795                 {
2796                     int inputValue  = inputBufferInt[NUM_FLOAT_PIXEL_COUNT * i + j];
2797                     int outputValue = outputBufferInt[NUM_FLOAT_PIXEL_COUNT * i + j];
2798 
2799                     if (inputSampler == SAMPLER_UINT)
2800                         // If input data was unsigned, it should be clamped to fit into
2801                         // internal format positive range (otherwise it may wrap and
2802                         // yield negative internalformat values)
2803                         inputValue = clampUnsignedValue(bit3 - 1, inputValue);
2804 
2805                     inputValue = clampSignedValue(bit3, inputValue);
2806                     if (isCopy)
2807                     {
2808                         inputValue = clampSignedValue(copyFormatBitTable[j], inputValue);
2809                     }
2810                     if (outputSampler == SAMPLER_UINT)
2811                         inputValue = clampUnsignedValue(bit2, inputValue);
2812                     else
2813                         inputValue = clampSignedValue(bit2, inputValue);
2814 
2815                     if (inputValue != outputValue)
2816                     {
2817                         m_testCtx.getLog() << tcu::TestLog::Message << "Integer comparison: " << i << ", " << j << ", "
2818                                            << NUM_FLOAT_PIXEL_COUNT * i + j << ": " << inputValue
2819                                            << " == " << outputValue << ": not equal." << tcu::TestLog::EndMessage;
2820                         return false;
2821                     }
2822                 }
2823                 else if (samplerIsIntUintFloat == 2) // 2: UINT
2824                 {
2825                     unsigned int inputValue  = inputBufferUint[NUM_FLOAT_PIXEL_COUNT * i + j + 6];
2826                     unsigned int outputValue = outputBufferUint[NUM_FLOAT_PIXEL_COUNT * i + j + 6];
2827 
2828                     inputValue = clampUnsignedValue(bit3, inputValue);
2829                     if (isCopy)
2830                         inputValue = clampUnsignedValue(copyFormatBitTable[j], inputValue);
2831 
2832                     if (outputSampler == SAMPLER_UINT)
2833                         inputValue = clampUnsignedValue(bit2, inputValue);
2834                     else if (outputSampler == SAMPLER_INT)
2835                         inputValue = clampUnsignedValue(bit2 - 1, inputValue);
2836                     if (inputValue != outputValue)
2837                     {
2838                         m_testCtx.getLog() << tcu::TestLog::Message << "Integer comparison: " << i << ", " << j << ", "
2839                                            << NUM_FLOAT_PIXEL_COUNT * i + j << ": " << inputValue
2840                                            << " == " << outputValue << ": not equal." << tcu::TestLog::EndMessage;
2841                         return false;
2842                     }
2843                 }
2844                 else if (samplerIsIntUintFloat == 3) // 3: FLOAT / UNORM / NORM
2845                 {
2846                     float inputValue  = inputBufferFloat[NUM_FLOAT_PIXEL_COUNT * i + j + 12];
2847                     float outputValue = outputBufferFloat[NUM_FLOAT_PIXEL_COUNT * i + j + 12];
2848                     float epsilon;
2849 
2850                     if ((outputSampler == SAMPLER_UNORM) || (outputSampler == SAMPLER_NORM))
2851                     {
2852                         // Check if format is UNORM/NORM which needs different
2853                         // precision since it implies a int->float conversion.
2854                         epsilon = 1.0f / ((float)((1 << (bitdiff - 1))) - 1);
2855                     }
2856                     else if ((inputSampler == SAMPLER_FLOAT) != (outputSampler == SAMPLER_FLOAT))
2857                     {
2858                         // Allow for rounding in either direction for float->int conversions.
2859                         epsilon = 1.0f / ((float)((1 << (bitdiff - 1))) - 1);
2860                     }
2861                     else
2862                         epsilon = 1.0f / ((float)((1 << bitdiff) - 1));
2863 
2864                     if (inputSampler == SAMPLER_FLOAT || outputSampler == SAMPLER_FLOAT)
2865                     {
2866                         // According to GL spec the precision requirement
2867                         // of floating-point values is 1 part in 10^5.
2868                         epsilon = deFloatMax(epsilon, 0.00001f);
2869                     }
2870 
2871                     if (m_internalFormat.flags & FLAG_COMPRESSED)
2872                         epsilon = deFloatMax(epsilon, 0.1f);
2873 
2874                     // Clamp input value to range of output
2875                     if (iformatSampler == SAMPLER_UNORM || outputSampler == SAMPLER_UNORM)
2876                         inputValue = deFloatMax(deFloatMin(inputValue, 1.0f), 0.0f);
2877                     else if (iformatSampler == SAMPLER_NORM || outputSampler == SAMPLER_NORM)
2878                         inputValue = deFloatMax(deFloatMin(inputValue, 1.0f), -1.0f);
2879 
2880                     // Compare the input and output
2881                     if (deFloatAbs(inputValue - outputValue) > epsilon)
2882                     {
2883                         m_testCtx.getLog()
2884                             << tcu::TestLog::Message << "Non-integer comparison: " << i << ", " << j << ", "
2885                             << NUM_FLOAT_PIXEL_COUNT * i + j << ", " << epsilon << ": " << inputValue
2886                             << " == " << outputValue << ": not equal." << tcu::TestLog::EndMessage;
2887                         return false;
2888                     }
2889                 }
2890                 else
2891                 {
2892                     m_testCtx.getLog() << tcu::TestLog::Message << "Sampler type cannot be recognised, so no comparison"
2893                                        << tcu::TestLog::EndMessage;
2894                     return false;
2895                 }
2896             }
2897         }
2898     }
2899 
2900     return true;
2901 }
2902 
getFloatBuffer(GLvoid * gradient,int samplerIsIntUintFloat,const PixelFormat & format,const PixelType & type,int elementCount,std::vector<FloatPixel> & result) const2903 void RectangleTest::getFloatBuffer(GLvoid *gradient, int samplerIsIntUintFloat, const PixelFormat &format,
2904                                    const PixelType &type, int elementCount, std::vector<FloatPixel> &result) const
2905 {
2906     int componentCount = format.components;
2907     switch (type.type)
2908     {
2909     case GL_UNSIGNED_BYTE:
2910         makeBuffer(gradient, format, samplerIsIntUintFloat, elementCount, componentCount, pack_UNSIGNED_BYTE, result);
2911         break;
2912     case GL_BYTE:
2913         makeBuffer(gradient, format, samplerIsIntUintFloat, elementCount, componentCount, pack_BYTE, result);
2914         break;
2915     case GL_UNSIGNED_SHORT:
2916         makeBuffer(gradient, format, samplerIsIntUintFloat, elementCount, componentCount, pack_UNSIGNED_SHORT, result);
2917         break;
2918     case GL_SHORT:
2919         makeBuffer(gradient, format, samplerIsIntUintFloat, elementCount, componentCount, pack_SHORT, result);
2920         break;
2921     case GL_UNSIGNED_INT:
2922         makeBuffer(gradient, format, samplerIsIntUintFloat, elementCount, componentCount, pack_UNSIGNED_INT, result);
2923         break;
2924     case GL_INT:
2925         makeBuffer(gradient, format, samplerIsIntUintFloat, elementCount, componentCount, pack_INT, result);
2926         break;
2927     case GL_HALF_FLOAT:
2928         makeBuffer(gradient, format, samplerIsIntUintFloat, elementCount, componentCount, pack_HALF_FLOAT, result);
2929         break;
2930     case GL_FLOAT:
2931         makeBuffer(gradient, format, samplerIsIntUintFloat, elementCount, componentCount, pack_FLOAT, result);
2932         break;
2933     case GL_UNSIGNED_SHORT_5_6_5:
2934         if (samplerIsIntUintFloat == 1)
2935             makeBufferPackedInt(gradient, format, elementCount, pack_UNSIGNED_SHORT_5_6_5_INT, result);
2936         else if (samplerIsIntUintFloat == 2)
2937             makeBufferPackedUint(gradient, format, elementCount, pack_UNSIGNED_SHORT_5_6_5_UINT, result);
2938         else if (samplerIsIntUintFloat == 3)
2939             makeBufferPackedFloat(gradient, format, elementCount, pack_UNSIGNED_SHORT_5_6_5, result);
2940         break;
2941     case GL_UNSIGNED_SHORT_4_4_4_4:
2942         if (samplerIsIntUintFloat == 1)
2943             makeBufferPackedInt(gradient, format, elementCount, pack_UNSIGNED_SHORT_4_4_4_4_INT, result);
2944         else if (samplerIsIntUintFloat == 2)
2945             makeBufferPackedUint(gradient, format, elementCount, pack_UNSIGNED_SHORT_4_4_4_4_UINT, result);
2946         else if (samplerIsIntUintFloat == 3)
2947             makeBufferPackedFloat(gradient, format, elementCount, pack_UNSIGNED_SHORT_4_4_4_4, result);
2948         break;
2949     case GL_UNSIGNED_SHORT_5_5_5_1:
2950         if (samplerIsIntUintFloat == 1)
2951             makeBufferPackedInt(gradient, format, elementCount, pack_UNSIGNED_SHORT_5_5_5_1_INT, result);
2952         else if (samplerIsIntUintFloat == 2)
2953             makeBufferPackedUint(gradient, format, elementCount, pack_UNSIGNED_SHORT_5_5_5_1_UINT, result);
2954         else if (samplerIsIntUintFloat == 3)
2955             makeBufferPackedFloat(gradient, format, elementCount, pack_UNSIGNED_SHORT_5_5_5_1, result);
2956         break;
2957     case GL_UNSIGNED_INT_2_10_10_10_REV:
2958         if (samplerIsIntUintFloat == 1)
2959             makeBufferPackedInt(gradient, format, elementCount, pack_UNSIGNED_INT_2_10_10_10_REV_INT, result);
2960         else if (samplerIsIntUintFloat == 2)
2961             makeBufferPackedUint(gradient, format, elementCount, pack_UNSIGNED_INT_2_10_10_10_REV_UINT, result);
2962         else if (samplerIsIntUintFloat == 3)
2963             makeBufferPackedFloat(gradient, format, elementCount, pack_UNSIGNED_INT_2_10_10_10_REV, result);
2964         break;
2965     case GL_UNSIGNED_INT_24_8:
2966         makeBufferPackedFloat(gradient, format, elementCount, pack_UNSIGNED_INT_24_8, result);
2967         break;
2968     case GL_UNSIGNED_INT_10F_11F_11F_REV:
2969         makeBufferPackedFloat(gradient, format, elementCount, pack_UNSIGNED_INT_10F_11F_11F_REV, result);
2970         break;
2971     case GL_UNSIGNED_INT_5_9_9_9_REV:
2972         makeBufferPackedFloat(gradient, format, elementCount, pack_UNSIGNED_INT_5_9_9_9_REV, result);
2973         break;
2974     case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
2975         makeBufferPackedFloat(gradient, format, elementCount, pack_FLOAT_32_UNSIGNED_INT_24_8_REV, result);
2976         break;
2977     case GL_UNSIGNED_BYTE_3_3_2:
2978         if (samplerIsIntUintFloat == 1)
2979             makeBufferPackedInt(gradient, format, elementCount, pack_UNSIGNED_BYTE_3_3_2_INT, result);
2980         else if (samplerIsIntUintFloat == 2)
2981             makeBufferPackedUint(gradient, format, elementCount, pack_UNSIGNED_BYTE_3_3_2_UINT, result);
2982         else if (samplerIsIntUintFloat == 3)
2983             makeBufferPackedFloat(gradient, format, elementCount, pack_UNSIGNED_BYTE_3_3_2, result);
2984         break;
2985     case GL_UNSIGNED_BYTE_2_3_3_REV:
2986         if (samplerIsIntUintFloat == 1)
2987             makeBufferPackedInt(gradient, format, elementCount, pack_UNSIGNED_BYTE_2_3_3_REV_INT, result);
2988         else if (samplerIsIntUintFloat == 2)
2989             makeBufferPackedUint(gradient, format, elementCount, pack_UNSIGNED_BYTE_2_3_3_REV_UINT, result);
2990         else if (samplerIsIntUintFloat == 3)
2991             makeBufferPackedFloat(gradient, format, elementCount, pack_UNSIGNED_BYTE_2_3_3_REV, result);
2992         break;
2993     case GL_UNSIGNED_SHORT_5_6_5_REV:
2994         if (samplerIsIntUintFloat == 1)
2995             makeBufferPackedInt(gradient, format, elementCount, pack_UNSIGNED_SHORT_5_6_5_REV_INT, result);
2996         else if (samplerIsIntUintFloat == 2)
2997             makeBufferPackedUint(gradient, format, elementCount, pack_UNSIGNED_SHORT_5_6_5_REV_UINT, result);
2998         else if (samplerIsIntUintFloat == 3)
2999             makeBufferPackedFloat(gradient, format, elementCount, pack_UNSIGNED_SHORT_5_6_5_REV, result);
3000         break;
3001     case GL_UNSIGNED_SHORT_4_4_4_4_REV:
3002         if (samplerIsIntUintFloat == 1)
3003             makeBufferPackedInt(gradient, format, elementCount, pack_UNSIGNED_SHORT_4_4_4_4_REV_INT, result);
3004         else if (samplerIsIntUintFloat == 2)
3005             makeBufferPackedUint(gradient, format, elementCount, pack_UNSIGNED_SHORT_4_4_4_4_REV_UINT, result);
3006         else if (samplerIsIntUintFloat == 3)
3007             makeBufferPackedFloat(gradient, format, elementCount, pack_UNSIGNED_SHORT_4_4_4_4_REV, result);
3008         break;
3009     case GL_UNSIGNED_SHORT_1_5_5_5_REV:
3010         if (samplerIsIntUintFloat == 1)
3011             makeBufferPackedInt(gradient, format, elementCount, pack_UNSIGNED_SHORT_1_5_5_5_REV_INT, result);
3012         else if (samplerIsIntUintFloat == 2)
3013             makeBufferPackedUint(gradient, format, elementCount, pack_UNSIGNED_SHORT_1_5_5_5_REV_UINT, result);
3014         else if (samplerIsIntUintFloat == 3)
3015             makeBufferPackedFloat(gradient, format, elementCount, pack_UNSIGNED_SHORT_1_5_5_5_REV, result);
3016         break;
3017     case GL_UNSIGNED_INT_8_8_8_8:
3018         if (samplerIsIntUintFloat == 1)
3019             makeBufferPackedInt(gradient, format, elementCount, pack_UNSIGNED_INT_8_8_8_8_INT, result);
3020         else if (samplerIsIntUintFloat == 2)
3021             makeBufferPackedUint(gradient, format, elementCount, pack_UNSIGNED_INT_8_8_8_8_UINT, result);
3022         else if (samplerIsIntUintFloat == 3)
3023             makeBufferPackedFloat(gradient, format, elementCount, pack_UNSIGNED_INT_8_8_8_8, result);
3024         break;
3025     case GL_UNSIGNED_INT_8_8_8_8_REV:
3026         if (samplerIsIntUintFloat == 1)
3027             makeBufferPackedInt(gradient, format, elementCount, pack_UNSIGNED_INT_8_8_8_8_REV_INT, result);
3028         else if (samplerIsIntUintFloat == 2)
3029             makeBufferPackedUint(gradient, format, elementCount, pack_UNSIGNED_INT_8_8_8_8_REV_UINT, result);
3030         else if (samplerIsIntUintFloat == 3)
3031             makeBufferPackedFloat(gradient, format, elementCount, pack_UNSIGNED_INT_8_8_8_8_REV, result);
3032         break;
3033     case GL_UNSIGNED_INT_10_10_10_2:
3034         if (samplerIsIntUintFloat == 1)
3035             makeBufferPackedInt(gradient, format, elementCount, pack_UNSIGNED_INT_10_10_10_2_INT, result);
3036         else if (samplerIsIntUintFloat == 2)
3037             makeBufferPackedUint(gradient, format, elementCount, pack_UNSIGNED_INT_10_10_10_2_UINT, result);
3038         else if (samplerIsIntUintFloat == 3)
3039             makeBufferPackedFloat(gradient, format, elementCount, pack_UNSIGNED_INT_10_10_10_2, result);
3040         break;
3041     default:
3042         TCU_FAIL("Unsuported type");
3043     }
3044 }
3045 
3046 template <typename Type>
makeBuffer(const GLvoid * gradient,const PixelFormat & format,int samplerIsIntUintFloat,int elementCount,int componentCount,float (* pack)(Type),std::vector<FloatPixel> & result) const3047 void RectangleTest::makeBuffer(const GLvoid *gradient, const PixelFormat &format, int samplerIsIntUintFloat,
3048                                int elementCount, int componentCount, float (*pack)(Type),
3049                                std::vector<FloatPixel> &result) const
3050 {
3051     const Type *sourceData = static_cast<const Type *>(gradient);
3052     result.resize(sizeof(FloatPixel) * elementCount);
3053     for (int i = 0; i < elementCount; ++i)
3054     {
3055         rawFloatPixel values;
3056         rawIntPixel valuesInt;
3057         rawUintPixel valuesUint;
3058         for (int j = 0; j < componentCount; j++)
3059         {
3060             if (samplerIsIntUintFloat == 1)
3061                 valuesInt[j] = (int)static_cast<Type>(sourceData[componentCount * i + j]);
3062             else if (samplerIsIntUintFloat == 2)
3063                 valuesUint[j] = (unsigned int)static_cast<Type>(sourceData[componentCount * i + j]);
3064             else if (samplerIsIntUintFloat == 3)
3065                 values[j] = pack(sourceData[componentCount * i + j]);
3066         }
3067         if (samplerIsIntUintFloat == 1)
3068             result[i] = orderComponentsInt(valuesInt, format);
3069         else if (samplerIsIntUintFloat == 2)
3070             result[i] = orderComponentsUint(valuesUint, format);
3071         else if (samplerIsIntUintFloat == 3)
3072             result[i] = orderComponentsFloat(values, format);
3073     }
3074 }
3075 
getBits(const PixelType & type,const PixelFormat & format,std::vector<int> & resultTable) const3076 void RectangleTest::getBits(const PixelType &type, const PixelFormat &format, std::vector<int> &resultTable) const
3077 {
3078     // return bit depth table based on type and format pair;
3079     // table is always NUM_FLOAT_PIXEL_COUNT digit long
3080 
3081     resultTable.resize(NUM_FLOAT_PIXEL_COUNT);
3082     std::fill(resultTable.begin(), resultTable.end(), 0);
3083 
3084     if (type.special == true)
3085     {
3086         std::memcpy(&resultTable[0], &type.bits, sizeof(type.bits));
3087         if (type.type == GL_UNSIGNED_INT_5_9_9_9_REV)
3088         {
3089             //this type is another special case: it is always converted to 3-channel color (no A).
3090             //as results of this function are used for comparison of converted values we set A bits to 0.
3091             resultTable[3] = 0;
3092         }
3093     }
3094     else
3095     {
3096         int bits;
3097 
3098         if (type.type == GL_FLOAT)
3099             bits = 32;
3100         else if (type.type == GL_HALF_FLOAT)
3101             bits = 16;
3102         else
3103             bits = type.size << 3;
3104 
3105         if (format.format == GL_DEPTH_STENCIL || format.format == GL_DEPTH_COMPONENT)
3106             resultTable[4] = bits;
3107 
3108         if (format.format == GL_DEPTH_STENCIL || format.format == GL_STENCIL_INDEX ||
3109             format.format == GL_STENCIL_INDEX8)
3110         {
3111             resultTable[5] = bits;
3112         }
3113 
3114         if (format.format == GL_RED || format.format == GL_RG || format.format == GL_RGB || format.format == GL_RGBA ||
3115             format.format == GL_BGR || format.format == GL_BGRA || format.format == GL_RED_INTEGER ||
3116             format.format == GL_RG_INTEGER || format.format == GL_RGB_INTEGER || format.format == GL_RGBA_INTEGER ||
3117             format.format == GL_BGR_INTEGER || format.format == GL_BGRA_INTEGER)
3118         {
3119             resultTable[0] = bits;
3120         }
3121 
3122         if (format.format == GL_RG || format.format == GL_RGB || format.format == GL_RGBA || format.format == GL_BGR ||
3123             format.format == GL_BGRA || format.format == GL_RG_INTEGER || format.format == GL_RGB_INTEGER ||
3124             format.format == GL_RGBA_INTEGER || format.format == GL_BGR_INTEGER || format.format == GL_BGRA_INTEGER)
3125         {
3126             resultTable[1] = bits;
3127         }
3128 
3129         if (format.format == GL_RGB || format.format == GL_RGBA || format.format == GL_BGR ||
3130             format.format == GL_BGRA || format.format == GL_RGB_INTEGER || format.format == GL_RGBA_INTEGER ||
3131             format.format == GL_BGR_INTEGER || format.format == GL_BGRA_INTEGER)
3132         {
3133             resultTable[2] = bits;
3134         }
3135 
3136         if (format.format == GL_RGBA || format.format == GL_BGRA || format.format == GL_RGBA_INTEGER ||
3137             format.format == GL_BGRA_INTEGER)
3138         {
3139             resultTable[3] = bits;
3140         }
3141     }
3142 }
3143 
3144 template <typename Type>
makeBufferPackedInt(const GLvoid * gradient,const PixelFormat & format,int elementCount,void (* pack)(rawIntPixel *,Type),std::vector<FloatPixel> & result) const3145 void RectangleTest::makeBufferPackedInt(const GLvoid *gradient, const PixelFormat &format, int elementCount,
3146                                         void (*pack)(rawIntPixel *, Type), std::vector<FloatPixel> &result) const
3147 {
3148     const Type *sourceData = static_cast<const Type *>(gradient);
3149     result.resize(sizeof(FloatPixel) * elementCount);
3150     for (int i = 0; i < elementCount; ++i)
3151     {
3152         rawIntPixel values;
3153         pack(&values, sourceData[i]);
3154         result[i] = orderComponentsInt(values, format);
3155     }
3156 }
3157 
3158 template <typename Type>
makeBufferPackedUint(const GLvoid * gradient,const PixelFormat & format,int elementCount,void (* pack)(rawUintPixel *,Type),std::vector<FloatPixel> & result) const3159 void RectangleTest::makeBufferPackedUint(const GLvoid *gradient, const PixelFormat &format, int elementCount,
3160                                          void (*pack)(rawUintPixel *, Type), std::vector<FloatPixel> &result) const
3161 {
3162     const Type *sourceData = static_cast<const Type *>(gradient);
3163     result.resize(sizeof(FloatPixel) * elementCount);
3164     for (int i = 0; i < elementCount; ++i)
3165     {
3166         rawUintPixel values;
3167         pack(&values, sourceData[i]);
3168         result[i] = orderComponentsUint(values, format);
3169     }
3170 }
3171 
3172 template <typename Type>
makeBufferPackedFloat(const GLvoid * gradient,const PixelFormat & format,int elementCount,void (* pack)(rawFloatPixel *,Type),std::vector<FloatPixel> & result) const3173 void RectangleTest::makeBufferPackedFloat(const GLvoid *gradient, const PixelFormat &format, int elementCount,
3174                                           void (*pack)(rawFloatPixel *, Type), std::vector<FloatPixel> &result) const
3175 {
3176     const Type *sourceData = static_cast<const Type *>(gradient);
3177     result.resize(sizeof(FloatPixel) * elementCount);
3178     for (int i = 0; i < elementCount; ++i)
3179     {
3180         rawFloatPixel values;
3181         pack(&values, sourceData[i]);
3182         result[i] = orderComponentsFloat(values, format);
3183     }
3184 }
3185 
orderComponentsInt(rawIntPixel values,const PixelFormat & format) const3186 FloatPixel RectangleTest::orderComponentsInt(rawIntPixel values, const PixelFormat &format) const
3187 {
3188     FloatPixel fp = {PACK_DEFAULTI,  PACK_DEFAULTI,  PACK_DEFAULTI,  PACK_DEFAULTI,  PACK_DEFAULTI,  PACK_DEFAULTI,
3189                      PACK_DEFAULTUI, PACK_DEFAULTUI, PACK_DEFAULTUI, PACK_DEFAULTUI, PACK_DEFAULTUI, PACK_DEFAULTUI,
3190                      PACK_DEFAULTF,  PACK_DEFAULTF,  PACK_DEFAULTF,  PACK_DEFAULTF,  PACK_DEFAULTF,  PACK_DEFAULTF};
3191 
3192     if (format.componentOrder.bits.red >= 0)
3193         fp.i_r = values[format.componentOrder.bits.red];
3194     if (format.componentOrder.bits.green >= 0)
3195         fp.i_g = values[format.componentOrder.bits.green];
3196     if (format.componentOrder.bits.blue >= 0)
3197         fp.i_b = values[format.componentOrder.bits.blue];
3198     if (format.componentOrder.bits.alpha >= 0)
3199         fp.i_a = values[format.componentOrder.bits.alpha];
3200     if (format.componentOrder.bits.depth >= 0)
3201         fp.i_d = values[format.componentOrder.bits.depth];
3202     if (format.componentOrder.bits.stencil >= 0)
3203         fp.i_s = values[format.componentOrder.bits.stencil];
3204 
3205     return fp;
3206 }
3207 
orderComponentsUint(rawUintPixel values,const PixelFormat & format) const3208 FloatPixel RectangleTest::orderComponentsUint(rawUintPixel values, const PixelFormat &format) const
3209 {
3210     FloatPixel fp = {PACK_DEFAULTI,  PACK_DEFAULTI,  PACK_DEFAULTI,  PACK_DEFAULTI,  PACK_DEFAULTI,  PACK_DEFAULTI,
3211                      PACK_DEFAULTUI, PACK_DEFAULTUI, PACK_DEFAULTUI, PACK_DEFAULTUI, PACK_DEFAULTUI, PACK_DEFAULTUI,
3212                      PACK_DEFAULTF,  PACK_DEFAULTF,  PACK_DEFAULTF,  PACK_DEFAULTF,  PACK_DEFAULTF,  PACK_DEFAULTF};
3213 
3214     if (format.componentOrder.bits.red >= 0)
3215         fp.ui_r = values[format.componentOrder.bits.red];
3216     if (format.componentOrder.bits.green >= 0)
3217         fp.ui_g = values[format.componentOrder.bits.green];
3218     if (format.componentOrder.bits.blue >= 0)
3219         fp.ui_b = values[format.componentOrder.bits.blue];
3220     if (format.componentOrder.bits.alpha >= 0)
3221         fp.ui_a = values[format.componentOrder.bits.alpha];
3222     if (format.componentOrder.bits.depth >= 0)
3223         fp.ui_d = values[format.componentOrder.bits.depth];
3224     if (format.componentOrder.bits.stencil >= 0)
3225         fp.ui_s = values[format.componentOrder.bits.stencil];
3226 
3227     return fp;
3228 }
3229 
orderComponentsFloat(rawFloatPixel values,const PixelFormat & format) const3230 FloatPixel RectangleTest::orderComponentsFloat(rawFloatPixel values, const PixelFormat &format) const
3231 {
3232     FloatPixel fp = {PACK_DEFAULTI,  PACK_DEFAULTI,  PACK_DEFAULTI,  PACK_DEFAULTI,  PACK_DEFAULTI,  PACK_DEFAULTI,
3233                      PACK_DEFAULTUI, PACK_DEFAULTUI, PACK_DEFAULTUI, PACK_DEFAULTUI, PACK_DEFAULTUI, PACK_DEFAULTUI,
3234                      PACK_DEFAULTF,  PACK_DEFAULTF,  PACK_DEFAULTF,  PACK_DEFAULTF,  PACK_DEFAULTF,  PACK_DEFAULTF};
3235 
3236     if (format.componentOrder.bits.red >= 0)
3237         fp.r = values[format.componentOrder.bits.red];
3238     if (format.componentOrder.bits.green >= 0)
3239         fp.g = values[format.componentOrder.bits.green];
3240     if (format.componentOrder.bits.blue >= 0)
3241         fp.b = values[format.componentOrder.bits.blue];
3242     if (format.componentOrder.bits.alpha >= 0)
3243         fp.a = values[format.componentOrder.bits.alpha];
3244     if (format.componentOrder.bits.depth >= 0)
3245         fp.d = values[format.componentOrder.bits.depth];
3246     if (format.componentOrder.bits.stencil >= 0)
3247         fp.s = values[format.componentOrder.bits.stencil];
3248 
3249     return fp;
3250 }
3251 
getRealBitPrecision(int bits,bool isFloat) const3252 unsigned int RectangleTest::getRealBitPrecision(int bits, bool isFloat) const
3253 {
3254     if (!isFloat)
3255         return bits;
3256     switch (bits)
3257     {
3258     case 32:
3259         return 23;
3260     case 16:
3261         return 10;
3262     case 11:
3263         return 6;
3264     case 10:
3265         return 5;
3266     }
3267     return bits;
3268 }
3269 
stripBuffer(const PackedPixelsBufferProperties & props,const GLubyte * orginalBuffer,std::vector<GLubyte> & newBuffer,bool validate) const3270 bool RectangleTest::stripBuffer(const PackedPixelsBufferProperties &props, const GLubyte *orginalBuffer,
3271                                 std::vector<GLubyte> &newBuffer, bool validate) const
3272 {
3273     // Extracts pixel data from a buffer with specific
3274     // pixel store configuration into a flat buffer
3275 
3276     int newBufferSize = props.elementSize * props.elementsInRowNoAlign * GRADIENT_HEIGHT;
3277     if (!newBufferSize)
3278         return false;
3279     newBuffer.resize(newBufferSize);
3280 
3281     int skipBottom = ((props.skipImages * props.rowCount + props.skipRows) * props.elementsInRow) * props.elementSize;
3282     int skipTop    = (props.rowCount - GRADIENT_HEIGHT - props.skipRows) * props.elementsInRow * props.elementSize;
3283     int skipLeft   = props.skipPixels * props.elementsInGroup * props.elementSize;
3284     int skipRight  = (props.elementsInRow - GRADIENT_WIDTH * props.elementsInGroup) * props.elementSize - skipLeft;
3285     int copy       = GRADIENT_WIDTH * props.elementsInGroup * props.elementSize;
3286     int skipAlign  = (props.elementsInRow - props.elementsInRowNoAlign) * props.elementSize;
3287 
3288     if (validate)
3289     {
3290         for (int i = 0; i < skipBottom; i++)
3291         {
3292             if (orginalBuffer[i] != m_defaultFillValue)
3293                 return false;
3294         }
3295     }
3296 
3297     int index_src = skipBottom;
3298     int index_dst = 0;
3299 
3300     for (int j = 0; j < GRADIENT_HEIGHT; j++)
3301     {
3302         if (validate)
3303         {
3304             for (int i = 0; i < skipLeft; i++)
3305             {
3306                 if (orginalBuffer[index_src + i] != m_defaultFillValue)
3307                     return false;
3308             }
3309         }
3310         index_src += skipLeft;
3311 
3312         std::memcpy(&newBuffer[0] + index_dst, &orginalBuffer[0] + index_src, copy);
3313         index_src += copy;
3314         index_dst += copy;
3315 
3316         if (validate)
3317         {
3318             for (int i = skipAlign; i < skipRight; i++)
3319             {
3320                 if (orginalBuffer[index_src + i] != m_defaultFillValue)
3321                     return false;
3322             }
3323         }
3324         index_src += skipRight;
3325     }
3326 
3327     if (validate)
3328     {
3329         for (int i = 0; i < skipTop; i++)
3330         {
3331             if (orginalBuffer[index_src + i] != m_defaultFillValue)
3332                 return false;
3333         }
3334     }
3335     index_src += skipTop;
3336 
3337     return true;
3338 }
3339 
clampSignedValue(int bits,int value) const3340 int RectangleTest::clampSignedValue(int bits, int value) const
3341 {
3342     int max = 2147483647;
3343     int min = 0x80000000;
3344 
3345     if (bits < 32)
3346     {
3347         max = (1 << (bits - 1)) - 1;
3348         min = (1 << (bits - 1)) - (1 << bits);
3349     }
3350 
3351     if (value >= max)
3352         return max;
3353     else if (value <= min)
3354         return min;
3355 
3356     return value;
3357 }
3358 
clampUnsignedValue(int bits,unsigned int value) const3359 unsigned int RectangleTest::clampUnsignedValue(int bits, unsigned int value) const
3360 {
3361     unsigned int max = 4294967295u;
3362     unsigned int min = 0;
3363 
3364     if (bits < 32)
3365     {
3366         max = (1 << bits) - 1;
3367     }
3368 
3369     if (value >= max)
3370         return max;
3371     else if (value <= min)
3372         return min;
3373 
3374     return value;
3375 }
3376 
pack_UNSIGNED_BYTE(GLubyte value)3377 float RectangleTest::pack_UNSIGNED_BYTE(GLubyte value)
3378 {
3379     return static_cast<GLfloat>(value) / std::numeric_limits<GLubyte>::max();
3380 }
3381 
pack_BYTE(GLbyte value)3382 float RectangleTest::pack_BYTE(GLbyte value)
3383 {
3384     return deFloatMax(static_cast<GLfloat>(value) / std::numeric_limits<GLbyte>::max(), -1.0f);
3385 }
3386 
pack_UNSIGNED_SHORT(GLushort value)3387 float RectangleTest::pack_UNSIGNED_SHORT(GLushort value)
3388 {
3389     return static_cast<GLfloat>(value) / std::numeric_limits<GLushort>::max();
3390 }
3391 
pack_SHORT(GLshort value)3392 float RectangleTest::pack_SHORT(GLshort value)
3393 {
3394     return deFloatMax(static_cast<GLfloat>(value) / std::numeric_limits<GLshort>::max(), -1.0f);
3395 }
3396 
pack_UNSIGNED_INT(GLuint value)3397 float RectangleTest::pack_UNSIGNED_INT(GLuint value)
3398 {
3399     return static_cast<GLfloat>(value) / std::numeric_limits<GLuint>::max();
3400 }
3401 
pack_INT(GLint value)3402 float RectangleTest::pack_INT(GLint value)
3403 {
3404     return deFloatMax(static_cast<GLfloat>(value) / std::numeric_limits<GLint>::max(), -1.0f);
3405 }
3406 
pack_HALF_FLOAT(GLhalf value)3407 float RectangleTest::pack_HALF_FLOAT(GLhalf value)
3408 {
3409     return halfFloatToFloat(value);
3410 }
3411 
pack_FLOAT(GLfloat value)3412 float RectangleTest::pack_FLOAT(GLfloat value)
3413 {
3414     return value;
3415 }
3416 
pack_UNSIGNED_BYTE_3_3_2(rawFloatPixel * values,GLubyte value)3417 void RectangleTest::pack_UNSIGNED_BYTE_3_3_2(rawFloatPixel *values, GLubyte value)
3418 {
3419     (*values)[0] = ((value >> 5) & 7) / 7.0f;
3420     (*values)[1] = ((value >> 2) & 7) / 7.0f;
3421     (*values)[2] = ((value >> 0) & 3) / 3.0f;
3422 }
3423 
pack_UNSIGNED_BYTE_3_3_2_UINT(rawUintPixel * values,GLubyte value)3424 void RectangleTest::pack_UNSIGNED_BYTE_3_3_2_UINT(rawUintPixel *values, GLubyte value)
3425 {
3426     (*values)[0] = (value >> 5) & 7;
3427     (*values)[1] = (value >> 2) & 7;
3428     (*values)[2] = (value >> 0) & 3;
3429 }
3430 
pack_UNSIGNED_BYTE_3_3_2_INT(rawIntPixel * values,GLubyte value)3431 void RectangleTest::pack_UNSIGNED_BYTE_3_3_2_INT(rawIntPixel *values, GLubyte value)
3432 {
3433     (*values)[0] = (static_cast<GLbyte>(value) >> 5) & 7;
3434     (*values)[1] = (static_cast<GLbyte>(value) >> 2) & 7;
3435     (*values)[2] = (static_cast<GLbyte>(value) >> 0) & 3;
3436 }
3437 
pack_UNSIGNED_BYTE_2_3_3_REV(rawFloatPixel * values,GLubyte value)3438 void RectangleTest::pack_UNSIGNED_BYTE_2_3_3_REV(rawFloatPixel *values, GLubyte value)
3439 {
3440     (*values)[2] = ((value >> 6) & 3) / 3.0f;
3441     (*values)[1] = ((value >> 3) & 7) / 7.0f;
3442     (*values)[0] = ((value >> 0) & 7) / 7.0f;
3443 }
3444 
pack_UNSIGNED_BYTE_2_3_3_REV_UINT(rawUintPixel * values,GLubyte value)3445 void RectangleTest::pack_UNSIGNED_BYTE_2_3_3_REV_UINT(rawUintPixel *values, GLubyte value)
3446 {
3447     (*values)[2] = (value >> 6) & 3;
3448     (*values)[1] = (value >> 3) & 7;
3449     (*values)[0] = (value >> 0) & 7;
3450 }
3451 
pack_UNSIGNED_BYTE_2_3_3_REV_INT(rawIntPixel * values,GLubyte value)3452 void RectangleTest::pack_UNSIGNED_BYTE_2_3_3_REV_INT(rawIntPixel *values, GLubyte value)
3453 {
3454     (*values)[2] = (static_cast<GLbyte>(value) >> 6) & 3;
3455     (*values)[1] = (static_cast<GLbyte>(value) >> 3) & 7;
3456     (*values)[0] = (static_cast<GLbyte>(value) >> 0) & 7;
3457 }
3458 
pack_UNSIGNED_SHORT_5_6_5(rawFloatPixel * values,GLushort value)3459 void RectangleTest::pack_UNSIGNED_SHORT_5_6_5(rawFloatPixel *values, GLushort value)
3460 {
3461     (*values)[0] = ((value >> 11) & 31) / 31.0f;
3462     (*values)[1] = ((value >> 5) & 63) / 63.0f;
3463     (*values)[2] = ((value >> 0) & 31) / 31.0f;
3464 }
3465 
pack_UNSIGNED_SHORT_5_6_5_UINT(rawUintPixel * values,GLushort value)3466 void RectangleTest::pack_UNSIGNED_SHORT_5_6_5_UINT(rawUintPixel *values, GLushort value)
3467 {
3468     (*values)[0] = (value >> 11) & 31;
3469     (*values)[1] = (value >> 5) & 63;
3470     (*values)[2] = (value >> 0) & 31;
3471 }
3472 
pack_UNSIGNED_SHORT_5_6_5_INT(rawIntPixel * values,GLushort value)3473 void RectangleTest::pack_UNSIGNED_SHORT_5_6_5_INT(rawIntPixel *values, GLushort value)
3474 {
3475     (*values)[0] = (static_cast<GLshort>(value) >> 11) & 31;
3476     (*values)[1] = (static_cast<GLshort>(value) >> 5) & 63;
3477     (*values)[2] = (static_cast<GLshort>(value) >> 0) & 31;
3478 }
3479 
pack_UNSIGNED_SHORT_5_6_5_REV(rawFloatPixel * values,GLushort value)3480 void RectangleTest::pack_UNSIGNED_SHORT_5_6_5_REV(rawFloatPixel *values, GLushort value)
3481 {
3482     (*values)[2] = ((value >> 11) & 31) / 31.0f;
3483     (*values)[1] = ((value >> 5) & 63) / 63.0f;
3484     (*values)[0] = ((value >> 0) & 31) / 31.0f;
3485 }
3486 
pack_UNSIGNED_SHORT_5_6_5_REV_UINT(rawUintPixel * values,GLushort value)3487 void RectangleTest::pack_UNSIGNED_SHORT_5_6_5_REV_UINT(rawUintPixel *values, GLushort value)
3488 {
3489     (*values)[2] = (value >> 11) & 31;
3490     (*values)[1] = (value >> 5) & 63;
3491     (*values)[0] = (value >> 0) & 31;
3492 }
3493 
pack_UNSIGNED_SHORT_5_6_5_REV_INT(rawIntPixel * values,GLushort value)3494 void RectangleTest::pack_UNSIGNED_SHORT_5_6_5_REV_INT(rawIntPixel *values, GLushort value)
3495 {
3496     (*values)[2] = (static_cast<GLshort>(value) >> 11) & 31;
3497     (*values)[1] = (static_cast<GLshort>(value) >> 5) & 63;
3498     (*values)[0] = (static_cast<GLshort>(value) >> 0) & 31;
3499 }
3500 
pack_UNSIGNED_SHORT_4_4_4_4(rawFloatPixel * values,GLushort value)3501 void RectangleTest::pack_UNSIGNED_SHORT_4_4_4_4(rawFloatPixel *values, GLushort value)
3502 {
3503     (*values)[0] = ((value >> 12) & 15) / 15.0f;
3504     (*values)[1] = ((value >> 8) & 15) / 15.0f;
3505     (*values)[2] = ((value >> 4) & 15) / 15.0f;
3506     (*values)[3] = ((value >> 0) & 15) / 15.0f;
3507 }
3508 
pack_UNSIGNED_SHORT_4_4_4_4_UINT(rawUintPixel * values,GLushort value)3509 void RectangleTest::pack_UNSIGNED_SHORT_4_4_4_4_UINT(rawUintPixel *values, GLushort value)
3510 {
3511     (*values)[0] = (value >> 12) & 15;
3512     (*values)[1] = (value >> 8) & 15;
3513     (*values)[2] = (value >> 4) & 15;
3514     (*values)[3] = (value >> 0) & 15;
3515 }
3516 
pack_UNSIGNED_SHORT_4_4_4_4_INT(rawIntPixel * values,GLushort value)3517 void RectangleTest::pack_UNSIGNED_SHORT_4_4_4_4_INT(rawIntPixel *values, GLushort value)
3518 {
3519     (*values)[0] = (static_cast<GLshort>(value) >> 12) & 15;
3520     (*values)[1] = (static_cast<GLshort>(value) >> 8) & 15;
3521     (*values)[2] = (static_cast<GLshort>(value) >> 4) & 15;
3522     (*values)[3] = (static_cast<GLshort>(value) >> 0) & 15;
3523 }
3524 
pack_UNSIGNED_SHORT_4_4_4_4_REV(rawFloatPixel * values,GLushort value)3525 void RectangleTest::pack_UNSIGNED_SHORT_4_4_4_4_REV(rawFloatPixel *values, GLushort value)
3526 {
3527     (*values)[3] = ((value >> 12) & 15) / 15.0f;
3528     (*values)[2] = ((value >> 8) & 15) / 15.0f;
3529     (*values)[1] = ((value >> 4) & 15) / 15.0f;
3530     (*values)[0] = ((value >> 0) & 15) / 15.0f;
3531 }
3532 
pack_UNSIGNED_SHORT_4_4_4_4_REV_UINT(rawUintPixel * values,GLushort value)3533 void RectangleTest::pack_UNSIGNED_SHORT_4_4_4_4_REV_UINT(rawUintPixel *values, GLushort value)
3534 {
3535     (*values)[3] = (value >> 12) & 15;
3536     (*values)[2] = (value >> 8) & 15;
3537     (*values)[1] = (value >> 4) & 15;
3538     (*values)[0] = (value >> 0) & 15;
3539 }
3540 
pack_UNSIGNED_SHORT_4_4_4_4_REV_INT(rawIntPixel * values,GLushort value)3541 void RectangleTest::pack_UNSIGNED_SHORT_4_4_4_4_REV_INT(rawIntPixel *values, GLushort value)
3542 {
3543     (*values)[3] = (static_cast<GLshort>(value) >> 12) & 15;
3544     (*values)[2] = (static_cast<GLshort>(value) >> 8) & 15;
3545     (*values)[1] = (static_cast<GLshort>(value) >> 4) & 15;
3546     (*values)[0] = (static_cast<GLshort>(value) >> 0) & 15;
3547 }
3548 
pack_UNSIGNED_SHORT_5_5_5_1(rawFloatPixel * values,GLushort value)3549 void RectangleTest::pack_UNSIGNED_SHORT_5_5_5_1(rawFloatPixel *values, GLushort value)
3550 {
3551     (*values)[0] = ((value >> 11) & 31) / 31.0f;
3552     (*values)[1] = ((value >> 6) & 31) / 31.0f;
3553     (*values)[2] = ((value >> 1) & 31) / 31.0f;
3554     (*values)[3] = ((value >> 0) & 1) / 1.0f;
3555 }
3556 
pack_UNSIGNED_SHORT_5_5_5_1_UINT(rawUintPixel * values,GLushort value)3557 void RectangleTest::pack_UNSIGNED_SHORT_5_5_5_1_UINT(rawUintPixel *values, GLushort value)
3558 {
3559     (*values)[0] = (value >> 11) & 31;
3560     (*values)[1] = (value >> 6) & 31;
3561     (*values)[2] = (value >> 1) & 31;
3562     (*values)[3] = (value >> 0) & 1;
3563 }
3564 
pack_UNSIGNED_SHORT_5_5_5_1_INT(rawIntPixel * values,GLushort value)3565 void RectangleTest::pack_UNSIGNED_SHORT_5_5_5_1_INT(rawIntPixel *values, GLushort value)
3566 {
3567     (*values)[0] = (static_cast<GLshort>(value) >> 11) & 31;
3568     (*values)[1] = (static_cast<GLshort>(value) >> 6) & 31;
3569     (*values)[2] = (static_cast<GLshort>(value) >> 1) & 31;
3570     (*values)[3] = (static_cast<GLshort>(value) >> 0) & 1;
3571 }
3572 
pack_UNSIGNED_SHORT_1_5_5_5_REV(rawFloatPixel * values,GLushort value)3573 void RectangleTest::pack_UNSIGNED_SHORT_1_5_5_5_REV(rawFloatPixel *values, GLushort value)
3574 {
3575     (*values)[3] = ((value >> 15) & 1) / 1.0f;
3576     (*values)[2] = ((value >> 10) & 31) / 31.0f;
3577     (*values)[1] = ((value >> 5) & 31) / 31.0f;
3578     (*values)[0] = ((value >> 0) & 31) / 31.0f;
3579 }
3580 
pack_UNSIGNED_SHORT_1_5_5_5_REV_UINT(rawUintPixel * values,GLushort value)3581 void RectangleTest::pack_UNSIGNED_SHORT_1_5_5_5_REV_UINT(rawUintPixel *values, GLushort value)
3582 {
3583     (*values)[3] = (value >> 15) & 1;
3584     (*values)[2] = (value >> 10) & 31;
3585     (*values)[1] = (value >> 5) & 31;
3586     (*values)[0] = (value >> 0) & 31;
3587 }
3588 
pack_UNSIGNED_SHORT_1_5_5_5_REV_INT(rawIntPixel * values,GLushort value)3589 void RectangleTest::pack_UNSIGNED_SHORT_1_5_5_5_REV_INT(rawIntPixel *values, GLushort value)
3590 {
3591     (*values)[3] = (static_cast<GLshort>(value) >> 15) & 1;
3592     (*values)[2] = (static_cast<GLshort>(value) >> 10) & 31;
3593     (*values)[1] = (static_cast<GLshort>(value) >> 5) & 31;
3594     (*values)[0] = (static_cast<GLshort>(value) >> 0) & 31;
3595 }
3596 
pack_UNSIGNED_INT_8_8_8_8(rawFloatPixel * values,GLuint value)3597 void RectangleTest::pack_UNSIGNED_INT_8_8_8_8(rawFloatPixel *values, GLuint value)
3598 {
3599     (*values)[0] = ((value >> 24) & 255) / 255.0f;
3600     (*values)[1] = ((value >> 16) & 255) / 255.0f;
3601     (*values)[2] = ((value >> 8) & 255) / 255.0f;
3602     (*values)[3] = ((value >> 0) & 255) / 255.0f;
3603 }
3604 
pack_UNSIGNED_INT_8_8_8_8_UINT(rawUintPixel * values,GLuint value)3605 void RectangleTest::pack_UNSIGNED_INT_8_8_8_8_UINT(rawUintPixel *values, GLuint value)
3606 {
3607     (*values)[0] = (value >> 24) & 255;
3608     (*values)[1] = (value >> 16) & 255;
3609     (*values)[2] = (value >> 8) & 255;
3610     (*values)[3] = (value >> 0) & 255;
3611 }
3612 
pack_UNSIGNED_INT_8_8_8_8_INT(rawIntPixel * values,GLuint value)3613 void RectangleTest::pack_UNSIGNED_INT_8_8_8_8_INT(rawIntPixel *values, GLuint value)
3614 {
3615     (*values)[0] = (static_cast<GLint>(value) >> 24) & 255;
3616     (*values)[1] = (static_cast<GLint>(value) >> 16) & 255;
3617     (*values)[2] = (static_cast<GLint>(value) >> 8) & 255;
3618     (*values)[3] = (static_cast<GLint>(value) >> 0) & 255;
3619 }
3620 
pack_UNSIGNED_INT_8_8_8_8_REV(rawFloatPixel * values,GLuint value)3621 void RectangleTest::pack_UNSIGNED_INT_8_8_8_8_REV(rawFloatPixel *values, GLuint value)
3622 {
3623     (*values)[3] = ((value >> 24) & 255) / 255.0f;
3624     (*values)[2] = ((value >> 16) & 255) / 255.0f;
3625     (*values)[1] = ((value >> 8) & 255) / 255.0f;
3626     (*values)[0] = ((value >> 0) & 255) / 255.0f;
3627 }
3628 
pack_UNSIGNED_INT_8_8_8_8_REV_UINT(rawUintPixel * values,GLuint value)3629 void RectangleTest::pack_UNSIGNED_INT_8_8_8_8_REV_UINT(rawUintPixel *values, GLuint value)
3630 {
3631     (*values)[3] = (value >> 24) & 255;
3632     (*values)[2] = (value >> 16) & 255;
3633     (*values)[1] = (value >> 8) & 255;
3634     (*values)[0] = (value >> 0) & 255;
3635 }
3636 
pack_UNSIGNED_INT_8_8_8_8_REV_INT(rawIntPixel * values,GLuint value)3637 void RectangleTest::pack_UNSIGNED_INT_8_8_8_8_REV_INT(rawIntPixel *values, GLuint value)
3638 {
3639     (*values)[3] = (static_cast<GLint>(value) >> 24) & 255;
3640     (*values)[2] = (static_cast<GLint>(value) >> 16) & 255;
3641     (*values)[1] = (static_cast<GLint>(value) >> 8) & 255;
3642     (*values)[0] = (static_cast<GLint>(value) >> 0) & 255;
3643 }
3644 
pack_UNSIGNED_INT_10_10_10_2(rawFloatPixel * values,GLuint value)3645 void RectangleTest::pack_UNSIGNED_INT_10_10_10_2(rawFloatPixel *values, GLuint value)
3646 {
3647     (*values)[0] = ((value >> 22) & 1023) / 1023.0f;
3648     (*values)[1] = ((value >> 12) & 1023) / 1023.0f;
3649     (*values)[2] = ((value >> 2) & 1023) / 1023.0f;
3650     (*values)[3] = ((value >> 0) & 3) / 3.0f;
3651 }
3652 
pack_UNSIGNED_INT_10_10_10_2_UINT(rawUintPixel * values,GLuint value)3653 void RectangleTest::pack_UNSIGNED_INT_10_10_10_2_UINT(rawUintPixel *values, GLuint value)
3654 {
3655     (*values)[0] = ((value >> 22) & 1023);
3656     (*values)[1] = ((value >> 12) & 1023);
3657     (*values)[2] = ((value >> 2) & 1023);
3658     (*values)[3] = ((value >> 0) & 3);
3659 }
3660 
pack_UNSIGNED_INT_10_10_10_2_INT(rawIntPixel * values,GLuint value)3661 void RectangleTest::pack_UNSIGNED_INT_10_10_10_2_INT(rawIntPixel *values, GLuint value)
3662 {
3663     (*values)[0] = ((static_cast<GLint>(value) >> 22) & 1023);
3664     (*values)[1] = ((static_cast<GLint>(value) >> 12) & 1023);
3665     (*values)[2] = ((static_cast<GLint>(value) >> 2) & 1023);
3666     (*values)[3] = ((static_cast<GLint>(value) >> 0) & 3);
3667 }
3668 
pack_UNSIGNED_INT_2_10_10_10_REV(rawFloatPixel * values,GLuint value)3669 void RectangleTest::pack_UNSIGNED_INT_2_10_10_10_REV(rawFloatPixel *values, GLuint value)
3670 {
3671     (*values)[3] = ((value >> 30) & 3) / 3.0f;
3672     (*values)[2] = ((value >> 20) & 1023) / 1023.0f;
3673     (*values)[1] = ((value >> 10) & 1023) / 1023.0f;
3674     (*values)[0] = ((value >> 0) & 1023) / 1023.0f;
3675 }
3676 
pack_UNSIGNED_INT_2_10_10_10_REV_UINT(rawUintPixel * values,GLuint value)3677 void RectangleTest::pack_UNSIGNED_INT_2_10_10_10_REV_UINT(rawUintPixel *values, GLuint value)
3678 {
3679     (*values)[3] = (value >> 30) & 3;
3680     (*values)[2] = (value >> 20) & 1023;
3681     (*values)[1] = (value >> 10) & 1023;
3682     (*values)[0] = (value >> 0) & 1023;
3683 }
3684 
pack_UNSIGNED_INT_2_10_10_10_REV_INT(rawIntPixel * values,GLuint value)3685 void RectangleTest::pack_UNSIGNED_INT_2_10_10_10_REV_INT(rawIntPixel *values, GLuint value)
3686 {
3687     (*values)[3] = (static_cast<GLint>(value) >> 30) & 3;
3688     (*values)[2] = (static_cast<GLint>(value) >> 20) & 1023;
3689     (*values)[1] = (static_cast<GLint>(value) >> 10) & 1023;
3690     (*values)[0] = (static_cast<GLint>(value) >> 0) & 1023;
3691 }
3692 
pack_UNSIGNED_INT_24_8(rawFloatPixel * values,GLuint value)3693 void RectangleTest::pack_UNSIGNED_INT_24_8(rawFloatPixel *values, GLuint value)
3694 {
3695     (*values)[0] = ((value >> 8) & 16777215) / 16777215.0f;
3696     (*values)[1] = ((value >> 0) & 255) / 255.0f;
3697 }
3698 
pack_UNSIGNED_INT_10F_11F_11F_REV(rawFloatPixel * values,GLuint value)3699 void RectangleTest::pack_UNSIGNED_INT_10F_11F_11F_REV(rawFloatPixel *values, GLuint value)
3700 {
3701     (*values)[2] = unsignedF10ToFloat((value >> 22) & 1023);
3702     (*values)[1] = unsignedF11ToFloat((value >> 11) & 2047);
3703     (*values)[0] = unsignedF11ToFloat((value >> 0) & 2047);
3704 }
3705 
pack_UNSIGNED_INT_5_9_9_9_REV(rawFloatPixel * values,GLuint value)3706 void RectangleTest::pack_UNSIGNED_INT_5_9_9_9_REV(rawFloatPixel *values, GLuint value)
3707 {
3708     const int B   = 15;
3709     const int N   = 9;
3710     GLint pExp    = ((value >> 27) & 31);
3711     GLuint pBlue  = ((value >> 18) & 511);
3712     GLuint pGreen = ((value >> 9) & 511);
3713     GLuint pRed   = ((value >> 0) & 511);
3714 
3715     (*values)[2] = (float)(pBlue * pow(2.0, pExp - B - N));
3716     (*values)[1] = (float)(pGreen * pow(2.0, pExp - B - N));
3717     (*values)[0] = (float)(pRed * pow(2.0, pExp - B - N));
3718     (*values)[3] = 1.0f;
3719 }
3720 
pack_FLOAT_32_UNSIGNED_INT_24_8_REV(rawFloatPixel * values,F_32_UINT_24_8_REV value)3721 void RectangleTest::pack_FLOAT_32_UNSIGNED_INT_24_8_REV(rawFloatPixel *values, F_32_UINT_24_8_REV value)
3722 {
3723     (*values)[0] = value.d;
3724     (*values)[1] = (value.s & 255) / 255.0f;
3725 }
3726 
getTexImage()3727 bool RectangleTest::getTexImage()
3728 {
3729     // for each output format
3730     for (int m = 0; m < DE_LENGTH_OF_ARRAY(coreFormats); ++m)
3731     {
3732         const PixelFormat &outputFormat = coreFormats[m];
3733 
3734         // for each output type
3735         for (int n = 0; n < DE_LENGTH_OF_ARRAY(coreTypes); ++n)
3736         {
3737             const PixelType &outputType = coreTypes[n];
3738 
3739             if ((m_inputFormat.format != m_internalFormat.format || m_inputType.type != m_internalFormat.type) &&
3740                 (outputFormat.format != m_internalFormat.format || outputType.type != m_internalFormat.type))
3741             {
3742                 continue;
3743             }
3744 
3745             if (!getTexImageInner(outputFormat, outputType))
3746                 return false;
3747         }
3748     }
3749 
3750     return true;
3751 }
3752 
getTexImageInner(const PixelFormat & outputFormat,const PixelType & outputType)3753 bool RectangleTest::getTexImageInner(const PixelFormat &outputFormat, const PixelType &outputType)
3754 {
3755     bool outputFormatValid = isFormatValid(outputFormat, outputType, m_internalFormat, false, true, OUTPUT_GETTEXIMAGE);
3756 
3757     GLenum error = readOutputData(outputFormat, outputType, OUTPUT_GETTEXIMAGE);
3758     m_countGetTexImage++;
3759 
3760     if (!outputFormatValid)
3761     {
3762         if (error)
3763         {
3764             m_countGetTexImageOK++;
3765             return true;
3766         }
3767 
3768         m_testCtx.getLog() << tcu::TestLog::Message << "Expected error but got no GL error" << tcu::TestLog::EndMessage;
3769         return false;
3770     }
3771     else if (error)
3772     {
3773         m_testCtx.getLog() << tcu::TestLog::Message << "Error during glGetTexImage" << tcu::TestLog::EndMessage;
3774         return false;
3775     }
3776 
3777     m_countGetTexImageOK++;
3778     m_countCompare++;
3779 
3780     // compare output gradient to input gradient
3781     if (compare(&m_gradient[0], &m_outputBuffer[0], outputFormat, outputType, false))
3782     {
3783         m_countCompareOK++;
3784         return true;
3785     }
3786 
3787     m_testCtx.getLog() << tcu::TestLog::Message << "Gradient comparison failed during GetTexImage for input = ["
3788                        << getFormatStr(m_inputFormat.format) << ", " << getTypeStr(m_inputType.type) << "] output = ["
3789                        << getFormatStr(outputFormat.format) << ", " << getTypeStr(outputType.type) << "]"
3790                        << tcu::TestLog::EndMessage;
3791     return false;
3792 }
3793 
testAllFormatsAndTypes()3794 void RectangleTest::testAllFormatsAndTypes()
3795 {
3796     DE_ASSERT((m_textureTarget == GL_TEXTURE_2D) || (m_textureTarget == GL_TEXTURE_3D));
3797 
3798     glu::RenderContext &renderContext = m_context.getRenderContext();
3799     const Functions &gl               = renderContext.getFunctions();
3800     bool result                       = true;
3801 
3802     gl.clear(GL_COLOR_BUFFER_BIT);
3803 
3804     const PixelType *types;
3805     int typesCount;
3806     const PixelFormat *formats;
3807     int formatsCount;
3808     if (glu::isContextTypeES(m_context.getRenderContext().getType()))
3809     {
3810         types        = esTypes;
3811         typesCount   = DE_LENGTH_OF_ARRAY(esTypes);
3812         formats      = esFormats;
3813         formatsCount = DE_LENGTH_OF_ARRAY(esFormats);
3814     }
3815     else
3816     {
3817         types        = coreTypes;
3818         typesCount   = DE_LENGTH_OF_ARRAY(coreTypes);
3819         formats      = coreFormats;
3820         formatsCount = DE_LENGTH_OF_ARRAY(coreFormats);
3821     }
3822 
3823     for (int inputFormatIndex = 0; inputFormatIndex < formatsCount; inputFormatIndex++)
3824     {
3825         m_inputFormat = formats[inputFormatIndex];
3826 
3827         for (int inputTypeIndex = 0; inputTypeIndex < typesCount; inputTypeIndex++)
3828         {
3829             GLenum error = 0;
3830             m_inputType  = types[inputTypeIndex];
3831 
3832             applyInitialStorageModes();
3833 
3834             // Create input gradient in format,type, with appropriate range
3835             createGradient();
3836             if (m_gradient.empty())
3837                 TCU_FAIL("Could not create gradient.");
3838 
3839             if (m_unpackProperties.swapBytes)
3840                 swapBytes(m_inputType.size, m_gradient);
3841 
3842             GLuint texture;
3843             gl.genTextures(1, &texture);
3844             gl.bindTexture(m_textureTarget, texture);
3845             GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture");
3846             if (m_textureTarget == GL_TEXTURE_3D)
3847             {
3848                 gl.texImage3D(GL_TEXTURE_3D, 0, m_internalFormat.sizedFormat, GRADIENT_WIDTH, GRADIENT_HEIGHT, 1, 0,
3849                               m_inputFormat.format, m_inputType.type, &m_gradient[0]);
3850             }
3851             else
3852             {
3853                 gl.texImage2D(GL_TEXTURE_2D, 0, m_internalFormat.sizedFormat, GRADIENT_WIDTH, GRADIENT_HEIGHT, 0,
3854                               m_inputFormat.format, m_inputType.type, &m_gradient[0]);
3855             }
3856 
3857             if (m_unpackProperties.swapBytes)
3858                 swapBytes(m_inputType.size, m_gradient);
3859 
3860             error = gl.getError();
3861             if (isFormatValid(m_inputFormat, m_inputType, m_internalFormat, true, false, INPUT_TEXIMAGE))
3862             {
3863                 if (error == GL_NO_ERROR)
3864                 {
3865                     if (!glu::isContextTypeES(renderContext.getType()))
3866                         result &= getTexImage();
3867                     result &= doRead(texture);
3868                 }
3869                 else
3870                 {
3871                     m_testCtx.getLog() << tcu::TestLog::Message << "Valid format used but glTexImage2D/3D failed"
3872                                        << tcu::TestLog::EndMessage;
3873                     result = false;
3874                 }
3875             }
3876             else if (error == GL_NO_ERROR)
3877             {
3878                 m_testCtx.getLog() << tcu::TestLog::Message << "Invalid format used but glTexImage2D/3D succeeded"
3879                                    << tcu::TestLog::EndMessage;
3880                 result = false;
3881             }
3882 
3883             gl.deleteTextures(1, &texture);
3884         }
3885     }
3886 
3887     if (result)
3888         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
3889     else
3890         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
3891 }
3892 
iterate(void)3893 tcu::TestNode::IterateResult RectangleTest::iterate(void)
3894 {
3895     resetInitialStorageModes();
3896     testAllFormatsAndTypes();
3897     return STOP;
3898 }
3899 
3900 class InitialValuesTest : public deqp::TestCase
3901 {
3902 public:
3903     InitialValuesTest(deqp::Context &context);
3904     virtual ~InitialValuesTest();
3905 
3906     tcu::TestNode::IterateResult iterate(void);
3907 };
3908 
InitialValuesTest(deqp::Context & context)3909 InitialValuesTest::InitialValuesTest(deqp::Context &context)
3910     : deqp::TestCase(context, "initial_values",
3911                      "Verify if all UNPACK and PACK initial "
3912                      "state matches the values in table 6.28 (6.23, in ES.)")
3913 {
3914 }
3915 
~InitialValuesTest()3916 InitialValuesTest::~InitialValuesTest()
3917 {
3918 }
3919 
iterate(void)3920 tcu::TestNode::IterateResult InitialValuesTest::iterate(void)
3921 {
3922     glu::RenderContext &renderContext = m_context.getRenderContext();
3923     const Functions &gl               = renderContext.getFunctions();
3924 
3925     bool result = true;
3926 
3927     GLenum commonIntModes[] = {GL_UNPACK_ROW_LENGTH,   GL_UNPACK_SKIP_ROWS,   GL_UNPACK_SKIP_PIXELS,
3928                                GL_UNPACK_IMAGE_HEIGHT, GL_UNPACK_SKIP_IMAGES, GL_PACK_ROW_LENGTH,
3929                                GL_PACK_SKIP_ROWS,      GL_PACK_SKIP_PIXELS};
3930 
3931     // check if following eight storage modes are 0
3932     GLint i = 1;
3933     for (int mode = 0; mode < DE_LENGTH_OF_ARRAY(commonIntModes); mode++)
3934     {
3935         gl.getIntegerv(commonIntModes[mode], &i);
3936         result &= (i == 0);
3937     }
3938 
3939     // check if following two storage modes are 4
3940     gl.getIntegerv(GL_UNPACK_ALIGNMENT, &i);
3941     result &= (i == 4);
3942     gl.getIntegerv(GL_PACK_ALIGNMENT, &i);
3943     result &= (i == 4);
3944 
3945     // check storage modes available only in core GL
3946     if (!glu::isContextTypeES(renderContext.getType()))
3947     {
3948         // check if following four boolean modes are false
3949         GLboolean b = true;
3950         gl.getBooleanv(GL_UNPACK_SWAP_BYTES, &b);
3951         result &= (b == false);
3952         gl.getBooleanv(GL_UNPACK_LSB_FIRST, &b);
3953         result &= (b == false);
3954         gl.getBooleanv(GL_PACK_SWAP_BYTES, &b);
3955         result &= (b == false);
3956         gl.getBooleanv(GL_PACK_LSB_FIRST, &b);
3957         result &= (b == false);
3958 
3959         // check if following two modes are 0
3960         gl.getIntegerv(GL_PACK_IMAGE_HEIGHT, &i);
3961         result &= (i == 0);
3962         gl.getIntegerv(GL_PACK_SKIP_IMAGES, &i);
3963         result &= (i == 0);
3964     }
3965 
3966     // make sure that no pack/unpack buffers are bound
3967     gl.getIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &i);
3968     result &= (i == 0);
3969     gl.getIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &i);
3970     result &= (i == 0);
3971 
3972     if (result)
3973         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
3974     else
3975         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
3976     return STOP;
3977 }
3978 
3979 class PBORectangleTest : public RectangleTest
3980 {
3981 public:
3982     PBORectangleTest(deqp::Context &context, std::string &name, InternalFormat internalFormat);
3983     virtual ~PBORectangleTest();
3984 };
3985 
PBORectangleTest(deqp::Context & context,std::string & name,InternalFormat internalFormat)3986 PBORectangleTest::PBORectangleTest(deqp::Context &context, std::string &name, InternalFormat internalFormat)
3987     : RectangleTest(context, name, internalFormat)
3988 {
3989     m_usePBO = true;
3990 }
3991 
~PBORectangleTest()3992 PBORectangleTest::~PBORectangleTest()
3993 {
3994 }
3995 
3996 class VariedRectangleTest : public RectangleTest
3997 {
3998 public:
3999     VariedRectangleTest(deqp::Context &context, std::string &name, InternalFormat internalFormat);
4000     virtual ~VariedRectangleTest();
4001 
4002     tcu::TestNode::IterateResult iterate(void);
4003 
4004 protected:
4005     struct StoreMode
4006     {
4007         GLenum parameter;
4008         GLint *property;
4009         GLint value;
4010     };
4011 };
4012 
VariedRectangleTest(deqp::Context & context,std::string & name,InternalFormat internalFormat)4013 VariedRectangleTest::VariedRectangleTest(deqp::Context &context, std::string &name, InternalFormat internalFormat)
4014     : RectangleTest(context, name, internalFormat)
4015 {
4016 }
4017 
~VariedRectangleTest()4018 VariedRectangleTest::~VariedRectangleTest()
4019 {
4020 }
4021 
iterate(void)4022 tcu::TestNode::IterateResult VariedRectangleTest::iterate(void)
4023 {
4024     const int IMAGE_WIDTH_1  = 10;
4025     const int IMAGE_WIDTH_2  = 15;
4026     const int IMAGE_HEIGHT_1 = 10;
4027     const int IMAGE_HEIGHT_2 = 15;
4028 
4029     PackedPixelsBufferProperties &up = m_initialUnpackProperties;
4030     PackedPixelsBufferProperties &pp = m_initialPackProperties;
4031 
4032     StoreMode commonCases[] = {
4033         {GL_UNPACK_ROW_LENGTH, &up.rowLength, 0},
4034         {GL_UNPACK_ROW_LENGTH, &up.rowLength, IMAGE_WIDTH_1},
4035         {GL_UNPACK_ROW_LENGTH, &up.rowLength, IMAGE_WIDTH_2},
4036         {GL_UNPACK_SKIP_ROWS, &up.skipRows, 0},
4037         {GL_UNPACK_SKIP_ROWS, &up.skipRows, 1},
4038         {GL_UNPACK_SKIP_ROWS, &up.skipRows, 2},
4039         {GL_UNPACK_SKIP_PIXELS, &up.skipPixels, 0},
4040         {GL_UNPACK_SKIP_PIXELS, &up.skipPixels, 1},
4041         {GL_UNPACK_SKIP_PIXELS, &up.skipPixels, 2},
4042         {GL_UNPACK_ALIGNMENT, &up.alignment, 1},
4043         {GL_UNPACK_ALIGNMENT, &up.alignment, 2},
4044         {GL_UNPACK_ALIGNMENT, &up.alignment, 4},
4045         {GL_UNPACK_ALIGNMENT, &up.alignment, 8},
4046         {GL_UNPACK_IMAGE_HEIGHT, &up.rowCount, 0},
4047         {GL_UNPACK_IMAGE_HEIGHT, &up.rowCount, IMAGE_HEIGHT_1},
4048         {GL_UNPACK_IMAGE_HEIGHT, &up.rowCount, IMAGE_HEIGHT_2},
4049         {GL_UNPACK_SKIP_IMAGES, &up.skipImages, 0},
4050         {GL_UNPACK_SKIP_IMAGES, &up.skipImages, 1},
4051         {GL_UNPACK_SKIP_IMAGES, &up.skipImages, 2},
4052         {GL_PACK_ROW_LENGTH, &pp.rowLength, 0},
4053         {GL_PACK_ROW_LENGTH, &pp.rowLength, IMAGE_WIDTH_1},
4054         {GL_PACK_ROW_LENGTH, &pp.rowLength, IMAGE_WIDTH_2},
4055         {GL_PACK_SKIP_ROWS, &pp.skipRows, 0},
4056         {GL_PACK_SKIP_ROWS, &pp.skipRows, 1},
4057         {GL_PACK_SKIP_ROWS, &pp.skipRows, 2},
4058         {GL_PACK_SKIP_PIXELS, &pp.skipPixels, 0},
4059         {GL_PACK_SKIP_PIXELS, &pp.skipPixels, 1},
4060         {GL_PACK_SKIP_PIXELS, &pp.skipPixels, 2},
4061         {GL_PACK_ALIGNMENT, &pp.alignment, 1},
4062         {GL_PACK_ALIGNMENT, &pp.alignment, 2},
4063         {GL_PACK_ALIGNMENT, &pp.alignment, 4},
4064         {GL_PACK_ALIGNMENT, &pp.alignment, 8},
4065     };
4066 
4067     StoreMode coreCases[] = {
4068         {GL_UNPACK_SWAP_BYTES, &up.swapBytes, GL_FALSE},
4069         {GL_UNPACK_SWAP_BYTES, &up.swapBytes, GL_TRUE},
4070         {GL_UNPACK_LSB_FIRST, &up.lsbFirst, GL_FALSE},
4071         {GL_UNPACK_LSB_FIRST, &up.lsbFirst, GL_TRUE},
4072         {GL_PACK_SWAP_BYTES, &pp.swapBytes, GL_FALSE},
4073         {GL_PACK_SWAP_BYTES, &pp.swapBytes, GL_TRUE},
4074         {GL_PACK_LSB_FIRST, &pp.lsbFirst, GL_FALSE},
4075         {GL_PACK_LSB_FIRST, &pp.lsbFirst, GL_TRUE},
4076         {GL_PACK_IMAGE_HEIGHT, &pp.rowCount, 0},
4077         {GL_PACK_IMAGE_HEIGHT, &pp.rowCount, IMAGE_HEIGHT_1},
4078         {GL_PACK_IMAGE_HEIGHT, &pp.rowCount, IMAGE_HEIGHT_2},
4079         {GL_PACK_SKIP_IMAGES, &pp.skipImages, 0},
4080         {GL_PACK_SKIP_IMAGES, &pp.skipImages, 1},
4081         {GL_PACK_SKIP_IMAGES, &pp.skipImages, 2},
4082     };
4083 
4084     std::vector<StoreMode> testModes(commonCases, commonCases + DE_LENGTH_OF_ARRAY(commonCases));
4085     glu::RenderContext &renderContext = m_context.getRenderContext();
4086     bool contextTypeIsCoreGL          = !glu::isContextTypeES(renderContext.getType());
4087     if (contextTypeIsCoreGL)
4088         testModes.insert(testModes.end(), coreCases, coreCases + DE_LENGTH_OF_ARRAY(coreCases));
4089 
4090     std::vector<StoreMode>::iterator currentCase = testModes.begin();
4091     while (currentCase != testModes.end())
4092     {
4093         resetInitialStorageModes();
4094 
4095         GLenum parameter = currentCase->parameter;
4096         GLint value      = currentCase->value;
4097 
4098         *(currentCase->property) = value;
4099 
4100         // for some parameters an additional parameter needs to be set
4101         if (parameter == GL_PACK_SKIP_ROWS)
4102         {
4103             if (contextTypeIsCoreGL)
4104                 m_initialPackProperties.rowCount = GRADIENT_HEIGHT + value;
4105         }
4106         else if (parameter == GL_PACK_SKIP_PIXELS)
4107             m_initialPackProperties.rowLength = GRADIENT_WIDTH + value;
4108         else if (parameter == GL_UNPACK_SKIP_ROWS)
4109             m_initialUnpackProperties.rowCount = GRADIENT_HEIGHT + value;
4110         else if (parameter == GL_UNPACK_SKIP_PIXELS)
4111             m_initialUnpackProperties.rowLength = GRADIENT_WIDTH + value;
4112 
4113         m_textureTarget = GL_TEXTURE_2D;
4114         if ((parameter == GL_PACK_IMAGE_HEIGHT) || (parameter == GL_PACK_SKIP_IMAGES) ||
4115             (parameter == GL_UNPACK_IMAGE_HEIGHT) || (parameter == GL_UNPACK_SKIP_IMAGES))
4116             m_textureTarget = GL_TEXTURE_3D;
4117 
4118         testAllFormatsAndTypes();
4119 
4120         if (m_testCtx.getTestResult() != QP_TEST_RESULT_PASS)
4121         {
4122             m_testCtx.getLog() << tcu::TestLog::Message
4123                                << "Case for: " << glu::getGettableStateStr(parameter).toString() << " = " << value
4124                                << " failed." << tcu::TestLog::EndMessage;
4125             return STOP;
4126         }
4127 
4128         ++currentCase;
4129     }
4130 
4131     return STOP;
4132 }
4133 
PackedPixelsTests(deqp::Context & context)4134 PackedPixelsTests::PackedPixelsTests(deqp::Context &context) : TestCaseGroup(context, "packed_pixels", "")
4135 {
4136 }
4137 
~PackedPixelsTests(void)4138 PackedPixelsTests::~PackedPixelsTests(void)
4139 {
4140 #ifdef LOG_PACKED_PIXELS_STATISTICS
4141     m_testCtx.getLog() << tcu::TestLog::Message << "PackedPixelsTests statistics:"
4142                        << "\n  countReadPixels: " << RectangleTest::m_countReadPixels
4143                        << "\n  countReadPixelsOK: " << RectangleTest::m_countReadPixelsOK
4144                        << "\n  countGetTexImage: " << RectangleTest::m_countGetTexImage
4145                        << "\n  countGetTexImageOK: " << RectangleTest::m_countGetTexImageOK
4146                        << "\n  countCompare: " << RectangleTest::m_countCompare
4147                        << "\n  countCompareOK: " << RectangleTest::m_countCompareOK << tcu::TestLog::EndMessage;
4148 #endif
4149 }
4150 
init(void)4151 void PackedPixelsTests::init(void)
4152 {
4153     const InternalFormat *internalFormats;
4154     unsigned int internalFormatsCount;
4155 
4156     if (glu::isContextTypeES(m_context.getRenderContext().getType()))
4157     {
4158         internalFormats      = esInternalformats;
4159         internalFormatsCount = DE_LENGTH_OF_ARRAY(esInternalformats);
4160     }
4161     else
4162     {
4163         internalFormats      = coreInternalformats;
4164         internalFormatsCount = DE_LENGTH_OF_ARRAY(coreInternalformats);
4165     }
4166 
4167     TestCaseGroup *rectangleGroup = new deqp::TestCaseGroup(m_context, "rectangle", "");
4168     rectangleGroup->addChild(new InitialValuesTest(m_context));
4169     TestCaseGroup *pboRectangleGroup    = new deqp::TestCaseGroup(m_context, "pbo_rectangle", "");
4170     TestCaseGroup *variedRectangleGroup = new deqp::TestCaseGroup(m_context, "varied_rectangle", "");
4171 
4172     for (unsigned int internalFormatIndex = 0; internalFormatIndex < internalFormatsCount; internalFormatIndex++)
4173     {
4174         const InternalFormat &internalFormat = internalFormats[internalFormatIndex];
4175         std::string internalFormatString     = getFormatStr(internalFormat.sizedFormat);
4176 
4177         std::string name = internalFormatString.substr(3);
4178         std::transform(name.begin(), name.end(), name.begin(), tolower);
4179 
4180         rectangleGroup->addChild(new RectangleTest(m_context, name, internalFormat));
4181         pboRectangleGroup->addChild(new PBORectangleTest(m_context, name, internalFormat));
4182         variedRectangleGroup->addChild(new VariedRectangleTest(m_context, name, internalFormat));
4183     }
4184 
4185     addChild(rectangleGroup);
4186     addChild(pboRectangleGroup);
4187     addChild(variedRectangleGroup);
4188 }
4189 
4190 } // namespace glcts
4191