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,8 +21,7 @@
package com.watabou.glwrap;
import android.opengl.GLES20;
import android.os.Build;
import com.badlogic.gdx.Gdx;
import java.nio.FloatBuffer;
@@ -39,18 +38,18 @@ public class Attribute {
}
public void enable() {
GLES20.glEnableVertexAttribArray( location );
Gdx.gl.glEnableVertexAttribArray( location );
}
public void disable() {
GLES20.glDisableVertexAttribArray( location );
Gdx.gl.glDisableVertexAttribArray( location );
}
public void vertexPointer( int size, int stride, FloatBuffer ptr ) {
GLES20.glVertexAttribPointer( location, size, GLES20.GL_FLOAT, false, stride * 4, ptr );
Gdx.gl.glVertexAttribPointer( location, size, Gdx.gl.GL_FLOAT, false, stride * 4, ptr );
}
public void vertexBuffer( int size, int stride, int offset) {
GLES20.glVertexAttribPointer(location, size, GLES20.GL_FLOAT, false, stride * 4, offset * 4);
Gdx.gl.glVertexAttribPointer(location, size, Gdx.gl.GL_FLOAT, false, stride * 4, offset * 4);
}
}

View File

@@ -21,7 +21,7 @@
package com.watabou.glwrap;
import android.opengl.GLES20;
import com.badlogic.gdx.Gdx;
import javax.microedition.khronos.opengles.GL10;
@@ -33,21 +33,21 @@ public class Blending {
}
public static void enable(){
GLES20.glEnable( GL10.GL_BLEND );
Gdx.gl.glEnable( GL10.GL_BLEND );
}
public static void disable(){
GLES20.glDisable( GL10.GL_BLEND );
Gdx.gl.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 );
Gdx.gl.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 );
Gdx.gl.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
}
}

View File

@@ -21,22 +21,20 @@
package com.watabou.glwrap;
import android.opengl.GLES20;
import com.badlogic.gdx.Gdx;
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 int COLOR = Gdx.gl.GL_COLOR_ATTACHMENT0;
public static final int DEPTH = Gdx.gl.GL_DEPTH_ATTACHMENT;
public static final int STENCIL = Gdx.gl.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];
id = Gdx.gl.glGenBuffer();
}
private Framebuffer( int n ) {
@@ -44,26 +42,25 @@ public class Framebuffer {
}
public void bind() {
GLES20.glBindFramebuffer( GLES20.GL_FRAMEBUFFER, id );
Gdx.gl.glBindFramebuffer( Gdx.gl.GL_FRAMEBUFFER, id );
}
public void delete() {
int[] buffers = {id};
GLES20.glDeleteFramebuffers( 1, buffers, 0 );
Gdx.gl.glDeleteBuffer(id);
}
public void attach( int point, Texture tex ) {
bind();
GLES20.glFramebufferTexture2D( GLES20.GL_FRAMEBUFFER, point, GLES20.GL_TEXTURE_2D, tex.id, 0 );
Gdx.gl.glFramebufferTexture2D( Gdx.gl.GL_FRAMEBUFFER, point, Gdx.gl.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() );
Gdx.gl.glFramebufferRenderbuffer( Gdx.gl.GL_RENDERBUFFER, point, Gdx.gl.GL_TEXTURE_2D, buffer.id() );
}
public boolean status() {
bind();
return GLES20.glCheckFramebufferStatus( GLES20.GL_FRAMEBUFFER ) == GLES20.GL_FRAMEBUFFER_COMPLETE;
return Gdx.gl.glCheckFramebufferStatus( Gdx.gl.GL_FRAMEBUFFER ) == Gdx.gl.GL_FRAMEBUFFER_COMPLETE;
}
}

View File

@@ -21,6 +21,8 @@
package com.watabou.glwrap;
//TODO LibGDX offer matrix classes as well, which might give better performance.
//should investigate using them
public class Matrix {
public static final float G2RAD = 0.01745329251994329576923690768489f;
@@ -91,7 +93,6 @@ public class Matrix {
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 ) {
@@ -100,6 +101,64 @@ public class Matrix {
}
public static void multiply( float[] left, float right[], float[] result ) {
android.opengl.Matrix.multiplyMM( result, 0, left, 0, right, 0 );
final float ax1 = left[0];
final float ay1 = left[1];
final float az1 = left[2];
final float aw1 = left[3];
final float ax2 = left[4];
final float ay2 = left[5];
final float az2 = left[6];
final float aw2 = left[7];
final float ax3 = left[8];
final float ay3 = left[9];
final float az3 = left[10];
final float aw3 = left[11];
final float ax4 = left[12];
final float ay4 = left[13];
final float az4 = left[14];
final float aw4 = left[15];
final float bx1 = right[0];
final float by1 = right[1];
final float bz1 = right[2];
final float bw1 = right[3];
final float bx2 = right[4];
final float by2 = right[5];
final float bz2 = right[6];
final float bw2 = right[7];
final float bx3 = right[8];
final float by3 = right[9];
final float bz3 = right[10];
final float bw3 = right[11];
final float bx4 = right[12];
final float by4 = right[13];
final float bz4 = right[14];
final float bw4 = right[15];
result[0] = ax1 * bx1 + ax2 * by1 + ax3 * bz1 + ax4 * bw1;
result[1] = ay1 * bx1 + ay2 * by1 + ay3 * bz1 + ay4 * bw1;
result[2] = az1 * bx1 + az2 * by1 + az3 * bz1 + az4 * bw1;
result[3] = aw1 * bx1 + aw2 * by1 + aw3 * bz1 + aw4 * bw1;
result[4] = ax1 * bx2 + ax2 * by2 + ax3 * bz2 + ax4 * bw2;
result[5] = ay1 * bx2 + ay2 * by2 + ay3 * bz2 + ay4 * bw2;
result[6] = az1 * bx2 + az2 * by2 + az3 * bz2 + az4 * bw2;
result[7] = aw1 * bx2 + aw2 * by2 + aw3 * bz2 + aw4 * bw2;
result[8] = ax1 * bx3 + ax2 * by3 + ax3 * bz3 + ax4 * bw3;
result[9] = ay1 * bx3 + ay2 * by3 + ay3 * bz3 + ay4 * bw3;
result[10] = az1 * bx3 + az2 * by3 + az3 * bz3 + az4 * bw3;
result[11] = aw1 * bx3 + aw2 * by3 + aw3 * bz3 + aw4 * bw3;
result[12] = ax1 * bx4 + ax2 * by4 + ax3 * bz4 + ax4 * bw4;
result[13] = ay1 * bx4 + ay2 * by4 + ay3 * bz4 + ay4 * bw4;
result[14] = az1 * bx4 + az2 * by4 + az3 * bz4 + az4 * bw4;
result[15] = aw1 * bx4 + aw2 * by4 + aw3 * bz4 + aw4 * bw4;
}
}

View File

@@ -21,14 +21,17 @@
package com.watabou.glwrap;
import android.opengl.GLES20;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.BufferUtils;
import java.nio.IntBuffer;
public class Program {
private int handle;
public Program() {
handle = GLES20.glCreateProgram();
handle = Gdx.gl.glCreateProgram();
}
public int handle() {
@@ -36,33 +39,33 @@ public class Program {
}
public void attach( Shader shader ) {
GLES20.glAttachShader( handle, shader.handle() );
Gdx.gl.glAttachShader( handle, shader.handle() );
}
public void link() {
GLES20.glLinkProgram( handle );
Gdx.gl.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 ) );
IntBuffer status = BufferUtils.newIntBuffer(1);
Gdx.gl.glGetProgramiv( handle, Gdx.gl.GL_LINK_STATUS, status );
if (status.get() == Gdx.gl.GL_FALSE) {
throw new Error( Gdx.gl.glGetProgramInfoLog( handle ) );
}
}
public Attribute attribute( String name ) {
return new Attribute( GLES20.glGetAttribLocation( handle, name ) );
return new Attribute( Gdx.gl.glGetAttribLocation( handle, name ) );
}
public Uniform uniform( String name ) {
return new Uniform( GLES20.glGetUniformLocation( handle, name ) );
return new Uniform( Gdx.gl.glGetUniformLocation( handle, name ) );
}
public void use() {
GLES20.glUseProgram( handle );
Gdx.gl.glUseProgram( handle );
}
public void delete() {
GLES20.glDeleteProgram( handle );
Gdx.gl.glDeleteProgram( handle );
}
public static Program create( Shader ...shaders ) {

View File

@@ -21,7 +21,7 @@
package com.watabou.glwrap;
import android.opengl.GLES20;
import com.badlogic.gdx.Gdx;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -59,21 +59,19 @@ public class Quad {
public static void setupIndices(){
ShortBuffer indices = getIndices( Short.MAX_VALUE );
if (bufferIndex == -1){
int[] buf = new int[1];
GLES20.glGenBuffers(1, buf, 0);
bufferIndex = buf[0];
bufferIndex = Gdx.gl.glGenBuffer();
}
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, bufferIndex);
GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER, (indices.capacity()*2), indices, GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
Gdx.gl.glBindBuffer(Gdx.gl.GL_ELEMENT_ARRAY_BUFFER, bufferIndex);
Gdx.gl.glBufferData(Gdx.gl.GL_ELEMENT_ARRAY_BUFFER, (indices.capacity()*2), indices, Gdx.gl.GL_STATIC_DRAW);
Gdx.gl.glBindBuffer(Gdx.gl.GL_ELEMENT_ARRAY_BUFFER, 0);
}
public static void bindIndices(){
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, bufferIndex);
Gdx.gl.glBindBuffer(Gdx.gl.GL_ELEMENT_ARRAY_BUFFER, bufferIndex);
}
public static void releaseIndices(){
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
Gdx.gl.glBindBuffer(Gdx.gl.GL_ELEMENT_ARRAY_BUFFER, 0);
}
public static ShortBuffer getIndices( int size ) {

View File

@@ -21,20 +21,18 @@
package com.watabou.glwrap;
import android.opengl.GLES20;
import com.badlogic.gdx.Gdx;
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;
public static final int RGBA8 = Gdx.gl.GL_RGBA; // ?
public static final int DEPTH16 = Gdx.gl.GL_DEPTH_COMPONENT16;
public static final int STENCIL8 = Gdx.gl.GL_STENCIL_INDEX8;
private int id;
public Renderbuffer() {
int[] buffers = new int[1];
GLES20.glGenRenderbuffers( 1, buffers, 0 );
id = buffers[0];
id = Gdx.gl.glGenRenderbuffer();
}
public int id() {
@@ -42,15 +40,14 @@ public class Renderbuffer {
}
public void bind() {
GLES20.glBindRenderbuffer( GLES20.GL_RENDERBUFFER, id );
Gdx.gl.glBindRenderbuffer( Gdx.gl.GL_RENDERBUFFER, id );
}
public void delete() {
int[] buffers = {id};
GLES20.glDeleteRenderbuffers( 1, buffers, 0 );
Gdx.gl.glDeleteRenderbuffer( id );
}
public void storage( int format, int width, int height ) {
GLES20.glRenderbufferStorage( GLES20.GL_RENDERBUFFER, format , width, height );
Gdx.gl.glRenderbufferStorage( Gdx.gl.GL_RENDERBUFFER, format , width, height );
}
}

View File

@@ -1,183 +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 <http://www.gnu.org/licenses/>
*/
package com.watabou.glwrap;
import android.opengl.GLSurfaceView;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;
public class ScreenConfigChooser implements GLSurfaceView.EGLConfigChooser {
//array of corresponding EGL attributes for each array index
private int[] attribEGLconsts = new int[]{
EGL10.EGL_RED_SIZE,
EGL10.EGL_GREEN_SIZE,
EGL10.EGL_BLUE_SIZE,
EGL10.EGL_ALPHA_SIZE,
EGL10.EGL_DEPTH_SIZE,
EGL10.EGL_STENCIL_SIZE
};
private int[] desiredAttribVals = new int[attribEGLconsts.length]; //desired attribute values
private int[] attribPrefs = new int[attribEGLconsts.length]; //attribute preferences types
private int[] prefWeights = new int[attribEGLconsts.length]; //weights for preferences
//attributes with this preference are ignored
public static final int DONT_CARE = 0;
//attributes with this preference must be present in the config at exactly the given value
public static final int EXACTLY = 1;
//attributes with this preference must be present in the config with at least the given value
// In the case of multiple valid configs, chooser will prefer lower values for these attributes
public static final int PREF_LOW = 2;
//attributes with this preference must be present in the config with at least the given value
// In the case of multiple valid configs, chooser will prefer higher values for these attributes
public static final int PREF_HIGH = 3;
private EGL10 egl;
private EGLDisplay display;
public ScreenConfigChooser(){
this( false );
}
public ScreenConfigChooser( boolean depth ){
this( false, depth );
}
//helper constructor for a basic config with or without depth
//and whether or not to prefer RGB565 for performance reasons
//On many devices RGB565 gives slightly better performance for a minimal quality tradeoff.
public ScreenConfigChooser( boolean prefRGB565, boolean depth ){
this(
new int[]{ 5 , 6 , 5 , 0 , depth ? 16 : 0, 0 } ,
prefRGB565 ?
new int[]{ PREF_LOW , PREF_LOW , PREF_LOW , EXACTLY , PREF_LOW , PREF_LOW } :
new int[]{ PREF_HIGH, PREF_HIGH, PREF_HIGH, EXACTLY , PREF_LOW , PREF_LOW },
new int[]{ 2 , 2 , 2 , 1 , 1 , 1 }
);
}
public ScreenConfigChooser( int[] vals, int[] prefs, int[] weights){
if (vals.length != desiredAttribVals.length
|| prefs.length != attribPrefs.length
|| weights.length != prefWeights.length)
throw new IllegalArgumentException("incorrect array lengths!");
desiredAttribVals = vals;
attribPrefs = prefs;
prefWeights = weights;
}
private int[] eglPrefs = new int[]{
EGL10.EGL_RENDERABLE_TYPE, 4, //same as EGL_OPENGL_ES2_BIT. config must support GLES 2.0
EGL10.EGL_SURFACE_TYPE, EGL10.EGL_WINDOW_BIT,
EGL10.EGL_NONE
};
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
this.egl = egl;
this.display = display;
int[] num = new int[1];
if (!egl.eglChooseConfig(display, eglPrefs, null, 0, num)) {
throw new IllegalArgumentException("eglChooseConfig failed");
}
EGLConfig[] configs = new EGLConfig[num[0]];
if (!egl.eglChooseConfig(display, eglPrefs, configs, num[0], num)) {
throw new IllegalArgumentException("eglChooseConfig failed");
}
EGLConfig config = chooseConfig(configs);
if (config == null) {
throw new IllegalArgumentException("No config chosen");
}
return config;
}
private EGLConfig chooseConfig( EGLConfig[] configs ){
EGLConfig bestConfig = null;
int bestConfigValue = Integer.MIN_VALUE;
for (EGLConfig curConfig : configs){
int curConfigValue = 0;
for (int i = 0; i < attribEGLconsts.length; i++){
int val = findConfigAttrib(curConfig, attribEGLconsts[i]);
if (attribPrefs[i] == EXACTLY) {
if (desiredAttribVals[i] != val) {
curConfigValue = Integer.MIN_VALUE;
break;
}
} else if (attribPrefs[i] == PREF_HIGH) {
if (desiredAttribVals[i] > val) {
curConfigValue = Integer.MIN_VALUE;
break;
} else {
curConfigValue += prefWeights[i]*(val - desiredAttribVals[i]);
}
} else if (attribPrefs[i] == PREF_LOW) {
if (desiredAttribVals[i] > val) {
curConfigValue = Integer.MIN_VALUE;
break;
} else {
curConfigValue -= prefWeights[i]*(val - desiredAttribVals[i]);
}
}
}
if (curConfigValue > bestConfigValue){
bestConfigValue = curConfigValue;
bestConfig = curConfig;
}
}
return bestConfig;
}
private int[] value = new int[1];
private int findConfigAttrib(EGLConfig config, int attribute) {
if (egl.eglGetConfigAttrib(display, config, attribute, value)) {
return value[0];
} else {
throw new IllegalArgumentException("eglGetConfigAttrib failed");
}
}
}

View File

@@ -21,17 +21,20 @@
package com.watabou.glwrap;
import android.opengl.GLES20;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.BufferUtils;
import java.nio.IntBuffer;
public class Shader {
public static final int VERTEX = GLES20.GL_VERTEX_SHADER;
public static final int FRAGMENT = GLES20.GL_FRAGMENT_SHADER;
public static final int VERTEX = Gdx.gl.GL_VERTEX_SHADER;
public static final int FRAGMENT = Gdx.gl.GL_FRAGMENT_SHADER;
private int handle;
public Shader( int type ) {
handle = GLES20.glCreateShader( type );
handle = Gdx.gl.glCreateShader( type );
}
public int handle() {
@@ -39,21 +42,21 @@ public class Shader {
}
public void source( String src ) {
GLES20.glShaderSource( handle, src );
Gdx.gl.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 ) );
Gdx.gl.glCompileShader( handle );
IntBuffer status = BufferUtils.newIntBuffer(1);
Gdx.gl.glGetShaderiv( handle, Gdx.gl.GL_COMPILE_STATUS, status);
if (status.get() == Gdx.gl.GL_FALSE) {
throw new Error( Gdx.gl.glGetShaderInfoLog( handle ) );
}
}
public void delete() {
GLES20.glDeleteShader( handle );
Gdx.gl.glDeleteShader( handle );
}
public static Shader createCompiled( int type, String src ) {

View File

@@ -21,9 +21,8 @@
package com.watabou.glwrap;
import android.graphics.Bitmap;
import android.opengl.GLES20;
import android.opengl.GLUtils;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -31,12 +30,12 @@ import java.nio.IntBuffer;
public class Texture {
public static final int NEAREST = GLES20.GL_NEAREST;
public static final int LINEAR = GLES20.GL_LINEAR;
public static final int NEAREST = Gdx.gl.GL_NEAREST;
public static final int LINEAR = Gdx.gl.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 static final int REPEAT = Gdx.gl.GL_REPEAT;
public static final int MIRROR = Gdx.gl.GL_MIRRORED_REPEAT;
public static final int CLAMP = Gdx.gl.GL_CLAMP_TO_EDGE;
public int id = -1;
private static int bound_id = 0; //id of the currently bound texture
@@ -44,13 +43,11 @@ public class Texture {
public boolean premultiplied = false;
protected void generate(){
int[] ids = new int[1];
GLES20.glGenTextures( 1, ids, 0 );
id = ids[0];
id = Gdx.gl.glGenTexture();
}
public static void activate( int index ) {
GLES20.glActiveTexture( GLES20.GL_TEXTURE0 + index );
Gdx.gl.glActiveTexture( Gdx.gl.GL_TEXTURE0 + index );
}
public void bind() {
@@ -58,32 +55,42 @@ public class Texture {
generate();
}
if (id != bound_id) {
GLES20.glBindTexture( GLES20.GL_TEXTURE_2D, id );
Gdx.gl.glBindTexture( Gdx.gl.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 );
Gdx.gl.glTexParameterf( Gdx.gl.GL_TEXTURE_2D, Gdx.gl.GL_TEXTURE_MIN_FILTER, minMode );
Gdx.gl.glTexParameterf( Gdx.gl.GL_TEXTURE_2D, Gdx.gl.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 );
Gdx.gl.glTexParameterf( Gdx.gl.GL_TEXTURE_2D, Gdx.gl.GL_TEXTURE_WRAP_S, s );
Gdx.gl.glTexParameterf( Gdx.gl.GL_TEXTURE_2D, Gdx.gl.GL_TEXTURE_WRAP_T, t );
}
public void delete() {
if (bound_id == id) bound_id = 0;
int[] ids = {id};
GLES20.glDeleteTextures( 1, ids, 0 );
Gdx.gl.glDeleteTexture( id );
}
public void bitmap( Bitmap bitmap ) {
public void bitmap( Pixmap pixmap ) {
bind();
GLUtils.texImage2D( GLES20.GL_TEXTURE_2D, 0, bitmap, 0 );
Gdx.gl.glTexImage2D(
Gdx.gl.GL_TEXTURE_2D,
0,
pixmap.getGLInternalFormat(),
pixmap.getWidth(),
pixmap.getHeight(),
0,
pixmap.getGLFormat(),
pixmap.getGLType(),
pixmap.getPixels()
);
premultiplied = true;
}
@@ -99,15 +106,15 @@ public class Texture {
imageBuffer.put( pixels );
imageBuffer.position( 0 );
GLES20.glTexImage2D(
GLES20.GL_TEXTURE_2D,
Gdx.gl.glTexImage2D(
Gdx.gl.GL_TEXTURE_2D,
0,
GLES20.GL_RGBA,
Gdx.gl.GL_RGBA,
w,
h,
0,
GLES20.GL_RGBA,
GLES20.GL_UNSIGNED_BYTE,
Gdx.gl.GL_RGBA,
Gdx.gl.GL_UNSIGNED_BYTE,
imageBuffer );
}
@@ -121,23 +128,24 @@ public class Texture {
imageBuffer.put( pixels );
imageBuffer.position( 0 );
GLES20.glPixelStorei( GLES20.GL_UNPACK_ALIGNMENT, 1 );
Gdx.gl.glPixelStorei( Gdx.gl.GL_UNPACK_ALIGNMENT, 1 );
GLES20.glTexImage2D(
GLES20.GL_TEXTURE_2D,
Gdx.gl.glTexImage2D(
Gdx.gl.GL_TEXTURE_2D,
0,
GLES20.GL_ALPHA,
Gdx.gl.GL_ALPHA,
w,
h,
0,
GLES20.GL_ALPHA,
GLES20.GL_UNSIGNED_BYTE,
Gdx.gl.GL_ALPHA,
Gdx.gl.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 ) {
//TODO this seems to be unused, and is dependant on android code, remove?
/*public void handMade( Bitmap bitmap, boolean recode ) {
int w = bitmap.getWidth();
int h = bitmap.getHeight();
@@ -159,11 +167,11 @@ public class Texture {
pixels( w, h, pixels );
premultiplied = false;
}
}*/
public static Texture create( Bitmap bmp ) {
public static Texture create( Pixmap pix ) {
Texture tex = new Texture();
tex.bitmap( bmp );
tex.bitmap( pix );
return tex;
}

View File

@@ -21,7 +21,7 @@
package com.watabou.glwrap;
import android.opengl.GLES20;
import com.badlogic.gdx.Gdx;
public class Uniform {
@@ -36,30 +36,30 @@ public class Uniform {
}
public void enable() {
GLES20.glEnableVertexAttribArray(location);
Gdx.gl.glEnableVertexAttribArray(location);
}
public void disable() {
GLES20.glDisableVertexAttribArray(location);
Gdx.gl.glDisableVertexAttribArray(location);
}
public void value1f(float value) {
GLES20.glUniform1f(location, value);
Gdx.gl.glUniform1f(location, value);
}
public void value2f(float v1, float v2) {
GLES20.glUniform2f(location, v1, v2);
Gdx.gl.glUniform2f(location, v1, v2);
}
public void value4f(float v1, float v2, float v3, float v4) {
GLES20.glUniform4f(location, v1, v2, v3, v4);
Gdx.gl.glUniform4f(location, v1, v2, v3, v4);
}
public void valueM3(float[] value) {
GLES20.glUniformMatrix3fv(location, 1, false, value, 0);
Gdx.gl.glUniformMatrix3fv(location, 1, false, value, 0);
}
public void valueM4(float[] value) {
GLES20.glUniformMatrix4fv(location, 1, false, value, 0);
Gdx.gl.glUniformMatrix4fv(location, 1, false, value, 0);
}
}

View File

@@ -21,7 +21,7 @@
package com.watabou.glwrap;
import android.opengl.GLES20;
import com.badlogic.gdx.Gdx;
import java.nio.FloatBuffer;
import java.util.ArrayList;
@@ -36,9 +36,7 @@ public class Vertexbuffer {
public Vertexbuffer( FloatBuffer vertices ) {
synchronized (buffers) {
int[] ptr = new int[1];
GLES20.glGenBuffers(1, ptr, 0);
id = ptr[0];
id = Gdx.gl.glGenBuffer();
this.vertices = vertices;
buffers.add(this);
@@ -80,9 +78,9 @@ public class Vertexbuffer {
bind();
if (updateStart == 0 && updateEnd == vertices.limit()){
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, vertices.limit()*4, vertices, GLES20.GL_DYNAMIC_DRAW);
Gdx.gl.glBufferData(Gdx.gl.GL_ARRAY_BUFFER, vertices.limit()*4, vertices, Gdx.gl.GL_DYNAMIC_DRAW);
} else {
GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, updateStart*4, (updateEnd - updateStart)*4, vertices);
Gdx.gl.glBufferSubData(Gdx.gl.GL_ARRAY_BUFFER, updateStart*4, (updateEnd - updateStart)*4, vertices);
}
release();
@@ -90,16 +88,16 @@ public class Vertexbuffer {
}
public void bind(){
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, id);
Gdx.gl.glBindBuffer(Gdx.gl.GL_ARRAY_BUFFER, id);
}
public void release(){
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
Gdx.gl.glBindBuffer(Gdx.gl.GL_ARRAY_BUFFER, 0);
}
public void delete(){
synchronized (buffers) {
GLES20.glDeleteBuffers(1, new int[]{id}, 0);
Gdx.gl.glDeleteBuffer( id );
buffers.remove(this);
}
}