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.
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] framebuffer valid framebuffer, must not be used with renderTarget
182 * @param[in] renderArea area to draw
183 * @param[in] clearValues clear values (compatible with renderpass spec)
185 virtual void BeginRenderPass(
186 RenderPass* renderPass,
187 RenderTarget* renderTarget,
189 std::vector<ClearValue> clearValues) = 0;
192 * @brief Ends current render pass
194 * This command must be issued in order to finalize the render pass.
195 * It's up to the implementation whether anything has to be done but
196 * the Controller may use end RP marker in order to resolve resource
197 * dependencies (for example, to know when target texture is ready
198 * before passing it to another render pass).
200 virtual void EndRenderPass() = 0;
203 * @brief Executes a list of secondary command buffers
205 * @param[in] commandBuffers List of buffers to execute
207 virtual void ExecuteCommandBuffers( std::vector<CommandBuffer*>&& commandBuffers ) = 0;
210 * @brief Draw primitives
212 * @param[in] vertexCount number of vertices
213 * @param[in] instanceCount number of instances
214 * @param[in] firstVertex index of first vertex
215 * @param[in] firstInstance index of first instance
218 uint32_t vertexCount,
219 uint32_t instanceCount,
220 uint32_t firstVertex,
221 uint32_t firstInstance) = 0;
224 * @brief Draws indexed primitives
226 * @param[in] indexCount Number of indices
227 * @param[in] instanceCount Number of instances
228 * @param[in] firstIndex first index
229 * @param[in] vertexOffset offset of first vertex
230 * @param[in] firstInstance first instance
232 virtual void DrawIndexed(
234 uint32_t instanceCount,
236 int32_t vertexOffset,
237 uint32_t firstInstance) = 0;
240 * @brief Draws indexed primitives indirectly
242 * Indirect draw uses additional buffer that holds render data.
244 * Indirect draw support depends on the hardware (most of modern hardware
245 * supports this drawing technique).
247 * @param[in] buffer Buffer containing draw parameters
248 * @param[in] offset Offset in bytes where parameters begin
249 * @param[in] drawCount number of draws to execute
250 * @param[in] stride stride between draw parameters
252 virtual void DrawIndexedIndirect(
256 uint32_t stride) = 0;
259 * @brief Resets CommandBuffer
261 * This function resets the command buffer and discards all previously
264 * Since the allocation may use internal memory pool of the CommandBuffer,
265 * resetting doesn't have to discard all the resources (for example, it doesn't
266 * need to destroy command but only move the pointer to the beginning of
267 * the command buffer).
269 * It is useful if the command buffer has to be re-recorded frequently, for example,
272 virtual void Reset() = 0;
275 * @brief Changes scissor rect
277 * @param[in] value 2D scissor rectangle
279 virtual void SetScissor(Rect2D value) = 0;
282 * @brief Enables/disables scissor test
284 * @param[in] value State of scissor test
286 virtual void SetScissorTestEnable(bool value) = 0;
289 * @brief Sets viewport
291 * @param[in] value 2D viewport area
293 virtual void SetViewport(Viewport value) = 0;
296 * @brief Sets whether the viewport should be changed
297 * @param[in] value state of viewport
299 virtual void SetViewportEnable(bool value) = 0;
302 CommandBuffer(CommandBuffer&&) = default;
303 CommandBuffer& operator=(CommandBuffer&&) = default;