I am developing a program in C ++ / OpenGL that paints the landscape of the whole world. I have a base of heights of heights stored as tiles. Each time I run the program, the tile loads. Then, when a person moves, another tile should be loaded, this does not happen every frame, maybe once every 5 minutes.
I load the source plate into the memory of the video card:
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 cannot calculate the vertex + color + normal + another texture of the same frame, since it takes about 20 seconds to create the tile.
So, I decided to create a bootloader thread that will check when it will be necessary to load a new plate, and then load it. When everything is done, you just need to change the VBO (hence [idx].
So, for the bootloader thread, I know that I need a second OpenGL context, I created it, and I share the lists between them. The idea works, but in the bootloader thread, when I send new VBO data, I need this function: wglMakeCurrent
Only when all the data has been loaded can I set the context to the render stream (main program stream). This does not lead to the fact that nothing is done for this period of time, which makes the program useless.
Do you have any ideas for a solution? Do I need to change the concept?
I am using OpenGL 2.1. Will upgrading to OpenGL 3 solve the problem?