glsTextureBufferCase.cpp revision c8e526bfc2141e1cb7a269483fb55dc2a8e77c11
13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL (ES) 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 Texture buffer test case 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsTextureBufferCase.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuFormatUtil.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuImageCompare.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuStringTemplate.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp" 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp" 33ab44fc6da25bb126919615ad2ded101695251161Jarkko Pöyry#include "tcuResultCollector.hpp" 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rrRenderer.hpp" 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rrShaders.hpp" 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluObjectWrapper.hpp" 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp" 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderProgram.hpp" 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderUtil.hpp" 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluStrUtil.hpp" 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTexture.hpp" 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp" 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp" 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.hpp" 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp" 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deUniquePtr.hpp" 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMemory.h" 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h" 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMath.h" 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <sstream> 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string> 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector> 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog; 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::map; 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string; 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector; 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace deqp::gls::TextureBufferCaseUtil; 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gls 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MAX_VIEWPORT_WIDTH = 256, 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MAX_VIEWPORT_HEIGHT = 256, 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MIN_VIEWPORT_WIDTH = 64, 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MIN_VIEWPORT_HEIGHT = 64, 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 833c827367444ee418f129b2c238299f49d3264554Jarkko PoyrydeUint8 extend2BitsToByte (deUint8 bits) 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT((bits & (~0x03u)) == 0); 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 87c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry return (deUint8)(bits | (bits << 2) | (bits << 4) | (bits << 6)); 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid genRandomCoords (de::Random rng, vector<deUint8>& coords, size_t offset, size_t size) 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint8 bits = 2; 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint8 bitMask = deUint8((0x1u << bits) - 1); 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry coords.resize(size); 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < (int)size; i++) 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint8 xBits = deUint8(rng.getUint32() & bitMask); 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry coords[i] = extend2BitsToByte(xBits); 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fill indices with nice quad 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint8 indices[] = 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x0u), 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x1u), 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x2u), 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x3u) 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < DE_LENGTH_OF_ARRAY(indices); i++) 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint8 index = indices[i]; 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t posX = (size_t(index) * 2) + 0; 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t posY = (size_t(index) * 2) + 1; 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (posX >= offset && posX < offset+size) 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry coords[posX - offset] = ((i % 2) == 0 ? extend2BitsToByte(0x0u) : extend2BitsToByte(0x3u)); 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (posY >= offset && posY < offset+size) 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry coords[posY - offset] = ((i / 2) == 1 ? extend2BitsToByte(0x3u) : extend2BitsToByte(0x0u)); 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fill beginning of buffer 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint8 indices[] = 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x0u), 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x3u), 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x1u), 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x1u), 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x2u), 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x0u), 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x0u), 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x2u), 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x1u), 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x1u), 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x3u), 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x0u) 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = (int)offset; i < DE_LENGTH_OF_ARRAY(indices) && i < (int)(offset + size); i++) 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry coords[i-offset] = indices[i]; 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass CoordVertexShader : public rr::VertexShader 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CoordVertexShader (void) 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : rr::VertexShader(1, 1) 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_inputs[0].type = rr::GENERICVECTYPE_FLOAT; 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_outputs[0].type = rr::GENERICVECTYPE_FLOAT; 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int packetNdx = 0; packetNdx < numPackets; packetNdx++) 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::VertexPacket* const packet = packets[packetNdx]; 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 position; 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry readVertexAttrib(position, inputs[0], packet->instanceNdx, packet->vertexNdx); 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry packet->outputs[0] = tcu::Vec4(1.0f); 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry packet->position = tcu::Vec4(2.0f * (position.x() - 0.5f), 2.0f * (position.y() - 0.5f), 0.0f, 1.0f); 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TextureVertexShader : public rr::VertexShader 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureVertexShader (const tcu::ConstPixelBufferAccess& texture) 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : rr::VertexShader (1, 1) 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_texture (texture) 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_inputs[0].type = rr::GENERICVECTYPE_FLOAT; 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_outputs[0].type = rr::GENERICVECTYPE_FLOAT; 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int packetNdx = 0; packetNdx < numPackets; packetNdx++) 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::VertexPacket* const packet = packets[packetNdx]; 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 position; 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 texelValue; 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry readVertexAttrib(position, inputs[0], packet->instanceNdx, packet->vertexNdx); 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry texelValue = tcu::Vec4(m_texture.getPixel(de::clamp<int>((deRoundFloatToInt32(position.x() * 4) + 4) * (deRoundFloatToInt32(position.y() * 4) + 4), 0, m_texture.getWidth()-1), 0)); 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry packet->outputs[0] = texelValue; 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry packet->position = tcu::Vec4(2.0f * (position.x() - 0.5f), 2.0f * (position.y() - 0.5f), 0.0f, 1.0f); 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::ConstPixelBufferAccess& m_texture; 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass CoordFragmentShader : public rr::FragmentShader 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CoordFragmentShader (void) 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : rr::FragmentShader (1, 1) 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_inputs[0].type = rr::GENERICVECTYPE_FLOAT; 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_outputs[0].type = rr::GENERICVECTYPE_FLOAT; 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int packetNdx = 0; packetNdx < numPackets; packetNdx++) 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::FragmentPacket& packet = packets[packetNdx]; 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vtxColor0 = rr::readVarying<float>(packet, context, 0, 0); 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vtxColor1 = rr::readVarying<float>(packet, context, 0, 1); 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vtxColor2 = rr::readVarying<float>(packet, context, 0, 2); 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vtxColor3 = rr::readVarying<float>(packet, context, 0, 3); 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 color0 = vtxColor0; 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 color1 = vtxColor1; 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 color2 = vtxColor2; 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 color3 = vtxColor3; 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::writeFragmentOutput(context, packetNdx, 0, 0, tcu::Vec4(color0.x() * color0.w(), color0.y() * color0.w(), color0.z() * color0.w(), 1.0f)); 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::writeFragmentOutput(context, packetNdx, 1, 0, tcu::Vec4(color1.x() * color1.w(), color1.y() * color1.w(), color1.z() * color1.w(), 1.0f)); 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::writeFragmentOutput(context, packetNdx, 2, 0, tcu::Vec4(color2.x() * color2.w(), color2.y() * color2.w(), color2.z() * color2.w(), 1.0f)); 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::writeFragmentOutput(context, packetNdx, 3, 0, tcu::Vec4(color3.x() * color3.w(), color3.y() * color3.w(), color3.z() * color3.w(), 1.0f)); 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TextureFragmentShader : public rr::FragmentShader 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureFragmentShader (const tcu::ConstPixelBufferAccess& texture) 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : rr::FragmentShader (1, 1) 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_texture (texture) 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_inputs[0].type = rr::GENERICVECTYPE_FLOAT; 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_outputs[0].type = rr::GENERICVECTYPE_FLOAT; 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int packetNdx = 0; packetNdx < numPackets; packetNdx++) 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::FragmentPacket& packet = packets[packetNdx]; 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec2 position0 = packet.position + tcu::IVec2(0, 0); 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec2 position1 = packet.position + tcu::IVec2(1, 0); 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec2 position2 = packet.position + tcu::IVec2(0, 1); 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec2 position3 = packet.position + tcu::IVec2(1, 1); 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 texColor0 = m_texture.getPixel(de::clamp((position0.x() * position0.y()), 0, m_texture.getWidth()-1), 0); 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 texColor1 = m_texture.getPixel(de::clamp((position1.x() * position1.y()), 0, m_texture.getWidth()-1), 0); 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 texColor2 = m_texture.getPixel(de::clamp((position2.x() * position2.y()), 0, m_texture.getWidth()-1), 0); 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 texColor3 = m_texture.getPixel(de::clamp((position3.x() * position3.y()), 0, m_texture.getWidth()-1), 0); 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vtxColor0 = rr::readVarying<float>(packet, context, 0, 0); 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vtxColor1 = rr::readVarying<float>(packet, context, 0, 1); 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vtxColor2 = rr::readVarying<float>(packet, context, 0, 2); 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vtxColor3 = rr::readVarying<float>(packet, context, 0, 3); 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 color0 = 0.5f * (vtxColor0 + texColor0); 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 color1 = 0.5f * (vtxColor1 + texColor1); 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 color2 = 0.5f * (vtxColor2 + texColor2); 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 color3 = 0.5f * (vtxColor3 + texColor3); 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::writeFragmentOutput(context, packetNdx, 0, 0, tcu::Vec4(color0.x() * color0.w(), color0.y() * color0.w(), color0.z() * color0.w(), 1.0f)); 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::writeFragmentOutput(context, packetNdx, 1, 0, tcu::Vec4(color1.x() * color1.w(), color1.y() * color1.w(), color1.z() * color1.w(), 1.0f)); 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::writeFragmentOutput(context, packetNdx, 2, 0, tcu::Vec4(color2.x() * color2.w(), color2.y() * color2.w(), color2.z() * color2.w(), 1.0f)); 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::writeFragmentOutput(context, packetNdx, 3, 0, tcu::Vec4(color3.x() * color3.w(), color3.y() * color3.w(), color3.z() * color3.w(), 1.0f)); 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::ConstPixelBufferAccess& m_texture; 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystring generateVertexShaderTemplate (RenderBits renderBits) 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::ostringstream stream; 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "${VERSION_HEADER}\n"; 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_VERTEX_TEXTURE) 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "${TEXTURE_BUFFER_EXT}"; 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "${VTX_INPUT} layout(location = 0) ${HIGHP} vec2 i_coord;\n" 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "${VTX_OUTPUT} ${HIGHP} vec4 v_color;\n"; 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_VERTEX_TEXTURE) 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "uniform ${HIGHP} samplerBuffer u_vtxSampler;\n"; 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "\n" 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main (void)\n" 3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n"; 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_VERTEX_TEXTURE) 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "\tv_color = texelFetch(u_vtxSampler, clamp((int(round(i_coord.x * 4.0)) + 4) * (int(round(i_coord.y * 4.0)) + 4), 0, textureSize(u_vtxSampler)-1));\n"; 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "\tv_color = vec4(1.0);\n"; 3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << 3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "\tgl_Position = vec4(2.0 * (i_coord - vec2(0.5)), 0.0, 1.0);\n" 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n"; 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return stream.str(); 3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystring generateFragmentShaderTemplate (RenderBits renderBits) 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::ostringstream stream; 3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << 3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "${VERSION_HEADER}\n"; 3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_FRAGMENT_TEXTURE) 3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "${TEXTURE_BUFFER_EXT}"; 3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << 3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "${FRAG_OUTPUT} layout(location = 0) ${HIGHP} vec4 dEQP_FragColor;\n" 3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "${FRAG_INPUT} ${HIGHP} vec4 v_color;\n"; 3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_FRAGMENT_TEXTURE) 3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "uniform ${HIGHP} samplerBuffer u_fragSampler;\n"; 3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << 3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "\n" 3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main (void)\n" 3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n"; 3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_FRAGMENT_TEXTURE) 3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "\t${HIGHP} vec4 color = 0.5 * (v_color + texelFetch(u_fragSampler, clamp(int(gl_FragCoord.x) * int(gl_FragCoord.y), 0, textureSize(u_fragSampler)-1)));\n"; 3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "\t${HIGHP} vec4 color = v_color;\n"; 3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << 3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "\tdEQP_FragColor = vec4(color.xyz * color.w, 1.0);\n" 3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n"; 3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return stream.str(); 3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystring specializeShader (const string& shaderTemplateString, glu::GLSLVersion glslVersion) 3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::StringTemplate shaderTemplate(shaderTemplateString); 3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry map<string, string> parameters; 3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parameters["VERSION_HEADER"] = glu::getGLSLVersionDeclaration(glslVersion); 3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parameters["VTX_OUTPUT"] = "out"; 3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parameters["VTX_INPUT"] = "in"; 3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parameters["FRAG_INPUT"] = "in"; 3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parameters["FRAG_OUTPUT"] = "out"; 3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parameters["HIGHP"] = (glslVersion == glu::GLSL_VERSION_330 ? "" : "highp"); 3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parameters["TEXTURE_BUFFER_EXT"] = (glslVersion == glu::GLSL_VERSION_330 ? "" : "#extension GL_EXT_texture_buffer : enable\n"); 3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return shaderTemplate.specialize(parameters); 3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyryglu::ShaderProgram* createRenderProgram (glu::RenderContext& renderContext, 3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RenderBits renderBits) 3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const string vertexShaderTemplate = generateVertexShaderTemplate(renderBits); 3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const string fragmentShaderTemplate = generateFragmentShaderTemplate(renderBits); 3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::GLSLVersion glslVersion = glu::getContextTypeGLSLVersion(renderContext.getType()); 3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const string vertexShaderSource = specializeShader(vertexShaderTemplate, glslVersion); 3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const string fragmentShaderSource = specializeShader(fragmentShaderTemplate, glslVersion); 3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram* const program = new glu::ShaderProgram(renderContext, glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource)); 3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return program; 3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid logModifications (TestLog& log, ModifyBits modifyBits) 3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ScopedLogSection section(log, "Modify Operations", "Modify Operations"); 3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const struct 4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ModifyBits bit; 4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* str; 4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } bitInfos[] = 4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { MODIFYBITS_BUFFERDATA, "Recreate buffer data with glBufferData()." }, 4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { MODIFYBITS_BUFFERSUBDATA, "Modify texture buffer with glBufferSubData()." }, 4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { MODIFYBITS_MAPBUFFER_WRITE, "Map buffer write-only and rewrite data." }, 4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { MODIFYBITS_MAPBUFFER_READWRITE, "Map buffer readw-write check and rewrite data." } 4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(modifyBits != 0); 4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int infoNdx = 0; infoNdx < DE_LENGTH_OF_ARRAY(bitInfos); infoNdx++) 4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (modifyBits & bitInfos[infoNdx].bit) 4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << bitInfos[infoNdx].str << TestLog::EndMessage; 4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid modifyBufferData (TestLog& log, 4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random& rng, 4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureBuffer& texture) 4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<deUint8> data; 4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genRandomCoords(rng, data, 0, texture.getBufferSize()); 4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "BufferData, Size: " << data.size() << TestLog::EndMessage; 4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry texture.bufferData(&(data[0]), data.size()); 4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry texture.upload(); 4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid modifyBufferSubData (TestLog& log, 4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random& rng, 4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl, 4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureBuffer& texture) 4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t minSize = 4*16; 441c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry const size_t size = de::max<size_t>(minSize, size_t((float)(texture.getSize() != 0 ? texture.getSize() : texture.getBufferSize()) * (0.7f + 0.3f * rng.getFloat()))); 4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t minOffset = texture.getOffset(); 4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t offset = minOffset + (rng.getUint32() % (texture.getBufferSize() - (size + minOffset))); 4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<deUint8> data; 4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genRandomCoords(rng, data, offset, size); 4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "BufferSubData, Offset: " << offset << ", Size: " << size << TestLog::EndMessage; 4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_TEXTURE_BUFFER, texture.getGLBuffer()); 4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferSubData(GL_TEXTURE_BUFFER, (glw::GLsizei)offset, (glw::GLsizei)data.size(), &(data[0])); 4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_TEXTURE_BUFFER, 0); 4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to update data with glBufferSubData()"); 4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deMemcpy(texture.getRefBuffer() + offset, &(data[0]), int(data.size())); 4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid modifyMapWrite (TestLog& log, 4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random& rng, 4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl, 4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureBuffer& texture) 4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t minSize = 4*16; 464c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry const size_t size = de::max<size_t>(minSize, size_t((float)(texture.getSize() != 0 ? texture.getSize() : texture.getBufferSize()) * (0.7f + 0.3f * rng.getFloat()))); 4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t minOffset = texture.getOffset(); 4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t offset = minOffset + (rng.getUint32() % (texture.getBufferSize() - (size + minOffset))); 4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<deUint8> data; 4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genRandomCoords(rng, data, offset, size); 4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "glMapBufferRange, Write Only, Offset: " << offset << ", Size: " << size << TestLog::EndMessage; 4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_TEXTURE_BUFFER, texture.getGLBuffer()); 4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint8* ptr = (deUint8*)gl.mapBufferRange(GL_TEXTURE_BUFFER, (glw::GLsizei)offset, (glw::GLsizei)size, GL_MAP_WRITE_BIT); 4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glMapBufferRange()"); 4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(ptr); 4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < (int)data.size(); i++) 4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ptr[i] = data[i]; 4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(gl.unmapBuffer(GL_TEXTURE_BUFFER)); 4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_TEXTURE_BUFFER, 0); 4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to update data with glMapBufferRange()"); 4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deMemcpy(texture.getRefBuffer()+offset, &(data[0]), int(data.size())); 4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid modifyMapReadWrite (TestLog& log, 4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ResultCollector& resultCollector, 4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random& rng, 4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl, 4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureBuffer& texture) 4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t minSize = 4*16; 498c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry const size_t size = de::max<size_t>(minSize, size_t((float)(texture.getSize() != 0 ? texture.getSize() : texture.getBufferSize()) * (0.7f + 0.3f * rng.getFloat()))); 4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t minOffset = texture.getOffset(); 5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t offset = minOffset + (rng.getUint32() % (texture.getBufferSize() - (size + minOffset))); 5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<deUint8> data; 5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genRandomCoords(rng, data, offset, size); 5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "glMapBufferRange, Read Write, Offset: " << offset << ", Size: " << size << TestLog::EndMessage; 5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_TEXTURE_BUFFER, texture.getGLBuffer()); 5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t invalidBytes = 0; 5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint8* const ptr = (deUint8*)gl.mapBufferRange(GL_TEXTURE_BUFFER, (glw::GLsizei)offset, (glw::GLsizei)size, GL_MAP_WRITE_BIT|GL_MAP_READ_BIT); 5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glMapBufferRange()"); 5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(ptr); 5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < (int)data.size(); i++) 5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (ptr[i] != texture.getRefBuffer()[offset+i]) 5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (invalidBytes < 24) 5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "Invalid byte in mapped buffer. " << tcu::Format::Hex<2>(data[i]).toString() << " at " << i << ", expected " << tcu::Format::Hex<2>(texture.getRefBuffer()[i]).toString() << TestLog::EndMessage; 5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry invalidBytes++; 5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ptr[i] = data[i]; 5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(gl.unmapBuffer(GL_TEXTURE_BUFFER)); 5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (invalidBytes > 0) 5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "Total of " << invalidBytes << " invalid bytes." << TestLog::EndMessage; 5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry resultCollector.fail("Invalid data in mapped buffer"); 5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_TEXTURE_BUFFER, 0); 5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to update data with glMapBufferRange()"); 5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < (int)data.size(); i++) 5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry texture.getRefBuffer()[offset+i] = data[i]; 5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid modify (TestLog& log, 5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ResultCollector& resultCollector, 5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::RenderContext& renderContext, 5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ModifyBits modifyBits, 5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random& rng, 5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureBuffer& texture) 5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::ScopedLogSection modifySection(log, "Modifying Texture buffer", "Modifying Texture Buffer"); 5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry logModifications(log, modifyBits); 5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (modifyBits & MODIFYBITS_BUFFERDATA) 5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry modifyBufferData(log, rng, texture); 5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (modifyBits & MODIFYBITS_BUFFERSUBDATA) 5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry modifyBufferSubData(log, rng, renderContext.getFunctions(), texture); 5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (modifyBits & MODIFYBITS_MAPBUFFER_WRITE) 5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry modifyMapWrite(log, rng, renderContext.getFunctions(), texture); 5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (modifyBits & MODIFYBITS_MAPBUFFER_READWRITE) 5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry modifyMapReadWrite(log, resultCollector, rng, renderContext.getFunctions(), texture); 5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid renderGL (glu::RenderContext& renderContext, 5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RenderBits renderBits, 5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 coordSeed, 5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int triangleCount, 5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram& program, 5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureBuffer& texture) 5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = renderContext.getFunctions(); 5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::VertexArray vao (renderContext); 5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::Buffer coordBuffer (renderContext); 5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram(program.getProgram()); 5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindVertexArray(*vao); 5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.enableVertexAttribArray(0); 5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_VERTEX_ARRAY) 5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ARRAY_BUFFER, texture.getGLBuffer()); 5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.vertexAttribPointer(0, 2, GL_UNSIGNED_BYTE, true, 0, DE_NULL); 5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random rng(coordSeed); 5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<deUint8> coords; 5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genRandomCoords(rng, coords, 0, 256*2); 5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ARRAY_BUFFER, *coordBuffer); 5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizei)coords.size(), &(coords[0]), GL_STREAM_DRAW); 5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.vertexAttribPointer(0, 2, GL_UNSIGNED_BYTE, true, 0, DE_NULL); 5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_VERTEX_TEXTURE) 6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deInt32 location = gl.getUniformLocation(program.getProgram(), "u_vtxSampler"); 6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.activeTexture(GL_TEXTURE0); 6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_BUFFER, texture.getGLTexture()); 6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.uniform1i(location, 0); 6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_FRAGMENT_TEXTURE) 6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deInt32 location = gl.getUniformLocation(program.getProgram(), "u_fragSampler"); 6133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.activeTexture(GL_TEXTURE1); 6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_BUFFER, texture.getGLTexture()); 6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.uniform1i(location, 1); 6173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.activeTexture(GL_TEXTURE0); 6183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_INDEX_ARRAY) 6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, texture.getGLBuffer()); 6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.drawElements(GL_TRIANGLES, triangleCount * 3, GL_UNSIGNED_BYTE, DE_NULL); 6243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 6273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.drawArrays(GL_TRIANGLES, 0, triangleCount * 3); 6283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_FRAGMENT_TEXTURE) 6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.activeTexture(GL_TEXTURE1); 6323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_BUFFER, 0); 6333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_VERTEX_TEXTURE) 6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.activeTexture(GL_TEXTURE0); 6383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_BUFFER, 0); 6393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ARRAY_BUFFER, 0); 6423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.disableVertexAttribArray(0); 6433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindVertexArray(0); 6453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram(0); 6463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Rendering failed"); 6473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid renderReference (RenderBits renderBits, 6503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 coordSeed, 6513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int triangleCount, 6523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureBuffer& texture, 6533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::PixelBufferAccess& target) 6543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const CoordVertexShader coordVertexShader; 6563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const TextureVertexShader textureVertexShader (texture.getRefTexture()); 6573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const rr::VertexShader* const vertexShader = (renderBits & RENDERBITS_AS_VERTEX_TEXTURE ? static_cast<const rr::VertexShader*>(&textureVertexShader) : &coordVertexShader); 6583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const CoordFragmentShader coordFragmmentShader; 6603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const TextureFragmentShader textureFragmentShader (texture.getRefTexture()); 6613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const rr::FragmentShader* const fragmentShader = (renderBits & RENDERBITS_AS_FRAGMENT_TEXTURE ? static_cast<const rr::FragmentShader*>(&textureFragmentShader) : &coordFragmmentShader); 6623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const rr::Renderer renderer; 6643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const rr::RenderState renderState(rr::ViewportState(rr::WindowRectangle(0, 0, target.getWidth(), target.getHeight()))); 6653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const rr::RenderTarget renderTarget(rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(target)); 6663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const rr::Program program(vertexShader, fragmentShader); 6683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::VertexAttrib vertexAttribs[1]; 6703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<deUint8> coords; 6713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_VERTEX_ARRAY) 6733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vertexAttribs[0].type = rr::VERTEXATTRIBTYPE_NONPURE_UNORM8; 6753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vertexAttribs[0].size = 2; 6763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vertexAttribs[0].pointer = texture.getRefBuffer(); 6773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 6793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random rng(coordSeed); 6813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genRandomCoords(rng, coords, 0, 256*2); 6833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vertexAttribs[0].type = rr::VERTEXATTRIBTYPE_NONPURE_UNORM8; 6853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vertexAttribs[0].size = 2; 6863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vertexAttribs[0].pointer = &(coords[0]); 6873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_INDEX_ARRAY) 6903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const rr::PrimitiveList primitives(rr::PRIMITIVETYPE_TRIANGLES, triangleCount * 3, rr::DrawIndices((const void*)texture.getRefBuffer(), rr::INDEXTYPE_UINT8)); 6923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const rr::DrawCommand cmd(renderState, renderTarget, program, 1, vertexAttribs, primitives); 6933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderer.draw(cmd); 6953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 6973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const rr::PrimitiveList primitives(rr::PRIMITIVETYPE_TRIANGLES, triangleCount * 3, 0); 6993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const rr::DrawCommand cmd(renderState, renderTarget, program, 1, vertexAttribs, primitives); 7003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderer.draw(cmd); 7023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7053c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid logRendering (TestLog& log, RenderBits renderBits) 7063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const struct 7083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RenderBits bit; 7103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* str; 7113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } bitInfos[] = 7123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { RENDERBITS_AS_VERTEX_ARRAY, "vertex array" }, 7143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { RENDERBITS_AS_INDEX_ARRAY, "index array" }, 7153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { RENDERBITS_AS_VERTEX_TEXTURE, "vertex texture" }, 7163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { RENDERBITS_AS_FRAGMENT_TEXTURE, "fragment texture" } 7173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 7183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::ostringstream stream; 7203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<const char*> usedAs; 7213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(renderBits != 0); 7233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int infoNdx = 0; infoNdx < DE_LENGTH_OF_ARRAY(bitInfos); infoNdx++) 7253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & bitInfos[infoNdx].bit) 7273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry usedAs.push_back(bitInfos[infoNdx].str); 7283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "Render using texture buffer as "; 7313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int asNdx = 0; asNdx < (int)usedAs.size(); asNdx++) 7333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (asNdx+1 == (int)usedAs.size() && (int)usedAs.size() > 1) 7353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << " and "; 7363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (asNdx > 0) 7373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << ", "; 7383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << usedAs[asNdx]; 7403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "."; 7433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << stream.str() << TestLog::EndMessage; 7453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid render (TestLog& log, 7483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::RenderContext& renderContext, 7493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RenderBits renderBits, 7503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random& rng, 7513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram& program, 7523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureBuffer& texture, 7533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::PixelBufferAccess& target) 7543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::ScopedLogSection renderSection (log, "Render Texture buffer", "Render Texture Buffer"); 7563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int triangleCount = 8; 7573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 coordSeed = rng.getUint32(); 7583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry logRendering(log, renderBits); 7603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderGL(renderContext, renderBits, coordSeed, triangleCount, program, texture); 7623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderReference(renderBits, coordSeed, triangleCount, texture, target); 7633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7653c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid verifyScreen (TestLog& log, 7663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ResultCollector& resultCollector, 7673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::RenderContext& renderContext, 7683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::ConstPixelBufferAccess& referenceTarget) 7693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::ScopedLogSection verifySection (log, "Verify screen contents", "Verify screen contents"); 7713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface screen (referenceTarget.getWidth(), referenceTarget.getHeight()); 7723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::readPixels(renderContext, 0, 0, screen.getAccess()); 7743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!tcu::fuzzyCompare(log, "Result of rendering", "Result of rendering", referenceTarget, screen.getAccess(), 0.05f, tcu::COMPARE_LOG_RESULT)) 7763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry resultCollector.fail("Rendering failed"); 7773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7793c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid logImplementationInfo (TestLog& log, glu::RenderContext& renderContext) 7803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::ScopedLogSection section (log, "Implementation Values", "Implementation Values"); 7823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::UniquePtr<glu::ContextInfo> info (glu::ContextInfo::create(renderContext)); 7833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = renderContext.getFunctions(); 7843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (glu::contextSupports(renderContext.getType(), glu::ApiType(3, 3, glu::PROFILE_CORE))) 7863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7877a2ea3f817e3acb0bcdc4d5e66e714d541bd648fJarkko Pöyry deInt32 maxTextureSize = 0; 7883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.getIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &maxTextureSize); 7903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE)"); 7913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "GL_MAX_TEXTURE_BUFFER_SIZE : " << maxTextureSize << TestLog::EndMessage; 7933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (glu::contextSupports(renderContext.getType(), glu::ApiType(3, 1, glu::PROFILE_ES)) && info->isExtensionSupported("GL_EXT_texture_buffer")) 7953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7977a2ea3f817e3acb0bcdc4d5e66e714d541bd648fJarkko Pöyry deInt32 maxTextureSize = 0; 7983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.getIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &maxTextureSize); 8003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE_EXT)"); 8013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "GL_MAX_TEXTURE_BUFFER_SIZE_EXT : " << maxTextureSize << TestLog::EndMessage; 8033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8067a2ea3f817e3acb0bcdc4d5e66e714d541bd648fJarkko Pöyry deInt32 textureBufferAlignment = 0; 8073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.getIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &textureBufferAlignment); 8093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT_EXT)"); 8103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT_EXT : " << textureBufferAlignment << TestLog::EndMessage; 8123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 8153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(DE_FALSE); 8163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 8173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8183c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid logTextureInfo (TestLog& log, 8193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 format, 8203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t bufferSize, 8213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t offset, 8223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t size) 8233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 8243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::ScopedLogSection section(log, "Texture Info", "Texture Info"); 8253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "Texture format : " << glu::getPixelFormatStr(format) << TestLog::EndMessage; 8273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "Buffer size : " << bufferSize << TestLog::EndMessage; 8283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (offset != 0 || size != 0) 8303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "Buffer range offset: " << offset << TestLog::EndMessage; 8323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "Buffer range size: " << size << TestLog::EndMessage; 8333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 8353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid runTests (tcu::TestContext& testCtx, 8373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::RenderContext& renderContext, 8383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random& rng, 8393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 format, 8403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t bufferSize, 8413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t offset, 8423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t size, 8433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RenderBits preRender, 8443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram* preRenderProgram, 8453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ModifyBits modifyType, 8463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RenderBits postRender, 8473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram* postRenderProgram) 8483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 8493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::RenderTarget renderTarget (renderContext.getRenderTarget()); 8503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = renderContext.getFunctions(); 8513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int width = de::min<int>(renderTarget.getWidth(), MAX_VIEWPORT_WIDTH); 8533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int height = de::min<int>(renderTarget.getHeight(), MAX_VIEWPORT_HEIGHT); 8543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 clearColor (0.25f, 0.5f, 0.75f, 1.0f); 8553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestLog& log = testCtx.getLog(); 8573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ResultCollector resultCollector (log); 8583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry logImplementationInfo(log, renderContext); 8603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry logTextureInfo(log, format, bufferSize, offset, size); 8613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface referenceTarget (width, height); 8643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<deUint8> bufferData; 8653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genRandomCoords(rng, bufferData, 0, bufferSize); 8673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (deUint8 i = 0; i < 4; i++) 8693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint8 val = extend2BitsToByte(i); 8713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (val >= offset && val < offset + size) 8733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bufferData[val*2 + 0] = (i / 2 == 0 ? extend2BitsToByte(0x2u) : extend2BitsToByte(0x01u)); 8753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bufferData[val*2 + 1] = (i % 2 == 0 ? extend2BitsToByte(0x2u) : extend2BitsToByte(0x01u)); 8763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureBuffer texture (renderContext, format, bufferSize, offset, size, &(bufferData[0])); 8813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK_MSG(width >= MIN_VIEWPORT_WIDTH || height >= MIN_VIEWPORT_HEIGHT, "Too small viewport"); 8833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(preRender == 0 || preRenderProgram); 8853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(postRender == 0 || postRenderProgram); 8863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.viewport(0, 0, width, height); 8883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w()); 8893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clear(GL_COLOR_BUFFER_BIT); 8903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Screen setup failed"); 8913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::clear(referenceTarget.getAccess(), clearColor); 8933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry texture.upload(); 8953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (preRender != 0) 8973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry render(log, renderContext, preRender, rng, *preRenderProgram, texture, referenceTarget.getAccess()); 8983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (modifyType != 0) 9003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry modify(log, resultCollector, renderContext, modifyType, rng, texture); 9013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (postRender != 0) 9033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry render(log, renderContext, postRender, rng, *postRenderProgram, texture, referenceTarget.getAccess()); 9043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry verifyScreen(log, resultCollector, renderContext, referenceTarget.getAccess()); 9073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry resultCollector.setTestContextResult(testCtx); 9093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 9113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // anonymous 9133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9143c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureBufferCase::TextureBufferCase (tcu::TestContext& testCtx, 9153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::RenderContext& renderCtx, 9163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 format, 9173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t bufferSize, 9183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t offset, 9193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t size, 9203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RenderBits preRender, 9213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ModifyBits modify, 9223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RenderBits postRender, 9233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* name, 9243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* description) 9253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : tcu::TestCase (testCtx, name, description) 9263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_renderCtx (renderCtx) 9273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (format) 9283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_bufferSize (bufferSize) 9293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_offset (offset) 9303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_size (size) 9313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_preRender (preRender) 9333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_modify (modify) 9343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_postRender (postRender) 9353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_preRenderProgram (DE_NULL) 9373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_postRenderProgram (DE_NULL) 9383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 9393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 9403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9413c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureBufferCase::~TextureBufferCase (void) 9423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 9433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureBufferCase::deinit(); 9443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 9453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureBufferCase::init (void) 9473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 9483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::UniquePtr<glu::ContextInfo> info (glu::ContextInfo::create(m_renderCtx)); 9493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!glu::contextSupports(m_renderCtx.getType(), glu::ApiType(3, 3, glu::PROFILE_CORE)) 9513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry && !(glu::contextSupports(m_renderCtx.getType(), glu::ApiType(3, 1, glu::PROFILE_ES)) && info->isExtensionSupported("GL_EXT_texture_buffer"))) 9523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("Texture buffers not supported", "", __FILE__, __LINE__); 9533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_preRender != 0) 9553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestLog& log = m_testCtx.getLog(); 9573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* const sectionName = (m_postRender != 0 ? "Primary render program" : "Render program"); 9583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::ScopedLogSection section (log, sectionName, sectionName); 9593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_preRenderProgram = createRenderProgram(m_renderCtx, m_preRender); 9613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << (*m_preRenderProgram); 9623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(m_preRenderProgram->isOk()); 9643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_postRender != 0) 9673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Reusing program 9693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_preRender == m_postRender) 9703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_postRenderProgram = m_preRenderProgram; 9723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 9743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestLog& log = m_testCtx.getLog(); 9763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* const sectionName = (m_preRender!= 0 ? "Secondary render program" : "Render program"); 9773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::ScopedLogSection section (log, sectionName, sectionName); 9783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_postRenderProgram = createRenderProgram(m_renderCtx, m_postRender); 9803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << (*m_postRenderProgram); 9813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(m_postRenderProgram->isOk()); 9833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 9863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9873c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureBufferCase::deinit (void) 9883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 9893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_preRenderProgram == m_postRenderProgram) 9903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_postRenderProgram = DE_NULL; 9913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_preRenderProgram; 9933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_preRenderProgram = DE_NULL; 9943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_postRenderProgram; 9963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_postRenderProgram = DE_NULL; 9973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 9983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9993c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::TestCase::IterateResult TextureBufferCase::iterate (void) 10003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 10013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random rng (deInt32Hash(deStringHash(getName()))); 10023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t offset; 10033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_offset != 0) 10053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 10063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_renderCtx.getFunctions(); 10073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deInt32 alignment = 0; 10083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.getIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &alignment); 10103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT)"); 10113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry offset = m_offset * alignment; 10133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 10143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 10153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry offset = 0; 10163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry runTests(m_testCtx, m_renderCtx, rng, m_format, m_bufferSize, offset, m_size, m_preRender, m_preRenderProgram, m_modify, m_postRender, m_postRenderProgram); 10183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 10203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 10213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gls 10233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp 1024