Transforming or Moving objects in opengl e3

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Transforming or Moving objects in opengl e3

DearDaniel
hi, I am trying to making a OpenGL program which the object might be modified in during the execution of the program.
I have 2 approaches in my mind but I don't know which is better(especially for the new opengl). In the hello texture example, the rotation was done on the camera but this is not what I want to do for my program.

1. provide a transformation matrix for each object. An pass it as a uniform variable(once for an object) to the opengl, let the gpu do the calculation on each vertex every frame

2. do pre-calculation on the coordinates of the vertex before inserting it into the buffer and bind it to the uniform variable.

Which is preferred? Personally, I think both is ok but 1 requires more processing but simpler in implementation. Am I correct?

Actually, I always have problems in doing some trade-offs between processing speed and updating speed(update vertex buffer). For cases similar the above one, how should I make decisions on building a faster program?
Never Stop ... Learn more ... Be humble ...
Reply | Threaded
Open this post in threaded view
|

Re: Transforming or Moving objects in opengl e3

jmaasing
On most modern computers the bandwidth between the CPU and the GPU is the limiting factor. Meanwhile the GPU are super-optimized for matrix calculations. So it is usually better to let the GPU do calculations - even complex ones, instead of calculating on the CPU and send data to the GPU.
Reply | Threaded
Open this post in threaded view
|

Re: Transforming or Moving objects in opengl e3

DearDaniel
Thanks for your reply. So,the major advices are :

>>  I should minimize the data transfer between the GPU and the CPU
>>  Let the GPU do the most complicated jobs

Correct?
Never Stop ... Learn more ... Be humble ...
Reply | Threaded
Open this post in threaded view
|

Re: Transforming or Moving objects in opengl e3

elect
Jmaasing is right. The only optimizations you may want to implement, however, is calculating gl_Position in this way

gl_Position = proj * (view * (model * position));

rather than this:

gl_Position = proj * view * model * position;

So that you force always a mat * vec multiplication instead a mat * mat which is something more complex

And you may also want to pre-calculate proj * view on the cpu since those matrices are supposed to stay per-frame constant, so

gl_Position = projView * (model * position);

Anyway, it's very difficult to see improvements by things like this unless very very special conditions apply, because usually one has much stronger bottlenecks somewhere else
Reply | Threaded
Open this post in threaded view
|

Re: Transforming or Moving objects in opengl e3

DearDaniel
Thanks. I like that idea. I haven't thought of that before.

Daniel
Never Stop ... Learn more ... Be humble ...