10-28-2023 07:27 PM
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.
After digging in the hello_xr, I've found the problem and add a solution :
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