1 #ifndef DALI_INTERNAL_SCENE_GRAPH_GEOMETRY_H
2 #define DALI_INTERNAL_SCENE_GRAPH_GEOMETRY_H
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <dali/public-api/geometry/geometry.h>
21 #include <dali/internal/event/common/event-thread-services.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/double-buffered-property.h>
25 #include <dali/internal/update/common/property-owner.h>
26 #include <dali/internal/update/common/property-boolean.h>
27 #include <dali/internal/update/common/uniform-map.h>
28 #include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
29 #include <dali/internal/update/common/scene-graph-property-buffer.h>
30 #include <dali/internal/render/data-providers/geometry-data-provider.h>
38 class SceneController;
41 * This scene graph object is a property owner. It describes a geometry using a
42 * number of PropertyBuffers acting as Vertex buffers.
44 class Geometry : public PropertyOwner, public GeometryDataProvider, public UniformMap::Observer
59 * Add a property buffer to be used as a vertex buffer
61 void AddVertexBuffer( PropertyBuffer* vertexBuffer );
64 * Remove a property buffer to be used as a vertex buffer
65 * @param[in] vertexBuffer the associated vertex buffer to remove
67 void RemoveVertexBuffer( PropertyBuffer* vertexBuffer );
70 * Set the buffer to be used as a source of indices for the geometry
71 * @param[in] indexBuffer the Property buffer describing the indexes for Line, Triangle tyes.
73 void SetIndexBuffer( PropertyBuffer* indexBuffer );
76 * Clear the index buffer if it is no longer required, e.g. if changing geometry type
79 void ClearIndexBuffer();
82 * Set the type of geometry to draw (Points, Lines, Triangles, etc)
83 * @param[in] geometryType The geometry type
85 void SetGeometryType( BufferIndex bufferIndex, GeometryType geometryType );
88 * Connect the object to the scene graph
90 * @param[in] sceneController The scene controller - used for sending messages to render thread
91 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
93 void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
96 * Disconnect the object from the scene graph
97 * @param[in] sceneController The scene controller - used for sending messages to render thread
98 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
100 void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
103 * @copydoc ConnectionObservers::AddObserver
105 void AddConnectionObserver(ConnectionChangePropagator::Observer& observer);
108 * @copydoc ConnectionObservers::RemoveObserver
110 void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer);
112 public: // UniformMap::Observer
114 * @copydoc UniformMap::Observer::UniformMappingsChanged
116 virtual void UniformMappingsChanged( const UniformMap& mappings );
119 * Get the vertex buffers of the geometry
120 * @return A const reference to the vertex buffers
122 Vector<PropertyBuffer*>& GetVertexBuffers();
125 * Get the index buffer of the geometry
126 * @return A pointer to the index buffer if it exists, or NULL if it doesn't.
128 PropertyBuffer* GetIndexBuffer();
130 public: // GeometryDataProvider
132 * Get the type of geometry to draw
134 virtual GeometryType GetGeometryType( BufferIndex bufferIndex ) const;
137 * Returns true if this geometry requires depth testing, e.g. if it is
138 * a set of vertices with z != 0
140 virtual bool GetRequiresDepthTesting( BufferIndex bufferIndex ) const;
142 protected: // From PropertyOwner
144 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
146 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
149 Vector<PropertyBuffer*> mVertexBuffers; ///< The vertex buffers
150 PropertyBuffer* mIndexBuffer; ///< The index buffer if required
151 ConnectionChangePropagator mConnectionObservers;
153 public: // Properties
154 AnimatableProperty<Vector3> mCenter;
155 AnimatableProperty<Vector3> mHalfExtents;
156 DoubleBufferedProperty<int> mGeometryType;
157 DoubleBufferedProperty<bool> mRequiresDepthTest;
160 inline void AddVertexBufferMessage( EventThreadServices& eventThreadServices , const Geometry& geometry, const PropertyBuffer& vertexBuffer )
162 typedef MessageValue1< Geometry, PropertyBuffer* > LocalType;
164 // Reserve some memory inside the message queue
165 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
167 // Construct message in the message queue memory; note that delete should not be called on the return value
168 new (slot) LocalType( &geometry, &Geometry::AddVertexBuffer, const_cast<PropertyBuffer*>(&vertexBuffer) );
171 inline void RemoveVertexBufferMessage( EventThreadServices& eventThreadServices, const Geometry& geometry, const PropertyBuffer& vertexBuffer )
173 typedef MessageValue1< Geometry, PropertyBuffer* > LocalType;
175 // Reserve some memory inside the message queue
176 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
178 // Construct message in the message queue memory; note that delete should not be called on the return value
179 new (slot) LocalType( &geometry, &Geometry::RemoveVertexBuffer, const_cast<PropertyBuffer*>(&vertexBuffer) );
182 inline void SetIndexBufferMessage( EventThreadServices& eventThreadServices, const Geometry& geometry, const PropertyBuffer& indexBuffer )
184 typedef MessageValue1< Geometry, PropertyBuffer* > LocalType;
186 // Reserve some memory inside the message queue
187 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
189 // Construct message in the message queue memory; note that delete should not be called on the return value
190 new (slot) LocalType( &geometry, &Geometry::SetIndexBuffer, const_cast<PropertyBuffer*>(&indexBuffer) );
193 inline void ClearIndexBufferMessage( EventThreadServices& eventThreadServices, const Geometry& geometry )
195 typedef Message< Geometry > LocalType;
197 // Reserve some memory inside the message queue
198 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
200 // Construct message in the message queue memory; note that delete should not be called on the return value
201 new (slot) LocalType( &geometry, &Geometry::ClearIndexBuffer );
204 } // namespace SceneGraph
206 // Declare enum as a message parameter type
207 template <> struct ParameterType< SceneGraph::Geometry::GeometryType > : public BasicType< SceneGraph::Geometry::GeometryType > {};
212 inline void SetGeometryTypeMessage( EventThreadServices& eventThreadServices, const Geometry& geometry, SceneGraph::Geometry::GeometryType geometryType )
214 typedef MessageDoubleBuffered1< Geometry, SceneGraph::Geometry::GeometryType > LocalType;
216 // Reserve some memory inside the message queue
217 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
219 // Construct message in the message queue memory; note that delete should not be called on the return value
220 new (slot) LocalType( &geometry, &Geometry::SetGeometryType, geometryType );
223 } // namespace SceneGraph
224 } // namespace Internal
227 #endif // DALI_INTERNAL_SCENE_GRAPH_GEOMETRY_H