From 29a0d43b5674be6e4463cd04667c315c01ece570 Mon Sep 17 00:00:00 2001 From: bsp2 Date: Sun, 28 Oct 2018 11:14:52 +0100 Subject: [PATCH] add USE_BEGIN_REDRAW_FXN build option (disabled by default, see setenv_linux.sh) --- include/plugin.hpp | 39 +++++++++++++++++++++++++++++++++++---- setenv_linux.sh | 3 ++- src/plugin.cpp | 11 +++++++++++ src/vst2_main.cpp | 7 +++++++ 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/include/plugin.hpp b/include/plugin.hpp index 72166f90..dbefb7a1 100644 --- a/include/plugin.hpp +++ b/include/plugin.hpp @@ -6,9 +6,14 @@ #include "tags.hpp" #include "util/common.hpp" - #define RACK_PLUGIN_INIT_ID_INTERNAL p->slug = TOSTRING(SLUG); p->version = TOSTRING(VERSION) +#ifdef USE_BEGIN_REDRAW_FXN +extern "C" { +#include +} +#endif // USE_BEGIN_REDRAW_FXN + #ifdef USE_VST2 namespace rack { @@ -20,6 +25,9 @@ namespace rack { typedef void (*vst2_handle_ui_param_fxn_t) (int uniqueParamId, float normValue); typedef void (*vst2_queue_param_sync_fxn_t) (int uniqueParamId, float value, bool _bNormalized); typedef void (*rack_set_tls_globals_fxn_t) (rack::Plugin *p); +#ifdef USE_BEGIN_REDRAW_FXN +typedef void (*rack_begin_redraw_fxn_t) (void); +#endif // USE_BEGIN_REDRAW_FXN #ifdef RACK_HOST @@ -64,7 +72,21 @@ extern vst2_queue_param_sync_fxn_t vst2_queue_param_sync; #else #define JSON_SEED_INIT_EXTERNAL extern "C" { extern volatile char seed_initialized; } #endif - #define RACK_PLUGIN_INIT(pluginname) \ + +#ifdef USE_BEGIN_REDRAW_FXN +// a hack that rebinds the GL context in shared plugins (may fix shared module redraw issues on Linux) +#define BEGIN_REDRAW_FXN_SET \ + rack::plugin->begin_redraw_fxn = &rack::loc_begin_redraw; +#define BEGIN_REDRAW_FXN_IMP \ + static void loc_begin_redraw(void) { \ + lglw_glcontext_rebind(global_ui->window.lglw); \ + } +#else +#define BEGIN_REDRAW_FXN_SET +#define BEGIN_REDRAW_FXN_IMP +#endif // USE_BEGIN_REDRAW_FXN + +#define RACK_PLUGIN_INIT(pluginname) \ vst2_handle_ui_param_fxn_t vst2_handle_ui_param; \ vst2_queue_param_sync_fxn_t vst2_queue_param_sync; \ JSON_SEED_INIT_EXTERNAL \ @@ -74,18 +96,20 @@ namespace rack { \ RACK_TLS Global *global; \ RACK_TLS GlobalUI *global_ui; \ static void loc_set_tls_globals(rack::Plugin *p) { \ - plugin = p; \ + plugin = p; \ global = plugin->global; \ global_ui = plugin->global_ui; \ /*printf("xxx plugin:loc_set_tls_globals: &global=%p global=%p\n", &global, plugin->global);*/ \ hashtable_seed = p->json.hashtable_seed; \ seed_initialized = p->json.seed_initialized; \ } \ + BEGIN_REDRAW_FXN_IMP \ } \ static void loc_init_plugin(rack::Plugin *p); extern "C" { RACK_PLUGIN_EXPORT void init_plugin(rack::Plugin *p) { loc_init_plugin(p); } } static void loc_init_plugin(rack::Plugin *p) #define RACK_PLUGIN_INIT_ID() \ rack::plugin = p; \ rack::plugin->set_tls_globals_fxn = &rack::loc_set_tls_globals; \ + BEGIN_REDRAW_FXN_SET \ vst2_handle_ui_param = p->vst2_handle_ui_param_fxn; \ vst2_queue_param_sync = p->vst2_queue_param_sync_fxn; \ rack::global = p->global; \ @@ -186,10 +210,17 @@ struct Plugin { // // Set by plugin: // - in init_plugin() - // - called by Rack host in audio thread + // - called by Rack host in audio+UI threads // - NULL if this is a statically linked add-on // rack_set_tls_globals_fxn_t set_tls_globals_fxn = NULL; + +#ifdef USE_BEGIN_REDRAW_FXN + // Called when redrawing the UI. + // An attempt to fix the GL issue with shared modules on Cameron's machine. + rack_begin_redraw_fxn_t begin_redraw_fxn = NULL; +#endif // USE_BEGIN_REDRAW_FXN + #endif // USE_VST2 virtual ~Plugin(); diff --git a/setenv_linux.sh b/setenv_linux.sh index 4c83cf27..dbdbbf26 100644 --- a/setenv_linux.sh +++ b/setenv_linux.sh @@ -23,13 +23,14 @@ fi # Extra compiler flags (C and C++) #EXTRA_FLAGS=-DUSE_LOG_PRINTF +#EXTRA_FLAGS="-DUSE_BEGIN_REDRAW_FXN -I${VSVR_BASE_DIR}/dep/lglw" EXTRA_FLAGS="" # Extra C compiler flags export EXTRA_CFLAGS="-march=${CPU_ARCH} ${EXTRA_FLAGS}" # Extra C++ compiler flags -export EXTRA_CPPFLAGS="-march=${CPU_ARCH} ${EXTRA_FLAGS}" +export EXTRA_CPPFLAGS="-march=${CPU_ARCH} ${EXTRA_FLAGS}" # Extra optimization flags (C/C++) export EXTRA_OPTFLAGS= diff --git a/src/plugin.cpp b/src/plugin.cpp index 2ce729e6..e8ef70d6 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -629,6 +629,17 @@ void vst2_set_shared_plugin_tls_globals(void) { } } } +#ifdef USE_BEGIN_REDRAW_FXN +void vst2_begin_shared_plugin_redraw(void) { + // Called in UI thread + for(Plugin *p : global->plugin.gPlugins) { + if(NULL != p->begin_redraw_fxn) { + printf("xxx call begin_redraw_fxn()\n"); + p->begin_redraw_fxn(); + } + } +} +#endif // USE_BEGIN_REDRAW_FXN #endif // USE_VST2 RackScene *rack_plugin_ui_get_rackscene(void) { diff --git a/src/vst2_main.cpp b/src/vst2_main.cpp index 5ae6c08b..2008f5e7 100644 --- a/src/vst2_main.cpp +++ b/src/vst2_main.cpp @@ -85,6 +85,9 @@ extern void vst2_handle_queued_params (void); extern float vst2_get_param (int uniqueParamId); extern void vst2_get_param_name (int uniqueParamId, char *s, int sMaxLen); extern void vst2_set_shared_plugin_tls_globals (void); // see plugin.cpp +#ifdef USE_BEGIN_REDRAW_FXN +extern void vst2_begin_shared_plugin_redraw (void); // see plugin.cpp +#endif // USE_BEGIN_REDRAW_FXN extern "C" { extern int vst2_handle_effeditkeydown (unsigned int _vkey); } namespace rack { @@ -1175,6 +1178,10 @@ public: // Save DAW GL context and bind our own lglw_glcontext_push(rack::global_ui->window.lglw); +#ifdef USE_BEGIN_REDRAW_FXN + vst2_begin_shared_plugin_redraw(); +#endif // USE_BEGIN_REDRAW_FXN + rack::vst2_editor_redraw(); // Restore the DAW's GL context