I implemented a small particle simulation viewer, that displays particle simulations. Similar to VMD.
Since I got a huge number of particles (> 80000), I use a GL_ARRAY_BUFFER and GL_POINTS to display them. This works quite well with small datasets.
On each timestep, I fill in the new particle positions using the following code:
void displayPoints(Timestep t) {
int elements = t.elements;
unsigned int glbuffersize = elements*sizeof(float4);
glBindBuffer(GL_ARRAY_BUFFER,positionsVBO);
glBufferData(GL_ARRAY_BUFFER,glbuffersize,t.pos,GL_DYNAMIC_DRAW);
glVertexAttribPointer(shaderAtribute,4,GL_FLOAT,GL_FALSE,0,0);
glEnableVertexAttribArray(shaderAtribute);
glBindBuffer(GL_ARRAY_BUFFER,positionsVBO);
glUseProgram(shaderProgram);
glDrawArrays(GL_POINTS, 0, elements);
}
t.pos is just a simple float4 struct array.
If I run this now with my 600MB testset with >80000 points per timestep, the display locks up after the first 20-50 frames. I have to wait for 2mins until, I see the program running again for 10 frames until it freezes again.
I suspect that the code above might fill up the graphics memory. Is there a better way to just do this animation?
If you want to have a look at the complete code, it’s provided here: https://github.com/moeeeep/opengl_dataviewer
(The shaders are currently hardcoded to my machines, since I didn’t have the time to fix my CMake file yet).
glBufferData(re-)intializes a whole new Buffer Object – just likeglTexImagereinitializes a whole new texture.Use
glBufferSubDatato update the contents, without going a full object allocation.