diff --git a/MLEM.Data/RuntimeTexturePacker.cs b/MLEM.Data/RuntimeTexturePacker.cs index d75f8d4..7ee4242 100644 --- a/MLEM.Data/RuntimeTexturePacker.cs +++ b/MLEM.Data/RuntimeTexturePacker.cs @@ -16,6 +16,7 @@ namespace MLEM.Data { public class RuntimeTexturePacker { private readonly List textures = new List(); + private readonly bool autoIncreaseMaxWidth; /// /// The generated packed texture. @@ -34,14 +35,16 @@ namespace MLEM.Data { /// The time that took the last time it was called /// public TimeSpan LastTotalTime => this.LastCalculationTime + this.LastPackTime; - private readonly int maxWidth; + private int maxWidth; /// /// Creates a new runtime texture packer with the given settings /// /// The maximum width that the packed texture can have. Defaults to 2048. - public RuntimeTexturePacker(int maxWidth = 2048) { + /// Whether the maximum width should be increased if there is a texture to be packed that is wider than . Defaults to false. + public RuntimeTexturePacker(int maxWidth = 2048, bool autoIncreaseMaxWidth = false) { this.maxWidth = maxWidth; + this.autoIncreaseMaxWidth = autoIncreaseMaxWidth; } /// @@ -64,8 +67,13 @@ namespace MLEM.Data { public void Add(TextureRegion texture, Action result) { if (this.PackedTexture != null) throw new InvalidOperationException("Cannot add texture to a texture packer that is already packed"); - 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 (texture.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)); }