从示例中复制并粘贴源代码是一回事,但我正在寻找一些答案来解释为什么示例是这样的。
我无法回答的一个问题是为什么三角形的 ByteBuffer 每个坐标需要四个字节。
在 example presented by Google ByteBuffer 用每个三角形坐标四个字节来实例化。
// initialize vertex byte buffer for shape coordinates
// (number of coordinate values * 4 bytes per float)
ByteBuffer bb = ByteBuffer.allocateDirect(triangleCoords.length * 4);
// use the device hardware's native byte order
bb.order(ByteOrder.nativeOrder());
- 为什么每个坐标是 4 个字节而不是 2 或 8 个字节?
- nativeOrder() 调用的目的是什么?
最佳答案
float 由 32 位表示,相当于 4 个字节。
对 native 顺序的调用将缓冲区中的字节重新排列为 native 系统的顺序,大端、小端等。
关于java - Android、OpenGL ES 2.0 - 为什么为 ByteBuffer.allocateDirect 调用设置每个 float 4 个字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12611424/