mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 17:20:36 +00:00
gstglshader: cache uniform locations
Avoid redundant calls to glGetUniformLocation. The results can be cached once the shader has been linked.
This commit is contained in:
parent
7e1a42ce55
commit
bc8d272aad
1 changed files with 52 additions and 25 deletions
|
@ -73,6 +73,7 @@ struct _GstGLShaderPrivate
|
|||
GList *stages;
|
||||
|
||||
gboolean linked;
|
||||
GHashTable *uniform_locations;
|
||||
|
||||
GstGLSLFuncs vtable;
|
||||
};
|
||||
|
@ -122,6 +123,7 @@ gst_gl_shader_finalize (GObject * object)
|
|||
(GstGLContextThreadFunc) _cleanup_shader, shader);
|
||||
|
||||
priv->program_handle = 0;
|
||||
g_hash_table_destroy (priv->uniform_locations);
|
||||
|
||||
if (shader->context) {
|
||||
gst_object_unref (shader->context);
|
||||
|
@ -189,6 +191,30 @@ gst_gl_shader_init (GstGLShader * self)
|
|||
priv = self->priv = GST_GL_SHADER_GET_PRIVATE (self);
|
||||
|
||||
priv->linked = FALSE;
|
||||
priv->uniform_locations =
|
||||
g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
_get_uniform_location (GstGLShader * shader, const gchar * name)
|
||||
{
|
||||
GstGLShaderPrivate *priv = shader->priv;
|
||||
int location;
|
||||
gpointer value;
|
||||
|
||||
g_return_val_if_fail (priv->linked, 0);
|
||||
|
||||
if (!g_hash_table_lookup_extended (priv->uniform_locations, name, NULL,
|
||||
&value)) {
|
||||
const GstGLFuncs *gl = shader->context->gl_vtable;
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
g_hash_table_insert (priv->uniform_locations, g_strdup (name),
|
||||
GINT_TO_POINTER (location));
|
||||
} else {
|
||||
location = GPOINTER_TO_INT (value);
|
||||
}
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
static GstGLShader *
|
||||
|
@ -680,6 +706,7 @@ gst_gl_shader_release_unlocked (GstGLShader * shader)
|
|||
shader->priv->stages = NULL;
|
||||
|
||||
priv->linked = FALSE;
|
||||
g_hash_table_remove_all (priv->uniform_locations);
|
||||
|
||||
g_object_notify (G_OBJECT (shader), "linked");
|
||||
}
|
||||
|
@ -763,7 +790,7 @@ gst_gl_shader_set_uniform_1f (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->Uniform1f (location, value);
|
||||
}
|
||||
|
@ -781,7 +808,7 @@ gst_gl_shader_set_uniform_1fv (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->Uniform1fv (location, count, value);
|
||||
}
|
||||
|
@ -799,7 +826,7 @@ gst_gl_shader_set_uniform_1i (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->Uniform1i (location, value);
|
||||
}
|
||||
|
@ -817,7 +844,7 @@ gst_gl_shader_set_uniform_1iv (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->Uniform1iv (location, count, value);
|
||||
}
|
||||
|
@ -835,7 +862,7 @@ gst_gl_shader_set_uniform_2f (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->Uniform2f (location, value0, value1);
|
||||
}
|
||||
|
@ -853,7 +880,7 @@ gst_gl_shader_set_uniform_2fv (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->Uniform2fv (location, count, value);
|
||||
}
|
||||
|
@ -871,7 +898,7 @@ gst_gl_shader_set_uniform_2i (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->Uniform2i (location, v0, v1);
|
||||
}
|
||||
|
@ -889,7 +916,7 @@ gst_gl_shader_set_uniform_2iv (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->Uniform2iv (location, count, value);
|
||||
}
|
||||
|
@ -907,7 +934,7 @@ gst_gl_shader_set_uniform_3f (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->Uniform3f (location, v0, v1, v2);
|
||||
}
|
||||
|
@ -925,7 +952,7 @@ gst_gl_shader_set_uniform_3fv (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->Uniform3fv (location, count, value);
|
||||
}
|
||||
|
@ -943,7 +970,7 @@ gst_gl_shader_set_uniform_3i (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->Uniform3i (location, v0, v1, v2);
|
||||
}
|
||||
|
@ -961,7 +988,7 @@ gst_gl_shader_set_uniform_3iv (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->Uniform3iv (location, count, value);
|
||||
}
|
||||
|
@ -979,7 +1006,7 @@ gst_gl_shader_set_uniform_4f (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->Uniform4f (location, v0, v1, v2, v3);
|
||||
}
|
||||
|
@ -997,7 +1024,7 @@ gst_gl_shader_set_uniform_4fv (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->Uniform4fv (location, count, value);
|
||||
}
|
||||
|
@ -1015,7 +1042,7 @@ gst_gl_shader_set_uniform_4i (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->Uniform4i (location, v0, v1, v2, v3);
|
||||
}
|
||||
|
@ -1033,7 +1060,7 @@ gst_gl_shader_set_uniform_4iv (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->Uniform4iv (location, count, value);
|
||||
}
|
||||
|
@ -1051,7 +1078,7 @@ gst_gl_shader_set_uniform_matrix_2fv (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->UniformMatrix2fv (location, count, transpose, value);
|
||||
}
|
||||
|
@ -1069,7 +1096,7 @@ gst_gl_shader_set_uniform_matrix_3fv (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->UniformMatrix3fv (location, count, transpose, value);
|
||||
}
|
||||
|
@ -1087,7 +1114,7 @@ gst_gl_shader_set_uniform_matrix_4fv (GstGLShader * shader, const gchar * name,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->UniformMatrix4fv (location, count, transpose, value);
|
||||
}
|
||||
|
@ -1106,7 +1133,7 @@ gst_gl_shader_set_uniform_matrix_2x3fv (GstGLShader * shader,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->UniformMatrix2x3fv (location, count, transpose, value);
|
||||
}
|
||||
|
@ -1124,7 +1151,7 @@ gst_gl_shader_set_uniform_matrix_2x4fv (GstGLShader * shader,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->UniformMatrix2x4fv (location, count, transpose, value);
|
||||
}
|
||||
|
@ -1142,7 +1169,7 @@ gst_gl_shader_set_uniform_matrix_3x2fv (GstGLShader * shader,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->UniformMatrix3x2fv (location, count, transpose, value);
|
||||
}
|
||||
|
@ -1160,7 +1187,7 @@ gst_gl_shader_set_uniform_matrix_3x4fv (GstGLShader * shader,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->UniformMatrix3x4fv (location, count, transpose, value);
|
||||
}
|
||||
|
@ -1178,7 +1205,7 @@ gst_gl_shader_set_uniform_matrix_4x2fv (GstGLShader * shader,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->UniformMatrix4x2fv (location, count, transpose, value);
|
||||
}
|
||||
|
@ -1196,7 +1223,7 @@ gst_gl_shader_set_uniform_matrix_4x3fv (GstGLShader * shader,
|
|||
g_return_if_fail (priv->program_handle != 0);
|
||||
gl = shader->context->gl_vtable;
|
||||
|
||||
location = gl->GetUniformLocation (priv->program_handle, name);
|
||||
location = _get_uniform_location (shader, name);
|
||||
|
||||
gl->UniformMatrix4x3fv (location, count, transpose, value);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue