Login  Register

Re: Multithreading

Posted by Wade Walker on Jan 09, 2011; 5:00pm
URL: https://forum.jogamp.org/Multithreading-tp2221001p2222020.html

Here's some more detail. You'll still need more code to coordinate between the threads.

I'd strongly suggest getting this working in a single thread first, then trying to move the buffer fill to a second thread

I don't think the ByteBuffer is really memory on the graphics card. I believe it's in system memory, and is copied to the graphics card with a DMA when you call glUnmapBuffer().

main thread:
    gl.glGenBuffers( 1, aiVertexBufferIndices, 0 );

    // create vertex buffer data store without initial copy
    gl.glBindBuffer( GL.GL_ARRAY_BUFFER, aiVertexBufferIndices[0] );
    gl.glBufferData( GL.GL_ARRAY_BUFFER,
                             aiNumOfVertices[0] * 3 * Buffers.SIZEOF_FLOAT * 2,
                             null,
                             GL2.GL_DYNAMIC_DRAW );

    // map the buffer and write vertex and color data directly into it
    gl.glBindBuffer( GL.GL_ARRAY_BUFFER, aiVertexBufferIndices[0] );
    ByteBuffer bytebuffer = gl.glMapBuffer( GL.GL_ARRAY_BUFFER, GL2.GL_WRITE_ONLY );
    FloatBuffer floatbuffer = bytebuffer.order( ByteOrder.nativeOrder() ).asFloatBuffer();

secondary thread:
    // fill the buffer
    for( ... )
        floatbuffer.put( your data );

main thread:
    gl.glUnmapBuffer( GL.GL_ARRAY_BUFFER );