diff --git a/SPD-classes/src/main/java/com/watabou/gltextures/BufferTexture.java b/SPD-classes/src/main/java/com/watabou/gltextures/BufferTexture.java deleted file mode 100644 index 9a88d4e19..000000000 --- a/SPD-classes/src/main/java/com/watabou/gltextures/BufferTexture.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Pixel Dungeon - * Copyright (C) 2012-2015 Oleg Dolya - * - * Shattered Pixel Dungeon - * Copyright (C) 2014-2019 Evan Debenham - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see - */ - -package com.watabou.gltextures; - -import com.badlogic.gdx.Gdx; -import com.watabou.glwrap.Texture; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.IntBuffer; - -//provides a native intbuffer implementation because pixmap is too slow -//TODO: should evaluate this again, seeing as I've moved to LibGDX -public class BufferTexture extends SmartTexture { - - public IntBuffer pixels; - - public BufferTexture(int w, int h) { - super(); - width = w; - height = h; - pixels = ByteBuffer. - allocateDirect( w * h * 4 ). - order( ByteOrder.nativeOrder() ). - asIntBuffer(); - } - - @Override - protected void generate() { - id = Gdx.gl.glGenTexture(); - } - - @Override - public void reload() { - super.reload(); - update(); - } - - public void update(){ - bind(); - filter( Texture.LINEAR, Texture.LINEAR ); - wrap( Texture.CLAMP, Texture.CLAMP); - pixels.position(0); - Gdx.gl.glTexImage2D( - Gdx.gl.GL_TEXTURE_2D, - 0, - Gdx.gl.GL_RGBA, - width, - height, - 0, - Gdx.gl.GL_RGBA, - Gdx.gl.GL_UNSIGNED_BYTE, - pixels ); - } - - //allows partially updating the texture - public void update(int top, int bottom){ - bind(); - filter( Texture.LINEAR, Texture.LINEAR ); - wrap( Texture.CLAMP, Texture.CLAMP); - pixels.position(top*width); - Gdx.gl.glTexSubImage2D(Gdx.gl.GL_TEXTURE_2D, - 0, - 0, - top, - width, - bottom - top, - Gdx.gl.GL_RGBA, - Gdx.gl.GL_UNSIGNED_BYTE, - pixels); - } -} 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 9a3c6a27a..0bc4f0068 100644 --- a/SPD-classes/src/main/java/com/watabou/gltextures/SmartTexture.java +++ b/SPD-classes/src/main/java/com/watabou/gltextures/SmartTexture.java @@ -40,13 +40,6 @@ public class SmartTexture extends Texture { public Atlas atlas; - protected SmartTexture( ) { - //useful for subclasses which want to manage their own texture data - // in cases where pixmaps isn't fast enough. - - //subclasses which use this MUST also override some mix of reload/generate/bind - } - public SmartTexture( Pixmap bitmap ) { this( bitmap, NEAREST, CLAMP, false ); } diff --git a/SPD-classes/src/main/java/com/watabou/noosa/Game.java b/SPD-classes/src/main/java/com/watabou/noosa/Game.java index 30f45dfbd..adfec6f4e 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/Game.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/Game.java @@ -140,7 +140,6 @@ public class Game implements ApplicationListener { draw(); Gdx.gl.glDisable( Gdx.gl.GL_SCISSOR_TEST ); - Gdx.gl.glFlush(); step(); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/tiles/FogOfWar.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/tiles/FogOfWar.java index 5819c6c44..ff8dba680 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/tiles/FogOfWar.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/tiles/FogOfWar.java @@ -21,10 +21,12 @@ package com.shatteredpixel.shatteredpixeldungeon.tiles; +import com.badlogic.gdx.graphics.Pixmap; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; -import com.watabou.gltextures.BufferTexture; +import com.watabou.gltextures.SmartTexture; import com.watabou.gltextures.TextureCache; +import com.watabou.glwrap.Texture; import com.watabou.noosa.Image; import com.watabou.noosa.NoosaScript; import com.watabou.noosa.NoosaScriptNoLighting; @@ -109,8 +111,12 @@ public class FogOfWar extends Image { float size = DungeonTilemap.SIZE / PIX_PER_TILE; width = width2 * size; height = height2 * size; - - BufferTexture tx = new BufferTexture(width2, height2); + + //TODO might be nice to compartmentalize the pixmap access and modification into texture/texturecache + Pixmap px = new Pixmap(width2, height2, Pixmap.Format.RGBA8888); + px.setBlending(Pixmap.Blending.None); + px.fill(); + SmartTexture tx = new SmartTexture(px, Texture.LINEAR, Texture.CLAMP, false); TextureCache.add(FogOfWar.class, tx); texture( tx ); @@ -182,7 +188,7 @@ public class FogOfWar extends Image { } } - BufferTexture fog = (BufferTexture) texture; + Pixmap fog = texture.bitmap; int cell; @@ -273,11 +279,7 @@ public class FogOfWar extends Image { } - if (updating.size() == 1 && !fullUpdate){ - fog.update(updating.get(0).top * PIX_PER_TILE, updating.get(0).bottom * PIX_PER_TILE); - } else { - fog.update(); - } + texture.bitmap(fog); } @@ -298,31 +300,19 @@ public class FogOfWar extends Image { } } - private void fillLeft( BufferTexture fog, int x, int y, int color){ - for (int i = 0; i < PIX_PER_TILE; i++){ - fog.pixels.position(((y * PIX_PER_TILE)+i)*width2 + x * PIX_PER_TILE); - for (int j = 0; j < PIX_PER_TILE/2; j++) { - fog.pixels.put(color); - } - } + private void fillLeft( Pixmap fog, int x, int y, int color){ + fog.setColor((color << 8) | (color >>> 24)); + fog.fillRectangle(x * PIX_PER_TILE, y*PIX_PER_TILE, PIX_PER_TILE/2, PIX_PER_TILE); } - private void fillRight( BufferTexture fog, int x, int y, int color){ - for (int i = 0; i < PIX_PER_TILE; i++){ - fog.pixels.position(((y * PIX_PER_TILE)+i)*width2 + x * PIX_PER_TILE + PIX_PER_TILE/2); - for (int j = PIX_PER_TILE/2; j < PIX_PER_TILE; j++) { - fog.pixels.put(color); - } - } + private void fillRight( Pixmap fog, int x, int y, int color){ + fog.setColor((color << 8) | (color >>> 24)); + fog.fillRectangle(x * PIX_PER_TILE + PIX_PER_TILE/2, y*PIX_PER_TILE, PIX_PER_TILE/2, PIX_PER_TILE); } - private void fillCell( BufferTexture fog, int x, int y, int color){ - for (int i = 0; i < PIX_PER_TILE; i++){ - fog.pixels.position(((y * PIX_PER_TILE)+i)*width2 + x * PIX_PER_TILE); - for (int j = 0; j < PIX_PER_TILE; j++) { - fog.pixels.put(color); - } - } + private void fillCell( Pixmap fog, int x, int y, int color){ + fog.setColor((color << 8) | (color >>> 24)); + fog.fillRectangle(x * PIX_PER_TILE, y*PIX_PER_TILE, PIX_PER_TILE, PIX_PER_TILE); } @Override