Java的OpenGL的:glDrawElements()与> 32767顶点 [英] java opengl: glDrawElements() with >32767 vertices

查看:142
本文介绍了Java的OpenGL的:glDrawElements()与> 32767顶点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这一定是简单的,但我很想念它。

我有了> 32767个顶点复杂的模型。现在,指数只能传递到OpenGL作为类型GL_UNSIGNED_BYTE或GL_UNSIGNED_SHORT。 Java没有无符号的概念,所以无符号短选项映射为简单的(签约)的简称,它是16位,或+32767。当我指定的顶点,我需要通过OpenGL的一个短[],其中在阵列点到顶点数组中顶点的值。但是,如果有> 32767个顶点,值将不适合在短期[]。

有另一种方式来指定的指数? code片断如下,谢谢。

 短[] =短裤...阅读指数...;
    ...
    ShortBuffer indicesBuffer = NULL;
    IBB的ByteBuffer = ByteBuffer.allocateDirect(indices.length * Short.SIZE / 8);
    ibb.order(ByteOrder.nativeOrder());
    indicesBuffer = ibb.asShortBuffer();
    indicesBuffer.put(指数);
    indicesBuffer.position(0);
    ...
    gl.glDrawElements(GL10.GL_TRIANGLES,numOfIndices,GL10.GL_UNSIGNED_SHORT,indicesBuffer);
    ...


解决方案

我没有使用的OpenGL从Java,所以我推测这里,但有,你可以只使用负数,其二进制重新$ P的好机会$ pntation是一样的,你真正想要的无符号正数。你给GL一些字节对,它告诉国米preT他们作为符号,只要他们有正确的价值时,除preTED这种方式,它应该工作。如果Java的认为他们意味着什么不同,当存储在内存中的位没关系。

如果你迭代,只是忽略了概括,不断递增。当你为-1,就大功告成了。

如果你正在计算索引号为int(不具有此范围内的问题),然后转换为短,从任何数量的是大于32767减去65536。

this must be simple, but i'm missing it.

i have a complex model that has >32767 vertices. now, the indices can only be passed to opengl as type GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT. java has no concept of unsigned, so the unsigned short option maps to simply (signed) short, which is 16 bits, or +32767. when i specify the vertices, i need to pass opengl a short[], where the values in the array point to a vertex in the vertice array. however, if there are >32767 vertices, the value won't fit in the short[].

is there another way to specify the indices? code snippet is below, thanks.

    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);
    ...

解决方案

I haven't used OpenGL from Java so I'm speculating here, but there's a good chance that you can just use the negative numbers whose binary reprentation is the same as the unsigned positive numbers you really want. You're giving GL some byte pairs and telling it to interpret them as unsigned, and as long as they have the right value when interpreted that way, it should work. It doesn't matter if Java thought they meant something different when it stored those bits in memory.

If you're iterating, just ignore the wraparound and keep on incrementing. When you get to -1, you're done.

If you're calculating the index numbers as ints (which don't have this range problem) and then casting to short, subtract 65536 from any number that's greater than 32767.

这篇关于Java的OpenGL的:glDrawElements()与> 32767顶点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆