1 #ifndef DALI_GRAPHICS_GLES_CONTEXT_H
2 #define DALI_GRAPHICS_GLES_CONTEXT_H
5 * Copyright (c) 2021 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;
36 * @brief Context represents single GLES context
41 explicit Context(EglGraphicsController& controller);
46 * @brief Flushes the context
48 * Flushes the context by issuing GL calls to set the required
51 * @param[in] reset If true then state is reset unconditionally
53 void Flush(bool reset, const GLES::DrawCallDescriptor& drawCall);
56 * @brief Returns context Id
59 uint32_t GetContextId() const
65 * @brief Binds textures to the context
67 * Bindings are merged, they are resolved at later time
68 * when the draw call is issued. Then the texture binding
69 * slots (GL active texture binding) are enabled/disabled accordingly
70 * to the uniform layout.
72 * @param[in] bindings List of bindings
75 void BindTextures(const Graphics::TextureBinding* bindings, uint32_t count);
78 * @brief Vertex buffers to bind
80 * The bindings are taken from a command buffer being
81 * currently processed and copied into the local storage.
84 void BindVertexBuffers(const GLES::VertexBufferBindingDescriptor* bindings, uint32_t count);
87 * @brief Binds index buffer
89 * @param indexBufferBinding
91 void BindIndexBuffer(const IndexBufferBindingDescriptor& indexBufferBinding);
94 * @brief Binds pipeline to the context
97 void BindPipeline(const GLES::Pipeline* newPipeline);
100 * @brief Binds uniform buffers to the context
102 * @param[in] uboBindings real UBO binfins
103 * @param[in] standaloneBindings emulated (legacy) UBO object
105 void BindUniformBuffers(const UniformBufferBindingDescriptor* uboBindings, uint32_t uboCount, const UniformBufferBindingDescriptor& standaloneBindings);
108 * @brief Resolves blend state on the currently attached pipeline
110 void ResolveBlendState();
113 * @brief Resolves rasterization state on the currently attached pipeline
115 void ResolveRasterizationState();
118 * @brief Resolves uniform buffers and binds data to the pipeline
120 void ResolveUniformBuffers();
123 * @brief Special usecase for legacy shaders, called by ResolveUniformBuffers()
125 void ResolveStandaloneUniforms();
128 * @brief Begins render pass for sepcified render target
130 * @param[in] renderPass render pass object to begin
131 * @param[in] renderTarget render target to be drawn onto
133 void BeginRenderPass(const BeginRenderPassDescriptor& renderPassBegin);
136 * @brief Ends render pass
138 * Ending render pass is necessary in order to ensure
139 * proper implicit synchronization is in place
141 void EndRenderPass();
144 * @brief Returns the cache of GL state in the context
145 * @return the reference of GL state cache (which can be modified)
147 GLStateCache& GetGLStateCache();
150 * @brief Called when the GL context has been created.
152 void GlContextCreated();
155 * @brief Called when the GL context has been destroyed.
157 void GlContextDestroyed();
160 * @brief Invalidates the cached pipeline object in the context if it matches
161 * This is called before the pipeline is deleted
163 * @param[in] pipeline The pipeline
165 void InvalidateCachedPipeline(GLES::Pipeline* pipeline);
167 void ActiveTexture(uint32_t textureBindingIndex);
168 void BindTexture(GLenum target, BoundTextureType textureTypeId, uint32_t textureId);
169 void GenerateMipmap(GLenum target);
170 void BindBuffer(GLenum target, uint32_t bufferId);
171 void DrawBuffers(uint32_t count, const GLenum* buffers);
172 void BindFrameBuffer(GLenum target, uint32_t bufferId);
173 void GenFramebuffers(uint32_t count, uint32_t* framebuffers);
174 void DeleteFramebuffers(uint32_t count, uint32_t* framebuffers);
175 void ColorMask(bool enabled);
176 void ClearStencilBuffer();
177 void ClearDepthBuffer();
178 void ClearBuffer(uint32_t mask, bool forceClear);
179 void InvalidateDepthStencilBuffers();
180 void SetScissorTestEnabled(bool scissorEnabled);
181 void SetStencilTestEnable(bool stencilEnable);
182 void StencilMask(uint32_t writeMask);
183 void StencilFunc(Graphics::CompareOp compareOp,
185 uint32_t compareMask);
186 void StencilOp(Graphics::StencilOp failOp,
187 Graphics::StencilOp depthFailOp,
188 Graphics::StencilOp passOp);
189 void SetDepthCompareOp(Graphics::CompareOp compareOp);
190 void SetDepthTestEnable(bool depthTestEnable);
191 void SetDepthWriteEnable(bool depthWriteEnable);
195 * @brief Clear current state
201 std::unique_ptr<Impl> mImpl;
204 } // namespace Dali::Graphics
205 #endif //DALI_GRAPHICS_GLES_CONTEXT_H