2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "test-gl-abstraction.h"
19 #include "test-trace-call-stack.h"
21 static const bool TRACE{false};
23 uint32_t GetGLDataTypeSize(GLenum type)
25 // There are many more types than what are covered here, but
26 // they are not supported in dali.
29 case GL_FLOAT: // "float", 1 float, 4 bytes
31 case GL_FLOAT_VEC2: // "vec2", 2 floats, 8 bytes
33 case GL_FLOAT_VEC3: // "vec3", 3 floats, 12 bytes
35 case GL_FLOAT_VEC4: // "vec4", 4 floats, 16 bytes
37 case GL_INT: // "int", 1 integer, 4 bytes
39 case GL_FLOAT_MAT2: // "mat2", 4 floats, 16 bytes
41 case GL_FLOAT_MAT3: // "mat3", 3 vec3, 36 bytes
43 case GL_FLOAT_MAT4: // "mat4", 4 vec4, 64 bytes
52 TestGlAbstraction::TestGlAbstraction()
53 : mBufferTrace(TRACE, std::string("gl")),
54 mCullFaceTrace(TRACE, "gl"),
55 mEnableDisableTrace(TRACE, "gl"),
56 mShaderTrace(TRACE, "gl"),
57 mTextureTrace(TRACE, std::string("gl")),
58 mTexParameterTrace(TRACE, "gl"),
59 mDrawTrace(TRACE, "gl"),
60 mDepthFunctionTrace(TRACE, "gl"),
61 mStencilFunctionTrace(TRACE, "gl"),
62 mScissorTrace(TRACE, "gl"),
63 mSetUniformTrace(TRACE, "Uniform "),
64 mViewportTrace(TRACE, "gl")
69 TestGlAbstraction::~TestGlAbstraction()
73 void TestGlAbstraction::Initialize()
76 mCompileStatus = GL_TRUE;
77 mLinkStatus = GL_TRUE;
79 mGetStringResult = NULL;
82 mIsFramebufferResult = 0;
84 mIsRenderbufferResult = 0;
87 mActiveTextureUnit = 0;
88 mCheckFramebufferStatusResult = 0;
89 mFramebufferStatus = 0;
90 mFramebufferDepthAttached = 0;
91 mFramebufferStencilAttached = 0;
92 mFramebufferDepthStencilAttached = 0;
93 mFramebufferColorAttachmentCount = 0;
94 mFrameBufferColorStatus = 0;
95 mFramebufferDepthAttachmentCount = 0;
96 mFramebufferStencilAttachmentCount = 0;
97 mFramebufferDepthStencilAttachmentCount = 0;
98 mNumBinaryFormats = 0;
100 mProgramBinaryLength = 0;
102 mVertexAttribArrayChanged = false;
103 mGetProgramBinaryCalled = false;
105 mLastShaderCompiled = 0;
106 mLastClearBitMask = 0;
107 mLastClearColor = Color::TRANSPARENT;
110 mLastBlendEquationRgb = 0;
111 mLastBlendEquationAlpha = 0;
112 mLastBlendFuncSrcRgb = 0;
113 mLastBlendFuncDstRgb = 0;
114 mLastBlendFuncSrcAlpha = 0;
115 mLastBlendFuncDstAlpha = 0;
116 mLastAutoTextureIdUsed = 0;
117 mNumGeneratedTextures = 0;
118 mLastShaderIdUsed = 0;
119 mLastProgramIdUsed = 0;
120 mLastUniformIdUsed = 0;
121 mLastDepthMask = false;
124 mProgramUniforms1i.clear();
125 mProgramUniforms1f.clear();
126 mProgramUniforms2f.clear();
127 mProgramUniforms3f.clear();
128 mProgramUniforms4f.clear();
130 mAttribLocs = {"aPosition", "aTexCoord"};
131 mAttribTypes = {GL_FLOAT, GL_FLOAT};
133 mCullFaceTrace.Reset();
134 mDepthFunctionTrace.Reset();
135 mEnableDisableTrace.Reset();
136 mShaderTrace.Reset();
137 mStencilFunctionTrace.Reset();
138 mScissorTrace.Reset();
139 mTextureTrace.Reset();
140 mTexParameterTrace.Reset();
143 for(unsigned int i = 0; i < MAX_ATTRIBUTE_CACHE_SIZE; ++i)
145 mVertexAttribArrayState[i] = false;
148 mActiveUniforms = std::vector<ActiveUniform>{
149 {"uRendererColor", GL_FLOAT, 1},
150 {"uCustom", GL_FLOAT_VEC3, 1},
151 {"uCustom3", GL_FLOAT_VEC3, 1},
152 {"uFadeColor", GL_FLOAT_VEC4, 1},
153 {"uUniform1", GL_FLOAT_VEC4, 1},
154 {"uUniform2", GL_FLOAT_VEC4, 1},
155 {"uUniform3", GL_FLOAT_VEC4, 1},
156 {"uFadeProgress", GL_FLOAT, 1},
157 {"uANormalMatrix", GL_FLOAT_MAT3, 1},
158 {"sEffect", GL_SAMPLER_2D, 1},
159 {"sTexture", GL_SAMPLER_2D, 1},
160 {"sTextureRect", GL_SAMPLER_2D, 1},
161 {"sGloss", GL_SAMPLER_2D, 1},
162 {"uColor", GL_FLOAT_VEC4, 1},
163 {"uActorColor", GL_FLOAT_VEC4, 1},
164 {"uModelMatrix", GL_FLOAT_MAT4, 1},
165 {"uModelView", GL_FLOAT_MAT4, 1},
166 {"uMvpMatrix", GL_FLOAT_MAT4, 1},
167 {"uNormalMatrix", GL_FLOAT_MAT4, 1},
168 {"uProjection", GL_FLOAT_MAT4, 1},
169 {"uScale", GL_FLOAT_VEC3, 1},
170 {"uSize", GL_FLOAT_VEC3, 1},
171 {"uViewMatrix", GL_FLOAT_MAT4, 1},
172 {"uLightCameraProjectionMatrix", GL_FLOAT_MAT4, 1},
173 {"uLightCameraViewMatrix", GL_FLOAT_MAT4, 1}};
176 for(uint32_t i = 0; i < mActiveUniforms.size(); ++i)
178 mActiveUniforms[i].offset = offset;
179 offset += mActiveUniforms[i].size * GetGLDataTypeSize(mActiveUniforms[i].type);
181 // WARNING: IF YOU CHANGE THIS LIST, ALSO CHANGE UNIFORMS IN test-graphics-reflection.cpp
184 void TestGlAbstraction::PreRender()
188 void TestGlAbstraction::PostRender()
192 bool TestGlAbstraction::IsSurfacelessContextSupported() const
197 bool TestGlAbstraction::IsAdvancedBlendEquationSupported()
202 bool TestGlAbstraction::IsMultisampledRenderToTextureSupported()
207 bool TestGlAbstraction::IsBlendEquationSupported(DevelBlendEquation::Type blendEquation)
212 std::string TestGlAbstraction::GetShaderVersionPrefix()
214 return std::string("");
217 std::string TestGlAbstraction::GetVertexShaderPrefix()
219 return std::string("");
222 std::string TestGlAbstraction::GetFragmentShaderPrefix()
224 return std::string("");
227 bool TestGlAbstraction::TextureRequiresConverting(const GLenum imageGlFormat, const GLenum textureGlFormat, const bool isSubImage) const
229 return ((imageGlFormat == GL_RGB) && (textureGlFormat == GL_RGBA));
232 void TestGlAbstraction::SetActiveUniforms(const std::vector<ActiveUniform>& uniforms)
234 mActiveUniforms = uniforms;
236 for(uint32_t i = 0; i < uniforms.size(); ++i)
238 mActiveUniforms[i].offset = offset;
239 offset += mActiveUniforms[i].size * GetGLDataTypeSize(mActiveUniforms[i].type);
245 bool BlendEnabled(const Dali::TraceCallStack& callStack)
247 std::stringstream out;
249 bool blendEnabled = callStack.FindMethodAndParams("Enable", out.str());
253 bool BlendDisabled(const Dali::TraceCallStack& callStack)
255 std::stringstream out;
257 bool blendEnabled = callStack.FindMethodAndParams("Disable", out.str());