OpenGl VBO技术在C ++ [英] OpenGl VBO technicalities in C++

查看:287
本文介绍了OpenGl VBO技术在C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对于在OpenGL程序中正确使用VBO有点困惑。

I'm a little confused as to the proper usage of VBOs in an OpenGL program.

我想创建一个地形分页算法,一个4096x4096的灰度高度贴图作为整个地图。

I want to create a terrain paging algorithm, using a map called from a 4096x4096 greyscale heightmap as the "whole" map.

从我读到的,存储在VBO中的每个顶点将占用64字节。

From what I've read, each vertex stored in the VBO will take up 64 bytes.

我遇到的问题是,大多数来源说,单个VBO的大小应该在1-4mb之间,更少的VBOs更好。
然而根据我的计算,存储每个顶点将需要大约一千兆字节的数据! (4096x4096x64)
这不包括每个顶点可能需要为每个三角形存储多次。

The problem I have is that most sources state that a single VBO should be between 1-4mb in size, and less VBOs is better. Yet according to my calculations, storing each vertex would take a total of about a gigabyte of data! (4096x4096x64) That's not including that each vertice may need to be stored multiple times for each triangle.

一旦我得到了编码的地形部分,这也不适应不同的车辆和人在这张地图上。

Nor does this accommodate the different vehicles and people that would be on this map once I get the terrain portion of the code worked out.

我看到的另一个解决方案是在程序运行时从硬盘驱动器中寻找数据,但另一个来源说,在程序运行时创建和销毁是一个坏主意,而且它也是最好的实践中尽可能少的VBO。

the other solution I looked at was to page the data from the hard drive while the program is running, but another source says it's a bad idea to create and destroy while the program's running, and that it's also best practice to have as few VBOs as possible.

我真正想知道的是,我错过了什么?
我相信我在这里做了一些大量的监督,因为最大的VBO大小4mb只是看起来非常低,即使我在64x64块加载纹理,以及将填充的不同的交互式对象地图太。

What I really want to know is, what am I missing? I'm sure I'm making some kind of massive oversight here, because a maximum VBO size of 4mb just seems extremely low, even if I was loading the texture in 64x64 blocks, and the different interactive objects that would populate the map too.

还是我对我能达到的期望是不现实的?
有没有更好的方法给我,我不知道?
我正在看像Oblivion或Fallout 3这样的游戏,并且在某种程度上扩展到无边星球,看到大规模的地形,并且想知道如何在地球上是可能的。

Or are my expectations of what I can achieve just unrealistic? Is there a better method available to me that I'm unaware of? I'm looking at games like Oblivion or Fallout 3, and to some extend Boundless Planet, and seeing massive terrains, and wondering how on earth that can be possible.

我明白如何编写代码,这不是我第一次深入研究OpenGL,而是我第一次试图理解和利用VBOs。

I understand how to code, this isn't my first delve into OpenGL, but is my first time attempting to understand and utilize VBOs.

如果任何人都可以一些光进入我对VBOs的理解错误,这将是非常感激。

If anyone can shed some light into where my understanding of VBOs is going wrong, it would be much appreciated.

推荐答案


从我读到的,存储在VBO中的每个顶点将占用64字节。

From what I've read, each vertex stored in the VBO will take up 64 bytes.

它可以占用尽可能多的字节

position + normal + texcoords = 4 *(3 + 3 + 2)=每个顶点32个字节

position + normal + texcoords + tangent vector for bump)= 4 *(3 + 3 + 2 + 3)= 44字节

It can take as many bytes as you want, depending on vertex format.
position + normal + texcoords = 4*(3+3+2) = 32 bytes per vertex
position + normal + texcoords + tangent vector (for bump) = 4*(3+3+2+3) = 44 bytes


这不包括每个顶点可能需要每个三角形存储多次。

That's not including that each vertice may need to be stored multiple times for each triangle.

相同的顶点不应多次存储。使用索引基元(三角形列表或三角形条)。绑定标记的缓冲区,然后使用 glDrawElements glDrawRangeElements 。请记住,您可以在OpenGL中使用四边形 - 不必只使用三角形。

Identical vertices should not be stored multiple times. Use indexed primitives (triangle lists or triangle strips). Bind buffer for indicies, then use glDrawElements and glDrawRangeElements . Keep in mind that you can use quads in OpenGL - you don't have to use only triangles.


(4096x4096x64)

(4096x4096x64)

您不需要为地图上的每个像素创建四边形。一些区域是完全平坦的(即高度不改变),因此添加额外的三角形将会浪费资源。如果你添加某种网格简化算法来完成景观,你应该能够掉掉很多三角形。此外,太多的多边形将导致问题 - 三角形或四边形应该采取几个像素。如果有多个原语应该占据相同的像素,则渲染的结果将是有点噪声。因此,您必须考虑到所需的详细程度。

You don't need to create quad for every pixel on the map. Some areas are completely flat (i.e. height doesn't change), so adding extra triangles there will be a waste of resources. If you add some kind of mesh simplification algorithm to finished landscape, you should be able to drop quite a lot of triangles. Also, too many polygons will lead to problems - A triangle or quad should take several pixels. If there are multiple primitives that should occupy same pixel, the rendered result will be a bit "noisy". So you'll have to take desired level of detail into account.


我遇到的问题是,大多数来源说,单个VBO应该

The problem I have is that most sources state that a single VBO should be between 1-4mb in size, and less VBOs is better.

我不会信任每个来源,特别是在互联网上。很多人写作教程远不是专家。另一件事是,在DirectX(不是OpenGL)中,建议在可能的情况下将所有(即具有兼容顶点格式的所有对象)放入一个大静态顶点缓冲区(VBO模拟)缓冲区以减少渲染调用的CPU开销。所以建议VBO不应该大于4 MB看起来非常可疑的我。

I wouldn't trust every source, especially on the internet. A lot of people writing tutorials are far from being "experts". Another thing is that in DirectX (not OpenGL), it is recommended to put everything(i.e. all objects with compatible vertex format) into one large static vertex buffer (VBO analog), when possible, and avoid switching buffers to reduce CPU overhead for rendering calls. So advice that "VBO shouldn't be larger than 4 MB" looks extremely suspicious to me.

只有来自API开发人员或来自驱动程序开发人员(ATI或NVidia)的信息才是可信赖的 。或者当绝对肯定作者(教程或文章)有很多在该领域的经验,而不是另一个无知的wannabe游戏开发商。来自GDC,Siggraph,ATI,NVidia的文档可能是受信任的。

Information may be trustworthy only if it comes from API developer or from a driver developer (ATI or NVidia). Or when it is absolutely certain that author (of tutorial or article) has a lot of experience in the field and not another clueless wannabe game developer. Documents that come from GDC, Siggraph, ATI, NVidia may be trusted. Some tutorial written by anonymouse "someone" should be checked for being actually correct.

无论如何,关于性能,微软有两个文档:
Windows标题的问题
性能优化(Direct3D 9)(DirectX的东西,但一些建议可以适用于OpenGL)。

Anyway, regarding performance, microsoft had two documents: "Top Issues for Windows Titles" "Performance Optimizations (Direct3D 9)" (DirectX stuff, but some advices can be applicable to OpenGL).

此外,NVidia还收集了 OpenGL资源 ,其中包括与效果相关的实用程序( GLexpert 可能对您有用,并且有NVIdia OpenGL SDK等)。 )。一般来说,当您尝试提高成效时,请尝试不同的方法,并测量结果,而不是盲目追踪某人的建议。

Also, NVidia has a collection of OpenGL resources, that include performance-related utilities (GLexpert may be useful for you, and there is NVIdia OpenGL SDK, etc.). In general, when you're trying to improve performance, try different techniques, and measure results instead of blindly following someone's advice. See how many extra frames per second you get from using one technique or another.


但是根据我的计算,存储每个顶点将需要一个总共大约有一个gigabyte的数据! (4096x4096x64)

Yet according to my calculations, storing each vertex would take a total of about a gigabyte of data! (4096x4096x64)

这是正确的,如果你将这样构建整个地图。但没有理由一次加载整个地图,所以你只需要立即可见的地图块。

This is correct if you'll build entire map this way. But there is no reason to load entire map at once, so you'll just need immediately visible chunk of map.


我正在寻找像湮灭或辐射3的游戏,在某种程度上扩展到无边星球,看到大规模的地形,

I'm looking at games like Oblivion or Fallout 3, and to some extend Boundless Planet, and seeing massive terrains, and wondering how on earth that can be possible.

他们不能一次性加载所有内容。只有可见的对象,当前的块的地形和低多边形版本的几个附近的地形块在任何单个时刻加载。游戏商店只有当前使用的或即将使用的对象。它不断从HDD获取数据。

They DON'T load everything at once. Only objects that are visible, current "chunk" of terrain and low-polygonal version of few nearby terrain chunks are loaded at any single moment. Game stores only object that are currently used, or that will be used soon. It constantly gets data from HDD.

这篇关于OpenGl VBO技术在C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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