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/devel-api/rendering/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>
31 #include <dali/internal/render/data-providers/render-data-provider.h>
39 class SceneController;
43 * This scene graph object is a property owner. It describes a geometry using a
44 * number of PropertyBuffers acting as Vertex buffers.
46 class Geometry : public PropertyOwner, public GeometryDataProvider, public UniformMap::Observer
61 * Add a property buffer to be used as a vertex buffer
63 void AddVertexBuffer( PropertyBuffer* vertexBuffer );
66 * Remove a property buffer to be used as a vertex buffer
67 * @param[in] vertexBuffer the associated vertex buffer to remove
69 void RemoveVertexBuffer( PropertyBuffer* vertexBuffer );
72 * Set the buffer to be used as a source of indices for the geometry
73 * @param[in] indexBuffer the Property buffer describing the indexes for Line, Triangle tyes.
75 void SetIndexBuffer( PropertyBuffer* indexBuffer );
78 * Clear the index buffer if it is no longer required, e.g. if changing geometry type
81 void ClearIndexBuffer();
84 * Set the type of geometry to draw (Points, Lines, Triangles, etc)
85 * @param[in] bufferIndex Index for double buffered values
86 * @param[in] geometryType The geometry type
88 void SetGeometryType( BufferIndex bufferIndex, GeometryType geometryType );
91 * Connect the object to the scene graph
93 * @param[in] sceneController The scene controller - used for sending messages to render thread
94 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
96 void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
99 * Disconnect the object from the scene graph
100 * @param[in] sceneController The scene controller - used for sending messages to render thread
101 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
103 void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
106 * @copydoc ConnectionObservers::AddObserver
108 void AddConnectionObserver(ConnectionChangePropagator::Observer& observer);
111 * @copydoc ConnectionObservers::RemoveObserver
113 void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer);
115 public: // UniformMap::Observer
117 * @copydoc UniformMap::Observer::UniformMappingsChanged
119 virtual void UniformMappingsChanged( const UniformMap& mappings );
122 * Get the vertex buffers of the geometry
123 * @return A const reference to the vertex buffers
125 Vector<PropertyBuffer*>& GetVertexBuffers();
128 * Get the index buffer of the geometry
129 * @return A pointer to the index buffer if it exists, or NULL if it doesn't.
131 PropertyBuffer* GetIndexBuffer();
134 * Gets the associated RenderGeometry
135 * @param[in] sceneController The scene controller
136 * @return The RenderGeometry associated to this Geometry
138 RenderGeometry* GetRenderGeometry(SceneController* sceneController);
141 * Called from renderers using this geometry when they get disconnected from the scenegraph
143 void OnRendererDisconnect();
146 public: // GeometryDataProvider
148 * Get the type of geometry to draw
149 * @param[in] bufferIndex Index for double buffered values
151 virtual GeometryType GetGeometryType( BufferIndex bufferIndex ) const;
154 * Returns true if this geometry requires depth testing, e.g. if it is
155 * a set of vertices with z != 0
156 * @param[in] bufferIndex Index for double buffered values
158 virtual bool GetRequiresDepthTesting( BufferIndex bufferIndex ) const;
160 protected: // From PropertyOwner
162 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
164 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
169 * @brief Calculate the extents of geometry contained in a vertex buffer.
171 * @param[in] vertexBuffer pointer to a vertex buffer.
173 void CalculateExtents( PropertyBuffer* vertexBuffer );
175 Vector<PropertyBuffer*> mVertexBuffers; ///< The vertex buffers
176 PropertyBuffer* mIndexBuffer; ///< The index buffer if required
177 ConnectionChangePropagator mConnectionObservers;
179 RenderGeometry* mRenderGeometry;
180 SceneController* mSceneController;
181 unsigned int mRendererRefCount;
183 public: // Properties
184 AnimatableProperty<Vector3> mCenter;
185 AnimatableProperty<Vector3> mHalfExtents;
186 AnimatableProperty<float> mRadius;
187 DoubleBufferedProperty<int> mGeometryType;
188 DoubleBufferedProperty<bool> mRequiresDepthTest;
191 inline void AddVertexBufferMessage( EventThreadServices& eventThreadServices , const Geometry& geometry, const PropertyBuffer& vertexBuffer )
193 typedef MessageValue1< Geometry, PropertyBuffer* > LocalType;
195 // Reserve some memory inside the message queue
196 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
198 // Construct message in the message queue memory; note that delete should not be called on the return value
199 new (slot) LocalType( &geometry, &Geometry::AddVertexBuffer, const_cast<PropertyBuffer*>(&vertexBuffer) );
202 inline void RemoveVertexBufferMessage( EventThreadServices& eventThreadServices, const Geometry& geometry, const PropertyBuffer& vertexBuffer )
204 typedef MessageValue1< Geometry, PropertyBuffer* > LocalType;
206 // Reserve some memory inside the message queue
207 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
209 // Construct message in the message queue memory; note that delete should not be called on the return value
210 new (slot) LocalType( &geometry, &Geometry::RemoveVertexBuffer, const_cast<PropertyBuffer*>(&vertexBuffer) );
213 inline void SetIndexBufferMessage( EventThreadServices& eventThreadServices, const Geometry& geometry, const PropertyBuffer& indexBuffer )
215 typedef MessageValue1< Geometry, PropertyBuffer* > LocalType;
217 // Reserve some memory inside the message queue
218 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
220 // Construct message in the message queue memory; note that delete should not be called on the return value
221 new (slot) LocalType( &geometry, &Geometry::SetIndexBuffer, const_cast<PropertyBuffer*>(&indexBuffer) );
224 inline void ClearIndexBufferMessage( EventThreadServices& eventThreadServices, const Geometry& geometry )
226 typedef Message< Geometry > LocalType;
228 // Reserve some memory inside the message queue
229 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
231 // Construct message in the message queue memory; note that delete should not be called on the return value
232 new (slot) LocalType( &geometry, &Geometry::ClearIndexBuffer );
235 } // namespace SceneGraph
237 // Declare enum as a message parameter type
238 template <> struct ParameterType< SceneGraph::Geometry::GeometryType > : public BasicType< SceneGraph::Geometry::GeometryType > {};
243 inline void SetGeometryTypeMessage( EventThreadServices& eventThreadServices, const Geometry& geometry, SceneGraph::Geometry::GeometryType geometryType )
245 typedef MessageDoubleBuffered1< Geometry, SceneGraph::Geometry::GeometryType > LocalType;
247 // Reserve some memory inside the message queue
248 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
250 // Construct message in the message queue memory; note that delete should not be called on the return value
251 new (slot) LocalType( &geometry, &Geometry::SetGeometryType, geometryType );
254 } // namespace SceneGraph
255 } // namespace Internal
258 #endif // DALI_INTERNAL_SCENE_GRAPH_GEOMETRY_H