每个着色器属性的 VBO 没有 VAO,还是不同的方法?
我在应用程序中使用各种“嵌套”上下文(用于着色器和几何共享),因此我无法使用 VAO,因为它们无法跨上下文共享。
我的网格数据作为唯一顶点的“池”存储在一个 VBO 中,在另一个 VBO 中我存储构成面的索引。我目前正在我的 CAD 应用程序中成功使用它进行线框渲染,但我想添加平面着色模式 - 为此我需要面法线。
如果我需要顶点法线,我只需将数据附加到顶点位置数据,但我不能在这里这样做,因为顶点将具有不同的面法线,具体取决于它所属的面正在渲染。理想情况下,我想创建另一个 VBO 对来保存我的面部法线和索引,但是如果没有 VAO,我无法将两个 VBO 绑定到同一目标 - 即使它们用于不同的属性。
我很欣赏正常的路线是使用 VAO,它确实可以让您将多个 VBO 分配给同一目标,但我无法使用它们,因为我的几何上下文是共享的,而 VAO 不是。这个问题有其他解决方案吗?
I'm using various 'nested' contexts in my application (for shader and geometry sharing), so I cannot use VAOs as they cannot be shared across contexts.
My mesh data is stored in one VBO as a 'pool' of unique vertices, and in another VBO I store the indices that make up the faces. I'm currently using this successfully for wireframe rendering in my CAD app, but I would like to add a flat shaded mode - and for that I need face normals.
If I needed vertex normals, I would just append the data to the vertex position data, but I can't do that here because a vertex would have a different face normal depending on which face it belonged to is being rendered. Ideally I would like to create another VBO pair holding my face normals and indices, however I can't bind two VBOs to the same target without a VAO - even though they're used in different attributes.
I appreciate that the normal route is to use a VAO which does let you assign multiple VBOs to the same target, but I can't use them because my geometry context is shared and VAOs are not. Are there any alternative solutions to this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题与 VAO 或缓冲区对象无关。 VAO 不允许您拥有多个索引列表。他们不允许你有“面部法线”。
顶点数组对象只不过是存储顶点属性绑定的容器。它们并不能让你做任何没有它们就做不到的事情;有一种简单的方法可以更改所有属性绑定。
您需要将顶点位置分解为不同的面。因此,您需要复制位置值,以便每个唯一的位置/法线对都是唯一的。 VAO 无法绕过这个限制。
仅供参考:VAO 不共享的原因是它们太简单,无需共享。您可以轻松地在两个不同的上下文中设置相同的 VAO。只需在您想要使用它的上下文中创建一个 VAO,然后按照通常的方式进行设置即可。它只是一个简单的状态对象;它实际上不包含任何东西。
Your problem has nothing to do with VAOs or buffer objects. VAOs do not allow you to have multiple index lists. They do not allow you to have "face normals".
A vertex array objects is nothing more than a container that stores vertex attribute bindings. They do not enable you to do anything you couldn't do without them; there's simply a convenient way to change all attribute bindings.
You need to break your vertex positions up into different faces. So you need to duplicate position values, so that each unique position/normal pair is properly unique. VAOs don't get around this limitation.
FYI: the reason VAOs aren't shared is because they're too simple to bother sharing. You can set the same VAO up in two different contexts easily enough. Just create a VAO in the context you want to use it in, and do what you would normally do to set it up. It's just a simple state object; it doesn't really contain anything.