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( const Shader* shader )
49 // @todo inform NewRenderer about this shader
50 mConnectionObservers.ConnectionsChanged(*this);
53 Shader* Material::GetShader() const
55 // @todo - Fix this - move shader setup to the Renderer connect to stage...
56 return const_cast<Shader*>(mShader);
59 void Material::AddSampler( const Sampler* sampler )
61 const SamplerDataProvider* sdp = static_cast< const SamplerDataProvider*>( sampler );
62 mSamplers.PushBack( sdp );
64 mConnectionObservers.ConnectionsChanged(*this);
67 void Material::RemoveSampler( const Sampler* sampler )
69 const SamplerDataProvider* samplerDataProvider = sampler;
72 RenderDataProvider::Samplers::Iterator iter = mSamplers.Begin();
73 for( ; iter != mSamplers.End(); ++iter )
75 if( *iter == samplerDataProvider )
84 mSamplers.Erase(iter);
85 mConnectionObservers.ConnectionsChanged(*this);
89 DALI_ASSERT_DEBUG( 0 && "Sampler not found" );
93 const RenderDataProvider::Samplers& Material::GetSamplers() const
98 void Material::ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
102 void Material::DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
106 void Material::AddConnectionObserver( ConnectionObservers::Observer& observer )
108 mConnectionObservers.Add(observer);
111 void Material::RemoveConnectionObserver( ConnectionObservers::Observer& observer )
113 mConnectionObservers.Remove(observer);
116 void Material::UniformMappingsChanged( const UniformMap& mappings )
118 // Our uniform map, or that of one of the watched children has changed.
119 // Inform connected observers.
120 mConnectionObservers.ConnectedUniformMapChanged();
123 void Material::ResetDefaultProperties( BufferIndex updateBufferIndex )
125 mColor.ResetToBaseValue( updateBufferIndex );
126 mBlendColor.ResetToBaseValue( updateBufferIndex );
127 mFaceCullingMode.CopyPrevious( updateBufferIndex );
130 } // namespace SceneGraph
131 } // namespace Internal