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"
350fe53277c5a9fe323fc38f9de747af9ca4178b44Jarkko Pöyry#include "deStringUtil.hpp"
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluDefs.hpp"
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderProgram.hpp"
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluStrUtil.hpp"
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTextureUtil.hpp"
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glw.h"
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <cstring>
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles2
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ReadPixelsTest : public TestCase
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					ReadPixelsTest	(Context& context, const char* name, const char* description, bool chooseFormat, int alignment);
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult	iterate			(void);
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			render			(tcu::Texture2D& reference);
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool			m_chooseFormat;
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				m_alignment;
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				m_seed;
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
66115e0bf114f70d2c8caec6ff7a85aa7536ac713fMika Isojärvi	void			getFormatInfo	(tcu::TextureFormat& format, GLint& glFormat, GLint& glType, int& pixelSize);
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
693c827367444ee418f129b2c238299f49d3264554Jarkko PoyryReadPixelsTest::ReadPixelsTest	(Context& context, const char* name, const char* description, bool chooseFormat, int alignment)
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase			(context, name, description)
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_chooseFormat	(chooseFormat)
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_alignment		(alignment)
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_seed			(deStringHash(name))
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ReadPixelsTest::render (tcu::Texture2D& reference)
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Create program
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char* vertexSource =
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"attribute mediump vec2 a_coord;\n"
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"void main (void)\n"
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"{\n"
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"\tgl_Position = vec4(a_coord, 0.0, 1.0);\n"
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"}\n";
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char* fragmentSource =
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"void main (void)\n"
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"{\n"
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"\tgl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n"
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"}\n";
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::ShaderProgram program(m_context.getRenderContext(), glu::makeVtxFragSources(vertexSource, fragmentSource));
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << program;
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK(program.isOk());
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_CHECK_CALL(glUseProgram(program.getProgram()));
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float coords[] =
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			-0.5f, -0.5f,
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			 0.5f, -0.5f,
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			 0.5f,  0.5f,
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			 0.5f,  0.5f,
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			-0.5f,  0.5f,
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			-0.5f, -0.5f
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		};
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLuint coordLoc;
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		coordLoc = glGetAttribLocation(program.getProgram(), "a_coord");
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_MSG("glGetAttribLocation()");
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_CALL(glEnableVertexAttribArray(coordLoc));
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_CALL(glVertexAttribPointer(coordLoc, 2, GL_FLOAT, GL_FALSE, 0, coords));
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_CALL(glDrawArrays(GL_TRIANGLES, 0, 6));
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_CALL(glDisableVertexAttribArray(coordLoc));
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render reference
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int coordX1 = (int)((-0.5f * reference.getWidth()		/ 2.0f) + reference.getWidth() / 2.0f);
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int coordY1 = (int)((-0.5f * reference.getHeight()	/ 2.0f) + reference.getHeight() / 2.0f);
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int coordX2 = (int)(( 0.5f * reference.getWidth()		/ 2.0f) + reference.getWidth() / 2.0f);
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int coordY2 = (int)(( 0.5f * reference.getHeight()	/ 2.0f) + reference.getHeight() / 2.0f);
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int x = 0; x < reference.getWidth(); x++)
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (x < coordX1 || x > coordX2)
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			continue;
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int y = 0; y < reference.getHeight(); y++)
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (y >= coordY1 && y <= coordY2)
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				reference.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), x, y);
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
144115e0bf114f70d2c8caec6ff7a85aa7536ac713fMika Isojärvivoid ReadPixelsTest::getFormatInfo (tcu::TextureFormat& format, GLint& glFormat, GLint& glType, int& pixelSize)
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_chooseFormat)
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_CALL(glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &glFormat));
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_CALL(glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &glType));
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1510fe53277c5a9fe323fc38f9de747af9ca4178b44Jarkko Pöyry		if (glFormat != GL_RGBA && glFormat != GL_BGRA && glFormat != GL_RGB)
1520fe53277c5a9fe323fc38f9de747af9ca4178b44Jarkko Pöyry			TCU_THROW(NotSupportedError, ("Unsupported IMPLEMENTATION_COLOR_READ_FORMAT: " + de::toString(glu::getPixelFormatStr(glFormat))).c_str());
1530fe53277c5a9fe323fc38f9de747af9ca4178b44Jarkko Pöyry		if (glu::getTypeName(glType) == DE_NULL)
1540fe53277c5a9fe323fc38f9de747af9ca4178b44Jarkko Pöyry			TCU_THROW(NotSupportedError, ("Unsupported GL_IMPLEMENTATION_COLOR_READ_TYPE: " + de::toString(tcu::Format::Hex<4>(glType))).c_str());
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1560fe53277c5a9fe323fc38f9de747af9ca4178b44Jarkko Pöyry		format = glu::mapGLTransferFormat(glFormat, glType);
1570fe53277c5a9fe323fc38f9de747af9ca4178b44Jarkko Pöyry		pixelSize = format.getPixelSize();
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		format		= tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8);
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		pixelSize	= 1 * 4;
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glFormat	= GL_RGBA;
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glType		= GL_UNSIGNED_BYTE;
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1683c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTestCase::IterateResult ReadPixelsTest::iterate (void)
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Create reference
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					width	= 13;
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					height	= 13;
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	de::Random					rnd(m_seed);
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureFormat			format(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8);
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int							pixelSize;
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLint						glFormat;
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLint						glType;
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
181115e0bf114f70d2c8caec6ff7a85aa7536ac713fMika Isojärvi	getFormatInfo(format, glFormat, glType, pixelSize);
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << tcu::TestLog::Message << "Format: " << glu::getPixelFormatStr(glFormat) << ", Type: " << glu::getTypeStr(glType) << tcu::TestLog::EndMessage;
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Texture2D reference(format, width, height);
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	reference.allocLevel(0);
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_CHECK_CALL(glViewport(0, 0, width, height));
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Clear color
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float red		= rnd.getFloat();
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float green	= rnd.getFloat();
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float blue	= rnd.getFloat();
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float alpha	= 1.0f;
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << tcu::TestLog::Message << "Clear color: (" << red << ", " << green << ", " << blue << ", " << alpha << ")" << tcu::TestLog::EndMessage;
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Clear target
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_CALL(glClearColor(red, green, blue, alpha));
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_CALL(glClear(GL_COLOR_BUFFER_BIT));
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
202e0f21cf5f2ee3a06c497f32a4392d23e4bbcd573Mika Isojärvi		tcu::clear(reference.getLevel(0), tcu::Vec4(red, green, blue, alpha));
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	render(reference);
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<deUint8> pixelData;
208115e0bf114f70d2c8caec6ff7a85aa7536ac713fMika Isojärvi	const int rowPitch = m_alignment * deCeilFloatToInt32(pixelSize * width / (float)m_alignment);
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	pixelData.resize(rowPitch * height, 0);
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_CHECK_CALL(glPixelStorei(GL_PACK_ALIGNMENT, m_alignment));
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_CHECK_CALL(glReadPixels(0, 0, width, height, glFormat, glType, &(pixelData[0])));
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_context.getRenderTarget().getNumSamples() > 1)
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::IVec4	formatBitDepths	= tcu::getTextureFormatBitDepth(format);
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint8		redThreshold	= (deUint8)deCeilFloatToInt32(256.0f * (2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().redBits,		formatBitDepths.x()))));
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint8		greenThreshold	= (deUint8)deCeilFloatToInt32(256.0f * (2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().greenBits,	formatBitDepths.y()))));
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint8		blueThreshold	= (deUint8)deCeilFloatToInt32(256.0f * (2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().blueBits,		formatBitDepths.z()))));
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint8		alphaThreshold	= (deUint8)deCeilFloatToInt32(256.0f * (2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().alphaBits,	formatBitDepths.w()))));
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2230fe53277c5a9fe323fc38f9de747af9ca4178b44Jarkko Pöyry		// bilinearCompare only accepts RGBA, UINT8
2240fe53277c5a9fe323fc38f9de747af9ca4178b44Jarkko Pöyry		tcu::Texture2D		referenceRGBA8	(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), width, height);
2250fe53277c5a9fe323fc38f9de747af9ca4178b44Jarkko Pöyry		tcu::Texture2D		resultRGBA8		(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), width, height);
2260fe53277c5a9fe323fc38f9de747af9ca4178b44Jarkko Pöyry
2270fe53277c5a9fe323fc38f9de747af9ca4178b44Jarkko Pöyry		referenceRGBA8.allocLevel(0);
2280fe53277c5a9fe323fc38f9de747af9ca4178b44Jarkko Pöyry		resultRGBA8.allocLevel(0);
2290fe53277c5a9fe323fc38f9de747af9ca4178b44Jarkko Pöyry
2300fe53277c5a9fe323fc38f9de747af9ca4178b44Jarkko Pöyry		tcu::copy(referenceRGBA8.getLevel(0), reference.getLevel(0));
2310fe53277c5a9fe323fc38f9de747af9ca4178b44Jarkko Pöyry		tcu::copy(resultRGBA8.getLevel(0), tcu::PixelBufferAccess(format, width, height, 1, rowPitch, 0, &(pixelData[0])));
2320fe53277c5a9fe323fc38f9de747af9ca4178b44Jarkko Pöyry
2330fe53277c5a9fe323fc38f9de747af9ca4178b44Jarkko Pöyry		if (tcu::bilinearCompare(m_testCtx.getLog(), "Result", "Result", referenceRGBA8.getLevel(0), resultRGBA8.getLevel(0), tcu::RGBA(redThreshold, greenThreshold, blueThreshold, alphaThreshold), tcu::COMPARE_LOG_RESULT))
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::IVec4	formatBitDepths	= tcu::getTextureFormatBitDepth(format);
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float			redThreshold	= 2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().redBits,	formatBitDepths.x()));
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float			greenThreshold	= 2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().greenBits,	formatBitDepths.y()));
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float			blueThreshold	= 2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().blueBits,	formatBitDepths.z()));
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float			alphaThreshold	= 2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().alphaBits,	formatBitDepths.w()));
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Compare
2473c827367444ee418f129b2c238299f49d3264554Jarkko 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))
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2563c827367444ee418f129b2c238299f49d3264554Jarkko PoyryReadPixelsTests::ReadPixelsTests (Context& context)
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(context, "read_pixels", "ReadPixel tests")
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ReadPixelsTests::init (void)
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new ReadPixelsTest(m_context, "rgba_ubyte_align_1", "", false, 1));
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new ReadPixelsTest(m_context, "rgba_ubyte_align_2", "", false, 2));
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new ReadPixelsTest(m_context, "rgba_ubyte_align_4", "", false, 4));
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new ReadPixelsTest(m_context, "rgba_ubyte_align_8", "", false, 8));
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new ReadPixelsTest(m_context, "choose_align_1", "", true, 1));
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new ReadPixelsTest(m_context, "choose_align_2", "", true, 2));
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new ReadPixelsTest(m_context, "choose_align_4", "", true, 4));
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new ReadPixelsTest(m_context, "choose_align_8", "", true, 8));
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles2
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
277