Merge branch 'devel/master' into devel/new_mesh
[platform/core/uifw/dali-core.git] / dali / devel-api / rendering / geometry.h
1 #ifndef DALI_GEOMETRY_H
2 #define DALI_GEOMETRY_H
3
4 /*
5  * Copyright (c) 2015 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
24 // INTERNAL INCLUDES
25 #include <dali/public-api/object/handle.h> // Dali::Handle
26 #include <dali/public-api/object/property-index-ranges.h> // DEFAULT_DERIVED_HANDLE_PROPERTY_START_INDEX
27 #include <dali/devel-api/object/property-buffer.h> // Dali::PropertyBuffer
28
29 namespace Dali
30 {
31
32 namespace Internal DALI_INTERNAL
33 {
34 class Geometry;
35 }
36
37 /**
38  * @brief Geometry is handle to an object that can be used to define a geometric elements.
39  */
40 class DALI_IMPORT_API Geometry : public Handle
41 {
42 public:
43
44   enum GeometryType
45   {
46     POINTS,
47     LINES,
48     LINE_LOOP,
49     LINE_STRIP,
50     TRIANGLES,
51     TRIANGLE_FAN,
52     TRIANGLE_STRIP
53   };
54
55   /**
56    * @brief An enumeration of properties belonging to the Geometry class.
57    */
58   struct Property
59   {
60     enum
61     {
62       GEOMETRY_TYPE = DEFAULT_OBJECT_PROPERTY_START_INDEX,  ///< name "depth-index",            type STRING
63       GEOMETRY_CENTER,                                      ///< name "geometry-center",        type VECTOR3
64       GEOMETRY_HALF_EXTENTS,                                ///< name "geometry-half-extents",  type VECTOR3
65       REQUIRES_DEPTH_TEST,                                  ///< name "requires-depth-testing", type BOOLEAN
66     };
67   };
68
69   /**
70    * @brief Creates a new Geometry object
71    *
72    * @return An handle to a newly allocated Geometry
73    */
74   static Geometry New();
75
76   /**
77    * @brief Default constructor, creates an empty handle
78    */
79   Geometry();
80
81   /**
82    * @brief Destructor
83    */
84   ~Geometry();
85
86   /**
87    * @brief Copy constructor, creates a new handle to the same object
88    *
89    * @param[in] handle Handle to an object
90    */
91   Geometry( const Geometry& handle );
92
93   /**
94    * @brief Downcast to a geometry.
95    *
96    * If not the returned handle is left uninitialized.
97    * @param[in] handle to an object
98    * @return geometry handle or an uninitialized handle
99    */
100   static Geometry DownCast( BaseHandle handle );
101
102   /**
103    * @brief Assignment operator, changes this handle to point at the same object
104    *
105    * @param[in] handle Handle to an object
106    * @return Reference to the assigned object
107    */
108   Geometry& operator=( const Geometry& handle );
109
110   /**
111    * @brief Add a PropertyBuffer to be used as source of geometry vertices
112    *
113    * @param[in] vertexBuffer PropertyBuffer to be used as source of geometry vertices
114    * @return Index of the newly added buffer, can be used with RemoveVertexBuffer to remove
115    *         this buffer if no longer required
116    */
117   std::size_t AddVertexBuffer( PropertyBuffer& vertexBuffer );
118
119   /**
120    * @brief Retrieve the number of vertex buffers that have been added to this geometry
121    *
122    * @return Number of vertex buffers that have been added to this geometry
123    */
124   std::size_t GetNumberOfVertexBuffers() const;
125
126   /**
127    * @brief Remove a vertex buffer
128    *
129    * The index must be between 0 and GetNumberOfVertexBuffers()
130    *
131    * @param[in] index Index to the vertex buffer to remove
132    */
133   void RemoveVertexBuffer( std::size_t index );
134
135   /**
136    * @brief Set a PropertyBuffer to be used as a source of indices for the geometry
137    *
138    * This buffer is required to have exactly one component and it must be of the type Property::INTEGER
139    *
140    * By setting this buffer the will case the geometry to be rendered using indices.
141    * To unset call SetIndexBuffer with an empty handle.
142    *
143    * @param[in] indexBuffer PropertyBuffer to be used as a source of indices for the geometry
144    */
145   void SetIndexBuffer( PropertyBuffer& indexBuffer );
146
147   /**
148    * @brief Set the type of primitives this geometry contains
149    *
150    * @param[in] geometryType Type of primitives this geometry contains
151    */
152   void SetGeometryType( GeometryType geometryType );
153
154   /**
155    * @brief Get the type of primitives this geometry contains
156    *
157    * Calling this function sets the property GEOMETRY_TYPE
158    *
159    * @return Type of primitives this geometry contains
160    */
161   GeometryType GetGeometryType() const;
162
163   /**
164    * @brief Set if the geometry requires depth testing
165    *
166    * Should be set to true if this geometry has overlapping triangles in arbitrary order
167    *
168    * Calling this function is equivalent to setting the REQUIRES_DEPTH_TESTING property
169    *
170    * @param[in] requiresDepthTest Specifies if the geometry requires depth testing
171    */
172   void SetRequiresDepthTesting( bool requiresDepthTest );
173
174   /**
175    * @brief Return if the geometry requires depth testing
176    *
177    * @return True if the geometry requires depth testing
178    */
179   bool GetRequiresDepthTesting() const;
180
181 public:
182   /**
183    * @brief The constructor
184    *
185    * @param [in] pointer A pointer to a newly allocated Geometry
186    */
187   explicit DALI_INTERNAL Geometry( Internal::Geometry* pointer );
188 };
189
190 } //namespace Dali
191
192 #endif // DALI_GEOMETRY_H