java opengl: glDrawElements() 具有 >32767 个顶点

发布于 2024-10-06 02:11:26 字数 711 浏览 9 评论 0原文

我有一个具有 >32767 个顶点的复杂模型。现在,索引只能以 GL_UNSIGNED_BYTE 或 GL_UNSIGNED_SHORT 类型传递给 opengl。 java没有无符号的概念,因此无符号短选项映射到简单的(有符号)短,即16位,或+32767。当我指定顶点时,我需要向 opengl 传递一个短[],其中数组中的值指向顶点数组中的一个顶点。但是,如果有 >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);
    ...

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,

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

脱离于你 2024-10-13 02:11:26

我没有使用过 Java 中的 OpenGL,所以我在这里进行推测,但很有可能您可以只使用负数,其二进制表示与您真正想要的无符号正数相同。您给 GL 一些字节对并告诉它将它们解释为无符号,并且只要它们以这种方式解释时具有正确的值,它就应该起作用。当 Java 将这些位存储在内存中时,它是否认为它们意味着不同的东西,这并不重要。

如果您正在迭代,只需忽略环绕并继续递增。当你达到-1时,你就完成了。

如果您将索引数字计算为整数(不存在此范围问题),然后转换为短整型,请从任何大于 32767 的数字中减去 65536。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文