@@ -473,7 +473,6 @@ struct state_gl {
473473 int pos_y = INT_MIN;
474474
475475 enum modeset_t { MODESET = -2 , MODESET_SIZE_ONLY = GLFW_DONT_CARE, NOMODESET = 0 } modeset = NOMODESET; // /< positive vals force framerate
476- struct dictionary *init_hints;
477476 struct dictionary *window_hints;
478477 int use_pbo = -1 ;
479478 int req_monitor_idx = -1 ;
@@ -646,15 +645,20 @@ static void gl_show_help(bool full) {
646645 keybindings[i].description );
647646 }
648647
649- gl_print_monitors (full);
650- if (full) {
651- gl_print_platforms ();
652- }
653- GLFWwindow *window = glfwCreateWindow (32 , 32 , DEFAULT_WIN_NAME, nullptr , nullptr );
654- if (window != nullptr ) {
655- glfwMakeContextCurrent (window);
656- check_display_gl_version (true );
657- glfwDestroyWindow (window);
648+ if (glfwInit () != GLFW_FALSE) {
649+ gl_print_monitors (full);
650+ if (full) {
651+ gl_print_platforms ();
652+ }
653+ GLFWwindow *window = glfwCreateWindow (32 , 32 , DEFAULT_WIN_NAME,
654+ nullptr , nullptr );
655+ if (window != nullptr ) {
656+ glfwMakeContextCurrent (window);
657+ check_display_gl_version (true );
658+ glfwDestroyWindow (window);
659+ }
660+ } else {
661+ MSG (ERROR, " Cannot initialize GLFW!\n " );
658662 }
659663
660664 col () << " Compiled " << SBOLD (" features: " ) << " SPOUT - "
@@ -731,7 +735,7 @@ get_hint_from_string(const char *string)
731735
732736// / @param window_hints true for window hints, otherwise init hints
733737static void
734- parse_hints (struct state_gl *s, bool window_hints, char *hints)
738+ set_hints (struct state_gl *s, bool window_hints, char *hints)
735739{
736740 char *tok = nullptr ;
737741 char *save_ptr = nullptr ;
@@ -745,29 +749,36 @@ parse_hints(struct state_gl *s, bool window_hints, char *hints)
745749 const char *key_s = tok;
746750 const char *val_s = strchr (tok, ' =' ) + 1 ;
747751 *strchr (tok, ' =' ) = ' \0 ' ;
748- dictionary_insert (window_hints ? s->window_hints
749- : s->init_hints ,
750- key_s, val_s);
752+ if (window_hints) {
753+ dictionary_insert (s->window_hints , key_s, val_s);
754+ } else {
755+ #if GLFW_VERSION_MAJOR < 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR < 3)
756+ MSG (WARNING,
757+ " GLFW version < 3.3 doesn't support init hints. "
758+ " Ignoring them.\n " );
759+ #else
760+
761+ glfwInitHint (get_hint_from_string (key_s),
762+ get_hint_from_string (val_s));
763+ #endif
764+ }
751765 }
752766}
753767
754768static bool
755- set_platform (struct state_gl *s, const char *platform)
769+ set_platform (const char *platform)
756770{
757771#ifdef GLFW_PLATFORM
758772 for (unsigned i = 0 ; i < ARR_COUNT (platform_map); ++i) {
759773 if (strcasecmp (platform_map[i].name , platform) == 0 ) {
760- char platform[32 ];
761- snprintf_ch (platform, " %d" , platform_map[i].platform_id );
762- dictionary_insert (s->init_hints ,
763- TOSTRING (GLFW_PLATFORM), platform);
774+ glfwInitHint (GLFW_PLATFORM, platform_map[i].platform_id );
764775 return true ;
765776 }
766777 }
767778 MSG (ERROR, " Unknown platform: %s\n " , platform);
768779 return false ;
769780#else
770- (void ) s, ( void ) platform;
781+ (void ) platform;
771782 MSG (ERROR, " platforms unsupported (old GLFW)\n " );
772783 return false ;
773784#endif
@@ -879,11 +890,11 @@ display_gl_parse_fmt(struct state_gl *s, char *ptr)
879890 } else if (strcmp (tok, " noresizable" ) == 0 ) {
880891 s->noresizable = true ;
881892 } else if (strstr (tok, " window_hint=" ) == tok) {
882- parse_hints (s, true , strchr (tok, ' =' ) + 1 );
893+ set_hints (s, true , strchr (tok, ' =' ) + 1 );
883894 } else if (strstr (tok, " init_hint=" ) == tok) {
884- parse_hints (s, false , strchr (tok, ' =' ) + 1 );
895+ set_hints (s, false , strchr (tok, ' =' ) + 1 );
885896 } else if (IS_KEY_PREFIX (tok, " platform" )) {
886- ret = ret && set_platform (s, strchr (tok, ' =' ) + 1 );
897+ ret = ret && set_platform (strchr (tok, ' =' ) + 1 );
887898 } else if (strcmp (tok, " list_hints" ) == 0 ) {
888899 list_hints ();
889900 return false ;
@@ -901,16 +912,11 @@ static void * display_gl_init(struct module *parent, const char *fmt, unsigned i
901912 UNUSED (flags);
902913
903914 glfwSetErrorCallback (glfw_print_error);
904- if (glfwInit () != GLFW_TRUE) {
905- MSG (ERROR, " Cannot initialize GLFW!\n " );
906- return nullptr ;
907- }
908915
909916 auto *s = new state_gl ();
910917 module_init_default (&s->mod );
911918 s->mod .cls = MODULE_CLASS_DATA;
912919 module_register (&s->mod , parent);
913- s->init_hints = dictionary_init ();
914920 s->window_hints = dictionary_init ();
915921 dictionary_insert (s->window_hints , TOSTRING (GLFW_AUTO_ICONIFY),
916922 TOSTRING (GLFW_FALSE));
@@ -930,6 +936,12 @@ static void * display_gl_init(struct module *parent, const char *fmt, unsigned i
930936 }
931937 }
932938
939+ if (glfwInit () != GLFW_TRUE) {
940+ MSG (ERROR, " Cannot initialize GLFW!\n " );
941+ display_gl_done (s);
942+ return nullptr ;
943+ }
944+
933945 s->use_pbo = s->use_pbo == -1 ? !check_rpi_pbo_quirks () : s->use_pbo ; // don't use PBO for Raspberry Pi (better performance)
934946
935947 log_msg (LOG_LEVEL_INFO," GL setup: fullscreen: %s, deinterlace: %s\n " ,
@@ -947,18 +959,6 @@ static void * display_gl_init(struct module *parent, const char *fmt, unsigned i
947959 keybindings[i].description );
948960 }
949961
950- #if GLFW_VERSION_MAJOR < 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR < 3)
951- if (dictionary_first (s->init_hints , nullptr ) != nullptr ) {
952- MSG (WARNING, " GLFW version < 3.3 doesn't support init hints. "
953- " Ignoring them.\n " );
954- }
955- #else
956- DICTIONARY_ITERATE (s->init_hints , key_s, val_s) {
957- glfwInitHint (get_hint_from_string (key_s),
958- get_hint_from_string (val_s));
959- }
960- #endif
961-
962962 if (!display_gl_init_opengl (s)) {
963963 display_gl_done (s);
964964 return nullptr ;
@@ -2212,7 +2212,6 @@ static void display_gl_done(void *state)
22122212
22132213 vf_free (s->current_frame );
22142214 free (s->scratchpad );
2215- dictionary_destroy (s->init_hints );
22162215 dictionary_destroy (s->window_hints );
22172216
22182217 glfwTerminate ();
0 commit comments