1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.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 "es3pBlendTests.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 gles3
34 {
35 namespace Performance
36 {
37
38 using namespace gls;
39 using namespace glw; // GL types
40 using tcu::TestLog;
41 using tcu::Vec4;
42
43 class BlendCase : public ShaderPerformanceCase
44 {
45 public:
46 BlendCase(Context &context, const char *name, const char *description, GLenum modeRGB, GLenum modeAlpha,
47 GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
48 ~BlendCase(void);
49
50 void init(void);
51
52 private:
53 void setupRenderState(void);
54
55 GLenum m_modeRGB;
56 GLenum m_modeAlpha;
57 GLenum m_srcRGB;
58 GLenum m_dstRGB;
59 GLenum m_srcAlpha;
60 GLenum m_dstAlpha;
61 };
62
BlendCase(Context & context,const char * name,const char * description,GLenum modeRGB,GLenum modeAlpha,GLenum srcRGB,GLenum dstRGB,GLenum srcAlpha,GLenum dstAlpha)63 BlendCase::BlendCase(Context &context, const char *name, const char *description, GLenum modeRGB, GLenum modeAlpha,
64 GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
65 : ShaderPerformanceCase(context.getTestContext(), context.getRenderContext(), name, description, CASETYPE_FRAGMENT)
66 , m_modeRGB(modeRGB)
67 , m_modeAlpha(modeAlpha)
68 , m_srcRGB(srcRGB)
69 , m_dstRGB(dstRGB)
70 , m_srcAlpha(srcAlpha)
71 , m_dstAlpha(dstAlpha)
72 {
73 }
74
~BlendCase(void)75 BlendCase::~BlendCase(void)
76 {
77 }
78
init(void)79 void BlendCase::init(void)
80 {
81 TestLog &log = m_testCtx.getLog();
82
83 log << TestLog::Message << "modeRGB: " << glu::getBlendEquationStr(m_modeRGB) << TestLog::EndMessage;
84 log << TestLog::Message << "modeAlpha: " << glu::getBlendEquationStr(m_modeAlpha) << TestLog::EndMessage;
85 log << TestLog::Message << "srcRGB: " << glu::getBlendFactorStr(m_srcRGB) << TestLog::EndMessage;
86 log << TestLog::Message << "dstRGB: " << glu::getBlendFactorStr(m_dstRGB) << TestLog::EndMessage;
87 log << TestLog::Message << "srcAlpha: " << glu::getBlendFactorStr(m_srcAlpha) << TestLog::EndMessage;
88 log << TestLog::Message << "dstAlpha: " << glu::getBlendFactorStr(m_dstAlpha) << TestLog::EndMessage;
89
90 m_vertShaderSource = "#version 300 es\n"
91 "in highp vec4 a_position;\n"
92 "in mediump vec4 a_color;\n"
93 "out mediump vec4 v_color;\n"
94 "void main (void)\n"
95 "{\n"
96 " gl_Position = a_position;\n"
97 " v_color = a_color;\n"
98 "}\n";
99 m_fragShaderSource = "#version 300 es\n"
100 "in mediump vec4 v_color;\n"
101 "layout(location = 0) out mediump vec4 o_color;\n"
102 "void main (void)\n"
103 "{\n"
104 " o_color = v_color;\n"
105 "}\n";
106
107 m_attributes.push_back(AttribSpec("a_color", Vec4(0.0f, 0.5f, 0.5f, 1.0f), Vec4(0.5f, 1.0f, 0.0f, 0.5f),
108 Vec4(0.5f, 0.0f, 1.0f, 0.5f), Vec4(1.0f, 0.5f, 0.5f, 0.0f)));
109
110 ShaderPerformanceCase::init();
111 }
112
setupRenderState(void)113 void BlendCase::setupRenderState(void)
114 {
115 const glw::Functions &gl = m_renderCtx.getFunctions();
116
117 gl.enable(GL_BLEND);
118 gl.blendEquationSeparate(m_modeRGB, m_modeAlpha);
119 gl.blendFuncSeparate(m_srcRGB, m_dstRGB, m_srcAlpha, m_dstAlpha);
120
121 GLU_EXPECT_NO_ERROR(gl.getError(), "After render state setup");
122 }
123
BlendTests(Context & context)124 BlendTests::BlendTests(Context &context) : 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 // Single blend func, factor one.
145 {"add", GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE, GL_ONE, GL_ONE, GL_ONE},
146 {"subtract", GL_FUNC_SUBTRACT, GL_FUNC_SUBTRACT, GL_ONE, GL_ONE, GL_ONE, GL_ONE},
147 {"reverse_subtract", GL_FUNC_REVERSE_SUBTRACT, GL_FUNC_REVERSE_SUBTRACT, GL_ONE, GL_ONE, GL_ONE, GL_ONE},
148 {"min", GL_MIN, GL_MIN, GL_ONE, GL_ONE, GL_ONE, GL_ONE},
149 {"max", GL_MAX, GL_MAX, GL_ONE, GL_ONE, GL_ONE, GL_ONE},
150
151 // Porter-duff modes that can be implemented.
152 {"dst_atop", GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA, GL_ONE, GL_ZERO},
153 {"dst_in", GL_FUNC_ADD, GL_FUNC_ADD, GL_ZERO, GL_SRC_ALPHA, GL_ZERO, GL_SRC_ALPHA},
154 {"dst_out", GL_FUNC_ADD, GL_FUNC_ADD, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA},
155 {"dst_over", GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE_MINUS_DST_ALPHA, GL_ONE, GL_ONE, GL_ONE_MINUS_SRC_ALPHA},
156 {"src_atop", GL_FUNC_ADD, GL_FUNC_ADD, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE},
157 {"src_in", GL_FUNC_ADD, GL_FUNC_ADD, GL_DST_ALPHA, GL_ZERO, GL_DST_ALPHA, GL_ZERO},
158 {"src_out", GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE_MINUS_DST_ALPHA, GL_ZERO, GL_ONE_MINUS_DST_ALPHA, GL_ZERO},
159 {"src_over", GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA},
160 {"multiply", GL_FUNC_ADD, GL_FUNC_ADD, GL_DST_COLOR, GL_ZERO, GL_DST_ALPHA, GL_ZERO},
161 {"screen", GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE, GL_ONE_MINUS_SRC_COLOR, GL_ONE, GL_ONE_MINUS_SRC_ALPHA},
162
163 {"alpha_saturate", GL_FUNC_ADD, GL_FUNC_ADD, GL_SRC_ALPHA_SATURATE, GL_ONE, GL_ONE, GL_ONE},
164 };
165
166 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); caseNdx++)
167 addChild(new BlendCase(m_context, cases[caseNdx].name, "", cases[caseNdx].modeRGB, cases[caseNdx].modeAlpha,
168 cases[caseNdx].srcRGB, cases[caseNdx].dstRGB, cases[caseNdx].srcAlpha,
169 cases[caseNdx].dstAlpha));
170 }
171
172 } // namespace Performance
173 } // namespace gles3
174 } // namespace deqp
175