如何使用 OpenGL 3.x VBO 渲染动态世界? [英] How do I use OpenGL 3.x VBOs to render a dynamic world?

查看:34
本文介绍了如何使用 OpenGL 3.x VBO 渲染动态世界?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然对于 OpenGL 3.x 本身的最新引用似乎很少,但 OpenGL 的实际低级操作相对简单.然而,我什至在尝试将如何操纵 VBO 以呈现动态世界的概念化时遇到了严重的麻烦.

Although there seem to be very few up to date references for OpenGL 3.x itself, the actual low level manipulation of OpenGL is relatively straight forward. However I am having serious trouble trying to even conceptualise how one would manipulate VBOs in order to render a dynamic world.

显然旧的立即模式方式不适用,但我该去哪里呢?我是否编写某种场景结构,然后将其转换为一组顶点并将其流式传输到 VBO,我将如何存储翻译数据?如果是这样,那看起来代码明智吗?

Obviously the immediate mode ways of old are non applicable, but from there where do I go? Do I write some kind of scene structure and then convert that to a set of vertices and stream that to the VBO, how would I store translation data? If so how would that look code wise?

基本上真的不确定如何继续.

Basically really unsure how to continue.

推荐答案

如果您的整个世界确实是动态的,您可以使用 GL_STREAM_DRAW_ARB 使用标志并重置每一帧的数据.不要费心去操作它,只要尽可能高效地进行流式传输即可.

If your entire world is truly dynamic, you can use the GL_STREAM_DRAW_ARB usage flag and reset the data on each frame. Don't bother manipulating it, just try to stream as efficient as possible.

但是,我假设您有一个由多个相对移动的刚性对象组成的场景.在这种情况下,为每个对象使用一个 VBO 并指定 GL_STATIC_DRAW_ARB 使用标志.然后,您可以为对象的每个实例设置模型视图转换,并为每个实例使用一个绘制调用来渲染它们.

However, I assume that you have a scene that consists of multiple rigid objects that move relative to each other. In this case, use one VBO for each object and specify the GL_STATIC_DRAW_ARB usage flag. You can then set the modelview transform for each instance of an object and render them using one draw call per instance.

经验法则(在 PC 上)是每 MHz CPU 发出不超过一个绘制调用.这是一个粗略的估计,但有一定的道理.如果您保持在此限制以下,请不要担心将多个独立对象放入单个 VBO 或其他性能技巧.

A rule of thumb (on the PC) is to issue not more than one draw call per MHz of your CPU. This is a crude estimate, but there's some truth to it. Don't worry about putting multiple independent objects into a single VBO or other performance tricks if you stay below this limit.

这篇关于如何使用 OpenGL 3.x VBO 渲染动态世界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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