Use stencil buffer when use SceneView's FrameBuffer
[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   mFramebufferDepthStencilAttached        = 0;
67   mFramebufferColorAttachmentCount        = 0;
68   mFrameBufferColorStatus                 = 0;
69   mFramebufferDepthAttachmentCount        = 0;
70   mFramebufferStencilAttachmentCount      = 0;
71   mFramebufferDepthStencilAttachmentCount = 0;
72   mNumBinaryFormats                       = 0;
73   mBinaryFormats                          = 0;
74   mProgramBinaryLength                    = 0;
75
76   mVertexAttribArrayChanged = false;
77   mGetProgramBinaryCalled   = false;
78
79   mLastShaderCompiled = 0;
80   mLastClearBitMask   = 0;
81   mLastClearColor     = Color::TRANSPARENT;
82   mClearCount         = 0;
83
84   mLastBlendEquationRgb   = 0;
85   mLastBlendEquationAlpha = 0;
86   mLastBlendFuncSrcRgb    = 0;
87   mLastBlendFuncDstRgb    = 0;
88   mLastBlendFuncSrcAlpha  = 0;
89   mLastBlendFuncDstAlpha  = 0;
90   mLastAutoTextureIdUsed  = 0;
91   mNumGeneratedTextures   = 0;
92   mLastShaderIdUsed       = 0;
93   mLastProgramIdUsed      = 0;
94   mLastUniformIdUsed      = 0;
95   mLastDepthMask          = false;
96
97   mUniforms.clear();
98   mProgramUniforms1i.clear();
99   mProgramUniforms1f.clear();
100   mProgramUniforms2f.clear();
101   mProgramUniforms3f.clear();
102   mProgramUniforms4f.clear();
103
104   mAttribLocs.clear();
105   mAttribLocs.push_back("aPosition");
106   mAttribLocs.push_back("aTexCoord");
107   mCullFaceTrace.Reset();
108   mDepthFunctionTrace.Reset();
109   mEnableDisableTrace.Reset();
110   mShaderTrace.Reset();
111   mStencilFunctionTrace.Reset();
112   mScissorTrace.Reset();
113   mTextureTrace.Reset();
114   mTexParameterTrace.Reset();
115   mDrawTrace.Reset();
116
117   for(unsigned int i = 0; i < MAX_ATTRIBUTE_CACHE_SIZE; ++i)
118   {
119     mVertexAttribArrayState[i] = false;
120   }
121
122   mActiveUniforms = std::vector<ActiveUniform>{
123     {"uRendererColor", GL_FLOAT, 1},
124     {"uCustom", GL_FLOAT_VEC3, 1},
125     {"uCustom3", GL_FLOAT_VEC3, 1},
126     {"uFadeColor", GL_FLOAT_VEC4, 1},
127     {"uUniform1", GL_FLOAT_VEC4, 1},
128     {"uUniform2", GL_FLOAT_VEC4, 1},
129     {"uUniform3", GL_FLOAT_VEC4, 1},
130     {"uFadeProgress", GL_FLOAT, 1},
131     {"uANormalMatrix", GL_FLOAT_MAT3, 1},
132     {"sEffect", GL_SAMPLER_2D, 1},
133     {"sTexture", GL_SAMPLER_2D, 1},
134     {"sTextureRect", GL_SAMPLER_2D, 1},
135     {"sGloss", GL_SAMPLER_2D, 1},
136     {"uColor", GL_FLOAT_VEC4, 1},
137     {"uActorColor", GL_FLOAT_VEC4, 1},
138     {"uModelMatrix", GL_FLOAT_MAT4, 1},
139     {"uModelView", GL_FLOAT_MAT4, 1},
140     {"uMvpMatrix", GL_FLOAT_MAT4, 1},
141     {"uNormalMatrix", GL_FLOAT_MAT4, 1},
142     {"uProjection", GL_FLOAT_MAT4, 1},
143     {"uSize", GL_FLOAT_VEC3, 1},
144     {"uViewMatrix", GL_FLOAT_MAT4, 1},
145     {"uLightCameraProjectionMatrix", GL_FLOAT_MAT4, 1},
146     {"uLightCameraViewMatrix", GL_FLOAT_MAT4, 1}};
147
148   // WARNING: IF YOU CHANGE THIS LIST, ALSO CHANGE UNIFORMS IN test-graphics-reflection.cpp
149 }
150
151 void TestGlAbstraction::PreRender()
152 {
153 }
154
155 void TestGlAbstraction::PostRender()
156 {
157 }
158
159 bool TestGlAbstraction::IsSurfacelessContextSupported() const
160 {
161   return true;
162 }
163
164 bool TestGlAbstraction::IsAdvancedBlendEquationSupported()
165 {
166   return true;
167 }
168
169 bool TestGlAbstraction::IsBlendEquationSupported(DevelBlendEquation::Type blendEquation)
170 {
171   return true;
172 }
173
174 std::string TestGlAbstraction::GetShaderVersionPrefix()
175 {
176   return std::string("");
177 }
178
179 std::string TestGlAbstraction::GetVertexShaderPrefix()
180 {
181   return std::string("");
182 }
183
184 std::string TestGlAbstraction::GetFragmentShaderPrefix()
185 {
186   return std::string("");
187 }
188
189 bool TestGlAbstraction::TextureRequiresConverting(const GLenum imageGlFormat, const GLenum textureGlFormat, const bool isSubImage) const
190 {
191   return ((imageGlFormat == GL_RGB) && (textureGlFormat == GL_RGBA));
192 }
193
194 } // namespace Dali
195
196 bool BlendEnabled(const Dali::TraceCallStack& callStack)
197 {
198   std::stringstream out;
199   out << GL_BLEND;
200   bool blendEnabled = callStack.FindMethodAndParams("Enable", out.str());
201   return blendEnabled;
202 }
203
204 bool BlendDisabled(const Dali::TraceCallStack& callStack)
205 {
206   std::stringstream out;
207   out << GL_BLEND;
208   bool blendEnabled = callStack.FindMethodAndParams("Disable", out.str());
209   return blendEnabled;
210 }