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