1 /*-------------------------------------------------------------------------
2 * OpenGL Conformance Test Suite
3 * -----------------------------
5 * Copyright (c) 2017 The Khronos Group Inc.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 * \file InternalformatTests.cpp
22 */ /*-------------------------------------------------------------------*/
24 #include "glcInternalformatTests.hpp"
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"
51 // all extension names required by the tests
52 static const char* EXT_texture_type_2_10_10_10_REV = "GL_EXT_texture_type_2_10_10_10_REV";
53 static const char* EXT_texture_shared_exponent = "GL_EXT_texture_shared_exponent";
54 static const char* EXT_texture_integer = "GL_EXT_texture_integer";
55 static const char* ARB_texture_rgb10_a2ui = "GL_ARB_texture_rgb10_a2ui";
56 static const char* ARB_depth_texture = "GL_ARB_depth_texture";
57 static const char* ARB_texture_float = "GL_ARB_texture_float";
58 static const char* OES_texture_float = "GL_OES_texture_float";
59 static const char* OES_texture_float_linear = "GL_OES_texture_float_linear";
60 static const char* OES_texture_half_float = "GL_OES_texture_half_float";
61 static const char* OES_texture_half_float_linear = "GL_OES_texture_half_float_linear";
62 static const char* OES_rgb8_rgba8 = "GL_OES_rgb8_rgba8";
63 static const char* OES_depth_texture = "GL_OES_depth_texture";
64 static const char* OES_depth24 = "GL_OES_depth24";
65 static const char* OES_depth32 = "GL_OES_depth32";
66 static const char* OES_packed_depth_stencil = "GL_OES_packed_depth_stencil";
67 static const char* OES_stencil1 = "GL_OES_stencil1";
68 static const char* OES_stencil4 = "GL_OES_stencil4";
69 static const char* OES_stencil8 = "GL_OES_stencil8";
70 static const char* OES_required_internalformat = "GL_OES_required_internalformat";
77 const char* requiredExtension;
78 const char* secondReqiredExtension;
86 TextureFormat(GLenum aFormat, GLenum aType, GLint aInternalFormat, const char* aRequiredExtension = DE_NULL,
87 const char* aSecondReqiredExtension = DE_NULL, GLint aMinFilter = GL_NEAREST,
88 GLint aMagFilter = GL_NEAREST)
91 , internalFormat(aInternalFormat)
92 , requiredExtension(aRequiredExtension)
93 , secondReqiredExtension(aSecondReqiredExtension)
94 , minFilter(aMinFilter)
95 , magFilter(aMagFilter)
100 struct CopyTexImageFormat
102 GLint internalFormat;
103 const char* requiredExtension;
104 const char* secondReqiredExtension;
108 CopyTexImageFormat(GLenum aInternalFormat, const char* aRequiredExtension = DE_NULL,
109 const char* aSecondReqiredExtension = DE_NULL, GLint aMinFilter = GL_NEAREST,
110 GLint aMagFilter = GL_NEAREST)
111 : internalFormat(aInternalFormat)
112 , requiredExtension(aRequiredExtension)
113 , secondReqiredExtension(aSecondReqiredExtension)
114 , minFilter(aMinFilter)
115 , magFilter(aMagFilter)
120 enum RenderBufferType
123 RENDERBUFFER_STENCIL,
125 RENDERBUFFER_DEPTH_STENCIL
128 struct RenderbufferFormat
131 RenderBufferType type;
132 const char* requiredExtension;
133 const char* secondReqiredExtension;
135 RenderbufferFormat(GLenum aFormat, RenderBufferType aType, const char* aRequiredExtension = DE_NULL,
136 const char* aSecondReqiredExtension = DE_NULL)
139 , requiredExtension(aRequiredExtension)
140 , secondReqiredExtension(aSecondReqiredExtension)
145 class InternalformatCaseBase : public deqp::TestCase
148 InternalformatCaseBase(deqp::Context& context, const std::string& name);
149 virtual ~InternalformatCaseBase()
154 bool requiredExtensionsSupported(const char* extension1, const char* extension2);
155 GLuint createTexture(GLint internalFormat, GLenum format, GLenum type, GLint minFilter, GLint magFilter,
156 bool generateData = true) const;
157 glu::ProgramSources prepareTexturingProgramSources(GLint internalFormat, GLenum format, GLenum type) const;
158 void renderTexturedQuad(GLuint programId) const;
159 GLenum getUnsizedFormatFromInternalFormat(GLint internalFormat) const;
160 GLenum getTypeFromInternalFormat(GLint internalFormat) const;
163 void generateTextureData(GLuint width, GLuint height, GLenum type, unsigned int pixelSize, unsigned int components,
164 std::vector<unsigned char>& result) const;
166 // color converting methods
167 static void convertByte(tcu::Vec4 inColor, unsigned char* dst, int components);
168 static void convertUByte(tcu::Vec4 inColor, unsigned char* dst, int components);
169 static void convertHFloat(tcu::Vec4 inColor, unsigned char* dst, int components);
170 static void convertFloat(tcu::Vec4 inColor, unsigned char* dst, int components);
171 static void convertShort(tcu::Vec4 inColor, unsigned char* dst, int components);
172 static void convertUShort(tcu::Vec4 inColor, unsigned char* dst, int components);
173 static void convertInt(tcu::Vec4 inColor, unsigned char* dst, int components);
174 static void convertUInt(tcu::Vec4 inColor, unsigned char* dst, int components);
175 static void convertUInt_24_8(tcu::Vec4 inColor, unsigned char* dst, int components);
176 static void convertUShort_4_4_4_4(tcu::Vec4 inColor, unsigned char* dst, int);
177 static void convertUShort_5_5_5_1(tcu::Vec4 inColor, unsigned char* dst, int);
178 static void convertUShort_5_6_5(tcu::Vec4 inColor, unsigned char* dst, int);
179 static void convertUInt_2_10_10_10_rev(tcu::Vec4 inColor, unsigned char* dst, int);
181 static GLhalf floatToHalf(float f);
184 GLsizei m_renderWidth;
185 GLsizei m_renderHeight;
188 InternalformatCaseBase::InternalformatCaseBase(deqp::Context& context, const std::string& name)
189 : deqp::TestCase(context, name.c_str(), ""), m_renderWidth(64), m_renderHeight(64)
193 bool InternalformatCaseBase::requiredExtensionsSupported(const char* extension1, const char* extension2)
195 const glu::ContextInfo& contextInfo = m_context.getContextInfo();
200 if (!contextInfo.isExtensionSupported(extension1) || !contextInfo.isExtensionSupported(extension2))
202 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "One of required extensions is not supported");
206 else if (!contextInfo.isExtensionSupported(extension1))
208 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Required extension is not supported");
215 GLuint InternalformatCaseBase::createTexture(GLint internalFormat, GLenum format, GLenum type, GLint minFilter,
216 GLint magFilter, bool generateData) const
218 const Functions& gl = m_context.getRenderContext().getFunctions();
220 std::vector<unsigned char> textureData;
221 GLvoid* textureDataPtr = DE_NULL;
225 tcu::TextureFormat tcuTextureFormat = glu::mapGLTransferFormat(format, type);
226 unsigned int components = tcu::getNumUsedChannels(tcuTextureFormat.order);
227 unsigned int pixelSize = 4;
229 // note: getPixelSize hits assertion for GL_UNSIGNED_INT_2_10_10_10_REV when format is RGB
230 if (type != GL_UNSIGNED_INT_2_10_10_10_REV)
231 pixelSize = tcu::getPixelSize(tcuTextureFormat);
233 generateTextureData(m_renderWidth, m_renderHeight, type, pixelSize, components, textureData);
234 textureDataPtr = &textureData[0];
237 gl.genTextures(1, &textureName);
238 gl.bindTexture(GL_TEXTURE_2D, textureName);
239 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture");
241 gl.texImage2D(GL_TEXTURE_2D, 0, internalFormat, m_renderWidth, m_renderHeight, 0, format, type, textureDataPtr);
242 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D");
244 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
245 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
246 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
247 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri");
248 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
249 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri");
254 glu::ProgramSources InternalformatCaseBase::prepareTexturingProgramSources(GLint internalFormat, GLenum format,
257 glu::RenderContext& renderContext = m_context.getRenderContext();
258 glu::ContextType contextType = renderContext.getType();
259 glu::GLSLVersion glslVersion = glu::getContextTypeGLSLVersion(contextType);
264 std::map<std::string, std::string> specializationMap;
265 specializationMap["VERSION"] = glu::getGLSLVersionDeclaration(glslVersion);
267 if (glu::contextSupports(contextType, glu::ApiType::es(3, 0)) || glu::isContextTypeGLCore(contextType))
270 "precision highp float;\n"
271 "in vec2 position;\n"
272 "in vec2 inTexcoord;\n"
273 "out vec2 texcoord;\n"
276 " texcoord = inTexcoord;\n"
277 " gl_Position = vec4(position, 0.0, 1.0);\n"
280 "precision highp float;\n"
281 "uniform ${SAMPLER} sampler;\n"
282 "in vec2 texcoord;\n"
283 "out highp vec4 color;\n"
286 " ${SAMPLED_TYPE} v = texture(sampler, texcoord);\n"
287 " color = ${CALCULATE_COLOR};\n"
288 " ${PROCESS_COLOR}\n"
291 specializationMap["PROCESS_COLOR"] = "";
292 if ((format == GL_RGB_INTEGER) || (format == GL_RGBA_INTEGER))
294 specializationMap["SAMPLED_TYPE"] = "uvec4";
295 specializationMap["SAMPLER"] = "usampler2D";
298 specializationMap["SAMPLED_TYPE"] = "ivec4";
299 specializationMap["SAMPLER"] = "isampler2D";
300 specializationMap["CALCULATE_COLOR"] = "vec4(v) / 127.0";
302 else if (type == GL_UNSIGNED_BYTE)
304 specializationMap["CALCULATE_COLOR"] = "vec4(v) / 255.0";
306 else if (type == GL_SHORT)
308 specializationMap["SAMPLED_TYPE"] = "ivec4";
309 specializationMap["SAMPLER"] = "isampler2D";
310 specializationMap["CALCULATE_COLOR"] = "vec4(v / 128) / 256.0";
312 else if (type == GL_UNSIGNED_SHORT)
314 specializationMap["CALCULATE_COLOR"] = "vec4(v / 256) / 256.0";
316 else if (type == GL_INT)
318 specializationMap["SAMPLED_TYPE"] = "ivec4";
319 specializationMap["SAMPLER"] = "isampler2D";
320 specializationMap["CALCULATE_COLOR"] = "vec4(v / 2097152u) / 1024.0";
322 else // GL_UNSIGNED_INT
324 if (internalFormat == GL_RGB10_A2UI)
325 specializationMap["CALCULATE_COLOR"] = "vec4(vec3(v.rgb) / 1023.0, float(v.a) / 3.0)";
327 specializationMap["CALCULATE_COLOR"] = "vec4(v / 4194304u) / 1024.0";
330 if (format == GL_RGB_INTEGER)
331 specializationMap["PROCESS_COLOR"] = "color.a = 1.0;\n";
335 specializationMap["SAMPLED_TYPE"] = "vec4";
336 specializationMap["SAMPLER"] = "sampler2D";
337 if (format == GL_DEPTH_STENCIL)
338 specializationMap["CALCULATE_COLOR"] = "vec4(v.r, 0.0, 0.0, 1.0)";
340 specializationMap["CALCULATE_COLOR"] = "v";
346 "attribute highp vec2 position;\n"
347 "attribute highp vec2 inTexcoord;\n"
348 "varying highp vec2 texcoord;\n"
351 " texcoord = inTexcoord;\n"
352 " gl_Position = vec4(position, 0.0, 1.0);\n"
355 "uniform highp sampler2D sampler;\n"
356 "varying highp vec2 texcoord;\n"
359 " highp vec4 color = texture2D(sampler, texcoord);\n"
360 " gl_FragColor = ${CALCULATE_COLOR};\n"
363 if ((internalFormat == GL_DEPTH_COMPONENT) || (internalFormat == GL_DEPTH_STENCIL))
364 specializationMap["CALCULATE_COLOR"] = "vec4(color.r, 0.0, 0.0, 1.0)";
366 specializationMap["CALCULATE_COLOR"] = "color";
369 vs = tcu::StringTemplate(vs).specialize(specializationMap);
370 fs = tcu::StringTemplate(fs).specialize(specializationMap);
371 return glu::makeVtxFragSources(vs.c_str(), fs.c_str());
374 void InternalformatCaseBase::renderTexturedQuad(GLuint programId) const
376 // Prepare data for rendering
377 static const deUint16 quadIndices[] = { 0, 1, 2, 2, 1, 3 };
378 static const float position[] = { -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f };
379 static const float texCoord[] = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f };
380 static const glu::VertexArrayBinding vertexArrays[] = { glu::va::Float("position", 2, 4, 0, position),
381 glu::va::Float("inTexcoord", 2, 4, 0, texCoord) };
383 glu::draw(m_context.getRenderContext(), programId, DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays,
384 glu::pr::TriangleStrip(DE_LENGTH_OF_ARRAY(quadIndices), quadIndices));
387 GLenum InternalformatCaseBase::getUnsizedFormatFromInternalFormat(GLint internalFormat) const
389 switch (internalFormat)
398 case GL_RGBA8UI: //remove this
399 return GL_RGBA_INTEGER;
406 case GL_LUMINANCE_ALPHA:
407 case GL_LUMINANCE4_ALPHA4_OES:
408 case GL_LUMINANCE8_ALPHA8_OES:
409 return GL_LUMINANCE_ALPHA;
411 case GL_LUMINANCE8_OES:
416 case GL_DEPTH_COMPONENT16:
417 case GL_DEPTH_COMPONENT24:
418 case GL_DEPTH_COMPONENT32:
419 return GL_DEPTH_COMPONENT;
420 case GL_DEPTH24_STENCIL8:
421 return GL_DEPTH_STENCIL;
422 case GL_STENCIL_INDEX8:
423 return GL_STENCIL_INDEX;
425 TCU_FAIL("Unrecognized internal format");
430 GLenum InternalformatCaseBase::getTypeFromInternalFormat(GLint internalFormat) const
432 switch (internalFormat)
437 return GL_UNSIGNED_INT_2_10_10_10_REV;
438 case GL_DEPTH_COMPONENT16:
439 case GL_DEPTH_COMPONENT24:
440 return GL_UNSIGNED_SHORT;
441 case GL_DEPTH_COMPONENT32:
442 return GL_UNSIGNED_INT;
445 return GL_UNSIGNED_BYTE;
448 void InternalformatCaseBase::generateTextureData(GLuint width, GLuint height, GLenum type, unsigned int pixelSize,
449 unsigned int components, std::vector<unsigned char>& result) const
451 // colors are the 4 corner colors specified ( lower left, lower right, upper left, upper right )
452 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),
453 tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), tcu::Vec4(0.0f, 1.0f, 1.0f, 1.0f) };
455 typedef void (*ColorConversionFunc)(tcu::Vec4, unsigned char*, int);
456 typedef std::map<GLenum, ColorConversionFunc> ColorConversionMap;
457 static ColorConversionMap colorConversionMap;
458 if (colorConversionMap.empty())
460 colorConversionMap[GL_BYTE] = &convertByte;
461 colorConversionMap[GL_UNSIGNED_BYTE] = &convertUByte;
462 colorConversionMap[GL_HALF_FLOAT] = &convertHFloat;
463 colorConversionMap[GL_FLOAT] = &convertFloat;
464 colorConversionMap[GL_SHORT] = &convertShort;
465 colorConversionMap[GL_UNSIGNED_SHORT] = &convertUShort;
466 colorConversionMap[GL_INT] = &convertInt;
467 colorConversionMap[GL_UNSIGNED_INT] = &convertUInt;
468 colorConversionMap[GL_UNSIGNED_INT_24_8] = &convertUInt_24_8;
469 colorConversionMap[GL_UNSIGNED_SHORT_4_4_4_4] = &convertUShort_4_4_4_4;
470 colorConversionMap[GL_UNSIGNED_SHORT_5_5_5_1] = &convertUShort_5_5_5_1;
471 colorConversionMap[GL_UNSIGNED_SHORT_5_6_5] = &convertUShort_5_6_5;
472 colorConversionMap[GL_UNSIGNED_INT_2_10_10_10_REV] = &convertUInt_2_10_10_10_rev;
475 ColorConversionFunc convertColor = colorConversionMap.at(type);
477 float lwidth = static_cast<float>(width - 1);
478 float lheight = static_cast<float>(height - 1);
480 result.resize(width * height * pixelSize);
481 unsigned char* dataPtr = &result[0];
483 for (GLuint y = 0; y < height; ++y)
485 for (GLuint x = 0; x < width; ++x)
487 float posX = (lwidth - static_cast<float>(x)) / lwidth;
488 float posY = (lheight - static_cast<float>(y)) / lheight;
489 float rposX = 1.f - posX;
490 float rposY = 1.f - posY;
491 tcu::Vec4 c = colors[0] * (posX * posY) + colors[1] * (rposX * posY) + colors[2] * (posX * rposY);
493 // Hard-code the alpha as small floating point instability results in large differences for some formats
495 convertColor(c, dataPtr, static_cast<int>(components));
496 dataPtr += pixelSize;
501 void InternalformatCaseBase::convertByte(tcu::Vec4 inColor, unsigned char* dst, int components)
503 char* dstChar = reinterpret_cast<char*>(dst);
504 for (int i = 0; i < components; ++i)
505 dstChar[i] = static_cast<char>(inColor[i] * 127.0f);
508 void InternalformatCaseBase::convertUByte(tcu::Vec4 inColor, unsigned char* dst, int components)
510 for (int i = 0; i < components; ++i)
511 dst[i] = static_cast<unsigned char>(inColor[i] * 255.f);
514 void InternalformatCaseBase::convertHFloat(tcu::Vec4 inColor, unsigned char* dst, int components)
516 GLhalf* dstHalf = reinterpret_cast<GLhalf*>(dst);
517 for (int i = 0; i < components; ++i)
518 dstHalf[i] = floatToHalf(inColor[i]);
521 void InternalformatCaseBase::convertFloat(tcu::Vec4 inColor, unsigned char* dst, int components)
523 float* dstFloat = reinterpret_cast<float*>(dst);
524 for (int i = 0; i < components; ++i)
525 dstFloat[i] = inColor[i];
528 void InternalformatCaseBase::convertShort(tcu::Vec4 inColor, unsigned char* dst, int components)
530 short* dstUShort = reinterpret_cast<short*>(dst);
531 for (int i = 0; i < components; ++i)
533 double c = static_cast<double>(inColor[i]);
534 dstUShort[i] = static_cast<short>(c * 32768 - 1);
538 void InternalformatCaseBase::convertUShort(tcu::Vec4 inColor, unsigned char* dst, int components)
540 unsigned short* dstUShort = reinterpret_cast<unsigned short*>(dst);
541 for (int i = 0; i < components; ++i)
543 double c = static_cast<double>(inColor[i]);
544 dstUShort[i] = static_cast<unsigned short>(c * 65535u);
548 void InternalformatCaseBase::convertInt(tcu::Vec4 inColor, unsigned char* dst, int components)
550 int* dstUInt = reinterpret_cast<int*>(dst);
551 for (int i = 0; i < components; ++i)
552 dstUInt[i] = static_cast<int>(inColor[i] * 2147483648u - 1);
555 void InternalformatCaseBase::convertUInt(tcu::Vec4 inColor, unsigned char* dst, int components)
557 unsigned int* dstUInt = reinterpret_cast<unsigned int*>(dst);
558 for (int i = 0; i < components; ++i)
560 double c = static_cast<double>(inColor[i]);
561 dstUInt[i] = static_cast<unsigned int>(c * 4294967295u);
565 void InternalformatCaseBase::convertUInt_24_8(tcu::Vec4 inColor, unsigned char* dst, int)
567 unsigned int* dstUint = reinterpret_cast<unsigned int*>(dst);
569 unsigned int d = static_cast<unsigned int>(inColor[0] * 16777215u) << 8;
570 unsigned int s = static_cast<unsigned int>(inColor[1] * 255u);
572 dstUint[0] = (d & 0xFFFFFF00) | (s & 0xFF);
575 void InternalformatCaseBase::convertUShort_4_4_4_4(tcu::Vec4 inColor, unsigned char* dst, int)
577 unsigned short* dstUShort = reinterpret_cast<unsigned short*>(dst);
579 unsigned int r = static_cast<unsigned int>(inColor[0] * 15) << 12;
580 unsigned int g = static_cast<unsigned int>(inColor[1] * 15) << 8;
581 unsigned int b = static_cast<unsigned int>(inColor[2] * 15) << 4;
582 unsigned int a = static_cast<unsigned int>(inColor[3] * 15) << 0;
584 dstUShort[0] = (r & 0xF000) | (g & 0x0F00) | (b & 0x00F0) | (a & 0x000F);
587 void InternalformatCaseBase::convertUShort_5_5_5_1(tcu::Vec4 inColor, unsigned char* dst, int)
589 unsigned short* dstUShort = reinterpret_cast<unsigned short*>(dst);
591 unsigned int r = static_cast<unsigned int>(inColor[0] * 31) << 11;
592 unsigned int g = static_cast<unsigned int>(inColor[1] * 31) << 6;
593 unsigned int b = static_cast<unsigned int>(inColor[2] * 31) << 1;
594 unsigned int a = static_cast<unsigned int>(inColor[3] * 1) << 0;
596 dstUShort[0] = (r & 0xF800) | (g & 0x07c0) | (b & 0x003e) | (a & 0x0001);
599 void InternalformatCaseBase::convertUShort_5_6_5(tcu::Vec4 inColor, unsigned char* dst, int)
601 unsigned short* dstUShort = reinterpret_cast<unsigned short*>(dst);
603 unsigned int r = static_cast<unsigned int>(inColor[0] * 31) << 11;
604 unsigned int g = static_cast<unsigned int>(inColor[1] * 63) << 5;
605 unsigned int b = static_cast<unsigned int>(inColor[2] * 31) << 0;
607 dstUShort[0] = (r & 0xF800) | (g & 0x07e0) | (b & 0x001f);
610 void InternalformatCaseBase::convertUInt_2_10_10_10_rev(tcu::Vec4 inColor, unsigned char* dst, int)
612 unsigned int* dstUint = reinterpret_cast<unsigned int*>(dst);
614 // Alpha value is rounded to eliminate small precision errors that
615 // may result in big errors after converting value to just 4 bits
616 unsigned int a = static_cast<unsigned int>(deFloatRound(inColor[3] * 3)) << 30;
617 unsigned int b = static_cast<unsigned int>(inColor[2] * 1023) << 20;
618 unsigned int g = static_cast<unsigned int>(inColor[1] * 1023) << 10;
619 unsigned int r = static_cast<unsigned int>(inColor[0] * 1023) << 0;
621 dstUint[0] = (a & 0xC0000000) | (b & 0x3FF00000) | (g & 0x000FFC00) | (r & 0x000003FF);
624 GLhalf InternalformatCaseBase::floatToHalf(float f)
626 const unsigned int HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP = 0x38000000;
627 // Max exponent value in single precision that will be converted
628 // to Inf or Nan when stored as a half-float
629 const unsigned int HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_FP_EXP = 0x47800000;
630 // 255 is the max exponent biased value
631 const unsigned int FLOAT_MAX_BIASED_EXP = (0xFF << 23);
632 const unsigned int HALF_FLOAT_MAX_BIASED_EXP = (0x1F << 10);
634 char* c = reinterpret_cast<char*>(&f);
635 unsigned int x = *reinterpret_cast<unsigned int*>(c);
636 unsigned int sign = static_cast<GLhalf>(x >> 31);
639 unsigned int mantissa = x & ((1 << 23) - 1);
641 unsigned int exp = x & FLOAT_MAX_BIASED_EXP;
643 if (exp >= HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_FP_EXP)
645 // Check if the original single precision float number is a NaN
646 if (mantissa && (exp == FLOAT_MAX_BIASED_EXP))
648 // We have a single precision NaN
649 mantissa = (1 << 23) - 1;
653 // 16-bit half-float representation stores number as Inf
656 return (GLhalf)((((GLhalf)sign) << 15) | (GLhalf)(HALF_FLOAT_MAX_BIASED_EXP) | (GLhalf)(mantissa >> 13));
658 // Check if exponent is <= -15
659 else if (exp <= HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP)
661 // Store a denorm half-float value or zero
662 exp = (HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP - exp) >> 23;
663 mantissa |= (1 << 23);
664 mantissa >>= (14 + exp);
665 return (GLhalf)((((GLhalf)sign) << 15) | (GLhalf)(mantissa));
668 return (GLhalf)((((GLhalf)sign) << 15) | (GLhalf)((exp - HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP) >> 13) |
669 (GLhalf)(mantissa >> 13));
672 class Texture2DCase : public InternalformatCaseBase
675 Texture2DCase(deqp::Context& context, const std::string& name, const TextureFormat& textureFormat);
676 virtual ~Texture2DCase()
680 virtual tcu::TestNode::IterateResult iterate(void);
683 TextureFormat m_testFormat;
686 Texture2DCase::Texture2DCase(deqp::Context& context, const std::string& name, const TextureFormat& testFormat)
687 : InternalformatCaseBase(context, name.c_str()), m_testFormat(testFormat)
691 tcu::TestNode::IterateResult Texture2DCase::iterate(void)
693 if (!requiredExtensionsSupported(m_testFormat.requiredExtension, m_testFormat.secondReqiredExtension))
696 typedef std::map<GLenum, TextureFormat> ReferenceFormatMap;
697 static ReferenceFormatMap formatMap;
698 if (formatMap.empty())
700 formatMap[GL_RED] = TextureFormat(GL_RED, GL_UNSIGNED_BYTE, GL_RED);
701 formatMap[GL_RG] = TextureFormat(GL_RG, GL_UNSIGNED_BYTE, GL_RG);
702 formatMap[GL_RGB] = TextureFormat(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB);
703 formatMap[GL_RGBA] = TextureFormat(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB);
704 formatMap[GL_RGBA_INTEGER] = TextureFormat(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB);
705 formatMap[GL_RGB_INTEGER] = TextureFormat(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB);
706 formatMap[GL_ALPHA] = TextureFormat(GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA);
707 formatMap[GL_LUMINANCE] = TextureFormat(GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE);
708 formatMap[GL_LUMINANCE_ALPHA] = TextureFormat(GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE_ALPHA);
709 formatMap[GL_DEPTH_COMPONENT] = TextureFormat(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT);
710 formatMap[GL_DEPTH_STENCIL] = TextureFormat(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8);
713 ReferenceFormatMap::iterator formatIterator = formatMap.find(m_testFormat.format);
714 if (formatIterator == formatMap.end())
716 m_testCtx.getLog() << tcu::TestLog::Message << "Error: Unknown 2D texture format "
717 << glu::getTextureFormatStr(m_testFormat.format).toString() << tcu::TestLog::EndMessage;
718 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
722 const TextureFormat& referenceFormat = formatIterator->second;
723 glu::RenderContext& renderContext = m_context.getRenderContext();
724 const Functions& gl = renderContext.getFunctions();
726 if (m_renderWidth > m_context.getRenderTarget().getWidth())
727 m_renderWidth = m_context.getRenderTarget().getWidth();
728 if (m_renderHeight > m_context.getRenderTarget().getHeight())
729 m_renderHeight = m_context.getRenderTarget().getHeight();
732 gl.viewport(0, 0, m_renderWidth, m_renderHeight);
733 gl.pixelStorei(GL_UNPACK_ALIGNMENT, 1);
735 // Create test and reference texture
736 GLuint testTextureName = createTexture(m_testFormat.internalFormat, m_testFormat.format, m_testFormat.type,
737 m_testFormat.minFilter, m_testFormat.magFilter);
738 GLuint referenceTextureName = createTexture(referenceFormat.internalFormat, referenceFormat.format,
739 referenceFormat.type, m_testFormat.minFilter, m_testFormat.magFilter);
741 // Create program that will render tested texture to screen
742 glu::ShaderProgram testProgram(
744 prepareTexturingProgramSources(m_testFormat.internalFormat, m_testFormat.format, m_testFormat.type));
745 if (!testProgram.isOk())
747 m_testCtx.getLog() << testProgram;
748 TCU_FAIL("Compile failed");
750 gl.useProgram(testProgram.getProgram());
751 gl.uniform1i(gl.getUniformLocation(testProgram.getProgram(), "sampler"), 0);
753 // Render textured quad with tested texture
754 gl.bindTexture(GL_TEXTURE_2D, testTextureName);
755 renderTexturedQuad(testProgram.getProgram());
756 tcu::Surface testSurface(m_renderWidth, m_renderHeight);
757 glu::readPixels(renderContext, 0, 0, testSurface.getAccess());
759 // Create program that will render reference texture to screen
760 glu::ProgramSources referenceSources =
761 prepareTexturingProgramSources(referenceFormat.internalFormat, referenceFormat.format, referenceFormat.type);
762 glu::ShaderProgram referenceProgram(renderContext, referenceSources);
763 if (!referenceProgram.isOk())
765 m_testCtx.getLog() << referenceProgram;
766 TCU_FAIL("Compile failed");
768 gl.useProgram(referenceProgram.getProgram());
769 gl.uniform1i(gl.getUniformLocation(referenceProgram.getProgram(), "sampler"), 0);
771 // Render textured quad with reference texture
772 gl.bindTexture(GL_TEXTURE_2D, referenceTextureName);
773 renderTexturedQuad(referenceProgram.getProgram());
774 tcu::Surface referenceSurface(m_renderWidth, m_renderHeight);
775 glu::readPixels(renderContext, 0, 0, referenceSurface.getAccess());
778 if (tcu::fuzzyCompare(m_testCtx.getLog(), "Result", "Image comparison result", referenceSurface, testSurface, 0.05f,
779 tcu::COMPARE_LOG_RESULT))
780 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
782 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
784 gl.deleteTextures(1, &testTextureName);
785 gl.deleteTextures(1, &referenceTextureName);
790 class CopyTexImageCase : public InternalformatCaseBase
793 CopyTexImageCase(deqp::Context& context, const std::string& name, const CopyTexImageFormat& copyTexImageFormat);
794 virtual ~CopyTexImageCase()
798 virtual tcu::TestNode::IterateResult iterate(void);
801 CopyTexImageFormat m_testFormat;
804 CopyTexImageCase::CopyTexImageCase(deqp::Context& context, const std::string& name,
805 const CopyTexImageFormat& copyTexImageFormat)
806 : InternalformatCaseBase(context, name.c_str()), m_testFormat(copyTexImageFormat)
810 tcu::TestNode::IterateResult CopyTexImageCase::iterate(void)
812 if (!requiredExtensionsSupported(m_testFormat.requiredExtension, m_testFormat.secondReqiredExtension))
815 glu::RenderContext& renderContext = m_context.getRenderContext();
816 const Functions& gl = renderContext.getFunctions();
818 // Determine texture format and type
819 GLint textureInternalFormat = m_testFormat.internalFormat;
820 GLuint textureType = getTypeFromInternalFormat(textureInternalFormat);
821 GLuint textureFormat = getUnsizedFormatFromInternalFormat(textureInternalFormat);
823 // Create program that will render texture to screen
824 glu::ShaderProgram program(renderContext,
825 prepareTexturingProgramSources(textureInternalFormat, textureFormat, textureType));
828 m_testCtx.getLog() << program;
829 TCU_FAIL("Compile failed");
831 gl.useProgram(program.getProgram());
832 gl.uniform1i(gl.getUniformLocation(program.getProgram(), "sampler"), 0);
833 gl.viewport(0, 0, m_renderWidth, m_renderHeight);
835 // Create required textures
836 GLuint referenceTextureId = createTexture(textureInternalFormat, textureFormat, textureType, m_testFormat.minFilter,
837 m_testFormat.magFilter);
838 GLuint copiedTextureId = createTexture(textureInternalFormat, textureFormat, textureType, m_testFormat.minFilter,
839 m_testFormat.magFilter, false);
841 // Create main RGBA framebuffer - this is needed because some default framebuffer may be RGB
842 GLuint mainFboId = 0;
843 gl.genFramebuffers(1, &mainFboId);
844 gl.bindFramebuffer(GL_FRAMEBUFFER, mainFboId);
845 GLuint mainFboColorTextureId = createTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, GL_NEAREST, false);
846 gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mainFboColorTextureId, 0);
848 // Render reference texture to main FBO and grab it
849 gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
850 gl.bindTexture(GL_TEXTURE_2D, referenceTextureId);
851 renderTexturedQuad(program.getProgram());
852 tcu::Surface referenceSurface(m_renderWidth, m_renderHeight);
853 glu::readPixels(renderContext, 0, 0, referenceSurface.getAccess());
855 GLuint copyFboId = 0;
856 GLuint copyFboColorTextureId = 0;
858 // When possible use separate FBO for copy operation; create copy FBO and
859 // attach reference texture to color or depth attachment
860 gl.genFramebuffers(1, ©FboId);
861 gl.bindFramebuffer(GL_FRAMEBUFFER, copyFboId);
863 if (textureFormat == GL_DEPTH_COMPONENT)
865 copyFboColorTextureId = createTexture(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, GL_NEAREST, GL_NEAREST, false);
866 gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, copyFboColorTextureId, 0);
867 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture2D");
868 gl.framebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, referenceTextureId, 0);
869 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture2D");
873 gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, referenceTextureId, 0);
874 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture2D");
877 // If FBO is complete, then go back to use default FBO
878 GLenum bufferStatus = gl.checkFramebufferStatus(GL_FRAMEBUFFER);
879 if (bufferStatus != GL_FRAMEBUFFER_COMPLETE)
881 // Bind back to main FBO
882 gl.bindFramebuffer(GL_FRAMEBUFFER, mainFboId);
883 gl.deleteFramebuffers(1, ©FboId);
884 if (copyFboColorTextureId)
885 gl.deleteTextures(1, ©FboColorTextureId);
886 // Check the bits of each channel first, because according the GLES3.2 spec, the component sizes of internalformat
887 // must exactly match the corresponding component sizes of the source buffer's effective internal format.
888 if (glu::isContextTypeES(renderContext.getType()) && getTypeFromInternalFormat(textureInternalFormat) != GL_UNSIGNED_BYTE)
890 m_testCtx.getLog() << tcu::TestLog::Message << "Not supported: The component sizes of internalformat do not exactly "
891 << "match the corresponding component sizes of the source buffer's effective internal format." << tcu::TestLog::EndMessage;
892 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "The test format isn't renderable, and the component sizes of "
893 "internalformat do not exactly match the corresponding component sizes of the source buffer's effective internal format.");
894 gl.deleteFramebuffers(1, &mainFboId);
895 gl.deleteTextures(1, &mainFboColorTextureId);
896 gl.deleteTextures(1, &copiedTextureId);
897 gl.deleteTextures(1, &referenceTextureId);
902 // Copy attachment from copy FBO to tested texture (if copy FBO couldn't be created
903 // then copying will be done from main FBO color attachment)
904 gl.bindTexture(GL_TEXTURE_2D, copiedTextureId);
905 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture");
906 gl.copyTexImage2D(GL_TEXTURE_2D, 0, textureInternalFormat, 0, 0, m_renderWidth, m_renderHeight, 0);
907 GLU_EXPECT_NO_ERROR(gl.getError(), "glCopyTexImage2D");
909 // Make sure that main FBO is bound
910 gl.bindFramebuffer(GL_FRAMEBUFFER, mainFboId);
912 // Render and grab tested texture
913 gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
914 gl.bindTexture(GL_TEXTURE_2D, copiedTextureId);
915 renderTexturedQuad(program.getProgram());
916 tcu::Surface resultSurface(m_renderWidth, m_renderHeight);
917 glu::readPixels(renderContext, 0, 0, resultSurface.getAccess());
920 if (tcu::fuzzyCompare(m_testCtx.getLog(), "Result", "Image comparison result", referenceSurface, resultSurface,
921 0.05f, tcu::COMPARE_LOG_RESULT))
922 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
924 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
927 gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
928 gl.deleteFramebuffers(1, &mainFboId);
929 gl.deleteTextures(1, &mainFboColorTextureId);
930 gl.deleteTextures(1, &copiedTextureId);
931 gl.deleteTextures(1, &referenceTextureId);
936 class RenderbufferCase : public InternalformatCaseBase
939 RenderbufferCase(deqp::Context& context, const std::string& name, const RenderbufferFormat& renderbufferFormat);
940 virtual ~RenderbufferCase();
942 virtual tcu::TestNode::IterateResult iterate(void);
945 void constructOrthoProjMatrix(GLfloat* mat4, GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n,
947 bool createFramebuffer();
948 void deleteFramebuffer();
949 GLuint createAndAttachRenderBuffer(GLenum rbFormat, GLenum fbAttachment);
950 void renderColoredQuad(GLuint programId, const float* positions) const;
951 glu::ProgramSources prepareColoringProgramSources(GLenum format, GLenum type) const;
952 void convertUInt(const tcu::PixelBufferAccess &src, const tcu::PixelBufferAccess &dst);
953 void convertUInt_2_10_10_10_rev(const tcu::PixelBufferAccess &src, const tcu::PixelBufferAccess &dst);
960 RenderbufferFormat m_testFormat;
963 RenderbufferCase::RenderbufferCase(deqp::Context& context, const std::string& name,
964 const RenderbufferFormat& renderbufferFormat)
965 : InternalformatCaseBase(context, name.c_str())
970 , m_testFormat(renderbufferFormat)
974 RenderbufferCase::~RenderbufferCase()
978 tcu::TestNode::IterateResult RenderbufferCase::iterate(void)
980 if (!requiredExtensionsSupported(m_testFormat.requiredExtension, m_testFormat.secondReqiredExtension))
983 glu::RenderContext& renderContext = m_context.getRenderContext();
984 const Functions& gl = renderContext.getFunctions();
986 int maxRenderbufferSize;
987 gl.getIntegerv(GL_MAX_RENDERBUFFER_SIZE, &maxRenderbufferSize);
988 int windowWidth = m_context.getRenderTarget().getWidth();
989 int windowHeight = m_context.getRenderTarget().getHeight();
990 m_renderWidth = (windowWidth > maxRenderbufferSize) ? maxRenderbufferSize : windowWidth;
991 m_renderHeight = (windowHeight > maxRenderbufferSize) ? maxRenderbufferSize : windowHeight;
993 float w = static_cast<float>(m_renderWidth);
994 float h = static_cast<float>(m_renderHeight);
995 static const float bigQuadPositionsSet[] = { 0, 0, 0, w, 0, 0, 0, h, 0, w, h, 0 };
996 static const float smallQuadPositionsSet[] = { 5.0f, 5.0f, 0.5f, w / 2, 5.0f, 0.5f,
997 5.0f, h / 2, 0.5f, w / 2, h / 2, 0.5f };
999 bool stencilRenderbufferAvailable =
1000 (m_testFormat.type == RENDERBUFFER_STENCIL) || (m_testFormat.type == RENDERBUFFER_DEPTH_STENCIL);
1002 GLenum testFormat = getUnsizedFormatFromInternalFormat(m_testFormat.format);
1003 GLenum testType = getTypeFromInternalFormat(m_testFormat.format);
1005 // We need surfaces for depth testing and stencil testing, and also for
1006 // storing the reference and the values for the format under testing
1007 tcu::Surface testSurface[2][2];
1008 for (GLuint loop1 = 0; loop1 < 2; loop1++)
1009 for (GLuint loop2 = 0; loop2 < 2; loop2++)
1010 testSurface[loop1][loop2].setSize(m_renderWidth, m_renderHeight);
1012 GLint defaultFramebufferDepthBits = 0;
1013 GLint defaultFramebufferStencilBits = 0;
1014 if (glu::isContextTypeES(m_context.getRenderContext().getType()))
1016 gl.getIntegerv(GL_DEPTH_BITS, &defaultFramebufferDepthBits);
1017 gl.getIntegerv(GL_STENCIL_BITS, &defaultFramebufferStencilBits);
1021 GLint hasDepthBuffer = 0;
1022 GLint hasStencilBuffer = 0;
1024 gl.getNamedFramebufferAttachmentParameteriv(0, GL_DEPTH, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE,
1026 gl.getNamedFramebufferAttachmentParameteriv(0, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE,
1029 if (hasDepthBuffer != GL_NONE)
1030 gl.getNamedFramebufferAttachmentParameteriv(0, GL_DEPTH, GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE,
1031 &defaultFramebufferDepthBits);
1033 if (hasStencilBuffer != GL_NONE)
1034 gl.getNamedFramebufferAttachmentParameteriv(0, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE,
1035 &defaultFramebufferStencilBits);
1038 // Create two programs for rendering, one for rendering into default FB, and
1039 // a second one to render in our created FB
1041 glu::ShaderProgram program0(renderContext, prepareColoringProgramSources(GL_RGBA, GL_UNSIGNED_BYTE));
1042 glu::ShaderProgram program1(renderContext, prepareColoringProgramSources(testFormat, testType));
1044 std::vector<glu::ShaderProgram*> programs;
1045 programs.push_back(&program0);
1046 programs.push_back(&program1);
1048 bool testNonStencil = (m_testFormat.type != RENDERBUFFER_STENCIL);
1049 bool testStencil = defaultFramebufferStencilBits && stencilRenderbufferAvailable;
1051 for (GLuint loop = 0; loop < 2; loop++)
1053 if (!programs[loop]->isOk())
1055 m_testCtx.getLog() << *programs[loop];
1056 TCU_FAIL("Compile failed");
1059 gl.useProgram(programs[loop]->getProgram());
1060 GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram");
1062 float mvpMatrix[16];
1063 constructOrthoProjMatrix(mvpMatrix, 0.0, m_renderWidth, 0.0f, m_renderHeight, 1.0f, -1.0f);
1064 GLint mvpUniformLocation = gl.getUniformLocation(programs[loop]->getProgram(), "mvpMatrix");
1065 gl.uniformMatrix4fv(mvpUniformLocation, 1, 0, mvpMatrix);
1067 gl.bindTexture(GL_TEXTURE_2D, 0);
1068 gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
1069 gl.viewport(0, 0, m_renderWidth, m_renderHeight);
1073 if (loop && !createFramebuffer())
1076 if (defaultFramebufferDepthBits)
1078 gl.enable(GL_DEPTH_TEST);
1079 gl.depthFunc(GL_LESS);
1082 gl.bindFramebuffer(GL_FRAMEBUFFER, loop ? m_fbo : m_context.getRenderContext().getDefaultFramebuffer());
1083 gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1085 if (defaultFramebufferDepthBits)
1087 // Draw a small quad just in the z buffer
1088 gl.colorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
1089 renderColoredQuad(programs[loop]->getProgram(), smallQuadPositionsSet);
1091 // Large quad should be drawn on top small one to verify that the depth test is working
1092 gl.colorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1096 renderColoredQuad(programs[loop]->getProgram(), bigQuadPositionsSet);
1098 if (loop && testFormat == GL_RGBA_INTEGER)
1100 de::ArrayBuffer<deUint32> pixels;
1101 pixels.setStorage(4 * m_renderWidth * m_renderHeight);
1102 tcu::PixelBufferAccess pixelBuffer(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNSIGNED_INT32),
1103 m_renderWidth, m_renderHeight, 1, pixels.getPtr());
1104 glu::readPixels(renderContext, 0, 0, pixelBuffer);
1105 if (testType == GL_UNSIGNED_INT_2_10_10_10_REV)
1106 convertUInt_2_10_10_10_rev(pixelBuffer, testSurface[0][loop].getAccess());
1108 convertUInt(pixelBuffer, testSurface[0][loop].getAccess());
1112 glu::readPixels(renderContext, 0, 0, testSurface[0][loop].getAccess());
1117 deleteFramebuffer();
1119 if (defaultFramebufferStencilBits && stencilRenderbufferAvailable)
1121 gl.disable(GL_DEPTH_TEST);
1122 gl.enable(GL_STENCIL_TEST);
1124 if (loop && !createFramebuffer())
1127 gl.bindFramebuffer(GL_FRAMEBUFFER, loop ? m_fbo : m_context.getRenderContext().getDefaultFramebuffer());
1128 gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1130 // Draw a rect scissored to half the screen height, incrementing the stencil buffer.
1131 gl.enable(GL_SCISSOR_TEST);
1132 gl.scissor(0, 0, m_renderWidth, m_renderHeight / 2);
1133 gl.stencilFunc(GL_ALWAYS, 0x0, 0xFF);
1134 gl.stencilOp(GL_ZERO, GL_INCR, GL_INCR);
1135 GLU_EXPECT_NO_ERROR(gl.getError(), "glStencilOp");
1136 renderColoredQuad(programs[loop]->getProgram(), bigQuadPositionsSet);
1137 gl.disable(GL_SCISSOR_TEST);
1139 // Only draw where stencil is equal to 1
1140 gl.stencilFunc(GL_EQUAL, 0x01, 0xFF);
1141 gl.stencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
1142 gl.clear(GL_COLOR_BUFFER_BIT);
1143 renderColoredQuad(programs[loop]->getProgram(), bigQuadPositionsSet);
1145 glu::readPixels(renderContext, 0, 0, testSurface[1][loop].getAccess());
1147 gl.disable(GL_STENCIL_TEST);
1150 deleteFramebuffer();
1154 // Compare surfaces for non-stencil
1155 if (testNonStencil && !tcu::fuzzyCompare(m_testCtx.getLog(), "Result", "Image comparison result",
1156 testSurface[0][0], testSurface[0][1],
1157 0.05f, tcu::COMPARE_LOG_RESULT))
1159 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Depth subtest failed");
1163 // Compare surfaces for stencil
1164 if (testStencil && !tcu::fuzzyCompare(m_testCtx.getLog(), "Result", "Image comparison result",
1165 testSurface[1][0], testSurface[1][1],
1166 0.05f, tcu::COMPARE_LOG_RESULT))
1168 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Stencil subtest failed");
1172 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1176 void RenderbufferCase::constructOrthoProjMatrix(GLfloat* mat4, GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n,
1179 GLfloat inv_width = 1.0f / (r - l);
1180 GLfloat inv_height = 1.0f / (t - b);
1181 GLfloat inv_depth = 1.0f / (f - n);
1183 memset(mat4, 0, sizeof(GLfloat) * 16);
1191 mat4[0] = 2.0f * inv_width;
1192 mat4[5] = 2.0f * inv_height;
1193 mat4[10] = 2.0f * inv_depth;
1195 mat4[12] = -(r + l) * inv_width;
1196 mat4[13] = -(t + b) * inv_height;
1197 mat4[14] = -(f + n) * inv_depth;
1201 bool RenderbufferCase::createFramebuffer()
1203 glu::RenderContext& renderContext = m_context.getRenderContext();
1204 const Functions& gl = renderContext.getFunctions();
1206 gl.genFramebuffers(1, &m_fbo);
1207 gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
1209 if (m_testFormat.type == RENDERBUFFER_COLOR)
1211 m_rbColor = createAndAttachRenderBuffer(m_testFormat.format, GL_COLOR_ATTACHMENT0);
1212 m_rbDepth = createAndAttachRenderBuffer(GL_DEPTH_COMPONENT16, GL_DEPTH_ATTACHMENT);
1216 m_rbColor = createAndAttachRenderBuffer(GL_RGBA8, GL_COLOR_ATTACHMENT0);
1217 if (m_testFormat.type == RENDERBUFFER_DEPTH)
1218 m_rbDepth = createAndAttachRenderBuffer(m_testFormat.format, GL_DEPTH_ATTACHMENT);
1219 else if (m_testFormat.type == RENDERBUFFER_STENCIL)
1220 m_rbStencil = createAndAttachRenderBuffer(m_testFormat.format, GL_STENCIL_ATTACHMENT);
1221 else if (m_testFormat.type == RENDERBUFFER_DEPTH_STENCIL)
1223 if (glu::contextSupports(renderContext.getType(), glu::ApiType::es(2, 0)))
1225 m_rbDepth = createAndAttachRenderBuffer(m_testFormat.format, GL_DEPTH_ATTACHMENT);
1226 gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_rbDepth);
1227 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer");
1230 m_rbDepth = createAndAttachRenderBuffer(m_testFormat.format, GL_DEPTH_STENCIL_ATTACHMENT);
1234 GLenum bufferStatus = gl.checkFramebufferStatus(GL_FRAMEBUFFER);
1235 if (bufferStatus == GL_FRAMEBUFFER_UNSUPPORTED)
1237 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Unsuported framebuffer");
1240 else if (bufferStatus != GL_FRAMEBUFFER_COMPLETE)
1242 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Framebuffer not complete");
1249 void RenderbufferCase::deleteFramebuffer()
1251 const Functions& gl = m_context.getRenderContext().getFunctions();
1253 gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
1255 gl.deleteFramebuffers(1, &m_fbo);
1257 gl.deleteRenderbuffers(1, &m_rbColor);
1259 gl.deleteRenderbuffers(1, &m_rbDepth);
1261 gl.deleteRenderbuffers(1, &m_rbStencil);
1264 GLuint RenderbufferCase::createAndAttachRenderBuffer(GLenum rbFormat, GLenum fbAttachment)
1266 const Functions& gl = m_context.getRenderContext().getFunctions();
1270 gl.genRenderbuffers(1, &rbName);
1271 gl.bindRenderbuffer(GL_RENDERBUFFER, rbName);
1272 gl.renderbufferStorage(GL_RENDERBUFFER, rbFormat, m_renderWidth, m_renderHeight);
1273 GLU_EXPECT_NO_ERROR(gl.getError(), "glRenderbufferStorage");
1274 gl.framebufferRenderbuffer(GL_FRAMEBUFFER, fbAttachment, GL_RENDERBUFFER, rbName);
1275 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer");
1280 void RenderbufferCase::renderColoredQuad(GLuint programId, const float* positions) const
1282 // Prepare data for rendering
1283 static const deUint16 quadIndices[] = { 0, 1, 2, 2, 1, 3 };
1284 static const float colors[] = {
1285 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,
1287 const glu::VertexArrayBinding vertexArrays[] = { glu::va::Float("position", 3, 4, 0, positions),
1288 glu::va::Float("color", 4, 4, 0, colors) };
1290 glu::draw(m_context.getRenderContext(), programId, DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays,
1291 glu::pr::TriangleStrip(DE_LENGTH_OF_ARRAY(quadIndices), quadIndices));
1294 glu::ProgramSources RenderbufferCase::prepareColoringProgramSources(GLenum format, GLenum type) const
1296 glu::RenderContext& renderContext = m_context.getRenderContext();
1297 glu::ContextType contextType = renderContext.getType();
1298 glu::GLSLVersion glslVersion = glu::getContextTypeGLSLVersion(contextType);
1299 std::string versionDeclaration = glu::getGLSLVersionDeclaration(glslVersion);
1301 std::map<std::string, std::string> specializationMap;
1303 versionDeclaration += "\n";
1304 std::string vs = versionDeclaration;
1305 std::string fs = versionDeclaration;
1306 if (glu::contextSupports(contextType, glu::ApiType::es(3, 0)) || glu::isContextTypeGLCore(contextType))
1308 vs += "in highp vec3 position;\n"
1309 "in highp vec4 color;\n"
1310 "out highp vec4 fColor;\n"
1311 "uniform mat4 mvpMatrix;\n"
1314 " fColor = color;\n"
1315 " gl_Position = mvpMatrix * vec4(position, 1.0);\n"
1317 fs += "in highp vec4 fColor;\n"
1318 "out ${COLOR_DATA} color;\n"
1321 " color = ${COMPUTE_COLOR};\n"
1326 vs += "attribute highp vec3 position;\n"
1327 "attribute highp vec4 color;\n"
1328 "varying highp vec4 fColor;\n"
1329 "uniform mat4 mvpMatrix;\n"
1332 " fColor = color;\n"
1333 " gl_Position = mvpMatrix * vec4(position, 1.0);\n"
1335 fs += "varying highp vec4 fColor;\n"
1338 " gl_FragColor = fColor;\n"
1342 if (format == GL_RGBA_INTEGER)
1344 std::string compute_color = "${COLOR_DATA}("
1345 "${MAX_RED} * fColor.r, "
1346 "${MAX_GREEN} * fColor.g, "
1347 "${MAX_BLUE} * fColor.b, "
1348 "${MAX_ALPHA} * fColor.a)";
1350 if (type == GL_UNSIGNED_INT_2_10_10_10_REV)
1352 specializationMap["MAX_RED"] = "1023";
1353 specializationMap["MAX_GREEN"] = "1023";
1354 specializationMap["MAX_BLUE"] = "1023";
1355 specializationMap["MAX_ALPHA"] = "3";
1359 specializationMap["MAX_RED"] = "255";
1360 specializationMap["MAX_GREEN"] = "255";
1361 specializationMap["MAX_BLUE"] = "255";
1362 specializationMap["MAX_ALPHA"] = "255";
1364 specializationMap["COLOR_DATA"] = "uvec4";
1365 specializationMap["COMPUTE_COLOR"] = tcu::StringTemplate(compute_color).specialize(specializationMap);
1369 specializationMap["COLOR_DATA"] = "highp vec4";
1370 specializationMap["COMPUTE_COLOR"] = "fColor";
1373 vs = tcu::StringTemplate(vs).specialize(specializationMap);
1374 fs = tcu::StringTemplate(fs).specialize(specializationMap);
1375 return glu::makeVtxFragSources(vs.c_str(), fs.c_str());
1378 typedef TextureFormat TF;
1379 typedef CopyTexImageFormat CF;
1380 typedef RenderbufferFormat RF;
1384 std::vector<TextureFormat> texture2DFormats;
1385 std::vector<CopyTexImageFormat> copyTexImageFormats;
1386 std::vector<RenderbufferFormat> renderbufferFormats;
1391 * @param context Rendering context.
1393 InternalformatTests::InternalformatTests(deqp::Context& context)
1394 : TestCaseGroup(context, "internalformat", "Texture internalformat tests")
1398 template <typename Data, unsigned int Size>
1399 void InternalformatTests::append(std::vector<Data>& dataVector, const Data (&dataArray)[Size])
1401 dataVector.insert(dataVector.end(), dataArray, dataArray + Size);
1404 void InternalformatTests::getESTestData(TestData& testData, glu::ContextType& contextType)
1406 TextureFormat commonTexture2DFormats[] = {
1407 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA),
1408 TF(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB),
1409 TF(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA),
1410 TF(GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE_ALPHA),
1411 TF(GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE),
1412 TF(GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA),
1413 TF(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGBA, EXT_texture_type_2_10_10_10_REV),
1414 TF(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2, EXT_texture_type_2_10_10_10_REV),
1415 TF(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB5_A1, EXT_texture_type_2_10_10_10_REV),
1416 TF(GL_RGB, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB, EXT_texture_type_2_10_10_10_REV),
1417 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT, OES_depth_texture),
1418 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT, OES_depth_texture),
1419 TF(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH_STENCIL, OES_packed_depth_stencil, OES_depth_texture),
1420 TF(GL_RGB, GL_HALF_FLOAT, GL_RGB16F, OES_texture_half_float),
1421 TF(GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F, OES_texture_half_float),
1422 TF(GL_RGB, GL_HALF_FLOAT, GL_RGB16F, OES_texture_half_float_linear, DE_NULL, GL_LINEAR, GL_LINEAR),
1423 TF(GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F, OES_texture_half_float_linear, DE_NULL, GL_LINEAR, GL_LINEAR),
1424 TF(GL_RGB, GL_FLOAT, GL_RGB32F, OES_texture_float),
1425 TF(GL_RGBA, GL_FLOAT, GL_RGBA32F, OES_texture_float),
1426 TF(GL_RGB, GL_FLOAT, GL_RGB32F, OES_texture_float_linear, DE_NULL, GL_LINEAR, GL_LINEAR),
1427 TF(GL_RGBA, GL_FLOAT, GL_RGBA32F, OES_texture_float_linear, DE_NULL, GL_LINEAR, GL_LINEAR),
1430 CopyTexImageFormat commonCopyTexImageFormats[] = {
1435 CF(GL_LUMINANCE_ALPHA),
1438 RenderbufferFormat commonRenderbufferFormats[] = {
1439 RF(GL_RGBA8, RENDERBUFFER_COLOR, OES_rgb8_rgba8),
1440 RF(GL_RGB8, RENDERBUFFER_COLOR, OES_rgb8_rgba8),
1443 append(testData.texture2DFormats, commonTexture2DFormats);
1444 append(testData.copyTexImageFormats, commonCopyTexImageFormats);
1445 append(testData.renderbufferFormats, commonRenderbufferFormats);
1447 if (glu::contextSupports(contextType, glu::ApiType::es(3, 0)))
1449 TextureFormat es3Texture2DFormats[] = {
1450 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA4),
1451 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGB5_A1),
1452 TF(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB565),
1453 TF(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4),
1454 TF(GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGBA),
1455 TF(GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1),
1456 TF(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB),
1457 TF(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565),
1458 TF(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8),
1459 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8),
1460 TF(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8),
1463 CopyTexImageFormat es3CopyTexImageFormats[] = {
1471 RenderbufferFormat es3RenderbufferFormats[] = {
1472 RF(GL_RGB5_A1, RENDERBUFFER_COLOR),
1475 append(testData.texture2DFormats, es3Texture2DFormats);
1476 append(testData.copyTexImageFormats, es3CopyTexImageFormats);
1477 append(testData.renderbufferFormats, es3RenderbufferFormats);
1479 else if (glu::contextSupports(contextType, glu::ApiType::es(2, 0)))
1481 TextureFormat es2Texture2DFormats[] = {
1482 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGB5_A1, OES_required_internalformat),
1483 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA4, OES_required_internalformat),
1484 TF(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB565, OES_required_internalformat),
1485 TF(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4, OES_required_internalformat),
1486 TF(GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGBA, OES_required_internalformat),
1487 TF(GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1, OES_required_internalformat),
1488 TF(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB, OES_required_internalformat),
1489 TF(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565, OES_required_internalformat),
1490 TF(GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_OES, OES_required_internalformat),
1491 TF(GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE4_ALPHA4_OES, OES_required_internalformat),
1492 TF(GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_OES, OES_required_internalformat),
1493 TF(GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_OES, OES_required_internalformat),
1494 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT16, OES_required_internalformat,
1496 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16, OES_required_internalformat,
1498 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT24, OES_required_internalformat, OES_depth24),
1499 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32, OES_required_internalformat, OES_depth32),
1502 CopyTexImageFormat es2CopyTexImageFormats[] = {
1503 CF(GL_RGB5_A1, OES_required_internalformat),
1504 CF(GL_RGB565, OES_required_internalformat),
1505 CF(GL_RGBA4, OES_required_internalformat),
1506 CF(GL_LUMINANCE4_ALPHA4_OES, OES_required_internalformat),
1507 CF(GL_LUMINANCE8_ALPHA8_OES, OES_required_internalformat),
1508 CF(GL_LUMINANCE8_OES, OES_required_internalformat),
1509 CF(GL_ALPHA8_OES, OES_required_internalformat),
1510 CF(GL_RGB10_A2, EXT_texture_type_2_10_10_10_REV, OES_required_internalformat),
1511 CF(GL_RGB10, EXT_texture_type_2_10_10_10_REV, OES_required_internalformat)
1514 RenderbufferFormat es2RenderbufferFormats[] = {
1515 RF(GL_STENCIL_INDEX1, RENDERBUFFER_STENCIL, OES_stencil1),
1516 RF(GL_STENCIL_INDEX4, RENDERBUFFER_STENCIL, OES_stencil4),
1517 RF(GL_STENCIL_INDEX8, RENDERBUFFER_STENCIL, OES_stencil8),
1518 RF(GL_DEPTH_COMPONENT16, RENDERBUFFER_DEPTH, OES_depth_texture),
1519 RF(GL_DEPTH_COMPONENT24, RENDERBUFFER_DEPTH, OES_depth24),
1520 RF(GL_DEPTH_COMPONENT32, RENDERBUFFER_DEPTH, OES_depth32),
1521 RF(GL_DEPTH24_STENCIL8, RENDERBUFFER_DEPTH_STENCIL, OES_packed_depth_stencil),
1522 RF(GL_RGB5_A1, RENDERBUFFER_COLOR, OES_required_internalformat),
1525 append(testData.texture2DFormats, es2Texture2DFormats);
1526 append(testData.copyTexImageFormats, es2CopyTexImageFormats);
1527 append(testData.renderbufferFormats, es2RenderbufferFormats);
1531 void InternalformatTests::getGLTestData(TestData& testData, glu::ContextType&)
1533 TextureFormat commonTexture2DFormats[] = {
1534 TF(GL_RED, GL_BYTE, GL_R8_SNORM),
1535 TF(GL_RED, GL_SHORT, GL_R16_SNORM),
1536 TF(GL_RG, GL_BYTE, GL_RG8_SNORM),
1537 TF(GL_RG, GL_SHORT, GL_RG16_SNORM),
1538 TF(GL_RGB, GL_BYTE, GL_RGB8_SNORM),
1539 TF(GL_RGB, GL_SHORT, GL_RGB16_SNORM),
1540 TF(GL_RGBA, GL_BYTE, GL_RGBA8_SNORM),
1541 TF(GL_RGBA, GL_SHORT, GL_RGBA16_SNORM),
1542 TF(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGBA),
1543 TF(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2),
1544 TF(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB5_A1),
1545 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT, ARB_depth_texture),
1546 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16, ARB_depth_texture),
1547 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT, ARB_depth_texture),
1548 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT24, ARB_depth_texture),
1549 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32, ARB_depth_texture),
1550 TF(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT16, ARB_depth_texture),
1551 TF(GL_RGBA, GL_UNSIGNED_BYTE, GL_RGB9_E5, EXT_texture_shared_exponent),
1552 TF(GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2UI, ARB_texture_rgb10_a2ui),
1553 TF(GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_RGBA32UI, EXT_texture_integer),
1554 TF(GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_RGB32UI, EXT_texture_integer),
1555 TF(GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_RGBA16UI, EXT_texture_integer),
1556 TF(GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_RGB16UI, EXT_texture_integer),
1557 TF(GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_RGBA8UI, EXT_texture_integer),
1558 TF(GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_RGB8UI, EXT_texture_integer),
1559 TF(GL_RGBA_INTEGER, GL_INT, GL_RGBA32I, EXT_texture_integer),
1560 TF(GL_RGB_INTEGER, GL_INT, GL_RGB32I, EXT_texture_integer),
1561 TF(GL_RGBA_INTEGER, GL_SHORT, GL_RGBA16I, EXT_texture_integer),
1562 TF(GL_RGB_INTEGER, GL_SHORT, GL_RGB16I, EXT_texture_integer),
1563 TF(GL_RGBA_INTEGER, GL_BYTE, GL_RGBA8I, EXT_texture_integer),
1564 TF(GL_RGB_INTEGER, GL_BYTE, GL_RGB8I, EXT_texture_integer),
1565 TF(GL_RED, GL_HALF_FLOAT, GL_R16F, ARB_texture_float),
1566 TF(GL_RG, GL_HALF_FLOAT, GL_RG16F, ARB_texture_float),
1567 TF(GL_RGB, GL_HALF_FLOAT, GL_RGB16F, ARB_texture_float),
1568 TF(GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F, ARB_texture_float),
1569 TF(GL_RED, GL_FLOAT, GL_R32F, ARB_texture_float),
1570 TF(GL_RG, GL_FLOAT, GL_RG32F, ARB_texture_float),
1571 TF(GL_RGB, GL_FLOAT, GL_RGB32F, ARB_texture_float),
1572 TF(GL_RGBA, GL_FLOAT, GL_RGBA32F, ARB_texture_float),
1575 CopyTexImageFormat commonCopyTexImageFormats[] = {
1576 CF(GL_DEPTH_COMPONENT16, ARB_depth_texture),
1577 CF(GL_DEPTH_COMPONENT24, ARB_depth_texture),
1578 CF(GL_DEPTH_COMPONENT32, ARB_depth_texture),
1579 CF(GL_RGB9_E5, EXT_texture_shared_exponent),
1580 CF(GL_RGB10_A2UI, ARB_texture_rgb10_a2ui),
1584 RenderbufferFormat commonRenderbufferFormats[] = {
1585 RF(GL_RGBA8, RENDERBUFFER_COLOR),
1586 RF(GL_RGB9_E5, RENDERBUFFER_COLOR, EXT_texture_shared_exponent),
1587 RF(GL_RGB10_A2UI, RENDERBUFFER_COLOR, ARB_texture_rgb10_a2ui),
1588 RF(GL_DEPTH24_STENCIL8, RENDERBUFFER_DEPTH_STENCIL),
1589 RF(GL_DEPTH_COMPONENT16, RENDERBUFFER_DEPTH, ARB_depth_texture),
1590 RF(GL_DEPTH_COMPONENT24, RENDERBUFFER_DEPTH, ARB_depth_texture),
1591 RF(GL_DEPTH_COMPONENT32, RENDERBUFFER_DEPTH, ARB_depth_texture),
1594 append(testData.texture2DFormats, commonTexture2DFormats);
1595 append(testData.copyTexImageFormats, commonCopyTexImageFormats);
1596 append(testData.renderbufferFormats, commonRenderbufferFormats);
1599 std::string formatToString(GLenum format)
1601 // this function extends glu::getTextureFormatStr by formats used in thise tests
1603 typedef std::map<GLenum, std::string> FormatMap;
1604 static FormatMap formatMap;
1605 if (formatMap.empty())
1607 // store in map formats that are not supported by glu::getTextureFormatStr
1608 formatMap[GL_LUMINANCE8_ALPHA8_OES] = "luminance8_alpha8_oes";
1609 formatMap[GL_LUMINANCE4_ALPHA4_OES] = "luminance4_alpha4_oes";
1610 formatMap[GL_STENCIL_INDEX1_OES] = "stencil_index1_oes";
1611 formatMap[GL_STENCIL_INDEX4_OES] = "stencil_index4_oes";
1612 formatMap[GL_LUMINANCE8_OES] = "luminance8_oes";
1613 formatMap[GL_ALPHA8_OES] = "alpha8_oes";
1616 FormatMap::iterator it = formatMap.find(format);
1617 if (it == formatMap.end())
1619 // if format is not in map try glu function
1620 std::string formatString = glu::getTextureFormatStr(format).toString();
1622 // cut out "GL_" from string
1623 formatString = formatString.substr(3, formatString.length());
1626 std::transform(formatString.begin(), formatString.end(), formatString.begin(), tolower);
1628 return formatString;
1633 /** Initializes the test group contents. */
1634 void InternalformatTests::init()
1636 // Determine which data sets should be used for tests
1638 glu::ContextType contextType = m_context.getRenderContext().getType();
1639 if (glu::isContextTypeGLCore(contextType))
1640 getGLTestData(testData, contextType);
1642 getESTestData(testData, contextType);
1644 // Construct texture2d tests
1645 TestCaseGroup* texture2DGroup = new deqp::TestCaseGroup(m_context, "texture2d", "");
1646 for (unsigned int i = 0; i < testData.texture2DFormats.size(); i++)
1648 const TextureFormat& tf = testData.texture2DFormats[i];
1649 std::string format = formatToString(tf.format);
1650 std::string type = glu::getTypeStr(tf.type).toString();
1651 std::string internalFormat = formatToString(tf.internalFormat);
1653 // cut out "GL_" from type and make it lowercase
1654 type = type.substr(3, type.length());
1655 std::transform(type.begin(), type.end(), type.begin(), tolower);
1657 std::string name = format + "_" + type + "_" + internalFormat;
1658 if (tf.minFilter == GL_LINEAR)
1661 texture2DGroup->addChild(new Texture2DCase(m_context, name, tf));
1663 addChild(texture2DGroup);
1665 // Construct copy_text_image tests
1666 TestCaseGroup* copyTexImageGroup = new deqp::TestCaseGroup(m_context, "copy_tex_image", "");
1667 for (unsigned int i = 0; i < testData.copyTexImageFormats.size(); i++)
1669 const CopyTexImageFormat& ctif = testData.copyTexImageFormats[i];
1670 std::string name = formatToString(ctif.internalFormat);
1671 copyTexImageGroup->addChild(new CopyTexImageCase(m_context, name, ctif));
1673 addChild(copyTexImageGroup);
1675 // Construct renderbuffer tests
1676 TestCaseGroup* renderbufferGroup = new deqp::TestCaseGroup(m_context, "renderbuffer", "");
1677 for (unsigned int i = 0; i < testData.renderbufferFormats.size(); i++)
1679 const RenderbufferFormat& rbf = testData.renderbufferFormats[i];
1680 std::string name = formatToString(rbf.format);
1681 renderbufferGroup->addChild(new RenderbufferCase(m_context, name, rbf));
1683 addChild(renderbufferGroup);
1686 void RenderbufferCase::convertUInt(const tcu::PixelBufferAccess &src, const tcu::PixelBufferAccess &dst)
1688 for (int z = 0; z < dst.getDepth(); ++z)
1689 for (int y = 0; y < dst.getHeight(); ++y)
1690 for (int x = 0; x < dst.getWidth(); ++x)
1692 tcu::UVec4 srcPixel = src.getPixelUint(x, y, z);
1693 tcu::Vec4 dstPixel(srcPixel.x() / 255.0f, srcPixel.y() / 255.0f, srcPixel.z() / 255.0f, srcPixel.w() / 255.0f);
1694 dst.setPixel(dstPixel, x, y, z);
1698 void RenderbufferCase::convertUInt_2_10_10_10_rev(const tcu::PixelBufferAccess &src, const tcu::PixelBufferAccess &dst)
1700 for (int z = 0; z < dst.getDepth(); ++z)
1701 for (int y = 0; y < dst.getHeight(); ++y)
1702 for (int x = 0; x < dst.getWidth(); ++x)
1704 tcu::UVec4 srcPixel = src.getPixelUint(x, y, z);
1705 tcu::Vec4 dstPixel(srcPixel.x() / 1023.0f, srcPixel.y() / 1023.0f, srcPixel.z() / 1023.0f, srcPixel.w() / 3.0f);
1706 dst.setPixel(dstPixel, x, y, z);
1709 } /* glcts namespace */