Graphics API
[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 <string>
23 #include <utility>
24 #include <vector>
25
26 namespace Dali
27 {
28 namespace Graphics
29 {
30 class CommandBuffer;
31 class Texture;
32 class Buffer;
33 class Shader;
34 class Framebuffer;
35
36 /**
37  * @brief Structure describes 2D offset
38  */
39 struct Offset2D
40 {
41   int32_t x = 0;
42   int32_t y = 0;
43 };
44
45 /**
46  * @brief Structure describes 2D dimensions
47  */
48 struct Extent2D
49 {
50   uint32_t width;
51   uint32_t height;
52 };
53
54 /**
55  * @brief Structure describes 2D rectangle (offset, extent)
56  */
57 struct Rect2D
58 {
59   int32_t  x      = 0;
60   int32_t  y      = 0;
61   uint32_t width  = 0;
62   uint32_t height = 0;
63 };
64
65 /**
66  * @brief Structure represents area of viewport
67  */
68 struct Viewport
69 {
70   float x        = 0.0f;
71   float y        = 0.0f;
72   float width    = 0.0f;
73   float height   = 0.0f;
74   float minDepth = 0.0f;
75   float maxDepth = 0.0f;
76 };
77
78 /**
79  * @brief Describes vertex attribute input rate
80  */
81 enum class VertexInputRate
82 {
83   PER_VERTEX,  ///< Attribute read per vertex
84   PER_INSTANCE ///< Attribute read per instance
85 };
86
87 /**
88  * @brief Vertex input format
89  *
90  * When UNDEFINED, the reflection is used to determine what
91  * the actual format is.
92  */
93 enum class VertexInputFormat
94 {
95   UNDEFINED,
96   FVECTOR2,
97   FVECTOR3,
98   FVECTOR4,
99   IVECTOR2,
100   IVECTOR3,
101   IVECTOR4,
102   FLOAT,
103   INTEGER,
104 };
105
106 /**
107  * @brief Logic operators used by color blending state
108  * when logicOpEnable is set.
109  */
110 enum class LogicOp
111 {
112   CLEAR         = 0,
113   AND           = 1,
114   AND_REVERSE   = 2,
115   COPY          = 3,
116   AND_INVERTED  = 4,
117   NO_OP         = 5,
118   XOR           = 6,
119   OR            = 7,
120   NOR           = 8,
121   EQUIVALENT    = 9,
122   INVERT        = 10,
123   OR_REVERSE    = 11,
124   COPY_INVERTED = 12,
125   OR_INVERTED   = 13,
126   NAND          = 14,
127   SET           = 15,
128 };
129
130 /**
131  * @brief Blend factors
132  */
133 enum class BlendFactor
134 {
135   ZERO                     = 0,
136   ONE                      = 1,
137   SRC_COLOR                = 2,
138   ONE_MINUS_SRC_COLOR      = 3,
139   DST_COLOR                = 4,
140   ONE_MINUS_DST_COLOR      = 5,
141   SRC_ALPHA                = 6,
142   ONE_MINUS_SRC_ALPHA      = 7,
143   DST_ALPHA                = 8,
144   ONE_MINUS_DST_ALPHA      = 9,
145   CONSTANT_COLOR           = 10,
146   ONE_MINUS_CONSTANT_COLOR = 11,
147   CONSTANT_ALPHA           = 12,
148   ONE_MINUS_CONSTANT_ALPHA = 13,
149   SRC_ALPHA_SATURATE       = 14,
150   SRC1_COLOR               = 15,
151   ONE_MINUS_SRC1_COLOR     = 16,
152   SRC1_ALPHA               = 17,
153   ONE_MINUS_SRC1_ALPHA     = 18,
154 };
155
156 /**
157  * @brief Blend operators
158  */
159 enum class BlendOp
160 {
161   ADD              = 0,
162   SUBTRACT         = 1,
163   REVERSE_SUBTRACT = 2,
164   MIN              = 3,
165   MAX              = 4,
166 };
167
168 /**
169  * @brief Compare operators
170  */
171 enum class CompareOp
172 {
173   NEVER,
174   LESS,
175   EQUAL,
176   LESS_OR_EQUAL,
177   GREATER,
178   NOT_EQUAL,
179   GREATER_OR_EQUAL,
180   ALWAYS
181 };
182
183 /**
184  * @brief Stencil operators
185  */
186 enum class StencilOp
187 {
188   KEEP,
189   ZERO,
190   REPLACE,
191   INCREMENT_AND_CLAMP,
192   DECREMENT_AND_CLAMP,
193   INVERT,
194   INCREMENT_AND_WRAP,
195   DECREMENT_AND_WRAP
196 };
197
198 /**
199  * @brief Backface culling modes
200  */
201 enum class CullMode
202 {
203   NONE,
204   FRONT,
205   BACK,
206   FRONT_AND_BACK
207 };
208
209 /**
210  * @brief Polygon drawing modes
211  */
212 enum class PolygonMode
213 {
214   FILL,
215   LINE,
216   POINT
217 };
218
219 /**
220  * @brief Front face direction
221  */
222 enum class FrontFace
223 {
224   COUNTER_CLOCKWISE,
225   CLOCKWISE
226 };
227
228 /**
229  * @brief Primitive geometry topology
230  */
231 enum class PrimitiveTopology
232 {
233   POINT_LIST,
234   LINE_LIST,
235   LINE_STRIP,
236   TRIANGLE_LIST,
237   TRIANGLE_STRIP,
238   TRIANGLE_FAN
239 };
240
241 /**
242  * @brief Sampler address ( wrapping ) mode
243  */
244 enum class SamplerAddressMode
245 {
246   REPEAT,
247   MIRRORED_REPEAT,
248   CLAMP_TO_EDGE,
249   CLAMP_TO_BORDER,
250   MIRROR_CLAMP_TO_EDGE
251 };
252
253 /**
254  * @brief Filtering mode
255  */
256 enum class SamplerFilter
257 {
258   NEAREST,
259   LINEAR
260 };
261
262 /**
263  * @brief Mipmap mode
264  */
265 enum class SamplerMipmapMode
266 {
267   NONE,
268   NEAREST,
269   LINEAR
270 };
271
272 /**
273  * @brief Describes pipeline's color blend state
274  */
275 struct ColorBlendState
276 {
277   bool        logicOpEnable           = false;
278   LogicOp     logicOp                 = {};
279   float       blendConstants[4]       = {0.0f, 0.0f, 0.0f, 0.0f};
280   bool        blendEnable             = false;
281   BlendFactor srcColorBlendFactor     = BlendFactor::ZERO;
282   BlendFactor dstColorBlendFactor     = BlendFactor::ZERO;
283   BlendOp     colorBlendOp            = {};
284   BlendFactor srcAlphaBlendFactor     = BlendFactor::ZERO;
285   BlendFactor dstAlphaBlendFactor     = BlendFactor::ZERO;
286   BlendOp     alphaBlendOp            = {};
287   uint32_t    colorComponentWriteBits = {0u};
288
289   auto& SetLogicOpEnable(bool value)
290   {
291     logicOpEnable = value;
292     return *this;
293   }
294
295   auto& SetLogicOp(LogicOp value)
296   {
297     logicOp = value;
298     return *this;
299   }
300
301   auto& SetBlendConstants(float value[4])
302   {
303     std::copy(value, value + 4, blendConstants);
304     return *this;
305   }
306
307   auto& SetBlendEnable(bool value)
308   {
309     blendEnable = value;
310     return *this;
311   }
312
313   auto& SetSrcColorBlendFactor(BlendFactor value)
314   {
315     srcColorBlendFactor = value;
316     return *this;
317   }
318
319   auto& SetDstColorBlendFactor(BlendFactor value)
320   {
321     dstColorBlendFactor = value;
322     return *this;
323   }
324
325   auto& SetColorBlendOp(BlendOp value)
326   {
327     colorBlendOp = value;
328     return *this;
329   }
330
331   auto& SetSrcAlphaBlendFactor(BlendFactor value)
332   {
333     srcAlphaBlendFactor = value;
334     return *this;
335   }
336
337   auto& SetDstAlphaBlendFactor(BlendFactor value)
338   {
339     dstAlphaBlendFactor = value;
340     return *this;
341   }
342
343   auto& SetAlphaBlendOp(BlendOp value)
344   {
345     alphaBlendOp = value;
346     return *this;
347   }
348
349   auto& SetColorComponentsWriteBits(uint32_t value)
350   {
351     colorComponentWriteBits = value;
352     return *this;
353   }
354 };
355
356 /**
357  * @brief  Framebuffer state
358  */
359 struct FramebufferState
360 {
361   const Framebuffer* framebuffer{nullptr};
362
363   auto& SetFramebuffer(const Framebuffer& value)
364   {
365     framebuffer = &value;
366     return *this;
367   }
368 };
369
370 /**
371  * @brief Describes pipeline's viewport and scissor state
372  */
373 struct ViewportState
374 {
375   Viewport viewport{0.0, 0.0, 0.0, 0.0};
376   Rect2D   scissor{0, 0, 0, 0};
377   bool     scissorTestEnable{false};
378
379   auto& SetViewport(const Viewport& value)
380   {
381     viewport = value;
382     return *this;
383   }
384
385   auto& SetScissor(const Rect2D& value)
386   {
387     scissor = value;
388     return *this;
389   }
390
391   auto& SetScissorTestEnable(bool value)
392   {
393     scissorTestEnable = value;
394     return *this;
395   }
396 };
397
398 /**
399  * @brief Describes stencil operation state
400  */
401 struct StencilOpState
402 {
403   StencilOp failOp{};
404   StencilOp passOp{};
405   StencilOp depthFailOp{};
406   CompareOp compareOp{};
407   uint32_t  compareMask{0u};
408   uint32_t  writeMask{0u};
409   uint32_t  reference{0u};
410
411   auto& SetFailOp(StencilOp value)
412   {
413     failOp = value;
414     return *this;
415   }
416
417   auto& SetPassOp(StencilOp value)
418   {
419     failOp = value;
420     return *this;
421   }
422
423   auto& SetDepthFailOp(StencilOp value)
424   {
425     failOp = value;
426     return *this;
427   }
428
429   auto& SetCompareOp(CompareOp value)
430   {
431     compareOp = value;
432     return *this;
433   }
434
435   auto& SetCompareMask(uint32_t value)
436   {
437     compareMask = value;
438     return *this;
439   }
440
441   auto& SetWriteMask(uint32_t value)
442   {
443     writeMask = value;
444     return *this;
445   }
446
447   auto& SetReference(uint32_t value)
448   {
449     reference = value;
450     return *this;
451   }
452 };
453
454 /**
455  * @brief Describes pipeline's viewport and scissor state
456  */
457 struct DepthStencilState
458 {
459   bool      depthTestEnable{false};
460   bool      depthWriteEnable{false};
461   CompareOp depthCompareOp{};
462
463   bool           stencilTestEnable{false};
464   StencilOpState front{};
465   StencilOpState back{};
466
467   auto& SetDepthTestEnable(bool value)
468   {
469     depthTestEnable = value;
470     return *this;
471   }
472
473   auto& SetDepthWriteEnable(bool value)
474   {
475     depthWriteEnable = value;
476     return *this;
477   }
478
479   auto& SetDepthCompareOp(CompareOp value)
480   {
481     depthCompareOp = value;
482     return *this;
483   }
484
485   auto& SetFront(StencilOpState value)
486   {
487     front = value;
488     return *this;
489   }
490
491   auto& SetBack(StencilOpState value)
492   {
493     back = value;
494     return *this;
495   }
496
497   auto& SetStencilTestEnable(bool value)
498   {
499     stencilTestEnable = value;
500     return *this;
501   }
502 };
503
504 /**
505  * @brief Rasterization state descriptor
506  */
507 struct RasterizationState
508 {
509   CullMode    cullMode{};
510   PolygonMode polygonMode{};
511   FrontFace   frontFace{};
512
513   auto& SetCullMode(CullMode value)
514   {
515     cullMode = value;
516     return *this;
517   }
518
519   auto& SetPolygonMode(PolygonMode value)
520   {
521     polygonMode = value;
522     return *this;
523   }
524
525   auto& SetFrontFace(FrontFace value)
526   {
527     frontFace = value;
528     return *this;
529   }
530 };
531
532 /**
533  * @brief Input assembly state descriptor.
534  *
535  * Structure describes the topology for submitted
536  * geometry.
537  */
538 struct InputAssemblyState
539 {
540   PrimitiveTopology topology{};
541   bool              primitiveRestartEnable{true};
542
543   auto& SetTopology(PrimitiveTopology value)
544   {
545     topology = value;
546     return *this;
547   }
548
549   auto& SetPrimitiveRestartEnable(bool value)
550   {
551     primitiveRestartEnable = true;
552     return *this;
553   }
554 };
555
556 /**
557  * @brief Pipeline dynamic state bits
558  */
559 namespace PipelineDynamicStateBits
560 {
561 const uint32_t VIEWPORT_BIT             = 1 << 0;
562 const uint32_t SCISSOR_BIT              = 1 << 1;
563 const uint32_t LINE_WIDTH_BIT           = 1 << 2;
564 const uint32_t DEPTH_BIAS_BIT           = 1 << 3;
565 const uint32_t BLEND_CONSTANTS_BIT      = 1 << 4;
566 const uint32_t DEPTH_BOUNDS_BIT         = 1 << 5;
567 const uint32_t STENCIL_COMPARE_MASK_BIT = 1 << 6;
568 const uint32_t STENCIL_WRITE_MASK_BIT   = 1 << 7;
569 const uint32_t STENCIL_REFERENCE_BIT    = 1 << 8;
570 } // namespace PipelineDynamicStateBits
571
572 const uint32_t PIPELINE_DYNAMIC_STATE_COUNT(9u);
573
574 using PipelineDynamicStateMask = uint32_t;
575
576 /**
577  * @brief Structure describes vertex input state of the pipeline.
578  * It specifies buffer binding and attribute format to be used.
579  */
580 struct VertexInputState
581 {
582   VertexInputState() = default;
583
584   /**
585    * @brief Vertex buffer binding
586    */
587   struct Binding
588   {
589     Binding(uint32_t _stride, VertexInputRate _inputRate)
590     : stride(_stride),
591       inputRate(_inputRate)
592     {
593     }
594     uint32_t        stride;
595     VertexInputRate inputRate;
596   };
597
598   /**
599    * @brief Attribute description
600    */
601   struct Attribute
602   {
603     Attribute(uint32_t _location, uint32_t _binding, uint32_t _offset, VertexInputFormat _format)
604     : location(_location),
605       binding(_binding),
606       offset(_offset),
607       format(_format)
608     {
609     }
610
611     uint32_t          location;
612     uint32_t          binding;
613     uint32_t          offset;
614     VertexInputFormat format;
615   };
616
617   VertexInputState(std::vector<Binding> _bufferBindings, std::vector<Attribute> _attributes)
618   : bufferBindings(std::move(_bufferBindings)),
619     attributes(std::move(_attributes))
620   {
621   }
622
623   std::vector<Binding>   bufferBindings{};
624   std::vector<Attribute> attributes{};
625 };
626
627 /**
628  * @brief List of all possible formats
629  * Not all formats may be supported
630  */
631 enum class Format
632 {
633   UNDEFINED,
634   // GLES compatible, luminance doesn't exist in Vulkan
635   L8,
636   L8A8,
637
638   // Vulkan compatible
639   R4G4_UNORM_PACK8,
640   R4G4B4A4_UNORM_PACK16,
641   B4G4R4A4_UNORM_PACK16,
642   R5G6B5_UNORM_PACK16,
643   B5G6R5_UNORM_PACK16,
644   R5G5B5A1_UNORM_PACK16,
645   B5G5R5A1_UNORM_PACK16,
646   A1R5G5B5_UNORM_PACK16,
647   R8_UNORM,
648   R8_SNORM,
649   R8_USCALED,
650   R8_SSCALED,
651   R8_UINT,
652   R8_SINT,
653   R8_SRGB,
654   R8G8_UNORM,
655   R8G8_SNORM,
656   R8G8_USCALED,
657   R8G8_SSCALED,
658   R8G8_UINT,
659   R8G8_SINT,
660   R8G8_SRGB,
661   R8G8B8_UNORM,
662   R8G8B8_SNORM,
663   R8G8B8_USCALED,
664   R8G8B8_SSCALED,
665   R8G8B8_UINT,
666   R8G8B8_SINT,
667   R8G8B8_SRGB,
668   B8G8R8_UNORM,
669   B8G8R8_SNORM,
670   B8G8R8_USCALED,
671   B8G8R8_SSCALED,
672   B8G8R8_UINT,
673   B8G8R8_SINT,
674   B8G8R8_SRGB,
675   R8G8B8A8_UNORM,
676   R8G8B8A8_SNORM,
677   R8G8B8A8_USCALED,
678   R8G8B8A8_SSCALED,
679   R8G8B8A8_UINT,
680   R8G8B8A8_SINT,
681   R8G8B8A8_SRGB,
682   B8G8R8A8_UNORM,
683   B8G8R8A8_SNORM,
684   B8G8R8A8_USCALED,
685   B8G8R8A8_SSCALED,
686   B8G8R8A8_UINT,
687   B8G8R8A8_SINT,
688   B8G8R8A8_SRGB,
689   A8B8G8R8_UNORM_PACK32,
690   A8B8G8R8_SNORM_PACK32,
691   A8B8G8R8_USCALED_PACK32,
692   A8B8G8R8_SSCALED_PACK32,
693   A8B8G8R8_UINT_PACK32,
694   A8B8G8R8_SINT_PACK32,
695   A8B8G8R8_SRGB_PACK32,
696   A2R10G10B10_UNORM_PACK32,
697   A2R10G10B10_SNORM_PACK32,
698   A2R10G10B10_USCALED_PACK32,
699   A2R10G10B10_SSCALED_PACK32,
700   A2R10G10B10_UINT_PACK32,
701   A2R10G10B10_SINT_PACK32,
702   A2B10G10R10_UNORM_PACK32,
703   A2B10G10R10_SNORM_PACK32,
704   A2B10G10R10_USCALED_PACK32,
705   A2B10G10R10_SSCALED_PACK32,
706   A2B10G10R10_UINT_PACK32,
707   A2B10G10R10_SINT_PACK32,
708   R16_UNORM,
709   R16_SNORM,
710   R16_USCALED,
711   R16_SSCALED,
712   R16_UINT,
713   R16_SINT,
714   R16_SFLOAT,
715   R16G16_UNORM,
716   R16G16_SNORM,
717   R16G16_USCALED,
718   R16G16_SSCALED,
719   R16G16_UINT,
720   R16G16_SINT,
721   R16G16_SFLOAT,
722   R16G16B16_UNORM,
723   R16G16B16_SNORM,
724   R16G16B16_USCALED,
725   R16G16B16_SSCALED,
726   R16G16B16_UINT,
727   R16G16B16_SINT,
728   R16G16B16_SFLOAT,
729   R16G16B16A16_UNORM,
730   R16G16B16A16_SNORM,
731   R16G16B16A16_USCALED,
732   R16G16B16A16_SSCALED,
733   R16G16B16A16_UINT,
734   R16G16B16A16_SINT,
735   R16G16B16A16_SFLOAT,
736   R32_UINT,
737   R32_SINT,
738   R32_SFLOAT,
739   R32G32_UINT,
740   R32G32_SINT,
741   R32G32_SFLOAT,
742   R32G32B32_UINT,
743   R32G32B32_SINT,
744   R32G32B32_SFLOAT,
745   R32G32B32A32_UINT,
746   R32G32B32A32_SINT,
747   R32G32B32A32_SFLOAT,
748   R64_UINT,
749   R64_SINT,
750   R64_SFLOAT,
751   R64G64_UINT,
752   R64G64_SINT,
753   R64G64_SFLOAT,
754   R64G64B64_UINT,
755   R64G64B64_SINT,
756   R64G64B64_SFLOAT,
757   R64G64B64A64_UINT,
758   R64G64B64A64_SINT,
759   R64G64B64A64_SFLOAT,
760   B10G11R11_UFLOAT_PACK32,
761   E5B9G9R9_UFLOAT_PACK32,
762   D16_UNORM,
763   X8_D24_UNORM_PACK32,
764   D32_SFLOAT,
765   S8_UINT,
766   D16_UNORM_S8_UINT,
767   D24_UNORM_S8_UINT,
768   D32_SFLOAT_S8_UINT,
769   BC1_RGB_UNORM_BLOCK,
770   BC1_RGB_SRGB_BLOCK,
771   BC1_RGBA_UNORM_BLOCK,
772   BC1_RGBA_SRGB_BLOCK,
773   BC2_UNORM_BLOCK,
774   BC2_SRGB_BLOCK,
775   BC3_UNORM_BLOCK,
776   BC3_SRGB_BLOCK,
777   BC4_UNORM_BLOCK,
778   BC4_SNORM_BLOCK,
779   BC5_UNORM_BLOCK,
780   BC5_SNORM_BLOCK,
781   BC6H_UFLOAT_BLOCK,
782   BC6H_SFLOAT_BLOCK,
783   BC7_UNORM_BLOCK,
784   BC7_SRGB_BLOCK,
785   ETC2_R8G8B8_UNORM_BLOCK,
786   ETC2_R8G8B8_SRGB_BLOCK,
787   ETC2_R8G8B8A1_UNORM_BLOCK,
788   ETC2_R8G8B8A1_SRGB_BLOCK,
789   ETC2_R8G8B8A8_UNORM_BLOCK,
790   ETC2_R8G8B8A8_SRGB_BLOCK,
791   EAC_R11_UNORM_BLOCK,
792   EAC_R11_SNORM_BLOCK,
793   EAC_R11G11_UNORM_BLOCK,
794   EAC_R11G11_SNORM_BLOCK,
795   ASTC_4x4_UNORM_BLOCK,
796   ASTC_4x4_SRGB_BLOCK,
797   ASTC_5x4_UNORM_BLOCK,
798   ASTC_5x4_SRGB_BLOCK,
799   ASTC_5x5_UNORM_BLOCK,
800   ASTC_5x5_SRGB_BLOCK,
801   ASTC_6x5_UNORM_BLOCK,
802   ASTC_6x5_SRGB_BLOCK,
803   ASTC_6x6_UNORM_BLOCK,
804   ASTC_6x6_SRGB_BLOCK,
805   ASTC_8x5_UNORM_BLOCK,
806   ASTC_8x5_SRGB_BLOCK,
807   ASTC_8x6_UNORM_BLOCK,
808   ASTC_8x6_SRGB_BLOCK,
809   ASTC_8x8_UNORM_BLOCK,
810   ASTC_8x8_SRGB_BLOCK,
811   ASTC_10x5_UNORM_BLOCK,
812   ASTC_10x5_SRGB_BLOCK,
813   ASTC_10x6_UNORM_BLOCK,
814   ASTC_10x6_SRGB_BLOCK,
815   ASTC_10x8_UNORM_BLOCK,
816   ASTC_10x8_SRGB_BLOCK,
817   ASTC_10x10_UNORM_BLOCK,
818   ASTC_10x10_SRGB_BLOCK,
819   ASTC_12x10_UNORM_BLOCK,
820   ASTC_12x10_SRGB_BLOCK,
821   ASTC_12x12_UNORM_BLOCK,
822   ASTC_12x12_SRGB_BLOCK,
823   PVRTC1_2BPP_UNORM_BLOCK_IMG,
824   PVRTC1_4BPP_UNORM_BLOCK_IMG,
825   PVRTC2_2BPP_UNORM_BLOCK_IMG,
826   PVRTC2_4BPP_UNORM_BLOCK_IMG,
827   PVRTC1_2BPP_SRGB_BLOCK_IMG,
828   PVRTC1_4BPP_SRGB_BLOCK_IMG,
829   PVRTC2_2BPP_SRGB_BLOCK_IMG,
830   PVRTC2_4BPP_SRGB_BLOCK_IMG,
831 };
832
833 /**
834  * @brief Flags specifying a buffer usage
835  */
836 enum class BufferUsage
837 {
838   TRANSFER_SRC         = 1 << 0,
839   TRANSFER_DST         = 1 << 1,
840   UNIFORM_TEXEL_BUFFER = 1 << 2,
841   STORAGE_TEXEL_BUFFER = 1 << 3,
842   UNIFORM_BUFFER       = 1 << 4,
843   STORAGE_BUFFER       = 1 << 5,
844   INDEX_BUFFER         = 1 << 6,
845   VERTEX_BUFFER        = 1 << 7,
846   INDIRECT_BUFFER      = 1 << 8,
847 };
848
849 using BufferUsageFlags = uint32_t;
850
851 inline BufferUsageFlags operator|(BufferUsageFlags flags, BufferUsage usage)
852 {
853   flags |= static_cast<uint32_t>(usage);
854   return flags;
855 }
856
857 /**
858  * @brief The structure describes memory requirements of GPU resource (texture, buffer)
859  */
860 struct MemoryRequirements
861 {
862   size_t size;
863   size_t alignment;
864 };
865
866 using TextureUpdateFlags = uint32_t;
867 enum class TextureUpdateFlagBits
868 {
869   KEEP_SOURCE = 1 << 0,
870 };
871
872 /**
873  * @brief Texture update info
874  *
875  * Describes the texture update to be executed by
876  * Controller::UpdateTextures()
877  */
878 struct TextureUpdateInfo
879 {
880   Texture* dstTexture{};
881   Offset2D dstOffset2D;
882   uint32_t layer{};
883   uint32_t level{};
884
885   uint32_t srcReference{};
886   Extent2D srcExtent2D{};
887   uint32_t srcOffset{};
888   uint32_t srcSize{};
889 };
890
891 /**
892  * @brief Texture update source info
893  *
894  * Describes the source of data (memory, buffer or another texture)
895  * to be used when updating textures using Controller::UpdateTextures().
896  */
897 struct TextureUpdateSourceInfo
898 {
899   enum class Type
900   {
901     BUFFER,
902     MEMORY,
903     TEXTURE
904   };
905
906   Type sourceType;
907
908   struct BufferSource
909   {
910     Buffer* buffer;
911   } bufferSource;
912
913   struct MemorySource
914   {
915     void* memory;
916   } memorySource;
917
918   struct TextureSource
919   {
920     Texture* texture;
921   } textureSource;
922 };
923
924 /**
925  * @brief Properties of texture
926  */
927 struct TextureProperties
928 {
929   Format   format;                   ///< Texture format
930   Format   format1;                  ///< Texture format (if emulated)
931   bool     emulated;                 ///< Format is emulated (for example RGB as RGBA)
932   bool     compressed;               ///< Texture is compressed
933   bool     packed;                   ///< Texture is packed
934   Extent2D extent2D;                 ///< Size of texture
935   bool     directWriteAccessEnabled; ///< Direct write access (mappable textures)
936 };
937
938 /**
939  * @brief Texture tiling that directly refers to the tiling
940  * mode supported by the Vulkan. Other implementations
941  * of the backend may ignore the value.
942  */
943 enum class TextureTiling
944 {
945   OPTIMAL,
946   LINEAR
947 };
948
949 /**
950  * @brief Texture color attachment used by FramebufferCreateInfo
951  */
952 struct ColorAttachment
953 {
954   uint32_t attachmentId;
955   Texture* texture;
956   uint32_t layerId;
957   uint32_t levelId;
958 };
959
960 /**
961  * @brief Depth stencil attachment used by FramebufferCreateInfo
962  */
963 struct DepthStencilAttachment
964 {
965   // TODO:
966 };
967
968 /**
969  * @brief Submit flags
970  */
971 using SubmitFlags = uint32_t;
972
973 /**
974  * Submit flag bits
975  */
976 enum class SubmitFlagBits : uint32_t
977 {
978   FLUSH         = 1 << 0, // Flush immediately
979   DONT_OPTIMIZE = 1 << 1  // Tells controller not to optimize commands
980 };
981
982 template<typename T>
983 inline SubmitFlags operator|(T flags, SubmitFlagBits bit)
984 {
985   return static_cast<SubmitFlags>(flags) | static_cast<SubmitFlags>(bit);
986 }
987
988 /**
989  * @brief Describes command buffers submission
990  */
991 struct SubmitInfo
992 {
993   std::vector<CommandBuffer*> cmdBuffer;
994   SubmitFlags                 flags;
995 };
996
997 /**
998  * @brief Shader language enum
999  */
1000 enum class ShaderLanguage
1001 {
1002   GLSL_1,
1003   GLSL_3_1,
1004   GLSL_3_2,
1005   SPIRV_1_0,
1006   SPIRV_1_1,
1007 };
1008
1009 /**
1010  * @brief Pipeline stages
1011  */
1012 enum class PipelineStage
1013 {
1014   TOP_OF_PIPELINE,
1015   VERTEX_SHADER,
1016   GEOMETRY_SHADER,
1017   FRAGMENT_SHADER,
1018   COMPUTE_SHADER,
1019   TESSELATION_CONTROL,
1020   TESSELATION_EVALUATION,
1021   BOTTOM_OF_PIPELINE
1022 };
1023
1024 /**
1025  * @brief Vertex attribute format
1026  *
1027  * TODO: to be replaced with Format
1028  */
1029 enum class VertexInputAttributeFormat
1030 {
1031   UNDEFINED,
1032   FLOAT,
1033   INTEGER,
1034   VEC2,
1035   VEC3,
1036   VEC4
1037 };
1038
1039 /**
1040  * @brief Type of texture
1041  */
1042 enum class TextureType
1043 {
1044   TEXTURE_2D,
1045   TEXTURE_3D,
1046   TEXTURE_CUBEMAP,
1047 };
1048
1049 /**
1050  * @brief Describes pipeline's shading stages
1051  *
1052  * Shader state binds shader and pipeline stage that the
1053  * shader will be executed. The shader may be created with
1054  * pipeline stage and the pipelineStage member may be ignored
1055  * by setting inheritPipelineStage to true.
1056  */
1057 struct ShaderState
1058 {
1059   const Shader* shader{nullptr};             // shader to attach
1060   PipelineStage pipelineStage{};             // pipeline stage to execute the shader
1061   bool          inheritPipelineStage{false}; // stage inheritance
1062
1063   auto& SetShader(const Shader& value)
1064   {
1065     shader = &value;
1066     return *this;
1067   }
1068
1069   auto& SetPipelineStage(PipelineStage value)
1070   {
1071     pipelineStage = value;
1072     return *this;
1073   }
1074
1075   auto& SetInheritPipelineStage(bool value)
1076   {
1077     inheritPipelineStage = value;
1078     return *this;
1079   }
1080 };
1081
1082 /**
1083  * @brief Flag determining usage of texture
1084  */
1085 using TextureUsageFlags = uint32_t;
1086 enum class TextureUsageFlagBits : uint32_t
1087 {
1088   SAMPLE                   = 1 << 0,
1089   COLOR_ATTACHMENT         = 1 << 1,
1090   DEPTH_STENCIL_ATTACHMENT = 1 << 2,
1091   DONT_CARE                = 1 << 4,
1092 };
1093
1094 template<typename T>
1095 inline TextureUsageFlags operator|(T flags, TextureUsageFlagBits bit)
1096 {
1097   return static_cast<TextureUsageFlags>(flags) | static_cast<TextureUsageFlags>(bit);
1098 }
1099
1100 using TextureFormat = Dali::Graphics::Format;
1101
1102 /**
1103  * @brief Texture mipmap disable/enable enum
1104  */
1105 enum class TextureMipMapFlag
1106 {
1107   ENABLED,
1108   DISABLED,
1109 };
1110
1111 /**
1112  * @brief Depth/stencil attachment flag
1113  */
1114 enum class TextureDepthStencilFlag
1115 {
1116   NONE,
1117   DEPTH,
1118   STENCIL,
1119   DEPTH_STENCIL,
1120 };
1121
1122 /**
1123  * @brief Layout of texture
1124  *
1125  * Specifies how the memory will be allocated, organized and accessed.
1126  */
1127 enum class TextureLayout
1128 {
1129   LINEAR, ///< Creates linear memory, mapping possible
1130   OPTIMAL ///< Usually, read-only memory, driver-optimal layout
1131 };
1132
1133 /**
1134  * @brief Level of command buffer
1135  */
1136 enum class CommandBufferLevel
1137 {
1138   PRIMARY,  ///< Primary buffer can be executed on its own
1139   SECONDARY ///< Secondary buffer must be executed within scope of Primary buffer
1140 };
1141
1142 /**
1143  * @brief Enum indicating whether shader source
1144  * is text-based or binary.
1145  */
1146 enum class ShaderSourceMode
1147 {
1148   TEXT,
1149   BINARY
1150 };
1151
1152 /**
1153  * @brief Memory usage flags to be set when mapping the buffer
1154  */
1155 using MemoryUsageFlags = uint32_t;
1156 enum class MemoryUsageFlagBits : uint32_t
1157 {
1158   WRITE        = 1 << 0,
1159   READ         = 1 << 1,
1160   PERSISTENT   = 1 << 2,
1161   ASYNCHRONOUS = 1 << 3,
1162   DONT_CARE    = 1 << 4,
1163 };
1164
1165 template<typename T>
1166 inline MemoryUsageFlags operator|(T flags, MemoryUsageFlagBits bit)
1167 {
1168   return static_cast<MemoryUsageFlags>(flags) | static_cast<MemoryUsageFlags>(bit);
1169 }
1170
1171 /**
1172  * @brief Describes buffer mapping details
1173  */
1174 struct MapBufferInfo
1175 {
1176   Buffer*          buffer;
1177   MemoryUsageFlags usage;
1178   uint32_t         offset;
1179   uint32_t         size;
1180 };
1181
1182 /**
1183  * @brief Describes buffer mapping details
1184  * TODO: mapping by texture level and layer
1185  */
1186 struct MapTextureInfo
1187 {
1188   Texture*         texture;
1189   MemoryUsageFlags usage;
1190   uint32_t         offset;
1191   uint32_t         size;
1192 };
1193
1194 /**
1195  * @brief GraphicsStructureType enum is used by all create info structures
1196  * in order to identify by the implementation which structure it is
1197  * dealing with.
1198  */
1199 enum class GraphicsStructureType : uint32_t
1200 {
1201   BUFFER_CREATE_INFO_STRUCT,
1202   COMMAND_BUFFER_CREATE_INFO_STRUCT,
1203   FRAMEBUFFER_CREATE_INFO_STRUCT,
1204   PIPELINE_CREATE_INFO_STRUCT,
1205   RENDERPASS_CREATE_INFO_STRUCT,
1206   SAMPLER_CREATE_INFO_STRUCT,
1207   SHADER_CREATE_INFO_STRUCT,
1208   TEXTURE_CREATE_INFO_STRUCT,
1209   RENDER_TARGET_CREATE_INFO_STRUCT
1210 };
1211
1212 /**
1213  * @brief Helper function to be used by the extension developers
1214  *
1215  * The value of custom type must be unique and recognizable by the
1216  * implementation.
1217  *
1218  * @param customValue Custom value of GraphicsStructureType
1219  * @return Integer converted to GraphicsStructureType
1220  */
1221 inline GraphicsStructureType GraphicsExtensionType(uint32_t customValue)
1222 {
1223   return static_cast<GraphicsStructureType>(customValue);
1224 }
1225
1226 /**
1227  * @brief The allocation callbacks may be passed when the object is created.
1228  */
1229 struct AllocationCallbacks
1230 {
1231   void* userData                                                                          = nullptr; ///< User data passed to the allocator
1232   void* (*allocCallback)(size_t size, size_t alignment, void* userData)                   = nullptr;
1233   void* (*reallocCallback)(void* original, size_t size, size_t alignment, void* userData) = nullptr;
1234   void (*freeCallback)(void* memory, void* userData)                                      = nullptr;
1235 };
1236
1237 /**
1238  * @brief The ExtensionCreateInfo structure should be a base of any
1239  * extension create info structure. The structure isn't virtual
1240  * so the implementation must prevent slicing it.
1241  */
1242 struct ExtensionCreateInfo
1243 {
1244   GraphicsStructureType type{};
1245   ExtensionCreateInfo*  nextExtension{};
1246 };
1247
1248 } // namespace Graphics
1249 } // namespace Dali
1250
1251 #endif //DALI_GRAPHICS_API_TYPES_H