copy data from non OpenGL context thread

Hi,

I’m trying to upload data to my rendering engine using a simple known approach:

  1. Rendering thread maps a buffer, back buffer and draw front buffer
  2. Working thread copy data to back buffer
  3. Rendering thread after draw unmap the back buffer, swap the buffers, orphan and map again the new

This is very simple but I get weird results:

  1. First time I call glUnMapBuffer I get INVALID_OPERATION after that no errors, the buffer was mapped correctly (same buffer id and given size)
  2. The drawing is done one cycle on one cycle off, and it blinks like hell
  3. Sometimes the entire screen, not just the OpenGL windows blinks
  4. Sometime I get “lost connection to nVidia drivers”, that timeout win7 TDR thing

I’ve looked at the data, the copy, no overruns, all syncs and locks are ok, swap and load is protected, buffers are binded when mapped and unmapped

I’ve already implemented similar thing but not directly swapping the buffer but using PBO to copy to new front buffer after orphaning with rendering and working threat but this seems more correct when loading instancing data to my instance renderer

Am I missing something here, seems simple enough, is that not the way?

Any help will be appreciated
Ido

Solved,

My mistake, for future use:

  1. There are two VAO that encapsulate all buffers state
  2. Instance geometry is shared between VAO but in back buffer the geometry was not set

The weird stuff is that that the error reported by the driver is not related, INVALID_OPERATION in the unmap buffer, the output debug extension show the same error.

Ido