From eeb5f987585b47b2d5828cac0f2d90e0c503ce4c Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 9 Nov 2015 16:24:01 +0100 Subject: vo_opengl: handle GL_ARB_uniform_buffer_object with low GLSL versions Why is this stupid crap being so much a pain for no reason. --- video/out/opengl/nnedi3.c | 4 +++- video/out/opengl/nnedi3.h | 2 +- video/out/opengl/utils.c | 16 +++++++++++++--- video/out/opengl/utils.h | 1 + video/out/opengl/video.c | 2 +- 5 files changed, 19 insertions(+), 6 deletions(-) (limited to 'video') diff --git a/video/out/opengl/nnedi3.c b/video/out/opengl/nnedi3.c index fb704d2ab6..f757324608 100644 --- a/video/out/opengl/nnedi3.c +++ b/video/out/opengl/nnedi3.c @@ -80,7 +80,7 @@ const float* get_nnedi3_weights(const struct nnedi3_opts *conf, int *size) return (const float*)(nnedi3_weights + offset * 4); } -void pass_nnedi3(struct gl_shader_cache *sc, int planes, int tex_num, +void pass_nnedi3(GL *gl, struct gl_shader_cache *sc, int planes, int tex_num, int step, const struct nnedi3_opts *conf, struct gl_transform *transform) { @@ -108,6 +108,8 @@ void pass_nnedi3(struct gl_shader_cache *sc, int planes, int tex_num, snprintf(buf, sizeof(buf), "vec4 weights[%d];", neurons * (sample_count * 2 + 1)); gl_sc_uniform_buffer(sc, "NNEDI3_WEIGHTS", buf, 0); + if (gl->glsl_version < 140) + gl_sc_enable_extension(sc, "GL_ARB_uniform_buffer_object"); } else if (conf->upload == NNEDI3_UPLOAD_SHADER) { // Somehow necessary for hard coding approach. GLSLH(#pragma optionNV(fastprecision on)) diff --git a/video/out/opengl/nnedi3.h b/video/out/opengl/nnedi3.h index ae0104ef04..8498b9de7a 100644 --- a/video/out/opengl/nnedi3.h +++ b/video/out/opengl/nnedi3.h @@ -40,7 +40,7 @@ extern const struct m_sub_options nnedi3_conf; const float* get_nnedi3_weights(const struct nnedi3_opts *conf, int *size); -void pass_nnedi3(struct gl_shader_cache *sc, int planes, int tex_num, +void pass_nnedi3(GL *gl, struct gl_shader_cache *sc, int planes, int tex_num, int step, const struct nnedi3_opts *conf, struct gl_transform *transform); diff --git a/video/out/opengl/utils.c b/video/out/opengl/utils.c index 6ddb333e47..83bed06498 100644 --- a/video/out/opengl/utils.c +++ b/video/out/opengl/utils.c @@ -513,8 +513,9 @@ struct gl_shader_cache { struct mp_log *log; // this is modified during use (gl_sc_add() etc.) - char *text; + char *prelude_text; char *header_text; + char *text; struct gl_vao *vao; struct sc_entry entries[SC_ENTRIES]; @@ -530,16 +531,18 @@ struct gl_shader_cache *gl_sc_create(GL *gl, struct mp_log *log) *sc = (struct gl_shader_cache){ .gl = gl, .log = log, - .text = talloc_strdup(sc, ""), + .prelude_text = talloc_strdup(sc, ""), .header_text = talloc_strdup(sc, ""), + .text = talloc_strdup(sc, ""), }; return sc; } void gl_sc_reset(struct gl_shader_cache *sc) { - sc->text[0] = '\0'; + sc->prelude_text[0] = '\0'; sc->header_text[0] = '\0'; + sc->text[0] = '\0'; for (int n = 0; n < sc->num_uniforms; n++) { talloc_free(sc->uniforms[n].name); if (sc->uniforms[n].type == UT_buffer) @@ -567,6 +570,12 @@ void gl_sc_destroy(struct gl_shader_cache *sc) talloc_free(sc); } +void gl_sc_enable_extension(struct gl_shader_cache *sc, char *name) +{ + sc->prelude_text = talloc_asprintf_append(sc->prelude_text, + "#extension %s : enable\n", name); +} + void gl_sc_add(struct gl_shader_cache *sc, const char *text) { sc->text = talloc_strdup_append(sc->text, text); @@ -867,6 +876,7 @@ void gl_sc_gen_shader_and_reset(struct gl_shader_cache *sc) gl->es >= 300 ? " es" : ""); if (gl->es) ADD(header, "precision mediump float;\n"); + ADD(header, "%s", sc->prelude_text); char *vert_in = gl->glsl_version >= 130 ? "in" : "attribute"; char *vert_out = gl->glsl_version >= 130 ? "out" : "varying"; char *frag_in = gl->glsl_version >= 130 ? "in" : "varying"; diff --git a/video/out/opengl/utils.h b/video/out/opengl/utils.h index fa76ee85a8..8808157376 100644 --- a/video/out/opengl/utils.h +++ b/video/out/opengl/utils.h @@ -142,6 +142,7 @@ void gl_sc_uniform_mat3(struct gl_shader_cache *sc, char *name, void gl_sc_uniform_buffer(struct gl_shader_cache *sc, char *name, const char *text, int binding); void gl_sc_set_vao(struct gl_shader_cache *sc, struct gl_vao *vao); +void gl_sc_enable_extension(struct gl_shader_cache *sc, char *name); void gl_sc_gen_shader_and_reset(struct gl_shader_cache *sc); void gl_sc_reset(struct gl_shader_cache *sc); diff --git a/video/out/opengl/video.c b/video/out/opengl/video.c index 2c3a22d1ca..14ad3dee79 100644 --- a/video/out/opengl/video.c +++ b/video/out/opengl/video.c @@ -1213,7 +1213,7 @@ static void pass_prescale(struct gl_video *p, int src_tex_num, int dst_tex_num, p->opts.superxbr_opts, &transform); break; case 2: - pass_nnedi3(p->sc, planes, tex_num, step, + pass_nnedi3(p->gl, p->sc, planes, tex_num, step, p->opts.nnedi3_opts, &transform); break; default: -- cgit v1.2.3