ByteBuffer.allocateDirect() 和 glGenBuffers() 之间的区别
Difference between ByteBuffer.allocateDirect() and glGenBuffers()
ByteBuffer.allocateDirect()
和 glGenBuffers()
有什么区别?为什么我们使用 android ByteBuffer.allocateDirect()
而不是经典 OpenGL 中的 glGenBuffers()
?
But why in every basic OpenGL Tutorial for rendering triangle is used OpenGL object and in every Android OpenGL ES tutorial for rendering triangle is used java object instead of OpenGL object?
因为他们可以。
ByteBuffer
表示 CPU 内存分配。一个 OpenGL 缓冲区对象表示一个 GPU 可访问的内存分配。
OpenGL ES 2.0 允许用户从 CPU 内存或缓冲区对象中指定顶点数据。自 2009 年以来,桌面核心 OpenGL 移除了 此功能。因此现代桌面 OpenGL 教程使用缓冲区对象存储顶点数据。
请注意,ES 3.0 明确表示 "client-side vertex arrays":
are present to maintain backward compatibility with OpenGL ES 2.0, but their use in not recommended as it is likely for these features to be removed in a future version.
它们还没有被删除。但它们确实会干扰许多功能。例如,他们使 gl_VertexID
未定义。
所以你不应该直接对顶点数组使用 ByteBuffer
。而且你应该避免这样做的学习材料,因为它们可能会教你其他不好的做法。
ByteBuffer.allocateDirect()
和 glGenBuffers()
有什么区别?为什么我们使用 android ByteBuffer.allocateDirect()
而不是经典 OpenGL 中的 glGenBuffers()
?
But why in every basic OpenGL Tutorial for rendering triangle is used OpenGL object and in every Android OpenGL ES tutorial for rendering triangle is used java object instead of OpenGL object?
因为他们可以。
ByteBuffer
表示 CPU 内存分配。一个 OpenGL 缓冲区对象表示一个 GPU 可访问的内存分配。
OpenGL ES 2.0 允许用户从 CPU 内存或缓冲区对象中指定顶点数据。自 2009 年以来,桌面核心 OpenGL 移除了 此功能。因此现代桌面 OpenGL 教程使用缓冲区对象存储顶点数据。
请注意,ES 3.0 明确表示 "client-side vertex arrays":
are present to maintain backward compatibility with OpenGL ES 2.0, but their use in not recommended as it is likely for these features to be removed in a future version.
它们还没有被删除。但它们确实会干扰许多功能。例如,他们使 gl_VertexID
未定义。
所以你不应该直接对顶点数组使用 ByteBuffer
。而且你应该避免这样做的学习材料,因为它们可能会教你其他不好的做法。