Home | History | Annotate | Download | only in performance
      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::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 
     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 
     73 BlendCase::~BlendCase (void)
     74 {
     75 }
     76 
     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 		"#version 300 es\n"
     90 		"in highp vec4 a_position;\n"
     91 		"in mediump vec4 a_color;\n"
     92 		"out mediump vec4 v_color;\n"
     93 		"void main (void)\n"
     94 		"{\n"
     95 		"	gl_Position = a_position;\n"
     96 		"	v_color = a_color;\n"
     97 		"}\n";
     98 	m_fragShaderSource =
     99 		"#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),
    108 												 Vec4(0.5f, 1.0f, 0.0f, 0.5f),
    109 												 Vec4(0.5f, 0.0f, 1.0f, 0.5f),
    110 												 Vec4(1.0f, 0.5f, 0.5f, 0.0f)));
    111 
    112 	ShaderPerformanceCase::init();
    113 }
    114 
    115 void BlendCase::setupRenderState (void)
    116 {
    117 	const glw::Functions& gl = m_renderCtx.getFunctions();
    118 
    119 	gl.enable(GL_BLEND);
    120 	gl.blendEquationSeparate(m_modeRGB, m_modeAlpha);
    121 	gl.blendFuncSeparate(m_srcRGB, m_dstRGB, m_srcAlpha, m_dstAlpha);
    122 
    123 	GLU_EXPECT_NO_ERROR(gl.getError(), "After render state setup");
    124 }
    125 
    126 BlendTests::BlendTests (Context& context)
    127 	: TestCaseGroup(context, "blend", "Blend Performance Tests")
    128 {
    129 }
    130 
    131 BlendTests::~BlendTests (void)
    132 {
    133 }
    134 
    135 void BlendTests::init (void)
    136 {
    137 	static const struct
    138 	{
    139 		const char*	name;
    140 		GLenum		modeRGB;
    141 		GLenum		modeAlpha;
    142 		GLenum		srcRGB;
    143 		GLenum		dstRGB;
    144 		GLenum		srcAlpha;
    145 		GLenum		dstAlpha;
    146 	} cases[] =
    147 	{
    148 		// Single blend func, factor one.
    149 		{ "add",						GL_FUNC_ADD,				GL_FUNC_ADD,				GL_ONE,		GL_ONE,		GL_ONE,		GL_ONE		},
    150 		{ "subtract",					GL_FUNC_SUBTRACT,			GL_FUNC_SUBTRACT,			GL_ONE,		GL_ONE,		GL_ONE,		GL_ONE		},
    151 		{ "reverse_subtract",			GL_FUNC_REVERSE_SUBTRACT,	GL_FUNC_REVERSE_SUBTRACT,	GL_ONE,		GL_ONE,		GL_ONE,		GL_ONE		},
    152 		{ "min",						GL_MIN,						GL_MIN,						GL_ONE,		GL_ONE,		GL_ONE,		GL_ONE		},
    153 		{ "max",						GL_MAX,						GL_MAX,						GL_ONE,		GL_ONE,		GL_ONE,		GL_ONE		},
    154 
    155 		// Porter-duff modes that can be implemented.
    156 		{ "dst_atop",					GL_FUNC_ADD,				GL_FUNC_ADD,				GL_ONE_MINUS_DST_ALPHA,		GL_SRC_ALPHA,				GL_ONE,					GL_ZERO					},
    157 		{ "dst_in",						GL_FUNC_ADD,				GL_FUNC_ADD,				GL_ZERO,					GL_SRC_ALPHA,				GL_ZERO,				GL_SRC_ALPHA			},
    158 		{ "dst_out",					GL_FUNC_ADD,				GL_FUNC_ADD,				GL_ZERO,					GL_ONE_MINUS_SRC_ALPHA,		GL_ZERO,				GL_ONE_MINUS_SRC_ALPHA	},
    159 		{ "dst_over",					GL_FUNC_ADD,				GL_FUNC_ADD,				GL_ONE_MINUS_DST_ALPHA,		GL_ONE,						GL_ONE,					GL_ONE_MINUS_SRC_ALPHA	},
    160 		{ "src_atop",					GL_FUNC_ADD,				GL_FUNC_ADD,				GL_DST_ALPHA,				GL_ONE_MINUS_SRC_ALPHA,		GL_ZERO,				GL_ONE					},
    161 		{ "src_in",						GL_FUNC_ADD,				GL_FUNC_ADD,				GL_DST_ALPHA,				GL_ZERO,					GL_DST_ALPHA,			GL_ZERO					},
    162 		{ "src_out",					GL_FUNC_ADD,				GL_FUNC_ADD,				GL_ONE_MINUS_DST_ALPHA,		GL_ZERO,					GL_ONE_MINUS_DST_ALPHA,	GL_ZERO					},
    163 		{ "src_over",					GL_FUNC_ADD,				GL_FUNC_ADD,				GL_ONE,						GL_ONE_MINUS_SRC_ALPHA,		GL_ONE,					GL_ONE_MINUS_SRC_ALPHA	},
    164 		{ "multiply",					GL_FUNC_ADD,				GL_FUNC_ADD,				GL_DST_COLOR,				GL_ZERO,					GL_DST_ALPHA,			GL_ZERO					},
    165 		{ "screen",						GL_FUNC_ADD,				GL_FUNC_ADD,				GL_ONE,						GL_ONE_MINUS_SRC_COLOR,		GL_ONE,					GL_ONE_MINUS_SRC_ALPHA	},
    166 
    167 		{ "alpha_saturate",				GL_FUNC_ADD,				GL_FUNC_ADD,				GL_SRC_ALPHA_SATURATE,		GL_ONE,						GL_ONE,					GL_ONE					},
    168 	};
    169 
    170 	for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); caseNdx++)
    171 		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));
    172 }
    173 
    174 } // Performance
    175 } // gles3
    176 } // deqp
    177