Search code examples
wpfperformanceopenglsharpgl

OpenGL: More vertices, slower performance


I am working on a part of a program where given a collection of xyz-coordinates, a 3D model is made. I have all of the functionality needed for this picture done (i.e. panning, rotating, scaling) however the more xyz-coordinates given, the slower my program runs. My program runs pretty smooth when processing 29,000 coordinates, but I when I have 300,000 points, my program slows down. I am using SharpGL in order to use OpenGL in WPF. The code for inserting all these points looks as follows:

gl.Begin(OpenGL.GL_LINES);

        for (int i = 0; i < (parser.dataSet.Count - 1); i++)
        {

            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(parser.dataSet[i].X / parser.xDiv, parser.dataSet[i].Y / parser.yDiv, parser.dataSet[i].Z);
            gl.Vertex(parser.dataSet[i + 1].X / parser.xDiv, parser.dataSet[i + 1].Y / parser.yDiv, parser.dataSet[i + 1].Z);
        }

        gl.End();
        gl.Flush();

Am I doing something noobish (im not familiar with OpenGL) that I can fix? Some people have mentioned scaling my data down, which I am not totally opposed to, but is there a way to 'scale back up' as I "zoom"(rescale) in on the picture?


Solution

  • The immediate-mode (glBegin()/glEnd()) function-call overhead for 300,000 points is massive.

    Batch up your geometry submission using vertex arrays or vertex buffer objects. That way you can draw all your points in 10-20 calls instead of nearly a million.