sensics / OSVR-RenderManager

Apache License 2.0
63 stars 45 forks source link

RenderManagerOpenGL::PresentEye after use program: OpenGL error GL_INVALID_OPERATION) #223

Open phr00t opened 7 years ago

phr00t commented 7 years ago

Working on jMonkeyVR integration. I'm trying to reduce as many variables as possible in resolving the issue in the title: using a "test tracker" plugin which is a dummy headset (provided by OSVR, thank you), no timewarp & extended mode. I'm using the OpenGL Render Manager in my application, which does attempt to share an OpenGL context. The OSVR OpenGL Render Manager is opened first, and then the LWJGL context is opened. The scene renders fine to my buffers & I copy the buffer to the main display for verification, I also try and present those buffers to the OpenGL Render Manager. I get this error when trying to do so:

Sept 13 11:06:33.626 warning [RenderManager]: RenderManagerOpenGL::PresentEye after use program: OpenGL error GL_INVALID_OPERATION) Sept 13 11:06:33.626 error [RenderManager]: RenderManager::PresentRenderBuffers(): PresentEye failed.

os-ver.txt is v0.6-1328-g3a449d7

Any help would be greatly appreciated!

JeroMiya commented 7 years ago

Does LWJGL have a way of setting the current opengl context to itself? If so, you'll need to do so after opening the display and after presenting your render targets, before making GL calls for your own context.

Our shared OpenGL context examples, such as they are (they only work for sharing among SDL-created contexts), do this: https://github.com/sensics/OSVR-RenderManager/blob/master/examples/RenderManagerOpenGLSharedContextPresentExample.cpp#L364

phr00t commented 7 years ago

LWJGL 3 uses GLFW, and this looks like the magic sauce:

http://www.glfw.org/docs/latest/group__context.html#ga1c04dc242268f827290fe40aa1c91157

I'll experiment with it...

JeroMiya commented 7 years ago

Note: you will need to also wglShareLists on the two contexts to actually enable texture sharing. It doesn't look like GLFW supports sharing with non-GLFW windows: http://www.glfw.org/docs/latest/context_guide.html#context_sharing

However, you may be able to call wglGetCurrentContext after you create your GLFW window, and again after you call OpenDisplay, and then wglShareLists to setup resource sharing. You'll need to call wglShareLists before creating your render targets in the GLFW context.

phr00t commented 7 years ago

Making progress! Apparently the context numbers returned from GLFW are not the same context numbers from WGL calls, so I get both sets. The WGLShareList call returns success! I commited the changes to jMonkeyVR. The context stuff can be seen here:

https://github.com/phr00t/jMonkeyVR/blob/master/src/jmevr/input/OSVR.java#L123

However, the OpenGL Render Manager now returns this error:

Sept 13 16:43:38.376 error [RenderManager]: RenderManager::PresentRenderBuffers: Given 2 eyes, but only 1 buffers

... which is kinda what I want, because I'm doing single-pass rendering & the single buffer contains both eyes. What gives?

JeroMiya commented 7 years ago

How many times is your code calling osvrRenderManagerPresentRenderBufferOpenGL before calling osvrRenderManagerFinishPresentRenderBuffers? I would expect two calls. Each call to osvrRenderManagerPresentRenderBufferOpenGL should add a buffer to the list that gets passed down into the internal Present call.

russell-taylor commented 7 years ago

It is okay if the same buffer is passed twice, with two different viewports.

phr00t commented 7 years ago

That was it, @JeroMiya -- I was calling "start" & "finish" present for each eye, when I should start, present both & then finish. No more errors! Not getting desired results, though... the Render Manager went from white to black & my primary mirror display became oddly rotated... I took a screenshot here:

http://i.imgur.com/T0GSSmT.png

I have to use default camera projection, because something gets funky when I try using the OSVR-provided projection (another support topic for another day).

phr00t commented 7 years ago

It appears as if the Render Manager is getting the buffer & is flipping it (perhaps to adjust it for headset display), but it just isn't presenting it within the Render Manager -- but instead my GLFW "primary mirror" window. I've tried setting the context to the Render Manager during the present phase, but that doesn't seem to help... if I don't create my own window, the Render Manager still remains black. Here is the present section of jMonkeyVR:

https://github.com/phr00t/jMonkeyVR/blob/master/src/jmevr/input/OSVR.java#L68

No errors are reported to syserr, nor do I see errors in the osvr_server output. Here are some structures that are being passed to the present calls:

eyeLeftInfo = (osvrrendermanageropengl.OSVR_RenderInfoOpenGL$ByValue) OSVR_RenderInfoOpenGL$ByValue(auto-allocated@0x206f3ca0 (88 bytes)) {
  OSVR_GraphicsLibraryOpenGL library@0=OSVR_GraphicsLibraryOpenGL(allocated@0x206f3ca0 (8 bytes) (shared from auto-allocated@0x206f3ca0 (88 bytes))) {
    OSVR_OpenGLToolkitFunctions$ByReference toolkit@0=null
  }
  OSVR_ViewportDescription viewport@8=OSVR_ViewportDescription(allocated@0x206f3ca8 (32 bytes) (shared from auto-allocated@0x206f3ca0 (88 bytes))) {
    double left@0=0.0
    double lower@8=0.0
    double width@10=1920.0
    double height@18=2160.0
  }
  OSVR_ProjectionMatrix projection@28=OSVR_ProjectionMatrix(allocated@0x206f3cc8 (48 bytes) (shared from auto-allocated@0x206f3ca0 (88 bytes))) {
    double left@0=0.0315
    double right@8=0.0
    double top@10=0.0
    double bottom@18=1.0
    double nearClip@20=0.0
    double farClip@28=0.0
  }
}

leftView = (osvrrendermanageropengl.OSVR_ViewportDescription$ByValue) OSVR_ViewportDescription$ByValue(auto-allocated@0x3be5da60 (32 bytes)) {
  double left@0=0.0
  double lower@8=0.0
  double width@10=0.5
  double height@18=1.0
}

EDIT: I'll add that I don't use the projection information to configure the cameras, because it doesn't work right. Those structures are passed to the present functions, though... so I tried setting the nearClip/farClip values to something sane, and it didn't appear to help. However, it looks like something IS being rendered, just not to the Render Manager as described above.

phr00t commented 7 years ago

Progress! I have it displaying on the OSVR Render Manager, although my main mirror window is black.. however, that is acceptable. I was able to have something display on the main mirror window, but it caused a nasty black flicker on the Render Manager.

It required some juggling of the contexts:

https://github.com/phr00t/jMonkeyVR/commit/f21ed07598667265f08ca8144df96f48aaf48698

This is just with the "null" driver & no HDK attached though.. I'll be trying that next.

russell-taylor commented 4 years ago

@phr00t Did you get this working? Should this issue still be open? Thanks!