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:

  1. Use of SSE to optimize the normal calculation.
  2. Use of TBB or openMP to parallelize loops.

Answers


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.


Need Your Help

How to get Java's int.class in Scala?

java scala reflection

I am using Scala to do some work with Java's reflection API. But I can't seem to figure out how to access in Scala what in Java would be: int.class, float.class, boolean.class.

How to use Popen to run backgroud process and avoid zombie?

python process subprocess zombie-process

I've a listener server running new thread to for each client handler. Each handler can use:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.