diff options
author | clayjohn <claynjohn@gmail.com> | 2019-11-23 18:08:19 -0800 |
---|---|---|
committer | clayjohn <claynjohn@gmail.com> | 2019-11-23 18:08:19 -0800 |
commit | 5ab3b6152025a6ab83b30181bbb04e452d7da9f5 (patch) | |
tree | 6b3a7d3c0b494117c85ee1f1fc71849f04b1730d /drivers | |
parent | bb1d75f55e1dc15eaa2ea550fc30aeaa5c2e3783 (diff) |
Restructure depth_internalformat code to work on mobile
This changes the code path so that `glRenderBufferStorage*` always uses
values appropriate for renderbuffers and `glTexImage2D` never uses an
internalformat meant for buffers.
Fixes #33825.
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gles2/rasterizer_storage_gles2.cpp | 28 | ||||
-rw-r--r-- | drivers/gles2/rasterizer_storage_gles2.h | 1 |
2 files changed, 18 insertions, 11 deletions
diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index 4e5eef2bd2..15b2193cbe 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -4657,7 +4657,7 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) { glGenRenderbuffers(1, &rt->depth); glBindRenderbuffer(GL_RENDERBUFFER, rt->depth); - glRenderbufferStorage(GL_RENDERBUFFER, config.depth_internalformat, rt->width, rt->height); + glRenderbufferStorage(GL_RENDERBUFFER, config.depth_buffer_internalformat, rt->width, rt->height); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->depth); } @@ -4725,7 +4725,7 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) { glGenRenderbuffers(1, &rt->multisample_depth); glBindRenderbuffer(GL_RENDERBUFFER, rt->multisample_depth); - glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, config.depth_internalformat, rt->width, rt->height); + glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, config.depth_buffer_internalformat, rt->width, rt->height); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->multisample_depth); @@ -5189,7 +5189,7 @@ void RasterizerStorageGLES2::render_target_set_external_texture(RID p_render_tar // create a multisample depth buffer, we're not reusing Godots because Godot's didn't get created.. glGenRenderbuffers(1, &rt->external.depth); glBindRenderbuffer(GL_RENDERBUFFER, rt->external.depth); - glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, config.depth_internalformat, rt->width, rt->height); + glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, config.depth_buffer_internalformat, rt->width, rt->height); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->external.depth); } @@ -5302,7 +5302,7 @@ RID RasterizerStorageGLES2::canvas_light_shadow_buffer_create(int p_width) { glGenRenderbuffers(1, &cls->depth); glBindRenderbuffer(GL_RENDERBUFFER, cls->depth); - glRenderbufferStorage(GL_RENDERBUFFER, config.depth_internalformat, cls->size, cls->height); + glRenderbufferStorage(GL_RENDERBUFFER, config.depth_buffer_internalformat, cls->size, cls->height); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, cls->depth); glGenTextures(1, &cls->distance); @@ -5783,6 +5783,8 @@ void RasterizerStorageGLES2::initialize() { config.keep_original_textures = false; config.shrink_textures_x2 = false; + config.depth_internalformat = GL_DEPTH_COMPONENT; + config.depth_type = GL_UNSIGNED_INT; #ifdef GLES_OVER_GL config.float_texture_supported = true; @@ -5790,20 +5792,20 @@ void RasterizerStorageGLES2::initialize() { config.pvrtc_supported = false; config.etc1_supported = false; config.support_npot_repeat_mipmap = true; - config.depth_internalformat = GL_DEPTH_COMPONENT; - config.depth_type = GL_UNSIGNED_INT; + config.depth_buffer_internalformat = GL_DEPTH_COMPONENT24; #else config.float_texture_supported = config.extensions.has("GL_ARB_texture_float") || config.extensions.has("GL_OES_texture_float"); config.s3tc_supported = config.extensions.has("GL_EXT_texture_compression_s3tc") || config.extensions.has("WEBGL_compressed_texture_s3tc"); config.etc1_supported = config.extensions.has("GL_OES_compressed_ETC1_RGB8_texture") || config.extensions.has("WEBGL_compressed_texture_etc1"); config.pvrtc_supported = config.extensions.has("IMG_texture_compression_pvrtc") || config.extensions.has("WEBGL_compressed_texture_pvrtc"); config.support_npot_repeat_mipmap = config.extensions.has("GL_OES_texture_npot"); - // on mobile check for 24 bit depth support + + // on mobile check for 24 bit depth support for RenderBufferStorage if (config.extensions.has("GL_OES_depth24")) { - config.depth_internalformat = _DEPTH_COMPONENT24_OES; + config.depth_buffer_internalformat = _DEPTH_COMPONENT24_OES; config.depth_type = GL_UNSIGNED_INT; } else { - config.depth_internalformat = GL_DEPTH_COMPONENT16; + config.depth_buffer_internalformat = GL_DEPTH_COMPONENT16; config.depth_type = GL_UNSIGNED_SHORT; } #endif @@ -5901,8 +5903,12 @@ void RasterizerStorageGLES2::initialize() { if (status != GL_FRAMEBUFFER_COMPLETE) { // If it fails, test to see if it supports a framebuffer texture using UNSIGNED_SHORT // This is needed because many OSX devices don't support either UNSIGNED_INT or UNSIGNED_SHORT - +#ifdef GLES_OVER_GL config.depth_internalformat = GL_DEPTH_COMPONENT16; +#else + // OES_depth_texture extension only specifies GL_DEPTH_COMPONENT. + config.depth_internalformat = GL_DEPTH_COMPONENT; +#endif config.depth_type = GL_UNSIGNED_SHORT; glGenFramebuffers(1, &fbo); @@ -5910,7 +5916,7 @@ void RasterizerStorageGLES2::initialize() { glGenTextures(1, &depth); glBindTexture(GL_TEXTURE_2D, depth); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, 32, 32, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, config.depth_internalformat, 32, 32, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h index 6de530d8c3..daf6b93afc 100644 --- a/drivers/gles2/rasterizer_storage_gles2.h +++ b/drivers/gles2/rasterizer_storage_gles2.h @@ -99,6 +99,7 @@ public: GLuint depth_internalformat; GLuint depth_type; + GLuint depth_buffer_internalformat; } config; |