From 83374de0fffee571849127498bf9dd66d2c352e7 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 31 Dec 2018 14:01:26 +0100 Subject: [PATCH] shader: don't use GENERIC profile to compile Cg shaders Instead, make an educated guess of what the GSG we are going to be compiling this shader for wants to use as profile. --- panda/src/display/config_display.cxx | 9 -------- panda/src/display/config_display.h | 1 - .../glstuff/glGraphicsStateGuardian_src.cxx | 2 ++ panda/src/gobj/config_gobj.cxx | 9 ++++++++ panda/src/gobj/config_gobj.h | 1 + panda/src/gobj/shader.cxx | 21 ++++++++++++++++--- panda/src/gobj/shader.h | 2 ++ 7 files changed, 32 insertions(+), 13 deletions(-) diff --git a/panda/src/display/config_display.cxx b/panda/src/display/config_display.cxx index 78c0b17418..965d68f4e3 100644 --- a/panda/src/display/config_display.cxx +++ b/panda/src/display/config_display.cxx @@ -478,15 +478,6 @@ ConfigVariableBool sync_video "cheesy estimate of scene complexity. Some drivers may ignore " "this request.")); -ConfigVariableBool basic_shaders_only -("basic-shaders-only", false, - PRC_DESC("Set this to true if you aren't interested in shader model three " - "and beyond. Setting this flag will cause panda to disable " - "bleeding-edge shader functionality which tends to be unreliable " - "or broken. At some point, when functionality that is currently " - "flaky becomes reliable, we may expand the definition of what " - "constitutes 'basic' shaders.")); - /** * Initializes the library. This must be called at least once before any of * the functions or classes in this library can be used. Normally it will be diff --git a/panda/src/display/config_display.h b/panda/src/display/config_display.h index 0b76e06472..21f1acb510 100644 --- a/panda/src/display/config_display.h +++ b/panda/src/display/config_display.h @@ -108,7 +108,6 @@ extern EXPCL_PANDA_DISPLAY ConfigVariableDouble pixel_zoom; extern EXPCL_PANDA_DISPLAY ConfigVariableColor background_color; extern EXPCL_PANDA_DISPLAY ConfigVariableBool sync_video; -extern EXPCL_PANDA_DISPLAY ConfigVariableBool basic_shaders_only; extern EXPCL_PANDA_DISPLAY void init_libdisplay(); diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 1e6d1781cc..6151a2c00d 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -1684,6 +1684,8 @@ reset() { } } + Shader::set_default_caps(_shader_caps); + } else if (_supports_glsl) { // No, but we do support GLSL... _shader_caps._active_vprofile = (int)CG_PROFILE_GLSLV; diff --git a/panda/src/gobj/config_gobj.cxx b/panda/src/gobj/config_gobj.cxx index 12840f7d04..07075a94a8 100644 --- a/panda/src/gobj/config_gobj.cxx +++ b/panda/src/gobj/config_gobj.cxx @@ -511,6 +511,15 @@ ConfigVariableBool stereo_lens_old_convergence "old, incorrect behavior, this may be set to 'true' to switch " "back to the old calculation.")); +ConfigVariableBool basic_shaders_only +("basic-shaders-only", false, + PRC_DESC("Set this to true if you aren't interested in shader model three " + "and beyond. Setting this flag will cause panda to disable " + "bleeding-edge shader functionality which tends to be unreliable " + "or broken. At some point, when functionality that is currently " + "flaky becomes reliable, we may expand the definition of what " + "constitutes 'basic' shaders.")); + ConfigVariableString cg_glsl_version ("cg-glsl-version", "", PRC_DESC("If this is set, it forces the Cg compiler to generate GLSL " diff --git a/panda/src/gobj/config_gobj.h b/panda/src/gobj/config_gobj.h index 7e769c0f45..90a5673c12 100644 --- a/panda/src/gobj/config_gobj.h +++ b/panda/src/gobj/config_gobj.h @@ -87,6 +87,7 @@ extern EXPCL_PANDA_GOBJ ConfigVariableDouble async_load_delay; extern EXPCL_PANDA_GOBJ ConfigVariableInt lens_geom_segments; extern EXPCL_PANDA_GOBJ ConfigVariableBool stereo_lens_old_convergence; +extern EXPCL_PANDA_GOBJ ConfigVariableBool basic_shaders_only; extern EXPCL_PANDA_GOBJ ConfigVariableString cg_glsl_version; extern EXPCL_PANDA_GOBJ ConfigVariableBool glsl_preprocess; extern EXPCL_PANDA_GOBJ ConfigVariableInt glsl_include_recursion_limit; diff --git a/panda/src/gobj/shader.cxx b/panda/src/gobj/shader.cxx index fde084aa18..d42e6a4734 100644 --- a/panda/src/gobj/shader.cxx +++ b/panda/src/gobj/shader.cxx @@ -1589,6 +1589,15 @@ get_compiled(unsigned int &format, string &binary) const { return !binary.empty(); } +/** + * Called by the graphics back-end to specify the caps with which we will + * likely want to be compiling our shaders. + */ +void Shader:: +set_default_caps(const ShaderCaps &caps) { + _default_caps = caps; +} + #ifdef HAVE_CG /** * @@ -2364,9 +2373,15 @@ Shader(ShaderLanguage lang) : _cg_fprofile = CG_PROFILE_UNKNOWN; _cg_gprofile = CG_PROFILE_UNKNOWN; if (_default_caps._ultimate_vprofile == 0 || _default_caps._ultimate_vprofile == CG_PROFILE_UNKNOWN) { - _default_caps._active_vprofile = CG_PROFILE_GENERIC; - _default_caps._active_fprofile = CG_PROFILE_GENERIC; - _default_caps._active_gprofile = CG_PROFILE_GENERIC; + if (basic_shaders_only) { + _default_caps._active_vprofile = CG_PROFILE_ARBVP1; + _default_caps._active_fprofile = CG_PROFILE_ARBFP1; + _default_caps._active_gprofile = CG_PROFILE_UNKNOWN; + } else { + _default_caps._active_vprofile = CG_PROFILE_UNKNOWN; + _default_caps._active_fprofile = CG_PROFILE_UNKNOWN; + _default_caps._active_gprofile = CG_PROFILE_UNKNOWN; + } _default_caps._ultimate_vprofile = cgGetProfile("glslv"); _default_caps._ultimate_fprofile = cgGetProfile("glslf"); _default_caps._ultimate_gprofile = cgGetProfile("glslg"); diff --git a/panda/src/gobj/shader.h b/panda/src/gobj/shader.h index 35971b243b..940e2d0ccf 100644 --- a/panda/src/gobj/shader.h +++ b/panda/src/gobj/shader.h @@ -527,6 +527,8 @@ public: void set_compiled(unsigned int format, const char *data, size_t length); bool get_compiled(unsigned int &format, std::string &binary) const; + static void set_default_caps(const ShaderCaps &caps); + private: #ifdef HAVE_CG ShaderArgClass cg_parameter_class(CGparameter p);