mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
Support for disposing textures.
This commit is contained in:
parent
143f99a81f
commit
f2a08876c7
@ -30,6 +30,7 @@ namespace Spine {
|
||||
public class Atlas {
|
||||
List<AtlasPage> pages = new List<AtlasPage>();
|
||||
List<AtlasRegion> regions = new List<AtlasRegion>();
|
||||
TextureLoader textureLoader;
|
||||
|
||||
public Atlas (String path, TextureLoader textureLoader) {
|
||||
using (StreamReader reader = new StreamReader(path)) {
|
||||
@ -47,6 +48,7 @@ namespace Spine {
|
||||
|
||||
private void Load (TextReader reader, String imagesDir, TextureLoader textureLoader) {
|
||||
if (textureLoader == null) throw new ArgumentNullException("textureLoader cannot be null.");
|
||||
this.textureLoader = textureLoader;
|
||||
|
||||
String[] tuple = new String[4];
|
||||
AtlasPage page = null;
|
||||
@ -163,6 +165,11 @@ namespace Spine {
|
||||
if (regions[i].name == name) return regions[i];
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Dispose () {
|
||||
for (int i = 0, n = pages.Count; i < n; i++)
|
||||
textureLoader.Unload(pages[i].texture);
|
||||
}
|
||||
}
|
||||
|
||||
public enum Format {
|
||||
@ -217,5 +224,6 @@ namespace Spine {
|
||||
|
||||
public interface TextureLoader {
|
||||
void Load (AtlasPage page, String path);
|
||||
void Unload (Object texture);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,4 +74,7 @@ public class SingleTextureLoader : TextureLoader {
|
||||
page.width = material.mainTexture.width;
|
||||
page.height = material.mainTexture.height;
|
||||
}
|
||||
|
||||
public void Unload (object texture) {
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,6 +31,7 @@ using Microsoft.Xna.Framework.Graphics;
|
||||
namespace Spine {
|
||||
public class XnaTextureLoader : TextureLoader {
|
||||
GraphicsDevice device;
|
||||
|
||||
public XnaTextureLoader (GraphicsDevice device) {
|
||||
this.device = device;
|
||||
}
|
||||
@ -41,5 +42,9 @@ namespace Spine {
|
||||
page.width = texture.Width;
|
||||
page.height = texture.Height;
|
||||
}
|
||||
|
||||
public void Unload (Object texture) {
|
||||
((Texture2D)texture).Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user