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 glDepthRangef() tests.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es2fDepthRangeTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuVector.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuImageCompare.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderProgram.hpp"
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderContext.hpp"
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.hpp"
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMath.h"
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h"
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glw.h"
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles2
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VISUALIZE_DEPTH_STEPS	= 32 //!< Number of depth steps in visualization
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec2;
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec3;
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec4;
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog;
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string;
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector;
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* s_vertexShaderSrc =
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"attribute highp vec4 a_position;\n"
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"attribute highp vec2 a_coord;\n"
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"void main (void)\n"
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"{\n"
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"	gl_Position = a_position;\n"
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"}\n";
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* s_fragmentShaderSrc =
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"uniform mediump vec4 u_color;\n"
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"void main (void)\n"
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"{\n"
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"	gl_FragColor = u_color;\n"
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	"}\n";
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T>
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline bool compare (deUint32 func, T a, T b)
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (func)
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_NEVER:		return false;
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_ALWAYS:		return true;
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_LESS:		return a < b;
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_LEQUAL:		return a <= b;
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_EQUAL:		return a == b;
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_NOTEQUAL:	return a != b;
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_GEQUAL:		return a >= b;
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_GREATER:	return a > b;
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(DE_FALSE);
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return false;
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline float triangleInterpolate (const float v0, const float v1, const float v2, const float x, const float y)
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return v0 + (v2-v0)*x + (v1-v0)*y;
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline float triQuadInterpolate (const float x, const float y, const tcu::Vec4& quad)
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// \note Top left fill rule.
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (x + y < 1.0f)
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return triangleInterpolate(quad.x(), quad.y(), quad.z(), x, y);
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return triangleInterpolate(quad.w(), quad.z(), quad.y(), 1.0f-x, 1.0f-y);
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline float depthRangeTransform (const float zd, const float zNear, const float zFar)
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float	cNear	= de::clamp(zNear, 0.0f, 1.0f);
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float	cFar	= de::clamp(zFar, 0.0f, 1.0f);
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return ((cFar - cNear)/2.0f) * zd + (cNear + cFar)/2.0f;
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass DepthRangeCompareCase : public TestCase
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							DepthRangeCompareCase	(Context& context, const char* name, const char* desc, const tcu::Vec4& depthCoord, const float zNear, const float zFar, const deUint32 compareFunc);
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							~DepthRangeCompareCase	(void);
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult			iterate					(void);
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Vec4			m_depthCoord;
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				m_zNear;
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				m_zFar;
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32			m_compareFunc;
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1273c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDepthRangeCompareCase::DepthRangeCompareCase (Context& context, const char* name, const char* desc, const tcu::Vec4& depthCoord, const float zNear, const float zFar, const deUint32 compareFunc)
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase			(context, name, desc)
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_depthCoord		(depthCoord)
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_zNear			(zNear)
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_zFar			(zFar)
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_compareFunc		(compareFunc)
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1363c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDepthRangeCompareCase::~DepthRangeCompareCase (void)
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1403c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDepthRangeCompareCase::IterateResult DepthRangeCompareCase::iterate (void)
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestLog&					log					= m_testCtx.getLog();
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	de::Random					rnd					(deStringHash(getName()));
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::RenderTarget&	renderTarget		= m_context.getRenderContext().getRenderTarget();
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					viewportW			= de::min(128, renderTarget.getWidth());
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					viewportH			= de::min(128, renderTarget.getHeight());
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					viewportX			= rnd.getInt(0, renderTarget.getWidth()-viewportW);
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					viewportY			= rnd.getInt(0, renderTarget.getHeight()-viewportH);
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface				renderedFrame		(viewportW, viewportH);
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface				referenceFrame		(viewportW, viewportH);
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float					constDepth			= 0.1f;
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (renderTarget.getDepthBits() == 0)
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::NotSupportedError("Depth buffer is required", "", __FILE__, __LINE__);
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glu::ShaderProgram	program				(m_context.getRenderContext(), glu::makeVtxFragSources(s_vertexShaderSrc, s_fragmentShaderSrc));
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!program.isOk())
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log << program;
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_FAIL("Compile failed");
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					colorLoc			= glGetUniformLocation(program.getProgram(), "u_color");
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					posLoc				= glGetAttribLocation(program.getProgram(), "a_position");
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << TestLog::Message << "glDepthRangef(" << m_zNear << ", " << m_zFar << ")" << TestLog::EndMessage;
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glViewport(viewportX, viewportY, viewportW, viewportH);
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glEnable(GL_DEPTH_TEST);
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glUseProgram(program.getProgram());
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glEnableVertexAttribArray(posLoc);
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const deUint16 quadIndices[] = { 0, 1, 2, 2, 1, 3 };
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Fill viewport with 2 quads - one with constant depth and another with d = [-1..1]
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		static const float constDepthCoord[] =
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			-1.0f, -1.0f, constDepth, 1.0f,
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			-1.0f, +1.0f, constDepth, 1.0f,
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			 0.0f, -1.0f, constDepth, 1.0f,
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			 0.0f, +1.0f, constDepth, 1.0f
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		};
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		static const float varyingDepthCoord[] =
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			 0.0f, -1.0f, +1.0f, 1.0f,
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			 0.0f, +1.0f,  0.0f, 1.0f,
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			+1.0f, -1.0f,  0.0f, 1.0f,
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			+1.0f, +1.0f, -1.0f, 1.0f
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		};
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glUniform4f(colorLoc, 0.0f, 0.0f, 1.0f, 1.0f);
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glDepthFunc(GL_ALWAYS);
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glVertexAttribPointer(posLoc, 4, GL_FLOAT, GL_FALSE, 0, &constDepthCoord);
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glDrawElements(GL_TRIANGLES, DE_LENGTH_OF_ARRAY(quadIndices), GL_UNSIGNED_SHORT, &quadIndices[0]);
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glVertexAttribPointer(posLoc, 4, GL_FLOAT, GL_FALSE, 0, &varyingDepthCoord);
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glDrawElements(GL_TRIANGLES, DE_LENGTH_OF_ARRAY(quadIndices), GL_UNSIGNED_SHORT, &quadIndices[0]);
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK();
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render with depth test.
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float position[] =
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			-1.0f, -1.0f, m_depthCoord[0], 1.0f,
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			-1.0f, +1.0f, m_depthCoord[1], 1.0f,
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			+1.0f, -1.0f, m_depthCoord[2], 1.0f,
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			+1.0f, +1.0f, m_depthCoord[3], 1.0f
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		};
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glDepthRangef(m_zNear, m_zFar);
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glDepthFunc(m_compareFunc);
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glUniform4f(colorLoc, 0.0f, 1.0f, 0.0f, 1.0f);
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glVertexAttribPointer(posLoc, 4, GL_FLOAT, GL_FALSE, 0, &position[0]);
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glDrawElements(GL_TRIANGLES, DE_LENGTH_OF_ARRAY(quadIndices), GL_UNSIGNED_SHORT, &quadIndices[0]);
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK();
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::readPixels(m_context.getRenderContext(), viewportX, viewportY, renderedFrame.getAccess());
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render reference.
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int y = 0; y < referenceFrame.getHeight(); y++)
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float	yf		= ((float)y + 0.5f) / referenceFrame.getHeight();
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int		half	= de::clamp((int)((float)referenceFrame.getWidth()*0.5f + 0.5f), 0, referenceFrame.getWidth());
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Fill left half - comparison to constant 0.5
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int x = 0; x < half; x++)
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			float	xf		= ((float)x + 0.5f) / (float)referenceFrame.getWidth();
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			float	d		= depthRangeTransform(triQuadInterpolate(xf, yf, m_depthCoord), m_zNear, m_zFar);
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			bool	dpass	= compare(m_compareFunc, d, constDepth*0.5f + 0.5f);
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			referenceFrame.setPixel(x, y, dpass ? tcu::RGBA::green : tcu::RGBA::blue);
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Fill right half - comparison to interpolated depth
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int x = half; x < referenceFrame.getWidth(); x++)
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			float	xf		= ((float)x + 0.5f) / (float)referenceFrame.getWidth();
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			float	xh		= ((float)x - half + 0.5f) / (float)(referenceFrame.getWidth()-half);
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			float	rd		= 1.0f - (xh + yf) * 0.5f;
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			float	d		= depthRangeTransform(triQuadInterpolate(xf, yf, m_depthCoord), m_zNear, m_zFar);
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			bool	dpass	= compare(m_compareFunc, d, rd);
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			referenceFrame.setPixel(x, y, dpass ? tcu::RGBA::green : tcu::RGBA::blue);
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool isOk = tcu::fuzzyCompare(log, "Result", "Image comparison result", referenceFrame, renderedFrame, 0.05f, tcu::COMPARE_LOG_RESULT);
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS	: QP_TEST_RESULT_FAIL,
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							isOk ? "Pass"				: "Fail");
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass DepthRangeWriteCase : public TestCase
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							DepthRangeWriteCase		(Context& context, const char* name, const char* desc, const tcu::Vec4& depthCoord, const float zNear, const float zFar);
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							~DepthRangeWriteCase	(void);
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult			iterate					(void);
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Vec4&		m_depthCoord;
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				m_zNear;
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				m_zFar;
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2773c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDepthRangeWriteCase::DepthRangeWriteCase (Context& context, const char* name, const char* desc, const tcu::Vec4& depthCoord, const float zNear, const float zFar)
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase			(context, name, desc)
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_depthCoord		(depthCoord)
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_zNear			(zNear)
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_zFar			(zFar)
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2853c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDepthRangeWriteCase::~DepthRangeWriteCase (void)
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2893c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDepthRangeWriteCase::IterateResult DepthRangeWriteCase::iterate (void)
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestLog&					log				= m_testCtx.getLog();
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	de::Random					rnd				(deStringHash(getName()));
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::RenderTarget&	renderTarget	= m_context.getRenderContext().getRenderTarget();
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					viewportW		= de::min(128, renderTarget.getWidth());
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					viewportH		= de::min(128, renderTarget.getHeight());
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					viewportX		= rnd.getInt(0, renderTarget.getWidth()-viewportW);
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					viewportY		= rnd.getInt(0, renderTarget.getHeight()-viewportH);
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface				renderedFrame	(viewportW, viewportH);
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface				referenceFrame	(viewportW, viewportH);
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					numDepthSteps	= VISUALIZE_DEPTH_STEPS;
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float					depthStep		= 1.0f/(float)(numDepthSteps-1);
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (renderTarget.getDepthBits() == 0)
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::NotSupportedError("Depth buffer is required", "", __FILE__, __LINE__);
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glu::ShaderProgram	program			(m_context.getRenderContext(), glu::makeVtxFragSources(s_vertexShaderSrc, s_fragmentShaderSrc));
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!program.isOk())
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log << program;
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_FAIL("Compile failed");
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					colorLoc		= glGetUniformLocation(program.getProgram(), "u_color");
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					posLoc			= glGetAttribLocation(program.getProgram(), "a_position");
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << TestLog::Message << "glDepthRangef(" << m_zNear << ", " << m_zFar << ")" << TestLog::EndMessage;
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glViewport(viewportX, viewportY, viewportW, viewportH);
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glEnable(GL_DEPTH_TEST);
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glUseProgram(program.getProgram());
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glEnableVertexAttribArray(posLoc);
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const deUint16 quadIndices[] = { 0, 1, 2, 2, 1, 3 };
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render with depth range.
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float position[] =
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			-1.0f, -1.0f, m_depthCoord[0], 1.0f,
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			-1.0f, +1.0f, m_depthCoord[1], 1.0f,
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			+1.0f, -1.0f, m_depthCoord[2], 1.0f,
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			+1.0f, +1.0f, m_depthCoord[3], 1.0f
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		};
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glDepthFunc(GL_ALWAYS);
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glDepthRangef(m_zNear, m_zFar);
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glUniform4f(colorLoc, 0.0f, 1.0f, 0.0f, 1.0f);
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glVertexAttribPointer(posLoc, 4, GL_FLOAT, GL_FALSE, 0, &position[0]);
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glDrawElements(GL_TRIANGLES, DE_LENGTH_OF_ARRAY(quadIndices), GL_UNSIGNED_SHORT, &quadIndices[0]);
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK();
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Visualize by rendering full-screen quads with increasing depth and color.
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glDepthFunc(GL_LEQUAL);
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glDepthMask(GL_FALSE);
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glDepthRangef(0.0f, 1.0f);
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int stepNdx = 0; stepNdx < numDepthSteps; stepNdx++)
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			float	f		= (float)stepNdx*depthStep;
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			float	depth	= f*2.0f - 1.0f;
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			Vec4	color	= Vec4(f, f, f, 1.0f);
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			float position[] =
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				-1.0f, -1.0f, depth, 1.0f,
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				-1.0f, +1.0f, depth, 1.0f,
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				+1.0f, -1.0f, depth, 1.0f,
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				+1.0f, +1.0f, depth, 1.0f
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			};
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			glUniform4fv(colorLoc, 1, color.getPtr());
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			glVertexAttribPointer(posLoc, 4, GL_FLOAT, GL_FALSE, 0, &position[0]);
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			glDrawElements(GL_TRIANGLES, DE_LENGTH_OF_ARRAY(quadIndices), GL_UNSIGNED_SHORT, &quadIndices[0]);
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK();
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::readPixels(m_context.getRenderContext(), viewportX, viewportY, renderedFrame.getAccess());
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render reference.
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int y = 0; y < referenceFrame.getHeight(); y++)
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int x = 0; x < referenceFrame.getWidth(); x++)
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			float	xf		= ((float)x + 0.5f) / (float)referenceFrame.getWidth();
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			float	yf		= ((float)y + 0.5f) / (float)referenceFrame.getHeight();
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			float	d		= depthRangeTransform(triQuadInterpolate(xf, yf, m_depthCoord), m_zNear, m_zFar);
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int		step	= (int)deFloatFloor(d / depthStep);
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int		col		= de::clamp(deRoundFloatToInt32((float)step*depthStep*255.0f), 0, 255);
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			referenceFrame.setPixel(x, y, tcu::RGBA(col, col, col, 0xff));
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool isOk = tcu::fuzzyCompare(log, "Result", "Image comparison result", referenceFrame, renderedFrame, 0.05f, tcu::COMPARE_LOG_RESULT);
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS	: QP_TEST_RESULT_FAIL,
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							isOk ? "Pass"				: "Fail");
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3963c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDepthRangeTests::DepthRangeTests (Context& context)
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(context, "depth_range", "glDepthRangef() tests")
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4013c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDepthRangeTests::~DepthRangeTests (void)
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid DepthRangeTests::init (void)
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*			name;
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*			desc;
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::Vec4		depthCoord;
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float			zNear;
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float			zFar;
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} cases[] =
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "default",		"Default depth range",		tcu::Vec4(-1.0f, 0.2f, -0.3f, 1.0f),	0.0f,		1.0f },
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "reverse",		"Reversed default range",	tcu::Vec4(-1.0f, 0.2f, -0.3f, 1.0f),	1.0f,		0.0f },
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "zero_to_half",	"From 0 to 0.5",			tcu::Vec4(-1.0f, 0.2f, -0.3f, 1.0f),	0.0f,		0.5f },
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "half_to_one",	"From 0.5 to 1",			tcu::Vec4(-1.0f, 0.2f, -0.3f, 1.0f),	0.5f,		1.0f },
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "half_to_zero",	"From 0.5 to 0",			tcu::Vec4(-1.0f, 0.2f, -0.3f, 1.0f),	0.5f,		0.0f },
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "one_to_half",	"From 1 to 0.5",			tcu::Vec4(-1.0f, 0.2f, -0.3f, 1.0f),	1.0f,		0.5f },
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "third_to_0_8",	"From 1/3 to 0.8",			tcu::Vec4(-1.0f, 0.2f, -0.3f, 1.0f),	1.0f/3.0f,	0.8f },
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "0_8_to_third",	"From 0.8 to 1/3",			tcu::Vec4(-1.0f, 0.2f, -0.3f, 1.0f),	0.8f,		1.0f/3.0f },
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "zero_to_zero",	"From 0 to 0",				tcu::Vec4(-1.0f, 0.2f, -0.3f, 1.0f),	0.0f,		0.0f },
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "half_to_half",	"From 0.5 to 0.5",			tcu::Vec4(-1.0f, 0.2f, -0.3f, 1.0f),	0.5f,		0.5f },
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "one_to_one",		"From 1 to 1",				tcu::Vec4(-1.0f, 0.2f, -0.3f, 1.0f),	1.0f,		1.0f },
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "clamp_near",		"From -1 to 1",				tcu::Vec4(-1.0f, 0.2f, -0.3f, 1.0f),	-1.0f,		1.0f },
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "clamp_far",		"From 0 to 2",				tcu::Vec4(-1.0f, 0.2f, -0.3f, 1.0f),	0.0f,		2.0 },
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "clamp_both",		"From -1 to 2",				tcu::Vec4(-1.0f, 0.2f, -0.3f, 1.0f),	-1.0,		2.0 }
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// .write
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TestCaseGroup* writeGroup = new tcu::TestCaseGroup(m_testCtx, "write", "gl_FragDepth write tests");
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(writeGroup);
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(cases); ndx++)
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		writeGroup->addChild(new DepthRangeWriteCase(m_context, cases[ndx].name, cases[ndx].desc, cases[ndx].depthCoord, cases[ndx].zNear, cases[ndx].zFar));
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// .compare
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TestCaseGroup* compareGroup = new tcu::TestCaseGroup(m_testCtx, "compare", "gl_FragDepth used with depth comparison");
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(compareGroup);
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(cases); ndx++)
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		compareGroup->addChild(new DepthRangeCompareCase(m_context, cases[ndx].name, cases[ndx].desc, cases[ndx].depthCoord, cases[ndx].zNear, cases[ndx].zFar, GL_LESS));
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles3
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
448