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
This commit is contained in:
Stefano Pigozzi 2013-09-28 13:51:29 +02:00
parent 73808cd8f0
commit 9d3943840c
3 changed files with 23 additions and 2 deletions

View File

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

View File

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

View File

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