mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 14:38:34 +01:00
allow extending the max width of a runtime texture packer
This commit is contained in:
parent
e783f4f769
commit
e2cb125356
1 changed files with 12 additions and 4 deletions
|
@ -16,6 +16,7 @@ namespace MLEM.Data {
|
||||||
public class RuntimeTexturePacker {
|
public class RuntimeTexturePacker {
|
||||||
|
|
||||||
private readonly List<Request> textures = new List<Request>();
|
private readonly List<Request> textures = new List<Request>();
|
||||||
|
private readonly bool autoIncreaseMaxWidth;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The generated packed texture.
|
/// The generated packed texture.
|
||||||
|
@ -34,14 +35,16 @@ namespace MLEM.Data {
|
||||||
/// The time that <see cref="Pack"/> took the last time it was called
|
/// The time that <see cref="Pack"/> took the last time it was called
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TimeSpan LastTotalTime => this.LastCalculationTime + this.LastPackTime;
|
public TimeSpan LastTotalTime => this.LastCalculationTime + this.LastPackTime;
|
||||||
private readonly int maxWidth;
|
private int maxWidth;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new runtime texture packer with the given settings
|
/// Creates a new runtime texture packer with the given settings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="maxWidth">The maximum width that the packed texture can have. Defaults to 2048.</param>
|
/// <param name="maxWidth">The maximum width that the packed texture can have. Defaults to 2048.</param>
|
||||||
public RuntimeTexturePacker(int maxWidth = 2048) {
|
/// <param name="autoIncreaseMaxWidth">Whether the maximum width should be increased if there is a texture to be packed that is wider than <see cref="maxWidth"/>. Defaults to false.</param>
|
||||||
|
public RuntimeTexturePacker(int maxWidth = 2048, bool autoIncreaseMaxWidth = false) {
|
||||||
this.maxWidth = maxWidth;
|
this.maxWidth = maxWidth;
|
||||||
|
this.autoIncreaseMaxWidth = autoIncreaseMaxWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -64,8 +67,13 @@ namespace MLEM.Data {
|
||||||
public void Add(TextureRegion texture, Action<TextureRegion> result) {
|
public void Add(TextureRegion texture, Action<TextureRegion> result) {
|
||||||
if (this.PackedTexture != null)
|
if (this.PackedTexture != null)
|
||||||
throw new InvalidOperationException("Cannot add texture to a texture packer that is already packed");
|
throw new InvalidOperationException("Cannot add texture to a texture packer that is already packed");
|
||||||
if (texture.Width > this.maxWidth)
|
if (texture.Width > this.maxWidth) {
|
||||||
throw new InvalidOperationException($"Cannot add texture with width {texture.Width} to a texture packer with max width {this.maxWidth}");
|
if (this.autoIncreaseMaxWidth) {
|
||||||
|
this.maxWidth = texture.Width;
|
||||||
|
} else {
|
||||||
|
throw new InvalidOperationException($"Cannot add texture with width {texture.Width} to a texture packer with max width {this.maxWidth}");
|
||||||
|
}
|
||||||
|
}
|
||||||
this.textures.Add(new Request(texture, result));
|
this.textures.Add(new Request(texture, result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue