I have been looking into using some software to perform industrial-scale DEM simulations. These type of simulations will require millions of particles to be simulated.
Currently, the software I would like to use has some notable performance issues when visualizing the results during the simulation when using openGL. It turns out the part of the code responsible for drawing the particles is this:
void Draw_ParticleGeometry_Sphere()
{
SetColor_Ramp();
//if(m_OpenGL.Debug_Lines==1)
//{
// Gl_WireframeP = true;
//}
for( int i=0; i<m_num_KParticleObjects; i++ )
{
glNewList(10+i,GL_COMPILE);
if(m_OpenGL.color_type==0)
{
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, Col[i]);
glMaterialfv(GL_FRONT, GL_SPECULAR, materialSpecular);
glMaterialfv(GL_FRONT, GL_EMISSION, materialEmission);
glMaterialf(GL_FRONT, GL_SHININESS, shininess);
}
glPushMatrix();
glutSolidSphere(m_KParticleObject[i].radius,20,20);
if(Gl_WireframeP)
{
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, Col[6]);
glMaterialfv(GL_FRONT, GL_SPECULAR, materialSpecular);
glMaterialfv(GL_FRONT, GL_EMISSION, materialEmission);
glMaterialf(GL_FRONT, GL_SHININESS, shininess);
glutWireSphere(m_KParticleObject[i].radius*1.02f,15,15);
}
glPopMatrix();
glEndList();
}
}
To be fair I'm new to openGL, but it seems to me that this piece of code loops over all particles, assigns them attributes and add them to a list. Generally, looping like this is not very efficient for a large number of elements. I have been reading up in visualizing particles in openGL and it seems instancing would be a better fit. My questions are:
- Is looping over all particles like this an efficient way of handling such large systems of particles in openGL?
- Is there an alternative to looping over all particles?
- How could this code be improved?