v0.4.2: various performance improvements to core classes
This commit is contained in:
parent
71c7c264ac
commit
926b02ce65
|
@ -47,14 +47,14 @@ public class Attribute {
|
|||
}
|
||||
|
||||
public void vertexPointer( int size, int stride, FloatBuffer ptr ) {
|
||||
GLES20.glVertexAttribPointer( location, size, GLES20.GL_FLOAT, false, stride * Float.SIZE / 8, ptr );
|
||||
GLES20.glVertexAttribPointer( location, size, GLES20.GL_FLOAT, false, stride * 4, ptr );
|
||||
}
|
||||
|
||||
public void vertexBuffer( int size, int stride, int offset) {
|
||||
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);
|
||||
GLES20.glVertexAttribPointer(location, size, GLES20.GL_FLOAT, false, stride * 4, offset * 4);
|
||||
} else {
|
||||
FroyoGLES20Fix.glVertexAttribPointer(location, size, GLES20.GL_FLOAT, false, stride * Float.SIZE / 8, offset * Float.SIZE / 8);
|
||||
FroyoGLES20Fix.glVertexAttribPointer(location, size, GLES20.GL_FLOAT, false, stride * 4, offset * 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,14 +44,16 @@ public class Matrix {
|
|||
} while (n > 0);
|
||||
|
||||
}
|
||||
|
||||
private static float[] identity = new float[]{
|
||||
1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
System.arraycopy(identity, 0, m, 0, identity.length);
|
||||
}
|
||||
|
||||
public static void rotate( float[] m, float a ) {
|
||||
|
|
|
@ -28,8 +28,6 @@ import java.util.Arrays;
|
|||
public class Uniform {
|
||||
|
||||
private int location;
|
||||
|
||||
private float[] prevVal = new float[4];
|
||||
|
||||
public Uniform(int location) {
|
||||
this.location = location;
|
||||
|
@ -56,16 +54,6 @@ public class Uniform {
|
|||
}
|
||||
|
||||
public void value4f(float v1, float v2, float v3, float v4) {
|
||||
if (v1 == prevVal[0] &&
|
||||
v2 == prevVal[1] &&
|
||||
v3 == prevVal[2] &&
|
||||
v4 == prevVal[3])
|
||||
return;
|
||||
|
||||
prevVal[0] = v1;
|
||||
prevVal[1] = v2;
|
||||
prevVal[2] = v3;
|
||||
prevVal[3] = v4;
|
||||
GLES20.glUniform4f(location, v1, v2, v3, v4);
|
||||
}
|
||||
|
||||
|
@ -74,10 +62,6 @@ public class Uniform {
|
|||
}
|
||||
|
||||
public void valueM4(float[] value) {
|
||||
if (Arrays.equals(prevVal, value))
|
||||
return;
|
||||
|
||||
System.arraycopy(value, 0, prevVal, 0, 4);
|
||||
GLES20.glUniformMatrix4fv(location, 1, false, value, 0);
|
||||
}
|
||||
}
|
|
@ -79,18 +79,22 @@ public class Visual extends Gizmo {
|
|||
public void draw() {
|
||||
updateMatrix();
|
||||
}
|
||||
|
||||
|
||||
//FIXME this is recomputing a lot of stuff every frame
|
||||
// would be far better to redo this only when changes happen
|
||||
protected void updateMatrix() {
|
||||
Matrix.setIdentity( matrix );
|
||||
Matrix.translate( matrix, x, y );
|
||||
Matrix.translate( matrix, origin.x, origin.y );
|
||||
if (origin.x != 0 || origin.y != 0)
|
||||
Matrix.translate( matrix, origin.x, origin.y );
|
||||
if (angle != 0) {
|
||||
Matrix.rotate( matrix, angle );
|
||||
}
|
||||
if (scale.x != 1 || scale.y != 1) {
|
||||
Matrix.scale( matrix, scale.x, scale.y );
|
||||
}
|
||||
Matrix.translate( matrix, -origin.x, -origin.y );
|
||||
if (origin.x != 0 || origin.y != 0)
|
||||
Matrix.translate( matrix, -origin.x, -origin.y );
|
||||
}
|
||||
|
||||
public PointF point() {
|
||||
|
@ -128,20 +132,19 @@ public class Visual extends Gizmo {
|
|||
}
|
||||
|
||||
protected void updateMotion() {
|
||||
|
||||
float elapsed = Game.elapsed;
|
||||
|
||||
float d = (GameMath.speed( speed.x, acc.x ) - speed.x) / 2;
|
||||
speed.x += d;
|
||||
x += speed.x * elapsed;
|
||||
speed.x += d;
|
||||
|
||||
d = (GameMath.speed( speed.y, acc.y ) - speed.y) / 2;
|
||||
speed.y += d;
|
||||
y += speed.y * elapsed;
|
||||
speed.y += d;
|
||||
|
||||
angle += angularSpeed * elapsed;
|
||||
|
||||
if (acc.x != 0)
|
||||
speed.x += acc.x * Game.elapsed;
|
||||
if (speed.x != 0)
|
||||
x += speed.x * Game.elapsed;
|
||||
|
||||
if (acc.y != 0)
|
||||
speed.y += acc.y * Game.elapsed;
|
||||
if (speed.y != 0)
|
||||
y += speed.y * Game.elapsed;
|
||||
|
||||
if (angularSpeed != 0)
|
||||
angle += angularSpeed * Game.elapsed;
|
||||
}
|
||||
|
||||
public void alpha( float value ) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user