ValveSoftware / openvr

OpenVR SDK
http://steamvr.com
BSD 3-Clause "New" or "Revised" License
6.12k stars 1.28k forks source link

Overlay flickers and dissapears #741

Closed bholcomb closed 6 years ago

bholcomb commented 6 years ago

I'm using the C# API and I've integrated openVR (v1.0.12) into my openGL rendering engine without any issues except overlays fail to display (mostly). When I submit an overlay to be displayed, it flickers in my view for a few frames then dissapears. If I pause rendering in my app (such as hitting a debug breakpoint for example) the view fades to the gray grid and my overlay is visible. I don't get any errors returned from any functions and when the overlay is visible in the grey grid loading screen, it behaves properly with respect to being absolute or relative to the HMD and located where my transform says it should be.

I've attached my overlay.cs source that shows creation and submitting of the overlay. My project is on github if you need a working example (should build and run without much setup once downloaded).

Any suggestions for how to begin debugging this would be appreciated.

cheers,

Bob

overlay.cs.txt

bholcomb commented 6 years ago

Please close this issue, it turns out there were a few things wrong, mostly on my side of the fence:

  1. OpenGL textures submitted as overlays need to have an Alpha Channel. I found that GL_RGBA8 textures were visible, but GL_RGB8 textures were not. Can you please add a list of the acceptable texture formats to the wiki. I also found that GL_RGBA32 did not work for overlays, but does for eye textures.

  2. While debugging this, I was calling SetOverlayFromFile every frame in my overlay submit function. This was causing the flicker and disappearing overlay. While this is really bad for performance, I would expect this to not to stop working. I know this is a stupid use case but might be worth a bug.

  3. I had an order operations error outside of openVR that invalidated the texture I was using. Apparently you need to submit overlay textures that actually have data in them. There was a window resize event is triggered on startup that would call a function to recreate my framebuffer targets (my UI being one of the targets). I needed to update the overlay object to use the new texture.

Not related, but may be a problem elsewhere:

  1. I noticed that the C# strings are being passed to the OpenVR functions without any marshalling hints. I'm pretty sure this passes them as Unicode (16 bit characters) unless you use MarshalAs(UnmanagedType.LPWStr) to get ANSI (8 bit characters). I didn't see this break anything, but probably should be looked into.

cheers,

Bob