@@ -142,6 +142,7 @@ class Texture2DAtlas
142142 private AtlasAllocator m_AtlasAllocator = null ;
143143 private Dictionary < int , Vector4 > m_AllocationCache = new Dictionary < int , Vector4 > ( ) ;
144144 private Dictionary < int , uint > m_IsGPUTextureUpToDate = new Dictionary < int , uint > ( ) ;
145+ private Dictionary < int , int > m_TextureHashes = new Dictionary < int , int > ( ) ;
145146
146147 static readonly Vector4 fullScaleOffset = new Vector4 ( 1 , 1 , 0 , 0 ) ;
147148
@@ -280,6 +281,7 @@ public virtual bool AllocateTextureWithoutBlit(int instanceId, int width, int he
280281 scaleOffset . Scale ( new Vector4 ( 1.0f / m_Width , 1.0f / m_Height , 1.0f / m_Width , 1.0f / m_Height ) ) ;
281282 m_AllocationCache . Add ( instanceId , scaleOffset ) ;
282283 MarkGPUTextureInvalid ( instanceId ) ; // the texture data haven't been uploaded
284+ m_TextureHashes [ instanceId ] = - 1 ;
283285 return true ;
284286 }
285287 else
@@ -291,10 +293,29 @@ public virtual bool AllocateTextureWithoutBlit(int instanceId, int width, int he
291293 public bool IsCached ( out Vector4 scaleOffset , Texture texture )
292294 => m_AllocationCache . TryGetValue ( texture . GetInstanceID ( ) , out scaleOffset ) ;
293295
296+ protected int GetTextureHash ( Texture texture )
297+ {
298+ int hash = texture . GetHashCode ( ) ;
299+
300+ unchecked
301+ {
302+ hash = hash * 23 + texture . graphicsFormat . GetHashCode ( ) ;
303+ hash = hash * 23 + texture . wrapMode . GetHashCode ( ) ;
304+ hash = hash * 23 + texture . width . GetHashCode ( ) ;
305+ hash = hash * 23 + texture . height . GetHashCode ( ) ;
306+ hash = hash * 23 + texture . filterMode . GetHashCode ( ) ;
307+ hash = hash * 23 + texture . anisoLevel . GetHashCode ( ) ;
308+ hash = hash * 23 + texture . mipmapCount . GetHashCode ( ) ;
309+ }
310+
311+ return hash ;
312+ }
313+
294314 public virtual bool NeedsUpdate ( Texture texture , bool needMips = false )
295315 {
296316 RenderTexture rt = texture as RenderTexture ;
297317 int key = texture . GetInstanceID ( ) ;
318+ int textureHash = GetTextureHash ( texture ) ;
298319
299320 // Update the render texture if needed
300321 if ( rt != null )
@@ -311,6 +332,12 @@ public virtual bool NeedsUpdate(Texture texture, bool needMips = false)
311332 m_IsGPUTextureUpToDate [ key ] = rt . updateCount ;
312333 }
313334 }
335+ // In case the texture settings/import settings have changed, we need to update it
336+ else if ( m_TextureHashes . TryGetValue ( key , out int hash ) && hash != textureHash )
337+ {
338+ m_TextureHashes [ key ] = textureHash ;
339+ return true ;
340+ }
314341 // For regular textures, values == 0 means that their GPU data needs to be updated (either because
315342 // the atlas have been re-layouted or the texture have never been uploaded. We also check if the mips
316343 // are valid for the texture if we need them
0 commit comments