diff options
author | Robert Bragg <robert@linux.intel.com> | 2010-08-11 19:18:14 +0100 |
---|---|---|
committer | Robert Bragg <robert@linux.intel.com> | 2010-08-12 16:50:46 +0100 |
commit | 8d80a88e148419c0b2be9a7cdea6c6638d3f921e (patch) | |
tree | 6636288e0833a10275cefa978817a116e48f05ed /cogl/driver | |
parent | 64b5308d7fe2d80ae4d6ae4e04b7150ae76dec7e (diff) | |
download | cogl-8d80a88e148419c0b2be9a7cdea6c6638d3f921e.tar.gz |
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
Diffstat (limited to 'cogl/driver')
-rw-r--r-- | cogl/driver/gl/cogl-program.c | 157 | ||||
-rw-r--r-- | cogl/driver/gles/cogl-program.c | 127 |
2 files changed, 196 insertions, 88 deletions
diff --git a/cogl/driver/gl/cogl-program.c b/cogl/driver/gl/cogl-program.c index 7b808b9c..20dec0a2 100644 --- a/cogl/driver/gl/cogl-program.c +++ b/cogl/driver/gl/cogl-program.c @@ -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); +} - program = ctx->current_program; +void +cogl_program_set_uniform_1i (CoglHandle handle, + int uniform_location, + int value) +{ + CoglProgram *program = handle; - g_return_if_fail (program != NULL); + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + 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); +} - program = ctx->current_program; +void +cogl_program_set_uniform_float (CoglHandle handle, + int uniform_location, + int n_components, + int count, + const float *value) +{ + CoglProgram *program = handle; - g_return_if_fail (program != NULL); + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + + 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); +} - program = ctx->current_program; +void +cogl_program_set_uniform_int (CoglHandle handle, + int uniform_location, + int n_components, + int count, + const int *value) +{ + CoglProgram *program = handle; - g_return_if_fail (program != NULL); + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + + 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); +} - program = ctx->current_program; +void +cogl_program_set_uniform_matrix (CoglHandle handle, + int uniform_location, + int n_components, + int count, + gboolean transpose, + const float*value) +{ + CoglProgram *program = handle; - g_return_if_fail (program != NULL); + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + 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) { diff --git a/cogl/driver/gles/cogl-program.c b/cogl/driver/gles/cogl-program.c index a99fbcd5..50715613 100644 --- a/cogl/driver/gles/cogl-program.c +++ b/cogl/driver/gles/cogl-program.c @@ -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 @@ -233,49 +219,126 @@ 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_uniform_matrix (int uniform_no, - int size, - int count, - gboolean transpose, - const GLfloat *value) +cogl_program_set_uniform_int (CoglHandle handle, + int uniform_location, + int n_components, + int count, + const int *value) { - CoglProgram *program; + 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); - program = ctx->current_program; - - g_return_if_fail (program != NULL); + g_return_if_fail (cogl_is_program (handle)); - bv = program->custom_uniforms + uniform_no; + bv = program->custom_uniforms + uniform_location; - cogl_program_uniform_x (uniform_no, size, count, COGL_BOXED_MATRIX, - sizeof (float) * size * size, value); + 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 float *value) +{ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + cogl_program_set_uniform_matrix (ctx->current_program, + uniform_no, size, count, transpose, value); +} + #else /* HAVE_COGL_GLES2 */ /* No support on regular OpenGL 1.1 */ |