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