1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-24 17:29:23 +01:00

only store texture data if it changed

This commit is contained in:
Ell 2021-01-20 05:22:30 +01:00
parent e2cb125356
commit 3cd8c54e5c

View file

@ -25,6 +25,8 @@ namespace MLEM.Extensions {
private readonly Texture2D texture;
private readonly Color[] data;
private bool dirty;
/// <summary>
/// Returns the color at the given x,y position of the texture, where 0,0 represents the bottom left.
/// </summary>
@ -32,7 +34,13 @@ namespace MLEM.Extensions {
/// <param name="y">The y coordinate of the texture location</param>
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;
}
}
}
/// <inheritdoc cref="this[int,int]"/>
public Color this[Point point] {
@ -55,7 +63,10 @@ namespace MLEM.Extensions {
/// Stores this texture data back into the underlying texture
/// </summary>
public void Store() {
this.texture.SetData(this.data);
if (this.dirty) {
this.texture.SetData(this.data);
this.dirty = false;
}
}
/// <summary>