1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES 2.0 Module
3  * -------------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Blend performance tests.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "es2pBlendTests.hpp"
25 #include "glsShaderPerformanceCase.hpp"
26 #include "tcuTestLog.hpp"
27 #include "gluStrUtil.hpp"
28 #include "glwEnums.hpp"
29 #include "glwFunctions.hpp"
30 
31 namespace deqp
32 {
33 namespace gles2
34 {
35 namespace Performance
36 {
37 
38 using namespace gls;
39 using namespace glw; // GL types
40 using tcu::Vec4;
41 using tcu::TestLog;
42 
43 class BlendCase : public ShaderPerformanceCase
44 {
45 public:
46 						BlendCase			(Context& context, const char* name, const char* description, GLenum modeRGB, GLenum modeAlpha, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
47 						~BlendCase			(void);
48 
49 	void				init				(void);
50 
51 private:
52 	void				setupRenderState	(void);
53 
54 	GLenum				m_modeRGB;
55 	GLenum				m_modeAlpha;
56 	GLenum				m_srcRGB;
57 	GLenum				m_dstRGB;
58 	GLenum				m_srcAlpha;
59 	GLenum				m_dstAlpha;
60 };
61 
BlendCase(Context & context,const char * name,const char * description,GLenum modeRGB,GLenum modeAlpha,GLenum srcRGB,GLenum dstRGB,GLenum srcAlpha,GLenum dstAlpha)62 BlendCase::BlendCase (Context& context, const char* name, const char* description, GLenum modeRGB, GLenum modeAlpha, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
63 	: ShaderPerformanceCase	(context.getTestContext(), context.getRenderContext(), name, description, CASETYPE_FRAGMENT)
64 	, m_modeRGB				(modeRGB)
65 	, m_modeAlpha			(modeAlpha)
66 	, m_srcRGB				(srcRGB)
67 	, m_dstRGB				(dstRGB)
68 	, m_srcAlpha			(srcAlpha)
69 	, m_dstAlpha			(dstAlpha)
70 {
71 }
72 
~BlendCase(void)73 BlendCase::~BlendCase (void)
74 {
75 }
76 
init(void)77 void BlendCase::init (void)
78 {
79 	TestLog& log = m_testCtx.getLog();
80 
81 	log << TestLog::Message << "modeRGB: " << glu::getBlendEquationStr(m_modeRGB) << TestLog::EndMessage;
82 	log << TestLog::Message << "modeAlpha: " << glu::getBlendEquationStr(m_modeAlpha) << TestLog::EndMessage;
83 	log << TestLog::Message << "srcRGB: " << glu::getBlendFactorStr(m_srcRGB) << TestLog::EndMessage;
84 	log << TestLog::Message << "dstRGB: " << glu::getBlendFactorStr(m_dstRGB) << TestLog::EndMessage;
85 	log << TestLog::Message << "srcAlpha: " << glu::getBlendFactorStr(m_srcAlpha) << TestLog::EndMessage;
86 	log << TestLog::Message << "dstAlpha: " << glu::getBlendFactorStr(m_dstAlpha) << TestLog::EndMessage;
87 
88 	m_vertShaderSource =
89 		"attribute highp vec4 a_position;\n"
90 		"attribute mediump vec4 a_color;\n"
91 		"varying mediump vec4 v_color;\n"
92 		"void main (void)\n"
93 		"{\n"
94 		"	gl_Position = a_position;\n"
95 		"	v_color = a_color;\n"
96 		"}\n";
97 	m_fragShaderSource =
98 		"varying mediump vec4 v_color;\n"
99 		"void main (void)\n"
100 		"{\n"
101 		"	gl_FragColor = v_color;\n"
102 		"}\n";
103 
104 	m_attributes.push_back(AttribSpec("a_color", Vec4(0.0f, 0.5f, 0.5f, 1.0f),
105 												 Vec4(0.5f, 1.0f, 0.0f, 0.5f),
106 												 Vec4(0.5f, 0.0f, 1.0f, 0.5f),
107 												 Vec4(1.0f, 0.5f, 0.5f, 0.0f)));
108 
109 	ShaderPerformanceCase::init();
110 }
111 
setupRenderState(void)112 void BlendCase::setupRenderState (void)
113 {
114 	const glw::Functions& gl = m_renderCtx.getFunctions();
115 
116 	gl.enable(GL_BLEND);
117 	gl.blendEquationSeparate(m_modeRGB, m_modeAlpha);
118 	gl.blendFuncSeparate(m_srcRGB, m_dstRGB, m_srcAlpha, m_dstAlpha);
119 
120 	GLU_EXPECT_NO_ERROR(gl.getError(), "After render state setup");
121 }
122 
BlendTests(Context & context)123 BlendTests::BlendTests (Context& context)
124 	: TestCaseGroup(context, "blend", "Blend Performance Tests")
125 {
126 }
127 
~BlendTests(void)128 BlendTests::~BlendTests (void)
129 {
130 }
131 
init(void)132 void BlendTests::init (void)
133 {
134 	static const struct
135 	{
136 		const char*	name;
137 		GLenum		modeRGB;
138 		GLenum		modeAlpha;
139 		GLenum		srcRGB;
140 		GLenum		dstRGB;
141 		GLenum		srcAlpha;
142 		GLenum		dstAlpha;
143 	} cases[] =
144 	{
145 		// Single blend func, factor one.
146 		{ "add",						GL_FUNC_ADD,				GL_FUNC_ADD,				GL_ONE,		GL_ONE,		GL_ONE,		GL_ONE		},
147 		{ "subtract",					GL_FUNC_SUBTRACT,			GL_FUNC_SUBTRACT,			GL_ONE,		GL_ONE,		GL_ONE,		GL_ONE		},
148 		{ "reverse_subtract",			GL_FUNC_REVERSE_SUBTRACT,	GL_FUNC_REVERSE_SUBTRACT,	GL_ONE,		GL_ONE,		GL_ONE,		GL_ONE		},
149 
150 		// Porter-duff modes that can be implemented.
151 		{ "dst_atop",					GL_FUNC_ADD,				GL_FUNC_ADD,				GL_ONE_MINUS_DST_ALPHA,		GL_SRC_ALPHA,				GL_ONE,					GL_ZERO					},
152 		{ "dst_in",						GL_FUNC_ADD,				GL_FUNC_ADD,				GL_ZERO,					GL_SRC_ALPHA,				GL_ZERO,				GL_SRC_ALPHA			},
153 		{ "dst_out",					GL_FUNC_ADD,				GL_FUNC_ADD,				GL_ZERO,					GL_ONE_MINUS_SRC_ALPHA,		GL_ZERO,				GL_ONE_MINUS_SRC_ALPHA	},
154 		{ "dst_over",					GL_FUNC_ADD,				GL_FUNC_ADD,				GL_ONE_MINUS_DST_ALPHA,		GL_ONE,						GL_ONE,					GL_ONE_MINUS_SRC_ALPHA	},
155 		{ "src_atop",					GL_FUNC_ADD,				GL_FUNC_ADD,				GL_DST_ALPHA,				GL_ONE_MINUS_SRC_ALPHA,		GL_ZERO,				GL_ONE					},
156 		{ "src_in",						GL_FUNC_ADD,				GL_FUNC_ADD,				GL_DST_ALPHA,				GL_ZERO,					GL_DST_ALPHA,			GL_ZERO					},
157 		{ "src_out",					GL_FUNC_ADD,				GL_FUNC_ADD,				GL_ONE_MINUS_DST_ALPHA,		GL_ZERO,					GL_ONE_MINUS_DST_ALPHA,	GL_ZERO					},
158 		{ "src_over",					GL_FUNC_ADD,				GL_FUNC_ADD,				GL_ONE,						GL_ONE_MINUS_SRC_ALPHA,		GL_ONE,					GL_ONE_MINUS_SRC_ALPHA	},
159 		{ "multiply",					GL_FUNC_ADD,				GL_FUNC_ADD,				GL_DST_COLOR,				GL_ZERO,					GL_DST_ALPHA,			GL_ZERO					},
160 		{ "screen",						GL_FUNC_ADD,				GL_FUNC_ADD,				GL_ONE,						GL_ONE_MINUS_SRC_COLOR,		GL_ONE,					GL_ONE_MINUS_SRC_ALPHA	}
161 	};
162 
163 	for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); caseNdx++)
164 		addChild(new BlendCase(m_context, cases[caseNdx].name, "", cases[caseNdx].modeRGB, cases[caseNdx].modeAlpha, cases[caseNdx].srcRGB, cases[caseNdx].dstRGB, cases[caseNdx].srcAlpha, cases[caseNdx].dstAlpha));
165 }
166 
167 } // Performance
168 } // gles2
169 } // deqp
170