Added sampler properties, test cases.
[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/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-observers.h>
29 #include <dali/internal/update/common/scene-graph-property-buffer.h>
30 #include <dali/internal/render/data-providers/geometry-data-provider.h>
31
32 namespace Dali
33 {
34 namespace Internal
35 {
36 namespace SceneGraph
37 {
38 class SceneController;
39
40 /**
41  * This scene graph object is a property owner. It describes a geometry using a
42  * number of PropertyBuffers acting as Vertex buffers.
43  */
44 class Geometry : public PropertyOwner, public GeometryDataProvider, public UniformMap::Observer
45 {
46 public:
47
48   /**
49    * Constructor
50    */
51   Geometry();
52
53   /**
54    * Destructor
55    */
56   virtual ~Geometry();
57
58   /**
59    * Add a property buffer to be used as a vertex buffer
60    */
61   void AddVertexBuffer( const PropertyBuffer* vertexBuffer );
62
63   /**
64    * Remove a property buffer to be used as a vertex buffer
65    * @param[in] vertexBuffer the associated vertex buffer to remove
66    */
67   void RemoveVertexBuffer( const PropertyBuffer* vertexBuffer );
68
69   /**
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.
72    */
73   void SetIndexBuffer( const PropertyBuffer* indexBuffer );
74
75   /**
76    * Clear the index buffer if it is no longer required, e.g. if changing geometry type
77    * to POINTS.
78    */
79   void ClearIndexBuffer();
80
81   /**
82    * Set the type of geometry to draw (Points, Lines, Triangles, etc)
83    * @param[in] geometryType The geometry type
84    */
85   void SetGeometryType( BufferIndex bufferIndex, GeometryType geometryType );
86
87   /**
88    * Connect the object to the scene graph
89    *
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
92    */
93   void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
94
95   /**
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
99    */
100   void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
101
102   /**
103    * @copydoc ConnectionObservers::AddObserver
104    */
105   void AddConnectionObserver(ConnectionObservers::Observer& observer);
106
107   /**
108    * @copydoc ConnectionObservers::RemoveObserver
109    */
110   void RemoveConnectionObserver(ConnectionObservers::Observer& observer);
111
112 public: // UniformMap::Observer
113   /**
114    * @copydoc UniformMap::Observer::UniformMappingsChanged
115    */
116   virtual void UniformMappingsChanged( const UniformMap& mappings );
117
118   /**
119    * Get the vertex buffers of the geometry
120    * @return A const reference to the vertex buffers
121    */
122   const GeometryDataProvider::VertexBuffers& GetVertexBuffers() const;
123
124   /**
125    * Get the index buffer of the geometry
126    * @return A const pointer to the index buffer if it exists, or NULL if it doesn't.
127    */
128   const PropertyBuffer* GetIndexBuffer() const;
129
130 public: // GeometryDataProvider
131   /**
132    * Get the type of geometry to draw
133    */
134   virtual GeometryType GetGeometryType( BufferIndex bufferIndex ) const;
135
136   /**
137    * Returns true if this geometry requires depth testing, e.g. if it is
138    * a set of vertices with z != 0
139    */
140   virtual bool GetRequiresDepthTesting( BufferIndex bufferIndex ) const;
141
142 protected: // From PropertyOwner
143   /**
144    * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
145    */
146   virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
147
148 private:
149   VertexBuffers mVertexBuffers; ///< The vertex buffers
150   const PropertyBuffer* mIndexBuffer;  ///< The index buffer if required
151   ConnectionObservers mConnectionObservers;
152
153 public: // Properties
154   AnimatableProperty<Vector3>  mCenter;
155   AnimatableProperty<Vector3>  mHalfExtents;
156   DoubleBufferedProperty<int>  mGeometryType;
157   DoubleBufferedProperty<bool> mRequiresDepthTest;
158 };
159
160 inline void AddVertexBufferMessage( EventThreadServices& eventThreadServices , const Geometry& geometry, const PropertyBuffer& vertexBuffer )
161 {
162   typedef MessageValue1< Geometry, const PropertyBuffer* > LocalType;
163
164   // Reserve some memory inside the message queue
165   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
166
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, &vertexBuffer );
169 }
170
171 inline void RemoveVertexBufferMessage( EventThreadServices& eventThreadServices, const Geometry& geometry, const PropertyBuffer& vertexBuffer )
172 {
173   typedef MessageValue1< Geometry, const PropertyBuffer* > LocalType;
174
175   // Reserve some memory inside the message queue
176   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
177
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, &vertexBuffer );
180 }
181
182 inline void SetIndexBufferMessage( EventThreadServices& eventThreadServices, const Geometry& geometry, const PropertyBuffer& indexBuffer )
183 {
184   typedef MessageValue1< Geometry, const PropertyBuffer* > LocalType;
185
186   // Reserve some memory inside the message queue
187   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
188
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, &indexBuffer );
191 }
192
193 inline void ClearIndexBufferMessage( EventThreadServices& eventThreadServices, const Geometry& geometry )
194 {
195   typedef Message< Geometry > LocalType;
196
197   // Reserve some memory inside the message queue
198   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
199
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 );
202 }
203
204 } // namespace SceneGraph
205
206 // Declare enum as a message parameter type
207 template <> struct ParameterType< SceneGraph::Geometry::GeometryType > : public BasicType< SceneGraph::Geometry::GeometryType > {};
208
209 namespace SceneGraph
210 {
211
212 inline void SetGeometryTypeMessage( EventThreadServices& eventThreadServices, const Geometry& geometry, SceneGraph::Geometry::GeometryType geometryType )
213 {
214   typedef MessageDoubleBuffered1< Geometry, SceneGraph::Geometry::GeometryType > LocalType;
215
216   // Reserve some memory inside the message queue
217   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
218
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 );
221 }
222
223 } // namespace SceneGraph
224 } // namespace Internal
225 } // namespace Dali
226
227 #endif // DALI_INTERNAL_SCENE_GRAPH_GEOMETRY_H