Support for disposing textures.

This commit is contained in:
NathanSweet 2013-04-18 12:20:08 +02:00
parent 143f99a81f
commit f2a08876c7
3 changed files with 16 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -74,4 +74,7 @@ public class SingleTextureLoader : TextureLoader {
page.width = material.mainTexture.width;
page.height = material.mainTexture.height;
}
public void Unload (object texture) {
}
}

View File

@ -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();
}
}
}