1 #ifndef DALI_GRAPHICS_GLES_CONTEXT_H
2 #define DALI_GRAPHICS_GLES_CONTEXT_H
5 * Copyright (c) 2023 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);
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 Begins render pass for specified render target
134 * @param[in] renderPass render pass object to begin
136 void BeginRenderPass(const BeginRenderPassDescriptor& renderPassBegin);
139 * @brief Ends render pass
141 * Ending render pass is necessary in order to ensure
142 * proper explicit synchronization is in place
144 void EndRenderPass(TextureDependencyChecker& checker);
147 * @brief Returns the cache of GL state in the context
148 * @return the reference of GL state cache (which can be modified)
150 GLStateCache& GetGLStateCache();
153 * @brief Called when the GL context has been created.
155 void GlContextCreated();
158 * @brief Called when the GL context has been destroyed.
160 void GlContextDestroyed();
163 * @brief Invalidates the cached pipeline object in the context if it matches
164 * This is called before the pipeline is deleted
166 * @param[in] pipeline The pipeline
168 void InvalidateCachedPipeline(GLES::Pipeline* pipeline);
171 * @brief Sets up EGL context for native rendering
173 * - The native rendering uses dedicated context
174 * - There is one EGL native rendering context per GLES::Context object
175 * - Native rendering context is compatible with the window/surface context
176 * - Native rendering context dies with GLES::Context object
178 * When native rendering is about to be executed, the dedicated EGL context
179 * is acquired (created or reused) and made current. The Window/Surface context
180 * is cached to be restored afterwards.
182 void PrepareForNativeRendering();
185 * @brief Restores window/surface context after native rendering.
187 void RestoreFromNativeRendering();
189 void ActiveTexture(uint32_t textureBindingIndex);
190 void BindTexture(GLenum target, BoundTextureType textureTypeId, uint32_t textureId);
191 void GenerateMipmap(GLenum target);
195 * @return true if the buffer was actually bound, false if it's cached
197 bool BindBuffer(GLenum target, uint32_t bufferId);
199 void DrawBuffers(uint32_t count, const GLenum* buffers);
200 void BindFrameBuffer(GLenum target, uint32_t bufferId);
201 void GenFramebuffers(uint32_t count, uint32_t* framebuffers);
202 void DeleteFramebuffers(uint32_t count, uint32_t* framebuffers);
203 void ColorMask(bool enabled);
204 void ClearStencilBuffer();
205 void ClearDepthBuffer();
206 void ClearBuffer(uint32_t mask, bool forceClear);
207 void InvalidateDepthStencilBuffers();
208 void SetScissorTestEnabled(bool scissorEnabled);
209 void SetStencilTestEnable(bool stencilEnable);
210 void StencilMask(uint32_t writeMask);
211 void StencilFunc(Graphics::CompareOp compareOp,
213 uint32_t compareMask);
214 void StencilOp(Graphics::StencilOp failOp,
215 Graphics::StencilOp depthFailOp,
216 Graphics::StencilOp passOp);
217 void SetDepthCompareOp(Graphics::CompareOp compareOp);
218 void SetDepthTestEnable(bool depthTestEnable);
219 void SetDepthWriteEnable(bool depthWriteEnable);
223 * @brief Clear current state
229 std::unique_ptr<Impl> mImpl;
232 } // namespace Dali::Graphics
233 #endif //DALI_GRAPHICS_GLES_CONTEXT_H