Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When updating a mesh does the glBufferSubdata call belong in the update function or render function?

I'm trying to organize my game appropriately and knowing this would help me. This is my first game and I want to structure it properly.

share|improve this question
That depends entirely on what, in general, your "update" function does and what your "render" function does. – Josh Petrie Apr 4 '12 at 1:32
Yes, this is just a cosmetic decision. – stephelton Apr 4 '12 at 5:08

It really depends on what the purpose of the update and render functions you wrote and are referring to are.

The purpose of glBufferSubData is to update, in whole or in part, the data stored in an OpenGL buffer object. It is fundamentally a rendering operation, and so it absolutely belongs in render code.

Consequently if you are asking if the function belongs in the "update-the-game-logic" function called update or the "render the mesh" function called render, the answer is the latter. In this case you're talking about the separation of game state and specific gameplay logic from the act of rendering, which is generally a good separation, and should be enforced (if that is what your update is doing, it shouldn't be part of the mesh class at all because that is breaking that separation).

However if your update function is a render-specific update (for example, one that applies animation data to a mesh in some form, or one that pushes through new values for time-based shader parameters), then it is probably a reasonable approach to have your glBufferSubData call in that function rather than render, because fundamentally the call is about updating render information. This approach also makes it a little more obvious that you could update a mesh once to make it current, and then render it multiple times and helps keep that behavior separation in place, reducing the length of the render method which might otherwise need to have some lazy-evaluation checks so you didn't needlessly call glBufferSubData more times than you wanted to.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.