Hi guys, new to the forum,
So I’m working on some quantum mechanics and acoustic wave problems. For now we’re focusing on two-dimensional problems. So we need to visualize functions that look like z = F(x,y,t). So I’m doing animations of 2D-plots. simple enough. I’ve been doing this with freeglut under xubuntu, and I’m really happy with the results so far.
My main problem is that the animations are very unsmooth for large grid sizes. I get about 16 FPS on an X-Y grid of 128128 points. For 256256 that goes down to about 5 FPS, which is pretty unusable.
I’m doing all of the computations before hand, and storing the triangle data in the data structures that are detailed further down. Bascially the object glutFrame2D contains all the data the animation needs for a particular frame. I’ve got a scheme going to make sure that each time a new frame is drawn, the program chooses the frame whose time stamp best matches the current wall clock time, so that the animation is running in ‘real time’.
So the problem is that my PC (lenovo x60 with 3 gigs ram) can’t draw enough of these glutFrame2D objects per second, and I’m kind of stuck; I’m not sure how to make this any faster. All the glutFrame2D objects are already in memory before the animation starts. For a 256*256 grid each frame is 2.5 megs, so I couldn’t load too many into video memory. I tried parallelizing the for-loop that draws each quad, using Intel’s TBB library, but got ugly results, also that approach will give me at best about a 70% speed gain, which won’t solve the problem.
Is there generally a better way to approach this?
There are some basic things I could do to at least make each frame smaller in size; most of the vertex data is repeated as the quads are next to each other for instance. But I don’t think any of that will really solve the problem.
Here are the objects I’m using to store the triangle data; take it as pseudo code - many details omitted.
struct glut_4color // pretty obvious
{
public:
GLubyte red;
GLubyte green;
GLubyte blue;
GLubyte alpha;
void set()
{ glColor4ub(red,green,blue,alpha); }
};
struct glut_quad // two triangles with common hypotenuse
{
public:
float x0,x1,y0,y1,z00,z01,z10,z11; //locations of vertexes
glut_4color c0,c1; //color of each triangle
void draw() {
c0.set();
glBegin(GL_TRIANGLES);
glVertex3f( x0, y0, z00);
glVertex3f( x1, y0, z10);
glVertex3f( x0, y1, z01);
glEnd();
c1.set();
glBegin(GL_TRIANGLES);
glVertex3f( x1, y1, z11);
glVertex3f( x1, y0, z10);
glVertex3f( x0, y1, z01);
glEnd();
}
};
class glutFrame2D // each frame is a collection of glut_quads
{
public:
unsigned N; // number of glut_quads - 256*256
float t; // time stamp for this frame
glut_quad * U; // memory block
void draw() {
for (unsigned i = 0;i<N;i++)
U[i].draw(); } /// draws each quad; this is what takes so long.
};
Thanks in advance for any advice,
cheers,
nick maxwell