Results 1 to 3 of 3

Thread: OpenGL VBO within multiple threads

  1. #1
    Junior Member Newbie
    Join Date
    May 2010
    Posts
    6

    OpenGL VBO within multiple threads

    I am developing a program in C++/OpenGL which draws terrain of the entire world. I have a database of altitude heights stored as tiles. Every time I start the program, a tile is loaded. Then as the person moves, another tile should load, this does not happen every frame, maybe once every 5 minutes.

    I load the initial tile in the video card's memory:

    glBindBufferARB(GL_ARRAY_BUFFER_ARB, VertexBuffer[idx]);
    glBufferDataARB(GL_ARRAY_BUFFER_ARB, VBOsz * 3 * sizeof(float), tile_data, GL_STATIC_DRAW_ARB);

    ...There are normals, color and index buffers

    And I draw them:

    glBindBufferARB(GL_ARRAY_BUFFER_ARB, VertexBuffer[idx]);
    glBufferDataARB(GL_ARRAY_BUFFER_ARB, VBOsz * 3 * sizeof(float), tile_data, GL_STATIC_DRAW_ARB);


    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);

    glBindBufferARB(GL_ARRAY_BUFFER_ARB, VertexBuffer[idx]);
    glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));

    ...

    glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, IndexBuffer[idx]);
    glDrawElements(GL_TRIANGLES, IndexBuffersz, GL_UNSIGNED_INT, BUFFER_OFFSET(0));

    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);

    Since I want the program to be as smooth as possible, I can't calculate the vertex+color+normal+ other textures the same frame, as it takes about 20 seconds to create a tile.

    So I decided to make a loader thread that would check for when a new tile needs to be loaded and then load it. When it would be all done, it should just swap the VBO(hence the [idx].

    So for a loader thread, I know that I need a second OpenGL context, I created one and I share the lists between them. The idea is working, but in the loader thread, when I send the new VBO data, I need this function: wglMakeCurrent

    Only when all the data has been loaded, I can set the context to the rendering thread(main program's thread). This causes nothing to be drawn for that amount of time, which makes the program useless.

    Do you have any ideas on a solution? Do I need to change the concept?

    I am using OpenGL 2.1. Will upgrading to OpenGL 3 solve the problem?

    Thank you for your help in advance.

  2. #2
    Senior Member Regular Contributor Rosario Leonardi's Avatar
    Join Date
    Aug 2008
    Location
    Italy
    Posts
    356

    Re: OpenGL VBO within multiple threads

    If you have two context that share the buffers you don't need to call make current more than once per-thread.
    Each thread will work on its context. You only need to signal to the drawing thread when the tile is loaded.
    ~ ~ I tell you, realtime 3D is made of blood, sweat and screams! ~ ~

  3. #3
    V-man
    Guest

    Re: OpenGL VBO within multiple threads

    You could also stick to the 1 context method. From your GL context, call glMapBuffer and it returns a pointer. Give the pointer to your second thread and fill the buffer with your vertices. When you are finished, just send a signal to your first thread and glUnmapBuffer the buffer and you can render from it.

Similar Threads

  1. OpenGL ES calls across multiple threads
    By hbar in forum OpenGL ES
    Replies: 6
    Last Post: 01-15-2009, 04:54 AM
  2. OpenGL calls across multiple threads
    By hbar in forum OpenGL: Linux
    Replies: 1
    Last Post: 11-07-2008, 03:37 AM
  3. OpenGL and multiple threads
    By def in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 03-30-2004, 05:23 AM
  4. using OpenGL in multiple threads
    By Rob Lemmens in forum OpenGL: Advanced Coding
    Replies: 11
    Last Post: 09-26-2002, 11:29 AM
  5. 0n multiple glut/opengl windows in multiple threads
    By kaas in forum OpenGL: Advanced Coding
    Replies: 11
    Last Post: 05-30-2002, 01:55 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
  •  
Proudly hosted by Digital Ocean