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.
This commit is contained in:
wm4
2015-11-09 16:24:01 +01:00
parent caa497ee8a
commit eeb5f98758
5 changed files with 19 additions and 6 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -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: