1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.1 Module
3 * -------------------------------------------------
5 * Copyright 2017 The Android Open Source Project
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.
21 * \brief FBO sRGB tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es31fFboSRGBWriteControlTests.hpp"
25 #include "es31fFboTestUtil.hpp"
26 #include "gluTextureUtil.hpp"
27 #include "gluContextInfo.hpp"
28 #include "tcuTestLog.hpp"
29 #include "glwEnums.hpp"
30 #include "sglrContextUtil.hpp"
31 #include "glwFunctions.hpp"
32 #include "deUniquePtr.hpp"
33 #include "deSharedPtr.hpp"
34 #include "gluObjectWrapper.hpp"
35 #include "gluPixelTransfer.hpp"
36 #include "glsTextureTestUtil.hpp"
37 #include "tcuVectorUtil.hpp"
38 #include "gluStrUtil.hpp"
49 tcu::Vec4 getTestColorLinear (void)
51 return tcu::Vec4(0.2f, 0.3f, 0.4f, 1.0f);
54 tcu::Vec4 getTestColorSRGB (void)
56 return linearToSRGB(tcu::Vec4(0.2f, 0.3f, 0.4f, 1.0f));
59 tcu::Vec4 getTestColorBlank (void)
61 return tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
64 tcu::Vec4 getEpsilonError (void)
66 return tcu::Vec4(0.005f);
71 QUERYTYPE_ISENABLED = 0,
89 FRAMEBUFFERSRGB_ENABLED = 0,
90 FRAMEBUFFERSRGB_DISABLED
95 FRAMEBUFFERBLEND_ENABLED = 0,
96 FRAMEBUFFERBLEND_DISABLED
99 enum TextureSourcesType
101 TEXTURESOURCESTYPE_RGBA = 0,
102 TEXTURESOURCESTYPE_SRGBA,
103 TEXTURESOURCESTYPE_BOTH,
104 TEXTURESOURCESTYPE_NONE
115 RENDERERTASK_DRAW = 0,
121 SAMPLINGTYPE_TEXTURE = 0,
122 SAMPLINGTYPE_TEXTURE_LOD,
123 SAMPLINGTYPE_TEXTURE_GRAD,
124 SAMPLINGTYPE_TEXTURE_OFFSET,
125 SAMPLINGTYPE_TEXTURE_PROJ,
128 namespace TestTextureSizes
130 const int WIDTH = 128;
131 const int HEIGHT = 128;
132 } // global test texture sizes
134 namespace SampligTypeCount
137 } // global max number of sampling types
139 std::string buildSamplingPassType (const int samplerTotal)
141 std::ostringstream shaderFragment;
143 const SamplingType samplingTypeList [] =
145 SAMPLINGTYPE_TEXTURE, SAMPLINGTYPE_TEXTURE_LOD, SAMPLINGTYPE_TEXTURE_GRAD, SAMPLINGTYPE_TEXTURE_OFFSET, SAMPLINGTYPE_TEXTURE_PROJ
148 for (int samplerTypeIdx = 0; samplerTypeIdx < DE_LENGTH_OF_ARRAY(samplingTypeList); samplerTypeIdx++)
151 << " if (uFunctionType == " << samplerTypeIdx << ") \n"
154 for (int samplerIdx = 0; samplerIdx < samplerTotal; samplerIdx++)
156 switch (static_cast<SamplingType>(samplerTypeIdx))
158 case SAMPLINGTYPE_TEXTURE:
161 << " texelColor" << samplerIdx << " = texture(uTexture" << samplerIdx << ", vs_aTexCoord); \n";
164 case SAMPLINGTYPE_TEXTURE_LOD:
167 << " texelColor" << samplerIdx << " = textureLod(uTexture" << samplerIdx << ", vs_aTexCoord, 0.0f); \n";
170 case SAMPLINGTYPE_TEXTURE_GRAD:
173 << " texelColor" << samplerIdx << " = textureGrad(uTexture" << samplerIdx << ", vs_aTexCoord, vec2(0.0f, 0.0f), vec2(0.0f, 0.0f)); \n";
176 case SAMPLINGTYPE_TEXTURE_OFFSET:
179 << " texelColor" << samplerIdx << " = textureOffset(uTexture" << samplerIdx << ", vs_aTexCoord, ivec2(0.0f, 0.0f)); \n";
182 case SAMPLINGTYPE_TEXTURE_PROJ:
185 << " texelColor" << samplerIdx << " = textureProj(uTexture" << samplerIdx << ", vec3(vs_aTexCoord, 1.0f)); \n";
189 DE_FATAL("Error: sampling type unrecognised");
197 return shaderFragment.str();
200 void logColor (Context& context, const std::string& colorLogMessage, const tcu::Vec4 resultColor)
202 tcu::TestLog& log = context.getTestContext().getLog();
203 std::ostringstream message;
205 message << colorLogMessage << " = (" << resultColor.x() << ", " << resultColor.y() << ", " << resultColor.z() << ", " << resultColor.w() << ")";
206 log << tcu::TestLog::Message << message.str() << tcu::TestLog::EndMessage;
211 explicit TestFunction (const bool hasFunctionValue)
212 : hasFunction (hasFunctionValue) {}
213 TestFunction (const char* const functionNameValue, const char* const functionDefinition)
215 , functionName (functionNameValue)
216 , functionDefintion (functionDefinition) {}
217 ~TestFunction (void) {}
220 const char* functionName;
221 const char* functionDefintion;
224 TestFunction getFunctionBlendLinearToSRGBCheck (void)
226 const char* const functionName = "blendPlusLinearToSRGB";
228 const char* const functionDefinition =
229 "mediump vec4 blendPlusLinearToSRGB(in mediump vec4 colorSrc, in mediump vec4 colorDst) \n"
231 " const int MAX_VECTOR_SIZE = 4; \n"
232 " mediump vec4 colorConverted; \n"
233 " mediump vec4 colorBlended; \n"
234 " for (int idx = 0; idx < MAX_VECTOR_SIZE; idx++) \n"
236 " if (uBlendFunctionType == 0) \n"
238 " colorBlended[idx] = (colorSrc[idx] * uFactorSrc) + colorDst[idx] * uFactorDst; \n"
240 " if (uBlendFunctionType == 1) \n"
242 " colorBlended[idx] = (colorSrc[idx] * uFactorSrc) - (colorDst[idx] * uFactorDst); \n"
244 "if (uBlendFunctionType == 2) \n"
246 " colorBlended[idx] = (colorDst[idx] * uFactorDst) - (colorSrc[idx] * uFactorSrc); \n"
248 " if (colorBlended[idx] < 0.0031308f) \n"
250 " colorConverted[idx] = 12.92f * colorBlended[idx]; \n"
254 " colorConverted[idx] = 1.055f * pow(colorBlended[idx], 0.41666f) - 0.055f; \n"
257 " return colorConverted; \n"
260 TestFunction testFunction(functionName, functionDefinition);
267 FBOConfig (const deUint32 textureInternalFormatValue,
268 const tcu::Vec4 textureColorValue,
269 const deUint32 fboTargetTypeValue,
270 const deUint32 fboColorAttachmentValue,
271 const FboType fboTypeValue)
272 : textureInternalFormat (textureInternalFormatValue)
273 , textureColor (textureColorValue)
274 , fboTargetType (fboTargetTypeValue)
275 , fboColorAttachment (fboColorAttachmentValue)
276 , fboType (fboTypeValue) {}
279 deUint32 textureInternalFormat;
280 tcu::Vec4 textureColor;
281 deUint32 fboTargetType;
282 deUint32 fboColorAttachment;
293 std::vector<BlendConfig> getBlendingConfigList (void)
295 BlendConfig blendConfigs[12];
297 // add function permutations
298 blendConfigs[0].equation = GL_FUNC_ADD;
299 blendConfigs[1].equation = GL_FUNC_ADD;
300 blendConfigs[2].equation = GL_FUNC_ADD;
301 blendConfigs[3].equation = GL_FUNC_ADD;
303 blendConfigs[0].funcSrc = GL_ONE;
304 blendConfigs[0].funcDst = GL_ONE;
305 blendConfigs[1].funcSrc = GL_ONE;
306 blendConfigs[1].funcDst = GL_ZERO;
307 blendConfigs[2].funcSrc = GL_ZERO;
308 blendConfigs[2].funcDst = GL_ONE;
309 blendConfigs[3].funcSrc = GL_ZERO;
310 blendConfigs[3].funcDst = GL_ZERO;
312 // subtract function permutations
313 blendConfigs[4].equation = GL_FUNC_SUBTRACT;
314 blendConfigs[5].equation = GL_FUNC_SUBTRACT;
315 blendConfigs[6].equation = GL_FUNC_SUBTRACT;
316 blendConfigs[7].equation = GL_FUNC_SUBTRACT;
318 blendConfigs[4].funcSrc = GL_ONE;
319 blendConfigs[4].funcDst = GL_ONE;
320 blendConfigs[5].funcSrc = GL_ONE;
321 blendConfigs[5].funcDst = GL_ZERO;
322 blendConfigs[6].funcSrc = GL_ZERO;
323 blendConfigs[6].funcDst = GL_ONE;
324 blendConfigs[7].funcSrc = GL_ZERO;
325 blendConfigs[7].funcDst = GL_ZERO;
327 // reverse subtract function permutations
328 blendConfigs[8].equation = GL_FUNC_REVERSE_SUBTRACT;
329 blendConfigs[9].equation = GL_FUNC_REVERSE_SUBTRACT;
330 blendConfigs[10].equation = GL_FUNC_REVERSE_SUBTRACT;
331 blendConfigs[11].equation = GL_FUNC_REVERSE_SUBTRACT;
333 blendConfigs[8].funcSrc = GL_ONE;
334 blendConfigs[8].funcDst = GL_ONE;
335 blendConfigs[9].funcSrc = GL_ONE;
336 blendConfigs[9].funcDst = GL_ZERO;
337 blendConfigs[10].funcSrc = GL_ZERO;
338 blendConfigs[10].funcDst = GL_ONE;
339 blendConfigs[11].funcSrc = GL_ZERO;
340 blendConfigs[11].funcDst = GL_ZERO;
342 std::vector<BlendConfig> configList(blendConfigs, blendConfigs + DE_LENGTH_OF_ARRAY(blendConfigs));
347 struct TestRenderPassConfig
349 TestRenderPassConfig (void)
350 : testFunction (false) {}
352 TestRenderPassConfig (const TextureSourcesType textureSourcesTypeValue,
353 FBOConfig fboConfigListValue,
354 const FramebufferSRGB framebufferSRGBValue,
355 const FramebufferBlend framebufferBendValue,
356 const RendererTask rendererTaskValue)
357 : textureSourcesType (textureSourcesTypeValue)
358 , framebufferSRGB (framebufferSRGBValue)
359 , frameBufferBlend (framebufferBendValue)
360 , testFunction (false)
361 , rendererTask (rendererTaskValue) {fboConfigList.push_back(fboConfigListValue);}
363 TestRenderPassConfig (const TextureSourcesType textureSourcesTypeValue,
364 FBOConfig fboConfigListValue,
365 const FramebufferSRGB framebufferSRGBValue,
366 const FramebufferBlend framebufferBendValue,
367 TestFunction testFunctionValue,
368 const RendererTask rendererTaskValue)
369 : textureSourcesType (textureSourcesTypeValue)
370 , framebufferSRGB (framebufferSRGBValue)
371 , frameBufferBlend (framebufferBendValue)
372 , testFunction (testFunctionValue)
373 , rendererTask (rendererTaskValue) {fboConfigList.push_back(fboConfigListValue);}
375 TestRenderPassConfig (const TextureSourcesType textureSourcesTypeValue,
376 std::vector<FBOConfig> fboConfigListValue,
377 const FramebufferSRGB framebufferSRGBValue,
378 const FramebufferBlend framebufferBendValue,
379 TestFunction testFunctionValue,
380 const RendererTask rendererTaskValue)
381 : textureSourcesType (textureSourcesTypeValue)
382 , fboConfigList (fboConfigListValue)
383 , framebufferSRGB (framebufferSRGBValue)
384 , frameBufferBlend (framebufferBendValue)
385 , testFunction (testFunctionValue)
386 , rendererTask (rendererTaskValue) {}
388 ~TestRenderPassConfig (void) {}
390 TextureSourcesType textureSourcesType;
391 std::vector<FBOConfig> fboConfigList;
392 FramebufferSRGB framebufferSRGB;
393 FramebufferBlend frameBufferBlend;
394 TestFunction testFunction;
395 RendererTask rendererTask;
401 TestVertexData (Context& context);
402 ~TestVertexData (void);
406 void bind (void) const;
407 void unbind (void) const;
410 const glw::Functions* m_gl;
411 std::vector<float> m_data;
412 glw::GLuint m_vboHandle;
413 glw::GLuint m_vaoHandle;
416 TestVertexData::TestVertexData (Context& context)
417 : m_gl (&context.getRenderContext().getFunctions())
419 const glw::GLfloat vertexData[] =
421 // position // texcoord
422 -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, // bottom left corner
423 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, // bottom right corner
424 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, // Top right corner
426 -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, // top left corner
427 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, // Top right corner
428 -1.0f, -1.0f, 0.0f, 0.0f, 0.0f // bottom left corner
431 m_data.resize(DE_LENGTH_OF_ARRAY(vertexData));
432 for (int idx = 0; idx < (int)m_data.size(); idx++)
433 m_data[idx] = vertexData[idx];
435 m_gl->genVertexArrays(1, &m_vaoHandle);
436 m_gl->bindVertexArray(m_vaoHandle);
438 m_gl->genBuffers(1, &m_vboHandle);
439 m_gl->bindBuffer(GL_ARRAY_BUFFER, m_vboHandle);
441 m_gl->bufferData(GL_ARRAY_BUFFER, (glw::GLsizei)(m_data.size() * sizeof(glw::GLfloat)), &m_data[0], GL_STATIC_DRAW);
443 m_gl->enableVertexAttribArray(0);
444 m_gl->vertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * (glw::GLsizei)sizeof(GL_FLOAT), (glw::GLvoid *)0);
445 m_gl->enableVertexAttribArray(1);
446 m_gl->vertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * (glw::GLsizei)sizeof(GL_FLOAT), (glw::GLvoid *)(3 * sizeof(GL_FLOAT)));
448 m_gl->bindVertexArray(0);
449 m_gl->bindBuffer(GL_ARRAY_BUFFER, 0);
450 GLU_EXPECT_NO_ERROR(m_gl->getError(), "gl error during vertex data setup");
453 TestVertexData::~TestVertexData (void)
455 m_gl->deleteBuffers(1, &m_vboHandle);
456 m_gl->deleteVertexArrays(1, &m_vaoHandle);
459 void TestVertexData::bind (void) const
461 m_gl->bindVertexArray(m_vaoHandle);
464 void TestVertexData::unbind (void) const
466 m_gl->bindVertexArray(0);
472 TestTexture2D (Context& context, const deUint32 internalFormatValue, const deUint32 transferFormatValue, const deUint32 transferTypeValue, const tcu::Vec4 imageColorValue, const int idx);
473 ~TestTexture2D (void);
475 int getTextureUnit (void) const;
476 deUint32 getHandle (void) const;
477 int getIdx (void) const;
479 void bind (const int textureUnit);
480 void unbind (void) const;
483 const glw::Functions* m_gl;
484 glw::GLuint m_handle;
485 const deUint32 m_internalFormat;
486 tcu::TextureFormat m_transferFormat;
489 tcu::TextureLevel m_imageData;
494 TestTexture2D::TestTexture2D (Context& context, const deUint32 internalFormat, const deUint32 transferFormat, const deUint32 transferType, const tcu::Vec4 imageColor, const int idx)
495 : m_gl (&context.getRenderContext().getFunctions())
496 , m_internalFormat (internalFormat)
497 , m_transferFormat (tcu::TextureFormat(glu::mapGLTransferFormat(transferFormat, transferType)))
498 , m_width (TestTextureSizes::WIDTH)
499 , m_height (TestTextureSizes::HEIGHT)
500 , m_imageData (tcu::TextureLevel(glu::mapGLInternalFormat(internalFormat), m_width, m_height, 1))
503 // fill image data with a solid test color
504 tcu::clear(m_imageData.getAccess(), tcu::Vec4(0.0f));
505 for (int py = 0; py < m_imageData.getHeight(); py++)
507 for (int px = 0; px < m_imageData.getWidth(); px++)
508 m_imageData.getAccess().setPixel(imageColor, px, py);
511 m_gl->genTextures(1, &m_handle);
513 m_gl->bindTexture(GL_TEXTURE_2D, m_handle);
514 m_gl->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
515 m_gl->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
516 m_gl->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
517 m_gl->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
519 m_gl->texImage2D(GL_TEXTURE_2D, 0, m_internalFormat, m_width, m_height, 0, transferFormat, transferType, m_imageData.getAccess().getDataPtr());
521 m_gl->bindTexture(GL_TEXTURE_2D, 0);
524 TestTexture2D::~TestTexture2D (void)
526 m_gl->deleteTextures(1, &m_handle);
529 int TestTexture2D::getTextureUnit (void) const
531 return m_textureUnit;
534 deUint32 TestTexture2D::getHandle (void) const
539 int TestTexture2D::getIdx (void) const
544 void TestTexture2D::bind (const int textureUnit)
546 m_textureUnit = textureUnit;
547 m_gl->activeTexture(GL_TEXTURE0 + m_textureUnit);
548 m_gl->bindTexture(GL_TEXTURE_2D, m_handle);
551 void TestTexture2D::unbind (void) const
553 m_gl->bindTexture(GL_TEXTURE_2D, 0);
556 class TestFramebuffer
559 TestFramebuffer (void);
560 TestFramebuffer (Context& context, const deUint32 targetType, const deUint32 colorAttachment, glw::GLuint textureAttachmentHandle, const bool isSRGB, const FboType fboType, const int idx);
561 ~TestFramebuffer (void);
563 void setTargetType (const deUint32 targetType);
565 FboType getType (void) const;
566 deUint32 getHandle (void) const;
567 deUint32 getColorAttachment (void) const;
568 int getIdx (void) const;
569 deUint32 getTargetType (void) const;
574 typedef de::UniquePtr<glu::Framebuffer> fboUniquePtr;
577 const glw::Functions* m_gl;
578 fboUniquePtr m_referenceSource;
579 deUint32 m_targetType;
584 deUint32 m_colorAttachment;
587 TestFramebuffer::TestFramebuffer (Context& context, const deUint32 targetType, const deUint32 colorAttachment, glw::GLuint textureAttachmentHandle, const bool isSRGB, const FboType fboType, const int idx)
588 : m_gl (&context.getRenderContext().getFunctions())
589 , m_referenceSource (new glu::Framebuffer(context.getRenderContext()))
590 , m_targetType (targetType)
595 , m_colorAttachment (colorAttachment)
597 m_gl->bindFramebuffer(m_targetType, **m_referenceSource);
599 m_gl->framebufferTexture2D(m_targetType, m_colorAttachment, GL_TEXTURE_2D, textureAttachmentHandle, 0);
601 TCU_CHECK(m_gl->checkFramebufferStatus(m_targetType) == GL_FRAMEBUFFER_COMPLETE);
603 if (targetType == GL_DRAW_BUFFER)
605 glw::GLuint textureAttachments[] = {m_colorAttachment};
606 m_gl->drawBuffers(DE_LENGTH_OF_ARRAY(textureAttachments), textureAttachments);
607 GLU_EXPECT_NO_ERROR(m_gl->getError(), "glDrawBuffer()");
610 if (targetType == GL_READ_BUFFER)
612 m_gl->readBuffer(m_colorAttachment);
613 GLU_EXPECT_NO_ERROR(m_gl->getError(), "glReadBuffer()");
616 m_gl->bindFramebuffer(m_targetType, 0);
619 TestFramebuffer::~TestFramebuffer (void)
623 void TestFramebuffer::setTargetType (const deUint32 targetType)
625 m_targetType = targetType;
628 FboType TestFramebuffer::getType (void) const
633 deUint32 TestFramebuffer::getHandle (void) const
635 return **m_referenceSource;
638 deUint32 TestFramebuffer::getColorAttachment (void) const
640 return m_colorAttachment;
643 int TestFramebuffer::getIdx (void) const
648 deUint32 TestFramebuffer::getTargetType (void) const
653 void TestFramebuffer::bind (void)
657 m_gl->bindFramebuffer(m_targetType, **m_referenceSource);
662 void TestFramebuffer::unbind (void)
666 m_gl->bindFramebuffer(m_targetType, 0);
671 class TestShaderProgram
674 TestShaderProgram (Context& context, const int samplerTotal, TestFunction testFunction);
675 ~TestShaderProgram (void);
677 glw::GLuint getHandle (void) const;
678 int getSamplerTotal (void) const;
680 void use (void) const;
681 void unuse (void) const;
683 glu::ShaderProgramInfo getLogInfo (void);
686 const glw::Functions* m_gl;
687 de::MovePtr<glu::ShaderProgram> m_referenceSource;
688 const int m_samplerTotal;
689 const int m_shaderStagesTotal;
692 TestShaderProgram::TestShaderProgram (Context& context, const int samplerTotal, TestFunction testFunction)
693 : m_gl (&context.getRenderContext().getFunctions())
694 , m_samplerTotal (samplerTotal)
695 , m_shaderStagesTotal (2)
697 std::ostringstream shaderFragment;
699 const char* const shaderVertex =
701 "layout (location = 0) in mediump vec3 aPosition; \n"
702 "layout (location = 1) in mediump vec2 aTexCoord; \n"
703 "out mediump vec2 vs_aTexCoord; \n"
706 " gl_Position = vec4(aPosition, 1.0f); \n"
707 " vs_aTexCoord = aTexCoord; \n"
711 << "#version 310 es \n"
712 << "in mediump vec2 vs_aTexCoord; \n"
713 << "layout (location = 0) out mediump vec4 fs_aColor0; \n";
715 for (int samplerIdx = 0; samplerIdx < m_samplerTotal; samplerIdx++)
717 << "uniform sampler2D uTexture" << samplerIdx << "; \n";
720 << "uniform int uFunctionType; \n";
722 if (testFunction.hasFunction)
724 << "uniform int uBlendFunctionType; \n"
725 << "uniform mediump float uFactorSrc; \n"
726 << "uniform mediump float uFactorDst; \n"
727 << testFunction.functionDefintion;
733 for (int samplerIdx = 0; samplerIdx < m_samplerTotal; samplerIdx++)
735 <<" mediump vec4 texelColor" << samplerIdx << " = vec4(0.0f, 0.0f, 0.0f, 1.0f); \n";
738 << buildSamplingPassType(m_samplerTotal);
740 if (testFunction.hasFunction)
742 << " fs_aColor0 = " << testFunction.functionName << "(texelColor0, texelColor1); \n";
745 << " fs_aColor0 = texelColor0; \n";
750 m_referenceSource = de::MovePtr<glu::ShaderProgram>(new glu::ShaderProgram(context.getRenderContext(), glu::makeVtxFragSources(shaderVertex, shaderFragment.str())));
751 if (!m_referenceSource->isOk())
753 tcu::TestLog& log = context.getTestContext().getLog();
754 log << this->getLogInfo();
755 TCU_FAIL("Failed to compile shaders and link program");
759 TestShaderProgram::~TestShaderProgram (void)
761 m_referenceSource = de::MovePtr<glu::ShaderProgram>(DE_NULL);
762 m_referenceSource.clear();
765 deUint32 TestShaderProgram::getHandle (void) const
767 return m_referenceSource->getProgram();
770 int TestShaderProgram::getSamplerTotal (void) const
772 return m_samplerTotal;
775 void TestShaderProgram::use (void) const
777 m_gl->useProgram(this->getHandle());
780 void TestShaderProgram::unuse (void) const
785 glu::ShaderProgramInfo TestShaderProgram::getLogInfo (void)
787 glu::ShaderProgramInfo buildInfo;
789 // log shader program info. Only vertex and fragment shaders included
790 buildInfo.program = m_referenceSource->getProgramInfo();
791 for (int shaderIdx = 0; shaderIdx < m_shaderStagesTotal; shaderIdx++)
793 glu::ShaderInfo shaderInfo = m_referenceSource->getShaderInfo(static_cast<glu::ShaderType>(static_cast<int>(glu::SHADERTYPE_VERTEX) + static_cast<int>(shaderIdx)), 0);
794 buildInfo.shaders.push_back(shaderInfo);
802 Renderer (Context& context);
805 void init (const TestRenderPassConfig& renderPassConfig, const int renderpass);
808 void setSamplingType (const SamplingType samplerIdx);
809 void setBlendIteration (const int blendIteration);
810 void setFramebufferBlend (const bool blend);
811 void setFramebufferSRGB (const bool sRGB);
813 std::vector<tcu::Vec4> getResultsPreDraw (void) const;
814 std::vector<tcu::Vec4> getResultsPostDraw (void) const;
815 int getBlendConfigCount (void) const;
816 glu::ShaderProgramInfo getShaderProgramInfo (void);
818 void copyFrameBufferTexture (const int srcPx, const int srcPy, const int dstPx, const int dstPy);
820 void storeShaderProgramInfo (void);
821 void logShaderProgramInfo (void);
823 typedef de::SharedPtr<TestTexture2D> TextureSp;
824 typedef de::SharedPtr<TestFramebuffer> FboSp;
827 void createFBOwithColorAttachment (const std::vector<FBOConfig> fboConfigList);
828 void setShaderProgramSamplingType (const int samplerIdx);
829 void setShaderBlendFunctionType (void);
830 void setShaderBlendSrcDstValues (void);
831 void bindActiveTexturesSamplers (void);
832 void bindAllRequiredSourceTextures (const TextureSourcesType texturesRequired);
833 void unbindAllSourceTextures (void);
834 void bindFramebuffer (const int framebufferIdx);
835 void unbindFramebuffer (const int framebufferIdx);
836 void enableFramebufferSRGB (void);
837 void enableFramebufferBlend (void);
838 bool isFramebufferAttachmentSRGB (const deUint32 targetType, const deUint32 attachment) const;
839 void readTexels (const int px, const int py, const deUint32 attachment, tcu::Vec4& texelData);
840 void logState (const deUint32 targetType, const deUint32 attachment, const SamplingType samplingType) const;
842 // renderer specific constants initialized during constructor
844 const TestVertexData m_vertexData;
845 const int m_textureSourceTotal;
847 // additional resources monitored by the renderer
848 std::vector<BlendConfig> m_blendConfigList;
849 std::vector<TextureSp> m_textureSourceList;
850 TestRenderPassConfig m_renderPassConfig;
851 std::vector<TextureSp> m_fboTextureList;
852 TestShaderProgram* m_shaderProgram;
853 std::vector<FboSp> m_framebufferList;
854 std::vector<tcu::Vec4> m_resultsListPreDraw;
855 std::vector<tcu::Vec4> m_resultsListPostDraw;
857 // mutable state variables (internal access only)
858 bool m_hasShaderProgramInfo;
860 int m_samplersRequired;
862 bool m_blittingEnabled;
863 glu::ShaderProgramInfo m_shaderProgramInfo;
865 // mutable state variables (external access via setters)
866 SamplingType m_samplingType;
867 int m_blendIteration;
868 bool m_framebufferBlendEnabled;
869 bool m_framebufferSRGBEnabled;
872 Renderer::Renderer (Context& context)
873 : m_context (context)
874 , m_vertexData (context)
875 , m_textureSourceTotal (2)
876 , m_blendConfigList (getBlendingConfigList())
877 , m_hasShaderProgramInfo (false)
879 TextureSp textureLinear(new TestTexture2D(m_context, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, getTestColorLinear(), 0));
880 m_textureSourceList.push_back(textureLinear);
882 TextureSp textureSRGB(new TestTexture2D(m_context, GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, getTestColorLinear(), 1));
883 m_textureSourceList.push_back(textureSRGB);
886 Renderer::~Renderer (void)
888 m_textureSourceList.clear();
892 void Renderer::init (const TestRenderPassConfig& renderPassConfig, const int renderpass)
894 m_renderPassConfig = renderPassConfig;
895 m_renderPass = renderpass;
897 this->createFBOwithColorAttachment(m_renderPassConfig.fboConfigList);
899 if (m_renderPassConfig.textureSourcesType != TEXTURESOURCESTYPE_NONE)
901 if (m_renderPassConfig.textureSourcesType == TEXTURESOURCESTYPE_RGBA || m_renderPassConfig.textureSourcesType == TEXTURESOURCESTYPE_SRGBA)
902 m_samplersRequired = 1;
903 else if (m_renderPassConfig.textureSourcesType ==TEXTURESOURCESTYPE_BOTH )
904 m_samplersRequired = 2;
906 DE_FATAL("Error: Texture source required not recognised");
908 m_shaderProgram = new TestShaderProgram(m_context, m_samplersRequired, m_renderPassConfig.testFunction);
909 m_hasFunction = m_renderPassConfig.testFunction.hasFunction;
912 m_shaderProgram = DE_NULL;
915 void Renderer::deinit (void)
917 if (m_shaderProgram != DE_NULL)
919 delete m_shaderProgram;
920 m_shaderProgram = DE_NULL;
923 m_fboTextureList.clear();
924 m_framebufferList.clear();
927 void Renderer::setSamplingType (const SamplingType samplingType)
929 m_samplingType = samplingType;
932 void Renderer::setBlendIteration (const int blendIteration)
934 m_blendIteration = blendIteration;
937 void Renderer::setFramebufferBlend (const bool blend)
939 m_framebufferBlendEnabled = blend;
942 void Renderer::setFramebufferSRGB (const bool sRGB)
944 m_framebufferSRGBEnabled = sRGB;
947 std::vector<tcu::Vec4> Renderer::getResultsPreDraw (void) const
949 return m_resultsListPreDraw;
952 std::vector<tcu::Vec4> Renderer::getResultsPostDraw (void) const
954 return m_resultsListPostDraw;
957 int Renderer::getBlendConfigCount (void) const
959 return (int)m_blendConfigList.size();
962 void Renderer::copyFrameBufferTexture (const int srcPx, const int srcPy, const int dstPx, const int dstPy)
964 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
967 deUint32 fboSrcColAttachment = GL_NONE;
968 deUint32 fboDstColAttachment = GL_NONE;
970 for (int idx = 0; idx < (int)m_framebufferList.size(); idx++)
971 this->bindFramebuffer(idx);
973 // cache fbo attachments and idx locations
974 for (int idx = 0; idx < (int)m_framebufferList.size(); idx++)
976 if (m_framebufferList[idx]->getType() == FBOTYPE_SOURCE)
978 fboSrcIdx = m_framebufferList[idx]->getIdx();
979 fboSrcColAttachment = m_framebufferList[fboSrcIdx]->getColorAttachment();
981 if (m_framebufferList[idx]->getType() == FBOTYPE_DESTINATION)
983 fboDstIdx = m_framebufferList[idx]->getIdx();
984 fboDstColAttachment = m_framebufferList[fboDstIdx]->getColorAttachment();
988 for (int idx = 0; idx < (int)m_framebufferList.size(); idx++)
989 m_framebufferList[idx]->unbind();
991 // store texel data from both src and dst before performing the copy
992 m_resultsListPreDraw.resize(2);
993 m_framebufferList[fboSrcIdx]->bind();
994 this->readTexels(0, 0, fboSrcColAttachment, m_resultsListPreDraw[0]);
995 m_framebufferList[fboSrcIdx]->unbind();
996 m_framebufferList[fboDstIdx]->setTargetType(GL_READ_FRAMEBUFFER);
997 m_framebufferList[fboDstIdx]->bind();
998 this->readTexels(0, 0, fboDstColAttachment, m_resultsListPreDraw[1]);
999 m_framebufferList[fboDstIdx]->unbind();
1000 m_framebufferList[fboDstIdx]->setTargetType(GL_DRAW_FRAMEBUFFER);
1002 m_framebufferList[fboSrcIdx]->bind();
1003 m_framebufferList[fboDstIdx]->bind();
1005 this->enableFramebufferSRGB();
1006 this->enableFramebufferBlend();
1008 gl.blitFramebuffer( srcPx, srcPy, TestTextureSizes::WIDTH, TestTextureSizes::HEIGHT,
1009 dstPx, dstPy, TestTextureSizes::WIDTH, TestTextureSizes::HEIGHT,
1010 GL_COLOR_BUFFER_BIT, GL_NEAREST);
1012 m_resultsListPostDraw.resize(2);
1013 this->readTexels(0, 0, fboSrcColAttachment, m_resultsListPostDraw[0]);
1014 m_framebufferList[fboSrcIdx]->unbind();
1015 m_framebufferList[fboDstIdx]->unbind();
1017 m_framebufferList[fboDstIdx]->setTargetType(GL_READ_FRAMEBUFFER);
1018 m_framebufferList[fboDstIdx]->bind();
1019 this->readTexels(0, 0, fboDstColAttachment, m_resultsListPostDraw[1]);
1020 m_framebufferList[fboDstIdx]->unbind();
1023 void Renderer::draw (void)
1025 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1027 if (m_renderPassConfig.textureSourcesType == TEXTURESOURCESTYPE_NONE)
1028 DE_FATAL("Error: Attempted to draw with no texture sources");
1030 // resize results storage with each render pass
1031 m_resultsListPreDraw.resize(m_renderPass + 1);
1032 m_resultsListPostDraw.resize(m_renderPass + 1);
1034 m_shaderProgram->use();
1035 m_vertexData.bind();
1037 for (int idx = 0; idx < (int)m_framebufferList.size(); idx++)
1038 this->bindFramebuffer(idx);
1040 this->bindAllRequiredSourceTextures(m_renderPassConfig.textureSourcesType);
1041 this->bindActiveTexturesSamplers();
1043 this->enableFramebufferSRGB();
1044 this->enableFramebufferBlend();
1046 this->readTexels(0, 0, GL_COLOR_ATTACHMENT0, m_resultsListPreDraw[m_renderPass]);
1047 this->setShaderProgramSamplingType(m_samplingType);
1050 this->setShaderBlendFunctionType();
1051 this->setShaderBlendSrcDstValues();
1054 gl.drawArrays(GL_TRIANGLES, 0, 6);
1056 this->readTexels(0, 0, GL_COLOR_ATTACHMENT0, m_resultsListPostDraw[m_renderPass]);
1057 this->logState(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_samplingType);
1059 this->unbindAllSourceTextures();
1060 for (int idx = 0; idx < (int)m_framebufferList.size(); idx++)
1061 this->unbindFramebuffer(idx);
1062 m_vertexData.unbind();
1063 m_shaderProgram->unuse();
1066 void Renderer::storeShaderProgramInfo (void)
1068 m_shaderProgramInfo = m_shaderProgram->getLogInfo();
1069 m_hasShaderProgramInfo = true;
1072 void Renderer::logShaderProgramInfo (void)
1074 tcu::TestLog& log = m_context.getTestContext().getLog();
1076 if (m_hasShaderProgramInfo)
1077 log << m_shaderProgramInfo;
1080 void Renderer::createFBOwithColorAttachment (const std::vector<FBOConfig> fboConfigList)
1082 const int size = (int)fboConfigList.size();
1083 for (int idx = 0; idx < size; idx++)
1085 TextureSp texture(new TestTexture2D(m_context, fboConfigList[idx].textureInternalFormat, GL_RGBA, GL_UNSIGNED_BYTE, fboConfigList[idx].textureColor, idx));
1086 m_fboTextureList.push_back(texture);
1089 if (fboConfigList[idx].textureInternalFormat == GL_SRGB8_ALPHA8)
1094 FboSp framebuffer(new TestFramebuffer(m_context, fboConfigList[idx].fboTargetType, fboConfigList[idx].fboColorAttachment, texture->getHandle(), isSRGB, fboConfigList[idx].fboType, idx));
1095 m_framebufferList.push_back(framebuffer);
1099 void Renderer::setShaderProgramSamplingType (const int samplerIdx)
1101 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1103 glw::GLuint location = gl.getUniformLocation(m_shaderProgram->getHandle(), "uFunctionType");
1104 DE_ASSERT(location != (glw::GLuint)-1);
1105 gl.uniform1i(location, samplerIdx);
1108 void Renderer::setShaderBlendFunctionType (void)
1110 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1113 if (m_blendConfigList[m_blendIteration].equation == GL_FUNC_ADD)
1115 else if (m_blendConfigList[m_blendIteration].equation == GL_FUNC_SUBTRACT)
1117 else if (m_blendConfigList[m_blendIteration].equation == GL_FUNC_REVERSE_SUBTRACT)
1120 DE_FATAL("Error: Blend function not recognised");
1122 glw::GLuint location = gl.getUniformLocation(m_shaderProgram->getHandle(), "uBlendFunctionType");
1123 DE_ASSERT(location != (glw::GLuint)-1);
1124 gl.uniform1i(location, function);
1127 void Renderer::setShaderBlendSrcDstValues (void)
1129 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1132 if (m_blendConfigList[m_blendIteration].funcSrc == GL_ONE)
1138 if (m_blendConfigList[m_blendIteration].funcDst == GL_ONE)
1143 glw::GLuint locationSrc = gl.getUniformLocation(m_shaderProgram->getHandle(), "uFactorSrc");
1144 gl.uniform1f(locationSrc, funcSrc);
1145 GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1f()");
1147 glw::GLuint locationDst = gl.getUniformLocation(m_shaderProgram->getHandle(), "uFactorDst");
1148 gl.uniform1f(locationDst, funcDst);
1149 GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1f()");
1152 void Renderer::bindActiveTexturesSamplers (void)
1154 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1156 for (int idx = 0; idx < m_samplersRequired; idx++)
1158 std::ostringstream stream;
1159 stream << "uTexture" << idx;
1160 std::string uniformName(stream.str());
1161 glw::GLint location = gl.getUniformLocation(m_shaderProgram->getHandle(), uniformName.c_str());
1162 DE_ASSERT(location != -1);
1163 gl.uniform1i(location, m_textureSourceList[idx]->getTextureUnit());
1164 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetUniformLocation()");
1168 void Renderer::bindAllRequiredSourceTextures (const TextureSourcesType texturesRequired)
1170 if (texturesRequired == TEXTURESOURCESTYPE_RGBA)
1171 m_textureSourceList[0]->bind(0);
1172 else if (texturesRequired == TEXTURESOURCESTYPE_SRGBA)
1173 m_textureSourceList[1]->bind(0);
1174 else if (texturesRequired == TEXTURESOURCESTYPE_BOTH)
1176 m_textureSourceList[0]->bind(0);
1177 m_textureSourceList[1]->bind(1);
1180 DE_FATAL("Error: Invalid sources requested in bind all");
1183 void Renderer::unbindAllSourceTextures (void)
1185 for (int idx = 0; idx < (int)m_textureSourceList.size(); idx++)
1186 m_textureSourceList[idx]->unbind();
1189 void Renderer::bindFramebuffer (const int framebufferIdx)
1191 m_framebufferList[framebufferIdx]->bind();
1194 void Renderer::unbindFramebuffer (const int framebufferIdx)
1196 m_framebufferList[framebufferIdx]->unbind();
1199 void Renderer::enableFramebufferSRGB (void)
1201 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1203 if (m_framebufferSRGBEnabled)
1204 gl.enable(GL_FRAMEBUFFER_SRGB);
1206 gl.disable(GL_FRAMEBUFFER_SRGB);
1209 void Renderer::enableFramebufferBlend (void)
1211 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1212 tcu::TestLog& log = m_context.getTestContext().getLog();
1213 std::ostringstream message;
1215 message << "Blend settings = ";
1217 if (m_framebufferBlendEnabled)
1219 gl.enable(GL_BLEND);
1220 gl.blendEquation(m_blendConfigList[m_blendIteration].equation);
1221 gl.blendFunc(m_blendConfigList[m_blendIteration].funcSrc, m_blendConfigList[m_blendIteration].funcDst);
1223 std::string equation, src, dst;
1224 if (m_blendConfigList[m_blendIteration].equation == GL_FUNC_ADD)
1225 equation = "GL_FUNC_ADD";
1226 if (m_blendConfigList[m_blendIteration].equation == GL_FUNC_SUBTRACT)
1227 equation = "GL_FUNC_SUBTRACT";
1228 if (m_blendConfigList[m_blendIteration].equation == GL_FUNC_REVERSE_SUBTRACT)
1229 equation = "GL_FUNC_REVERSE_SUBTRACT";
1230 if (m_blendConfigList[m_blendIteration].funcSrc == GL_ONE)
1234 if (m_blendConfigList[m_blendIteration].funcDst == GL_ONE)
1239 message << "Enabled: equation = " << equation << ", func src = " << src << ", func dst = " << dst;
1243 gl.disable(GL_BLEND);
1244 message << "Disabled";
1247 log << tcu::TestLog::Message << message.str() << tcu::TestLog::EndMessage;
1250 bool Renderer::isFramebufferAttachmentSRGB (const deUint32 targetType, const deUint32 attachment) const
1252 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1253 glw::GLint encodingType;
1255 gl.getFramebufferAttachmentParameteriv(targetType, attachment, GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, &encodingType);
1256 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetNamedFramebufferAttachmentParameteriv()");
1258 switch (static_cast<glw::GLenum>(encodingType))
1272 DE_FATAL("Error: Color attachment format not recognised");
1278 void Renderer::readTexels (const int px, const int py, const deUint32 mode, tcu::Vec4& texelData)
1280 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1281 tcu::TextureLevel textureRead;
1283 // ensure result sampling coordinates are within range of the result color attachment
1284 DE_ASSERT((px >= 0) && (px < m_context.getRenderTarget().getWidth()));
1285 DE_ASSERT((py >= 0) && (py < m_context.getRenderTarget().getHeight()));
1287 gl.readBuffer(mode);
1288 textureRead.setStorage(glu::mapGLTransferFormat(GL_RGBA, GL_UNSIGNED_BYTE), TestTextureSizes::WIDTH, TestTextureSizes::HEIGHT);
1289 glu::readPixels(m_context.getRenderContext(), px, py, textureRead.getAccess());
1290 GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels()");
1291 texelData = textureRead.getAccess().getPixel(px, py);
1294 void Renderer::logState (const deUint32 targetType, const deUint32 attachment, const SamplingType samplingType) const
1296 tcu::TestLog& log = m_context.getTestContext().getLog();
1297 std::ostringstream message;
1299 bool fboAttachmentSRGB = this->isFramebufferAttachmentSRGB(targetType, attachment);
1301 message << "getFramebufferAttachmentParameteriv() check = ";
1302 if (fboAttachmentSRGB)
1303 message << "GL_SRGB";
1305 message << "GL_LINEAR";
1306 log << tcu::TestLog::Message << message.str() << tcu::TestLog::EndMessage;
1309 message << "Framebuffer color attachment value BEFORE draw call";
1310 logColor(m_context, message.str(), m_resultsListPreDraw[m_renderPass]);
1313 message << "Framebuffer color attachment value AFTER draw call";
1314 logColor(m_context, message.str(), m_resultsListPostDraw[m_renderPass]);
1317 message << "Sampling type = ";
1319 if (samplingType == 0)
1321 else if (samplingType == 1)
1322 type = "textureLOD()";
1323 else if (samplingType == 2)
1324 type = "textureGrad()";
1325 else if (samplingType == 3)
1326 type = "textureOffset()";
1327 else if (samplingType == 4)
1328 type = "textureProj()";
1330 DE_FATAL("Error: Sampling type unregonised");
1332 log << tcu::TestLog::Message << message.str() << tcu::TestLog::EndMessage;
1335 if (m_framebufferSRGBEnabled)
1336 message << "Framebuffer SRGB = enabled";
1338 message << "Framebuffer SRGB = disabled";
1339 log << tcu::TestLog::Message << message.str() << tcu::TestLog::EndMessage;
1342 class FboSRGBTestCase : public TestCase
1345 FboSRGBTestCase (Context& context, const char* const name, const char* const desc);
1346 ~FboSRGBTestCase (void);
1350 IterateResult iterate (void);
1352 void setTestConfig (std::vector<TestRenderPassConfig> renderPassConfigList);
1354 virtual void setupTest (void) = 0;
1355 virtual bool verifyResult (void) = 0;
1358 bool m_hasTestConfig;
1359 std::vector<TestRenderPassConfig> m_renderPassConfigList;
1360 bool m_testcaseRequiresBlend;
1361 std::vector<tcu::Vec4> m_resultsPreDraw;
1362 std::vector<tcu::Vec4> m_resultsPostDraw;
1365 FboSRGBTestCase (const FboSRGBTestCase&);
1366 FboSRGBTestCase& operator= (const FboSRGBTestCase&);
1369 FboSRGBTestCase::FboSRGBTestCase (Context& context, const char* const name, const char* const desc)
1370 : TestCase (context, name, desc)
1371 , m_hasTestConfig (false)
1375 FboSRGBTestCase::~FboSRGBTestCase (void)
1377 FboSRGBTestCase::deinit();
1380 void FboSRGBTestCase::init (void)
1382 // extensions requirements for test
1383 if (!glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::es(3, 2)))
1384 TCU_THROW(NotSupportedError, "Test requires a context version equal or higher than 3.2");
1386 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_sRGB_write_control"))
1387 TCU_THROW(NotSupportedError, "Test requires extension GL_EXT_sRGB_write_control");
1389 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_texture_sRGB_decode"))
1390 TCU_THROW(NotSupportedError, "Test requires GL_EXT_texture_sRGB_decode extension");
1393 void FboSRGBTestCase::deinit (void)
1397 FboSRGBTestCase::IterateResult FboSRGBTestCase::iterate (void)
1401 DE_ASSERT(m_hasTestConfig && "Error: Renderer was not supplied a test config");
1403 Renderer renderer(m_context);
1405 // loop through each sampling type
1406 for (int samplingIdx = 0; samplingIdx < SampligTypeCount::MAX; samplingIdx++)
1408 renderer.setSamplingType(static_cast<SamplingType>(samplingIdx));
1410 // loop through each blend configuration
1411 const int blendCount = renderer.getBlendConfigCount();
1412 for (int blendIdx = 0; blendIdx < blendCount; blendIdx++)
1414 // loop through each render pass
1415 const int renderPassCount = (int)m_renderPassConfigList.size();
1416 for (int renderPassIdx = 0; renderPassIdx < renderPassCount; renderPassIdx++)
1418 TestRenderPassConfig renderPassConfig = m_renderPassConfigList[renderPassIdx];
1420 renderer.init(renderPassConfig, renderPassIdx);
1422 if (blendIdx == 0 && renderPassConfig.rendererTask == RENDERERTASK_DRAW)
1423 renderer.storeShaderProgramInfo();
1425 if (renderPassConfig.frameBufferBlend == FRAMEBUFFERBLEND_ENABLED)
1427 renderer.setBlendIteration(blendIdx);
1428 renderer.setFramebufferBlend(true);
1431 renderer.setFramebufferBlend(false);
1433 if (renderPassConfig.framebufferSRGB == FRAMEBUFFERSRGB_ENABLED)
1434 renderer.setFramebufferSRGB(true);
1436 renderer.setFramebufferSRGB(false);
1438 if (renderPassConfig.rendererTask == RENDERERTASK_DRAW)
1440 else if (renderPassConfig.rendererTask == RENDERERTASK_COPY)
1441 renderer.copyFrameBufferTexture(0, 0, 0, 0);
1443 DE_FATAL("Error: render task not recognised");
1449 m_resultsPreDraw = renderer.getResultsPreDraw();
1450 m_resultsPostDraw = renderer.getResultsPostDraw();
1452 bool testPassed = this->verifyResult();
1454 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1457 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Result verification failed");
1458 renderer.logShaderProgramInfo();
1462 if (!m_testcaseRequiresBlend)
1466 renderer.logShaderProgramInfo();
1472 void FboSRGBTestCase::setTestConfig (std::vector<TestRenderPassConfig> renderPassConfigList)
1474 m_renderPassConfigList = renderPassConfigList;
1475 m_hasTestConfig = true;
1477 for (int idx = 0; idx < (int)renderPassConfigList.size(); idx++)
1479 if (renderPassConfigList[idx].frameBufferBlend == FRAMEBUFFERBLEND_ENABLED)
1481 m_testcaseRequiresBlend = true;
1485 m_testcaseRequiresBlend = false;
1488 class FboSRGBQueryCase : public TestCase
1491 FboSRGBQueryCase (Context& context, const char* const name, const char* const description);
1492 ~FboSRGBQueryCase (void);
1496 IterateResult iterate (void);
1499 FboSRGBQueryCase::FboSRGBQueryCase (Context& context, const char* const name, const char* const description)
1500 : TestCase (context, name, description)
1504 FboSRGBQueryCase::~FboSRGBQueryCase (void)
1506 FboSRGBQueryCase::deinit();
1509 void FboSRGBQueryCase::init (void)
1511 // extension requirements for test
1512 if (!glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::es(3, 2)) && !m_context.getContextInfo().isExtensionSupported("GL_EXT_sRGB_write_control"))
1513 TCU_THROW(NotSupportedError, "Test requires extension GL_EXT_sRGB_write_control or a context version equal or higher than 3.2");
1516 void FboSRGBQueryCase::deinit (void)
1520 FboSRGBQueryCase::IterateResult FboSRGBQueryCase::iterate (void)
1523 // API tests which check when querying FRAMEBUFFER_SRGB_EXT capability returns the correct information when using glEnabled() or glDisabled()
1525 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1526 tcu::TestLog& log = m_context.getTestContext().getLog();
1527 const char* const msgPart = ", after disabling = ";
1529 for (int idx = 0; idx < static_cast<int>(QUERYTYPE_LAST); idx++)
1531 std::ostringstream message;
1534 message << std::string("Results: After Enabling = ");
1536 gl.enable(GL_FRAMEBUFFER_SRGB);
1538 switch (static_cast<QueryType>(idx))
1540 case QUERYTYPE_ISENABLED:
1542 glw::GLboolean enabled[2];
1543 enabled[0] = gl.isEnabled(GL_FRAMEBUFFER_SRGB);
1544 gl.disable(GL_FRAMEBUFFER_SRGB);
1545 enabled[1] = gl.isEnabled(GL_FRAMEBUFFER_SRGB);
1547 message << static_cast<float>(enabled[0]) << msgPart << static_cast<float>(enabled[1]);
1548 pass = (enabled[0] && !(enabled[1])) ? true : false;
1551 case QUERYTYPE_BOOLEAN:
1553 glw::GLboolean enabled[2];
1554 gl.getBooleanv(GL_FRAMEBUFFER_SRGB,&enabled[0]);
1555 gl.disable(GL_FRAMEBUFFER_SRGB);
1556 gl.getBooleanv(GL_FRAMEBUFFER_SRGB,&enabled[1]);
1558 message << static_cast<float>(enabled[0]) << msgPart << static_cast<float>(enabled[1]);
1559 pass = (enabled[0] && !(enabled[1])) ? true : false;
1562 case QUERYTYPE_FLOAT:
1564 glw::GLfloat enabled[2];
1565 gl.getFloatv(GL_FRAMEBUFFER_SRGB, &enabled[0]);
1566 gl.disable(GL_FRAMEBUFFER_SRGB);
1567 gl.getFloatv(GL_FRAMEBUFFER_SRGB, &enabled[1]);
1569 message << static_cast<float>(enabled[0]) << msgPart << static_cast<float>(enabled[1]);
1570 pass = ((int)enabled[0] && !((int)enabled[1])) ? true : false;
1575 glw::GLint enabled[2];
1576 gl.getIntegerv(GL_FRAMEBUFFER_SRGB, &enabled[0]);
1577 gl.disable(GL_FRAMEBUFFER_SRGB);
1578 gl.getIntegerv(GL_FRAMEBUFFER_SRGB, &enabled[1]);
1580 message << static_cast<float>(enabled[0]) << msgPart << static_cast<float>(enabled[1]);
1581 pass = (enabled[0] && !(enabled[1])) ? true : false;
1584 case QUERYTYPE_INT64:
1586 glw::GLint64 enabled[2];
1587 gl.getInteger64v(GL_FRAMEBUFFER_SRGB, &enabled[0]);
1588 gl.disable(GL_FRAMEBUFFER_SRGB);
1589 gl.getInteger64v(GL_FRAMEBUFFER_SRGB, &enabled[1]);
1591 message << static_cast<float>(enabled[0]) << msgPart << static_cast<float>(enabled[1]);
1592 pass = (enabled[0] && !(enabled[1])) ? true : false;
1596 DE_FATAL("Error: Datatype not recognised");
1599 log << tcu::TestLog::Message << message.str() << tcu::TestLog::EndMessage;
1602 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1605 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Result verification failed");
1612 class FboSRGBColAttachCase : public FboSRGBTestCase
1615 FboSRGBColAttachCase (Context& context, const char* const name, const char* const description)
1616 : FboSRGBTestCase (context, name, description) {}
1617 ~FboSRGBColAttachCase (void) {}
1619 void setupTest (void);
1620 bool verifyResult (void);
1623 void FboSRGBColAttachCase::setupTest (void)
1626 // Check if FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING set to SRGB and FRAMEBUFFER_SRGB_EXT enabled, destination colors are converted from SRGB to linear
1627 // before and after blending, finally the result is converted back to SRGB for storage
1630 // if fbo pre-draw color set to linaer, color values get linearlized "twice"
1631 // (0.2f, 0.3f, 0.4f, 1.0f) when sampled i.e. converted in shader = (0.0331048f, 0.073239f, 0.132868f)
1632 // resulting in the follolwing blending equation (0.2f, 0.3f, 0.4f 1.0f) + (0.0331048, 0.073239, 0.132868) = (0.521569f, 0.647059f, 0.756863f, 1.0f)
1634 FBOConfig fboConfig0 = FBOConfig(GL_SRGB8_ALPHA8, getTestColorLinear(), GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FBOTYPE_SOURCE);
1635 FBOConfig fboConfig1 = FBOConfig(GL_RGBA8, getTestColorLinear(), GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FBOTYPE_SOURCE);
1637 const TestRenderPassConfig renderPassConfigs[] =
1639 TestRenderPassConfig(TEXTURESOURCESTYPE_RGBA, fboConfig0, FRAMEBUFFERSRGB_ENABLED, FRAMEBUFFERBLEND_ENABLED, RENDERERTASK_DRAW),
1640 TestRenderPassConfig(TEXTURESOURCESTYPE_BOTH, fboConfig1, FRAMEBUFFERSRGB_DISABLED, FRAMEBUFFERBLEND_DISABLED, getFunctionBlendLinearToSRGBCheck(), RENDERERTASK_DRAW)
1642 std::vector<TestRenderPassConfig> renderPassConfigList(renderPassConfigs, renderPassConfigs + DE_LENGTH_OF_ARRAY(renderPassConfigs));
1644 this->setTestConfig(renderPassConfigList);
1647 bool FboSRGBColAttachCase::verifyResult (void)
1649 if (tcu::boolAll(tcu::lessThan(tcu::abs(m_resultsPostDraw[0] - m_resultsPostDraw[1]), getEpsilonError())) || tcu::boolAll(tcu::equal(m_resultsPostDraw[0], m_resultsPostDraw[1])))
1655 class FboSRGBToggleBlendCase : public FboSRGBTestCase
1658 FboSRGBToggleBlendCase (Context& context, const char* const name, const char* const description)
1659 : FboSRGBTestCase (context, name, description) {}
1660 ~FboSRGBToggleBlendCase (void) {}
1662 void setupTest (void);
1663 bool verifyResult (void);
1666 void FboSRGBToggleBlendCase::setupTest (void)
1669 // Test to check if changing FRAMEBUFFER_SRGB_EXT from enabled to disabled. Enabled should produce SRGB color whilst disabled
1670 // should produce linear color. Test conducted with blending disabled.
1672 FBOConfig fboConfig0 = FBOConfig(GL_SRGB8_ALPHA8, getTestColorLinear(), GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FBOTYPE_DESTINATION);
1674 const TestRenderPassConfig renderPassConfigs[] =
1676 TestRenderPassConfig(TEXTURESOURCESTYPE_RGBA, fboConfig0, FRAMEBUFFERSRGB_ENABLED, FRAMEBUFFERBLEND_DISABLED, TestFunction(false), RENDERERTASK_DRAW),
1677 TestRenderPassConfig(TEXTURESOURCESTYPE_RGBA, fboConfig0, FRAMEBUFFERSRGB_DISABLED, FRAMEBUFFERBLEND_DISABLED, TestFunction(false), RENDERERTASK_DRAW)
1679 std::vector<TestRenderPassConfig> renderPassConfigList(renderPassConfigs, renderPassConfigs + DE_LENGTH_OF_ARRAY(renderPassConfigs));
1681 this->setTestConfig(renderPassConfigList);
1684 bool FboSRGBToggleBlendCase::verifyResult (void)
1686 if (tcu::boolAny(tcu::greaterThan(tcu::abs(m_resultsPostDraw[0] - m_resultsPostDraw[1]), getEpsilonError())))
1692 class FboSRGBRenderTargetIgnoreCase : public FboSRGBTestCase
1695 FboSRGBRenderTargetIgnoreCase (Context& context, const char* const name, const char* const description)
1696 : FboSRGBTestCase (context, name, description) {}
1697 ~FboSRGBRenderTargetIgnoreCase (void) {}
1699 void setupTest (void);
1700 bool verifyResult (void);
1703 void FboSRGBRenderTargetIgnoreCase::setupTest (void)
1706 // Check if render targets that are non-RGB ignore the state of GL_FRAMEBUFFER_SRGB_EXT. Rendering to an fbo with non-sRGB color
1707 // attachment should ignore color space conversion, producing linear color.
1709 FBOConfig fboConfig0 = FBOConfig(GL_RGBA8, getTestColorBlank(), GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FBOTYPE_DESTINATION);
1711 const TestRenderPassConfig renderPassConfigs[] =
1713 TestRenderPassConfig(TEXTURESOURCESTYPE_RGBA, fboConfig0, FRAMEBUFFERSRGB_ENABLED, FRAMEBUFFERBLEND_DISABLED, TestFunction(false), RENDERERTASK_DRAW)
1716 std::vector<TestRenderPassConfig> renderPassConfigList(renderPassConfigs, renderPassConfigs + DE_LENGTH_OF_ARRAY(renderPassConfigs));
1718 this->setTestConfig(renderPassConfigList);
1721 bool FboSRGBRenderTargetIgnoreCase::verifyResult (void)
1723 if (tcu::boolAll(tcu::lessThan(tcu::abs(m_resultsPostDraw[0] - getTestColorLinear()), getEpsilonError())) || tcu::boolAll(tcu::equal(m_resultsPostDraw[0], getTestColorLinear())))
1729 class FboSRGBCopyToLinearCase : public FboSRGBTestCase
1732 FboSRGBCopyToLinearCase (Context& context, const char* const name, const char* const description)
1733 : FboSRGBTestCase (context, name, description) {}
1734 ~FboSRGBCopyToLinearCase (void) {}
1736 void setupTest (void);
1737 bool verifyResult (void);
1740 void FboSRGBCopyToLinearCase::setupTest (void)
1743 // Check if copying from an fbo with an sRGB color attachment to an fbo with a linear color attachment with FRAMEBUFFER_EXT enabled results in
1744 // an sRGB to linear conversion
1746 FBOConfig fboConfigs[] =
1748 FBOConfig(GL_SRGB8_ALPHA8, getTestColorSRGB(), GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FBOTYPE_SOURCE),
1749 FBOConfig(GL_RGBA8, getTestColorBlank(), GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FBOTYPE_DESTINATION)
1751 std::vector<FBOConfig> fboConfigList(fboConfigs, fboConfigs + DE_LENGTH_OF_ARRAY(fboConfigs));
1753 const TestRenderPassConfig renderPassConfigs[] =
1755 TestRenderPassConfig(TEXTURESOURCESTYPE_NONE, fboConfigList, FRAMEBUFFERSRGB_ENABLED, FRAMEBUFFERBLEND_DISABLED, TestFunction(false), RENDERERTASK_COPY)
1757 std::vector<TestRenderPassConfig> renderPassConfigList(renderPassConfigs, renderPassConfigs + DE_LENGTH_OF_ARRAY(renderPassConfigs));
1759 this->setTestConfig(renderPassConfigList);
1762 bool FboSRGBCopyToLinearCase::verifyResult (void)
1764 logColor(m_context, "pre-copy source fbo color values", m_resultsPreDraw[0]);
1765 logColor(m_context, "pre-copy destination fbo color values", m_resultsPreDraw[1]);
1766 logColor(m_context, "post-copy source fbo color values", m_resultsPostDraw[0]);
1767 logColor(m_context, "post-copy destination fbo color values", m_resultsPostDraw[1]);
1769 if (tcu::boolAll(tcu::lessThan(tcu::abs(m_resultsPostDraw[1] - getTestColorLinear()), getEpsilonError())) || tcu::boolAll(tcu::equal(m_resultsPostDraw[1], getTestColorLinear())))
1775 class FboSRGBUnsupportedEnumCase : public TestCase
1778 FboSRGBUnsupportedEnumCase (Context& context, const char* const name, const char* const description);
1779 ~FboSRGBUnsupportedEnumCase (void);
1783 bool isInvalidEnum (std::string functionName);
1784 IterateResult iterate (void);
1787 FboSRGBUnsupportedEnumCase::FboSRGBUnsupportedEnumCase (Context& context, const char* const name, const char* const description)
1788 : TestCase (context, name, description)
1792 FboSRGBUnsupportedEnumCase::~FboSRGBUnsupportedEnumCase (void)
1794 FboSRGBUnsupportedEnumCase::deinit();
1797 void FboSRGBUnsupportedEnumCase::init (void)
1799 // extension requirements for test
1800 if (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::es(3, 2)) || m_context.getContextInfo().isExtensionSupported("GL_EXT_sRGB_write_control"))
1801 TCU_THROW(NotSupportedError, "Test requires extension GL_EXT_sRGB_write_control to be unsupported and a context version less than 3.2");
1804 void FboSRGBUnsupportedEnumCase::deinit (void)
1808 bool FboSRGBUnsupportedEnumCase::isInvalidEnum (std::string functionName)
1810 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1811 tcu::TestLog& log = m_context.getTestContext().getLog();
1813 glw::GLenum error = GL_NO_ERROR;
1815 log << tcu::TestLog::Message << "Checking call to " << functionName << tcu::TestLog::EndMessage;
1817 error = gl.getError();
1819 if (error != GL_INVALID_ENUM)
1821 log << tcu::TestLog::Message << " returned wrong value [" << glu::getErrorStr(error) << ", expected " << glu::getErrorStr(GL_INVALID_ENUM) << "]" << tcu::TestLog::EndMessage;
1828 FboSRGBUnsupportedEnumCase::IterateResult FboSRGBUnsupportedEnumCase::iterate (void)
1831 // API tests that check calls using enum GL_FRAMEBUFFER_SRGB return GL_INVALID_ENUM when GL_EXT_sRGB_write_control is not supported
1833 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1834 bool allPass = true;
1835 glw::GLboolean bEnabled = GL_FALSE;
1836 glw::GLfloat fEnabled = 0;
1837 glw::GLint iEnabled = 0;
1838 glw::GLint64 lEnabled = 0;
1840 m_context.getTestContext().getLog() << tcu::TestLog::Message
1841 << "Check calls using enum GL_FRAMEBUFFER_SRGB return GL_INVALID_ENUM when GL_EXT_sRGB_write_control is not supported\n\n"
1842 << tcu::TestLog::EndMessage;
1844 gl.enable(GL_FRAMEBUFFER_SRGB);
1845 allPass &= isInvalidEnum("glEnable()");
1847 gl.disable(GL_FRAMEBUFFER_SRGB);
1848 allPass &= isInvalidEnum("glDisable()");
1850 gl.isEnabled(GL_FRAMEBUFFER_SRGB);
1851 allPass &= isInvalidEnum("glIsEnabled()");
1853 gl.getBooleanv(GL_FRAMEBUFFER_SRGB, &bEnabled);
1854 allPass &= isInvalidEnum("glGetBooleanv()");
1856 gl.getFloatv(GL_FRAMEBUFFER_SRGB, &fEnabled);
1857 allPass &= isInvalidEnum("glGetFloatv()");
1859 gl.getIntegerv(GL_FRAMEBUFFER_SRGB, &iEnabled);
1860 allPass &= isInvalidEnum("glGetIntegerv()");
1862 gl.getInteger64v(GL_FRAMEBUFFER_SRGB, &lEnabled);
1863 allPass &= isInvalidEnum("glGetInteger64v()");
1866 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1868 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1875 FboSRGBWriteControlTests::FboSRGBWriteControlTests (Context& context)
1876 : TestCaseGroup (context, "srgb_write_control", "Colorbuffer tests")
1880 FboSRGBWriteControlTests::~FboSRGBWriteControlTests (void)
1884 void FboSRGBWriteControlTests::init (void)
1886 this->addChild(new FboSRGBQueryCase (m_context, "framebuffer_srgb_enabled", "srgb enable framebuffer"));
1887 this->addChild(new FboSRGBColAttachCase (m_context, "framebuffer_srgb_enabled_col_attach", "srgb enable color attachment and framebuffer"));
1888 this->addChild(new FboSRGBToggleBlendCase (m_context, "framebuffer_srgb_enabled_blend", "toggle framebuffer srgb settings with blend disabled"));
1889 this->addChild(new FboSRGBRenderTargetIgnoreCase (m_context, "framebuffer_srgb_enabled_render_target_ignore", "enable framebuffer srgb, non-srgb render target should ignore"));
1890 this->addChild(new FboSRGBCopyToLinearCase (m_context, "framebuffer_srgb_enabled_copy_to_linear", "no conversion when blittering between framebuffer srgb and linear"));
1893 this->addChild(new FboSRGBUnsupportedEnumCase (m_context, "framebuffer_srgb_unsupported_enum", "check error codes for query functions when extension is not supported"));