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 Depth & stencil tests.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es2fDepthStencilTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsFragmentOpUtil.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluStrUtil.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuImageCompare.hpp"
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuCommandLine.hpp"
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp"
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.hpp"
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp"
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMemory.h"
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h"
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rrFragmentOperations.hpp"
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "sglrReferenceUtils.hpp"
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <algorithm>
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <sstream>
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glw.h"
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles2
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector;
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::IVec2;
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec2;
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec4;
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog;
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::ostringstream;
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VIEWPORT_WIDTH			= 4*3*4,
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VIEWPORT_HEIGHT			= 4*12,
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NUM_RANDOM_CASES		= 25,
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NUM_RANDOM_SUB_CASES	= 10
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace DepthStencilCaseUtil
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct StencilParams
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	function;
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			reference;
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	compareMask;
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	stencilFailOp;
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	depthFailOp;
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	depthPassOp;
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	writeMask;
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	StencilParams (void)
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: function		(0)
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, reference		(0)
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, compareMask	(0)
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, stencilFailOp	(0)
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, depthFailOp	(0)
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, depthPassOp	(0)
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, writeMask		(0)
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct DepthStencilParams
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rr::FaceType	visibleFace;			//!< Quad visible face.
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool			stencilTestEnabled;
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	StencilParams	stencil[rr::FACETYPE_LAST];
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool			depthTestEnabled;
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32		depthFunc;
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float			depth;
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool			depthWriteMask;
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DepthStencilParams (void)
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: visibleFace			(rr::FACETYPE_LAST)
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, stencilTestEnabled	(false)
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, depthTestEnabled		(false)
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, depthFunc				(0)
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, depth					(0.0f)
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, depthWriteMask		(false)
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::TestLog& operator<< (tcu::TestLog& log, const StencilParams& params)
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << "  func = " << glu::getCompareFuncStr(params.function) << "\n"
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< "  ref = " << params.reference << "\n"
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< "  compare mask = " << tcu::toHex(params.compareMask) << "\n"
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< "  stencil fail = " << glu::getStencilOpStr(params.stencilFailOp) << "\n"
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< "  depth fail = " << glu::getStencilOpStr(params.depthFailOp) << "\n"
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< "  depth pass = " << glu::getStencilOpStr(params.depthPassOp) << "\n"
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< "  write mask = " << tcu::toHex(params.writeMask) << "\n"
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< TestLog::EndMessage;
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return log;
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::TestLog& operator<< (tcu::TestLog& log, const DepthStencilParams& params)
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << "Stencil test: " << (params.stencilTestEnabled ? "enabled" : "disabled") << TestLog::EndMessage;
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (params.stencilTestEnabled)
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log << TestLog::Message << "Front-face stencil state: " << TestLog::EndMessage;
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log << params.stencil[rr::FACETYPE_FRONT];
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log << TestLog::Message << "Back-face stencil state: " << TestLog::EndMessage;
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log << params.stencil[rr::FACETYPE_BACK];
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << "Depth test: " << (params.depthTestEnabled ? "enabled" : "disabled") << TestLog::EndMessage;
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (params.depthTestEnabled)
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log << TestLog::Message << "  func = " << glu::getCompareFuncStr(params.depthFunc) << "\n"
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								   "  depth value = " << params.depth << "\n"
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								   "  write mask = " << (params.depthWriteMask ? "true" : "false") << "\n"
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< TestLog::EndMessage;
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << "Triangles are " << (params.visibleFace == rr::FACETYPE_FRONT ? "front" : "back") << "-facing" << TestLog::EndMessage;
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return log;
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct ClearCommand
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rr::WindowRectangle	rect;
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			buffers;
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Vec4			color;
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					stencil;
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// \note No depth here - don't use clears for setting depth values; use quad rendering instead. Cleared depths are in [0, 1] to begin with,
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	//		 whereas rendered depths are given in [-1, 1] and then mapped to [0, 1]; this discrepancy could cause precision issues in depth tests.
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ClearCommand (void)
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: rect		(0, 0, 0, 0)
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, buffers	(0)
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, stencil	(0)
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ClearCommand (const rr::WindowRectangle&	rect_,
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				  deUint32					buffers_,
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				  const tcu::Vec4&			color_,
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				  int						stencil_)
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: rect		(rect_)
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, buffers	(buffers_)
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, color		(color_)
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, stencil	(stencil_)
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct RenderCommand
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DepthStencilParams		params;
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rr::WindowRectangle		rect;
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Vec4				color;
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::BVec4				colorMask;
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RenderCommand (void)
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: rect(0, 0, 0, 0)
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct RefRenderCommand
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gls::FragmentOpUtil::IntegerQuad	quad;
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rr::FragmentOperationState			state;
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct TestRenderTarget
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int		width;
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int		height;
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int		depthBits;
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int		stencilBits;
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestRenderTarget (int width_,
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					  int height_,
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					  int depthBits_,
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					  int stencilBits_)
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: width			(width_)
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, height		(height_)
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, depthBits		(depthBits_)
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, stencilBits	(stencilBits_)
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestRenderTarget (void)
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: width			(0)
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, height		(0)
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, depthBits		(0)
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, stencilBits	(0)
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid getStencilTestValues (int stencilBits, int numValues, int* values)
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int numLowest		= numValues/2;
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int	numHighest		= numValues-numLowest;
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int	maxVal			= (1<<stencilBits)-1;
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < numLowest; ndx++)
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		values[ndx] = ndx;
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < numHighest; ndx++)
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		values[numValues-ndx-1] = maxVal-ndx;
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid generateBaseClearAndDepthCommands (const TestRenderTarget& target, vector<ClearCommand>& clearCommands, vector<RenderCommand>& renderCommands)
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(clearCommands.empty());
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(renderCommands.empty());
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int		numL0CellsX		= 4;
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int		numL0CellsY		= 4;
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int		numL1CellsX		= 3;
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int		numL1CellsY		= 1;
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				cellL0Width		= target.width/numL0CellsX;
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				cellL0Height	= target.height/numL0CellsY;
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				cellL1Width		= cellL0Width/numL1CellsX;
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				cellL1Height	= cellL0Height/numL1CellsY;
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				stencilValues[numL0CellsX*numL0CellsY];
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float			depthValues[numL1CellsX*numL1CellsY];
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (cellL0Width <= 0 || cellL1Width <= 0 || cellL0Height <= 0 || cellL1Height <= 0)
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::NotSupportedError("Too small render target");
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Fullscreen clear to black.
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	clearCommands.push_back(ClearCommand(rr::WindowRectangle(0, 0, target.width, target.height), GL_COLOR_BUFFER_BIT, Vec4(0.0f, 0.0f, 0.0f, 1.0f), 0));
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Compute stencil values: numL0CellsX*numL0CellsY combinations of lowest and highest bits.
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	getStencilTestValues(target.stencilBits, numL0CellsX*numL0CellsY, &stencilValues[0]);
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Compute depth values
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int		numValues		= DE_LENGTH_OF_ARRAY(depthValues);
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float	depthStep		= 2.0f/(numValues-1);
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int ndx = 0; ndx < numValues; ndx++)
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			depthValues[ndx] = -1.0f + depthStep*ndx;
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int y0 = 0; y0 < numL0CellsY; y0++)
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int x0 = 0; x0 < numL0CellsX; x0++)
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int stencilValue = stencilValues[y0*numL0CellsX + x0];
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int y1 = 0; y1 < numL1CellsY; y1++)
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				for (int x1 = 0; x1 < numL1CellsX; x1++)
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					int					x			= x0*cellL0Width + x1*cellL1Width;
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					int					y			= y0*cellL0Height + y1*cellL1Height;
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					rr::WindowRectangle	cellL1Rect	(x, y, cellL1Width, cellL1Height);
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					clearCommands.push_back(ClearCommand(cellL1Rect, GL_STENCIL_BUFFER_BIT, Vec4(0), stencilValue));
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					RenderCommand renderCmd;
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					renderCmd.params.visibleFace		= rr::FACETYPE_FRONT;
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					renderCmd.params.depth				= depthValues[y1*numL1CellsX + x1];;
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					renderCmd.params.depthTestEnabled	= true;
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					renderCmd.params.depthFunc			= GL_ALWAYS;
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					renderCmd.params.depthWriteMask		= true;
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					renderCmd.colorMask					= tcu::BVec4(false);
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					renderCmd.rect						= cellL1Rect;
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					renderCommands.push_back(renderCmd);
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid generateDepthVisualizeCommands (const TestRenderTarget& target, vector<RenderCommand>& commands)
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float			epsilon			= -0.05f;
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const float	depthSteps[]	= {-1.0f, -0.5f, 0.0f, 0.5f, 1.0f};
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					numSteps		= DE_LENGTH_OF_ARRAY(depthSteps);
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float			colorStep		= 1.0f / (float)(numSteps-1);
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < numSteps; ndx++)
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		RenderCommand cmd;
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.params.visibleFace		= rr::FACETYPE_FRONT;
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.rect					= rr::WindowRectangle(0, 0, target.width, target.height);
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.color					= Vec4(0.0f, 0.0f, colorStep*ndx, 0.0f);
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.colorMask				= tcu::BVec4(false, false, true, false);
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.params.depth			= depthSteps[ndx]+epsilon;
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.params.depthTestEnabled	= true;
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.params.depthFunc		= GL_LESS;
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.params.depthWriteMask	= false;
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		commands.push_back(cmd);
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid generateStencilVisualizeCommands (const TestRenderTarget& target, vector<RenderCommand>& commands)
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int	numValues		= 4*4;
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float		colorStep		= 1.0f / numValues; // 0 is reserved for non-matching.
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			stencilValues[numValues];
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	getStencilTestValues(target.stencilBits, numValues, &stencilValues[0]);
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < numValues; ndx++)
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		RenderCommand cmd;
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.params.visibleFace							= rr::FACETYPE_FRONT;
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.rect										= rr::WindowRectangle(0, 0, target.width, target.height);
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.color										= Vec4(0.0f, colorStep*(ndx+1), 0.0f, 0.0f);
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.colorMask									= tcu::BVec4(false, true, false, false);
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.params.stencilTestEnabled					= true;
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.params.stencil[rr::FACETYPE_FRONT].function			= GL_EQUAL;
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.params.stencil[rr::FACETYPE_FRONT].reference		= stencilValues[ndx];
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.params.stencil[rr::FACETYPE_FRONT].compareMask		= ~0u;
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.params.stencil[rr::FACETYPE_FRONT].stencilFailOp	= GL_KEEP;
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.params.stencil[rr::FACETYPE_FRONT].depthFailOp		= GL_KEEP;
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.params.stencil[rr::FACETYPE_FRONT].depthPassOp		= GL_KEEP;
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.params.stencil[rr::FACETYPE_FRONT].writeMask		= 0u;
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		cmd.params.stencil[rr::FACETYPE_BACK] = cmd.params.stencil[rr::FACETYPE_FRONT];
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		commands.push_back(cmd);
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid translateStencilState (const StencilParams& src, rr::StencilState& dst)
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst.func		= sglr::rr_util::mapGLTestFunc(src.function);
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst.ref			= src.reference;
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst.compMask	= src.compareMask;
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst.sFail		= sglr::rr_util::mapGLStencilOp(src.stencilFailOp);
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst.dpFail		= sglr::rr_util::mapGLStencilOp(src.depthFailOp);
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst.dpPass		= sglr::rr_util::mapGLStencilOp(src.depthPassOp);
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst.writeMask	= src.writeMask;
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid translateCommand (const RenderCommand& src, RefRenderCommand& dst, const TestRenderTarget& renderTarget)
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float		far				= 1.0f;
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float		near			= 0.0f;
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool			hasDepth		= renderTarget.depthBits > 0;
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool			hasStencil		= renderTarget.stencilBits > 0;
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool			isFrontFacing	= src.params.visibleFace == rr::FACETYPE_FRONT;
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst.quad.posA = IVec2(isFrontFacing ? src.rect.left : (src.rect.left+src.rect.width-1), src.rect.bottom);
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst.quad.posB = IVec2(isFrontFacing ? (src.rect.left+src.rect.width-1) : src.rect.left, src.rect.bottom+src.rect.height-1);
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::fill(DE_ARRAY_BEGIN(dst.quad.color), DE_ARRAY_END(dst.quad.color), src.color);
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::fill(DE_ARRAY_BEGIN(dst.quad.depth), DE_ARRAY_END(dst.quad.depth), ((far-near)/2.0f) * src.params.depth + (near+far)/2.0f);
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst.state.colorMask = src.colorMask;
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst.state.scissorTestEnabled		= false;
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst.state.stencilTestEnabled		= hasStencil && src.params.stencilTestEnabled;
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst.state.depthTestEnabled			= hasDepth && src.params.depthTestEnabled;
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst.state.blendMode					= rr::BLENDMODE_NONE;
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst.state.numStencilBits			= renderTarget.stencilBits;
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (dst.state.depthTestEnabled)
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		dst.state.depthFunc					= sglr::rr_util::mapGLTestFunc(src.params.depthFunc);
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		dst.state.depthMask					= src.params.depthWriteMask;
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (dst.state.stencilTestEnabled)
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		translateStencilState(src.params.stencil[rr::FACETYPE_BACK],	dst.state.stencilStates[rr::FACETYPE_BACK]);
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		translateStencilState(src.params.stencil[rr::FACETYPE_FRONT],	dst.state.stencilStates[rr::FACETYPE_FRONT]);
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid render (const vector<ClearCommand>& clears, int viewportX, int viewportY)
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glEnable(GL_SCISSOR_TEST);
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < (int)clears.size(); ndx++)
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const ClearCommand& clear = clears[ndx];
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (clear.buffers & GL_COLOR_BUFFER_BIT)	glClearColor(clear.color.x(), clear.color.y(), clear.color.z(), clear.color.w());
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (clear.buffers & GL_STENCIL_BUFFER_BIT)	glClearStencil(clear.stencil);
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(clear.buffers == (clear.buffers & (GL_COLOR_BUFFER_BIT|GL_STENCIL_BUFFER_BIT))); // \note Don't use clear for depths.
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glScissor(clear.rect.left+viewportX, clear.rect.bottom+viewportY, clear.rect.width, clear.rect.height);
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glClear(clear.buffers);
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glDisable(GL_SCISSOR_TEST);
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid render (gls::FragmentOpUtil::QuadRenderer& renderer, const RenderCommand& command, int viewportX, int viewportY)
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (command.params.stencilTestEnabled)
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glEnable(GL_STENCIL_TEST);
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int face = 0; face < rr::FACETYPE_LAST; face++)
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint32				glFace	= face == rr::FACETYPE_BACK ? GL_BACK : GL_FRONT;
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const StencilParams&	sParams	= command.params.stencil[face];
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			glStencilFuncSeparate(glFace, sParams.function, sParams.reference, sParams.compareMask);
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			glStencilOpSeparate(glFace, sParams.stencilFailOp, sParams.depthFailOp, sParams.depthPassOp);
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			glStencilMaskSeparate(glFace, sParams.writeMask);
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glDisable(GL_STENCIL_TEST);
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (command.params.depthTestEnabled)
4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glEnable(GL_DEPTH_TEST);
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glDepthFunc(command.params.depthFunc);
4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glDepthMask(command.params.depthWriteMask ? GL_TRUE : GL_FALSE);
4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glDisable(GL_DEPTH_TEST);
4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glColorMask(command.colorMask[0] ? GL_TRUE : GL_FALSE,
4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				command.colorMask[1] ? GL_TRUE : GL_FALSE,
4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				command.colorMask[2] ? GL_TRUE : GL_FALSE,
4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				command.colorMask[3] ? GL_TRUE : GL_FALSE);
4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glViewport(command.rect.left+viewportX, command.rect.bottom+viewportY, command.rect.width, command.rect.height);
4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gls::FragmentOpUtil::Quad quad;
4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool isFrontFacing = command.params.visibleFace == rr::FACETYPE_FRONT;
4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	quad.posA = Vec2(isFrontFacing ? -1.0f :  1.0f, -1.0f);
4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	quad.posB = Vec2(isFrontFacing ?  1.0f : -1.0f,  1.0f);
4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::fill(DE_ARRAY_BEGIN(quad.color), DE_ARRAY_END(quad.color), command.color);
4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::fill(DE_ARRAY_BEGIN(quad.depth), DE_ARRAY_END(quad.depth), command.params.depth);
4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	renderer.render(quad);
4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_CHECK();
4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid renderReference (const vector<ClearCommand>& clears, const tcu::PixelBufferAccess& dstColor, const tcu::PixelBufferAccess& dstStencil, int stencilBits)
4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < (int)clears.size(); ndx++)
4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const ClearCommand& clear = clears[ndx];
4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (clear.buffers & GL_COLOR_BUFFER_BIT)
4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::clear(tcu::getSubregion(dstColor, clear.rect.left, clear.rect.bottom, clear.rect.width, clear.rect.height), clear.color);
4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (clear.buffers & GL_STENCIL_BUFFER_BIT && stencilBits > 0)
4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int maskedVal = clear.stencil & ((1<<stencilBits)-1);
4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::clearStencil(tcu::getSubregion(dstStencil, clear.rect.left, clear.rect.bottom, clear.rect.width, clear.rect.height), maskedVal);
4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(clear.buffers == (clear.buffers & (GL_COLOR_BUFFER_BIT|GL_STENCIL_BUFFER_BIT))); // \note Don't use clear for depths.
4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // DepthStencilCaseUtil
5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace DepthStencilCaseUtil;
5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass DepthStencilCase : public TestCase
5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							DepthStencilCase		(Context& context, const char* name, const char* desc, const std::vector<DepthStencilParams>& cases);
5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							~DepthStencilCase		(void);
5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					init					(void);
5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					deinit					(void);
5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult			iterate					(void);
5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							DepthStencilCase		(const DepthStencilCase& other);
5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DepthStencilCase&		operator=				(const DepthStencilCase& other);
5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<DepthStencilParams>					m_cases;
5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestRenderTarget								m_renderTarget;
5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<ClearCommand>						m_baseClears;
5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<RenderCommand>						m_baseDepthRenders;
5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<RenderCommand>						m_visualizeCommands;
5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<RefRenderCommand>					m_refBaseDepthRenders;
5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<RefRenderCommand>					m_refVisualizeCommands;
5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gls::FragmentOpUtil::QuadRenderer*				m_renderer;
5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface*									m_refColorBuffer;
5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureLevel*								m_refDepthBuffer;
5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureLevel*								m_refStencilBuffer;
5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gls::FragmentOpUtil::ReferenceQuadRenderer*		m_refRenderer;
5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int												m_iterNdx;
5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5373c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDepthStencilCase::DepthStencilCase (Context& context, const char* name, const char* desc, const std::vector<DepthStencilParams>& cases)
5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase				(context, name, desc)
5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_cases				(cases)
5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_renderer			(DE_NULL)
5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_refColorBuffer		(DE_NULL)
5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_refDepthBuffer		(DE_NULL)
5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_refStencilBuffer	(DE_NULL)
5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_refRenderer			(DE_NULL)
5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_iterNdx				(0)
5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5493c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDepthStencilCase::~DepthStencilCase (void)
5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_renderer;
5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_refColorBuffer;
5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_refDepthBuffer;
5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_refStencilBuffer;
5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_refRenderer;
5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid DepthStencilCase::init (void)
5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(!m_renderer && !m_refColorBuffer && !m_refDepthBuffer && !m_refStencilBuffer && !m_refRenderer);
5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Compute render target.
5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int viewportW	= de::min<int>(m_context.getRenderTarget().getWidth(), VIEWPORT_WIDTH);
5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int viewportH	= de::min<int>(m_context.getRenderTarget().getHeight(), VIEWPORT_HEIGHT);
5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_renderTarget	= TestRenderTarget(viewportW, viewportH, m_context.getRenderTarget().getDepthBits(), m_context.getRenderTarget().getStencilBits());
5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Compute base clears & visualization commands.
5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	generateBaseClearAndDepthCommands(m_renderTarget, m_baseClears, m_baseDepthRenders);
5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	generateDepthVisualizeCommands(m_renderTarget, m_visualizeCommands);
5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	generateStencilVisualizeCommands(m_renderTarget, m_visualizeCommands);
5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Translate to ref commands.
5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refBaseDepthRenders.resize(m_baseDepthRenders.size());
5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < (int)m_baseDepthRenders.size(); ndx++)
5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		translateCommand(m_baseDepthRenders[ndx], m_refBaseDepthRenders[ndx], m_renderTarget);
5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refVisualizeCommands.resize(m_visualizeCommands.size());
5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < (int)m_visualizeCommands.size(); ndx++)
5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		translateCommand(m_visualizeCommands[ndx], m_refVisualizeCommands[ndx], m_renderTarget);
5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_renderer			= new gls::FragmentOpUtil::QuadRenderer(m_context.getRenderContext(), glu::GLSL_VERSION_100_ES);
5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refColorBuffer	= new tcu::Surface(viewportW, viewportH);
5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refDepthBuffer	= new tcu::TextureLevel(tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::FLOAT),			viewportW, viewportH);
5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refStencilBuffer	= new tcu::TextureLevel(tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT32),	viewportW, viewportH);
5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refRenderer		= new gls::FragmentOpUtil::ReferenceQuadRenderer();
5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_iterNdx			= 0;
5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid DepthStencilCase::deinit (void)
5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_renderer;
5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_refColorBuffer;
5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_refDepthBuffer;
5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_refStencilBuffer;
5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_refRenderer;
5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_renderer			= DE_NULL;
6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refColorBuffer	= DE_NULL;
6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refDepthBuffer	= DE_NULL;
6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refStencilBuffer	= DE_NULL;
6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refRenderer		= DE_NULL;
6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_baseClears.clear();
6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_baseDepthRenders.clear();
6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_visualizeCommands.clear();
6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refBaseDepthRenders.clear();
6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refVisualizeCommands.clear();
6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6123c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDepthStencilCase::IterateResult DepthStencilCase::iterate (void)
6133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	de::Random				rnd				(deStringHash(getName()) ^ deInt32Hash(m_iterNdx));
6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						viewportX		= rnd.getInt(0, m_context.getRenderTarget().getWidth()-m_renderTarget.width);
6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						viewportY		= rnd.getInt(0, m_context.getRenderTarget().getHeight()-m_renderTarget.height);
6173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RenderCommand			testCmd;
6183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface			renderedImg		(m_renderTarget.width, m_renderTarget.height);
6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::RGBA				threshold		= m_context.getRenderTarget().getPixelFormat().getColorThreshold();
6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Fill in test command for this iteration.
6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	testCmd.color		= Vec4(1.0f, 0.0f, 0.0f, 1.0f);
6243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	testCmd.colorMask	= tcu::BVec4(true);
6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	testCmd.rect		= rr::WindowRectangle(0, 0, m_renderTarget.width, m_renderTarget.height);
6263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	testCmd.params		= m_cases[m_iterNdx];
6273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_iterNdx == 0)
6293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << "Channels:\n"
6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"  RED: passing pixels\n"
6323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"  GREEN: stencil values\n"
6333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"  BLUE: depth values"
6343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< TestLog::EndMessage;
6353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_cases.size() > 1)
6383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << "Iteration " << m_iterNdx << "..." << TestLog::EndMessage;
6393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << m_cases[m_iterNdx];
6413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Submit render commands to gl GL.
6433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Base clears.
6453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	render(m_baseClears, viewportX, viewportY);
6463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Base depths.
6483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (vector<RenderCommand>::const_iterator cmd = m_baseDepthRenders.begin(); cmd != m_baseDepthRenders.end(); ++cmd)
6493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		render(*m_renderer, *cmd, viewportX, viewportY);
6503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Test command.
6523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	render(*m_renderer, testCmd, viewportX, viewportY);
6533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Visualization commands.
6553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (vector<RenderCommand>::const_iterator cmd = m_visualizeCommands.begin(); cmd != m_visualizeCommands.end(); ++cmd)
6563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		render(*m_renderer, *cmd, viewportX, viewportY);
6573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Re-enable all write masks.
6593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
6603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glDepthMask(GL_TRUE);
6613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glStencilMask(~0u);
6623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Ask GPU to start rendering.
6643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glFlush();
6653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render reference while GPU is doing work.
6673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		RefRenderCommand refTestCmd;
6693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		translateCommand(testCmd, refTestCmd, m_renderTarget);
6703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Base clears.
6723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		renderReference(m_baseClears, m_refColorBuffer->getAccess(), m_refStencilBuffer->getAccess(), m_renderTarget.depthBits);
6733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Base depths.
6753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (vector<RefRenderCommand>::const_iterator cmd = m_refBaseDepthRenders.begin(); cmd != m_refBaseDepthRenders.end(); ++cmd)
6763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_refRenderer->render(gls::FragmentOpUtil::getMultisampleAccess(m_refColorBuffer->getAccess()),
6773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  gls::FragmentOpUtil::getMultisampleAccess(m_refDepthBuffer->getAccess()),
6783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  gls::FragmentOpUtil::getMultisampleAccess(m_refStencilBuffer->getAccess()),
6793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  cmd->quad, cmd->state);
6803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Test command.
6823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_refRenderer->render(gls::FragmentOpUtil::getMultisampleAccess(m_refColorBuffer->getAccess()),
6833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							  gls::FragmentOpUtil::getMultisampleAccess(m_refDepthBuffer->getAccess()),
6843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							  gls::FragmentOpUtil::getMultisampleAccess(m_refStencilBuffer->getAccess()),
6853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							  refTestCmd.quad, refTestCmd.state);
6863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Visualization commands.
6883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (vector<RefRenderCommand>::const_iterator cmd = m_refVisualizeCommands.begin(); cmd != m_refVisualizeCommands.end(); ++cmd)
6893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_refRenderer->render(gls::FragmentOpUtil::getMultisampleAccess(m_refColorBuffer->getAccess()),
6903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  gls::FragmentOpUtil::getMultisampleAccess(m_refDepthBuffer->getAccess()),
6913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  gls::FragmentOpUtil::getMultisampleAccess(m_refStencilBuffer->getAccess()),
6923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  cmd->quad, cmd->state);
6933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Read rendered image.
6963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::readPixels(m_context.getRenderContext(), viewportX, viewportY, renderedImg.getAccess());
6973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_iterNdx += 1;
6993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Compare to reference.
7013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool	isLastIter	= m_iterNdx >= (int)m_cases.size();
7023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool	compareOk	= tcu::pixelThresholdCompare(m_testCtx.getLog(), "CompareResult", "Image Comparison Result", *m_refColorBuffer, renderedImg, threshold,
7033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 tcu::COMPARE_LOG_RESULT);
7043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << TestLog::Message << (compareOk ? "  Passed." : "  FAILED!") << TestLog::EndMessage;
7063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!compareOk)
7073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image comparison failed");
7083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (compareOk && !isLastIter)
7103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return CONTINUE;
7113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
7123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return STOP;
7133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7153c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDepthStencilTests::DepthStencilTests (Context& context)
7163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(context, "depth_stencil", "Depth and Stencil Op Tests")
7173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7203c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDepthStencilTests::~DepthStencilTests (void)
7213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7243c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void randomDepthStencilState (de::Random& rnd, DepthStencilParams& params)
7253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float stencilTestProbability	= 0.8f;
7273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float depthTestProbability	= 0.7f;
7283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const deUint32 compareFuncs[] =
7303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_NEVER,
7323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_ALWAYS,
7333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_LESS,
7343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_LEQUAL,
7353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_EQUAL,
7363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_GEQUAL,
7373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_GREATER,
7383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_NOTEQUAL
7393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
7403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const deUint32 stencilOps[] =
7423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_KEEP,
7443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_ZERO,
7453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_REPLACE,
7463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_INCR,
7473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_DECR,
7483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_INVERT,
7493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_INCR_WRAP,
7503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_DECR_WRAP
7513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
7523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const float depthValues[] = { -1.0f, -0.8f, -0.6f, -0.4f, -0.2f, 0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0f };
7543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	params.visibleFace			= rnd.getBool() ? rr::FACETYPE_FRONT : rr::FACETYPE_BACK;
7563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	params.stencilTestEnabled	= rnd.getFloat() < stencilTestProbability;
7573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	params.depthTestEnabled		= !params.stencilTestEnabled || (rnd.getFloat() < depthTestProbability);
7583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (params.stencilTestEnabled)
7603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int ndx = 0; ndx < 2; ndx++)
7623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
7633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[ndx].function		= rnd.choose<deUint32>(DE_ARRAY_BEGIN(compareFuncs), DE_ARRAY_END(compareFuncs));
7643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[ndx].reference		= rnd.getInt(-2, 260);
7653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[ndx].compareMask		= rnd.getUint32();
7663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[ndx].stencilFailOp	= rnd.choose<deUint32>(DE_ARRAY_BEGIN(stencilOps), DE_ARRAY_END(stencilOps));
7673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[ndx].depthFailOp		= rnd.choose<deUint32>(DE_ARRAY_BEGIN(stencilOps), DE_ARRAY_END(stencilOps));
7683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[ndx].depthPassOp		= rnd.choose<deUint32>(DE_ARRAY_BEGIN(stencilOps), DE_ARRAY_END(stencilOps));
7693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[ndx].writeMask		= rnd.getUint32();
7703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
7713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
7723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (params.depthTestEnabled)
7743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params.depthFunc		= rnd.choose<deUint32>(DE_ARRAY_BEGIN(compareFuncs), DE_ARRAY_END(compareFuncs));
7763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params.depth			= rnd.choose<float>(DE_ARRAY_BEGIN(depthValues), DE_ARRAY_END(depthValues));
7773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params.depthWriteMask	= rnd.getBool();
7783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
7793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7813c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid DepthStencilTests::init (void)
7823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
7843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*	name;
7863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32	func;
7873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} compareFuncs[] =
7883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "never",		GL_NEVER	},
7903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "always",		GL_ALWAYS	},
7913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "less",		GL_LESS		},
7923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "lequal",		GL_LEQUAL	},
7933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "equal",		GL_EQUAL	},
7943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "gequal",		GL_GEQUAL	},
7953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "greater",	GL_GREATER	},
7963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "notequal",	GL_NOTEQUAL	}
7973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
7983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
8003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
8013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*	name;
8023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32	op;
8033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} stencilOps[] =
8043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
8053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "keep",		GL_KEEP			},
8063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "zero",		GL_ZERO			},
8073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "replace",	GL_REPLACE		},
8083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "incr",		GL_INCR			},
8093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "decr",		GL_DECR			},
8103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "invert",		GL_INVERT		},
8113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "incr_wrap",	GL_INCR_WRAP	},
8123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "decr_wrap",	GL_DECR_WRAP	}
8133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
8143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
8163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
8173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		rr::FaceType	visibleFace;
8183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		sFail;
8193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		dFail;
8203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		dPass;
8213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int				stencilRef;
8223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		compareMask;
8233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		writeMask;
8243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float			depth;
8253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} functionCases[] =
8263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
8273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ rr::FACETYPE_BACK,	GL_DECR,		GL_INCR,	GL_INVERT,		4,	~0u, ~0u,	-0.7f },
8283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ rr::FACETYPE_FRONT,	GL_DECR,		GL_INCR,	GL_INVERT,		2,	~0u, ~0u,	0.0f },
8293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ rr::FACETYPE_BACK,	GL_DECR,		GL_INCR,	GL_INVERT,		1,	~0u, ~0u,	0.2f },
8303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ rr::FACETYPE_FRONT,	GL_DECR_WRAP,	GL_INVERT,	GL_REPLACE,		4,	~0u, ~0u,	1.0f }
8313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
8323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// All combinations of depth stencil functions.
8343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
8353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestCaseGroup* functionsGroup = new tcu::TestCaseGroup(m_testCtx, "stencil_depth_funcs", "Combinations of Depth and Stencil Functions");
8363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(functionsGroup);
8373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int stencilFunc = 0; stencilFunc < DE_LENGTH_OF_ARRAY(compareFuncs)+1; stencilFunc++)
8393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
8403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// One extra: depth test disabled.
8413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int depthFunc = 0; depthFunc < DE_LENGTH_OF_ARRAY(compareFuncs)+1; depthFunc++)
8423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
8433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				DepthStencilParams	params;
8443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				ostringstream		name;
8453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				bool				hasStencilFunc	= de::inBounds(stencilFunc, 0, DE_LENGTH_OF_ARRAY(compareFuncs));
8463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				bool				hasDepthFunc	= de::inBounds(depthFunc, 0, DE_LENGTH_OF_ARRAY(compareFuncs));
8473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (hasStencilFunc)
8493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					name << "stencil_" << compareFuncs[stencilFunc].name << "_";
8503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				else
8513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					name << "no_stencil_";
8523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (hasDepthFunc)
8543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					name << "depth_" << compareFuncs[depthFunc].name;
8553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				else
8563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					name << "no_depth";
8573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				params.depthFunc			= hasDepthFunc ? compareFuncs[depthFunc].func : 0;
8593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				params.depthTestEnabled		= hasDepthFunc;
8603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				params.depthWriteMask		= true;
8613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				params.stencilTestEnabled	= hasStencilFunc;
8633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				vector<DepthStencilParams> cases;
8653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(functionCases); ndx++)
8663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
8673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					rr::FaceType	visible		= functionCases[ndx].visibleFace;
8683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					rr::FaceType	notVisible	= visible == rr::FACETYPE_FRONT ? rr::FACETYPE_BACK : rr::FACETYPE_FRONT;
8693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.depth								= functionCases[ndx].depth;
8713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.visibleFace							= visible;
8723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.stencil[visible].function			= hasStencilFunc ? compareFuncs[stencilFunc].func : 0;
8743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.stencil[visible].reference			= functionCases[ndx].stencilRef;
8753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.stencil[visible].stencilFailOp		= functionCases[ndx].sFail;
8763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.stencil[visible].depthFailOp			= functionCases[ndx].dFail;
8773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.stencil[visible].depthPassOp			= functionCases[ndx].dPass;
8783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.stencil[visible].compareMask			= functionCases[ndx].compareMask;
8793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.stencil[visible].writeMask			= functionCases[ndx].writeMask;
8803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.stencil[notVisible].function			= GL_ALWAYS;
8823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.stencil[notVisible].reference		= 0;
8833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.stencil[notVisible].stencilFailOp	= GL_REPLACE;
8843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.stencil[notVisible].depthFailOp		= GL_REPLACE;
8853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.stencil[notVisible].depthPassOp		= GL_REPLACE;
8863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.stencil[notVisible].compareMask		= 0u;
8873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.stencil[notVisible].writeMask		= ~0u;
8883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					cases.push_back(params);
8913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
8923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				functionsGroup->addChild(new DepthStencilCase(m_context, name.str().c_str(), "", cases));
8943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
8953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
8963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
8973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
8993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
9003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		rr::FaceType	visibleFace;
9013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		func;
9023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int				ref;
9033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		compareMask;
9043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		writeMask;
9053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} opCombinationCases[] =
9063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
9073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ rr::FACETYPE_BACK,	GL_LESS,		4,		~0u,	~0u	},
9083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ rr::FACETYPE_FRONT,	GL_GREATER,		2,		~0u,	~0u	},
9093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ rr::FACETYPE_BACK,	GL_EQUAL,		3,		~2u,	~0u	},
9103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ rr::FACETYPE_FRONT,	GL_NOTEQUAL,	1,		~0u,	~1u	}
9113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
9123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// All combinations of stencil ops.
9143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
9153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestCaseGroup* opCombinationGroup = new tcu::TestCaseGroup(m_testCtx, "stencil_ops", "Stencil Op Combinations");
9163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(opCombinationGroup);
9173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int sFail = 0; sFail < DE_LENGTH_OF_ARRAY(stencilOps); sFail++)
9193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
9203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int dFail = 0; dFail < DE_LENGTH_OF_ARRAY(stencilOps); dFail++)
9213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
9223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				for (int dPass = 0; dPass < DE_LENGTH_OF_ARRAY(stencilOps); dPass++)
9233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
9243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					DepthStencilParams	params;
9253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					ostringstream		name;
9263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					name << stencilOps[sFail].name << "_" << stencilOps[dFail].name << "_" << stencilOps[dPass].name;
9283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.depthFunc			= GL_LEQUAL;
9303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.depth				= 0.0f;
9313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.depthTestEnabled		= true;
9323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.depthWriteMask		= true;
9333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					params.stencilTestEnabled	= true;
9353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					vector<DepthStencilParams> cases;
9373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(opCombinationCases); ndx++)
9383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
9393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						rr::FaceType	visible		= opCombinationCases[ndx].visibleFace;
9403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						rr::FaceType	notVisible	= visible == rr::FACETYPE_FRONT ? rr::FACETYPE_BACK : rr::FACETYPE_FRONT;
9413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						params.visibleFace							= visible;
9433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						params.stencil[visible].function			= opCombinationCases[ndx].func;
9453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						params.stencil[visible].reference			= opCombinationCases[ndx].ref;
9463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						params.stencil[visible].stencilFailOp		= stencilOps[sFail].op;
9473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						params.stencil[visible].depthFailOp			= stencilOps[dFail].op;
9483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						params.stencil[visible].depthPassOp			= stencilOps[dPass].op;
9493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						params.stencil[visible].compareMask			= opCombinationCases[ndx].compareMask;
9503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						params.stencil[visible].writeMask			= opCombinationCases[ndx].writeMask;
9513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						params.stencil[notVisible].function			= GL_ALWAYS;
9533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						params.stencil[notVisible].reference		= 0;
9543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						params.stencil[notVisible].stencilFailOp	= GL_REPLACE;
9553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						params.stencil[notVisible].depthFailOp		= GL_REPLACE;
9563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						params.stencil[notVisible].depthPassOp		= GL_REPLACE;
9573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						params.stencil[notVisible].compareMask		= 0u;
9583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						params.stencil[notVisible].writeMask		= ~0u;
9593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						cases.push_back(params);
9623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					}
9633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					opCombinationGroup->addChild(new DepthStencilCase(m_context, name.str().c_str(), "", cases));
9653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
9663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
9673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
9683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
9693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Write masks
9713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
9723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestCaseGroup* writeMaskGroup = new tcu::TestCaseGroup(m_testCtx, "write_mask", "Depth and Stencil Write Masks");
9733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(writeMaskGroup);
9743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Depth mask
9763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
9773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DepthStencilParams params;
9783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.depthFunc			= GL_LEQUAL;
9803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.depth				= 0.0f;
9813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.depthTestEnabled		= true;
9823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencilTestEnabled	= true;
9833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].function			= GL_NOTEQUAL;
9853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].reference		= 1;
9863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].stencilFailOp	= GL_INVERT;
9873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].depthFailOp		= GL_INCR;
9883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].depthPassOp		= GL_DECR;
9893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].compareMask		= ~0u;
9903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].writeMask		= ~0u;
9913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].function			= GL_ALWAYS;
9933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].reference			= 0;
9943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].stencilFailOp		= GL_REPLACE;
9953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].depthFailOp		= GL_INVERT;
9963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].depthPassOp		= GL_INCR;
9973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].compareMask		= ~0u;
9983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].writeMask			= ~0u;
9993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			vector<DepthStencilParams> cases;
10013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Case 1: front, depth write enabled
10033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.visibleFace		= rr::FACETYPE_FRONT;
10043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.depthWriteMask	= true;
10053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			cases.push_back(params);
10063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Case 2: front, depth write disabled
10083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.visibleFace		= rr::FACETYPE_FRONT;
10093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.depthWriteMask	= false;
10103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			cases.push_back(params);
10113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Case 3: back, depth write enabled
10133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.visibleFace		= rr::FACETYPE_BACK;
10143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.depthWriteMask	= true;
10153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			cases.push_back(params);
10163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Case 4: back, depth write disabled
10183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.visibleFace		= rr::FACETYPE_BACK;
10193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.depthWriteMask	= false;
10203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			cases.push_back(params);
10213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			writeMaskGroup->addChild(new DepthStencilCase(m_context, "depth", "Depth Write Mask", cases));
10233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
10243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Stencil write masks.
10263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
10273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			static const struct
10283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
10293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				rr::FaceType	visibleFace;
10303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32		frontWriteMask;
10313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32		backWriteMask;
10323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			} stencilWmaskCases[] =
10333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
10343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ rr::FACETYPE_FRONT,	~0u,	0u		},
10353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ rr::FACETYPE_FRONT,	0u,		~0u		},
10363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ rr::FACETYPE_FRONT,	0xfu,	0xf0u	},
10373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ rr::FACETYPE_FRONT,	0x2u,	0x4u	},
10383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ rr::FACETYPE_BACK,	0u,		~0u		},
10393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ rr::FACETYPE_BACK,	~0u,	0u		},
10403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ rr::FACETYPE_BACK,	0xf0u,	0xfu	},
10413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ rr::FACETYPE_BACK,	0x4u,	0x2u	}
10423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			};
10433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DepthStencilParams params;
10453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.depthFunc			= GL_LEQUAL;
10473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.depth				= 0.0f;
10483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.depthTestEnabled		= true;
10493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.depthWriteMask		= true;
10503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencilTestEnabled	= true;
10513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].function			= GL_NOTEQUAL;
10533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].reference		= 1;
10543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].stencilFailOp	= GL_INVERT;
10553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].depthFailOp		= GL_INCR;
10563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].depthPassOp		= GL_DECR;
10573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].compareMask		= ~0u;
10583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].function			= GL_ALWAYS;
10603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].reference			= 0;
10613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].stencilFailOp		= GL_REPLACE;
10623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].depthFailOp		= GL_INVERT;
10633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].depthPassOp		= GL_INCR;
10643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].compareMask		= ~0u;
10653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			vector<DepthStencilParams> cases;
10673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(stencilWmaskCases); ndx++)
10683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
10693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				params.visibleFace								= stencilWmaskCases[ndx].visibleFace;
10703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				params.stencil[rr::FACETYPE_FRONT].writeMask	= stencilWmaskCases[ndx].frontWriteMask;
10713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				params.stencil[rr::FACETYPE_BACK].writeMask		= stencilWmaskCases[ndx].backWriteMask;
10723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				cases.push_back(params);
10733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
10743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			writeMaskGroup->addChild(new DepthStencilCase(m_context, "stencil", "Stencil Write Mask", cases));
10763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
10773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Depth & stencil write masks.
10793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
10803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			static const struct
10813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
10823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				bool			depthWriteMask;
10833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				rr::FaceType	visibleFace;
10843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32		frontWriteMask;
10853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32		backWriteMask;
10863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			} depthStencilWmaskCases[] =
10873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
10883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ false,	rr::FACETYPE_FRONT,		~0u,	0u		},
10893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ false,	rr::FACETYPE_FRONT,		0u,		~0u		},
10903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ false,	rr::FACETYPE_FRONT,		0xfu,	0xf0u	},
10913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ true,		rr::FACETYPE_FRONT,		~0u,	0u		},
10923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ true,		rr::FACETYPE_FRONT,		0u,		~0u		},
10933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ true,		rr::FACETYPE_FRONT,		0xfu,	0xf0u	},
10943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ false,	rr::FACETYPE_BACK,		0u,		~0u		},
10953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ false,	rr::FACETYPE_BACK,		~0u,	0u		},
10963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ false,	rr::FACETYPE_BACK,		0xf0u,	0xfu	},
10973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ true,		rr::FACETYPE_BACK,		0u,		~0u		},
10983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ true,		rr::FACETYPE_BACK,		~0u,	0u		},
10993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ true,		rr::FACETYPE_BACK,		0xf0u,	0xfu	}
11003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			};
11013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DepthStencilParams params;
11033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.depthFunc			= GL_LEQUAL;
11053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.depth				= 0.0f;
11063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.depthTestEnabled		= true;
11073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.depthWriteMask		= true;
11083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencilTestEnabled	= true;
11093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].function			= GL_NOTEQUAL;
11113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].reference		= 1;
11123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].stencilFailOp	= GL_INVERT;
11133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].depthFailOp		= GL_INCR;
11143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].depthPassOp		= GL_DECR;
11153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_FRONT].compareMask		= ~0u;
11163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].function			= GL_ALWAYS;
11183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].reference			= 0;
11193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].stencilFailOp		= GL_REPLACE;
11203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].depthFailOp		= GL_INVERT;
11213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].depthPassOp		= GL_INCR;
11223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			params.stencil[rr::FACETYPE_BACK].compareMask		= ~0u;
11233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			vector<DepthStencilParams> cases;
11253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(depthStencilWmaskCases); ndx++)
11263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
11273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				params.depthWriteMask							= depthStencilWmaskCases[ndx].depthWriteMask;
11283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				params.visibleFace								= depthStencilWmaskCases[ndx].visibleFace;
11293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				params.stencil[rr::FACETYPE_FRONT].writeMask	= depthStencilWmaskCases[ndx].frontWriteMask;
11303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				params.stencil[rr::FACETYPE_BACK].writeMask		= depthStencilWmaskCases[ndx].backWriteMask;
11313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				cases.push_back(params);
11323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
11333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			writeMaskGroup->addChild(new DepthStencilCase(m_context, "both", "Depth and Stencil Write Masks", cases));
11353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
11363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
11373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Randomized cases
11393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
11403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestCaseGroup* randomGroup = new tcu::TestCaseGroup(m_testCtx, "random", "Randomized Depth and Stencil Test Cases");
11413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(randomGroup);
11423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int caseNdx = 0; caseNdx < NUM_RANDOM_CASES; caseNdx++)
11443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
11453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			vector<DepthStencilParams>	subCases	(NUM_RANDOM_SUB_CASES);
11463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			de::Random					rnd			(deInt32Hash(caseNdx) ^ deInt32Hash(m_testCtx.getCommandLine().getBaseSeed()));
11473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (vector<DepthStencilParams>::iterator iter = subCases.begin(); iter != subCases.end(); ++iter)
11493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				randomDepthStencilState(rnd, *iter);
11503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			randomGroup->addChild(new DepthStencilCase(m_context, de::toString(caseNdx).c_str(), "", subCases));
11523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
11533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
11543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional
11573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles2
11583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
1159