r/oculusdev • • Mar 01 '20

Oculus Opengl 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) in a 640X320 resolution. 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 rendering 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):
static void ReadPixels(void* data, int textureWidth, int textureHeight)
{
int currentFBORead;
int currentFBOWrite;

glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &currentFBORead);
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &currentFBOWrite);

glBindFramebuffer(GL_READ_FRAMEBUFFER, currentFBOWrite);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, textureWidth, textureHeight, GL_RGBA, GL_UNSIGNED_BYTE, data);

glBindFramebuffer(GL_READ_FRAMEBUFFER, currentFBORead);

So I set a rendertexture active and in a camera 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? How can I get a "Screenshot"?

6 Upvotes

2 comments sorted by

1

u/durrandi Mar 02 '20

From what I understand about the Quest/Go, they are tile based GPUs. The output isn't a singular texture like you may be used to. I'm not sure if it's possible within the confines of Unity to do this efficiently. Can you get away with using the Cast feature built into quest/go to get your byte array on the recipient device?

1

u/AdiXRHealth Mar 03 '20

I'm afraid not. Is there is a way to get access to the buildin casting feature on the quest? Maybe getting the info from them? I looked into it but i couldn't find a way...