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 wrap mode tests.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es2fTextureWrapTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsTextureTestUtil.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTexture.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluStrUtil.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTextureUtil.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp"
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp"
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp"
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles2
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog;
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector;
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string;
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Sampler;
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace glu;
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace gls::TextureTestUtil;
49c4eb6f3271a0bcd54835e666e836e3e72beebbd2Peter Siketusing namespace glu::TextureTestUtil;
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VIEWPORT_WIDTH		= 256,
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VIEWPORT_HEIGHT		= 256
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TextureWrapCase : public tcu::TestCase
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								TextureWrapCase			(tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* description, deUint32 format, deUint32 dataType, deUint32 wrapS, deUint32 wrapT, deUint32 minFilter, deUint32 magFilter, int width, int height);
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								TextureWrapCase			(tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* description, deUint32 wrapS, deUint32 wrapT, deUint32 minFilter, deUint32 magFilter, const std::vector<std::string>& filenames);
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								~TextureWrapCase		(void);
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void						init					(void);
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void						deinit					(void);
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult				iterate					(void);
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								TextureWrapCase			(const TextureWrapCase& other);
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureWrapCase&			operator=				(const TextureWrapCase& other);
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::RenderContext&			m_renderCtx;
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glu::ContextInfo&		m_renderCtxInfo;
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_format;
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_dataType;
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_wrapS;
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_wrapT;
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_minFilter;
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_magFilter;
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int							m_width;
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int							m_height;
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<std::string>	m_filenames;
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::Texture2D*				m_texture;
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureRenderer				m_renderer;
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
903c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureWrapCase::TextureWrapCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* description, deUint32 format, deUint32 dataType, deUint32 wrapS, deUint32 wrapT, deUint32 minFilter, deUint32 magFilter, int width, int height)
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase			(testCtx, name, description)
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_renderCtx		(renderCtx)
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_renderCtxInfo	(ctxInfo)
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_format			(format)
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_dataType		(dataType)
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_wrapS			(wrapS)
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_wrapT			(wrapT)
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_minFilter		(minFilter)
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_magFilter		(magFilter)
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_width			(width)
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_height			(height)
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_texture			(DE_NULL)
103469002caa1ccd58f59f53a1bf3dbac4cf6a5d817Jarkko Pöyry	, m_renderer		(renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1073c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureWrapCase::TextureWrapCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* description, deUint32 wrapS, deUint32 wrapT, deUint32 minFilter, deUint32 magFilter, const std::vector<std::string>& filenames)
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase			(testCtx, name, description)
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_renderCtx		(renderCtx)
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_renderCtxInfo	(ctxInfo)
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_format			(GL_NONE)
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_dataType		(GL_NONE)
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_wrapS			(wrapS)
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_wrapT			(wrapT)
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_minFilter		(minFilter)
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_magFilter		(magFilter)
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_width			(0)
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_height			(0)
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_filenames		(filenames)
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_texture			(DE_NULL)
121469002caa1ccd58f59f53a1bf3dbac4cf6a5d817Jarkko Pöyry	, m_renderer		(renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1253c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureWrapCase::~TextureWrapCase (void)
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deinit();
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureWrapCase::init (void)
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!m_filenames.empty())
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(m_width == 0 && m_height == 0 && m_format == GL_NONE && m_dataType == GL_NONE);
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_texture	= glu::Texture2D::create(m_renderCtx, m_renderCtxInfo, m_testCtx.getArchive(), (int)m_filenames.size(), m_filenames);
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_width		= m_texture->getRefTexture().getWidth();
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_height	= m_texture->getRefTexture().getHeight();
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_texture = new Texture2D(m_renderCtx, m_format, m_dataType, m_width, m_height);
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Fill level 0.
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_texture->getRefTexture().allocLevel(0);
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::fillWithComponentGradients(m_texture->getRefTexture().getLevel(0), tcu::Vec4(-0.5f, -0.5f, -0.5f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f));
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_texture->upload();
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureWrapCase::deinit (void)
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_texture;
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_texture = DE_NULL;
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_renderer.clear();
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1603c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureWrapCase::IterateResult TextureWrapCase::iterate (void)
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl					= m_renderCtx.getFunctions();
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestLog&				log					= m_testCtx.getLog();
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RandomViewport			viewport			(m_renderCtx.getRenderTarget(), VIEWPORT_WIDTH, VIEWPORT_HEIGHT, deStringHash(getName()));
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface			renderedFrame		(viewport.width, viewport.height);
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface			referenceFrame		(viewport.width, viewport.height);
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool					isCompressedTex		= !m_filenames.empty();
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ReferenceParams			refParams			(TEXTURETYPE_2D);
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						leftWidth			= viewport.width / 2;
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						rightWidth			= viewport.width - leftWidth;
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<float>			texCoord;
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::RGBA				threshold			= m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold()
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												+ (isCompressedTex ? tcu::RGBA(7,7,7,7) : tcu::RGBA(3,3,3,3));
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Bind to unit 0.
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.activeTexture(GL_TEXTURE0);
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindTexture(GL_TEXTURE_2D, m_texture->getGLTexture());
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Setup filtering and wrap modes.
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,		m_wrapS);
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,		m_wrapT);
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,	m_minFilter);
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,	m_magFilter);
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "Set texturing state");
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Parameters for reference images.
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	refParams.sampler	= mapGLSampler(m_wrapS, m_wrapT, m_minFilter, m_magFilter);
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	refParams.lodMode	= LODMODE_EXACT;
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Left: minification
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.viewport(viewport.x, viewport.y, leftWidth, viewport.height);
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		computeQuadTexCoord2D(texCoord, tcu::Vec2(-1.5f, -3.0f), tcu::Vec2(1.5f, 2.5f));
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_renderer.renderQuad(0, &texCoord[0], refParams);
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
200c4eb6f3271a0bcd54835e666e836e3e72beebbd2Peter Siket		sampleTexture(tcu::SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), 0, 0, leftWidth, viewport.height),
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					  m_texture->getRefTexture(), &texCoord[0], refParams);
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Right: magnification
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.viewport(viewport.x+leftWidth, viewport.y, rightWidth, viewport.height);
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		computeQuadTexCoord2D(texCoord, tcu::Vec2(-0.5f, 0.75f), tcu::Vec2(0.25f, 1.25f));
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_renderer.renderQuad(0, &texCoord[0], refParams);
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
213c4eb6f3271a0bcd54835e666e836e3e72beebbd2Peter Siket		sampleTexture(tcu::SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), leftWidth, 0, rightWidth, viewport.height),
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					  m_texture->getRefTexture(), &texCoord[0], refParams);
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Compare and log.
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool isOk = compareImages(log, referenceFrame, renderedFrame, threshold);
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS	: QP_TEST_RESULT_FAIL,
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							isOk ? "Pass"				: "Image comparison failed");
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2263c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureWrapTests::TextureWrapTests (Context& context)
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(context, "wrap", "Wrap Mode Tests")
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2313c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureWrapTests::~TextureWrapTests (void)
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureWrapTests::init (void)
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		name;
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		mode;
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} wrapModes[] =
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "clamp",		GL_CLAMP_TO_EDGE },
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "repeat",		GL_REPEAT },
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "mirror",		GL_MIRRORED_REPEAT }
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		name;
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		mode;
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} filteringModes[] =
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "nearest",	GL_NEAREST },
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "linear",		GL_LINEAR }
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		name;
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int				width;
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int				height;
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} sizes[] =
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "pot",		64, 128 },
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "npot",		63, 112 }
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		name;
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		format;
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		dataType;
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} formats[] =
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "rgba8888",	GL_RGBA,			GL_UNSIGNED_BYTE },
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "rgb888",		GL_RGB,				GL_UNSIGNED_BYTE },
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "rgba4444",	GL_RGBA,			GL_UNSIGNED_SHORT_4_4_4_4 },
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "l8",			GL_LUMINANCE,		GL_UNSIGNED_BYTE },
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define FOR_EACH(ITERATOR, ARRAY, BODY)	\
283dc795cd4f3d064cbbe2bf9899bf2088d206b7434Chih-Hung Hsieh	for (int (ITERATOR) = 0; (ITERATOR) < DE_LENGTH_OF_ARRAY(ARRAY); (ITERATOR)++)	\
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		BODY
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FOR_EACH(wrapS,		wrapModes,
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FOR_EACH(wrapT,		wrapModes,
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FOR_EACH(filter,	filteringModes,
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FOR_EACH(size,		sizes,
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FOR_EACH(format,	formats,
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			bool is_clamp_clamp		= (wrapModes[wrapS].mode == GL_CLAMP_TO_EDGE	&& wrapModes[wrapT].mode == GL_CLAMP_TO_EDGE);
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			bool is_repeat_mirror	= (wrapModes[wrapS].mode == GL_REPEAT			&& wrapModes[wrapT].mode == GL_MIRRORED_REPEAT);
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!is_clamp_clamp && !is_repeat_mirror && format != 0)
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				continue; // Use other format varants with clamp_clamp & repeat_mirror pair only.
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!is_clamp_clamp && (!deIsPowerOfTwo32(sizes[size].width) || !deIsPowerOfTwo32(sizes[size].height)))
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				continue; // Not supported as described in Spec section 3.8.2.
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			string name = string("") + wrapModes[wrapS].name + "_" + wrapModes[wrapT].name + "_" + filteringModes[filter].name + "_" + sizes[size].name + "_" + formats[format].name;
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			addChild(new TextureWrapCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), name.c_str(), "",
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										 formats[format].format, formats[format].dataType,
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										 wrapModes[wrapS].mode,
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										 wrapModes[wrapT].mode,
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										 filteringModes[filter].mode, filteringModes[filter].mode,
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										 sizes[size].width, sizes[size].height));
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		})))));
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Power-of-two ETC1 texture
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<std::string> potFilenames;
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	potFilenames.push_back("data/etc1/photo_helsinki_mip_0.pkm");
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FOR_EACH(wrapS,		wrapModes,
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FOR_EACH(wrapT,		wrapModes,
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FOR_EACH(filter,	filteringModes,
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			string name = string("") + wrapModes[wrapS].name + "_" + wrapModes[wrapT].name + "_" + filteringModes[filter].name + "_pot_etc1";
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			addChild(new TextureWrapCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), name.c_str(), "",
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										 wrapModes[wrapS].mode,
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										 wrapModes[wrapT].mode,
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										 filteringModes[filter].mode, filteringModes[filter].mode,
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										 potFilenames));
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		})));
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<std::string> npotFilenames;
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	npotFilenames.push_back("data/etc1/photo_helsinki_113x89.pkm");
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// NPOT ETC1 texture
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int filter = 0; filter < DE_LENGTH_OF_ARRAY(filteringModes); filter++)
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		string name = string("clamp_clamp_") + filteringModes[filter].name + "_npot_etc1";
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(new TextureWrapCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), name.c_str(), "",
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									 GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									 filteringModes[filter].mode, filteringModes[filter].mode,
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									 npotFilenames));
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles2
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
345