55816f55860bac2db6a31135f67babdda9c79869
[platform/core/uifw/dali-core.git] / dali / graphics-api / graphics-types.h
1 #ifndef DALI_GRAPHICS_API_TYPES
2 #define DALI_GRAPHICS_API_TYPES
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <memory>
23 #include <string>
24 #include <utility>
25 #include <vector>
26
27 namespace Dali
28 {
29 namespace Graphics
30 {
31 class Buffer;
32 class CommandBuffer;
33 class Framebuffer;
34 class Program;
35 class Shader;
36 class Texture;
37
38 /**
39  * @brief Structure describes 2D offset
40  */
41 struct Offset2D
42 {
43   int32_t x = 0;
44   int32_t y = 0;
45 };
46
47 /**
48  * @brief Structure describes 2D dimensions
49  */
50 struct Extent2D
51 {
52   uint32_t width;
53   uint32_t height;
54 };
55
56 /**
57  * @brief Structure describes 2D rectangle (offset, extent)
58  */
59 struct Rect2D
60 {
61   int32_t  x      = 0;
62   int32_t  y      = 0;
63   uint32_t width  = 0;
64   uint32_t height = 0;
65 };
66
67 /**
68  * @brief Structure represents area of viewport
69  */
70 struct Viewport
71 {
72   float x        = 0.0f;
73   float y        = 0.0f;
74   float width    = 0.0f;
75   float height   = 0.0f;
76   float minDepth = 0.0f;
77   float maxDepth = 0.0f;
78 };
79
80 /**
81  * @brief Describes vertex attribute input rate
82  */
83 enum class VertexInputRate
84 {
85   PER_VERTEX,  ///< Attribute read per vertex
86   PER_INSTANCE ///< Attribute read per instance
87 };
88
89 /**
90  * @brief Vertex input format
91  *
92  * When UNDEFINED, the reflection is used to determine what
93  * the actual format is.
94  */
95 enum class VertexInputFormat
96 {
97   UNDEFINED,
98   FVECTOR2,
99   FVECTOR3,
100   FVECTOR4,
101   IVECTOR2,
102   IVECTOR3,
103   IVECTOR4,
104   FLOAT,
105   INTEGER,
106 };
107
108 /**
109  * @brief Logic operators used by color blending state
110  * when logicOpEnable is set.
111  */
112 enum class LogicOp
113 {
114   CLEAR         = 0,
115   AND           = 1,
116   AND_REVERSE   = 2,
117   COPY          = 3,
118   AND_INVERTED  = 4,
119   NO_OP         = 5,
120   XOR           = 6,
121   OR            = 7,
122   NOR           = 8,
123   EQUIVALENT    = 9,
124   INVERT        = 10,
125   OR_REVERSE    = 11,
126   COPY_INVERTED = 12,
127   OR_INVERTED   = 13,
128   NAND          = 14,
129   SET           = 15,
130 };
131
132 /**
133  * @brief Blend factors
134  */
135 enum class BlendFactor
136 {
137   ZERO                     = 0,
138   ONE                      = 1,
139   SRC_COLOR                = 2,
140   ONE_MINUS_SRC_COLOR      = 3,
141   DST_COLOR                = 4,
142   ONE_MINUS_DST_COLOR      = 5,
143   SRC_ALPHA                = 6,
144   ONE_MINUS_SRC_ALPHA      = 7,
145   DST_ALPHA                = 8,
146   ONE_MINUS_DST_ALPHA      = 9,
147   CONSTANT_COLOR           = 10,
148   ONE_MINUS_CONSTANT_COLOR = 11,
149   CONSTANT_ALPHA           = 12,
150   ONE_MINUS_CONSTANT_ALPHA = 13,
151   SRC_ALPHA_SATURATE       = 14,
152   SRC1_COLOR               = 15,
153   ONE_MINUS_SRC1_COLOR     = 16,
154   SRC1_ALPHA               = 17,
155   ONE_MINUS_SRC1_ALPHA     = 18,
156 };
157
158 /**
159  * @brief Blend operators
160  */
161 enum class BlendOp
162 {
163   ADD              = 0,
164   SUBTRACT         = 1,
165   REVERSE_SUBTRACT = 2,
166   MIN              = 3,
167   MAX              = 4,
168   MULTIPLY         = 5,
169   SCREEN           = 6,
170   OVERLAY          = 7,
171   DARKEN           = 8,
172   LIGHTEN          = 9,
173   COLOR_DODGE      = 10,
174   COLOR_BURN       = 11,
175   HARD_LIGHT       = 12,
176   SOFT_LIGHT       = 13,
177   DIFFERENCE       = 14,
178   EXCLUSION        = 15,
179   HUE              = 16,
180   SATURATION       = 17,
181   COLOR            = 18,
182   LUMINOSITY       = 19,
183 };
184
185 const BlendOp ADVANCED_BLEND_OPTIONS_START(BlendOp::MULTIPLY);
186
187 /**
188  * @brief Compare operators
189  */
190 enum class CompareOp
191 {
192   NEVER,
193   LESS,
194   EQUAL,
195   LESS_OR_EQUAL,
196   GREATER,
197   NOT_EQUAL,
198   GREATER_OR_EQUAL,
199   ALWAYS
200 };
201
202 /**
203  * @brief Stencil operators
204  */
205 enum class StencilOp
206 {
207   KEEP,
208   ZERO,
209   REPLACE,
210   INCREMENT_AND_CLAMP,
211   DECREMENT_AND_CLAMP,
212   INVERT,
213   INCREMENT_AND_WRAP,
214   DECREMENT_AND_WRAP
215 };
216
217 /**
218  * @brief Backface culling modes
219  */
220 enum class CullMode
221 {
222   NONE,
223   FRONT,
224   BACK,
225   FRONT_AND_BACK
226 };
227
228 /**
229  * @brief Polygon drawing modes
230  */
231 enum class PolygonMode
232 {
233   FILL,
234   LINE,
235   POINT
236 };
237
238 /**
239  * @brief Front face direction
240  */
241 enum class FrontFace
242 {
243   COUNTER_CLOCKWISE,
244   CLOCKWISE
245 };
246
247 /**
248  * @brief Primitive geometry topology
249  */
250 enum class PrimitiveTopology
251 {
252   POINT_LIST,
253   LINE_LIST,
254   LINE_LOOP,
255   LINE_STRIP,
256   TRIANGLE_LIST,
257   TRIANGLE_STRIP,
258   TRIANGLE_FAN
259 };
260
261 /**
262  * @brief Sampler address ( wrapping ) mode
263  */
264 enum class SamplerAddressMode
265 {
266   REPEAT,
267   MIRRORED_REPEAT,
268   CLAMP_TO_EDGE,
269   CLAMP_TO_BORDER,
270   MIRROR_CLAMP_TO_EDGE
271 };
272
273 /**
274  * @brief Filtering mode
275  */
276 enum class SamplerFilter
277 {
278   NEAREST,
279   LINEAR
280 };
281
282 /**
283  * @brief Mipmap mode
284  */
285 enum class SamplerMipmapMode
286 {
287   NONE,
288   NEAREST,
289   LINEAR
290 };
291
292 /**
293  * @brief Describes pipeline's color blend state
294  */
295 struct ColorBlendState
296 {
297   bool        logicOpEnable           = false;
298   LogicOp     logicOp                 = {};
299   float       blendConstants[4]       = {0.0f, 0.0f, 0.0f, 0.0f};
300   bool        blendEnable             = false;
301   BlendFactor srcColorBlendFactor     = BlendFactor::ZERO;
302   BlendFactor dstColorBlendFactor     = BlendFactor::ZERO;
303   BlendOp     colorBlendOp            = {};
304   BlendFactor srcAlphaBlendFactor     = BlendFactor::ZERO;
305   BlendFactor dstAlphaBlendFactor     = BlendFactor::ZERO;
306   BlendOp     alphaBlendOp            = {};
307   uint32_t    colorComponentWriteBits = {0u};
308
309   auto& SetLogicOpEnable(bool value)
310   {
311     logicOpEnable = value;
312     return *this;
313   }
314
315   auto& SetLogicOp(LogicOp value)
316   {
317     logicOp = value;
318     return *this;
319   }
320
321   auto& SetBlendConstants(float value[4])
322   {
323     std::copy(value, value + 4, blendConstants);
324     return *this;
325   }
326
327   auto& SetBlendEnable(bool value)
328   {
329     blendEnable = value;
330     return *this;
331   }
332
333   auto& SetSrcColorBlendFactor(BlendFactor value)
334   {
335     srcColorBlendFactor = value;
336     return *this;
337   }
338
339   auto& SetDstColorBlendFactor(BlendFactor value)
340   {
341     dstColorBlendFactor = value;
342     return *this;
343   }
344
345   auto& SetColorBlendOp(BlendOp value)
346   {
347     colorBlendOp = value;
348     return *this;
349   }
350
351   auto& SetSrcAlphaBlendFactor(BlendFactor value)
352   {
353     srcAlphaBlendFactor = value;
354     return *this;
355   }
356
357   auto& SetDstAlphaBlendFactor(BlendFactor value)
358   {
359     dstAlphaBlendFactor = value;
360     return *this;
361   }
362
363   auto& SetAlphaBlendOp(BlendOp value)
364   {
365     alphaBlendOp = value;
366     return *this;
367   }
368
369   auto& SetColorComponentsWriteBits(uint32_t value)
370   {
371     colorComponentWriteBits = value;
372     return *this;
373   }
374 };
375
376 /**
377  * @brief Program State
378  */
379 struct ProgramState
380 {
381   const Program* program{nullptr};
382
383   auto& SetProgram(const Program& value)
384   {
385     program = &value;
386     return *this;
387   }
388 };
389
390 /**
391  * @brief  Framebuffer state.
392  */
393 struct FramebufferState
394 {
395   const Framebuffer* framebuffer{nullptr};
396
397   auto& SetFramebuffer(const Framebuffer& value)
398   {
399     framebuffer = &value;
400     return *this;
401   }
402 };
403
404 /**
405  * @brief Describes pipeline's viewport and scissor state
406  */
407 struct ViewportState
408 {
409   Viewport viewport{0.0, 0.0, 0.0, 0.0};
410   Rect2D   scissor{0, 0, 0, 0};
411   bool     scissorTestEnable{false};
412
413   auto& SetViewport(const Viewport& value)
414   {
415     viewport = value;
416     return *this;
417   }
418
419   auto& SetScissor(const Rect2D& value)
420   {
421     scissor = value;
422     return *this;
423   }
424
425   auto& SetScissorTestEnable(bool value)
426   {
427     scissorTestEnable = value;
428     return *this;
429   }
430 };
431
432 /**
433  * @brief Describes stencil operation state
434  */
435 struct StencilOpState
436 {
437   StencilOp failOp{};
438   StencilOp passOp{};
439   StencilOp depthFailOp{};
440   CompareOp compareOp{};
441   uint32_t  compareMask{0u};
442   uint32_t  writeMask{0u};
443   uint32_t  reference{0u};
444
445   auto& SetFailOp(StencilOp value)
446   {
447     failOp = value;
448     return *this;
449   }
450
451   auto& SetPassOp(StencilOp value)
452   {
453     failOp = value;
454     return *this;
455   }
456
457   auto& SetDepthFailOp(StencilOp value)
458   {
459     failOp = value;
460     return *this;
461   }
462
463   auto& SetCompareOp(CompareOp value)
464   {
465     compareOp = value;
466     return *this;
467   }
468
469   auto& SetCompareMask(uint32_t value)
470   {
471     compareMask = value;
472     return *this;
473   }
474
475   auto& SetWriteMask(uint32_t value)
476   {
477     writeMask = value;
478     return *this;
479   }
480
481   auto& SetReference(uint32_t value)
482   {
483     reference = value;
484     return *this;
485   }
486 };
487
488 /**
489  * @brief Describes pipeline's viewport and scissor state
490  */
491 struct DepthStencilState
492 {
493   bool      depthTestEnable{false};
494   bool      depthWriteEnable{false};
495   CompareOp depthCompareOp{};
496
497   bool           stencilTestEnable{false};
498   StencilOpState front{};
499   StencilOpState back{};
500
501   auto& SetDepthTestEnable(bool value)
502   {
503     depthTestEnable = value;
504     return *this;
505   }
506
507   auto& SetDepthWriteEnable(bool value)
508   {
509     depthWriteEnable = value;
510     return *this;
511   }
512
513   auto& SetDepthCompareOp(CompareOp value)
514   {
515     depthCompareOp = value;
516     return *this;
517   }
518
519   auto& SetFront(StencilOpState value)
520   {
521     front = value;
522     return *this;
523   }
524
525   auto& SetBack(StencilOpState value)
526   {
527     back = value;
528     return *this;
529   }
530
531   auto& SetStencilTestEnable(bool value)
532   {
533     stencilTestEnable = value;
534     return *this;
535   }
536 };
537
538 /**
539  * @brief Rasterization state descriptor
540  */
541 struct RasterizationState
542 {
543   CullMode    cullMode{};
544   PolygonMode polygonMode{};
545   FrontFace   frontFace{};
546
547   auto& SetCullMode(CullMode value)
548   {
549     cullMode = value;
550     return *this;
551   }
552
553   auto& SetPolygonMode(PolygonMode value)
554   {
555     polygonMode = value;
556     return *this;
557   }
558
559   auto& SetFrontFace(FrontFace value)
560   {
561     frontFace = value;
562     return *this;
563   }
564 };
565
566 /**
567  * @brief Input assembly state descriptor.
568  *
569  * Structure describes the topology for submitted
570  * geometry.
571  */
572 struct InputAssemblyState
573 {
574   PrimitiveTopology topology{};
575   bool              primitiveRestartEnable{true};
576
577   auto& SetTopology(PrimitiveTopology value)
578   {
579     topology = value;
580     return *this;
581   }
582
583   auto& SetPrimitiveRestartEnable(bool value)
584   {
585     primitiveRestartEnable = true;
586     return *this;
587   }
588 };
589
590 /**
591  * @brief Pipeline dynamic state bits
592  */
593 namespace PipelineDynamicStateBits
594 {
595 const uint32_t VIEWPORT_BIT             = 1 << 0;
596 const uint32_t SCISSOR_BIT              = 1 << 1;
597 const uint32_t LINE_WIDTH_BIT           = 1 << 2;
598 const uint32_t DEPTH_BIAS_BIT           = 1 << 3;
599 const uint32_t BLEND_CONSTANTS_BIT      = 1 << 4;
600 const uint32_t DEPTH_BOUNDS_BIT         = 1 << 5;
601 const uint32_t STENCIL_COMPARE_MASK_BIT = 1 << 6;
602 const uint32_t STENCIL_WRITE_MASK_BIT   = 1 << 7;
603 const uint32_t STENCIL_REFERENCE_BIT    = 1 << 8;
604 } // namespace PipelineDynamicStateBits
605
606 const uint32_t PIPELINE_DYNAMIC_STATE_COUNT(9u);
607
608 using PipelineDynamicStateMask = uint32_t;
609
610 /**
611  * @brief Structure describes vertex input state of the pipeline.
612  * It specifies buffer binding and attribute format to be used.
613  */
614 struct VertexInputState
615 {
616   VertexInputState() = default;
617
618   /**
619    * @brief Vertex buffer binding
620    */
621   struct Binding
622   {
623     Binding(uint32_t _stride, VertexInputRate _inputRate)
624     : stride(_stride),
625       inputRate(_inputRate)
626     {
627     }
628     uint32_t        stride;
629     VertexInputRate inputRate;
630   };
631
632   /**
633    * @brief Attribute description
634    */
635   struct Attribute
636   {
637     Attribute(uint32_t _location, uint32_t _binding, uint32_t _offset, VertexInputFormat _format)
638     : location(_location),
639       binding(_binding),
640       offset(_offset),
641       format(_format)
642     {
643     }
644
645     uint32_t          location;
646     uint32_t          binding;
647     uint32_t          offset;
648     VertexInputFormat format;
649   };
650
651   VertexInputState(std::vector<Binding> _bufferBindings, std::vector<Attribute> _attributes)
652   : bufferBindings(std::move(_bufferBindings)),
653     attributes(std::move(_attributes))
654   {
655   }
656
657   std::vector<Binding>   bufferBindings{};
658   std::vector<Attribute> attributes{};
659 };
660
661 /**
662  * @brief List of all possible formats
663  * Not all formats may be supported
664  */
665 enum class Format
666 {
667   UNDEFINED,
668   // GLES compatible, luminance doesn't exist in Vulkan
669   L8,
670   L8A8,
671
672   // Vulkan compatible
673   R4G4_UNORM_PACK8,
674   R4G4B4A4_UNORM_PACK16,
675   B4G4R4A4_UNORM_PACK16,
676   R5G6B5_UNORM_PACK16,
677   B5G6R5_UNORM_PACK16,
678   R5G5B5A1_UNORM_PACK16,
679   B5G5R5A1_UNORM_PACK16,
680   A1R5G5B5_UNORM_PACK16,
681   R8_UNORM,
682   R8_SNORM,
683   R8_USCALED,
684   R8_SSCALED,
685   R8_UINT,
686   R8_SINT,
687   R8_SRGB,
688   R8G8_UNORM,
689   R8G8_SNORM,
690   R8G8_USCALED,
691   R8G8_SSCALED,
692   R8G8_UINT,
693   R8G8_SINT,
694   R8G8_SRGB,
695   R8G8B8_UNORM,
696   R8G8B8_SNORM,
697   R8G8B8_USCALED,
698   R8G8B8_SSCALED,
699   R8G8B8_UINT,
700   R8G8B8_SINT,
701   R8G8B8_SRGB,
702   B8G8R8_UNORM,
703   B8G8R8_SNORM,
704   B8G8R8_USCALED,
705   B8G8R8_SSCALED,
706   B8G8R8_UINT,
707   B8G8R8_SINT,
708   B8G8R8_SRGB,
709   R8G8B8A8_UNORM,
710   R8G8B8A8_SNORM,
711   R8G8B8A8_USCALED,
712   R8G8B8A8_SSCALED,
713   R8G8B8A8_UINT,
714   R8G8B8A8_SINT,
715   R8G8B8A8_SRGB,
716   B8G8R8A8_UNORM,
717   B8G8R8A8_SNORM,
718   B8G8R8A8_USCALED,
719   B8G8R8A8_SSCALED,
720   B8G8R8A8_UINT,
721   B8G8R8A8_SINT,
722   B8G8R8A8_SRGB,
723   A8B8G8R8_UNORM_PACK32,
724   A8B8G8R8_SNORM_PACK32,
725   A8B8G8R8_USCALED_PACK32,
726   A8B8G8R8_SSCALED_PACK32,
727   A8B8G8R8_UINT_PACK32,
728   A8B8G8R8_SINT_PACK32,
729   A8B8G8R8_SRGB_PACK32,
730   A2R10G10B10_UNORM_PACK32,
731   A2R10G10B10_SNORM_PACK32,
732   A2R10G10B10_USCALED_PACK32,
733   A2R10G10B10_SSCALED_PACK32,
734   A2R10G10B10_UINT_PACK32,
735   A2R10G10B10_SINT_PACK32,
736   A2B10G10R10_UNORM_PACK32,
737   A2B10G10R10_SNORM_PACK32,
738   A2B10G10R10_USCALED_PACK32,
739   A2B10G10R10_SSCALED_PACK32,
740   A2B10G10R10_UINT_PACK32,
741   A2B10G10R10_SINT_PACK32,
742   R16_UNORM,
743   R16_SNORM,
744   R16_USCALED,
745   R16_SSCALED,
746   R16_UINT,
747   R16_SINT,
748   R16_SFLOAT,
749   R16G16_UNORM,
750   R16G16_SNORM,
751   R16G16_USCALED,
752   R16G16_SSCALED,
753   R16G16_UINT,
754   R16G16_SINT,
755   R16G16_SFLOAT,
756   R16G16B16_UNORM,
757   R16G16B16_SNORM,
758   R16G16B16_USCALED,
759   R16G16B16_SSCALED,
760   R16G16B16_UINT,
761   R16G16B16_SINT,
762   R16G16B16_SFLOAT,
763   R16G16B16A16_UNORM,
764   R16G16B16A16_SNORM,
765   R16G16B16A16_USCALED,
766   R16G16B16A16_SSCALED,
767   R16G16B16A16_UINT,
768   R16G16B16A16_SINT,
769   R16G16B16A16_SFLOAT,
770   R32_UINT,
771   R32_SINT,
772   R32_SFLOAT,
773   R32G32_UINT,
774   R32G32_SINT,
775   R32G32_SFLOAT,
776   R32G32B32_UINT,
777   R32G32B32_SINT,
778   R32G32B32_SFLOAT,
779   R32G32B32A32_UINT,
780   R32G32B32A32_SINT,
781   R32G32B32A32_SFLOAT,
782   R64_UINT,
783   R64_SINT,
784   R64_SFLOAT,
785   R64G64_UINT,
786   R64G64_SINT,
787   R64G64_SFLOAT,
788   R64G64B64_UINT,
789   R64G64B64_SINT,
790   R64G64B64_SFLOAT,
791   R64G64B64A64_UINT,
792   R64G64B64A64_SINT,
793   R64G64B64A64_SFLOAT,
794   R11G11B10_UFLOAT_PACK32,
795   B10G11R11_UFLOAT_PACK32,
796   E5B9G9R9_UFLOAT_PACK32,
797   D16_UNORM,
798   X8_D24_UNORM_PACK32,
799   D32_SFLOAT,
800   S8_UINT,
801   D16_UNORM_S8_UINT,
802   D24_UNORM_S8_UINT,
803   D32_SFLOAT_S8_UINT,
804   BC1_RGB_UNORM_BLOCK,
805   BC1_RGB_SRGB_BLOCK,
806   BC1_RGBA_UNORM_BLOCK,
807   BC1_RGBA_SRGB_BLOCK,
808   BC2_UNORM_BLOCK,
809   BC2_SRGB_BLOCK,
810   BC3_UNORM_BLOCK,
811   BC3_SRGB_BLOCK,
812   BC4_UNORM_BLOCK,
813   BC4_SNORM_BLOCK,
814   BC5_UNORM_BLOCK,
815   BC5_SNORM_BLOCK,
816   BC6H_UFLOAT_BLOCK,
817   BC6H_SFLOAT_BLOCK,
818   BC7_UNORM_BLOCK,
819   BC7_SRGB_BLOCK,
820   ETC2_R8G8B8_UNORM_BLOCK,
821   ETC2_R8G8B8_SRGB_BLOCK,
822   ETC2_R8G8B8A1_UNORM_BLOCK,
823   ETC2_R8G8B8A1_SRGB_BLOCK,
824   ETC2_R8G8B8A8_UNORM_BLOCK,
825   ETC2_R8G8B8A8_SRGB_BLOCK,
826   EAC_R11_UNORM_BLOCK,
827   EAC_R11_SNORM_BLOCK,
828   EAC_R11G11_UNORM_BLOCK,
829   EAC_R11G11_SNORM_BLOCK,
830   ASTC_4x4_UNORM_BLOCK,
831   ASTC_4x4_SRGB_BLOCK,
832   ASTC_5x4_UNORM_BLOCK,
833   ASTC_5x4_SRGB_BLOCK,
834   ASTC_5x5_UNORM_BLOCK,
835   ASTC_5x5_SRGB_BLOCK,
836   ASTC_6x5_UNORM_BLOCK,
837   ASTC_6x5_SRGB_BLOCK,
838   ASTC_6x6_UNORM_BLOCK,
839   ASTC_6x6_SRGB_BLOCK,
840   ASTC_8x5_UNORM_BLOCK,
841   ASTC_8x5_SRGB_BLOCK,
842   ASTC_8x6_UNORM_BLOCK,
843   ASTC_8x6_SRGB_BLOCK,
844   ASTC_8x8_UNORM_BLOCK,
845   ASTC_8x8_SRGB_BLOCK,
846   ASTC_10x5_UNORM_BLOCK,
847   ASTC_10x5_SRGB_BLOCK,
848   ASTC_10x6_UNORM_BLOCK,
849   ASTC_10x6_SRGB_BLOCK,
850   ASTC_10x8_UNORM_BLOCK,
851   ASTC_10x8_SRGB_BLOCK,
852   ASTC_10x10_UNORM_BLOCK,
853   ASTC_10x10_SRGB_BLOCK,
854   ASTC_12x10_UNORM_BLOCK,
855   ASTC_12x10_SRGB_BLOCK,
856   ASTC_12x12_UNORM_BLOCK,
857   ASTC_12x12_SRGB_BLOCK,
858   PVRTC1_2BPP_UNORM_BLOCK_IMG,
859   PVRTC1_4BPP_UNORM_BLOCK_IMG,
860   PVRTC2_2BPP_UNORM_BLOCK_IMG,
861   PVRTC2_4BPP_UNORM_BLOCK_IMG,
862   PVRTC1_2BPP_SRGB_BLOCK_IMG,
863   PVRTC1_4BPP_SRGB_BLOCK_IMG,
864   PVRTC2_2BPP_SRGB_BLOCK_IMG,
865   PVRTC2_4BPP_SRGB_BLOCK_IMG,
866 };
867
868 /**
869  * @brief Flags specifying a buffer usage
870  */
871 enum class BufferUsage
872 {
873   TRANSFER_SRC         = 1 << 0,
874   TRANSFER_DST         = 1 << 1,
875   UNIFORM_TEXEL_BUFFER = 1 << 2,
876   STORAGE_TEXEL_BUFFER = 1 << 3,
877   UNIFORM_BUFFER       = 1 << 4,
878   STORAGE_BUFFER       = 1 << 5,
879   INDEX_BUFFER         = 1 << 6,
880   VERTEX_BUFFER        = 1 << 7,
881   INDIRECT_BUFFER      = 1 << 8,
882 };
883
884 using BufferUsageFlags = uint32_t;
885
886 inline BufferUsageFlags operator|(BufferUsageFlags flags, BufferUsage usage)
887 {
888   flags |= static_cast<uint32_t>(usage);
889   return flags;
890 }
891
892 /**
893  * @brief Buffer property bits
894  *
895  * Use these bits to set BufferPropertiesFlags.
896  */
897 enum class BufferPropertiesFlagBit : uint32_t
898 {
899   CPU_ALLOCATED    = 1 << 0, ///< Buffer is allocated on the CPU side
900   TRANSIENT_MEMORY = 1 << 1, ///< Buffer memory will be short-lived
901 };
902
903 /**
904  * @brief BufferPropetiesFlags alters behaviour of implementation
905  */
906 using BufferPropertiesFlags = uint32_t;
907
908 inline BufferPropertiesFlags operator|(BufferPropertiesFlags flags, BufferPropertiesFlagBit usage)
909 {
910   flags |= static_cast<uint32_t>(usage);
911   return flags;
912 }
913
914 /**
915  * @brief The structure describes memory requirements of GPU resource (texture, buffer)
916  */
917 struct MemoryRequirements
918 {
919   size_t size;
920   size_t alignment;
921 };
922
923 using TextureUpdateFlags = uint32_t;
924 enum class TextureUpdateFlagBits
925 {
926   KEEP_SOURCE = 1 << 0,
927 };
928
929 /**
930  * @brief Texture update info
931  *
932  * Describes the texture update to be executed by
933  * Controller::UpdateTextures()
934  */
935 struct TextureUpdateInfo
936 {
937   Texture* dstTexture{};
938   Offset2D dstOffset2D;
939   uint32_t layer{};
940   uint32_t level{};
941
942   uint32_t srcReference{};
943   Extent2D srcExtent2D{};
944   uint32_t srcOffset{};
945   uint32_t srcSize{};
946   Format   srcFormat{}; ///< Should match dstTexture's format, otherwise conversion may occur
947 };
948
949 /**
950  * @brief Texture update source info
951  *
952  * Describes the source of data (memory, buffer or another texture)
953  * to be used when updating textures using Controller::UpdateTextures().
954  */
955 struct TextureUpdateSourceInfo
956 {
957   enum class Type
958   {
959     BUFFER,
960     MEMORY,
961     TEXTURE
962   };
963
964   Type sourceType;
965
966   struct BufferSource
967   {
968     Buffer* buffer;
969   } bufferSource;
970
971   struct MemorySource
972   {
973     void* memory;
974   } memorySource;
975
976   struct TextureSource
977   {
978     Texture* texture;
979   } textureSource;
980 };
981
982 /**
983  * @brief Properties of texture
984  */
985 struct TextureProperties
986 {
987   Format   format;                   ///< Texture format
988   Format   format1;                  ///< Texture format (if emulated)
989   bool     emulated;                 ///< Format is emulated (for example RGB as RGBA)
990   bool     compressed;               ///< Texture is compressed
991   bool     packed;                   ///< Texture is packed
992   Extent2D extent2D;                 ///< Size of texture
993   bool     directWriteAccessEnabled; ///< Direct write access (mappable textures)
994 };
995
996 /**
997  * @brief Texture tiling that directly refers to the tiling
998  * mode supported by the Vulkan. Other implementations
999  * of the backend may ignore the value.
1000  */
1001 enum class TextureTiling
1002 {
1003   OPTIMAL,
1004   LINEAR
1005 };
1006
1007 /**
1008  * @brief Texture color attachment used by FramebufferCreateInfo
1009  */
1010 struct ColorAttachment
1011 {
1012   uint32_t attachmentId;
1013   Texture* texture;
1014   uint32_t layerId;
1015   uint32_t levelId;
1016 };
1017
1018 /**
1019  * @brief Depth stencil attachment used by FramebufferCreateInfo
1020  */
1021 struct DepthStencilAttachment
1022 {
1023   enum class Usage
1024   {
1025     WRITE, // If no texture, will create a RenderBuffer instead
1026     NONE   // If no attachment/RenderBuffer required
1027   };
1028   Texture* depthTexture{nullptr};
1029   Texture* stencilTexture{nullptr};
1030   uint32_t depthLevel{0};
1031   uint32_t stencilLevel{0};
1032   Usage    depthUsage{Usage::NONE};
1033   Usage    stencilUsage{Usage::NONE};
1034 };
1035
1036 /**
1037  * @brief Submit flags
1038  */
1039 using SubmitFlags = uint32_t;
1040
1041 /**
1042  * Submit flag bits
1043  */
1044 enum class SubmitFlagBits : uint32_t
1045 {
1046   FLUSH         = 1 << 0, // Flush immediately
1047   DONT_OPTIMIZE = 1 << 1  // Tells controller not to optimize commands
1048 };
1049
1050 template<typename T>
1051 inline SubmitFlags operator|(T flags, SubmitFlagBits bit)
1052 {
1053   return static_cast<SubmitFlags>(flags) | static_cast<SubmitFlags>(bit);
1054 }
1055
1056 /**
1057  * @brief Describes command buffers submission
1058  */
1059 struct SubmitInfo
1060 {
1061   std::vector<CommandBuffer*> cmdBuffer;
1062   SubmitFlags                 flags;
1063 };
1064
1065 /**
1066  * @brief Shader language enum
1067  */
1068 enum class ShaderLanguage
1069 {
1070   GLSL_1,
1071   GLSL_3_1,
1072   GLSL_3_2,
1073   SPIRV_1_0,
1074   SPIRV_1_1,
1075 };
1076
1077 /**
1078  * @brief Pipeline stages
1079  */
1080 enum class PipelineStage
1081 {
1082   TOP_OF_PIPELINE,
1083   VERTEX_SHADER,
1084   GEOMETRY_SHADER,
1085   FRAGMENT_SHADER,
1086   COMPUTE_SHADER,
1087   TESSELATION_CONTROL,
1088   TESSELATION_EVALUATION,
1089   BOTTOM_OF_PIPELINE
1090 };
1091
1092 /**
1093  * @brief Vertex attribute format
1094  *
1095  * TODO: to be replaced with Format
1096  */
1097 enum class VertexInputAttributeFormat
1098 {
1099   UNDEFINED,
1100   FLOAT,
1101   INTEGER,
1102   VEC2,
1103   VEC3,
1104   VEC4
1105 };
1106
1107 /**
1108  * @brief Uniform class
1109  */
1110 enum class UniformClass
1111 {
1112   SAMPLER,
1113   IMAGE,
1114   COMBINED_IMAGE_SAMPLER,
1115   UNIFORM_BUFFER,
1116   UNIFORM,
1117   UNDEFINED
1118 };
1119
1120 /**
1121  * @brief Type of texture
1122  */
1123 enum class TextureType
1124 {
1125   TEXTURE_2D,
1126   TEXTURE_3D,
1127   TEXTURE_CUBEMAP,
1128 };
1129
1130 /**
1131  * @brief The information of the uniform
1132  */
1133 struct UniformInfo
1134 {
1135   std::string  name{""};
1136   UniformClass uniformClass{UniformClass::UNDEFINED};
1137   uint32_t     binding{0u};
1138   uint32_t     bufferIndex{0u};
1139   uint32_t     offset{0u};
1140   uint32_t     location{0u};
1141
1142   bool operator==(const UniformInfo& rhs)
1143   {
1144     return name == rhs.name &&
1145            uniformClass == rhs.uniformClass &&
1146            binding == rhs.binding &&
1147            bufferIndex == rhs.bufferIndex &&
1148            offset == rhs.offset &&
1149            location == rhs.location;
1150   }
1151 };
1152
1153 /**
1154  * @brief The information of the uniform block
1155  */
1156 struct UniformBlockInfo
1157 {
1158   std::string              name{""};
1159   uint32_t                 descriptorSet{0u};
1160   uint32_t                 binding{0u};
1161   uint32_t                 size{0u};
1162   std::vector<UniformInfo> members{};
1163 };
1164
1165 /**
1166  * @brief Describes pipeline's shading stages
1167  *
1168  * Shader state binds shader and pipeline stage that the
1169  * shader will be executed. The shader may be created with
1170  * pipeline stage and the pipelineStage member may be ignored
1171  * by setting inheritPipelineStage to true.
1172  */
1173 struct ShaderState
1174 {
1175   const Shader* shader{nullptr};             // shader to attach
1176   PipelineStage pipelineStage{};             // pipeline stage to execute the shader
1177   bool          inheritPipelineStage{false}; // stage inheritance
1178
1179   auto& SetShader(const Shader& value)
1180   {
1181     shader = &value;
1182     return *this;
1183   }
1184
1185   auto& SetPipelineStage(PipelineStage value)
1186   {
1187     pipelineStage = value;
1188     return *this;
1189   }
1190
1191   auto& SetInheritPipelineStage(bool value)
1192   {
1193     inheritPipelineStage = value;
1194     return *this;
1195   }
1196 };
1197
1198 /**
1199  * @brief Flag determining usage of texture
1200  */
1201 using TextureUsageFlags = uint32_t;
1202 enum class TextureUsageFlagBits : uint32_t
1203 {
1204   SAMPLE                   = 1 << 0,
1205   COLOR_ATTACHMENT         = 1 << 1,
1206   DEPTH_STENCIL_ATTACHMENT = 1 << 2,
1207   DONT_CARE                = 1 << 4,
1208 };
1209
1210 template<typename T>
1211 inline TextureUsageFlags operator|(T flags, TextureUsageFlagBits bit)
1212 {
1213   return static_cast<TextureUsageFlags>(flags) | static_cast<TextureUsageFlags>(bit);
1214 }
1215
1216 using TextureFormat = Dali::Graphics::Format;
1217
1218 /**
1219  * @brief Texture mipmap disable/enable enum
1220  */
1221 enum class TextureMipMapFlag
1222 {
1223   ENABLED,
1224   DISABLED,
1225 };
1226
1227 /**
1228  * @brief Depth/stencil attachment flag
1229  */
1230 enum class TextureDepthStencilFlag
1231 {
1232   NONE,
1233   DEPTH,
1234   STENCIL,
1235   DEPTH_STENCIL,
1236 };
1237
1238 /**
1239  * @brief Layout of texture
1240  *
1241  * Specifies how the memory will be allocated, organized and accessed.
1242  */
1243 enum class TextureLayout
1244 {
1245   LINEAR, ///< Creates linear memory, mapping possible
1246   OPTIMAL ///< Usually, read-only memory, driver-optimal layout
1247 };
1248
1249 /**
1250  * @brief Level of command buffer
1251  */
1252 enum class CommandBufferLevel
1253 {
1254   PRIMARY,  ///< Primary buffer can be executed on its own
1255   SECONDARY ///< Secondary buffer must be executed within scope of Primary buffer
1256 };
1257
1258 /**
1259  * @brief Enum indicating whether shader source
1260  * is text-based or binary.
1261  */
1262 enum class ShaderSourceMode
1263 {
1264   TEXT,
1265   BINARY
1266 };
1267
1268 /**
1269  * @brief Memory usage flags to be set when mapping the buffer
1270  */
1271 using MemoryUsageFlags = uint32_t;
1272 enum class MemoryUsageFlagBits : uint32_t
1273 {
1274   WRITE        = 1 << 0,
1275   READ         = 1 << 1,
1276   PERSISTENT   = 1 << 2,
1277   ASYNCHRONOUS = 1 << 3,
1278   DONT_CARE    = 1 << 4,
1279 };
1280
1281 template<typename T>
1282 inline MemoryUsageFlags operator|(T flags, MemoryUsageFlagBits bit)
1283 {
1284   return static_cast<MemoryUsageFlags>(flags) | static_cast<MemoryUsageFlags>(bit);
1285 }
1286
1287 /**
1288  * @brief Describes buffer mapping details
1289  */
1290 struct MapBufferInfo
1291 {
1292   Buffer*          buffer;
1293   MemoryUsageFlags usage;
1294   uint32_t         offset;
1295   uint32_t         size;
1296 };
1297
1298 /**
1299  * @brief Describes buffer mapping details
1300  * TODO: mapping by texture level and layer
1301  */
1302 struct MapTextureInfo
1303 {
1304   Texture*         texture;
1305   MemoryUsageFlags usage;
1306   uint32_t         offset;
1307   uint32_t         size;
1308 };
1309
1310 /**
1311  * @brief GraphicsStructureType enum is used by all create info structures
1312  * in order to identify by the implementation which structure it is
1313  * dealing with.
1314  */
1315 enum class GraphicsStructureType : uint32_t
1316 {
1317   BUFFER_CREATE_INFO_STRUCT,
1318   COMMAND_BUFFER_CREATE_INFO_STRUCT,
1319   FRAMEBUFFER_CREATE_INFO_STRUCT,
1320   PROGRAM_CREATE_INFO_STRUCT,
1321   PIPELINE_CREATE_INFO_STRUCT,
1322   RENDERPASS_CREATE_INFO_STRUCT,
1323   SAMPLER_CREATE_INFO_STRUCT,
1324   SHADER_CREATE_INFO_STRUCT,
1325   TEXTURE_CREATE_INFO_STRUCT,
1326   RENDER_TARGET_CREATE_INFO_STRUCT,
1327   SYNC_OBJECT_CREATE_INFO_STRUCT
1328 };
1329
1330 /**
1331  * @brief Enum describes load operation associated
1332  * with particular framebuffer attachment
1333  */
1334 enum class AttachmentLoadOp
1335 {
1336   LOAD,     ///< Load previous content
1337   CLEAR,    ///< Clear the attachment
1338   DONT_CARE ///< Let driver decide
1339 };
1340
1341 /**
1342  * @brief Enum describes store operation associated
1343  * with particular framebuffer attachment
1344  */
1345 enum class AttachmentStoreOp
1346 {
1347   STORE,    ///< Store content (color attachemnts)
1348   DONT_CARE ///< Let driver decide (depth/stencil attachemnt with no intention of reading)
1349 };
1350
1351 /**
1352  * @brief The structure describes the read/write
1353  * modes of a single framebuffer attachment
1354  *
1355  * The attachment description specifies what is going to
1356  * happen to the attachment at the beginning and end of the
1357  * render pass.
1358  *
1359  * The stencil operation is separated as it may be set
1360  * independent from the depth component (use loadOp, storeOp
1361  * to set up the depth component and stencilLoadOp, stencilStoreOp
1362  * for stencil component).
1363  */
1364 struct AttachmentDescription
1365 {
1366   /**
1367    * @brief Sets load operation for the attachment
1368    *
1369    * @param value Load operation
1370    * @return this structure
1371    */
1372   auto& SetLoadOp(AttachmentLoadOp value)
1373   {
1374     loadOp = value;
1375     return *this;
1376   }
1377
1378   /**
1379    * @brief Sets store operation for the attachment
1380    *
1381    * @param value Store operation
1382    * @return this structure
1383    */
1384   auto& SetStoreOp(AttachmentStoreOp value)
1385   {
1386     storeOp = value;
1387     return *this;
1388   }
1389
1390   /**
1391    * @brief Sets load operation for the stencil part of attachment
1392    *
1393    * @param value load operation
1394    * @return this structure
1395    */
1396   auto& SetStencilLoadOp(AttachmentLoadOp value)
1397   {
1398     stencilLoadOp = value;
1399     return *this;
1400   }
1401
1402   /**
1403    * @brief Sets store operation for the stencil part of attachment
1404    *
1405    * @param value store operation
1406    * @return this structure
1407    */
1408   auto& SetStencilStoreOp(AttachmentStoreOp value)
1409   {
1410     stencilStoreOp = value;
1411     return *this;
1412   }
1413
1414   AttachmentLoadOp  loadOp{};
1415   AttachmentStoreOp storeOp{};
1416   AttachmentLoadOp  stencilLoadOp{};
1417   AttachmentStoreOp stencilStoreOp{};
1418 };
1419
1420 /**
1421  * @brief Helper function to be used by the extension developers
1422  *
1423  * The value of custom type must be unique and recognizable by the
1424  * implementation.
1425  *
1426  * @param customValue Custom value of GraphicsStructureType
1427  * @return Integer converted to GraphicsStructureType
1428  */
1429 inline GraphicsStructureType GraphicsExtensionType(uint32_t customValue)
1430 {
1431   return static_cast<GraphicsStructureType>(customValue);
1432 }
1433
1434 /**
1435  * @brief The allocation callbacks may be passed when the object is created.
1436  */
1437 struct AllocationCallbacks
1438 {
1439   void* userData                                                                          = nullptr; ///< User data passed to the allocator
1440   void* (*allocCallback)(size_t size, size_t alignment, void* userData)                   = nullptr;
1441   void* (*reallocCallback)(void* original, size_t size, size_t alignment, void* userData) = nullptr;
1442   void (*freeCallback)(void* memory, void* userData)                                      = nullptr;
1443 };
1444
1445 /**
1446  * @brief The ExtensionCreateInfo structure should be a base of any
1447  * extension create info structure. The structure isn't virtual
1448  * so the implementation must prevent slicing it.
1449  */
1450 struct ExtensionCreateInfo
1451 {
1452   GraphicsStructureType type{};
1453   ExtensionCreateInfo*  nextExtension{};
1454 };
1455
1456 /**
1457  * @brief Default deleter for graphics unique pointers
1458  *
1459  * Returned unique_ptr may require custom deleter. To get it working
1460  * with std::unique_ptr the custom type is used with polymorphic deleter
1461  */
1462 template<class T>
1463 struct DefaultDeleter
1464 {
1465   DefaultDeleter() = default;
1466
1467   /**
1468    * @brief Conversion constructor
1469    *
1470    * This constructor will set the lambda for type passed
1471    * as an argument.
1472    */
1473   template<class P, template<typename> typename U>
1474   DefaultDeleter(const U<P>& deleter)
1475   {
1476     deleteFunction = [](T* object) { U<P>()(static_cast<P*>(object)); };
1477   }
1478
1479   /**
1480    * @brief Conversion constructor from DefaultDelete<P>
1481    *
1482    * This constructor transfers deleteFunction only
1483    */
1484   template<class P>
1485   explicit DefaultDeleter(const DefaultDeleter<P>& deleter)
1486   {
1487     deleteFunction = decltype(deleteFunction)(deleter.deleteFunction);
1488   }
1489
1490   /**
1491    * @brief Default deleter
1492    *
1493    * Default deleter will use standard 'delete' call in order
1494    * to discard graphics objects unless a custom deleter was
1495    * used.
1496    *
1497    * @param[in] object Object to delete
1498    */
1499   void operator()(T* object)
1500   {
1501     if(deleteFunction)
1502     {
1503       deleteFunction(object);
1504     }
1505     else
1506     {
1507       delete object;
1508     }
1509   }
1510
1511   void (*deleteFunction)(T* object){nullptr}; ///< Custom delete function
1512 };
1513
1514 /**
1515  * Surface type is just a void* to any native object.
1516  */
1517 using Surface = void;
1518
1519 /**
1520  * @brief Enum describing preTransform of render target
1521  */
1522 enum class RenderTargetTransformFlagBits
1523 {
1524   TRANSFORM_IDENTITY_BIT           = 0x00000001,
1525   ROTATE_90_BIT                    = 0x00000002,
1526   ROTATE_180_BIT                   = 0x00000004,
1527   ROTATE_270_BIT                   = 0x00000008,
1528   HORIZONTAL_MIRROR_BIT            = 0x00000010,
1529   HORIZONTAL_MIRROR_ROTATE_90_BIT  = 0x00000020,
1530   HORIZONTAL_MIRROR_ROTATE_180_BIT = 0x00000040,
1531   HORIZONTAL_MIRROR_ROTATE_270_BIT = 0x00000080,
1532 };
1533
1534 using RenderTargetTransformFlags = uint32_t;
1535
1536 template<typename T>
1537 inline RenderTargetTransformFlags operator|(T flags, RenderTargetTransformFlagBits bit)
1538 {
1539   return static_cast<RenderTargetTransformFlags>(flags) | static_cast<RenderTargetTransformFlags>(bit);
1540 }
1541
1542 /**
1543  * unique_ptr defined in the Graphics scope
1544  */
1545 template<class T, class D = DefaultDeleter<T>>
1546 using UniquePtr = std::unique_ptr<T, D>;
1547
1548 /**
1549  * @brief MakeUnique<> version that returns Graphics::UniquePtr
1550  * @param[in] args Arguments for construction
1551  * @return
1552  */
1553 template<class T, class Deleter = DefaultDeleter<T>, class... Args>
1554 std::enable_if_t<!std::is_array<T>::value, Graphics::UniquePtr<T>>
1555 MakeUnique(Args&&... args)
1556 {
1557   return UniquePtr<T>(new T(std::forward<Args>(args)...), Deleter());
1558 }
1559
1560 } // namespace Graphics
1561 } // namespace Dali
1562
1563 #endif //DALI_GRAPHICS_API_TYPES_H