1 #ifndef DALI_INTERNAL_SCENE_GRAPH_UNIFORM_MAP_H
2 #define DALI_INTERNAL_SCENE_GRAPH_UNIFORM_MAP_H
5 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <cstdint> // uint32_t
25 #include <dali/devel-api/common/hash.h>
26 #include <dali/devel-api/common/owner-container.h>
32 class PropertyInputImpl;
38 * The uniform map is used to map a uniform name to a property value.
40 class UniformPropertyMapping
43 typedef unsigned long Hash;
48 UniformPropertyMapping( const std::string& theUniformName, const PropertyInputImpl* thePropertyPtr )
49 : propertyPtr( thePropertyPtr ),
50 uniformName( theUniformName ),
51 uniformNameHash( Dali::CalculateHash( theUniformName ) )
55 UniformPropertyMapping()
56 : propertyPtr( NULL ),
63 const PropertyInputImpl* propertyPtr;
64 std::string uniformName;
69 * The UniformMap class is used to map uniform names to property values. It is available
70 * in all of the classes responsible for rendering:
71 * Actor, Renderer, Geometry, TextureSet, Shader.
73 * It can be observed for changes to the mapping table.
78 using SizeType = uint32_t;
85 * Inform observer that uniform mappings have been changed
88 virtual void UniformMappingsChanged(const UniformMap& mappings) = 0;
93 * Virtual destructor, no deletion through this interface
95 virtual ~Observer() {}
109 * Add an observer that watches for changes in the mappings
111 void AddObserver( Observer& observer );
116 void RemoveObserver( Observer& observer );
119 * Add a map to the mappings table.
121 void Add( UniformPropertyMapping* map );
124 * Remove a map from the mappings table
126 void Remove( const std::string& uniformName );
129 * Find a property given the uniform name.
130 * @return The address of the property if it's in the map, or NULL otherwise.
132 const PropertyInputImpl* Find( const std::string& uniformName );
135 * Get the count of uniforms in the map
136 * @return The number of uniform mappings
138 SizeType Count() const;
141 * @pre index must be in the range 0 :: Count()-1
142 * @param[in] index The index of the element to fetch
143 * @return reference to the element in the map
145 const UniformPropertyMapping& operator[]( SizeType index ) const;
149 * Helper to call the observers when the mappings have changed
151 void MappingChanged();
154 typedef OwnerContainer< UniformPropertyMapping* > UniformMapContainer;
155 typedef UniformMapContainer::Iterator UniformMapIter;
156 typedef Dali::Vector< Observer* > Observers;
157 typedef Observers::Iterator ObserversIter;
159 UniformMapContainer mUniformMaps; // Owner container of uniform maps
161 Observers mObservers;
165 } // namespace SceneGraph
166 } // namespace Internal
169 #endif // DALI_INTERNAL_SCENE_GRAPH_UNIFORM_MAP_H