13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES 3.0 Module 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ------------------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief GLSL ES 1.0 gl_FragData[] tests. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es3fShaderFragDataTests.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsShaderLibrary.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderContext.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderProgram.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluDrawUtil.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp" 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluObjectWrapper.hpp" 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp" 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuStringTemplate.hpp" 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp" 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp" 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp" 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp" 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles3 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string; 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog; 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum IndexExprType 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry INDEX_EXPR_STATIC = 0, 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry INDEX_EXPR_UNIFORM, 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry INDEX_EXPR_DYNAMIC, 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry INDEX_EXPR_TYPE_LAST 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic bool compareSingleColor (tcu::TestLog& log, const tcu::Surface& surface, tcu::RGBA expectedColor, tcu::RGBA threshold) 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int maxPrints = 10; 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int numFailedPixels = 0; 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "Expecting " << expectedColor << " with threshold " << threshold << TestLog::EndMessage; 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < surface.getHeight(); y++) 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < surface.getWidth(); x++) 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::RGBA resultColor = surface.getPixel(x, y); 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool isOk = compareThreshold(resultColor, expectedColor, threshold); 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!isOk) 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (numFailedPixels < maxPrints) 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "ERROR: Got " << resultColor << " at (" << x << ", " << y << ")!" << TestLog::EndMessage; 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (numFailedPixels == maxPrints) 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "..." << TestLog::EndMessage; 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry numFailedPixels += 1; 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (numFailedPixels > 0) 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "Found " << numFailedPixels << " invalid pixels, comparison FAILED!" << TestLog::EndMessage; 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Image("ResultImage", "Result Image", surface); 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return false; 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "Image comparison passed." << TestLog::EndMessage; 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return true; 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass FragDataIndexingCase : public TestCase 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FragDataIndexingCase (Context& context, const char* name, const char* description, IndexExprType indexExprType) 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (context, name, description) 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_indexExprType (indexExprType) 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static glu::ProgramSources genSources (const IndexExprType indexExprType) 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* const fragIndexExpr = indexExprType == INDEX_EXPR_STATIC ? "0" : 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry indexExprType == INDEX_EXPR_UNIFORM ? "u_index" : 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry indexExprType == INDEX_EXPR_DYNAMIC ? "int(v_index)" : DE_NULL; 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ProgramSources sources; 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(fragIndexExpr); 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sources << glu::VertexSource( 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "attribute highp vec4 a_position;\n" 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "attribute highp float a_index;\n" 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "attribute highp vec4 a_color;\n" 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "varying mediump float v_index;\n" 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "varying mediump vec4 v_color;\n" 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main (void)\n" 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " gl_Position = a_position;\n" 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " v_color = a_color;\n" 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " v_index = a_index;\n" 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n"); 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sources << glu::FragmentSource(string( 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "varying mediump vec4 v_color;\n" 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "varying mediump float v_index;\n" 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "uniform mediump int u_index;\n" 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main (void)\n" 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " gl_FragData[") + fragIndexExpr + "] = v_color;\n" 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n"); 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return sources; 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void) 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::RenderContext& renderCtx = m_context.getRenderContext(); 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = renderCtx.getFunctions(); 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::ShaderProgram program (renderCtx, genSources(m_indexExprType)); 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int viewportW = de::min(renderCtx.getRenderTarget().getWidth(), 128); 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int viewportH = de::min(renderCtx.getRenderTarget().getHeight(), 128); 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float positions[] = 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry -1.0f, -1.0f, 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry +1.0f, -1.0f, 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry -1.0f, +1.0f, 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry +1.0f, +1.0f 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float colors[] = 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 0.0f, 1.0f, 0.0f, 1.0f, 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 0.0f, 1.0f, 0.0f, 1.0f, 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 0.0f, 1.0f, 0.0f, 1.0f, 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 0.0f, 1.0f, 0.0f, 1.0f 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float indexValues[] = { 0.0f, 0.0f, 0.0f, 0.0f }; 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint8 indices[] = { 0, 1, 2, 2, 1, 3 }; 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::VertexArrayBinding vertexArrays[] = 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::va::Float("a_position", 2, 4, 0, &positions[0]), 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::va::Float("a_color", 4, 4, 0, &colors[0]), 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::va::Float("a_index", 1, 4, 0, &indexValues[0]) 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << program; 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!program.isOk()) 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_indexExprType == INDEX_EXPR_STATIC) 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_FAIL("Compile failed"); 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("Dynamic indexing of gl_FragData[] not supported"); 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clearColor (1.0f, 0.0f, 0.0f, 1.0f); 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.viewport (0, 0, viewportW, viewportH); 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram (program.getProgram()); 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.uniform1i (gl.getUniformLocation(program.getProgram(), "u_index"), 0); 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::draw(renderCtx, program.getProgram(), DE_LENGTH_OF_ARRAY(vertexArrays), &vertexArrays[0], 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::pr::Triangles(DE_LENGTH_OF_ARRAY(indices), &indices[0])); 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Rendering failed"); 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface result (viewportW, viewportH); 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::RGBA threshold = renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(1,1,1,1); 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isOk; 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::readPixels(renderCtx, 0, 0, result.getAccess()); 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Reading pixels failed"); 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry isOk = compareSingleColor(m_testCtx.getLog(), result, tcu::RGBA::green, threshold); 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry isOk ? "Pass" : "Image comparison failed"); 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const IndexExprType m_indexExprType; 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass FragDataDrawBuffersCase : public TestCase 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FragDataDrawBuffersCase (Context& context) 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase(context, "draw_buffers", "gl_FragData[] and glDrawBuffers() interaction") 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void) 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::RenderContext& renderCtx = m_context.getRenderContext(); 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::ShaderProgram program (renderCtx, glu::ProgramSources() 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << glu::VertexSource( 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "attribute highp vec4 a_position;\n" 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "attribute highp vec4 a_color;\n" 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "varying mediump vec4 v_color;\n" 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main (void)\n" 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " gl_Position = a_position;\n" 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " v_color = a_color;\n" 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n") 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << glu::FragmentSource( 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "varying mediump vec4 v_color;\n" 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "uniform mediump int u_index;\n" 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main (void)\n" 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " gl_FragData[u_index] = v_color;\n" 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n")); 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = renderCtx.getFunctions(); 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int width = 128; 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int height = 128; 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int indexLoc = program.isOk() ? gl.getUniformLocation(program.getProgram(), "u_index") : -1; 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::Framebuffer fbo (renderCtx); 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::Renderbuffer colorBuf0 (renderCtx); 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::Renderbuffer colorBuf1 (renderCtx); 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float positions[] = 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry -1.0f, -1.0f, 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry +1.0f, -1.0f, 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry -1.0f, +1.0f, 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry +1.0f, +1.0f 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float colors[] = 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 0.0f, 1.0f, 0.0f, 1.0f, 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 0.0f, 1.0f, 0.0f, 1.0f, 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 0.0f, 1.0f, 0.0f, 1.0f, 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 0.0f, 1.0f, 0.0f, 1.0f 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint8 indices[] = { 0, 1, 2, 2, 1, 3 }; 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::VertexArrayBinding vertexArrays[] = 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::va::Float("a_position", 2, 4, 0, &positions[0]), 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::va::Float("a_color", 4, 4, 0, &colors[0]) 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << program; 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!program.isOk()) 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("Dynamic indexing of gl_FragData[] not supported"); 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindFramebuffer(GL_FRAMEBUFFER, *fbo); 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < 2; ndx++) 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 rbo = ndx == 0 ? *colorBuf0 : *colorBuf1; 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindRenderbuffer(GL_RENDERBUFFER, rbo); 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.renderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, width, height); 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+ndx, GL_RENDERBUFFER, rbo); 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 drawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 }; 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.drawBuffers(DE_LENGTH_OF_ARRAY(drawBuffers), &drawBuffers[0]); 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clearBufferfv(GL_COLOR, 0, tcu::RGBA::red.toVec().getPtr()); 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clearBufferfv(GL_COLOR, 1, tcu::RGBA::red.toVec().getPtr()); 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.viewport (0, 0, width, height); 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram (program.getProgram()); 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Setup failed"); 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << TestLog::Message << "Drawing to attachments 0 and 1, expecting only attachment 0 to change." << TestLog::EndMessage; 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < 2; ndx++) 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.uniform1i(indexLoc, ndx); 3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::draw(renderCtx, program.getProgram(), DE_LENGTH_OF_ARRAY(vertexArrays), &vertexArrays[0], 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::pr::Triangles(DE_LENGTH_OF_ARRAY(indices), &indices[0])); 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Rendering failed"); 3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface result (width, height); 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::RGBA threshold = renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(1,1,1,1); 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool allOk = true; 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < 2; ndx++) 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << TestLog::Message << "Verifying attachment " << ndx << "..." << TestLog::EndMessage; 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.readBuffer(GL_COLOR_ATTACHMENT0+ndx); 3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::readPixels(renderCtx, 0, 0, result.getAccess()); 3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Reading pixels failed"); 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!compareSingleColor(m_testCtx.getLog(), result, ndx == 0 ? tcu::RGBA::green : tcu::RGBA::red, threshold)) 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry allOk = false; 3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(allOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, 3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry allOk ? "Pass" : "Image comparison failed"); 3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // anonymous 3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3443c827367444ee418f129b2c238299f49d3264554Jarkko PoyryShaderFragDataTests::ShaderFragDataTests (Context& context) 3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup(context, "fragdata", "gl_FragData[] Tests") 3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3493c827367444ee418f129b2c238299f49d3264554Jarkko PoyryShaderFragDataTests::~ShaderFragDataTests (void) 3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ShaderFragDataTests::init (void) 3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new FragDataIndexingCase (m_context, "valid_static_index", "Valid gl_FragData[] assignment using static index", INDEX_EXPR_STATIC)); 3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new FragDataIndexingCase (m_context, "valid_uniform_index", "Valid gl_FragData[] assignment using uniform index", INDEX_EXPR_UNIFORM)); 3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new FragDataIndexingCase (m_context, "valid_dynamic_index", "Valid gl_FragData[] assignment using dynamic index", INDEX_EXPR_DYNAMIC)); 3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new FragDataDrawBuffersCase (m_context)); 3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Negative cases. 3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::ShaderLibrary library(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo()); 3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<tcu::TestNode*> negativeCases = library.loadShaderFile("shaders/fragdata.test"); 3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (std::vector<tcu::TestNode*>::iterator i = negativeCases.begin(); i != negativeCases.end(); i++) 3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(*i); 3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional 3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles3 3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp 373