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