Skip to content

Commit 0fce351

Browse files
committed
Fixed glDrawElements for GL_UNSIGNED_INT and GL_UNSIGNED_SHORT
1 parent f9c224c commit 0fce351

File tree

7 files changed

+1239
-1223
lines changed

7 files changed

+1239
-1223
lines changed

app/src/main/java/org/andresoviedo/app/model3D/model/Object3DData.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.nio.ByteOrder;
2020
import java.nio.FloatBuffer;
2121
import java.nio.IntBuffer;
22+
import java.nio.ShortBuffer;
2223
import java.util.ArrayList;
2324
import java.util.List;
2425

@@ -62,6 +63,7 @@ public class Object3DData {
6263
private FloatBuffer vertexBuffer = null;
6364
private FloatBuffer vertexNormalsBuffer = null;
6465
private IntBuffer drawOrderBuffer = null;
66+
private ShortBuffer shortDrawOrderBuffer = null; // in case system doesn't support ints
6567
private ArrayList<Tuple3> texCoords;
6668
private Faces faces;
6769
private FaceMaterials faceMats;
@@ -85,6 +87,7 @@ public class Object3DData {
8587
protected float[] rotation = new float[] { 0f, 0f, 0f };
8688
protected float[] scale = new float[] { 1, 1, 1 };
8789
protected float[] modelMatrix = new float[16];
90+
8891
{
8992
Matrix.setIdentityM(modelMatrix,0);
9093
}
@@ -334,6 +337,20 @@ public IntBuffer getDrawOrder() {
334337
return drawOrderBuffer;
335338
}
336339

340+
/**
341+
* In case OpenGL doesn't support using GL_UNSIGNED_INT for glDrawElements(), then use this buffer
342+
* @return the draw buffer as short
343+
*/
344+
public ShortBuffer getDrawOrderAsShort() {
345+
if (shortDrawOrderBuffer == null) {
346+
shortDrawOrderBuffer = createNativeByteBuffer(drawOrderBuffer.capacity() * 2).asShortBuffer();
347+
for (int i=0; i<drawOrderBuffer.capacity(); i++){
348+
shortDrawOrderBuffer.put((short)drawOrderBuffer.get(i));
349+
}
350+
}
351+
return shortDrawOrderBuffer;
352+
}
353+
337354
public Object3DData setDrawOrder(IntBuffer drawBuffer) {
338355
this.drawOrderBuffer = drawBuffer;
339356
return this;

0 commit comments

Comments
 (0)