Best Way to update all vertices data in openGL and to recalculate normals
Q1: I have a 3D model which has a vertex array. each element has x,y and z values. Now I have created a dynamic vbo buffer to render this array in OpenGL. The problem is that I have to update all the vertices each frame [ which depends on some logic. but its for sure that it is not a simple transformation: I mean it cannot be done using a single transformation matrix for all vertices ].Now for each frame I map the vbo buffer then update the data and unmap it, and then render it. The update is done in a for loop. Now I was wondering is there any faster way to do that?
Some points: I have to update all vertices. Its my requirement, I cannot work with a subset of vertices.
Q2: I have to recalculate the normals because the vertices has been updated.and for smooth shading I need to take the resultant of all the normals at a vertex which is slow. Is there any faster way to do so? Basically faster recalculation of normals for smooth shading.
Some things which I already know:
- Use of SSE to optimize the normal calculation.
- Use of TBB or openMP to parallelize loops.
I think that Transform Feedback is what you are looking for.
Using transform feed back, you can modify your vertex data during runtime and use it for another rendering , and all these operations can be achieved from GPU itself inside a vertex shader using transform feedback.
And it is supported in Opengl 3.0 and above.
Here is a simple example for how to use transfrom feedback.
here is some details about feedback buffer usage.