GlBuffer with heap memory

I'm having a problem, I'm not sure how to handle it correctly. I recently started creating a particle system for my game and used a structure called the โ€œParticleโ€ for these particles. "Particle" contains vertex information for rendering.

The reason I am having problems is because I collect my particle structures in heap memory to save on large allocation volumes, however I'm not sure how to use the pointer array in glBufferData, I have the impression that glBufferData requires an actual an instance of a structure, not a pointer to an instance of a structure.

I know that I can rebuild an array of floats, each rendering is just for drawing my particles, but is there an OpenGL call, such as glBufferData, which I am missing somewhere that can cancel references to my pointers as it looks through the data I supply? I would ideally want to avoid having to iterate over an array just for copying data.

+4
source share
1 answer

I get the impression that glBufferData requires an actual instance of the structure, not a pointer to an instance of the structure.

Right. Effectively glBufferData creates a flat copy of the data previously set to it at the address specified by it through the data parameter.

which I am missing somewhere, which can cancel the links to my pointers, because it passes the data that I provide?

You think of client-side vertex arrays, and they are among the oldest OpenGL features. They work with OpenGL-1.1, released 19 years ago.

You just do not use a buffer object, i.e. do not call glGenBuffers, glBindBuffer, glBufferData and pass the client-side data address directly to glVertexPointer or glVertexAttribPointer.

However, I highly recommend actually using buffer objects. Data must be copied to the GPU in any case so that it can be visualized. And doing this through a buffer object allows the OpenGL driver to work more efficiently. In addition, since OpenGL-4, the use of buffer objects is no longer mandatory.

+3
source

All Articles