Home | History | Annotate | Download | only in functional
      1 /*-------------------------------------------------------------------------
      2  * drawElements Quality Program OpenGL ES 2.0 Module
      3  * -------------------------------------------------
      4  *
      5  * Copyright 2014 The Android Open Source Project
      6  *
      7  * Licensed under the Apache License, Version 2.0 (the "License");
      8  * you may not use this file except in compliance with the License.
      9  * You may obtain a copy of the License at
     10  *
     11  *      http://www.apache.org/licenses/LICENSE-2.0
     12  *
     13  * Unless required by applicable law or agreed to in writing, software
     14  * distributed under the License is distributed on an "AS IS" BASIS,
     15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16  * See the License for the specific language governing permissions and
     17  * limitations under the License.
     18  *
     19  *//*!
     20  * \file
     21  * \brief Texture wrap mode tests.
     22  *//*--------------------------------------------------------------------*/
     23 
     24 #include "es2fTextureWrapTests.hpp"
     25 #include "glsTextureTestUtil.hpp"
     26 #include "gluTexture.hpp"
     27 #include "gluStrUtil.hpp"
     28 #include "gluTextureUtil.hpp"
     29 #include "gluPixelTransfer.hpp"
     30 #include "tcuTestLog.hpp"
     31 #include "tcuTextureUtil.hpp"
     32 
     33 #include "glwEnums.hpp"
     34 #include "glwFunctions.hpp"
     35 
     36 namespace deqp
     37 {
     38 namespace gles2
     39 {
     40 namespace Functional
     41 {
     42 
     43 using tcu::TestLog;
     44 using std::vector;
     45 using std::string;
     46 using tcu::Sampler;
     47 using namespace glu;
     48 using namespace gls::TextureTestUtil;
     49 
     50 enum
     51 {
     52 	VIEWPORT_WIDTH		= 256,
     53 	VIEWPORT_HEIGHT		= 256
     54 };
     55 
     56 class TextureWrapCase : public tcu::TestCase
     57 {
     58 public:
     59 								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);
     60 								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);
     61 								~TextureWrapCase		(void);
     62 
     63 	void						init					(void);
     64 	void						deinit					(void);
     65 	IterateResult				iterate					(void);
     66 
     67 private:
     68 								TextureWrapCase			(const TextureWrapCase& other);
     69 	TextureWrapCase&			operator=				(const TextureWrapCase& other);
     70 
     71 	glu::RenderContext&			m_renderCtx;
     72 	const glu::ContextInfo&		m_renderCtxInfo;
     73 
     74 	deUint32					m_format;
     75 	deUint32					m_dataType;
     76 	deUint32					m_wrapS;
     77 	deUint32					m_wrapT;
     78 	deUint32					m_minFilter;
     79 	deUint32					m_magFilter;
     80 
     81 	int							m_width;
     82 	int							m_height;
     83 	std::vector<std::string>	m_filenames;
     84 
     85 	glu::Texture2D*				m_texture;
     86 	TextureRenderer				m_renderer;
     87 };
     88 
     89 TextureWrapCase::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)
     90 	: TestCase			(testCtx, name, description)
     91 	, m_renderCtx		(renderCtx)
     92 	, m_renderCtxInfo	(ctxInfo)
     93 	, m_format			(format)
     94 	, m_dataType		(dataType)
     95 	, m_wrapS			(wrapS)
     96 	, m_wrapT			(wrapT)
     97 	, m_minFilter		(minFilter)
     98 	, m_magFilter		(magFilter)
     99 	, m_width			(width)
    100 	, m_height			(height)
    101 	, m_texture			(DE_NULL)
    102 	, m_renderer		(renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
    103 {
    104 }
    105 
    106 TextureWrapCase::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)
    107 	: TestCase			(testCtx, name, description)
    108 	, m_renderCtx		(renderCtx)
    109 	, m_renderCtxInfo	(ctxInfo)
    110 	, m_format			(GL_NONE)
    111 	, m_dataType		(GL_NONE)
    112 	, m_wrapS			(wrapS)
    113 	, m_wrapT			(wrapT)
    114 	, m_minFilter		(minFilter)
    115 	, m_magFilter		(magFilter)
    116 	, m_width			(0)
    117 	, m_height			(0)
    118 	, m_filenames		(filenames)
    119 	, m_texture			(DE_NULL)
    120 	, m_renderer		(renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
    121 {
    122 }
    123 
    124 TextureWrapCase::~TextureWrapCase (void)
    125 {
    126 	deinit();
    127 }
    128 
    129 void TextureWrapCase::init (void)
    130 {
    131 	if (!m_filenames.empty())
    132 	{
    133 		DE_ASSERT(m_width == 0 && m_height == 0 && m_format == GL_NONE && m_dataType == GL_NONE);
    134 
    135 		m_texture	= glu::Texture2D::create(m_renderCtx, m_renderCtxInfo, m_testCtx.getArchive(), (int)m_filenames.size(), m_filenames);
    136 		m_width		= m_texture->getRefTexture().getWidth();
    137 		m_height	= m_texture->getRefTexture().getHeight();
    138 	}
    139 	else
    140 	{
    141 		m_texture = new Texture2D(m_renderCtx, m_format, m_dataType, m_width, m_height);
    142 
    143 		// Fill level 0.
    144 		m_texture->getRefTexture().allocLevel(0);
    145 		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));
    146 
    147 		m_texture->upload();
    148 	}
    149 }
    150 
    151 void TextureWrapCase::deinit (void)
    152 {
    153 	delete m_texture;
    154 	m_texture = DE_NULL;
    155 
    156 	m_renderer.clear();
    157 }
    158 
    159 TextureWrapCase::IterateResult TextureWrapCase::iterate (void)
    160 {
    161 	const glw::Functions&	gl					= m_renderCtx.getFunctions();
    162 	TestLog&				log					= m_testCtx.getLog();
    163 	RandomViewport			viewport			(m_renderCtx.getRenderTarget(), VIEWPORT_WIDTH, VIEWPORT_HEIGHT, deStringHash(getName()));
    164 	tcu::Surface			renderedFrame		(viewport.width, viewport.height);
    165 	tcu::Surface			referenceFrame		(viewport.width, viewport.height);
    166 	bool					isCompressedTex		= !m_filenames.empty();
    167 	ReferenceParams			refParams			(TEXTURETYPE_2D);
    168 	int						leftWidth			= viewport.width / 2;
    169 	int						rightWidth			= viewport.width - leftWidth;
    170 	vector<float>			texCoord;
    171 	tcu::RGBA				threshold			= m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold()
    172 												+ (isCompressedTex ? tcu::RGBA(7,7,7,7) : tcu::RGBA(3,3,3,3));
    173 
    174 	// Bind to unit 0.
    175 	gl.activeTexture(GL_TEXTURE0);
    176 	gl.bindTexture(GL_TEXTURE_2D, m_texture->getGLTexture());
    177 
    178 	// Setup filtering and wrap modes.
    179 	gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,		m_wrapS);
    180 	gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,		m_wrapT);
    181 	gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,	m_minFilter);
    182 	gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,	m_magFilter);
    183 
    184 	GLU_EXPECT_NO_ERROR(gl.getError(), "Set texturing state");
    185 
    186 	// Parameters for reference images.
    187 	refParams.sampler	= mapGLSampler(m_wrapS, m_wrapT, m_minFilter, m_magFilter);
    188 	refParams.lodMode	= LODMODE_EXACT;
    189 
    190 	// Left: minification
    191 	{
    192 		gl.viewport(viewport.x, viewport.y, leftWidth, viewport.height);
    193 
    194 		computeQuadTexCoord2D(texCoord, tcu::Vec2(-1.5f, -3.0f), tcu::Vec2(1.5f, 2.5f));
    195 
    196 		m_renderer.renderQuad(0, &texCoord[0], refParams);
    197 		glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
    198 
    199 		sampleTexture(SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), 0, 0, leftWidth, viewport.height),
    200 					  m_texture->getRefTexture(), &texCoord[0], refParams);
    201 	}
    202 
    203 	// Right: magnification
    204 	{
    205 		gl.viewport(viewport.x+leftWidth, viewport.y, rightWidth, viewport.height);
    206 
    207 		computeQuadTexCoord2D(texCoord, tcu::Vec2(-0.5f, 0.75f), tcu::Vec2(0.25f, 1.25f));
    208 
    209 		m_renderer.renderQuad(0, &texCoord[0], refParams);
    210 		glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
    211 
    212 		sampleTexture(SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), leftWidth, 0, rightWidth, viewport.height),
    213 					  m_texture->getRefTexture(), &texCoord[0], refParams);
    214 	}
    215 
    216 	// Compare and log.
    217 	bool isOk = compareImages(log, referenceFrame, renderedFrame, threshold);
    218 
    219 	m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS	: QP_TEST_RESULT_FAIL,
    220 							isOk ? "Pass"				: "Image comparison failed");
    221 
    222 	return STOP;
    223 }
    224 
    225 TextureWrapTests::TextureWrapTests (Context& context)
    226 	: TestCaseGroup(context, "wrap", "Wrap Mode Tests")
    227 {
    228 }
    229 
    230 TextureWrapTests::~TextureWrapTests (void)
    231 {
    232 }
    233 
    234 void TextureWrapTests::init (void)
    235 {
    236 	static const struct
    237 	{
    238 		const char*		name;
    239 		deUint32		mode;
    240 	} wrapModes[] =
    241 	{
    242 		{ "clamp",		GL_CLAMP_TO_EDGE },
    243 		{ "repeat",		GL_REPEAT },
    244 		{ "mirror",		GL_MIRRORED_REPEAT }
    245 	};
    246 
    247 	static const struct
    248 	{
    249 		const char*		name;
    250 		deUint32		mode;
    251 	} filteringModes[] =
    252 	{
    253 		{ "nearest",	GL_NEAREST },
    254 		{ "linear",		GL_LINEAR }
    255 	};
    256 
    257 	static const struct
    258 	{
    259 		const char*		name;
    260 		int				width;
    261 		int				height;
    262 	} sizes[] =
    263 	{
    264 		{ "pot",		64, 128 },
    265 		{ "npot",		63, 112 }
    266 	};
    267 
    268 	static const struct
    269 	{
    270 		const char*		name;
    271 		deUint32		format;
    272 		deUint32		dataType;
    273 	} formats[] =
    274 	{
    275 		{ "rgba8888",	GL_RGBA,			GL_UNSIGNED_BYTE },
    276 		{ "rgb888",		GL_RGB,				GL_UNSIGNED_BYTE },
    277 		{ "rgba4444",	GL_RGBA,			GL_UNSIGNED_SHORT_4_4_4_4 },
    278 		{ "l8",			GL_LUMINANCE,		GL_UNSIGNED_BYTE },
    279 	};
    280 
    281 #define FOR_EACH(ITERATOR, ARRAY, BODY)	\
    282 	for (int ITERATOR = 0; ITERATOR < DE_LENGTH_OF_ARRAY(ARRAY); ITERATOR++)	\
    283 		BODY
    284 
    285 	FOR_EACH(wrapS,		wrapModes,
    286 	FOR_EACH(wrapT,		wrapModes,
    287 	FOR_EACH(filter,	filteringModes,
    288 	FOR_EACH(size,		sizes,
    289 	FOR_EACH(format,	formats,
    290 		{
    291 			bool is_clamp_clamp		= (wrapModes[wrapS].mode == GL_CLAMP_TO_EDGE	&& wrapModes[wrapT].mode == GL_CLAMP_TO_EDGE);
    292 			bool is_repeat_mirror	= (wrapModes[wrapS].mode == GL_REPEAT			&& wrapModes[wrapT].mode == GL_MIRRORED_REPEAT);
    293 
    294 			if (!is_clamp_clamp && !is_repeat_mirror && format != 0)
    295 				continue; // Use other format varants with clamp_clamp & repeat_mirror pair only.
    296 
    297 			if (!is_clamp_clamp && (!deIsPowerOfTwo32(sizes[size].width) || !deIsPowerOfTwo32(sizes[size].height)))
    298 				continue; // Not supported as described in Spec section 3.8.2.
    299 
    300 			string name = string("") + wrapModes[wrapS].name + "_" + wrapModes[wrapT].name + "_" + filteringModes[filter].name + "_" + sizes[size].name + "_" + formats[format].name;
    301 			addChild(new TextureWrapCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), name.c_str(), "",
    302 										 formats[format].format, formats[format].dataType,
    303 										 wrapModes[wrapS].mode,
    304 										 wrapModes[wrapT].mode,
    305 										 filteringModes[filter].mode, filteringModes[filter].mode,
    306 										 sizes[size].width, sizes[size].height));
    307 
    308 		})))));
    309 
    310 	// Power-of-two ETC1 texture
    311 	std::vector<std::string> potFilenames;
    312 	potFilenames.push_back("data/etc1/photo_helsinki_mip_0.pkm");
    313 
    314 	FOR_EACH(wrapS,		wrapModes,
    315 	FOR_EACH(wrapT,		wrapModes,
    316 	FOR_EACH(filter,	filteringModes,
    317 		{
    318 			string name = string("") + wrapModes[wrapS].name + "_" + wrapModes[wrapT].name + "_" + filteringModes[filter].name + "_pot_etc1";
    319 			addChild(new TextureWrapCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), name.c_str(), "",
    320 										 wrapModes[wrapS].mode,
    321 										 wrapModes[wrapT].mode,
    322 										 filteringModes[filter].mode, filteringModes[filter].mode,
    323 										 potFilenames));
    324 
    325 		})));
    326 
    327 	std::vector<std::string> npotFilenames;
    328 	npotFilenames.push_back("data/etc1/photo_helsinki_113x89.pkm");
    329 
    330 	// NPOT ETC1 texture
    331 	for (int filter = 0; filter < DE_LENGTH_OF_ARRAY(filteringModes); filter++)
    332 	{
    333 		string name = string("clamp_clamp_") + filteringModes[filter].name + "_npot_etc1";
    334 		addChild(new TextureWrapCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), name.c_str(), "",
    335 									 GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
    336 									 filteringModes[filter].mode, filteringModes[filter].mode,
    337 									 npotFilenames));
    338 	}
    339 }
    340 
    341 } // Functional
    342 } // gles2
    343 } // deqp
    344