diff --git a/SPD-classes/src/main/AndroidManifest.xml b/SPD-classes/src/main/AndroidManifest.xml index c85e822df..a753de49d 100644 --- a/SPD-classes/src/main/AndroidManifest.xml +++ b/SPD-classes/src/main/AndroidManifest.xml @@ -1,6 +1,12 @@ + + + + diff --git a/SPD-classes/src/main/java/com/watabou/glwrap/Attribute.java b/SPD-classes/src/main/java/com/watabou/glwrap/Attribute.java index 9b495b25a..af2c8a56b 100644 --- a/SPD-classes/src/main/java/com/watabou/glwrap/Attribute.java +++ b/SPD-classes/src/main/java/com/watabou/glwrap/Attribute.java @@ -24,6 +24,7 @@ package com.watabou.glwrap; import java.nio.FloatBuffer; import android.opengl.GLES20; +import android.os.Build; public class Attribute { @@ -50,6 +51,10 @@ public class Attribute { } public void vertexBuffer( int size, int stride, int offset) { - GLES20.glVertexAttribPointer( location, size, GLES20.GL_FLOAT, false, stride * Float.SIZE / 8, offset * Float.SIZE / 8 ); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { + GLES20.glVertexAttribPointer(location, size, GLES20.GL_FLOAT, false, stride * Float.SIZE / 8, offset * Float.SIZE / 8); + } else { + FroyoGLES20Fix.glVertexAttribPointer(location, size, GLES20.GL_FLOAT, false, stride * Float.SIZE / 8, offset * Float.SIZE / 8); + } } } diff --git a/SPD-classes/src/main/java/com/watabou/glwrap/FroyoGLES20Fix.java b/SPD-classes/src/main/java/com/watabou/glwrap/FroyoGLES20Fix.java new file mode 100644 index 000000000..337e572fe --- /dev/null +++ b/SPD-classes/src/main/java/com/watabou/glwrap/FroyoGLES20Fix.java @@ -0,0 +1,50 @@ +/* + * Pixel Dungeon + * Copyright (C) 2012-2015 Oleg Dolya + * + * Shattered Pixel Dungeon + * Copyright (C) 2014-2016 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.glwrap; + +//This class exists because the back-end OpenGL implementation (written in C) +// supports VBO operations (along with the rest of GLES 2.0) since android 2.2 (Froyo, api 8), +// but for some reason the Java calls for these methods were only added in 2.3 (Gingerbread, api 9) + +//So this class is here specifically to reference an armabi/x86 compiled binary +// which gives us Java hooks for VBOs on android 2.2 + +//...I don't know what google engineer forgot to put the java hooks in android 2.2 back in 2010, +// but you know who you are and this class is your fault. + +//Note that compiled binares are included with this source, +// so the android NDK is not needed to compile this project + +//DO NOT REFERENCE THIS CLASS ON DEVICES API 9 AND ABOVE, use android.opengl.GLES20 instead. +@SuppressWarnings("JniMissingFunction") +public class FroyoGLES20Fix { + + static + { + System.loadLibrary("FroyoGLES20Fix"); + } + + native public static void glVertexAttribPointer(int index, int size, int type, boolean normalized, int stride, int offset); + + native public static void glDrawElements(int mode, int count, int type, int offset); + +} diff --git a/SPD-classes/src/main/java/com/watabou/noosa/NoosaScript.java b/SPD-classes/src/main/java/com/watabou/noosa/NoosaScript.java index a59e5a558..63900ff52 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/NoosaScript.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/NoosaScript.java @@ -25,8 +25,10 @@ import java.nio.FloatBuffer; import java.nio.ShortBuffer; import android.opengl.GLES20; +import android.os.Build; import com.watabou.glscripts.Script; +import com.watabou.glwrap.FroyoGLES20Fix; import com.watabou.glwrap.Attribute; import com.watabou.glwrap.Quad; import com.watabou.glwrap.Uniform; @@ -85,7 +87,6 @@ public class NoosaScript extends Script { Quad.bindIndices(); } - //FIXME need to do some voodoo to get this working properly on android 2.2 public void drawQuad( FloatBuffer vertices ) { vertices.position( 0 ); @@ -94,7 +95,11 @@ public class NoosaScript extends Script { vertices.position( 2 ); aUV.vertexPointer( 2, 4, vertices ); - GLES20.glDrawElements( GLES20.GL_TRIANGLES, Quad.SIZE, GLES20.GL_UNSIGNED_SHORT, 0 ); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { + GLES20.glDrawElements( GLES20.GL_TRIANGLES, Quad.SIZE, GLES20.GL_UNSIGNED_SHORT, 0 ); + } else { + FroyoGLES20Fix.glDrawElements( GLES20.GL_TRIANGLES, Quad.SIZE, GLES20.GL_UNSIGNED_SHORT, 0 ); + } } @@ -109,7 +114,11 @@ public class NoosaScript extends Script { buffer.release(); - GLES20.glDrawElements( GLES20.GL_TRIANGLES, Quad.SIZE, GLES20.GL_UNSIGNED_SHORT, 0 ); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { + GLES20.glDrawElements( GLES20.GL_TRIANGLES, Quad.SIZE, GLES20.GL_UNSIGNED_SHORT, 0 ); + } else { + FroyoGLES20Fix.glDrawElements( GLES20.GL_TRIANGLES, Quad.SIZE, GLES20.GL_UNSIGNED_SHORT, 0 ); + } } public void drawQuadSet( FloatBuffer vertices, int size ) { @@ -124,7 +133,11 @@ public class NoosaScript extends Script { vertices.position( 2 ); aUV.vertexPointer( 2, 4, vertices ); - GLES20.glDrawElements( GLES20.GL_TRIANGLES, Quad.SIZE * size, GLES20.GL_UNSIGNED_SHORT, 0 ); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { + GLES20.glDrawElements( GLES20.GL_TRIANGLES, Quad.SIZE * size, GLES20.GL_UNSIGNED_SHORT, 0 ); + } else { + FroyoGLES20Fix.glDrawElements( GLES20.GL_TRIANGLES, Quad.SIZE * size, GLES20.GL_UNSIGNED_SHORT, 0 ); + } } @@ -143,7 +156,11 @@ public class NoosaScript extends Script { buffer.release(); - GLES20.glDrawElements( GLES20.GL_TRIANGLES, Quad.SIZE * length, GLES20.GL_UNSIGNED_SHORT, Quad.SIZE * offset ); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { + GLES20.glDrawElements( GLES20.GL_TRIANGLES, Quad.SIZE * length, GLES20.GL_UNSIGNED_SHORT, Quad.SIZE * offset ); + } else { + FroyoGLES20Fix.glDrawElements( GLES20.GL_TRIANGLES, Quad.SIZE * length, GLES20.GL_UNSIGNED_SHORT, Quad.SIZE * offset ); + } } public void lighting( float rm, float gm, float bm, float am, float ra, float ga, float ba, float aa ) { diff --git a/SPD-classes/src/main/jniLibs/armeabi/libFroyoGLES20Fix.so b/SPD-classes/src/main/jniLibs/armeabi/libFroyoGLES20Fix.so new file mode 100644 index 000000000..c71ffc321 Binary files /dev/null and b/SPD-classes/src/main/jniLibs/armeabi/libFroyoGLES20Fix.so differ diff --git a/SPD-classes/src/main/jniLibs/x86/libFroyoGLES20Fix.so b/SPD-classes/src/main/jniLibs/x86/libFroyoGLES20Fix.so new file mode 100644 index 000000000..9e0647f80 Binary files /dev/null and b/SPD-classes/src/main/jniLibs/x86/libFroyoGLES20Fix.so differ