From 481fc679962bff05cbab2d3f3b968cca72ad06ad Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 30 Aug 2021 14:01:43 +0200 Subject: [PATCH] gles2gsg: Support gl-depth-zero-to-one in OpenGL ES 2+ Requires GL_EXT_clip_control support in the driver. --- panda/src/gles2gsg/gles2gsg.h | 2 ++ panda/src/gles2gsg/panda_esgl2ext.h | 14 ++++++++++ .../glstuff/glGraphicsStateGuardian_src.cxx | 27 ++++++++++++------- .../src/glstuff/glGraphicsStateGuardian_src.h | 4 ++- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/panda/src/gles2gsg/gles2gsg.h b/panda/src/gles2gsg/gles2gsg.h index c328c99ac4..044ac72991 100644 --- a/panda/src/gles2gsg/gles2gsg.h +++ b/panda/src/gles2gsg/gles2gsg.h @@ -120,6 +120,8 @@ typedef char GLchar; #define GL_ONE_MINUS_SRC1_COLOR GL_ONE_MINUS_SRC1_COLOR_EXT #define GL_SRC1_ALPHA GL_SRC1_ALPHA_EXT #define GL_ONE_MINUS_SRC1_ALPHA GL_ONE_MINUS_SRC1_ALPHA_EXT +#define GL_LOWER_LEFT GL_LOWER_LEFT_EXT +#define GL_ZERO_TO_ONE GL_ZERO_TO_ONE_EXT #define GL_DEBUG_OUTPUT_SYNCHRONOUS GL_DEBUG_OUTPUT_SYNCHRONOUS_KHR #define GL_DEBUG_TYPE_PERFORMANCE GL_DEBUG_TYPE_PERFORMANCE_KHR diff --git a/panda/src/gles2gsg/panda_esgl2ext.h b/panda/src/gles2gsg/panda_esgl2ext.h index 6d5258fff0..888e8e2553 100644 --- a/panda/src/gles2gsg/panda_esgl2ext.h +++ b/panda/src/gles2gsg/panda_esgl2ext.h @@ -1050,6 +1050,20 @@ GL_APICALL void GL_APIENTRY glBufferStorageEXT (GLenum target, GLsizeiptr size, #endif #endif /* GL_EXT_buffer_storage */ +#ifndef GL_EXT_clip_control +#define GL_EXT_clip_control 1 +#define GL_LOWER_LEFT_EXT 0x8CA1 +#define GL_UPPER_LEFT_EXT 0x8CA2 +#define GL_NEGATIVE_ONE_TO_ONE_EXT 0x935E +#define GL_ZERO_TO_ONE_EXT 0x935F +#define GL_CLIP_ORIGIN_EXT 0x935C +#define GL_CLIP_DEPTH_MODE_EXT 0x935D +typedef void (GL_APIENTRYP PFNGLCLIPCONTROLEXTPROC) (GLenum origin, GLenum depth); +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glClipControlEXT (GLenum origin, GLenum depth); +#endif +#endif /* GL_EXT_clip_control */ + #ifndef GL_EXT_color_buffer_float #define GL_EXT_color_buffer_float 1 #endif /* GL_EXT_color_buffer_float */ diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 4f0a30df8a..2bbeff7665 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -3293,23 +3293,30 @@ reset() { #endif // Set depth range from zero to one if requested. -#ifndef OPENGLES +#ifndef OPENGLES_1 _use_depth_zero_to_one = false; _use_remapped_depth_range = false; if (gl_depth_zero_to_one) { +#ifndef OPENGLES + PFNGLCLIPCONTROLPROC pglClipControl = nullptr; if (is_at_least_gl_version(4, 5) || has_extension("GL_ARB_clip_control")) { - PFNGLCLIPCONTROLPROC pglClipControl = - (PFNGLCLIPCONTROLPROC)get_extension_func("glClipControl"); + pglClipControl = (PFNGLCLIPCONTROLPROC)get_extension_func("glClipControl"); + } +#else + PFNGLCLIPCONTROLEXTPROC pglClipControl = nullptr; + if (has_extension("GL_EXT_clip_control")) { + pglClipControl = (PFNGLCLIPCONTROLEXTPROC)get_extension_func("glClipControlEXT"); + } +#endif - if (pglClipControl != nullptr) { - pglClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); - _use_depth_zero_to_one = true; + if (pglClipControl != nullptr) { + pglClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); + _use_depth_zero_to_one = true; - if (GLCAT.is_debug()) { - GLCAT.debug() - << "Set zero-to-one depth using glClipControl\n"; - } + if (GLCAT.is_debug()) { + GLCAT.debug() + << "Set zero-to-one depth using glClipControl\n"; } }/* else if (has_extension("GL_NV_depth_buffer_float")) { // Alternatively, all GeForce 8+ and even some AMD drivers support this diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.h b/panda/src/glstuff/glGraphicsStateGuardian_src.h index 19d4a63d68..c889545fc9 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.h +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.h @@ -761,9 +761,11 @@ protected: #endif public: -#ifndef OPENGLES +#ifndef OPENGLES_1 bool _use_depth_zero_to_one; bool _use_remapped_depth_range; +#endif +#ifndef OPENGLES PFNGLDEPTHRANGEDNVPROC _glDepthRangedNV; #endif