Dynamic memory allocation on GPU?

Started by
2 comments, last by Yann L 18 years ago
Since I can't get real-time vertex displacement mapping to work on the GPU, I decided to try displacing my vertices by passing object locations to the vertex shader and calculating displacement for each vertex depending on the distance to these objects. Works great, and it seems pretty fast too. Problem is, I don't know how many objects I need to pass to the shader until runtime. Had I done this in software, it would not have been a problem - using a list or queue or whatever would let me deal with any amount of objects. However, right now I have to pass each object explicitly, putting a cap on the max amount of objects I can pass to the shader. So, I'm wondering, is there a way to pass a list or array or similar object of arbitrary size to a vertex shader and then iterate through said list/array on the GPU?
-------------Please rate this post if it was useful.
Advertisement
Do you mean as uniforms or as vertex attributes ? In the former case, just supply an array and an object counter to the shader. Of course you'll still have a fixed max amount you can pass, but the GPU is not a CPU after all.
Neat, didn't know that was possible. So I can make an array of, say, 100 2D vectors and pass them as an array to GLSL?

Could you tell me which command I should use to pass arrays to the shader like this (glUniform2fv()?) and how to declare the uniform in the shader?

Thanks for your help.
-------------Please rate this post if it was useful.
In the shader, you can declare it like this:
uniform vec2 Objects[20];


In your CPU side code, you can write to this array using glUniform2fv(ARB):
glUniform2fv(location, count, Your_Data_Array);


Just make sure to not exceed the native uniform limit of your hardware, and that your hardware supports looping in vertex shaders.

This topic is closed to new replies.

Advertisement