diff options
author | igv <igv@users.noreply.github.com> | 2016-03-02 21:18:01 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-03-09 22:57:05 +0100 |
commit | 95ca308d4494fc010802ed79fad5a9f85d9a5730 (patch) | |
tree | f0ae8a1344caddcddc315d58d3fe833cffacf807 | |
parent | 876a3bafc5a0cb491ee1f1d5e928cd6e6ef530a8 (diff) | |
download | mpv-95ca308d4494fc010802ed79fad5a9f85d9a5730.tar.bz2 mpv-95ca308d4494fc010802ed79fad5a9f85d9a5730.tar.xz |
vo_opengl: cache the locations of the uniform variables
-rw-r--r-- | video/out/opengl/utils.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/video/out/opengl/utils.c b/video/out/opengl/utils.c index 02f1ea6584..288e552521 100644 --- a/video/out/opengl/utils.c +++ b/video/out/opengl/utils.c @@ -544,6 +544,7 @@ struct sc_uniform { struct sc_entry { GLuint gl_shader; + GLint uniform_locs[SC_UNIFORM_ENTRIES]; // the following fields define the shader's contents char *key; // vertex+frag shader (mangled) struct gl_vao *vao; @@ -797,14 +798,13 @@ static const char *vao_glsl_type(const struct gl_vao_entry *e) } // Assumes program is current (gl->UseProgram(program)). -static void update_uniform(GL *gl, GLuint program, struct sc_uniform *u) +static void update_uniform(GL *gl, GLuint program, struct sc_uniform *u, GLint loc) { if (u->type == UT_buffer) { GLuint idx = gl->GetUniformBlockIndex(program, u->name); gl->UniformBlockBinding(program, idx, u->v.buffer.binding); return; } - GLint loc = gl->GetUniformLocation(program, u->name); if (loc < 0) return; switch (u->type) { @@ -1008,16 +1008,23 @@ void gl_sc_gen_shader_and_reset(struct gl_shader_cache *sc) entry = &sc->entries[sc->num_entries++]; *entry = (struct sc_entry){.key = talloc_strdup(NULL, key)}; } - // build vertex shader from vao - if (!entry->gl_shader) + // build vertex shader from vao and cache the locations of the uniform variables + if (!entry->gl_shader) { entry->gl_shader = create_program(sc, vert, frag); + for (int n = 0; n < sc->num_uniforms; n++) { + entry->uniform_locs[n] = gl->GetUniformLocation(entry->gl_shader, + sc->uniforms[n].name); + } + } gl->UseProgram(entry->gl_shader); // For now we set the uniforms every time. This is probably bad, and we // should switch to caching them. - for (int n = 0; n < sc->num_uniforms; n++) - update_uniform(gl, entry->gl_shader, &sc->uniforms[n]); + for (int n = 0; n < sc->num_uniforms; n++) { + update_uniform(gl, entry->gl_shader, &sc->uniforms[n], + entry->uniform_locs[n]); + } talloc_free(tmp); |