d0a37eff738d4781d63c3fae8260fb7c133a63f2
[platform/core/uifw/dali-core.git] / dali / internal / update / geometry / scene-graph-geometry.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_GEOMETRY_H
2 #define DALI_INTERNAL_SCENE_GRAPH_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 #include <dali/public-api/geometry/geometry.h>
21 #include <dali/internal/common/event-to-update.h>
22 #include <dali/internal/update/common/animatable-property.h>
23 #include <dali/internal/update/common/double-buffered.h>
24 #include <dali/internal/update/common/property-owner.h>
25 #include <dali/internal/update/common/property-boolean.h>
26 #include <dali/internal/update/common/scene-graph-property-buffer.h>
27 #include <dali/internal/render/data-providers/geometry-data-provider.h>
28
29 namespace Dali
30 {
31 namespace Internal
32 {
33 namespace SceneGraph
34 {
35
36 /**
37  * This scene graph object is a property owner. It describes a geometry using a
38  * number of PropertyBuffers acting as Vertex buffers.
39  */
40 class Geometry : public PropertyOwner, public GeometryDataProvider
41 {
42 public:
43
44   /**
45    * Constructor
46    */
47   Geometry();
48
49   /**
50    * Destructor
51    */
52   ~Geometry();
53
54   /**
55    * Add a property buffer to be used as a vertex buffer
56    */
57   void AddVertexBuffer( PropertyBuffer* vertexBuffer );
58
59   /**
60    * Remove a property buffer to be used as a vertex buffer
61    * @param[in] vertexBuffer the associated vertex buffer to remove
62    */
63   void RemoveVertexBuffer( PropertyBuffer* vertexBuffer );
64
65   /**
66    * Set the buffer to be used as a source of indices for the geometry
67    * @param[in] indexBuffer the Property buffer describing the indexes for Line, Triangle tyes.
68    */
69   void SetIndexBuffer( PropertyBuffer* indexBuffer );
70
71   /**
72    * Clear the index buffer if it is no longer required, e.g. if changing geometry type
73    * to POINTS.
74    */
75   void ClearIndexBuffer();
76
77   /**
78    * Set the type of geometry to draw (Points, Lines, Triangles, etc)
79    * @param[in] geometryType The geometry type
80    */
81   void SetGeometryType( BufferIndex bufferIndex, GeometryType geometryType );
82
83 public: // GeometryDataProvider
84   /**
85    * Get the vertex buffers of the geometry
86    * @return A const reference to the vertex buffers
87    */
88   virtual const GeometryDataProvider::VertexBuffers& GetVertexBuffers() const;
89
90   /**
91    * Get the index buffer of the geometry
92    * @return A const pointer to the index buffer if it exists, or NULL if it doesn't.
93    */
94   virtual const PropertyBuffer* GetIndexBuffer() const;
95
96   /**
97    * Get the type of geometry to draw
98    */
99   virtual GeometryType GetGeometryType( BufferIndex bufferIndex ) const;
100
101     /**
102    * Returns true if this geometry requires depth testing, e.g. if it is
103    * a set of vertices with z != 0
104    */
105   virtual bool GetRequiresDepthTest( BufferIndex bufferIndex ) const;
106
107 private:
108   VertexBuffers mVertexBuffers; ///< The vertex buffers
109   OwnerPointer<PropertyBuffer> mIndexBuffer;  ///< The index buffer if required
110
111 private: // Properties
112   //DoubleBufferedProperty<Vector3>       mCenter;
113   //DoubleBufferedProperty<Vector3>       mHalfExtents;
114   //DoubleBufferedProperty<GeometryType>  mGeometryType;   ///< The type of geometry (tris/lines etc)
115   //DoubleBufferedProperty<bool>          mRequiresDepthTest;
116
117   AnimatableProperty<Vector3>  mCenter;
118   AnimatableProperty<Vector3>  mHalfExtents;
119   AnimatableProperty<int>      mGeometryType;   ///< The type of geometry (tris/lines etc)
120   PropertyBoolean              mRequiresDepthTest;
121 };
122
123 inline void AddVertexBufferMessage( EventToUpdate& eventToUpdate, const Geometry& geometry, PropertyBuffer& vertexBuffer )
124 {
125   typedef MessageValue1< Geometry, OwnerPointer<PropertyBuffer> > LocalType;
126
127   // Reserve some memory inside the message queue
128   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
129
130   // Construct message in the message queue memory; note that delete should not be called on the return value
131   new (slot) LocalType( &geometry, &Geometry::AddVertexBuffer, &vertexBuffer );
132 }
133
134 inline void RemoveVertexBufferMessage( EventToUpdate& eventToUpdate, const Geometry& geometry, PropertyBuffer& vertexBuffer )
135 {
136   typedef MessageValue1< Geometry, PropertyBuffer* > LocalType;
137
138   // Reserve some memory inside the message queue
139   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
140
141   // Construct message in the message queue memory; note that delete should not be called on the return value
142   new (slot) LocalType( &geometry, &Geometry::RemoveVertexBuffer, &vertexBuffer );
143 }
144
145 inline void SetIndexBufferMessage( EventToUpdate& eventToUpdate, const Geometry& geometry, PropertyBuffer& indexBuffer )
146 {
147   typedef MessageValue1< Geometry, OwnerPointer< PropertyBuffer > > LocalType;
148
149   // Reserve some memory inside the message queue
150   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
151
152   // Construct message in the message queue memory; note that delete should not be called on the return value
153   new (slot) LocalType( &geometry, &Geometry::SetIndexBuffer, &indexBuffer );
154 }
155
156 inline void ClearIndexBufferMessage( EventToUpdate& eventToUpdate, const Geometry& geometry )
157 {
158   typedef Message< Geometry > LocalType;
159
160   // Reserve some memory inside the message queue
161   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
162
163   // Construct message in the message queue memory; note that delete should not be called on the return value
164   new (slot) LocalType( &geometry, &Geometry::ClearIndexBuffer );
165 }
166
167 } // namespace SceneGraph
168
169 // Declare enum as a message parameter type
170 template <> struct ParameterType< SceneGraph::Geometry::GeometryType > : public BasicType< SceneGraph::Geometry::GeometryType > {};
171
172 namespace SceneGraph
173 {
174
175 inline void SetGeometryTypeMessage( EventToUpdate& eventToUpdate, const Geometry& geometry, SceneGraph::Geometry::GeometryType geometryType )
176 {
177   typedef MessageDoubleBuffered1< Geometry, SceneGraph::Geometry::GeometryType > LocalType;
178
179   // Reserve some memory inside the message queue
180   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
181
182   // Construct message in the message queue memory; note that delete should not be called on the return value
183   new (slot) LocalType( &geometry, &Geometry::SetGeometryType, geometryType );
184 }
185
186 } // namespace SceneGraph
187 } // namespace Internal
188 } // namespace Dali
189
190 #endif // DALI_INTERNAL_SCENE_GRAPH_GEOMETRY_H