Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 11

Thread: Optimizing rendering of rectangles

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member Newbie
    Join Date
    Sep 2015

    Optimizing rendering of rectangles

    I need to draw couple of millions of rectangles, and I would like to get some advice on optimization, because currently it gets very slow (can notice lag when starting, zooming or dragging). The code is as follows:

    Code :
        const GLfloat vertexes[] =
            x,              y,              0.0,
            x + x_delta,    y,              0.0,
            x,              y + y_delta,    0.0,
            x + x_delta,    y + y_delta,    0.0,
        int vertexLocation = m_program.attributeLocation("aVertex");
        m_program.setAttributeArray(vertexLocation, GL_FLOAT, vertexes, 3);
        const GLfloat colors[] =
            0.2, 0.6, 1.0, 0.3,
            0.2, 0.6, 1.0, 0.3,
            0.2, 0.6, 1.0, 0.3,
            0.2, 0.6, 1.0, 0.3,
        int colorLocation = m_program.attributeLocation("aColor");
        m_program.setAttributeArray(colorLocation, GL_FLOAT, colors, 4);
        const GLushort indices[] =
            0, 1, 2, // first triangle
            3, 3, 2, // second triangle
        glDrawElements(GL_TRIANGLES, sizeof(indices)/sizeof(indices[0]), GL_UNSIGNED_SHORT, indices);
        m_program.disableAttributeArray( vertexLocation );
        m_program.disableAttributeArray( colorLocation );

    These rectangles are actually very small and they appear as lines (code for drawing lines is almost the same), so to certain zoom level I draw only lines, still is very slow. I am not sure if such performance is ok when drawing so many of rectangles. Maybe I am expecting too much, or there is a mistake in code. Anyway, I would like to hear some hints on performance optimization.

    Already using glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE);, drawing only in 2D. All rectangles are of unique dimensions.

    Thanks you in advance.
    Last edited by Kozersky; 10-07-2015 at 08:00 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts