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 Mipmapping accuracy tests.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es3aTextureMipmapTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsTextureTestUtil.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTexture.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTextureUtil.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuMatrix.hpp"
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuMatrixUtil.hpp"
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp"
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.hpp"
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h"
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp"
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp"
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles3
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Accuracy
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string;
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector;
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog;
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec2;
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec3;
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec4;
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::IVec4;
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace gls::TextureTestUtil;
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum CoordType
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	COORDTYPE_BASIC,		//!< texCoord = translateScale(position).
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	COORDTYPE_BASIC_BIAS,	//!< Like basic, but with bias values.
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	COORDTYPE_AFFINE,		//!< texCoord = translateScaleRotateShear(position).
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	COORDTYPE_PROJECTED,	//!< Projected coordinates, w != 1
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	COORDTYPE_LAST
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Texture2DMipmapCase
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Texture2DMipmapCase : public tcu::TestCase
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								Texture2DMipmapCase			(tcu::TestContext&			testCtx,
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 glu::RenderContext&		renderCtx,
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 const glu::ContextInfo&	renderCtxInfo,
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 const char*				name,
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 const char*				desc,
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 CoordType					coordType,
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 deUint32					minFilter,
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 deUint32					wrapS,
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 deUint32					wrapT,
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 deUint32					format,
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 deUint32					dataType,
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 int						width,
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 int						height);
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								~Texture2DMipmapCase		(void);
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void						init						(void);
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void						deinit						(void);
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult				iterate						(void);
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								Texture2DMipmapCase			(const Texture2DMipmapCase& other);
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Texture2DMipmapCase&		operator=					(const Texture2DMipmapCase& other);
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::RenderContext&			m_renderCtx;
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glu::ContextInfo&		m_renderCtxInfo;
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	CoordType					m_coordType;
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_minFilter;
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_wrapS;
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_wrapT;
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_format;
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_dataType;
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int							m_width;
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int							m_height;
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::Texture2D*				m_texture;
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureRenderer				m_renderer;
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1123c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2DMipmapCase::Texture2DMipmapCase (tcu::TestContext&			testCtx,
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										  glu::RenderContext&		renderCtx,
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										  const glu::ContextInfo&	renderCtxInfo,
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										  const char*				name,
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										  const char*				desc,
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										  CoordType					coordType,
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										  deUint32					minFilter,
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										  deUint32					wrapS,
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										  deUint32					wrapT,
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										  deUint32					format,
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										  deUint32					dataType,
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										  int						width,
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										  int						height)
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase			(testCtx, tcu::NODETYPE_ACCURACY, name, desc)
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_renderCtx		(renderCtx)
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_renderCtxInfo	(renderCtxInfo)
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_coordType		(coordType)
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_minFilter		(minFilter)
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_wrapS			(wrapS)
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_wrapT			(wrapT)
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_format			(format)
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_dataType		(dataType)
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_width			(width)
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_height			(height)
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_texture			(DE_NULL)
137469002caa1ccd58f59f53a1bf3dbac4cf6a5d817Jarkko Pöyry	, m_renderer		(renderCtx, testCtx.getLog(), glu::GLSL_VERSION_300_ES, glu::PRECISION_HIGHP)
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1413c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2DMipmapCase::~Texture2DMipmapCase (void)
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deinit();
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DMipmapCase::init (void)
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_texture = new glu::Texture2D(m_renderCtx, m_format, m_dataType, m_width, m_height);
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int numLevels = deLog2Floor32(de::max(m_width, m_height))+1;
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Fill texture with colored grid.
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32	step		= 0xff / (numLevels-1);
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32	inc			= deClamp32(step*levelNdx, 0x00, 0xff);
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32	dec			= 0xff - inc;
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32	rgb			= (inc << 16) | (dec << 8) | 0xff;
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32	color		= 0xff000000 | rgb;
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_texture->getRefTexture().allocLevel(levelNdx);
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::clear(m_texture->getRefTexture().getLevel(levelNdx), toVec4(tcu::RGBA(color)));
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DMipmapCase::deinit (void)
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_texture;
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_texture = DE_NULL;
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_renderer.clear();
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void getBasicTexCoord2D (std::vector<float>& dst, int cellNdx)
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Vec2 bottomLeft;
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Vec2 topRight;
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} s_basicCoords[] =
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ Vec2(-0.1f,  0.1f), Vec2( 0.8f,  1.0f) },
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ Vec2(-0.3f, -0.6f), Vec2( 0.7f,  0.4f) },
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ Vec2(-0.3f,  0.6f), Vec2( 0.7f, -0.9f) },
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ Vec2(-0.8f,  0.6f), Vec2( 0.7f, -0.9f) },
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ Vec2(-0.5f, -0.5f), Vec2( 1.5f,  1.5f) },
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ Vec2( 1.0f, -1.0f), Vec2(-1.3f,  1.0f) },
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ Vec2( 1.2f, -1.0f), Vec2(-1.3f,  1.6f) },
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ Vec2( 2.2f, -1.1f), Vec2(-1.3f,  0.8f) },
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ Vec2(-1.5f,  1.6f), Vec2( 1.7f, -1.4f) },
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ Vec2( 2.0f,  1.6f), Vec2( 2.3f, -1.4f) },
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ Vec2( 1.3f, -2.6f), Vec2(-2.7f,  2.9f) },
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ Vec2(-0.8f, -6.6f), Vec2( 6.0f, -0.9f) },
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ Vec2( -8.0f,   9.0f), Vec2(  8.3f,  -7.0f) },
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ Vec2(-16.0f,  10.0f), Vec2( 18.3f,  24.0f) },
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ Vec2( 30.2f,  55.0f), Vec2(-24.3f,  -1.6f) },
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ Vec2(-33.2f,  64.1f), Vec2( 32.1f, -64.1f) },
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(de::inBounds(cellNdx, 0, DE_LENGTH_OF_ARRAY(s_basicCoords)));
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const Vec2& bottomLeft	= s_basicCoords[cellNdx].bottomLeft;
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const Vec2& topRight	= s_basicCoords[cellNdx].topRight;
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	computeQuadTexCoord2D(dst, bottomLeft, topRight);
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void getAffineTexCoord2D (std::vector<float>& dst, int cellNdx)
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Use basic coords as base.
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	getBasicTexCoord2D(dst, cellNdx);
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Rotate based on cell index.
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float		angle		= 2.0f*DE_PI * ((float)cellNdx / 16.0f);
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Mat2	rotMatrix	= tcu::rotationMatrix(angle);
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Second and third row are sheared.
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float		shearX		= de::inRange(cellNdx, 4, 11) ? (float)(15-cellNdx) / 16.0f : 0.0f;
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Mat2	shearMatrix	= tcu::shearMatrix(tcu::Vec2(shearX, 0.0f));
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Mat2	transform	= rotMatrix * shearMatrix;
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vec2		p0			= transform * Vec2(dst[0], dst[1]);
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vec2		p1			= transform * Vec2(dst[2], dst[3]);
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vec2		p2			= transform * Vec2(dst[4], dst[5]);
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vec2		p3			= transform * Vec2(dst[6], dst[7]);
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst[0] = p0.x();	dst[1] = p0.y();
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst[2] = p1.x();	dst[3] = p1.y();
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst[4] = p2.x();	dst[5] = p2.y();
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst[6] = p3.x();	dst[7] = p3.y();
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2363c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2DMipmapCase::IterateResult Texture2DMipmapCase::iterate (void)
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Constants.
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32				magFilter			= GL_NEAREST;
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&		gl					= m_renderCtx.getFunctions();
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestLog&					log					= m_testCtx.getLog();
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Texture2D&		refTexture			= m_texture->getRefTexture();
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::TextureFormat&	texFmt				= refTexture.getFormat();
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureFormatInfo		fmtInfo				= tcu::getTextureFormatInfo(texFmt);
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int							texWidth			= refTexture.getWidth();
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int							texHeight			= refTexture.getHeight();
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int							defViewportWidth	= texWidth*4;
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int							defViewportHeight	= texHeight*4;
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RandomViewport				viewport			(m_renderCtx.getRenderTarget(), defViewportWidth, defViewportHeight, deStringHash(getName()));
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ReferenceParams				sampleParams		(TEXTURETYPE_2D);
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<float>				texCoord;
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool						isProjected			= m_coordType == COORDTYPE_PROJECTED;
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool						useLodBias			= m_coordType == COORDTYPE_BASIC_BIAS;
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface				renderedFrame		(viewport.width, viewport.height);
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Accuracy cases test against ideal lod computation.
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface				idealFrame			(viewport.width, viewport.height);
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Viewport is divided into 4x4 grid.
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int							gridWidth			= 4;
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int							gridHeight			= 4;
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int							cellWidth			= viewport.width / gridWidth;
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int							cellHeight			= viewport.height / gridHeight;
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Accuracy measurements are off unless we get the expected viewport size.
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (viewport.width < defViewportWidth || viewport.height < defViewportHeight)
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::NotSupportedError("Too small viewport", "", __FILE__, __LINE__);
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Sampling parameters.
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sampleParams.sampler		= glu::mapGLSampler(m_wrapS, m_wrapT, m_minFilter, magFilter);
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sampleParams.samplerType	= gls::TextureTestUtil::getSamplerType(m_texture->getRefTexture().getFormat());
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sampleParams.colorBias		= fmtInfo.lookupBias;
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sampleParams.colorScale		= fmtInfo.lookupScale;
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sampleParams.flags			= (isProjected ? ReferenceParams::PROJECTED : 0) | (useLodBias ? ReferenceParams::USE_BIAS : 0);
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Upload texture data.
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_texture->upload();
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Use unit 0.
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.activeTexture(GL_TEXTURE0);
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Bind gradient texture and setup sampler parameters.
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindTexture(GL_TEXTURE_2D, m_texture->getGLTexture());
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,		m_wrapS);
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,		m_wrapT);
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,	m_minFilter);
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,	magFilter);
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "After texture setup");
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Bias values.
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const float s_bias[] = { 1.0f, -2.0f, 0.8f, -0.5f, 1.5f, 0.9f, 2.0f, 4.0f };
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Projection values.
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const Vec4 s_projections[] =
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Vec4(1.2f, 1.0f, 0.7f, 1.0f),
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Vec4(1.3f, 0.8f, 0.6f, 2.0f),
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Vec4(0.8f, 1.0f, 1.7f, 0.6f),
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Vec4(1.2f, 1.0f, 1.7f, 1.5f)
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render cells.
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int gridY = 0; gridY < gridHeight; gridY++)
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int gridX = 0; gridX < gridWidth; gridX++)
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int				curX		= cellWidth*gridX;
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int				curY		= cellHeight*gridY;
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int				curW		= gridX+1 == gridWidth ? (viewport.width-curX) : cellWidth;
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int				curH		= gridY+1 == gridHeight ? (viewport.height-curY) : cellHeight;
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int				cellNdx		= gridY*gridWidth + gridX;
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Compute texcoord.
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			switch (m_coordType)
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case COORDTYPE_BASIC_BIAS:	// Fall-through.
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case COORDTYPE_PROJECTED:
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case COORDTYPE_BASIC:		getBasicTexCoord2D	(texCoord, cellNdx);	break;
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case COORDTYPE_AFFINE:		getAffineTexCoord2D	(texCoord, cellNdx);	break;
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				default:					DE_ASSERT(DE_FALSE);
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (isProjected)
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				sampleParams.w = s_projections[cellNdx % DE_LENGTH_OF_ARRAY(s_projections)];
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (useLodBias)
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				sampleParams.bias = s_bias[cellNdx % DE_LENGTH_OF_ARRAY(s_bias)];
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Render with GL.
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.viewport(viewport.x+curX, viewport.y+curY, curW, curH);
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_renderer.renderQuad(0, &texCoord[0], sampleParams);
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Render reference(s).
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				SurfaceAccess idealDst(idealFrame, m_renderCtx.getRenderTarget().getPixelFormat(), curX, curY, curW, curH);
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				sampleParams.lodMode = LODMODE_EXACT;
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				sampleTexture(idealDst, m_texture->getRefTexture(), &texCoord[0], sampleParams);
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Read result.
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Compare and log.
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int	bestScoreDiff	= (texWidth/16)*(texHeight/16);
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int	worstScoreDiff	= texWidth*texHeight;
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int score = measureAccuracy(log, idealFrame, renderedFrame, bestScoreDiff, worstScoreDiff);
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::toString(score).c_str());
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// TextureCubeMipmapCase
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TextureCubeMipmapCase : public tcu::TestCase
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								TextureCubeMipmapCase		(tcu::TestContext&			testCtx,
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 glu::RenderContext&		renderCtx,
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 const glu::ContextInfo&	renderCtxInfo,
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 const char*				name,
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 const char*				desc,
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 CoordType					coordType,
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 deUint32					minFilter,
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 deUint32					wrapS,
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 deUint32					wrapT,
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 deUint32					format,
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 deUint32					dataType,
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 int						size);
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								~TextureCubeMipmapCase		(void);
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void						init						(void);
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void						deinit						(void);
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult				iterate						(void);
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								TextureCubeMipmapCase		(const TextureCubeMipmapCase& other);
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureCubeMipmapCase&		operator=					(const TextureCubeMipmapCase& other);
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::RenderContext&			m_renderCtx;
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glu::ContextInfo&		m_renderCtxInfo;
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	CoordType					m_coordType;
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_minFilter;
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_wrapS;
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_wrapT;
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_format;
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_dataType;
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int							m_size;
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::TextureCube*			m_texture;
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureRenderer				m_renderer;
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4073c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCubeMipmapCase::TextureCubeMipmapCase (tcu::TestContext&			testCtx,
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  glu::RenderContext&		renderCtx,
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  const glu::ContextInfo&	renderCtxInfo,
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  const char*				name,
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  const char*				desc,
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  CoordType					coordType,
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  deUint32					minFilter,
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  deUint32					wrapS,
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  deUint32					wrapT,
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  deUint32					format,
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  deUint32					dataType,
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  int						size)
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase			(testCtx, tcu::NODETYPE_ACCURACY, name, desc)
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_renderCtx		(renderCtx)
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_renderCtxInfo	(renderCtxInfo)
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_coordType		(coordType)
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_minFilter		(minFilter)
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_wrapS			(wrapS)
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_wrapT			(wrapT)
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_format			(format)
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_dataType		(dataType)
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_size			(size)
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_texture			(DE_NULL)
430469002caa1ccd58f59f53a1bf3dbac4cf6a5d817Jarkko Pöyry	, m_renderer		(renderCtx, testCtx.getLog(), glu::GLSL_VERSION_300_ES, glu::PRECISION_HIGHP)
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4343c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCubeMipmapCase::~TextureCubeMipmapCase (void)
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deinit();
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureCubeMipmapCase::init (void)
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_texture = new glu::TextureCube(m_renderCtx, m_format, m_dataType, m_size);
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int numLevels = deLog2Floor32(m_size)+1;
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Fill texture with colored grid.
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int faceNdx = 0; faceNdx < tcu::CUBEFACE_LAST; faceNdx++)
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint32	step		= 0xff / (numLevels-1);
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint32	inc			= deClamp32(step*levelNdx, 0x00, 0xff);
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint32	dec			= 0xff - inc;
4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint32	rgb			= 0;
4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			switch (faceNdx)
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case 0: rgb = (inc << 16) | (dec << 8) | 255; break;
4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case 1: rgb = (255 << 16) | (inc << 8) | dec; break;
4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case 2: rgb = (dec << 16) | (255 << 8) | inc; break;
4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case 3: rgb = (dec << 16) | (inc << 8) | 255; break;
4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case 4: rgb = (255 << 16) | (dec << 8) | inc; break;
4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case 5: rgb = (inc << 16) | (255 << 8) | dec; break;
4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint32	color		= 0xff000000 | rgb;
4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_texture->getRefTexture().allocLevel((tcu::CubeFace)faceNdx, levelNdx);
4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::clear(m_texture->getRefTexture().getLevelFace(levelNdx, (tcu::CubeFace)faceNdx), toVec4(tcu::RGBA(color)));
4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureCubeMipmapCase::deinit (void)
4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_texture;
4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_texture = DE_NULL;
4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_renderer.clear();
4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void randomPartition (vector<IVec4>& dst, de::Random& rnd, int x, int y, int width, int height)
4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int minWidth	= 8;
4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int minHeight	= 8;
4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool	partition		= rnd.getFloat() > 0.4f;
4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool	partitionX		= partition && width > minWidth && rnd.getBool();
4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool	partitionY		= partition && height > minHeight && !partitionX;
4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (partitionX)
4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int split = width/2 + rnd.getInt(-width/4, +width/4);
4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		randomPartition(dst, rnd, x, y, split, height);
4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		randomPartition(dst, rnd, x+split, y, width-split, height);
4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (partitionY)
4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int split = height/2 + rnd.getInt(-height/4, +height/4);
4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		randomPartition(dst, rnd, x, y, width, split);
5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		randomPartition(dst, rnd, x, y+split, width, height-split);
5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		dst.push_back(IVec4(x, y, width, height));
5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void computeGridLayout (vector<IVec4>& dst, int width, int height)
5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	de::Random rnd(7);
5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	randomPartition(dst, rnd, 0, 0, width, height);
5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5123c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCubeMipmapCase::IterateResult TextureCubeMipmapCase::iterate (void)
5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Constants.
5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32			magFilter			= GL_NEAREST;
5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						texWidth			= m_texture->getRefTexture().getSize();
5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						texHeight			= m_texture->getRefTexture().getSize();
5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						defViewportWidth	= texWidth*2;
5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						defViewportHeight	= texHeight*2;
5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl					= m_renderCtx.getFunctions();
5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestLog&				log					= m_testCtx.getLog();
5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RandomViewport			viewport			(m_renderCtx.getRenderTarget(), defViewportWidth, defViewportHeight, deStringHash(getName()));
5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Sampler			sampler				= glu::mapGLSampler(m_wrapS, m_wrapT, m_minFilter, magFilter);
5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sampler.seamlessCubeMap = true;
5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<float>			texCoord;
5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool					isProjected			= m_coordType == COORDTYPE_PROJECTED;
5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool					useLodBias			= m_coordType == COORDTYPE_BASIC_BIAS;
5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface			renderedFrame		(viewport.width, viewport.height);
5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Accuracy cases test against ideal lod computation.
5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface			idealFrame			(viewport.width, viewport.height);
5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Accuracy measurements are off unless we get the expected viewport size.
5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (viewport.width < defViewportWidth || viewport.height < defViewportHeight)
5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::NotSupportedError("Too small viewport", "", __FILE__, __LINE__);
5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Upload texture data.
5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_texture->upload();
5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Use unit 0.
5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.activeTexture(GL_TEXTURE0);
5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Bind gradient texture and setup sampler parameters.
5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindTexture(GL_TEXTURE_CUBE_MAP, m_texture->getGLTexture());
5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S,		m_wrapS);
5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T,		m_wrapT);
5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER,	m_minFilter);
5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER,	magFilter);
5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "After texture setup");
5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Compute grid.
5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<IVec4> gridLayout;
5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	computeGridLayout(gridLayout, viewport.width, viewport.height);
5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Bias values.
5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const float s_bias[] = { 1.0f, -2.0f, 0.8f, -0.5f, 1.5f, 0.9f, 2.0f, 4.0f };
5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Projection values \note Less agressive than in 2D case due to smaller quads.
5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const Vec4 s_projections[] =
5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Vec4(1.2f, 1.0f, 0.7f, 1.0f),
5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Vec4(1.3f, 0.8f, 0.6f, 1.1f),
5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Vec4(0.8f, 1.0f, 1.2f, 0.8f),
5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Vec4(1.2f, 1.0f, 1.3f, 0.9f)
5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int cellNdx = 0; cellNdx < (int)gridLayout.size(); cellNdx++)
5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int				curX		= gridLayout[cellNdx].x();
5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int				curY		= gridLayout[cellNdx].y();
5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int				curW		= gridLayout[cellNdx].z();
5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int				curH		= gridLayout[cellNdx].w();
5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::CubeFace	cubeFace	= (tcu::CubeFace)(cellNdx % tcu::CUBEFACE_LAST);
5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ReferenceParams	params		(TEXTURETYPE_CUBE);
5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params.sampler = sampler;
5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(m_coordType != COORDTYPE_AFFINE); // Not supported.
5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		computeQuadTexCoordCube(texCoord, cubeFace);
5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (isProjected)
5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.flags	|= ReferenceParams::PROJECTED;
5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.w		 = s_projections[cellNdx % DE_LENGTH_OF_ARRAY(s_projections)];
5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (useLodBias)
5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.flags	|= ReferenceParams::USE_BIAS;
5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.bias		 = s_bias[cellNdx % DE_LENGTH_OF_ARRAY(s_bias)];
5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Render with GL.
6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.viewport(viewport.x+curX, viewport.y+curY, curW, curH);
6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_renderer.renderQuad(0, &texCoord[0], params);
6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Render reference(s).
6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			SurfaceAccess idealDst(idealFrame, m_renderCtx.getRenderTarget().getPixelFormat(), curX, curY, curW, curH);
6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.lodMode = LODMODE_EXACT;
6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			sampleTexture(idealDst, m_texture->getRefTexture(), &texCoord[0], params);
6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Read result.
6133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Compare and log.
6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int	bestScoreDiff	= (texWidth/16)*(texHeight/16);
6183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int	worstScoreDiff	= texWidth*texHeight;
6193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int score = measureAccuracy(log, idealFrame, renderedFrame, bestScoreDiff, worstScoreDiff);
6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::toString(score).c_str());
6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6273c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureMipmapTests::TextureMipmapTests (Context& context)
6283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(context, "mipmap", "Mipmapping accuracy tests")
6293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6323c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureMipmapTests::~TextureMipmapTests (void)
6333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureMipmapTests::init (void)
6373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TestCaseGroup* group2D		= new tcu::TestCaseGroup(m_testCtx, "2d",	"2D Texture Mipmapping");
6393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TestCaseGroup*	groupCube	= new tcu::TestCaseGroup(m_testCtx, "cube",	"Cube Map Filtering");
6403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(group2D);
6413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(groupCube);
6423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
6443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		name;
6463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		mode;
6473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} wrapModes[] =
6483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "clamp",		GL_CLAMP_TO_EDGE },
6503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "repeat",		GL_REPEAT },
6513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "mirror",		GL_MIRRORED_REPEAT }
6523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
6533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
6553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		name;
6573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		mode;
6583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} minFilterModes[] =
6593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "nearest_nearest",	GL_NEAREST_MIPMAP_NEAREST	},
6613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "linear_nearest",		GL_LINEAR_MIPMAP_NEAREST	},
6623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "nearest_linear",		GL_NEAREST_MIPMAP_LINEAR	},
6633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "linear_linear",		GL_LINEAR_MIPMAP_LINEAR		}
6643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
6653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
6673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CoordType		type;
6693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		name;
6703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		desc;
6713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} coordTypes[] =
6723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ COORDTYPE_BASIC,		"basic",		"Mipmapping with translated and scaled coordinates" },
6743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ COORDTYPE_AFFINE,		"affine",		"Mipmapping with affine coordinate transform"		},
6753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ COORDTYPE_PROJECTED,	"projected",	"Mipmapping with perspective projection"			}
6763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
6773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int tex2DWidth	= 64;
6793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int tex2DHeight	= 64;
6803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// 2D cases.
6823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int coordType = 0; coordType < DE_LENGTH_OF_ARRAY(coordTypes); coordType++)
6833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestCaseGroup* coordTypeGroup = new tcu::TestCaseGroup(m_testCtx, coordTypes[coordType].name, coordTypes[coordType].desc);
6853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		group2D->addChild(coordTypeGroup);
6863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int minFilter = 0; minFilter < DE_LENGTH_OF_ARRAY(minFilterModes); minFilter++)
6883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
6893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int wrapMode = 0; wrapMode < DE_LENGTH_OF_ARRAY(wrapModes); wrapMode++)
6903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
6913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				std::ostringstream name;
6923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				name << minFilterModes[minFilter].name
6933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						<< "_" << wrapModes[wrapMode].name;
6943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				coordTypeGroup->addChild(new Texture2DMipmapCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(),
6963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																	name.str().c_str(), "",
6973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																	coordTypes[coordType].type,
6983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																	minFilterModes[minFilter].mode,
6993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																	wrapModes[wrapMode].mode,
7003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																	wrapModes[wrapMode].mode,
7013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																	GL_RGBA, GL_UNSIGNED_BYTE,
7023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																	tex2DWidth, tex2DHeight));
7033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
7043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
7053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
7063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int cubeMapSize = 64;
7083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
7103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CoordType		type;
7123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		name;
7133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		desc;
7143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} cubeCoordTypes[] =
7153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ COORDTYPE_BASIC,		"basic",		"Mipmapping with translated and scaled coordinates" },
7173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ COORDTYPE_PROJECTED,	"projected",	"Mipmapping with perspective projection"			}
7183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
7193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Cubemap cases.
7213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int coordType = 0; coordType < DE_LENGTH_OF_ARRAY(cubeCoordTypes); coordType++)
7223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestCaseGroup* coordTypeGroup = new tcu::TestCaseGroup(m_testCtx, cubeCoordTypes[coordType].name, cubeCoordTypes[coordType].desc);
7243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		groupCube->addChild(coordTypeGroup);
7253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int minFilter = 0; minFilter < DE_LENGTH_OF_ARRAY(minFilterModes); minFilter++)
7273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
7283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			coordTypeGroup->addChild(new TextureCubeMipmapCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(),
7293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															   minFilterModes[minFilter].name, "",
7303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															   cubeCoordTypes[coordType].type,
7313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															   minFilterModes[minFilter].mode,
7323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															   GL_CLAMP_TO_EDGE,
7333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															   GL_CLAMP_TO_EDGE,
7343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															   GL_RGBA, GL_UNSIGNED_BYTE, cubeMapSize));
7353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
7363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
7373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Accuracy
7403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles3
7413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
742