DirectRendering:
[platform/core/uifw/dali-core.git] / dali / graphics-api / graphics-command-buffer.h
index 0b81870..61dd8df 100644 (file)
@@ -2,7 +2,7 @@
 #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.
@@ -83,12 +82,28 @@ struct ClearValue
     } 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
+  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.
@@ -112,9 +127,9 @@ public:
    * @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
@@ -135,14 +150,14 @@ public:
    *
    * @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
@@ -179,15 +194,15 @@ public:
    * 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
@@ -197,8 +212,25 @@ public:
    * 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() = 0;
+  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 ExecuteCommandBuffers(std::vector<const CommandBuffer*>&& commandBuffers) = 0;
 
   /**
    * @brief Draw primitives
@@ -250,6 +282,21 @@ public:
     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
@@ -292,11 +339,82 @@ public:
    */
   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