2010-10-15 13:00:29 -04:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2010-10-15 13:00:29 -04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2008,2009,2010 Intel Corporation.
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2010-10-15 13:00:29 -04:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2010-10-15 13:00:29 -04:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2010-10-15 13:00:29 -04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-10-13 17:34:30 -04:00
|
|
|
#include "cogl-util.h"
|
2013-01-20 13:47:40 -05:00
|
|
|
#include "cogl-util-gl-private.h"
|
2010-11-04 18:25:52 -04:00
|
|
|
#include "cogl-context-private.h"
|
2012-04-16 09:14:10 -04:00
|
|
|
#include "cogl-object-private.h"
|
2010-10-15 13:00:29 -04:00
|
|
|
|
|
|
|
#include "cogl-shader-private.h"
|
|
|
|
#include "cogl-program-private.h"
|
|
|
|
|
2011-01-17 07:21:33 -05:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-10-15 13:00:29 -04:00
|
|
|
static void _cogl_program_free (CoglProgram *program);
|
|
|
|
|
|
|
|
COGL_HANDLE_DEFINE (Program, program);
|
|
|
|
COGL_OBJECT_DEFINE_DEPRECATED_REF_COUNTING (program);
|
|
|
|
|
|
|
|
/* A CoglProgram is effectively just a list of shaders that will be
|
|
|
|
used together and a set of values for the custom uniforms. No
|
|
|
|
actual GL program is created - instead this is the responsibility
|
|
|
|
of the GLSL material backend. The uniform values are collected in
|
|
|
|
an array and then flushed whenever the material backend requests
|
|
|
|
it. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_program_free (CoglProgram *program)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
/* Unref all of the attached shaders */
|
|
|
|
g_slist_foreach (program->attached_shaders, (GFunc) cogl_handle_unref, NULL);
|
|
|
|
/* Destroy the list */
|
|
|
|
g_slist_free (program->attached_shaders);
|
|
|
|
|
|
|
|
for (i = 0; i < program->custom_uniforms->len; i++)
|
|
|
|
{
|
|
|
|
CoglProgramUniform *uniform =
|
|
|
|
&g_array_index (program->custom_uniforms, CoglProgramUniform, i);
|
|
|
|
|
|
|
|
g_free (uniform->name);
|
|
|
|
|
|
|
|
if (uniform->value.count > 1)
|
|
|
|
g_free (uniform->value.v.array);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_array_free (program->custom_uniforms, TRUE);
|
|
|
|
|
|
|
|
g_slice_free (CoglProgram, program);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglHandle
|
|
|
|
cogl_create_program (void)
|
|
|
|
{
|
|
|
|
CoglProgram *program;
|
|
|
|
|
|
|
|
program = g_slice_new0 (CoglProgram);
|
|
|
|
|
|
|
|
program->custom_uniforms =
|
|
|
|
g_array_new (FALSE, FALSE, sizeof (CoglProgramUniform));
|
|
|
|
program->age = 0;
|
|
|
|
|
|
|
|
return _cogl_program_handle_new (program);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_program_attach_shader (CoglHandle program_handle,
|
|
|
|
CoglHandle shader_handle)
|
|
|
|
{
|
|
|
|
CoglProgram *program;
|
|
|
|
CoglShader *shader;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
if (!cogl_is_program (program_handle) || !cogl_is_shader (shader_handle))
|
|
|
|
return;
|
|
|
|
|
2012-03-06 13:21:28 -05:00
|
|
|
program = program_handle;
|
|
|
|
shader = shader_handle;
|
2010-10-15 13:00:29 -04:00
|
|
|
|
|
|
|
/* Only one shader is allowed if the type is ARBfp */
|
|
|
|
if (shader->language == COGL_SHADER_LANGUAGE_ARBFP)
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (program->attached_shaders == NULL);
|
2010-10-15 13:00:29 -04:00
|
|
|
else if (shader->language == COGL_SHADER_LANGUAGE_GLSL)
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (_cogl_program_get_language (program) ==
|
2010-10-15 13:00:29 -04:00
|
|
|
COGL_SHADER_LANGUAGE_GLSL);
|
|
|
|
|
|
|
|
program->attached_shaders
|
|
|
|
= g_slist_prepend (program->attached_shaders,
|
|
|
|
cogl_handle_ref (shader_handle));
|
|
|
|
|
|
|
|
program->age++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_program_link (CoglHandle handle)
|
|
|
|
{
|
|
|
|
/* There's no point in linking the program here because it will have
|
|
|
|
to be relinked with a different fixed functionality shader
|
|
|
|
whenever the settings change */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_program_use (CoglHandle handle)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (handle == COGL_INVALID_HANDLE ||
|
2010-10-15 13:00:29 -04:00
|
|
|
cogl_is_program (handle));
|
|
|
|
|
|
|
|
if (ctx->current_program == 0 && handle != 0)
|
|
|
|
ctx->legacy_state_set++;
|
|
|
|
else if (handle == 0 && ctx->current_program != 0)
|
|
|
|
ctx->legacy_state_set--;
|
|
|
|
|
|
|
|
if (handle != COGL_INVALID_HANDLE)
|
|
|
|
cogl_handle_ref (handle);
|
|
|
|
if (ctx->current_program != COGL_INVALID_HANDLE)
|
|
|
|
cogl_handle_unref (ctx->current_program);
|
|
|
|
ctx->current_program = handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cogl_program_get_uniform_location (CoglHandle handle,
|
|
|
|
const char *uniform_name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
CoglProgram *program;
|
|
|
|
CoglProgramUniform *uniform;
|
|
|
|
|
|
|
|
if (!cogl_is_program (handle))
|
|
|
|
return -1;
|
|
|
|
|
2012-03-06 13:21:28 -05:00
|
|
|
program = handle;
|
2010-10-15 13:00:29 -04:00
|
|
|
|
|
|
|
/* We can't just ask the GL program object for the uniform location
|
|
|
|
directly because it will change every time the program is linked
|
|
|
|
with a different shader. Instead we make our own mapping of
|
|
|
|
uniform numbers and cache the names */
|
|
|
|
for (i = 0; i < program->custom_uniforms->len; i++)
|
|
|
|
{
|
|
|
|
uniform = &g_array_index (program->custom_uniforms,
|
|
|
|
CoglProgramUniform, i);
|
|
|
|
|
|
|
|
if (!strcmp (uniform->name, uniform_name))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a new uniform with the given name */
|
|
|
|
g_array_set_size (program->custom_uniforms,
|
|
|
|
program->custom_uniforms->len + 1);
|
|
|
|
uniform = &g_array_index (program->custom_uniforms,
|
|
|
|
CoglProgramUniform,
|
|
|
|
program->custom_uniforms->len - 1);
|
|
|
|
|
|
|
|
uniform->name = g_strdup (uniform_name);
|
|
|
|
memset (&uniform->value, 0, sizeof (CoglBoxedValue));
|
|
|
|
uniform->dirty = TRUE;
|
|
|
|
uniform->location_valid = FALSE;
|
|
|
|
|
|
|
|
return program->custom_uniforms->len - 1;
|
|
|
|
}
|
|
|
|
|
2011-10-27 11:54:50 -04:00
|
|
|
static CoglProgramUniform *
|
|
|
|
cogl_program_modify_uniform (CoglProgram *program,
|
|
|
|
int uniform_no)
|
2010-10-15 13:00:29 -04:00
|
|
|
{
|
2011-10-27 11:54:50 -04:00
|
|
|
CoglProgramUniform *uniform;
|
2010-10-15 13:00:29 -04:00
|
|
|
|
2011-10-27 11:54:50 -04:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (cogl_is_program (program), NULL);
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (uniform_no >= 0 &&
|
|
|
|
uniform_no < program->custom_uniforms->len,
|
|
|
|
NULL);
|
2010-10-15 13:00:29 -04:00
|
|
|
|
2011-10-27 11:54:50 -04:00
|
|
|
uniform = &g_array_index (program->custom_uniforms,
|
|
|
|
CoglProgramUniform, uniform_no);
|
|
|
|
uniform->dirty = TRUE;
|
2010-10-15 13:00:29 -04:00
|
|
|
|
2011-10-27 11:54:50 -04:00
|
|
|
return uniform;
|
2010-10-15 13:00:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_program_uniform_1f (int uniform_no,
|
|
|
|
float value)
|
|
|
|
{
|
2011-10-27 11:54:50 -04:00
|
|
|
CoglProgramUniform *uniform;
|
|
|
|
|
2010-10-15 13:00:29 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2011-10-27 11:54:50 -04:00
|
|
|
|
|
|
|
uniform = cogl_program_modify_uniform (ctx->current_program, uniform_no);
|
|
|
|
_cogl_boxed_value_set_1f (&uniform->value, value);
|
2010-10-15 13:00:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_program_set_uniform_1f (CoglHandle handle,
|
|
|
|
int uniform_location,
|
|
|
|
float value)
|
|
|
|
{
|
2011-10-27 11:54:50 -04:00
|
|
|
CoglProgramUniform *uniform;
|
|
|
|
|
|
|
|
uniform = cogl_program_modify_uniform (handle, uniform_location);
|
|
|
|
_cogl_boxed_value_set_1f (&uniform->value, value);
|
2010-10-15 13:00:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_program_uniform_1i (int uniform_no,
|
|
|
|
int value)
|
|
|
|
{
|
2011-10-27 11:54:50 -04:00
|
|
|
CoglProgramUniform *uniform;
|
|
|
|
|
2010-10-15 13:00:29 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2011-10-27 11:54:50 -04:00
|
|
|
|
|
|
|
uniform = cogl_program_modify_uniform (ctx->current_program, uniform_no);
|
|
|
|
_cogl_boxed_value_set_1i (&uniform->value, value);
|
2010-10-15 13:00:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_program_set_uniform_1i (CoglHandle handle,
|
|
|
|
int uniform_location,
|
|
|
|
int value)
|
|
|
|
{
|
2011-10-27 11:54:50 -04:00
|
|
|
CoglProgramUniform *uniform;
|
|
|
|
|
|
|
|
uniform = cogl_program_modify_uniform (handle, uniform_location);
|
|
|
|
_cogl_boxed_value_set_1i (&uniform->value, value);
|
2010-10-15 13:00:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_program_uniform_float (int uniform_no,
|
|
|
|
int size,
|
|
|
|
int count,
|
2011-10-27 11:54:50 -04:00
|
|
|
const float *value)
|
2010-10-15 13:00:29 -04:00
|
|
|
{
|
2011-10-27 11:54:50 -04:00
|
|
|
CoglProgramUniform *uniform;
|
|
|
|
|
2010-10-15 13:00:29 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2011-10-27 11:54:50 -04:00
|
|
|
|
|
|
|
uniform = cogl_program_modify_uniform (ctx->current_program, uniform_no);
|
|
|
|
_cogl_boxed_value_set_float (&uniform->value, size, count, value);
|
2010-10-15 13:00:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_program_set_uniform_float (CoglHandle handle,
|
|
|
|
int uniform_location,
|
|
|
|
int n_components,
|
|
|
|
int count,
|
|
|
|
const float *value)
|
|
|
|
{
|
2011-10-27 11:54:50 -04:00
|
|
|
CoglProgramUniform *uniform;
|
|
|
|
|
|
|
|
uniform = cogl_program_modify_uniform (handle, uniform_location);
|
|
|
|
_cogl_boxed_value_set_float (&uniform->value, n_components, count, value);
|
2010-10-15 13:00:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_program_uniform_int (int uniform_no,
|
|
|
|
int size,
|
|
|
|
int count,
|
2011-10-27 11:54:50 -04:00
|
|
|
const int *value)
|
2010-10-15 13:00:29 -04:00
|
|
|
{
|
2011-10-27 11:54:50 -04:00
|
|
|
CoglProgramUniform *uniform;
|
|
|
|
|
2010-10-15 13:00:29 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2011-10-27 11:54:50 -04:00
|
|
|
|
|
|
|
uniform = cogl_program_modify_uniform (ctx->current_program, uniform_no);
|
|
|
|
_cogl_boxed_value_set_int (&uniform->value, size, count, value);
|
2010-10-15 13:00:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_program_set_uniform_int (CoglHandle handle,
|
|
|
|
int uniform_location,
|
|
|
|
int n_components,
|
|
|
|
int count,
|
|
|
|
const int *value)
|
|
|
|
{
|
2011-10-27 11:54:50 -04:00
|
|
|
CoglProgramUniform *uniform;
|
|
|
|
|
|
|
|
uniform = cogl_program_modify_uniform (handle, uniform_location);
|
|
|
|
_cogl_boxed_value_set_int (&uniform->value, n_components, count, value);
|
2010-10-15 13:00:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_program_set_uniform_matrix (CoglHandle handle,
|
|
|
|
int uniform_location,
|
|
|
|
int dimensions,
|
|
|
|
int count,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
CoglBool transpose,
|
2010-10-15 13:00:29 -04:00
|
|
|
const float *value)
|
|
|
|
{
|
2011-10-27 11:54:50 -04:00
|
|
|
CoglProgramUniform *uniform;
|
|
|
|
|
|
|
|
uniform = cogl_program_modify_uniform (handle, uniform_location);
|
|
|
|
_cogl_boxed_value_set_matrix (&uniform->value,
|
|
|
|
dimensions,
|
|
|
|
count,
|
|
|
|
transpose,
|
|
|
|
value);
|
2010-10-15 13:00:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_program_uniform_matrix (int uniform_no,
|
|
|
|
int size,
|
|
|
|
int count,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
CoglBool transpose,
|
2010-10-15 13:00:29 -04:00
|
|
|
const float *value)
|
|
|
|
{
|
2011-10-27 11:54:50 -04:00
|
|
|
CoglProgramUniform *uniform;
|
|
|
|
|
2010-10-15 13:00:29 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2011-10-27 11:54:50 -04:00
|
|
|
|
|
|
|
uniform = cogl_program_modify_uniform (ctx->current_program, uniform_no);
|
|
|
|
_cogl_boxed_value_set_matrix (&uniform->value, size, count, transpose, value);
|
2010-10-15 13:00:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARBfp local parameters can be referenced like:
|
|
|
|
*
|
|
|
|
* "program.local[5]"
|
|
|
|
* ^14char offset (after whitespace is stripped)
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
get_local_param_index (const char *uniform_name)
|
|
|
|
{
|
|
|
|
char *input = g_strdup (uniform_name);
|
|
|
|
int i;
|
|
|
|
char *p = input;
|
|
|
|
char *endptr;
|
|
|
|
int _index;
|
|
|
|
|
|
|
|
for (i = 0; input[i] != '\0'; i++)
|
|
|
|
if (input[i] != '_' && input[i] != '\t')
|
|
|
|
*p++ = input[i];
|
|
|
|
input[i] = '\0';
|
|
|
|
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (strncmp ("program.local[", input, 14) == 0, -1);
|
2010-10-15 13:00:29 -04:00
|
|
|
|
|
|
|
_index = g_ascii_strtoull (input + 14, &endptr, 10);
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (endptr != input + 14, -1);
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (*endptr == ']', -1);
|
2010-10-15 13:00:29 -04:00
|
|
|
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (_index >= 0, -1);
|
2010-10-15 13:00:29 -04:00
|
|
|
|
|
|
|
g_free (input);
|
|
|
|
|
|
|
|
return _index;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_COGL_GL
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_program_flush_uniform_arbfp (GLint location,
|
|
|
|
CoglBoxedValue *value)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
if (value->type != COGL_BOXED_NONE)
|
|
|
|
{
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (value->type == COGL_BOXED_FLOAT);
|
|
|
|
_COGL_RETURN_IF_FAIL (value->size == 4);
|
|
|
|
_COGL_RETURN_IF_FAIL (value->count == 1);
|
2010-10-15 13:00:29 -04:00
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glProgramLocalParameter4fv (GL_FRAGMENT_PROGRAM_ARB, location,
|
|
|
|
value->v.float_value) );
|
2010-10-15 13:00:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_COGL_GL */
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_program_flush_uniforms (CoglProgram *program,
|
|
|
|
GLuint gl_program,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
CoglBool gl_program_changed)
|
2010-10-15 13:00:29 -04:00
|
|
|
{
|
|
|
|
CoglProgramUniform *uniform;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (ctx->driver != COGL_DRIVER_GLES1);
|
2011-07-07 15:44:56 -04:00
|
|
|
|
2010-10-15 13:00:29 -04:00
|
|
|
for (i = 0; i < program->custom_uniforms->len; i++)
|
|
|
|
{
|
|
|
|
uniform = &g_array_index (program->custom_uniforms,
|
|
|
|
CoglProgramUniform, i);
|
|
|
|
|
|
|
|
if (gl_program_changed || uniform->dirty)
|
|
|
|
{
|
|
|
|
if (gl_program_changed || !uniform->location_valid)
|
|
|
|
{
|
|
|
|
if (_cogl_program_get_language (program) ==
|
|
|
|
COGL_SHADER_LANGUAGE_GLSL)
|
|
|
|
uniform->location =
|
2011-07-06 16:51:00 -04:00
|
|
|
ctx->glGetUniformLocation (gl_program, uniform->name);
|
2010-10-15 13:00:29 -04:00
|
|
|
else
|
|
|
|
uniform->location =
|
|
|
|
get_local_param_index (uniform->name);
|
|
|
|
|
|
|
|
uniform->location_valid = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the uniform isn't really in the program then there's
|
|
|
|
no need to actually set it */
|
|
|
|
if (uniform->location != -1)
|
|
|
|
{
|
|
|
|
switch (_cogl_program_get_language (program))
|
|
|
|
{
|
|
|
|
case COGL_SHADER_LANGUAGE_GLSL:
|
2011-10-27 11:54:50 -04:00
|
|
|
_cogl_boxed_value_set_uniform (ctx,
|
|
|
|
uniform->location,
|
|
|
|
&uniform->value);
|
2010-10-15 13:00:29 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COGL_SHADER_LANGUAGE_ARBFP:
|
2011-07-07 15:44:56 -04:00
|
|
|
#ifdef HAVE_COGL_GL
|
2010-10-15 13:00:29 -04:00
|
|
|
_cogl_program_flush_uniform_arbfp (uniform->location,
|
|
|
|
&uniform->value);
|
|
|
|
#endif
|
2011-07-07 15:44:56 -04:00
|
|
|
break;
|
2010-10-15 13:00:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uniform->dirty = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglShaderLanguage
|
|
|
|
_cogl_program_get_language (CoglHandle handle)
|
|
|
|
{
|
|
|
|
CoglProgram *program = handle;
|
|
|
|
|
|
|
|
/* Use the language of the first shader */
|
|
|
|
|
|
|
|
if (program->attached_shaders)
|
|
|
|
{
|
|
|
|
CoglShader *shader = program->attached_shaders->data;
|
|
|
|
return shader->language;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return COGL_SHADER_LANGUAGE_GLSL;
|
|
|
|
}
|
2010-12-02 08:54:15 -05:00
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2010-12-02 08:54:15 -05:00
|
|
|
_cogl_program_has_shader_type (CoglProgram *program,
|
|
|
|
CoglShaderType type)
|
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
for (l = program->attached_shaders; l; l = l->next)
|
|
|
|
{
|
|
|
|
CoglShader *shader = l->data;
|
|
|
|
|
|
|
|
if (shader->type == type)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
CoglBool
|
2010-12-02 08:54:15 -05:00
|
|
|
_cogl_program_has_fragment_shader (CoglHandle handle)
|
|
|
|
{
|
|
|
|
return _cogl_program_has_shader_type (handle, COGL_SHADER_TYPE_FRAGMENT);
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
CoglBool
|
2010-12-02 08:54:15 -05:00
|
|
|
_cogl_program_has_vertex_shader (CoglHandle handle)
|
|
|
|
{
|
|
|
|
return _cogl_program_has_shader_type (handle, COGL_SHADER_TYPE_VERTEX);
|
|
|
|
}
|