Merge branch 'devel/master' into devel/graphics
[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-graphics-types.h"
23
24 namespace Dali::Graphics
25 {
26 class EglGraphicsController;
27 namespace GLES
28 {
29 class Pipeline;
30 class RenderPass;
31 class RenderTarget;
32 /**
33  * @brief Context represents single GLES context
34  */
35 class Context
36 {
37 public:
38   explicit Context(EglGraphicsController& controller);
39
40   ~Context();
41
42   /**
43    * @brief Flushes the context
44    *
45    * Flushes the context by issuing GL calls to set the required
46    * state.
47    *
48    * @param[in] reset If true then state is reset unconditionally
49    */
50   void Flush(bool reset, const GLES::DrawCallDescriptor& drawCall);
51
52   /**
53    * @brief Returns context Id
54    * @return
55    */
56   uint32_t GetContextId() const
57   {
58     return 0;
59   }
60
61   /**
62    * @brief Binds textures to the context
63    *
64    * Bindings are merged, they are resolved at later time
65    * when the draw call is issued. Then the texture binding
66    * slots (GL active texture binding) are enabled/disabled accordingly
67    * to the uniform layout.
68    *
69    * @param[in] bindings List of bindings
70    *
71    */
72   void BindTextures(const std::vector<Graphics::TextureBinding>& bindings);
73
74   /**
75    * @brief Vertex buffers to bind
76    *
77    * The bindings are taken from a command buffer being
78    * currently processed and copied into the local storage.
79    */
80
81   void BindVertexBuffers(const std::vector<GLES::VertexBufferBindingDescriptor>& bindings);
82
83   /**
84    * @brief Binds index buffer
85    *
86    * @param indexBufferBinding
87    */
88   void BindIndexBuffer(const IndexBufferBindingDescriptor& indexBufferBinding);
89
90   /**
91    * @brief Binds pipeline to the context
92    * @param newPipeline
93    */
94   void BindPipeline(const GLES::Pipeline* newPipeline);
95
96   /**
97    * @brief Binds uniform buffers to the context
98    *
99    * @param[in] uboBindings real UBO binfins
100    * @param[in] standaloneBindings emulated (legacy) UBO object
101    */
102   void BindUniformBuffers(const std::vector<UniformBufferBindingDescriptor>& uboBindings, const UniformBufferBindingDescriptor& standaloneBindings);
103
104   /**
105    * @brief Resolves blend state on the currently attached pipeline
106    */
107   void ResolveBlendState();
108
109   /**
110    * @brief Resolves rasterization state on the currently attached pipeline
111    */
112   void ResolveRasterizationState();
113
114   /**
115    * @brief Resolves uniform buffers and binds data to the pipeline
116    */
117   void ResolveUniformBuffers();
118
119   /**
120    * @brief Special usecase for legacy shaders, called by ResolveUniformBuffers()
121    */
122   void ResolveStandaloneUniforms();
123
124   /**
125    * @brief Begins render pass for sepcified render target
126    *
127    * @param[in] renderPass render pass object to begin
128    * @param[in] renderTarget render target to be drawn onto
129    */
130   void BeginRenderPass(const BeginRenderPassDescriptor& renderPassBegin);
131
132   /**
133    * @brief Ends render pass
134    *
135    * Ending render pass is necessary in order to ensure
136    * proper implicit synchronization is in place
137    */
138   void EndRenderPass();
139
140   void ColorMask(bool enabled);
141   void ClearStencilBuffer();
142   void ClearDepthBuffer();
143   void SetStencilTestEnable(bool stencilEnable);
144   void StencilMask(uint32_t writeMask);
145   void StencilFunc(Graphics::CompareOp compareOp,
146                    uint32_t            reference,
147                    uint32_t            compareMask);
148   void StencilOp(Graphics::StencilOp failOp,
149                  Graphics::StencilOp depthFailOp,
150                  Graphics::StencilOp passOp);
151   void SetDepthCompareOp(Graphics::CompareOp compareOp);
152   void SetDepthTestEnable(bool depthTestEnable);
153   void SetDepthWriteEnable(bool depthWriteEnable);
154
155 private:
156   /**
157    * @brief Clear current state
158    */
159   void ClearState();
160
161 private:
162   struct Impl;
163   std::unique_ptr<Impl> mImpl;
164 };
165 } // namespace GLES
166 } // namespace Dali::Graphics
167 #endif //DALI_GRAPHICS_GLES_CONTEXT_H