13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES 3.0 Module
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * -------------------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief FBO test utilities.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es3fFboTestUtil.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "sglrContextUtil.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "sglrGLContext.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "sglrReferenceContext.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTextureUtil.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMath.h"
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp"
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp"
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <limits>
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles3
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace FboTestUtil
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string;
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector;
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec2;
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec3;
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec4;
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::IVec2;
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::IVec3;
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::IVec4;
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic rr::GenericVecType mapDataTypeToGenericVecType(glu::DataType type)
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (type)
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case glu::TYPE_FLOAT_VEC4:	return rr::GENERICVECTYPE_FLOAT;
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case glu::TYPE_INT_VEC4:	return rr::GENERICVECTYPE_INT32;
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case glu::TYPE_UINT_VEC4:	return rr::GENERICVECTYPE_UINT32;
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(DE_FALSE);
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return rr::GENERICVECTYPE_LAST;
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T>
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic tcu::Vector<T, 4> castVectorSaturate (const tcu::Vec4& in)
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return tcu::Vector<T, 4>((in.x() + 0.5f >= std::numeric_limits<T>::max()) ? (std::numeric_limits<T>::max()) : ((in.x() - 0.5f <= std::numeric_limits<T>::min()) ? (std::numeric_limits<T>::min()) : (T(in.x()))),
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	                         (in.y() + 0.5f >= std::numeric_limits<T>::max()) ? (std::numeric_limits<T>::max()) : ((in.y() - 0.5f <= std::numeric_limits<T>::min()) ? (std::numeric_limits<T>::min()) : (T(in.y()))),
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							 (in.z() + 0.5f >= std::numeric_limits<T>::max()) ? (std::numeric_limits<T>::max()) : ((in.z() - 0.5f <= std::numeric_limits<T>::min()) ? (std::numeric_limits<T>::min()) : (T(in.z()))),
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							 (in.w() + 0.5f >= std::numeric_limits<T>::max()) ? (std::numeric_limits<T>::max()) : ((in.w() - 0.5f <= std::numeric_limits<T>::min()) ? (std::numeric_limits<T>::min()) : (T(in.w()))));
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
773c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFlatColorShader::FlatColorShader (glu::DataType outputType)
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::FragmentOutput(mapDataTypeToGenericVecType(outputType))
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::Uniform("u_color", glu::TYPE_FLOAT_VEC4)
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::VertexSource(
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"#version 300 es\n"
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"in highp vec4 a_position;\n"
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"void main (void)\n"
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"{\n"
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"	gl_Position = a_position;\n"
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"}\n")
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::FragmentSource(
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							string(
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"#version 300 es\n"
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"uniform highp vec4 u_color;\n"
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"layout(location = 0) out highp ") + glu::getDataTypeName(outputType) + " o_color;\n"
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"void main (void)\n"
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"{\n"
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"	o_color = " + glu::getDataTypeName(outputType) + "(u_color);\n"
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"}\n"))
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_outputType(outputType)
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid FlatColorShader::setColor (sglr::Context& context, deUint32 program, const tcu::Vec4& color)
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deInt32 location = context.getUniformLocation(program, "u_color");
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.useProgram(program);
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.uniform4fv(location, 1, color.getPtr());
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid FlatColorShader::shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		rr::VertexPacket& packet = *packets[packetNdx];
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		packet.position = rr::readVertexAttribFloat(inputs[0], packet.instanceNdx, packet.vertexNdx);
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid FlatColorShader::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Vec4		color	(m_uniforms[0].value.f4);
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::IVec4	icolor	= castVectorSaturate<deInt32>(color);
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::UVec4	uicolor	= castVectorSaturate<deUint32>(color);
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(packets);
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_outputType == glu::TYPE_FLOAT_VEC4)
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, color);
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_outputType == glu::TYPE_INT_VEC4)
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, icolor);
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_outputType == glu::TYPE_UINT_VEC4)
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, uicolor);
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(DE_FALSE);
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1513c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGradientShader::GradientShader (glu::DataType outputType)
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::VertexAttribute("a_coord", rr::GENERICVECTYPE_FLOAT)
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::FragmentOutput(mapDataTypeToGenericVecType(outputType))
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::Uniform("u_gradientMin", glu::TYPE_FLOAT_VEC4)
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::Uniform("u_gradientMax", glu::TYPE_FLOAT_VEC4)
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::VertexSource(
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"#version 300 es\n"
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"in highp vec4 a_position;\n"
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"in highp vec4 a_coord;\n"
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"out highp vec4 v_coord;\n"
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"void main (void)\n"
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"{\n"
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"	gl_Position = a_position;\n"
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"	v_coord = a_coord;\n"
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"}\n")
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::FragmentSource(
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							string(
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"#version 300 es\n"
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"in highp vec4 v_coord;\n"
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"uniform highp vec4 u_gradientMin;\n"
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"uniform highp vec4 u_gradientMax;\n"
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"layout(location = 0) out highp ") + glu::getDataTypeName(outputType) + " o_color;\n"
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"void main (void)\n"
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"{\n"
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"	highp float x = v_coord.x;\n"
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"	highp float y = v_coord.y;\n"
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"	highp float f0 = (x + y) * 0.5;\n"
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"	highp float f1 = 0.5 + (x - y) * 0.5;\n"
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"	highp vec4 fv = vec4(f0, f1, 1.0f-f0, 1.0f-f1);\n"
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"	o_color = " + glu::getDataTypeName(outputType) + "(u_gradientMin + (u_gradientMax-u_gradientMin)*fv);\n"
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"}\n"))
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_outputType(outputType)
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid GradientShader::setGradient (sglr::Context& ctx, deUint32 program, const tcu::Vec4& gradientMin, const tcu::Vec4& gradientMax)
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.useProgram(program);
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.uniform4fv(ctx.getUniformLocation(program, "u_gradientMin"), 1, gradientMin.getPtr());
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.uniform4fv(ctx.getUniformLocation(program, "u_gradientMax"), 1, gradientMax.getPtr());
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid GradientShader::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& packet = *packets[packetNdx];
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		packet.position		= rr::readVertexAttribFloat(inputs[0], packet.instanceNdx, packet.vertexNdx);
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		packet.outputs[0]	= rr::readVertexAttribFloat(inputs[1], packet.instanceNdx, packet.vertexNdx);
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid GradientShader::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Vec4	gradientMin(m_uniforms[0].value.f4);
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Vec4	gradientMax(m_uniforms[1].value.f4);
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::Vec4		coord	= rr::readTriangleVarying<float>(packets[packetNdx], context, 0, fragNdx);
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float			x		= coord.x();
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float			y		= coord.y();
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float			f0		= (x + y) * 0.5f;
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float			f1		= 0.5f + (x - y) * 0.5f;
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::Vec4		fv		= Vec4(f0, f1, 1.0f-f0, 1.0f-f1);
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::Vec4		color	= gradientMin + (gradientMax-gradientMin) * fv;
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::IVec4	icolor	= castVectorSaturate<deInt32>(color);
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::UVec4	uicolor	= castVectorSaturate<deUint32>(color);
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_outputType == glu::TYPE_FLOAT_VEC4)			rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, color);
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_outputType == glu::TYPE_INT_VEC4)		rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, icolor);
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_outputType == glu::TYPE_UINT_VEC4)		rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, uicolor);
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(DE_FALSE);
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic string genTexFragmentShader (const vector<glu::DataType>& samplerTypes, glu::DataType outputType)
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*			precision	= "highp";
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::ostringstream	src;
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	src << "#version 300 es\n"
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "layout(location = 0) out highp " << glu::getDataTypeName(outputType) << " o_color0;\n";
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	src << "in highp vec2 v_coord;\n";
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int samplerNdx = 0; samplerNdx < (int)samplerTypes.size(); samplerNdx++)
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		src << "uniform " << precision << " " << glu::getDataTypeName(samplerTypes[samplerNdx]) << " u_sampler" << samplerNdx << ";\n";
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		src << "uniform " << precision << " vec4 u_texScale" << samplerNdx << ";\n";
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		src << "uniform " << precision << " vec4 u_texBias" << samplerNdx << ";\n";
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Output scale & bias
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	src << "uniform " << precision << " vec4 u_outScale0;\n"
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "uniform " << precision << " vec4 u_outBias0;\n";
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	src << "\n"
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "void main (void)\n"
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "{\n"
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "	" << precision << " vec4 out0 = vec4(0.0);\n";
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Texture input fetch and combine.
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int inNdx = 0; inNdx < (int)samplerTypes.size(); inNdx++)
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		src << "\tout0 += vec4("
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "texture(u_sampler" << inNdx << ", v_coord)) * u_texScale" << inNdx << " + u_texBias" << inNdx << ";\n";
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Write output.
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	src << "	o_color0 = " << glu::getDataTypeName(outputType) << "(out0 * u_outScale0 + u_outBias0);\n";
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	src << "}\n";
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return src.str();
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic sglr::pdec::ShaderProgramDeclaration genTexture2DShaderDecl (const DataTypes& samplerTypes, glu::DataType outputType)
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::pdec::ShaderProgramDeclaration decl;
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	decl << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT);
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	decl << sglr::pdec::VertexAttribute("a_coord", rr::GENERICVECTYPE_FLOAT);
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	decl << sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT);
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	decl << sglr::pdec::FragmentOutput(mapDataTypeToGenericVecType(outputType));
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	decl << sglr::pdec::VertexSource(
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"#version 300 es\n"
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"in highp vec4 a_position;\n"
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"in highp vec2 a_coord;\n"
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"out highp vec2 v_coord;\n"
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"void main(void)\n"
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"{\n"
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"	gl_Position = a_position;\n"
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"	v_coord = a_coord;\n"
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"}\n");
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	decl << sglr::pdec::FragmentSource(genTexFragmentShader(samplerTypes.vec, outputType));
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	decl << sglr::pdec::Uniform("u_outScale0", glu::TYPE_FLOAT_VEC4);
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	decl << sglr::pdec::Uniform("u_outBias0", glu::TYPE_FLOAT_VEC4);
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (size_t ndx = 0; ndx < samplerTypes.vec.size(); ++ndx)
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		decl << sglr::pdec::Uniform(std::string("u_sampler")  + de::toString(ndx), samplerTypes.vec[ndx]);
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		decl << sglr::pdec::Uniform(std::string("u_texScale") + de::toString(ndx), glu::TYPE_FLOAT_VEC4);
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		decl << sglr::pdec::Uniform(std::string("u_texBias")  + de::toString(ndx), glu::TYPE_FLOAT_VEC4);
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return decl;
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3073c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2DShader::Texture2DShader (const DataTypes& samplerTypes, glu::DataType outputType, const Vec4& outScale, const Vec4& outBias)
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: sglr::ShaderProgram	(genTexture2DShaderDecl(samplerTypes, outputType))
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_outScale			(outScale)
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_outBias				(outBias)
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_outputType			(outputType)
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_inputs.resize(samplerTypes.vec.size());
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Initialize units.
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < (int)m_inputs.size(); ndx++)
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_inputs[ndx].unitNdx	= ndx;
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_inputs[ndx].scale		= Vec4(1.0f);
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_inputs[ndx].bias		= Vec4(0.0f);
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DShader::setUnit (int inputNdx, int unitNdx)
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_inputs[inputNdx].unitNdx = unitNdx;
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DShader::setTexScaleBias (int inputNdx, const Vec4& scale, const Vec4& bias)
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_inputs[inputNdx].scale	= scale;
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_inputs[inputNdx].bias		= bias;
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DShader::setOutScaleBias (const Vec4& scale, const Vec4& bias)
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_outScale	= scale;
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_outBias	= bias;
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DShader::setUniforms (sglr::Context& gl, deUint32 program) const
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.useProgram(program);
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int texNdx = 0; texNdx < (int)m_inputs.size(); texNdx++)
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		string	samplerName	= string("u_sampler") + de::toString(texNdx);
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		string	scaleName	= string("u_texScale") + de::toString(texNdx);
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		string	biasName	= string("u_texBias") + de::toString(texNdx);
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.uniform1i(gl.getUniformLocation(program, samplerName.c_str()), m_inputs[texNdx].unitNdx);
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.uniform4fv(gl.getUniformLocation(program, scaleName.c_str()), 1, m_inputs[texNdx].scale.getPtr());
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.uniform4fv(gl.getUniformLocation(program, biasName.c_str()), 1, m_inputs[texNdx].bias.getPtr());
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniform4fv(gl.getUniformLocation(program, "u_outScale0"), 1, m_outScale.getPtr());
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniform4fv(gl.getUniformLocation(program, "u_outBias0"), 1, m_outBias.getPtr());
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DShader::shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		rr::VertexPacket& packet = *packets[packetNdx];
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		packet.position		= rr::readVertexAttribFloat(inputs[0], packet.instanceNdx, packet.vertexNdx);
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		packet.outputs[0]	= rr::readVertexAttribFloat(inputs[1], packet.instanceNdx, packet.vertexNdx);
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DShader::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Vec4 outScale (m_uniforms[0].value.f4);
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Vec4 outBias	 (m_uniforms[1].value.f4);
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Vec2 texCoords[4];
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Vec4 colors[4];
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// setup tex coords
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::Vec4	coord = rr::readTriangleVarying<float>(packets[packetNdx], context, 0, fragNdx);
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			texCoords[fragNdx] = tcu::Vec2(coord.x(), coord.y());
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// clear result
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			colors[fragNdx] = tcu::Vec4(0.0f);
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// sample each texture
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int ndx = 0; ndx < (int)m_inputs.size(); ndx++)
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const sglr::rc::Texture2D*	tex		= m_uniforms[2 + ndx*3].sampler.tex2D;
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::Vec4				scale	(m_uniforms[2 + ndx*3 + 1].value.f4);
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::Vec4				bias	(m_uniforms[2 + ndx*3 + 2].value.f4);
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::Vec4 tmpColors[4];
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tex->sample4(tmpColors, texCoords);
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				colors[fragNdx] += tmpColors[fragNdx] * scale + bias;
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// write out
4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::Vec4		color	= colors[fragNdx] * outScale + outBias;
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::IVec4	icolor	= castVectorSaturate<deInt32>(color);
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::UVec4	uicolor	= castVectorSaturate<deUint32>(color);
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (m_outputType == glu::TYPE_FLOAT_VEC4)			rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, color);
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else if (m_outputType == glu::TYPE_INT_VEC4)		rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, icolor);
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else if (m_outputType == glu::TYPE_UINT_VEC4)		rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, uicolor);
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				DE_ASSERT(DE_FALSE);
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4223c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCubeShader::TextureCubeShader (glu::DataType samplerType, glu::DataType outputType)
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: sglr::ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::VertexAttribute("a_coord", rr::GENERICVECTYPE_FLOAT)
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::FragmentOutput(mapDataTypeToGenericVecType(outputType))
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::Uniform("u_coordMat", glu::TYPE_FLOAT_MAT3)
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::Uniform("u_sampler0", samplerType)
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::Uniform("u_scale", glu::TYPE_FLOAT_VEC4)
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::Uniform("u_bias", glu::TYPE_FLOAT_VEC4)
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::VertexSource(
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"#version 300 es\n"
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"in highp vec4 a_position;\n"
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"in mediump vec2 a_coord;\n"
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"uniform mat3 u_coordMat;\n"
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"out mediump vec3 v_coord;\n"
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"void main (void)\n"
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"{\n"
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"	gl_Position = a_position;\n"
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"	v_coord = u_coordMat * vec3(a_coord, 1.0);\n"
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"}\n")
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::FragmentSource(
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									string("") +
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"#version 300 es\n"
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"uniform highp " + glu::getDataTypeName(samplerType) + " u_sampler0;\n"
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"uniform highp vec4 u_scale;\n"
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"uniform highp vec4 u_bias;\n"
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"in mediump vec3 v_coord;\n"
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"layout(location = 0) out highp " + glu::getDataTypeName(outputType) + " o_color;\n"
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"void main (void)\n"
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"{\n"
4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"	o_color = " + glu::getDataTypeName(outputType) + "(vec4(texture(u_sampler0, v_coord)) * u_scale + u_bias);\n"
4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"}\n"))
4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_texScale	(1.0f)
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_texBias		(0.0f)
4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_outputType	(outputType)
4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureCubeShader::setFace (tcu::CubeFace face)
4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const float s_cubeTransforms[][3*3] =
4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Face -X: (x, y, 1) -> (-1, -(2*y-1), +(2*x-1))
4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{  0.0f,  0.0f, -1.0f,
4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   0.0f, -2.0f,  1.0f,
4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   2.0f,  0.0f, -1.0f },
4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Face +X: (x, y, 1) -> (+1, -(2*y-1), -(2*x-1))
4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{  0.0f,  0.0f,  1.0f,
4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   0.0f, -2.0f,  1.0f,
4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  -2.0f,  0.0f,  1.0f },
4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Face -Y: (x, y, 1) -> (+(2*x-1), -1, -(2*y-1))
4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{  2.0f,  0.0f, -1.0f,
4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   0.0f,  0.0f, -1.0f,
4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   0.0f, -2.0f,  1.0f },
4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Face +Y: (x, y, 1) -> (+(2*x-1), +1, +(2*y-1))
4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{  2.0f,  0.0f, -1.0f,
4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   0.0f,  0.0f,  1.0f,
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   0.0f,  2.0f, -1.0f },
4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Face -Z: (x, y, 1) -> (-(2*x-1), -(2*y-1), -1)
4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ -2.0f,  0.0f,  1.0f,
4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   0.0f, -2.0f,  1.0f,
4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   0.0f,  0.0f, -1.0f },
4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Face +Z: (x, y, 1) -> (+(2*x-1), -(2*y-1), +1)
4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{  2.0f,  0.0f, -1.0f,
4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   0.0f, -2.0f,  1.0f,
4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   0.0f,  0.0f,  1.0f }
4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(de::inBounds<int>(face, 0, tcu::CUBEFACE_LAST));
4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_coordMat = tcu::Mat3(s_cubeTransforms[face]);
4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureCubeShader::setTexScaleBias (const Vec4& scale, const Vec4& bias)
4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_texScale	= scale;
4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_texBias	= bias;
4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureCubeShader::setUniforms (sglr::Context& gl, deUint32 program) const
5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.useProgram(program);
5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniform1i(gl.getUniformLocation(program, "u_sampler0"), 0);
5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniformMatrix3fv(gl.getUniformLocation(program, "u_coordMat"), 1, GL_FALSE, m_coordMat.getColumnMajorData().getPtr());
5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniform4fv(gl.getUniformLocation(program, "u_scale"), 1, m_texScale.getPtr());
5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniform4fv(gl.getUniformLocation(program, "u_bias"), 1, m_texBias.getPtr());
5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureCubeShader::shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Mat3 texCoordMat = tcu::Mat3(m_uniforms[0].value.m3);
5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		rr::VertexPacket&	packet	= *packets[packetNdx];
5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec2			a_coord = rr::readVertexAttribFloat(inputs[1], packet.instanceNdx, packet.vertexNdx).xy();
5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec3			v_coord = texCoordMat * tcu::Vec3(a_coord.x(), a_coord.y(), 1.0f);
5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		packet.position				= rr::readVertexAttribFloat(inputs[0], packet.instanceNdx, packet.vertexNdx);
5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		packet.outputs[0]			= tcu::Vec4(v_coord.x(), v_coord.y(), v_coord.z(), 0.0f);
5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureCubeShader::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Vec4 texScale (m_uniforms[2].value.f4);
5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Vec4 texBias	 (m_uniforms[3].value.f4);
5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Vec3 texCoords[4];
5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Vec4 colors[4];
5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const sglr::rc::TextureCube* tex = m_uniforms[1].sampler.texCube;
5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::Vec4	coord = rr::readTriangleVarying<float>(packets[packetNdx], context, 0, fragNdx);
5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			texCoords[fragNdx] = tcu::Vec3(coord.x(), coord.y(), coord.z());
5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tex->sample4(colors, texCoords);
5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::Vec4		color	= colors[fragNdx] * texScale + texBias;
5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::IVec4	icolor	= castVectorSaturate<deInt32>(color);
5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::UVec4	uicolor	= castVectorSaturate<deUint32>(color);
5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (m_outputType == glu::TYPE_FLOAT_VEC4)			rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, color);
5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else if (m_outputType == glu::TYPE_INT_VEC4)		rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, icolor);
5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else if (m_outputType == glu::TYPE_UINT_VEC4)		rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, uicolor);
5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				DE_ASSERT(DE_FALSE);
5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5603c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2DArrayShader::Texture2DArrayShader (glu::DataType samplerType, glu::DataType outputType)
5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: sglr::ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::VertexAttribute("a_coord", rr::GENERICVECTYPE_FLOAT)
5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::FragmentOutput(mapDataTypeToGenericVecType(outputType))
5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::Uniform("u_sampler0", samplerType)
5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::Uniform("u_scale", glu::TYPE_FLOAT_VEC4)
5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::Uniform("u_bias", glu::TYPE_FLOAT_VEC4)
5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::Uniform("u_layer", glu::TYPE_INT)
5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::VertexSource(
5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"#version 300 es\n"
5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"in highp vec4 a_position;\n"
5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"in highp vec2 a_coord;\n"
5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"out highp vec2 v_coord;\n"
5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"void main (void)\n"
5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"{\n"
5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"	gl_Position = a_position;\n"
5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"	v_coord = a_coord;\n"
5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"}\n")
5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::FragmentSource(
5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									string("") +
5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"#version 300 es\n"
5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"uniform highp " + glu::getDataTypeName(samplerType) + " u_sampler0;\n"
5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"uniform highp vec4 u_scale;\n"
5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"uniform highp vec4 u_bias;\n"
5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"uniform highp int u_layer;\n"
5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"in highp vec2 v_coord;\n"
5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"layout(location = 0) out highp " + glu::getDataTypeName(outputType) + " o_color;\n"
5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"void main (void)\n"
5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"{\n"
5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"	o_color = " + glu::getDataTypeName(outputType) + "(vec4(texture(u_sampler0, vec3(v_coord, u_layer))) * u_scale + u_bias);\n"
5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"}\n"))
5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_texScale	(1.0f)
5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_texBias		(0.0f)
5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_layer		(0)
5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_outputType	(outputType)
5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DArrayShader::setLayer (int layer)
6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_layer = layer;
6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DArrayShader::setTexScaleBias (const Vec4& scale, const Vec4& bias)
6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_texScale	= scale;
6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_texBias	= bias;
6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DArrayShader::setUniforms (sglr::Context& gl, deUint32 program) const
6123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.useProgram(program);
6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniform1i	(gl.getUniformLocation(program, "u_sampler0"),	0);
6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniform1i	(gl.getUniformLocation(program, "u_layer"),		m_layer);
6173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniform4fv	(gl.getUniformLocation(program, "u_scale"),		1, m_texScale.getPtr());
6183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniform4fv	(gl.getUniformLocation(program, "u_bias"),		1, m_texBias.getPtr());
6193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DArrayShader::shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
6243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		rr::VertexPacket& packet = *packets[packetNdx];
6263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		packet.position		= rr::readVertexAttribFloat(inputs[0], packet.instanceNdx, packet.vertexNdx);
6283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		packet.outputs[0]	= rr::readVertexAttribFloat(inputs[1], packet.instanceNdx, packet.vertexNdx);
6293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6323c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DArrayShader::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
6333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Vec4 texScale	(m_uniforms[1].value.f4);
6353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Vec4 texBias		(m_uniforms[2].value.f4);
6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int		layer		= m_uniforms[3].value.i;
6373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Vec3 texCoords[4];
6393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Vec4 colors[4];
6403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
6423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const sglr::rc::Texture2DArray* tex = m_uniforms[0].sampler.tex2DArray;
6443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
6463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
6473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::Vec4	coord = rr::readTriangleVarying<float>(packets[packetNdx], context, 0, fragNdx);
6483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			texCoords[fragNdx] = tcu::Vec3(coord.x(), coord.y(), float(layer));
6493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
6503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tex->sample4(colors, texCoords);
6523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
6543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
6553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::Vec4		color	= colors[fragNdx] * texScale + texBias;
6563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::IVec4	icolor	= castVectorSaturate<deInt32>(color);
6573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::UVec4	uicolor	= castVectorSaturate<deUint32>(color);
6583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (m_outputType == glu::TYPE_FLOAT_VEC4)			rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, color);
6603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else if (m_outputType == glu::TYPE_INT_VEC4)		rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, icolor);
6613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else if (m_outputType == glu::TYPE_UINT_VEC4)		rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, uicolor);
6623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
6633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				DE_ASSERT(DE_FALSE);
6643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
6653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6683c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture3DShader::Texture3DShader (glu::DataType samplerType, glu::DataType outputType)
6693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: sglr::ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
6703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
6713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::VertexAttribute("a_coord", rr::GENERICVECTYPE_FLOAT)
6723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
6733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::FragmentOutput(mapDataTypeToGenericVecType(outputType))
6743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::Uniform("u_sampler0", samplerType)
6753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::Uniform("u_scale", glu::TYPE_FLOAT_VEC4)
6763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::Uniform("u_bias", glu::TYPE_FLOAT_VEC4)
6773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::Uniform("u_depth", glu::TYPE_FLOAT)
6783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::VertexSource(
6793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"#version 300 es\n"
6803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"in highp vec4 a_position;\n"
6813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"in highp vec2 a_coord;\n"
6823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"out highp vec2 v_coord;\n"
6833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"void main (void)\n"
6843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"{\n"
6853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"	gl_Position = a_position;\n"
6863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"	v_coord = a_coord;\n"
6873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"}\n")
6883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< sglr::pdec::FragmentSource(
6893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									string("") +
6903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"#version 300 es\n"
6913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"uniform highp " + glu::getDataTypeName(samplerType) + " u_sampler0;\n"
6923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"uniform highp vec4 u_scale;\n"
6933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"uniform highp vec4 u_bias;\n"
6943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"uniform highp float u_depth;\n"
6953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"in highp vec2 v_coord;\n"
6963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"layout(location = 0) out highp " + glu::getDataTypeName(outputType) + " o_color;\n"
6973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"void main (void)\n"
6983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"{\n"
6993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"	o_color = " + glu::getDataTypeName(outputType) + "(vec4(texture(u_sampler0, vec3(v_coord, u_depth))) * u_scale + u_bias);\n"
7003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									"}\n"))
7013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_texScale	(1.0f)
7023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_texBias		(0.0f)
7033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_depth		(0.0f)
7043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_outputType	(outputType)
7053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7083c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture3DShader::setDepth (float depth)
7093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_depth = depth;
7113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7133c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture3DShader::setTexScaleBias (const Vec4& scale, const Vec4& bias)
7143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_texScale	= scale;
7163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_texBias	= bias;
7173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7193c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture3DShader::setUniforms (sglr::Context& gl, deUint32 program) const
7203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.useProgram(program);
7223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniform1i	(gl.getUniformLocation(program, "u_sampler0"),	0);
7243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniform1f	(gl.getUniformLocation(program, "u_depth"),		m_depth);
7253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniform4fv	(gl.getUniformLocation(program, "u_scale"),		1, m_texScale.getPtr());
7263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniform4fv	(gl.getUniformLocation(program, "u_bias"),		1, m_texBias.getPtr());
7273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7293c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture3DShader::shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
7303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
7323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		rr::VertexPacket& packet = *packets[packetNdx];
7343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		packet.position		= rr::readVertexAttribFloat(inputs[0], packet.instanceNdx, packet.vertexNdx);
7363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		packet.outputs[0]	= rr::readVertexAttribFloat(inputs[1], packet.instanceNdx, packet.vertexNdx);
7373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
7383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7403c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture3DShader::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
7413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Vec4 texScale	(m_uniforms[1].value.f4);
7433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Vec4 texBias		(m_uniforms[2].value.f4);
7443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float		depth		= m_uniforms[3].value.f;
7453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Vec3 texCoords[4];
7473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Vec4 colors[4];
7483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
7503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const sglr::rc::Texture3D* tex = m_uniforms[0].sampler.tex3D;
7523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
7543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
7553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::Vec4	coord = rr::readTriangleVarying<float>(packets[packetNdx], context, 0, fragNdx);
7563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			texCoords[fragNdx] = tcu::Vec3(coord.x(), coord.y(), depth);
7573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
7583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tex->sample4(colors, texCoords);
7603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
7623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
7633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::Vec4		color	= colors[fragNdx] * texScale + texBias;
7643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::IVec4	icolor	= castVectorSaturate<deInt32>(color);
7653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::UVec4	uicolor	= castVectorSaturate<deUint32>(color);
7663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (m_outputType == glu::TYPE_FLOAT_VEC4)			rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, color);
7683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else if (m_outputType == glu::TYPE_INT_VEC4)		rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, icolor);
7693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else if (m_outputType == glu::TYPE_UINT_VEC4)		rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, uicolor);
7703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
7713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				DE_ASSERT(DE_FALSE);
7723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
7733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
7743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7763c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDepthGradientShader::DepthGradientShader (glu::DataType outputType)
7773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
7783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
7793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::VertexAttribute("a_coord", rr::GENERICVECTYPE_FLOAT)
7803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
7813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::FragmentOutput(mapDataTypeToGenericVecType(outputType))
7823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::Uniform("u_maxGradient", glu::TYPE_FLOAT)
7833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::Uniform("u_minGradient", glu::TYPE_FLOAT)
7843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::Uniform("u_color", glu::TYPE_FLOAT_VEC4)
7853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::VertexSource(
7863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"#version 300 es\n"
7873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"in highp vec4 a_position;\n"
7883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"in highp vec4 a_coord;\n"
7893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"out highp vec4 v_coord;\n"
7903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"void main (void)\n"
7913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"{\n"
7923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"	gl_Position = a_position;\n"
7933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"	v_coord = a_coord;\n"
7943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							"}\n")
7953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< sglr::pdec::FragmentSource(
7963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							string(
7973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"#version 300 es\n"
7983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"in highp vec4 v_coord;\n"
7993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"uniform highp float u_minGradient;\n"
8003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"uniform highp float u_maxGradient;\n"
8013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"uniform highp vec4 u_color;\n"
8023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"layout(location = 0) out highp ") + glu::getDataTypeName(outputType) + " o_color;\n"
8033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"void main (void)\n"
8043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"{\n"
8053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"	highp float x = v_coord.x;\n"
8063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"	highp float y = v_coord.y;\n"
8073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"	highp float f0 = (x + y) * 0.5;\n"
8083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"	gl_FragDepth = u_minGradient + (u_maxGradient-u_minGradient)*f0;\n"
8093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"	o_color = " + glu::getDataTypeName(outputType) + "(u_color);\n"
8103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"}\n"))
8113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_outputType	(outputType)
8123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, u_minGradient	(getUniformByName("u_minGradient"))
8133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, u_maxGradient	(getUniformByName("u_maxGradient"))
8143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, u_color		(getUniformByName("u_color"))
8153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8183c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid DepthGradientShader::setUniforms (sglr::Context& ctx, deUint32 program, const float gradientMin, const float gradientMax, const tcu::Vec4& color)
8193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.useProgram(program);
8213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.uniform1fv(ctx.getUniformLocation(program, "u_minGradient"), 1, &gradientMin);
8223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.uniform1fv(ctx.getUniformLocation(program, "u_maxGradient"), 1, &gradientMax);
8233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.uniform4fv(ctx.getUniformLocation(program, "u_color"), 1, color.getPtr());
8243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8263c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid DepthGradientShader::shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
8273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
8293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
8303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		rr::VertexPacket& packet = *packets[packetNdx];
8313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		packet.position		= rr::readVertexAttribFloat(inputs[0], packet.instanceNdx, packet.vertexNdx);
8333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		packet.outputs[0]	= rr::readVertexAttribFloat(inputs[1], packet.instanceNdx, packet.vertexNdx);
8343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
8353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8373c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid DepthGradientShader::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
8383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float			gradientMin	(u_minGradient.value.f);
8403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float			gradientMax	(u_maxGradient.value.f);
8413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Vec4		color		(u_color.value.f4);
8423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::IVec4	icolor		(castVectorSaturate<deInt32>(color));
8433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::UVec4	uicolor		(castVectorSaturate<deUint32>(color));
8443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// running this shader without a depth buffer does not make any sense
8463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(context.fragmentDepths);
8473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
8493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
8503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
8513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::Vec4		coord	= rr::readTriangleVarying<float>(packets[packetNdx], context, 0, fragNdx);
8523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float			x		= coord.x();
8533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float			y		= coord.y();
8543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float			f0		= (x + y) * 0.5f;
8553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		rr::writeFragmentDepth(context, packetNdx, fragNdx, 0, gradientMin + (gradientMax-gradientMin) * f0);
8573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_outputType == glu::TYPE_FLOAT_VEC4)			rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, color);
8593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_outputType == glu::TYPE_INT_VEC4)		rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, icolor);
8603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_outputType == glu::TYPE_UINT_VEC4)		rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, uicolor);
8613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
8623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(DE_FALSE);
8633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
8643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8663c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clearColorBuffer (sglr::Context& ctx, const tcu::TextureFormat& format, const tcu::Vec4& value)
8673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::TextureChannelClass fmtClass = tcu::getTextureChannelClass(format.type);
8693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (fmtClass)
8713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
8723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
8733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
8743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
8753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			ctx.clearBufferfv(GL_COLOR, 0, value.getPtr());
8763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
8773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
8793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			ctx.clearBufferuiv(GL_COLOR, 0, value.asUint().getPtr());
8803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
8813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
8833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			ctx.clearBufferiv(GL_COLOR, 0, value.asInt().getPtr());
8843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
8853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
8873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(DE_FALSE);
8883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
8893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8913c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid readPixels (sglr::Context& ctx, tcu::Surface& dst, int x, int y, int width, int height, const tcu::TextureFormat& format, const tcu::Vec4& scale, const tcu::Vec4& bias)
8923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureFormat		readFormat		= getFramebufferReadFormat(format);
8943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::TransferFormat		transferFmt		= glu::getTransferFormat(readFormat);
8953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						alignment		= 4; // \note GL_PACK_ALIGNMENT = 4 is assumed.
8963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						rowSize			= deAlign32(readFormat.getPixelSize()*width, alignment);
8973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<deUint8>			data			(rowSize*height);
8983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.readPixels(x, y, width, height, transferFmt.format, transferFmt.dataType, &data[0]);
9003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Convert to surface.
9023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::ConstPixelBufferAccess src(readFormat, width, height, 1, rowSize, 0, &data[0]);
9033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst.setSize(width, height);
9053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::PixelBufferAccess dstAccess = dst.getAccess();
9063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int yo = 0; yo < height; yo++)
9083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int xo = 0; xo < width; xo++)
9093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		dstAccess.setPixel(src.getPixel(xo, yo) * scale + bias, xo, yo);
9103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
9113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9123c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* getFboIncompleteReasonName (deUint32 reason)
9133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
9143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (reason)
9153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
9163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:			return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
9173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:	return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
9183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:			return "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS";
9193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_FRAMEBUFFER_UNSUPPORTED:					return "GL_FRAMEBUFFER_UNSUPPORTED";
9203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_FRAMEBUFFER_COMPLETE:						return "GL_FRAMEBUFFER_COMPLETE";
9213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:											return "UNKNOWN";
9223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
9233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
9243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9253c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFboIncompleteException::FboIncompleteException (deUint32 reason, const char* file, int line)
9263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestError		("Framebuffer is not complete", getFboIncompleteReasonName(reason), file, line)
9273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_reason		(reason)
9283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
9293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
9303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9313c827367444ee418f129b2c238299f49d3264554Jarkko Poyryconst char* getFormatName (deUint32 format)
9323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
9333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (format)
9343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
9353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB565:				return "rgb565";
9363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB5_A1:			return "rgb5_a1";
9373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGBA4:				return "rgba4";
9383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_DEPTH_COMPONENT16:	return "depth_component16";
9393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_STENCIL_INDEX8:		return "stencil_index8";
9403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGBA32F:			return "rgba32f";
9413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGBA32I:			return "rgba32i";
9423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGBA32UI:			return "rgba32ui";
9433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGBA16F:			return "rgba16f";
9443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGBA16I:			return "rgba16i";
9453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGBA16UI:			return "rgba16ui";
9463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGBA8:				return "rgba8";
9473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGBA8I:				return "rgba8i";
9483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGBA8UI:			return "rgba8ui";
9493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_SRGB8_ALPHA8:		return "srgb8_alpha8";
9503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB10_A2:			return "rgb10_a2";
9513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB10_A2UI:			return "rgb10_a2ui";
9523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGBA8_SNORM:		return "rgba8_snorm";
9533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB8:				return "rgb8";
9543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_R11F_G11F_B10F:		return "r11f_g11f_b10f";
9553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB32F:				return "rgb32f";
9563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB32I:				return "rgb32i";
9573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB32UI:			return "rgb32ui";
9583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB16F:				return "rgb16f";
9593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB16I:				return "rgb16i";
9603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB16UI:			return "rgb16ui";
9613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB8_SNORM:			return "rgb8_snorm";
9623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB8I:				return "rgb8i";
9633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB8UI:				return "rgb8ui";
9643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_SRGB8:				return "srgb8";
9653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB9_E5:			return "rgb9_e5";
9663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RG32F:				return "rg32f";
9673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RG32I:				return "rg32i";
9683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RG32UI:				return "rg32ui";
9693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RG16F:				return "rg16f";
9703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RG16I:				return "rg16i";
9713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RG16UI:				return "rg16ui";
9723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RG8:				return "rg8";
9733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RG8I:				return "rg8i";
9743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RG8UI:				return "rg8ui";
9753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RG8_SNORM:			return "rg8_snorm";
9763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_R32F:				return "r32f";
9773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_R32I:				return "r32i";
9783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_R32UI:				return "r32ui";
9793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_R16F:				return "r16f";
9803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_R16I:				return "r16i";
9813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_R16UI:				return "r16ui";
9823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_R8:					return "r8";
9833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_R8I:				return "r8i";
9843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_R8UI:				return "r8ui";
9853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_R8_SNORM:			return "r8_snorm";
9863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_DEPTH_COMPONENT32F:	return "depth_component32f";
9873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_DEPTH_COMPONENT24:	return "depth_component24";
9883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_DEPTH32F_STENCIL8:	return "depth32f_stencil8";
9893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_DEPTH24_STENCIL8:	return "depth24_stencil8";
9903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
9923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			TCU_FAIL("Unknown format");
9933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
9943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
9953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9963c827367444ee418f129b2c238299f49d3264554Jarkko Poyryglu::DataType getFragmentOutputType (const tcu::TextureFormat& format)
9973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
9983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (tcu::getTextureChannelClass(format.type))
9993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
10003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
10013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
10023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
10033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return glu::TYPE_FLOAT_VEC4;
10043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
10063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return glu::TYPE_UINT_VEC4;
10073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
10093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return glu::TYPE_INT_VEC4;
10103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
10123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(!"Unknown format");
10133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return glu::TYPE_LAST;
10143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
10153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10173c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::TextureFormat getFramebufferReadFormat (const tcu::TextureFormat& format)
10183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (tcu::getTextureChannelClass(format.type))
10203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
10213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
10223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::FLOAT);
10233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
10253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
10263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8);
10273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
10293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNSIGNED_INT32);
10303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
10323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::SIGNED_INT32);
10333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
10353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(!"Unknown format");
10363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return tcu::TextureFormat();
10373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
10383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10403c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic int calculateU8ConversionError (int srcBits)
10413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (srcBits > 0)
10433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
10443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int clampedBits	= de::clamp<int>(srcBits, 0, 8);
10453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int srcMaxValue	= de::max((1<<clampedBits) - 1, 1);
10463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int error			= int(deFloatCeil(255.0f * 2.0f / float(srcMaxValue)));
10473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return de::clamp<int>(error, 0, 255);
10493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
10503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
10513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return 1;
10523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10543c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::RGBA getFormatThreshold (const tcu::TextureFormat& format)
10553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1056ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry	const tcu::IVec4 bits = tcu::getTextureFormatMantissaBitDepth(format);
10573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return tcu::RGBA(calculateU8ConversionError(bits.x()),
10593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					 calculateU8ConversionError(bits.y()),
10603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					 calculateU8ConversionError(bits.z()),
10613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					 calculateU8ConversionError(bits.w()));
10623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10643c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::RGBA getFormatThreshold (deUint32 glFormat)
10653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::TextureFormat format = glu::mapGLInternalFormat(glFormat);
10673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return getFormatThreshold(format);
10693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10713c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic int getToSRGB8ConversionError (int srcBits)
10723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// \note These are pre-computed based on simulation results.
10743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const int errors[] =
10753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
10763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		1,		// 0 bits - rounding
10773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		255,	// 1 bits
10783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		157,	// 2 bits
10793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		106,	// 3 bits
10803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		74,		// 4 bits
10813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		51,		// 5 bits
10823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		34,		// 6 bits
10833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		22,		// 7 bits
10843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		13,		// 8 bits
10853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		7,		// 9 bits
10863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		4,		// 10 bits
10873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		3,		// 11 bits
10883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		2,		// 12 bits
10893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// 1 from this on
10903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
10913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(srcBits >= 0);
10933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (srcBits < DE_LENGTH_OF_ARRAY(errors))
10943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return errors[srcBits];
10953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
10963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return 1;
10973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10993c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::RGBA getToSRGBConversionThreshold (const tcu::TextureFormat& src, const tcu::TextureFormat& dst)
11003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Only SRGB8 and SRGB8_ALPHA8 formats are supported.
110289a729134d6a1880d2b59426dfe14d615381e314Jarkko Pöyry	DE_ASSERT(dst.type == tcu::TextureFormat::UNORM_INT8 && tcu::isSRGB(dst));
11033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1104ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry	const tcu::IVec4	bits		= tcu::getTextureFormatMantissaBitDepth(src);
11053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool			dstHasAlpha	= dst.order == tcu::TextureFormat::sRGBA;
11063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return tcu::RGBA(getToSRGB8ConversionError(bits.x()),
11083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					 getToSRGB8ConversionError(bits.y()),
11093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					 getToSRGB8ConversionError(bits.z()),
11103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					 dstHasAlpha ? calculateU8ConversionError(bits.w()) : 0);
11113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // FboTestUtil
11143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional
11153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles3
11163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
1117