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 "uniform-map.h"
26 UniformMap::UniformMap()
30 UniformMap::~UniformMap()
32 // Nothing to do - let the owner container delete the maps
35 void UniformMap::AddObserver( Observer& observer )
37 bool foundObserver = false;
38 for( ObserversIter iter = mObservers.Begin(); iter != mObservers.End(); ++iter )
40 if( *iter == &observer )
48 mObservers.PushBack( &observer );
52 void UniformMap::RemoveObserver( Observer& observer )
54 for( ObserversIter iter = mObservers.Begin(); iter != mObservers.End(); ++iter )
56 if( *iter == &observer )
58 mObservers.Erase(iter);
64 void UniformMap::MappingChanged()
66 for( ObserversIter iter = mObservers.Begin(); iter != mObservers.End(); ++iter )
68 Observer* observer = (*iter);
69 observer->UniformMappingsChanged( *this );
73 // @todo MESH_REWORK Benchmark and test
74 // The uniform map can never grow beyond the limits of GL - so really, the
75 // map size is likely to be small; if retaining an unsorted map proves to be
76 // slow, then it should be changed to perform an insertion sort.
77 void UniformMap::Add( UniformPropertyMapping* newMap )
79 UniformPropertyMapping::Hash nameHash = CalculateHash( newMap->uniformName );
83 for( UniformMapIter iter = mUniformMaps.Begin() ;
84 iter != mUniformMaps.End() ;
87 UniformPropertyMapping* map = *iter;
88 if( map->uniformNameHash == nameHash )
90 if( map->uniformName == newMap->uniformName )
93 // Mapping already exists - update it.
94 map->propertyPtr = newMap->propertyPtr;
102 // Take ownership of the new map
103 mUniformMaps.PushBack(newMap);
109 void UniformMap::Remove( const std::string& uniformName )
111 UniformPropertyMapping::Hash nameHash = CalculateHash( uniformName );
115 for( UniformMapIter iter = mUniformMaps.Begin() ;
116 iter != mUniformMaps.End() ;
119 UniformPropertyMapping* map = *iter;
120 if( map->uniformNameHash == nameHash )
122 if( map->uniformName == uniformName )
124 mUniformMaps.Erase( iter );
137 const PropertyInputImpl* UniformMap::Find( const std::string& uniformName )
139 UniformPropertyMapping::Hash nameHash = CalculateHash( uniformName );
141 for( UniformMapIter iter = mUniformMaps.Begin() ;
142 iter != mUniformMaps.End() ;
145 UniformPropertyMapping* map = *iter;
146 if( map->uniformNameHash == nameHash )
148 if( map->uniformName == uniformName )
150 return map->propertyPtr;
157 unsigned int UniformMap::Count() const
159 return mUniformMaps.Count();
162 const UniformPropertyMapping& UniformMap::operator[]( unsigned int index ) const
164 return *mUniformMaps[index];