1 /*-------------------------------------------------------------------------
2 * OpenGL Conformance Test Suite
3 * -----------------------------
5 * Copyright (c) 2015-2016 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.
22 */ /*-------------------------------------------------------------------*/
25 * \file gl3cTextureSizePromotionTests.hpp
26 * \brief Implements test classes for testing of texture internal format
28 */ /*-------------------------------------------------------------------*/
30 #include "gl3cTextureSizePromotion.hpp"
33 #include "gluContextInfo.hpp"
34 #include "gluStrUtil.hpp"
35 #include "glwFunctions.hpp"
36 #include "tcuTestLog.hpp"
38 /* Stringify macro. */
39 #define _STR(s) STR(s)
44 namespace TextureSizePromotion
46 Tests::Tests(deqp::Context& context)
47 : TestCaseGroup(context, "texture_size_promotion", "Verifies texture internal format size promotion mechanism.")
49 /* Left blank on purpose */
52 void Tests::init(void)
54 addChild(new TextureSizePromotion::FunctionalTest(m_context));
57 /*===========================================================================================================*/
59 FunctionalTest::FunctionalTest(deqp::Context& context)
60 : TestCase(context, "functional", "Verifies that texture internal format size promotion mechanism can be used.")
63 , m_destination_texture(0)
68 /* Left blank on purpose */
71 tcu::TestNode::IterateResult FunctionalTest::iterate()
73 /* Get context setup. */
74 glu::ContextType context_type = m_context.getRenderContext().getType();
75 bool is_arb_texture_storage_multisample =
76 m_context.getContextInfo().isExtensionSupported("GL_ARB_texture_storage_multisample");
78 /* Prepare initial results. */
80 bool was_error = false;
82 /* Iterate over test cases. */
85 /* Only for OpenGL 3.1 context. */
86 if (glu::contextSupports(context_type, glu::ApiType::core(3, 1)))
88 /* Generate and bind VAO. */
89 prepareVertexArrayObject();
91 /* For every required format */
92 for (glw::GLuint i = 0; i < s_formats_size; ++i)
94 /* Test only if format is required by context. */
95 if (glu::contextSupports(context_type, s_formats[i].required_by_context.getAPI()))
97 /* For every target. */
98 for (glw::GLuint j = 0; j < s_source_texture_targets_count; ++j)
100 /* Test if it is supported by context or internal format. */
101 if (isTargetMultisampled(s_source_texture_targets[j]))
103 if ((!is_arb_texture_storage_multisample) &&
104 (!glu::contextSupports(context_type, glu::ApiType::core(4, 3))))
110 .is_color_renderable) /* Multisampled textures need to be set using rendering. */
115 if (isDepthType(s_formats[i]) || isStencilType(s_formats[i]))
121 if ((isDepthType(s_formats[i]) || isStencilType(s_formats[i])) &&
122 (GL_TEXTURE_3D == s_source_texture_targets[j]))
127 /* Prepare source texture to be tested. */
128 prepareSourceTexture(s_formats[i], s_source_texture_targets[j]);
130 /* Check basic API queries for source texture. */
131 is_ok = is_ok & checkSourceTextureSizeAndType(s_formats[i], s_source_texture_targets[j]);
133 /* For every [R, G, B, A] component. */
134 for (glw::GLuint k = 0; k < COMPONENTS_COUNT; ++k)
136 /* Prepare destination texture. */
137 prepareDestinationTextureAndFramebuffer(s_formats[i], GL_TEXTURE_2D);
139 /* Building program (throws on failure). */
141 prepareProgram(s_source_texture_targets[j], s_formats[i], ColorChannelSelector(k));
143 /* Setup GL and draw. */
144 makeProgramAndSourceTextureActive(s_source_texture_targets[j]);
149 is_ok = is_ok & checkDestinationTexture(s_formats[i], ColorChannelSelector(k),
150 s_source_texture_targets[j],
151 s_source_texture_targets_names[j]);
154 cleanDestinationTexture();
159 cleanSourceTexture();
167 /* Error have occured. */
174 cleanSourceTexture();
175 cleanDestinationTexture();
178 cleanVertexArrayObject();
180 /* Result's setup. */
184 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Texture Size Promotion Test have passed."
185 << tcu::TestLog::EndMessage;
187 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
194 m_context.getTestContext().getLog() << tcu::TestLog::Message
195 << "Texture Size Promotion Test have approached error."
196 << tcu::TestLog::EndMessage;
198 m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
203 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Texture Size Promotion Test have failed."
204 << tcu::TestLog::EndMessage;
206 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
211 return tcu::TestNode::STOP;
214 void FunctionalTest::prepareVertexArrayObject()
216 /* GL functions object. */
217 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
219 gl.genVertexArrays(1, &m_vao);
220 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays have failed");
222 gl.bindVertexArray(m_vao);
223 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray have failed");
226 void FunctionalTest::prepareSourceTexture(TextureInternalFormatDescriptor descriptor, glw::GLenum target)
228 /* GL functions object. */
229 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
231 /* Create and bind texture object. */
232 gl.genTextures(1, &m_source_texture);
233 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv have failed");
235 gl.bindTexture(target, m_source_texture);
236 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv have failed");
238 /* Select proper data set. */
239 glw::GLvoid* source_data = DE_NULL;
240 glw::GLenum source_type = GL_NONE;
241 glw::GLenum source_format = GL_RGBA;
243 if (isFloatType(descriptor)) /* For floating type. */
245 source_data = (glw::GLvoid*)s_source_texture_data_f;
246 source_type = GL_FLOAT;
247 source_format = GL_RGBA;
251 if (isFixedSignedType(descriptor)) /* For fixed signed type. */
253 source_data = (glw::GLvoid*)s_source_texture_data_sn;
254 source_type = GL_FLOAT;
255 source_format = GL_RGBA;
259 if (isFixedUnsignedType(descriptor)) /* For fixed unsigned type. */
261 source_data = (glw::GLvoid*)s_source_texture_data_n;
262 source_type = GL_FLOAT;
263 source_format = GL_RGBA;
267 if (isIntegerSignedType(descriptor)) /* For integral signed type. */
269 source_data = (glw::GLvoid*)s_source_texture_data_i;
270 source_type = GL_INT;
271 source_format = GL_RGBA_INTEGER;
275 if (isIntegerUnsignedType(descriptor)) /* For integral unsigned type. */
277 source_data = (glw::GLvoid*)s_source_texture_data_ui;
278 source_type = GL_UNSIGNED_INT;
279 source_format = GL_RGBA_INTEGER;
283 if (isDepthType(descriptor)) /* For depth type. */
286 source_type = GL_UNSIGNED_INT;
287 source_format = GL_DEPTH_COMPONENT;
291 if (isStencilType(descriptor)) /* For stencil type. */
294 source_type = GL_UNSIGNED_INT;
295 source_format = GL_STENCIL_INDEX;
304 /* Prepare texture storage depending on the target. */
308 gl.texImage1D(target, 0, descriptor.internal_format, s_source_texture_size, 0, source_format, source_type,
310 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv have failed");
312 case GL_TEXTURE_1D_ARRAY:
314 case GL_TEXTURE_RECTANGLE:
315 gl.texImage2D(target, 0, descriptor.internal_format, s_source_texture_size, s_source_texture_size, 0,
316 source_format, source_type, source_data);
317 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv have failed");
319 case GL_TEXTURE_2D_ARRAY:
321 gl.texImage3D(target, 0, descriptor.internal_format, s_source_texture_size, s_source_texture_size,
322 s_source_texture_size, 0, source_format, source_type, source_data);
323 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv have failed");
325 case GL_TEXTURE_2D_MULTISAMPLE:
326 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
327 renderDataIntoMultisampledTexture(descriptor, target);
334 void FunctionalTest::renderDataIntoMultisampledTexture(TextureInternalFormatDescriptor descriptor, glw::GLenum target)
336 /* GL functions object. */
337 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
340 gl.getIntegerv(GL_MAX_SAMPLES, &m_max_samples);
341 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv have failed");
343 if (m_max_samples == 0)
349 glw::GLenum non_ms_target = (target == GL_TEXTURE_2D_MULTISAMPLE) ? GL_TEXTURE_2D : GL_TEXTURE_2D_ARRAY;
351 /* Cleanup required by prepareSourceTexture(...). */
352 cleanSourceTexture();
354 /* Prepare textures and program. */
355 prepareSourceTexture(descriptor, non_ms_target);
357 prepareDestinationTextureAndFramebuffer(descriptor, target);
359 m_program = prepareProgram(non_ms_target, descriptor, COMPONENTS_COUNT);
361 /* Setup GL and render texture. */
362 makeProgramAndSourceTextureActive(non_ms_target);
368 cleanSourceTexture();
370 /* Swpaing destination texture to source texture. */
371 m_source_texture = m_destination_texture;
373 m_destination_texture = 0;
379 void FunctionalTest::prepareDestinationTextureAndFramebuffer(TextureInternalFormatDescriptor descriptor,
382 /* GL functions object. */
383 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
385 /* Get internal format. */
386 glw::GLenum internal_format = getDestinationFormatForChannel(descriptor);
388 /* Create framebuffer object. */
389 gl.genFramebuffers(1, &m_framebuffer);
390 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
392 gl.bindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
393 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
395 /* Create framebuffer's destination texture. */
396 gl.genTextures(1, &m_destination_texture);
397 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv have failed");
399 gl.bindTexture(target, m_destination_texture);
400 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv have failed");
402 /* Allocate texture storage and upload data for test rendering. */
403 if (target == GL_TEXTURE_2D)
405 glw::GLenum destination_format = GL_RED;
406 glw::GLenum destination_type = GL_FLOAT;
407 glw::GLvoid* destination_data = (glw::GLvoid*)s_destination_texture_data_f;
409 if (isIntegerSignedType(descriptor))
411 destination_format = GL_RED_INTEGER;
412 destination_type = GL_INT;
413 destination_data = (glw::GLvoid*)s_destination_texture_data_i;
416 if (isIntegerUnsignedType(descriptor))
418 destination_format = GL_RED_INTEGER;
419 destination_type = GL_UNSIGNED_INT;
420 destination_data = (glw::GLvoid*)s_destination_texture_data_ui;
423 gl.texImage2D(target, 0, internal_format, s_source_texture_size, s_source_texture_size, 0, destination_format,
424 destination_type, destination_data);
425 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv have failed");
427 gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_destination_texture, 0);
428 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture2D have failed");
430 else /* Allocate texture storage for uploading datat for multisampled targets (upload must be done via shader). */
432 if (target == GL_TEXTURE_2D_MULTISAMPLE)
434 gl.texImage2DMultisample(target, m_max_samples - 1, descriptor.internal_format, s_source_texture_size,
435 s_source_texture_size, GL_TRUE);
436 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv have failed");
438 gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, m_destination_texture, 0);
439 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture2D have failed");
443 gl.texImage3DMultisample(target, m_max_samples - 1, descriptor.internal_format, s_source_texture_size,
444 s_source_texture_size, s_source_texture_size, GL_TRUE);
445 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv have failed");
447 gl.framebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_destination_texture, 0, 0);
448 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture2D have failed");
452 /* Check framebuffer completness. */
453 if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
458 /* Setup viewport. */
459 gl.viewport(0, 0, s_source_texture_size, s_source_texture_size);
460 GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
463 void FunctionalTest::makeProgramAndSourceTextureActive(glw::GLenum target)
465 /* GL functions object. */
466 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
468 /* Use GLSL program. */
469 gl.useProgram(m_program);
470 GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram have failed");
472 /* Setup source texture. */
473 gl.activeTexture(GL_TEXTURE0);
474 GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture have failed");
476 gl.bindTexture(target, m_source_texture);
477 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv have failed");
479 glw::GLint location = gl.getUniformLocation(m_program, "data");
480 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetUniformLocation have failed");
482 gl.uniform1i(location, 0);
483 GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i have failed");
486 bool FunctionalTest::checkSourceTextureSizeAndType(TextureInternalFormatDescriptor descriptor, glw::GLenum target)
488 /* GL functions object. */
489 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
491 /* query result storage */
492 glw::GLint red_size = 0;
493 glw::GLint blue_size = 0;
494 glw::GLint green_size = 0;
495 glw::GLint alpha_size = 0;
496 glw::GLint depth_size = 0;
497 glw::GLint stencil_size = 0;
499 glw::GLint red_type = 0;
500 glw::GLint green_type = 0;
501 glw::GLint blue_type = 0;
502 glw::GLint alpha_type = 0;
503 glw::GLint depth_type = 0;
506 gl.bindTexture(target, m_source_texture);
507 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv have failed");
510 gl.getTexLevelParameteriv(target, 0, GL_TEXTURE_RED_SIZE, &red_size);
511 gl.getTexLevelParameteriv(target, 0, GL_TEXTURE_GREEN_SIZE, &green_size);
512 gl.getTexLevelParameteriv(target, 0, GL_TEXTURE_BLUE_SIZE, &blue_size);
513 gl.getTexLevelParameteriv(target, 0, GL_TEXTURE_ALPHA_SIZE, &alpha_size);
514 gl.getTexLevelParameteriv(target, 0, GL_TEXTURE_DEPTH_SIZE, &depth_size);
515 gl.getTexLevelParameteriv(target, 0, GL_TEXTURE_STENCIL_SIZE, &stencil_size);
517 gl.getTexLevelParameteriv(target, 0, GL_TEXTURE_RED_TYPE, &red_type);
518 gl.getTexLevelParameteriv(target, 0, GL_TEXTURE_GREEN_TYPE, &green_type);
519 gl.getTexLevelParameteriv(target, 0, GL_TEXTURE_BLUE_TYPE, &blue_type);
520 gl.getTexLevelParameteriv(target, 0, GL_TEXTURE_ALPHA_TYPE, &alpha_type);
521 gl.getTexLevelParameteriv(target, 0, GL_TEXTURE_DEPTH_TYPE, &depth_type);
523 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv have failed");
525 /* check expected values */
528 is_ok = is_ok && (red_size >= descriptor.min_red_size);
529 is_ok = is_ok && (green_size >= descriptor.min_green_size);
530 is_ok = is_ok && (blue_size >= descriptor.min_blue_size);
531 is_ok = is_ok && (alpha_size >= descriptor.min_alpha_size);
532 is_ok = is_ok && (depth_size >= descriptor.min_depth_size);
533 is_ok = is_ok && (stencil_size >= descriptor.min_stencil_size);
535 is_ok = is_ok && ((glw::GLenum)red_type == descriptor.expected_red_type);
536 is_ok = is_ok && ((glw::GLenum)green_type == descriptor.expected_green_type);
537 is_ok = is_ok && ((glw::GLenum)blue_type == descriptor.expected_blue_type);
538 is_ok = is_ok && ((glw::GLenum)alpha_type == descriptor.expected_alpha_type);
539 is_ok = is_ok && ((glw::GLenum)depth_type == descriptor.expected_depth_type);
541 /* Log on failure. */
544 m_context.getTestContext().getLog()
545 << tcu::TestLog::Message << "Promotion from internal format " << descriptor.internal_format_name
546 << " have failed during glGetTexLevelParameteriv query. "
547 << "Expected red size = " << descriptor.min_red_size
548 << ", expected green size = " << descriptor.min_green_size
549 << ", expected blue size = " << descriptor.min_blue_size
550 << ", expected alpha size = " << descriptor.min_alpha_size
551 << ", expected depth size = " << descriptor.min_depth_size
552 << ", expected stencil size = " << descriptor.min_stencil_size << ". Queried red size = " << red_size
553 << ", queried green size = " << green_size << ", queried blue size = " << blue_size
554 << ", queried alpha size = " << alpha_size << ", queried depth size = " << depth_size
555 << ", queried stencil size = " << stencil_size << ". "
556 << "Expected red type = " << glu::getTypeStr(descriptor.expected_red_type)
557 << ", expected green type = " << glu::getTypeStr(descriptor.expected_green_type)
558 << ", expected blue type = " << glu::getTypeStr(descriptor.expected_blue_type)
559 << ", expected alpha type = " << glu::getTypeStr(descriptor.expected_alpha_type)
560 << ", expected depth type = " << glu::getTypeStr(descriptor.expected_depth_type)
561 << ". Queried red type = " << glu::getTypeStr(red_type)
562 << ", queried green type = " << glu::getTypeStr(green_type)
563 << ", queried blue type = " << glu::getTypeStr(blue_type)
564 << ", queried alpha type = " << glu::getTypeStr(alpha_type)
565 << ", queried depth type = " << glu::getTypeStr(depth_type) << "." << tcu::TestLog::EndMessage;
568 /* return results. */
572 glw::GLenum FunctionalTest::getDestinationFormatForChannel(TextureInternalFormatDescriptor descriptor)
574 if (isFloatType(descriptor))
579 if (isFixedUnsignedType(descriptor))
584 if (isFixedSignedType(descriptor))
589 if (isIntegerUnsignedType(descriptor))
594 if (isIntegerSignedType(descriptor))
602 glw::GLuint FunctionalTest::prepareProgram(glw::GLenum target, TextureInternalFormatDescriptor descriptor,
603 ColorChannelSelector channel)
605 /* GL functions object. */
606 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
608 /* Preparing sampler name and textelFetch arguments */
609 std::string sampler_name = "";
610 std::string texel_fetch_arguments_tail = "";
615 sampler_name = "sampler1D";
616 texel_fetch_arguments_tail = "0, 0";
619 sampler_name = "sampler2D";
620 texel_fetch_arguments_tail = "ivec2(0), 0";
622 case GL_TEXTURE_1D_ARRAY:
623 sampler_name = "sampler1DArray";
624 texel_fetch_arguments_tail = "ivec2(0), 0";
626 case GL_TEXTURE_RECTANGLE:
627 sampler_name = "sampler2DRect";
628 texel_fetch_arguments_tail = "ivec2(0)";
630 case GL_TEXTURE_2D_ARRAY:
631 sampler_name = "sampler2DArray";
632 texel_fetch_arguments_tail = "ivec3(0), 0";
635 sampler_name = "sampler3D";
636 texel_fetch_arguments_tail = "ivec3(0), 0";
638 case GL_TEXTURE_2D_MULTISAMPLE:
639 sampler_name = "sampler2DMS";
640 texel_fetch_arguments_tail = "ivec2(0), ";
641 texel_fetch_arguments_tail.append(Utilities::itoa(m_max_samples - 1));
643 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
644 sampler_name = "sampler2DMSArray";
645 texel_fetch_arguments_tail = "ivec3(0), ";
646 texel_fetch_arguments_tail.append(Utilities::itoa(m_max_samples - 1));
652 /* Preparing component selector name */
653 std::string component_name = "";
658 component_name = ".r";
660 case GREEN_COMPONENT:
661 component_name = ".g";
664 component_name = ".b";
666 case ALPHA_COMPONENT:
667 component_name = ".a";
669 case COMPONENTS_COUNT:
675 /* Preparing output type name and sampler prefix */
676 std::string type_name = "";
677 std::string sampler_prefix = "";
679 if (isFloatType(descriptor) || isFixedSignedType(descriptor) || isFixedUnsignedType(descriptor) ||
680 isDepthType(descriptor) || isStencilType(descriptor))
682 if (channel == COMPONENTS_COUNT)
694 if (isIntegerSignedType(descriptor))
696 if (channel == COMPONENTS_COUNT)
704 sampler_prefix = "i";
708 if (channel == COMPONENTS_COUNT)
716 sampler_prefix = "u";
720 std::string template_verison = "#version 150";
722 /* Preprocessing fragment shader source code. */
723 std::string fragment_shader = s_fragment_shader_template;
725 fragment_shader = Utilities::preprocessString(fragment_shader, "TEMPLATE_TYPE", type_name);
727 Utilities::preprocessString(fragment_shader, "TEMPLATE_SAMPLER", sampler_prefix.append(sampler_name));
729 Utilities::preprocessString(fragment_shader, "TEMPLATE_TEXEL_FETCH_ARGUMENTS", texel_fetch_arguments_tail);
730 fragment_shader = Utilities::preprocessString(fragment_shader, "TEMPLATE_COMPONENT", component_name);
732 /* Building program. */
733 glw::GLuint program =
734 Utilities::buildProgram(gl, m_context.getTestContext().getLog(), s_vertex_shader_code, fragment_shader.c_str());
741 /* Return program name. */
745 void FunctionalTest::drawQuad()
747 /* GL functions object. */
748 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
751 gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
752 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays have failed");
755 void FunctionalTest::cleanSourceTexture()
757 /* GL functions object. */
758 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
761 if (m_source_texture)
763 gl.deleteTextures(1, &m_source_texture);
764 GLU_EXPECT_NO_ERROR(gl.getError(), "glDeleteTextures have failed");
766 m_source_texture = 0;
770 void FunctionalTest::cleanDestinationTexture()
772 /* GL functions object. */
773 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
776 if (m_destination_texture)
778 gl.deleteTextures(1, &m_destination_texture);
780 m_destination_texture = 0;
784 void FunctionalTest::cleanFramebuffer()
786 /* GL functions object. */
787 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
792 gl.deleteFramebuffers(1, &m_framebuffer);
798 void FunctionalTest::cleanProgram()
800 /* GL functions object. */
801 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
808 gl.deleteProgram(m_program);
814 void FunctionalTest::cleanVertexArrayObject()
816 /* GL functions object. */
817 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
822 gl.deleteVertexArrays(1, &m_vao);
828 bool FunctionalTest::checkDestinationTexture(TextureInternalFormatDescriptor descriptor, ColorChannelSelector channel,
829 glw::GLenum target, const glw::GLchar* target_name)
831 /* GL functions object. */
832 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
834 /* Check depending on format. */
835 if (isFloatType(descriptor) || isDepthType(descriptor) || isStencilType(descriptor))
837 /* Fetch results from destination texture (attached to current framebuffer). */
838 glw::GLfloat pixel = 3.1415927f;
839 gl.readPixels(0, 0, 1, 1, GL_RED, GL_FLOAT, &pixel);
840 GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels have failed");
842 /* Setup expected value. */
843 glw::GLfloat expected_value = isChannelTypeNone(descriptor, channel) ?
844 ((channel == ALPHA_COMPONENT) ? 1.f : 0.f) :
845 s_source_texture_data_f[channel];
847 /* Compare expected and fetched values. */
848 if (fabs(pixel - expected_value) <= getMinPrecision(descriptor, channel))
856 m_context.getTestContext().getLog()
857 << tcu::TestLog::Message << "Promotion from internal format " << descriptor.internal_format_name
858 << " have failed during functional test of " << s_color_channel_names[channel]
859 << " channel with target " << target_name << ". Expected value = " << expected_value
860 << " read value = " << pixel << "." << tcu::TestLog::EndMessage;
865 if (isFixedSignedType(descriptor))
867 /* Fetch results from destination texture (attached to current framebuffer). */
868 glw::GLfloat pixel = 3.1415927f;
869 gl.readPixels(0, 0, 1, 1, GL_RED, GL_FLOAT, &pixel);
870 GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels have failed");
872 /* Setup expected value. */
873 glw::GLfloat expected_value = isChannelTypeNone(descriptor, channel) ?
874 ((channel == ALPHA_COMPONENT) ? 1.f : 0.f) :
875 s_source_texture_data_sn[channel];
877 /* Compare expected and fetched values. */
878 if (fabs(pixel - expected_value) <= getMinPrecision(descriptor, channel))
886 m_context.getTestContext().getLog()
887 << tcu::TestLog::Message << "Promotion from internal format " << descriptor.internal_format_name
888 << " have failed during functional test of " << s_color_channel_names[channel]
889 << " channel with target " << target_name << ". Expected value = " << expected_value
890 << " read value = " << pixel << "." << tcu::TestLog::EndMessage;
895 if (isFixedUnsignedType(descriptor))
897 /* Fetch results from destination texture (attached to current framebuffer). */
898 glw::GLfloat pixel = 3.1415927f;
899 gl.readPixels(0, 0, 1, 1, GL_RED, GL_FLOAT, &pixel);
900 GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels have failed");
902 /* Setup expected value. */
903 glw::GLfloat expected_value = isChannelTypeNone(descriptor, channel) ?
904 ((channel == ALPHA_COMPONENT) ? 1.f : 0.f) :
905 s_source_texture_data_n[channel];
907 /* For sRGB internal formats convert value to linear space. */
908 if (descriptor.is_sRGB && (channel < ALPHA_COMPONENT))
910 expected_value = convert_from_sRGB(expected_value);
912 if (isTargetMultisampled(
913 target)) /* In multisampled targets two conversions are made (in upload and in shader) */
915 expected_value = convert_from_sRGB(expected_value);
919 /* Compare expected and fetched values. */
920 if (fabs(pixel - expected_value) <= getMinPrecision(descriptor, channel))
928 m_context.getTestContext().getLog()
929 << tcu::TestLog::Message << "Promotion from internal format " << descriptor.internal_format_name
930 << " have failed during functional test of " << s_color_channel_names[channel]
931 << " channel with target " << target_name << ". Expected value = " << expected_value
932 << " read value = " << pixel << "." << tcu::TestLog::EndMessage;
937 if (isIntegerSignedType(descriptor))
939 /* Fetch results from destination texture (attached to current framebuffer). */
940 glw::GLint pixel = 5;
941 gl.readPixels(0, 0, 1, 1, GL_RED_INTEGER, GL_INT, &pixel);
942 GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels have failed");
944 /* Setup expected value. */
945 glw::GLint expected_value = isChannelTypeNone(descriptor, channel) ?
946 ((channel == ALPHA_COMPONENT) ? 1 : 0) :
947 s_source_texture_data_i[channel];
949 /* Compare expected and fetched values. */
950 if (pixel == expected_value)
958 m_context.getTestContext().getLog()
959 << tcu::TestLog::Message << "Promotion from internal format "
960 << descriptor.internal_format_name << " have failed during functional test of "
961 << s_color_channel_names[channel] << " channel with target " << target_name
962 << ". Expected value = " << expected_value << " read value = " << pixel << "."
963 << tcu::TestLog::EndMessage;
968 if (isIntegerUnsignedType(descriptor))
970 /* Fetch results from destination texture (attached to current framebuffer). */
971 glw::GLuint pixel = 5;
972 gl.readPixels(0, 0, 1, 1, GL_RED_INTEGER, GL_UNSIGNED_INT, &pixel);
973 GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels have failed");
975 /* Setup expected value. */
976 glw::GLuint expected_value = isChannelTypeNone(descriptor, channel) ?
977 ((channel == ALPHA_COMPONENT) ? 1 : 0) :
978 s_source_texture_data_ui[channel];
980 /* Compare expected and fetched values. */
981 if (pixel == expected_value)
989 m_context.getTestContext().getLog()
990 << tcu::TestLog::Message << "Promotion from internal format "
991 << descriptor.internal_format_name << " have failed during functional test of "
992 << s_color_channel_names[channel] << " channel with target " << target_name
993 << ". Expected value = " << expected_value << " read value = " << pixel << "."
994 << tcu::TestLog::EndMessage;
1006 bool FunctionalTest::isFloatType(TextureInternalFormatDescriptor descriptor)
1008 return (GL_FLOAT == descriptor.expected_red_type) || (GL_FLOAT == descriptor.expected_green_type) ||
1009 (GL_FLOAT == descriptor.expected_blue_type) || (GL_FLOAT == descriptor.expected_alpha_type);
1012 bool FunctionalTest::isFixedSignedType(TextureInternalFormatDescriptor descriptor)
1014 return (GL_SIGNED_NORMALIZED == descriptor.expected_red_type) ||
1015 (GL_SIGNED_NORMALIZED == descriptor.expected_green_type) ||
1016 (GL_SIGNED_NORMALIZED == descriptor.expected_blue_type) ||
1017 (GL_SIGNED_NORMALIZED == descriptor.expected_alpha_type);
1020 bool FunctionalTest::isFixedUnsignedType(TextureInternalFormatDescriptor descriptor)
1022 return (GL_UNSIGNED_NORMALIZED == descriptor.expected_red_type) ||
1023 (GL_UNSIGNED_NORMALIZED == descriptor.expected_green_type) ||
1024 (GL_UNSIGNED_NORMALIZED == descriptor.expected_blue_type) ||
1025 (GL_UNSIGNED_NORMALIZED == descriptor.expected_alpha_type);
1028 bool FunctionalTest::isIntegerSignedType(TextureInternalFormatDescriptor descriptor)
1030 return (GL_INT == descriptor.expected_red_type) || (GL_INT == descriptor.expected_green_type) ||
1031 (GL_INT == descriptor.expected_blue_type) || (GL_INT == descriptor.expected_alpha_type);
1034 bool FunctionalTest::isIntegerUnsignedType(TextureInternalFormatDescriptor descriptor)
1036 return (GL_UNSIGNED_INT == descriptor.expected_red_type) || (GL_UNSIGNED_INT == descriptor.expected_green_type) ||
1037 (GL_UNSIGNED_INT == descriptor.expected_blue_type) || (GL_UNSIGNED_INT == descriptor.expected_alpha_type);
1040 bool FunctionalTest::isDepthType(TextureInternalFormatDescriptor descriptor)
1042 return (GL_NONE != descriptor.expected_depth_type);
1045 bool FunctionalTest::isStencilType(TextureInternalFormatDescriptor descriptor)
1047 return (descriptor.min_stencil_size > 0);
1050 bool FunctionalTest::isChannelTypeNone(TextureInternalFormatDescriptor descriptor, ColorChannelSelector channel)
1055 return (GL_NONE == descriptor.expected_red_type);
1056 case GREEN_COMPONENT:
1057 return (GL_NONE == descriptor.expected_green_type);
1058 case BLUE_COMPONENT:
1059 return (GL_NONE == descriptor.expected_blue_type);
1060 case ALPHA_COMPONENT:
1061 return (GL_NONE == descriptor.expected_alpha_type);
1069 glw::GLfloat FunctionalTest::getMinPrecision(TextureInternalFormatDescriptor descriptor, ColorChannelSelector channel)
1071 /* Select channel data. */
1072 glw::GLenum type = GL_NONE;
1073 glw::GLuint size = 0;
1078 type = descriptor.expected_red_type;
1079 size = descriptor.min_red_size;
1081 case GREEN_COMPONENT:
1082 type = descriptor.expected_green_type;
1083 size = descriptor.min_green_size;
1085 case BLUE_COMPONENT:
1086 type = descriptor.expected_blue_type;
1087 size = descriptor.min_blue_size;
1089 case ALPHA_COMPONENT:
1090 type = descriptor.expected_alpha_type;
1091 size = descriptor.min_alpha_size;
1097 /* If it is empty channel. */
1098 if ((type == GL_NONE) || (size == 0))
1103 /* If float type. */
1104 if (isFloatType(descriptor))
1109 return 0.00001f; /* specification GL4.5 core constant */
1111 return 1.f / 1024.f; /* specification GL4.5 core 10 bit mantisa constant */
1113 return 1.f / 64.f; /* specification GL4.5 core 6 bit mantisa constant */
1115 return 1.f / 32.f; /* specification GL4.5 core 5 bit mantisa constant */
1121 /* Fixed types precision */
1122 if (isFixedSignedType(descriptor))
1124 return (float)(1.0 / pow(2.0, (double)(size - 1 /* sign bit */)));
1127 if (isFixedUnsignedType(descriptor))
1129 return (float)(1.0 / pow(2.0, (double)(size)));
1132 /* other aka (unsigned) integer */
1136 bool FunctionalTest::isTargetMultisampled(glw::GLenum target)
1138 return (GL_TEXTURE_2D_MULTISAMPLE == target) || (GL_TEXTURE_2D_MULTISAMPLE_ARRAY == target);
1141 float FunctionalTest::convert_from_sRGB(float value)
1143 /* For reference check OpenGL specification (eg. OpenGL 4.5 core profile specification chapter 8.24 */
1144 if (value > 0.04045f)
1146 return deFloatPow((value + 0.055f) / 1.055f, 2.4f);
1149 return value / 12.92f;
1152 const glw::GLfloat FunctionalTest::s_source_texture_data_f[] = { 0.125f, 0.25f, 0.5f, 0.75f };
1154 const glw::GLfloat FunctionalTest::s_source_texture_data_n[] = { 0.125f, 0.25f, 0.5f, 0.75f };
1156 const glw::GLfloat FunctionalTest::s_source_texture_data_sn[] = { -0.125f, 0.25f, -0.5f, 0.75f };
1158 const glw::GLint FunctionalTest::s_source_texture_data_i[] = { -1, 2, -3, 4 };
1160 const glw::GLuint FunctionalTest::s_source_texture_data_ui[] = { 1, 2, 3, 4 };
1162 const glw::GLfloat FunctionalTest::s_destination_texture_data_f[] = {
1164 }; /* False data for destination texture to be overwriten. */
1166 const glw::GLint FunctionalTest::s_destination_texture_data_i[] = {
1168 }; /* False data for destination texture to be overwriten. */
1170 const glw::GLuint FunctionalTest::s_destination_texture_data_ui[] = {
1172 }; /* False data for destination texture to be overwriten. */
1174 const glw::GLenum FunctionalTest::s_source_texture_targets[] = {
1175 GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_1D_ARRAY, GL_TEXTURE_RECTANGLE,
1176 GL_TEXTURE_2D_ARRAY, GL_TEXTURE_3D, GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_2D_MULTISAMPLE_ARRAY
1179 const glw::GLchar* FunctionalTest::s_source_texture_targets_names[] = {
1180 STR(GL_TEXTURE_1D), STR(GL_TEXTURE_2D), STR(GL_TEXTURE_1D_ARRAY), STR(GL_TEXTURE_RECTANGLE),
1181 STR(GL_TEXTURE_2D_ARRAY), STR(GL_TEXTURE_3D), STR(GL_TEXTURE_2D_MULTISAMPLE), STR(GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
1184 const glw::GLuint FunctionalTest::s_source_texture_targets_count =
1185 sizeof(s_source_texture_targets) / sizeof(s_source_texture_targets[0]);
1187 const glw::GLuint FunctionalTest::s_source_texture_size = 1;
1189 const glw::GLchar* FunctionalTest::s_color_channel_names[] = { "red", "green", "blue", "alpha", "all" };
1191 const FunctionalTest::TextureInternalFormatDescriptor FunctionalTest::s_formats[] = {
1192 /* context version, internal format, internal format name, is sRGB, CR,size{R, G, B, A, D, S}, type of R, type of G, type of B, type of A, type of depth */
1193 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_R8, STR(GL_R8), false, true, 8, 0, 0, 0, 0, 0,
1194 GL_UNSIGNED_NORMALIZED, GL_NONE, GL_NONE, GL_NONE, GL_NONE },
1195 { glu::ContextType(3, 1, glu::PROFILE_CORE), GL_R8_SNORM, STR(GL_R8_SNORM), false, true, 8, 0, 0, 0, 0, 0,
1196 GL_SIGNED_NORMALIZED, GL_NONE, GL_NONE, GL_NONE, GL_NONE },
1197 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_R16, STR(GL_R16), false, true, 16, 0, 0, 0, 0, 0,
1198 GL_UNSIGNED_NORMALIZED, GL_NONE, GL_NONE, GL_NONE, GL_NONE },
1199 { glu::ContextType(3, 1, glu::PROFILE_CORE), GL_R16_SNORM, STR(GL_R16_SNORM), false, true, 16, 0, 0, 0, 0, 0,
1200 GL_SIGNED_NORMALIZED, GL_NONE, GL_NONE, GL_NONE, GL_NONE },
1201 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RG8, STR(GL_RG8), false, true, 8, 8, 0, 0, 0, 0,
1202 GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_NONE, GL_NONE, GL_NONE },
1203 { glu::ContextType(3, 1, glu::PROFILE_CORE), GL_RG8_SNORM, STR(GL_RG8_SNORM), false, true, 8, 8, 0, 0, 0, 0,
1204 GL_SIGNED_NORMALIZED, GL_SIGNED_NORMALIZED, GL_NONE, GL_NONE, GL_NONE },
1205 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RG16, STR(GL_RG16), false, true, 16, 16, 0, 0, 0, 0,
1206 GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_NONE, GL_NONE, GL_NONE },
1207 { glu::ContextType(3, 1, glu::PROFILE_CORE), GL_RG16_SNORM, STR(GL_RG16_SNORM), false, true, 16, 16, 0, 0, 0, 0,
1208 GL_SIGNED_NORMALIZED, GL_SIGNED_NORMALIZED, GL_NONE, GL_NONE, GL_NONE },
1209 { glu::ContextType(4, 4, glu::PROFILE_CORE), GL_R3_G3_B2, STR(GL_R3_G3_B2), false, true, 3, 3, 2, 0, 0, 0,
1210 GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_NONE, GL_NONE },
1211 { glu::ContextType(4, 4, glu::PROFILE_CORE), GL_RGB4, STR(GL_RGB4), false, true, 4, 4, 4, 0, 0, 0,
1212 GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_NONE, GL_NONE },
1213 { glu::ContextType(4, 4, glu::PROFILE_CORE), GL_RGB5, STR(GL_RGB5), false, true, 5, 5, 5, 0, 0, 0,
1214 GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_NONE, GL_NONE },
1215 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGB8, STR(GL_RGB8), false, true, 8, 8, 8, 0, 0, 0,
1216 GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_NONE, GL_NONE },
1217 { glu::ContextType(3, 1, glu::PROFILE_CORE), GL_RGB8_SNORM, STR(GL_RGB8_SNORM), false, true, 8, 8, 8, 0, 0, 0,
1218 GL_SIGNED_NORMALIZED, GL_SIGNED_NORMALIZED, GL_SIGNED_NORMALIZED, GL_NONE, GL_NONE },
1219 { glu::ContextType(4, 4, glu::PROFILE_CORE), GL_RGB10, STR(GL_RGB10), false, true, 10, 10, 10, 0, 0, 0,
1220 GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_NONE, GL_NONE },
1221 { glu::ContextType(4, 4, glu::PROFILE_CORE), GL_RGB12, STR(GL_RGB12), false, true, 12, 12, 12, 0, 0, 0,
1222 GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_NONE, GL_NONE },
1223 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGB16, STR(GL_RGB16), false, true, 16, 16, 16, 0, 0, 0,
1224 GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_NONE, GL_NONE },
1225 { glu::ContextType(3, 1, glu::PROFILE_CORE), GL_RGB16_SNORM, STR(GL_RGB16_SNORM), false, true, 16, 16, 16, 0, 0, 0,
1226 GL_SIGNED_NORMALIZED, GL_SIGNED_NORMALIZED, GL_SIGNED_NORMALIZED, GL_NONE, GL_NONE },
1227 { glu::ContextType(4, 4, glu::PROFILE_CORE), GL_RGBA2, STR(GL_RGBA2), false, true, 2, 2, 2, 2, 0, 0,
1228 GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_NONE },
1229 { glu::ContextType(4, 2, glu::PROFILE_CORE), GL_RGBA4, STR(GL_RGBA4), false, true, 4, 4, 4, 4, 0, 0,
1230 GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_NONE },
1231 { glu::ContextType(4, 2, glu::PROFILE_CORE), GL_RGB5_A1, STR(GL_RGB5_A1), false, true, 5, 5, 5, 1, 0, 0,
1232 GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_NONE },
1233 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGBA8, STR(GL_RGBA8), false, true, 8, 8, 8, 8, 0, 0,
1234 GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_NONE },
1235 { glu::ContextType(3, 1, glu::PROFILE_CORE), GL_RGBA8_SNORM, STR(GL_RGBA8_SNORM), false, true, 8, 8, 8, 8, 0, 0,
1236 GL_SIGNED_NORMALIZED, GL_SIGNED_NORMALIZED, GL_SIGNED_NORMALIZED, GL_SIGNED_NORMALIZED, GL_NONE },
1237 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGB10_A2, STR(GL_RGB10_A2), false, true, 10, 10, 10, 2, 0, 0,
1238 GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_NONE },
1239 { glu::ContextType(3, 3, glu::PROFILE_CORE), GL_RGB10_A2UI, STR(GL_RGB10_A2UI), false, true, 10, 10, 10, 2, 0, 0,
1240 GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_NONE },
1241 { glu::ContextType(4, 4, glu::PROFILE_CORE), GL_RGBA12, STR(GL_RGBA12), false, true, 12, 12, 12, 12, 0, 0,
1242 GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_NONE },
1243 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGBA16, STR(GL_RGBA16), false, true, 16, 16, 16, 16, 0, 0,
1244 GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_NONE },
1245 { glu::ContextType(3, 1, glu::PROFILE_CORE), GL_RGBA16_SNORM, STR(GL_RGBA16_SNORM), false, true, 16, 16, 16, 16, 0,
1246 0, GL_SIGNED_NORMALIZED, GL_SIGNED_NORMALIZED, GL_SIGNED_NORMALIZED, GL_SIGNED_NORMALIZED, GL_NONE },
1247 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_SRGB8, STR(GL_SRGB8), true, true, 8, 8, 8, 0, 0, 0,
1248 GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_NONE, GL_NONE },
1249 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_SRGB8_ALPHA8, STR(GL_SRGB8_ALPHA8), true, true, 8, 8, 8, 8, 0, 0,
1250 GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_NONE },
1251 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_R16F, STR(GL_R16F), false, true, 16, 0, 0, 0, 0, 0, GL_FLOAT,
1252 GL_NONE, GL_NONE, GL_NONE, GL_NONE },
1253 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RG16F, STR(GL_RG16F), false, true, 16, 16, 0, 0, 0, 0, GL_FLOAT,
1254 GL_FLOAT, GL_NONE, GL_NONE, GL_NONE },
1255 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGB16F, STR(GL_RGB16F), false, true, 16, 16, 16, 0, 0, 0, GL_FLOAT,
1256 GL_FLOAT, GL_FLOAT, GL_NONE, GL_NONE },
1257 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGBA16F, STR(GL_RGBA16F), false, true, 16, 16, 16, 16, 0, 0,
1258 GL_FLOAT, GL_FLOAT, GL_FLOAT, GL_FLOAT, GL_NONE },
1259 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_R32F, STR(GL_R32F), false, true, 32, 0, 0, 0, 0, 0, GL_FLOAT,
1260 GL_NONE, GL_NONE, GL_NONE, GL_NONE },
1261 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RG32F, STR(GL_RG32F), false, true, 32, 32, 0, 0, 0, 0, GL_FLOAT,
1262 GL_FLOAT, GL_NONE, GL_NONE, GL_NONE },
1263 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGB32F, STR(GL_RGB32F), false, true, 32, 32, 32, 0, 0, 0, GL_FLOAT,
1264 GL_FLOAT, GL_FLOAT, GL_NONE, GL_NONE },
1265 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGBA32F, STR(GL_RGBA32F), false, true, 32, 32, 32, 32, 0, 0,
1266 GL_FLOAT, GL_FLOAT, GL_FLOAT, GL_FLOAT, GL_NONE },
1267 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_R11F_G11F_B10F, STR(GL_R11F_G11F_B10F), false, true, 11, 11, 10, 0,
1268 0, 0, GL_FLOAT, GL_FLOAT, GL_FLOAT, GL_NONE, GL_NONE },
1269 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGB9_E5, STR(GL_RGB9_E5), false, false, 9, 9, 9, 0, 0, 0, GL_FLOAT,
1270 GL_FLOAT, GL_FLOAT, GL_NONE, GL_NONE },
1271 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_R8I, STR(GL_R8I), false, true, 8, 0, 0, 0, 0, 0, GL_INT, GL_NONE,
1272 GL_NONE, GL_NONE, GL_NONE },
1273 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_R8UI, STR(GL_R8UI), false, true, 8, 0, 0, 0, 0, 0, GL_UNSIGNED_INT,
1274 GL_NONE, GL_NONE, GL_NONE, GL_NONE },
1275 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_R16I, STR(GL_R16I), false, true, 16, 0, 0, 0, 0, 0, GL_INT, GL_NONE,
1276 GL_NONE, GL_NONE, GL_NONE },
1277 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_R16UI, STR(GL_R16UI), false, true, 16, 0, 0, 0, 0, 0,
1278 GL_UNSIGNED_INT, GL_NONE, GL_NONE, GL_NONE, GL_NONE },
1279 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_R32I, STR(GL_R32I), false, true, 32, 0, 0, 0, 0, 0, GL_INT, GL_NONE,
1280 GL_NONE, GL_NONE, GL_NONE },
1281 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_R32UI, STR(GL_R32UI), false, true, 32, 0, 0, 0, 0, 0,
1282 GL_UNSIGNED_INT, GL_NONE, GL_NONE, GL_NONE, GL_NONE },
1283 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RG8I, STR(GL_RG8I), false, true, 8, 8, 0, 0, 0, 0, GL_INT, GL_INT,
1284 GL_NONE, GL_NONE, GL_NONE },
1285 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RG8UI, STR(GL_RG8UI), false, true, 8, 8, 0, 0, 0, 0,
1286 GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_NONE, GL_NONE, GL_NONE },
1287 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RG16I, STR(GL_RG16I), false, true, 16, 16, 0, 0, 0, 0, GL_INT,
1288 GL_INT, GL_NONE, GL_NONE, GL_NONE },
1289 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RG16UI, STR(GL_RG16UI), false, true, 16, 16, 0, 0, 0, 0,
1290 GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_NONE, GL_NONE, GL_NONE },
1291 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RG32I, STR(GL_RG32I), false, true, 32, 32, 0, 0, 0, 0, GL_INT,
1292 GL_INT, GL_NONE, GL_NONE, GL_NONE },
1293 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RG32UI, STR(GL_RG32UI), false, true, 32, 32, 0, 0, 0, 0,
1294 GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_NONE, GL_NONE, GL_NONE },
1295 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGB8I, STR(GL_RGB8I), false, true, 8, 8, 8, 0, 0, 0, GL_INT, GL_INT,
1296 GL_INT, GL_NONE, GL_NONE },
1297 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGB8UI, STR(GL_RGB8UI), false, true, 8, 8, 8, 0, 0, 0,
1298 GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_NONE, GL_NONE },
1299 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGB16I, STR(GL_RGB16I), false, true, 16, 16, 16, 0, 0, 0, GL_INT,
1300 GL_INT, GL_INT, GL_NONE, GL_NONE },
1301 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGB16UI, STR(GL_RGB16UI), false, true, 16, 16, 16, 0, 0, 0,
1302 GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_NONE, GL_NONE },
1303 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGB32I, STR(GL_RGB32I), false, true, 32, 32, 32, 0, 0, 0, GL_INT,
1304 GL_INT, GL_INT, GL_NONE, GL_NONE },
1305 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGB32UI, STR(GL_RGB32UI), false, true, 32, 32, 32, 0, 0, 0,
1306 GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_NONE, GL_NONE },
1307 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGBA8I, STR(GL_RGBA8I), false, true, 8, 8, 8, 8, 0, 0, GL_INT,
1308 GL_INT, GL_INT, GL_INT, GL_NONE },
1309 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGBA8UI, STR(GL_RGBA8UI), false, true, 8, 8, 8, 8, 0, 0,
1310 GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_NONE },
1311 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGBA16I, STR(GL_RGBA16I), false, true, 16, 16, 16, 16, 0, 0, GL_INT,
1312 GL_INT, GL_INT, GL_INT, GL_NONE },
1313 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGBA16UI, STR(GL_RGBA16UI), false, true, 16, 16, 16, 16, 0, 0,
1314 GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_NONE },
1315 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGBA32I, STR(GL_RGBA32I), false, true, 32, 32, 32, 32, 0, 0, GL_INT,
1316 GL_INT, GL_INT, GL_INT, GL_NONE },
1317 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_RGBA32UI, STR(GL_RGBA32UI), false, true, 32, 32, 32, 32, 0, 0,
1318 GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_UNSIGNED_INT, GL_NONE },
1319 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_DEPTH_COMPONENT16, STR(GL_DEPTH_COMPONENT16), false, true, 0, 0, 0,
1320 0, 16, 0, GL_NONE, GL_NONE, GL_NONE, GL_NONE, GL_UNSIGNED_NORMALIZED },
1321 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_DEPTH_COMPONENT24, STR(GL_DEPTH_COMPONENT24), false, true, 0, 0, 0,
1322 0, 24, 0, GL_NONE, GL_NONE, GL_NONE, GL_NONE, GL_UNSIGNED_NORMALIZED },
1323 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_DEPTH_COMPONENT32F, STR(GL_DEPTH_COMPONENT32F), false, true, 0, 0,
1324 0, 0, 32, 0, GL_NONE, GL_NONE, GL_NONE, GL_NONE, GL_FLOAT },
1325 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_DEPTH24_STENCIL8, STR(GL_DEPTH24_STENCIL8), false, true, 0, 0, 0, 0,
1326 24, 8, GL_NONE, GL_NONE, GL_NONE, GL_NONE, GL_UNSIGNED_NORMALIZED },
1327 { glu::ContextType(3, 0, glu::PROFILE_CORE), GL_DEPTH32F_STENCIL8, STR(GL_DEPTH32F_STENCIL8), false, true, 0, 0, 0,
1328 0, 32, 8, GL_NONE, GL_NONE, GL_NONE, GL_NONE, GL_FLOAT }
1331 const glw::GLuint FunctionalTest::s_formats_size = sizeof(s_formats) / sizeof(s_formats[0]);
1333 const glw::GLchar* FunctionalTest::s_vertex_shader_code = "#version 150\n"
1337 " switch(gl_VertexID % 4)\n"
1340 " gl_Position = vec4(-1.0, -1.0, 0.0, 1.0);\n"
1343 " gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
1346 " gl_Position = vec4( 1.0, -1.0, 0.0, 1.0);\n"
1349 " gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n"
1354 const glw::GLchar* FunctionalTest::s_fragment_shader_template =
1357 "out TEMPLATE_TYPE result;\n"
1359 "uniform TEMPLATE_SAMPLER data;\n"
1363 " result = texelFetch(data, TEMPLATE_TEXEL_FETCH_ARGUMENTS)TEMPLATE_COMPONENT;\n"
1366 /*===========================================================================================================*/
1371 glw::GLuint buildProgram(glw::Functions const& gl, tcu::TestLog& log, glw::GLchar const* const vertex_shader_source,
1372 glw::GLchar const* const fragment_shader_source)
1374 glw::GLuint program = 0;
1378 glw::GLchar const* const source;
1379 glw::GLenum const type;
1381 } shader[] = { { vertex_shader_source, GL_VERTEX_SHADER, 0 }, { fragment_shader_source, GL_FRAGMENT_SHADER, 0 } };
1383 glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]);
1387 /* Create program. */
1388 program = gl.createProgram();
1389 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed.");
1391 /* Shader compilation. */
1393 for (glw::GLuint i = 0; i < shader_count; ++i)
1395 if (DE_NULL != shader[i].source)
1397 shader[i].id = gl.createShader(shader[i].type);
1399 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed.");
1401 gl.attachShader(program, shader[i].id);
1403 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed.");
1405 gl.shaderSource(shader[i].id, 1, &(shader[i].source), NULL);
1407 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed.");
1409 gl.compileShader(shader[i].id);
1411 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed.");
1413 glw::GLint status = GL_FALSE;
1415 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status);
1416 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
1418 if (GL_FALSE == status)
1420 glw::GLint log_size = 0;
1421 gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size);
1422 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
1424 glw::GLchar* log_text = new glw::GLchar[log_size];
1426 gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]);
1428 log << tcu::TestLog::Message << "Shader compilation has failed.\n"
1429 << "Shader type: " << glu::getShaderTypeStr(shader[i].type) << "\n"
1430 << "Shader compilation error log:\n"
1432 << "Shader source code:\n"
1433 << shader[i].source << "\n"
1434 << tcu::TestLog::EndMessage;
1438 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed.");
1446 gl.linkProgram(program);
1447 GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed.");
1449 glw::GLint status = GL_FALSE;
1451 gl.getProgramiv(program, GL_LINK_STATUS, &status);
1453 if (GL_TRUE == status)
1455 for (glw::GLuint i = 0; i < shader_count; ++i)
1459 gl.detachShader(program, shader[i].id);
1461 GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed.");
1467 glw::GLint log_size = 0;
1469 gl.getProgramiv(program, GL_INFO_LOG_LENGTH, &log_size);
1471 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed.");
1473 glw::GLchar* log_text = new glw::GLchar[log_size];
1475 gl.getProgramInfoLog(program, log_size, NULL, &log_text[0]);
1477 log << tcu::TestLog::Message << "Program linkage has failed due to:\n"
1479 << tcu::TestLog::EndMessage;
1483 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed.");
1492 gl.deleteProgram(program);
1498 for (glw::GLuint i = 0; i < shader_count; ++i)
1500 if (0 != shader[i].id)
1502 gl.deleteShader(shader[i].id);
1511 std::string preprocessString(std::string source, std::string key, std::string value)
1513 std::string destination = source;
1517 /* Find token in source code. */
1518 size_t position = destination.find(key, 0);
1520 /* No more occurences of this key. */
1521 if (position == std::string::npos)
1526 /* Replace token with sub_code. */
1527 destination.replace(position, key.size(), value);
1533 std::string itoa(glw::GLint i)
1535 std::stringstream stream;
1539 return stream.str();
1542 } // namespace Utilities
1543 } // namespace TextureSizePromotion
1544 } // namespace gl3cts