19
19
import java .nio .ByteOrder ;
20
20
import java .nio .FloatBuffer ;
21
21
import java .nio .IntBuffer ;
22
+ import java .nio .ShortBuffer ;
22
23
import java .util .ArrayList ;
23
24
import java .util .List ;
24
25
@@ -62,6 +63,7 @@ public class Object3DData {
62
63
private FloatBuffer vertexBuffer = null ;
63
64
private FloatBuffer vertexNormalsBuffer = null ;
64
65
private IntBuffer drawOrderBuffer = null ;
66
+ private ShortBuffer shortDrawOrderBuffer = null ; // in case system doesn't support ints
65
67
private ArrayList <Tuple3 > texCoords ;
66
68
private Faces faces ;
67
69
private FaceMaterials faceMats ;
@@ -85,6 +87,7 @@ public class Object3DData {
85
87
protected float [] rotation = new float [] { 0f , 0f , 0f };
86
88
protected float [] scale = new float [] { 1 , 1 , 1 };
87
89
protected float [] modelMatrix = new float [16 ];
90
+
88
91
{
89
92
Matrix .setIdentityM (modelMatrix ,0 );
90
93
}
@@ -334,6 +337,20 @@ public IntBuffer getDrawOrder() {
334
337
return drawOrderBuffer ;
335
338
}
336
339
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
+
337
354
public Object3DData setDrawOrder (IntBuffer drawBuffer ) {
338
355
this .drawOrderBuffer = drawBuffer ;
339
356
return this ;
0 commit comments