diff --git a/SPD-classes/src/main/java/com/watabou/gltextures/SmartTexture.java b/SPD-classes/src/main/java/com/watabou/gltextures/SmartTexture.java index 067440b94..83e1ac4be 100644 --- a/SPD-classes/src/main/java/com/watabou/gltextures/SmartTexture.java +++ b/SPD-classes/src/main/java/com/watabou/gltextures/SmartTexture.java @@ -42,11 +42,10 @@ public class SmartTexture extends Texture { public Atlas atlas; protected SmartTexture( ) { - super(); //useful for subclasses which want to manage their own texture data // in cases where android.graphics.bitmap isn't fast enough. - //subclasses which use this MUST also override reload() + //subclasses which use this MUST also override some mix of reload/generate/bind } public SmartTexture( Bitmap bitmap ) { @@ -54,23 +53,38 @@ public class SmartTexture extends Texture { } public SmartTexture( Bitmap bitmap, int filtering, int wrapping, boolean premultiplied ) { - - super(); - - bitmap( bitmap, premultiplied ); - filter( filtering, filtering ); - wrap( wrapping, wrapping ); - + + this.bitmap = bitmap; + width = bitmap.getWidth(); + height = bitmap.getHeight(); + this.fModeMin = this.fModeMax = filtering; + this.wModeH = this.wModeV = wrapping; + this.premultiplied = premultiplied; + } - + + @Override + protected void generate() { + super.generate(); + bitmap( bitmap, premultiplied ); + filter( fModeMin, fModeMax ); + wrap( wModeH, wModeV ); + } + @Override public void filter(int minMode, int maxMode) { - super.filter( fModeMin = minMode, fModeMax = maxMode); + fModeMin = minMode; + fModeMax = maxMode; + if (id != -1) + super.filter( fModeMin = minMode, fModeMax = maxMode); } @Override public void wrap( int s, int t ) { - super.wrap( wModeH = s, wModeV = t ); + wModeH = s; + wModeV = t; + if (id != -1) + super.wrap( wModeH = s, wModeV = t ); } @Override @@ -91,9 +105,8 @@ public class SmartTexture extends Texture { } public void reload() { - id = new SmartTexture( bitmap, NEAREST, CLAMP, premultiplied ).id; - filter( fModeMin, fModeMax ); - wrap( wModeH, wModeV ); + id = -1; + generate(); } @Override diff --git a/SPD-classes/src/main/java/com/watabou/glwrap/Texture.java b/SPD-classes/src/main/java/com/watabou/glwrap/Texture.java index 2260636e2..5e0b2e556 100644 --- a/SPD-classes/src/main/java/com/watabou/glwrap/Texture.java +++ b/SPD-classes/src/main/java/com/watabou/glwrap/Texture.java @@ -38,24 +38,25 @@ public class Texture { public static final int MIRROR = GLES20.GL_MIRRORED_REPEAT; public static final int CLAMP = GLES20.GL_CLAMP_TO_EDGE; - public int id; + public int id = -1; private static int bound_id = 0; //id of the currently bound texture public boolean premultiplied = false; - - public Texture() { + + protected void generate(){ int[] ids = new int[1]; GLES20.glGenTextures( 1, ids, 0 ); id = ids[0]; - - bind(); } - public static void activate( int index ) { + public static void activ1ate( int index ) { GLES20.glActiveTexture( GLES20.GL_TEXTURE0 + index ); } public void bind() { + if (id == -1){ + generate(); + } if (id != bound_id) { GLES20.glBindTexture( GLES20.GL_TEXTURE_2D, id ); bound_id = id; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/FogOfWar.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/FogOfWar.java index 9589cf963..98f7e1941 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/FogOfWar.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/FogOfWar.java @@ -135,21 +135,25 @@ public class FogOfWar extends Image { order( ByteOrder.nativeOrder() ). asIntBuffer(); - filter( Texture.LINEAR, Texture.LINEAR ); TextureCache.add( FogOfWar.class, this ); } - + @Override - public void reload() { + protected void generate() { int[] ids = new int[1]; GLES20.glGenTextures( 1, ids, 0 ); id = ids[0]; - filter( Texture.LINEAR, Texture.LINEAR ); + } + + @Override + public void reload() { + generate(); update(); } public void update(){ bind(); + filter( Texture.LINEAR, Texture.LINEAR ); pixels.position(0); GLES20.glTexImage2D( GLES20.GL_TEXTURE_2D, @@ -166,6 +170,7 @@ public class FogOfWar extends Image { //allows partially updating the texture public void update(int top, int bottom){ bind(); + filter( Texture.LINEAR, Texture.LINEAR ); pixels.position(top*width); GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0,