Renamed ConnectionObservers class, un-consted objects
[platform/core/uifw/dali-core.git] / dali / internal / update / effects / scene-graph-material.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 // CLASS HEADER
18 #include "scene-graph-material.h"
19
20 // INTERNAL HEADERS
21 #include <dali/public-api/shader-effects/material.h>
22 #include <dali/internal/render/data-providers/sampler-data-provider.h>
23 #include <dali/internal/update/effects/scene-graph-sampler.h>
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 namespace SceneGraph
30 {
31
32 Material::Material()
33 : mColor( Color::WHITE ),
34   mBlendColor( Color::WHITE ),
35   mFaceCullingMode(Dali::Material::NONE),
36   mShader(NULL)
37 {
38   // Observe own property-owner's uniform map
39   AddUniformMapObserver( *this );
40 }
41
42 Material::~Material()
43 {
44 }
45
46 void Material::SetShader( Shader* shader )
47 {
48   mShader = shader;
49   // Inform NewRenderer about this shader: (Will force a re-load of the
50   // shader from the data providers)
51   mConnectionObservers.ConnectionsChanged(*this);
52 }
53
54 Shader* Material::GetShader() const
55 {
56   // @todo - Fix this - move shader setup to the Renderer connect to stage...
57   return mShader;
58 }
59
60 void Material::AddSampler( Sampler* sampler )
61 {
62   mSamplers.PushBack( sampler );
63
64   sampler->AddConnectionObserver( *this );
65   sampler->AddUniformMapObserver( *this );
66
67   mConnectionObservers.ConnectionsChanged(*this);
68 }
69
70 void Material::RemoveSampler( Sampler* sampler )
71 {
72   Vector<Sampler*>::Iterator match = std::find( mSamplers.Begin(), mSamplers.End(), sampler );
73
74   DALI_ASSERT_DEBUG( mSamplers.End() != match );
75   if( mSamplers.End() != match )
76   {
77     sampler->RemoveConnectionObserver( *this );
78     sampler->RemoveUniformMapObserver( *this );
79     mSamplers.Erase( match );
80     mConnectionObservers.ConnectionsChanged(*this);
81   }
82   else
83   {
84     DALI_ASSERT_DEBUG( 0 && "Sampler not found" );
85   }
86 }
87
88 Vector<Sampler*>& Material::GetSamplers()
89 {
90   return mSamplers;
91 }
92
93 void Material::ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
94 {
95 }
96
97 void Material::DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
98 {
99 }
100
101 void Material::AddConnectionObserver( ConnectionChangePropagator::Observer& observer )
102 {
103   mConnectionObservers.Add(observer);
104 }
105
106 void Material::RemoveConnectionObserver( ConnectionChangePropagator::Observer& observer )
107 {
108   mConnectionObservers.Remove(observer);
109 }
110
111 void Material::UniformMappingsChanged( const UniformMap& mappings )
112 {
113   // Our uniform map, or that of one of the watched children has changed.
114   // Inform connected observers.
115   mConnectionObservers.ConnectedUniformMapChanged();
116 }
117
118 void Material::ConnectionsChanged( PropertyOwner& owner )
119 {
120   mConnectionObservers.ConnectionsChanged(*this);
121 }
122
123 void Material::ConnectedUniformMapChanged( )
124 {
125   mConnectionObservers.ConnectedUniformMapChanged();
126 }
127
128 void Material::ResetDefaultProperties( BufferIndex updateBufferIndex )
129 {
130   mColor.ResetToBaseValue( updateBufferIndex );
131   mBlendColor.ResetToBaseValue( updateBufferIndex );
132   mFaceCullingMode.CopyPrevious( updateBufferIndex );
133 }
134
135 } // namespace SceneGraph
136 } // namespace Internal
137 } // namespace Dali