X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fupdate%2Fcommon%2Funiform-map.h;h=015d582f7286c32ff21a07a99896461b7f8549b9;hb=d67b366a74050ddec47340ff10a0188c0d381561;hp=8ca4246043af3fb99bf32a24d6ab7fb6b69ae0a5;hpb=8b0b50bb14b39e34a119c573cad63fd03c96b09a;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/update/common/uniform-map.h b/dali/internal/update/common/uniform-map.h index 8ca4246..015d582 100644 --- a/dali/internal/update/common/uniform-map.h +++ b/dali/internal/update/common/uniform-map.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_SCENE_GRAPH_UNIFORM_MAP_H /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,10 +17,17 @@ * limitations under the License. */ -#include -#include +// EXTERNAL INCLUDES +#include // uint32_t #include +// INTERNAL INCLUDES +#include + +#include + +#include + namespace Dali { namespace Internal @@ -29,102 +36,99 @@ class PropertyInputImpl; namespace SceneGraph { - /** * The uniform map is used to map a uniform name to a property value. */ class UniformPropertyMapping { public: - typedef unsigned long Hash; + using Hash = unsigned long; /** * Constructor */ - UniformPropertyMapping( const std::string& theUniformName, const PropertyInputImpl* thePropertyPtr ) - : propertyPtr( thePropertyPtr ), - uniformName( theUniformName ), - uniformNameHash( Dali::CalculateHash( theUniformName ) ) + UniformPropertyMapping(ConstString theUniformName, const PropertyInputImpl* thePropertyPtr) + : propertyPtr(thePropertyPtr), + uniformName(theUniformName), + uniformNameHash(0u), + uniformNameHashNoArray(0u), + arrayIndex(0u) { + // Look for array index closing bracket + auto nameStringView = theUniformName.GetStringView(); + auto pos = nameStringView.rfind("]"); + + // If found, extract the array index and store it, if it's an element in an array of basic types. + if(pos != std::string::npos) + { + auto pos0 = theUniformName.GetStringView().rfind("[", pos); + if(pos == nameStringView.length() - 1) // if element is in struct, don't set array index. + { + arrayIndex = atoi(theUniformName.GetCString() + pos0 + 1); + } + // Calculate hash from name without array index + uniformNameHashNoArray = Dali::CalculateHash(theUniformName.GetStringView().substr(0, pos0).data(), '['); + } + uniformName = theUniformName; + uniformNameHash = Dali::CalculateHash(theUniformName.GetCString()); } - UniformPropertyMapping() - : propertyPtr( NULL ), - uniformName( "" ), - uniformNameHash( 0 ) - { - } + UniformPropertyMapping() = default; - - const PropertyInputImpl* propertyPtr; - std::string uniformName; - Hash uniformNameHash; + const PropertyInputImpl* propertyPtr{nullptr}; + ConstString uniformName{}; + Hash uniformNameHash{0u}; + Hash uniformNameHashNoArray{0u}; + int32_t arrayIndex{0u}; }; /** * The UniformMap class is used to map uniform names to property values. It is available - * in all of the classes responsible for rendering: - * Actor, Renderer, Geometry, Material, Shader. + * in the following rendering classes: Node, Renderer, Shader. * - * It can be observed for changes to the mapping table. + * They can test the ChangeCounter to see if the mapping has been updated. */ class UniformMap { public: - class Observer - { - public: - virtual void UniformMappingsChanged(const UniformMap& mappings) = 0; - }; - - /** - * Constructor - */ - UniformMap(); - - /** - * Destructor - */ - ~UniformMap(); - - /** - * Add an observer that watches for changes in the mappings - */ - void AddObserver( Observer& observer ); - - /** - * Remove an observer - */ - void RemoveObserver( Observer& observer ); + using SizeType = uint32_t; /** * Add a map to the mappings table. */ - void Add( UniformPropertyMapping* map ); + void Add(UniformPropertyMapping map); /** * Remove a map from the mappings table */ - void Remove( const std::string& uniformName ); + void Remove(ConstString uniformName); /** * Find a property given the uniform name. * @return The address of the property if it's in the map, or NULL otherwise. */ - const PropertyInputImpl* Find( const std::string& uniformName ); + const PropertyInputImpl* Find(ConstString uniformName); /** * Get the count of uniforms in the map * @return The number of uniform mappings */ - unsigned int Count() const; + SizeType Count() const; /** * @pre index must be in the range 0 :: Count()-1 * @param[in] index The index of the element to fetch * @return reference to the element in the map */ - const UniformPropertyMapping& operator[]( unsigned int index ) const; + const UniformPropertyMapping& operator[](SizeType index) const; + + /** + * Return the change counter + */ + inline std::size_t GetChangeCounter() const + { + return mChangeCounter; + } private: /** @@ -133,17 +137,13 @@ private: void MappingChanged(); private: - typedef OwnerContainer< UniformPropertyMapping* > UniformMapContainer; - typedef UniformMapContainer::Iterator UniformMapIter; - typedef Dali::Vector< Observer* > Observers; - typedef Observers::Iterator ObserversIter; - - UniformMapContainer mUniformMaps; // Owner container of uniform maps + using UniformMapContainer = Dali::Vector; + using UniformMapIter = UniformMapContainer::Iterator; - Observers mObservers; + UniformMapContainer mUniformMaps; ///< container of uniform maps + std::size_t mChangeCounter{0u}; ///< Counter that is incremented when the map changes }; - } // namespace SceneGraph } // namespace Internal } // namespace Dali