简体   繁体   English

使用OpenGL创建多个多边形很慢?

[英]Creating many polygons with OpenGL is slow?

I want to draw many polygons to the screen but i'm quickly noticing that it slows down quickly. 我想在屏幕上绘制许多多边形,但我很快注意到它会很快减速。 As a test I did this: 作为测试,我这样做:

for(int i = 0; i < 50; ++i)
{
        glBegin( GL_POLYGON);
        glColor3f( 0.0f, 1, 0.0f ); glVertex2f( 500.0 + frameGL.GetCameraX(), 0.0f + frameGL.GetCameraY());
        glColor3f( 0.0f, 1.0f, 0.0f ); glVertex2f( 900.0 + frameGL.GetCameraX(), 0.0f + frameGL.GetCameraY());
        glColor3f( 0.0f, 0.0f, 0.5 ); glVertex2f(900.0 + frameGL.GetCameraX(), 500.0f + frameGL.GetCameraY() + (150));
        glColor3f( 0.0f, 1.0f, 0.0f ); glVertex2f( 500 + frameGL.GetCameraX(), 500.0f + frameGL.GetCameraY());
        glColor3f( 1.0f, 1.0f, 0.0f ); glVertex2f( 300 + frameGL.GetCameraX(), 200.0f + frameGL.GetCameraY());
        glEnd();
}

This is only 50 polygons and already it's gtting slow. 这只有50个多边形,而且已经很慢了。 I can't upload them directly to the card because my program will allow the user to reshape the verticies. 我无法将它们直接上传到卡片中,因为我的程序将允许用户重新整形顶点。

My question is, how can I speed this up. 我的问题是,我怎样才能加快速度。 I'm not using depth. 我没有使用深度。 I also know it's not my GetCamera() functions because if I create 500,000 polygons spread apart t's fine, it just has trouble showing them in the view. 我也知道这不是我的GetCamera()函数,因为如果我创建500,000个多边形分开t很好,它只是在视图中显示它们有困难。 If a graphics card can support 500,000,000 on screen polygons per second, this should be easy right? 如果显卡每秒可以支持500,000,000个屏幕多边形,这应该很容易吗?

Thanks 谢谢

  1. as already mentioned don't do glBegin and glEnd in the loop but outside 如前所述,不要在循环中执行glBegin和glEnd,而是在外部
  2. for even better performance use vertex arrays 为了更好的性能使用顶点数组
  3. for optimal performance use vertex buffer objects 为了获得最佳性能,请使用顶点缓冲对象

The solutions are ordered in how much speed gain you will get, and inversly how wide supported they are. 这些解决方案按照您将获得多少速度的顺序排序,并且反过来支持它们的宽度。 That said, any modern graphics card supports all of those -- you just need to be careful when coding for embedded OpenGL systems. 也就是说,任何现代显卡都支持所有这些 - 在编写嵌入式OpenGL系统时只需要小心。

Contemporary games (the ones that achieve your cited 500kk limit) all use at least VBO's (if not Geometry Shaders, but that's even a step beyond). 当代游戏(达到你引用的500kk限制的游戏)都至少使用VBO(如果不是几何着色器,但这甚至超过了一步)。 To effectively learn the techniques mentioned I honestly suggest taking them a step at a time -- eg first learning display lists, then vertex arrays, then VBO's, because in practice each one builds on top of the former. 为了有效地学习所提到的技术,我诚实地建议他们一步一步 - 例如首先学习显示列表,然后是顶点数组,然后是VBO,因为在实践中每个都建立在前者之上。

Immediate mode (characterized by using a GL command per object) is extremely slow, and even deprecated in the current GL standard -- a long theory short, it's because one of the most expensive graphics operation (apart from texture manipulation) are draw calls -- calls between the graphics card and the processor -- so in practice it's best to prepare all you can beforehand, and submit it to the GPU in one call (or as little as possible). 立即模式(以每个对象使用GL命令为特征)非常慢,甚至在当前的GL标准中被弃用 - 这是一个很长的理论简称,因为最昂贵的图形操作之一(除了纹理操作)是绘制调用 - - 显卡和处理器之间的通话 - 所以在实践中最好事先做好准备,然后一次通话(或尽可能少)将其提交给GPU。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM