2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "scene-graph-geometry.h"
29 mGeometryType(Dali::Geometry::TRIANGLES),
30 mRequiresDepthTest(false)
33 // Observe our own PropertyOwner's uniform map
34 AddUniformMapObserver( *this );
39 // @todo Inform renderers of deletion of buffers?
41 // could remove self from own uniform map observer, but it's about to be destroyed.
44 void Geometry::AddVertexBuffer( const PropertyBuffer* vertexBuffer )
46 mVertexBuffers.PushBack( vertexBuffer );
47 PropertyBuffer* theVertexBuffer = const_cast<PropertyBuffer*>(vertexBuffer);
48 theVertexBuffer->AddUniformMapObserver(*this);
49 mConnectionObservers.ConnectionsChanged(*this);
52 void Geometry::RemoveVertexBuffer( const PropertyBuffer* vertexBuffer )
54 DALI_ASSERT_DEBUG( NULL != vertexBuffer );
56 // Find the object and destroy it
57 VertexBuffers::Iterator match = std::find( mVertexBuffers.Begin(),
61 DALI_ASSERT_DEBUG( mVertexBuffers.End() != match );
62 if( mVertexBuffers.End() != match )
64 PropertyBuffer* theVertexBuffer = const_cast<PropertyBuffer*>(vertexBuffer);
65 theVertexBuffer->RemoveUniformMapObserver(*this);
66 mVertexBuffers.Erase( match );
67 mConnectionObservers.ConnectionsChanged(*this);
71 void Geometry::SetIndexBuffer( const PropertyBuffer* indexBuffer )
73 if( mIndexBuffer != indexBuffer )
75 mIndexBuffer = indexBuffer;
76 mConnectionObservers.ConnectionsChanged(*this);
80 void Geometry::ClearIndexBuffer()
82 // @todo Actually delete, or put on Discard Queue and tell Renderer in render thread?
84 mConnectionObservers.ConnectionsChanged(*this);
87 void Geometry::SetGeometryType( BufferIndex bufferIndex, Geometry::GeometryType geometryType )
89 mGeometryType[bufferIndex] = geometryType;
92 const GeometryDataProvider::VertexBuffers& Geometry::GetVertexBuffers() const
94 return mVertexBuffers;
97 const PropertyBuffer* Geometry::GetIndexBuffer() const
102 Geometry::GeometryType Geometry::GetGeometryType( BufferIndex bufferIndex) const
104 int geometryType = mGeometryType[ bufferIndex ];
105 return static_cast< GeometryDataProvider::GeometryType > ( geometryType );
108 bool Geometry::GetRequiresDepthTesting( BufferIndex bufferIndex ) const
110 return mRequiresDepthTest.GetBoolean( bufferIndex );
113 void Geometry::ResetDefaultProperties( BufferIndex updateBufferIndex )
115 // Reset the animated properties
116 mCenter.ResetToBaseValue( updateBufferIndex );
117 mHalfExtents.ResetToBaseValue( updateBufferIndex );
119 // Age the double buffered properties
120 mGeometryType.CopyPrevious(updateBufferIndex);
121 mRequiresDepthTest.CopyPrevious(updateBufferIndex);
124 void Geometry::ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
128 void Geometry::DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
132 void Geometry::AddConnectionObserver( ConnectionObservers::Observer& observer )
134 mConnectionObservers.Add(observer);
137 void Geometry::RemoveConnectionObserver( ConnectionObservers::Observer& observer )
139 mConnectionObservers.Remove(observer);
142 void Geometry::UniformMappingsChanged( const UniformMap& mappings )
144 // Our uniform map, or that of one of the watched children has changed.
145 // Inform connected observers.
146 mConnectionObservers.ConnectedUniformMapChanged();
149 } // namespace SceneGraph
150 } // namespace Internal