From 9d3943840cb472e7921a933a06477f53eca4a17e Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 28 Sep 2013 13:51:29 +0200 Subject: cocoa_common: call gl_clear indirectly glClear needs GL headers and we don't want those in `cocoa_common`. Create a callback in `gl_cocoa` and register it `cocoa_common`. Fixes #264 --- video/out/cocoa_common.h | 3 +++ video/out/cocoa_common.m | 13 +++++++++++-- video/out/gl_cocoa.c | 9 +++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) (limited to 'video') diff --git a/video/out/cocoa_common.h b/video/out/cocoa_common.h index 5584ae6b05..453e52c6c6 100644 --- a/video/out/cocoa_common.h +++ b/video/out/cocoa_common.h @@ -41,6 +41,9 @@ int vo_cocoa_control(struct vo *vo, int *events, int request, void *arg); void vo_cocoa_register_resize_callback(struct vo *vo, void (*cb)(struct vo *vo, int w, int h)); +void vo_cocoa_register_gl_clear_callback(struct vo *vo, void *ctx, + void (*cb)(void *ctx)); + // returns an int to conform to the gl extensions from other platforms int vo_cocoa_swap_interval(int enabled); diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m index b15ffd3d36..85d92c861f 100644 --- a/video/out/cocoa_common.m +++ b/video/out/cocoa_common.m @@ -65,6 +65,8 @@ struct vo_cocoa_state { NSLock *lock; bool enable_resize_redraw; + void *ctx; + void (*gl_clear)(void *ctx); void (*resize_redraw)(struct vo *vo, int w, int h); struct mp_log *log; @@ -163,6 +165,14 @@ void vo_cocoa_register_resize_callback(struct vo *vo, s->resize_redraw = cb; } +void vo_cocoa_register_gl_clear_callback(struct vo *vo, void *ctx, + void (*cb)(void *ctx)) +{ + struct vo_cocoa_state *s = vo->cocoa; + s->ctx = ctx; + s->gl_clear = cb; +} + static int get_screen_handle(struct vo *vo, int identifier, NSWindow *window, NSScreen **screen) { struct vo_cocoa_state *s = vo->cocoa; @@ -361,8 +371,7 @@ static void vo_cocoa_resize_redraw(struct vo *vo, int width, int height) s->resize_redraw(vo, width, height); s->skip_next_swap_buffer = true; } else { - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + s->gl_clear(s->ctx); } [s->gl_ctx flushBuffer]; diff --git a/video/out/gl_cocoa.c b/video/out/gl_cocoa.c index f9acffb2fb..80be3a471d 100644 --- a/video/out/gl_cocoa.c +++ b/video/out/gl_cocoa.c @@ -22,6 +22,13 @@ #include "cocoa_common.h" #include "gl_common.h" +static void gl_clear(void *ctx) +{ + struct GL *gl = ctx; + gl->ClearColor(0.0f, 0.0f, 0.0f, 0.0f); + gl->Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +} + static bool config_window_cocoa(struct MPGLContext *ctx, uint32_t d_width, uint32_t d_height, uint32_t flags) { @@ -39,6 +46,8 @@ static bool config_window_cocoa(struct MPGLContext *ctx, uint32_t d_width, if (!ctx->gl->SwapInterval) ctx->gl->SwapInterval = vo_cocoa_swap_interval; + vo_cocoa_register_gl_clear_callback(ctx->vo, ctx->gl, gl_clear); + return true; } -- cgit v1.2.3