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 Read pixels tests
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es2fReadPixelsTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTexture.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuImageCompare.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.hpp"
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMath.h"
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h"
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluDefs.hpp"
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderProgram.hpp"
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluStrUtil.hpp"
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTextureUtil.hpp"
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glw.h"
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <cstring>
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles2
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ReadPixelsTest : public TestCase
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					ReadPixelsTest	(Context& context, const char* name, const char* description, bool chooseFormat, int alignment);
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult	iterate			(void);
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			render			(tcu::Texture2D& reference);
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool			m_chooseFormat;
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				m_alignment;
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				m_seed;
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			getFormatInfo	(tcu::TextureFormat& format, GLint& glFormat, GLint& glType, int& pixelSize, bool& align);
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
683c827367444ee418f129b2c238299f49d3264554Jarkko PoyryReadPixelsTest::ReadPixelsTest	(Context& context, const char* name, const char* description, bool chooseFormat, int alignment)
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase			(context, name, description)
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_chooseFormat	(chooseFormat)
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_alignment		(alignment)
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_seed			(deStringHash(name))
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ReadPixelsTest::render (tcu::Texture2D& reference)
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Create program
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char* vertexSource =
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"attribute mediump vec2 a_coord;\n"
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"void main (void)\n"
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"{\n"
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"\tgl_Position = vec4(a_coord, 0.0, 1.0);\n"
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"}\n";
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char* fragmentSource =
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"void main (void)\n"
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"{\n"
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"\tgl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n"
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"}\n";
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::ShaderProgram program(m_context.getRenderContext(), glu::makeVtxFragSources(vertexSource, fragmentSource));
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << program;
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK(program.isOk());
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_CHECK_CALL(glUseProgram(program.getProgram()));
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float coords[] =
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			-0.5f, -0.5f,
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			 0.5f, -0.5f,
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			 0.5f,  0.5f,
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			 0.5f,  0.5f,
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			-0.5f,  0.5f,
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			-0.5f, -0.5f
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		};
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLuint coordLoc;
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		coordLoc = glGetAttribLocation(program.getProgram(), "a_coord");
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_MSG("glGetAttribLocation()");
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_CALL(glEnableVertexAttribArray(coordLoc));
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_CALL(glVertexAttribPointer(coordLoc, 2, GL_FLOAT, GL_FALSE, 0, coords));
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_CALL(glDrawArrays(GL_TRIANGLES, 0, 6));
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_CALL(glDisableVertexAttribArray(coordLoc));
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render reference
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int coordX1 = (int)((-0.5f * reference.getWidth()		/ 2.0f) + reference.getWidth() / 2.0f);
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int coordY1 = (int)((-0.5f * reference.getHeight()	/ 2.0f) + reference.getHeight() / 2.0f);
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int coordX2 = (int)(( 0.5f * reference.getWidth()		/ 2.0f) + reference.getWidth() / 2.0f);
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int coordY2 = (int)(( 0.5f * reference.getHeight()	/ 2.0f) + reference.getHeight() / 2.0f);
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int x = 0; x < reference.getWidth(); x++)
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (x < coordX1 || x > coordX2)
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			continue;
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int y = 0; y < reference.getHeight(); y++)
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (y >= coordY1 && y <= coordY2)
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				reference.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), x, y);
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ReadPixelsTest::getFormatInfo (tcu::TextureFormat& format, GLint& glFormat, GLint& glType, int& pixelSize, bool& align)
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_chooseFormat)
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_CALL(glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &glFormat));
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_CALL(glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &glType));
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		format = glu::mapGLTransferFormat(glFormat, glType);
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Check if aligment is allowed
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		switch (glType)
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_BYTE:
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_UNSIGNED_BYTE:
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_SHORT:
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_UNSIGNED_SHORT:
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_INT:
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_UNSIGNED_INT:
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_FLOAT:
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_HALF_FLOAT:
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				align = true;
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_UNSIGNED_SHORT_5_6_5:
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_UNSIGNED_SHORT_4_4_4_4:
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_UNSIGNED_SHORT_5_5_5_1:
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_UNSIGNED_INT_2_10_10_10_REV:
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_UNSIGNED_INT_10F_11F_11F_REV:
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_UNSIGNED_INT_24_8:
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_UNSIGNED_INT_5_9_9_9_REV:
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				align = false;
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			default:
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				throw tcu::InternalError("Unsupported format", "", __FILE__, __LINE__);
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		pixelSize	= format.getPixelSize();
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		format		= tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8);
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		pixelSize	= 1 * 4;
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		align		= true;
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glFormat	= GL_RGBA;
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glType		= GL_UNSIGNED_BYTE;
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1933c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTestCase::IterateResult ReadPixelsTest::iterate (void)
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Create reference
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					width	= 13;
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					height	= 13;
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	de::Random					rnd(m_seed);
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureFormat			format(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8);
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int							pixelSize;
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLint						glFormat;
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLint						glType;
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool						align;
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	getFormatInfo(format, glFormat, glType, pixelSize, align);
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << tcu::TestLog::Message << "Format: " << glu::getPixelFormatStr(glFormat) << ", Type: " << glu::getTypeStr(glType) << tcu::TestLog::EndMessage;
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Texture2D reference(format, width, height);
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	reference.allocLevel(0);
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_CHECK_CALL(glViewport(0, 0, width, height));
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Clear color
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float red		= rnd.getFloat();
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float green	= rnd.getFloat();
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float blue	= rnd.getFloat();
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float alpha	= 1.0f;
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << tcu::TestLog::Message << "Clear color: (" << red << ", " << green << ", " << blue << ", " << alpha << ")" << tcu::TestLog::EndMessage;
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Clear target
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_CALL(glClearColor(red, green, blue, alpha));
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_CALL(glClear(GL_COLOR_BUFFER_BIT));
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Clear reference
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int x = 0; x < reference.getWidth(); x++)
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int y = 0; y < reference.getHeight(); y++)
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					reference.getLevel(0).setPixel(tcu::Vec4(red, green, blue, alpha), x, y);
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	render(reference);
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<deUint8> pixelData;
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int rowPitch = (align ? m_alignment * deCeilFloatToInt32(pixelSize * width / (float)m_alignment) : width * pixelSize);
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	pixelData.resize(rowPitch * height, 0);
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_CHECK_CALL(glPixelStorei(GL_PACK_ALIGNMENT, m_alignment));
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_CHECK_CALL(glReadPixels(0, 0, width, height, glFormat, glType, &(pixelData[0])));
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_context.getRenderTarget().getNumSamples() > 1)
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::IVec4	formatBitDepths	= tcu::getTextureFormatBitDepth(format);
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint8		redThreshold	= (deUint8)deCeilFloatToInt32(256.0f * (2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().redBits,		formatBitDepths.x()))));
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint8		greenThreshold	= (deUint8)deCeilFloatToInt32(256.0f * (2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().greenBits,	formatBitDepths.y()))));
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint8		blueThreshold	= (deUint8)deCeilFloatToInt32(256.0f * (2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().blueBits,		formatBitDepths.z()))));
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint8		alphaThreshold	= (deUint8)deCeilFloatToInt32(256.0f * (2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().alphaBits,	formatBitDepths.w()))));
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (tcu::bilinearCompare(m_testCtx.getLog(), "Result", "Result", reference.getLevel(0), tcu::PixelBufferAccess(format, width, height, 1, rowPitch, 0, &(pixelData[0])), tcu::RGBA(redThreshold, greenThreshold, blueThreshold, alphaThreshold), tcu::COMPARE_LOG_RESULT))
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::IVec4	formatBitDepths	= tcu::getTextureFormatBitDepth(format);
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float			redThreshold	= 2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().redBits,	formatBitDepths.x()));
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float			greenThreshold	= 2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().greenBits,	formatBitDepths.y()));
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float			blueThreshold	= 2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().blueBits,	formatBitDepths.z()));
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float			alphaThreshold	= 2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().alphaBits,	formatBitDepths.w()));
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Compare
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (tcu::floatThresholdCompare(m_testCtx.getLog(), "Result", "Result", reference.getLevel(0), tcu::PixelBufferAccess(format, width, height, 1, rowPitch, 0, &(pixelData[0])), tcu::Vec4(redThreshold, greenThreshold, blueThreshold, alphaThreshold), tcu::COMPARE_LOG_RESULT))
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2753c827367444ee418f129b2c238299f49d3264554Jarkko PoyryReadPixelsTests::ReadPixelsTests (Context& context)
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(context, "read_pixels", "ReadPixel tests")
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ReadPixelsTests::init (void)
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new ReadPixelsTest(m_context, "rgba_ubyte_align_1", "", false, 1));
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new ReadPixelsTest(m_context, "rgba_ubyte_align_2", "", false, 2));
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new ReadPixelsTest(m_context, "rgba_ubyte_align_4", "", false, 4));
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new ReadPixelsTest(m_context, "rgba_ubyte_align_8", "", false, 8));
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new ReadPixelsTest(m_context, "choose_align_1", "", true, 1));
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new ReadPixelsTest(m_context, "choose_align_2", "", true, 2));
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new ReadPixelsTest(m_context, "choose_align_4", "", true, 4));
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new ReadPixelsTest(m_context, "choose_align_8", "", true, 8));
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles2
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
296