cogl-program: Adds use_uniform_xyz methods
Instead of exposing an API that provides an OpenGL state machine style where you first have to bind the program to the context using cogl_program_use() followed by updating uniforms using cogl_program_uniform_xyz we now have uniform setter methods that take an explicit CoglHandle for the program. This deprecates cogl_program_use and all the cogl_program_uniform variants and provides the following replacements: cogl_program_set_uniform_1i cogl_program_set_uniform_1f cogl_program_set_uniform_int cogl_program_set_uniform_float cogl_program_set_uniform_matrix
This commit is contained in:
parent
64b5308d7f
commit
8d80a88e14
@ -258,13 +258,120 @@ int
|
||||
cogl_program_get_uniform_location (CoglHandle handle,
|
||||
const char *uniform_name);
|
||||
|
||||
/**
|
||||
* cogl_program_set_uniform_1f:
|
||||
* @program: A #CoglHandle for a linked program
|
||||
* @uniform_location: the uniform location retrieved from
|
||||
* cogl_program_get_uniform_location().
|
||||
* @value: the new value of the uniform.
|
||||
*
|
||||
* Changes the value of a floating point uniform for the given linked
|
||||
* @program.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_program_set_uniform_1f (CoglHandle program,
|
||||
int uniform_location,
|
||||
float value);
|
||||
|
||||
/**
|
||||
* cogl_program_set_uniform_1i:
|
||||
* @program: A #CoglHandle for a linked program
|
||||
* @uniform_location: the uniform location retrieved from
|
||||
* cogl_program_get_uniform_location().
|
||||
* @value: the new value of the uniform.
|
||||
*
|
||||
* Changes the value of an integer uniform for the given linked
|
||||
* @program.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_program_set_uniform_1i (CoglHandle program,
|
||||
int uniform_location,
|
||||
int value);
|
||||
|
||||
/**
|
||||
* cogl_program_set_uniform_float:
|
||||
* @program: A #CoglHandle for a linked program
|
||||
* @uniform_location: the uniform location retrieved from
|
||||
* cogl_program_get_uniform_location().
|
||||
* @n_components: The number of components for the uniform. For
|
||||
* example with glsl you'd use 3 for a vec3 or 4 for a vec4.
|
||||
* @count: For uniform arrays this is the array length otherwise just
|
||||
* pass 1
|
||||
* @value: (array length=count): the new value of the uniform[s].
|
||||
*
|
||||
* Changes the value of a float vector uniform, or uniform array for
|
||||
* the given linked @program.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_program_set_uniform_float (CoglHandle program,
|
||||
int uniform_location,
|
||||
int n_components,
|
||||
int count,
|
||||
const float *value);
|
||||
|
||||
/**
|
||||
* cogl_program_set_uniform_int:
|
||||
* @program: A #CoglHandle for a linked program
|
||||
* @uniform_location: the uniform location retrieved from
|
||||
* cogl_program_get_uniform_location().
|
||||
* @n_components: The number of components for the uniform. For
|
||||
* example with glsl you'd use 3 for a vec3 or 4 for a vec4.
|
||||
* @count: For uniform arrays this is the array length otherwise just
|
||||
* pass 1
|
||||
* @value: (array length=count): the new value of the uniform[s].
|
||||
*
|
||||
* Changes the value of a int vector uniform, or uniform array for
|
||||
* the given linked @program.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_program_set_uniform_int (CoglHandle program,
|
||||
int uniform_location,
|
||||
int n_components,
|
||||
int count,
|
||||
const int *value);
|
||||
|
||||
/**
|
||||
* cogl_program_set_uniform_matrix:
|
||||
* @program: A #CoglHandle for a linked program
|
||||
* @uniform_location: the uniform location retrieved from
|
||||
* cogl_program_get_uniform_location().
|
||||
* @dimensions: The dimensions of the matrix. So for for example pass
|
||||
* 2 for a 2x2 matrix or 3 for 3x3.
|
||||
* @count: For uniform arrays this is the array length otherwise just
|
||||
* pass 1
|
||||
* @transpose: Whether to transpose the matrix when setting the uniform.
|
||||
* @value: (array length=count): the new value of the uniform.
|
||||
*
|
||||
* Changes the value of a matrix uniform, or uniform array in the
|
||||
* given linked @program.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_program_set_uniform_matrix (CoglHandle program,
|
||||
int uniform_location,
|
||||
int dimensions,
|
||||
int count,
|
||||
gboolean transpose,
|
||||
const float *value);
|
||||
|
||||
/**
|
||||
* cogl_program_uniform_1f:
|
||||
* @uniform_no: the unform to set.
|
||||
* @uniform_no: the uniform to set.
|
||||
* @value: the new value of the uniform.
|
||||
*
|
||||
* Changes the value of a floating point uniform in the currently
|
||||
* used (see cogl_program_use()) shader program.
|
||||
*
|
||||
* Deprecated: 1.4: Use cogl_program_set_uniform_1f() instead.
|
||||
*/
|
||||
void
|
||||
cogl_program_uniform_1f (int uniform_no,
|
||||
@ -272,17 +379,19 @@ cogl_program_uniform_1f (int uniform_no,
|
||||
|
||||
/**
|
||||
* cogl_program_uniform_1i:
|
||||
* @uniform_no: the unform to set.
|
||||
* @uniform_no: the uniform to set.
|
||||
* @value: the new value of the uniform.
|
||||
*
|
||||
* Changes the value of an integer uniform in the currently
|
||||
* used (see cogl_program_use()) shader program.
|
||||
*
|
||||
* Deprecated: 1.4: Use cogl_program_set_uniform_1i() instead.
|
||||
*/
|
||||
void
|
||||
cogl_program_uniform_1i (int uniform_no,
|
||||
int value);
|
||||
|
||||
/**
|
||||
/**
|
||||
* cogl_program_uniform_float:
|
||||
* @uniform_no: the uniform to set.
|
||||
* @size: Size of float vector.
|
||||
@ -291,12 +400,14 @@ cogl_program_uniform_1i (int uniform_no,
|
||||
*
|
||||
* Changes the value of a float vector uniform, or uniform array in the
|
||||
* currently used (see cogl_program_use()) shader program.
|
||||
*
|
||||
* Deprecated: 1.4: Use cogl_program_set_uniform_float() instead.
|
||||
*/
|
||||
void
|
||||
cogl_program_uniform_float (int uniform_no,
|
||||
int size,
|
||||
int count,
|
||||
const GLfloat *value);
|
||||
const float *value);
|
||||
|
||||
/**
|
||||
* cogl_program_uniform_int:
|
||||
|
@ -269,65 +269,77 @@ cogl_program_get_uniform_location (CoglHandle handle,
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_uniform_1f (int uniform_no,
|
||||
float value)
|
||||
cogl_program_set_uniform_1f (CoglHandle handle,
|
||||
int uniform_location,
|
||||
float value)
|
||||
{
|
||||
CoglProgram *program;
|
||||
CoglProgram *program = handle;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
program = ctx->current_program;
|
||||
|
||||
g_return_if_fail (program != NULL);
|
||||
|
||||
g_return_if_fail (cogl_is_program (handle));
|
||||
g_return_if_fail (program->language != COGL_SHADER_LANGUAGE_ARBFP);
|
||||
|
||||
_cogl_gl_use_program_wrapper (program);
|
||||
|
||||
GE (glUniform1f (uniform_no, value));
|
||||
GE (glUniform1f (uniform_location, value));
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_uniform_1i (int uniform_no,
|
||||
int value)
|
||||
cogl_program_uniform_1f (int uniform_location,
|
||||
float value)
|
||||
{
|
||||
CoglProgram *program;
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
cogl_program_set_uniform_1f (ctx->current_program,
|
||||
uniform_location, value);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_set_uniform_1i (CoglHandle handle,
|
||||
int uniform_location,
|
||||
int value)
|
||||
{
|
||||
CoglProgram *program = handle;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
program = ctx->current_program;
|
||||
|
||||
g_return_if_fail (program != NULL);
|
||||
|
||||
g_return_if_fail (cogl_is_program (handle));
|
||||
g_return_if_fail (program->language != COGL_SHADER_LANGUAGE_ARBFP);
|
||||
|
||||
_cogl_gl_use_program_wrapper (program);
|
||||
|
||||
GE (glUniform1i (uniform_no, value));
|
||||
GE (glUniform1i (uniform_location, value));
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_uniform_float (int uniform_no,
|
||||
int size,
|
||||
int count,
|
||||
const GLfloat *value)
|
||||
cogl_program_uniform_1i (int uniform_location,
|
||||
int value)
|
||||
{
|
||||
CoglProgram *program;
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
cogl_program_set_uniform_1i (ctx->current_program, uniform_location, value);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_set_uniform_float (CoglHandle handle,
|
||||
int uniform_location,
|
||||
int n_components,
|
||||
int count,
|
||||
const float *value)
|
||||
{
|
||||
CoglProgram *program = handle;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
program = ctx->current_program;
|
||||
|
||||
g_return_if_fail (program != NULL);
|
||||
g_return_if_fail (cogl_is_program (handle));
|
||||
|
||||
if (program->language == COGL_SHADER_LANGUAGE_ARBFP)
|
||||
{
|
||||
unsigned int _index = uniform_no;
|
||||
unsigned int _index = uniform_location;
|
||||
unsigned int index_end = _index + count;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
g_return_if_fail (size == 4);
|
||||
g_return_if_fail (n_components == 4);
|
||||
|
||||
GE (glBindProgram (GL_FRAGMENT_PROGRAM_ARB, program->gl_handle));
|
||||
|
||||
@ -344,19 +356,19 @@ cogl_program_uniform_float (int uniform_no,
|
||||
{
|
||||
_cogl_gl_use_program_wrapper (program);
|
||||
|
||||
switch (size)
|
||||
switch (n_components)
|
||||
{
|
||||
case 1:
|
||||
GE (glUniform1fv (uniform_no, count, value));
|
||||
GE (glUniform1fv (uniform_location, count, value));
|
||||
break;
|
||||
case 2:
|
||||
GE (glUniform2fv (uniform_no, count, value));
|
||||
GE (glUniform2fv (uniform_location, count, value));
|
||||
break;
|
||||
case 3:
|
||||
GE (glUniform3fv (uniform_no, count, value));
|
||||
GE (glUniform3fv (uniform_location, count, value));
|
||||
break;
|
||||
case 4:
|
||||
GE (glUniform4fv (uniform_no, count, value));
|
||||
GE (glUniform4fv (uniform_location, count, value));
|
||||
break;
|
||||
default:
|
||||
g_warning ("%s called with invalid size parameter", G_STRFUNC);
|
||||
@ -365,34 +377,45 @@ cogl_program_uniform_float (int uniform_no,
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_uniform_int (int uniform_no,
|
||||
int size,
|
||||
int count,
|
||||
const int *value)
|
||||
cogl_program_uniform_float (int uniform_location,
|
||||
int n_components,
|
||||
int count,
|
||||
const float *value)
|
||||
{
|
||||
CoglProgram *program;
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
cogl_program_set_uniform_float (ctx->current_program,
|
||||
uniform_location,
|
||||
n_components, count, value);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_set_uniform_int (CoglHandle handle,
|
||||
int uniform_location,
|
||||
int n_components,
|
||||
int count,
|
||||
const int *value)
|
||||
{
|
||||
CoglProgram *program = handle;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
program = ctx->current_program;
|
||||
|
||||
g_return_if_fail (program != NULL);
|
||||
g_return_if_fail (cogl_is_program (handle));
|
||||
|
||||
_cogl_gl_use_program_wrapper (program);
|
||||
|
||||
switch (size)
|
||||
switch (n_components)
|
||||
{
|
||||
case 1:
|
||||
glUniform1iv (uniform_no, count, value);
|
||||
glUniform1iv (uniform_location, count, value);
|
||||
break;
|
||||
case 2:
|
||||
glUniform2iv (uniform_no, count, value);
|
||||
glUniform2iv (uniform_location, count, value);
|
||||
break;
|
||||
case 3:
|
||||
glUniform3iv (uniform_no, count, value);
|
||||
glUniform3iv (uniform_location, count, value);
|
||||
break;
|
||||
case 4:
|
||||
glUniform4iv (uniform_no, count, value);
|
||||
glUniform4iv (uniform_location, count, value);
|
||||
break;
|
||||
default:
|
||||
g_warning ("%s called with invalid size parameter", G_STRFUNC);
|
||||
@ -400,40 +423,62 @@ cogl_program_uniform_int (int uniform_no,
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_uniform_matrix (int uniform_no,
|
||||
int size,
|
||||
int count,
|
||||
gboolean transpose,
|
||||
const GLfloat *value)
|
||||
cogl_program_uniform_int (int uniform_location,
|
||||
int n_components,
|
||||
int count,
|
||||
const int *value)
|
||||
{
|
||||
CoglProgram *program;
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
cogl_program_set_uniform_int (ctx->current_program,
|
||||
uniform_location, n_components, count, value);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_set_uniform_matrix (CoglHandle handle,
|
||||
int uniform_location,
|
||||
int n_components,
|
||||
int count,
|
||||
gboolean transpose,
|
||||
const float*value)
|
||||
{
|
||||
CoglProgram *program = handle;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
program = ctx->current_program;
|
||||
|
||||
g_return_if_fail (program != NULL);
|
||||
|
||||
g_return_if_fail (cogl_is_program (handle));
|
||||
g_return_if_fail (program->language != COGL_SHADER_LANGUAGE_ARBFP);
|
||||
|
||||
_cogl_gl_use_program_wrapper (program);
|
||||
|
||||
switch (size)
|
||||
switch (n_components)
|
||||
{
|
||||
case 2 :
|
||||
GE (glUniformMatrix2fv (uniform_no, count, transpose, value));
|
||||
GE (glUniformMatrix2fv (uniform_location, count, transpose, value));
|
||||
break;
|
||||
case 3 :
|
||||
GE (glUniformMatrix3fv (uniform_no, count, transpose, value));
|
||||
GE (glUniformMatrix3fv (uniform_location, count, transpose, value));
|
||||
break;
|
||||
case 4 :
|
||||
GE (glUniformMatrix4fv (uniform_no, count, transpose, value));
|
||||
GE (glUniformMatrix4fv (uniform_location, count, transpose, value));
|
||||
break;
|
||||
default :
|
||||
g_warning ("%s called with invalid size parameter", G_STRFUNC);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_uniform_matrix (int uniform_location,
|
||||
int dimensions,
|
||||
int count,
|
||||
gboolean transpose,
|
||||
const float *value)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
cogl_program_set_uniform_matrix (ctx->current_program,
|
||||
uniform_location, dimensions,
|
||||
count, transpose, value);
|
||||
}
|
||||
|
||||
CoglShaderLanguage
|
||||
_cogl_program_get_language (CoglHandle handle)
|
||||
{
|
||||
|
@ -166,34 +166,20 @@ cogl_program_get_uniform_location (CoglHandle handle,
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_uniform_1f (int uniform_no,
|
||||
float value)
|
||||
{
|
||||
cogl_program_uniform_float (uniform_no, 1, 1, &value);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_uniform_1i (int uniform_no,
|
||||
int value)
|
||||
{
|
||||
cogl_program_uniform_int (uniform_no, 1, 1, &value);
|
||||
}
|
||||
|
||||
static void
|
||||
cogl_program_uniform_x (int uniform_no,
|
||||
cogl_program_uniform_x (CoglHandle handle,
|
||||
int uniform_no,
|
||||
int size,
|
||||
int count,
|
||||
CoglBoxedType type,
|
||||
gsize value_size,
|
||||
gconstpointer value)
|
||||
{
|
||||
CoglProgram *program;
|
||||
CoglProgram *program = handle;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
program = ctx->current_program;
|
||||
|
||||
g_return_if_fail (cogl_is_program (handle));
|
||||
g_return_if_fail (program != NULL);
|
||||
|
||||
if (uniform_no >= 0 && uniform_no < COGL_PROGRAM_NUM_CUSTOM_UNIFORMS
|
||||
@ -232,48 +218,125 @@ cogl_program_uniform_x (int uniform_no,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_uniform_1f (int uniform_no,
|
||||
float value)
|
||||
{
|
||||
cogl_program_uniform_float (uniform_no, 1, 1, &value);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_set_uniform_1f (CoglHandle handle,
|
||||
int uniform_location,
|
||||
float value)
|
||||
{
|
||||
cogl_program_uniform_x (handle,
|
||||
uniform_location, 1, 1, COGL_BOXED_FLOAT,
|
||||
sizeof (float), &value);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_uniform_1i (int uniform_no,
|
||||
int value)
|
||||
{
|
||||
cogl_program_uniform_int (uniform_no, 1, 1, &value);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_set_uniform_1i (CoglHandle handle,
|
||||
int uniform_location,
|
||||
int value)
|
||||
{
|
||||
cogl_program_uniform_x (handle,
|
||||
uniform_location, 1, 1, COGL_BOXED_INT,
|
||||
sizeof (int), &value);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_uniform_float (int uniform_no,
|
||||
int size,
|
||||
int count,
|
||||
const GLfloat *value)
|
||||
{
|
||||
cogl_program_uniform_x (uniform_no, size, count, COGL_BOXED_FLOAT,
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
cogl_program_uniform_x (ctx->current_program,
|
||||
uniform_no, size, count, COGL_BOXED_FLOAT,
|
||||
sizeof (float) * size, value);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_set_uniform_float (CoglHandle handle,
|
||||
int uniform_location,
|
||||
int n_components,
|
||||
int count,
|
||||
const float *value)
|
||||
{
|
||||
cogl_program_uniform_x (handle,
|
||||
uniform_location, n_components, count,
|
||||
COGL_BOXED_FLOAT,
|
||||
sizeof (float) * n_components, value);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_uniform_int (int uniform_no,
|
||||
int size,
|
||||
int count,
|
||||
const GLint *value)
|
||||
{
|
||||
cogl_program_uniform_x (uniform_no, size, count, COGL_BOXED_INT,
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
cogl_program_uniform_x (ctx->current_program,
|
||||
uniform_no, size, count, COGL_BOXED_INT,
|
||||
sizeof (int) * size, value);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_set_uniform_int (CoglHandle handle,
|
||||
int uniform_location,
|
||||
int n_components,
|
||||
int count,
|
||||
const int *value)
|
||||
{
|
||||
cogl_program_uniform_x (handle,
|
||||
uniform_location, n_components, count,
|
||||
COGL_BOXED_INT,
|
||||
sizeof (int) * n_components, value);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_set_uniform_matrix (CoglHandle handle,
|
||||
int uniform_location,
|
||||
int dimensions,
|
||||
int count,
|
||||
gboolean transpose,
|
||||
const float *value)
|
||||
{
|
||||
CoglProgram *program = handle;
|
||||
CoglBoxedValue *bv;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
g_return_if_fail (cogl_is_program (handle));
|
||||
|
||||
bv = program->custom_uniforms + uniform_location;
|
||||
|
||||
cogl_program_uniform_x (ctx->current_program,
|
||||
uniform_location, dimensions, count,
|
||||
COGL_BOXED_MATRIX,
|
||||
sizeof (float) * dimensions * dimensions , value);
|
||||
|
||||
bv->transpose = transpose;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_uniform_matrix (int uniform_no,
|
||||
int size,
|
||||
int count,
|
||||
gboolean transpose,
|
||||
const GLfloat *value)
|
||||
const float *value)
|
||||
{
|
||||
CoglProgram *program;
|
||||
CoglBoxedValue *bv;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
program = ctx->current_program;
|
||||
|
||||
g_return_if_fail (program != NULL);
|
||||
|
||||
bv = program->custom_uniforms + uniform_no;
|
||||
|
||||
cogl_program_uniform_x (uniform_no, size, count, COGL_BOXED_MATRIX,
|
||||
sizeof (float) * size * size, value);
|
||||
|
||||
bv->transpose = transpose;
|
||||
cogl_program_set_uniform_matrix (ctx->current_program,
|
||||
uniform_no, size, count, transpose, value);
|
||||
}
|
||||
|
||||
#else /* HAVE_COGL_GLES2 */
|
||||
|
@ -263,6 +263,11 @@ cogl_program_attach_shader
|
||||
cogl_program_link
|
||||
cogl_program_use
|
||||
cogl_program_get_uniform_location
|
||||
cogl_program_set_uniform_1f
|
||||
cogl_program_set_uniform_1i
|
||||
cogl_program_set_uniform_float
|
||||
cogl_program_set_uniform_int
|
||||
cogl_program_set_uniform_matrix
|
||||
cogl_program_uniform_1f
|
||||
cogl_program_uniform_1i
|
||||
cogl_program_uniform_float
|
||||
|
Loading…
Reference in New Issue
Block a user