From d83e935a1425063574a75d1decdaa62ed5b53e8b Mon Sep 17 00:00:00 2001 From: "aliaksei.kalosha" Date: Tue, 18 Mar 2025 12:41:59 +0100 Subject: [PATCH] add check to not recalculate the same textures twice --- Runtime/PSXObjectExporter.cs | 7 +++++-- Runtime/PSXTexture2D.cs | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Runtime/PSXObjectExporter.cs b/Runtime/PSXObjectExporter.cs index 371c973..f1da72a 100644 --- a/Runtime/PSXObjectExporter.cs +++ b/Runtime/PSXObjectExporter.cs @@ -19,8 +19,11 @@ namespace SplashEdit.RuntimeCode Renderer renderer = GetComponent(); if (renderer.sharedMaterial != null && renderer.sharedMaterial.mainTexture is Texture2D texture) { - Texture = PSXTexture2D.CreateFromTexture2D(texture, BitDepth); - Texture.OriginalTexture = texture; // Stores reference to the original texture + if (Texture == null || Texture.NeedUpdate(BitDepth, texture)) + { + Texture = PSXTexture2D.CreateFromTexture2D(texture, BitDepth); + Texture.OriginalTexture = texture; // Stores reference to the original texture + } } else { diff --git a/Runtime/PSXTexture2D.cs b/Runtime/PSXTexture2D.cs index 975b26b..34dd54a 100644 --- a/Runtime/PSXTexture2D.cs +++ b/Runtime/PSXTexture2D.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using UnityEngine; @@ -275,5 +276,15 @@ namespace SplashEdit.RuntimeCode return vramTexture; } + /// + /// Check if we need to update stored texture + /// + /// new settings for color bit depth + /// new texture + /// return true if sored texture is different from a new one + internal bool NeedUpdate(PSXBPP bitDepth, Texture2D texture) + { + return BitDepth != bitDepth || texture.GetInstanceID() != texture.GetInstanceID(); + } } } \ No newline at end of file