Пример #1
0
/**
 * clutter_shader_set_uniform:
 * @shader: a #ClutterShader.
 * @name: name of uniform in GLSL shader program to set.
 * @value: a #ClutterShaderFloat, #ClutterShaderInt or #ClutterShaderMatrix
 *         #GValue.
 *
 * Sets a user configurable variable in the GLSL shader programs attached to
 * a #ClutterShader.
 *
 * Since: 1.0
 */
void
clutter_shader_set_uniform (ClutterShader *shader,
                            const gchar   *name,
                            const GValue  *value)
{
  ClutterShaderPrivate *priv;
  GLint                 location = 0;
  gsize                 size;

  g_return_if_fail (CLUTTER_IS_SHADER (shader));
  g_return_if_fail (name != NULL);
  g_return_if_fail (value != NULL);
  g_return_if_fail (CLUTTER_VALUE_HOLDS_SHADER_FLOAT (value) ||
                    CLUTTER_VALUE_HOLDS_SHADER_INT (value) ||
                    CLUTTER_VALUE_HOLDS_SHADER_MATRIX (value) ||
                    G_VALUE_HOLDS_FLOAT (value) ||
                    G_VALUE_HOLDS_INT (value));

  priv = shader->priv;
  g_return_if_fail (priv->program != COGL_INVALID_HANDLE);

  location = cogl_program_get_uniform_location (priv->program, name);

  if (CLUTTER_VALUE_HOLDS_SHADER_FLOAT (value))
    {
      const GLfloat *floats;

      floats = clutter_value_get_shader_float (value, &size);
      cogl_program_uniform_float (location, size, 1, floats);
    }
  else if (CLUTTER_VALUE_HOLDS_SHADER_INT (value))
    {
      const int *ints;

      ints = clutter_value_get_shader_int (value, &size);
      cogl_program_uniform_int (location, size, 1, ints);
    }
  else if (CLUTTER_VALUE_HOLDS_SHADER_MATRIX (value))
    {
      const GLfloat *matrix;

      matrix = clutter_value_get_shader_matrix (value, &size);
      cogl_program_uniform_matrix (location, size, 1, FALSE, matrix);
    }
  else if (G_VALUE_HOLDS_FLOAT (value))
    {
      GLfloat float_val = g_value_get_float (value);

      cogl_program_uniform_float (location, 1, 1, &float_val);
    }
  else if (G_VALUE_HOLDS_INT (value))
    {
      int int_val = g_value_get_int (value);

      cogl_program_uniform_int (location, 1, 1, &int_val);
    }
  else
    g_assert_not_reached ();
}
Пример #2
0
void
cogl_program_uniform_1i (int uniform_no,
                         gint    value)
{
  cogl_program_uniform_int (uniform_no, 1, 1, &value);
}