java - Android、OpenGL ES 2.0 - 为什么为 ByteBuffer.allocateDirect 调用设置每个 float 4 个字节?

标签 java android opengl-es-2.0

从示例中复制并粘贴源代码是一回事,但我正在寻找一些答案来解释为什么示例是这样的。

我无法回答的一个问题是为什么三角形的 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());
  1. 为什么每个坐标是 4 个字节而不是 2 或 8 个字节?
  2. nativeOrder() 调用的目的是什么?

最佳答案

float 由 32 位表示,相当于 4 个字节。

对 native 顺序的调用将缓冲区中的字节重新排列为 native 系统的顺序,大端、小端等。

关于java - Android、OpenGL ES 2.0 - 为什么为 ByteBuffer.allocateDirect 调用设置每个 float 4 个字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12611424/

相关文章:

java - 用Java快速实现、部署一个Webservice

java - label.setText() 发生 NullPointerException

android - 在 Fragment 中实现 onKeyPreIme(int keyCode, KeyEvent event)

android - XML 中的字体 android :fontFamily is not applied to toolbars

java - HQL更新问题

java - 如何修复错误 "cannot be cast to com.sun.speech.freetts.VoiceDirectory"?

java - 我如何为 json 解析集成 loopj

android - Opengl es 2.0 3d

iphone - iOS OpenGL ES 逻辑缓冲区加载

ios - iPad Opengl ES 程序在模拟器上运行良好但在设备上运行不正常