Added sampler properties, test cases.
[platform/core/uifw/dali-core.git] / dali / internal / update / geometry / scene-graph-geometry.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "scene-graph-geometry.h"
18
19 namespace Dali
20 {
21 namespace Internal
22 {
23 namespace SceneGraph
24 {
25
26 Geometry::Geometry()
27 : mCenter(),
28   mHalfExtents(),
29   mGeometryType(Dali::Geometry::TRIANGLES),
30   mRequiresDepthTest(false)
31 {
32
33   // Observe our own PropertyOwner's uniform map
34   AddUniformMapObserver( *this );
35 }
36
37 Geometry::~Geometry()
38 {
39   // @todo Inform renderers of deletion of buffers?
40
41   // could remove self from own uniform map observer, but it's about to be destroyed.
42 }
43
44 void Geometry::AddVertexBuffer( const PropertyBuffer* vertexBuffer )
45 {
46   mVertexBuffers.PushBack( vertexBuffer );
47   PropertyBuffer* theVertexBuffer = const_cast<PropertyBuffer*>(vertexBuffer);
48   theVertexBuffer->AddUniformMapObserver(*this);
49   mConnectionObservers.ConnectionsChanged(*this);
50 }
51
52 void Geometry::RemoveVertexBuffer( const PropertyBuffer* vertexBuffer )
53 {
54   DALI_ASSERT_DEBUG( NULL != vertexBuffer );
55
56   // Find the object and destroy it
57   VertexBuffers::Iterator match = std::find( mVertexBuffers.Begin(),
58                                              mVertexBuffers.End(),
59                                              vertexBuffer );
60
61   DALI_ASSERT_DEBUG( mVertexBuffers.End() != match );
62   if( mVertexBuffers.End() != match )
63   {
64     PropertyBuffer* theVertexBuffer = const_cast<PropertyBuffer*>(vertexBuffer);
65     theVertexBuffer->RemoveUniformMapObserver(*this);
66     mVertexBuffers.Erase( match );
67     mConnectionObservers.ConnectionsChanged(*this);
68   }
69 }
70
71 void Geometry::SetIndexBuffer( const PropertyBuffer* indexBuffer )
72 {
73   if( mIndexBuffer != indexBuffer )
74   {
75     mIndexBuffer = indexBuffer;
76     mConnectionObservers.ConnectionsChanged(*this);
77   }
78 }
79
80 void Geometry::ClearIndexBuffer()
81 {
82   // @todo Actually delete, or put on Discard Queue and tell Renderer in render thread?
83   mIndexBuffer = 0;
84   mConnectionObservers.ConnectionsChanged(*this);
85 }
86
87 void Geometry::SetGeometryType( BufferIndex bufferIndex, Geometry::GeometryType geometryType )
88 {
89   mGeometryType[bufferIndex] = geometryType;
90 }
91
92 const GeometryDataProvider::VertexBuffers& Geometry::GetVertexBuffers() const
93 {
94   return mVertexBuffers;
95 }
96
97 const PropertyBuffer* Geometry::GetIndexBuffer() const
98 {
99   return mIndexBuffer;
100 }
101
102 Geometry::GeometryType Geometry::GetGeometryType( BufferIndex bufferIndex) const
103 {
104   int geometryType = mGeometryType[ bufferIndex ];
105   return static_cast< GeometryDataProvider::GeometryType > ( geometryType );
106 }
107
108 bool Geometry::GetRequiresDepthTesting( BufferIndex bufferIndex ) const
109 {
110   return mRequiresDepthTest.GetBoolean( bufferIndex );
111 }
112
113 void Geometry::ResetDefaultProperties( BufferIndex updateBufferIndex )
114 {
115   // Reset the animated properties
116   mCenter.ResetToBaseValue( updateBufferIndex );
117   mHalfExtents.ResetToBaseValue( updateBufferIndex );
118
119   // Age the double buffered properties
120   mGeometryType.CopyPrevious(updateBufferIndex);
121   mRequiresDepthTest.CopyPrevious(updateBufferIndex);
122 }
123
124 void Geometry::ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
125 {
126 }
127
128 void Geometry::DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
129 {
130 }
131
132 void Geometry::AddConnectionObserver( ConnectionObservers::Observer& observer )
133 {
134   mConnectionObservers.Add(observer);
135 }
136
137 void Geometry::RemoveConnectionObserver( ConnectionObservers::Observer& observer )
138 {
139   mConnectionObservers.Remove(observer);
140 }
141
142 void Geometry::UniformMappingsChanged( const UniformMap& mappings )
143 {
144   // Our uniform map, or that of one of the watched children has changed.
145   // Inform connected observers.
146   mConnectionObservers.ConnectedUniformMapChanged();
147 }
148
149 } // namespace SceneGraph
150 } // namespace Internal
151 } // namespace Dali