1 #ifndef DALI_GRAPHICS_GLES_CONTEXT_H
2 #define DALI_GRAPHICS_GLES_CONTEXT_H
5 * Copyright (c) 2024 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 #include <dali/graphics-api/graphics-command-buffer.h>
22 #include "gles-context-state-cache.h"
23 #include "gles-graphics-types.h"
25 namespace Dali::Graphics
27 class EglGraphicsController;
34 class TextureDependencyChecker;
37 * @brief Context represents single GLES context
42 explicit Context(EglGraphicsController& controller, Integration::GlAbstraction* glAbstraction);
47 * @brief Flushes the context
49 * Flushes the context by issuing GL calls to set the required
50 * state. Causes a glWaitSync if any drawn textures are dependent
53 * @param[in] reset If true then state is reset unconditionally
54 * @param[in] drawCall the draws that need flushing
55 * @param[in] dependencyChecker The texture dependecy checker
57 void Flush(bool reset, const GLES::DrawCallDescriptor& drawCall, GLES::TextureDependencyChecker& dependencyChecker);
60 * @brief Returns context Id
63 uint32_t GetContextId() const
69 * @brief Binds textures to the context
71 * Bindings are merged, they are resolved at later time
72 * when the draw call is issued. Then the texture binding
73 * slots (GL active texture binding) are enabled/disabled accordingly
74 * to the uniform layout.
76 * @param[in] bindings List of bindings
79 void BindTextures(const Graphics::TextureBinding* bindings, uint32_t count);
82 * @brief Vertex buffers to bind
84 * The bindings are taken from a command buffer being
85 * currently processed and copied into the local storage.
88 void BindVertexBuffers(const GLES::VertexBufferBindingDescriptor* bindings, uint32_t count);
91 * @brief Binds index buffer
93 * @param indexBufferBinding
95 void BindIndexBuffer(const IndexBufferBindingDescriptor& indexBufferBinding);
98 * @brief Binds pipeline to the context
101 void BindPipeline(const GLES::Pipeline* newPipeline);
104 * @brief Binds uniform buffers to the context
106 * @param[in] uboBindings real UBO binfins
107 * @param[in] standaloneBindings emulated (legacy) UBO object
109 void BindUniformBuffers(const UniformBufferBindingDescriptor* uboBindings, uint32_t uboCount, const UniformBufferBindingDescriptor& standaloneBindings);
112 * @brief Resolves blend state on the currently attached pipeline
114 void ResolveBlendState();
117 * @brief Resolves rasterization state on the currently attached pipeline
119 void ResolveRasterizationState();
122 * @brief Resolves uniform buffers and binds data to the pipeline
124 void ResolveUniformBuffers();
127 * @brief Special usecase for legacy shaders, called by ResolveUniformBuffers()
129 void ResolveStandaloneUniforms();
132 * @brief Resolves GPU-based uniform buffers
134 void ResolveGpuUniformBuffers();
137 * @brief Begins render pass for specified render target
139 * @param[in] renderPass render pass object to begin
141 void BeginRenderPass(const BeginRenderPassDescriptor& renderPassBegin);
144 * @brief Ends render pass
146 * Ending render pass is necessary in order to ensure
147 * proper explicit synchronization is in place
149 void EndRenderPass(TextureDependencyChecker& checker);
152 * @brief Returns the cache of GL state in the context
153 * @return the reference of GL state cache (which can be modified)
155 GLStateCache& GetGLStateCache();
158 * @brief Called when the GL context has been created.
160 void GlContextCreated();
163 * @brief Called when the GL context has been destroyed.
165 void GlContextDestroyed();
168 * @brief Invalidates the cached pipeline object in the context if it matches
169 * This is called before the pipeline is deleted
171 * @param[in] pipeline The pipeline
173 void InvalidateCachedPipeline(GLES::Pipeline* pipeline);
176 * @brief Sets up EGL context for native rendering
178 * - The native rendering uses dedicated context
179 * - There is one EGL native rendering context per GLES::Context object
180 * - Native rendering context is compatible with the window/surface context
181 * - Native rendering context dies with GLES::Context object
183 * When native rendering is about to be executed, the dedicated EGL context
184 * is acquired (created or reused) and made current. The Window/Surface context
185 * is cached to be restored afterwards.
187 void PrepareForNativeRendering();
190 * @brief Restores window/surface context after native rendering.
192 void RestoreFromNativeRendering();
194 void ActiveTexture(uint32_t textureBindingIndex);
195 void BindTexture(GLenum target, BoundTextureType textureTypeId, uint32_t textureId);
196 void GenerateMipmap(GLenum target);
200 * @return true if the buffer was actually bound, false if it's cached
202 bool BindBuffer(GLenum target, uint32_t bufferId);
204 void DrawBuffers(uint32_t count, const GLenum* buffers);
205 void BindFrameBuffer(GLenum target, uint32_t bufferId);
206 void GenFramebuffers(uint32_t count, uint32_t* framebuffers);
207 void DeleteFramebuffers(uint32_t count, uint32_t* framebuffers);
208 void ColorMask(bool enabled);
209 void ClearStencilBuffer();
210 void ClearDepthBuffer();
211 void ClearBuffer(uint32_t mask, bool forceClear);
212 void InvalidateDepthStencilBuffers();
213 void SetScissorTestEnabled(bool scissorEnabled);
214 void SetStencilTestEnable(bool stencilEnable);
215 void StencilMask(uint32_t writeMask);
216 void StencilFunc(Graphics::CompareOp compareOp,
218 uint32_t compareMask);
219 void StencilOp(Graphics::StencilOp failOp,
220 Graphics::StencilOp depthFailOp,
221 Graphics::StencilOp passOp);
222 void SetDepthCompareOp(Graphics::CompareOp compareOp);
223 void SetDepthTestEnable(bool depthTestEnable);
224 void SetDepthWriteEnable(bool depthWriteEnable);
228 * @brief Clear current state
234 std::unique_ptr<Impl> mImpl;
237 } // namespace Dali::Graphics
238 #endif //DALI_GRAPHICS_GLES_CONTEXT_H