将顶点缓冲区转换为顶点数组 [英] convert Vertex buffer to Vertex array

查看:35
本文介绍了将顶点缓冲区转换为顶点数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 OpenGL 程序,我必须计算一个边界框.我编写了代码来执行此操作,但我无法从 vertex buffer 获取顶点坐标.有人可以向我解释一种从顶点缓冲区获取数据的简单方法吗?我将 Java 用于 android 和 OpenGL es

I'm working on OpenGL program and I must calculate a bounding box . I made the code to do it but I can't get vertexes coordinations from vertex buffer . Someone can explain me an easy way to get data from vertex buffer? I'm using Java for android and OpenGL es

推荐答案

如果你使用 OpenGL ES 3.0 或更高版本,你可以使用 glMapBufferRange() 直接访问缓冲区数据.有关功能的详细信息,请参阅 手册页,以及GLES30 文档 了解有关 Android 中的 Java 绑定的详细信息.

If you use OpenGL ES 3.0 or later, you can use glMapBufferRange() to access buffer data directly. See the man page for details about the functionality, and the GLES30 documentation for details about the Java bindings in Android.

我认为在 ES 2.0 中没有任何合理的方法可以做到这一点.我可以想出绝对糟糕的方法,但我会觉得把你引向那个方向会很糟糕.好吧,为了完整起见,但请不要这样做:您可以渲染一些最终将顶点数据留在渲染目标中的内容,然后使用 glReadPixels() 将其读回.

I don't think there's any reasonable way to do this in ES 2.0. I could think of absolutely awful ways, but I would feel bad to steer you in that direction. Well, for completeness, but please do not do this: You could render something that ends up leaving the vertex data in a render target, and read it back with glReadPixels().

如果您需要在自己的代码中频繁访问顶点数据,则保留一份副本很可能会更好.当您调用 glBufferData() 时,您已经获得了数据.如果您当前在 glBufferData() 调用后将其丢弃,只需将其保留,并在您需要访问顶点数据时使用它.

If you need frequent access to the vertex data in your own code, it will most likely work better if you keep a copy of it. You already had the data when you called glBufferData(). If you're currently throwing it away after the glBufferData() call, simply keep it around, and use it whenever you need access to vertex data.

这篇关于将顶点缓冲区转换为顶点数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆