Reputation: 588
If I have a model that's vertices constantly change and thus I need to rebind all the information on my VBO every frame would it be more performant to use immediate mode? Or is the fact that all the data is being passed in to the GFX card at once still a redeeming factor for the VBO?
Depending on the answer to the first question does this mean that keeping a world matrix for each mesh is better than simply translating the geometry and recreating the VBO?
Upvotes: 5
Views: 2322
Reputation: 54642
As with almost all performance questions, the answer is: It depends. A lot of factors come into play, primarily your exact usage patterns, and the characteristics of the OpenGL implementation.
While immediate mode is largely considered obsolete, and has been removed from modern OpenGL versions, it can be surprisingly difficult to get better performance with VBOs if your geometry is highly dynamic.
As a case study, I've been working on a hobby project (1) for a fairly long time (and with very long breaks). In this case, all vertex coordinates are calculated dynamically, and used for rendering only once. The initial version was using immediate mode because it was convenient for this case, and immediate mode was not quite as obsolete yet when I wrote it. Once I picked it up again several years later, and ported it to the Core Profile and to ES 3.0, I initially had a hard time getting equal performance.
You'll have to try various options to find what works best for your use case and platform. Common options include:
glBufferSubData()
in batches.glBufferData()
with a NULL data pointer. Then use glMapBuffer()
or glMapBufferRange()
to map the buffer memory, and write your vertex data to the mapped memory.There's a common misconception (which partly reflects in the other answers) about how immediate mode works on current GPUs. No current GPU (that I know of) actually supports immediate mode. When you make immediate mode calls, the driver will generally put the vertex data in buffers, and submit those buffers to the GPU at a later point. So the GPU will execute pretty much the same drawing in the end. The only difference is if you build buffers (by using VBO based drawing), or if you let the driver handle it (by using immediate mode).
The main reason why immediate mode drawing is generally inefficient is that it requires so many API calls, not because of what the GPU ends up executing.
(1) Shameless plug, if anybody wants to see what it is: http://retokoradi.com/volume-rendering/.
Upvotes: 10
Reputation: 155
A VBO will perform better because, as you say, it's sending all of the data to the GPU at once. It will generally run even faster if you use a double-buffering solution where you prep the VBO for the next frame while the GPU is working on rendering the one from the previous frame since it will not stall waiting on more data from the CPU.
And yes, it would be far better to store a separate world matrix for each VBO if your transformation can be adequately described by such a matrix. You would be changing less data each frame which causes less to have to be transferred across the bus to the GPU.
Upvotes: 1
Reputation: 4888
Yeah, it's almost always best to use a matrix for transforming geometries. Vertex shader will multiply each vertex by a world matrix. And it's all on GPU which is multithreaded, meaning good performance even on complex geometries.
Upvotes: 1