Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 3 of 3 FirstFirst 123
Results 21 to 23 of 23

Thread: Buffer vs immediate

  1. #21
    Junior Member Newbie
    Join Date
    Jun 2012
    Posts
    16
    Quote Originally Posted by mhagain View Post
    Probably best to stick with standard vertex arrays, yes. There's a good chance that you don't have hardware T&L either, so you won't get much benefit from VBOs even if you could find a driver that supported them.
    So what are my alternatives to glMapBuffer? I am having the code throws an excpetion because (obviously) without glMapBuffers memcpy attempts to copy to a NULL destination.

    Could (should) I just pass (from your code) myWonderfulPoints to glVertexPointer and glColorPointer? Or would this be dangerous due to myWonderfulPoints having the possibility of being changed mid frame?

    Or should I create a new array of MAX_POINTS every frame and run memcpy on that, or is that too costly?
    Last edited by Beiufin; 06-27-2012 at 02:21 PM.

  2. #22
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,217
    This code should work as a non-VBO alternative:
    Code :
    // your point struct might look something like this
    struct drawpoint
    {
        float position[3];
        unsigned char color[4];
    };
     
    // using a vector here; just change it to whatever container type you prefer
    std::vector<drawpoint> myWonderfulPoints;
     
    // call this every frame to draw stuff!
    void DrawMeSomePoints (void)
    {
        glEnableClientState (GL_VERTEX_ARRAY);
        glEnableClientState (GL_COLOR_ARRAY);
     
        glVertexPointer (3, GL_FLOAT, sizeof (drawpoint), myWonderfulPoints[0].position);
        glColorPointer (4, GL_UNSIGNED_BYTE, sizeof (drawpoint), myWonderfulPoints[0].color);
     
        glDrawArrays (GL_POINTS, 0, myWonderfulPoints.size ());
     
        glDisableClientState (GL_VERTEX_ARRAY);
        glDisableClientState (GL_COLOR_ARRAY);
    }

    If you have the kind of gfx hardware that I think you have, display lists are unlikely to give good performance. Plus there is the overhead of having to destroy and recreate the display list every time your points list needs to change, which, even if I'm wrong, will murder your performance.

    Is it more efficient to check and exclude off screen points from the VertexArray or just add them all?

    Also, as this program has a zoom, when zoomed out a lot of the points may overlap due to lack of pixels. Is it more efficient to check and only include points that are far enough appart to be unique on screen or should I just add every single point regardless of overlaps?
    It's likely going to be cheaper to just submit everything and let the GPU and/or driver deal with offscreen/overlap cases ("hang 'em all and let God sort 'em out", if you will) than to do potentially expensive CPU-side checks and potentially expensive point list rebuilding. The exception would be if you were doing some really expensive fragment shader ops on your points, which - given that you have OpenGL 1.4 - I doubt. You would also do these tests yourself if you had geometry that was more complex than points.

    Also, and if my first guess is correct, you most likely have software T&L which means that you'd be doing this bunch of work on the CPU only for the driver to have to come along and do the exact same bunch of work (also on the CPU) itself later on. Again, there would be an exception for much more complex geometry, but for points I wouldn't bother.

    (One other exception - if you have a bunch of points that you know ahead of time are going to be in close proximity then there is value in doing an offscreen test on the bounds of that bunch. If you don't have this info - "hang 'em all".)

  3. #23
    Junior Member Newbie
    Join Date
    Jun 2012
    Posts
    16
    Quote Originally Posted by mhagain View Post
    This code should work as a non-VBO alternative:
    Code :
    // your point struct might look something like this
    struct drawpoint
    {
        float position[3];
        unsigned char color[4];
    };
     
    // using a vector here; just change it to whatever container type you prefer
    std::vector<drawpoint> myWonderfulPoints;
     
    // call this every frame to draw stuff!
    void DrawMeSomePoints (void)
    {
        glEnableClientState (GL_VERTEX_ARRAY);
        glEnableClientState (GL_COLOR_ARRAY);
     
        glVertexPointer (3, GL_FLOAT, sizeof (drawpoint), myWonderfulPoints[0].position);
        glColorPointer (4, GL_UNSIGNED_BYTE, sizeof (drawpoint), myWonderfulPoints[0].color);
     
        glDrawArrays (GL_POINTS, 0, myWonderfulPoints.size ());
     
        glDisableClientState (GL_VERTEX_ARRAY);
        glDisableClientState (GL_COLOR_ARRAY);
    }
    I have divided my points into multiple deques (for orginization purposes), originally I was just going to use memcpy to add them all to the same array each frame and draw that... Is it better to put copy the point's pointers from multiple deques into one array or just to call
    Code :
         glVertexPointer (3, GL_FLOAT, sizeof (drawpoint), myWonderfulPoints[0].position);
        glColorPointer (4, GL_UNSIGNED_BYTE, sizeof (drawpoint), myWonderfulPoints[0].color);
     
        glDrawArrays (GL_POINTS, 0, myWonderfulPoints.size ());
    multiple times?
    Quote Originally Posted by mhagain View Post
    If you have the kind of gfx hardware that I think you have, display lists are unlikely to give good performance. Plus there is the overhead of having to destroy and recreate the display list every time your points list needs to change, which, even if I'm wrong, will murder your performance.
    Whats the best alternative? (The grid consists of lines, and points. The points in the grid are smaller than the points I'm tracking so I cant just draw them with the other points.)
    - Should I just use immediates?
    - Should I create and draw three more VertexArrays? (one will remain static (lines), the other two will update on zoom.(lines and points))
    - or is there another draw method that is good for static/rarely updating vertices?
    Last edited by Beiufin; 06-28-2012 at 06:24 AM.

Posting Permissions

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