v0.6.3: refactored all opengl code out of the core module (except fog)

This commit is contained in:
Evan Debenham 2017-12-27 02:58:45 -05:00
parent 7afd8b8889
commit 6abb58fd81
18 changed files with 105 additions and 85 deletions

View File

@ -0,0 +1,53 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2017 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 <http://www.gnu.org/licenses/>
*/
package com.watabou.glwrap;
import android.opengl.GLES20;
import javax.microedition.khronos.opengles.GL10;
public class Blending {
public static void useDefault(){
enable();
setNormalMode();
}
public static void enable(){
GLES20.glEnable( GL10.GL_BLEND );
}
public static void disable(){
GLES20.glDisable( GL10.GL_BLEND );
}
//in this mode colors overwrite eachother, based on alpha value
public static void setNormalMode(){
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
}
//in this mode colors add to eachother, eventually reaching pure white
public static void setLightMode(){
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
}
}

View File

@ -39,6 +39,7 @@ import android.view.View;
import com.watabou.glscripts.Script;
import com.watabou.gltextures.TextureCache;
import com.watabou.glwrap.Blending;
import com.watabou.glwrap.ScreenConfigChooser;
import com.watabou.glwrap.Vertexbuffer;
import com.watabou.input.Keys;
@ -307,8 +308,7 @@ public class Game extends Activity implements GLSurfaceView.Renderer, View.OnTou
@Override
public void onSurfaceCreated( GL10 gl, EGLConfig config ) {
GLES20.glEnable( GL10.GL_BLEND );
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
Blending.useDefault();
//refreshes texture and vertex data stored on the gpu
TextureCache.reload();

View File

@ -21,10 +21,7 @@
package com.watabou.noosa.particles;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLES20;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.Game;
import com.watabou.noosa.Group;
import com.watabou.noosa.Visual;
@ -150,9 +147,9 @@ public class Emitter extends Group {
@Override
public void draw() {
if (lightMode) {
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
Blending.setLightMode();
super.draw();
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
Blending.setNormalMode();
} else {
super.draw();
}

View File

@ -21,15 +21,13 @@
package com.shatteredpixel.shatteredpixeldungeon.effects;
import android.opengl.GLES20;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.PointF;
import javax.microedition.khronos.opengles.GL10;
public class Beam extends Image {
private static final double A = 180 / Math.PI;
@ -89,8 +87,8 @@ public class Beam extends Image {
@Override
public void draw() {
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
Blending.setLightMode();
super.draw();
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
Blending.setNormalMode();
}
}

View File

@ -21,14 +21,12 @@
package com.shatteredpixel.shatteredpixeldungeon.effects;
import android.opengl.GLES20;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.Group;
import com.watabou.noosa.particles.PixelParticle;
import com.watabou.utils.PointF;
import com.watabou.utils.Random;
import javax.microedition.khronos.opengles.GL10;
public class Degradation extends Group {
private static int[] WEAPON = {
@ -114,9 +112,9 @@ public class Degradation extends Group {
@Override
public void draw() {
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
Blending.setLightMode();
super.draw();
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
Blending.setNormalMode();
}
public static class Speck extends PixelParticle {

View File

@ -22,8 +22,9 @@
package com.shatteredpixel.shatteredpixeldungeon.effects;
import android.graphics.RectF;
import android.opengl.GLES20;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.watabou.glwrap.Blending;
import com.watabou.glwrap.Texture;
import com.watabou.noosa.Game;
import com.watabou.noosa.Group;
@ -34,8 +35,6 @@ import com.watabou.noosa.ui.Component;
import com.watabou.utils.ColorMath;
import com.watabou.utils.Random;
import javax.microedition.khronos.opengles.GL10;
public class Fireball extends Component {
private static final RectF BLIGHT = new RectF( 0, 0, 0.25f, 1 );
@ -118,9 +117,9 @@ public class Fireball extends Component {
@Override
public void draw() {
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
Blending.setLightMode();
super.draw();
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
Blending.setNormalMode();
}
public static class Flame extends Image {

View File

@ -22,10 +22,10 @@
package com.shatteredpixel.shatteredpixeldungeon.effects;
import android.annotation.SuppressLint;
import android.opengl.GLES20;
import com.watabou.gltextures.SmartTexture;
import com.watabou.gltextures.TextureCache;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.Game;
import com.watabou.noosa.Group;
import com.watabou.noosa.NoosaScript;
@ -37,8 +37,6 @@ import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
import javax.microedition.khronos.opengles.GL10;
public class Flare extends Visual {
private float duration = 0;
@ -158,9 +156,9 @@ public class Flare extends Visual {
super.draw();
if (lightMode) {
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
Blending.setLightMode();
drawRays();
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
Blending.setNormalMode();
} else {
drawRays();
}

View File

@ -21,14 +21,12 @@
package com.shatteredpixel.shatteredpixeldungeon.effects;
import android.opengl.GLES20;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.Group;
import com.watabou.noosa.particles.PixelParticle;
import com.watabou.utils.PointF;
import com.watabou.utils.Random;
import javax.microedition.khronos.opengles.GL10;
public class Identification extends Group {
private static int[] DOTS = {
@ -62,9 +60,9 @@ public class Identification extends Group {
@Override
public void draw() {
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
Blending.setLightMode();
super.draw();
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
Blending.setNormalMode();
}
public static class Speck extends PixelParticle {

View File

@ -21,9 +21,9 @@
package com.shatteredpixel.shatteredpixeldungeon.effects;
import android.opengl.GLES20;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.Game;
import com.watabou.noosa.Group;
import com.watabou.noosa.Image;
@ -32,7 +32,6 @@ import com.watabou.utils.Callback;
import com.watabou.utils.PointF;
import com.watabou.utils.Random;
import javax.microedition.khronos.opengles.GL10;
import java.util.Arrays;
import java.util.List;
@ -102,9 +101,9 @@ public class Lightning extends Group {
@Override
public void draw() {
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
Blending.setLightMode();
super.draw();
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
Blending.setNormalMode();
}
//A lightning object is meant to be loaded up with arcs.

View File

@ -21,12 +21,10 @@
package com.shatteredpixel.shatteredpixeldungeon.effects;
import android.opengl.GLES20;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.Game;
import javax.microedition.khronos.opengles.GL10;
public class TorchHalo extends Halo {
private CharSprite target;
@ -63,9 +61,9 @@ public class TorchHalo extends Halo {
@Override
public void draw() {
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
Blending.setLightMode();
super.draw();
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
Blending.setNormalMode();
}
public void putOut() {

View File

@ -21,8 +21,6 @@
package com.shatteredpixel.shatteredpixeldungeon.levels;
import android.opengl.GLES20;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.items.Torch;
@ -47,14 +45,13 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.traps.WarpingTrap;
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.WeakeningTrap;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.Game;
import com.watabou.noosa.Group;
import com.watabou.noosa.particles.PixelParticle;
import com.watabou.utils.PointF;
import com.watabou.utils.Random;
import javax.microedition.khronos.opengles.GL10;
public class HallsLevel extends RegularLevel {
{
@ -199,9 +196,9 @@ public class HallsLevel extends RegularLevel {
@Override
public void draw() {
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
Blending.setLightMode();
super.draw();
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
Blending.setNormalMode();
}
}

View File

@ -21,8 +21,6 @@
package com.shatteredpixel.shatteredpixeldungeon.scenes;
import android.opengl.GLES20;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
@ -94,6 +92,7 @@ import com.shatteredpixel.shatteredpixeldungeon.windows.WndMessage;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndStory;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndTradeItem;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Group;
@ -185,9 +184,9 @@ public class GameScene extends PixelScene {
@Override
public void draw() {
//water has no alpha component, this improves performance
GLES20.glBlendFunc( GLES20.GL_ONE, GLES20.GL_ZERO );
Blending.disable();
super.draw();
GLES20.glBlendFunc( GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA );
Blending.enable();
}
};
terrain.add( water );

View File

@ -21,12 +21,12 @@
package com.shatteredpixel.shatteredpixeldungeon.scenes;
import android.opengl.GLES20;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.effects.BadgeBanner;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.watabou.glwrap.Blending;
import com.watabou.glwrap.Texture;
import com.watabou.input.Touchscreen;
import com.watabou.noosa.BitmapText;
@ -41,8 +41,6 @@ import com.watabou.noosa.Visual;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.BitmapCache;
import javax.microedition.khronos.opengles.GL10;
public class PixelScene extends Scene {
// Minimum virtual display size for portrait orientation
@ -240,7 +238,7 @@ public class PixelScene extends Scene {
if (noFade) {
noFade = false;
} else {
fadeIn( 0xFF000000, false );
fadeIn( 0xFF000000, true );
}
}
@ -291,9 +289,9 @@ public class PixelScene extends Scene {
@Override
public void draw() {
if (light) {
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
Blending.setLightMode();
super.draw();
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
Blending.setNormalMode();
} else {
super.draw();
}

View File

@ -21,8 +21,6 @@
package com.shatteredpixel.shatteredpixeldungeon.scenes;
import android.opengl.GLES20;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.effects.BannerSprites;
@ -33,6 +31,7 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.ChangesButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.LanguageButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.PrefsButton;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
@ -42,8 +41,6 @@ import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
import javax.microedition.khronos.opengles.GL10;
public class TitleScene extends PixelScene {
@Override
@ -88,9 +85,9 @@ public class TitleScene extends PixelScene {
}
@Override
public void draw() {
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
Blending.setLightMode();
super.draw();
GLES20.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
Blending.setNormalMode();
}
};
signs.x = title.x + (title.width() - signs.width())/2f;

View File

@ -21,8 +21,6 @@
package com.shatteredpixel.shatteredpixeldungeon.scenes;
import android.opengl.GLES20;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Rankings;
@ -32,13 +30,12 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.Fireball;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.audio.Sample;
import javax.microedition.khronos.opengles.GL10;
public class WelcomeScene extends PixelScene {
private static int LATEST_UPDATE = ShatteredPixelDungeon.v0_6_2;
@ -83,9 +80,9 @@ public class WelcomeScene extends PixelScene {
}
@Override
public void draw() {
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
Blending.setLightMode();
super.draw();
GLES20.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
Blending.setNormalMode();
}
};
signs.x = title.x + (title.width() - signs.width())/2f;

View File

@ -21,15 +21,12 @@
package com.shatteredpixel.shatteredpixeldungeon.sprites;
import android.opengl.GLES20;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShaftParticle;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.TextureFilm;
import javax.microedition.khronos.opengles.GL10;
public class GhostSprite extends MobSprite {
public GhostSprite() {
@ -56,9 +53,9 @@ public class GhostSprite extends MobSprite {
@Override
public void draw() {
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
Blending.setLightMode();
super.draw();
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
Blending.setNormalMode();
}
@Override

View File

@ -21,18 +21,16 @@
package com.shatteredpixel.shatteredpixeldungeon.sprites;
import android.opengl.GLES20;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.effects.Halo;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ElmoParticle;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.Game;
import com.watabou.noosa.TextureFilm;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.PointF;
import javax.microedition.khronos.opengles.GL10;
public class WandmakerSprite extends MobSprite {
private Shield shield;
@ -115,9 +113,9 @@ public class WandmakerSprite extends MobSprite {
@Override
public void draw() {
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
Blending.setLightMode();
super.draw();
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
Blending.setNormalMode();
}
public void putOut() {

View File

@ -21,9 +21,8 @@
package com.shatteredpixel.shatteredpixeldungeon.ui;
import android.opengl.GLES20;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.Game;
import com.watabou.noosa.NoosaScript;
import com.watabou.noosa.NoosaScriptNoLighting;
@ -53,9 +52,9 @@ public class Archs extends Component {
@Override
public void draw() {
//arch bg has no alpha component, this improves performance
GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ZERO);
Blending.disable();
super.draw();
GLES20.glBlendFunc( GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA );
Blending.enable();
}
};
arcsBg.autoAdjust = true;