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