Game Programming and Development Tools

OpenGL - glFlush – ssquared

SSquared

Member

Posts: 654
From: Pacific Northwest
Registered: 03-22-2005
Our product contains/displays GIS data. I am attempting to display street data which is made up of thousands of poly lines. For some reason, its been taking around 40 seconds to draw in my MFC port, but the Borland code is neglible. I finally decided to tackle this issue today as its been really slowing me down and bothering me.

The code reads in a file with the street data. It reads in each street, or partial segment of a street, and then writes it out with glDrawArrays using GL_LINE_STRIP. After each draw, it calls glFlush. This can happen thousands (or, in my example, I think it happens over 20,000 times). I narrowed down the problem to glFlush.

Is glFlush an expensive hit? I have removed the repetitive one and only call it once my street layer is complete. This has significantly sped up the code. I found a good article on glFlush and my suspicions appear correct. The article also makes it sound like I don't even need to bother with the call because: 1) Things get flushed automatically if the buffer gets full and 2) It will get flushed when I call SwapBuffers on the OpenGL double buffer.

So, do I really need to use glFlush? I am still quite curious why it is so slothful in VS 2005 C++ and no noticeable issue with the old Borland 5.01 compiler.

Another question. I'm not quite sure how to properly ask this. Does OpenGL have some way to pass in a large number of GL_LINE_STRIP segments? The code uses glDrawArrays to draw the segments, but is there a way to also pass in non-contiguous sections of GL_LINE_STRIPs? glDrawArrays wants to always start from the previous point and make a line to the next point. I want to do something where the first 5 points may be attached, then lift up the pen and move to another starting, then have the next 8 points be contiguous, lift up pen, move to another coordinate, etc. Is this possible in one easy call or must it be done for each contiguous segment?


Thanks for your help. Sorry for the length.

steveth45

Member

Posts: 536
From: Eugene, OR, USA
Registered: 08-10-2005
Maybe glFlush causes a VSync wait each time it is called in your particular implementation. The way that a particular GUI API deals with the window handle/OpenGL interaction could cause glFlush to be handled differently.

If you are drawing the same map data repeatedly, using display lists could speed things up considerably. Something like this:


GLuint myDisplayList;
myDisplayList = glGenLists(1);
glNewList(myDisplayList, GL_COMPILE);
// Make all of your drawing calls here, nothing is drawn
glEndList();

glClear(GL_COLOR_BUFFER_BIT);
glCallList(myDisplayList); // Here is where it actually gets drawn
glFlush();

------------------
+---------+
|steveth45|
+---------+

SSquared

Member

Posts: 654
From: Pacific Northwest
Registered: 03-22-2005
Dude!!! That is so what I'm looking for. Thanks! Not sure at what point I will implement something like this. Right now, we are just trying to get things ported. Due to my huge speed issue, I had to figure out some types of optimization now (I'm now down to a reasonable level), but once the port is done, we will then rethink how to better optimize the OpenGL code.

By using the list, does that mean I can simply re-use the List each time I want to draw? That would be GREAT. Keep in mind, this is not animating anything, it's generally static data.

We've talked about hiring an intern who understands OpenGL and how we can best optimize things. Or perhaps direct us to some other library. The OpenGL code is maintained within two classes (a drawing and utility class), so it should not be too painful to slip in another library, if needed.

steveth45

Member

Posts: 536
From: Eugene, OR, USA
Registered: 08-10-2005
quote:
Originally posted by ssquared:
Dude!!! That is so what I'm looking for. Thanks!

By using the list, does that mean I can simply re-use the List each time I want to draw? That would be GREAT. Keep in mind, this is not animating anything, it's generally static data.

No problem. Yes, once you create the display list, you can reuse it as many times as necessary, which makes it ideal for static content. OpenGL is the most mature and portable standard for hardware accelerated rendering. Every popular OS and programming language support it. You don't need to hire an intern, just pay me consulting fees .

Most of the information you need about OpenGL is available online, including the famed Red Book and Blue Book. The first one is a programming guide and the second one is a programming reference, for whatever that's worth. I think the Red Book has more complete examples.

------------------
+---------+
|steveth45|
+---------+