1 #ifndef DALI_GRAPHICS_COMMAND_BUFFER_H
2 #define DALI_GRAPHICS_COMMAND_BUFFER_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.
22 #include "graphics-types.h"
24 namespace Dali::Graphics
34 * @brief Uniform buffer bindings.
36 struct UniformBufferBinding
38 Buffer* buffer; // Buffer
41 void* offsetPtr; // pointer to the client-side memory
42 uint32_t offset; // Offset within buffer
44 uint32_t dataSize; // Size of data to bind
45 uint32_t binding; // Binding index
49 * @brief Texture bindings
51 * Additionally, sampler may be used in case of having combined
57 const Texture* texture; // texture to be bound
58 const Sampler* sampler; // sampler to be bound
59 uint32_t binding; // binding index
63 * @brief Sampler binding
67 Sampler* sampler; // sampler to be bound
68 uint32_t binding; // binding index
72 * @brief ClearValue contains an union of RGBA and depthStencil values.
84 float depth; // glClearDepthf
85 uint32_t stencil; // glClearStencil
91 * @brief CommandBuffer contains a stream of commands to be executed
97 CommandBuffer() = default;
98 virtual ~CommandBuffer() = default;
101 CommandBuffer(const CommandBuffer&) = delete;
102 CommandBuffer& operator=(const CommandBuffer&) = delete;
105 * @brief Binds vertex buffers
107 * The buffers and offsets arrays must be same length
109 * @param[in] firstBinding First binding index
110 * @param[in] buffers List of buffers to bind
111 * @param[in] offsets List of offsets for each buffer
113 virtual void BindVertexBuffers(uint32_t firstBinding,
114 std::vector<const Buffer*> buffers,
115 std::vector<uint32_t> offsets) = 0;
118 * @brief Binds uniform buffers
120 * @param[in] bindings List of uniform buffer bindings
122 virtual void BindUniformBuffers(const std::vector<UniformBufferBinding>& bindings) = 0;
125 * @brief Binds pipeline
127 * @param[in] pipeline valid pipeline
129 virtual void BindPipeline(const Pipeline& pipeline) = 0;
132 * @brief Binds textures
134 * @param[in] textureBindings List of texture bindings
136 virtual void BindTextures(std::vector<TextureBinding>& textureBindings) = 0;
139 * @brief Binds samplers
141 * @param[in] samplerBindings List of sampler bindings
143 virtual void BindSamplers(std::vector<SamplerBinding>& samplerBindings) = 0;
146 * @brief Binds buffer containing push constants
148 * @param[in] data pointer to the buffer
149 * @param[in] size size of data in bytes
150 * @param[in] binding push constants binding index
152 virtual void BindPushConstants(void* data,
154 uint32_t binding) = 0;
157 * @brief Binds index buffer
159 * Most commonly used formats:
163 * @param[in] buffer Valid buffer
164 * @param[in] offset offset within buffer
165 * @param[in] format Format of index buffer
167 virtual void BindIndexBuffer(const Buffer& buffer,
171 * @brief Begins render pass
173 * The function initialises rendering for specified RenderPass object
174 * onto renderTarget. renderArea defines the scissor rect. Depends on the
175 * renderPass spec, the clearValues may be used.
177 * Calling EndRenderPass() is necessary to finalize the render pass.
179 * @param[in] renderPass valid render pass object
180 * @param[in] renderTarget valid render target, must not be used when framebuffer set
181 * @param[in] renderArea area to draw (clear operation is affected)
182 * @param[in] clearValues clear values (compatible with renderpass spec)
184 virtual void BeginRenderPass(
185 RenderPass* renderPass,
186 RenderTarget* renderTarget,
188 std::vector<ClearValue> clearValues) = 0;
191 * @brief Ends current render pass
193 * This command must be issued in order to finalize the render pass.
194 * It's up to the implementation whether anything has to be done but
195 * the Controller may use end RP marker in order to resolve resource
196 * dependencies (for example, to know when target texture is ready
197 * before passing it to another render pass).
199 virtual void EndRenderPass() = 0;
202 * @brief Executes a list of secondary command buffers
204 * The secondary command buffers will be executed as a part of a primary
205 * command buffer that calls this function.
207 * @param[in] commandBuffers List of buffers to execute
209 virtual void ExecuteCommandBuffers(std::vector<const CommandBuffer*>&& commandBuffers) = 0;
212 * @brief Draw primitives
214 * @param[in] vertexCount number of vertices
215 * @param[in] instanceCount number of instances
216 * @param[in] firstVertex index of first vertex
217 * @param[in] firstInstance index of first instance
220 uint32_t vertexCount,
221 uint32_t instanceCount,
222 uint32_t firstVertex,
223 uint32_t firstInstance) = 0;
226 * @brief Draws indexed primitives
228 * @param[in] indexCount Number of indices
229 * @param[in] instanceCount Number of instances
230 * @param[in] firstIndex first index
231 * @param[in] vertexOffset offset of first vertex
232 * @param[in] firstInstance first instance
234 virtual void DrawIndexed(
236 uint32_t instanceCount,
238 int32_t vertexOffset,
239 uint32_t firstInstance) = 0;
242 * @brief Draws indexed primitives indirectly
244 * Indirect draw uses additional buffer that holds render data.
246 * Indirect draw support depends on the hardware (most of modern hardware
247 * supports this drawing technique).
249 * @param[in] buffer Buffer containing draw parameters
250 * @param[in] offset Offset in bytes where parameters begin
251 * @param[in] drawCount number of draws to execute
252 * @param[in] stride stride between draw parameters
254 virtual void DrawIndexedIndirect(
258 uint32_t stride) = 0;
261 * @brief Resets CommandBuffer
263 * This function resets the command buffer and discards all previously
266 * Since the allocation may use internal memory pool of the CommandBuffer,
267 * resetting doesn't have to discard all the resources (for example, it doesn't
268 * need to destroy command but only move the pointer to the beginning of
269 * the command buffer).
271 * It is useful if the command buffer has to be re-recorded frequently, for example,
274 virtual void Reset() = 0;
277 * @brief Changes scissor rect
279 * @param[in] value 2D scissor rectangle
281 virtual void SetScissor(Rect2D value) = 0;
284 * @brief Enables/disables scissor test
286 * @param[in] value State of scissor test
288 virtual void SetScissorTestEnable(bool value) = 0;
291 * @brief Sets viewport
293 * @param[in] value 2D viewport area
295 virtual void SetViewport(Viewport value) = 0;
298 * @brief Sets whether the viewport should be changed
299 * @param[in] value state of viewport
301 virtual void SetViewportEnable(bool value) = 0;
304 * @brief Sets the color mask for all channels.
306 virtual void SetColorMask(bool enabled) = 0;
309 * @brief Clears the stencil buffer (outside of BeginRenderPass) to the current stencil mask
311 virtual void ClearStencilBuffer() = 0;
312 virtual void ClearDepthBuffer() = 0;
314 virtual void SetStencilTestEnable(bool stencilEnable) = 0;
315 virtual void SetStencilWriteMask(uint32_t writeMask) = 0;
316 virtual void SetStencilFunc(Graphics::CompareOp compareOp,
318 uint32_t compareMask) = 0;
320 virtual void SetStencilOp(Graphics::StencilOp failOp,
321 Graphics::StencilOp passOp,
322 Graphics::StencilOp depthFailOp) = 0;
324 virtual void SetDepthCompareOp(Graphics::CompareOp compareOp) = 0;
325 virtual void SetDepthTestEnable(bool depthTestEnable) = 0;
326 virtual void SetDepthWriteEnable(bool depthWriteEnable) = 0;
329 CommandBuffer(CommandBuffer&&) = default;
330 CommandBuffer& operator=(CommandBuffer&&) = default;
332 } // namespace Dali::Graphics