From 300090e457668bdc51fb1e75cfa160d57f736c2e Mon Sep 17 00:00:00 2001 From: rdb Date: Wed, 28 Jan 2026 14:12:38 +0100 Subject: [PATCH] glgsg: Disable Cg support when using EGL instead of GLX Cg is hard-wired to use GLX instead of EGL, so without hacky monkey-patching it is not possible to use it under EGL --- panda/src/egldisplay/eglGraphicsStateGuardian.cxx | 9 +++++++++ panda/src/egldisplay/eglGraphicsStateGuardian.h | 1 + panda/src/glstuff/glGraphicsStateGuardian_src.cxx | 15 ++++++++++++++- panda/src/glstuff/glGraphicsStateGuardian_src.h | 1 + panda/src/glxdisplay/glxGraphicsStateGuardian.cxx | 12 ++++++++++++ panda/src/glxdisplay/glxGraphicsStateGuardian.h | 1 + 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/panda/src/egldisplay/eglGraphicsStateGuardian.cxx b/panda/src/egldisplay/eglGraphicsStateGuardian.cxx index 70924505ad..f4348f26ca 100644 --- a/panda/src/egldisplay/eglGraphicsStateGuardian.cxx +++ b/panda/src/egldisplay/eglGraphicsStateGuardian.cxx @@ -377,3 +377,12 @@ void *eglGraphicsStateGuardian:: do_get_extension_func(const char *name) { return (void *)eglGetProcAddress(name); } + +/** + * Returns true if this implementation may support Cg shaders. + */ +bool eglGraphicsStateGuardian:: +may_support_cg_shaders() { + // Never supported under EGL as CgGL is hard-wired to use GLX functions. + return false; +} diff --git a/panda/src/egldisplay/eglGraphicsStateGuardian.h b/panda/src/egldisplay/eglGraphicsStateGuardian.h index 1a7a036609..94b1c724d6 100644 --- a/panda/src/egldisplay/eglGraphicsStateGuardian.h +++ b/panda/src/egldisplay/eglGraphicsStateGuardian.h @@ -68,6 +68,7 @@ protected: virtual void query_gl_version(); virtual void get_extra_extensions(); virtual void *do_get_extension_func(const char *name); + virtual bool may_support_cg_shaders(); private: int _egl_version_major, _egl_version_minor; diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index d5b98d8418..1550d51829 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -2059,7 +2059,8 @@ reset() { // Check for support for other types of shaders that can be used by Cg. _supports_basic_shaders = false; #if defined(HAVE_CG) && !defined(OPENGLES) - if (has_extension("GL_ARB_vertex_program") && + if (may_support_cg_shaders() && + has_extension("GL_ARB_vertex_program") && has_extension("GL_ARB_fragment_program")) { _supports_basic_shaders = true; _shader_caps._active_vprofile = (int)CG_PROFILE_ARBVP1; @@ -10236,6 +10237,18 @@ do_get_extension_func(const char *) { return nullptr; } +/** + * Returns true if this implementation may support Cg shaders. + */ +bool CLP(GraphicsStateGuardian):: +may_support_cg_shaders() { +#if defined(HAVE_CG) && !defined(OPENGLES) + return true; +#else + return false; +#endif +} + /** * Sets up the glDrawBuffer to render into the buffer indicated by the * RenderBuffer object. This only sets up the color and aux bits; it does not diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.h b/panda/src/glstuff/glGraphicsStateGuardian_src.h index af9cc85f8c..4514d3f04c 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.h +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.h @@ -525,6 +525,7 @@ protected: INLINE bool is_at_least_gles_version(int major_version, int minor_version) const; void *get_extension_func(const char *name); virtual void *do_get_extension_func(const char *name); + virtual bool may_support_cg_shaders(); virtual void reissue_transforms(); diff --git a/panda/src/glxdisplay/glxGraphicsStateGuardian.cxx b/panda/src/glxdisplay/glxGraphicsStateGuardian.cxx index be8c5f7f10..cdaf98800b 100644 --- a/panda/src/glxdisplay/glxGraphicsStateGuardian.cxx +++ b/panda/src/glxdisplay/glxGraphicsStateGuardian.cxx @@ -572,6 +572,18 @@ do_get_extension_func(const char *name) { return PosixGraphicsStateGuardian::do_get_extension_func(name); } +/** + * Returns true if this implementation may support Cg shaders. + */ +bool glxGraphicsStateGuardian:: +may_support_cg_shaders() { +#ifdef HAVE_CG + return true; +#else + return false; +#endif +} + /** * Queries the GLX extension pointers. */ diff --git a/panda/src/glxdisplay/glxGraphicsStateGuardian.h b/panda/src/glxdisplay/glxGraphicsStateGuardian.h index 4470f00d0b..6e13a67484 100644 --- a/panda/src/glxdisplay/glxGraphicsStateGuardian.h +++ b/panda/src/glxdisplay/glxGraphicsStateGuardian.h @@ -128,6 +128,7 @@ protected: virtual void query_gl_version(); virtual void get_extra_extensions(); virtual void *do_get_extension_func(const char *name); + virtual bool may_support_cg_shaders(); private: void query_glx_extensions();