2010-12-02 14:00:46 +00:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Intel Corporation.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Neil Roberts <neil@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
cogl-pipeline: Add support for setting uniform values
This adds the following new public experimental functions to set
uniform values on a CoglPipeline:
void
cogl_pipeline_set_uniform_1f (CoglPipeline *pipeline,
int uniform_location,
float value);
void
cogl_pipeline_set_uniform_1i (CoglPipeline *pipeline,
int uniform_location,
int value);
void
cogl_pipeline_set_uniform_float (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const float *value);
void
cogl_pipeline_set_uniform_int (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const int *value);
void
cogl_pipeline_set_uniform_matrix (CoglPipeline *pipeline,
int uniform_location,
int dimensions,
int count,
gboolean transpose,
const float *value);
These are similar to the old functions used to set uniforms on a
CoglProgram. To get a value to pass in as the uniform_location there
is also:
int
cogl_pipeline_get_uniform_location (CoglPipeline *pipeline,
const char *uniform_name);
Conceptually the uniform locations are tied to the pipeline so that
whenever setting a value for a new pipeline the application is
expected to call this function. However in practice the uniform
locations are global to the CoglContext. The names are stored in a
linked list where the position in the list is the uniform location.
The global indices are used so that each pipeline can store a mask of
which uniforms it overrides. That way it is quicker to detect which
uniforms are different from the last pipeline that used the same
CoglProgramState so it can avoid flushing uniforms that haven't
changed. Currently the values are not actually compared which means
that it will only avoid flushing a uniform if there is a common
ancestor that sets the value (or if the same pipeline is being flushed
again - in which case the pipeline and its common ancestor are the
same thing).
The uniform values are stored in the big state of the pipeline as a
sparse linked list. A bitmask stores which values have been overridden
and only overridden values are stored in the linked list.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 17:20:43 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2011-10-13 21:34:30 +00:00
|
|
|
#include "cogl-util.h"
|
2011-09-23 08:43:05 +00:00
|
|
|
#include "cogl-context-private.h"
|
2010-12-02 14:00:46 +00:00
|
|
|
#include "cogl-pipeline-private.h"
|
|
|
|
#include "cogl-pipeline-opengl-private.h"
|
2012-02-18 01:19:17 +00:00
|
|
|
#include "cogl-offscreen.h"
|
2010-12-02 14:00:46 +00:00
|
|
|
|
|
|
|
#ifdef COGL_PIPELINE_PROGEND_GLSL
|
|
|
|
|
|
|
|
#include "cogl-internal.h"
|
2010-11-04 22:25:52 +00:00
|
|
|
#include "cogl-context-private.h"
|
2012-04-16 13:14:10 +00:00
|
|
|
#include "cogl-object-private.h"
|
2010-12-02 14:00:46 +00:00
|
|
|
#include "cogl-program-private.h"
|
|
|
|
#include "cogl-pipeline-fragend-glsl-private.h"
|
2010-12-02 20:48:45 +00:00
|
|
|
#include "cogl-pipeline-vertend-glsl-private.h"
|
2011-06-30 17:34:05 +00:00
|
|
|
#include "cogl-pipeline-cache.h"
|
cogl-pipeline: Add support for setting uniform values
This adds the following new public experimental functions to set
uniform values on a CoglPipeline:
void
cogl_pipeline_set_uniform_1f (CoglPipeline *pipeline,
int uniform_location,
float value);
void
cogl_pipeline_set_uniform_1i (CoglPipeline *pipeline,
int uniform_location,
int value);
void
cogl_pipeline_set_uniform_float (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const float *value);
void
cogl_pipeline_set_uniform_int (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const int *value);
void
cogl_pipeline_set_uniform_matrix (CoglPipeline *pipeline,
int uniform_location,
int dimensions,
int count,
gboolean transpose,
const float *value);
These are similar to the old functions used to set uniforms on a
CoglProgram. To get a value to pass in as the uniform_location there
is also:
int
cogl_pipeline_get_uniform_location (CoglPipeline *pipeline,
const char *uniform_name);
Conceptually the uniform locations are tied to the pipeline so that
whenever setting a value for a new pipeline the application is
expected to call this function. However in practice the uniform
locations are global to the CoglContext. The names are stored in a
linked list where the position in the list is the uniform location.
The global indices are used so that each pipeline can store a mask of
which uniforms it overrides. That way it is quicker to detect which
uniforms are different from the last pipeline that used the same
CoglProgramState so it can avoid flushing uniforms that haven't
changed. Currently the values are not actually compared which means
that it will only avoid flushing a uniform if there is a common
ancestor that sets the value (or if the same pipeline is being flushed
again - in which case the pipeline and its common ancestor are the
same thing).
The uniform values are stored in the big state of the pipeline as a
sparse linked list. A bitmask stores which values have been overridden
and only overridden values are stored in the linked list.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 17:20:43 +00:00
|
|
|
#include "cogl-pipeline-state-private.h"
|
2011-11-24 18:09:53 +00:00
|
|
|
#include "cogl-attribute-private.h"
|
2011-11-29 14:21:07 +00:00
|
|
|
#include "cogl-framebuffer-private.h"
|
2012-03-06 18:21:28 +00:00
|
|
|
#include "cogl-pipeline-progend-glsl-private.h"
|
2010-12-02 14:00:46 +00:00
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
#ifdef HAVE_COGL_GLES2
|
2011-01-13 18:24:22 +00:00
|
|
|
|
|
|
|
/* These are used to generalise updating some uniforms that are
|
|
|
|
required when building for GLES2 */
|
|
|
|
|
|
|
|
typedef void (* UpdateUniformFunc) (CoglPipeline *pipeline,
|
|
|
|
int uniform_location,
|
|
|
|
void *getter_func);
|
|
|
|
|
|
|
|
static void update_float_uniform (CoglPipeline *pipeline,
|
|
|
|
int uniform_location,
|
|
|
|
void *getter_func);
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const char *uniform_name;
|
|
|
|
void *getter_func;
|
|
|
|
UpdateUniformFunc update_func;
|
|
|
|
CoglPipelineState change;
|
|
|
|
} BuiltinUniformData;
|
|
|
|
|
|
|
|
static BuiltinUniformData builtin_uniforms[] =
|
|
|
|
{
|
|
|
|
{ "cogl_point_size_in",
|
|
|
|
cogl_pipeline_get_point_size, update_float_uniform,
|
|
|
|
COGL_PIPELINE_STATE_POINT_SIZE },
|
|
|
|
{ "_cogl_alpha_test_ref",
|
|
|
|
cogl_pipeline_get_alpha_test_reference, update_float_uniform,
|
|
|
|
COGL_PIPELINE_STATE_ALPHA_FUNC_REFERENCE }
|
|
|
|
};
|
|
|
|
|
2010-12-02 14:00:46 +00:00
|
|
|
#endif /* HAVE_COGL_GLES2 */
|
|
|
|
|
|
|
|
const CoglPipelineProgend _cogl_pipeline_glsl_progend;
|
|
|
|
|
|
|
|
typedef struct _UnitState
|
|
|
|
{
|
|
|
|
unsigned int dirty_combine_constant:1;
|
2010-12-06 12:31:51 +00:00
|
|
|
unsigned int dirty_texture_matrix:1;
|
2010-12-02 14:00:46 +00:00
|
|
|
|
|
|
|
GLint combine_constant_uniform;
|
2010-12-06 12:31:51 +00:00
|
|
|
|
|
|
|
GLint texture_matrix_uniform;
|
2010-12-02 14:00:46 +00:00
|
|
|
} UnitState;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
unsigned int ref_count;
|
|
|
|
|
|
|
|
/* Age that the user program had last time we generated a GL
|
|
|
|
program. If it's different then we need to relink the program */
|
|
|
|
unsigned int user_program_age;
|
|
|
|
|
|
|
|
GLuint program;
|
|
|
|
|
|
|
|
/* To allow writing shaders that are portable between GLES 2 and
|
|
|
|
* OpenGL Cogl prepends a number of boilerplate #defines and
|
|
|
|
* declarations to user shaders. One of those declarations is an
|
|
|
|
* array of texture coordinate varyings, but to know how to emit the
|
|
|
|
* declaration we need to know how many texture coordinate
|
|
|
|
* attributes are in use. The boilerplate also needs to be changed
|
2011-10-19 11:47:22 +00:00
|
|
|
* if this changes. */
|
2010-12-02 14:00:46 +00:00
|
|
|
int n_tex_coord_attribs;
|
|
|
|
|
|
|
|
#ifdef HAVE_COGL_GLES2
|
2011-01-13 18:24:22 +00:00
|
|
|
unsigned long dirty_builtin_uniforms;
|
|
|
|
GLint builtin_uniform_locations[G_N_ELEMENTS (builtin_uniforms)];
|
2010-12-03 17:46:16 +00:00
|
|
|
|
2010-12-06 12:31:51 +00:00
|
|
|
GLint modelview_uniform;
|
|
|
|
GLint projection_uniform;
|
|
|
|
GLint mvp_uniform;
|
|
|
|
|
2011-11-29 14:21:07 +00:00
|
|
|
CoglMatrixStackCache projection_cache;
|
|
|
|
CoglMatrixStackCache modelview_cache;
|
2010-12-02 14:00:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* We need to track the last pipeline that the program was used with
|
|
|
|
* so know if we need to update all of the uniforms */
|
|
|
|
CoglPipeline *last_used_for_pipeline;
|
|
|
|
|
cogl-pipeline: Add support for setting uniform values
This adds the following new public experimental functions to set
uniform values on a CoglPipeline:
void
cogl_pipeline_set_uniform_1f (CoglPipeline *pipeline,
int uniform_location,
float value);
void
cogl_pipeline_set_uniform_1i (CoglPipeline *pipeline,
int uniform_location,
int value);
void
cogl_pipeline_set_uniform_float (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const float *value);
void
cogl_pipeline_set_uniform_int (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const int *value);
void
cogl_pipeline_set_uniform_matrix (CoglPipeline *pipeline,
int uniform_location,
int dimensions,
int count,
gboolean transpose,
const float *value);
These are similar to the old functions used to set uniforms on a
CoglProgram. To get a value to pass in as the uniform_location there
is also:
int
cogl_pipeline_get_uniform_location (CoglPipeline *pipeline,
const char *uniform_name);
Conceptually the uniform locations are tied to the pipeline so that
whenever setting a value for a new pipeline the application is
expected to call this function. However in practice the uniform
locations are global to the CoglContext. The names are stored in a
linked list where the position in the list is the uniform location.
The global indices are used so that each pipeline can store a mask of
which uniforms it overrides. That way it is quicker to detect which
uniforms are different from the last pipeline that used the same
CoglProgramState so it can avoid flushing uniforms that haven't
changed. Currently the values are not actually compared which means
that it will only avoid flushing a uniform if there is a common
ancestor that sets the value (or if the same pipeline is being flushed
again - in which case the pipeline and its common ancestor are the
same thing).
The uniform values are stored in the big state of the pipeline as a
sparse linked list. A bitmask stores which values have been overridden
and only overridden values are stored in the linked list.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 17:20:43 +00:00
|
|
|
/* Array of GL uniform locations indexed by Cogl's uniform
|
|
|
|
location. We are careful only to allocated this array if a custom
|
|
|
|
uniform is actually set */
|
|
|
|
GArray *uniform_locations;
|
|
|
|
|
2011-11-24 18:09:53 +00:00
|
|
|
/* Array of attribute locations. */
|
|
|
|
GArray *attribute_locations;
|
|
|
|
|
2011-11-29 14:21:07 +00:00
|
|
|
/* The 'flip' uniform is used to flip the geometry upside-down when
|
|
|
|
the framebuffer requires it only when there are vertex
|
|
|
|
snippets. Otherwise this is acheived using the projection
|
|
|
|
matrix */
|
|
|
|
GLint flip_uniform;
|
|
|
|
int flushed_flip_state;
|
|
|
|
|
2010-12-02 14:00:46 +00:00
|
|
|
UnitState *unit_state;
|
2011-06-30 12:39:48 +00:00
|
|
|
} CoglPipelineProgramState;
|
2010-12-02 14:00:46 +00:00
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
static CoglUserDataKey program_state_key;
|
2010-12-02 14:00:46 +00:00
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
static CoglPipelineProgramState *
|
|
|
|
get_program_state (CoglPipeline *pipeline)
|
2010-12-02 14:00:46 +00:00
|
|
|
{
|
2011-06-30 12:39:48 +00:00
|
|
|
return cogl_object_get_user_data (COGL_OBJECT (pipeline), &program_state_key);
|
2010-12-02 14:00:46 +00:00
|
|
|
}
|
|
|
|
|
cogl-pipeline: Add support for setting uniform values
This adds the following new public experimental functions to set
uniform values on a CoglPipeline:
void
cogl_pipeline_set_uniform_1f (CoglPipeline *pipeline,
int uniform_location,
float value);
void
cogl_pipeline_set_uniform_1i (CoglPipeline *pipeline,
int uniform_location,
int value);
void
cogl_pipeline_set_uniform_float (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const float *value);
void
cogl_pipeline_set_uniform_int (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const int *value);
void
cogl_pipeline_set_uniform_matrix (CoglPipeline *pipeline,
int uniform_location,
int dimensions,
int count,
gboolean transpose,
const float *value);
These are similar to the old functions used to set uniforms on a
CoglProgram. To get a value to pass in as the uniform_location there
is also:
int
cogl_pipeline_get_uniform_location (CoglPipeline *pipeline,
const char *uniform_name);
Conceptually the uniform locations are tied to the pipeline so that
whenever setting a value for a new pipeline the application is
expected to call this function. However in practice the uniform
locations are global to the CoglContext. The names are stored in a
linked list where the position in the list is the uniform location.
The global indices are used so that each pipeline can store a mask of
which uniforms it overrides. That way it is quicker to detect which
uniforms are different from the last pipeline that used the same
CoglProgramState so it can avoid flushing uniforms that haven't
changed. Currently the values are not actually compared which means
that it will only avoid flushing a uniform if there is a common
ancestor that sets the value (or if the same pipeline is being flushed
again - in which case the pipeline and its common ancestor are the
same thing).
The uniform values are stored in the big state of the pipeline as a
sparse linked list. A bitmask stores which values have been overridden
and only overridden values are stored in the linked list.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 17:20:43 +00:00
|
|
|
#define UNIFORM_LOCATION_UNKNOWN -2
|
|
|
|
|
2010-12-03 17:46:16 +00:00
|
|
|
#define ATTRIBUTE_LOCATION_UNKNOWN -2
|
|
|
|
|
|
|
|
/* Under GLES2 the vertex attribute API needs to query the attribute
|
|
|
|
numbers because it can't used the fixed function API to set the
|
|
|
|
builtin attributes. We cache the attributes here because the
|
|
|
|
progend knows when the program is changed so it can clear the
|
|
|
|
cache. This should always be called after the pipeline is flushed
|
|
|
|
so they can assert that the gl program is valid */
|
|
|
|
|
2011-11-24 18:09:53 +00:00
|
|
|
/* All attributes names get internally mapped to a global set of
|
|
|
|
* sequential indices when they are setup which we need to need to
|
|
|
|
* then be able to map to a GL attribute location once we have
|
|
|
|
* a linked GLSL program */
|
2010-12-03 17:46:16 +00:00
|
|
|
|
|
|
|
int
|
2011-11-24 18:09:53 +00:00
|
|
|
_cogl_pipeline_progend_glsl_get_attrib_location (CoglPipeline *pipeline,
|
|
|
|
int name_index)
|
2010-12-03 17:46:16 +00:00
|
|
|
{
|
2011-06-30 12:39:48 +00:00
|
|
|
CoglPipelineProgramState *program_state = get_program_state (pipeline);
|
2011-11-24 18:09:53 +00:00
|
|
|
int *locations;
|
2010-12-03 17:46:16 +00:00
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
_COGL_GET_CONTEXT (ctx, -1);
|
|
|
|
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (program_state != NULL, -1);
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (program_state->program != 0, -1);
|
2010-12-03 17:46:16 +00:00
|
|
|
|
2011-11-24 18:09:53 +00:00
|
|
|
if (G_UNLIKELY (program_state->attribute_locations == NULL))
|
|
|
|
program_state->attribute_locations =
|
|
|
|
g_array_new (FALSE, FALSE, sizeof (int));
|
2010-12-03 17:46:16 +00:00
|
|
|
|
2011-11-24 18:09:53 +00:00
|
|
|
if (G_UNLIKELY (program_state->attribute_locations->len <= name_index))
|
2010-12-03 17:46:16 +00:00
|
|
|
{
|
2011-11-24 18:09:53 +00:00
|
|
|
int i = program_state->attribute_locations->len;
|
|
|
|
g_array_set_size (program_state->attribute_locations, name_index + 1);
|
|
|
|
for (; i < program_state->attribute_locations->len; i++)
|
|
|
|
g_array_index (program_state->attribute_locations, int, i)
|
|
|
|
= ATTRIBUTE_LOCATION_UNKNOWN;
|
2010-12-03 17:46:16 +00:00
|
|
|
}
|
|
|
|
|
2011-11-24 18:09:53 +00:00
|
|
|
locations = &g_array_index (program_state->attribute_locations, int, 0);
|
2010-12-03 17:46:16 +00:00
|
|
|
|
2011-11-24 18:09:53 +00:00
|
|
|
if (locations[name_index] == ATTRIBUTE_LOCATION_UNKNOWN)
|
|
|
|
{
|
|
|
|
CoglAttributeNameState *name_state =
|
|
|
|
g_array_index (ctx->attribute_name_index_map,
|
|
|
|
CoglAttributeNameState *, name_index);
|
2010-12-03 17:46:16 +00:00
|
|
|
|
2011-11-24 18:09:53 +00:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (name_state != NULL, 0);
|
2010-12-03 17:46:16 +00:00
|
|
|
|
2011-11-24 18:09:53 +00:00
|
|
|
GE_RET( locations[name_index],
|
|
|
|
ctx, glGetAttribLocation (program_state->program,
|
|
|
|
name_state->name) );
|
2010-12-03 17:46:16 +00:00
|
|
|
}
|
2011-11-24 18:09:53 +00:00
|
|
|
|
|
|
|
return locations[name_index];
|
2010-12-03 17:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-30 12:39:48 +00:00
|
|
|
clear_attribute_cache (CoglPipelineProgramState *program_state)
|
2010-12-03 17:46:16 +00:00
|
|
|
{
|
2011-11-24 18:09:53 +00:00
|
|
|
if (program_state->attribute_locations)
|
2010-12-03 17:46:16 +00:00
|
|
|
{
|
2011-11-24 18:09:53 +00:00
|
|
|
g_array_free (program_state->attribute_locations, TRUE);
|
|
|
|
program_state->attribute_locations = NULL;
|
2010-12-03 17:46:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-24 18:09:53 +00:00
|
|
|
#ifdef HAVE_COGL_GLES2
|
|
|
|
|
2010-12-06 12:31:51 +00:00
|
|
|
static void
|
2011-06-30 12:39:48 +00:00
|
|
|
clear_flushed_matrix_stacks (CoglPipelineProgramState *program_state)
|
2010-12-06 12:31:51 +00:00
|
|
|
{
|
2011-11-29 14:21:07 +00:00
|
|
|
_cogl_matrix_stack_destroy_cache (&program_state->projection_cache);
|
|
|
|
_cogl_matrix_stack_init_cache (&program_state->projection_cache);
|
|
|
|
_cogl_matrix_stack_destroy_cache (&program_state->modelview_cache);
|
|
|
|
_cogl_matrix_stack_init_cache (&program_state->modelview_cache);
|
2010-12-06 12:31:51 +00:00
|
|
|
}
|
|
|
|
|
2010-12-03 17:46:16 +00:00
|
|
|
#endif /* HAVE_COGL_GLES2 */
|
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
static CoglPipelineProgramState *
|
|
|
|
program_state_new (int n_layers)
|
|
|
|
{
|
|
|
|
CoglPipelineProgramState *program_state;
|
|
|
|
|
|
|
|
program_state = g_slice_new (CoglPipelineProgramState);
|
|
|
|
program_state->ref_count = 1;
|
|
|
|
program_state->program = 0;
|
|
|
|
program_state->n_tex_coord_attribs = 0;
|
|
|
|
program_state->unit_state = g_new (UnitState, n_layers);
|
cogl-pipeline: Add support for setting uniform values
This adds the following new public experimental functions to set
uniform values on a CoglPipeline:
void
cogl_pipeline_set_uniform_1f (CoglPipeline *pipeline,
int uniform_location,
float value);
void
cogl_pipeline_set_uniform_1i (CoglPipeline *pipeline,
int uniform_location,
int value);
void
cogl_pipeline_set_uniform_float (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const float *value);
void
cogl_pipeline_set_uniform_int (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const int *value);
void
cogl_pipeline_set_uniform_matrix (CoglPipeline *pipeline,
int uniform_location,
int dimensions,
int count,
gboolean transpose,
const float *value);
These are similar to the old functions used to set uniforms on a
CoglProgram. To get a value to pass in as the uniform_location there
is also:
int
cogl_pipeline_get_uniform_location (CoglPipeline *pipeline,
const char *uniform_name);
Conceptually the uniform locations are tied to the pipeline so that
whenever setting a value for a new pipeline the application is
expected to call this function. However in practice the uniform
locations are global to the CoglContext. The names are stored in a
linked list where the position in the list is the uniform location.
The global indices are used so that each pipeline can store a mask of
which uniforms it overrides. That way it is quicker to detect which
uniforms are different from the last pipeline that used the same
CoglProgramState so it can avoid flushing uniforms that haven't
changed. Currently the values are not actually compared which means
that it will only avoid flushing a uniform if there is a common
ancestor that sets the value (or if the same pipeline is being flushed
again - in which case the pipeline and its common ancestor are the
same thing).
The uniform values are stored in the big state of the pipeline as a
sparse linked list. A bitmask stores which values have been overridden
and only overridden values are stored in the linked list.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 17:20:43 +00:00
|
|
|
program_state->uniform_locations = NULL;
|
2011-11-24 18:09:53 +00:00
|
|
|
program_state->attribute_locations = NULL;
|
2011-06-30 12:39:48 +00:00
|
|
|
#ifdef HAVE_COGL_GLES2
|
2011-11-29 14:21:07 +00:00
|
|
|
_cogl_matrix_stack_init_cache (&program_state->modelview_cache);
|
|
|
|
_cogl_matrix_stack_init_cache (&program_state->projection_cache);
|
2011-06-30 12:39:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return program_state;
|
|
|
|
}
|
|
|
|
|
2010-12-02 14:00:46 +00:00
|
|
|
static void
|
2011-10-23 19:22:23 +00:00
|
|
|
destroy_program_state (void *user_data,
|
|
|
|
void *instance)
|
2010-12-02 14:00:46 +00:00
|
|
|
{
|
2011-06-30 12:39:48 +00:00
|
|
|
CoglPipelineProgramState *program_state = user_data;
|
2010-12-02 14:00:46 +00:00
|
|
|
|
2010-12-05 18:02:05 +00:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2011-10-23 19:22:23 +00:00
|
|
|
/* If the program state was last used for this pipeline then clear
|
|
|
|
it so that if same address gets used again for a new pipeline
|
|
|
|
then we won't think it's the same pipeline and avoid updating the
|
|
|
|
uniforms */
|
|
|
|
if (program_state->last_used_for_pipeline == instance)
|
|
|
|
program_state->last_used_for_pipeline = NULL;
|
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
if (--program_state->ref_count == 0)
|
2010-12-02 14:00:46 +00:00
|
|
|
{
|
2011-11-24 18:09:53 +00:00
|
|
|
clear_attribute_cache (program_state);
|
|
|
|
|
2010-12-03 17:46:16 +00:00
|
|
|
#ifdef HAVE_COGL_GLES2
|
2011-07-07 19:44:56 +00:00
|
|
|
if (ctx->driver == COGL_DRIVER_GLES2)
|
2011-11-29 14:21:07 +00:00
|
|
|
{
|
|
|
|
_cogl_matrix_stack_destroy_cache (&program_state->projection_cache);
|
|
|
|
_cogl_matrix_stack_destroy_cache (&program_state->modelview_cache);
|
|
|
|
}
|
2010-12-03 17:46:16 +00:00
|
|
|
#endif
|
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
if (program_state->program)
|
|
|
|
GE( ctx, glDeleteProgram (program_state->program) );
|
2010-12-02 14:00:46 +00:00
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
g_free (program_state->unit_state);
|
2010-12-02 14:00:46 +00:00
|
|
|
|
cogl-pipeline: Add support for setting uniform values
This adds the following new public experimental functions to set
uniform values on a CoglPipeline:
void
cogl_pipeline_set_uniform_1f (CoglPipeline *pipeline,
int uniform_location,
float value);
void
cogl_pipeline_set_uniform_1i (CoglPipeline *pipeline,
int uniform_location,
int value);
void
cogl_pipeline_set_uniform_float (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const float *value);
void
cogl_pipeline_set_uniform_int (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const int *value);
void
cogl_pipeline_set_uniform_matrix (CoglPipeline *pipeline,
int uniform_location,
int dimensions,
int count,
gboolean transpose,
const float *value);
These are similar to the old functions used to set uniforms on a
CoglProgram. To get a value to pass in as the uniform_location there
is also:
int
cogl_pipeline_get_uniform_location (CoglPipeline *pipeline,
const char *uniform_name);
Conceptually the uniform locations are tied to the pipeline so that
whenever setting a value for a new pipeline the application is
expected to call this function. However in practice the uniform
locations are global to the CoglContext. The names are stored in a
linked list where the position in the list is the uniform location.
The global indices are used so that each pipeline can store a mask of
which uniforms it overrides. That way it is quicker to detect which
uniforms are different from the last pipeline that used the same
CoglProgramState so it can avoid flushing uniforms that haven't
changed. Currently the values are not actually compared which means
that it will only avoid flushing a uniform if there is a common
ancestor that sets the value (or if the same pipeline is being flushed
again - in which case the pipeline and its common ancestor are the
same thing).
The uniform values are stored in the big state of the pipeline as a
sparse linked list. A bitmask stores which values have been overridden
and only overridden values are stored in the linked list.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 17:20:43 +00:00
|
|
|
if (program_state->uniform_locations)
|
|
|
|
g_array_free (program_state->uniform_locations, TRUE);
|
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
g_slice_free (CoglPipelineProgramState, program_state);
|
2010-12-02 14:00:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-30 12:39:48 +00:00
|
|
|
set_program_state (CoglPipeline *pipeline,
|
|
|
|
CoglPipelineProgramState *program_state)
|
2010-12-02 14:00:46 +00:00
|
|
|
{
|
2011-10-23 19:22:23 +00:00
|
|
|
_cogl_object_set_user_data (COGL_OBJECT (pipeline),
|
|
|
|
&program_state_key,
|
|
|
|
program_state,
|
|
|
|
destroy_program_state);
|
2010-12-02 14:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-30 12:39:48 +00:00
|
|
|
dirty_program_state (CoglPipeline *pipeline)
|
2010-12-02 14:00:46 +00:00
|
|
|
{
|
|
|
|
cogl_object_set_user_data (COGL_OBJECT (pipeline),
|
2011-06-30 12:39:48 +00:00
|
|
|
&program_state_key,
|
2010-12-02 14:00:46 +00:00
|
|
|
NULL,
|
2011-06-30 12:39:48 +00:00
|
|
|
NULL);
|
2010-12-02 14:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
link_program (GLint gl_program)
|
|
|
|
{
|
|
|
|
GLint link_status;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
GE( ctx, glLinkProgram (gl_program) );
|
2010-12-02 14:00:46 +00:00
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
GE( ctx, glGetProgramiv (gl_program, GL_LINK_STATUS, &link_status) );
|
2010-12-02 14:00:46 +00:00
|
|
|
|
|
|
|
if (!link_status)
|
|
|
|
{
|
|
|
|
GLint log_length;
|
|
|
|
GLsizei out_log_length;
|
|
|
|
char *log;
|
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
GE( ctx, glGetProgramiv (gl_program, GL_INFO_LOG_LENGTH, &log_length) );
|
2010-12-02 14:00:46 +00:00
|
|
|
|
|
|
|
log = g_malloc (log_length);
|
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
GE( ctx, glGetProgramInfoLog (gl_program, log_length,
|
|
|
|
&out_log_length, log) );
|
2010-12-02 14:00:46 +00:00
|
|
|
|
|
|
|
g_warning ("Failed to link GLSL program:\n%.*s\n",
|
|
|
|
log_length, log);
|
|
|
|
|
|
|
|
g_free (log);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int unit;
|
|
|
|
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 20:56:40 +00:00
|
|
|
CoglBool update_all;
|
2011-06-30 12:39:48 +00:00
|
|
|
CoglPipelineProgramState *program_state;
|
2010-12-02 14:00:46 +00:00
|
|
|
} UpdateUniformsState;
|
|
|
|
|
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 20:56:40 +00:00
|
|
|
static CoglBool
|
2010-12-02 14:00:46 +00:00
|
|
|
get_uniform_cb (CoglPipeline *pipeline,
|
|
|
|
int layer_index,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
UpdateUniformsState *state = user_data;
|
2011-06-30 12:39:48 +00:00
|
|
|
CoglPipelineProgramState *program_state = state->program_state;
|
|
|
|
UnitState *unit_state = &program_state->unit_state[state->unit];
|
2010-12-02 14:00:46 +00:00
|
|
|
GLint uniform_location;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
|
|
|
/* We can reuse the source buffer to create the uniform name because
|
|
|
|
the program has now been linked */
|
2010-12-02 18:05:22 +00:00
|
|
|
g_string_set_size (ctx->codegen_source_buffer, 0);
|
|
|
|
g_string_append_printf (ctx->codegen_source_buffer,
|
2012-01-03 11:42:42 +00:00
|
|
|
"cogl_sampler%i", layer_index);
|
2010-12-02 14:00:46 +00:00
|
|
|
|
|
|
|
GE_RET( uniform_location,
|
2011-07-06 20:51:00 +00:00
|
|
|
ctx, glGetUniformLocation (state->gl_program,
|
|
|
|
ctx->codegen_source_buffer->str) );
|
2010-12-02 14:00:46 +00:00
|
|
|
|
|
|
|
/* We can set the uniform immediately because the samplers are the
|
|
|
|
unit index not the texture object number so it will never
|
|
|
|
change. Unfortunately GL won't let us use a constant instead of a
|
|
|
|
uniform */
|
|
|
|
if (uniform_location != -1)
|
2011-07-06 20:51:00 +00:00
|
|
|
GE( ctx, glUniform1i (uniform_location, state->unit) );
|
2010-12-02 14:00:46 +00:00
|
|
|
|
2010-12-02 18:05:22 +00:00
|
|
|
g_string_set_size (ctx->codegen_source_buffer, 0);
|
|
|
|
g_string_append_printf (ctx->codegen_source_buffer,
|
2012-02-10 14:17:10 +00:00
|
|
|
"_cogl_layer_constant_%i", layer_index);
|
2010-12-02 14:00:46 +00:00
|
|
|
|
|
|
|
GE_RET( uniform_location,
|
2011-07-06 20:51:00 +00:00
|
|
|
ctx, glGetUniformLocation (state->gl_program,
|
|
|
|
ctx->codegen_source_buffer->str) );
|
2010-12-02 14:00:46 +00:00
|
|
|
|
|
|
|
unit_state->combine_constant_uniform = uniform_location;
|
|
|
|
|
2010-12-06 12:31:51 +00:00
|
|
|
#ifdef HAVE_COGL_GLES2
|
2011-07-07 19:44:56 +00:00
|
|
|
if (ctx->driver == COGL_DRIVER_GLES2)
|
|
|
|
{
|
|
|
|
g_string_set_size (ctx->codegen_source_buffer, 0);
|
|
|
|
g_string_append_printf (ctx->codegen_source_buffer,
|
|
|
|
"cogl_texture_matrix[%i]", state->unit);
|
2010-12-06 12:31:51 +00:00
|
|
|
|
2011-07-07 19:44:56 +00:00
|
|
|
GE_RET( uniform_location,
|
|
|
|
ctx, glGetUniformLocation (state->gl_program,
|
|
|
|
ctx->codegen_source_buffer->str) );
|
2010-12-06 12:31:51 +00:00
|
|
|
|
2011-07-07 19:44:56 +00:00
|
|
|
unit_state->texture_matrix_uniform = uniform_location;
|
|
|
|
}
|
2010-12-06 12:31:51 +00:00
|
|
|
#endif
|
|
|
|
|
2010-12-02 14:00:46 +00:00
|
|
|
state->unit++;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
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 20:56:40 +00:00
|
|
|
static CoglBool
|
2010-12-02 14:00:46 +00:00
|
|
|
update_constants_cb (CoglPipeline *pipeline,
|
|
|
|
int layer_index,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
UpdateUniformsState *state = user_data;
|
2011-06-30 12:39:48 +00:00
|
|
|
CoglPipelineProgramState *program_state = state->program_state;
|
|
|
|
UnitState *unit_state = &program_state->unit_state[state->unit++];
|
2010-12-02 14:00:46 +00:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
|
|
|
if (unit_state->combine_constant_uniform != -1 &&
|
|
|
|
(state->update_all || unit_state->dirty_combine_constant))
|
|
|
|
{
|
|
|
|
float constant[4];
|
|
|
|
_cogl_pipeline_get_layer_combine_constant (pipeline,
|
|
|
|
layer_index,
|
|
|
|
constant);
|
2011-07-06 20:51:00 +00:00
|
|
|
GE (ctx, glUniform4fv (unit_state->combine_constant_uniform,
|
|
|
|
1, constant));
|
2010-12-02 14:00:46 +00:00
|
|
|
unit_state->dirty_combine_constant = FALSE;
|
|
|
|
}
|
2010-12-06 12:31:51 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_COGL_GLES2
|
|
|
|
|
2011-07-07 19:44:56 +00:00
|
|
|
if (ctx->driver == COGL_DRIVER_GLES2 &&
|
|
|
|
unit_state->texture_matrix_uniform != -1 &&
|
2010-12-06 12:31:51 +00:00
|
|
|
(state->update_all || unit_state->dirty_texture_matrix))
|
|
|
|
{
|
|
|
|
const CoglMatrix *matrix;
|
|
|
|
const float *array;
|
|
|
|
|
|
|
|
matrix = _cogl_pipeline_get_layer_matrix (pipeline, layer_index);
|
|
|
|
array = cogl_matrix_get_array (matrix);
|
2011-07-06 20:51:00 +00:00
|
|
|
GE (ctx, glUniformMatrix4fv (unit_state->texture_matrix_uniform,
|
|
|
|
1, FALSE, array));
|
2010-12-06 12:31:51 +00:00
|
|
|
unit_state->dirty_texture_matrix = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_COGL_GLES2 */
|
|
|
|
|
2010-12-02 14:00:46 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_COGL_GLES2
|
|
|
|
|
|
|
|
static void
|
2011-01-13 18:24:22 +00:00
|
|
|
update_builtin_uniforms (CoglPipeline *pipeline,
|
|
|
|
GLuint gl_program,
|
2011-06-30 12:39:48 +00:00
|
|
|
CoglPipelineProgramState *program_state)
|
2010-12-02 14:00:46 +00:00
|
|
|
{
|
2011-01-13 18:24:22 +00:00
|
|
|
int i;
|
2010-12-02 14:00:46 +00:00
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
if (program_state->dirty_builtin_uniforms == 0)
|
2011-01-13 18:24:22 +00:00
|
|
|
return;
|
2010-12-02 20:48:45 +00:00
|
|
|
|
2011-01-13 18:24:22 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (builtin_uniforms); i++)
|
2011-06-30 12:39:48 +00:00
|
|
|
if ((program_state->dirty_builtin_uniforms & (1 << i)) &&
|
|
|
|
program_state->builtin_uniform_locations[i] != -1)
|
2011-01-13 18:24:22 +00:00
|
|
|
builtin_uniforms[i].update_func (pipeline,
|
2011-06-30 12:39:48 +00:00
|
|
|
program_state
|
|
|
|
->builtin_uniform_locations[i],
|
2011-01-13 18:24:22 +00:00
|
|
|
builtin_uniforms[i].getter_func);
|
2010-12-02 20:48:45 +00:00
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
program_state->dirty_builtin_uniforms = 0;
|
2010-12-02 20:48:45 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 14:00:46 +00:00
|
|
|
#endif /* HAVE_COGL_GLES2 */
|
|
|
|
|
cogl-pipeline: Add support for setting uniform values
This adds the following new public experimental functions to set
uniform values on a CoglPipeline:
void
cogl_pipeline_set_uniform_1f (CoglPipeline *pipeline,
int uniform_location,
float value);
void
cogl_pipeline_set_uniform_1i (CoglPipeline *pipeline,
int uniform_location,
int value);
void
cogl_pipeline_set_uniform_float (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const float *value);
void
cogl_pipeline_set_uniform_int (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const int *value);
void
cogl_pipeline_set_uniform_matrix (CoglPipeline *pipeline,
int uniform_location,
int dimensions,
int count,
gboolean transpose,
const float *value);
These are similar to the old functions used to set uniforms on a
CoglProgram. To get a value to pass in as the uniform_location there
is also:
int
cogl_pipeline_get_uniform_location (CoglPipeline *pipeline,
const char *uniform_name);
Conceptually the uniform locations are tied to the pipeline so that
whenever setting a value for a new pipeline the application is
expected to call this function. However in practice the uniform
locations are global to the CoglContext. The names are stored in a
linked list where the position in the list is the uniform location.
The global indices are used so that each pipeline can store a mask of
which uniforms it overrides. That way it is quicker to detect which
uniforms are different from the last pipeline that used the same
CoglProgramState so it can avoid flushing uniforms that haven't
changed. Currently the values are not actually compared which means
that it will only avoid flushing a uniform if there is a common
ancestor that sets the value (or if the same pipeline is being flushed
again - in which case the pipeline and its common ancestor are the
same thing).
The uniform values are stored in the big state of the pipeline as a
sparse linked list. A bitmask stores which values have been overridden
and only overridden values are stored in the linked list.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 17:20:43 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
CoglPipelineProgramState *program_state;
|
|
|
|
unsigned long *uniform_differences;
|
|
|
|
int n_differences;
|
|
|
|
CoglContext *ctx;
|
2011-11-04 17:56:44 +00:00
|
|
|
const CoglBoxedValue *values;
|
|
|
|
int value_index;
|
cogl-pipeline: Add support for setting uniform values
This adds the following new public experimental functions to set
uniform values on a CoglPipeline:
void
cogl_pipeline_set_uniform_1f (CoglPipeline *pipeline,
int uniform_location,
float value);
void
cogl_pipeline_set_uniform_1i (CoglPipeline *pipeline,
int uniform_location,
int value);
void
cogl_pipeline_set_uniform_float (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const float *value);
void
cogl_pipeline_set_uniform_int (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const int *value);
void
cogl_pipeline_set_uniform_matrix (CoglPipeline *pipeline,
int uniform_location,
int dimensions,
int count,
gboolean transpose,
const float *value);
These are similar to the old functions used to set uniforms on a
CoglProgram. To get a value to pass in as the uniform_location there
is also:
int
cogl_pipeline_get_uniform_location (CoglPipeline *pipeline,
const char *uniform_name);
Conceptually the uniform locations are tied to the pipeline so that
whenever setting a value for a new pipeline the application is
expected to call this function. However in practice the uniform
locations are global to the CoglContext. The names are stored in a
linked list where the position in the list is the uniform location.
The global indices are used so that each pipeline can store a mask of
which uniforms it overrides. That way it is quicker to detect which
uniforms are different from the last pipeline that used the same
CoglProgramState so it can avoid flushing uniforms that haven't
changed. Currently the values are not actually compared which means
that it will only avoid flushing a uniform if there is a common
ancestor that sets the value (or if the same pipeline is being flushed
again - in which case the pipeline and its common ancestor are the
same thing).
The uniform values are stored in the big state of the pipeline as a
sparse linked list. A bitmask stores which values have been overridden
and only overridden values are stored in the linked list.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 17:20:43 +00:00
|
|
|
} FlushUniformsClosure;
|
|
|
|
|
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 20:56:40 +00:00
|
|
|
static CoglBool
|
cogl-pipeline: Add support for setting uniform values
This adds the following new public experimental functions to set
uniform values on a CoglPipeline:
void
cogl_pipeline_set_uniform_1f (CoglPipeline *pipeline,
int uniform_location,
float value);
void
cogl_pipeline_set_uniform_1i (CoglPipeline *pipeline,
int uniform_location,
int value);
void
cogl_pipeline_set_uniform_float (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const float *value);
void
cogl_pipeline_set_uniform_int (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const int *value);
void
cogl_pipeline_set_uniform_matrix (CoglPipeline *pipeline,
int uniform_location,
int dimensions,
int count,
gboolean transpose,
const float *value);
These are similar to the old functions used to set uniforms on a
CoglProgram. To get a value to pass in as the uniform_location there
is also:
int
cogl_pipeline_get_uniform_location (CoglPipeline *pipeline,
const char *uniform_name);
Conceptually the uniform locations are tied to the pipeline so that
whenever setting a value for a new pipeline the application is
expected to call this function. However in practice the uniform
locations are global to the CoglContext. The names are stored in a
linked list where the position in the list is the uniform location.
The global indices are used so that each pipeline can store a mask of
which uniforms it overrides. That way it is quicker to detect which
uniforms are different from the last pipeline that used the same
CoglProgramState so it can avoid flushing uniforms that haven't
changed. Currently the values are not actually compared which means
that it will only avoid flushing a uniform if there is a common
ancestor that sets the value (or if the same pipeline is being flushed
again - in which case the pipeline and its common ancestor are the
same thing).
The uniform values are stored in the big state of the pipeline as a
sparse linked list. A bitmask stores which values have been overridden
and only overridden values are stored in the linked list.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 17:20:43 +00:00
|
|
|
flush_uniform_cb (int uniform_num, void *user_data)
|
|
|
|
{
|
|
|
|
FlushUniformsClosure *data = user_data;
|
|
|
|
|
|
|
|
if (COGL_FLAGS_GET (data->uniform_differences, uniform_num))
|
|
|
|
{
|
|
|
|
GArray *uniform_locations;
|
|
|
|
GLint uniform_location;
|
|
|
|
|
|
|
|
if (data->program_state->uniform_locations == NULL)
|
|
|
|
data->program_state->uniform_locations =
|
|
|
|
g_array_new (FALSE, FALSE, sizeof (GLint));
|
|
|
|
|
|
|
|
uniform_locations = data->program_state->uniform_locations;
|
|
|
|
|
|
|
|
if (uniform_locations->len <= uniform_num)
|
|
|
|
{
|
|
|
|
unsigned int old_len = uniform_locations->len;
|
|
|
|
|
|
|
|
g_array_set_size (uniform_locations, uniform_num + 1);
|
|
|
|
|
|
|
|
while (old_len <= uniform_num)
|
|
|
|
{
|
|
|
|
g_array_index (uniform_locations, GLint, old_len) =
|
|
|
|
UNIFORM_LOCATION_UNKNOWN;
|
|
|
|
old_len++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uniform_location = g_array_index (uniform_locations, GLint, uniform_num);
|
|
|
|
|
|
|
|
if (uniform_location == UNIFORM_LOCATION_UNKNOWN)
|
|
|
|
{
|
|
|
|
const char *uniform_name =
|
2011-11-04 18:26:17 +00:00
|
|
|
g_ptr_array_index (data->ctx->uniform_names, uniform_num);
|
cogl-pipeline: Add support for setting uniform values
This adds the following new public experimental functions to set
uniform values on a CoglPipeline:
void
cogl_pipeline_set_uniform_1f (CoglPipeline *pipeline,
int uniform_location,
float value);
void
cogl_pipeline_set_uniform_1i (CoglPipeline *pipeline,
int uniform_location,
int value);
void
cogl_pipeline_set_uniform_float (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const float *value);
void
cogl_pipeline_set_uniform_int (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const int *value);
void
cogl_pipeline_set_uniform_matrix (CoglPipeline *pipeline,
int uniform_location,
int dimensions,
int count,
gboolean transpose,
const float *value);
These are similar to the old functions used to set uniforms on a
CoglProgram. To get a value to pass in as the uniform_location there
is also:
int
cogl_pipeline_get_uniform_location (CoglPipeline *pipeline,
const char *uniform_name);
Conceptually the uniform locations are tied to the pipeline so that
whenever setting a value for a new pipeline the application is
expected to call this function. However in practice the uniform
locations are global to the CoglContext. The names are stored in a
linked list where the position in the list is the uniform location.
The global indices are used so that each pipeline can store a mask of
which uniforms it overrides. That way it is quicker to detect which
uniforms are different from the last pipeline that used the same
CoglProgramState so it can avoid flushing uniforms that haven't
changed. Currently the values are not actually compared which means
that it will only avoid flushing a uniform if there is a common
ancestor that sets the value (or if the same pipeline is being flushed
again - in which case the pipeline and its common ancestor are the
same thing).
The uniform values are stored in the big state of the pipeline as a
sparse linked list. A bitmask stores which values have been overridden
and only overridden values are stored in the linked list.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 17:20:43 +00:00
|
|
|
|
|
|
|
uniform_location =
|
|
|
|
data->ctx->glGetUniformLocation (data->program_state->program,
|
|
|
|
uniform_name);
|
|
|
|
g_array_index (uniform_locations, GLint, uniform_num) =
|
|
|
|
uniform_location;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uniform_location != -1)
|
|
|
|
_cogl_boxed_value_set_uniform (data->ctx,
|
|
|
|
uniform_location,
|
2011-11-04 17:56:44 +00:00
|
|
|
data->values + data->value_index);
|
cogl-pipeline: Add support for setting uniform values
This adds the following new public experimental functions to set
uniform values on a CoglPipeline:
void
cogl_pipeline_set_uniform_1f (CoglPipeline *pipeline,
int uniform_location,
float value);
void
cogl_pipeline_set_uniform_1i (CoglPipeline *pipeline,
int uniform_location,
int value);
void
cogl_pipeline_set_uniform_float (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const float *value);
void
cogl_pipeline_set_uniform_int (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const int *value);
void
cogl_pipeline_set_uniform_matrix (CoglPipeline *pipeline,
int uniform_location,
int dimensions,
int count,
gboolean transpose,
const float *value);
These are similar to the old functions used to set uniforms on a
CoglProgram. To get a value to pass in as the uniform_location there
is also:
int
cogl_pipeline_get_uniform_location (CoglPipeline *pipeline,
const char *uniform_name);
Conceptually the uniform locations are tied to the pipeline so that
whenever setting a value for a new pipeline the application is
expected to call this function. However in practice the uniform
locations are global to the CoglContext. The names are stored in a
linked list where the position in the list is the uniform location.
The global indices are used so that each pipeline can store a mask of
which uniforms it overrides. That way it is quicker to detect which
uniforms are different from the last pipeline that used the same
CoglProgramState so it can avoid flushing uniforms that haven't
changed. Currently the values are not actually compared which means
that it will only avoid flushing a uniform if there is a common
ancestor that sets the value (or if the same pipeline is being flushed
again - in which case the pipeline and its common ancestor are the
same thing).
The uniform values are stored in the big state of the pipeline as a
sparse linked list. A bitmask stores which values have been overridden
and only overridden values are stored in the linked list.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 17:20:43 +00:00
|
|
|
|
|
|
|
data->n_differences--;
|
|
|
|
COGL_FLAGS_SET (data->uniform_differences, uniform_num, FALSE);
|
|
|
|
}
|
|
|
|
|
2011-11-04 17:56:44 +00:00
|
|
|
data->value_index++;
|
cogl-pipeline: Add support for setting uniform values
This adds the following new public experimental functions to set
uniform values on a CoglPipeline:
void
cogl_pipeline_set_uniform_1f (CoglPipeline *pipeline,
int uniform_location,
float value);
void
cogl_pipeline_set_uniform_1i (CoglPipeline *pipeline,
int uniform_location,
int value);
void
cogl_pipeline_set_uniform_float (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const float *value);
void
cogl_pipeline_set_uniform_int (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const int *value);
void
cogl_pipeline_set_uniform_matrix (CoglPipeline *pipeline,
int uniform_location,
int dimensions,
int count,
gboolean transpose,
const float *value);
These are similar to the old functions used to set uniforms on a
CoglProgram. To get a value to pass in as the uniform_location there
is also:
int
cogl_pipeline_get_uniform_location (CoglPipeline *pipeline,
const char *uniform_name);
Conceptually the uniform locations are tied to the pipeline so that
whenever setting a value for a new pipeline the application is
expected to call this function. However in practice the uniform
locations are global to the CoglContext. The names are stored in a
linked list where the position in the list is the uniform location.
The global indices are used so that each pipeline can store a mask of
which uniforms it overrides. That way it is quicker to detect which
uniforms are different from the last pipeline that used the same
CoglProgramState so it can avoid flushing uniforms that haven't
changed. Currently the values are not actually compared which means
that it will only avoid flushing a uniform if there is a common
ancestor that sets the value (or if the same pipeline is being flushed
again - in which case the pipeline and its common ancestor are the
same thing).
The uniform values are stored in the big state of the pipeline as a
sparse linked list. A bitmask stores which values have been overridden
and only overridden values are stored in the linked list.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 17:20:43 +00:00
|
|
|
|
|
|
|
return data->n_differences > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_pipeline_progend_glsl_flush_uniforms (CoglPipeline *pipeline,
|
|
|
|
CoglPipelineProgramState *
|
|
|
|
program_state,
|
|
|
|
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 20:56:40 +00:00
|
|
|
CoglBool program_changed)
|
cogl-pipeline: Add support for setting uniform values
This adds the following new public experimental functions to set
uniform values on a CoglPipeline:
void
cogl_pipeline_set_uniform_1f (CoglPipeline *pipeline,
int uniform_location,
float value);
void
cogl_pipeline_set_uniform_1i (CoglPipeline *pipeline,
int uniform_location,
int value);
void
cogl_pipeline_set_uniform_float (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const float *value);
void
cogl_pipeline_set_uniform_int (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const int *value);
void
cogl_pipeline_set_uniform_matrix (CoglPipeline *pipeline,
int uniform_location,
int dimensions,
int count,
gboolean transpose,
const float *value);
These are similar to the old functions used to set uniforms on a
CoglProgram. To get a value to pass in as the uniform_location there
is also:
int
cogl_pipeline_get_uniform_location (CoglPipeline *pipeline,
const char *uniform_name);
Conceptually the uniform locations are tied to the pipeline so that
whenever setting a value for a new pipeline the application is
expected to call this function. However in practice the uniform
locations are global to the CoglContext. The names are stored in a
linked list where the position in the list is the uniform location.
The global indices are used so that each pipeline can store a mask of
which uniforms it overrides. That way it is quicker to detect which
uniforms are different from the last pipeline that used the same
CoglProgramState so it can avoid flushing uniforms that haven't
changed. Currently the values are not actually compared which means
that it will only avoid flushing a uniform if there is a common
ancestor that sets the value (or if the same pipeline is being flushed
again - in which case the pipeline and its common ancestor are the
same thing).
The uniform values are stored in the big state of the pipeline as a
sparse linked list. A bitmask stores which values have been overridden
and only overridden values are stored in the linked list.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 17:20:43 +00:00
|
|
|
{
|
|
|
|
CoglPipelineUniformsState *uniforms_state;
|
|
|
|
FlushUniformsClosure data;
|
|
|
|
int n_uniform_longs;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
if (pipeline->differences & COGL_PIPELINE_STATE_UNIFORMS)
|
|
|
|
uniforms_state = &pipeline->big_state->uniforms_state;
|
|
|
|
else
|
|
|
|
uniforms_state = NULL;
|
|
|
|
|
|
|
|
data.program_state = program_state;
|
|
|
|
data.ctx = ctx;
|
|
|
|
|
|
|
|
n_uniform_longs = COGL_FLAGS_N_LONGS_FOR_SIZE (ctx->n_uniform_names);
|
|
|
|
|
|
|
|
data.uniform_differences = g_newa (unsigned long, n_uniform_longs);
|
|
|
|
|
|
|
|
/* Try to find a common ancestor for the values that were already
|
|
|
|
flushed on the pipeline that this program state was last used for
|
|
|
|
so we can avoid flushing those */
|
|
|
|
|
|
|
|
if (program_changed || program_state->last_used_for_pipeline == NULL)
|
|
|
|
{
|
|
|
|
if (program_changed)
|
|
|
|
{
|
|
|
|
/* The program has changed so all of the uniform locations
|
|
|
|
are invalid */
|
|
|
|
if (program_state->uniform_locations)
|
|
|
|
g_array_set_size (program_state->uniform_locations, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We need to flush everything so mark all of the uniforms as
|
|
|
|
dirty */
|
|
|
|
memset (data.uniform_differences, 0xff,
|
|
|
|
n_uniform_longs * sizeof (unsigned long));
|
|
|
|
data.n_differences = G_MAXINT;
|
|
|
|
}
|
|
|
|
else if (program_state->last_used_for_pipeline)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
memset (data.uniform_differences, 0,
|
|
|
|
n_uniform_longs * sizeof (unsigned long));
|
|
|
|
_cogl_pipeline_compare_uniform_differences
|
|
|
|
(data.uniform_differences,
|
|
|
|
program_state->last_used_for_pipeline,
|
|
|
|
pipeline);
|
|
|
|
|
|
|
|
/* We need to be sure to flush any uniforms that have changed
|
|
|
|
since the last flush */
|
|
|
|
if (uniforms_state)
|
|
|
|
_cogl_bitmask_set_flags (&uniforms_state->changed_mask,
|
|
|
|
data.uniform_differences);
|
|
|
|
|
|
|
|
/* Count the number of differences. This is so we can stop early
|
|
|
|
when we've flushed all of them */
|
|
|
|
data.n_differences = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < n_uniform_longs; i++)
|
|
|
|
data.n_differences +=
|
|
|
|
_cogl_util_popcountl (data.uniform_differences[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (pipeline && data.n_differences > 0)
|
|
|
|
{
|
|
|
|
if (pipeline->differences & COGL_PIPELINE_STATE_UNIFORMS)
|
|
|
|
{
|
|
|
|
const CoglPipelineUniformsState *parent_uniforms_state =
|
|
|
|
&pipeline->big_state->uniforms_state;
|
|
|
|
|
2011-11-04 17:56:44 +00:00
|
|
|
data.values = parent_uniforms_state->override_values;
|
|
|
|
data.value_index = 0;
|
cogl-pipeline: Add support for setting uniform values
This adds the following new public experimental functions to set
uniform values on a CoglPipeline:
void
cogl_pipeline_set_uniform_1f (CoglPipeline *pipeline,
int uniform_location,
float value);
void
cogl_pipeline_set_uniform_1i (CoglPipeline *pipeline,
int uniform_location,
int value);
void
cogl_pipeline_set_uniform_float (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const float *value);
void
cogl_pipeline_set_uniform_int (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const int *value);
void
cogl_pipeline_set_uniform_matrix (CoglPipeline *pipeline,
int uniform_location,
int dimensions,
int count,
gboolean transpose,
const float *value);
These are similar to the old functions used to set uniforms on a
CoglProgram. To get a value to pass in as the uniform_location there
is also:
int
cogl_pipeline_get_uniform_location (CoglPipeline *pipeline,
const char *uniform_name);
Conceptually the uniform locations are tied to the pipeline so that
whenever setting a value for a new pipeline the application is
expected to call this function. However in practice the uniform
locations are global to the CoglContext. The names are stored in a
linked list where the position in the list is the uniform location.
The global indices are used so that each pipeline can store a mask of
which uniforms it overrides. That way it is quicker to detect which
uniforms are different from the last pipeline that used the same
CoglProgramState so it can avoid flushing uniforms that haven't
changed. Currently the values are not actually compared which means
that it will only avoid flushing a uniform if there is a common
ancestor that sets the value (or if the same pipeline is being flushed
again - in which case the pipeline and its common ancestor are the
same thing).
The uniform values are stored in the big state of the pipeline as a
sparse linked list. A bitmask stores which values have been overridden
and only overridden values are stored in the linked list.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 17:20:43 +00:00
|
|
|
|
|
|
|
_cogl_bitmask_foreach (&parent_uniforms_state->override_mask,
|
|
|
|
flush_uniform_cb,
|
|
|
|
&data);
|
|
|
|
}
|
|
|
|
|
|
|
|
pipeline = _cogl_pipeline_get_parent (pipeline);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uniforms_state)
|
|
|
|
_cogl_bitmask_clear_all (&uniforms_state->changed_mask);
|
|
|
|
}
|
|
|
|
|
2010-12-02 14:00:46 +00:00
|
|
|
static void
|
|
|
|
_cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline,
|
|
|
|
unsigned long pipelines_difference,
|
|
|
|
int n_tex_coord_attribs)
|
|
|
|
{
|
2011-06-30 12:39:48 +00:00
|
|
|
CoglPipelineProgramState *program_state;
|
2010-12-02 14:00:46 +00:00
|
|
|
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 20:56:40 +00:00
|
|
|
CoglBool program_changed = FALSE;
|
2010-12-02 14:00:46 +00:00
|
|
|
UpdateUniformsState state;
|
|
|
|
CoglProgram *user_program;
|
2011-06-30 17:34:05 +00:00
|
|
|
CoglPipeline *template_pipeline = NULL;
|
2010-12-02 14:00:46 +00:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
/* If neither of the glsl fragend or vertends are used then we don't
|
|
|
|
need to do anything */
|
2010-12-02 20:48:45 +00:00
|
|
|
if (pipeline->fragend != COGL_PIPELINE_FRAGEND_GLSL &&
|
|
|
|
pipeline->vertend != COGL_PIPELINE_VERTEND_GLSL)
|
2010-12-02 14:00:46 +00:00
|
|
|
return;
|
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
program_state = get_program_state (pipeline);
|
2010-12-02 14:00:46 +00:00
|
|
|
|
|
|
|
user_program = cogl_pipeline_get_user_program (pipeline);
|
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
if (program_state == NULL)
|
2010-12-02 14:00:46 +00:00
|
|
|
{
|
|
|
|
CoglPipeline *authority;
|
|
|
|
|
|
|
|
/* Get the authority for anything affecting program state. This
|
|
|
|
should include both fragment codegen state and vertex codegen
|
|
|
|
state */
|
|
|
|
authority = _cogl_pipeline_find_equivalent_parent
|
|
|
|
(pipeline,
|
2010-12-02 20:48:45 +00:00
|
|
|
(COGL_PIPELINE_STATE_AFFECTS_VERTEX_CODEGEN |
|
2011-07-07 19:44:56 +00:00
|
|
|
_cogl_pipeline_get_state_for_fragment_codegen (ctx)) &
|
2010-12-02 14:00:46 +00:00
|
|
|
~COGL_PIPELINE_STATE_LAYERS,
|
2011-07-07 19:44:56 +00:00
|
|
|
_cogl_pipeline_get_layer_state_for_fragment_codegen (ctx) |
|
2011-01-11 16:02:06 +00:00
|
|
|
COGL_PIPELINE_LAYER_STATE_AFFECTS_VERTEX_CODEGEN);
|
2010-12-02 14:00:46 +00:00
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
program_state = get_program_state (authority);
|
2010-12-02 14:00:46 +00:00
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
if (program_state == NULL)
|
2010-12-02 14:00:46 +00:00
|
|
|
{
|
2011-06-30 17:34:05 +00:00
|
|
|
/* Check if there is already a similar cached pipeline whose
|
|
|
|
program state we can share */
|
|
|
|
if (G_LIKELY (!(COGL_DEBUG_ENABLED
|
|
|
|
(COGL_DEBUG_DISABLE_PROGRAM_CACHES))))
|
|
|
|
{
|
|
|
|
template_pipeline =
|
|
|
|
_cogl_pipeline_cache_get_combined_template (ctx->pipeline_cache,
|
|
|
|
authority);
|
|
|
|
|
|
|
|
program_state = get_program_state (template_pipeline);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (program_state)
|
|
|
|
program_state->ref_count++;
|
|
|
|
else
|
|
|
|
program_state
|
|
|
|
= program_state_new (cogl_pipeline_get_n_layers (authority));
|
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
set_program_state (authority, program_state);
|
2011-06-30 17:34:05 +00:00
|
|
|
|
|
|
|
if (template_pipeline)
|
|
|
|
{
|
|
|
|
program_state->ref_count++;
|
|
|
|
set_program_state (template_pipeline, program_state);
|
|
|
|
}
|
2010-12-02 14:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (authority != pipeline)
|
|
|
|
{
|
2011-06-30 12:39:48 +00:00
|
|
|
program_state->ref_count++;
|
|
|
|
set_program_state (pipeline, program_state);
|
2010-12-02 14:00:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the program has changed since the last link then we do
|
|
|
|
* need to relink
|
|
|
|
*
|
|
|
|
* Also if the number of texture coordinate attributes in use has
|
2011-10-19 11:47:22 +00:00
|
|
|
* changed, then delete the program so we can prepend a new
|
2010-12-02 14:00:46 +00:00
|
|
|
* _cogl_tex_coord[] varying array declaration. */
|
2011-10-19 11:47:22 +00:00
|
|
|
if ((program_state->program && user_program &&
|
|
|
|
user_program->age != program_state->user_program_age) ||
|
|
|
|
(ctx->driver == COGL_DRIVER_GLES2 &&
|
|
|
|
n_tex_coord_attribs != program_state->n_tex_coord_attribs))
|
2010-12-02 14:00:46 +00:00
|
|
|
{
|
2011-06-30 12:39:48 +00:00
|
|
|
GE( ctx, glDeleteProgram (program_state->program) );
|
|
|
|
program_state->program = 0;
|
2010-12-02 14:00:46 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
if (program_state->program == 0)
|
2010-12-02 14:00:46 +00:00
|
|
|
{
|
|
|
|
GLuint backend_shader;
|
|
|
|
GSList *l;
|
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
GE_RET( program_state->program, ctx, glCreateProgram () );
|
2010-12-02 14:00:46 +00:00
|
|
|
|
|
|
|
/* Attach all of the shader from the user program */
|
|
|
|
if (user_program)
|
|
|
|
{
|
|
|
|
for (l = user_program->attached_shaders; l; l = l->next)
|
|
|
|
{
|
|
|
|
CoglShader *shader = l->data;
|
|
|
|
|
|
|
|
_cogl_shader_compile_real (shader, n_tex_coord_attribs);
|
|
|
|
|
|
|
|
g_assert (shader->language == COGL_SHADER_LANGUAGE_GLSL);
|
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
GE( ctx, glAttachShader (program_state->program,
|
2011-07-06 20:51:00 +00:00
|
|
|
shader->gl_handle) );
|
2010-12-02 14:00:46 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
program_state->user_program_age = user_program->age;
|
2010-12-02 14:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Attach any shaders from the GLSL backends */
|
|
|
|
if (pipeline->fragend == COGL_PIPELINE_FRAGEND_GLSL &&
|
|
|
|
(backend_shader = _cogl_pipeline_fragend_glsl_get_shader (pipeline)))
|
2011-06-30 12:39:48 +00:00
|
|
|
GE( ctx, glAttachShader (program_state->program, backend_shader) );
|
2010-12-02 20:48:45 +00:00
|
|
|
if (pipeline->vertend == COGL_PIPELINE_VERTEND_GLSL &&
|
|
|
|
(backend_shader = _cogl_pipeline_vertend_glsl_get_shader (pipeline)))
|
2011-06-30 12:39:48 +00:00
|
|
|
GE( ctx, glAttachShader (program_state->program, backend_shader) );
|
2010-12-02 14:00:46 +00:00
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
link_program (program_state->program);
|
2010-12-02 14:00:46 +00:00
|
|
|
|
|
|
|
program_changed = TRUE;
|
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
program_state->n_tex_coord_attribs = n_tex_coord_attribs;
|
2010-12-02 14:00:46 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
gl_program = program_state->program;
|
2010-12-02 14:00:46 +00:00
|
|
|
|
2010-12-02 20:48:45 +00:00
|
|
|
if (pipeline->fragend == COGL_PIPELINE_FRAGEND_GLSL)
|
|
|
|
_cogl_use_fragment_program (gl_program, COGL_PIPELINE_PROGRAM_TYPE_GLSL);
|
|
|
|
if (pipeline->vertend == COGL_PIPELINE_VERTEND_GLSL)
|
|
|
|
_cogl_use_vertex_program (gl_program, COGL_PIPELINE_PROGRAM_TYPE_GLSL);
|
2010-12-02 14:00:46 +00:00
|
|
|
|
|
|
|
state.unit = 0;
|
|
|
|
state.gl_program = gl_program;
|
2011-06-30 12:39:48 +00:00
|
|
|
state.program_state = program_state;
|
2010-12-02 14:00:46 +00:00
|
|
|
|
|
|
|
if (program_changed)
|
2011-11-24 18:09:53 +00:00
|
|
|
{
|
|
|
|
cogl_pipeline_foreach_layer (pipeline,
|
|
|
|
get_uniform_cb,
|
|
|
|
&state);
|
|
|
|
clear_attribute_cache (program_state);
|
2011-11-29 14:21:07 +00:00
|
|
|
|
|
|
|
GE_RET (program_state->flip_uniform,
|
|
|
|
ctx, glGetUniformLocation (gl_program, "_cogl_flip_vector"));
|
|
|
|
program_state->flushed_flip_state = -1;
|
2011-11-24 18:09:53 +00:00
|
|
|
}
|
2010-12-02 14:00:46 +00:00
|
|
|
|
|
|
|
state.unit = 0;
|
|
|
|
state.update_all = (program_changed ||
|
2011-06-30 12:39:48 +00:00
|
|
|
program_state->last_used_for_pipeline != pipeline);
|
2010-12-02 14:00:46 +00:00
|
|
|
|
|
|
|
cogl_pipeline_foreach_layer (pipeline,
|
|
|
|
update_constants_cb,
|
|
|
|
&state);
|
|
|
|
|
|
|
|
#ifdef HAVE_COGL_GLES2
|
2011-07-07 19:44:56 +00:00
|
|
|
if (ctx->driver == COGL_DRIVER_GLES2)
|
2010-12-02 20:48:45 +00:00
|
|
|
{
|
2011-07-07 19:44:56 +00:00
|
|
|
if (program_changed)
|
|
|
|
{
|
|
|
|
int i;
|
2011-01-13 18:24:22 +00:00
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
clear_flushed_matrix_stacks (program_state);
|
2010-12-03 17:46:16 +00:00
|
|
|
|
2011-07-07 19:44:56 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (builtin_uniforms); i++)
|
2011-06-30 12:39:48 +00:00
|
|
|
GE_RET( program_state->builtin_uniform_locations[i], ctx,
|
2011-07-07 19:44:56 +00:00
|
|
|
glGetUniformLocation (gl_program,
|
|
|
|
builtin_uniforms[i].uniform_name) );
|
2010-12-02 20:48:45 +00:00
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
GE_RET( program_state->modelview_uniform, ctx,
|
|
|
|
glGetUniformLocation (gl_program,
|
|
|
|
"cogl_modelview_matrix") );
|
2010-12-06 12:31:51 +00:00
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
GE_RET( program_state->projection_uniform, ctx,
|
|
|
|
glGetUniformLocation (gl_program,
|
|
|
|
"cogl_projection_matrix") );
|
2010-12-06 12:31:51 +00:00
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
GE_RET( program_state->mvp_uniform, ctx,
|
2011-07-07 19:44:56 +00:00
|
|
|
glGetUniformLocation (gl_program,
|
|
|
|
"cogl_modelview_projection_matrix") );
|
|
|
|
}
|
|
|
|
if (program_changed ||
|
2011-06-30 12:39:48 +00:00
|
|
|
program_state->last_used_for_pipeline != pipeline)
|
|
|
|
program_state->dirty_builtin_uniforms = ~(unsigned long) 0;
|
2010-12-02 14:00:46 +00:00
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
update_builtin_uniforms (pipeline, gl_program, program_state);
|
2011-07-07 19:44:56 +00:00
|
|
|
}
|
2010-12-02 14:00:46 +00:00
|
|
|
#endif
|
|
|
|
|
cogl-pipeline: Add support for setting uniform values
This adds the following new public experimental functions to set
uniform values on a CoglPipeline:
void
cogl_pipeline_set_uniform_1f (CoglPipeline *pipeline,
int uniform_location,
float value);
void
cogl_pipeline_set_uniform_1i (CoglPipeline *pipeline,
int uniform_location,
int value);
void
cogl_pipeline_set_uniform_float (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const float *value);
void
cogl_pipeline_set_uniform_int (CoglPipeline *pipeline,
int uniform_location,
int n_components,
int count,
const int *value);
void
cogl_pipeline_set_uniform_matrix (CoglPipeline *pipeline,
int uniform_location,
int dimensions,
int count,
gboolean transpose,
const float *value);
These are similar to the old functions used to set uniforms on a
CoglProgram. To get a value to pass in as the uniform_location there
is also:
int
cogl_pipeline_get_uniform_location (CoglPipeline *pipeline,
const char *uniform_name);
Conceptually the uniform locations are tied to the pipeline so that
whenever setting a value for a new pipeline the application is
expected to call this function. However in practice the uniform
locations are global to the CoglContext. The names are stored in a
linked list where the position in the list is the uniform location.
The global indices are used so that each pipeline can store a mask of
which uniforms it overrides. That way it is quicker to detect which
uniforms are different from the last pipeline that used the same
CoglProgramState so it can avoid flushing uniforms that haven't
changed. Currently the values are not actually compared which means
that it will only avoid flushing a uniform if there is a common
ancestor that sets the value (or if the same pipeline is being flushed
again - in which case the pipeline and its common ancestor are the
same thing).
The uniform values are stored in the big state of the pipeline as a
sparse linked list. A bitmask stores which values have been overridden
and only overridden values are stored in the linked list.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 17:20:43 +00:00
|
|
|
_cogl_pipeline_progend_glsl_flush_uniforms (pipeline,
|
|
|
|
program_state,
|
|
|
|
gl_program,
|
|
|
|
program_changed);
|
|
|
|
|
2010-12-02 14:00:46 +00:00
|
|
|
if (user_program)
|
|
|
|
_cogl_program_flush_uniforms (user_program,
|
|
|
|
gl_program,
|
|
|
|
program_changed);
|
|
|
|
|
|
|
|
/* We need to track the last pipeline that the program was used with
|
|
|
|
* so know if we need to update all of the uniforms */
|
2011-06-30 12:39:48 +00:00
|
|
|
program_state->last_used_for_pipeline = pipeline;
|
2010-12-02 14:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_pipeline_progend_glsl_pre_change_notify (CoglPipeline *pipeline,
|
|
|
|
CoglPipelineState change,
|
|
|
|
const CoglColor *new_color)
|
|
|
|
{
|
2011-07-07 19:44:56 +00:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
if ((change & _cogl_pipeline_get_state_for_fragment_codegen (ctx)))
|
2011-06-30 12:39:48 +00:00
|
|
|
dirty_program_state (pipeline);
|
|
|
|
|
2010-12-02 20:48:45 +00:00
|
|
|
#ifdef HAVE_COGL_GLES2
|
2011-07-07 19:44:56 +00:00
|
|
|
else if (ctx->driver == COGL_DRIVER_GLES2)
|
2010-12-02 20:48:45 +00:00
|
|
|
{
|
2011-01-13 18:24:22 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (builtin_uniforms); i++)
|
|
|
|
if ((change & builtin_uniforms[i].change))
|
|
|
|
{
|
2011-06-30 12:39:48 +00:00
|
|
|
CoglPipelineProgramState *program_state
|
|
|
|
= get_program_state (pipeline);
|
|
|
|
if (program_state)
|
|
|
|
program_state->dirty_builtin_uniforms |= 1 << i;
|
2011-01-13 18:24:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-12-02 20:48:45 +00:00
|
|
|
}
|
|
|
|
#endif /* HAVE_COGL_GLES2 */
|
2010-12-02 14:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* NB: layers are considered immutable once they have any dependants
|
|
|
|
* so although multiple pipelines can end up depending on a single
|
|
|
|
* static layer, we can guarantee that if a layer is being *changed*
|
|
|
|
* then it can only have one pipeline depending on it.
|
|
|
|
*
|
|
|
|
* XXX: Don't forget this is *pre* change, we can't read the new value
|
|
|
|
* yet!
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
_cogl_pipeline_progend_glsl_layer_pre_change_notify (
|
|
|
|
CoglPipeline *owner,
|
|
|
|
CoglPipelineLayer *layer,
|
|
|
|
CoglPipelineLayerState change)
|
|
|
|
{
|
2011-07-07 19:44:56 +00:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
if ((change & _cogl_pipeline_get_state_for_fragment_codegen (ctx)))
|
2010-12-02 14:00:46 +00:00
|
|
|
{
|
2011-06-30 12:39:48 +00:00
|
|
|
dirty_program_state (owner);
|
2010-12-02 14:00:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (change & COGL_PIPELINE_LAYER_STATE_COMBINE_CONSTANT)
|
|
|
|
{
|
2011-06-30 12:39:48 +00:00
|
|
|
CoglPipelineProgramState *program_state = get_program_state (owner);
|
|
|
|
if (program_state)
|
2010-12-02 14:00:46 +00:00
|
|
|
{
|
|
|
|
int unit_index = _cogl_pipeline_layer_get_unit_index (layer);
|
2011-06-30 12:39:48 +00:00
|
|
|
program_state->unit_state[unit_index].dirty_combine_constant = TRUE;
|
2010-12-02 14:00:46 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-06 12:31:51 +00:00
|
|
|
|
|
|
|
if (change & COGL_PIPELINE_LAYER_STATE_USER_MATRIX)
|
|
|
|
{
|
2011-06-30 12:39:48 +00:00
|
|
|
CoglPipelineProgramState *program_state = get_program_state (owner);
|
|
|
|
if (program_state)
|
2010-12-06 12:31:51 +00:00
|
|
|
{
|
|
|
|
int unit_index = _cogl_pipeline_layer_get_unit_index (layer);
|
2011-06-30 12:39:48 +00:00
|
|
|
program_state->unit_state[unit_index].dirty_texture_matrix = TRUE;
|
2010-12-06 12:31:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_pipeline_progend_glsl_pre_paint (CoglPipeline *pipeline)
|
|
|
|
{
|
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 20:56:40 +00:00
|
|
|
CoglBool needs_flip;
|
2011-11-29 14:21:07 +00:00
|
|
|
CoglMatrixStack *projection_stack;
|
|
|
|
CoglMatrixStack *modelview_stack;
|
|
|
|
CoglPipelineProgramState *program_state;
|
2010-12-06 12:31:51 +00:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2011-11-29 14:21:07 +00:00
|
|
|
if (pipeline->vertend != COGL_PIPELINE_VERTEND_GLSL)
|
2011-07-07 19:44:56 +00:00
|
|
|
return;
|
|
|
|
|
2011-06-30 12:39:48 +00:00
|
|
|
program_state = get_program_state (pipeline);
|
2010-12-06 12:31:51 +00:00
|
|
|
|
2011-11-29 14:21:07 +00:00
|
|
|
projection_stack = ctx->current_projection_stack;
|
|
|
|
modelview_stack = ctx->current_modelview_stack;
|
|
|
|
|
2010-12-06 12:31:51 +00:00
|
|
|
/* An initial pipeline is flushed while creating the context. At
|
2011-11-29 14:21:07 +00:00
|
|
|
this point there are no matrices selected so we can't do
|
2010-12-06 12:31:51 +00:00
|
|
|
anything */
|
2011-11-29 14:21:07 +00:00
|
|
|
if (modelview_stack == NULL || projection_stack == NULL)
|
2010-12-06 12:31:51 +00:00
|
|
|
return;
|
|
|
|
|
2012-02-25 15:10:02 +00:00
|
|
|
needs_flip = cogl_is_offscreen (ctx->current_draw_buffer);
|
2011-11-29 14:21:07 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_COGL_GLES2
|
|
|
|
if (ctx->driver == COGL_DRIVER_GLES2)
|
|
|
|
{
|
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 20:56:40 +00:00
|
|
|
CoglBool modelview_changed;
|
|
|
|
CoglBool projection_changed;
|
|
|
|
CoglBool need_modelview;
|
|
|
|
CoglBool need_projection;
|
2011-11-29 14:21:07 +00:00
|
|
|
CoglMatrix modelview, projection;
|
|
|
|
|
|
|
|
projection_changed =
|
|
|
|
_cogl_matrix_stack_check_and_update_cache (projection_stack,
|
|
|
|
&program_state->
|
|
|
|
projection_cache,
|
|
|
|
needs_flip &&
|
|
|
|
program_state->
|
|
|
|
flip_uniform == -1);
|
|
|
|
|
|
|
|
modelview_changed =
|
|
|
|
_cogl_matrix_stack_check_and_update_cache (modelview_stack,
|
|
|
|
&program_state->
|
|
|
|
modelview_cache,
|
|
|
|
/* never flip modelview */
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
if (modelview_changed || projection_changed)
|
|
|
|
{
|
|
|
|
if (program_state->mvp_uniform != -1)
|
|
|
|
need_modelview = need_projection = TRUE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
need_projection = (program_state->projection_uniform != -1 &&
|
|
|
|
projection_changed);
|
|
|
|
need_modelview = (program_state->modelview_uniform != -1 &&
|
|
|
|
modelview_changed);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_modelview)
|
|
|
|
_cogl_matrix_stack_get (modelview_stack, &modelview);
|
|
|
|
if (need_projection)
|
|
|
|
{
|
|
|
|
if (needs_flip && program_state->flip_uniform == -1)
|
|
|
|
{
|
|
|
|
CoglMatrix tmp_matrix;
|
|
|
|
_cogl_matrix_stack_get (projection_stack, &tmp_matrix);
|
|
|
|
cogl_matrix_multiply (&projection,
|
|
|
|
&ctx->y_flip_matrix,
|
|
|
|
&tmp_matrix);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_cogl_matrix_stack_get (projection_stack, &projection);
|
|
|
|
}
|
2010-12-06 12:31:51 +00:00
|
|
|
|
2011-11-29 14:21:07 +00:00
|
|
|
if (projection_changed && program_state->projection_uniform != -1)
|
|
|
|
GE (ctx, glUniformMatrix4fv (program_state->projection_uniform,
|
|
|
|
1, /* count */
|
|
|
|
FALSE, /* transpose */
|
|
|
|
cogl_matrix_get_array (&projection)));
|
2010-12-06 12:31:51 +00:00
|
|
|
|
2011-11-29 14:21:07 +00:00
|
|
|
if (modelview_changed && program_state->modelview_uniform != -1)
|
|
|
|
GE (ctx, glUniformMatrix4fv (program_state->modelview_uniform,
|
|
|
|
1, /* count */
|
|
|
|
FALSE, /* transpose */
|
|
|
|
cogl_matrix_get_array (&modelview)));
|
|
|
|
|
|
|
|
if (program_state->mvp_uniform != -1)
|
|
|
|
{
|
|
|
|
/* The journal usually uses an identity matrix for the
|
|
|
|
modelview so we can optimise this common case by
|
|
|
|
avoiding the matrix multiplication */
|
|
|
|
if (_cogl_matrix_stack_has_identity_flag (modelview_stack))
|
|
|
|
{
|
|
|
|
GE (ctx,
|
|
|
|
glUniformMatrix4fv (program_state->mvp_uniform,
|
|
|
|
1, /* count */
|
|
|
|
FALSE, /* transpose */
|
|
|
|
cogl_matrix_get_array (&projection)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CoglMatrix combined;
|
|
|
|
|
|
|
|
cogl_matrix_multiply (&combined,
|
|
|
|
&projection,
|
|
|
|
&modelview);
|
|
|
|
GE (ctx,
|
|
|
|
glUniformMatrix4fv (program_state->mvp_uniform,
|
|
|
|
1, /* count */
|
|
|
|
FALSE, /* transpose */
|
|
|
|
cogl_matrix_get_array (&combined)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2010-12-06 12:31:51 +00: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 20:56:40 +00:00
|
|
|
CoglBool disable_flip;
|
2011-11-29 14:21:07 +00:00
|
|
|
|
|
|
|
/* If there are vertex snippets, then we'll disable flipping the
|
|
|
|
geometry via the matrix and use the flip vertex instead */
|
|
|
|
disable_flip = program_state->flip_uniform != -1;
|
|
|
|
|
|
|
|
_cogl_matrix_stack_flush_to_gl_builtins (ctx,
|
|
|
|
projection_stack,
|
|
|
|
COGL_MATRIX_PROJECTION,
|
|
|
|
disable_flip);
|
|
|
|
_cogl_matrix_stack_flush_to_gl_builtins (ctx,
|
|
|
|
modelview_stack,
|
|
|
|
COGL_MATRIX_MODELVIEW,
|
|
|
|
disable_flip);
|
2010-12-06 12:31:51 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 14:21:07 +00:00
|
|
|
if (program_state->flip_uniform != -1
|
|
|
|
&& program_state->flushed_flip_state != needs_flip)
|
2010-12-06 12:31:51 +00:00
|
|
|
{
|
2011-11-29 14:21:07 +00:00
|
|
|
static const float do_flip[4] = { 1.0f, -1.0f, 1.0f, 1.0f };
|
|
|
|
static const float dont_flip[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
|
|
|
GE( ctx, glUniform4fv (program_state->flip_uniform,
|
|
|
|
1, /* count */
|
|
|
|
needs_flip ? do_flip : dont_flip) );
|
|
|
|
program_state->flushed_flip_state = needs_flip;
|
2010-12-06 12:31:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-29 14:21:07 +00:00
|
|
|
#ifdef HAVE_COGL_GLES2
|
|
|
|
|
2011-01-13 18:24:22 +00:00
|
|
|
static void
|
|
|
|
update_float_uniform (CoglPipeline *pipeline,
|
|
|
|
int uniform_location,
|
|
|
|
void *getter_func)
|
|
|
|
{
|
|
|
|
float (* float_getter_func) (CoglPipeline *) = getter_func;
|
|
|
|
float value;
|
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2011-01-13 18:24:22 +00:00
|
|
|
value = float_getter_func (pipeline);
|
2011-07-06 20:51:00 +00:00
|
|
|
GE( ctx, glUniform1f (uniform_location, value) );
|
2011-01-13 18:24:22 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 12:31:51 +00:00
|
|
|
#endif
|
|
|
|
|
2010-12-02 14:00:46 +00:00
|
|
|
const CoglPipelineProgend _cogl_pipeline_glsl_progend =
|
|
|
|
{
|
|
|
|
_cogl_pipeline_progend_glsl_end,
|
|
|
|
_cogl_pipeline_progend_glsl_pre_change_notify,
|
2010-12-06 12:31:51 +00:00
|
|
|
_cogl_pipeline_progend_glsl_layer_pre_change_notify,
|
|
|
|
_cogl_pipeline_progend_glsl_pre_paint
|
2010-12-02 14:00:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* COGL_PIPELINE_PROGEND_GLSL */
|