Converted ShatteredPD to Build from Gradle

Major Changes:
- Shattered now builds effortlessly either from gradle CLI or android studio
- Much better dependency management through gradle (although it's not really used atm)
- Separate PD-classes repo is now SPD-classes module within main repo
This commit is contained in:
Evan Debenham
2016-08-13 02:11:29 -04:00
parent 188523b2a5
commit 36e44340a8
954 changed files with 8530 additions and 14 deletions

View File

@@ -0,0 +1,51 @@
/*
* 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 <http://www.gnu.org/licenses/>
*/
package com.watabou.glwrap;
import java.nio.FloatBuffer;
import android.opengl.GLES20;
public class Attribute {
private int location;
public Attribute( int location ) {
this.location = location;
}
public int location() {
return location;
}
public void enable() {
GLES20.glEnableVertexAttribArray( location );
}
public void disable() {
GLES20.glDisableVertexAttribArray( location );
}
public void vertexPointer( int size, int stride, FloatBuffer ptr ) {
GLES20.glVertexAttribPointer( location, size, GLES20.GL_FLOAT, false, stride * Float.SIZE / 8, ptr );
}
}

View File

@@ -0,0 +1,69 @@
/*
* 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 <http://www.gnu.org/licenses/>
*/
package com.watabou.glwrap;
import android.opengl.GLES20;
public class Framebuffer {
public static final int COLOR = GLES20.GL_COLOR_ATTACHMENT0;
public static final int DEPTH = GLES20.GL_DEPTH_ATTACHMENT;
public static final int STENCIL = GLES20.GL_STENCIL_ATTACHMENT;
public static final Framebuffer system = new Framebuffer( 0 );
private int id;
public Framebuffer() {
int[] buffers = new int[1];
GLES20.glGenBuffers( 1, buffers, 0 );
id = buffers[0];
}
private Framebuffer( int n ) {
}
public void bind() {
GLES20.glBindFramebuffer( GLES20.GL_FRAMEBUFFER, id );
}
public void delete() {
int[] buffers = {id};
GLES20.glDeleteFramebuffers( 1, buffers, 0 );
}
public void attach( int point, Texture tex ) {
bind();
GLES20.glFramebufferTexture2D( GLES20.GL_FRAMEBUFFER, point, GLES20.GL_TEXTURE_2D, tex.id, 0 );
}
public void attach( int point, Renderbuffer buffer ) {
bind();
GLES20.glFramebufferRenderbuffer( GLES20.GL_RENDERBUFFER, point, GLES20.GL_TEXTURE_2D, buffer.id() );
}
public boolean status() {
bind();
return GLES20.glCheckFramebufferStatus( GLES20.GL_FRAMEBUFFER ) == GLES20.GL_FRAMEBUFFER_COMPLETE;
}
}

View File

@@ -0,0 +1,103 @@
/*
* 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 <http://www.gnu.org/licenses/>
*/
package com.watabou.glwrap;
public class Matrix {
public static final float G2RAD = 0.01745329251994329576923690768489f;
public static float[] clone( float[] m ) {
int n = m.length;
float[] res = new float[n];
do {
res[--n] = m[n];
} while (n > 0);
return res;
}
public static void copy( float[] src, float[] dst ) {
int n = src.length;
do {
dst[--n] = src[n];
} while (n > 0);
}
public static void setIdentity( float[] m ) {
for (int i=0 ; i < 16 ; i++) {
m[i] = 0f;
}
for (int i = 0; i < 16; i += 5) {
m[i] = 1f;
}
}
public static void rotate( float[] m, float a ) {
a *= G2RAD;
float sin = (float)Math.sin( a );
float cos = (float)Math.cos( a );
float m0 = m[0];
float m1 = m[1];
float m4 = m[4];
float m5 = m[5];
m[0] = m0 * cos + m4 * sin;
m[1] = m1 * cos + m5 * sin;
m[4] = -m0 * sin + m4 * cos;
m[5] = -m1 * sin + m5 * cos;
}
public static void skewX( float[] m, float a ) {
double t = Math.tan( a * G2RAD );
m[4] += -m[0] * t;
m[5] += -m[1] * t;
}
public static void skewY( float[] m, float a ) {
double t = Math.tan( a * G2RAD );
m[0] += m[4] * t;
m[1] += m[5] * t;
}
public static void scale( float[] m, float x, float y ) {
m[0] *= x;
m[1] *= x;
m[2] *= x;
m[3] *= x;
m[4] *= y;
m[5] *= y;
m[6] *= y;
m[7] *= y;
// android.opengl.Matrix.scaleM( m, 0, x, y, 1 );
}
public static void translate( float[] m, float x, float y ) {
m[12] += m[0] * x + m[4] * y;
m[13] += m[1] * x + m[5] * y;
}
public static void multiply( float[] left, float right[], float[] result ) {
android.opengl.Matrix.multiplyMM( result, 0, left, 0, right, 0 );
}
}

View File

@@ -0,0 +1,76 @@
/*
* 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 <http://www.gnu.org/licenses/>
*/
package com.watabou.glwrap;
import android.opengl.GLES20;
public class Program {
private int handle;
public Program() {
handle = GLES20.glCreateProgram();
}
public int handle() {
return handle;
}
public void attach( Shader shader ) {
GLES20.glAttachShader( handle, shader.handle() );
}
public void link() {
GLES20.glLinkProgram( handle );
int[] status = new int[1];
GLES20.glGetProgramiv( handle, GLES20.GL_LINK_STATUS, status, 0 );
if (status[0] == GLES20.GL_FALSE) {
throw new Error( GLES20.glGetProgramInfoLog( handle ) );
}
}
public Attribute attribute( String name ) {
return new Attribute( GLES20.glGetAttribLocation( handle, name ) );
}
public Uniform uniform( String name ) {
return new Uniform( GLES20.glGetUniformLocation( handle, name ) );
}
public void use() {
GLES20.glUseProgram( handle );
}
public void delete() {
GLES20.glDeleteProgram( handle );
}
public static Program create( Shader ...shaders ) {
Program program = new Program();
for (int i=0; i < shaders.length; i++) {
program.attach( shaders[i] );
}
program.link();
return program;
}
}

View File

@@ -0,0 +1,140 @@
/*
* 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 <http://www.gnu.org/licenses/>
*/
package com.watabou.glwrap;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
public class Quad {
// 0---1
// | \ |
// 3---2
public static final short[] VALUES = {0, 1, 2, 0, 2, 3};
public static final int SIZE = VALUES.length;
private static ShortBuffer indices;
private static int indexSize = 0;
public static FloatBuffer create() {
return ByteBuffer.
allocateDirect( 16 * Float.SIZE / 8 ).
order( ByteOrder.nativeOrder() ).
asFloatBuffer();
}
public static FloatBuffer createSet( int size ) {
return ByteBuffer.
allocateDirect( size * 16 * Float.SIZE / 8 ).
order( ByteOrder.nativeOrder() ).
asFloatBuffer();
}
public static ShortBuffer getIndices( int size ) {
if (size > indexSize) {
// TODO: Optimize it!
indexSize = size;
indices = ByteBuffer.
allocateDirect( size * SIZE * Short.SIZE / 8 ).
order( ByteOrder.nativeOrder() ).
asShortBuffer();
short[] values = new short[size * 6];
int pos = 0;
int limit = size * 4;
for (int ofs=0; ofs < limit; ofs += 4) {
values[pos++] = (short)(ofs + 0);
values[pos++] = (short)(ofs + 1);
values[pos++] = (short)(ofs + 2);
values[pos++] = (short)(ofs + 0);
values[pos++] = (short)(ofs + 2);
values[pos++] = (short)(ofs + 3);
}
indices.put( values );
indices.position( 0 );
}
return indices;
}
public static void fill( float[] v,
float x1, float x2, float y1, float y2,
float u1, float u2, float v1, float v2 ) {
v[0] = x1;
v[1] = y1;
v[2] = u1;
v[3] = v1;
v[4] = x2;
v[5] = y1;
v[6] = u2;
v[7] = v1;
v[8] = x2;
v[9] = y2;
v[10]= u2;
v[11]= v2;
v[12]= x1;
v[13]= y2;
v[14]= u1;
v[15]= v2;
}
public static void fillXY( float[] v, float x1, float x2, float y1, float y2 ) {
v[0] = x1;
v[1] = y1;
v[4] = x2;
v[5] = y1;
v[8] = x2;
v[9] = y2;
v[12]= x1;
v[13]= y2;
}
public static void fillUV( float[] v, float u1, float u2, float v1, float v2 ) {
v[2] = u1;
v[3] = v1;
v[6] = u2;
v[7] = v1;
v[10]= u2;
v[11]= v2;
v[14]= u1;
v[15]= v2;
}
}

View File

@@ -0,0 +1,56 @@
/*
* 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 <http://www.gnu.org/licenses/>
*/
package com.watabou.glwrap;
import android.opengl.GLES20;
public class Renderbuffer {
public static final int RGBA8 = GLES20.GL_RGBA; // ?
public static final int DEPTH16 = GLES20.GL_DEPTH_COMPONENT16;
public static final int STENCIL8 = GLES20.GL_STENCIL_INDEX8;
private int id;
public Renderbuffer() {
int[] buffers = new int[1];
GLES20.glGenRenderbuffers( 1, buffers, 0 );
id = buffers[0];
}
public int id() {
return id;
}
public void bind() {
GLES20.glBindRenderbuffer( GLES20.GL_RENDERBUFFER, id );
}
public void delete() {
int[] buffers = {id};
GLES20.glDeleteRenderbuffers( 1, buffers, 0 );
}
public void storage( int format, int width, int height ) {
GLES20.glRenderbufferStorage( GLES20.GL_RENDERBUFFER, format , width, height );
}
}

View File

@@ -0,0 +1,65 @@
/*
* 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 <http://www.gnu.org/licenses/>
*/
package com.watabou.glwrap;
import android.opengl.GLES20;
public class Shader {
public static final int VERTEX = GLES20.GL_VERTEX_SHADER;
public static final int FRAGMENT = GLES20.GL_FRAGMENT_SHADER;
private int handle;
public Shader( int type ) {
handle = GLES20.glCreateShader( type );
}
public int handle() {
return handle;
}
public void source( String src ) {
GLES20.glShaderSource( handle, src );
}
public void compile() {
GLES20.glCompileShader( handle );
int[] status = new int[1];
GLES20.glGetShaderiv( handle, GLES20.GL_COMPILE_STATUS, status, 0 );
if (status[0] == GLES20.GL_FALSE) {
throw new Error( GLES20.glGetShaderInfoLog( handle ) );
}
}
public void delete() {
GLES20.glDeleteShader( handle );
}
public static Shader createCompiled( int type, String src ) {
Shader shader = new Shader( type );
shader.source( src );
shader.compile();
return shader;
}
}

View File

@@ -0,0 +1,183 @@
/*
* 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 <http://www.gnu.org/licenses/>
*/
package com.watabou.glwrap;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import android.graphics.Bitmap;
import android.opengl.GLES20;
import android.opengl.GLUtils;
public class Texture {
public static final int NEAREST = GLES20.GL_NEAREST;
public static final int LINEAR = GLES20.GL_LINEAR;
public static final int REPEAT = GLES20.GL_REPEAT;
public static final int MIRROR = GLES20.GL_MIRRORED_REPEAT;
public static final int CLAMP = GLES20.GL_CLAMP_TO_EDGE;
public int id;
private static int bound_id = 0; //id of the currently bound texture
public boolean premultiplied = false;
public Texture() {
int[] ids = new int[1];
GLES20.glGenTextures( 1, ids, 0 );
id = ids[0];
bind();
}
public static void activate( int index ) {
GLES20.glActiveTexture( GLES20.GL_TEXTURE0 + index );
}
public void bind() {
if (id != bound_id) {
GLES20.glBindTexture( GLES20.GL_TEXTURE_2D, id );
bound_id = id;
}
}
public void filter( int minMode, int maxMode ) {
bind();
GLES20.glTexParameterf( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, minMode );
GLES20.glTexParameterf( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, maxMode );
}
public void wrap( int s, int t ) {
bind();
GLES20.glTexParameterf( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, s );
GLES20.glTexParameterf( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, t );
}
public void delete() {
if (bound_id == id) bound_id = 0;
int[] ids = {id};
GLES20.glDeleteTextures( 1, ids, 0 );
}
public void bitmap( Bitmap bitmap ) {
bind();
GLUtils.texImage2D( GLES20.GL_TEXTURE_2D, 0, bitmap, 0 );
premultiplied = true;
}
public void pixels( int w, int h, int[] pixels ) {
bind();
IntBuffer imageBuffer = ByteBuffer.
allocateDirect( w * h * 4 ).
order( ByteOrder.nativeOrder() ).
asIntBuffer();
imageBuffer.put( pixels );
imageBuffer.position( 0 );
GLES20.glTexImage2D(
GLES20.GL_TEXTURE_2D,
0,
GLES20.GL_RGBA,
w,
h,
0,
GLES20.GL_RGBA,
GLES20.GL_UNSIGNED_BYTE,
imageBuffer );
}
public void pixels( int w, int h, byte[] pixels ) {
bind();
ByteBuffer imageBuffer = ByteBuffer.
allocateDirect( w * h ).
order( ByteOrder.nativeOrder() );
imageBuffer.put( pixels );
imageBuffer.position( 0 );
GLES20.glPixelStorei( GLES20.GL_UNPACK_ALIGNMENT, 1 );
GLES20.glTexImage2D(
GLES20.GL_TEXTURE_2D,
0,
GLES20.GL_ALPHA,
w,
h,
0,
GLES20.GL_ALPHA,
GLES20.GL_UNSIGNED_BYTE,
imageBuffer );
}
// If getConfig returns null (unsupported format?), GLUtils.texImage2D works
// incorrectly. In this case we need to load pixels manually
public void handMade( Bitmap bitmap, boolean recode ) {
int w = bitmap.getWidth();
int h = bitmap.getHeight();
int[] pixels = new int[w * h];
bitmap.getPixels( pixels, 0, w, 0, 0, w, h );
// recode - components reordering is needed
if (recode) {
for (int i=0; i < pixels.length; i++) {
int color = pixels[i];
int ag = color & 0xFF00FF00;
int r = (color >> 16) & 0xFF;
int b = color & 0xFF;
pixels[i] = ag | (b << 16) | r;
}
}
pixels( w, h, pixels );
premultiplied = false;
}
public static Texture create( Bitmap bmp ) {
Texture tex = new Texture();
tex.bitmap( bmp );
return tex;
}
public static Texture create( int width, int height, int[] pixels ) {
Texture tex = new Texture();
tex.pixels( width, height, pixels );
return tex;
}
public static Texture create( int width, int height, byte[] pixels ) {
Texture tex = new Texture();
tex.pixels( width, height, pixels );
return tex;
}
}

View File

@@ -0,0 +1,69 @@
/*
* 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 <http://www.gnu.org/licenses/>
*/
package com.watabou.glwrap;
import android.opengl.GLES20;
public class Uniform {
private int location;
public Uniform( int location ) {
this.location = location;
}
public int location() {
return location;
}
public void enable() {
GLES20.glEnableVertexAttribArray( location );
}
public void disable() {
GLES20.glDisableVertexAttribArray( location );
}
public void value( int value ) {
GLES20.glUniform1i( location, value );
}
public void value1f( float value ) {
GLES20.glUniform1f( location, value );
}
public void value2f( float v1, float v2 ) {
GLES20.glUniform2f( location, v1, v2 );
}
public void value4f( float v1, float v2, float v3, float v4 ) {
GLES20.glUniform4f( location, v1, v2, v3, v4 );
}
public void valueM3( float[] value ) {
GLES20.glUniformMatrix3fv( location, 1, false, value, 0 );
}
public void valueM4( float[] value ) {
GLES20.glUniformMatrix4fv( location, 1, false, value, 0 );
}
}