Adding source format to texture upload
[platform/core/uifw/dali-core.git] / dali / graphics-api / graphics-types.h
index a1bcccb..31b358e 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 // EXTERNAL INCLUDES
+#include <memory>
 #include <string>
 #include <utility>
 #include <vector>
@@ -27,11 +28,12 @@ namespace Dali
 {
 namespace Graphics
 {
-class CommandBuffer;
-class Texture;
 class Buffer;
-class Shader;
+class CommandBuffer;
 class Framebuffer;
+class Program;
+class Shader;
+class Texture;
 
 /**
  * @brief Structure describes 2D offset
@@ -232,6 +234,7 @@ enum class PrimitiveTopology
 {
   POINT_LIST,
   LINE_LIST,
+  LINE_LOOP,
   LINE_STRIP,
   TRIANGLE_LIST,
   TRIANGLE_STRIP,
@@ -354,7 +357,21 @@ struct ColorBlendState
 };
 
 /**
- * @brief  Framebuffer state
+ * @brief Program State
+ */
+struct ProgramState
+{
+  const Program* program{nullptr};
+
+  auto& SetProgram(const Program& value)
+  {
+    program = &value;
+    return *this;
+  }
+};
+
+/**
+ * @brief  Framebuffer state.
  */
 struct FramebufferState
 {
@@ -855,6 +872,28 @@ inline BufferUsageFlags operator|(BufferUsageFlags flags, BufferUsage usage)
 }
 
 /**
+ * @brief Buffer property bits
+ *
+ * Use these bits to set BufferPropertiesFlags.
+ */
+enum class BufferPropertiesFlagBit : uint32_t
+{
+  CPU_ALLOCATED    = 1 << 0, ///< Buffer is allocated on the CPU side
+  TRANSIENT_MEMORY = 1 << 1, ///< Buffer memory will be short-lived
+};
+
+/**
+ * @brief BufferPropetiesFlags alters behaviour of implementation
+ */
+using BufferPropertiesFlags = uint32_t;
+
+inline BufferPropertiesFlags operator|(BufferPropertiesFlags flags, BufferPropertiesFlagBit usage)
+{
+  flags |= static_cast<uint32_t>(usage);
+  return flags;
+}
+
+/**
  * @brief The structure describes memory requirements of GPU resource (texture, buffer)
  */
 struct MemoryRequirements
@@ -886,6 +925,7 @@ struct TextureUpdateInfo
   Extent2D srcExtent2D{};
   uint32_t srcOffset{};
   uint32_t srcSize{};
+  Format   srcFormat{}; ///< Should match dstTexture's format, otherwise conversion may occur
 };
 
 /**
@@ -963,6 +1003,10 @@ struct ColorAttachment
 struct DepthStencilAttachment
 {
   // TODO:
+  Texture* depthTexture;
+  Texture* stencilTexture;
+  uint32_t depthLevel;
+  uint32_t stencilLevel;
 };
 
 /**
@@ -1037,6 +1081,19 @@ enum class VertexInputAttributeFormat
 };
 
 /**
+ * @brief Uniform class
+ */
+enum class UniformClass
+{
+  SAMPLER,
+  IMAGE,
+  COMBINED_IMAGE_SAMPLER,
+  UNIFORM_BUFFER,
+  UNIFORM,
+  UNDEFINED
+};
+
+/**
  * @brief Type of texture
  */
 enum class TextureType
@@ -1047,6 +1104,41 @@ enum class TextureType
 };
 
 /**
+ * @brief The information of the uniform
+ */
+struct UniformInfo
+{
+  std::string  name{""};
+  UniformClass uniformClass{UniformClass::UNDEFINED};
+  uint32_t     binding{0u};
+  uint32_t     bufferIndex{0u};
+  uint32_t     offset{0u};
+  uint32_t     location{0u};
+
+  bool operator==(const UniformInfo& rhs)
+  {
+    return name == rhs.name &&
+           uniformClass == rhs.uniformClass &&
+           binding == rhs.binding &&
+           bufferIndex == rhs.bufferIndex &&
+           offset == rhs.offset &&
+           location == rhs.location;
+  }
+};
+
+/**
+ * @brief The information of the uniform block
+ */
+struct UniformBlockInfo
+{
+  std::string              name{""};
+  uint32_t                 descriptorSet{0u};
+  uint32_t                 binding{0u};
+  uint32_t                 size{0u};
+  std::vector<UniformInfo> members{};
+};
+
+/**
  * @brief Describes pipeline's shading stages
  *
  * Shader state binds shader and pipeline stage that the
@@ -1201,6 +1293,7 @@ enum class GraphicsStructureType : uint32_t
   BUFFER_CREATE_INFO_STRUCT,
   COMMAND_BUFFER_CREATE_INFO_STRUCT,
   FRAMEBUFFER_CREATE_INFO_STRUCT,
+  PROGRAM_CREATE_INFO_STRUCT,
   PIPELINE_CREATE_INFO_STRUCT,
   RENDERPASS_CREATE_INFO_STRUCT,
   SAMPLER_CREATE_INFO_STRUCT,
@@ -1210,6 +1303,96 @@ enum class GraphicsStructureType : uint32_t
 };
 
 /**
+ * @brief Enum describes load operation associated
+ * with particular framebuffer attachment
+ */
+enum class AttachmentLoadOp
+{
+  LOAD,     ///< Load previous content
+  CLEAR,    ///< Clear the attachment
+  DONT_CARE ///< Let driver decide
+};
+
+/**
+ * @brief Enum describes store operation associated
+ * with particular framebuffer attachment
+ */
+enum class AttachmentStoreOp
+{
+  STORE,    ///< Store content (color attachemnts)
+  DONT_CARE ///< Let driver decide (depth/stencil attachemnt with no intention of reading)
+};
+
+/**
+ * @brief The structure describes the read/write
+ * modes of a single framebuffer attachment
+ *
+ * The attachment description specifies what is going to
+ * happen to the attachment at the beginning and end of the
+ * render pass.
+ *
+ * The stencil operation is separated as it may be set
+ * independent from the depth component (use loadOp, storeOp
+ * to set up the depth component and stencilLoadOp, stencilStoreOp
+ * for stencil component).
+ */
+struct AttachmentDescription
+{
+  /**
+   * @brief Sets load operation for the attachment
+   *
+   * @param value Load operation
+   * @return this structure
+   */
+  auto& SetLoadOp(AttachmentLoadOp value)
+  {
+    loadOp = value;
+    return *this;
+  }
+
+  /**
+   * @brief Sets store operation for the attachment
+   *
+   * @param value Store operation
+   * @return this structure
+   */
+  auto& SetStoreOp(AttachmentStoreOp value)
+  {
+    storeOp = value;
+    return *this;
+  }
+
+  /**
+   * @brief Sets load operation for the stencil part of attachment
+   *
+   * @param value load operation
+   * @return this structure
+   */
+  auto& SetStencilLoadOp(AttachmentLoadOp value)
+  {
+    stencilLoadOp = value;
+    return *this;
+  }
+
+  /**
+   * @brief Sets store operation for the stencil part of attachment
+   *
+   * @param value store operation
+   * @return this structure
+   */
+  auto& SetStencilStoreOp(AttachmentStoreOp value)
+  {
+    stencilStoreOp = value;
+    return *this;
+  }
+
+  AttachmentLoadOp  loadOp{};
+  AttachmentStoreOp storeOp{};
+  AttachmentLoadOp  stencilLoadOp{};
+  AttachmentStoreOp stencilStoreOp{};
+};
+
+/**
  * @brief Helper function to be used by the extension developers
  *
  * The value of custom type must be unique and recognizable by the
@@ -1245,6 +1428,110 @@ struct ExtensionCreateInfo
   ExtensionCreateInfo*  nextExtension{};
 };
 
+/**
+ * @brief Default deleter for graphics unique pointers
+ *
+ * Returned unique_ptr may require custom deleter. To get it working
+ * with std::unique_ptr the custom type is used with polymorphic deleter
+ */
+template<class T>
+struct DefaultDeleter
+{
+  DefaultDeleter() = default;
+
+  /**
+   * @brief Conversion constructor
+   *
+   * This constructor will set the lambda for type passed
+   * as an argument.
+   */
+  template<class P, template<typename> typename U>
+  DefaultDeleter(const U<P>& deleter)
+  {
+    deleteFunction = [](T* object) { U<P>()(static_cast<P*>(object)); };
+  }
+
+  /**
+   * @brief Conversion constructor from DefaultDelete<P>
+   *
+   * This constructor transfers deleteFunction only
+   */
+  template<class P>
+  explicit DefaultDeleter(const DefaultDeleter<P>& deleter)
+  {
+    deleteFunction = decltype(deleteFunction)(deleter.deleteFunction);
+  }
+
+  /**
+   * @brief Default deleter
+   *
+   * Default deleter will use standard 'delete' call in order
+   * to discard graphics objects unless a custom deleter was
+   * used.
+   *
+   * @param[in] object Object to delete
+   */
+  void operator()(T* object)
+  {
+    if(deleteFunction)
+    {
+      deleteFunction(object);
+    }
+    else
+    {
+      delete object;
+    }
+  }
+
+  void (*deleteFunction)(T* object){nullptr}; ///< Custom delete function
+};
+
+/**
+ * Surface type is just a void* to any native object.
+ */
+using Surface = void;
+
+/**
+ * @brief Enum describing preTransform of render target
+ */
+enum class RenderTargetTransformFlagBits
+{
+  TRANSFORM_IDENTITY_BIT           = 0x00000001,
+  ROTATE_90_BIT                    = 0x00000002,
+  ROTATE_180_BIT                   = 0x00000004,
+  ROTATE_270_BIT                   = 0x00000008,
+  HORIZONTAL_MIRROR_BIT            = 0x00000010,
+  HORIZONTAL_MIRROR_ROTATE_90_BIT  = 0x00000020,
+  HORIZONTAL_MIRROR_ROTATE_180_BIT = 0x00000040,
+  HORIZONTAL_MIRROR_ROTATE_270_BIT = 0x00000080,
+};
+
+using RenderTargetTransformFlags = uint32_t;
+
+template<typename T>
+inline RenderTargetTransformFlags operator|(T flags, RenderTargetTransformFlagBits bit)
+{
+  return static_cast<RenderTargetTransformFlags>(flags) | static_cast<RenderTargetTransformFlags>(bit);
+}
+
+/**
+ * unique_ptr defined in the Graphics scope
+ */
+template<class T, class D = DefaultDeleter<T>>
+using UniquePtr = std::unique_ptr<T, D>;
+
+/**
+ * @brief MakeUnique<> version that returns Graphics::UniquePtr
+ * @param[in] args Arguments for construction
+ * @return
+ */
+template<class T, class Deleter = DefaultDeleter<T>, class... Args>
+std::enable_if_t<!std::is_array<T>::value, Graphics::UniquePtr<T>>
+MakeUnique(Args&&... args)
+{
+  return UniquePtr<T>(new T(std::forward<Args>(args)...), Deleter());
+}
+
 } // namespace Graphics
 } // namespace Dali