diff --git a/src/emulator.c b/src/emulator.c index 8b245b3d..266a61b7 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -311,8 +311,7 @@ struct emu *emu_create(struct window *window) { /* add window input listeners */ emu->listener = (struct window_listener){ - emu, NULL, &emu_joy_add, &emu_joy_remove, - &emu_keydown, NULL, &emu_close, {0}}; + emu, &emu_joy_add, &emu_joy_remove, &emu_keydown, NULL, &emu_close, {0}}; win_add_listener(emu->window, &emu->listener); /* setup dreamcast */ diff --git a/src/tracer.c b/src/tracer.c index 2ccd9803..b2e4e823 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -849,7 +849,7 @@ struct tracer *tracer_create(struct window *window) { /* add window input listeners */ tracer->listener = (struct window_listener){ - tracer, NULL, NULL, NULL, &tracer_keydown, NULL, &tracer_close, {0}}; + tracer, NULL, NULL, &tracer_keydown, NULL, &tracer_close, {0}}; win_add_listener(tracer->window, &tracer->listener); /* setup render backend */ diff --git a/src/ui/microprofile.cc b/src/ui/microprofile.cc index 868a8680..02bde01e 100644 --- a/src/ui/microprofile.cc +++ b/src/ui/microprofile.cc @@ -276,7 +276,7 @@ struct microprofile *mp_create(struct window *window, mp->rb = rb; /* add input event listeners */ - mp->listener = {mp, NULL, NULL, NULL, &mp_keydown, &mp_mousemove, NULL, {}}; + mp->listener = {mp, NULL, NULL, &mp_keydown, &mp_mousemove, NULL, {}}; win_add_listener(mp->window, &mp->listener); /* register and enable cpu and gpu groups by default */ diff --git a/src/ui/nuklear.c b/src/ui/nuklear.c index f133c77b..8010e01d 100644 --- a/src/ui/nuklear.c +++ b/src/ui/nuklear.c @@ -152,7 +152,7 @@ struct nuklear *nk_create(struct window *window, struct render_backend *rb) { /* add input event listeners */ nk->listener = (struct window_listener){ - nk, NULL, NULL, NULL, &nk_keydown, &nk_mousemove, NULL, {0}}; + nk, NULL, NULL, &nk_keydown, &nk_mousemove, NULL, {0}}; win_add_listener(nk->window, &nk->listener); /* create default font texture */ diff --git a/src/ui/window.c b/src/ui/window.c index 3003e11d..8dc034a9 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -841,18 +841,27 @@ glcontext_t win_gl_create_context(struct window *win) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + /* bind default context at this point to make sure a context is available to + be shared from */ + if (win->default_ctx) { + SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); + SDL_GL_MakeCurrent(win->handle, win->default_ctx); + } + SDL_GLContext ctx = SDL_GL_CreateContext(win->handle); CHECK_NOTNULL(ctx, "OpenGL context creation failed: %s", SDL_GetError()); + /* track default context for future sharing */ + if (!win->default_ctx) { + win->default_ctx = ctx; + } + /* link in gl functions at runtime */ glewExperimental = GL_TRUE; GLenum err = glewInit(); CHECK_EQ(err, GLEW_OK, "GLEW initialization failed: %s", glewGetErrorString(err)); - /* enable vsync */ - SDL_GL_SetSwapInterval(1); - return ctx; } diff --git a/src/ui/window.h b/src/ui/window.h index b4508531..e4d9fa29 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -30,7 +30,6 @@ typedef void *glcontext_t; struct window_listener { void *data; - void (*paint)(void *data); void (*joy_add)(void *data, int joystick_index); void (*joy_remove)(void *data, int joystick_index); void (*keydown)(void *data, int device_index, enum keycode code, @@ -43,6 +42,7 @@ struct window_listener { struct window { /* public */ struct SDL_Window *handle; + glcontext_t default_ctx; /* read only */ int width;