remove paint event from window listener

add multiple context support to win_gl_create_context
This commit is contained in:
Anthony Pesch 2017-04-13 19:21:26 -04:00
parent 83b74a2e46
commit 6660c33c1c
6 changed files with 17 additions and 9 deletions

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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;
}

View File

@ -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;