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 InternalformatTests.cpp
21 * \brief
22 */ /*-------------------------------------------------------------------*/
23
24 #include "glcInternalformatTests.hpp"
25 #include "deMath.h"
26 #include "gluContextInfo.hpp"
27 #include "gluDefs.hpp"
28 #include "gluDrawUtil.hpp"
29 #include "gluPixelTransfer.hpp"
30 #include "gluShaderProgram.hpp"
31 #include "gluStrUtil.hpp"
32 #include "gluTexture.hpp"
33 #include "gluTextureUtil.hpp"
34 #include "glwEnums.hpp"
35 #include "glwFunctions.hpp"
36 #include "tcuImageCompare.hpp"
37 #include "tcuRenderTarget.hpp"
38 #include "tcuStringTemplate.hpp"
39 #include "tcuSurface.hpp"
40 #include "tcuTestLog.hpp"
41 #include "tcuTextureUtil.hpp"
42
43 #include "glcMisc.hpp"
44
45 #include <algorithm>
46 #include <functional>
47 #include <map>
48
49 using namespace glw;
50
51 namespace glcts
52 {
53
54 // all extension names required by the tests
55 static const char* EXT_texture_type_2_10_10_10_REV = "GL_EXT_texture_type_2_10_10_10_REV";
56 static const char* EXT_texture_shared_exponent = "GL_EXT_texture_shared_exponent";
57 static const char* EXT_texture_integer = "GL_EXT_texture_integer";
58 static const char* ARB_texture_rgb10_a2ui = "GL_ARB_texture_rgb10_a2ui";
59 static const char* ARB_depth_texture = "GL_ARB_depth_texture";
60 static const char* ARB_texture_float = "GL_ARB_texture_float";
61 static const char* OES_texture_float = "GL_OES_texture_float";
62 static const char* OES_texture_float_linear = "GL_OES_texture_float_linear";
63 static const char* OES_texture_half_float = "GL_OES_texture_half_float";
64 static const char* OES_texture_half_float_linear = "GL_OES_texture_half_float_linear";
65 static const char* OES_rgb8_rgba8 = "GL_OES_rgb8_rgba8";
66 static const char* OES_depth_texture = "GL_OES_depth_texture";
67 static const char* OES_depth24 = "GL_OES_depth24";
68 static const char* OES_depth32 = "GL_OES_depth32";
69 static const char* OES_packed_depth_stencil = "GL_OES_packed_depth_stencil";
70 static const char* OES_stencil1 = "GL_OES_stencil1";
71 static const char* OES_stencil4 = "GL_OES_stencil4";
72 static const char* OES_stencil8 = "GL_OES_stencil8";
73 static const char* OES_required_internalformat = "GL_OES_required_internalformat";
74
75 struct TextureFormat
76 {
77 GLenum format;
78 GLenum type;
79 GLint internalFormat;
80 const char* requiredExtension;
81 const char* secondReqiredExtension;
82 GLint minFilter;
83 GLint magFilter;
84
TextureFormatglcts::TextureFormat85 TextureFormat()
86 {
87 }
88
TextureFormatglcts::TextureFormat89 TextureFormat(GLenum aFormat, GLenum aType, GLint aInternalFormat, const char* aRequiredExtension = DE_NULL,
90 const char* aSecondReqiredExtension = DE_NULL, GLint aMinFilter = GL_NEAREST,
91 GLint aMagFilter = GL_NEAREST)
92 : format(aFormat)
93 , type(aType)
94 , internalFormat(aInternalFormat)
95 , requiredExtension(aRequiredExtension)
96 , secondReqiredExtension(aSecondReqiredExtension)
97 , minFilter(aMinFilter)
98 , magFilter(aMagFilter)
99 {
100 }
101 };
102
103 struct CopyTexImageFormat
104 {
105 GLint internalFormat;
106 const char* requiredExtension;
107 const char* secondReqiredExtension;
108 GLint minFilter;
109 GLint magFilter;
110
CopyTexImageFormatglcts::CopyTexImageFormat111 CopyTexImageFormat(GLenum aInternalFormat, const char* aRequiredExtension = DE_NULL,
112 const char* aSecondReqiredExtension = DE_NULL, GLint aMinFilter = GL_NEAREST,
113 GLint aMagFilter = GL_NEAREST)
114 : internalFormat(aInternalFormat)
115 , requiredExtension(aRequiredExtension)
116 , secondReqiredExtension(aSecondReqiredExtension)
117 , minFilter(aMinFilter)
118 , magFilter(aMagFilter)
119 {
120 }
121 };
122
123 enum RenderBufferType
124 {
125 RENDERBUFFER_COLOR,
126 RENDERBUFFER_STENCIL,
127 RENDERBUFFER_DEPTH,
128 RENDERBUFFER_DEPTH_STENCIL
129 };
130
131 struct RenderbufferFormat
132 {
133 GLenum format;
134 RenderBufferType type;
135 const char* requiredExtension;
136 const char* secondReqiredExtension;
137
RenderbufferFormatglcts::RenderbufferFormat138 RenderbufferFormat(GLenum aFormat, RenderBufferType aType, const char* aRequiredExtension = DE_NULL,
139 const char* aSecondReqiredExtension = DE_NULL)
140 : format(aFormat)
141 , type(aType)
142 , requiredExtension(aRequiredExtension)
143 , secondReqiredExtension(aSecondReqiredExtension)
144 {
145 }
146 };
147
148 class InternalformatCaseBase : public deqp::TestCase
149 {
150 public:
151 InternalformatCaseBase(deqp::Context& context, const std::string& name);
~InternalformatCaseBase()152 virtual ~InternalformatCaseBase()
153 {
154 }
155
156 protected:
157 bool requiredExtensionsSupported(const char* extension1, const char* extension2);
158 GLuint createTexture(GLint internalFormat, GLenum format, GLenum type, GLint minFilter, GLint magFilter,
159 bool generateData = true) const;
160 glu::ProgramSources prepareTexturingProgramSources(GLint internalFormat, GLenum format, GLenum type) const;
161 void renderTexturedQuad(GLuint programId) const;
162 GLenum getUnsizedFormatFromInternalFormat(GLint internalFormat) const;
163 GLenum getTypeFromInternalFormat(GLint internalFormat) const;
164
165 private:
166 void generateTextureData(GLuint width, GLuint height, GLenum type, unsigned int pixelSize, unsigned int components,
167 bool isSRGB, std::vector<unsigned char>& result) const;
168
169 // color converting methods
170 static void convertByte(tcu::Vec4 inColor, unsigned char* dst, int components);
171 static void convertUByte(tcu::Vec4 inColor, unsigned char* dst, int components);
172 static void convertHFloat(tcu::Vec4 inColor, unsigned char* dst, int components);
173 static void convertFloat(tcu::Vec4 inColor, unsigned char* dst, int components);
174 static void convertShort(tcu::Vec4 inColor, unsigned char* dst, int components);
175 static void convertUShort(tcu::Vec4 inColor, unsigned char* dst, int components);
176 static void convertInt(tcu::Vec4 inColor, unsigned char* dst, int components);
177 static void convertUInt(tcu::Vec4 inColor, unsigned char* dst, int components);
178 static void convertUInt_24_8(tcu::Vec4 inColor, unsigned char* dst, int components);
179 static void convertFloat_32_Uint_24_8(tcu::Vec4 inColor, unsigned char* dst, int);
180 static void convertUShort_4_4_4_4(tcu::Vec4 inColor, unsigned char* dst, int);
181 static void convertUShort_5_5_5_1(tcu::Vec4 inColor, unsigned char* dst, int);
182 static void convertUShort_5_6_5(tcu::Vec4 inColor, unsigned char* dst, int);
183 static void convertUInt_2_10_10_10_rev(tcu::Vec4 inColor, unsigned char* dst, int);
184 static void convertUInt_10f_11f_11f_rev(tcu::Vec4 inColor, unsigned char* dst, int);
185 static void convertUint_5_9_9_9_rev(tcu::Vec4 inColor, unsigned char* dst, int);
186
187 static GLhalf floatToHalf(float f);
188
189 protected:
190 GLsizei m_renderWidth;
191 GLsizei m_renderHeight;
192 };
193
InternalformatCaseBase(deqp::Context & context,const std::string & name)194 InternalformatCaseBase::InternalformatCaseBase(deqp::Context& context, const std::string& name)
195 : deqp::TestCase(context, name.c_str(), ""), m_renderWidth(64), m_renderHeight(64)
196 {
197 }
198
requiredExtensionsSupported(const char * extension1,const char * extension2)199 bool InternalformatCaseBase::requiredExtensionsSupported(const char* extension1, const char* extension2)
200 {
201 const glu::ContextInfo& contextInfo = m_context.getContextInfo();
202 if (extension1)
203 {
204 if (extension2)
205 {
206 if (!contextInfo.isExtensionSupported(extension1) || !contextInfo.isExtensionSupported(extension2))
207 {
208 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "One of required extensions is not supported");
209 return false;
210 }
211 }
212 else if (!contextInfo.isExtensionSupported(extension1))
213 {
214 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Required extension is not supported");
215 return false;
216 }
217 }
218 return true;
219 }
220
createTexture(GLint internalFormat,GLenum format,GLenum type,GLint minFilter,GLint magFilter,bool generateData) const221 GLuint InternalformatCaseBase::createTexture(GLint internalFormat, GLenum format, GLenum type, GLint minFilter,
222 GLint magFilter, bool generateData) const
223 {
224 const Functions& gl = m_context.getRenderContext().getFunctions();
225 GLuint textureName;
226 std::vector<unsigned char> textureData;
227 GLvoid* textureDataPtr = DE_NULL;
228
229 if (generateData)
230 {
231 tcu::TextureFormat tcuTextureFormat = glu::mapGLTransferFormat(format, type);
232 unsigned int components = tcu::getNumUsedChannels(tcuTextureFormat.order);
233 unsigned int pixelSize = 4;
234 bool isSRGB = internalFormat == GL_SRGB8 || internalFormat == GL_SRGB8_ALPHA8;
235
236 // note: getPixelSize hits assertion for GL_UNSIGNED_INT_2_10_10_10_REV when format is RGB
237 if (type != GL_UNSIGNED_INT_2_10_10_10_REV)
238 pixelSize = tcu::getPixelSize(tcuTextureFormat);
239
240 generateTextureData(m_renderWidth, m_renderHeight, type, pixelSize, components, isSRGB, textureData);
241
242 textureDataPtr = &textureData[0];
243 }
244
245 gl.genTextures(1, &textureName);
246 gl.bindTexture(GL_TEXTURE_2D, textureName);
247 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture");
248
249 gl.texImage2D(GL_TEXTURE_2D, 0, internalFormat, m_renderWidth, m_renderHeight, 0, format, type, textureDataPtr);
250 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D");
251
252 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
253 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
254 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
255 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri");
256 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
257 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri");
258
259 return textureName;
260 }
261
prepareTexturingProgramSources(GLint internalFormat,GLenum format,GLenum type) const262 glu::ProgramSources InternalformatCaseBase::prepareTexturingProgramSources(GLint internalFormat, GLenum format,
263 GLenum type) const
264 {
265 glu::RenderContext& renderContext = m_context.getRenderContext();
266 glu::ContextType contextType = renderContext.getType();
267 glu::GLSLVersion glslVersion = glu::getContextTypeGLSLVersion(contextType);
268
269 std::string vs;
270 std::string fs;
271
272 std::map<std::string, std::string> specializationMap;
273 specializationMap["VERSION"] = glu::getGLSLVersionDeclaration(glslVersion);
274
275 if (glu::contextSupports(contextType, glu::ApiType::es(3, 0)) || glu::isContextTypeGLCore(contextType))
276 {
277 vs = "${VERSION}\n"
278 "precision highp float;\n"
279 "in vec2 position;\n"
280 "in vec2 inTexcoord;\n"
281 "out vec2 texcoord;\n"
282 "void main()\n"
283 "{\n"
284 " texcoord = inTexcoord;\n"
285 " gl_Position = vec4(position, 0.0, 1.0);\n"
286 "}\n";
287 fs = "${VERSION}\n"
288 "precision highp float;\n"
289 "precision highp int;\n"
290 "uniform highp ${SAMPLER} sampler;\n"
291 "in vec2 texcoord;\n"
292 "out highp vec4 color;\n"
293 "void main()\n"
294 "{\n"
295 " ${SAMPLED_TYPE} v = texture(sampler, texcoord);\n"
296 " color = ${CALCULATE_COLOR};\n"
297 " ${PROCESS_COLOR}\n"
298 "}\n";
299
300 specializationMap["PROCESS_COLOR"] = "";
301 if ((format == GL_RED_INTEGER) || (format == GL_RG_INTEGER) || (format == GL_RGB_INTEGER) ||
302 (format == GL_RGBA_INTEGER))
303 {
304 specializationMap["SAMPLED_TYPE"] = "uvec4";
305 specializationMap["SAMPLER"] = "usampler2D";
306 if (type == GL_BYTE)
307 {
308 specializationMap["SAMPLED_TYPE"] = "ivec4";
309 specializationMap["SAMPLER"] = "isampler2D";
310 specializationMap["CALCULATE_COLOR"] = "vec4(v) / 127.0";
311 }
312 else if (type == GL_UNSIGNED_BYTE)
313 {
314 specializationMap["CALCULATE_COLOR"] = "vec4(v) / 255.0";
315 }
316 else if (type == GL_SHORT)
317 {
318 specializationMap["SAMPLED_TYPE"] = "ivec4";
319 specializationMap["SAMPLER"] = "isampler2D";
320 specializationMap["CALCULATE_COLOR"] = "vec4(v / 128) / 256.0";
321 }
322 else if (type == GL_UNSIGNED_SHORT)
323 {
324 specializationMap["CALCULATE_COLOR"] = "vec4(v / 256u) / 256.0";
325 }
326 else if (type == GL_INT)
327 {
328 specializationMap["SAMPLED_TYPE"] = "ivec4";
329 specializationMap["SAMPLER"] = "isampler2D";
330 specializationMap["CALCULATE_COLOR"] = "vec4(uvec4(v) / 2097152u) / 1024.0";
331 }
332 else // GL_UNSIGNED_INT
333 {
334 if (internalFormat == GL_RGB10_A2UI)
335 specializationMap["CALCULATE_COLOR"] = "vec4(vec3(v.rgb) / 1023.0, float(v.a) / 3.0)";
336 else
337 specializationMap["CALCULATE_COLOR"] = "vec4(v / 4194304u) / 1024.0";
338 }
339
340 if (format == GL_RED_INTEGER)
341 specializationMap["PROCESS_COLOR"] = "color = vec4(color.r, 0.0, 0.0, 1.0);\n";
342 else if (format == GL_RG_INTEGER)
343 specializationMap["PROCESS_COLOR"] = "color = vec4(color.r, color.g, 0.0, 1.0);\n";
344 else if (format == GL_RGB_INTEGER)
345 specializationMap["PROCESS_COLOR"] = "color.a = 1.0;\n";
346 }
347 else
348 {
349 specializationMap["SAMPLED_TYPE"] = "vec4";
350 specializationMap["SAMPLER"] = "sampler2D";
351 if (format == GL_DEPTH_STENCIL || format == GL_DEPTH_COMPONENT)
352 specializationMap["CALCULATE_COLOR"] = "vec4(v.r, 0.0, 0.0, 1.0)";
353 else
354 specializationMap["CALCULATE_COLOR"] = "v";
355 }
356 }
357 else
358 {
359 vs = "${VERSION}\n"
360 "attribute highp vec2 position;\n"
361 "attribute highp vec2 inTexcoord;\n"
362 "varying highp vec2 texcoord;\n"
363 "void main()\n"
364 "{\n"
365 " texcoord = inTexcoord;\n"
366 " gl_Position = vec4(position, 0.0, 1.0);\n"
367 "}\n";
368 fs = "${VERSION}\n"
369 "uniform highp sampler2D sampler;\n"
370 "varying highp vec2 texcoord;\n"
371 "void main()\n"
372 "{\n"
373 " highp vec4 color = texture2D(sampler, texcoord);\n"
374 " gl_FragColor = ${CALCULATE_COLOR};\n"
375 "}\n";
376
377 if ((internalFormat == GL_DEPTH_COMPONENT) || (internalFormat == GL_DEPTH_STENCIL))
378 specializationMap["CALCULATE_COLOR"] = "vec4(color.r, 0.0, 0.0, 1.0)";
379 else if (internalFormat == GL_DEPTH_COMPONENT32F)
380 specializationMap["CALCULATE_COLOR"] = "vec4(color.r, color.r, color.r, 1.0)";
381 else
382 specializationMap["CALCULATE_COLOR"] = "color";
383 }
384
385 vs = tcu::StringTemplate(vs).specialize(specializationMap);
386 fs = tcu::StringTemplate(fs).specialize(specializationMap);
387 return glu::makeVtxFragSources(vs.c_str(), fs.c_str());
388 }
389
renderTexturedQuad(GLuint programId) const390 void InternalformatCaseBase::renderTexturedQuad(GLuint programId) const
391 {
392 // Prepare data for rendering
393 static const deUint16 quadIndices[] = { 0, 1, 2, 2, 1, 3 };
394 static const float position[] = { -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f };
395 static const float texCoord[] = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f };
396 static const glu::VertexArrayBinding vertexArrays[] = { glu::va::Float("position", 2, 4, 0, position),
397 glu::va::Float("inTexcoord", 2, 4, 0, texCoord) };
398
399 glu::draw(m_context.getRenderContext(), programId, DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays,
400 glu::pr::TriangleStrip(DE_LENGTH_OF_ARRAY(quadIndices), quadIndices));
401 }
402
getUnsizedFormatFromInternalFormat(GLint internalFormat) const403 GLenum InternalformatCaseBase::getUnsizedFormatFromInternalFormat(GLint internalFormat) const
404 {
405 switch (internalFormat)
406 {
407 case GL_RGBA:
408 case GL_RGBA4:
409 case GL_RGB5_A1:
410 case GL_RGBA8:
411 case GL_RGB10_A2:
412 case GL_RGBA8_SNORM:
413 case GL_SRGB8_ALPHA8:
414 return GL_RGBA;
415 case GL_RGB10_A2UI:
416 case GL_RGBA8UI: //remove this
417 return GL_RGBA_INTEGER;
418 case GL_RGB:
419 case GL_RGB565:
420 case GL_RGB8:
421 case GL_RGB10:
422 case GL_RGB9_E5:
423 case GL_R11F_G11F_B10F:
424 case GL_SRGB8:
425 return GL_RGB;
426 case GL_LUMINANCE_ALPHA:
427 case GL_LUMINANCE4_ALPHA4_OES:
428 case GL_LUMINANCE8_ALPHA8_OES:
429 return GL_LUMINANCE_ALPHA;
430 case GL_LUMINANCE:
431 case GL_LUMINANCE8_OES:
432 return GL_LUMINANCE;
433 case GL_ALPHA:
434 case GL_ALPHA8_OES:
435 return GL_ALPHA;
436 case GL_DEPTH_COMPONENT16:
437 case GL_DEPTH_COMPONENT24:
438 case GL_DEPTH_COMPONENT32:
439 case GL_DEPTH_COMPONENT32F:
440 return GL_DEPTH_COMPONENT;
441 case GL_DEPTH24_STENCIL8:
442 case GL_DEPTH32F_STENCIL8:
443 return GL_DEPTH_STENCIL;
444 case GL_STENCIL_INDEX8:
445 return GL_STENCIL_INDEX;
446 default:
447 TCU_FAIL("Unrecognized internal format");
448 }
449 return GL_NONE;
450 }
451
getTypeFromInternalFormat(GLint internalFormat) const452 GLenum InternalformatCaseBase::getTypeFromInternalFormat(GLint internalFormat) const
453 {
454 switch (internalFormat)
455 {
456 case GL_RGB10:
457 case GL_RGB10_A2:
458 case GL_RGB10_A2UI:
459 return GL_UNSIGNED_INT_2_10_10_10_REV;
460 case GL_R11F_G11F_B10F:
461 return GL_UNSIGNED_INT_10F_11F_11F_REV;
462 case GL_DEPTH_COMPONENT16:
463 case GL_DEPTH_COMPONENT24:
464 return GL_UNSIGNED_SHORT;
465 case GL_DEPTH_COMPONENT32:
466 return GL_UNSIGNED_INT;
467 case GL_DEPTH_COMPONENT32F:
468 return GL_FLOAT;
469 case GL_DEPTH32F_STENCIL8:
470 return GL_FLOAT_32_UNSIGNED_INT_24_8_REV;
471 }
472
473 return GL_UNSIGNED_BYTE;
474 }
475
generateTextureData(GLuint width,GLuint height,GLenum type,unsigned int pixelSize,unsigned int components,bool isSRGB,std::vector<unsigned char> & result) const476 void InternalformatCaseBase::generateTextureData(GLuint width, GLuint height, GLenum type, unsigned int pixelSize,
477 unsigned int components, bool isSRGB,
478 std::vector<unsigned char>& result) const
479 {
480 // colors are the 4 corner colors specified ( lower left, lower right, upper left, upper right )
481 static tcu::Vec4 colors[4] = { tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f),
482 tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), tcu::Vec4(0.0f, 1.0f, 1.0f, 1.0f) };
483
484 typedef std::function<void(tcu::Vec4, unsigned char*, int)> ColorConversionFunc;
485 typedef std::map<GLenum, ColorConversionFunc> ColorConversionMap;
486 using namespace std::placeholders;
487
488 static ColorConversionMap colorConversionMap;
489 if (colorConversionMap.empty())
490 {
491 colorConversionMap[GL_BYTE] = &convertByte;
492 colorConversionMap[GL_UNSIGNED_BYTE] = &convertUByte;
493 colorConversionMap[GL_HALF_FLOAT] = &convertHFloat;
494 colorConversionMap[GL_HALF_FLOAT_OES] = &convertHFloat;
495 colorConversionMap[GL_FLOAT] = &convertFloat;
496 colorConversionMap[GL_SHORT] = &convertShort;
497 colorConversionMap[GL_UNSIGNED_SHORT] = &convertUShort;
498 colorConversionMap[GL_INT] = &convertInt;
499 colorConversionMap[GL_UNSIGNED_INT] = &convertUInt;
500 colorConversionMap[GL_UNSIGNED_INT_24_8] = &convertUInt_24_8;
501 colorConversionMap[GL_FLOAT_32_UNSIGNED_INT_24_8_REV] = &convertFloat_32_Uint_24_8;
502 colorConversionMap[GL_UNSIGNED_SHORT_4_4_4_4] = &convertUShort_4_4_4_4;
503 colorConversionMap[GL_UNSIGNED_SHORT_5_5_5_1] = &convertUShort_5_5_5_1;
504 colorConversionMap[GL_UNSIGNED_SHORT_5_6_5] = &convertUShort_5_6_5;
505 colorConversionMap[GL_UNSIGNED_INT_2_10_10_10_REV] = &convertUInt_2_10_10_10_rev;
506 colorConversionMap[GL_UNSIGNED_INT_10F_11F_11F_REV] = &convertUInt_10f_11f_11f_rev;
507 colorConversionMap[GL_UNSIGNED_INT_5_9_9_9_REV] = &convertUint_5_9_9_9_rev;
508 }
509
510 ColorConversionFunc convertColor = colorConversionMap.at(type);
511 if (isSRGB)
512 convertColor = std::bind(convertColor, std::bind(tcu::linearToSRGB, _1), _2, _3);
513
514 float lwidth = static_cast<float>(width - 1);
515 float lheight = static_cast<float>(height - 1);
516
517 result.resize(width * height * pixelSize);
518 unsigned char* dataPtr = &result[0];
519
520 for (GLuint y = 0; y < height; ++y)
521 {
522 for (GLuint x = 0; x < width; ++x)
523 {
524 float posX = (lwidth - static_cast<float>(x)) / lwidth;
525 float posY = (lheight - static_cast<float>(y)) / lheight;
526 float rposX = 1.f - posX;
527 float rposY = 1.f - posY;
528 tcu::Vec4 c = colors[0] * (posX * posY) + colors[1] * (rposX * posY) + colors[2] * (posX * rposY);
529
530 // Hard-code the alpha as small floating point instability results in large differences for some formats
531 c[3] = 1.f;
532 convertColor(c, dataPtr, static_cast<int>(components));
533 dataPtr += pixelSize;
534 }
535 }
536 }
537
convertByte(tcu::Vec4 inColor,unsigned char * dst,int components)538 void InternalformatCaseBase::convertByte(tcu::Vec4 inColor, unsigned char* dst, int components)
539 {
540 char* dstChar = reinterpret_cast<char*>(dst);
541 for (int i = 0; i < components; ++i)
542 dstChar[i] = static_cast<char>(inColor[i] * 127.0f);
543 }
544
convertUByte(tcu::Vec4 inColor,unsigned char * dst,int components)545 void InternalformatCaseBase::convertUByte(tcu::Vec4 inColor, unsigned char* dst, int components)
546 {
547 for (int i = 0; i < components; ++i)
548 dst[i] = static_cast<unsigned char>(inColor[i] * 255.f);
549 }
550
convertHFloat(tcu::Vec4 inColor,unsigned char * dst,int components)551 void InternalformatCaseBase::convertHFloat(tcu::Vec4 inColor, unsigned char* dst, int components)
552 {
553 GLhalf* dstHalf = reinterpret_cast<GLhalf*>(dst);
554 for (int i = 0; i < components; ++i)
555 dstHalf[i] = floatToHalf(inColor[i]);
556 }
557
convertFloat(tcu::Vec4 inColor,unsigned char * dst,int components)558 void InternalformatCaseBase::convertFloat(tcu::Vec4 inColor, unsigned char* dst, int components)
559 {
560 float* dstFloat = reinterpret_cast<float*>(dst);
561 for (int i = 0; i < components; ++i)
562 dstFloat[i] = inColor[i];
563 }
564
convertShort(tcu::Vec4 inColor,unsigned char * dst,int components)565 void InternalformatCaseBase::convertShort(tcu::Vec4 inColor, unsigned char* dst, int components)
566 {
567 short* dstUShort = reinterpret_cast<short*>(dst);
568 for (int i = 0; i < components; ++i)
569 {
570 double c = static_cast<double>(inColor[i]);
571 dstUShort[i] = static_cast<short>(c * 32768 - 1);
572 }
573 }
574
convertUShort(tcu::Vec4 inColor,unsigned char * dst,int components)575 void InternalformatCaseBase::convertUShort(tcu::Vec4 inColor, unsigned char* dst, int components)
576 {
577 unsigned short* dstUShort = reinterpret_cast<unsigned short*>(dst);
578 for (int i = 0; i < components; ++i)
579 {
580 double c = static_cast<double>(inColor[i]);
581 dstUShort[i] = static_cast<unsigned short>(c * 65535u);
582 }
583 }
584
convertInt(tcu::Vec4 inColor,unsigned char * dst,int components)585 void InternalformatCaseBase::convertInt(tcu::Vec4 inColor, unsigned char* dst, int components)
586 {
587 int* dstUInt = reinterpret_cast<int*>(dst);
588 for (int i = 0; i < components; ++i)
589 dstUInt[i] = static_cast<int>(inColor[i] * 2147483648u - 1);
590 }
591
convertUInt(tcu::Vec4 inColor,unsigned char * dst,int components)592 void InternalformatCaseBase::convertUInt(tcu::Vec4 inColor, unsigned char* dst, int components)
593 {
594 unsigned int* dstUInt = reinterpret_cast<unsigned int*>(dst);
595 for (int i = 0; i < components; ++i)
596 {
597 double c = static_cast<double>(inColor[i]);
598 dstUInt[i] = static_cast<unsigned int>(c * 4294967295u);
599 }
600 }
601
convertUInt_24_8(tcu::Vec4 inColor,unsigned char * dst,int)602 void InternalformatCaseBase::convertUInt_24_8(tcu::Vec4 inColor, unsigned char* dst, int)
603 {
604 unsigned int* dstUint = reinterpret_cast<unsigned int*>(dst);
605
606 unsigned int d = static_cast<unsigned int>(inColor[0] * 16777215u) << 8;
607 unsigned int s = static_cast<unsigned int>(inColor[1] * 255u);
608
609 dstUint[0] = (d & 0xFFFFFF00) | (s & 0xFF);
610 }
611
convertFloat_32_Uint_24_8(tcu::Vec4 inColor,unsigned char * dst,int)612 void InternalformatCaseBase::convertFloat_32_Uint_24_8(tcu::Vec4 inColor, unsigned char* dst, int)
613 {
614 float* dstFloat = reinterpret_cast<float*>(dst);
615 unsigned int* dstUint = reinterpret_cast<unsigned int*>(dst);
616
617 dstFloat[0] = inColor[0];
618 dstUint[1] = static_cast<unsigned int>(inColor[1] * 255u) & 0xFF;
619 }
620
convertUShort_4_4_4_4(tcu::Vec4 inColor,unsigned char * dst,int)621 void InternalformatCaseBase::convertUShort_4_4_4_4(tcu::Vec4 inColor, unsigned char* dst, int)
622 {
623 unsigned short* dstUShort = reinterpret_cast<unsigned short*>(dst);
624
625 unsigned int r = static_cast<unsigned int>(inColor[0] * 15) << 12;
626 unsigned int g = static_cast<unsigned int>(inColor[1] * 15) << 8;
627 unsigned int b = static_cast<unsigned int>(inColor[2] * 15) << 4;
628 unsigned int a = static_cast<unsigned int>(inColor[3] * 15) << 0;
629
630 dstUShort[0] = (r & 0xF000) | (g & 0x0F00) | (b & 0x00F0) | (a & 0x000F);
631 }
632
convertUShort_5_5_5_1(tcu::Vec4 inColor,unsigned char * dst,int)633 void InternalformatCaseBase::convertUShort_5_5_5_1(tcu::Vec4 inColor, unsigned char* dst, int)
634 {
635 unsigned short* dstUShort = reinterpret_cast<unsigned short*>(dst);
636
637 unsigned int r = static_cast<unsigned int>(inColor[0] * 31) << 11;
638 unsigned int g = static_cast<unsigned int>(inColor[1] * 31) << 6;
639 unsigned int b = static_cast<unsigned int>(inColor[2] * 31) << 1;
640 unsigned int a = static_cast<unsigned int>(inColor[3] * 1) << 0;
641
642 dstUShort[0] = (r & 0xF800) | (g & 0x07c0) | (b & 0x003e) | (a & 0x0001);
643 }
644
convertUShort_5_6_5(tcu::Vec4 inColor,unsigned char * dst,int)645 void InternalformatCaseBase::convertUShort_5_6_5(tcu::Vec4 inColor, unsigned char* dst, int)
646 {
647 unsigned short* dstUShort = reinterpret_cast<unsigned short*>(dst);
648
649 unsigned int r = static_cast<unsigned int>(inColor[0] * 31) << 11;
650 unsigned int g = static_cast<unsigned int>(inColor[1] * 63) << 5;
651 unsigned int b = static_cast<unsigned int>(inColor[2] * 31) << 0;
652
653 dstUShort[0] = (r & 0xF800) | (g & 0x07e0) | (b & 0x001f);
654 }
655
convertUInt_2_10_10_10_rev(tcu::Vec4 inColor,unsigned char * dst,int)656 void InternalformatCaseBase::convertUInt_2_10_10_10_rev(tcu::Vec4 inColor, unsigned char* dst, int)
657 {
658 unsigned int* dstUint = reinterpret_cast<unsigned int*>(dst);
659
660 // Alpha value is rounded to eliminate small precision errors that
661 // may result in big errors after converting value to just 4 bits
662 unsigned int a = static_cast<unsigned int>(deFloatRound(inColor[3] * 3)) << 30;
663 unsigned int b = static_cast<unsigned int>(inColor[2] * 1023) << 20;
664 unsigned int g = static_cast<unsigned int>(inColor[1] * 1023) << 10;
665 unsigned int r = static_cast<unsigned int>(inColor[0] * 1023) << 0;
666
667 dstUint[0] = (a & 0xC0000000) | (b & 0x3FF00000) | (g & 0x000FFC00) | (r & 0x000003FF);
668 }
669
convertUInt_10f_11f_11f_rev(tcu::Vec4 inColor,unsigned char * dst,int)670 void InternalformatCaseBase::convertUInt_10f_11f_11f_rev(tcu::Vec4 inColor, unsigned char* dst, int)
671 {
672 unsigned int* dstUint = reinterpret_cast<unsigned int*>(dst);
673
674 unsigned int b = floatToUnisgnedF10(inColor[2]);
675 unsigned int g = floatToUnisgnedF11(inColor[1]);
676 unsigned int r = floatToUnisgnedF11(inColor[0]);
677
678 dstUint[0] = (b << 22) | (g << 11) | r;
679 }
680
convertUint_5_9_9_9_rev(tcu::Vec4 inColor,unsigned char * dst,int)681 void InternalformatCaseBase::convertUint_5_9_9_9_rev(tcu::Vec4 inColor, unsigned char* dst, int)
682 {
683 unsigned int* dstUint = reinterpret_cast<unsigned int*>(dst);
684
685 const int N = 9;
686 const int B = 15;
687 const int E_max = 31;
688
689 GLfloat red = inColor[0];
690 GLfloat green = inColor[1];
691 GLfloat blue = inColor[2];
692
693 GLfloat sharedExpMax =
694 (deFloatPow(2.0f, (float)N) - 1.0f) / deFloatPow(2.0f, (float)N) * deFloatPow(2.0f, (float)(E_max - B));
695
696 GLfloat red_c = deFloatMax(0, deFloatMin(sharedExpMax, red));
697 GLfloat green_c = deFloatMax(0, deFloatMin(sharedExpMax, green));
698 GLfloat blue_c = deFloatMax(0, deFloatMin(sharedExpMax, blue));
699
700 GLfloat max_c = deFloatMax(deFloatMax(red_c, green_c), blue_c);
701
702 GLfloat exp_p = deFloatMax(-B - 1, deFloatFloor(deFloatLog2(max_c))) + 1 + B;
703
704 GLfloat max_s = deFloatFloor(max_c / deFloatPow(2.0f, exp_p - (float)B - (float)N) + 0.5f);
705
706 GLfloat exp_s;
707
708 if (0 <= max_s && max_s < deFloatPow(2.0f, (float)N))
709 exp_s = exp_p;
710 else
711 exp_s = exp_p + 1;
712
713 GLfloat red_s = deFloatFloor(red_c / deFloatPow(2.0f, exp_s - (float)B - (float)N) + 0.5f);
714 GLfloat green_s = deFloatFloor(green_c / deFloatPow(2.0f, exp_s - (float)B - (float)N) + 0.5f);
715 GLfloat blue_s = deFloatFloor(blue_c / deFloatPow(2.0f, exp_s - (float)B - (float)N) + 0.5f);
716
717 GLuint c1 = (static_cast<GLuint>(red_s)) & 511;
718 GLuint c2 = (static_cast<GLuint>(green_s)) & 511;
719 GLuint c3 = (static_cast<GLuint>(blue_s)) & 511;
720 GLuint c4 = (static_cast<GLuint>(exp_s)) & 31;
721
722 dstUint[0] = (c1) | (c2 << 9) | (c3 << 18) | (c4 << 27);
723 }
724
floatToHalf(float f)725 GLhalf InternalformatCaseBase::floatToHalf(float f)
726 {
727 const unsigned int HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP = 0x38000000;
728 // Max exponent value in single precision that will be converted
729 // to Inf or Nan when stored as a half-float
730 const unsigned int HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_FP_EXP = 0x47800000;
731 // 255 is the max exponent biased value
732 const unsigned int FLOAT_MAX_BIASED_EXP = (0xFF << 23);
733 const unsigned int HALF_FLOAT_MAX_BIASED_EXP = (0x1F << 10);
734
735 char* c = reinterpret_cast<char*>(&f);
736 unsigned int x = *reinterpret_cast<unsigned int*>(c);
737 unsigned int sign = static_cast<GLhalf>(x >> 31);
738
739 // Get mantissa
740 unsigned int mantissa = x & ((1 << 23) - 1);
741 // Get exponent bits
742 unsigned int exp = x & FLOAT_MAX_BIASED_EXP;
743
744 if (exp >= HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_FP_EXP)
745 {
746 // Check if the original single precision float number is a NaN
747 if (mantissa && (exp == FLOAT_MAX_BIASED_EXP))
748 {
749 // We have a single precision NaN
750 mantissa = (1 << 23) - 1;
751 }
752 else
753 {
754 // 16-bit half-float representation stores number as Inf
755 mantissa = 0;
756 }
757 return (GLhalf)((((GLhalf)sign) << 15) | (GLhalf)(HALF_FLOAT_MAX_BIASED_EXP) | (GLhalf)(mantissa >> 13));
758 }
759 // Check if exponent is <= -15
760 else if (exp <= HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP)
761 {
762 // Store a denorm half-float value or zero
763 exp = (HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP - exp) >> 23;
764 mantissa |= (1 << 23);
765
766 if (exp < 18)
767 mantissa >>= (14 + exp);
768 else
769 mantissa = 0;
770
771 return (GLhalf)((((GLhalf)sign) << 15) | (GLhalf)(mantissa));
772 }
773
774 return (GLhalf)((((GLhalf)sign) << 15) | (GLhalf)((exp - HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP) >> 13) |
775 (GLhalf)(mantissa >> 13));
776 }
777
778 class Texture2DCase : public InternalformatCaseBase
779 {
780 public:
781 Texture2DCase(deqp::Context& context, const std::string& name, const TextureFormat& textureFormat);
~Texture2DCase()782 virtual ~Texture2DCase()
783 {
784 }
785
786 virtual tcu::TestNode::IterateResult iterate(void);
787
788 private:
789 TextureFormat m_testFormat;
790 };
791
Texture2DCase(deqp::Context & context,const std::string & name,const TextureFormat & testFormat)792 Texture2DCase::Texture2DCase(deqp::Context& context, const std::string& name, const TextureFormat& testFormat)
793 : InternalformatCaseBase(context, name.c_str()), m_testFormat(testFormat)
794 {
795 }
796
iterate(void)797 tcu::TestNode::IterateResult Texture2DCase::iterate(void)
798 {
799 if (!requiredExtensionsSupported(m_testFormat.requiredExtension, m_testFormat.secondReqiredExtension))
800 return STOP;
801
802 glu::RenderContext& renderContext = m_context.getRenderContext();
803 const Functions& gl = renderContext.getFunctions();
804
805 typedef std::map<GLenum, TextureFormat> ReferenceFormatMap;
806 static ReferenceFormatMap formatMap;
807 if (formatMap.empty())
808 {
809 formatMap[GL_RED] = TextureFormat(GL_RED, GL_UNSIGNED_BYTE, GL_RED);
810 formatMap[GL_RG] = TextureFormat(GL_RG, GL_UNSIGNED_BYTE, GL_RG);
811 formatMap[GL_RGB] = TextureFormat(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB);
812 formatMap[GL_RGBA] = TextureFormat(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB);
813 formatMap[GL_RGBA_INTEGER] = TextureFormat(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB);
814 formatMap[GL_RGB_INTEGER] = TextureFormat(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB);
815 formatMap[GL_ALPHA] = TextureFormat(GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA);
816 formatMap[GL_LUMINANCE] = TextureFormat(GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE);
817 formatMap[GL_LUMINANCE_ALPHA] = TextureFormat(GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE_ALPHA);
818 formatMap[GL_DEPTH_COMPONENT] = TextureFormat(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT);
819 formatMap[GL_DEPTH_STENCIL] = TextureFormat(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH_STENCIL);
820
821 if (glu::IsES3Compatible(gl))
822 {
823 formatMap[GL_RED] = TextureFormat(GL_RED, GL_UNSIGNED_BYTE, GL_R8);
824 formatMap[GL_RG] = TextureFormat(GL_RG, GL_UNSIGNED_BYTE, GL_RG8);
825 formatMap[GL_DEPTH_COMPONENT] =
826 TextureFormat(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT16);
827 formatMap[GL_DEPTH_STENCIL] =
828 TextureFormat(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8_OES);
829 formatMap[GL_RED_INTEGER] = TextureFormat(GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_R8UI);
830 formatMap[GL_RG_INTEGER] = TextureFormat(GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_RG8UI);
831 formatMap[GL_SRGB] = TextureFormat(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB);
832 formatMap[GL_SRGB_ALPHA] = TextureFormat(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB);
833 }
834 }
835
836 ReferenceFormatMap::iterator formatIterator = formatMap.find(m_testFormat.format);
837 if (formatIterator == formatMap.end())
838 {
839 m_testCtx.getLog() << tcu::TestLog::Message << "Error: Unknown 2D texture format "
840 << glu::getTextureFormatStr(m_testFormat.format).toString() << tcu::TestLog::EndMessage;
841 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
842 return STOP;
843 }
844
845 const TextureFormat& referenceFormat = formatIterator->second;
846
847 auto referenceInternalFormat = referenceFormat.internalFormat;
848 auto referenceType = referenceFormat.type;
849
850 // Above lookup only considers m_testFormat.format
851 if (m_testFormat.internalFormat == GL_DEPTH_COMPONENT32F)
852 {
853 referenceInternalFormat = GL_DEPTH_COMPONENT24;
854 referenceType = GL_UNSIGNED_INT;
855 }
856
857 if (m_renderWidth > m_context.getRenderTarget().getWidth())
858 m_renderWidth = m_context.getRenderTarget().getWidth();
859 if (m_renderHeight > m_context.getRenderTarget().getHeight())
860 m_renderHeight = m_context.getRenderTarget().getHeight();
861
862 // Setup viewport
863 gl.viewport(0, 0, m_renderWidth, m_renderHeight);
864 gl.pixelStorei(GL_UNPACK_ALIGNMENT, 1);
865
866 // Create test and reference texture
867 GLuint testTextureName = createTexture(m_testFormat.internalFormat, m_testFormat.format, m_testFormat.type,
868 m_testFormat.minFilter, m_testFormat.magFilter);
869 GLuint referenceTextureName = createTexture(referenceInternalFormat, referenceFormat.format, referenceType,
870 m_testFormat.minFilter, m_testFormat.magFilter);
871
872 // Create program that will render tested texture to screen
873 glu::ShaderProgram testProgram(
874 renderContext,
875 prepareTexturingProgramSources(m_testFormat.internalFormat, m_testFormat.format, m_testFormat.type));
876 if (!testProgram.isOk())
877 {
878 m_testCtx.getLog() << testProgram;
879 TCU_FAIL("Compile failed");
880 }
881 gl.useProgram(testProgram.getProgram());
882 gl.uniform1i(gl.getUniformLocation(testProgram.getProgram(), "sampler"), 0);
883
884 // Render textured quad with tested texture
885 gl.bindTexture(GL_TEXTURE_2D, testTextureName);
886 renderTexturedQuad(testProgram.getProgram());
887 tcu::Surface testSurface(m_renderWidth, m_renderHeight);
888 glu::readPixels(renderContext, 0, 0, testSurface.getAccess());
889
890 // Create program that will render reference texture to screen
891 glu::ProgramSources referenceSources =
892 prepareTexturingProgramSources(referenceInternalFormat, referenceFormat.format, referenceType);
893 glu::ShaderProgram referenceProgram(renderContext, referenceSources);
894 if (!referenceProgram.isOk())
895 {
896 m_testCtx.getLog() << referenceProgram;
897 TCU_FAIL("Compile failed");
898 }
899 gl.useProgram(referenceProgram.getProgram());
900 gl.uniform1i(gl.getUniformLocation(referenceProgram.getProgram(), "sampler"), 0);
901
902 // Render textured quad with reference texture
903 gl.bindTexture(GL_TEXTURE_2D, referenceTextureName);
904 renderTexturedQuad(referenceProgram.getProgram());
905 tcu::Surface referenceSurface(m_renderWidth, m_renderHeight);
906 glu::readPixels(renderContext, 0, 0, referenceSurface.getAccess());
907
908 // Compare surfaces
909 if (tcu::fuzzyCompare(m_testCtx.getLog(), "Result", "Image comparison result", referenceSurface, testSurface, 0.05f,
910 tcu::COMPARE_LOG_RESULT))
911 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
912 else
913 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
914
915 gl.deleteTextures(1, &testTextureName);
916 gl.deleteTextures(1, &referenceTextureName);
917
918 return STOP;
919 }
920
921 class CopyTexImageCase : public InternalformatCaseBase
922 {
923 public:
924 CopyTexImageCase(deqp::Context& context, const std::string& name, const CopyTexImageFormat& copyTexImageFormat);
~CopyTexImageCase()925 virtual ~CopyTexImageCase()
926 {
927 }
928
929 virtual tcu::TestNode::IterateResult iterate(void);
930
931 private:
932 CopyTexImageFormat m_testFormat;
933 };
934
CopyTexImageCase(deqp::Context & context,const std::string & name,const CopyTexImageFormat & copyTexImageFormat)935 CopyTexImageCase::CopyTexImageCase(deqp::Context& context, const std::string& name,
936 const CopyTexImageFormat& copyTexImageFormat)
937 : InternalformatCaseBase(context, name.c_str()), m_testFormat(copyTexImageFormat)
938 {
939 }
940
iterate(void)941 tcu::TestNode::IterateResult CopyTexImageCase::iterate(void)
942 {
943 if (!requiredExtensionsSupported(m_testFormat.requiredExtension, m_testFormat.secondReqiredExtension))
944 return STOP;
945
946 glu::RenderContext& renderContext = m_context.getRenderContext();
947 const Functions& gl = renderContext.getFunctions();
948
949 // Determine texture format and type
950 GLint textureInternalFormat = m_testFormat.internalFormat;
951 GLuint textureType = getTypeFromInternalFormat(textureInternalFormat);
952 GLuint textureFormat = getUnsizedFormatFromInternalFormat(textureInternalFormat);
953 const bool isSRGB = textureInternalFormat == GL_SRGB8 || textureInternalFormat == GL_SRGB8_ALPHA8;
954
955 // Create program that will render texture to screen
956 glu::ShaderProgram program(renderContext,
957 prepareTexturingProgramSources(textureInternalFormat, textureFormat, textureType));
958 if (!program.isOk())
959 {
960 m_testCtx.getLog() << program;
961 TCU_FAIL("Compile failed");
962 }
963 gl.useProgram(program.getProgram());
964 gl.uniform1i(gl.getUniformLocation(program.getProgram(), "sampler"), 0);
965 gl.viewport(0, 0, m_renderWidth, m_renderHeight);
966
967 // Create required textures
968 GLuint referenceTextureId = createTexture(textureInternalFormat, textureFormat, textureType, m_testFormat.minFilter,
969 m_testFormat.magFilter);
970 GLuint copiedTextureId = createTexture(textureInternalFormat, textureFormat, textureType, m_testFormat.minFilter,
971 m_testFormat.magFilter, false);
972
973 // Create main RGBA framebuffer - this is needed because some default framebuffer may be RGB
974 GLuint mainFboId = 0;
975 gl.genFramebuffers(1, &mainFboId);
976 gl.bindFramebuffer(GL_FRAMEBUFFER, mainFboId);
977 GLuint mainFboColorTextureId =
978 createTexture(isSRGB ? GL_SRGB8_ALPHA8 : GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, GL_NEAREST, false);
979 gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mainFboColorTextureId, 0);
980
981 // Render reference texture to main FBO and grab it
982 gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
983 gl.bindTexture(GL_TEXTURE_2D, referenceTextureId);
984 renderTexturedQuad(program.getProgram());
985 tcu::Surface referenceSurface(m_renderWidth, m_renderHeight);
986 glu::readPixels(renderContext, 0, 0, referenceSurface.getAccess());
987
988 GLuint copyFboId = 0;
989 GLuint copyFboColorTextureId = 0;
990
991 // When possible use separate FBO for copy operation; create copy FBO and
992 // attach reference texture to color or depth attachment
993 gl.genFramebuffers(1, ©FboId);
994 gl.bindFramebuffer(GL_FRAMEBUFFER, copyFboId);
995
996 if (textureFormat == GL_DEPTH_COMPONENT)
997 {
998 copyFboColorTextureId = createTexture(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, GL_NEAREST, GL_NEAREST, false);
999 gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, copyFboColorTextureId, 0);
1000 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture2D");
1001 gl.framebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, referenceTextureId, 0);
1002 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture2D");
1003 }
1004 else
1005 {
1006 gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, referenceTextureId, 0);
1007 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture2D");
1008 }
1009
1010 // If FBO is complete, then go back to use default FBO
1011 GLenum bufferStatus = gl.checkFramebufferStatus(GL_FRAMEBUFFER);
1012 if (bufferStatus != GL_FRAMEBUFFER_COMPLETE)
1013 {
1014 // Bind back to main FBO
1015 gl.bindFramebuffer(GL_FRAMEBUFFER, mainFboId);
1016 gl.deleteFramebuffers(1, ©FboId);
1017 if (copyFboColorTextureId)
1018 gl.deleteTextures(1, ©FboColorTextureId);
1019 // Check the bits of each channel first, because according the GLES3.2 spec, the component sizes of internalformat
1020 // must exactly match the corresponding component sizes of the source buffer's effective internal format.
1021 if (glu::isContextTypeES(renderContext.getType()) && getTypeFromInternalFormat(textureInternalFormat) != GL_UNSIGNED_BYTE)
1022 {
1023 m_testCtx.getLog() << tcu::TestLog::Message << "Not supported: The component sizes of internalformat do not exactly "
1024 << "match the corresponding component sizes of the source buffer's effective internal format." << tcu::TestLog::EndMessage;
1025 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "The test format isn't renderable, and the component sizes of "
1026 "internalformat do not exactly match the corresponding component sizes of the source buffer's effective internal format.");
1027 gl.deleteFramebuffers(1, &mainFboId);
1028 gl.deleteTextures(1, &mainFboColorTextureId);
1029 gl.deleteTextures(1, &copiedTextureId);
1030 gl.deleteTextures(1, &referenceTextureId);
1031 return STOP;
1032 }
1033 }
1034
1035 // Copy attachment from copy FBO to tested texture (if copy FBO couldn't be created
1036 // then copying will be done from main FBO color attachment)
1037 gl.bindTexture(GL_TEXTURE_2D, copiedTextureId);
1038 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture");
1039 gl.copyTexImage2D(GL_TEXTURE_2D, 0, textureInternalFormat, 0, 0, m_renderWidth, m_renderHeight, 0);
1040 GLU_EXPECT_NO_ERROR(gl.getError(), "glCopyTexImage2D");
1041
1042 // Make sure that main FBO is bound
1043 gl.bindFramebuffer(GL_FRAMEBUFFER, mainFboId);
1044
1045 // Render and grab tested texture
1046 gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1047 gl.bindTexture(GL_TEXTURE_2D, copiedTextureId);
1048 renderTexturedQuad(program.getProgram());
1049 tcu::Surface resultSurface(m_renderWidth, m_renderHeight);
1050 glu::readPixels(renderContext, 0, 0, resultSurface.getAccess());
1051
1052 // Compare surfaces
1053 if (tcu::fuzzyCompare(m_testCtx.getLog(), "Result", "Image comparison result", referenceSurface, resultSurface,
1054 0.05f, tcu::COMPARE_LOG_RESULT))
1055 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1056 else
1057 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1058
1059 // Cleanup
1060 gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
1061 gl.deleteFramebuffers(1, &mainFboId);
1062 gl.deleteTextures(1, &mainFboColorTextureId);
1063 gl.deleteTextures(1, &copiedTextureId);
1064 gl.deleteTextures(1, &referenceTextureId);
1065
1066 return STOP;
1067 }
1068
1069 class RenderbufferCase : public InternalformatCaseBase
1070 {
1071 public:
1072 RenderbufferCase(deqp::Context& context, const std::string& name, const RenderbufferFormat& renderbufferFormat);
1073 virtual ~RenderbufferCase();
1074
1075 virtual tcu::TestNode::IterateResult iterate(void);
1076
1077 private:
1078 void constructOrthoProjMatrix(GLfloat* mat4, GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n,
1079 GLfloat f) const;
1080 bool createFramebuffer();
1081 void deleteFramebuffer();
1082 GLuint createAndAttachRenderBuffer(GLenum rbFormat, GLenum fbAttachment);
1083 void renderColoredQuad(GLuint programId, const float* positions) const;
1084 glu::ProgramSources prepareColoringProgramSources(GLenum format, GLenum type) const;
1085 void convertUInt(const tcu::PixelBufferAccess &src, const tcu::PixelBufferAccess &dst);
1086 void convertsRGB(const tcu::PixelBufferAccess& src, const tcu::PixelBufferAccess& dst);
1087 void convertsRGBA(const tcu::PixelBufferAccess& src, const tcu::PixelBufferAccess& dst);
1088 void convertUInt_2_10_10_10_rev(const tcu::PixelBufferAccess &src, const tcu::PixelBufferAccess &dst);
1089
1090 private:
1091 GLuint m_fbo;
1092 GLuint m_rbColor;
1093 GLuint m_rbDepth;
1094 GLuint m_rbStencil;
1095 RenderbufferFormat m_testFormat;
1096 };
1097
RenderbufferCase(deqp::Context & context,const std::string & name,const RenderbufferFormat & renderbufferFormat)1098 RenderbufferCase::RenderbufferCase(deqp::Context& context, const std::string& name,
1099 const RenderbufferFormat& renderbufferFormat)
1100 : InternalformatCaseBase(context, name.c_str())
1101 , m_fbo(0)
1102 , m_rbColor(0)
1103 , m_rbDepth(0)
1104 , m_rbStencil(0)
1105 , m_testFormat(renderbufferFormat)
1106 {
1107 }
1108
~RenderbufferCase()1109 RenderbufferCase::~RenderbufferCase()
1110 {
1111 }
1112
iterate(void)1113 tcu::TestNode::IterateResult RenderbufferCase::iterate(void)
1114 {
1115 if (!requiredExtensionsSupported(m_testFormat.requiredExtension, m_testFormat.secondReqiredExtension))
1116 return STOP;
1117
1118 glu::RenderContext& renderContext = m_context.getRenderContext();
1119 const Functions& gl = renderContext.getFunctions();
1120
1121 int maxRenderbufferSize;
1122 gl.getIntegerv(GL_MAX_RENDERBUFFER_SIZE, &maxRenderbufferSize);
1123 int windowWidth = m_context.getRenderTarget().getWidth();
1124 int windowHeight = m_context.getRenderTarget().getHeight();
1125 m_renderWidth = (windowWidth > maxRenderbufferSize) ? maxRenderbufferSize : windowWidth;
1126 m_renderHeight = (windowHeight > maxRenderbufferSize) ? maxRenderbufferSize : windowHeight;
1127
1128 float w = static_cast<float>(m_renderWidth);
1129 float h = static_cast<float>(m_renderHeight);
1130 static const float bigQuadPositionsSet[] = { 0, 0, 0, w, 0, 0, 0, h, 0, w, h, 0 };
1131 static const float smallQuadPositionsSet[] = { 5.0f, 5.0f, 0.5f, w / 2, 5.0f, 0.5f,
1132 5.0f, h / 2, 0.5f, w / 2, h / 2, 0.5f };
1133
1134 bool stencilRenderbufferAvailable =
1135 (m_testFormat.type == RENDERBUFFER_STENCIL) || (m_testFormat.type == RENDERBUFFER_DEPTH_STENCIL);
1136
1137 GLenum testFormat = getUnsizedFormatFromInternalFormat(m_testFormat.format);
1138 GLenum testType = getTypeFromInternalFormat(m_testFormat.format);
1139 const bool isSRGB = m_testFormat.format == GL_SRGB8 || m_testFormat.format == GL_SRGB8_ALPHA8;
1140
1141 // We need surfaces for depth testing and stencil testing, and also for
1142 // storing the reference and the values for the format under testing
1143 tcu::Surface testSurface[2][2];
1144 for (GLuint loop1 = 0; loop1 < 2; loop1++)
1145 for (GLuint loop2 = 0; loop2 < 2; loop2++)
1146 testSurface[loop1][loop2].setSize(m_renderWidth, m_renderHeight);
1147
1148 GLint defaultFramebufferDepthBits = 0;
1149 GLint defaultFramebufferStencilBits = 0;
1150 if (glu::isContextTypeES(m_context.getRenderContext().getType()))
1151 {
1152 gl.getIntegerv(GL_DEPTH_BITS, &defaultFramebufferDepthBits);
1153 gl.getIntegerv(GL_STENCIL_BITS, &defaultFramebufferStencilBits);
1154 }
1155 else
1156 {
1157 GLint hasDepthBuffer = 0;
1158 GLint hasStencilBuffer = 0;
1159
1160 gl.getFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &hasDepthBuffer);
1161 gl.getFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &hasStencilBuffer);
1162
1163 if (hasDepthBuffer != GL_NONE)
1164 gl.getFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH, GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE,
1165 &defaultFramebufferDepthBits);
1166
1167 if (hasStencilBuffer != GL_NONE)
1168 gl.getFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE,
1169 &defaultFramebufferStencilBits);
1170 }
1171
1172 // Create two programs for rendering, one for rendering into default FB, and
1173 // a second one to render in our created FB
1174
1175 glu::ShaderProgram program0(renderContext,
1176 prepareColoringProgramSources(GL_RGBA, GL_UNSIGNED_BYTE));
1177 glu::ShaderProgram program1(renderContext, prepareColoringProgramSources(testFormat, testType));
1178
1179 std::vector<glu::ShaderProgram*> programs;
1180 programs.push_back(&program0);
1181 programs.push_back(&program1);
1182
1183 bool testNonStencil = (m_testFormat.type != RENDERBUFFER_STENCIL);
1184 bool testStencil = defaultFramebufferStencilBits && stencilRenderbufferAvailable;
1185
1186 for (GLuint loop = 0; loop < 2; loop++)
1187 {
1188 if (!programs[loop]->isOk())
1189 {
1190 m_testCtx.getLog() << *programs[loop];
1191 TCU_FAIL("Compile failed");
1192 }
1193
1194 gl.useProgram(programs[loop]->getProgram());
1195 GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram");
1196
1197 float mvpMatrix[16];
1198 constructOrthoProjMatrix(mvpMatrix, 0.0, w, 0.0f, h, 1.0f, -1.0f);
1199 GLint mvpUniformLocation = gl.getUniformLocation(programs[loop]->getProgram(), "mvpMatrix");
1200 gl.uniformMatrix4fv(mvpUniformLocation, 1, 0, mvpMatrix);
1201
1202 gl.bindTexture(GL_TEXTURE_2D, 0);
1203 gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
1204 gl.viewport(0, 0, m_renderWidth, m_renderHeight);
1205
1206 if (testNonStencil)
1207 {
1208 if (loop && !createFramebuffer())
1209 return STOP;
1210
1211 if (defaultFramebufferDepthBits)
1212 {
1213 gl.enable(GL_DEPTH_TEST);
1214 gl.depthFunc(GL_LESS);
1215 }
1216
1217 gl.bindFramebuffer(GL_FRAMEBUFFER, loop ? m_fbo : m_context.getRenderContext().getDefaultFramebuffer());
1218
1219 gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1220
1221 if (defaultFramebufferDepthBits)
1222 {
1223 // Draw a small quad just in the z buffer
1224 gl.colorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
1225 renderColoredQuad(programs[loop]->getProgram(), smallQuadPositionsSet);
1226
1227 // Large quad should be drawn on top small one to verify that the depth test is working
1228 gl.colorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1229 }
1230
1231 // Draws large quad
1232 renderColoredQuad(programs[loop]->getProgram(), bigQuadPositionsSet);
1233
1234 if (loop && isSRGB)
1235 {
1236 de::ArrayBuffer<deUint32> pixels;
1237 pixels.setStorage(4 * m_renderWidth * m_renderHeight);
1238 tcu::PixelBufferAccess pixelBuffer(tcu::TextureFormat(tcu::TextureFormat::sRGBA, tcu::TextureFormat::UNSIGNED_INT8),
1239 m_renderWidth, m_renderHeight, 1, pixels.getPtr());
1240 glu::readPixels(renderContext, 0, 0, pixelBuffer);
1241 if (m_testFormat.format == GL_SRGB8_ALPHA8)
1242 convertsRGBA(pixelBuffer, testSurface[0][loop].getAccess());
1243 else
1244 convertsRGB(pixelBuffer, testSurface[0][loop].getAccess());
1245 }
1246 else if (loop &&
1247 (testFormat == GL_RGBA_INTEGER || testFormat == GL_RG_INTEGER || testFormat == GL_RED_INTEGER))
1248 {
1249 de::ArrayBuffer<deUint32> pixels;
1250 pixels.setStorage(4 * m_renderWidth * m_renderHeight);
1251 tcu::PixelBufferAccess pixelBuffer(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNSIGNED_INT32),
1252 m_renderWidth, m_renderHeight, 1, pixels.getPtr());
1253 glu::readPixels(renderContext, 0, 0, pixelBuffer);
1254 if (testType == GL_UNSIGNED_INT_2_10_10_10_REV)
1255 convertUInt_2_10_10_10_rev(pixelBuffer, testSurface[0][loop].getAccess());
1256 else
1257 convertUInt(pixelBuffer, testSurface[0][loop].getAccess());
1258 }
1259 else
1260 {
1261 glu::readPixels(renderContext, 0, 0, testSurface[0][loop].getAccess());
1262 }
1263 }
1264
1265 if (loop)
1266 deleteFramebuffer();
1267
1268 if (defaultFramebufferStencilBits && stencilRenderbufferAvailable)
1269 {
1270 gl.disable(GL_DEPTH_TEST);
1271 gl.enable(GL_STENCIL_TEST);
1272
1273 if (loop && !createFramebuffer())
1274 return STOP;
1275
1276 gl.bindFramebuffer(GL_FRAMEBUFFER, loop ? m_fbo : m_context.getRenderContext().getDefaultFramebuffer());
1277 gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1278
1279 // Draw a rect scissored to half the screen height, incrementing the stencil buffer.
1280 gl.enable(GL_SCISSOR_TEST);
1281 gl.scissor(0, 0, m_renderWidth, m_renderHeight / 2);
1282 gl.stencilFunc(GL_ALWAYS, 0x0, 0xFF);
1283 gl.stencilOp(GL_ZERO, GL_INCR, GL_INCR);
1284 GLU_EXPECT_NO_ERROR(gl.getError(), "glStencilOp");
1285 renderColoredQuad(programs[loop]->getProgram(), bigQuadPositionsSet);
1286 gl.disable(GL_SCISSOR_TEST);
1287
1288 // Only draw where stencil is equal to 1
1289 gl.stencilFunc(GL_EQUAL, 0x01, 0xFF);
1290 gl.stencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
1291 gl.clear(GL_COLOR_BUFFER_BIT);
1292 renderColoredQuad(programs[loop]->getProgram(), bigQuadPositionsSet);
1293
1294 glu::readPixels(renderContext, 0, 0, testSurface[1][loop].getAccess());
1295
1296 gl.disable(GL_STENCIL_TEST);
1297
1298 if (loop)
1299 deleteFramebuffer();
1300 }
1301 }
1302
1303 // Compare surfaces for non-stencil
1304 if (testNonStencil && !tcu::fuzzyCompare(m_testCtx.getLog(), "Result", "Image comparison result",
1305 testSurface[0][0], testSurface[0][1],
1306 0.05f, tcu::COMPARE_LOG_RESULT))
1307 {
1308 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Depth subtest failed");
1309 return STOP;
1310 }
1311
1312 // Compare surfaces for stencil
1313 if (testStencil && !tcu::fuzzyCompare(m_testCtx.getLog(), "Result", "Image comparison result",
1314 testSurface[1][0], testSurface[1][1],
1315 0.05f, tcu::COMPARE_LOG_RESULT))
1316 {
1317 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Stencil subtest failed");
1318 return STOP;
1319 }
1320
1321 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1322 return STOP;
1323 }
1324
constructOrthoProjMatrix(GLfloat * mat4,GLfloat l,GLfloat r,GLfloat b,GLfloat t,GLfloat n,GLfloat f) const1325 void RenderbufferCase::constructOrthoProjMatrix(GLfloat* mat4, GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n,
1326 GLfloat f) const
1327 {
1328 GLfloat inv_width = 1.0f / (r - l);
1329 GLfloat inv_height = 1.0f / (t - b);
1330 GLfloat inv_depth = 1.0f / (f - n);
1331
1332 memset(mat4, 0, sizeof(GLfloat) * 16);
1333 /*
1334 0 4 8 12
1335 1 5 9 13
1336 2 6 10 14
1337 3 7 11 15
1338 */
1339
1340 mat4[0] = 2.0f * inv_width;
1341 mat4[5] = 2.0f * inv_height;
1342 mat4[10] = 2.0f * inv_depth;
1343
1344 mat4[12] = -(r + l) * inv_width;
1345 mat4[13] = -(t + b) * inv_height;
1346 mat4[14] = -(f + n) * inv_depth;
1347 mat4[15] = 1.0f;
1348 }
1349
createFramebuffer()1350 bool RenderbufferCase::createFramebuffer()
1351 {
1352 glu::RenderContext& renderContext = m_context.getRenderContext();
1353 const Functions& gl = renderContext.getFunctions();
1354
1355 gl.genFramebuffers(1, &m_fbo);
1356 gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
1357
1358 if (m_testFormat.type == RENDERBUFFER_COLOR)
1359 {
1360 m_rbColor = createAndAttachRenderBuffer(m_testFormat.format, GL_COLOR_ATTACHMENT0);
1361 m_rbDepth = createAndAttachRenderBuffer(GL_DEPTH_COMPONENT16, GL_DEPTH_ATTACHMENT);
1362 }
1363 else
1364 {
1365 m_rbColor = createAndAttachRenderBuffer(GL_RGBA8, GL_COLOR_ATTACHMENT0);
1366 if (m_testFormat.type == RENDERBUFFER_DEPTH)
1367 m_rbDepth = createAndAttachRenderBuffer(m_testFormat.format, GL_DEPTH_ATTACHMENT);
1368 else if (m_testFormat.type == RENDERBUFFER_STENCIL)
1369 m_rbStencil = createAndAttachRenderBuffer(m_testFormat.format, GL_STENCIL_ATTACHMENT);
1370 else if (m_testFormat.type == RENDERBUFFER_DEPTH_STENCIL)
1371 {
1372 if (glu::contextSupports(renderContext.getType(), glu::ApiType::es(2, 0)))
1373 {
1374 m_rbDepth = createAndAttachRenderBuffer(m_testFormat.format, GL_DEPTH_ATTACHMENT);
1375 gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_rbDepth);
1376 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer");
1377 }
1378 else
1379 m_rbDepth = createAndAttachRenderBuffer(m_testFormat.format, GL_DEPTH_STENCIL_ATTACHMENT);
1380 }
1381 }
1382
1383 GLenum bufferStatus = gl.checkFramebufferStatus(GL_FRAMEBUFFER);
1384 if (bufferStatus == GL_FRAMEBUFFER_UNSUPPORTED)
1385 {
1386 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Unsuported framebuffer");
1387 return false;
1388 }
1389 else if (bufferStatus != GL_FRAMEBUFFER_COMPLETE)
1390 {
1391 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Framebuffer not complete");
1392 return false;
1393 }
1394
1395 return true;
1396 }
1397
deleteFramebuffer()1398 void RenderbufferCase::deleteFramebuffer()
1399 {
1400 const Functions& gl = m_context.getRenderContext().getFunctions();
1401
1402 gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
1403 if (m_fbo)
1404 gl.deleteFramebuffers(1, &m_fbo);
1405 if (m_rbColor)
1406 gl.deleteRenderbuffers(1, &m_rbColor);
1407 if (m_rbDepth)
1408 gl.deleteRenderbuffers(1, &m_rbDepth);
1409 if (m_rbStencil)
1410 gl.deleteRenderbuffers(1, &m_rbStencil);
1411 }
1412
createAndAttachRenderBuffer(GLenum rbFormat,GLenum fbAttachment)1413 GLuint RenderbufferCase::createAndAttachRenderBuffer(GLenum rbFormat, GLenum fbAttachment)
1414 {
1415 const Functions& gl = m_context.getRenderContext().getFunctions();
1416
1417 GLuint rbName;
1418
1419 gl.genRenderbuffers(1, &rbName);
1420 gl.bindRenderbuffer(GL_RENDERBUFFER, rbName);
1421 gl.renderbufferStorage(GL_RENDERBUFFER, rbFormat, m_renderWidth, m_renderHeight);
1422 GLU_EXPECT_NO_ERROR(gl.getError(), "glRenderbufferStorage");
1423 gl.framebufferRenderbuffer(GL_FRAMEBUFFER, fbAttachment, GL_RENDERBUFFER, rbName);
1424 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer");
1425
1426 return rbName;
1427 }
1428
renderColoredQuad(GLuint programId,const float * positions) const1429 void RenderbufferCase::renderColoredQuad(GLuint programId, const float* positions) const
1430 {
1431 // Prepare data for rendering
1432 static const deUint16 quadIndices[] = { 0, 1, 2, 2, 1, 3 };
1433 static const float colors[] = {
1434 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1435 };
1436 const glu::VertexArrayBinding vertexArrays[] = { glu::va::Float("position", 3, 4, 0, positions),
1437 glu::va::Float("color", 4, 4, 0, colors) };
1438
1439 glu::draw(m_context.getRenderContext(), programId, DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays,
1440 glu::pr::TriangleStrip(DE_LENGTH_OF_ARRAY(quadIndices), quadIndices));
1441 }
1442
prepareColoringProgramSources(GLenum format,GLenum type) const1443 glu::ProgramSources RenderbufferCase::prepareColoringProgramSources(GLenum format, GLenum type) const
1444 {
1445 glu::RenderContext& renderContext = m_context.getRenderContext();
1446 glu::ContextType contextType = renderContext.getType();
1447 glu::GLSLVersion glslVersion = glu::getContextTypeGLSLVersion(contextType);
1448 std::string versionDeclaration = glu::getGLSLVersionDeclaration(glslVersion);
1449
1450 std::map<std::string, std::string> specializationMap;
1451
1452 versionDeclaration += "\n";
1453 std::string vs = versionDeclaration;
1454 std::string fs = versionDeclaration;
1455 if (glu::contextSupports(contextType, glu::ApiType::es(3, 0)) || glu::isContextTypeGLCore(contextType))
1456 {
1457 vs += "in highp vec3 position;\n"
1458 "in highp vec4 color;\n"
1459 "out highp vec4 fColor;\n"
1460 "uniform mat4 mvpMatrix;\n"
1461 "void main()\n"
1462 "{\n"
1463 " fColor = color;\n"
1464 " gl_Position = mvpMatrix * vec4(position, 1.0);\n"
1465 "}\n";
1466 fs += "in highp vec4 fColor;\n"
1467 "out ${COLOR_DATA} color;\n"
1468 "void main()\n"
1469 "{\n"
1470 " color = ${COMPUTE_COLOR};\n"
1471 "}\n";
1472 }
1473 else
1474 {
1475 vs += "attribute highp vec3 position;\n"
1476 "attribute highp vec4 color;\n"
1477 "varying highp vec4 fColor;\n"
1478 "uniform mat4 mvpMatrix;\n"
1479 "void main()\n"
1480 "{\n"
1481 " fColor = color;\n"
1482 " gl_Position = mvpMatrix * vec4(position, 1.0);\n"
1483 "}\n";
1484 fs += "varying highp vec4 fColor;\n"
1485 "void main()\n"
1486 "{\n"
1487 " gl_FragColor = fColor;\n"
1488 "}\n";
1489 }
1490
1491 if (format == GL_RGBA_INTEGER)
1492 {
1493 std::string compute_color = "${COLOR_DATA}("
1494 "${MAX_RED} * fColor.r, "
1495 "${MAX_GREEN} * fColor.g, "
1496 "${MAX_BLUE} * fColor.b, "
1497 "${MAX_ALPHA} * fColor.a)";
1498
1499 if (type == GL_UNSIGNED_INT_2_10_10_10_REV)
1500 {
1501 specializationMap["MAX_RED"] = "1023";
1502 specializationMap["MAX_GREEN"] = "1023";
1503 specializationMap["MAX_BLUE"] = "1023";
1504 specializationMap["MAX_ALPHA"] = "3";
1505 }
1506 else
1507 {
1508 specializationMap["MAX_RED"] = "255";
1509 specializationMap["MAX_GREEN"] = "255";
1510 specializationMap["MAX_BLUE"] = "255";
1511 specializationMap["MAX_ALPHA"] = "255";
1512 }
1513 specializationMap["COLOR_DATA"] = "uvec4";
1514 specializationMap["COMPUTE_COLOR"] = tcu::StringTemplate(compute_color).specialize(specializationMap);
1515 }
1516 else
1517 {
1518 specializationMap["COLOR_DATA"] = "highp vec4";
1519 specializationMap["COMPUTE_COLOR"] = "fColor";
1520 }
1521
1522 vs = tcu::StringTemplate(vs).specialize(specializationMap);
1523 fs = tcu::StringTemplate(fs).specialize(specializationMap);
1524 return glu::makeVtxFragSources(vs.c_str(), fs.c_str());
1525 }
1526
1527 typedef TextureFormat TF;
1528 typedef CopyTexImageFormat CF;
1529 typedef RenderbufferFormat RF;
1530
1531 struct TestData
1532 {
1533 std::vector<TextureFormat> texture2DFormats;
1534 std::vector<CopyTexImageFormat> copyTexImageFormats;
1535 std::vector<RenderbufferFormat> renderbufferFormats;
1536 };
1537
1538 /** Constructor.
1539 *
1540 * @param context Rendering context.
1541 */
InternalformatTests(deqp::Context & context)1542 InternalformatTests::InternalformatTests(deqp::Context& context)
1543 : TestCaseGroup(context, "internalformat", "Texture internalformat tests")
1544 {
1545 }
1546
1547 template <typename Data, unsigned int Size>
append(std::vector<Data> & dataVector,const Data (& dataArray)[Size])1548 void InternalformatTests::append(std::vector<Data>& dataVector, const Data (&dataArray)[Size])
1549 {
1550 dataVector.insert(dataVector.end(), dataArray, dataArray + Size);
1551 }
1552
getESTestData(TestData & testData,glu::ContextType & contextType)1553 void InternalformatTests::getESTestData(TestData& testData, glu::ContextType& contextType)
1554 {
1555 TextureFormat commonTexture2DFormats[] = {
1556 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA),
1557 TF(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB),
1558 TF(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA),
1559 TF(GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE_ALPHA),
1560 TF(GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE),
1561 TF(GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA),
1562 TF(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGBA, EXT_texture_type_2_10_10_10_REV),
1563 TF(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2, EXT_texture_type_2_10_10_10_REV),
1564 TF(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB5_A1, EXT_texture_type_2_10_10_10_REV),
1565 TF(GL_RGB, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB, EXT_texture_type_2_10_10_10_REV),
1566 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT, OES_depth_texture),
1567 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT, OES_depth_texture),
1568 TF(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH_STENCIL, OES_packed_depth_stencil, OES_depth_texture),
1569 TF(GL_RGB, GL_HALF_FLOAT_OES, GL_RGB, OES_texture_half_float),
1570 TF(GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA, OES_texture_half_float),
1571 TF(GL_RGB, GL_HALF_FLOAT_OES, GL_RGB, OES_texture_half_float_linear, DE_NULL, GL_LINEAR, GL_LINEAR),
1572 TF(GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA, OES_texture_half_float_linear, DE_NULL, GL_LINEAR, GL_LINEAR),
1573 TF(GL_RGB, GL_FLOAT, GL_RGB32F, OES_texture_float),
1574 TF(GL_RGBA, GL_FLOAT, GL_RGBA32F, OES_texture_float),
1575 TF(GL_RGB, GL_FLOAT, GL_RGB32F, OES_texture_float_linear, DE_NULL, GL_LINEAR, GL_LINEAR),
1576 TF(GL_RGBA, GL_FLOAT, GL_RGBA32F, OES_texture_float_linear, DE_NULL, GL_LINEAR, GL_LINEAR),
1577 };
1578
1579 CopyTexImageFormat commonCopyTexImageFormats[] = {
1580 CF(GL_RGB),
1581 CF(GL_RGBA),
1582 CF(GL_ALPHA),
1583 CF(GL_LUMINANCE),
1584 CF(GL_LUMINANCE_ALPHA),
1585 };
1586
1587 RenderbufferFormat commonRenderbufferFormats[] = {
1588 RF(GL_RGBA8, RENDERBUFFER_COLOR, OES_rgb8_rgba8),
1589 RF(GL_RGB8, RENDERBUFFER_COLOR, OES_rgb8_rgba8),
1590 };
1591
1592 append(testData.texture2DFormats, commonTexture2DFormats);
1593 append(testData.copyTexImageFormats, commonCopyTexImageFormats);
1594 append(testData.renderbufferFormats, commonRenderbufferFormats);
1595
1596 if (glu::contextSupports(contextType, glu::ApiType::es(3, 0)))
1597 {
1598 TextureFormat es3Texture2DFormats[] = {
1599 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8),
1600 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGB5_A1),
1601 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA4),
1602 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_SRGB8_ALPHA8),
1603 TF(GL_RGBA, GL_BYTE, GL_RGBA8_SNORM),
1604 TF(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4),
1605 TF(GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1),
1606 TF(GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F),
1607 TF(GL_RGBA, GL_FLOAT, GL_RGBA16F),
1608 TF(GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_RGBA8UI),
1609 TF(GL_RGBA_INTEGER, GL_BYTE, GL_RGBA8I),
1610 TF(GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_RGBA16UI),
1611 TF(GL_RGBA_INTEGER, GL_SHORT, GL_RGBA16I),
1612 TF(GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_RGBA32UI),
1613 TF(GL_RGBA_INTEGER, GL_INT, GL_RGBA32I),
1614 TF(GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2UI),
1615 TF(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8),
1616 TF(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB565),
1617 TF(GL_RGB, GL_UNSIGNED_BYTE, GL_SRGB8),
1618 TF(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565),
1619 TF(GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_R11F_G11F_B10F),
1620 TF(GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_RGB9_E5),
1621 TF(GL_RGB, GL_HALF_FLOAT, GL_RGB16F),
1622 TF(GL_RGB, GL_HALF_FLOAT, GL_R11F_G11F_B10F),
1623 TF(GL_RGB, GL_HALF_FLOAT, GL_RGB9_E5),
1624 TF(GL_RGB, GL_FLOAT, GL_RGB16F),
1625 TF(GL_RGB, GL_FLOAT, GL_R11F_G11F_B10F),
1626 TF(GL_RGB, GL_FLOAT, GL_RGB9_E5),
1627 TF(GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_RGB8UI),
1628 TF(GL_RGB_INTEGER, GL_BYTE, GL_RGB8I),
1629 TF(GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_RGB16UI),
1630 TF(GL_RGB_INTEGER, GL_SHORT, GL_RGB16I),
1631 TF(GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_RGB32UI),
1632 TF(GL_RGB_INTEGER, GL_INT, GL_RGB32I),
1633 TF(GL_RG, GL_UNSIGNED_BYTE, GL_RG8),
1634 TF(GL_RG, GL_HALF_FLOAT, GL_RG16F),
1635 TF(GL_RG, GL_FLOAT, GL_RG32F),
1636 TF(GL_RG, GL_FLOAT, GL_RG16F),
1637 TF(GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_RG8UI),
1638 TF(GL_RG_INTEGER, GL_BYTE, GL_RG8I),
1639 TF(GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_RG16UI),
1640 TF(GL_RG_INTEGER, GL_SHORT, GL_RG16I),
1641 TF(GL_RG_INTEGER, GL_UNSIGNED_INT, GL_RG32UI),
1642 TF(GL_RG_INTEGER, GL_INT, GL_RG32I),
1643 TF(GL_RED, GL_UNSIGNED_BYTE, GL_R8),
1644 TF(GL_RED, GL_HALF_FLOAT, GL_R16F),
1645 TF(GL_RED, GL_FLOAT, GL_R32F),
1646 TF(GL_RED, GL_FLOAT, GL_R16F),
1647 TF(GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_R8UI),
1648 TF(GL_RED_INTEGER, GL_BYTE, GL_R8I),
1649 TF(GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_R16UI),
1650 TF(GL_RED_INTEGER, GL_SHORT, GL_R16I),
1651 TF(GL_RED_INTEGER, GL_UNSIGNED_INT, GL_R32UI),
1652 TF(GL_RED_INTEGER, GL_INT, GL_R32I),
1653 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16),
1654 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT24),
1655 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT16),
1656 TF(GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32F),
1657 TF(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8),
1658 TF(GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_DEPTH32F_STENCIL8),
1659 TF(GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGBA),
1660 TF(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB),
1661 };
1662
1663 CopyTexImageFormat es3CopyTexImageFormats[] = {
1664 CF(GL_RGBA4), CF(GL_RGB5_A1), CF(GL_RGB565), CF(GL_RGBA8),
1665 CF(GL_RGB8), CF(GL_SRGB8_ALPHA8), CF(GL_SRGB8), CF(GL_R11F_G11F_B10F),
1666 };
1667
1668 RenderbufferFormat es3RenderbufferFormats[] = {
1669 RF(GL_RGB5_A1, RENDERBUFFER_COLOR),
1670 RF(GL_SRGB8_ALPHA8, RENDERBUFFER_COLOR),
1671 RF(GL_DEPTH_COMPONENT32F, RENDERBUFFER_DEPTH),
1672 RF(GL_DEPTH32F_STENCIL8, RENDERBUFFER_DEPTH_STENCIL),
1673 };
1674
1675 append(testData.texture2DFormats, es3Texture2DFormats);
1676 append(testData.copyTexImageFormats, es3CopyTexImageFormats);
1677 append(testData.renderbufferFormats, es3RenderbufferFormats);
1678 }
1679 else if (glu::contextSupports(contextType, glu::ApiType::es(2, 0)))
1680 {
1681 TextureFormat es2Texture2DFormats[] = {
1682 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGB5_A1, OES_required_internalformat),
1683 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA4, OES_required_internalformat),
1684 TF(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB565, OES_required_internalformat),
1685 TF(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4, OES_required_internalformat),
1686 TF(GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGBA, OES_required_internalformat),
1687 TF(GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1, OES_required_internalformat),
1688 TF(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB, OES_required_internalformat),
1689 TF(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565, OES_required_internalformat),
1690 TF(GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_OES, OES_required_internalformat),
1691 TF(GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE4_ALPHA4_OES, OES_required_internalformat),
1692 TF(GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_OES, OES_required_internalformat),
1693 TF(GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_OES, OES_required_internalformat),
1694 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT16, OES_required_internalformat,
1695 OES_depth_texture),
1696 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16, OES_required_internalformat,
1697 OES_depth_texture),
1698 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT24, OES_required_internalformat, OES_depth24),
1699 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32, OES_required_internalformat, OES_depth32),
1700 };
1701
1702 CopyTexImageFormat es2CopyTexImageFormats[] = {
1703 CF(GL_RGB5_A1, OES_required_internalformat),
1704 CF(GL_RGB565, OES_required_internalformat),
1705 CF(GL_RGBA4, OES_required_internalformat),
1706 CF(GL_LUMINANCE4_ALPHA4_OES, OES_required_internalformat),
1707 CF(GL_LUMINANCE8_ALPHA8_OES, OES_required_internalformat),
1708 CF(GL_LUMINANCE8_OES, OES_required_internalformat),
1709 CF(GL_ALPHA8_OES, OES_required_internalformat),
1710 CF(GL_RGB10_A2, EXT_texture_type_2_10_10_10_REV, OES_required_internalformat),
1711 CF(GL_RGB10, EXT_texture_type_2_10_10_10_REV, OES_required_internalformat)
1712 };
1713
1714 RenderbufferFormat es2RenderbufferFormats[] = {
1715 RF(GL_STENCIL_INDEX1, RENDERBUFFER_STENCIL, OES_stencil1),
1716 RF(GL_STENCIL_INDEX4, RENDERBUFFER_STENCIL, OES_stencil4),
1717 RF(GL_STENCIL_INDEX8, RENDERBUFFER_STENCIL, OES_stencil8),
1718 RF(GL_DEPTH_COMPONENT16, RENDERBUFFER_DEPTH, OES_depth_texture),
1719 RF(GL_DEPTH_COMPONENT24, RENDERBUFFER_DEPTH, OES_depth24),
1720 RF(GL_DEPTH_COMPONENT32, RENDERBUFFER_DEPTH, OES_depth32),
1721 RF(GL_DEPTH24_STENCIL8, RENDERBUFFER_DEPTH_STENCIL, OES_packed_depth_stencil),
1722 RF(GL_RGB5_A1, RENDERBUFFER_COLOR, OES_required_internalformat),
1723 };
1724
1725 append(testData.texture2DFormats, es2Texture2DFormats);
1726 append(testData.copyTexImageFormats, es2CopyTexImageFormats);
1727 append(testData.renderbufferFormats, es2RenderbufferFormats);
1728 }
1729 }
1730
getGLTestData(TestData & testData,glu::ContextType &)1731 void InternalformatTests::getGLTestData(TestData& testData, glu::ContextType&)
1732 {
1733 TextureFormat commonTexture2DFormats[] = {
1734 TF(GL_RED, GL_BYTE, GL_R8_SNORM),
1735 TF(GL_RED, GL_SHORT, GL_R16_SNORM),
1736 TF(GL_RG, GL_BYTE, GL_RG8_SNORM),
1737 TF(GL_RG, GL_SHORT, GL_RG16_SNORM),
1738 TF(GL_RGB, GL_BYTE, GL_RGB8_SNORM),
1739 TF(GL_RGB, GL_SHORT, GL_RGB16_SNORM),
1740 TF(GL_RGBA, GL_BYTE, GL_RGBA8_SNORM),
1741 TF(GL_RGBA, GL_SHORT, GL_RGBA16_SNORM),
1742 TF(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGBA),
1743 TF(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2),
1744 TF(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB5_A1),
1745 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT, ARB_depth_texture),
1746 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16, ARB_depth_texture),
1747 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT, ARB_depth_texture),
1748 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT24, ARB_depth_texture),
1749 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32, ARB_depth_texture),
1750 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT16, ARB_depth_texture),
1751 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGB9_E5, EXT_texture_shared_exponent),
1752 TF(GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2UI, ARB_texture_rgb10_a2ui),
1753 TF(GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_RGBA32UI, EXT_texture_integer),
1754 TF(GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_RGB32UI, EXT_texture_integer),
1755 TF(GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_RGBA16UI, EXT_texture_integer),
1756 TF(GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_RGB16UI, EXT_texture_integer),
1757 TF(GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_RGBA8UI, EXT_texture_integer),
1758 TF(GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_RGB8UI, EXT_texture_integer),
1759 TF(GL_RGBA_INTEGER, GL_INT, GL_RGBA32I, EXT_texture_integer),
1760 TF(GL_RGB_INTEGER, GL_INT, GL_RGB32I, EXT_texture_integer),
1761 TF(GL_RGBA_INTEGER, GL_SHORT, GL_RGBA16I, EXT_texture_integer),
1762 TF(GL_RGB_INTEGER, GL_SHORT, GL_RGB16I, EXT_texture_integer),
1763 TF(GL_RGBA_INTEGER, GL_BYTE, GL_RGBA8I, EXT_texture_integer),
1764 TF(GL_RGB_INTEGER, GL_BYTE, GL_RGB8I, EXT_texture_integer),
1765 TF(GL_RED, GL_HALF_FLOAT, GL_R16F, ARB_texture_float),
1766 TF(GL_RG, GL_HALF_FLOAT, GL_RG16F, ARB_texture_float),
1767 TF(GL_RGB, GL_HALF_FLOAT, GL_RGB16F, ARB_texture_float),
1768 TF(GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F, ARB_texture_float),
1769 TF(GL_RED, GL_FLOAT, GL_R32F, ARB_texture_float),
1770 TF(GL_RG, GL_FLOAT, GL_RG32F, ARB_texture_float),
1771 TF(GL_RGB, GL_FLOAT, GL_RGB32F, ARB_texture_float),
1772 TF(GL_RGBA, GL_FLOAT, GL_RGBA32F, ARB_texture_float),
1773 };
1774
1775 CopyTexImageFormat commonCopyTexImageFormats[] = {
1776 CF(GL_DEPTH_COMPONENT16, ARB_depth_texture), CF(GL_DEPTH_COMPONENT24, ARB_depth_texture),
1777 CF(GL_DEPTH_COMPONENT32, ARB_depth_texture), CF(GL_RGB9_E5, EXT_texture_shared_exponent),
1778 CF(GL_RGB10_A2UI, ARB_texture_rgb10_a2ui), CF(GL_RGB10_A2),
1779 };
1780
1781 RenderbufferFormat commonRenderbufferFormats[] = {
1782 RF(GL_RGBA8, RENDERBUFFER_COLOR),
1783 RF(GL_RGB9_E5, RENDERBUFFER_COLOR, EXT_texture_shared_exponent),
1784 RF(GL_RGB10_A2UI, RENDERBUFFER_COLOR, ARB_texture_rgb10_a2ui),
1785 RF(GL_DEPTH24_STENCIL8, RENDERBUFFER_DEPTH_STENCIL),
1786 RF(GL_DEPTH_COMPONENT16, RENDERBUFFER_DEPTH, ARB_depth_texture),
1787 RF(GL_DEPTH_COMPONENT24, RENDERBUFFER_DEPTH, ARB_depth_texture),
1788 RF(GL_DEPTH_COMPONENT32, RENDERBUFFER_DEPTH, ARB_depth_texture),
1789 };
1790
1791 append(testData.texture2DFormats, commonTexture2DFormats);
1792 append(testData.copyTexImageFormats, commonCopyTexImageFormats);
1793 append(testData.renderbufferFormats, commonRenderbufferFormats);
1794 }
1795
formatToString(GLenum format)1796 std::string formatToString(GLenum format)
1797 {
1798 // this function extends glu::getTextureFormatStr by formats used in thise tests
1799
1800 typedef std::map<GLenum, std::string> FormatMap;
1801 static FormatMap formatMap;
1802 if (formatMap.empty())
1803 {
1804 // store in map formats that are not supported by glu::getTextureFormatStr
1805 formatMap[GL_LUMINANCE8_ALPHA8_OES] = "luminance8_alpha8_oes";
1806 formatMap[GL_LUMINANCE4_ALPHA4_OES] = "luminance4_alpha4_oes";
1807 formatMap[GL_STENCIL_INDEX1_OES] = "stencil_index1_oes";
1808 formatMap[GL_STENCIL_INDEX4_OES] = "stencil_index4_oes";
1809 formatMap[GL_LUMINANCE8_OES] = "luminance8_oes";
1810 formatMap[GL_ALPHA8_OES] = "alpha8_oes";
1811 }
1812
1813 FormatMap::iterator it = formatMap.find(format);
1814 if (it == formatMap.end())
1815 {
1816 // if format is not in map try glu function
1817 std::string formatString = glu::getTextureFormatStr(format).toString();
1818
1819 // cut out "GL_" from string
1820 formatString = formatString.substr(3, formatString.length());
1821
1822 // make lower case
1823 std::transform(formatString.begin(), formatString.end(), formatString.begin(), tolower);
1824
1825 return formatString;
1826 }
1827 return it->second;
1828 }
1829
1830 /** Initializes the test group contents. */
init()1831 void InternalformatTests::init()
1832 {
1833 // Determine which data sets should be used for tests
1834 TestData testData;
1835 glu::ContextType contextType = m_context.getRenderContext().getType();
1836 if (glu::isContextTypeGLCore(contextType))
1837 getGLTestData(testData, contextType);
1838 else
1839 getESTestData(testData, contextType);
1840
1841 // Construct texture2d tests
1842 TestCaseGroup* texture2DGroup = new deqp::TestCaseGroup(m_context, "texture2d", "");
1843 for (unsigned int i = 0; i < testData.texture2DFormats.size(); i++)
1844 {
1845 const TextureFormat& tf = testData.texture2DFormats[i];
1846 std::string format = formatToString(tf.format);
1847 std::string type = glu::getTypeStr(tf.type).toString();
1848 std::string internalFormat = formatToString(tf.internalFormat);
1849
1850 // cut out "GL_" from type and make it lowercase
1851 type = type.substr(3, type.length());
1852 std::transform(type.begin(), type.end(), type.begin(), tolower);
1853
1854 std::string name = format + "_" + type + "_" + internalFormat;
1855 if (tf.minFilter == GL_LINEAR)
1856 name += "_linear";
1857
1858 texture2DGroup->addChild(new Texture2DCase(m_context, name, tf));
1859 }
1860 addChild(texture2DGroup);
1861
1862 // Construct copy_text_image tests
1863 TestCaseGroup* copyTexImageGroup = new deqp::TestCaseGroup(m_context, "copy_tex_image", "");
1864 for (unsigned int i = 0; i < testData.copyTexImageFormats.size(); i++)
1865 {
1866 const CopyTexImageFormat& ctif = testData.copyTexImageFormats[i];
1867 std::string name = formatToString(ctif.internalFormat);
1868 copyTexImageGroup->addChild(new CopyTexImageCase(m_context, name, ctif));
1869 }
1870 addChild(copyTexImageGroup);
1871
1872 // Construct renderbuffer tests
1873 TestCaseGroup* renderbufferGroup = new deqp::TestCaseGroup(m_context, "renderbuffer", "");
1874 for (unsigned int i = 0; i < testData.renderbufferFormats.size(); i++)
1875 {
1876 const RenderbufferFormat& rbf = testData.renderbufferFormats[i];
1877 std::string name = formatToString(rbf.format);
1878 renderbufferGroup->addChild(new RenderbufferCase(m_context, name, rbf));
1879 }
1880 addChild(renderbufferGroup);
1881 }
1882
convertUInt(const tcu::PixelBufferAccess & src,const tcu::PixelBufferAccess & dst)1883 void RenderbufferCase::convertUInt(const tcu::PixelBufferAccess &src, const tcu::PixelBufferAccess &dst)
1884 {
1885 for (int z = 0; z < dst.getDepth(); ++z)
1886 for (int y = 0; y < dst.getHeight(); ++y)
1887 for (int x = 0; x < dst.getWidth(); ++x)
1888 {
1889 tcu::UVec4 srcPixel = src.getPixelUint(x, y, z);
1890 tcu::Vec4 dstPixel(srcPixel.x() / 255.0f, srcPixel.y() / 255.0f, srcPixel.z() / 255.0f, srcPixel.w() / 255.0f);
1891 dst.setPixel(dstPixel, x, y, z);
1892 }
1893 }
1894
convertsRGB(const tcu::PixelBufferAccess & src,const tcu::PixelBufferAccess & dst)1895 void RenderbufferCase::convertsRGB(const tcu::PixelBufferAccess& src, const tcu::PixelBufferAccess& dst)
1896 {
1897 for (int z = 0; z < dst.getDepth(); ++z)
1898 for (int y = 0; y < dst.getHeight(); ++y)
1899 for (int x = 0; x < dst.getWidth(); ++x)
1900 {
1901 tcu::UVec4 srcPixel = src.getPixelUint(x, y, z);
1902 tcu::Vec4 dstPixel = sRGB8ToLinear(srcPixel);
1903 dst.setPixel(dstPixel, x, y, z);
1904 }
1905 }
1906
convertsRGBA(const tcu::PixelBufferAccess & src,const tcu::PixelBufferAccess & dst)1907 void RenderbufferCase::convertsRGBA(const tcu::PixelBufferAccess& src, const tcu::PixelBufferAccess& dst)
1908 {
1909 for (int z = 0; z < dst.getDepth(); ++z)
1910 for (int y = 0; y < dst.getHeight(); ++y)
1911 for (int x = 0; x < dst.getWidth(); ++x)
1912 {
1913 tcu::UVec4 srcPixel = src.getPixelUint(x, y, z);
1914 tcu::Vec4 dstPixel = sRGBA8ToLinear(srcPixel);
1915 dst.setPixel(dstPixel, x, y, z);
1916 }
1917 }
1918
convertUInt_2_10_10_10_rev(const tcu::PixelBufferAccess & src,const tcu::PixelBufferAccess & dst)1919 void RenderbufferCase::convertUInt_2_10_10_10_rev(const tcu::PixelBufferAccess &src, const tcu::PixelBufferAccess &dst)
1920 {
1921 for (int z = 0; z < dst.getDepth(); ++z)
1922 for (int y = 0; y < dst.getHeight(); ++y)
1923 for (int x = 0; x < dst.getWidth(); ++x)
1924 {
1925 tcu::UVec4 srcPixel = src.getPixelUint(x, y, z);
1926 tcu::Vec4 dstPixel(srcPixel.x() / 1023.0f, srcPixel.y() / 1023.0f, srcPixel.z() / 1023.0f, srcPixel.w() / 3.0f);
1927 dst.setPixel(dstPixel, x, y, z);
1928 }
1929 }
1930 } /* glcts namespace */
1931