Android OpenGL 使用浮点数组而不是 FloatBuffer 作为属性

发布于 2024-12-27 12:45:22 字数 116 浏览 2 评论 0原文

如何使用数组提供属性值?现在我正在使用 glVertexAttribPointer(maPosition, 3, GL_FLOAT, mVertBuffer) 我想使用包含 3 维点的 4 个坐标的数组 mVerts。

How can I feed an attribute value with an array? right now I am using glVertexAttribPointer(maPosition, 3, GL_FLOAT, mVertBuffer)
I want to use the array mVerts which contains 4 coordinates of 3 dimensional points.

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

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

发布评论

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

评论(1

潇烟暮雨 2025-01-03 12:45:22

Opengl.org 有以下说法:

如果在指定通用顶点属性数组时将非零命名缓冲区对象绑定到 GL_ARRAY_BUFFER 目标(请参阅 glBindBuffer),则指针将被视为缓冲区对象数据存储中的字节偏移量。此外,缓冲区对象绑定 (GL_ARRAY_BUFFER_BINDING) 被保存为索引索引的通用顶点属性数组客户端状态 (GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)。

这意味着你基本上必须这样做:

GLint currbuff =0;
//save the current bound buffer
glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&currbuff);
//unbind the currently bound buffer 
glBindBuffer(GL_ARRAY_BUFFER,0); //0 is reserved to unbind the currently bound buffer
//mVerts needs to be of type GLfloat *
glVertexAttribPointer(maPosition, 3, GL_FLOAT, mVerts);
//rebind the previously bound buffer
glBindBuffer(GL_ARRAY_BUFFER,currbuff);

如果你不使用 GL_ARRAY_BUFFER ,你当然不必保存/加载

Opengl.org has the following to say:

If a non-zero named buffer object is bound to the GL_ARRAY_BUFFER target (see glBindBuffer) while a generic vertex attribute array is specified, pointer is treated as a byte offset into the buffer object's data store. Also, the buffer object binding (GL_ARRAY_BUFFER_BINDING) is saved as generic vertex attribute array client-side state (GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING) for index index.

This means that you basically have to do this:

GLint currbuff =0;
//save the current bound buffer
glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&currbuff);
//unbind the currently bound buffer 
glBindBuffer(GL_ARRAY_BUFFER,0); //0 is reserved to unbind the currently bound buffer
//mVerts needs to be of type GLfloat *
glVertexAttribPointer(maPosition, 3, GL_FLOAT, mVerts);
//rebind the previously bound buffer
glBindBuffer(GL_ARRAY_BUFFER,currbuff);

you of course don't have to save/load if you don't use GL_ARRAY_BUFFER

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