1

This question comes in two (mostly) independent parts

My current setup is that I have a lot of Objects in gamespace. Each has a VBO assigned to it, which holds Vertex Attribute data for each vertex. If the Object wants to change its vertex data (position etc) it does so in an internal array and then call glBufferSubDataARB to update the version in the GPU.

Now I understand that this is a horrible thing to do and so I am looking for alternatives. One that presents itself is to have some managing thing that has a large VBO in the beginning and Objects can request space from it, and edit points in it. This drops the overhead of loading VBOs but comes with a large energy/time expenditure in creating and debugging such a beast (basically an entire memory management system).

My question (part (a)) is if this is the "best" method for doing this, or if there is something better that I have not thought of.

Such a system should allow easy addition/removal of vertices and editing them, as fast as possible.

Part (b) is about some simple actions taken on every object, ie those of rotation and translation. At the moment I am moving each vertex (ouch), but this must have a better option. I am considering uploading rotation and translation matrices to my shader to do there. This seems fine, but I am slightly worried about the overhead of changing uniform variables. Would it ultimately be to my advantage to do this? How fast is changing uniform variables?

Community
  • 1
  • 1
rspencer
  • 2,651
  • 2
  • 21
  • 29
  • 1
    **OF COURSE IT'S FASTER TO USE A UNIFORM!** Build your 4x4 transformation matrix (with any suitable library) and pass it to the vertex shader, then manipulate your vertexes there. Changing uniforms has a certain overhead, but that's negligible to the overhead of doing CPU math for each vertex (darn, it's **EXACTLY** what vertex shaders are for). (If you then find that you're switching too many uniforms, you can optimize things out by using Uniform Buffer Objects). – peppe Sep 09 '13 at 17:46

1 Answers1

2

Last time I checked the preferred way to do buffer updates was orphaning. Basically, whenever you want to update your buffered data, you call glBindBuffer on your buffer, which invalidates the current content of the buffer, and then you write your new data with glMapBuffer / glBufferSubdata.

Hence:

  1. Use a single big VBO for your static data is indeed a good idea. You must take care of the maximum allowed VBO size, and split your static data into multiple VBOs if necessary. But this is probably an over-optimization in most cases (i.e. "I wouldn't bother").
  2. Data which is updated frequently should be grouped in the same VBO (with usage = GL_STREAM_DRAW), and you shall use orphaning to update that.

Unfortunately, the actual performance of this stuff varies on different implementations. This guy made some tests on an actual game, it may be worth reading.

For the second part of your question, obviously using uniforms is the way to do it. Yes there is some (little) overhead, but it's sure 1000 times better than streaming all your data at every frame.

sbabbi
  • 11,070
  • 2
  • 29
  • 57