cancel
Showing results for 
Search instead for 
Did you mean: 

[OXR ]Meta Quest 2 : use stencil buffer with OpenXR SDK in hello_xr base application - SOLVED

antoine.emerit
Explorer

Hi,

To add "real mirrors" and "portals" to my Meta Quest 2 application, I need to use stencil buffer masking; however, the stencil OpenGL ES functions (glEnable(GL_STENCIL_TEST); glStencilFunc(GL_ALWAYS, 1, 0xff); ...) have no effect.

  • Desktop platform : Debian/GNU/Linux Bookworm
  • Developement IDE : Android Studio Flamingo 2022.2.1
  • VR platform : Meta Quest 2 v 57.0.0
  • SDK : OpenXR SDK Source 1.0.27 + ovr_openxr_mobile_sdk 54.0

After digging in the hello_xr, I've found the problem and add a solution :

  • in src/tests/hello_xr/graphicsplugin_opengles.cpp, the function GetDepthTexture(...) create an texture as the depth buffer and this can't manage a stencil buffer; it must create a renderbuffer to support stencil.

Here is my working patch :

antoine@pcantoine:~/AndroidStudioProjects/Bille2_VR$ diff  ~/Téléchargements/OpenXR-SDK-Source-release-1.0.27/src/tests/hello_xr/graphicsplugin_opengles.cpp  OpenXR-SDK-Source-release-1.0.27/src/tests/hello_xr/graphicsplugin_opengles.cpp 
263,269c267,269
<         glGenTextures(1, &depthTexture);
<         glBindTexture(GL_TEXTURE_2D, depthTexture);
<         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
<         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
<         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
<         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
<         glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr);
---
>         glGenRenderbuffers(1, &depthTexture);
>         glBindRenderbuffer(GL_RENDERBUFFER, depthTexture);
>         glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
298c298,299
<         glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0);
---
>         glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthTexture);
>         glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthTexture);

This may help other developers.

Regards

0 REPLIES 0