mirror of
https://github.com/mpv-player/mpv.git
synced 2024-09-20 12:02:23 +02:00
gl_common: factor context creation
Always create the context in mpgl_init(), instead of doing it when mpgl_config_window() is called the first time. This is a small step towards cleaning up the GL backend interface, and adding other things like perhaps GLES support, or a callback-driven backend for libmpv.
This commit is contained in:
parent
7e62f2b052
commit
3fe57e3cb6
@ -930,7 +930,7 @@ static MPGLContext *init_backend(struct vo *vo, MPGLSetBackendFn set_backend,
|
||||
return ctx;
|
||||
}
|
||||
|
||||
MPGLContext *mpgl_init(struct vo *vo, const char *backend_name)
|
||||
static MPGLContext *mpgl_create(struct vo *vo, const char *backend_name)
|
||||
{
|
||||
MPGLContext *ctx = NULL;
|
||||
int index = mpgl_find_backend(backend_name);
|
||||
@ -946,17 +946,22 @@ MPGLContext *mpgl_init(struct vo *vo, const char *backend_name)
|
||||
return ctx;
|
||||
}
|
||||
|
||||
bool mpgl_config_window(struct MPGLContext *ctx, int gl_caps, int flags)
|
||||
MPGLContext *mpgl_init(struct vo *vo, const char *backend_name,
|
||||
int gl_caps, int vo_flags)
|
||||
{
|
||||
MPGLContext *ctx = mpgl_create(vo, backend_name);
|
||||
if (!ctx)
|
||||
return NULL;
|
||||
|
||||
gl_caps |= MPGL_CAP_GL;
|
||||
|
||||
ctx->requested_gl_version = (gl_caps & MPGL_CAP_GL_LEGACY)
|
||||
? MPGL_VER(2, 1) : MPGL_VER(3, 0);
|
||||
|
||||
if (ctx->config_window(ctx, flags)) {
|
||||
if (ctx->config_window(ctx, vo_flags | VOFLAG_HIDDEN)) {
|
||||
int missing = (ctx->gl->mpgl_caps & gl_caps) ^ gl_caps;
|
||||
if (!missing)
|
||||
return true;
|
||||
return ctx;
|
||||
|
||||
MP_WARN(ctx->vo, "Missing OpenGL features:");
|
||||
list_features(missing, ctx->vo->log, MSGL_WARN, false);
|
||||
@ -970,7 +975,13 @@ bool mpgl_config_window(struct MPGLContext *ctx, int gl_caps, int flags)
|
||||
}
|
||||
|
||||
MP_ERR(ctx->vo, "OpenGL context creation failed!\n");
|
||||
return false;
|
||||
mpgl_uninit(ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool mpgl_reconfig_window(struct MPGLContext *ctx, int flags)
|
||||
{
|
||||
return ctx->config_window(ctx, flags);
|
||||
}
|
||||
|
||||
void mpgl_uninit(MPGLContext *ctx)
|
||||
|
@ -136,9 +136,6 @@ typedef struct MPGLContext {
|
||||
void *priv;
|
||||
} MPGLContext;
|
||||
|
||||
MPGLContext *mpgl_init(struct vo *vo, const char *backend_name);
|
||||
void mpgl_uninit(MPGLContext *ctx);
|
||||
|
||||
void mpgl_lock(MPGLContext *ctx);
|
||||
void mpgl_unlock(MPGLContext *ctx);
|
||||
void mpgl_set_context(MPGLContext *ctx);
|
||||
@ -150,7 +147,12 @@ bool mpgl_is_thread_safe(MPGLContext *ctx);
|
||||
// gl_caps: bitfield of MPGL_CAP_* (required GL version and feature set)
|
||||
// flags: passed to the backend's create window function
|
||||
// Returns success.
|
||||
bool mpgl_config_window(struct MPGLContext *ctx, int gl_caps, int flags);
|
||||
MPGLContext *mpgl_init(struct vo *vo, const char *backend_name,
|
||||
int gl_caps, int vo_flags);
|
||||
void mpgl_uninit(MPGLContext *ctx);
|
||||
|
||||
// flags: passed to the backend function
|
||||
bool mpgl_reconfig_window(struct MPGLContext *ctx, int flags);
|
||||
|
||||
int mpgl_find_backend(const char *name);
|
||||
|
||||
|
@ -186,23 +186,6 @@ static int query_format(struct vo *vo, uint32_t format)
|
||||
return caps;
|
||||
}
|
||||
|
||||
static bool config_window(struct gl_priv *p, int flags)
|
||||
{
|
||||
if (p->renderer_opts->stereo_mode == GL_3D_QUADBUFFER)
|
||||
flags |= VOFLAG_STEREO;
|
||||
|
||||
if (p->renderer_opts->alpha_mode == 1)
|
||||
flags |= VOFLAG_ALPHA;
|
||||
|
||||
if (p->use_gl_debug)
|
||||
flags |= VOFLAG_GL_DEBUG;
|
||||
|
||||
int mpgl_caps = MPGL_CAP_GL21 | MPGL_CAP_TEX_RG;
|
||||
if (!p->allow_sw)
|
||||
mpgl_caps |= MPGL_CAP_NO_SW;
|
||||
return mpgl_config_window(p->glctx, mpgl_caps, flags);
|
||||
}
|
||||
|
||||
static void video_resize_redraw_callback(struct vo *vo, int w, int h)
|
||||
{
|
||||
struct gl_priv *p = vo->priv;
|
||||
@ -216,7 +199,7 @@ static int reconfig(struct vo *vo, struct mp_image_params *params, int flags)
|
||||
|
||||
mpgl_lock(p->glctx);
|
||||
|
||||
if (!config_window(p, flags)) {
|
||||
if (!mpgl_reconfig_window(p->glctx, flags)) {
|
||||
mpgl_unlock(p->glctx);
|
||||
return -1;
|
||||
}
|
||||
@ -462,14 +445,26 @@ static int preinit(struct vo *vo)
|
||||
struct gl_priv *p = vo->priv;
|
||||
p->vo = vo;
|
||||
|
||||
p->glctx = mpgl_init(vo, p->backend);
|
||||
int vo_flags = 0;
|
||||
|
||||
if (p->renderer_opts->stereo_mode == GL_3D_QUADBUFFER)
|
||||
vo_flags |= VOFLAG_STEREO;
|
||||
|
||||
if (p->renderer_opts->alpha_mode == 1)
|
||||
vo_flags |= VOFLAG_ALPHA;
|
||||
|
||||
if (p->use_gl_debug)
|
||||
vo_flags |= VOFLAG_GL_DEBUG;
|
||||
|
||||
int mpgl_caps = MPGL_CAP_GL21 | MPGL_CAP_TEX_RG;
|
||||
if (!p->allow_sw)
|
||||
mpgl_caps |= MPGL_CAP_NO_SW;
|
||||
|
||||
p->glctx = mpgl_init(vo, p->backend, mpgl_caps, vo_flags);
|
||||
if (!p->glctx)
|
||||
goto err_out;
|
||||
p->gl = p->glctx->gl;
|
||||
|
||||
if (!config_window(p, VOFLAG_HIDDEN))
|
||||
goto err_out;
|
||||
|
||||
mpgl_set_context(p->glctx);
|
||||
|
||||
if (p->gl->SwapInterval)
|
||||
|
@ -1700,19 +1700,6 @@ static int initGl(struct vo *vo, uint32_t d_width, uint32_t d_height)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static bool config_window(struct vo *vo, int flags)
|
||||
{
|
||||
struct gl_priv *p = vo->priv;
|
||||
|
||||
if (p->stereo_mode == GL_3D_QUADBUFFER)
|
||||
flags |= VOFLAG_STEREO;
|
||||
|
||||
int mpgl_caps = MPGL_CAP_GL_LEGACY;
|
||||
if (!p->allow_sw)
|
||||
mpgl_caps |= MPGL_CAP_NO_SW;
|
||||
return mpgl_config_window(p->glctx, mpgl_caps, flags);
|
||||
}
|
||||
|
||||
static int reconfig(struct vo *vo, struct mp_image_params *params, int flags)
|
||||
{
|
||||
struct gl_priv *p = vo->priv;
|
||||
@ -1733,7 +1720,7 @@ static int reconfig(struct vo *vo, struct mp_image_params *params, int flags)
|
||||
|
||||
uninitGl(vo);
|
||||
|
||||
if (!config_window(vo, flags))
|
||||
if (!mpgl_reconfig_window(p->glctx, flags))
|
||||
return -1;
|
||||
|
||||
initGl(vo, vo->dwidth, vo->dheight);
|
||||
@ -2085,16 +2072,22 @@ static int preinit(struct vo *vo)
|
||||
p->use_yuv = 2;
|
||||
}
|
||||
|
||||
p->glctx = mpgl_init(vo, p->backend_arg);
|
||||
int vo_flags = 0;
|
||||
|
||||
if (p->stereo_mode == GL_3D_QUADBUFFER)
|
||||
vo_flags |= VOFLAG_STEREO;
|
||||
|
||||
int mpgl_caps = MPGL_CAP_GL_LEGACY;
|
||||
if (!p->allow_sw)
|
||||
mpgl_caps |= MPGL_CAP_NO_SW;
|
||||
|
||||
p->glctx = mpgl_init(vo, p->backend_arg, mpgl_caps, vo_flags);
|
||||
if (!p->glctx)
|
||||
goto err_out;
|
||||
p->gl = p->glctx->gl;
|
||||
|
||||
if (p->use_yuv == -1) {
|
||||
if (!config_window(vo, VOFLAG_HIDDEN))
|
||||
goto err_out;
|
||||
if (p->use_yuv == -1)
|
||||
autodetectGlExtensions(vo);
|
||||
}
|
||||
MP_VERBOSE(vo, "Using %d as slice height "
|
||||
"(0 means image height).\n", p->slice_height);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user