From a0b43a11e4e0edd6077c926f012c5f5c31a04e45 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 3 Oct 2012 01:54:13 +0200 Subject: vo_gl3: make it work on OpenGL 2.1 Now vo_gl3 should work with standard OpenGL 2.1, as long as the GL_ARB_texture_rg extension is available. Optional features, which require features that are always in OpenGL 3.0, but are available as extensions only in OpenGL 2.1, are automatically disabled. The force-gl2 suboption, which was an unreliable hack to run vo_gl3 in an OpenGL 2.1 context, is removed. Significant changes are done to the extension loader to make it easier to identify optional OpenGL features. Context creation is a bit changed to simplify the code and to handle the fallback better if OpenGL 3 context creation fails, and creating an OpenGL legacy context is attempted. Based on the initial work by Rudolf Polzer , which included making the shader GLSL 1.20 compatible, and more. --- libvo/vo_gl.c | 55 ++++++++++++++++++++++--------------------------------- 1 file changed, 22 insertions(+), 33 deletions(-) (limited to 'libvo/vo_gl.c') diff --git a/libvo/vo_gl.c b/libvo/vo_gl.c index 5453943fe9..f24448ac6c 100644 --- a/libvo/vo_gl.c +++ b/libvo/vo_gl.c @@ -62,6 +62,8 @@ struct gl_priv { MPGLContext *glctx; GL *gl; + int allow_sw; + int use_osd; int scaled_osd; //! Textures for OSD @@ -388,6 +390,9 @@ static void uninitGl(struct vo *vo) struct gl_priv *p = vo->priv; GL *gl = p->gl; + if (!gl) + return; + int i = 0; if (gl->DeletePrograms && p->fragprog) gl->DeletePrograms(1, &p->fragprog); @@ -415,16 +420,6 @@ static void uninitGl(struct vo *vo) p->err_shown = 0; } -static int isSoftwareGl(struct vo *vo) -{ - struct gl_priv *p = vo->priv; - const char *renderer = p->gl->GetString(GL_RENDERER); - const char *vendor = p->gl->GetString(GL_VENDOR); - return !renderer || strcmp(renderer, "Software Rasterizer") == 0 || - strstr(renderer, "llvmpipe") || - strcmp(vendor, "Microsoft Corporation") == 0; -} - static void autodetectGlExtensions(struct vo *vo) { struct gl_priv *p = vo->priv; @@ -596,15 +591,18 @@ static int initGl(struct vo *vo, uint32_t d_width, uint32_t d_height) return 1; } -static int create_window(struct vo *vo, uint32_t d_width, uint32_t d_height, - uint32_t flags) +static bool create_window(struct vo *vo, uint32_t d_width, uint32_t d_height, + uint32_t flags) { struct gl_priv *p = vo->priv; if (p->stereo_mode == GL_3D_QUADBUFFER) flags |= VOFLAG_STEREO; - return p->glctx->create_window(p->glctx, d_width, d_height, flags); + int mpgl_caps = MPGL_CAP_GL_LEGACY; + if (!p->allow_sw) + mpgl_caps |= MPGL_CAP_NO_SW; + return mpgl_create_window(p->glctx, mpgl_caps, d_width, d_height, flags); } static int config(struct vo *vo, uint32_t width, uint32_t height, @@ -626,13 +624,12 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, p->vo_flipped = !!(flags & VOFLAG_FLIPPING); - if (create_window(vo, d_width, d_height, flags) < 0) - return -1; - if (vo->config_count) uninitGl(vo); - if (p->glctx->setGlWindow(p->glctx) == SET_WINDOW_FAILED) + + if (!create_window(vo, d_width, d_height, flags)) return -1; + initGl(vo, vo->dwidth, vo->dheight); return 0; @@ -1153,13 +1150,12 @@ static void uninit(struct vo *vo) { struct gl_priv *p = vo->priv; - if (p->glctx) - uninitGl(vo); + uninitGl(vo); free(p->custom_prog); p->custom_prog = NULL; free(p->custom_tex); p->custom_tex = NULL; - uninit_mpglcontext(p->glctx); + mpgl_uninit(p->glctx); p->glctx = NULL; p->gl = NULL; } @@ -1192,7 +1188,6 @@ static int preinit(struct vo *vo, const char *arg) p->eosd = eosd_packer_create(vo); - int allow_sw = 0; char *backend_arg = NULL; //essentially unused; for legacy warnings only @@ -1223,7 +1218,7 @@ static int preinit(struct vo *vo, const char *arg) {"mipmapgen", OPT_ARG_BOOL, &p->mipmap_gen, NULL}, {"osdcolor", OPT_ARG_INT, &p->osd_color, NULL}, {"stereo", OPT_ARG_INT, &p->stereo_mode, NULL}, - {"sw", OPT_ARG_BOOL, &allow_sw, NULL}, + {"sw", OPT_ARG_BOOL, &p->allow_sw, NULL}, {"backend", OPT_ARG_MSTRZ,&backend_arg, backend_valid}, // Removed options. // They are only parsed to notify the user about the replacements. @@ -1330,27 +1325,21 @@ static int preinit(struct vo *vo, const char *arg) int backend = backend_arg ? mpgl_find_backend(backend_arg) : GLTYPE_AUTO; free(backend_arg); - p->glctx = init_mpglcontext(backend, vo); + p->glctx = mpgl_init(backend, vo); if (!p->glctx) goto err_out; p->gl = p->glctx->gl; - if (p->use_yuv == -1 || !allow_sw) { - if (create_window(vo, 320, 200, VOFLAG_HIDDEN) < 0) - goto err_out; - if (p->glctx->setGlWindow(p->glctx) == SET_WINDOW_FAILED) - goto err_out; - if (!allow_sw && isSoftwareGl(vo)) + if (p->use_yuv == -1) { + if (!create_window(vo, 320, 200, VOFLAG_HIDDEN)) goto err_out; autodetectGlExtensions(vo); // We created a window to test whether the GL context supports hardware // acceleration and so on. Destroy that window to make sure all state // associated with it is lost. - uninit(vo); - p->glctx = init_mpglcontext(backend, vo); - if (!p->glctx) + uninitGl(vo); + if (!mpgl_destroy_window(p->glctx)) goto err_out; - p->gl = p->glctx->gl; } if (p->many_fmts) mp_msg(MSGT_VO, MSGL_INFO, "[gl] using extended formats. " -- cgit v1.2.3