13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES 2.0 Module
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * -------------------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Texture access function tests.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es2fShaderTextureFunctionTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsShaderRenderCase.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsShaderLibrary.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTexture.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTextureUtil.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuMatrix.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuMatrixUtil.hpp"
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <sstream>
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp"
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp"
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles2
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum Function
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FUNCTION_TEXTURE = 0,		//!< texture(), textureOffset()
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FUNCTION_TEXTUREPROJ,		//!< textureProj(), textureProjOffset()
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FUNCTION_TEXTUREPROJ3,		//!< textureProj(sampler2D, vec3)
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FUNCTION_TEXTURELOD,		// ...
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FUNCTION_TEXTUREPROJLOD,
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FUNCTION_TEXTUREPROJLOD3,	//!< textureProjLod(sampler2D, vec3)
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FUNCTION_LAST
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline bool functionHasProj (Function function)
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return function == FUNCTION_TEXTUREPROJ		||
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   function == FUNCTION_TEXTUREPROJ3	||
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   function == FUNCTION_TEXTUREPROJLOD	||
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   function == FUNCTION_TEXTUREPROJLOD3;
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline bool functionHasLod (Function function)
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return function == FUNCTION_TEXTURELOD		||
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   function == FUNCTION_TEXTUREPROJLOD	||
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   function == FUNCTION_TEXTUREPROJLOD3;
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct TextureLookupSpec
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Function		function;
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Vec4		minCoord;
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Vec4		maxCoord;
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Bias
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool			useBias;
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Bias or Lod for *Lod* functions
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float			minLodBias;
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float			maxLodBias;
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureLookupSpec (void)
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: function		(FUNCTION_LAST)
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, minCoord		(0.0f)
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, maxCoord		(1.0f)
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, useBias		(false)
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, minLodBias	(0.0f)
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, maxLodBias	(0.0f)
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureLookupSpec (Function				function_,
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					   const tcu::Vec4&		minCoord_,
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					   const tcu::Vec4&		maxCoord_,
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					   bool					useBias_,
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					   float				minLodBias_,
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					   float				maxLodBias_)
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: function		(function_)
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, minCoord		(minCoord_)
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, maxCoord		(maxCoord_)
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, useBias		(useBias_)
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, minLodBias	(minLodBias_)
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, maxLodBias	(maxLodBias_)
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum TextureType
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TEXTURETYPE_2D,
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TEXTURETYPE_CUBE_MAP,
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TEXTURETYPE_LAST
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct TextureSpec
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureType			type;		//!< Texture type (2D, cubemap, ...)
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			format;
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			dataType;
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					width;
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					height;
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					numLevels;
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Sampler		sampler;
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureSpec (void)
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: type			(TEXTURETYPE_LAST)
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, format		(GL_NONE)
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, dataType		(GL_NONE)
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, width			(0)
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, height		(0)
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, numLevels		(0)
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureSpec (TextureType			type_,
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				 deUint32				format_,
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				 deUint32				dataType_,
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				 int					width_,
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				 int					height_,
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				 int					numLevels_,
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				 const tcu::Sampler&	sampler_)
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: type			(type_)
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, format		(format_)
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, dataType		(dataType_)
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, width			(width_)
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, height		(height_)
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, numLevels		(numLevels_)
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, sampler		(sampler_)
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct TexLookupParams
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float				lod;
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Vec4			scale;
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Vec4			bias;
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TexLookupParams (void)
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: lod		(0.0f)
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, scale		(1.0f)
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, bias		(0.0f)
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // anonymous
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec2;
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec3;
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec4;
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::IVec2;
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::IVec3;
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::IVec4;
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline float computeLodFromDerivates (float dudx, float dvdx, float dudy, float dvdy)
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float p = de::max(deFloatSqrt(dudx*dudx + dvdx*dvdx), deFloatSqrt(dudy*dudy + dvdy*dvdy));
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return deFloatLog2(p);
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef void (*TexEvalFunc) (gls::ShaderEvalContext& c, const TexLookupParams& lookupParams);
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Vec4 texture2D		(const gls::ShaderEvalContext& c, float s, float t, float lod)			{ return c.textures[0].tex2D->sample(c.textures[0].sampler, s, t, lod);			}
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Vec4 textureCube		(const gls::ShaderEvalContext& c, float s, float t, float r, float lod)	{ return c.textures[0].texCube->sample(c.textures[0].sampler, s, t, r, lod);	}
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Eval functions.
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void		evalTexture2D			(gls::ShaderEvalContext& c, const TexLookupParams& p)	{ c.color = texture2D(c, c.in[0].x(), c.in[0].y(), p.lod)*p.scale + p.bias; }
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void		evalTextureCube			(gls::ShaderEvalContext& c, const TexLookupParams& p)	{ c.color = textureCube(c, c.in[0].x(), c.in[0].y(), c.in[0].z(), p.lod)*p.scale + p.bias; }
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void		evalTexture2DBias		(gls::ShaderEvalContext& c, const TexLookupParams& p)	{ c.color = texture2D(c, c.in[0].x(), c.in[0].y(), p.lod+c.in[1].x())*p.scale + p.bias; }
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void		evalTextureCubeBias		(gls::ShaderEvalContext& c, const TexLookupParams& p)	{ c.color = textureCube(c, c.in[0].x(), c.in[0].y(), c.in[0].z(), p.lod+c.in[1].x())*p.scale + p.bias; }
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void		evalTexture2DProj3		(gls::ShaderEvalContext& c, const TexLookupParams& p)	{ c.color = texture2D(c, c.in[0].x()/c.in[0].z(), c.in[0].y()/c.in[0].z(), p.lod)*p.scale + p.bias; }
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void		evalTexture2DProj3Bias	(gls::ShaderEvalContext& c, const TexLookupParams& p)	{ c.color = texture2D(c, c.in[0].x()/c.in[0].z(), c.in[0].y()/c.in[0].z(), p.lod+c.in[1].x())*p.scale + p.bias; }
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void		evalTexture2DProj		(gls::ShaderEvalContext& c, const TexLookupParams& p)	{ c.color = texture2D(c, c.in[0].x()/c.in[0].w(), c.in[0].y()/c.in[0].w(), p.lod)*p.scale + p.bias; }
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void		evalTexture2DProjBias	(gls::ShaderEvalContext& c, const TexLookupParams& p)	{ c.color = texture2D(c, c.in[0].x()/c.in[0].w(), c.in[0].y()/c.in[0].w(), p.lod+c.in[1].x())*p.scale + p.bias; }
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void		evalTexture2DLod		(gls::ShaderEvalContext& c, const TexLookupParams& p)	{ c.color = texture2D(c, c.in[0].x(), c.in[0].y(), c.in[1].x())*p.scale + p.bias; }
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void		evalTextureCubeLod		(gls::ShaderEvalContext& c, const TexLookupParams& p)	{ c.color = textureCube(c, c.in[0].x(), c.in[0].y(), c.in[0].z(), c.in[1].x())*p.scale + p.bias; }
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void		evalTexture2DProjLod3	(gls::ShaderEvalContext& c, const TexLookupParams& p)	{ c.color = texture2D(c, c.in[0].x()/c.in[0].z(), c.in[0].y()/c.in[0].z(), c.in[1].x())*p.scale + p.bias; }
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void		evalTexture2DProjLod	(gls::ShaderEvalContext& c, const TexLookupParams& p)	{ c.color = texture2D(c, c.in[0].x()/c.in[0].w(), c.in[0].y()/c.in[0].w(), c.in[1].x())*p.scale + p.bias; }
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TexLookupEvaluator : public gls::ShaderEvaluator
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							TexLookupEvaluator		(TexEvalFunc evalFunc, const TexLookupParams& lookupParams) : m_evalFunc(evalFunc), m_lookupParams(lookupParams) {}
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void			evaluate				(gls::ShaderEvalContext& ctx) { m_evalFunc(ctx, m_lookupParams); }
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TexEvalFunc				m_evalFunc;
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const TexLookupParams&	m_lookupParams;
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ShaderTextureFunctionCase : public gls::ShaderRenderCase
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							ShaderTextureFunctionCase		(Context& context, const char* name, const char* desc, const TextureLookupSpec& lookup, const TextureSpec& texture, TexEvalFunc evalFunc, bool isVertexCase);
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							~ShaderTextureFunctionCase		(void);
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					init							(void);
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					deinit							(void);
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					setupUniforms					(int programID, const tcu::Vec4& constCoords);
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					initTexture						(void);
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					initShaderSources				(void);
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureLookupSpec		m_lookupSpec;
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureSpec				m_textureSpec;
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TexLookupParams			m_lookupParams;
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TexLookupEvaluator		m_evaluator;
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::Texture2D*			m_texture2D;
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::TextureCube*		m_textureCube;
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2513c827367444ee418f129b2c238299f49d3264554Jarkko PoyryShaderTextureFunctionCase::ShaderTextureFunctionCase (Context& context, const char* name, const char* desc, const TextureLookupSpec& lookup, const TextureSpec& texture, TexEvalFunc evalFunc, bool isVertexCase)
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: gls::ShaderRenderCase(context.getTestContext(), context.getRenderContext(), context.getContextInfo(), name, desc, isVertexCase, m_evaluator)
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_lookupSpec			(lookup)
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_textureSpec			(texture)
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_evaluator			(evalFunc, m_lookupParams)
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_texture2D			(DE_NULL)
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_textureCube			(DE_NULL)
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2613c827367444ee418f129b2c238299f49d3264554Jarkko PoyryShaderTextureFunctionCase::~ShaderTextureFunctionCase (void)
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_texture2D;
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_textureCube;
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ShaderTextureFunctionCase::init (void)
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_isVertexCase)
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const glw::Functions& gl = m_renderCtx.getFunctions();
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int numVertexUnits = 0;
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.getIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &numVertexUnits);
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (numVertexUnits < 1)
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			throw tcu::NotSupportedError("Vertex shader texture access is not supported");
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Base coord scale & bias
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Vec4 s = m_lookupSpec.maxCoord-m_lookupSpec.minCoord;
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Vec4 b = m_lookupSpec.minCoord;
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float baseCoordTrans[] =
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			s.x(),		0.0f,		0.f,	b.x(),
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			0.f,		s.y(),		0.f,	b.y(),
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			s.z()/2.f,	-s.z()/2.f,	0.f,	s.z()/2.f + b.z(),
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			-s.w()/2.f,	s.w()/2.f,	0.f,	s.w()/2.f + b.w()
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		};
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_userAttribTransforms.push_back(tcu::Mat4(baseCoordTrans));
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (functionHasLod(m_lookupSpec.function) || m_lookupSpec.useBias)
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float s = m_lookupSpec.maxLodBias-m_lookupSpec.minLodBias;
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float b = m_lookupSpec.minLodBias;
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float lodCoordTrans[] =
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			s/2.0f,		s/2.0f,		0.f,	b,
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			0.0f,		0.0f,		0.0f,	0.0f,
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			0.0f,		0.0f,		0.0f,	0.0f,
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			0.0f,		0.0f,		0.0f,	0.0f
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		};
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_userAttribTransforms.push_back(tcu::Mat4(lodCoordTrans));
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	initShaderSources();
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	initTexture();
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gls::ShaderRenderCase::init();
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ShaderTextureFunctionCase::initTexture (void)
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const IVec4 texCubeSwz[] =
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		IVec4(0,0,1,1),
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		IVec4(1,1,0,0),
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		IVec4(0,1,0,1),
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		IVec4(1,0,1,0),
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		IVec4(0,1,1,0),
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		IVec4(1,0,0,1)
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(texCubeSwz) == tcu::CUBEFACE_LAST);
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureFormat		texFmt			= glu::mapGLTransferFormat(m_textureSpec.format, m_textureSpec.dataType);
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureFormatInfo	fmtInfo			= tcu::getTextureFormatInfo(texFmt);
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::IVec2				viewportSize	= getViewportSize();
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool					isProj			= functionHasProj(m_lookupSpec.function);
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float					proj			= isProj ? 1.0f/m_lookupSpec.minCoord[m_lookupSpec.function == FUNCTION_TEXTUREPROJ3 ? 2 : 3] : 1.0f;
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (m_textureSpec.type)
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURETYPE_2D:
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			float	cStep			= 1.0f / (float)de::max(1, m_textureSpec.numLevels-1);
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			Vec4	cScale			= fmtInfo.valueMax-fmtInfo.valueMin;
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			Vec4	cBias			= fmtInfo.valueMin;
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int		baseCellSize	= de::min(m_textureSpec.width/4, m_textureSpec.height/4);
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_texture2D = new glu::Texture2D(m_renderCtx, m_textureSpec.format, m_textureSpec.dataType, m_textureSpec.width, m_textureSpec.height);
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int level = 0; level < m_textureSpec.numLevels; level++)
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				float	fA		= level*cStep;
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				float	fB		= 1.0f-fA;
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				Vec4	colorA	= cBias + cScale*Vec4(fA, fB, fA, fB);
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				Vec4	colorB	= cBias + cScale*Vec4(fB, fA, fB, fA);
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_texture2D->getRefTexture().allocLevel(level);
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				tcu::fillWithGrid(m_texture2D->getRefTexture().getLevel(level), de::max(1, baseCellSize>>level), colorA, colorB);
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_texture2D->upload();
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Compute LOD.
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			float dudx = (m_lookupSpec.maxCoord[0]-m_lookupSpec.minCoord[0])*proj*m_textureSpec.width	/ (float)viewportSize[0];
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			float dvdy = (m_lookupSpec.maxCoord[1]-m_lookupSpec.minCoord[1])*proj*m_textureSpec.height	/ (float)viewportSize[1];
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_lookupParams.lod = computeLodFromDerivates(dudx, 0.0f, 0.0f, dvdy);
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Append to texture list.
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_textures.push_back(gls::TextureBinding(m_texture2D, m_textureSpec.sampler));
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURETYPE_CUBE_MAP:
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			float	cStep			= 1.0f / (float)de::max(1, m_textureSpec.numLevels-1);
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			Vec4	cScale			= fmtInfo.valueMax-fmtInfo.valueMin;
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			Vec4	cBias			= fmtInfo.valueMin;
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int		baseCellSize	= de::min(m_textureSpec.width/4, m_textureSpec.height/4);
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(m_textureSpec.width == m_textureSpec.height);
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_textureCube = new glu::TextureCube(m_renderCtx, m_textureSpec.format, m_textureSpec.dataType, m_textureSpec.width);
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int level = 0; level < m_textureSpec.numLevels; level++)
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				float	fA		= level*cStep;
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				float	fB		= 1.0f-fA;
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				Vec2	f		(fA, fB);
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					const IVec4&	swzA	= texCubeSwz[face];
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					IVec4			swzB	= 1-swzA;
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					Vec4			colorA	= cBias + cScale*f.swizzle(swzA[0], swzA[1], swzA[2], swzA[3]);
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					Vec4			colorB	= cBias + cScale*f.swizzle(swzB[0], swzB[1], swzB[2], swzB[3]);
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_textureCube->getRefTexture().allocLevel((tcu::CubeFace)face, level);
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					tcu::fillWithGrid(m_textureCube->getRefTexture().getLevelFace(level, (tcu::CubeFace)face), de::max(1, baseCellSize>>level), colorA, colorB);
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_textureCube->upload();
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Compute LOD \note Assumes that only single side is accessed and R is constant major axis.
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(de::abs(m_lookupSpec.minCoord[2] - m_lookupSpec.maxCoord[2]) < 0.005);
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(de::abs(m_lookupSpec.minCoord[0]) < de::abs(m_lookupSpec.minCoord[2]) && de::abs(m_lookupSpec.maxCoord[0]) < de::abs(m_lookupSpec.minCoord[2]));
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(de::abs(m_lookupSpec.minCoord[1]) < de::abs(m_lookupSpec.minCoord[2]) && de::abs(m_lookupSpec.maxCoord[1]) < de::abs(m_lookupSpec.minCoord[2]));
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::CubeFaceFloatCoords	c00		= tcu::getCubeFaceCoords(Vec3(m_lookupSpec.minCoord[0]*proj, m_lookupSpec.minCoord[1]*proj, m_lookupSpec.minCoord[2]*proj));
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::CubeFaceFloatCoords	c10		= tcu::getCubeFaceCoords(Vec3(m_lookupSpec.maxCoord[0]*proj, m_lookupSpec.minCoord[1]*proj, m_lookupSpec.minCoord[2]*proj));
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::CubeFaceFloatCoords	c01		= tcu::getCubeFaceCoords(Vec3(m_lookupSpec.minCoord[0]*proj, m_lookupSpec.maxCoord[1]*proj, m_lookupSpec.minCoord[2]*proj));
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			float						dudx	= (c10.s - c00.s)*m_textureSpec.width	/ (float)viewportSize[0];
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			float						dvdy	= (c01.t - c00.t)*m_textureSpec.height	/ (float)viewportSize[1];
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_lookupParams.lod = computeLodFromDerivates(dudx, 0.0f, 0.0f, dvdy);
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_textures.push_back(gls::TextureBinding(m_textureCube, m_textureSpec.sampler));
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(DE_FALSE);
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Set lookup scale & bias
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_lookupParams.scale	= fmtInfo.lookupScale;
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_lookupParams.bias		= fmtInfo.lookupBias;
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ShaderTextureFunctionCase::initShaderSources (void)
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Function			function			= m_lookupSpec.function;
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool				isVtxCase			= m_isVertexCase;
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool				isProj				= functionHasProj(function);
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool				is2DProj4			= m_textureSpec.type == TEXTURETYPE_2D && (function == FUNCTION_TEXTUREPROJ || function == FUNCTION_TEXTUREPROJLOD);
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool				hasLodBias			= functionHasLod(m_lookupSpec.function) || m_lookupSpec.useBias;
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					texCoordComps		= m_textureSpec.type == TEXTURETYPE_2D ? 2 : 3;
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					extraCoordComps		= isProj ? (is2DProj4 ? 2 : 1) : 0;
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::DataType		coordType			= glu::getDataTypeFloatVec(texCoordComps+extraCoordComps);
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::Precision		coordPrec			= glu::PRECISION_MEDIUMP;
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*			coordTypeName		= glu::getDataTypeName(coordType);
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*			coordPrecName		= glu::getPrecisionName(coordPrec);
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureFormat	texFmt				= glu::mapGLTransferFormat(m_textureSpec.format, m_textureSpec.dataType);
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::DataType		samplerType			= glu::TYPE_LAST;
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*			baseFuncName		= m_textureSpec.type == TEXTURETYPE_2D ? "texture2D" : "textureCube";
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*			funcExt				= DE_NULL;
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (m_textureSpec.type)
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURETYPE_2D:		samplerType = glu::getSampler2DType(texFmt);		break;
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURETYPE_CUBE_MAP:	samplerType = glu::getSamplerCubeType(texFmt);		break;
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(DE_FALSE);
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (m_lookupSpec.function)
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case FUNCTION_TEXTURE:			funcExt = "";			break;
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case FUNCTION_TEXTUREPROJ:		funcExt = "Proj";		break;
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case FUNCTION_TEXTUREPROJ3:		funcExt = "Proj";		break;
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case FUNCTION_TEXTURELOD:		funcExt = "Lod";		break;
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case FUNCTION_TEXTUREPROJLOD:	funcExt = "ProjLod";	break;
4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case FUNCTION_TEXTUREPROJLOD3:	funcExt = "ProjLod";	break;
4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(DE_FALSE);
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::ostringstream	vert;
4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::ostringstream	frag;
4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::ostringstream&	op		= isVtxCase ? vert : frag;
4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vert << "attribute highp vec4 a_position;\n"
4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		 << "attribute " << coordPrecName << " " << coordTypeName << " a_in0;\n";
4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (hasLodBias)
4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vert << "attribute " << coordPrecName << " float a_in1;\n";
4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (isVtxCase)
4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vert << "varying mediump vec4 v_color;\n";
4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		frag << "varying mediump vec4 v_color;\n";
4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vert << "varying " << coordPrecName << " " << coordTypeName << " v_texCoord;\n";
4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		frag << "varying " << coordPrecName << " " << coordTypeName << " v_texCoord;\n";
4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (hasLodBias)
4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			vert << "varying " << coordPrecName << " float v_lodBias;\n";
4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			frag << "varying " << coordPrecName << " float v_lodBias;\n";
4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Uniforms
4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	op << "uniform lowp " << glu::getDataTypeName(samplerType) << " u_sampler;\n";
4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vert << "\nvoid main()\n{\n"
4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		 << "\tgl_Position = a_position;\n";
4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	frag << "\nvoid main()\n{\n";
4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (isVtxCase)
4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vert << "\tv_color = ";
4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		frag << "\tgl_FragColor = ";
4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Op.
4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*	texCoord	= isVtxCase ? "a_in0" : "v_texCoord";
5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*	lodBias		= isVtxCase ? "a_in1" : "v_lodBias";
5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << baseFuncName << funcExt;
5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << "(u_sampler, " << texCoord;
5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (functionHasLod(function) || m_lookupSpec.useBias)
5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			op << ", " << lodBias;
5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << ");\n";
5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (isVtxCase)
5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		frag << "\tgl_FragColor = v_color;\n";
5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vert << "\tv_texCoord = a_in0;\n";
5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (hasLodBias)
5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			vert << "\tv_lodBias = a_in1;\n";
5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vert << "}\n";
5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	frag << "}\n";
5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_vertShaderSource = vert.str();
5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_fragShaderSource = frag.str();
5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ShaderTextureFunctionCase::deinit (void)
5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gls::ShaderRenderCase::deinit();
5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_texture2D;
5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_textureCube;
5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_texture2D			= DE_NULL;
5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_textureCube		= DE_NULL;
5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ShaderTextureFunctionCase::setupUniforms (int programID, const tcu::Vec4&)
5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_renderCtx.getFunctions();
5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniform1i(gl.getUniformLocation(programID, "u_sampler"), 0);
5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5453c827367444ee418f129b2c238299f49d3264554Jarkko PoyryShaderTextureFunctionTests::ShaderTextureFunctionTests (Context& context)
5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(context, "texture_functions", "Texture Access Function Tests")
5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5503c827367444ee418f129b2c238299f49d3264554Jarkko PoyryShaderTextureFunctionTests::~ShaderTextureFunctionTests (void)
5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct TexFuncCaseSpec
5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*			name;
5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureLookupSpec	lookupSpec;
5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureSpec			texSpec;
5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TexEvalFunc			evalFunc;
5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define CASE_SPEC(NAME, FUNC, MINCOORD, MAXCOORD, USEBIAS, MINLOD, MAXLOD, TEXSPEC, EVALFUNC) \
5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{ #NAME, TextureLookupSpec(FUNC, MINCOORD, MAXCOORD, USEBIAS, MINLOD, MAXLOD), TEXSPEC, EVALFUNC }
5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void createCaseGroup (TestCaseGroup* parent, const char* groupName, const char* groupDesc, const TexFuncCaseSpec* cases, int numCases, bool isVertex)
5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TestCaseGroup* group = new tcu::TestCaseGroup(parent->getTestContext(), groupName, groupDesc);
5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	parent->addChild(group);
5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < numCases; ndx++)
5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		group->addChild(new ShaderTextureFunctionCase(parent->getContext(), cases[ndx].name, "", cases[ndx].lookupSpec, cases[ndx].texSpec, cases[ndx].evalFunc, isVertex));
5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ShaderTextureFunctionTests::init (void)
5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Samplers
5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const tcu::Sampler	samplerLinearNoMipmap	(tcu::Sampler::REPEAT_GL, tcu::Sampler::REPEAT_GL, tcu::Sampler::REPEAT_GL,
5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														 tcu::Sampler::LINEAR, tcu::Sampler::LINEAR);
5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const tcu::Sampler	samplerLinearMipmap		(tcu::Sampler::REPEAT_GL, tcu::Sampler::REPEAT_GL, tcu::Sampler::REPEAT_GL,
5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														 tcu::Sampler::LINEAR_MIPMAP_NEAREST, tcu::Sampler::LINEAR);
5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Default textures.
5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	//												Type			Format		DataType			W		H		L	Sampler
5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const TextureSpec tex2D			(TEXTURETYPE_2D,		GL_RGBA,	GL_UNSIGNED_BYTE,	256,	256,	1,	samplerLinearNoMipmap);
5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const TextureSpec tex2DMipmap	(TEXTURETYPE_2D,		GL_RGBA,	GL_UNSIGNED_BYTE,	256,	256,	9,	samplerLinearMipmap);
5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const TextureSpec texCube		(TEXTURETYPE_CUBE_MAP,	GL_RGBA,	GL_UNSIGNED_BYTE,	256,	256,	1,	samplerLinearNoMipmap);
5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const TextureSpec texCubeMipmap	(TEXTURETYPE_CUBE_MAP,	GL_RGBA,	GL_UNSIGNED_BYTE,	256,	256,	9,	samplerLinearMipmap);
5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Vertex cases
5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const TexFuncCaseSpec vertexCases[] =
5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		//		  Name						Function					MinCoord							MaxCoord							Bias?	MinLod	MaxLod	Texture			EvalFunc
5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_SPEC(texture2d,				FUNCTION_TEXTURE,			Vec4(-0.2f, -0.4f,  0.0f,  0.0f),	Vec4( 1.5f,  2.3f,  0.0f,  0.0f),	false,	0.0f,	0.0f,	tex2D,			evalTexture2D),
5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//		CASE_SPEC(texture2d_bias,			FUNCTION_TEXTURE,			Vec4(-0.2f, -0.4f,  0.0f,  0.0f),	Vec4( 1.5f,  2.3f,  0.0f,  0.0f),	true,	-2.0f,	2.0f,	tex2D,			evalTexture2DBias),
5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_SPEC(texture2dproj_vec3,		FUNCTION_TEXTUREPROJ3,		Vec4(-0.3f, -0.6f,  1.5f,  0.0f),	Vec4(2.25f, 3.45f,  1.5f,  0.0f),	false,	0.0f,	0.0f,	tex2D,			evalTexture2DProj3),
5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_SPEC(texture2dproj_vec4,		FUNCTION_TEXTUREPROJ,		Vec4(-0.3f, -0.6f,  0.0f,  1.5f),	Vec4(2.25f, 3.45f,  0.0f,  1.5f),	false,	0.0f,	0.0f,	tex2D,			evalTexture2DProj),
5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_SPEC(texture2dlod,				FUNCTION_TEXTURELOD,		Vec4(-0.2f, -0.4f,  0.0f,  0.0f),	Vec4( 1.5f,  2.3f,  0.0f,  0.0f),	false,	-1.0f,	9.0f,	tex2DMipmap,	evalTexture2DLod),
5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//		CASE_SPEC(texture2dproj_vec3_bias,	FUNCTION_TEXTUREPROJ3,		Vec4(-0.3f, -0.6f,  1.5f,  0.0f),	Vec4(2.25f, 3.45f,  1.5f,  0.0f),	true,	-2.0f,	2.0f,	tex2D,			evalTexture2DProj3Bias),
6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//		CASE_SPEC(texture2dproj_vec4_bias,	FUNCTION_TEXTUREPROJ,		Vec4(-0.3f, -0.6f,  0.0f,  1.5f),	Vec4(2.25f, 3.45f,  0.0f,  1.5f),	true,	-2.0f,	2.0f,	tex2D,			evalTexture2DProjBias),
6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_SPEC(texture2dprojlod_vec3,	FUNCTION_TEXTUREPROJLOD3,	Vec4(-0.3f, -0.6f,  1.5f,  0.0f),	Vec4(2.25f, 3.45f,  1.5f,  0.0f),	false,	-1.0f,	9.0f,	tex2D,			evalTexture2DProjLod3),
6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_SPEC(texture2dprojlod_vec4,	FUNCTION_TEXTUREPROJLOD,	Vec4(-0.3f, -0.6f,  0.0f,  1.5f),	Vec4(2.25f, 3.45f,  0.0f,  1.5f),	false,	-1.0f,	9.0f,	tex2D,			evalTexture2DProjLod),
6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_SPEC(texturecube,				FUNCTION_TEXTURE,			Vec4(-1.0f, -1.0f,  1.01f,  0.0f),	Vec4( 1.0f,  1.0f,  1.01f,  0.0f),	false,	0.0f,	0.0f,	texCube,		evalTextureCube),
6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//		CASE_SPEC(texturecube_bias,			FUNCTION_TEXTURE,			Vec4(-1.0f, -1.0f, -1.01f,  0.0f),	Vec4( 1.0f,  1.0f, -1.01f,  0.0f),	true,	-2.0f,	2.0f,	texCube,		evalTextureCubeBias),
6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_SPEC(texturecubelod,			FUNCTION_TEXTURELOD,		Vec4(-1.0f, -1.0f,  1.01f,  0.0f),	Vec4( 1.0f,  1.0f,  1.01f,  0.0f),	false,	-1.0f,	9.0f,	texCubeMipmap,	evalTextureCubeLod),
6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createCaseGroup(this, "vertex", "Vertex Shader Texture Lookups", &vertexCases[0], DE_LENGTH_OF_ARRAY(vertexCases), true);
6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Fragment cases
6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const TexFuncCaseSpec fragmentCases[] =
6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		//		  Name						Function				MinCoord							MaxCoord							Bias?	MinLod	MaxLod	Texture			EvalFunc
6133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_SPEC(texture2d,				FUNCTION_TEXTURE,		Vec4(-0.2f, -0.4f,  0.0f,  0.0f),	Vec4( 1.5f,  2.3f,  0.0f,  0.0f),	false,	0.0f,	0.0f,	tex2DMipmap,	evalTexture2D),
6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_SPEC(texture2d_bias,			FUNCTION_TEXTURE,		Vec4(-0.2f, -0.4f,  0.0f,  0.0f),	Vec4( 1.5f,  2.3f,  0.0f,  0.0f),	true,	-2.0f,	2.0f,	tex2DMipmap,	evalTexture2DBias),
6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_SPEC(texture2dproj_vec3,		FUNCTION_TEXTUREPROJ3,	Vec4(-0.3f, -0.6f,  1.5f,  0.0f),	Vec4(2.25f, 3.45f,  1.5f,  0.0f),	false,	0.0f,	0.0f,	tex2DMipmap,	evalTexture2DProj3),
6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_SPEC(texture2dproj_vec4,		FUNCTION_TEXTUREPROJ,	Vec4(-0.3f, -0.6f,  0.0f,  1.5f),	Vec4(2.25f, 3.45f,  0.0f,  1.5f),	false,	0.0f,	0.0f,	tex2DMipmap,	evalTexture2DProj),
6173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_SPEC(texture2dproj_vec3_bias,	FUNCTION_TEXTUREPROJ3,	Vec4(-0.3f, -0.6f,  1.5f,  0.0f),	Vec4(2.25f, 3.45f,  1.5f,  0.0f),	true,	-2.0f,	2.0f,	tex2DMipmap,	evalTexture2DProj3Bias),
6183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_SPEC(texture2dproj_vec4_bias,	FUNCTION_TEXTUREPROJ,	Vec4(-0.3f, -0.6f,  0.0f,  1.5f),	Vec4(2.25f, 3.45f,  0.0f,  1.5f),	true,	-2.0f,	2.0f,	tex2DMipmap,	evalTexture2DProjBias),
6193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_SPEC(texturecube,				FUNCTION_TEXTURE,		Vec4(-1.0f, -1.0f,  1.01f,  0.0f),	Vec4( 1.0f,  1.0f,  1.01f,  0.0f),	false,	0.0f,	0.0f,	texCubeMipmap,	evalTextureCube),
6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_SPEC(texturecube_bias,			FUNCTION_TEXTURE,		Vec4(-1.0f, -1.0f, -1.01f,  0.0f),	Vec4( 1.0f,  1.0f, -1.01f,  0.0f),	true,	-2.0f,	2.0f,	texCubeMipmap,	evalTextureCubeBias)
6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createCaseGroup(this, "fragment", "Fragment Shader Texture Lookups", &fragmentCases[0], DE_LENGTH_OF_ARRAY(fragmentCases), false);
6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Negative cases.
6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gls::ShaderLibrary library(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo());
6273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::vector<tcu::TestNode*> negativeCases = library.loadShaderFile("shaders/invalid_texture_functions.test");
6283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestCaseGroup* group = new tcu::TestCaseGroup(m_testCtx, "invalid", "Invalid texture function usage", negativeCases);
6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(group);
6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional
6353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles3
6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
637