我有一个具有> 32767 个顶点的复杂模型。现在,索引只能作为 GL_UNSIGNED_BYTE 或 GL_UNSIGNED_SHORT 类型传递给 opengl。java没有无符号的概念,因此无符号短选项映射为简单的(有符号)短,即16位或+32767。当我指定顶点时,我需要向opengl传递一个short [],其中数组中的值指向顶点数组中的一个顶点。但是,如果有 >32767 个顶点,则该值将不适合 short[]。
还有另一种指定索引的方法吗?代码片段如下,
short[] shorts = ... read the indices ...;
...
ShortBuffer indicesBuffer = null;
ByteBuffer ibb = ByteBuffer.allocateDirect(indices.length * Short.SIZE / 8);
ibb.order(ByteOrder.nativeOrder());
indicesBuffer = ibb.asShortBuffer();
indicesBuffer.put(indices);
indicesBuffer.position(0);
...
gl.glDrawElements(GL10.GL_TRIANGLES, numOfIndices, GL10.GL_UNSIGNED_SHORT, indicesBuffer);
...