ddeb1d9aaac1352bbccde277a6e7742612de25a0
[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   mNumberOfActiveUniforms          = 0;
53   mGetErrorResult                  = 0;
54   mGetStringResult                 = NULL;
55   mIsBufferResult                  = 0;
56   mIsEnabledResult                 = 0;
57   mIsFramebufferResult             = 0;
58   mIsProgramResult                 = 0;
59   mIsRenderbufferResult            = 0;
60   mIsShaderResult                  = 0;
61   mIsTextureResult                 = 0;
62   mActiveTextureUnit               = 0;
63   mCheckFramebufferStatusResult    = 0;
64   mFramebufferStatus               = 0;
65   mFramebufferDepthAttached        = 0;
66   mFramebufferStencilAttached      = 0;
67   mFramebufferColorAttachmentCount = 0;
68   mFrameBufferColorStatus          = 0;
69   mNumBinaryFormats                = 0;
70   mBinaryFormats                   = 0;
71   mProgramBinaryLength             = 0;
72
73   mVertexAttribArrayChanged = false;
74   mGetProgramBinaryCalled   = false;
75
76   mLastShaderCompiled = 0;
77   mLastClearBitMask   = 0;
78   mLastClearColor     = Color::TRANSPARENT;
79   mClearCount         = 0;
80
81   mLastBlendEquationRgb   = 0;
82   mLastBlendEquationAlpha = 0;
83   mLastBlendFuncSrcRgb    = 0;
84   mLastBlendFuncDstRgb    = 0;
85   mLastBlendFuncSrcAlpha  = 0;
86   mLastBlendFuncDstAlpha  = 0;
87   mLastAutoTextureIdUsed  = 0;
88   mNumGeneratedTextures   = 0;
89   mLastShaderIdUsed       = 0;
90   mLastProgramIdUsed      = 0;
91   mLastUniformIdUsed      = 0;
92   mLastDepthMask          = false;
93
94   mUniforms.clear();
95   mProgramUniforms1i.clear();
96   mProgramUniforms1f.clear();
97   mProgramUniforms2f.clear();
98   mProgramUniforms3f.clear();
99   mProgramUniforms4f.clear();
100
101   mAttribLocs.clear();
102   mAttribLocs.push_back("aPosition");
103   mAttribLocs.push_back("aTexCoord");
104   mCullFaceTrace.Reset();
105   mDepthFunctionTrace.Reset();
106   mEnableDisableTrace.Reset();
107   mShaderTrace.Reset();
108   mStencilFunctionTrace.Reset();
109   mScissorTrace.Reset();
110   mTextureTrace.Reset();
111   mTexParameterTrace.Reset();
112   mDrawTrace.Reset();
113
114   for(unsigned int i = 0; i < MAX_ATTRIBUTE_CACHE_SIZE; ++i)
115   {
116     mVertexAttribArrayState[i] = false;
117   }
118 }
119
120 void TestGlAbstraction::PreRender()
121 {
122 }
123
124 void TestGlAbstraction::PostRender()
125 {
126 }
127
128 bool TestGlAbstraction::IsSurfacelessContextSupported() const
129 {
130   return true;
131 }
132
133 bool TestGlAbstraction::IsAdvancedBlendEquationSupported()
134 {
135   return true;
136 }
137
138 bool TestGlAbstraction::IsBlendEquationSupported(DevelBlendEquation::Type blendEquation)
139 {
140   return true;
141 }
142
143 std::string TestGlAbstraction::GetShaderVersionPrefix()
144 {
145   return std::string("");
146 }
147
148 std::string TestGlAbstraction::GetVertexShaderPrefix()
149 {
150   return std::string("");
151 }
152
153 std::string TestGlAbstraction::GetFragmentShaderPrefix()
154 {
155   return std::string("");
156 }
157
158 bool TestGlAbstraction::TextureRequiresConverting(const GLenum imageGlFormat, const GLenum textureGlFormat, const bool isSubImage) const
159 {
160   return ((imageGlFormat == GL_RGB) && (textureGlFormat == GL_RGBA));
161 }
162
163 } // namespace Dali
164
165 bool BlendEnabled(const Dali::TraceCallStack& callStack)
166 {
167   std::stringstream out;
168   out << GL_BLEND;
169   bool blendEnabled = callStack.FindMethodAndParams("Enable", out.str());
170   return blendEnabled;
171 }
172
173 bool BlendDisabled(const Dali::TraceCallStack& callStack)
174 {
175   std::stringstream out;
176   out << GL_BLEND;
177   bool blendEnabled = callStack.FindMethodAndParams("Disable", out.str());
178   return blendEnabled;
179 }