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