#define DALI_GRAPHICS_COMMAND_BUFFER_H
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// INTERNAL INCLUDES
#include "graphics-types.h"
-namespace Dali
-{
-namespace Graphics
+namespace Dali::Graphics
{
class Buffer;
class Pipeline;
-class Texture;
-class Sampler;
class RenderTarget;
class RenderPass;
+class Sampler;
+class SyncObject;
+class Texture;
/**
* @brief Uniform buffer bindings.
} color;
struct
{
- float depth;
- uint32_t stencil;
+ float depth; // glClearDepthf
+ uint32_t stencil; // glClearStencil
} depthStencil;
};
};
+// Native rendering (using native APIs)
+
+enum class DrawNativeAPI
+{
+ GLES,
+ UNDEFINED
+};
+
+struct DrawNativeInfo
+{
+ DrawNativeAPI api; ///< API used by the callback
+ Dali::CallbackBase* callback; ///< Callback pointer
+
+ /**
+ * The call allows binding the resource so they can be passed into the callback
+ * Each resource will pass API specific data (for example GL texture and buffer ids)
+ */
+ Graphics::Texture** textureList; ///< Textures to be used by the call
+ uint32_t textureCount; ///< Number of texture used by the callback
+ Graphics::Buffer** bufferList; ///< Buffers to be used by the call
+ uint32_t bufferCount; ///< Number of buffers used by the callback
+
+ /**
+ * The GLES api specific structure that stores pointers to objects to be filled when requested
+ * by caller. The structure cointains void* to avoid creating any complex constructors and keep
+ * the class trivial.
+ */
+ struct GLESNativeInfo
+ {
+ void* eglSharedContextStoragePointer; ///< Indicates the storage object to pass the shared context, must be null if not in use
+ } glesNativeInfo;
+
+ void* userData; ///< Data passed into the callback (unspecified type, callback should decode it)
+ void* reserved; ///< Reserved for internal use
+};
+
/**
* @brief CommandBuffer contains a stream of commands to be executed
* by the controller.
* @param[in] buffers List of buffers to bind
* @param[in] offsets List of offsets for each buffer
*/
- virtual void BindVertexBuffers(uint32_t firstBinding,
- std::vector<const Buffer*> buffers,
- std::vector<uint32_t> offsets) = 0;
+ virtual void BindVertexBuffers(uint32_t firstBinding,
+ const std::vector<const Buffer*>& buffers,
+ const std::vector<uint32_t>& offsets) = 0;
/**
* @brief Binds uniform buffers
*
* @param[in] textureBindings List of texture bindings
*/
- virtual void BindTextures(std::vector<TextureBinding>& textureBindings) = 0;
+ virtual void BindTextures(const std::vector<TextureBinding>& textureBindings) = 0;
/**
* @brief Binds samplers
*
* @param[in] samplerBindings List of sampler bindings
*/
- virtual void BindSamplers(std::vector<SamplerBinding>& samplerBindings) = 0;
+ virtual void BindSamplers(const std::vector<SamplerBinding>& samplerBindings) = 0;
/**
* @brief Binds buffer containing push constants
* Calling EndRenderPass() is necessary to finalize the render pass.
*
* @param[in] renderPass valid render pass object
- * @param[in] renderTarget valid render target
- * @param[in] renderArea area to draw
+ * @param[in] renderTarget valid render target, must not be used when framebuffer set
+ * @param[in] renderArea area to draw (clear operation is affected)
* @param[in] clearValues clear values (compatible with renderpass spec)
*/
virtual void BeginRenderPass(
- RenderPass& renderPass,
- RenderTarget& renderTarget,
- Extent2D renderArea,
- std::vector<ClearValue> clearValues) = 0;
+ RenderPass* renderPass,
+ RenderTarget* renderTarget,
+ Rect2D renderArea,
+ const std::vector<ClearValue>& clearValues) = 0;
/**
* @brief Ends current render pass
* the Controller may use end RP marker in order to resolve resource
* dependencies (for example, to know when target texture is ready
* before passing it to another render pass).
+ *
+ * The caller may query the sync object to determine when this render
+ * pass has actually finished on the GPU.
+ *
+ * @param[in] syncObject If non-null, this object will ensure an
+ * appropriate fence sync object is created after the render pass is
+ * executed.
+ */
+ virtual void EndRenderPass(Graphics::SyncObject* syncObject) = 0;
+
+ /**
+ * @brief Executes a list of secondary command buffers
+ *
+ * The secondary command buffers will be executed as a part of a primary
+ * command buffer that calls this function.
+ *
+ * @param[in] commandBuffers List of buffers to execute
*/
- virtual void EndRenderPass() = 0;
+ virtual void ExecuteCommandBuffers(std::vector<const CommandBuffer*>&& commandBuffers) = 0;
/**
* @brief Draw primitives
uint32_t stride) = 0;
/**
+ * @brief Draws using native API (via callback)
+ *
+ * DrawNative should be use in order to acquire direct access to the
+ * graphics API like GL. Upon command execution, the backend will
+ * invoke given callback and pass API-specific arguments (for example,
+ * the GL callback will receive EGL context used for rendering).
+ *
+ * The client side must make sure the callback is valid for the
+ * time of execution.
+ *
+ * @param[in] drawInfo NativeDrawInfo structure
+ */
+ virtual void DrawNative(const DrawNativeInfo* drawInfo) = 0;
+
+ /**
* @brief Resets CommandBuffer
*
* This function resets the command buffer and discards all previously
/**
* @brief Changes scissor rect
*
- * @param[in] value 2D scissor area
+ * @param[in] value 2D scissor rectangle
*/
- virtual void SetScissor(Extent2D value) = 0;
+ virtual void SetScissor(Rect2D value) = 0;
/**
* @brief Enables/disables scissor test
*/
virtual void SetViewportEnable(bool value) = 0;
+ /**
+ * @brief Sets the color mask for all channels.
+ */
+ virtual void SetColorMask(bool enabled) = 0;
+
+ /**
+ * @brief Clears the stencil buffer (outside of BeginRenderPass) to the current stencil mask
+ */
+ virtual void ClearStencilBuffer() = 0;
+
+ /**
+ * @brief Clears the depth buffer (outside of BeginRenderPass) to the current depth mask
+ */
+ virtual void ClearDepthBuffer() = 0;
+
+ /**
+ * @brief Enable or disable the stencil test
+ *
+ * @param[in] stencilEnable whether stencil test should be enabled
+ */
+ virtual void SetStencilTestEnable(bool stencilEnable) = 0;
+
+ /**
+ * @brief The mask used for writing to the stencil buffer.
+ *
+ * It should be as wide as necessary for the stencil texture format.
+ * @param[in] writeMask The mask for wriing to / clearing the stencil buffer
+ */
+ virtual void SetStencilWriteMask(uint32_t writeMask) = 0;
+
+ /**
+ * @brief Setup the stencil function
+ *
+ * @param[in] compareOp How the stencil buffer, reference and compareMask are combined to determine whether to draw a pixel or not.
+ * @param[in] reference A reference value that is ANDed with the mask in the compare op.
+ * @param[in] compareMask The bitplanes from the stencil buffer that are active.
+ */
+ virtual void SetStencilFunc(Graphics::CompareOp compareOp,
+ uint32_t reference,
+ uint32_t compareMask) = 0;
+
+ /**
+ * @brief Set how subsequent draws will affect the stencil buffer.
+ * @param[in] failOp What happens to stencil buffer if drawing a pixel fails the stencil test
+ * @param[in] passOp What happens to stencil buffer if drawing a pixel passes stencil & depth test
+ * @param[in] depthFailOp What happens to stencil buffer if drawing a pixel passes stencil but fails depth test.
+ */
+ virtual void SetStencilOp(Graphics::StencilOp failOp,
+ Graphics::StencilOp passOp,
+ Graphics::StencilOp depthFailOp) = 0;
+
+ /**
+ * @brief Defines the comparison operator for passing the depth test.
+ *
+ * @param[in] compareOp The comparison operator
+ */
+ virtual void SetDepthCompareOp(Graphics::CompareOp compareOp) = 0;
+
+ /**
+ * @brief Enables depth testing
+ *
+ * @param[in] depthTestEnable True if depth testing will be enabled.
+ */
+ virtual void SetDepthTestEnable(bool depthTestEnable) = 0;
+
+ /**
+ * @brief Enables depth writing / clearing
+ *
+ * @param[in] depthWriteEnabled True if the depth buffer can be updated or cleared.
+ */
+ virtual void SetDepthWriteEnable(bool depthWriteEnable) = 0;
+
protected:
CommandBuffer(CommandBuffer&&) = default;
CommandBuffer& operator=(CommandBuffer&&) = default;
};
-} // Namespace Graphics
-} // Namespace Dali
+} // namespace Dali::Graphics
-#endif
\ No newline at end of file
+#endif