Skip to content

Commit ae61044

Browse files
committed
Don't use GL_DEPTH_STENCIL_ATTACHMENT on depth buffer from WebXR
1 parent e0603ae commit ae61044

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

drivers/gles3/storage/render_scene_buffers_gles3.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ RenderSceneBuffersGLES3::~RenderSceneBuffersGLES3() {
5858
free_render_buffer_data();
5959
}
6060

61-
void RenderSceneBuffersGLES3::_rt_attach_textures(GLuint p_color, GLuint p_depth, GLsizei p_samples, uint32_t p_view_count) {
61+
void RenderSceneBuffersGLES3::_rt_attach_textures(GLuint p_color, GLuint p_depth, GLsizei p_samples, uint32_t p_view_count, bool p_depth_has_stencil) {
6262
if (p_view_count > 1) {
6363
if (p_samples > 1) {
6464
#if defined(ANDROID_ENABLED) || defined(WEB_ENABLED)
6565
glFramebufferTextureMultisampleMultiviewOVR(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, p_color, 0, p_samples, 0, p_view_count);
66-
glFramebufferTextureMultisampleMultiviewOVR(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, p_depth, 0, p_samples, 0, p_view_count);
66+
glFramebufferTextureMultisampleMultiviewOVR(GL_FRAMEBUFFER, p_depth_has_stencil ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT, p_depth, 0, p_samples, 0, p_view_count);
6767
#else
6868
ERR_PRINT_ONCE("Multiview MSAA isn't supported on this platform.");
6969
#endif
7070
} else {
7171
#ifndef IOS_ENABLED
7272
glFramebufferTextureMultiviewOVR(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, p_color, 0, 0, p_view_count);
73-
glFramebufferTextureMultiviewOVR(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, p_depth, 0, 0, p_view_count);
73+
glFramebufferTextureMultiviewOVR(GL_FRAMEBUFFER, p_depth_has_stencil ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT, p_depth, 0, 0, p_view_count);
7474
#else
7575
ERR_PRINT_ONCE("Multiview isn't supported on this platform.");
7676
#endif
@@ -79,13 +79,13 @@ void RenderSceneBuffersGLES3::_rt_attach_textures(GLuint p_color, GLuint p_depth
7979
if (p_samples > 1) {
8080
#ifdef ANDROID_ENABLED
8181
glFramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, p_color, 0, p_samples);
82-
glFramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, p_depth, 0, p_samples);
82+
glFramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, p_depth_has_stencil ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, p_depth, 0, p_samples);
8383
#else
8484
ERR_PRINT_ONCE("MSAA via EXT_multisampled_render_to_texture isn't supported on this platform.");
8585
#endif
8686
} else {
8787
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, p_color, 0);
88-
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, p_depth, 0);
88+
glFramebufferTexture2D(GL_FRAMEBUFFER, p_depth_has_stencil ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, p_depth, 0);
8989
}
9090
}
9191
}
@@ -107,7 +107,7 @@ GLuint RenderSceneBuffersGLES3::_rt_get_cached_fbo(GLuint p_color, GLuint p_dept
107107
glGenFramebuffers(1, &new_fbo.fbo);
108108
glBindFramebuffer(GL_FRAMEBUFFER, new_fbo.fbo);
109109

110-
_rt_attach_textures(p_color, p_depth, p_samples, p_view_count);
110+
_rt_attach_textures(p_color, p_depth, p_samples, p_view_count, true);
111111

112112
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
113113
if (status != GL_FRAMEBUFFER_COMPLETE) {
@@ -383,7 +383,7 @@ void RenderSceneBuffersGLES3::_check_render_buffers() {
383383
glGenFramebuffers(1, &msaa3d.fbo);
384384
glBindFramebuffer(GL_FRAMEBUFFER, msaa3d.fbo);
385385

386-
_rt_attach_textures(internal3d.color, internal3d.depth, msaa3d.samples, view_count);
386+
_rt_attach_textures(internal3d.color, internal3d.depth, msaa3d.samples, view_count, true);
387387

388388
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
389389
if (status != GL_FRAMEBUFFER_COMPLETE) {
@@ -662,9 +662,10 @@ GLuint RenderSceneBuffersGLES3::get_render_fbo() {
662662
if (texture_storage->render_target_is_reattach_textures(render_target)) {
663663
GLuint color = texture_storage->render_target_get_color(render_target);
664664
GLuint depth = texture_storage->render_target_get_depth(render_target);
665+
bool depth_has_stencil = texture_storage->render_target_get_depth_has_stencil(render_target);
665666

666667
glBindFramebuffer(GL_FRAMEBUFFER, rt_fbo);
667-
_rt_attach_textures(color, depth, msaa3d.samples, view_count);
668+
_rt_attach_textures(color, depth, msaa3d.samples, view_count, depth_has_stencil);
668669
glBindFramebuffer(GL_FRAMEBUFFER, texture_storage->system_fbo);
669670
}
670671

drivers/gles3/storage/render_scene_buffers_gles3.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class RenderSceneBuffersGLES3 : public RenderSceneBuffers {
9393
void _clear_back_buffers();
9494
void _clear_glow_buffers();
9595

96-
void _rt_attach_textures(GLuint p_color, GLuint p_depth, GLsizei p_samples, uint32_t p_view_count);
96+
void _rt_attach_textures(GLuint p_color, GLuint p_depth, GLsizei p_samples, uint32_t p_view_count, bool p_depth_has_stencil);
9797
GLuint _rt_get_cached_fbo(GLuint p_color, GLuint p_depth, GLsizei p_samples, uint32_t p_view_count);
9898

9999
public:

drivers/gles3/storage/texture_storage.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,6 +2854,13 @@ GLuint TextureStorage::render_target_get_depth(RID p_render_target) const {
28542854
}
28552855
}
28562856

2857+
bool TextureStorage::render_target_get_depth_has_stencil(RID p_render_target) const {
2858+
RenderTarget *rt = render_target_owner.get_or_null(p_render_target);
2859+
ERR_FAIL_NULL_V(rt, 0);
2860+
2861+
return rt->depth_has_stencil;
2862+
}
2863+
28572864
void TextureStorage::render_target_set_reattach_textures(RID p_render_target, bool p_reattach_textures) const {
28582865
RenderTarget *rt = render_target_owner.get_or_null(p_render_target);
28592866
ERR_FAIL_NULL(rt);

drivers/gles3/storage/texture_storage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ class TextureStorage : public RendererTextureStorage {
669669
GLuint render_target_get_fbo(RID p_render_target) const;
670670
GLuint render_target_get_color(RID p_render_target) const;
671671
GLuint render_target_get_depth(RID p_render_target) const;
672+
bool render_target_get_depth_has_stencil(RID p_render_target) const;
672673
void render_target_set_reattach_textures(RID p_render_target, bool p_reattach_textures) const;
673674
bool render_target_is_reattach_textures(RID p_render_target) const;
674675

0 commit comments

Comments
 (0)