1 #ifndef DALI_GRAPHICS_GLES_COMMAND_BUFFER_H
2 #define DALI_GRAPHICS_GLES_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 <dali/graphics-api/graphics-command-buffer.h>
25 #include "egl-graphics-controller.h"
38 enum class CommandType
48 * Command structure allocates memory to store a single command
61 * @brief Copy constructor
62 * @param[in] rhs Command
64 Command(const Command& rhs)
68 case CommandType::BIND_VERTEX_BUFFERS:
70 bindVertexBuffers = rhs.bindVertexBuffers;
73 case CommandType::BIND_INDEX_BUFFER:
75 bindIndexBuffer = rhs.bindIndexBuffer;
78 case CommandType::BIND_SAMPLERS:
80 bindSamplers = rhs.bindSamplers;
83 case CommandType::BIND_TEXTURES:
85 bindTextures = rhs.bindTextures;
88 case CommandType::FLUSH:
98 * @brief Copy constructor
99 * @param[in] rhs Command
101 Command(Command&& rhs) noexcept
105 case CommandType::BIND_VERTEX_BUFFERS:
107 bindVertexBuffers = std::move(rhs.bindVertexBuffers);
110 case CommandType::BIND_INDEX_BUFFER:
112 bindIndexBuffer = rhs.bindIndexBuffer;
115 case CommandType::BIND_SAMPLERS:
117 bindSamplers = std::move(rhs.bindSamplers);
120 case CommandType::BIND_TEXTURES:
122 bindTextures = std::move(rhs.bindTextures);
125 case CommandType::FLUSH:
134 CommandType type{CommandType::FLUSH};
140 std::vector<Graphics::TextureBinding> textureBindings;
143 // BindSampler command
146 std::vector<Graphics::SamplerBinding> samplerBindings;
153 const Graphics::Buffer* buffer{nullptr};
156 std::vector<Binding> vertexBufferBindings;
161 const Graphics::Buffer* buffer{nullptr};
163 Graphics::Format format{};
168 using CommandBufferResource = Resource<Graphics::CommandBuffer, Graphics::CommandBufferCreateInfo>;
170 class CommandBuffer : public CommandBufferResource
173 CommandBuffer(const Graphics::CommandBufferCreateInfo& createInfo, EglGraphicsController& controller)
174 : CommandBufferResource(createInfo, controller)
178 void BindVertexBuffers(uint32_t firstBinding,
179 std::vector<const Graphics::Buffer*> buffers,
180 std::vector<uint32_t> offsets) override
182 mCommands.emplace_back();
183 mCommands.back().type = CommandType::BIND_VERTEX_BUFFERS;
184 auto& bindings = mCommands.back().bindVertexBuffers.vertexBufferBindings;
185 if(bindings.size() < firstBinding + buffers.size())
187 bindings.resize(firstBinding + buffers.size());
188 auto index = firstBinding;
189 for(auto& buf : buffers)
191 bindings[index].buffer = buf;
192 bindings[index].offset = offsets[index - firstBinding];
198 void BindUniformBuffers(const std::vector<Graphics::UniformBufferBinding>& bindings) override
202 void BindPipeline(const Graphics::Pipeline& pipeline) override
206 void BindTextures(std::vector<TextureBinding>& textureBindings) override
208 mCommands.emplace_back();
209 mCommands.back().type = CommandType::BIND_TEXTURES;
210 mCommands.back().bindTextures.textureBindings = std::move(textureBindings);
213 void BindSamplers(std::vector<SamplerBinding>& samplerBindings) override
215 mCommands.emplace_back();
216 mCommands.back().bindSamplers.samplerBindings = std::move(samplerBindings);
219 void BindPushConstants(void* data,
221 uint32_t binding) override
225 void BindIndexBuffer(const Graphics::Buffer& buffer,
227 Format format) override
229 mCommands.emplace_back();
230 mCommands.back().type = CommandType::BIND_INDEX_BUFFER;
231 mCommands.back().bindIndexBuffer.buffer = &buffer;
232 mCommands.back().bindIndexBuffer.offset = offset;
233 mCommands.back().bindIndexBuffer.format = format;
236 void BeginRenderPass(
237 Graphics::RenderPass& renderPass,
238 Graphics::RenderTarget& renderTarget,
240 std::vector<ClearValue> clearValues) override
245 * @brief Ends current render pass
247 * This command must be issued in order to finalize the render pass.
248 * It's up to the implementation whether anything has to be done but
249 * the Controller may use end RP marker in order to resolve resource
250 * dependencies (for example, to know when target texture is ready
251 * before passing it to another render pass).
253 void EndRenderPass() override
258 uint32_t vertexCount,
259 uint32_t instanceCount,
260 uint32_t firstVertex,
261 uint32_t firstInstance) override
267 uint32_t instanceCount,
269 int32_t vertexOffset,
270 uint32_t firstInstance) override
274 void DrawIndexedIndirect(
275 Graphics::Buffer& buffer,
278 uint32_t stride) override
282 void Reset(Graphics::CommandBuffer& commandBuffer) override
287 void SetScissor(Extent2D value) override
291 void SetScissorTestEnable(bool value) override
295 void SetViewport(Viewport value) override
299 void SetViewportEnable(bool value) override
303 [[nodiscard]] const std::vector<Command>& GetCommands() const
308 void DestroyResource() override
313 bool InitializeResource() override
319 void DiscardResource() override
325 std::vector<Command> mCommands;
328 } // Namespace Graphics