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/property-owner.h>
25 #include <dali/internal/update/common/uniform-map.h>
26 #include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
27 #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 UniformMap::Observer
50 typedef Dali::Geometry::GeometryType GeometryType;
62 * Add a property buffer to be used as a vertex buffer
64 void AddVertexBuffer( Render::PropertyBuffer* vertexBuffer );
67 * Remove a property buffer to be used as a vertex buffer
68 * @param[in] vertexBuffer the associated vertex buffer to remove
70 void RemoveVertexBuffer( Render::PropertyBuffer* vertexBuffer );
73 * Set the buffer to be used as a source of indices for the geometry
74 * @param[in] indexBuffer the Property buffer describing the indexes for Line, Triangle tyes.
76 void SetIndexBuffer( Render::PropertyBuffer* indexBuffer );
79 * Clear the index buffer if it is no longer required, e.g. if changing geometry type
82 void ClearIndexBuffer();
85 * Set the type of geometry to draw (Points, Lines, Triangles, etc)
86 * @param[in] bufferIndex Index for double buffered values
87 * @param[in] geometryType The geometry type
89 void SetGeometryType( GeometryType geometryType );
92 * Set if the geometry requires depth testing
93 * @param[in] requiresDepthTest True if depth testing is required, false otherwise
95 void SetRequiresDepthTest( bool requiresDepthTest );
98 * Connect the object to 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 ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
106 * Disconnect the object from the scene graph
107 * @param[in] sceneController The scene controller - used for sending messages to render thread
108 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
110 void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
113 * @copydoc ConnectionObservers::AddObserver
115 void AddConnectionObserver(ConnectionChangePropagator::Observer& observer);
118 * @copydoc ConnectionObservers::RemoveObserver
120 void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer);
122 public: // UniformMap::Observer
124 * @copydoc UniformMap::Observer::UniformMappingsChanged
126 virtual void UniformMappingsChanged( const UniformMap& mappings );
129 * Get the vertex buffers of the geometry
130 * @return A const reference to the vertex buffers
132 Vector<Render::PropertyBuffer*>& GetVertexBuffers();
135 * Get the index buffer of the geometry
136 * @return A pointer to the index buffer if it exists, or NULL if it doesn't.
138 Render::PropertyBuffer* GetIndexBuffer();
141 * Gets the associated RenderGeometry
142 * @param[in] sceneController The scene controller
143 * @return The RenderGeometry associated to this Geometry
145 RenderGeometry* GetRenderGeometry(SceneController* sceneController);
148 * Called from renderers using this geometry when they get disconnected from the scenegraph
150 void OnRendererDisconnect();
153 public: // GeometryDataProvider
155 * Get the type of geometry to draw
156 * @param[in] bufferIndex Index for double buffered values
158 virtual GeometryType GetGeometryType( BufferIndex bufferIndex ) const;
161 * Returns true if this geometry requires depth testing, e.g. if it is
162 * a set of vertices with z != 0
163 * @param[in] bufferIndex Index for double buffered values
165 virtual bool GetRequiresDepthTesting( BufferIndex bufferIndex ) const;
169 RenderGeometry* mRenderGeometry;
170 SceneController* mSceneController;
172 Render::PropertyBuffer* mIndexBuffer; ///< The index buffer if required
173 Vector<Render::PropertyBuffer*> mVertexBuffers; ///< The vertex buffers
175 ConnectionChangePropagator mConnectionObservers;
177 Geometry::GeometryType mGeometryType;
178 unsigned int mRendererRefCount;
179 bool mRequiresDepthTest;
182 inline void AddVertexBufferMessage( EventThreadServices& eventThreadServices , const Geometry& geometry, const Render::PropertyBuffer& vertexBuffer )
184 typedef MessageValue1< Geometry, Render::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::AddVertexBuffer, const_cast<Render::PropertyBuffer*>(&vertexBuffer) );
193 inline void RemoveVertexBufferMessage( EventThreadServices& eventThreadServices, const Geometry& geometry, const Render::PropertyBuffer& vertexBuffer )
195 typedef MessageValue1< Geometry, Render::PropertyBuffer* > 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::RemoveVertexBuffer, const_cast<Render::PropertyBuffer*>(&vertexBuffer) );
204 inline void SetIndexBufferMessage( EventThreadServices& eventThreadServices, const Geometry& geometry, const Render::PropertyBuffer& indexBuffer )
206 typedef MessageValue1< Geometry, Render::PropertyBuffer* > LocalType;
208 // Reserve some memory inside the message queue
209 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
211 // Construct message in the message queue memory; note that delete should not be called on the return value
212 new (slot) LocalType( &geometry, &Geometry::SetIndexBuffer, const_cast<Render::PropertyBuffer*>(&indexBuffer) );
215 inline void ClearIndexBufferMessage( EventThreadServices& eventThreadServices, const Geometry& geometry )
217 typedef Message< Geometry > LocalType;
219 // Reserve some memory inside the message queue
220 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
222 // Construct message in the message queue memory; note that delete should not be called on the return value
223 new (slot) LocalType( &geometry, &Geometry::ClearIndexBuffer );
226 } // namespace SceneGraph
228 // Declare enum as a message parameter type
229 template <> struct ParameterType< SceneGraph::Geometry::GeometryType > : public BasicType< SceneGraph::Geometry::GeometryType > {};
234 inline void SetGeometryTypeMessage( EventThreadServices& eventThreadServices, const Geometry& geometry, SceneGraph::Geometry::GeometryType geometryType )
236 typedef MessageValue1< Geometry, SceneGraph::Geometry::GeometryType > LocalType;
238 // Reserve some memory inside the message queue
239 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
241 // Construct message in the message queue memory; note that delete should not be called on the return value
242 new (slot) LocalType( &geometry, &Geometry::SetGeometryType, geometryType );
245 inline void SetGeometryRequiresDepthTestMessage( EventThreadServices& eventThreadServices, const Geometry& geometry, bool requiresDepthTest )
247 typedef MessageValue1< Geometry, bool > LocalType;
249 // Reserve some memory inside the message queue
250 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
252 // Construct message in the message queue memory; note that delete should not be called on the return value
253 new (slot) LocalType( &geometry, &Geometry::SetRequiresDepthTest, requiresDepthTest );
256 } // namespace SceneGraph
257 } // namespace Internal
260 #endif // DALI_INTERNAL_SCENE_GRAPH_GEOMETRY_H