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.
18 #include "scene-graph-material.h"
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>
33 : mColor( Color::WHITE ),
34 mBlendColor( Color::WHITE ),
35 mFaceCullingMode(Dali::Material::NONE),
38 // Observe own property-owner's uniform map
39 AddUniformMapObserver( *this );
46 void Material::SetShader( Shader* shader )
49 // Inform NewRenderer about this shader: (Will force a re-load of the
50 // shader from the data providers)
51 mConnectionObservers.ConnectionsChanged(*this);
54 Shader* Material::GetShader() const
56 // @todo - Fix this - move shader setup to the Renderer connect to stage...
60 void Material::AddSampler( Sampler* sampler )
62 mSamplers.PushBack( sampler );
64 sampler->AddConnectionObserver( *this );
65 sampler->AddUniformMapObserver( *this );
67 mConnectionObservers.ConnectionsChanged(*this);
70 void Material::RemoveSampler( Sampler* sampler )
72 Vector<Sampler*>::Iterator match = std::find( mSamplers.Begin(), mSamplers.End(), sampler );
74 DALI_ASSERT_DEBUG( mSamplers.End() != match );
75 if( mSamplers.End() != match )
77 sampler->RemoveConnectionObserver( *this );
78 sampler->RemoveUniformMapObserver( *this );
79 mSamplers.Erase( match );
80 mConnectionObservers.ConnectionsChanged(*this);
84 DALI_ASSERT_DEBUG( 0 && "Sampler not found" );
88 Vector<Sampler*>& Material::GetSamplers()
93 void Material::ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
97 void Material::DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
101 void Material::AddConnectionObserver( ConnectionChangePropagator::Observer& observer )
103 mConnectionObservers.Add(observer);
106 void Material::RemoveConnectionObserver( ConnectionChangePropagator::Observer& observer )
108 mConnectionObservers.Remove(observer);
111 void Material::UniformMappingsChanged( const UniformMap& mappings )
113 // Our uniform map, or that of one of the watched children has changed.
114 // Inform connected observers.
115 mConnectionObservers.ConnectedUniformMapChanged();
118 void Material::ConnectionsChanged( PropertyOwner& owner )
120 mConnectionObservers.ConnectionsChanged(*this);
123 void Material::ConnectedUniformMapChanged( )
125 mConnectionObservers.ConnectedUniformMapChanged();
128 void Material::ResetDefaultProperties( BufferIndex updateBufferIndex )
130 mColor.ResetToBaseValue( updateBufferIndex );
131 mBlendColor.ResetToBaseValue( updateBufferIndex );
132 mFaceCullingMode.CopyPrevious( updateBufferIndex );
135 } // namespace SceneGraph
136 } // namespace Internal