Allow to load uint32_t indices for geometry
[platform/core/uifw/dali-core.git] / dali / public-api / rendering / geometry.h
1 #ifndef DALI_GEOMETRY_H
2 #define DALI_GEOMETRY_H
3
4 /*
5  * Copyright (c) 2023 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 <cstddef> // std::size_t
23 #include <cstdint> // uint16_t
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/object/handle.h>                // Dali::Handle
27 #include <dali/public-api/object/property-index-ranges.h> // DEFAULT_DERIVED_HANDLE_PROPERTY_START_INDEX
28 #include <dali/public-api/rendering/vertex-buffer.h>      // Dali::VertexBuffer
29
30 namespace Dali
31 {
32 /**
33  * @addtogroup dali_core_rendering_effects
34  * @{
35  */
36
37 namespace Internal DALI_INTERNAL
38 {
39 class Geometry;
40 }
41
42 /**
43  * @brief Geometry is handle to an object that can be used to define a geometric elements.
44  *
45  * @SINCE_1_1.43
46  */
47 class DALI_CORE_API Geometry : public BaseHandle
48 {
49 public:
50   /**
51    * @brief Enumeration for the description of the type of geometry, used to determine how the coordinates will be used.
52    * @SINCE_1_1.45
53    */
54   enum Type
55   {
56     POINTS,        ///< Individual points                                                                                          @SINCE_1_1.45
57     LINES,         ///< Individual lines (made of 2 points each)                                                                   @SINCE_1_1.45
58     LINE_LOOP,     ///< A strip of lines (made of 1 point each) which also joins the first and last point                          @SINCE_1_1.45
59     LINE_STRIP,    ///< A strip of lines (made of 1 point each)                                                                    @SINCE_1_1.45
60     TRIANGLES,     ///< Individual triangles (made of 3 points each)                                                               @SINCE_1_1.45
61     TRIANGLE_FAN,  ///< A fan of triangles around a centre point (after the first triangle, following triangles need only 1 point) @SINCE_1_1.45
62     TRIANGLE_STRIP ///< A strip of triangles (after the first triangle, following triangles need only 1 point)                     @SINCE_1_1.45
63   };
64
65   /**
66    * @brief Creates a new Geometry object.
67    *
68    * @SINCE_1_1.43
69    * @return A handle to a newly allocated Geometry object
70    */
71   static Geometry New();
72
73   /**
74    * @brief Default constructor, creates an empty handle.
75    *
76    * @SINCE_1_1.43
77    */
78   Geometry();
79
80   /**
81    * @brief Destructor.
82    *
83    * @SINCE_1_1.43
84    */
85   ~Geometry();
86
87   /**
88    * @brief Copy constructor, creates a new handle to the same object.
89    *
90    * @SINCE_1_1.43
91    * @param[in] handle Handle to an object
92    */
93   Geometry(const Geometry& handle);
94
95   /**
96    * @brief Downcasts to a geometry.
97    * If not, the returned handle is left uninitialized.
98    *
99    * @SINCE_1_1.43
100    * @param[in] handle Handle to an object
101    * @return Geometry handle or an uninitialized handle
102    */
103   static Geometry DownCast(BaseHandle handle);
104
105   /**
106    * @brief Assignment operator, changes this handle to point at the same object.
107    *
108    * @SINCE_1_1.43
109    * @param[in] handle Handle to an object
110    * @return Reference to the assigned object
111    */
112   Geometry& operator=(const Geometry& handle);
113
114   /**
115    * @brief Move constructor.
116    *
117    * @SINCE_1_9.22
118    * @param[in] rhs A reference to the moved handle
119    */
120   Geometry(Geometry&& rhs);
121
122   /**
123    * @brief Move assignment operator.
124    *
125    * @SINCE_1_9.22
126    * @param[in] rhs A reference to the moved handle
127    * @return A reference to this handle
128    */
129   Geometry& operator=(Geometry&& rhs);
130
131   /**
132    * @brief Adds a VertexBuffer to be used as source of geometry vertices.
133    *
134    * @SINCE_1_9.27
135    * @param[in] vertexBuffer VertexBuffer to be used as source of geometry vertices
136    * @return Index of the newly added buffer, can be used with RemoveVertexBuffer to remove
137    *         this buffer if no longer required
138    */
139   std::size_t AddVertexBuffer(VertexBuffer& vertexBuffer);
140
141   /**
142    * @brief Retrieves the number of vertex buffers that have been added to this geometry.
143    *
144    * @SINCE_1_9.27
145    * @return Number of vertex buffers that have been added to this geometry
146    */
147   std::size_t GetNumberOfVertexBuffers() const;
148
149   /**
150    * @brief Removes a vertex buffer.
151    * The index must be between 0 and GetNumberOfVertexBuffers().
152    *
153    * @SINCE_1_9.27
154    * @param[in] index Index to the vertex buffer to remove
155    */
156   void RemoveVertexBuffer(std::size_t index);
157
158   /**
159    * @brief Sets the index data to be used as a source of indices for the geometry
160    * Setting this buffer will cause the geometry to be rendered using indices.
161    * To unset call SetIndexBuffer with a null pointer or count 0.
162    *
163    * @SINCE_1_1.43
164    * @param[in] indices Array of indices
165    * @param[in] count Number of indices in the array
166    */
167   void SetIndexBuffer(const uint16_t* indices, size_t count);
168
169   /**
170    * @brief Sets the 32bits index data to be used as a source of indices for the geometry
171    * Setting this buffer will cause the geometry to be rendered using indices.
172    * To unset call SetIndexBuffer with a null pointer or count 0.
173    *
174    * @SINCE_2_2.16
175    * @param[in] indices Array of indices with uint32_t elements.
176    * @param[in] count Number of indices in the array
177    */
178   void SetIndexBuffer(const uint32_t* indices, size_t count);
179
180   /**
181    * @brief Sets the type of primitives this geometry contains.
182    *
183    * @SINCE_1_1.43
184    * @param[in] geometryType Type of primitives this geometry contains
185    */
186   void SetType(Type geometryType);
187
188   /**
189    * @brief Gets the type of primitives this geometry contains.
190    * Calling this function sets the property GEOMETRY_TYPE.
191    *
192    * @SINCE_1_1.43
193    * @return Type of primitives this geometry contains
194    */
195   Type GetType() const;
196
197 public:
198   /**
199    * @brief The constructor.
200    * @note  Not intended for application developers.
201    * @SINCE_1_1.43
202    * @param[in] pointer A pointer to a newly allocated Geometry
203    */
204   explicit DALI_INTERNAL Geometry(Internal::Geometry* pointer);
205 };
206
207 /**
208  * @}
209  */
210 } //namespace Dali
211
212 #endif // DALI_GEOMETRY_H