Is there an equivalent to 'uniform' (shader) variables in openframeworks?

Currently for a project I have to call ofDrawBox(ofPoint(x, y, z), d); about 50,000 times, and its a bit laggy to make this call 50,000 times per draw command.

In my graphics class, we learned that when programming GLSL shaders, you can use a uniform variable to keep data on the GPU, and have the shader use the uniform variable to process the data differently (so you don’t have to resend the data over and over again).

Is there anything like this in openframeworks, where i.e. I know the (x, y, z) location of every box in advanced, so is there a way I could load this once, and only provide a d-parameter each loop of the draw command?


Yes, absolutely! Have a look at the setUniform* functions in ofShader - ofShader | openFrameworks

oF uses OpenGL under the hood so depending on your platform you can use anything OpenGL has.

On desktop platforms, I think the lowest version supported is on OSX which is OpenGL 4.0, Linux and Windows support higher.

This means you can use things like uniform buffers, instanced rendering etc. This is a really good site for learning about these things LearnOpenGL - Advanced GLSL

Also check out examples/gl for oF specific shader examples.

if I understand your question correctly, you might want to look at the “vboMeshDrawInstancedExample” that ships with OF

1 Like