gsk_gl_shader_format_args: Pass arguments by value

Primitive values are now passed by values (although vectors still
by pointer). Also since we can now no longer handle missing definitions
that is an error.
This commit is contained in:
Alexander Larsson
2020-09-28 13:44:44 +02:00
parent 947a933819
commit 796b205958
4 changed files with 25 additions and 25 deletions

View File

@@ -201,7 +201,7 @@ gtk_shader_bin_snapshot (GtkWidget *widget,
gtk_snapshot_push_gl_shader (snapshot, self->active_shader->shader,
&GRAPHENE_RECT_INIT(0, 0, width, height),
gsk_gl_shader_format_args (self->active_shader->shader,
"u_time", &self->time,
"u_time", self->time,
NULL));
gtk_widget_snapshot_child (widget, self->child, snapshot);
gtk_snapshot_gl_shader_pop_texture (snapshot);

View File

@@ -245,7 +245,7 @@ gtk_shader_stack_snapshot (GtkWidget *widget,
self->shader,
&GRAPHENE_RECT_INIT(0, 0, width, height),
gsk_gl_shader_format_args (self->shader,
"progress", &progress,
"progress", progress,
NULL));
gtk_widget_snapshot_child (widget, current, snapshot);

View File

@@ -904,10 +904,13 @@ gsk_gl_shader_get_arg_vec4 (GskGLShader *shader,
* @shader: A #GskGLShader
* @uniforms: Name-Value pairs for the uniforms of @shader, ending with a %NULL name, all values are passed by reference.
*
* Formats the uniform data as needed for feeding the named uniforms values into the shader.
* The argument list is a list of pairs of names, and pointers to data of the types
* that match the declared uniforms (i.e. `float *` for float uniforms and `graphene_vec4_t *` f
* or vec3 uniforms).
* Formats the uniform data as needed for feeding the named uniforms
* values into the shader. The argument list is a list of pairs of
* names, and values for the types that match the declared uniforms
* (i.e. double/int/guint/gboolean for primitive values and
* `graphene_vecN_t *` for vecN uniforms).
*
* It is an error to pass a uniform name that is not declared by the shader
*
* Returns: (transfer full): A newly allocated block of data which can be passed to gsk_gl_shader_node_new().
*/
@@ -921,17 +924,13 @@ gsk_gl_shader_format_args_va (GskGLShader *shader,
while ((name = va_arg (uniforms, const char *)) != NULL)
{
const GskGLUniform *u;
gpointer value = va_arg (uniforms, gpointer);
guchar *args_dest;
u = gsk_gl_shader_find_uniform (shader, name);
if (u == NULL)
{
/* This isn't really an error, because we can easily imaging
a shader interface that have input which isn't needed for
a particular shader */
g_debug ("No uniform named `%s` in shader", name);
continue;
g_warning ("No uniform named `%s` in shader", name);
break;
}
args_dest = args + u->offset;
@@ -942,33 +941,33 @@ gsk_gl_shader_format_args_va (GskGLShader *shader,
switch (u->type)
{
case GSK_GL_UNIFORM_TYPE_FLOAT:
*(float *)args_dest = *(float *)value;
*(float *)args_dest = (float)va_arg (uniforms, double); /* floats are promoted to double in varargs */
break;
case GSK_GL_UNIFORM_TYPE_INT:
*(gint32 *)args_dest = *(gint32 *)value;
*(gint32 *)args_dest = (gint32)va_arg (uniforms, int);
break;
case GSK_GL_UNIFORM_TYPE_UINT:
*(guint32 *)args_dest = *(guint32 *)value;
*(guint32 *)args_dest = (guint32)va_arg (uniforms, guint);
break;
case GSK_GL_UNIFORM_TYPE_BOOL:
*(guint32 *)args_dest = *(gboolean *)value;
*(guint32 *)args_dest = (gboolean)va_arg (uniforms, gboolean);
break;
case GSK_GL_UNIFORM_TYPE_VEC2:
graphene_vec2_to_float ((const graphene_vec2_t *)value,
graphene_vec2_to_float (va_arg (uniforms, const graphene_vec2_t *),
(float *)args_dest);
break;
case GSK_GL_UNIFORM_TYPE_VEC3:
graphene_vec3_to_float ((const graphene_vec3_t *)value,
graphene_vec3_to_float (va_arg (uniforms, const graphene_vec3_t *),
(float *)args_dest);
break;
case GSK_GL_UNIFORM_TYPE_VEC4:
graphene_vec4_to_float ((const graphene_vec4_t *)value,
graphene_vec4_to_float (va_arg (uniforms, const graphene_vec4_t *),
(float *)args_dest);
break;
@@ -986,10 +985,11 @@ gsk_gl_shader_format_args_va (GskGLShader *shader,
* @shader: A #GskGLShader
* @...: Name-Value pairs for the uniforms of @shader, ending with a %NULL name, all values are passed by reference.
*
* Formats the uniform data as needed for feeding the named uniforms values into the shader.
* The argument list is a list of pairs of names, and pointers to data of the types
* that match the declared uniforms (i.e. `float *` for float uniforms and `graphene_vec4_t *` f
* or vec3 uniforms).
* Formats the uniform data as needed for feeding the named uniforms
* values into the shader. The argument list is a list of pairs of
* names, and values for the types that match the declared uniforms
* (i.e. double/int/guint/gboolean for primitive values and
* `graphene_vecN_t *` for vecN uniforms).
*
* Returns: (transfer full): A newly allocated block of data which can be passed to gsk_gl_shader_node_new().
*/

View File

@@ -180,8 +180,8 @@ test_format_args (void)
f1 = 0.5;
f2 = 20.0;
args = gsk_gl_shader_format_args (shader,
"progress", &f1,
"dots", &f2,
"progress", f1,
"dots", f2,
"center", &v2,
"test4", &v3,
"test5", &v4,