Fixed SVACE errors in Test Graphics
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-gl-abstraction.cpp
1 /*
2  * Copyright (c) 2021 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     {"uModelMatrix", GL_FLOAT_MAT4, 1},
134     {"uModelView", GL_FLOAT_MAT4, 1},
135     {"uMvpMatrix", GL_FLOAT_MAT4, 1},
136     {"uNormalMatrix", GL_FLOAT_MAT4, 1},
137     {"uProjection", GL_FLOAT_MAT4, 1},
138     {"uSize", GL_FLOAT_VEC3, 1},
139     {"uViewMatrix", GL_FLOAT_MAT4, 1},
140     {"uLightCameraProjectionMatrix", GL_FLOAT_MAT4, 1},
141     {"uLightCameraViewMatrix", GL_FLOAT_MAT4, 1}};
142 }
143
144 void TestGlAbstraction::PreRender()
145 {
146 }
147
148 void TestGlAbstraction::PostRender()
149 {
150 }
151
152 bool TestGlAbstraction::IsSurfacelessContextSupported() const
153 {
154   return true;
155 }
156
157 bool TestGlAbstraction::IsAdvancedBlendEquationSupported()
158 {
159   return true;
160 }
161
162 bool TestGlAbstraction::IsBlendEquationSupported(DevelBlendEquation::Type blendEquation)
163 {
164   return true;
165 }
166
167 std::string TestGlAbstraction::GetShaderVersionPrefix()
168 {
169   return std::string("");
170 }
171
172 std::string TestGlAbstraction::GetVertexShaderPrefix()
173 {
174   return std::string("");
175 }
176
177 std::string TestGlAbstraction::GetFragmentShaderPrefix()
178 {
179   return std::string("");
180 }
181
182 bool TestGlAbstraction::TextureRequiresConverting(const GLenum imageGlFormat, const GLenum textureGlFormat, const bool isSubImage) const
183 {
184   return ((imageGlFormat == GL_RGB) && (textureGlFormat == GL_RGBA));
185 }
186
187 } // namespace Dali
188
189 bool BlendEnabled(const Dali::TraceCallStack& callStack)
190 {
191   std::stringstream out;
192   out << GL_BLEND;
193   bool blendEnabled = callStack.FindMethodAndParams("Enable", out.str());
194   return blendEnabled;
195 }
196
197 bool BlendDisabled(const Dali::TraceCallStack& callStack)
198 {
199   std::stringstream out;
200   out << GL_BLEND;
201   bool blendEnabled = callStack.FindMethodAndParams("Disable", out.str());
202   return blendEnabled;
203 }