add check to not recalculate the same textures twice
This commit is contained in:
@@ -18,10 +18,13 @@ namespace SplashEdit.RuntimeCode
|
|||||||
{
|
{
|
||||||
Renderer renderer = GetComponent<Renderer>();
|
Renderer renderer = GetComponent<Renderer>();
|
||||||
if (renderer.sharedMaterial != null && renderer.sharedMaterial.mainTexture is Texture2D texture)
|
if (renderer.sharedMaterial != null && renderer.sharedMaterial.mainTexture is Texture2D texture)
|
||||||
|
{
|
||||||
|
if (Texture == null || Texture.NeedUpdate(BitDepth, texture))
|
||||||
{
|
{
|
||||||
Texture = PSXTexture2D.CreateFromTexture2D(texture, BitDepth);
|
Texture = PSXTexture2D.CreateFromTexture2D(texture, BitDepth);
|
||||||
Texture.OriginalTexture = texture; // Stores reference to the original texture
|
Texture.OriginalTexture = texture; // Stores reference to the original texture
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//TODO: Better handle object with default texture
|
//TODO: Better handle object with default texture
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@@ -275,5 +276,15 @@ namespace SplashEdit.RuntimeCode
|
|||||||
return vramTexture;
|
return vramTexture;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Check if we need to update stored texture
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bitDepth">new settings for color bit depth</param>
|
||||||
|
/// <param name="texture">new texture</param>
|
||||||
|
/// <returns>return true if sored texture is different from a new one</returns>
|
||||||
|
internal bool NeedUpdate(PSXBPP bitDepth, Texture2D texture)
|
||||||
|
{
|
||||||
|
return BitDepth != bitDepth || texture.GetInstanceID() != texture.GetInstanceID();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user