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/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>
37 * This scene graph object is a property owner. It describes a geometry using a
38 * number of PropertyBuffers acting as Vertex buffers.
40 class Geometry : public PropertyOwner, public GeometryDataProvider
55 * Add a property buffer to be used as a vertex buffer
57 void AddVertexBuffer( PropertyBuffer* vertexBuffer );
60 * Remove a property buffer to be used as a vertex buffer
61 * @param[in] vertexBuffer the associated vertex buffer to remove
63 void RemoveVertexBuffer( PropertyBuffer* vertexBuffer );
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.
69 void SetIndexBuffer( PropertyBuffer* indexBuffer );
72 * Clear the index buffer if it is no longer required, e.g. if changing geometry type
75 void ClearIndexBuffer();
78 * Set the type of geometry to draw (Points, Lines, Triangles, etc)
79 * @param[in] geometryType The geometry type
81 void SetGeometryType( BufferIndex bufferIndex, GeometryType geometryType );
83 public: // GeometryDataProvider
85 * Get the vertex buffers of the geometry
86 * @return A const reference to the vertex buffers
88 virtual const GeometryDataProvider::VertexBuffers& GetVertexBuffers() const;
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.
94 virtual const PropertyBuffer* GetIndexBuffer() const;
97 * Get the type of geometry to draw
99 virtual GeometryType GetGeometryType( BufferIndex bufferIndex ) const;
102 * Returns true if this geometry requires depth testing, e.g. if it is
103 * a set of vertices with z != 0
105 virtual bool GetRequiresDepthTest( BufferIndex bufferIndex ) const;
108 VertexBuffers mVertexBuffers; ///< The vertex buffers
109 OwnerPointer<PropertyBuffer> mIndexBuffer; ///< The index buffer if required
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;
117 AnimatableProperty<Vector3> mCenter;
118 AnimatableProperty<Vector3> mHalfExtents;
119 AnimatableProperty<int> mGeometryType; ///< The type of geometry (tris/lines etc)
120 PropertyBoolean mRequiresDepthTest;
123 inline void AddVertexBufferMessage( EventToUpdate& eventToUpdate, const Geometry& geometry, PropertyBuffer& vertexBuffer )
125 typedef MessageValue1< Geometry, OwnerPointer<PropertyBuffer> > LocalType;
127 // Reserve some memory inside the message queue
128 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
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 );
134 inline void RemoveVertexBufferMessage( EventToUpdate& eventToUpdate, const Geometry& geometry, PropertyBuffer& vertexBuffer )
136 typedef MessageValue1< Geometry, PropertyBuffer* > LocalType;
138 // Reserve some memory inside the message queue
139 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
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 );
145 inline void SetIndexBufferMessage( EventToUpdate& eventToUpdate, const Geometry& geometry, PropertyBuffer& indexBuffer )
147 typedef MessageValue1< Geometry, OwnerPointer< PropertyBuffer > > LocalType;
149 // Reserve some memory inside the message queue
150 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
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 );
156 inline void ClearIndexBufferMessage( EventToUpdate& eventToUpdate, const Geometry& geometry )
158 typedef Message< Geometry > LocalType;
160 // Reserve some memory inside the message queue
161 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
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 );
167 } // namespace SceneGraph
169 // Declare enum as a message parameter type
170 template <> struct ParameterType< SceneGraph::Geometry::GeometryType > : public BasicType< SceneGraph::Geometry::GeometryType > {};
175 inline void SetGeometryTypeMessage( EventToUpdate& eventToUpdate, const Geometry& geometry, SceneGraph::Geometry::GeometryType geometryType )
177 typedef MessageDoubleBuffered1< Geometry, SceneGraph::Geometry::GeometryType > LocalType;
179 // Reserve some memory inside the message queue
180 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
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 );
186 } // namespace SceneGraph
187 } // namespace Internal
190 #endif // DALI_INTERNAL_SCENE_GRAPH_GEOMETRY_H