v0.7.4b: Initial LibGDX commit! more details below:

Large sections of game logic are now working through libgdx instead of
android libraries. There is still work to do but this is the first
major step. Big changes include:
- Graphics code is now through LibGDX (except for text rendering)
- Initialization and screen-handling logic is now mostly through LibGDX
- Audio is now through LibGDX
- Input handling is now through LibGDX
- Most misc functions are now through LibGDX
This commit is contained in:
Evan Debenham
2019-07-30 16:50:40 -04:00
parent f10be84a10
commit 2a523f2ea2
42 changed files with 828 additions and 972 deletions

View File

@@ -21,15 +21,15 @@
package com.watabou.gltextures;
import android.opengl.GLES20;
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 android.graphics.bitmap is too slow
//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;
@@ -46,9 +46,7 @@ public class BufferTexture extends SmartTexture {
@Override
protected void generate() {
int[] ids = new int[1];
GLES20.glGenTextures( 1, ids, 0 );
id = ids[0];
id = Gdx.gl.glGenTexture();
}
@Override
@@ -62,15 +60,15 @@ public class BufferTexture extends SmartTexture {
filter( Texture.LINEAR, Texture.LINEAR );
wrap( Texture.CLAMP, Texture.CLAMP);
pixels.position(0);
GLES20.glTexImage2D(
GLES20.GL_TEXTURE_2D,
Gdx.gl.glTexImage2D(
Gdx.gl.GL_TEXTURE_2D,
0,
GLES20.GL_RGBA,
Gdx.gl.GL_RGBA,
width,
height,
0,
GLES20.GL_RGBA,
GLES20.GL_UNSIGNED_BYTE,
Gdx.gl.GL_RGBA,
Gdx.gl.GL_UNSIGNED_BYTE,
pixels );
}
@@ -80,14 +78,14 @@ public class BufferTexture extends SmartTexture {
filter( Texture.LINEAR, Texture.LINEAR );
wrap( Texture.CLAMP, Texture.CLAMP);
pixels.position(top*width);
GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D,
Gdx.gl.glTexSubImage2D(Gdx.gl.GL_TEXTURE_2D,
0,
0,
top,
width,
bottom - top,
GLES20.GL_RGBA,
GLES20.GL_UNSIGNED_BYTE,
Gdx.gl.GL_RGBA,
Gdx.gl.GL_UNSIGNED_BYTE,
pixels);
}
}

View File

@@ -21,8 +21,7 @@
package com.watabou.gltextures;
import android.graphics.Bitmap;
import com.badlogic.gdx.graphics.Pixmap;
import com.watabou.glwrap.Texture;
import com.watabou.utils.RectF;
@@ -37,22 +36,22 @@ public class SmartTexture extends Texture {
public int wModeH;
public int wModeV;
public Bitmap bitmap;
public Pixmap bitmap;
public Atlas atlas;
protected SmartTexture( ) {
//useful for subclasses which want to manage their own texture data
// in cases where android.graphics.bitmap isn't fast enough.
// in cases where pixmaps isn't fast enough.
//subclasses which use this MUST also override some mix of reload/generate/bind
}
public SmartTexture( Bitmap bitmap ) {
public SmartTexture( Pixmap bitmap ) {
this( bitmap, NEAREST, CLAMP, false );
}
public SmartTexture( Bitmap bitmap, int filtering, int wrapping, boolean premultiplied ) {
public SmartTexture( Pixmap bitmap, int filtering, int wrapping, boolean premultiplied ) {
this.bitmap = bitmap;
width = bitmap.getWidth();
@@ -66,7 +65,7 @@ public class SmartTexture extends Texture {
@Override
protected void generate() {
super.generate();
bitmap( bitmap, premultiplied );
bitmap( bitmap );
filter( fModeMin, fModeMax );
wrap( wModeH, wModeV );
}
@@ -88,16 +87,8 @@ public class SmartTexture extends Texture {
}
@Override
public void bitmap( Bitmap bitmap ) {
bitmap( bitmap, false );
}
public void bitmap( Bitmap bitmap, boolean premultiplied ) {
if (premultiplied) {
super.bitmap( bitmap );
} else {
handMade( bitmap, true );
}
public void bitmap( Pixmap bitmap ) {
super.bitmap( bitmap );
this.bitmap = bitmap;
width = bitmap.getWidth();
@@ -119,7 +110,7 @@ public class SmartTexture extends Texture {
super.delete();
if (bitmap != null)
bitmap.recycle();
bitmap.dispose();
bitmap = null;
}

View File

@@ -21,28 +21,16 @@
package com.watabou.gltextures;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import com.watabou.glwrap.Texture;
import com.watabou.noosa.Game;
import java.util.HashMap;
public class TextureCache {
public static Context context;
private static HashMap<Object,SmartTexture> all = new HashMap<>();
// No dithering, no scaling, 32 bits per pixel
private static BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
static {
bitmapOptions.inScaled = false;
bitmapOptions.inDither = false;
bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
}
public synchronized static SmartTexture createSolid( int color ) {
final String key = "1x1:" + color;
@@ -52,11 +40,13 @@ public class TextureCache {
return all.get( key );
} else {
Bitmap bmp = Bitmap.createBitmap( 1, 1, Bitmap.Config.ARGB_8888 );
bmp.eraseColor( color );
SmartTexture tx = new SmartTexture( bmp );
Pixmap pixmap =new Pixmap( 1, 1, Pixmap.Format.RGBA8888 );
// In the rest of the code ARGB is used
pixmap.setColor( (color << 8) | (color >>> 24) );
pixmap.fill();
SmartTexture tx = new SmartTexture( pixmap );
all.put( key, tx );
return tx;
@@ -72,12 +62,13 @@ public class TextureCache {
return all.get( key );
} else {
Bitmap bmp = Bitmap.createBitmap( colors.length, 1, Bitmap.Config.ARGB_8888 );
Pixmap pixmap = new Pixmap( colors.length, 1, Pixmap.Format.RGBA8888);
for (int i=0; i < colors.length; i++) {
bmp.setPixel( i, 0, colors[i] );
// In the rest of the code ARGB is used
pixmap.drawPixel( i, 0, (colors[i] << 8) | (colors[i] >>> 24) );
}
SmartTexture tx = new SmartTexture( bmp );
SmartTexture tx = new SmartTexture( pixmap );
tx.filter( Texture.LINEAR, Texture.LINEAR );
tx.wrap( Texture.CLAMP, Texture.CLAMP );
@@ -134,22 +125,22 @@ public class TextureCache {
}
}
public static Bitmap getBitmap( Object src ) {
public static Pixmap getBitmap( Object src ) {
try {
if (src instanceof Integer){
return BitmapFactory.decodeResource(
context.getResources(), (Integer)src, bitmapOptions );
//LibGDX does not support android resource integer handles, and they were
//never used by the game anyway, should probably remove this entirely
return null;
} else if (src instanceof String) {
return BitmapFactory.decodeStream(
context.getAssets().open( (String)src ), null, bitmapOptions );
return new Pixmap(Gdx.files.internal((String)src));
} else if (src instanceof Bitmap) {
} else if (src instanceof Pixmap) {
return (Bitmap)src;
return (Pixmap)src;
} else {