mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 14:38:34 +01:00
only store texture data if it changed
This commit is contained in:
parent
e2cb125356
commit
3cd8c54e5c
1 changed files with 13 additions and 2 deletions
|
@ -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() {
|
||||
if (this.dirty) {
|
||||
this.texture.SetData(this.data);
|
||||
this.dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in a new issue