开发者

Fast rotate and translate without using glRotate / glTranslate

I have an octagon which I need to rotate and translate to 10,000 different locations/angle. The angle and coordinates changes dynamically.

  1. If I use glRotate and glTranslat开发者_如何转开发e in immediate mode, it would be too slow due to all the going back and forth between client/server.

  2. If I use glRotate and glTranslate on a Display List, it will be fast, but I am avoiding Display List because it is deprecated.

  3. If I use VBO, I have to pre-rotate and and pre-translate the octagon on the CPU prior to uploading it to server memory. This works, but takes lots of CPU time.

So I am wondering...is there anyway to translate/rotate with vertices stored in VBO , without resorting to CPU based computation. Is there a VBO equivalent for executing rotate/translate values stored in server memory? I would really love the GPU to do all the calculations and free my CPU from all the trig functions.


I would use VBO and regular glRotate and glTranslate, (or provide a matrix to a vertex shader using glUniformMatrix). I don't think it will slow down the rendering!


You can use GLSL to write a shader that handles the transformation for you. However, you will need to make the transformation matrix available to the shader somehow.

If you are doing this in 2D, there's a similar question (for quads, but the theory is the same) on the game development stack exchange: Basics of drawing in 2D with OpenGL 3 shaders.

Note that the second answer for that question, which gives more details, has a link to OpenGL.org which has a broken anchor. I believe it should link to Instanced arrays.

An example of instancing I found after a quick google search: Shader instancing. In this tutorial you probably want to look at the vertex shader for an example of a transformation matrix applied using a texture buffer for storing the matrix. The example code is Delphi, but it should be readable. The site is in German, but you can always use Google translate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜