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 mantissa >>= (14 + exp);
766 return (GLhalf)((((GLhalf)sign) << 15) | (GLhalf)(mantissa));
767 }
768
769 return (GLhalf)((((GLhalf)sign) << 15) | (GLhalf)((exp - HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP) >> 13) |
770 (GLhalf)(mantissa >> 13));
771 }
772
773 class Texture2DCase : public InternalformatCaseBase
774 {
775 public:
776 Texture2DCase(deqp::Context& context, const std::string& name, const TextureFormat& textureFormat);
~Texture2DCase()777 virtual ~Texture2DCase()
778 {
779 }
780
781 virtual tcu::TestNode::IterateResult iterate(void);
782
783 private:
784 TextureFormat m_testFormat;
785 };
786
Texture2DCase(deqp::Context & context,const std::string & name,const TextureFormat & testFormat)787 Texture2DCase::Texture2DCase(deqp::Context& context, const std::string& name, const TextureFormat& testFormat)
788 : InternalformatCaseBase(context, name.c_str()), m_testFormat(testFormat)
789 {
790 }
791
iterate(void)792 tcu::TestNode::IterateResult Texture2DCase::iterate(void)
793 {
794 if (!requiredExtensionsSupported(m_testFormat.requiredExtension, m_testFormat.secondReqiredExtension))
795 return STOP;
796
797 glu::RenderContext& renderContext = m_context.getRenderContext();
798 const Functions& gl = renderContext.getFunctions();
799
800 typedef std::map<GLenum, TextureFormat> ReferenceFormatMap;
801 static ReferenceFormatMap formatMap;
802 if (formatMap.empty())
803 {
804 formatMap[GL_RED] = TextureFormat(GL_RED, GL_UNSIGNED_BYTE, GL_RED);
805 formatMap[GL_RG] = TextureFormat(GL_RG, GL_UNSIGNED_BYTE, GL_RG);
806 formatMap[GL_RGB] = TextureFormat(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB);
807 formatMap[GL_RGBA] = TextureFormat(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB);
808 formatMap[GL_RGBA_INTEGER] = TextureFormat(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB);
809 formatMap[GL_RGB_INTEGER] = TextureFormat(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB);
810 formatMap[GL_ALPHA] = TextureFormat(GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA);
811 formatMap[GL_LUMINANCE] = TextureFormat(GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE);
812 formatMap[GL_LUMINANCE_ALPHA] = TextureFormat(GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE_ALPHA);
813 formatMap[GL_DEPTH_COMPONENT] = TextureFormat(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT);
814 formatMap[GL_DEPTH_STENCIL] = TextureFormat(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH_STENCIL);
815
816 if (glu::IsES3Compatible(gl))
817 {
818 formatMap[GL_RED] = TextureFormat(GL_RED, GL_UNSIGNED_BYTE, GL_R8);
819 formatMap[GL_RG] = TextureFormat(GL_RG, GL_UNSIGNED_BYTE, GL_RG8);
820 formatMap[GL_DEPTH_COMPONENT] =
821 TextureFormat(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT16);
822 formatMap[GL_DEPTH_STENCIL] =
823 TextureFormat(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8_OES);
824 formatMap[GL_RED_INTEGER] = TextureFormat(GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_R8UI);
825 formatMap[GL_RG_INTEGER] = TextureFormat(GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_RG8UI);
826 formatMap[GL_SRGB] = TextureFormat(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB);
827 formatMap[GL_SRGB_ALPHA] = TextureFormat(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB);
828 }
829 }
830
831 ReferenceFormatMap::iterator formatIterator = formatMap.find(m_testFormat.format);
832 if (formatIterator == formatMap.end())
833 {
834 m_testCtx.getLog() << tcu::TestLog::Message << "Error: Unknown 2D texture format "
835 << glu::getTextureFormatStr(m_testFormat.format).toString() << tcu::TestLog::EndMessage;
836 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
837 return STOP;
838 }
839
840 const TextureFormat& referenceFormat = formatIterator->second;
841
842 auto referenceInternalFormat = referenceFormat.internalFormat;
843 auto referenceType = referenceFormat.type;
844
845 // Above lookup only considers m_testFormat.format
846 if (m_testFormat.internalFormat == GL_DEPTH_COMPONENT32F)
847 {
848 referenceInternalFormat = GL_DEPTH_COMPONENT24;
849 referenceType = GL_UNSIGNED_INT;
850 }
851
852 if (m_renderWidth > m_context.getRenderTarget().getWidth())
853 m_renderWidth = m_context.getRenderTarget().getWidth();
854 if (m_renderHeight > m_context.getRenderTarget().getHeight())
855 m_renderHeight = m_context.getRenderTarget().getHeight();
856
857 // Setup viewport
858 gl.viewport(0, 0, m_renderWidth, m_renderHeight);
859 gl.pixelStorei(GL_UNPACK_ALIGNMENT, 1);
860
861 // Create test and reference texture
862 GLuint testTextureName = createTexture(m_testFormat.internalFormat, m_testFormat.format, m_testFormat.type,
863 m_testFormat.minFilter, m_testFormat.magFilter);
864 GLuint referenceTextureName = createTexture(referenceInternalFormat, referenceFormat.format, referenceType,
865 m_testFormat.minFilter, m_testFormat.magFilter);
866
867 // Create program that will render tested texture to screen
868 glu::ShaderProgram testProgram(
869 renderContext,
870 prepareTexturingProgramSources(m_testFormat.internalFormat, m_testFormat.format, m_testFormat.type));
871 if (!testProgram.isOk())
872 {
873 m_testCtx.getLog() << testProgram;
874 TCU_FAIL("Compile failed");
875 }
876 gl.useProgram(testProgram.getProgram());
877 gl.uniform1i(gl.getUniformLocation(testProgram.getProgram(), "sampler"), 0);
878
879 // Render textured quad with tested texture
880 gl.bindTexture(GL_TEXTURE_2D, testTextureName);
881 renderTexturedQuad(testProgram.getProgram());
882 tcu::Surface testSurface(m_renderWidth, m_renderHeight);
883 glu::readPixels(renderContext, 0, 0, testSurface.getAccess());
884
885 // Create program that will render reference texture to screen
886 glu::ProgramSources referenceSources =
887 prepareTexturingProgramSources(referenceInternalFormat, referenceFormat.format, referenceType);
888 glu::ShaderProgram referenceProgram(renderContext, referenceSources);
889 if (!referenceProgram.isOk())
890 {
891 m_testCtx.getLog() << referenceProgram;
892 TCU_FAIL("Compile failed");
893 }
894 gl.useProgram(referenceProgram.getProgram());
895 gl.uniform1i(gl.getUniformLocation(referenceProgram.getProgram(), "sampler"), 0);
896
897 // Render textured quad with reference texture
898 gl.bindTexture(GL_TEXTURE_2D, referenceTextureName);
899 renderTexturedQuad(referenceProgram.getProgram());
900 tcu::Surface referenceSurface(m_renderWidth, m_renderHeight);
901 glu::readPixels(renderContext, 0, 0, referenceSurface.getAccess());
902
903 // Compare surfaces
904 if (tcu::fuzzyCompare(m_testCtx.getLog(), "Result", "Image comparison result", referenceSurface, testSurface, 0.05f,
905 tcu::COMPARE_LOG_RESULT))
906 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
907 else
908 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
909
910 gl.deleteTextures(1, &testTextureName);
911 gl.deleteTextures(1, &referenceTextureName);
912
913 return STOP;
914 }
915
916 class CopyTexImageCase : public InternalformatCaseBase
917 {
918 public:
919 CopyTexImageCase(deqp::Context& context, const std::string& name, const CopyTexImageFormat& copyTexImageFormat);
~CopyTexImageCase()920 virtual ~CopyTexImageCase()
921 {
922 }
923
924 virtual tcu::TestNode::IterateResult iterate(void);
925
926 private:
927 CopyTexImageFormat m_testFormat;
928 };
929
CopyTexImageCase(deqp::Context & context,const std::string & name,const CopyTexImageFormat & copyTexImageFormat)930 CopyTexImageCase::CopyTexImageCase(deqp::Context& context, const std::string& name,
931 const CopyTexImageFormat& copyTexImageFormat)
932 : InternalformatCaseBase(context, name.c_str()), m_testFormat(copyTexImageFormat)
933 {
934 }
935
iterate(void)936 tcu::TestNode::IterateResult CopyTexImageCase::iterate(void)
937 {
938 if (!requiredExtensionsSupported(m_testFormat.requiredExtension, m_testFormat.secondReqiredExtension))
939 return STOP;
940
941 glu::RenderContext& renderContext = m_context.getRenderContext();
942 const Functions& gl = renderContext.getFunctions();
943
944 // Determine texture format and type
945 GLint textureInternalFormat = m_testFormat.internalFormat;
946 GLuint textureType = getTypeFromInternalFormat(textureInternalFormat);
947 GLuint textureFormat = getUnsizedFormatFromInternalFormat(textureInternalFormat);
948 const bool isSRGB = textureInternalFormat == GL_SRGB8 || textureInternalFormat == GL_SRGB8_ALPHA8;
949
950 // Create program that will render texture to screen
951 glu::ShaderProgram program(renderContext,
952 prepareTexturingProgramSources(textureInternalFormat, textureFormat, textureType));
953 if (!program.isOk())
954 {
955 m_testCtx.getLog() << program;
956 TCU_FAIL("Compile failed");
957 }
958 gl.useProgram(program.getProgram());
959 gl.uniform1i(gl.getUniformLocation(program.getProgram(), "sampler"), 0);
960 gl.viewport(0, 0, m_renderWidth, m_renderHeight);
961
962 // Create required textures
963 GLuint referenceTextureId = createTexture(textureInternalFormat, textureFormat, textureType, m_testFormat.minFilter,
964 m_testFormat.magFilter);
965 GLuint copiedTextureId = createTexture(textureInternalFormat, textureFormat, textureType, m_testFormat.minFilter,
966 m_testFormat.magFilter, false);
967
968 // Create main RGBA framebuffer - this is needed because some default framebuffer may be RGB
969 GLuint mainFboId = 0;
970 gl.genFramebuffers(1, &mainFboId);
971 gl.bindFramebuffer(GL_FRAMEBUFFER, mainFboId);
972 GLuint mainFboColorTextureId =
973 createTexture(isSRGB ? GL_SRGB8_ALPHA8 : GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, GL_NEAREST, false);
974 gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mainFboColorTextureId, 0);
975
976 // Render reference texture to main FBO and grab it
977 gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
978 gl.bindTexture(GL_TEXTURE_2D, referenceTextureId);
979 renderTexturedQuad(program.getProgram());
980 tcu::Surface referenceSurface(m_renderWidth, m_renderHeight);
981 glu::readPixels(renderContext, 0, 0, referenceSurface.getAccess());
982
983 GLuint copyFboId = 0;
984 GLuint copyFboColorTextureId = 0;
985
986 // When possible use separate FBO for copy operation; create copy FBO and
987 // attach reference texture to color or depth attachment
988 gl.genFramebuffers(1, ©FboId);
989 gl.bindFramebuffer(GL_FRAMEBUFFER, copyFboId);
990
991 if (textureFormat == GL_DEPTH_COMPONENT)
992 {
993 copyFboColorTextureId = createTexture(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, GL_NEAREST, GL_NEAREST, false);
994 gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, copyFboColorTextureId, 0);
995 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture2D");
996 gl.framebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, referenceTextureId, 0);
997 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture2D");
998 }
999 else
1000 {
1001 gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, referenceTextureId, 0);
1002 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture2D");
1003 }
1004
1005 // If FBO is complete, then go back to use default FBO
1006 GLenum bufferStatus = gl.checkFramebufferStatus(GL_FRAMEBUFFER);
1007 if (bufferStatus != GL_FRAMEBUFFER_COMPLETE)
1008 {
1009 // Bind back to main FBO
1010 gl.bindFramebuffer(GL_FRAMEBUFFER, mainFboId);
1011 gl.deleteFramebuffers(1, ©FboId);
1012 if (copyFboColorTextureId)
1013 gl.deleteTextures(1, ©FboColorTextureId);
1014 // Check the bits of each channel first, because according the GLES3.2 spec, the component sizes of internalformat
1015 // must exactly match the corresponding component sizes of the source buffer's effective internal format.
1016 if (glu::isContextTypeES(renderContext.getType()) && getTypeFromInternalFormat(textureInternalFormat) != GL_UNSIGNED_BYTE)
1017 {
1018 m_testCtx.getLog() << tcu::TestLog::Message << "Not supported: The component sizes of internalformat do not exactly "
1019 << "match the corresponding component sizes of the source buffer's effective internal format." << tcu::TestLog::EndMessage;
1020 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "The test format isn't renderable, and the component sizes of "
1021 "internalformat do not exactly match the corresponding component sizes of the source buffer's effective internal format.");
1022 gl.deleteFramebuffers(1, &mainFboId);
1023 gl.deleteTextures(1, &mainFboColorTextureId);
1024 gl.deleteTextures(1, &copiedTextureId);
1025 gl.deleteTextures(1, &referenceTextureId);
1026 return STOP;
1027 }
1028 }
1029
1030 // Copy attachment from copy FBO to tested texture (if copy FBO couldn't be created
1031 // then copying will be done from main FBO color attachment)
1032 gl.bindTexture(GL_TEXTURE_2D, copiedTextureId);
1033 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture");
1034 gl.copyTexImage2D(GL_TEXTURE_2D, 0, textureInternalFormat, 0, 0, m_renderWidth, m_renderHeight, 0);
1035 GLU_EXPECT_NO_ERROR(gl.getError(), "glCopyTexImage2D");
1036
1037 // Make sure that main FBO is bound
1038 gl.bindFramebuffer(GL_FRAMEBUFFER, mainFboId);
1039
1040 // Render and grab tested texture
1041 gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1042 gl.bindTexture(GL_TEXTURE_2D, copiedTextureId);
1043 renderTexturedQuad(program.getProgram());
1044 tcu::Surface resultSurface(m_renderWidth, m_renderHeight);
1045 glu::readPixels(renderContext, 0, 0, resultSurface.getAccess());
1046
1047 // Compare surfaces
1048 if (tcu::fuzzyCompare(m_testCtx.getLog(), "Result", "Image comparison result", referenceSurface, resultSurface,
1049 0.05f, tcu::COMPARE_LOG_RESULT))
1050 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1051 else
1052 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1053
1054 // Cleanup
1055 gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
1056 gl.deleteFramebuffers(1, &mainFboId);
1057 gl.deleteTextures(1, &mainFboColorTextureId);
1058 gl.deleteTextures(1, &copiedTextureId);
1059 gl.deleteTextures(1, &referenceTextureId);
1060
1061 return STOP;
1062 }
1063
1064 class RenderbufferCase : public InternalformatCaseBase
1065 {
1066 public:
1067 RenderbufferCase(deqp::Context& context, const std::string& name, const RenderbufferFormat& renderbufferFormat);
1068 virtual ~RenderbufferCase();
1069
1070 virtual tcu::TestNode::IterateResult iterate(void);
1071
1072 private:
1073 void constructOrthoProjMatrix(GLfloat* mat4, GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n,
1074 GLfloat f) const;
1075 bool createFramebuffer();
1076 void deleteFramebuffer();
1077 GLuint createAndAttachRenderBuffer(GLenum rbFormat, GLenum fbAttachment);
1078 void renderColoredQuad(GLuint programId, const float* positions) const;
1079 glu::ProgramSources prepareColoringProgramSources(GLenum format, GLenum type) const;
1080 void convertUInt(const tcu::PixelBufferAccess &src, const tcu::PixelBufferAccess &dst);
1081 void convertsRGB(const tcu::PixelBufferAccess& src, const tcu::PixelBufferAccess& dst);
1082 void convertsRGBA(const tcu::PixelBufferAccess& src, const tcu::PixelBufferAccess& dst);
1083 void convertUInt_2_10_10_10_rev(const tcu::PixelBufferAccess &src, const tcu::PixelBufferAccess &dst);
1084
1085 private:
1086 GLuint m_fbo;
1087 GLuint m_rbColor;
1088 GLuint m_rbDepth;
1089 GLuint m_rbStencil;
1090 RenderbufferFormat m_testFormat;
1091 };
1092
RenderbufferCase(deqp::Context & context,const std::string & name,const RenderbufferFormat & renderbufferFormat)1093 RenderbufferCase::RenderbufferCase(deqp::Context& context, const std::string& name,
1094 const RenderbufferFormat& renderbufferFormat)
1095 : InternalformatCaseBase(context, name.c_str())
1096 , m_fbo(0)
1097 , m_rbColor(0)
1098 , m_rbDepth(0)
1099 , m_rbStencil(0)
1100 , m_testFormat(renderbufferFormat)
1101 {
1102 }
1103
~RenderbufferCase()1104 RenderbufferCase::~RenderbufferCase()
1105 {
1106 }
1107
iterate(void)1108 tcu::TestNode::IterateResult RenderbufferCase::iterate(void)
1109 {
1110 if (!requiredExtensionsSupported(m_testFormat.requiredExtension, m_testFormat.secondReqiredExtension))
1111 return STOP;
1112
1113 glu::RenderContext& renderContext = m_context.getRenderContext();
1114 const Functions& gl = renderContext.getFunctions();
1115
1116 int maxRenderbufferSize;
1117 gl.getIntegerv(GL_MAX_RENDERBUFFER_SIZE, &maxRenderbufferSize);
1118 int windowWidth = m_context.getRenderTarget().getWidth();
1119 int windowHeight = m_context.getRenderTarget().getHeight();
1120 m_renderWidth = (windowWidth > maxRenderbufferSize) ? maxRenderbufferSize : windowWidth;
1121 m_renderHeight = (windowHeight > maxRenderbufferSize) ? maxRenderbufferSize : windowHeight;
1122
1123 float w = static_cast<float>(m_renderWidth);
1124 float h = static_cast<float>(m_renderHeight);
1125 static const float bigQuadPositionsSet[] = { 0, 0, 0, w, 0, 0, 0, h, 0, w, h, 0 };
1126 static const float smallQuadPositionsSet[] = { 5.0f, 5.0f, 0.5f, w / 2, 5.0f, 0.5f,
1127 5.0f, h / 2, 0.5f, w / 2, h / 2, 0.5f };
1128
1129 bool stencilRenderbufferAvailable =
1130 (m_testFormat.type == RENDERBUFFER_STENCIL) || (m_testFormat.type == RENDERBUFFER_DEPTH_STENCIL);
1131
1132 GLenum testFormat = getUnsizedFormatFromInternalFormat(m_testFormat.format);
1133 GLenum testType = getTypeFromInternalFormat(m_testFormat.format);
1134 const bool isSRGB = m_testFormat.format == GL_SRGB8 || m_testFormat.format == GL_SRGB8_ALPHA8;
1135
1136 // We need surfaces for depth testing and stencil testing, and also for
1137 // storing the reference and the values for the format under testing
1138 tcu::Surface testSurface[2][2];
1139 for (GLuint loop1 = 0; loop1 < 2; loop1++)
1140 for (GLuint loop2 = 0; loop2 < 2; loop2++)
1141 testSurface[loop1][loop2].setSize(m_renderWidth, m_renderHeight);
1142
1143 GLint defaultFramebufferDepthBits = 0;
1144 GLint defaultFramebufferStencilBits = 0;
1145 if (glu::isContextTypeES(m_context.getRenderContext().getType()))
1146 {
1147 gl.getIntegerv(GL_DEPTH_BITS, &defaultFramebufferDepthBits);
1148 gl.getIntegerv(GL_STENCIL_BITS, &defaultFramebufferStencilBits);
1149 }
1150 else
1151 {
1152 GLint hasDepthBuffer = 0;
1153 GLint hasStencilBuffer = 0;
1154
1155 gl.getNamedFramebufferAttachmentParameteriv(0, GL_DEPTH, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE,
1156 &hasDepthBuffer);
1157 gl.getNamedFramebufferAttachmentParameteriv(0, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE,
1158 &hasStencilBuffer);
1159
1160 if (hasDepthBuffer != GL_NONE)
1161 gl.getNamedFramebufferAttachmentParameteriv(0, GL_DEPTH, GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE,
1162 &defaultFramebufferDepthBits);
1163
1164 if (hasStencilBuffer != GL_NONE)
1165 gl.getNamedFramebufferAttachmentParameteriv(0, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE,
1166 &defaultFramebufferStencilBits);
1167 }
1168
1169 // Create two programs for rendering, one for rendering into default FB, and
1170 // a second one to render in our created FB
1171
1172 glu::ShaderProgram program0(renderContext,
1173 prepareColoringProgramSources(GL_RGBA, GL_UNSIGNED_BYTE));
1174 glu::ShaderProgram program1(renderContext, prepareColoringProgramSources(testFormat, testType));
1175
1176 std::vector<glu::ShaderProgram*> programs;
1177 programs.push_back(&program0);
1178 programs.push_back(&program1);
1179
1180 bool testNonStencil = (m_testFormat.type != RENDERBUFFER_STENCIL);
1181 bool testStencil = defaultFramebufferStencilBits && stencilRenderbufferAvailable;
1182
1183 for (GLuint loop = 0; loop < 2; loop++)
1184 {
1185 if (!programs[loop]->isOk())
1186 {
1187 m_testCtx.getLog() << *programs[loop];
1188 TCU_FAIL("Compile failed");
1189 }
1190
1191 gl.useProgram(programs[loop]->getProgram());
1192 GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram");
1193
1194 float mvpMatrix[16];
1195 constructOrthoProjMatrix(mvpMatrix, 0.0, w, 0.0f, h, 1.0f, -1.0f);
1196 GLint mvpUniformLocation = gl.getUniformLocation(programs[loop]->getProgram(), "mvpMatrix");
1197 gl.uniformMatrix4fv(mvpUniformLocation, 1, 0, mvpMatrix);
1198
1199 gl.bindTexture(GL_TEXTURE_2D, 0);
1200 gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
1201 gl.viewport(0, 0, m_renderWidth, m_renderHeight);
1202
1203 if (testNonStencil)
1204 {
1205 if (loop && !createFramebuffer())
1206 return STOP;
1207
1208 if (defaultFramebufferDepthBits)
1209 {
1210 gl.enable(GL_DEPTH_TEST);
1211 gl.depthFunc(GL_LESS);
1212 }
1213
1214 gl.bindFramebuffer(GL_FRAMEBUFFER, loop ? m_fbo : m_context.getRenderContext().getDefaultFramebuffer());
1215
1216 gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1217
1218 if (defaultFramebufferDepthBits)
1219 {
1220 // Draw a small quad just in the z buffer
1221 gl.colorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
1222 renderColoredQuad(programs[loop]->getProgram(), smallQuadPositionsSet);
1223
1224 // Large quad should be drawn on top small one to verify that the depth test is working
1225 gl.colorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1226 }
1227
1228 // Draws large quad
1229 renderColoredQuad(programs[loop]->getProgram(), bigQuadPositionsSet);
1230
1231 if (loop && isSRGB)
1232 {
1233 de::ArrayBuffer<deUint32> pixels;
1234 pixels.setStorage(4 * m_renderWidth * m_renderHeight);
1235 tcu::PixelBufferAccess pixelBuffer(tcu::TextureFormat(tcu::TextureFormat::sRGBA, tcu::TextureFormat::UNSIGNED_INT8),
1236 m_renderWidth, m_renderHeight, 1, pixels.getPtr());
1237 glu::readPixels(renderContext, 0, 0, pixelBuffer);
1238 if (m_testFormat.format == GL_SRGB8_ALPHA8)
1239 convertsRGBA(pixelBuffer, testSurface[0][loop].getAccess());
1240 else
1241 convertsRGB(pixelBuffer, testSurface[0][loop].getAccess());
1242 }
1243 else if (loop &&
1244 (testFormat == GL_RGBA_INTEGER || testFormat == GL_RG_INTEGER || testFormat == GL_RED_INTEGER))
1245 {
1246 de::ArrayBuffer<deUint32> pixels;
1247 pixels.setStorage(4 * m_renderWidth * m_renderHeight);
1248 tcu::PixelBufferAccess pixelBuffer(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNSIGNED_INT32),
1249 m_renderWidth, m_renderHeight, 1, pixels.getPtr());
1250 glu::readPixels(renderContext, 0, 0, pixelBuffer);
1251 if (testType == GL_UNSIGNED_INT_2_10_10_10_REV)
1252 convertUInt_2_10_10_10_rev(pixelBuffer, testSurface[0][loop].getAccess());
1253 else
1254 convertUInt(pixelBuffer, testSurface[0][loop].getAccess());
1255 }
1256 else
1257 {
1258 glu::readPixels(renderContext, 0, 0, testSurface[0][loop].getAccess());
1259 }
1260 }
1261
1262 if (loop)
1263 deleteFramebuffer();
1264
1265 if (defaultFramebufferStencilBits && stencilRenderbufferAvailable)
1266 {
1267 gl.disable(GL_DEPTH_TEST);
1268 gl.enable(GL_STENCIL_TEST);
1269
1270 if (loop && !createFramebuffer())
1271 return STOP;
1272
1273 gl.bindFramebuffer(GL_FRAMEBUFFER, loop ? m_fbo : m_context.getRenderContext().getDefaultFramebuffer());
1274 gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1275
1276 // Draw a rect scissored to half the screen height, incrementing the stencil buffer.
1277 gl.enable(GL_SCISSOR_TEST);
1278 gl.scissor(0, 0, m_renderWidth, m_renderHeight / 2);
1279 gl.stencilFunc(GL_ALWAYS, 0x0, 0xFF);
1280 gl.stencilOp(GL_ZERO, GL_INCR, GL_INCR);
1281 GLU_EXPECT_NO_ERROR(gl.getError(), "glStencilOp");
1282 renderColoredQuad(programs[loop]->getProgram(), bigQuadPositionsSet);
1283 gl.disable(GL_SCISSOR_TEST);
1284
1285 // Only draw where stencil is equal to 1
1286 gl.stencilFunc(GL_EQUAL, 0x01, 0xFF);
1287 gl.stencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
1288 gl.clear(GL_COLOR_BUFFER_BIT);
1289 renderColoredQuad(programs[loop]->getProgram(), bigQuadPositionsSet);
1290
1291 glu::readPixels(renderContext, 0, 0, testSurface[1][loop].getAccess());
1292
1293 gl.disable(GL_STENCIL_TEST);
1294
1295 if (loop)
1296 deleteFramebuffer();
1297 }
1298 }
1299
1300 // Compare surfaces for non-stencil
1301 if (testNonStencil && !tcu::fuzzyCompare(m_testCtx.getLog(), "Result", "Image comparison result",
1302 testSurface[0][0], testSurface[0][1],
1303 0.05f, tcu::COMPARE_LOG_RESULT))
1304 {
1305 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Depth subtest failed");
1306 return STOP;
1307 }
1308
1309 // Compare surfaces for stencil
1310 if (testStencil && !tcu::fuzzyCompare(m_testCtx.getLog(), "Result", "Image comparison result",
1311 testSurface[1][0], testSurface[1][1],
1312 0.05f, tcu::COMPARE_LOG_RESULT))
1313 {
1314 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Stencil subtest failed");
1315 return STOP;
1316 }
1317
1318 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1319 return STOP;
1320 }
1321
constructOrthoProjMatrix(GLfloat * mat4,GLfloat l,GLfloat r,GLfloat b,GLfloat t,GLfloat n,GLfloat f) const1322 void RenderbufferCase::constructOrthoProjMatrix(GLfloat* mat4, GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n,
1323 GLfloat f) const
1324 {
1325 GLfloat inv_width = 1.0f / (r - l);
1326 GLfloat inv_height = 1.0f / (t - b);
1327 GLfloat inv_depth = 1.0f / (f - n);
1328
1329 memset(mat4, 0, sizeof(GLfloat) * 16);
1330 /*
1331 0 4 8 12
1332 1 5 9 13
1333 2 6 10 14
1334 3 7 11 15
1335 */
1336
1337 mat4[0] = 2.0f * inv_width;
1338 mat4[5] = 2.0f * inv_height;
1339 mat4[10] = 2.0f * inv_depth;
1340
1341 mat4[12] = -(r + l) * inv_width;
1342 mat4[13] = -(t + b) * inv_height;
1343 mat4[14] = -(f + n) * inv_depth;
1344 mat4[15] = 1.0f;
1345 }
1346
createFramebuffer()1347 bool RenderbufferCase::createFramebuffer()
1348 {
1349 glu::RenderContext& renderContext = m_context.getRenderContext();
1350 const Functions& gl = renderContext.getFunctions();
1351
1352 gl.genFramebuffers(1, &m_fbo);
1353 gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
1354
1355 if (m_testFormat.type == RENDERBUFFER_COLOR)
1356 {
1357 m_rbColor = createAndAttachRenderBuffer(m_testFormat.format, GL_COLOR_ATTACHMENT0);
1358 m_rbDepth = createAndAttachRenderBuffer(GL_DEPTH_COMPONENT16, GL_DEPTH_ATTACHMENT);
1359 }
1360 else
1361 {
1362 m_rbColor = createAndAttachRenderBuffer(GL_RGBA8, GL_COLOR_ATTACHMENT0);
1363 if (m_testFormat.type == RENDERBUFFER_DEPTH)
1364 m_rbDepth = createAndAttachRenderBuffer(m_testFormat.format, GL_DEPTH_ATTACHMENT);
1365 else if (m_testFormat.type == RENDERBUFFER_STENCIL)
1366 m_rbStencil = createAndAttachRenderBuffer(m_testFormat.format, GL_STENCIL_ATTACHMENT);
1367 else if (m_testFormat.type == RENDERBUFFER_DEPTH_STENCIL)
1368 {
1369 if (glu::contextSupports(renderContext.getType(), glu::ApiType::es(2, 0)))
1370 {
1371 m_rbDepth = createAndAttachRenderBuffer(m_testFormat.format, GL_DEPTH_ATTACHMENT);
1372 gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_rbDepth);
1373 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer");
1374 }
1375 else
1376 m_rbDepth = createAndAttachRenderBuffer(m_testFormat.format, GL_DEPTH_STENCIL_ATTACHMENT);
1377 }
1378 }
1379
1380 GLenum bufferStatus = gl.checkFramebufferStatus(GL_FRAMEBUFFER);
1381 if (bufferStatus == GL_FRAMEBUFFER_UNSUPPORTED)
1382 {
1383 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Unsuported framebuffer");
1384 return false;
1385 }
1386 else if (bufferStatus != GL_FRAMEBUFFER_COMPLETE)
1387 {
1388 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Framebuffer not complete");
1389 return false;
1390 }
1391
1392 return true;
1393 }
1394
deleteFramebuffer()1395 void RenderbufferCase::deleteFramebuffer()
1396 {
1397 const Functions& gl = m_context.getRenderContext().getFunctions();
1398
1399 gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
1400 if (m_fbo)
1401 gl.deleteFramebuffers(1, &m_fbo);
1402 if (m_rbColor)
1403 gl.deleteRenderbuffers(1, &m_rbColor);
1404 if (m_rbDepth)
1405 gl.deleteRenderbuffers(1, &m_rbDepth);
1406 if (m_rbStencil)
1407 gl.deleteRenderbuffers(1, &m_rbStencil);
1408 }
1409
createAndAttachRenderBuffer(GLenum rbFormat,GLenum fbAttachment)1410 GLuint RenderbufferCase::createAndAttachRenderBuffer(GLenum rbFormat, GLenum fbAttachment)
1411 {
1412 const Functions& gl = m_context.getRenderContext().getFunctions();
1413
1414 GLuint rbName;
1415
1416 gl.genRenderbuffers(1, &rbName);
1417 gl.bindRenderbuffer(GL_RENDERBUFFER, rbName);
1418 gl.renderbufferStorage(GL_RENDERBUFFER, rbFormat, m_renderWidth, m_renderHeight);
1419 GLU_EXPECT_NO_ERROR(gl.getError(), "glRenderbufferStorage");
1420 gl.framebufferRenderbuffer(GL_FRAMEBUFFER, fbAttachment, GL_RENDERBUFFER, rbName);
1421 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer");
1422
1423 return rbName;
1424 }
1425
renderColoredQuad(GLuint programId,const float * positions) const1426 void RenderbufferCase::renderColoredQuad(GLuint programId, const float* positions) const
1427 {
1428 // Prepare data for rendering
1429 static const deUint16 quadIndices[] = { 0, 1, 2, 2, 1, 3 };
1430 static const float colors[] = {
1431 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,
1432 };
1433 const glu::VertexArrayBinding vertexArrays[] = { glu::va::Float("position", 3, 4, 0, positions),
1434 glu::va::Float("color", 4, 4, 0, colors) };
1435
1436 glu::draw(m_context.getRenderContext(), programId, DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays,
1437 glu::pr::TriangleStrip(DE_LENGTH_OF_ARRAY(quadIndices), quadIndices));
1438 }
1439
prepareColoringProgramSources(GLenum format,GLenum type) const1440 glu::ProgramSources RenderbufferCase::prepareColoringProgramSources(GLenum format, GLenum type) const
1441 {
1442 glu::RenderContext& renderContext = m_context.getRenderContext();
1443 glu::ContextType contextType = renderContext.getType();
1444 glu::GLSLVersion glslVersion = glu::getContextTypeGLSLVersion(contextType);
1445 std::string versionDeclaration = glu::getGLSLVersionDeclaration(glslVersion);
1446
1447 std::map<std::string, std::string> specializationMap;
1448
1449 versionDeclaration += "\n";
1450 std::string vs = versionDeclaration;
1451 std::string fs = versionDeclaration;
1452 if (glu::contextSupports(contextType, glu::ApiType::es(3, 0)) || glu::isContextTypeGLCore(contextType))
1453 {
1454 vs += "in highp vec3 position;\n"
1455 "in highp vec4 color;\n"
1456 "out highp vec4 fColor;\n"
1457 "uniform mat4 mvpMatrix;\n"
1458 "void main()\n"
1459 "{\n"
1460 " fColor = color;\n"
1461 " gl_Position = mvpMatrix * vec4(position, 1.0);\n"
1462 "}\n";
1463 fs += "in highp vec4 fColor;\n"
1464 "out ${COLOR_DATA} color;\n"
1465 "void main()\n"
1466 "{\n"
1467 " color = ${COMPUTE_COLOR};\n"
1468 "}\n";
1469 }
1470 else
1471 {
1472 vs += "attribute highp vec3 position;\n"
1473 "attribute highp vec4 color;\n"
1474 "varying highp vec4 fColor;\n"
1475 "uniform mat4 mvpMatrix;\n"
1476 "void main()\n"
1477 "{\n"
1478 " fColor = color;\n"
1479 " gl_Position = mvpMatrix * vec4(position, 1.0);\n"
1480 "}\n";
1481 fs += "varying highp vec4 fColor;\n"
1482 "void main()\n"
1483 "{\n"
1484 " gl_FragColor = fColor;\n"
1485 "}\n";
1486 }
1487
1488 if (format == GL_RGBA_INTEGER)
1489 {
1490 std::string compute_color = "${COLOR_DATA}("
1491 "${MAX_RED} * fColor.r, "
1492 "${MAX_GREEN} * fColor.g, "
1493 "${MAX_BLUE} * fColor.b, "
1494 "${MAX_ALPHA} * fColor.a)";
1495
1496 if (type == GL_UNSIGNED_INT_2_10_10_10_REV)
1497 {
1498 specializationMap["MAX_RED"] = "1023";
1499 specializationMap["MAX_GREEN"] = "1023";
1500 specializationMap["MAX_BLUE"] = "1023";
1501 specializationMap["MAX_ALPHA"] = "3";
1502 }
1503 else
1504 {
1505 specializationMap["MAX_RED"] = "255";
1506 specializationMap["MAX_GREEN"] = "255";
1507 specializationMap["MAX_BLUE"] = "255";
1508 specializationMap["MAX_ALPHA"] = "255";
1509 }
1510 specializationMap["COLOR_DATA"] = "uvec4";
1511 specializationMap["COMPUTE_COLOR"] = tcu::StringTemplate(compute_color).specialize(specializationMap);
1512 }
1513 else
1514 {
1515 specializationMap["COLOR_DATA"] = "highp vec4";
1516 specializationMap["COMPUTE_COLOR"] = "fColor";
1517 }
1518
1519 vs = tcu::StringTemplate(vs).specialize(specializationMap);
1520 fs = tcu::StringTemplate(fs).specialize(specializationMap);
1521 return glu::makeVtxFragSources(vs.c_str(), fs.c_str());
1522 }
1523
1524 typedef TextureFormat TF;
1525 typedef CopyTexImageFormat CF;
1526 typedef RenderbufferFormat RF;
1527
1528 struct TestData
1529 {
1530 std::vector<TextureFormat> texture2DFormats;
1531 std::vector<CopyTexImageFormat> copyTexImageFormats;
1532 std::vector<RenderbufferFormat> renderbufferFormats;
1533 };
1534
1535 /** Constructor.
1536 *
1537 * @param context Rendering context.
1538 */
InternalformatTests(deqp::Context & context)1539 InternalformatTests::InternalformatTests(deqp::Context& context)
1540 : TestCaseGroup(context, "internalformat", "Texture internalformat tests")
1541 {
1542 }
1543
1544 template <typename Data, unsigned int Size>
append(std::vector<Data> & dataVector,const Data (& dataArray)[Size])1545 void InternalformatTests::append(std::vector<Data>& dataVector, const Data (&dataArray)[Size])
1546 {
1547 dataVector.insert(dataVector.end(), dataArray, dataArray + Size);
1548 }
1549
getESTestData(TestData & testData,glu::ContextType & contextType)1550 void InternalformatTests::getESTestData(TestData& testData, glu::ContextType& contextType)
1551 {
1552 TextureFormat commonTexture2DFormats[] = {
1553 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA),
1554 TF(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB),
1555 TF(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA),
1556 TF(GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE_ALPHA),
1557 TF(GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE),
1558 TF(GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA),
1559 TF(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGBA, EXT_texture_type_2_10_10_10_REV),
1560 TF(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2, EXT_texture_type_2_10_10_10_REV),
1561 TF(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB5_A1, EXT_texture_type_2_10_10_10_REV),
1562 TF(GL_RGB, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB, EXT_texture_type_2_10_10_10_REV),
1563 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT, OES_depth_texture),
1564 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT, OES_depth_texture),
1565 TF(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH_STENCIL, OES_packed_depth_stencil, OES_depth_texture),
1566 TF(GL_RGB, GL_HALF_FLOAT_OES, GL_RGB, OES_texture_half_float),
1567 TF(GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA, OES_texture_half_float),
1568 TF(GL_RGB, GL_HALF_FLOAT_OES, GL_RGB, OES_texture_half_float_linear, DE_NULL, GL_LINEAR, GL_LINEAR),
1569 TF(GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA, OES_texture_half_float_linear, DE_NULL, GL_LINEAR, GL_LINEAR),
1570 TF(GL_RGB, GL_FLOAT, GL_RGB32F, OES_texture_float),
1571 TF(GL_RGBA, GL_FLOAT, GL_RGBA32F, OES_texture_float),
1572 TF(GL_RGB, GL_FLOAT, GL_RGB32F, OES_texture_float_linear, DE_NULL, GL_LINEAR, GL_LINEAR),
1573 TF(GL_RGBA, GL_FLOAT, GL_RGBA32F, OES_texture_float_linear, DE_NULL, GL_LINEAR, GL_LINEAR),
1574 };
1575
1576 CopyTexImageFormat commonCopyTexImageFormats[] = {
1577 CF(GL_RGB),
1578 CF(GL_RGBA),
1579 CF(GL_ALPHA),
1580 CF(GL_LUMINANCE),
1581 CF(GL_LUMINANCE_ALPHA),
1582 };
1583
1584 RenderbufferFormat commonRenderbufferFormats[] = {
1585 RF(GL_RGBA8, RENDERBUFFER_COLOR, OES_rgb8_rgba8),
1586 RF(GL_RGB8, RENDERBUFFER_COLOR, OES_rgb8_rgba8),
1587 };
1588
1589 append(testData.texture2DFormats, commonTexture2DFormats);
1590 append(testData.copyTexImageFormats, commonCopyTexImageFormats);
1591 append(testData.renderbufferFormats, commonRenderbufferFormats);
1592
1593 if (glu::contextSupports(contextType, glu::ApiType::es(3, 0)))
1594 {
1595 TextureFormat es3Texture2DFormats[] = {
1596 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8),
1597 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGB5_A1),
1598 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA4),
1599 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_SRGB8_ALPHA8),
1600 TF(GL_RGBA, GL_BYTE, GL_RGBA8_SNORM),
1601 TF(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4),
1602 TF(GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1),
1603 TF(GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F),
1604 TF(GL_RGBA, GL_FLOAT, GL_RGBA16F),
1605 TF(GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_RGBA8UI),
1606 TF(GL_RGBA_INTEGER, GL_BYTE, GL_RGBA8I),
1607 TF(GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_RGBA16UI),
1608 TF(GL_RGBA_INTEGER, GL_SHORT, GL_RGBA16I),
1609 TF(GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_RGBA32UI),
1610 TF(GL_RGBA_INTEGER, GL_INT, GL_RGBA32I),
1611 TF(GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2UI),
1612 TF(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8),
1613 TF(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB565),
1614 TF(GL_RGB, GL_UNSIGNED_BYTE, GL_SRGB8),
1615 TF(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565),
1616 TF(GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_R11F_G11F_B10F),
1617 TF(GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_RGB9_E5),
1618 TF(GL_RGB, GL_HALF_FLOAT, GL_RGB16F),
1619 TF(GL_RGB, GL_HALF_FLOAT, GL_R11F_G11F_B10F),
1620 TF(GL_RGB, GL_HALF_FLOAT, GL_RGB9_E5),
1621 TF(GL_RGB, GL_FLOAT, GL_RGB16F),
1622 TF(GL_RGB, GL_FLOAT, GL_R11F_G11F_B10F),
1623 TF(GL_RGB, GL_FLOAT, GL_RGB9_E5),
1624 TF(GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_RGB8UI),
1625 TF(GL_RGB_INTEGER, GL_BYTE, GL_RGB8I),
1626 TF(GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_RGB16UI),
1627 TF(GL_RGB_INTEGER, GL_SHORT, GL_RGB16I),
1628 TF(GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_RGB32UI),
1629 TF(GL_RGB_INTEGER, GL_INT, GL_RGB32I),
1630 TF(GL_RG, GL_UNSIGNED_BYTE, GL_RG8),
1631 TF(GL_RG, GL_HALF_FLOAT, GL_RG16F),
1632 TF(GL_RG, GL_FLOAT, GL_RG32F),
1633 TF(GL_RG, GL_FLOAT, GL_RG16F),
1634 TF(GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_RG8UI),
1635 TF(GL_RG_INTEGER, GL_BYTE, GL_RG8I),
1636 TF(GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_RG16UI),
1637 TF(GL_RG_INTEGER, GL_SHORT, GL_RG16I),
1638 TF(GL_RG_INTEGER, GL_UNSIGNED_INT, GL_RG32UI),
1639 TF(GL_RG_INTEGER, GL_INT, GL_RG32I),
1640 TF(GL_RED, GL_UNSIGNED_BYTE, GL_R8),
1641 TF(GL_RED, GL_HALF_FLOAT, GL_R16F),
1642 TF(GL_RED, GL_FLOAT, GL_R32F),
1643 TF(GL_RED, GL_FLOAT, GL_R16F),
1644 TF(GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_R8UI),
1645 TF(GL_RED_INTEGER, GL_BYTE, GL_R8I),
1646 TF(GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_R16UI),
1647 TF(GL_RED_INTEGER, GL_SHORT, GL_R16I),
1648 TF(GL_RED_INTEGER, GL_UNSIGNED_INT, GL_R32UI),
1649 TF(GL_RED_INTEGER, GL_INT, GL_R32I),
1650 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16),
1651 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT24),
1652 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT16),
1653 TF(GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32F),
1654 TF(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8),
1655 TF(GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_DEPTH32F_STENCIL8),
1656 TF(GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGBA),
1657 TF(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB),
1658 };
1659
1660 CopyTexImageFormat es3CopyTexImageFormats[] = {
1661 CF(GL_RGBA4), CF(GL_RGB5_A1), CF(GL_RGB565), CF(GL_RGBA8),
1662 CF(GL_RGB8), CF(GL_SRGB8_ALPHA8), CF(GL_SRGB8), CF(GL_R11F_G11F_B10F),
1663 };
1664
1665 RenderbufferFormat es3RenderbufferFormats[] = {
1666 RF(GL_RGB5_A1, RENDERBUFFER_COLOR),
1667 RF(GL_SRGB8_ALPHA8, RENDERBUFFER_COLOR),
1668 RF(GL_DEPTH_COMPONENT32F, RENDERBUFFER_DEPTH),
1669 RF(GL_DEPTH32F_STENCIL8, RENDERBUFFER_DEPTH_STENCIL),
1670 };
1671
1672 append(testData.texture2DFormats, es3Texture2DFormats);
1673 append(testData.copyTexImageFormats, es3CopyTexImageFormats);
1674 append(testData.renderbufferFormats, es3RenderbufferFormats);
1675 }
1676 else if (glu::contextSupports(contextType, glu::ApiType::es(2, 0)))
1677 {
1678 TextureFormat es2Texture2DFormats[] = {
1679 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGB5_A1, OES_required_internalformat),
1680 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA4, OES_required_internalformat),
1681 TF(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB565, OES_required_internalformat),
1682 TF(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4, OES_required_internalformat),
1683 TF(GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGBA, OES_required_internalformat),
1684 TF(GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1, OES_required_internalformat),
1685 TF(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB, OES_required_internalformat),
1686 TF(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565, OES_required_internalformat),
1687 TF(GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_OES, OES_required_internalformat),
1688 TF(GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE4_ALPHA4_OES, OES_required_internalformat),
1689 TF(GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_OES, OES_required_internalformat),
1690 TF(GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_OES, OES_required_internalformat),
1691 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT16, OES_required_internalformat,
1692 OES_depth_texture),
1693 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16, OES_required_internalformat,
1694 OES_depth_texture),
1695 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT24, OES_required_internalformat, OES_depth24),
1696 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32, OES_required_internalformat, OES_depth32),
1697 };
1698
1699 CopyTexImageFormat es2CopyTexImageFormats[] = {
1700 CF(GL_RGB5_A1, OES_required_internalformat),
1701 CF(GL_RGB565, OES_required_internalformat),
1702 CF(GL_RGBA4, OES_required_internalformat),
1703 CF(GL_LUMINANCE4_ALPHA4_OES, OES_required_internalformat),
1704 CF(GL_LUMINANCE8_ALPHA8_OES, OES_required_internalformat),
1705 CF(GL_LUMINANCE8_OES, OES_required_internalformat),
1706 CF(GL_ALPHA8_OES, OES_required_internalformat),
1707 CF(GL_RGB10_A2, EXT_texture_type_2_10_10_10_REV, OES_required_internalformat),
1708 CF(GL_RGB10, EXT_texture_type_2_10_10_10_REV, OES_required_internalformat)
1709 };
1710
1711 RenderbufferFormat es2RenderbufferFormats[] = {
1712 RF(GL_STENCIL_INDEX1, RENDERBUFFER_STENCIL, OES_stencil1),
1713 RF(GL_STENCIL_INDEX4, RENDERBUFFER_STENCIL, OES_stencil4),
1714 RF(GL_STENCIL_INDEX8, RENDERBUFFER_STENCIL, OES_stencil8),
1715 RF(GL_DEPTH_COMPONENT16, RENDERBUFFER_DEPTH, OES_depth_texture),
1716 RF(GL_DEPTH_COMPONENT24, RENDERBUFFER_DEPTH, OES_depth24),
1717 RF(GL_DEPTH_COMPONENT32, RENDERBUFFER_DEPTH, OES_depth32),
1718 RF(GL_DEPTH24_STENCIL8, RENDERBUFFER_DEPTH_STENCIL, OES_packed_depth_stencil),
1719 RF(GL_RGB5_A1, RENDERBUFFER_COLOR, OES_required_internalformat),
1720 };
1721
1722 append(testData.texture2DFormats, es2Texture2DFormats);
1723 append(testData.copyTexImageFormats, es2CopyTexImageFormats);
1724 append(testData.renderbufferFormats, es2RenderbufferFormats);
1725 }
1726 }
1727
getGLTestData(TestData & testData,glu::ContextType &)1728 void InternalformatTests::getGLTestData(TestData& testData, glu::ContextType&)
1729 {
1730 TextureFormat commonTexture2DFormats[] = {
1731 TF(GL_RED, GL_BYTE, GL_R8_SNORM),
1732 TF(GL_RED, GL_SHORT, GL_R16_SNORM),
1733 TF(GL_RG, GL_BYTE, GL_RG8_SNORM),
1734 TF(GL_RG, GL_SHORT, GL_RG16_SNORM),
1735 TF(GL_RGB, GL_BYTE, GL_RGB8_SNORM),
1736 TF(GL_RGB, GL_SHORT, GL_RGB16_SNORM),
1737 TF(GL_RGBA, GL_BYTE, GL_RGBA8_SNORM),
1738 TF(GL_RGBA, GL_SHORT, GL_RGBA16_SNORM),
1739 TF(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGBA),
1740 TF(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2),
1741 TF(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB5_A1),
1742 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT, ARB_depth_texture),
1743 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16, ARB_depth_texture),
1744 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT, ARB_depth_texture),
1745 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT24, ARB_depth_texture),
1746 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32, ARB_depth_texture),
1747 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT16, ARB_depth_texture),
1748 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGB9_E5, EXT_texture_shared_exponent),
1749 TF(GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2UI, ARB_texture_rgb10_a2ui),
1750 TF(GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_RGBA32UI, EXT_texture_integer),
1751 TF(GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_RGB32UI, EXT_texture_integer),
1752 TF(GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_RGBA16UI, EXT_texture_integer),
1753 TF(GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_RGB16UI, EXT_texture_integer),
1754 TF(GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_RGBA8UI, EXT_texture_integer),
1755 TF(GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_RGB8UI, EXT_texture_integer),
1756 TF(GL_RGBA_INTEGER, GL_INT, GL_RGBA32I, EXT_texture_integer),
1757 TF(GL_RGB_INTEGER, GL_INT, GL_RGB32I, EXT_texture_integer),
1758 TF(GL_RGBA_INTEGER, GL_SHORT, GL_RGBA16I, EXT_texture_integer),
1759 TF(GL_RGB_INTEGER, GL_SHORT, GL_RGB16I, EXT_texture_integer),
1760 TF(GL_RGBA_INTEGER, GL_BYTE, GL_RGBA8I, EXT_texture_integer),
1761 TF(GL_RGB_INTEGER, GL_BYTE, GL_RGB8I, EXT_texture_integer),
1762 TF(GL_RED, GL_HALF_FLOAT, GL_R16F, ARB_texture_float),
1763 TF(GL_RG, GL_HALF_FLOAT, GL_RG16F, ARB_texture_float),
1764 TF(GL_RGB, GL_HALF_FLOAT, GL_RGB16F, ARB_texture_float),
1765 TF(GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F, ARB_texture_float),
1766 TF(GL_RED, GL_FLOAT, GL_R32F, ARB_texture_float),
1767 TF(GL_RG, GL_FLOAT, GL_RG32F, ARB_texture_float),
1768 TF(GL_RGB, GL_FLOAT, GL_RGB32F, ARB_texture_float),
1769 TF(GL_RGBA, GL_FLOAT, GL_RGBA32F, ARB_texture_float),
1770 };
1771
1772 CopyTexImageFormat commonCopyTexImageFormats[] = {
1773 CF(GL_DEPTH_COMPONENT16, ARB_depth_texture), CF(GL_DEPTH_COMPONENT24, ARB_depth_texture),
1774 CF(GL_DEPTH_COMPONENT32, ARB_depth_texture), CF(GL_RGB9_E5, EXT_texture_shared_exponent),
1775 CF(GL_RGB10_A2UI, ARB_texture_rgb10_a2ui), CF(GL_RGB10_A2),
1776 };
1777
1778 RenderbufferFormat commonRenderbufferFormats[] = {
1779 RF(GL_RGBA8, RENDERBUFFER_COLOR),
1780 RF(GL_RGB9_E5, RENDERBUFFER_COLOR, EXT_texture_shared_exponent),
1781 RF(GL_RGB10_A2UI, RENDERBUFFER_COLOR, ARB_texture_rgb10_a2ui),
1782 RF(GL_DEPTH24_STENCIL8, RENDERBUFFER_DEPTH_STENCIL),
1783 RF(GL_DEPTH_COMPONENT16, RENDERBUFFER_DEPTH, ARB_depth_texture),
1784 RF(GL_DEPTH_COMPONENT24, RENDERBUFFER_DEPTH, ARB_depth_texture),
1785 RF(GL_DEPTH_COMPONENT32, RENDERBUFFER_DEPTH, ARB_depth_texture),
1786 };
1787
1788 append(testData.texture2DFormats, commonTexture2DFormats);
1789 append(testData.copyTexImageFormats, commonCopyTexImageFormats);
1790 append(testData.renderbufferFormats, commonRenderbufferFormats);
1791 }
1792
formatToString(GLenum format)1793 std::string formatToString(GLenum format)
1794 {
1795 // this function extends glu::getTextureFormatStr by formats used in thise tests
1796
1797 typedef std::map<GLenum, std::string> FormatMap;
1798 static FormatMap formatMap;
1799 if (formatMap.empty())
1800 {
1801 // store in map formats that are not supported by glu::getTextureFormatStr
1802 formatMap[GL_LUMINANCE8_ALPHA8_OES] = "luminance8_alpha8_oes";
1803 formatMap[GL_LUMINANCE4_ALPHA4_OES] = "luminance4_alpha4_oes";
1804 formatMap[GL_STENCIL_INDEX1_OES] = "stencil_index1_oes";
1805 formatMap[GL_STENCIL_INDEX4_OES] = "stencil_index4_oes";
1806 formatMap[GL_LUMINANCE8_OES] = "luminance8_oes";
1807 formatMap[GL_ALPHA8_OES] = "alpha8_oes";
1808 }
1809
1810 FormatMap::iterator it = formatMap.find(format);
1811 if (it == formatMap.end())
1812 {
1813 // if format is not in map try glu function
1814 std::string formatString = glu::getTextureFormatStr(format).toString();
1815
1816 // cut out "GL_" from string
1817 formatString = formatString.substr(3, formatString.length());
1818
1819 // make lower case
1820 std::transform(formatString.begin(), formatString.end(), formatString.begin(), tolower);
1821
1822 return formatString;
1823 }
1824 return it->second;
1825 }
1826
1827 /** Initializes the test group contents. */
init()1828 void InternalformatTests::init()
1829 {
1830 // Determine which data sets should be used for tests
1831 TestData testData;
1832 glu::ContextType contextType = m_context.getRenderContext().getType();
1833 if (glu::isContextTypeGLCore(contextType))
1834 getGLTestData(testData, contextType);
1835 else
1836 getESTestData(testData, contextType);
1837
1838 // Construct texture2d tests
1839 TestCaseGroup* texture2DGroup = new deqp::TestCaseGroup(m_context, "texture2d", "");
1840 for (unsigned int i = 0; i < testData.texture2DFormats.size(); i++)
1841 {
1842 const TextureFormat& tf = testData.texture2DFormats[i];
1843 std::string format = formatToString(tf.format);
1844 std::string type = glu::getTypeStr(tf.type).toString();
1845 std::string internalFormat = formatToString(tf.internalFormat);
1846
1847 // cut out "GL_" from type and make it lowercase
1848 type = type.substr(3, type.length());
1849 std::transform(type.begin(), type.end(), type.begin(), tolower);
1850
1851 std::string name = format + "_" + type + "_" + internalFormat;
1852 if (tf.minFilter == GL_LINEAR)
1853 name += "_linear";
1854
1855 texture2DGroup->addChild(new Texture2DCase(m_context, name, tf));
1856 }
1857 addChild(texture2DGroup);
1858
1859 // Construct copy_text_image tests
1860 TestCaseGroup* copyTexImageGroup = new deqp::TestCaseGroup(m_context, "copy_tex_image", "");
1861 for (unsigned int i = 0; i < testData.copyTexImageFormats.size(); i++)
1862 {
1863 const CopyTexImageFormat& ctif = testData.copyTexImageFormats[i];
1864 std::string name = formatToString(ctif.internalFormat);
1865 copyTexImageGroup->addChild(new CopyTexImageCase(m_context, name, ctif));
1866 }
1867 addChild(copyTexImageGroup);
1868
1869 // Construct renderbuffer tests
1870 TestCaseGroup* renderbufferGroup = new deqp::TestCaseGroup(m_context, "renderbuffer", "");
1871 for (unsigned int i = 0; i < testData.renderbufferFormats.size(); i++)
1872 {
1873 const RenderbufferFormat& rbf = testData.renderbufferFormats[i];
1874 std::string name = formatToString(rbf.format);
1875 renderbufferGroup->addChild(new RenderbufferCase(m_context, name, rbf));
1876 }
1877 addChild(renderbufferGroup);
1878 }
1879
convertUInt(const tcu::PixelBufferAccess & src,const tcu::PixelBufferAccess & dst)1880 void RenderbufferCase::convertUInt(const tcu::PixelBufferAccess &src, const tcu::PixelBufferAccess &dst)
1881 {
1882 for (int z = 0; z < dst.getDepth(); ++z)
1883 for (int y = 0; y < dst.getHeight(); ++y)
1884 for (int x = 0; x < dst.getWidth(); ++x)
1885 {
1886 tcu::UVec4 srcPixel = src.getPixelUint(x, y, z);
1887 tcu::Vec4 dstPixel(srcPixel.x() / 255.0f, srcPixel.y() / 255.0f, srcPixel.z() / 255.0f, srcPixel.w() / 255.0f);
1888 dst.setPixel(dstPixel, x, y, z);
1889 }
1890 }
1891
convertsRGB(const tcu::PixelBufferAccess & src,const tcu::PixelBufferAccess & dst)1892 void RenderbufferCase::convertsRGB(const tcu::PixelBufferAccess& src, const tcu::PixelBufferAccess& dst)
1893 {
1894 for (int z = 0; z < dst.getDepth(); ++z)
1895 for (int y = 0; y < dst.getHeight(); ++y)
1896 for (int x = 0; x < dst.getWidth(); ++x)
1897 {
1898 tcu::UVec4 srcPixel = src.getPixelUint(x, y, z);
1899 tcu::Vec4 dstPixel = sRGB8ToLinear(srcPixel);
1900 dst.setPixel(dstPixel, x, y, z);
1901 }
1902 }
1903
convertsRGBA(const tcu::PixelBufferAccess & src,const tcu::PixelBufferAccess & dst)1904 void RenderbufferCase::convertsRGBA(const tcu::PixelBufferAccess& src, const tcu::PixelBufferAccess& dst)
1905 {
1906 for (int z = 0; z < dst.getDepth(); ++z)
1907 for (int y = 0; y < dst.getHeight(); ++y)
1908 for (int x = 0; x < dst.getWidth(); ++x)
1909 {
1910 tcu::UVec4 srcPixel = src.getPixelUint(x, y, z);
1911 tcu::Vec4 dstPixel = sRGBA8ToLinear(srcPixel);
1912 dst.setPixel(dstPixel, x, y, z);
1913 }
1914 }
1915
convertUInt_2_10_10_10_rev(const tcu::PixelBufferAccess & src,const tcu::PixelBufferAccess & dst)1916 void RenderbufferCase::convertUInt_2_10_10_10_rev(const tcu::PixelBufferAccess &src, const tcu::PixelBufferAccess &dst)
1917 {
1918 for (int z = 0; z < dst.getDepth(); ++z)
1919 for (int y = 0; y < dst.getHeight(); ++y)
1920 for (int x = 0; x < dst.getWidth(); ++x)
1921 {
1922 tcu::UVec4 srcPixel = src.getPixelUint(x, y, z);
1923 tcu::Vec4 dstPixel(srcPixel.x() / 1023.0f, srcPixel.y() / 1023.0f, srcPixel.z() / 1023.0f, srcPixel.w() / 3.0f);
1924 dst.setPixel(dstPixel, x, y, z);
1925 }
1926 }
1927 } /* glcts namespace */
1928