13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program EGL 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 Test for mapping client color values to native surface colors
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "teglNativeColorMappingTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "teglSimpleConfigCase.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTexture.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluNativeDisplay.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluNativeWindow.hpp"
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluNativePixmap.hpp"
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluUnique.hpp"
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluUtil.hpp"
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluDefs.hpp"
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp"
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp"
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuImageCompare.hpp"
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTexture.hpp"
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp"
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deUniquePtr.hpp"
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp"
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deThread.hpp"
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector>
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string>
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <limits>
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog;
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector;
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string;
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace egl
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
653c827367444ee418f129b2c238299f49d3264554Jarkko PoyryEGLContext createGLES2Context (EGLDisplay display, EGLConfig config)
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	EGLContext		context = EGL_NO_CONTEXT;
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const EGLint	attribList[] =
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		EGL_CONTEXT_CLIENT_VERSION, 2,
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		EGL_NONE
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK_EGL_CALL(eglBindAPI(EGL_OPENGL_ES_API));
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context = eglCreateContext(display, config, EGL_NO_CONTEXT, attribList);
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK_EGL_MSG("eglCreateContext() failed");
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK(context);
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return context;
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
833c827367444ee418f129b2c238299f49d3264554Jarkko PoyrydeUint32 createGLES2Program (const glw::Functions& gl, TestLog& log)
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char* const vertexShaderSource =
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"attribute highp vec2 a_pos;\n"
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"void main (void)\n"
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"{\n"
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"\tgl_Position = vec4(a_pos, 0.0, 1.0);\n"
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"}";
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char* const fragmentShaderSource =
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"uniform mediump vec4 u_color;\n"
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"void main (void)\n"
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"{\n"
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"\tgl_FragColor = u_color;\n"
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"}";
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	program			= 0;
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	vertexShader	= 0;
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	fragmentShader	= 0;
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deInt32		vertexCompileStatus;
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	string		vertexInfoLog;
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deInt32		fragmentCompileStatus;
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	string		fragmentInfoLog;
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deInt32		linkStatus;
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	string		programInfoLog;
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	try
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		program			= gl.createProgram();
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vertexShader	= gl.createShader(GL_VERTEX_SHADER);
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		fragmentShader	= gl.createShader(GL_FRAGMENT_SHADER);
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to create shaders and program");
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.shaderSource(vertexShader, 1, &vertexShaderSource, DE_NULL);
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.compileShader(vertexShader);
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup vertex shader");
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.shaderSource(fragmentShader, 1, &fragmentShaderSource, DE_NULL);
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.compileShader(fragmentShader);
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup fragment shader");
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deInt32		infoLogLength = 0;
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.getShaderiv(vertexShader, GL_COMPILE_STATUS, &vertexCompileStatus);
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.getShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &infoLogLength);
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			vertexInfoLog.resize(infoLogLength, '\0');
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.getShaderInfoLog(vertexShader, (glw::GLsizei)vertexInfoLog.length(), &infoLogLength, &(vertexInfoLog[0]));
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to get vertex shader compile info");
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			vertexInfoLog.resize(infoLogLength);
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deInt32		infoLogLength = 0;
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.getShaderiv(fragmentShader, GL_COMPILE_STATUS, &fragmentCompileStatus);
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.getShaderiv(fragmentShader, GL_INFO_LOG_LENGTH, &infoLogLength);
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			fragmentInfoLog.resize(infoLogLength, '\0');
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.getShaderInfoLog(fragmentShader, (glw::GLsizei)fragmentInfoLog.length(), &infoLogLength, &(fragmentInfoLog[0]));
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to get fragment shader compile info");
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			fragmentInfoLog.resize(infoLogLength);
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.attachShader(program, vertexShader);
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.attachShader(program, fragmentShader);
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.linkProgram(program);
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup program");
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deInt32		infoLogLength = 0;
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.getProgramiv(program, GL_LINK_STATUS, &linkStatus);
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.getProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			programInfoLog.resize(infoLogLength, '\0');
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.getProgramInfoLog(program, (glw::GLsizei)programInfoLog.length(), &infoLogLength, &(programInfoLog[0]));
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to get program link info");
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			programInfoLog.resize(infoLogLength);
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (linkStatus == 0 || vertexCompileStatus == 0 || fragmentCompileStatus == 0)
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log.startShaderProgram(linkStatus != 0, programInfoLog.c_str());
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << TestLog::Shader(QP_SHADER_TYPE_VERTEX, vertexShaderSource, vertexCompileStatus != 0, vertexInfoLog);
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << TestLog::Shader(QP_SHADER_TYPE_FRAGMENT, fragmentShaderSource, fragmentCompileStatus != 0, fragmentInfoLog);
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log.endShaderProgram();
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.deleteShader(vertexShader);
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.deleteShader(fragmentShader);
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to delete shaders");
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK(linkStatus != 0 && vertexCompileStatus != 0 && fragmentCompileStatus != 0);
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	catch (...)
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (program)
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.deleteProgram(program);
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (vertexShader)
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.deleteShader(vertexShader);
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (fragmentShader)
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.deleteShader(fragmentShader);
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw;
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return program;
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clear (const glw::Functions& gl, const tcu::Vec4& color)
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clearColor(color.x(), color.y(), color.z(), color.w());
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clear(GL_COLOR_BUFFER_BIT);
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "Color clear failed");
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid render (const glw::Functions& gl, deUint32 program, const tcu::Vec4& color)
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float positions[] =
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		-1.0f, -1.0f,
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		 1.0f, -1.0f,
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		 1.0f,  1.0f,
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		 1.0f,  1.0f,
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		-1.0f,  1.0f,
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		-1.0f, -1.0f
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 posLocation;
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 colorLocation;
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.useProgram(program);
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	posLocation	= gl.getAttribLocation(program, "a_pos");
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.enableVertexAttribArray(posLocation);
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup shader program for rendering");
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	colorLocation = gl.getUniformLocation(program, "u_color");
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniform4fv(colorLocation, 1, color.getPtr());
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.vertexAttribPointer(posLocation, 2, GL_FLOAT, GL_FALSE, 0, positions);
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.drawArrays(GL_TRIANGLES, 0, 6);
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to render");
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool validate (TestLog& log, EGLDisplay display, EGLConfig config, const tcu::TextureLevel& result, const tcu::Vec4& color)
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::UVec4 eglBitDepth((deUint32)eglu::getConfigAttribInt(display, config, EGL_RED_SIZE),
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								 (deUint32)eglu::getConfigAttribInt(display, config, EGL_GREEN_SIZE),
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								 (deUint32)eglu::getConfigAttribInt(display, config, EGL_BLUE_SIZE),
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								 (deUint32)eglu::getConfigAttribInt(display, config, EGL_ALPHA_SIZE));
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::UVec4 nativeBitDepth(tcu::getTextureFormatBitDepth(result.getFormat()).asUint());
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::UVec4 bitDepth(deMinu32(nativeBitDepth.x(), eglBitDepth.x()),
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							  deMinu32(nativeBitDepth.y(), eglBitDepth.y()),
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							  deMinu32(nativeBitDepth.z(), eglBitDepth.z()),
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							  deMinu32(nativeBitDepth.w(), eglBitDepth.w()));
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::UVec4 uColor = tcu::UVec4((deUint32)(((1u << bitDepth.x()) - 1u) * color.x()),
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										 (deUint32)(((1u << bitDepth.y()) - 1u) * color.y()),
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										 (deUint32)(((1u << bitDepth.z()) - 1u) * color.z()),
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										 (deUint32)(((1u << bitDepth.w()) - 1u) * color.w()));
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureLevel reference(result.getFormat(), result.getWidth(), result.getHeight());
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int y = 0; y < result.getHeight(); y++)
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int x = 0; x < result.getWidth(); x++)
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			reference.getAccess().setPixel(uColor, x, y);
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return tcu::intThresholdCompare(log, "Result compare", "Compare results", reference.getAccess(), result.getAccess(), tcu::UVec4(1u, 1u, 1u, (bitDepth.w() > 0 ? 1u : std::numeric_limits<deUint32>::max())), tcu::COMPARE_LOG_RESULT);
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass NativeColorMappingCase : public SimpleConfigCase
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum NativeType
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		NATIVETYPE_WINDOW = 0,
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		NATIVETYPE_PIXMAP,
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		NATIVETYPE_PBUFFER_COPY_TO_PIXMAP
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				NativeColorMappingCase	(EglTestContext& eglTestCtx, const char* name, const char* description, bool render, NativeType nativeType, const vector<EGLint>& configIds);
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				~NativeColorMappingCase	(void);
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void		executeForConfig		(tcu::egl::Display& display, EGLConfig config);
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NativeType	m_nativeType;
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool		m_render;
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2923c827367444ee418f129b2c238299f49d3264554Jarkko PoyryNativeColorMappingCase::NativeColorMappingCase (EglTestContext& eglTestCtx, const char* name, const char* description, bool render, NativeType nativeType, const vector<EGLint>& configIds)
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: SimpleConfigCase	(eglTestCtx, name, description, configIds)
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_nativeType		(nativeType)
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_render			(render)
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2993c827367444ee418f129b2c238299f49d3264554Jarkko PoyryNativeColorMappingCase::~NativeColorMappingCase	(void)
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deinit();
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid logConfigInfo (TestLog& log, EGLDisplay display, EGLConfig config, NativeColorMappingCase::NativeType nativeType, int waitFrames)
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << "EGL_RED_SIZE: "		<< eglu::getConfigAttribInt(display, config, EGL_RED_SIZE)		<< TestLog::EndMessage;
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << "EGL_GREEN_SIZE: "	<< eglu::getConfigAttribInt(display, config, EGL_GREEN_SIZE)	<< TestLog::EndMessage;
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << "EGL_BLUE_SIZE: "	<< eglu::getConfigAttribInt(display, config, EGL_BLUE_SIZE)		<< TestLog::EndMessage;
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << "EGL_ALPHA_SIZE: "	<< eglu::getConfigAttribInt(display, config, EGL_ALPHA_SIZE)	<< TestLog::EndMessage;
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << "EGL_DEPTH_SIZE: "	<< eglu::getConfigAttribInt(display, config, EGL_DEPTH_SIZE)	<< TestLog::EndMessage;
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << "EGL_STENCIL_SIZE: "	<< eglu::getConfigAttribInt(display, config, EGL_STENCIL_SIZE)	<< TestLog::EndMessage;
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << "EGL_SAMPLES: "		<< eglu::getConfigAttribInt(display, config, EGL_SAMPLES)		<< TestLog::EndMessage;
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (nativeType == NativeColorMappingCase::NATIVETYPE_WINDOW)
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log << TestLog::Message << "Waiting " << waitFrames * 16 << "ms after eglSwapBuffers() and glFinish() for frame to become visible" << TestLog::EndMessage;
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool testNativeWindow (TestLog& log, eglu::NativeDisplay& nativeDisplay, eglu::NativeWindow& nativeWindow, EGLDisplay display, EGLContext context, EGLConfig config, const glw::Functions& gl, bool renderColor, int waitFrames, size_t colorCount, const tcu::Vec4* colors)
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	eglu::UniqueSurface	surface(display, eglu::createWindowSurface(nativeDisplay, nativeWindow, display, config, DE_NULL));
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureLevel	result;
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			program	= 0;
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool				isOk	= true;
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	try
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK_EGL_CALL(eglMakeCurrent(display, *surface, *surface, context));
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (renderColor)
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			program = createGLES2Program(gl, log);
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int colorNdx = 0; colorNdx < (int)colorCount; colorNdx++)
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (renderColor)
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				render(gl, program, colors[colorNdx]);
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				clear(gl, colors[colorNdx]);
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			TCU_CHECK_EGL_CALL(eglSwapBuffers(display, *surface));
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			TCU_CHECK_EGL_CALL(eglWaitClient());
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deSleep(waitFrames*16);
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			nativeWindow.readScreenPixels(&result);
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!validate(log, display, config, result, colors[colorNdx]))
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				isOk = false;
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK_EGL_CALL(eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	catch (...)
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (program)
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.deleteProgram(program);
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw;
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return isOk;
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool testNativePixmap (TestLog& log, eglu::NativeDisplay& nativeDisplay, eglu::NativePixmap& nativePixmap, EGLDisplay display, EGLContext context, EGLConfig config, const glw::Functions& gl, bool renderColor, size_t colorCount, const tcu::Vec4* colors)
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	eglu::UniqueSurface	surface(display, eglu::createPixmapSurface(nativeDisplay, nativePixmap, display, config, DE_NULL));
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureLevel	result;
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			program	= 0;
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool				isOk	= true;
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	try
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK_EGL_CALL(eglMakeCurrent(display, *surface, *surface, context));
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (renderColor)
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			program = createGLES2Program(gl, log);
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int colorNdx = 0; colorNdx < (int)colorCount; colorNdx++)
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (renderColor)
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				render(gl, program, colors[colorNdx]);
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				clear(gl, colors[colorNdx]);
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			TCU_CHECK_EGL_CALL(eglWaitClient());
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			nativePixmap.readPixels(&result);
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!validate(log, display, config, result, colors[colorNdx]))
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				isOk = false;
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK_EGL_CALL(eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	catch (...)
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (program)
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.deleteProgram(program);
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw;
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return isOk;
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool testNativePixmapCopy (TestLog& log, eglu::NativePixmap& nativePixmap, EGLDisplay display, EGLContext context, EGLConfig config, const glw::Functions& gl, bool renderColor, size_t colorCount, const tcu::Vec4* colors)
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	eglu::UniqueSurface	surface(display, eglCreatePbufferSurface(display, config, DE_NULL));
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureLevel	result;
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			program	= 0;
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool				isOk	= true;
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	try
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK_EGL_CALL(eglMakeCurrent(display, *surface, *surface, context));
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (renderColor)
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			program = createGLES2Program(gl, log);
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int colorNdx = 0; colorNdx < (int)colorCount; colorNdx++)
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (renderColor)
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				render(gl, program, colors[colorNdx]);
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				clear(gl, colors[colorNdx]);
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			TCU_CHECK_EGL_CALL(eglCopyBuffers(display, *surface, nativePixmap.getLegacyNative()));
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			TCU_CHECK_EGL_CALL(eglWaitClient());
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			nativePixmap.readPixels(&result);
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!validate(log, display, config, result, colors[colorNdx]))
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				isOk = false;
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK_EGL_CALL(eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	catch (...)
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (program)
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.deleteProgram(program);
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw;
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return isOk;
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid checkSupport (EglTestContext& eglTestCtx, NativeColorMappingCase::NativeType nativeType)
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (nativeType)
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case NativeColorMappingCase::NATIVETYPE_WINDOW:
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if ((eglTestCtx.getNativeWindowFactory().getCapabilities() & eglu::NativeWindow::CAPABILITY_READ_SCREEN_PIXELS) == 0)
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				throw tcu::NotSupportedError("Native window doesn't support readPixels()", "", __FILE__, __LINE__);
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case NativeColorMappingCase::NATIVETYPE_PIXMAP:
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if ((eglTestCtx.getNativePixmapFactory().getCapabilities() & eglu::NativePixmap::CAPABILITY_READ_PIXELS) == 0)
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				throw tcu::NotSupportedError("Native pixmap doesn't support readPixels()", "", __FILE__, __LINE__);
4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case NativeColorMappingCase::NATIVETYPE_PBUFFER_COPY_TO_PIXMAP:
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if ((eglTestCtx.getNativePixmapFactory().getCapabilities() & eglu::NativePixmap::CAPABILITY_READ_PIXELS) == 0 ||
4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				(eglTestCtx.getNativePixmapFactory().getCapabilities() & eglu::NativePixmap::CAPABILITY_CREATE_SURFACE_LEGACY) == 0)
4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				throw tcu::NotSupportedError("Native pixmap doesn't support readPixels() or legacy create surface", "", __FILE__, __LINE__);
4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(DE_FALSE);
4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid NativeColorMappingCase::executeForConfig (tcu::egl::Display& display, EGLConfig config)
4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int width		= 128;
4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int height	= 128;
4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Vec4 colors[] =
4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f),
4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f),
4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f),
4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4(0.0f, 1.0f, 1.0f, 1.0f),
4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f),
4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4(1.0f, 0.0f, 1.0f, 1.0f),
4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f),
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f),
4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4(0.0f, 0.0f, 0.5f, 1.0f),
4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4(0.0f, 0.5f, 0.0f, 1.0f),
4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4(0.0f, 0.5f, 0.5f, 1.0f),
4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4(0.5f, 0.0f, 0.0f, 1.0f),
4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4(0.5f, 0.0f, 0.5f, 1.0f),
4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4(0.5f, 0.5f, 0.0f, 1.0f),
4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4(0.5f, 0.5f, 0.5f, 1.0f)
4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const string			configIdStr	(de::toString(eglu::getConfigAttribInt(display.getEGLDisplay(), config, EGL_CONFIG_ID)));
4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::ScopedLogSection	logSection	(m_testCtx.getLog(), ("Config ID " + configIdStr).c_str(), ("Config ID " + configIdStr).c_str());
4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				waitFrames	= 5;
4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	logConfigInfo(m_testCtx.getLog(), display.getEGLDisplay(), config, m_nativeType, waitFrames);
4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	checkSupport(m_eglTestCtx, m_nativeType);
4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	eglu::UniqueContext context(display.getEGLDisplay(), createGLES2Context(display.getEGLDisplay(), config));
5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glw::Functions		gl;
5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_eglTestCtx.getGLFunctions(gl, glu::ApiType::es(2,0));
5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (m_nativeType)
5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case NATIVETYPE_WINDOW:
5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			de::UniquePtr<eglu::NativeWindow> nativeWindow(m_eglTestCtx.createNativeWindow(display.getEGLDisplay(), config, DE_NULL, width, height, eglu::WindowParams::VISIBILITY_VISIBLE));
5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!testNativeWindow(m_testCtx.getLog(), m_eglTestCtx.getNativeDisplay(), *nativeWindow, display.getEGLDisplay(), *context, config, gl, m_render, waitFrames, DE_LENGTH_OF_ARRAY(colors), colors))
5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid color rendered");
5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case NATIVETYPE_PIXMAP:
5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			de::UniquePtr<eglu::NativePixmap> nativePixmap(m_eglTestCtx.createNativePixmap(display.getEGLDisplay(), config, DE_NULL, width, height));
5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!testNativePixmap(m_testCtx.getLog(), m_eglTestCtx.getNativeDisplay(), *nativePixmap, display.getEGLDisplay(), *context, config, gl, m_render, DE_LENGTH_OF_ARRAY(colors), colors))
5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid color rendered");
5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case NATIVETYPE_PBUFFER_COPY_TO_PIXMAP:
5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			de::UniquePtr<eglu::NativePixmap> nativePixmap(m_eglTestCtx.createNativePixmap(display.getEGLDisplay(), config, DE_NULL, width, height));
5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!testNativePixmapCopy(m_testCtx.getLog(), *nativePixmap, display.getEGLDisplay(), *context, config, gl, m_render, DE_LENGTH_OF_ARRAY(colors), colors))
5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid color rendered");
5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(DE_FALSE);
5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid addTestGroups (EglTestContext& eglTestCtx, TestCaseGroup* group, NativeColorMappingCase::NativeType type)
5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	eglu::FilterList filters;
5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (type)
5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case NativeColorMappingCase::NATIVETYPE_WINDOW:
5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			filters << (eglu::ConfigSurfaceType() & EGL_WINDOW_BIT);
5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case NativeColorMappingCase::NATIVETYPE_PIXMAP:
5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			filters << (eglu::ConfigSurfaceType() & EGL_PIXMAP_BIT);
5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case NativeColorMappingCase::NATIVETYPE_PBUFFER_COPY_TO_PIXMAP:
5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			filters << (eglu::ConfigSurfaceType() & EGL_PBUFFER_BIT);
5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(DE_FALSE);
5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<NamedConfigIdSet> configIdSets;
5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NamedConfigIdSet::getDefaultSets(configIdSets, eglTestCtx.getConfigs(), filters);
5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (vector<NamedConfigIdSet>::iterator i = configIdSets.begin(); i != configIdSets.end(); i++)
5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		group->addChild(new NativeColorMappingCase(eglTestCtx, (string(i->getName()) + "_clear").c_str(), i->getDescription(), false, type, i->getConfigIds()));
5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		group->addChild(new NativeColorMappingCase(eglTestCtx, (string(i->getName()) + "_render").c_str(), i->getDescription(), true, type, i->getConfigIds()));
5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // anonymous
5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5733c827367444ee418f129b2c238299f49d3264554Jarkko PoyryNativeColorMappingTests::NativeColorMappingTests (EglTestContext& eglTestCtx)
5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(eglTestCtx, "native_color_mapping", "Tests for mapping client colors to native surface")
5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid NativeColorMappingTests::init (void)
5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TestCaseGroup* windowGroup = new TestCaseGroup(m_eglTestCtx, "native_window", "Tests for mapping client color to native window");
5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addTestGroups(m_eglTestCtx, windowGroup, NativeColorMappingCase::NATIVETYPE_WINDOW);
5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(windowGroup);
5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TestCaseGroup* pixmapGroup = new TestCaseGroup(m_eglTestCtx, "native_pixmap", "Tests for mapping client color to native pixmap");
5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addTestGroups(m_eglTestCtx, pixmapGroup, NativeColorMappingCase::NATIVETYPE_PIXMAP);
5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(pixmapGroup);
5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TestCaseGroup* pbufferGroup = new TestCaseGroup(m_eglTestCtx, "pbuffer_to_native_pixmap", "Tests for mapping client color to native pixmap with eglCopyBuffers()");
5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addTestGroups(m_eglTestCtx, pbufferGroup, NativeColorMappingCase::NATIVETYPE_PBUFFER_COPY_TO_PIXMAP);
5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(pbufferGroup);
5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // egl
6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
601