Is it possible to constantly change VBO values ​​on the iPhone OpenGL ES 2.0 inside the vertex shader?

I am new to Opengl ES 2.0 (and new to GLSL), so forgive me if this is an obvious question.

If I have a VBO that I initialize once on the processor at the beginning of my program, can I use vertex shaders to update each frame without performing calculations on the processor and then reloading it onto the GPU? I do not mean sending uniforms and data management based on this. Instead, I mean to cause a constant change in VBO on the GPU itself.

So, the simplest example that I can come up with is to add 1 to the x, y, and z components of gl_Position in the vertex shader every time you render a frame. This would mean that if I had only one vertex, and its initial position was set on the processor (0,0,0,1), then after 30 frames it would be (30,30,30,1) .

If possible, what would it look like in code?

+4
source share
1 answer

On modern desktop hardware (GL3 / DX10), you can use conversion feedback to write the output of the vertex or geometry shader to the buffer, but I really doubt that the transform_feedback extension is supported on the iPhone (or in ES in general).

If PBOs are supported (which I also doubt), you can at least do this with some copies of the GPU-GPU. Just copy the vertex buffer into the texture (linking it like a PBO), then render the textured full-screen square and update in the fragment shader. After that, you copy the framebuffer (which now contains the updated vertex data) to the vertex buffer (again, binding it as a PBO). But in this way you need to make 2 copies (although both of them must be fully implemented on the GPU), and if the vertex data is a floating point, you will also need to support floating point rendering goals and framebuffer objects.

I think that in ES, the best solution would be to do computations on the processor. Just keep a copy of the processor (so you at least don't get an unnecessary GPU-CPU countdown) and update the buffer data every frame (using GL_DYNAMIC_DRAW or even GL_STREAM_DRAW as a buffer use).

Perhaps you can also completely prevent constant updates by making changes dependent on other simpler data. In your example, you can simply use the uniform for the frame number and set this as the coordinate in the vertex shader for each frame, but I don’t know how complicated your update function is.

+1
source

All Articles