Jump to content
  • Advertisement
Sign in to follow this  
whaledawg

OpenGL Buffer Objects and Speed

This topic is 3618 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, So I'm planning on moving into the game industry and I figured the best way to get started would be to build a game. Toward that end I am teaching myself OpenGL out of the "OpenGL Super Bible(3rd edition)" and I just got through the chapter on buffer objects. It sets up a vertex array of 30,000 random(each frame) vertices in a sphere and draws them as points. It allows you to run it using regular vertex arrays or as a buffer object and it records the frames per second so you can see how much faster using a buffer object is. But it isn't. It's about 2% slower every time. Can anyone think of a good reason why? Here's the code:
// Switch between buffer objects and plain old vertex arrays
void SetRenderingMethod(void)
{
    if (useBufferObject)
    {
        glBindBuffer(GL_ARRAY_BUFFER, bufferID);
        // No stride, no offset
        glNormalPointer(GL_FLOAT, 0, 0);
        glVertexPointer(3, GL_FLOAT, 0, 0);

        if (!mapBufferObject)
        {
            if (animating)
            {
                glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GLfloat) * 
                                numSphereVertices * 3, sphereVertexArray);
            }
            else
            {
                // If not animating, this gets called once
                // to establish new static buffer object
                glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 
                             numSphereVertices * 3, sphereVertexArray, 
                             GL_STATIC_DRAW);
            }
        }
    }
    else
    {
        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glNormalPointer(GL_FLOAT, 0, sphereVertexArray);
        glVertexPointer(3, GL_FLOAT, 0, sphereVertexArray);
    }
}
By the way, if mapBufferObject is turned on then the buffer object is, well, mapped already and we don't have to copy it over.

Share this post


Link to post
Share on other sites
Advertisement
The flag you are using is GL_STATIC_DRAW while you seem to be updating the data at every frame.

Share this post


Link to post
Share on other sites
That's true, but only when animating is turned off. When it's turned on is when I was looking at the frame rate decrease.

Thanks for the reply.

Share this post


Link to post
Share on other sites
When you are animating, you could try to set the buffer using glBufferData once with the parameter GL_DYNAMIC_DRAW to indicate that this buffer will change often and then do the modifications using glBufferSubData per Frame.

The driver might choose a different type of memory for GL_DYNAMIC_DRAW where you can upload the data faster compared to GL_STATIC_DRAW.

Share this post


Link to post
Share on other sites
Also, if you will be updating a VBO every frame, it is better to use 2 VBOs and ping pong. I've found this increases performance.

Share this post


Link to post
Share on other sites
Quote:
Original post by V-man
Also, if you will be updating a VBO every frame, it is better to use 2 VBOs and ping pong. I've found this increases performance.


Does that make it perform the update asynchronously?

Share this post


Link to post
Share on other sites
Quote:
Original post by soconne
Does that make it perform the update asynchronously?


It's not asynchronous in the sense that PBOs are.
It is just for avoiding the stall. The GPU might be rendering from the first VBO so it is better for you to update the second VBO.
I was using glBufferData as recommended by some nVidia document but that wasn't giving the performance I wanted on ATI, so I implemented double VBOs.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!