1 #ifndef DALI_GRAPHICS_COMMAND_BUFFER_H
2 #define DALI_GRAPHICS_COMMAND_BUFFER_H
5 * Copyright (c) 2022 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.
22 #include "graphics-types.h"
24 namespace Dali::Graphics
35 * @brief Uniform buffer bindings.
37 struct UniformBufferBinding
39 Buffer* buffer; // Buffer
42 void* offsetPtr; // pointer to the client-side memory
43 uint32_t offset; // Offset within buffer
45 uint32_t dataSize; // Size of data to bind
46 uint32_t binding; // Binding index
50 * @brief Texture bindings
52 * Additionally, sampler may be used in case of having combined
58 const Texture* texture; // texture to be bound
59 const Sampler* sampler; // sampler to be bound
60 uint32_t binding; // binding index
64 * @brief Sampler binding
68 Sampler* sampler; // sampler to be bound
69 uint32_t binding; // binding index
73 * @brief ClearValue contains an union of RGBA and depthStencil values.
85 float depth; // glClearDepthf
86 uint32_t stencil; // glClearStencil
91 // Native rendering (using native APIs)
93 enum class DrawNativeAPI
101 DrawNativeAPI api; ///< API used by the callback
102 Dali::CallbackBase* callback; ///< Callback pointer
105 * The call allows binding the resource so they can be passed into the callback
106 * Each resource will pass API specific data (for example GL texture and buffer ids)
108 Graphics::Texture** textureList; ///< Textures to be used by the call
109 uint32_t textureCount; ///< Number of texture used by the callback
110 Graphics::Buffer** bufferList; ///< Buffers to be used by the call
111 uint32_t bufferCount; ///< Number of buffers used by the callback
114 * The GLES api specific structure that stores pointers to objects to be filled when requested
115 * by caller. The structure cointains void* to avoid creating any complex constructors and keep
118 struct GLESNativeInfo
120 void* eglSharedContextStoragePointer; ///< Indicates the storage object to pass the shared context, must be null if not in use
123 void* userData; ///< Data passed into the callback (unspecified type, callback should decode it)
124 void* reserved; ///< Reserved for internal use
128 * @brief CommandBuffer contains a stream of commands to be executed
134 CommandBuffer() = default;
135 virtual ~CommandBuffer() = default;
138 CommandBuffer(const CommandBuffer&) = delete;
139 CommandBuffer& operator=(const CommandBuffer&) = delete;
142 * @brief Binds vertex buffers
144 * The buffers and offsets arrays must be same length
146 * @param[in] firstBinding First binding index
147 * @param[in] buffers List of buffers to bind
148 * @param[in] offsets List of offsets for each buffer
150 virtual void BindVertexBuffers(uint32_t firstBinding,
151 const std::vector<const Buffer*>& buffers,
152 const std::vector<uint32_t>& offsets) = 0;
155 * @brief Binds uniform buffers
157 * @param[in] bindings List of uniform buffer bindings
159 virtual void BindUniformBuffers(const std::vector<UniformBufferBinding>& bindings) = 0;
162 * @brief Binds pipeline
164 * @param[in] pipeline valid pipeline
166 virtual void BindPipeline(const Pipeline& pipeline) = 0;
169 * @brief Binds textures
171 * @param[in] textureBindings List of texture bindings
173 virtual void BindTextures(const std::vector<TextureBinding>& textureBindings) = 0;
176 * @brief Binds samplers
178 * @param[in] samplerBindings List of sampler bindings
180 virtual void BindSamplers(const std::vector<SamplerBinding>& samplerBindings) = 0;
183 * @brief Binds buffer containing push constants
185 * @param[in] data pointer to the buffer
186 * @param[in] size size of data in bytes
187 * @param[in] binding push constants binding index
189 virtual void BindPushConstants(void* data,
191 uint32_t binding) = 0;
194 * @brief Binds index buffer
196 * Most commonly used formats:
200 * @param[in] buffer Valid buffer
201 * @param[in] offset offset within buffer
202 * @param[in] format Format of index buffer
204 virtual void BindIndexBuffer(const Buffer& buffer,
208 * @brief Begins render pass
210 * The function initialises rendering for specified RenderPass object
211 * onto renderTarget. renderArea defines the scissor rect. Depends on the
212 * renderPass spec, the clearValues may be used.
214 * Calling EndRenderPass() is necessary to finalize the render pass.
216 * @param[in] renderPass valid render pass object
217 * @param[in] renderTarget valid render target, must not be used when framebuffer set
218 * @param[in] renderArea area to draw (clear operation is affected)
219 * @param[in] clearValues clear values (compatible with renderpass spec)
221 virtual void BeginRenderPass(
222 RenderPass* renderPass,
223 RenderTarget* renderTarget,
225 const std::vector<ClearValue>& clearValues) = 0;
228 * @brief Ends current render pass
230 * This command must be issued in order to finalize the render pass.
231 * It's up to the implementation whether anything has to be done but
232 * the Controller may use end RP marker in order to resolve resource
233 * dependencies (for example, to know when target texture is ready
234 * before passing it to another render pass).
236 * The caller may query the sync object to determine when this render
237 * pass has actually finished on the GPU.
239 * @param[in] syncObject If non-null, this object will ensure an
240 * appropriate fence sync object is created after the render pass is
243 virtual void EndRenderPass(Graphics::SyncObject* syncObject) = 0;
246 * @brief Executes a list of secondary command buffers
248 * The secondary command buffers will be executed as a part of a primary
249 * command buffer that calls this function.
251 * @param[in] commandBuffers List of buffers to execute
253 virtual void ExecuteCommandBuffers(std::vector<const CommandBuffer*>&& commandBuffers) = 0;
256 * @brief Draw primitives
258 * @param[in] vertexCount number of vertices
259 * @param[in] instanceCount number of instances
260 * @param[in] firstVertex index of first vertex
261 * @param[in] firstInstance index of first instance
264 uint32_t vertexCount,
265 uint32_t instanceCount,
266 uint32_t firstVertex,
267 uint32_t firstInstance) = 0;
270 * @brief Draws indexed primitives
272 * @param[in] indexCount Number of indices
273 * @param[in] instanceCount Number of instances
274 * @param[in] firstIndex first index
275 * @param[in] vertexOffset offset of first vertex
276 * @param[in] firstInstance first instance
278 virtual void DrawIndexed(
280 uint32_t instanceCount,
282 int32_t vertexOffset,
283 uint32_t firstInstance) = 0;
286 * @brief Draws indexed primitives indirectly
288 * Indirect draw uses additional buffer that holds render data.
290 * Indirect draw support depends on the hardware (most of modern hardware
291 * supports this drawing technique).
293 * @param[in] buffer Buffer containing draw parameters
294 * @param[in] offset Offset in bytes where parameters begin
295 * @param[in] drawCount number of draws to execute
296 * @param[in] stride stride between draw parameters
298 virtual void DrawIndexedIndirect(
302 uint32_t stride) = 0;
305 * @brief Draws using native API (via callback)
307 * DrawNative should be use in order to acquire direct access to the
308 * graphics API like GL. Upon command execution, the backend will
309 * invoke given callback and pass API-specific arguments (for example,
310 * the GL callback will receive EGL context used for rendering).
312 * The client side must make sure the callback is valid for the
315 * @param[in] drawInfo NativeDrawInfo structure
317 virtual void DrawNative(const DrawNativeInfo* drawInfo) = 0;
320 * @brief Resets CommandBuffer
322 * This function resets the command buffer and discards all previously
325 * Since the allocation may use internal memory pool of the CommandBuffer,
326 * resetting doesn't have to discard all the resources (for example, it doesn't
327 * need to destroy command but only move the pointer to the beginning of
328 * the command buffer).
330 * It is useful if the command buffer has to be re-recorded frequently, for example,
333 virtual void Reset() = 0;
336 * @brief Changes scissor rect
338 * @param[in] value 2D scissor rectangle
340 virtual void SetScissor(Rect2D value) = 0;
343 * @brief Enables/disables scissor test
345 * @param[in] value State of scissor test
347 virtual void SetScissorTestEnable(bool value) = 0;
350 * @brief Sets viewport
352 * @param[in] value 2D viewport area
354 virtual void SetViewport(Viewport value) = 0;
357 * @brief Sets whether the viewport should be changed
358 * @param[in] value state of viewport
360 virtual void SetViewportEnable(bool value) = 0;
363 * @brief Sets the color mask for all channels.
365 virtual void SetColorMask(bool enabled) = 0;
368 * @brief Clears the stencil buffer (outside of BeginRenderPass) to the current stencil mask
370 virtual void ClearStencilBuffer() = 0;
373 * @brief Clears the depth buffer (outside of BeginRenderPass) to the current depth mask
375 virtual void ClearDepthBuffer() = 0;
378 * @brief Enable or disable the stencil test
380 * @param[in] stencilEnable whether stencil test should be enabled
382 virtual void SetStencilTestEnable(bool stencilEnable) = 0;
385 * @brief The mask used for writing to the stencil buffer.
387 * It should be as wide as necessary for the stencil texture format.
388 * @param[in] writeMask The mask for wriing to / clearing the stencil buffer
390 virtual void SetStencilWriteMask(uint32_t writeMask) = 0;
393 * @brief Setup the stencil function
395 * @param[in] compareOp How the stencil buffer, reference and compareMask are combined to determine whether to draw a pixel or not.
396 * @param[in] reference A reference value that is ANDed with the mask in the compare op.
397 * @param[in] compareMask The bitplanes from the stencil buffer that are active.
399 virtual void SetStencilFunc(Graphics::CompareOp compareOp,
401 uint32_t compareMask) = 0;
404 * @brief Set how subsequent draws will affect the stencil buffer.
405 * @param[in] failOp What happens to stencil buffer if drawing a pixel fails the stencil test
406 * @param[in] passOp What happens to stencil buffer if drawing a pixel passes stencil & depth test
407 * @param[in] depthFailOp What happens to stencil buffer if drawing a pixel passes stencil but fails depth test.
409 virtual void SetStencilOp(Graphics::StencilOp failOp,
410 Graphics::StencilOp passOp,
411 Graphics::StencilOp depthFailOp) = 0;
414 * @brief Defines the comparison operator for passing the depth test.
416 * @param[in] compareOp The comparison operator
418 virtual void SetDepthCompareOp(Graphics::CompareOp compareOp) = 0;
421 * @brief Enables depth testing
423 * @param[in] depthTestEnable True if depth testing will be enabled.
425 virtual void SetDepthTestEnable(bool depthTestEnable) = 0;
428 * @brief Enables depth writing / clearing
430 * @param[in] depthWriteEnabled True if the depth buffer can be updated or cleared.
432 virtual void SetDepthWriteEnable(bool depthWriteEnable) = 0;
435 CommandBuffer(CommandBuffer&&) = default;
436 CommandBuffer& operator=(CommandBuffer&&) = default;
438 } // namespace Dali::Graphics