I have a particle system with a Particle struct. My particle system moves the particles around every frame. In order to draw efficiently, I am using a VBO to draw the particles as points. Currently, in order to update the VBO with the new particle positions every frame, I have to extract the position from my vector of particles, build a new vector of ofVec3fs, and then copy that back into the VBO. However, this extra step is computationally inefficient.
If I was coding in raw OpenGL, I would copy the entire Particle struct to the VBO and setup the vertex attrib pointers with the correct offsets and strides to avoid the need for a second copy. How do achieve this with the ofVBO class?
You need to call ofVbo::setAttributeData, for the location parameter you need to call ofShader::getAttributeLocation, with the name of your attribute declared in GLSL code.
See how the other attributes are used in ofVbo (positionAttribute, colorAttribute, etc.), yours will go to ofVbo::customAttributes
My issue is with the param to actually pass the data into the set attribute data function. It accepts only float * types, whereas I would need to pass it a Particle *.
I don’t think you can, you shouldn’t be building new vector every time, you should just access the positions to be uploaded. You should probably keep your positions on a persistent vector and have your particles reference those via pointer.
Note
From of samples and particle addons, you can see that another good way of making this efficient is computing new particle positions via shaders, and encoding positions to colours. Check the gpuParticleSystemExample
@chuckleplant For now my computation is all done on CPU side, but the goal is to eventually port this to be a GPU driven system, hence my desire to copy the entire Particles struct into the VBO