aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-10-16 16:35:59 +0200
committerSven Gothel <[email protected]>2012-10-16 16:35:59 +0200
commitbf55e843dba2f8808817e756ccce0ea49c4d45b5 (patch)
treeaaea7a8a1256fbc78b9f3040d7f33a572a8c072b /src
parent0e0ab268b810371828f23d9e5f6be46a3c8a081f (diff)
Fix QGL for ES1/ES2: Use ushort indices, since uint is n/a on ES1/ES2 profile
glDrawElements(int mode, IntBuffer indices) -> glDrawElements(int mode, ShortBuffer indices)
Diffstat (limited to 'src')
-rw-r--r--src/jake2/qcommon/qfiles.java4
-rw-r--r--src/jake2/render/fast/Mesh.java3
-rw-r--r--src/jake2/render/fast/Model.java8
-rw-r--r--src/jake2/render/opengl/CountGL.java2
-rw-r--r--src/jake2/render/opengl/DummyGL.java6
-rw-r--r--src/jake2/render/opengl/JoglGL2.java5
-rw-r--r--src/jake2/render/opengl/JoglGL2ES1.java7
-rw-r--r--src/jake2/render/opengl/QGL.java2
-rw-r--r--src/jake2/util/Lib.java21
9 files changed, 34 insertions, 24 deletions
diff --git a/src/jake2/qcommon/qfiles.java b/src/jake2/qcommon/qfiles.java
index 67271df..11d5e6d 100644
--- a/src/jake2/qcommon/qfiles.java
+++ b/src/jake2/qcommon/qfiles.java
@@ -280,9 +280,9 @@ public class qfiles {
* new members for vertex array handling
*/
public FloatBuffer textureCoordBuf = null;
- public IntBuffer vertexIndexBuf = null;
+ public ShortBuffer vertexIndexBuf = null;
public int[] counts = null;
- public IntBuffer[] indexElements = null;
+ public ShortBuffer[] indexElements = null;
}
/*
diff --git a/src/jake2/render/fast/Mesh.java b/src/jake2/render/fast/Mesh.java
index a2e9268..547be66 100644
--- a/src/jake2/render/fast/Mesh.java
+++ b/src/jake2/render/fast/Mesh.java
@@ -36,6 +36,7 @@ import jake2.util.Math3D;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
+import java.nio.ShortBuffer;
/**
* Mesh
@@ -228,7 +229,7 @@ public abstract class Mesh extends Light {
int pos = 0;
int[] counts = paliashdr.counts;
- IntBuffer srcIndexBuf = null;
+ ShortBuffer srcIndexBuf = null;
FloatBuffer dstTextureCoords = textureArrayBuf;
FloatBuffer srcTextureCoords = paliashdr.textureCoordBuf;
diff --git a/src/jake2/render/fast/Model.java b/src/jake2/render/fast/Model.java
index 93180d5..15e8107 100644
--- a/src/jake2/render/fast/Model.java
+++ b/src/jake2/render/fast/Model.java
@@ -1287,12 +1287,12 @@ public abstract class Model extends Surf {
*/
static final int MODEL_BUFFER_SIZE = 50000;
static FloatBuffer globalModelTextureCoordBuf = Lib.newFloatBuffer(MODEL_BUFFER_SIZE * 2);
- static IntBuffer globalModelVertexIndexBuf = Lib.newIntBuffer(MODEL_BUFFER_SIZE);
+ static ShortBuffer globalModelVertexIndexBuf = Lib.newShortBuffer(MODEL_BUFFER_SIZE);
void precompileGLCmds(qfiles.dmdl_t model) {
model.textureCoordBuf = globalModelTextureCoordBuf.slice();
model.vertexIndexBuf = globalModelVertexIndexBuf.slice();
- Vector tmp = new Vector();
+ final Vector<Integer> tmp = new Vector<Integer>();
int count = 0;
int[] order = model.glCmds;
@@ -1320,7 +1320,7 @@ public abstract class Model extends Surf {
// texture coordinates come from the draw list
globalModelTextureCoordBuf.put(Float.intBitsToFloat(order[orderIndex + 0]));
globalModelTextureCoordBuf.put(Float.intBitsToFloat(order[orderIndex + 1]));
- globalModelVertexIndexBuf.put(order[orderIndex + 2]);
+ globalModelVertexIndexBuf.put( (short) ( 0x0000FFFF & order[orderIndex + 2] ) );
orderIndex += 3;
} while (--count != 0);
@@ -1329,7 +1329,7 @@ public abstract class Model extends Surf {
int size = tmp.size();
model.counts = new int[size];
- model.indexElements = new IntBuffer[size];
+ model.indexElements = new ShortBuffer[size];
count = 0;
int pos = 0;
diff --git a/src/jake2/render/opengl/CountGL.java b/src/jake2/render/opengl/CountGL.java
index 2752916..a671747 100644
--- a/src/jake2/render/opengl/CountGL.java
+++ b/src/jake2/render/opengl/CountGL.java
@@ -102,7 +102,7 @@ public class CountGL implements QGL {
++count;
}
- public void glDrawElements(int mode, IntBuffer indices) {
+ public void glDrawElements(int mode, ShortBuffer indices) {
++count;
}
diff --git a/src/jake2/render/opengl/DummyGL.java b/src/jake2/render/opengl/DummyGL.java
index 45cc9df..b7d4c58 100644
--- a/src/jake2/render/opengl/DummyGL.java
+++ b/src/jake2/render/opengl/DummyGL.java
@@ -1,8 +1,6 @@
package jake2.render.opengl;
-import java.nio.ByteBuffer;
-import java.nio.FloatBuffer;
-import java.nio.IntBuffer;
+import java.nio.*;
public class DummyGL implements QGL {
@@ -101,7 +99,7 @@ public class DummyGL implements QGL {
// do nothing
}
- public void glDrawElements(int mode, IntBuffer indices) {
+ public void glDrawElements(int mode, ShortBuffer indices) {
// do nothing
}
diff --git a/src/jake2/render/opengl/JoglGL2.java b/src/jake2/render/opengl/JoglGL2.java
index a1d1b17..d078585 100644
--- a/src/jake2/render/opengl/JoglGL2.java
+++ b/src/jake2/render/opengl/JoglGL2.java
@@ -3,6 +3,7 @@ package jake2.render.opengl;
import java.nio.*;
+import javax.media.opengl.GL;
import javax.media.opengl.GL2;
public class JoglGL2 implements QGL {
@@ -102,8 +103,8 @@ public class JoglGL2 implements QGL {
gl.glDrawBuffer(mode);
}
- public void glDrawElements(int mode, IntBuffer indices) {
- gl.glDrawElements(mode, indices.limit(), GL_UNSIGNED_INT, indices);
+ public void glDrawElements(int mode, ShortBuffer indices) {
+ gl.glDrawElements(mode, indices.remaining(), GL.GL_UNSIGNED_SHORT, indices);
}
public void glEnable(int cap) {
diff --git a/src/jake2/render/opengl/JoglGL2ES1.java b/src/jake2/render/opengl/JoglGL2ES1.java
index 605c152..94c0c45 100644
--- a/src/jake2/render/opengl/JoglGL2ES1.java
+++ b/src/jake2/render/opengl/JoglGL2ES1.java
@@ -172,7 +172,7 @@ public class JoglGL2ES1 implements QGL {
}
}
- public void glDrawElements(int mode, IntBuffer indices) {
+ public void glDrawElements(int mode, ShortBuffer indices) {
switch(mode) {
case GL_QUAD_STRIP:
mode=GL.GL_TRIANGLE_STRIP;
@@ -184,11 +184,12 @@ public class JoglGL2ES1 implements QGL {
final int idxLen = indices.remaining();
if ( GL_QUADS == mode && !gl.isGL2() ) {
final int idx0 = indices.position();
+ final ShortBuffer b = (ShortBuffer) indices;
for (int j = 0; j < idxLen; j++) {
- gl.glDrawArrays(GL.GL_TRIANGLE_FAN, (int)(0xffffffff & indices.get(idx0+j)), 4);
+ gl.glDrawArrays(GL.GL_TRIANGLE_FAN, (int)(0x0000ffff & b.get(idx0+j)), 4);
}
} else {
- gl.glDrawElements(mode, idxLen, GL_UNSIGNED_INT, indices);
+ gl.glDrawElements(mode, idxLen, GL.GL_UNSIGNED_SHORT, indices);
}
}
diff --git a/src/jake2/render/opengl/QGL.java b/src/jake2/render/opengl/QGL.java
index 81efe59..ca0c4dd 100644
--- a/src/jake2/render/opengl/QGL.java
+++ b/src/jake2/render/opengl/QGL.java
@@ -60,7 +60,7 @@ public interface QGL extends QGLConst {
void glDrawBuffer(int mode);
- void glDrawElements(int mode, IntBuffer indices);
+ void glDrawElements(int mode, ShortBuffer indices);
void glEnable(int cap);
diff --git a/src/jake2/util/Lib.java b/src/jake2/util/Lib.java
index 37ab5c8..173d998 100644
--- a/src/jake2/util/Lib.java
+++ b/src/jake2/util/Lib.java
@@ -353,6 +353,7 @@ public class Lib {
public static final int SIZEOF_FLOAT = 4;
public static final int SIZEOF_INT = 4;
+ public static final int SIZEOF_SHORT = 2;
public static FloatBuffer newFloatBuffer(int numElements) {
ByteBuffer bb = newByteBuffer(numElements * SIZEOF_FLOAT);
@@ -362,13 +363,21 @@ public class Lib {
ByteBuffer bb = newByteBuffer(numElements * SIZEOF_FLOAT, order);
return bb.asFloatBuffer();
}
- public static IntBuffer newIntBuffer(int numElements) {
- ByteBuffer bb = newByteBuffer(numElements * SIZEOF_INT);
- return bb.asIntBuffer();
+ public static IntBuffer newIntBuffer(int numElements) {
+ ByteBuffer bb = newByteBuffer(numElements * SIZEOF_INT);
+ return bb.asIntBuffer();
+ }
+ public static IntBuffer newIntBuffer(int numElements, ByteOrder order) {
+ ByteBuffer bb = newByteBuffer(numElements * SIZEOF_INT, order);
+ return bb.asIntBuffer();
+ }
+ public static ShortBuffer newShortBuffer(int numElements) {
+ ByteBuffer bb = newByteBuffer(numElements * SIZEOF_SHORT);
+ return bb.asShortBuffer();
}
- public static IntBuffer newIntBuffer(int numElements, ByteOrder order) {
- ByteBuffer bb = newByteBuffer(numElements * SIZEOF_INT, order);
- return bb.asIntBuffer();
+ public static ShortBuffer newShortBuffer(int numElements, ByteOrder order) {
+ ByteBuffer bb = newByteBuffer(numElements * SIZEOF_SHORT, order);
+ return bb.asShortBuffer();
}
public static ByteBuffer newByteBuffer(int numElements) {
ByteBuffer bb = ByteBuffer.allocateDirect(numElements);