From 3cd8c54e5c3a269a4f472ec07d4b944f9c39515b Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 20 Jan 2021 05:22:30 +0100 Subject: [PATCH] only store texture data if it changed --- MLEM/Extensions/TextureExtensions.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/MLEM/Extensions/TextureExtensions.cs b/MLEM/Extensions/TextureExtensions.cs index 977670c..541f667 100644 --- a/MLEM/Extensions/TextureExtensions.cs +++ b/MLEM/Extensions/TextureExtensions.cs @@ -25,6 +25,8 @@ namespace MLEM.Extensions { private readonly Texture2D texture; private readonly Color[] data; + private bool dirty; + /// /// Returns the color at the given x,y position of the texture, where 0,0 represents the bottom left. /// @@ -32,7 +34,13 @@ namespace MLEM.Extensions { /// The y coordinate of the texture location public Color this[int x, int y] { get => this.data[this.ToIndex(x, y)]; - set => this.data[this.ToIndex(x, y)] = value; + set { + var index = this.ToIndex(x, y); + if (this.data[index] != value) { + this.data[index] = value; + this.dirty = true; + } + } } /// public Color this[Point point] { @@ -55,7 +63,10 @@ namespace MLEM.Extensions { /// Stores this texture data back into the underlying texture /// public void Store() { - this.texture.SetData(this.data); + if (this.dirty) { + this.texture.SetData(this.data); + this.dirty = false; + } } ///