a4c3c8b5fbc901b2aa42fab9f91acad22ec82183
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles-impl / gles-context.h
1 #ifndef DALI_GRAPHICS_GLES_CONTEXT_H
2 #define DALI_GRAPHICS_GLES_CONTEXT_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 #include <dali/graphics-api/graphics-command-buffer.h>
22 #include "gles-context-state-cache.h"
23 #include "gles-graphics-types.h"
24
25 namespace Dali::Graphics
26 {
27 class EglGraphicsController;
28 namespace GLES
29 {
30 class Pipeline;
31 class RenderPass;
32 class RenderTarget;
33 class Texture;
34
35 /**
36  * @brief Context represents single GLES context
37  */
38 class Context
39 {
40 public:
41   explicit Context(EglGraphicsController& controller);
42
43   ~Context();
44
45   /**
46    * @brief Flushes the context
47    *
48    * Flushes the context by issuing GL calls to set the required
49    * state.
50    *
51    * @param[in] reset If true then state is reset unconditionally
52    */
53   void Flush(bool reset, const GLES::DrawCallDescriptor& drawCall);
54
55   /**
56    * @brief Returns context Id
57    * @return
58    */
59   uint32_t GetContextId() const
60   {
61     return 0;
62   }
63
64   /**
65    * @brief Binds textures to the context
66    *
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.
71    *
72    * @param[in] bindings List of bindings
73    *
74    */
75   void BindTextures(const Graphics::TextureBinding* bindings, uint32_t count);
76
77   /**
78    * @brief Vertex buffers to bind
79    *
80    * The bindings are taken from a command buffer being
81    * currently processed and copied into the local storage.
82    */
83
84   void BindVertexBuffers(const GLES::VertexBufferBindingDescriptor* bindings, uint32_t count);
85
86   /**
87    * @brief Binds index buffer
88    *
89    * @param indexBufferBinding
90    */
91   void BindIndexBuffer(const IndexBufferBindingDescriptor& indexBufferBinding);
92
93   /**
94    * @brief Binds pipeline to the context
95    * @param newPipeline
96    */
97   void BindPipeline(const GLES::Pipeline* newPipeline);
98
99   /**
100    * @brief Binds uniform buffers to the context
101    *
102    * @param[in] uboBindings real UBO binfins
103    * @param[in] standaloneBindings emulated (legacy) UBO object
104    */
105   void BindUniformBuffers(const UniformBufferBindingDescriptor* uboBindings, uint32_t uboCount, const UniformBufferBindingDescriptor& standaloneBindings);
106
107   /**
108    * @brief Resolves blend state on the currently attached pipeline
109    */
110   void ResolveBlendState();
111
112   /**
113    * @brief Resolves rasterization state on the currently attached pipeline
114    */
115   void ResolveRasterizationState();
116
117   /**
118    * @brief Resolves uniform buffers and binds data to the pipeline
119    */
120   void ResolveUniformBuffers();
121
122   /**
123    * @brief Special usecase for legacy shaders, called by ResolveUniformBuffers()
124    */
125   void ResolveStandaloneUniforms();
126
127   /**
128    * @brief Begins render pass for sepcified render target
129    *
130    * @param[in] renderPass render pass object to begin
131    * @param[in] renderTarget render target to be drawn onto
132    */
133   void BeginRenderPass(const BeginRenderPassDescriptor& renderPassBegin);
134
135   /**
136    * @brief Ends render pass
137    *
138    * Ending render pass is necessary in order to ensure
139    * proper implicit synchronization is in place
140    */
141   void EndRenderPass();
142
143   /**
144    * @brief Returns the cache of GL state in the context
145    * @return the reference of GL state cache (which can be modified)
146    */
147   GLStateCache& GetGLStateCache();
148
149   /**
150    * @brief Called when the GL context has been created.
151    */
152   void GlContextCreated();
153
154   /**
155    * @brief Called when the GL context has been destroyed.
156    */
157   void GlContextDestroyed();
158
159   /**
160    * @brief Invalidates the cached pipeline object in the context if it matches
161    * This is called before the pipeline is deleted
162    *
163    * @param[in] pipeline The pipeline
164    */
165   void InvalidateCachedPipeline(GLES::Pipeline* pipeline);
166
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,
184                    uint32_t            reference,
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);
192
193 private:
194   /**
195    * @brief Clear current state
196    */
197   void ClearState();
198
199 private:
200   struct Impl;
201   std::unique_ptr<Impl> mImpl;
202 };
203 } // namespace GLES
204 } // namespace Dali::Graphics
205 #endif //DALI_GRAPHICS_GLES_CONTEXT_H