@@ -141,6 +141,7 @@ class Texture2DAtlas
141141 private AtlasAllocator m_AtlasAllocator = null ;
142142 private Dictionary < int , Vector4 > m_AllocationCache = new Dictionary < int , Vector4 > ( ) ;
143143 private Dictionary < int , uint > m_IsGPUTextureUpToDate = new Dictionary < int , uint > ( ) ;
144+ private Dictionary < int , int > m_TextureHashes = new Dictionary < int , int > ( ) ;
144145
145146 static readonly Vector4 fullScaleOffset = new Vector4 ( 1 , 1 , 0 , 0 ) ;
146147
@@ -278,6 +279,7 @@ public virtual bool AllocateTextureWithoutBlit(int instanceId, int width, int he
278279 scaleOffset . Scale ( new Vector4 ( 1.0f / m_Width , 1.0f / m_Height , 1.0f / m_Width , 1.0f / m_Height ) ) ;
279280 m_AllocationCache . Add ( instanceId , scaleOffset ) ;
280281 MarkGPUTextureInvalid ( instanceId ) ; // the texture data haven't been uploaded
282+ m_TextureHashes [ instanceId ] = - 1 ;
281283 return true ;
282284 }
283285 else
@@ -289,10 +291,29 @@ public virtual bool AllocateTextureWithoutBlit(int instanceId, int width, int he
289291 public bool IsCached ( out Vector4 scaleOffset , Texture texture )
290292 => m_AllocationCache . TryGetValue ( texture . GetInstanceID ( ) , out scaleOffset ) ;
291293
294+ protected int GetTextureHash ( Texture texture )
295+ {
296+ int hash = texture . GetHashCode ( ) ;
297+
298+ unchecked
299+ {
300+ hash = hash * 23 + texture . graphicsFormat . GetHashCode ( ) ;
301+ hash = hash * 23 + texture . wrapMode . GetHashCode ( ) ;
302+ hash = hash * 23 + texture . width . GetHashCode ( ) ;
303+ hash = hash * 23 + texture . height . GetHashCode ( ) ;
304+ hash = hash * 23 + texture . filterMode . GetHashCode ( ) ;
305+ hash = hash * 23 + texture . anisoLevel . GetHashCode ( ) ;
306+ hash = hash * 23 + texture . mipmapCount . GetHashCode ( ) ;
307+ }
308+
309+ return hash ;
310+ }
311+
292312 public virtual bool NeedsUpdate ( Texture texture , bool needMips = false )
293313 {
294314 RenderTexture rt = texture as RenderTexture ;
295315 int key = texture . GetInstanceID ( ) ;
316+ int textureHash = GetTextureHash ( texture ) ;
296317
297318 // Update the render texture if needed
298319 if ( rt != null )
@@ -309,6 +330,12 @@ public virtual bool NeedsUpdate(Texture texture, bool needMips = false)
309330 m_IsGPUTextureUpToDate [ key ] = rt . updateCount ;
310331 }
311332 }
333+ // In case the texture settings/import settings have changed, we need to update it
334+ else if ( m_TextureHashes . TryGetValue ( key , out int hash ) && hash != textureHash )
335+ {
336+ m_TextureHashes [ key ] = textureHash ;
337+ return true ;
338+ }
312339 // For regular textures, values == 0 means that their GPU data needs to be updated (either because
313340 // the atlas have been re-layouted or the texture have never been uploaded. We also check if the mips
314341 // are valid for the texture if we need them
0 commit comments