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 Blend tests.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es2fBlendTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsFragmentOpUtil.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluStrUtil.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuImageCompare.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
32400df3e7e4040479e970611c2c11e39049e14cbaPyry Haulos#include "tcuTextureUtil.hpp"
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.hpp"
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rrFragmentOperations.hpp"
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "sglrReferenceUtils.hpp"
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glw.h"
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string>
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector>
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing gls::FragmentOpUtil::Quad;
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing gls::FragmentOpUtil::IntegerQuad;
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing gls::FragmentOpUtil::QuadRenderer;
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing gls::FragmentOpUtil::ReferenceQuadRenderer;
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing glu::getBlendEquationName;
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing glu::getBlendFactorName;
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec4;
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::UVec4;
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog;
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Surface;
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TextureFormat;
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TextureLevel;
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string;
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector;
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles2
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const int MAX_VIEWPORT_WIDTH		= 64;
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const int MAX_VIEWPORT_HEIGHT	= 64;
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct BlendParams
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum	equationRGB;
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum	srcFuncRGB;
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum	dstFuncRGB;
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum	equationAlpha;
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum	srcFuncAlpha;
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum	dstFuncAlpha;
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vec4	blendColor;
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BlendParams (GLenum		equationRGB_,
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				 GLenum		srcFuncRGB_,
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				 GLenum		dstFuncRGB_,
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				 GLenum		equationAlpha_,
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				 GLenum		srcFuncAlpha_,
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				 GLenum		dstFuncAlpha_,
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				 Vec4		blendColor_)
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: equationRGB	(equationRGB_)
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, srcFuncRGB	(srcFuncRGB_)
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, dstFuncRGB	(dstFuncRGB_)
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, equationAlpha	(equationAlpha_)
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, srcFuncAlpha	(srcFuncAlpha_)
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, dstFuncAlpha	(dstFuncAlpha_)
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, blendColor	(blendColor_)
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BlendCase : public TestCase
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							BlendCase	(Context&						context,
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										 const char*					name,
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										 const char*					desc,
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										 const vector<BlendParams>&		paramSets);
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							~BlendCase	(void);
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					init		(void);
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					deinit		(void);
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult			iterate		(void);
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							BlendCase	(const BlendCase& other);
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BlendCase&				operator=	(const BlendCase& other);
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<BlendParams>		m_paramSets;
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						m_curParamSetNdx;
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	QuadRenderer*			m_renderer;
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ReferenceQuadRenderer*	m_referenceRenderer;
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureLevel*			m_refColorBuffer;
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Quad					m_firstQuad;
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Quad					m_secondQuad;
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IntegerQuad				m_firstQuadInt;
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IntegerQuad				m_secondQuadInt;
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						m_viewportW;
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						m_viewportH;
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1303c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBlendCase::BlendCase (Context&						context,
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					  const char*					name,
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					  const char*					desc,
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					  const vector<BlendParams>&	paramSets)
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase				(context, name, desc)
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_paramSets			(paramSets)
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_curParamSetNdx		(0)
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_renderer			(DE_NULL)
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_referenceRenderer	(DE_NULL)
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_refColorBuffer		(DE_NULL)
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_viewportW			(0)
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_viewportH			(0)
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(!m_paramSets.empty());
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < (int)m_paramSets.size(); i++)
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(m_paramSets[i].dstFuncRGB != GL_SRC_ALPHA_SATURATE && m_paramSets[i].dstFuncAlpha != GL_SRC_ALPHA_SATURATE);
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BlendCase::init (void)
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool useRGB = m_context.getRenderTarget().getPixelFormat().alphaBits == 0;
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const Vec4 baseGradientColors[4] =
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Vec4(0.0f, 0.5f, 1.0f, 0.5f),
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Vec4(0.5f, 0.0f, 0.5f, 1.0f),
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Vec4(0.5f, 1.0f, 0.5f, 0.0f),
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Vec4(1.0f, 0.5f, 0.0f, 0.5f)
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(m_firstQuad.color) == DE_LENGTH_OF_ARRAY(m_firstQuadInt.color));
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < DE_LENGTH_OF_ARRAY(m_firstQuad.color); i++)
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_firstQuad.color[i]		= (baseGradientColors[i] - 0.5f) * 0.2f + 0.5f;
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_firstQuadInt.color[i]		= m_firstQuad.color[i];
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_secondQuad.color[i]		= (Vec4(1.0f) - baseGradientColors[i] - 0.5f) * 1.0f + 0.5f;
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_secondQuadInt.color[i]	= m_secondQuad.color[i];
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_viewportW = de::min<int>(m_context.getRenderTarget().getWidth(),	MAX_VIEWPORT_WIDTH);
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_viewportH = de::min<int>(m_context.getRenderTarget().getHeight(),	MAX_VIEWPORT_HEIGHT);
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_firstQuadInt.posA		= tcu::IVec2(0,					0);
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_secondQuadInt.posA	= tcu::IVec2(0,					0);
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_firstQuadInt.posB		= tcu::IVec2(m_viewportW-1,		m_viewportH-1);
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_secondQuadInt.posB	= tcu::IVec2(m_viewportW-1,		m_viewportH-1);
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(!m_renderer);
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(!m_referenceRenderer);
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(!m_refColorBuffer);
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_renderer				= new QuadRenderer(m_context.getRenderContext(), glu::GLSL_VERSION_100_ES);
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_referenceRenderer		= new ReferenceQuadRenderer;
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refColorBuffer		= new TextureLevel(TextureFormat(useRGB ? TextureFormat::RGB : TextureFormat::RGBA, TextureFormat::UNORM_INT8),
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											   m_viewportW, m_viewportH);
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_curParamSetNdx = 0;
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1903c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBlendCase::~BlendCase (void)
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_renderer;
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_referenceRenderer;
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_refColorBuffer;
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BlendCase::deinit (void)
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_renderer;
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_referenceRenderer;
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_refColorBuffer;
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_renderer			= DE_NULL;
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_referenceRenderer	= DE_NULL;
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refColorBuffer	= DE_NULL;
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2083c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBlendCase::IterateResult BlendCase::iterate (void)
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	de::Random						rnd				(deStringHash(getName()) ^ deInt32Hash(m_curParamSetNdx));
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int								viewportX		= rnd.getInt(0, m_context.getRenderTarget().getWidth() - m_viewportW);
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int								viewportY		= rnd.getInt(0, m_context.getRenderTarget().getHeight() - m_viewportH);
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface					renderedImg		(m_viewportW, m_viewportH);
214400df3e7e4040479e970611c2c11e39049e14cbaPyry Haulos	tcu::Surface					referenceImg	(m_viewportH, m_viewportH);
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestLog&						log				(m_testCtx.getLog());
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const BlendParams&				paramSet		= m_paramSets[m_curParamSetNdx];
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rr::FragmentOperationState		referenceState;
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Log the blend parameters.
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << "RGB equation = " << getBlendEquationName(paramSet.equationRGB) << TestLog::EndMessage;
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << "RGB src func = " << getBlendFactorName(paramSet.srcFuncRGB) << TestLog::EndMessage;
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << "RGB dst func = " << getBlendFactorName(paramSet.dstFuncRGB) << TestLog::EndMessage;
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << "Alpha equation = " << getBlendEquationName(paramSet.equationAlpha) << TestLog::EndMessage;
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << "Alpha src func = " << getBlendFactorName(paramSet.srcFuncAlpha) << TestLog::EndMessage;
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << "Alpha dst func = " << getBlendFactorName(paramSet.dstFuncAlpha) << TestLog::EndMessage;
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << "Blend color = (" << paramSet.blendColor.x() << ", " << paramSet.blendColor.y() << ", " << paramSet.blendColor.z() << ", " << paramSet.blendColor.w() << ")" << TestLog::EndMessage;
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Set GL state.
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_CHECK_CALL(glBlendEquationSeparate(paramSet.equationRGB, paramSet.equationAlpha));
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_CHECK_CALL(glBlendFuncSeparate(paramSet.srcFuncRGB, paramSet.dstFuncRGB, paramSet.srcFuncAlpha, paramSet.dstFuncAlpha));
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_CHECK_CALL(glBlendColor(paramSet.blendColor.x(), paramSet.blendColor.y(), paramSet.blendColor.z(), paramSet.blendColor.w()));
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Set reference state.
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	referenceState.blendRGBState.equation	= sglr::rr_util::mapGLBlendEquation(paramSet.equationRGB);
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	referenceState.blendRGBState.srcFunc	= sglr::rr_util::mapGLBlendFunc(paramSet.srcFuncRGB);
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	referenceState.blendRGBState.dstFunc	= sglr::rr_util::mapGLBlendFunc(paramSet.dstFuncRGB);
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	referenceState.blendAState.equation		= sglr::rr_util::mapGLBlendEquation(paramSet.equationAlpha);
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	referenceState.blendAState.srcFunc		= sglr::rr_util::mapGLBlendFunc(paramSet.srcFuncAlpha);
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	referenceState.blendAState.dstFunc		= sglr::rr_util::mapGLBlendFunc(paramSet.dstFuncAlpha);
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	referenceState.blendColor				= paramSet.blendColor;
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render with GL.
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glDisable(GL_BLEND);
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glViewport(viewportX, viewportY, m_viewportW, m_viewportH);
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_renderer->render(m_firstQuad);
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glEnable(GL_BLEND);
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_renderer->render(m_secondQuad);
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glFlush();
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render reference.
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
256b5d323b0daefbf7f7f4cb5e9cc631e2ab837b6edPyry Haulos	const tcu::PixelBufferAccess nullAccess = tcu::PixelBufferAccess();
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	referenceState.blendMode = rr::BLENDMODE_NONE;
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_referenceRenderer->render(gls::FragmentOpUtil::getMultisampleAccess(m_refColorBuffer->getAccess()), nullAccess /* no depth */, nullAccess /* no stencil */, m_firstQuadInt, referenceState);
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	referenceState.blendMode = rr::BLENDMODE_STANDARD;
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_referenceRenderer->render(gls::FragmentOpUtil::getMultisampleAccess(m_refColorBuffer->getAccess()), nullAccess /* no depth */, nullAccess /* no stencil */, m_secondQuadInt, referenceState);
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
263400df3e7e4040479e970611c2c11e39049e14cbaPyry Haulos	// Expand reference color buffer to RGBA8
264400df3e7e4040479e970611c2c11e39049e14cbaPyry Haulos	copy(referenceImg.getAccess(), m_refColorBuffer->getAccess());
265400df3e7e4040479e970611c2c11e39049e14cbaPyry Haulos
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Read GL image.
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::readPixels(m_context.getRenderContext(), viewportX, viewportY, renderedImg.getAccess());
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Compare images.
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UVec4 compareThreshold = m_context.getRenderTarget().getPixelFormat().getColorThreshold().toIVec().asUint()
27383d2cade65513f21ff9e1871d4b71ae1040d6cceMika Isojärvi							 * UVec4(5) / UVec4(2) + UVec4(3); // \note Non-scientific ad hoc formula. Need big threshold when few color bits; blending brings extra inaccuracy.
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
275400df3e7e4040479e970611c2c11e39049e14cbaPyry Haulos	bool comparePass = tcu::intThresholdCompare(m_testCtx.getLog(), "CompareResult", "Image Comparison Result", referenceImg.getAccess(), renderedImg.getAccess(), compareThreshold, tcu::COMPARE_LOG_RESULT);
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Fail now if images don't match.
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!comparePass)
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Image compare failed");
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return STOP;
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Continue if param sets still remain in m_paramSets; otherwise stop.
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_curParamSetNdx++;
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_curParamSetNdx < (int)m_paramSets.size())
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return CONTINUE;
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Passed");
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return STOP;
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2983c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBlendTests::BlendTests (Context& context)
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(context, "blend", "Blend tests")
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3033c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBlendTests::~BlendTests (void)
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BlendTests::init (void)
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	struct EnumGL
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLenum			glValue;
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		nameStr;
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const EnumGL blendEquations[] =
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_FUNC_ADD,					"add"					},
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_FUNC_SUBTRACT,				"subtract"				},
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_FUNC_REVERSE_SUBTRACT,		"reverse_subtract"		}
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const EnumGL blendFunctions[] =
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_ZERO,							"zero"						},
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_ONE,							"one"						},
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_SRC_COLOR,						"src_color"					},
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_ONE_MINUS_SRC_COLOR,			"one_minus_src_color"		},
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_DST_COLOR,						"dst_color"					},
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_ONE_MINUS_DST_COLOR,			"one_minus_dst_color"		},
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_SRC_ALPHA,						"src_alpha"					},
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_ONE_MINUS_SRC_ALPHA,			"one_minus_src_alpha"		},
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_DST_ALPHA,						"dst_alpha"					},
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_ONE_MINUS_DST_ALPHA,			"one_minus_dst_alpha"		},
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_CONSTANT_COLOR,				"constant_color"			},
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_ONE_MINUS_CONSTANT_COLOR,		"one_minus_constant_color"	},
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_CONSTANT_ALPHA,				"constant_alpha"			},
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_ONE_MINUS_CONSTANT_ALPHA,		"one_minus_constant_alpha"	},
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_SRC_ALPHA_SATURATE,			"src_alpha_saturate"		}
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const Vec4 defaultBlendColor(0.2f, 0.4f, 0.6f, 0.8f);
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Test all blend equation, src blend function, dst blend function combinations. RGB and alpha modes are the same.
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TestCaseGroup* group = new TestCaseGroup(m_context, "equation_src_func_dst_func", "Combinations of Blend Equations and Functions");
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(group);
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int equationNdx = 0;	equationNdx < DE_LENGTH_OF_ARRAY(blendEquations);	equationNdx++)
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int srcFuncNdx = 0;	srcFuncNdx < DE_LENGTH_OF_ARRAY(blendFunctions);	srcFuncNdx++)
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int dstFuncNdx = 0;	dstFuncNdx < DE_LENGTH_OF_ARRAY(blendFunctions);	dstFuncNdx++)
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const EnumGL& eq	= blendEquations[equationNdx];
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const EnumGL& src	= blendFunctions[srcFuncNdx];
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const EnumGL& dst	= blendFunctions[dstFuncNdx];
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (dst.glValue == GL_SRC_ALPHA_SATURATE) // SRC_ALPHA_SATURATE is only valid for src func.
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				continue;
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			string name			= string("") + eq.nameStr + "_" + src.nameStr + "_" + dst.nameStr;
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			string description	= string("") +
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  "Equations "		+ getBlendEquationName(eq.glValue) +
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  ", src funcs "	+ getBlendFactorName(src.glValue) +
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  ", dst funcs "	+ getBlendFactorName(dst.glValue);
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			vector<BlendParams> paramSets;
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			paramSets.push_back(BlendParams(eq.glValue, src.glValue, dst.glValue, eq.glValue, src.glValue, dst.glValue, defaultBlendColor));
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			group->addChild(new BlendCase(m_context, name.c_str(), description.c_str(), paramSets));
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Test all RGB src, alpha src and RGB dst, alpha dst combinations. Equations are ADD.
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// \note For all RGB src, alpha src combinations, also test a couple of different RGBA dst functions, and vice versa.
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TestCaseGroup* mainGroup = new TestCaseGroup(m_context, "rgb_func_alpha_func", "Combinations of RGB and Alpha Functions");
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(mainGroup);
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TestCaseGroup* srcGroup = new TestCaseGroup(m_context, "src", "Source functions");
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TestCaseGroup* dstGroup = new TestCaseGroup(m_context, "dst", "Destination functions");
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		mainGroup->addChild(srcGroup);
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		mainGroup->addChild(dstGroup);
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int isDstI = 0;		isDstI <= 1;										isDstI++)
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int rgbFuncNdx = 0;	rgbFuncNdx < DE_LENGTH_OF_ARRAY(blendFunctions);	rgbFuncNdx++)
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int alphaFuncNdx = 0;	alphaFuncNdx < DE_LENGTH_OF_ARRAY(blendFunctions);	alphaFuncNdx++)
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			bool			isSrc			= isDstI == 0;
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			TestCaseGroup*	curGroup		= isSrc ? srcGroup : dstGroup;
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const EnumGL&	funcRGB			= blendFunctions[rgbFuncNdx];
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const EnumGL&	funcAlpha		= blendFunctions[alphaFuncNdx];
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const char*		dstOrSrcStr		= isSrc ? "src" : "dst";
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!isSrc && (funcRGB.glValue == GL_SRC_ALPHA_SATURATE || funcAlpha.glValue == GL_SRC_ALPHA_SATURATE)) // SRC_ALPHA_SATURATE is only valid for src func.
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				continue;
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			string name			= string("") + funcRGB.nameStr + "_" + funcAlpha.nameStr;
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			string description	= string("") +
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  "RGB "		+ dstOrSrcStr + " func " + getBlendFactorName(funcRGB.glValue) +
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  ", alpha "	+ dstOrSrcStr + " func " + getBlendFactorName(funcAlpha.glValue);
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// First, make param sets as if this was a src case.
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			vector<BlendParams> paramSets;
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			paramSets.push_back(BlendParams(GL_FUNC_ADD, funcRGB.glValue, GL_ONE,			GL_FUNC_ADD, funcAlpha.glValue, GL_ONE,			defaultBlendColor));
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			paramSets.push_back(BlendParams(GL_FUNC_ADD, funcRGB.glValue, GL_ZERO,			GL_FUNC_ADD, funcAlpha.glValue, GL_ZERO,		defaultBlendColor));
4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			paramSets.push_back(BlendParams(GL_FUNC_ADD, funcRGB.glValue, GL_SRC_COLOR,		GL_FUNC_ADD, funcAlpha.glValue, GL_SRC_COLOR,	defaultBlendColor));
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			paramSets.push_back(BlendParams(GL_FUNC_ADD, funcRGB.glValue, GL_DST_COLOR,		GL_FUNC_ADD, funcAlpha.glValue, GL_DST_COLOR,	defaultBlendColor));
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Swap src and dst params if this is a dst case.
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!isSrc)
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				for (int i = 0; i < (int)paramSets.size(); i++)
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					std::swap(paramSets[i].srcFuncRGB,		paramSets[i].dstFuncRGB);
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					std::swap(paramSets[i].srcFuncAlpha,	paramSets[i].dstFuncAlpha);
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			curGroup->addChild(new BlendCase(m_context, name.c_str(), description.c_str(), paramSets));
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Test all RGB and alpha equation combinations. Src and dst funcs are ONE for both.
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TestCaseGroup* group = new TestCaseGroup(m_context, "rgb_equation_alpha_equation", "Combinations of RGB and Alpha Equation Combinations");
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(group);
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int equationRGBNdx = 0;	equationRGBNdx < DE_LENGTH_OF_ARRAY(blendEquations);	equationRGBNdx++)
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int equationAlphaNdx = 0;	equationAlphaNdx < DE_LENGTH_OF_ARRAY(blendEquations);	equationAlphaNdx++)
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const EnumGL& eqRGB			= blendEquations[equationRGBNdx];
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const EnumGL& eqAlpha		= blendEquations[equationAlphaNdx];
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			string name			= string("") + eqRGB.nameStr + "_" + eqAlpha.nameStr;
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			string description	= string("") +
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  "RGB equation "		+ getBlendEquationName(eqRGB.glValue) +
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  ", alpha equation "	+ getBlendEquationName(eqAlpha.glValue);
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			vector<BlendParams> paramSets;
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			paramSets.push_back(BlendParams(eqRGB.glValue, GL_ONE, GL_ONE, eqAlpha.glValue, GL_ONE, GL_ONE, defaultBlendColor));
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			group->addChild(new BlendCase(m_context, name.c_str(), description.c_str(), paramSets));
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles2
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
453