Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
adi.gonen.14's avatar
adi.gonen.14
Honored Guest
5 years ago

Unity Oculus Quest GLES help

TL;DR How can I read from the eye buffer on Oculus Quest/Go to a byte array without a rendertexture using OpenGL?

Hi, i'm tring to cast the VR view to an external app. To do that I need to send a byte array of each frame (at about 10 fps). After finding out that Oculus Quest and Go don't support AsyncGPUReadback the go to answer was to attach a rendertexture to a camera-> set it as the active rendertexture -> render to it-> do Texture2d.ReadPixels to a 2d texture-> Texture2d.apply->Texture2d.GetRawData.
While the method works it caused a few issues: some performance issues that were mostly acceptable, and a jittering in close moving objects (such as the controller objects or our gameplay object). The jittring make it a very unpleasant to play . We Know the jittring is connected to rendring to rendertexture, since we used to have that very problem when a wayward ForceIntoRT was left checked.
I tired to find any way to do it in Unity, but nothing worked. And so I turned to OpenGL. which I know nothing about. After lots of hours online and some banging the head against the wall, I managed to find a very partial not-solution (I'm using IUnityInterface and IUnityGraphics):

  1. static void ReadPixels(void* data, int textureWidth, int textureHeight)
  2. {
  3.     int currentFBORead;
  4.     int currentFBOWrite;
  5.  
  6.     glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &currentFBORead);
  7.     glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &currentFBOWrite);
  8.  
  9.     glBindFramebuffer(GL_READ_FRAMEBUFFER, currentFBOWrite);
  10.     glPixelStorei(GL_PACK_ALIGNMENT, 1);
  11.     glReadPixels(0, 0, textureWidth, textureHeight, GL_RGBA, GL_UNSIGNED_BYTE, data);
  12.  
  13.     glBindFramebuffer(GL_READ_FRAMEBUFFER, currentFBORead);
  14. }

So I set a rendertexture active and in a camera, then I render to it and my ReadPixels turn it to a byte array. No need to read into a Texture2D, apply it and read the raw data. Yay.
But no matter what I do, I can't seem to find a way to read directly from the eye buffer (any eye) or screen or the scene camera. I combed through the OVRPlugin in attempt to see if there is any chance Oculus can throw me a bone (or a buffer to read from), nothing.
So a go to you guys. I'm a total noob in OpenGL, and i'm at it for few weeks. How can I read the eye buffer to a byte array without a rendertexture?
Replies have been turned off for this discussion