multithreading - shared context with GLUT on Linux -


in current setup, have 2 displays being driven 2 gpus. using glut, create 2 windows (one per display) , render each 1 main thread calling glutsetwindow() in draw call, each window.

the draw calls renders texture2d sphere (using glusphere()) texture2d swapped image every few seconds. have set array of 2 texture2d can load next image while current texture2d shown. works long runs in main thread.

the problem call glteximage2d(), load next image, hangs draw call, need call glteximage2d() on different thread. calling glteximage2d() on different thread crashes, seems opengl context not shared. glut not seem provide way share context, should able context on linux via glxgetcurrentcontext().

my question if context via call, how can make shared context? , work glut? option has been switch different library replace glut, glfw in case loose handy function such glusphere(). recommendation if context cannot shared glut please?

with glx context sharing established @ context creation; unlike wgl can't establish sharing afterthought. since glut doesn't have context sharing feature (freeglut may have one, i'm not sure that) not going straightforward.

i have 2 displays being driven 2 gpus.

unless gpus sli-ed or crossfire-ed can't establish context sharing between them.

the problem call glteximage2d(), load next image, hangs draw call, need call glteximage2d() on different thread.

if images of same size, use gltexsubimage2d replace it. image data can loaded asynchronously using pixel buffer objects, using secondary thread doesn't need opengl context!

outlining steps:

in opengl context thread:

initiating transfer

  • glbindbuffer(gl_pixel_unpack_buffer, pboid)
  • void *p = glmapbuffer(gl_pixel_unpack_buffer, gl_write_only);
  • signal transfer thread
  • continue normal drawing operations

in transfer thread

on signal start transfer

  • copy data mapped buffer
  • signal opengl context thread

in opengl context thread:

on signal complete transfer

  • glunmapbuffer
  • gltex[sub]image
  • sync = glfencesync
  • keep on drawing old texture

on further iterations of drawing loop

  • poll sync glclientwaitsync using timeout of 0
  • if wait sync returns signalled switch new texture , delete old one
  • else keep on drawing old texture

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -