13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES 2.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 Default vertex attribute test 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es2fDefaultVertexAttributeTests.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuVector.hpp" 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderContext.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluCallLogWrapper.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderProgram.hpp" 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluObjectWrapper.hpp" 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp" 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp" 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp" 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMath.h" 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp" 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h" 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <limits> 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles2 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const int s_valueRange = 10; 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* const s_passThroughFragmentShaderSource = "varying mediump vec4 v_color;\n" 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main (void)\n" 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " gl_FragColor = v_color;\n" 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n"; 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T1, int S1, typename T2, int S2> 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::Vector<T1, S1> convertToTypeVec (const tcu::Vector<T2, S2>& v) 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vector<T1, S1> retVal; 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < S1; ++ndx) 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry retVal[ndx] = T1(0); 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (S1 == 4) 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry retVal[3] = T1(1); 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < de::min(S1, S2); ++ndx) 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry retVal[ndx] = T1(v[ndx]); 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return retVal; 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass FloatLoader 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~FloatLoader (void) {}; 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // returns the value loaded 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual tcu::Vec4 load (glu::CallLogWrapper& gl, int index, const tcu::Vec4& v) const = 0; 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define GEN_DIRECT_FLOAT_LOADER(TYPE, COMPS, TYPECODE, CASENAME, VALUES) \ 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry class LoaderVertexAttrib##COMPS##TYPECODE : public FloatLoader \ 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { \ 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry public: \ 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum \ 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { \ 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry NORMALIZING = 0, \ 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; \ 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum \ 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { \ 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry COMPONENTS = COMPS \ 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; \ 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry typedef TYPE Type; \ 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry \ 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 load (glu::CallLogWrapper& gl, int index, const tcu::Vec4& v) const \ 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { \ 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vector<TYPE, COMPONENTS> value; \ 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry value = convertToTypeVec<Type, COMPONENTS>(v); \ 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry \ 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.glVertexAttrib ##COMPS ##TYPECODE VALUES; \ 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return convertToTypeVec<float, 4>(value); \ 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } \ 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry \ 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const char* getCaseName (void) \ 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { \ 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return CASENAME; \ 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } \ 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry \ 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const char* getName (void) \ 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { \ 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return "VertexAttrib" #COMPS #TYPECODE; \ 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } \ 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define GEN_INDIRECT_FLOAT_LOADER(TYPE, COMPS, TYPECODE, CASENAME) \ 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry class LoaderVertexAttrib##COMPS##TYPECODE : public FloatLoader \ 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { \ 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry public: \ 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum \ 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { \ 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry NORMALIZING = 0, \ 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; \ 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum \ 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { \ 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry COMPONENTS = COMPS \ 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; \ 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry typedef TYPE Type; \ 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry \ 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 load (glu::CallLogWrapper& gl, int index, const tcu::Vec4& v) const \ 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { \ 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vector<TYPE, COMPONENTS> value; \ 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry value = convertToTypeVec<Type, COMPONENTS>(v); \ 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry \ 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.glVertexAttrib ##COMPS ##TYPECODE (index, value.getPtr()); \ 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return convertToTypeVec<float, 4>(value); \ 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } \ 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry \ 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const char* getCaseName (void) \ 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { \ 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return CASENAME; \ 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } \ 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry \ 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const char* getName (void) \ 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { \ 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return "VertexAttrib" #COMPS #TYPECODE; \ 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } \ 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1533c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGEN_DIRECT_FLOAT_LOADER(float, 1, f, "vertex_attrib_1f", (index, value.x())); 1543c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGEN_DIRECT_FLOAT_LOADER(float, 2, f, "vertex_attrib_2f", (index, value.x(), value.y())); 1553c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGEN_DIRECT_FLOAT_LOADER(float, 3, f, "vertex_attrib_3f", (index, value.x(), value.y(), value.z())); 1563c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGEN_DIRECT_FLOAT_LOADER(float, 4, f, "vertex_attrib_4f", (index, value.x(), value.y(), value.z(), value.w())); 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1583c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGEN_INDIRECT_FLOAT_LOADER(float, 1, fv, "vertex_attrib_1fv"); 1593c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGEN_INDIRECT_FLOAT_LOADER(float, 2, fv, "vertex_attrib_2fv"); 1603c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGEN_INDIRECT_FLOAT_LOADER(float, 3, fv, "vertex_attrib_3fv"); 1613c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGEN_INDIRECT_FLOAT_LOADER(float, 4, fv, "vertex_attrib_4fv"); 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass AttributeCase : public TestCase 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry AttributeCase (Context& ctx, const char* name, const char* desc, const char* funcName, bool normalizing, bool useNegative, glu::DataType dataType); 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry template<typename LoaderType> 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static AttributeCase* create (Context& ctx, glu::DataType dataType); 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~AttributeCase (void); 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void deinit (void); 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void); 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::DataType getTargetType (void) const; 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string genVertexSource (void) const; 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool renderWithValue (const tcu::Vec4& v); 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 computeColor (const tcu::Vec4& value); 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool verifyUnicoloredBuffer (const tcu::Surface& scene, const tcu::Vec4& refValue); 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool m_normalizing; 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool m_useNegativeValues; 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* const m_funcName; 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::DataType m_dataType; 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const FloatLoader* m_loader; 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram* m_program; 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_bufID; 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool m_allIterationsPassed; 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_iteration; 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RENDER_SIZE = 32 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1983c827367444ee418f129b2c238299f49d3264554Jarkko PoyryAttributeCase::AttributeCase (Context& ctx, const char* name, const char* desc, const char* funcName, bool normalizing, bool useNegative, glu::DataType dataType) 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (ctx, name, desc) 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_normalizing (normalizing) 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_useNegativeValues (useNegative) 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_funcName (funcName) 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_dataType (dataType) 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_loader (DE_NULL) 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_program (DE_NULL) 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_bufID (0) 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_allIterationsPassed (true) 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_iteration (0) 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename LoaderType> 2133c827367444ee418f129b2c238299f49d3264554Jarkko PoyryAttributeCase* AttributeCase::create (Context& ctx, glu::DataType dataType) 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry AttributeCase* retVal = new AttributeCase(ctx, 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry LoaderType::getCaseName(), 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry (std::string("Test ") + LoaderType::getName()).c_str(), 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry LoaderType::getName(), 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry LoaderType::NORMALIZING != 0, 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::numeric_limits<typename LoaderType::Type>::is_signed, 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dataType); 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry retVal->m_loader = new LoaderType(); 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return retVal; 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2263c827367444ee418f129b2c238299f49d3264554Jarkko PoyryAttributeCase::~AttributeCase (void) 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deinit(); 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid AttributeCase::init (void) 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_context.getRenderTarget().getWidth() < RENDER_SIZE || m_context.getRenderTarget().getHeight() < RENDER_SIZE) 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("Render target must be at least " + de::toString<int>(RENDER_SIZE) + "x" + de::toString<int>(RENDER_SIZE)); 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // log test info 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float maxRange = (m_normalizing) ? (1.0f) : (s_valueRange); 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float minRange = (m_useNegativeValues) ? (-maxRange) : (0.0f); 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << tcu::TestLog::Message 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "Loading attribute values using " << m_funcName << "\n" 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "Attribute type: " << glu::getDataTypeName(m_dataType) << "\n" 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "Attribute value range: [" << minRange << ", " << maxRange << "]" 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << tcu::TestLog::EndMessage; 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // gen shader and base quad 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_program = new glu::ShaderProgram(m_context.getRenderContext(), glu::ProgramSources() << glu::VertexSource(genVertexSource()) << glu::FragmentSource(s_passThroughFragmentShaderSource)); 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << *m_program; 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!m_program->isOk()) 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::TestError("could not build program"); 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 fullscreenQuad[] = 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4( 1.0f, 1.0f, 0.0f, 1.0f), 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4( 1.0f, -1.0f, 0.0f, 1.0f), 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f), 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(-1.0f, -1.0f, 0.0f, 1.0f), 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genBuffers(1, &m_bufID); 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ARRAY_BUFFER, m_bufID); 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_ARRAY_BUFFER, sizeof(fullscreenQuad), fullscreenQuad, GL_STATIC_DRAW); 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "fill buffer"); 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid AttributeCase::deinit (void) 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_loader; 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_loader = DE_NULL; 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_program; 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_program = DE_NULL; 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_bufID) 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_bufID); 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_bufID = 0; 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2903c827367444ee418f129b2c238299f49d3264554Jarkko PoyryAttributeCase::IterateResult AttributeCase::iterate (void) 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const tcu::Vec4 testValues[] = 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(0.0f, 0.5f, 0.2f, 1.0f), 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(0.1f, 0.7f, 1.0f, 0.6f), 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(0.4f, 0.2f, 0.0f, 0.5f), 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(0.5f, 0.0f, 0.9f, 0.1f), 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(0.6f, 0.2f, 0.2f, 0.9f), 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(0.9f, 1.0f, 0.0f, 0.0f), 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(1.0f, 0.5f, 0.3f, 0.8f), 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::ScopedLogSection section(m_testCtx.getLog(), "Iteration", "Iteration " + de::toString(m_iteration+1) + "/" + de::toString(DE_LENGTH_OF_ARRAY(testValues))); 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Test normalizing transfers with whole range, non-normalizing with up to s_valueRange 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 testValue = ((m_useNegativeValues) ? (testValues[m_iteration] * 2.0f - tcu::Vec4(1.0f)) : (testValues[m_iteration])) * ((m_normalizing) ? (1.0f) : ((float)s_valueRange)); 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!renderWithValue(testValue)) 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_allIterationsPassed = false; 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // continue 3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (++m_iteration < DE_LENGTH_OF_ARRAY(testValues)) 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return CONTINUE; 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_allIterationsPassed) 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got unexpected values"); 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::string AttributeCase::genVertexSource (void) const 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int vectorSize = (glu::isDataTypeMatrix(m_dataType)) ? (glu::getDataTypeMatrixNumRows(m_dataType)) : (glu::isDataTypeVector(m_dataType)) ? (glu::getDataTypeScalarSize(m_dataType)) : (-1); 3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* const vectorType = glu::getDataTypeName((glu::isDataTypeMatrix(m_dataType)) ? (glu::getDataTypeVector(glu::TYPE_FLOAT, vectorSize)) : (glu::isDataTypeVector(m_dataType)) ? (glu::getDataTypeVector(glu::TYPE_FLOAT, vectorSize)) : (glu::TYPE_FLOAT)); 3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int components = (glu::isDataTypeMatrix(m_dataType)) ? (glu::getDataTypeMatrixNumRows(m_dataType)) : (glu::getDataTypeScalarSize(m_dataType)); 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::ostringstream buf; 3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << "attribute highp vec4 a_position;\n" 3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "attribute highp " << glu::getDataTypeName(m_dataType) << " a_value;\n" 3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "varying highp vec4 v_color;\n" 3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main (void)\n" 3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " gl_Position = a_position;\n" 3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "\n"; 3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_normalizing) 3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << " highp " << vectorType << " normalizedValue = " << ((glu::getDataTypeScalarType(m_dataType) == glu::TYPE_FLOAT) ? ("") : (vectorType)) << "(a_value" << ((glu::isDataTypeMatrix(m_dataType)) ? ("[1]") : ("")) << ");\n"; 3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << " highp " << vectorType << " normalizedValue = " << ((glu::getDataTypeScalarType(m_dataType) == glu::TYPE_FLOAT) ? ("") : (vectorType)) << "(a_value" << ((glu::isDataTypeMatrix(m_dataType)) ? ("[1]") : ("")) << ") / float(" << s_valueRange << ");\n"; 3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_useNegativeValues) 3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << " highp " << vectorType << " positiveNormalizedValue = (normalizedValue + " << vectorType << "(1.0)) / 2.0;\n"; 3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << " highp " << vectorType << " positiveNormalizedValue = normalizedValue;\n"; 3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (components == 1) 3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << " v_color = vec4(positiveNormalizedValue, 0.0, 0.0, 1.0);\n"; 3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (components == 2) 3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << " v_color = vec4(positiveNormalizedValue.xy, 0.0, 1.0);\n"; 3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (components == 3) 3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << " v_color = vec4(positiveNormalizedValue.xyz, 1.0);\n"; 3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (components == 4) 3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << " v_color = vec4((positiveNormalizedValue.xy + positiveNormalizedValue.zz) / 2.0, positiveNormalizedValue.w, 1.0);\n"; 3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(DE_FALSE); 3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << "}\n"; 3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return buf.str(); 3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool AttributeCase::renderWithValue (const tcu::Vec4& v) 3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog()); 3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.enableLogging(true); 3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int positionIndex = gl.glGetAttribLocation(m_program->getProgram(), "a_position"); 3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int valueIndex = gl.glGetAttribLocation(m_program->getProgram(), "a_value"); 3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface dest (RENDER_SIZE, RENDER_SIZE); 3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 loadedValue; 3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.glClear(GL_COLOR_BUFFER_BIT); 3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.glViewport(0, 0, RENDER_SIZE, RENDER_SIZE); 3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.glGetError(), "setup"); 3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.glBindBuffer(GL_ARRAY_BUFFER, m_bufID); 3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.glVertexAttribPointer(positionIndex, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL); 3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.glEnableVertexAttribArray(positionIndex); 3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.glGetError(), "position va"); 3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // transfer test value. Load to the second column in the matrix case 3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry loadedValue = m_loader->load(gl, (glu::isDataTypeMatrix(m_dataType)) ? (valueIndex + 1) : (valueIndex), v); 3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.glGetError(), "default va"); 3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.glUseProgram(m_program->getProgram()); 3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.glUseProgram(0); 3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.glGetError(), "draw"); 3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::readPixels(m_context.getRenderContext(), 0, 0, dest.getAccess()); 3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // check whole result is colored correctly 3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return verifyUnicoloredBuffer(dest, computeColor(loadedValue)); 3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::Vec4 AttributeCase::computeColor (const tcu::Vec4& value) 4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 normalizedValue = value / ((m_normalizing) ? (1.0f) : ((float)s_valueRange)); 4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 positiveNormalizedValue = ((m_useNegativeValues) ? ((normalizedValue + tcu::Vec4(1.0f)) / 2.0f) : (normalizedValue)); 4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int components = (glu::isDataTypeMatrix(m_dataType)) ? (glu::getDataTypeMatrixNumRows(m_dataType)) : (glu::getDataTypeScalarSize(m_dataType)); 4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (components == 1) 4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return tcu::Vec4(positiveNormalizedValue.x(), 0.0f, 0.0f, 1.0f); 4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (components == 2) 4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return tcu::Vec4(positiveNormalizedValue.x(), positiveNormalizedValue.y(), 0.0f, 1.0f); 4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (components == 3) 4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return tcu::Vec4(positiveNormalizedValue.x(), positiveNormalizedValue.y(), positiveNormalizedValue.z(), 1.0f); 4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (components == 4) 4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return tcu::Vec4((positiveNormalizedValue.x() + positiveNormalizedValue.z()) / 2.0f, (positiveNormalizedValue.y() + positiveNormalizedValue.z()) / 2.0f, positiveNormalizedValue.w(), 1.0f); 4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(DE_FALSE); 4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f); 4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool AttributeCase::verifyUnicoloredBuffer (const tcu::Surface& scene, const tcu::Vec4& refValue) 4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface errorMask (RENDER_SIZE, RENDER_SIZE); 4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::RGBA refColor (refValue); 4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int resultThreshold = 2; 4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::RGBA colorThreshold = m_context.getRenderTarget().getPixelFormat().getColorThreshold() * resultThreshold; 4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool error = false; 4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::RGBA exampleColor; 4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::IVec2 examplePos; 4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::clear(errorMask.getAccess(), tcu::RGBA::green.toIVec()); 4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Verifying rendered image. Expecting color " << refColor << ", threshold " << colorThreshold << tcu::TestLog::EndMessage; 4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < RENDER_SIZE; ++y) 4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < RENDER_SIZE; ++x) 4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::RGBA color = scene.getPixel(x, y); 4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (de::abs(color.getRed() - refColor.getRed()) > colorThreshold.getRed() || 4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::abs(color.getGreen() - refColor.getGreen()) > colorThreshold.getGreen() || 4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::abs(color.getBlue() - refColor.getBlue()) > colorThreshold.getBlue()) 4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // first error 4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!error) 4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry exampleColor = color; 4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry examplePos = tcu::IVec2(x, y); 4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry error = true; 4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry errorMask.setPixel(x, y, tcu::RGBA::red); 4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!error) 4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Rendered image is valid." << tcu::TestLog::EndMessage; 4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message 4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "Found invalid pixel(s).\n" 4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "Pixel at (" << examplePos.x() << ", " << examplePos.y() << ") color: " << exampleColor 4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << tcu::TestLog::EndMessage 4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << tcu::TestLog::ImageSet("Result", "Render result") 4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << tcu::TestLog::Image("Result", "Result", scene) 4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << tcu::TestLog::Image("ErrorMask", "Error Mask", errorMask) 4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << tcu::TestLog::EndImageSet; 4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return !error; 4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // anonymous 4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4763c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDefaultVertexAttributeTests::DefaultVertexAttributeTests (Context& context) 4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup(context, "default_vertex_attrib", "Test default vertex attributes") 4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4813c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDefaultVertexAttributeTests::~DefaultVertexAttributeTests (void) 4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid DefaultVertexAttributeTests::init (void) 4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry struct Target 4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* name; 4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::DataType dataType; 4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool reducedTestSets; // !< use reduced coverage 4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const Target floatTargets[] = 4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "float", glu::TYPE_FLOAT, false }, 4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "vec2", glu::TYPE_FLOAT_VEC2, true }, 4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "vec3", glu::TYPE_FLOAT_VEC3, true }, 4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "vec4", glu::TYPE_FLOAT_VEC4, false }, 5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "mat2", glu::TYPE_FLOAT_MAT2, true }, 5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "mat3", glu::TYPE_FLOAT_MAT3, true }, 5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "mat4", glu::TYPE_FLOAT_MAT4, false }, 5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // float targets 5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(floatTargets); ++targetNdx) 5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TestCaseGroup* const group = new tcu::TestCaseGroup(m_testCtx, floatTargets[targetNdx].name, (std::string("test with ") + floatTargets[targetNdx].name).c_str()); 5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool fullSet = !floatTargets[targetNdx].reducedTestSets; 5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define ADD_CASE(X) group->addChild(AttributeCase::create<X>(m_context, floatTargets[targetNdx].dataType)) 5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define ADD_REDUCED_CASE(X) if (fullSet) ADD_CASE(X) 5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ADD_CASE (LoaderVertexAttrib1f); 5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ADD_REDUCED_CASE(LoaderVertexAttrib2f); 5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ADD_REDUCED_CASE(LoaderVertexAttrib3f); 5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ADD_CASE (LoaderVertexAttrib4f); 5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ADD_CASE (LoaderVertexAttrib1fv); 5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ADD_REDUCED_CASE(LoaderVertexAttrib2fv); 5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ADD_REDUCED_CASE(LoaderVertexAttrib3fv); 5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ADD_CASE (LoaderVertexAttrib4fv); 5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#undef ADD_CASE 5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#undef ADD_REDUCED_CASE 5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(group); 5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional 5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles2 5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp 535