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