e6416e3f4fe37244448c561a553ae123d9ea73fb
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-gl-abstraction.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include "test-gl-abstraction.h"
19 #include "test-trace-call-stack.h"
20
21 static const bool TRACE{
22   false};
23
24 namespace Dali
25 {
26 TestGlAbstraction::TestGlAbstraction()
27 : mBufferTrace(TRACE, std::string("gl")),
28   mCullFaceTrace(TRACE, "gl"),
29   mEnableDisableTrace(TRACE, "gl"),
30   mShaderTrace(TRACE, "gl"),
31   mTextureTrace(TRACE, std::string("gl")),
32   mTexParameterTrace(TRACE, "gl"),
33   mDrawTrace(TRACE, "gl"),
34   mDepthFunctionTrace(TRACE, "gl"),
35   mStencilFunctionTrace(TRACE, "gl"),
36   mScissorTrace(TRACE, "gl"),
37   mSetUniformTrace(TRACE, "Uniform "),
38   mViewportTrace(TRACE, "gl")
39 {
40   Initialize();
41 }
42
43 TestGlAbstraction::~TestGlAbstraction()
44 {
45 }
46
47 void TestGlAbstraction::Initialize()
48 {
49   mCurrentProgram                  = 0;
50   mCompileStatus                   = GL_TRUE;
51   mLinkStatus                      = GL_TRUE;
52   mGetErrorResult                  = 0;
53   mGetStringResult                 = NULL;
54   mIsBufferResult                  = 0;
55   mIsEnabledResult                 = 0;
56   mIsFramebufferResult             = 0;
57   mIsProgramResult                 = 0;
58   mIsRenderbufferResult            = 0;
59   mIsShaderResult                  = 0;
60   mIsTextureResult                 = 0;
61   mActiveTextureUnit               = 0;
62   mCheckFramebufferStatusResult    = 0;
63   mFramebufferStatus               = 0;
64   mFramebufferDepthAttached        = 0;
65   mFramebufferStencilAttached      = 0;
66   mFramebufferColorAttachmentCount = 0;
67   mFrameBufferColorStatus          = 0;
68   mNumBinaryFormats                = 0;
69   mBinaryFormats                   = 0;
70   mProgramBinaryLength             = 0;
71
72   mVertexAttribArrayChanged = false;
73   mGetProgramBinaryCalled   = false;
74
75   mLastShaderCompiled = 0;
76   mLastClearBitMask   = 0;
77   mLastClearColor     = Color::TRANSPARENT;
78   mClearCount         = 0;
79
80   mLastBlendEquationRgb   = 0;
81   mLastBlendEquationAlpha = 0;
82   mLastBlendFuncSrcRgb    = 0;
83   mLastBlendFuncDstRgb    = 0;
84   mLastBlendFuncSrcAlpha  = 0;
85   mLastBlendFuncDstAlpha  = 0;
86   mLastAutoTextureIdUsed  = 0;
87   mNumGeneratedTextures   = 0;
88   mLastShaderIdUsed       = 0;
89   mLastProgramIdUsed      = 0;
90   mLastUniformIdUsed      = 0;
91   mLastDepthMask          = false;
92
93   mUniforms.clear();
94   mProgramUniforms1i.clear();
95   mProgramUniforms1f.clear();
96   mProgramUniforms2f.clear();
97   mProgramUniforms3f.clear();
98   mProgramUniforms4f.clear();
99
100   mAttribLocs.clear();
101   mAttribLocs.push_back("aPosition");
102   mAttribLocs.push_back("aTexCoord");
103   mCullFaceTrace.Reset();
104   mDepthFunctionTrace.Reset();
105   mEnableDisableTrace.Reset();
106   mShaderTrace.Reset();
107   mStencilFunctionTrace.Reset();
108   mScissorTrace.Reset();
109   mTextureTrace.Reset();
110   mTexParameterTrace.Reset();
111   mDrawTrace.Reset();
112
113   for(unsigned int i = 0; i < MAX_ATTRIBUTE_CACHE_SIZE; ++i)
114   {
115     mVertexAttribArrayState[i] = false;
116   }
117
118   mActiveUniforms = std::vector<ActiveUniform>{
119     {"uRendererColor", GL_FLOAT, 1},
120     {"uCustom", GL_FLOAT_VEC3, 1},
121     {"uCustom3", GL_FLOAT_VEC3, 1},
122     {"uFadeColor", GL_FLOAT_VEC4, 1},
123     {"uUniform1", GL_FLOAT_VEC4, 1},
124     {"uUniform2", GL_FLOAT_VEC4, 1},
125     {"uUniform3", GL_FLOAT_VEC4, 1},
126     {"uFadeProgress", GL_FLOAT, 1},
127     {"uANormalMatrix", GL_FLOAT_MAT3, 1},
128     {"sEffect", GL_SAMPLER_2D, 1},
129     {"sTexture", GL_SAMPLER_2D, 1},
130     {"sTextureRect", GL_SAMPLER_2D, 1},
131     {"sGloss", GL_SAMPLER_2D, 1},
132     {"uColor", GL_FLOAT_VEC4, 1},
133     {"uActorColor", GL_FLOAT_VEC4, 1},
134     {"uModelMatrix", GL_FLOAT_MAT4, 1},
135     {"uModelView", GL_FLOAT_MAT4, 1},
136     {"uMvpMatrix", GL_FLOAT_MAT4, 1},
137     {"uNormalMatrix", GL_FLOAT_MAT4, 1},
138     {"uProjection", GL_FLOAT_MAT4, 1},
139     {"uSize", GL_FLOAT_VEC3, 1},
140     {"uViewMatrix", GL_FLOAT_MAT4, 1},
141     {"uLightCameraProjectionMatrix", GL_FLOAT_MAT4, 1},
142     {"uLightCameraViewMatrix", GL_FLOAT_MAT4, 1}};
143
144   // WARNING: IF YOU CHANGE THIS LIST, ALSO CHANGE UNIFORMS IN test-graphics-reflection.cpp
145 }
146
147 void TestGlAbstraction::PreRender()
148 {
149 }
150
151 void TestGlAbstraction::PostRender()
152 {
153 }
154
155 bool TestGlAbstraction::IsSurfacelessContextSupported() const
156 {
157   return true;
158 }
159
160 bool TestGlAbstraction::IsAdvancedBlendEquationSupported()
161 {
162   return true;
163 }
164
165 bool TestGlAbstraction::IsBlendEquationSupported(DevelBlendEquation::Type blendEquation)
166 {
167   return true;
168 }
169
170 std::string TestGlAbstraction::GetShaderVersionPrefix()
171 {
172   return std::string("");
173 }
174
175 std::string TestGlAbstraction::GetVertexShaderPrefix()
176 {
177   return std::string("");
178 }
179
180 std::string TestGlAbstraction::GetFragmentShaderPrefix()
181 {
182   return std::string("");
183 }
184
185 bool TestGlAbstraction::TextureRequiresConverting(const GLenum imageGlFormat, const GLenum textureGlFormat, const bool isSubImage) const
186 {
187   return ((imageGlFormat == GL_RGB) && (textureGlFormat == GL_RGBA));
188 }
189
190 } // namespace Dali
191
192 bool BlendEnabled(const Dali::TraceCallStack& callStack)
193 {
194   std::stringstream out;
195   out << GL_BLEND;
196   bool blendEnabled = callStack.FindMethodAndParams("Enable", out.str());
197   return blendEnabled;
198 }
199
200 bool BlendDisabled(const Dali::TraceCallStack& callStack)
201 {
202   std::stringstream out;
203   out << GL_BLEND;
204   bool blendEnabled = callStack.FindMethodAndParams("Disable", out.str());
205   return blendEnabled;
206 }