2011-09-07 18:44:37 -04:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2011-09-07 18:44:37 -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:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* 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.
|
2011-09-07 18:44:37 -04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Robert Bragg <robert@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
2016-05-05 10:21:51 -04:00
|
|
|
#include "cogl-config.h"
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
#include "cogl-context-private.h"
|
|
|
|
#include "cogl-color-private.h"
|
|
|
|
#include "cogl-blend-string.h"
|
|
|
|
#include "cogl-util.h"
|
|
|
|
#include "cogl-depth-state-private.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 13:20:43 -04:00
|
|
|
#include "cogl-pipeline-state-private.h"
|
2011-11-17 11:52:21 -05:00
|
|
|
#include "cogl-snippet-private.h"
|
2011-09-07 18:44:37 -04:00
|
|
|
|
2013-09-02 10:30:29 -04:00
|
|
|
#include <test-fixtures/test-unit.h>
|
|
|
|
|
2011-09-07 18:44:37 -04:00
|
|
|
#include "string.h"
|
|
|
|
|
|
|
|
#ifndef GL_FUNC_ADD
|
|
|
|
#define GL_FUNC_ADD 0x8006
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CoglPipeline *
|
|
|
|
_cogl_pipeline_get_user_program (CoglPipeline *pipeline)
|
|
|
|
{
|
|
|
|
CoglPipeline *authority;
|
|
|
|
|
2019-06-17 17:42:01 -04:00
|
|
|
g_return_val_if_fail (cogl_is_pipeline (pipeline), NULL);
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
authority =
|
|
|
|
_cogl_pipeline_get_authority (pipeline, COGL_PIPELINE_STATE_USER_SHADER);
|
|
|
|
|
|
|
|
return authority->big_state->user_program;
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2011-09-07 18:44:37 -04:00
|
|
|
_cogl_pipeline_color_equal (CoglPipeline *authority0,
|
|
|
|
CoglPipeline *authority1)
|
|
|
|
{
|
|
|
|
return cogl_color_equal (&authority0->color, &authority1->color);
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2011-09-07 18:44:37 -04:00
|
|
|
_cogl_pipeline_alpha_func_state_equal (CoglPipeline *authority0,
|
|
|
|
CoglPipeline *authority1)
|
|
|
|
{
|
|
|
|
CoglPipelineAlphaFuncState *alpha_state0 =
|
|
|
|
&authority0->big_state->alpha_state;
|
|
|
|
CoglPipelineAlphaFuncState *alpha_state1 =
|
|
|
|
&authority1->big_state->alpha_state;
|
|
|
|
|
|
|
|
return alpha_state0->alpha_func == alpha_state1->alpha_func;
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2011-09-07 18:44:37 -04:00
|
|
|
_cogl_pipeline_alpha_func_reference_state_equal (CoglPipeline *authority0,
|
|
|
|
CoglPipeline *authority1)
|
|
|
|
{
|
|
|
|
CoglPipelineAlphaFuncState *alpha_state0 =
|
|
|
|
&authority0->big_state->alpha_state;
|
|
|
|
CoglPipelineAlphaFuncState *alpha_state1 =
|
|
|
|
&authority1->big_state->alpha_state;
|
|
|
|
|
|
|
|
return (alpha_state0->alpha_func_reference ==
|
|
|
|
alpha_state1->alpha_func_reference);
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2011-09-07 18:44:37 -04:00
|
|
|
_cogl_pipeline_blend_state_equal (CoglPipeline *authority0,
|
|
|
|
CoglPipeline *authority1)
|
|
|
|
{
|
|
|
|
CoglPipelineBlendState *blend_state0 = &authority0->big_state->blend_state;
|
|
|
|
CoglPipelineBlendState *blend_state1 = &authority1->big_state->blend_state;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
2013-05-29 11:20:58 -04:00
|
|
|
if (blend_state0->blend_equation_rgb != blend_state1->blend_equation_rgb)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (blend_state0->blend_equation_alpha !=
|
|
|
|
blend_state1->blend_equation_alpha)
|
|
|
|
return FALSE;
|
|
|
|
if (blend_state0->blend_src_factor_alpha !=
|
|
|
|
blend_state1->blend_src_factor_alpha)
|
|
|
|
return FALSE;
|
|
|
|
if (blend_state0->blend_dst_factor_alpha !=
|
|
|
|
blend_state1->blend_dst_factor_alpha)
|
|
|
|
return FALSE;
|
|
|
|
|
2011-09-07 18:44:37 -04:00
|
|
|
if (blend_state0->blend_src_factor_rgb !=
|
|
|
|
blend_state1->blend_src_factor_rgb)
|
|
|
|
return FALSE;
|
|
|
|
if (blend_state0->blend_dst_factor_rgb !=
|
|
|
|
blend_state1->blend_dst_factor_rgb)
|
|
|
|
return FALSE;
|
2013-05-29 11:20:58 -04:00
|
|
|
|
|
|
|
if (blend_state0->blend_src_factor_rgb == GL_ONE_MINUS_CONSTANT_COLOR ||
|
|
|
|
blend_state0->blend_src_factor_rgb == GL_CONSTANT_COLOR ||
|
|
|
|
blend_state0->blend_dst_factor_rgb == GL_ONE_MINUS_CONSTANT_COLOR ||
|
|
|
|
blend_state0->blend_dst_factor_rgb == GL_CONSTANT_COLOR)
|
2011-09-07 18:44:37 -04:00
|
|
|
{
|
|
|
|
if (!cogl_color_equal (&blend_state0->blend_constant,
|
|
|
|
&blend_state1->blend_constant))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2011-09-07 18:44:37 -04:00
|
|
|
_cogl_pipeline_depth_state_equal (CoglPipeline *authority0,
|
|
|
|
CoglPipeline *authority1)
|
|
|
|
{
|
|
|
|
if (authority0->big_state->depth_state.test_enabled == FALSE &&
|
|
|
|
authority1->big_state->depth_state.test_enabled == FALSE)
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CoglDepthState *s0 = &authority0->big_state->depth_state;
|
|
|
|
CoglDepthState *s1 = &authority1->big_state->depth_state;
|
|
|
|
return s0->test_enabled == s1->test_enabled &&
|
|
|
|
s0->test_function == s1->test_function &&
|
|
|
|
s0->write_enabled == s1->write_enabled &&
|
|
|
|
s0->range_near == s1->range_near &&
|
|
|
|
s0->range_far == s1->range_far;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2013-06-20 08:25:49 -04:00
|
|
|
_cogl_pipeline_non_zero_point_size_equal (CoglPipeline *authority0,
|
|
|
|
CoglPipeline *authority1)
|
|
|
|
{
|
|
|
|
return (authority0->big_state->non_zero_point_size ==
|
|
|
|
authority1->big_state->non_zero_point_size);
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2011-09-07 18:44:37 -04:00
|
|
|
_cogl_pipeline_point_size_equal (CoglPipeline *authority0,
|
|
|
|
CoglPipeline *authority1)
|
|
|
|
{
|
|
|
|
return authority0->big_state->point_size == authority1->big_state->point_size;
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2012-11-08 11:56:02 -05:00
|
|
|
_cogl_pipeline_per_vertex_point_size_equal (CoglPipeline *authority0,
|
|
|
|
CoglPipeline *authority1)
|
|
|
|
{
|
|
|
|
return (authority0->big_state->per_vertex_point_size ==
|
|
|
|
authority1->big_state->per_vertex_point_size);
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2011-09-15 06:25:39 -04:00
|
|
|
_cogl_pipeline_cull_face_state_equal (CoglPipeline *authority0,
|
|
|
|
CoglPipeline *authority1)
|
|
|
|
{
|
|
|
|
CoglPipelineCullFaceState *cull_face_state0
|
|
|
|
= &authority0->big_state->cull_face_state;
|
|
|
|
CoglPipelineCullFaceState *cull_face_state1
|
|
|
|
= &authority1->big_state->cull_face_state;
|
|
|
|
|
|
|
|
/* The cull face state is considered equal if two pipelines are both
|
|
|
|
set to no culling. If the front winding property is ever used for
|
|
|
|
anything else or the comparison is used not just for drawing then
|
|
|
|
this would have to change */
|
|
|
|
|
|
|
|
if (cull_face_state0->mode == COGL_PIPELINE_CULL_FACE_MODE_NONE)
|
|
|
|
return cull_face_state1->mode == COGL_PIPELINE_CULL_FACE_MODE_NONE;
|
|
|
|
|
|
|
|
return (cull_face_state0->mode == cull_face_state1->mode &&
|
|
|
|
cull_face_state0->front_winding == cull_face_state1->front_winding);
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2011-09-07 18:44:37 -04:00
|
|
|
_cogl_pipeline_user_shader_equal (CoglPipeline *authority0,
|
|
|
|
CoglPipeline *authority1)
|
|
|
|
{
|
|
|
|
return (authority0->big_state->user_program ==
|
|
|
|
authority1->big_state->user_program);
|
|
|
|
}
|
|
|
|
|
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 13:20:43 -04:00
|
|
|
typedef struct
|
|
|
|
{
|
2011-11-04 13:56:44 -04:00
|
|
|
const CoglBoxedValue **dst_values;
|
|
|
|
const CoglBoxedValue *src_values;
|
|
|
|
int override_count;
|
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 13:20:43 -04:00
|
|
|
} GetUniformsClosure;
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
static gboolean
|
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 13:20:43 -04:00
|
|
|
get_uniforms_cb (int uniform_num, void *user_data)
|
|
|
|
{
|
|
|
|
GetUniformsClosure *data = user_data;
|
|
|
|
|
2011-11-04 13:56:44 -04:00
|
|
|
if (data->dst_values[uniform_num] == NULL)
|
|
|
|
data->dst_values[uniform_num] = data->src_values + data->override_count;
|
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 13:20:43 -04:00
|
|
|
|
2011-11-04 13:56:44 -04:00
|
|
|
data->override_count++;
|
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 13:20:43 -04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_pipeline_get_all_uniform_values (CoglPipeline *pipeline,
|
|
|
|
const CoglBoxedValue **values)
|
|
|
|
{
|
|
|
|
GetUniformsClosure data;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
memset (values, 0,
|
|
|
|
sizeof (const CoglBoxedValue *) * ctx->n_uniform_names);
|
|
|
|
|
2011-11-04 13:56:44 -04:00
|
|
|
data.dst_values = values;
|
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 13:20:43 -04:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if ((pipeline->differences & COGL_PIPELINE_STATE_UNIFORMS))
|
2012-02-13 13:48:17 -05:00
|
|
|
{
|
|
|
|
const CoglPipelineUniformsState *uniforms_state =
|
|
|
|
&pipeline->big_state->uniforms_state;
|
|
|
|
|
|
|
|
data.override_count = 0;
|
|
|
|
data.src_values = uniforms_state->override_values;
|
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 13:20:43 -04:00
|
|
|
|
2012-02-13 13:48:17 -05:00
|
|
|
_cogl_bitmask_foreach (&uniforms_state->override_mask,
|
|
|
|
get_uniforms_cb,
|
|
|
|
&data);
|
|
|
|
}
|
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 13:20:43 -04:00
|
|
|
pipeline = _cogl_pipeline_get_parent (pipeline);
|
|
|
|
}
|
|
|
|
while (pipeline);
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
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 13:20:43 -04:00
|
|
|
_cogl_pipeline_uniforms_state_equal (CoglPipeline *authority0,
|
|
|
|
CoglPipeline *authority1)
|
|
|
|
{
|
|
|
|
unsigned long *differences;
|
|
|
|
const CoglBoxedValue **values0, **values1;
|
|
|
|
int n_longs;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
|
|
|
if (authority0 == authority1)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
values0 = g_alloca (sizeof (const CoglBoxedValue *) * ctx->n_uniform_names);
|
|
|
|
values1 = g_alloca (sizeof (const CoglBoxedValue *) * ctx->n_uniform_names);
|
|
|
|
|
|
|
|
n_longs = COGL_FLAGS_N_LONGS_FOR_SIZE (ctx->n_uniform_names);
|
|
|
|
differences = g_alloca (n_longs * sizeof (unsigned long));
|
|
|
|
memset (differences, 0, sizeof (unsigned long) * n_longs);
|
|
|
|
_cogl_pipeline_compare_uniform_differences (differences,
|
|
|
|
authority0,
|
|
|
|
authority1);
|
|
|
|
|
|
|
|
_cogl_pipeline_get_all_uniform_values (authority0, values0);
|
|
|
|
_cogl_pipeline_get_all_uniform_values (authority1, values1);
|
|
|
|
|
|
|
|
COGL_FLAGS_FOREACH_START (differences, n_longs, i)
|
|
|
|
{
|
|
|
|
const CoglBoxedValue *value0 = values0[i];
|
|
|
|
const CoglBoxedValue *value1 = values1[i];
|
|
|
|
|
2011-11-17 11:35:23 -05:00
|
|
|
if (value0 == NULL)
|
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 13:20:43 -04:00
|
|
|
{
|
|
|
|
if (value1 != NULL && value1->type != COGL_BOXED_NONE)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-11-17 11:35:23 -05:00
|
|
|
else if (value1 == NULL)
|
|
|
|
{
|
|
|
|
if (value0 != NULL && value0->type != COGL_BOXED_NONE)
|
|
|
|
return FALSE;
|
|
|
|
}
|
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 13:20:43 -04:00
|
|
|
else if (!_cogl_boxed_value_equal (value0, value1))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
COGL_FLAGS_FOREACH_END;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2011-11-17 11:52:21 -05:00
|
|
|
_cogl_pipeline_vertex_snippets_state_equal (CoglPipeline *authority0,
|
|
|
|
CoglPipeline *authority1)
|
|
|
|
{
|
|
|
|
return _cogl_pipeline_snippet_list_equal (&authority0->big_state->
|
|
|
|
vertex_snippets,
|
|
|
|
&authority1->big_state->
|
|
|
|
vertex_snippets);
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2011-11-17 11:52:21 -05:00
|
|
|
_cogl_pipeline_fragment_snippets_state_equal (CoglPipeline *authority0,
|
|
|
|
CoglPipeline *authority1)
|
|
|
|
{
|
|
|
|
return _cogl_pipeline_snippet_list_equal (&authority0->big_state->
|
|
|
|
fragment_snippets,
|
|
|
|
&authority1->big_state->
|
|
|
|
fragment_snippets);
|
|
|
|
}
|
|
|
|
|
2011-09-07 18:44:37 -04:00
|
|
|
void
|
|
|
|
cogl_pipeline_get_color (CoglPipeline *pipeline,
|
|
|
|
CoglColor *color)
|
|
|
|
{
|
|
|
|
CoglPipeline *authority;
|
|
|
|
|
2019-06-17 17:40:06 -04:00
|
|
|
g_return_if_fail (cogl_is_pipeline (pipeline));
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
authority =
|
|
|
|
_cogl_pipeline_get_authority (pipeline, COGL_PIPELINE_STATE_COLOR);
|
|
|
|
|
|
|
|
*color = authority->color;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is used heavily by the cogl journal when logging quads */
|
|
|
|
void
|
|
|
|
_cogl_pipeline_get_colorubv (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 16:56:40 -04:00
|
|
|
uint8_t *color)
|
2011-09-07 18:44:37 -04:00
|
|
|
{
|
|
|
|
CoglPipeline *authority =
|
|
|
|
_cogl_pipeline_get_authority (pipeline, COGL_PIPELINE_STATE_COLOR);
|
|
|
|
|
|
|
|
_cogl_color_get_rgba_4ubv (&authority->color, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pipeline_set_color (CoglPipeline *pipeline,
|
|
|
|
const CoglColor *color)
|
|
|
|
{
|
|
|
|
CoglPipelineState state = COGL_PIPELINE_STATE_COLOR;
|
|
|
|
CoglPipeline *authority;
|
|
|
|
|
2019-06-17 17:40:06 -04:00
|
|
|
g_return_if_fail (cogl_is_pipeline (pipeline));
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
authority = _cogl_pipeline_get_authority (pipeline, state);
|
|
|
|
|
|
|
|
if (cogl_color_equal (color, &authority->color))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* - Flush journal primitives referencing the current state.
|
|
|
|
* - Make sure the pipeline has no dependants so it may be modified.
|
|
|
|
* - If the pipeline isn't currently an authority for the state being
|
|
|
|
* changed, then initialize that state from the current authority.
|
|
|
|
*/
|
|
|
|
_cogl_pipeline_pre_change_notify (pipeline, state, color, FALSE);
|
|
|
|
|
|
|
|
pipeline->color = *color;
|
|
|
|
|
|
|
|
_cogl_pipeline_update_authority (pipeline, authority, state,
|
|
|
|
_cogl_pipeline_color_equal);
|
|
|
|
|
2013-05-16 10:19:30 -04:00
|
|
|
pipeline->dirty_real_blend_enable = TRUE;
|
2011-09-07 18:44:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pipeline_set_color4ub (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 16:56:40 -04:00
|
|
|
uint8_t red,
|
|
|
|
uint8_t green,
|
|
|
|
uint8_t blue,
|
|
|
|
uint8_t alpha)
|
2011-09-07 18:44:37 -04:00
|
|
|
{
|
|
|
|
CoglColor color;
|
|
|
|
cogl_color_init_from_4ub (&color, red, green, blue, alpha);
|
|
|
|
cogl_pipeline_set_color (pipeline, &color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pipeline_set_color4f (CoglPipeline *pipeline,
|
|
|
|
float red,
|
|
|
|
float green,
|
|
|
|
float blue,
|
|
|
|
float alpha)
|
|
|
|
{
|
|
|
|
CoglColor color;
|
|
|
|
cogl_color_init_from_4f (&color, red, green, blue, alpha);
|
|
|
|
cogl_pipeline_set_color (pipeline, &color);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_pipeline_set_alpha_test_function (CoglPipeline *pipeline,
|
|
|
|
CoglPipelineAlphaFunc alpha_func)
|
|
|
|
{
|
|
|
|
CoglPipelineState state = COGL_PIPELINE_STATE_ALPHA_FUNC;
|
|
|
|
CoglPipeline *authority;
|
|
|
|
CoglPipelineAlphaFuncState *alpha_state;
|
|
|
|
|
2019-06-17 17:40:06 -04:00
|
|
|
g_return_if_fail (cogl_is_pipeline (pipeline));
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
authority = _cogl_pipeline_get_authority (pipeline, state);
|
|
|
|
|
|
|
|
alpha_state = &authority->big_state->alpha_state;
|
|
|
|
if (alpha_state->alpha_func == alpha_func)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* - Flush journal primitives referencing the current state.
|
|
|
|
* - Make sure the pipeline has no dependants so it may be modified.
|
|
|
|
* - If the pipeline isn't currently an authority for the state being
|
|
|
|
* changed, then initialize that state from the current authority.
|
|
|
|
*/
|
|
|
|
_cogl_pipeline_pre_change_notify (pipeline, state, NULL, FALSE);
|
|
|
|
|
|
|
|
alpha_state = &pipeline->big_state->alpha_state;
|
|
|
|
alpha_state->alpha_func = alpha_func;
|
|
|
|
|
|
|
|
_cogl_pipeline_update_authority (pipeline, authority, state,
|
|
|
|
_cogl_pipeline_alpha_func_state_equal);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_pipeline_set_alpha_test_function_reference (CoglPipeline *pipeline,
|
|
|
|
float alpha_reference)
|
|
|
|
{
|
|
|
|
CoglPipelineState state = COGL_PIPELINE_STATE_ALPHA_FUNC_REFERENCE;
|
|
|
|
CoglPipeline *authority;
|
|
|
|
CoglPipelineAlphaFuncState *alpha_state;
|
|
|
|
|
2019-06-17 17:40:06 -04:00
|
|
|
g_return_if_fail (cogl_is_pipeline (pipeline));
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
authority = _cogl_pipeline_get_authority (pipeline, state);
|
|
|
|
|
|
|
|
alpha_state = &authority->big_state->alpha_state;
|
|
|
|
if (alpha_state->alpha_func_reference == alpha_reference)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* - Flush journal primitives referencing the current state.
|
|
|
|
* - Make sure the pipeline has no dependants so it may be modified.
|
|
|
|
* - If the pipeline isn't currently an authority for the state being
|
|
|
|
* changed, then initialize that state from the current authority.
|
|
|
|
*/
|
|
|
|
_cogl_pipeline_pre_change_notify (pipeline, state, NULL, FALSE);
|
|
|
|
|
|
|
|
alpha_state = &pipeline->big_state->alpha_state;
|
|
|
|
alpha_state->alpha_func_reference = alpha_reference;
|
|
|
|
|
|
|
|
_cogl_pipeline_update_authority
|
|
|
|
(pipeline, authority, state,
|
|
|
|
_cogl_pipeline_alpha_func_reference_state_equal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pipeline_set_alpha_test_function (CoglPipeline *pipeline,
|
|
|
|
CoglPipelineAlphaFunc alpha_func,
|
|
|
|
float alpha_reference)
|
|
|
|
{
|
|
|
|
_cogl_pipeline_set_alpha_test_function (pipeline, alpha_func);
|
|
|
|
_cogl_pipeline_set_alpha_test_function_reference (pipeline, alpha_reference);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglPipelineAlphaFunc
|
|
|
|
cogl_pipeline_get_alpha_test_function (CoglPipeline *pipeline)
|
|
|
|
{
|
|
|
|
CoglPipeline *authority;
|
|
|
|
|
2019-06-17 17:42:01 -04:00
|
|
|
g_return_val_if_fail (cogl_is_pipeline (pipeline), 0);
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
authority =
|
|
|
|
_cogl_pipeline_get_authority (pipeline, COGL_PIPELINE_STATE_ALPHA_FUNC);
|
|
|
|
|
|
|
|
return authority->big_state->alpha_state.alpha_func;
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
cogl_pipeline_get_alpha_test_reference (CoglPipeline *pipeline)
|
|
|
|
{
|
|
|
|
CoglPipeline *authority;
|
|
|
|
|
2019-06-17 17:42:01 -04:00
|
|
|
g_return_val_if_fail (cogl_is_pipeline (pipeline), 0.0f);
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
authority =
|
|
|
|
_cogl_pipeline_get_authority (pipeline,
|
|
|
|
COGL_PIPELINE_STATE_ALPHA_FUNC_REFERENCE);
|
|
|
|
|
|
|
|
return authority->big_state->alpha_state.alpha_func_reference;
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:21:28 -05:00
|
|
|
static GLenum
|
2011-09-07 18:44:37 -04:00
|
|
|
arg_to_gl_blend_factor (CoglBlendStringArgument *arg)
|
|
|
|
{
|
|
|
|
if (arg->source.is_zero)
|
|
|
|
return GL_ZERO;
|
|
|
|
if (arg->factor.is_one)
|
|
|
|
return GL_ONE;
|
|
|
|
else if (arg->factor.is_src_alpha_saturate)
|
|
|
|
return GL_SRC_ALPHA_SATURATE;
|
|
|
|
else if (arg->factor.source.info->type ==
|
|
|
|
COGL_BLEND_STRING_COLOR_SOURCE_SRC_COLOR)
|
|
|
|
{
|
|
|
|
if (arg->factor.source.mask != COGL_BLEND_STRING_CHANNEL_MASK_ALPHA)
|
|
|
|
{
|
|
|
|
if (arg->factor.source.one_minus)
|
|
|
|
return GL_ONE_MINUS_SRC_COLOR;
|
|
|
|
else
|
|
|
|
return GL_SRC_COLOR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (arg->factor.source.one_minus)
|
|
|
|
return GL_ONE_MINUS_SRC_ALPHA;
|
|
|
|
else
|
|
|
|
return GL_SRC_ALPHA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (arg->factor.source.info->type ==
|
|
|
|
COGL_BLEND_STRING_COLOR_SOURCE_DST_COLOR)
|
|
|
|
{
|
|
|
|
if (arg->factor.source.mask != COGL_BLEND_STRING_CHANNEL_MASK_ALPHA)
|
|
|
|
{
|
|
|
|
if (arg->factor.source.one_minus)
|
|
|
|
return GL_ONE_MINUS_DST_COLOR;
|
|
|
|
else
|
|
|
|
return GL_DST_COLOR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (arg->factor.source.one_minus)
|
|
|
|
return GL_ONE_MINUS_DST_ALPHA;
|
|
|
|
else
|
|
|
|
return GL_DST_ALPHA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if defined(HAVE_COGL_GLES2) || defined(HAVE_COGL_GL)
|
|
|
|
else if (arg->factor.source.info->type ==
|
|
|
|
COGL_BLEND_STRING_COLOR_SOURCE_CONSTANT)
|
|
|
|
{
|
|
|
|
if (arg->factor.source.mask != COGL_BLEND_STRING_CHANNEL_MASK_ALPHA)
|
|
|
|
{
|
|
|
|
if (arg->factor.source.one_minus)
|
|
|
|
return GL_ONE_MINUS_CONSTANT_COLOR;
|
|
|
|
else
|
|
|
|
return GL_CONSTANT_COLOR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (arg->factor.source.one_minus)
|
|
|
|
return GL_ONE_MINUS_CONSTANT_ALPHA;
|
|
|
|
else
|
|
|
|
return GL_CONSTANT_ALPHA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
g_warning ("Unable to determine valid blend factor from blend string\n");
|
|
|
|
return GL_ONE;
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:21:28 -05:00
|
|
|
static void
|
2011-09-07 18:44:37 -04:00
|
|
|
setup_blend_state (CoglBlendStringStatement *statement,
|
|
|
|
GLenum *blend_equation,
|
|
|
|
GLint *blend_src_factor,
|
|
|
|
GLint *blend_dst_factor)
|
|
|
|
{
|
|
|
|
switch (statement->function->type)
|
|
|
|
{
|
|
|
|
case COGL_BLEND_STRING_FUNCTION_ADD:
|
|
|
|
*blend_equation = GL_FUNC_ADD;
|
|
|
|
break;
|
|
|
|
/* TODO - add more */
|
|
|
|
default:
|
|
|
|
g_warning ("Unsupported blend function given");
|
|
|
|
*blend_equation = GL_FUNC_ADD;
|
|
|
|
}
|
|
|
|
|
|
|
|
*blend_src_factor = arg_to_gl_blend_factor (&statement->args[0]);
|
|
|
|
*blend_dst_factor = arg_to_gl_blend_factor (&statement->args[1]);
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2011-09-07 18:44:37 -04:00
|
|
|
cogl_pipeline_set_blend (CoglPipeline *pipeline,
|
|
|
|
const char *blend_description,
|
2019-06-18 02:02:10 -04:00
|
|
|
GError **error)
|
2011-09-07 18:44:37 -04:00
|
|
|
{
|
|
|
|
CoglPipelineState state = COGL_PIPELINE_STATE_BLEND;
|
|
|
|
CoglPipeline *authority;
|
|
|
|
CoglBlendStringStatement statements[2];
|
|
|
|
CoglBlendStringStatement *rgb;
|
|
|
|
CoglBlendStringStatement *a;
|
|
|
|
int count;
|
|
|
|
CoglPipelineBlendState *blend_state;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
2019-06-17 17:42:01 -04:00
|
|
|
g_return_val_if_fail (cogl_is_pipeline (pipeline), FALSE);
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
count =
|
|
|
|
_cogl_blend_string_compile (blend_description,
|
|
|
|
COGL_BLEND_STRING_CONTEXT_BLENDING,
|
|
|
|
statements,
|
2012-08-31 14:28:27 -04:00
|
|
|
error);
|
2011-09-07 18:44:37 -04:00
|
|
|
if (!count)
|
2012-08-31 14:28:27 -04:00
|
|
|
return FALSE;
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
if (count == 1)
|
|
|
|
rgb = a = statements;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rgb = &statements[0];
|
|
|
|
a = &statements[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
authority =
|
|
|
|
_cogl_pipeline_get_authority (pipeline, state);
|
|
|
|
|
|
|
|
/* - Flush journal primitives referencing the current state.
|
|
|
|
* - Make sure the pipeline has no dependants so it may be modified.
|
|
|
|
* - If the pipeline isn't currently an authority for the state being
|
|
|
|
* changed, then initialize that state from the current authority.
|
|
|
|
*/
|
|
|
|
_cogl_pipeline_pre_change_notify (pipeline, state, NULL, FALSE);
|
|
|
|
|
|
|
|
blend_state = &pipeline->big_state->blend_state;
|
2013-05-29 11:20:58 -04:00
|
|
|
|
|
|
|
setup_blend_state (rgb,
|
|
|
|
&blend_state->blend_equation_rgb,
|
|
|
|
&blend_state->blend_src_factor_rgb,
|
|
|
|
&blend_state->blend_dst_factor_rgb);
|
|
|
|
setup_blend_state (a,
|
|
|
|
&blend_state->blend_equation_alpha,
|
|
|
|
&blend_state->blend_src_factor_alpha,
|
|
|
|
&blend_state->blend_dst_factor_alpha);
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
/* If we are the current authority see if we can revert to one of our
|
|
|
|
* ancestors being the authority */
|
|
|
|
if (pipeline == authority &&
|
|
|
|
_cogl_pipeline_get_parent (authority) != NULL)
|
|
|
|
{
|
|
|
|
CoglPipeline *parent = _cogl_pipeline_get_parent (authority);
|
|
|
|
CoglPipeline *old_authority =
|
|
|
|
_cogl_pipeline_get_authority (parent, state);
|
|
|
|
|
|
|
|
if (_cogl_pipeline_blend_state_equal (authority, old_authority))
|
|
|
|
pipeline->differences &= ~state;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we weren't previously the authority on this state then we need
|
|
|
|
* to extended our differences mask and so it's possible that some
|
|
|
|
* of our ancestry will now become redundant, so we aim to reparent
|
|
|
|
* ourselves if that's true... */
|
|
|
|
if (pipeline != authority)
|
|
|
|
{
|
|
|
|
pipeline->differences |= state;
|
|
|
|
_cogl_pipeline_prune_redundant_ancestry (pipeline);
|
|
|
|
}
|
|
|
|
|
2013-05-16 10:19:30 -04:00
|
|
|
pipeline->dirty_real_blend_enable = TRUE;
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pipeline_set_blend_constant (CoglPipeline *pipeline,
|
|
|
|
const CoglColor *constant_color)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2019-06-17 17:40:06 -04:00
|
|
|
g_return_if_fail (cogl_is_pipeline (pipeline));
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
#if defined(HAVE_COGL_GLES2) || defined(HAVE_COGL_GL)
|
|
|
|
{
|
|
|
|
CoglPipelineState state = COGL_PIPELINE_STATE_BLEND;
|
|
|
|
CoglPipeline *authority;
|
|
|
|
CoglPipelineBlendState *blend_state;
|
|
|
|
|
|
|
|
authority = _cogl_pipeline_get_authority (pipeline, state);
|
|
|
|
|
|
|
|
blend_state = &authority->big_state->blend_state;
|
|
|
|
if (cogl_color_equal (constant_color, &blend_state->blend_constant))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* - Flush journal primitives referencing the current state.
|
|
|
|
* - Make sure the pipeline has no dependants so it may be modified.
|
|
|
|
* - If the pipeline isn't currently an authority for the state being
|
|
|
|
* changed, then initialize that state from the current authority.
|
|
|
|
*/
|
|
|
|
_cogl_pipeline_pre_change_notify (pipeline, state, NULL, FALSE);
|
|
|
|
|
|
|
|
blend_state = &pipeline->big_state->blend_state;
|
|
|
|
blend_state->blend_constant = *constant_color;
|
|
|
|
|
|
|
|
_cogl_pipeline_update_authority (pipeline, authority, state,
|
|
|
|
_cogl_pipeline_blend_state_equal);
|
|
|
|
|
2013-05-16 10:19:30 -04:00
|
|
|
pipeline->dirty_real_blend_enable = TRUE;
|
2011-09-07 18:44:37 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglHandle
|
|
|
|
cogl_pipeline_get_user_program (CoglPipeline *pipeline)
|
|
|
|
{
|
|
|
|
CoglPipeline *authority;
|
|
|
|
|
2019-02-20 08:53:01 -05:00
|
|
|
g_return_val_if_fail (cogl_is_pipeline (pipeline), NULL);
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
authority =
|
|
|
|
_cogl_pipeline_get_authority (pipeline, COGL_PIPELINE_STATE_USER_SHADER);
|
|
|
|
|
|
|
|
return authority->big_state->user_program;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: for now we don't mind if the program has vertex shaders
|
|
|
|
* attached but if we ever make a similar API public we should only
|
|
|
|
* allow attaching of programs containing fragment shaders. Eventually
|
|
|
|
* we will have a CoglPipeline abstraction to also cover vertex
|
|
|
|
* processing.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cogl_pipeline_set_user_program (CoglPipeline *pipeline,
|
|
|
|
CoglHandle program)
|
|
|
|
{
|
|
|
|
CoglPipelineState state = COGL_PIPELINE_STATE_USER_SHADER;
|
|
|
|
CoglPipeline *authority;
|
|
|
|
|
2019-06-17 17:40:06 -04:00
|
|
|
g_return_if_fail (cogl_is_pipeline (pipeline));
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
authority = _cogl_pipeline_get_authority (pipeline, state);
|
|
|
|
|
|
|
|
if (authority->big_state->user_program == program)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* - Flush journal primitives referencing the current state.
|
|
|
|
* - Make sure the pipeline has no dependants so it may be modified.
|
|
|
|
* - If the pipeline isn't currently an authority for the state being
|
|
|
|
* changed, then initialize that state from the current authority.
|
|
|
|
*/
|
|
|
|
_cogl_pipeline_pre_change_notify (pipeline, state, NULL, FALSE);
|
|
|
|
|
|
|
|
/* If we are the current authority see if we can revert to one of our
|
|
|
|
* ancestors being the authority */
|
|
|
|
if (pipeline == authority &&
|
|
|
|
_cogl_pipeline_get_parent (authority) != NULL)
|
|
|
|
{
|
|
|
|
CoglPipeline *parent = _cogl_pipeline_get_parent (authority);
|
|
|
|
CoglPipeline *old_authority =
|
|
|
|
_cogl_pipeline_get_authority (parent, state);
|
|
|
|
|
|
|
|
if (old_authority->big_state->user_program == program)
|
|
|
|
pipeline->differences &= ~state;
|
|
|
|
}
|
|
|
|
else if (pipeline != authority)
|
|
|
|
{
|
|
|
|
/* If we weren't previously the authority on this state then we
|
|
|
|
* need to extended our differences mask and so it's possible
|
|
|
|
* that some of our ancestry will now become redundant, so we
|
|
|
|
* aim to reparent ourselves if that's true... */
|
|
|
|
pipeline->differences |= state;
|
|
|
|
_cogl_pipeline_prune_redundant_ancestry (pipeline);
|
|
|
|
}
|
|
|
|
|
2019-02-20 08:53:01 -05:00
|
|
|
if (program != NULL)
|
2019-02-20 08:51:12 -05:00
|
|
|
cogl_object_ref (program);
|
2011-09-07 18:44:37 -04:00
|
|
|
if (authority == pipeline &&
|
2019-02-20 08:53:01 -05:00
|
|
|
pipeline->big_state->user_program != NULL)
|
2019-02-20 08:51:12 -05:00
|
|
|
cogl_object_unref (pipeline->big_state->user_program);
|
2011-09-07 18:44:37 -04:00
|
|
|
pipeline->big_state->user_program = program;
|
|
|
|
|
2013-05-16 10:19:30 -04:00
|
|
|
pipeline->dirty_real_blend_enable = TRUE;
|
2011-09-07 18:44:37 -04:00
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2011-09-07 18:44:37 -04:00
|
|
|
cogl_pipeline_set_depth_state (CoglPipeline *pipeline,
|
|
|
|
const CoglDepthState *depth_state,
|
2019-06-18 02:02:10 -04:00
|
|
|
GError **error)
|
2011-09-07 18:44:37 -04:00
|
|
|
{
|
|
|
|
CoglPipelineState state = COGL_PIPELINE_STATE_DEPTH;
|
|
|
|
CoglPipeline *authority;
|
|
|
|
CoglDepthState *orig_state;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
2019-06-17 17:42:01 -04:00
|
|
|
g_return_val_if_fail (cogl_is_pipeline (pipeline), FALSE);
|
|
|
|
g_return_val_if_fail (depth_state->magic == COGL_DEPTH_STATE_MAGIC, FALSE);
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
authority = _cogl_pipeline_get_authority (pipeline, state);
|
|
|
|
|
|
|
|
orig_state = &authority->big_state->depth_state;
|
|
|
|
if (orig_state->test_enabled == depth_state->test_enabled &&
|
|
|
|
orig_state->write_enabled == depth_state->write_enabled &&
|
|
|
|
orig_state->test_function == depth_state->test_function &&
|
|
|
|
orig_state->range_near == depth_state->range_near &&
|
|
|
|
orig_state->range_far == depth_state->range_far)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* - Flush journal primitives referencing the current state.
|
|
|
|
* - Make sure the pipeline has no dependants so it may be modified.
|
|
|
|
* - If the pipeline isn't currently an authority for the state being
|
|
|
|
* changed, then initialize that state from the current authority.
|
|
|
|
*/
|
|
|
|
_cogl_pipeline_pre_change_notify (pipeline, state, NULL, FALSE);
|
|
|
|
|
|
|
|
pipeline->big_state->depth_state = *depth_state;
|
|
|
|
|
|
|
|
_cogl_pipeline_update_authority (pipeline, authority, state,
|
|
|
|
_cogl_pipeline_depth_state_equal);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pipeline_get_depth_state (CoglPipeline *pipeline,
|
|
|
|
CoglDepthState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *authority;
|
|
|
|
|
2019-06-17 17:40:06 -04:00
|
|
|
g_return_if_fail (cogl_is_pipeline (pipeline));
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
authority =
|
|
|
|
_cogl_pipeline_get_authority (pipeline, COGL_PIPELINE_STATE_DEPTH);
|
|
|
|
*state = authority->big_state->depth_state;
|
|
|
|
}
|
|
|
|
|
2011-09-15 06:25:39 -04:00
|
|
|
void
|
2011-11-08 08:58:33 -05:00
|
|
|
cogl_pipeline_set_cull_face_mode (CoglPipeline *pipeline,
|
|
|
|
CoglPipelineCullFaceMode cull_face_mode)
|
2011-09-15 06:25:39 -04:00
|
|
|
{
|
|
|
|
CoglPipelineState state = COGL_PIPELINE_STATE_CULL_FACE;
|
|
|
|
CoglPipeline *authority;
|
2011-11-08 08:58:33 -05:00
|
|
|
CoglPipelineCullFaceState *cull_face_state;
|
2011-09-15 06:25:39 -04:00
|
|
|
|
2019-06-17 17:40:06 -04:00
|
|
|
g_return_if_fail (cogl_is_pipeline (pipeline));
|
2011-09-15 06:25:39 -04:00
|
|
|
|
|
|
|
authority = _cogl_pipeline_get_authority (pipeline, state);
|
|
|
|
|
2011-11-08 08:58:33 -05:00
|
|
|
cull_face_state = &authority->big_state->cull_face_state;
|
2011-09-15 06:25:39 -04:00
|
|
|
|
2011-11-08 08:58:33 -05:00
|
|
|
if (cull_face_state->mode == cull_face_mode)
|
2011-09-15 06:25:39 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* - Flush journal primitives referencing the current state.
|
|
|
|
* - Make sure the pipeline has no dependants so it may be modified.
|
|
|
|
* - If the pipeline isn't currently an authority for the state being
|
|
|
|
* changed, then initialize that state from the current authority.
|
|
|
|
*/
|
|
|
|
_cogl_pipeline_pre_change_notify (pipeline, state, NULL, FALSE);
|
|
|
|
|
2011-11-08 08:58:33 -05:00
|
|
|
pipeline->big_state->cull_face_state.mode = cull_face_mode;
|
|
|
|
|
|
|
|
_cogl_pipeline_update_authority (pipeline, authority, state,
|
|
|
|
_cogl_pipeline_cull_face_state_equal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pipeline_set_front_face_winding (CoglPipeline *pipeline,
|
|
|
|
CoglWinding front_winding)
|
|
|
|
{
|
|
|
|
CoglPipelineState state = COGL_PIPELINE_STATE_CULL_FACE;
|
|
|
|
CoglPipeline *authority;
|
|
|
|
CoglPipelineCullFaceState *cull_face_state;
|
|
|
|
|
2019-06-17 17:40:06 -04:00
|
|
|
g_return_if_fail (cogl_is_pipeline (pipeline));
|
2011-11-08 08:58:33 -05:00
|
|
|
|
|
|
|
authority = _cogl_pipeline_get_authority (pipeline, state);
|
|
|
|
|
|
|
|
cull_face_state = &authority->big_state->cull_face_state;
|
|
|
|
|
|
|
|
if (cull_face_state->front_winding == front_winding)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* - Flush journal primitives referencing the current state.
|
|
|
|
* - Make sure the pipeline has no dependants so it may be modified.
|
|
|
|
* - If the pipeline isn't currently an authority for the state being
|
|
|
|
* changed, then initialize that state from the current authority.
|
|
|
|
*/
|
|
|
|
_cogl_pipeline_pre_change_notify (pipeline, state, NULL, FALSE);
|
|
|
|
|
|
|
|
pipeline->big_state->cull_face_state.front_winding = front_winding;
|
2011-09-15 06:25:39 -04:00
|
|
|
|
|
|
|
_cogl_pipeline_update_authority (pipeline, authority, state,
|
|
|
|
_cogl_pipeline_cull_face_state_equal);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglPipelineCullFaceMode
|
2011-11-08 08:58:33 -05:00
|
|
|
cogl_pipeline_get_cull_face_mode (CoglPipeline *pipeline)
|
2011-09-15 06:25:39 -04:00
|
|
|
{
|
|
|
|
CoglPipelineState state = COGL_PIPELINE_STATE_CULL_FACE;
|
|
|
|
CoglPipeline *authority;
|
|
|
|
|
2019-06-17 17:42:01 -04:00
|
|
|
g_return_val_if_fail (cogl_is_pipeline (pipeline),
|
|
|
|
COGL_PIPELINE_CULL_FACE_MODE_NONE);
|
2011-09-15 06:25:39 -04:00
|
|
|
|
|
|
|
authority = _cogl_pipeline_get_authority (pipeline, state);
|
|
|
|
|
|
|
|
return authority->big_state->cull_face_state.mode;
|
|
|
|
}
|
|
|
|
|
2011-11-08 08:58:33 -05:00
|
|
|
CoglWinding
|
|
|
|
cogl_pipeline_get_front_face_winding (CoglPipeline *pipeline)
|
|
|
|
{
|
|
|
|
CoglPipelineState state = COGL_PIPELINE_STATE_CULL_FACE;
|
|
|
|
CoglPipeline *authority;
|
|
|
|
|
2019-06-17 17:42:01 -04:00
|
|
|
g_return_val_if_fail (cogl_is_pipeline (pipeline),
|
2019-11-13 14:16:59 -05:00
|
|
|
COGL_WINDING_CLOCKWISE);
|
2011-11-08 08:58:33 -05:00
|
|
|
|
|
|
|
authority = _cogl_pipeline_get_authority (pipeline, state);
|
|
|
|
|
|
|
|
return authority->big_state->cull_face_state.front_winding;
|
|
|
|
}
|
|
|
|
|
2011-09-07 18:44:37 -04:00
|
|
|
float
|
|
|
|
cogl_pipeline_get_point_size (CoglPipeline *pipeline)
|
|
|
|
{
|
|
|
|
CoglPipeline *authority;
|
|
|
|
|
2019-06-17 17:42:01 -04:00
|
|
|
g_return_val_if_fail (cogl_is_pipeline (pipeline), FALSE);
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
authority =
|
|
|
|
_cogl_pipeline_get_authority (pipeline, COGL_PIPELINE_STATE_POINT_SIZE);
|
|
|
|
|
|
|
|
return authority->big_state->point_size;
|
|
|
|
}
|
|
|
|
|
2013-06-20 08:25:49 -04:00
|
|
|
static void
|
|
|
|
_cogl_pipeline_set_non_zero_point_size (CoglPipeline *pipeline,
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean value)
|
2013-06-20 08:25:49 -04:00
|
|
|
{
|
|
|
|
CoglPipelineState state = COGL_PIPELINE_STATE_NON_ZERO_POINT_SIZE;
|
|
|
|
CoglPipeline *authority;
|
|
|
|
|
2019-06-17 17:40:06 -04:00
|
|
|
g_return_if_fail (cogl_is_pipeline (pipeline));
|
2013-06-20 08:25:49 -04:00
|
|
|
|
|
|
|
authority = _cogl_pipeline_get_authority (pipeline, state);
|
|
|
|
|
|
|
|
/* - Flush journal primitives referencing the current state.
|
|
|
|
* - Make sure the pipeline has no dependants so it may be modified.
|
|
|
|
* - If the pipeline isn't currently an authority for the state being
|
|
|
|
* changed, then initialize that state from the current authority.
|
|
|
|
*/
|
|
|
|
_cogl_pipeline_pre_change_notify (pipeline, state, NULL, FALSE);
|
|
|
|
|
|
|
|
pipeline->big_state->non_zero_point_size = !!value;
|
|
|
|
|
|
|
|
_cogl_pipeline_update_authority (pipeline, authority, state,
|
|
|
|
_cogl_pipeline_non_zero_point_size_equal);
|
|
|
|
}
|
|
|
|
|
2011-09-07 18:44:37 -04:00
|
|
|
void
|
|
|
|
cogl_pipeline_set_point_size (CoglPipeline *pipeline,
|
|
|
|
float point_size)
|
|
|
|
{
|
|
|
|
CoglPipelineState state = COGL_PIPELINE_STATE_POINT_SIZE;
|
|
|
|
CoglPipeline *authority;
|
|
|
|
|
2019-06-17 17:40:06 -04:00
|
|
|
g_return_if_fail (cogl_is_pipeline (pipeline));
|
2011-09-07 18:44:37 -04:00
|
|
|
|
|
|
|
authority = _cogl_pipeline_get_authority (pipeline, state);
|
|
|
|
|
|
|
|
if (authority->big_state->point_size == point_size)
|
|
|
|
return;
|
|
|
|
|
2013-06-20 08:25:49 -04:00
|
|
|
/* Changing the point size may additionally modify
|
|
|
|
* COGL_PIPELINE_STATE_NON_ZERO_POINT_SIZE. */
|
|
|
|
|
|
|
|
if ((authority->big_state->point_size > 0.0f) != (point_size > 0.0f))
|
|
|
|
_cogl_pipeline_set_non_zero_point_size (pipeline, point_size > 0.0f);
|
|
|
|
|
2011-09-07 18:44:37 -04:00
|
|
|
/* - Flush journal primitives referencing the current state.
|
|
|
|
* - Make sure the pipeline has no dependants so it may be modified.
|
|
|
|
* - If the pipeline isn't currently an authority for the state being
|
|
|
|
* changed, then initialize that state from the current authority.
|
|
|
|
*/
|
|
|
|
_cogl_pipeline_pre_change_notify (pipeline, state, NULL, FALSE);
|
|
|
|
|
|
|
|
pipeline->big_state->point_size = point_size;
|
|
|
|
|
|
|
|
_cogl_pipeline_update_authority (pipeline, authority, state,
|
|
|
|
_cogl_pipeline_point_size_equal);
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2012-11-08 11:56:02 -05:00
|
|
|
cogl_pipeline_set_per_vertex_point_size (CoglPipeline *pipeline,
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean enable,
|
2019-06-18 02:02:10 -04:00
|
|
|
GError **error)
|
2012-11-08 11:56:02 -05:00
|
|
|
{
|
|
|
|
CoglPipelineState state = COGL_PIPELINE_STATE_PER_VERTEX_POINT_SIZE;
|
|
|
|
CoglPipeline *authority;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
2019-06-17 17:42:01 -04:00
|
|
|
g_return_val_if_fail (cogl_is_pipeline (pipeline), FALSE);
|
2012-11-08 11:56:02 -05:00
|
|
|
|
|
|
|
authority = _cogl_pipeline_get_authority (pipeline, state);
|
|
|
|
|
|
|
|
enable = !!enable;
|
|
|
|
|
|
|
|
if (authority->big_state->per_vertex_point_size == enable)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* - Flush journal primitives referencing the current state.
|
|
|
|
* - Make sure the pipeline has no dependants so it may be modified.
|
|
|
|
* - If the pipeline isn't currently an authority for the state being
|
|
|
|
* changed, then initialize that state from the current authority.
|
|
|
|
*/
|
|
|
|
_cogl_pipeline_pre_change_notify (pipeline, state, NULL, FALSE);
|
|
|
|
|
|
|
|
pipeline->big_state->per_vertex_point_size = enable;
|
|
|
|
|
|
|
|
_cogl_pipeline_update_authority (pipeline, authority, state,
|
|
|
|
_cogl_pipeline_point_size_equal);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2012-11-08 11:56:02 -05:00
|
|
|
cogl_pipeline_get_per_vertex_point_size (CoglPipeline *pipeline)
|
|
|
|
{
|
|
|
|
CoglPipeline *authority;
|
|
|
|
|
2019-06-17 17:42:01 -04:00
|
|
|
g_return_val_if_fail (cogl_is_pipeline (pipeline), FALSE);
|
2012-11-08 11:56:02 -05:00
|
|
|
|
|
|
|
authority =
|
|
|
|
_cogl_pipeline_get_authority (pipeline,
|
|
|
|
COGL_PIPELINE_STATE_PER_VERTEX_POINT_SIZE);
|
|
|
|
|
|
|
|
return authority->big_state->per_vertex_point_size;
|
|
|
|
}
|
|
|
|
|
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 13:20:43 -04:00
|
|
|
static CoglBoxedValue *
|
|
|
|
_cogl_pipeline_override_uniform (CoglPipeline *pipeline,
|
|
|
|
int location)
|
|
|
|
{
|
|
|
|
CoglPipelineState state = COGL_PIPELINE_STATE_UNIFORMS;
|
|
|
|
CoglPipelineUniformsState *uniforms_state;
|
2011-11-04 13:56:44 -04:00
|
|
|
int override_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 13:20:43 -04:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NULL);
|
|
|
|
|
|
|
|
g_return_val_if_fail (cogl_is_pipeline (pipeline), NULL);
|
|
|
|
g_return_val_if_fail (location >= 0, NULL);
|
|
|
|
g_return_val_if_fail (location < ctx->n_uniform_names, NULL);
|
|
|
|
|
|
|
|
/* - Flush journal primitives referencing the current state.
|
|
|
|
* - Make sure the pipeline has no dependants so it may be modified.
|
|
|
|
* - If the pipeline isn't currently an authority for the state being
|
|
|
|
* changed, then initialize that state from the current authority.
|
|
|
|
*/
|
|
|
|
_cogl_pipeline_pre_change_notify (pipeline, state, NULL, FALSE);
|
|
|
|
|
|
|
|
uniforms_state = &pipeline->big_state->uniforms_state;
|
|
|
|
|
2011-11-04 13:56:44 -04:00
|
|
|
/* Count the number of bits that are set below this location. That
|
|
|
|
should give us the position where our new value should lie */
|
|
|
|
override_index = _cogl_bitmask_popcount_upto (&uniforms_state->override_mask,
|
|
|
|
location);
|
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 13:20:43 -04:00
|
|
|
|
|
|
|
_cogl_bitmask_set (&uniforms_state->changed_mask, location, TRUE);
|
|
|
|
|
|
|
|
/* If this pipeline already has an override for this value then we
|
|
|
|
can just use it directly */
|
2011-11-04 13:56:44 -04:00
|
|
|
if (_cogl_bitmask_get (&uniforms_state->override_mask, location))
|
|
|
|
return uniforms_state->override_values + override_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 13:20:43 -04:00
|
|
|
|
2011-11-04 13:56:44 -04:00
|
|
|
/* We need to create a new override value in the right position
|
|
|
|
within the array. This is pretty inefficient but the hope is that
|
|
|
|
it will be much more common to modify an existing uniform rather
|
|
|
|
than modify a new one so it is more important to optimise the
|
|
|
|
former case. */
|
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 13:20:43 -04:00
|
|
|
|
2011-11-04 13:56:44 -04:00
|
|
|
if (uniforms_state->override_values == NULL)
|
|
|
|
{
|
|
|
|
g_assert (override_index == 0);
|
|
|
|
uniforms_state->override_values = g_new (CoglBoxedValue, 1);
|
|
|
|
}
|
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 13:20:43 -04:00
|
|
|
else
|
2011-11-04 13:56:44 -04:00
|
|
|
{
|
|
|
|
/* We need to grow the array and copy in the old values */
|
|
|
|
CoglBoxedValue *old_values = uniforms_state->override_values;
|
|
|
|
int old_size = _cogl_bitmask_popcount (&uniforms_state->override_mask);
|
|
|
|
|
|
|
|
uniforms_state->override_values = g_new (CoglBoxedValue, old_size + 1);
|
|
|
|
|
|
|
|
/* Copy in the old values leaving a gap for the new value */
|
|
|
|
memcpy (uniforms_state->override_values,
|
|
|
|
old_values,
|
|
|
|
sizeof (CoglBoxedValue) * override_index);
|
2011-12-29 20:08:10 -05:00
|
|
|
memcpy (uniforms_state->override_values + override_index + 1,
|
|
|
|
old_values + override_index,
|
2011-11-04 13:56:44 -04:00
|
|
|
sizeof (CoglBoxedValue) * (old_size - override_index));
|
|
|
|
|
|
|
|
g_free (old_values);
|
|
|
|
}
|
|
|
|
|
|
|
|
_cogl_boxed_value_init (uniforms_state->override_values + override_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 13:20:43 -04:00
|
|
|
|
|
|
|
_cogl_bitmask_set (&uniforms_state->override_mask, location, TRUE);
|
|
|
|
|
2011-11-04 13:56:44 -04:00
|
|
|
return uniforms_state->override_values + override_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 13:20:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pipeline_set_uniform_1f (CoglPipeline *pipeline,
|
|
|
|
int uniform_location,
|
|
|
|
float value)
|
|
|
|
{
|
|
|
|
CoglBoxedValue *boxed_value;
|
|
|
|
|
|
|
|
boxed_value = _cogl_pipeline_override_uniform (pipeline, uniform_location);
|
|
|
|
|
|
|
|
_cogl_boxed_value_set_1f (boxed_value, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pipeline_set_uniform_1i (CoglPipeline *pipeline,
|
|
|
|
int uniform_location,
|
|
|
|
int value)
|
|
|
|
{
|
|
|
|
CoglBoxedValue *boxed_value;
|
|
|
|
|
|
|
|
boxed_value = _cogl_pipeline_override_uniform (pipeline, uniform_location);
|
|
|
|
|
|
|
|
_cogl_boxed_value_set_1i (boxed_value, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pipeline_set_uniform_float (CoglPipeline *pipeline,
|
|
|
|
int uniform_location,
|
|
|
|
int n_components,
|
|
|
|
int count,
|
|
|
|
const float *value)
|
|
|
|
{
|
|
|
|
CoglBoxedValue *boxed_value;
|
|
|
|
|
|
|
|
boxed_value = _cogl_pipeline_override_uniform (pipeline, uniform_location);
|
|
|
|
|
|
|
|
_cogl_boxed_value_set_float (boxed_value, n_components, count, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pipeline_set_uniform_int (CoglPipeline *pipeline,
|
|
|
|
int uniform_location,
|
|
|
|
int n_components,
|
|
|
|
int count,
|
|
|
|
const int *value)
|
|
|
|
{
|
|
|
|
CoglBoxedValue *boxed_value;
|
|
|
|
|
|
|
|
boxed_value = _cogl_pipeline_override_uniform (pipeline, uniform_location);
|
|
|
|
|
|
|
|
_cogl_boxed_value_set_int (boxed_value, n_components, count, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pipeline_set_uniform_matrix (CoglPipeline *pipeline,
|
|
|
|
int uniform_location,
|
|
|
|
int dimensions,
|
|
|
|
int count,
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean transpose,
|
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 13:20:43 -04:00
|
|
|
const float *value)
|
|
|
|
{
|
|
|
|
CoglBoxedValue *boxed_value;
|
|
|
|
|
|
|
|
boxed_value = _cogl_pipeline_override_uniform (pipeline, uniform_location);
|
|
|
|
|
|
|
|
_cogl_boxed_value_set_matrix (boxed_value,
|
|
|
|
dimensions,
|
|
|
|
count,
|
|
|
|
transpose,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
2011-11-17 11:52:21 -05:00
|
|
|
static void
|
|
|
|
_cogl_pipeline_add_vertex_snippet (CoglPipeline *pipeline,
|
|
|
|
CoglSnippet *snippet)
|
|
|
|
{
|
|
|
|
CoglPipelineState state = COGL_PIPELINE_STATE_VERTEX_SNIPPETS;
|
|
|
|
|
|
|
|
/* - Flush journal primitives referencing the current state.
|
|
|
|
* - Make sure the pipeline has no dependants so it may be modified.
|
|
|
|
* - If the pipeline isn't currently an authority for the state being
|
|
|
|
* changed, then initialize that state from the current authority.
|
|
|
|
*/
|
|
|
|
_cogl_pipeline_pre_change_notify (pipeline, state, NULL, FALSE);
|
|
|
|
|
|
|
|
_cogl_pipeline_snippet_list_add (&pipeline->big_state->vertex_snippets,
|
|
|
|
snippet);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_pipeline_add_fragment_snippet (CoglPipeline *pipeline,
|
|
|
|
CoglSnippet *snippet)
|
|
|
|
{
|
|
|
|
CoglPipelineState state = COGL_PIPELINE_STATE_FRAGMENT_SNIPPETS;
|
|
|
|
|
|
|
|
/* - Flush journal primitives referencing the current state.
|
|
|
|
* - Make sure the pipeline has no dependants so it may be modified.
|
|
|
|
* - If the pipeline isn't currently an authority for the state being
|
|
|
|
* changed, then initialize that state from the current authority.
|
|
|
|
*/
|
|
|
|
_cogl_pipeline_pre_change_notify (pipeline, state, NULL, FALSE);
|
|
|
|
|
|
|
|
_cogl_pipeline_snippet_list_add (&pipeline->big_state->fragment_snippets,
|
|
|
|
snippet);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-11-25 15:54:14 -05:00
|
|
|
cogl_pipeline_add_snippet (CoglPipeline *pipeline,
|
|
|
|
CoglSnippet *snippet)
|
2011-11-17 11:52:21 -05:00
|
|
|
{
|
2011-11-25 15:54:14 -05:00
|
|
|
g_return_if_fail (cogl_is_pipeline (pipeline));
|
|
|
|
g_return_if_fail (cogl_is_snippet (snippet));
|
|
|
|
g_return_if_fail (snippet->hook < COGL_SNIPPET_FIRST_LAYER_HOOK);
|
|
|
|
|
|
|
|
if (snippet->hook < COGL_SNIPPET_FIRST_PIPELINE_FRAGMENT_HOOK)
|
|
|
|
_cogl_pipeline_add_vertex_snippet (pipeline, snippet);
|
|
|
|
else
|
|
|
|
_cogl_pipeline_add_fragment_snippet (pipeline, snippet);
|
2011-11-17 11:52:21 -05:00
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2011-11-25 12:59:52 -05:00
|
|
|
_cogl_pipeline_has_non_layer_vertex_snippets (CoglPipeline *pipeline)
|
2011-11-17 11:52:21 -05:00
|
|
|
{
|
|
|
|
CoglPipeline *authority =
|
|
|
|
_cogl_pipeline_get_authority (pipeline,
|
|
|
|
COGL_PIPELINE_STATE_VERTEX_SNIPPETS);
|
|
|
|
|
2013-06-08 18:53:11 -04:00
|
|
|
return authority->big_state->vertex_snippets.entries != NULL;
|
2011-11-17 11:52:21 -05:00
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
static gboolean
|
2011-11-28 14:58:15 -05:00
|
|
|
check_layer_has_vertex_snippet (CoglPipelineLayer *layer,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
unsigned long state = COGL_PIPELINE_LAYER_STATE_VERTEX_SNIPPETS;
|
|
|
|
CoglPipelineLayer *authority =
|
|
|
|
_cogl_pipeline_layer_get_authority (layer, state);
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean *found_vertex_snippet = user_data;
|
2011-11-28 14:58:15 -05:00
|
|
|
|
2013-06-08 18:53:11 -04:00
|
|
|
if (authority->big_state->vertex_snippets.entries)
|
2011-11-28 14:58:15 -05:00
|
|
|
{
|
|
|
|
*found_vertex_snippet = TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2011-11-25 12:59:52 -05:00
|
|
|
_cogl_pipeline_has_vertex_snippets (CoglPipeline *pipeline)
|
|
|
|
{
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean found_vertex_snippet = FALSE;
|
2011-11-28 14:58:15 -05:00
|
|
|
|
|
|
|
if (_cogl_pipeline_has_non_layer_vertex_snippets (pipeline))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
_cogl_pipeline_foreach_layer_internal (pipeline,
|
|
|
|
check_layer_has_vertex_snippet,
|
|
|
|
&found_vertex_snippet);
|
|
|
|
|
|
|
|
return found_vertex_snippet;
|
2011-11-25 12:59:52 -05:00
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2011-11-25 12:59:52 -05:00
|
|
|
_cogl_pipeline_has_non_layer_fragment_snippets (CoglPipeline *pipeline)
|
|
|
|
{
|
|
|
|
CoglPipeline *authority =
|
|
|
|
_cogl_pipeline_get_authority (pipeline,
|
|
|
|
COGL_PIPELINE_STATE_FRAGMENT_SNIPPETS);
|
|
|
|
|
2013-06-08 18:53:11 -04:00
|
|
|
return authority->big_state->fragment_snippets.entries != NULL;
|
2011-11-25 12:59:52 -05:00
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
static gboolean
|
2011-11-25 12:36:03 -05:00
|
|
|
check_layer_has_fragment_snippet (CoglPipelineLayer *layer,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
unsigned long state = COGL_PIPELINE_LAYER_STATE_FRAGMENT_SNIPPETS;
|
|
|
|
CoglPipelineLayer *authority =
|
|
|
|
_cogl_pipeline_layer_get_authority (layer, state);
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean *found_fragment_snippet = user_data;
|
2011-11-25 12:36:03 -05:00
|
|
|
|
2013-06-08 18:53:11 -04:00
|
|
|
if (authority->big_state->fragment_snippets.entries)
|
2011-11-25 12:36:03 -05:00
|
|
|
{
|
|
|
|
*found_fragment_snippet = TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean
|
2011-11-17 11:52:21 -05:00
|
|
|
_cogl_pipeline_has_fragment_snippets (CoglPipeline *pipeline)
|
|
|
|
{
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean found_fragment_snippet = FALSE;
|
2011-11-17 11:52:21 -05:00
|
|
|
|
2011-11-25 12:59:52 -05:00
|
|
|
if (_cogl_pipeline_has_non_layer_fragment_snippets (pipeline))
|
2011-11-25 12:36:03 -05:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
_cogl_pipeline_foreach_layer_internal (pipeline,
|
|
|
|
check_layer_has_fragment_snippet,
|
|
|
|
&found_fragment_snippet);
|
|
|
|
|
|
|
|
return found_fragment_snippet;
|
2011-11-17 11:52:21 -05:00
|
|
|
}
|
|
|
|
|
2011-09-07 18:44:37 -04:00
|
|
|
void
|
|
|
|
_cogl_pipeline_hash_color_state (CoglPipeline *authority,
|
|
|
|
CoglPipelineHashState *state)
|
|
|
|
{
|
|
|
|
state->hash = _cogl_util_one_at_a_time_hash (state->hash, &authority->color,
|
|
|
|
_COGL_COLOR_DATA_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pipeline_hash_alpha_func_state (CoglPipeline *authority,
|
|
|
|
CoglPipelineHashState *state)
|
|
|
|
{
|
|
|
|
CoglPipelineAlphaFuncState *alpha_state = &authority->big_state->alpha_state;
|
|
|
|
state->hash =
|
|
|
|
_cogl_util_one_at_a_time_hash (state->hash, &alpha_state->alpha_func,
|
|
|
|
sizeof (alpha_state->alpha_func));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pipeline_hash_alpha_func_reference_state (CoglPipeline *authority,
|
|
|
|
CoglPipelineHashState *state)
|
|
|
|
{
|
|
|
|
CoglPipelineAlphaFuncState *alpha_state = &authority->big_state->alpha_state;
|
|
|
|
float ref = alpha_state->alpha_func_reference;
|
|
|
|
state->hash =
|
|
|
|
_cogl_util_one_at_a_time_hash (state->hash, &ref, sizeof (float));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pipeline_hash_blend_state (CoglPipeline *authority,
|
|
|
|
CoglPipelineHashState *state)
|
|
|
|
{
|
|
|
|
CoglPipelineBlendState *blend_state = &authority->big_state->blend_state;
|
|
|
|
unsigned int hash;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
if (!authority->real_blend_enable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
hash = state->hash;
|
|
|
|
|
2013-05-29 11:20:58 -04:00
|
|
|
hash =
|
|
|
|
_cogl_util_one_at_a_time_hash (hash, &blend_state->blend_equation_rgb,
|
|
|
|
sizeof (blend_state->blend_equation_rgb));
|
|
|
|
hash =
|
|
|
|
_cogl_util_one_at_a_time_hash (hash, &blend_state->blend_equation_alpha,
|
|
|
|
sizeof (blend_state->blend_equation_alpha));
|
|
|
|
hash =
|
|
|
|
_cogl_util_one_at_a_time_hash (hash, &blend_state->blend_src_factor_alpha,
|
|
|
|
sizeof (blend_state->blend_src_factor_alpha));
|
|
|
|
hash =
|
|
|
|
_cogl_util_one_at_a_time_hash (hash, &blend_state->blend_dst_factor_alpha,
|
|
|
|
sizeof (blend_state->blend_dst_factor_alpha));
|
|
|
|
|
|
|
|
if (blend_state->blend_src_factor_rgb == GL_ONE_MINUS_CONSTANT_COLOR ||
|
|
|
|
blend_state->blend_src_factor_rgb == GL_CONSTANT_COLOR ||
|
|
|
|
blend_state->blend_dst_factor_rgb == GL_ONE_MINUS_CONSTANT_COLOR ||
|
|
|
|
blend_state->blend_dst_factor_rgb == GL_CONSTANT_COLOR)
|
2011-09-07 18:44:37 -04:00
|
|
|
{
|
|
|
|
hash =
|
2013-05-29 11:20:58 -04:00
|
|
|
_cogl_util_one_at_a_time_hash (hash, &blend_state->blend_constant,
|
|
|
|
sizeof (blend_state->blend_constant));
|
2011-09-07 18:44:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
hash =
|
|
|
|
_cogl_util_one_at_a_time_hash (hash, &blend_state->blend_src_factor_rgb,
|
|
|
|
sizeof (blend_state->blend_src_factor_rgb));
|
|
|
|
hash =
|
|
|
|
_cogl_util_one_at_a_time_hash (hash, &blend_state->blend_dst_factor_rgb,
|
|
|
|
sizeof (blend_state->blend_dst_factor_rgb));
|
|
|
|
|
|
|
|
state->hash = hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pipeline_hash_user_shader_state (CoglPipeline *authority,
|
|
|
|
CoglPipelineHashState *state)
|
|
|
|
{
|
|
|
|
CoglHandle user_program = authority->big_state->user_program;
|
|
|
|
state->hash = _cogl_util_one_at_a_time_hash (state->hash, &user_program,
|
|
|
|
sizeof (user_program));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pipeline_hash_depth_state (CoglPipeline *authority,
|
|
|
|
CoglPipelineHashState *state)
|
|
|
|
{
|
|
|
|
CoglDepthState *depth_state = &authority->big_state->depth_state;
|
|
|
|
unsigned int hash = state->hash;
|
|
|
|
|
|
|
|
if (depth_state->test_enabled)
|
|
|
|
{
|
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
|
|
|
uint8_t enabled = depth_state->test_enabled;
|
2011-09-07 18:44:37 -04:00
|
|
|
CoglDepthTestFunction function = depth_state->test_function;
|
|
|
|
hash = _cogl_util_one_at_a_time_hash (hash, &enabled, sizeof (enabled));
|
|
|
|
hash = _cogl_util_one_at_a_time_hash (hash, &function, sizeof (function));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (depth_state->write_enabled)
|
|
|
|
{
|
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
|
|
|
uint8_t enabled = depth_state->write_enabled;
|
2011-09-07 18:44:37 -04:00
|
|
|
float near_val = depth_state->range_near;
|
|
|
|
float far_val = depth_state->range_far;
|
|
|
|
hash = _cogl_util_one_at_a_time_hash (hash, &enabled, sizeof (enabled));
|
|
|
|
hash = _cogl_util_one_at_a_time_hash (hash, &near_val, sizeof (near_val));
|
|
|
|
hash = _cogl_util_one_at_a_time_hash (hash, &far_val, sizeof (far_val));
|
|
|
|
}
|
|
|
|
|
|
|
|
state->hash = hash;
|
|
|
|
}
|
|
|
|
|
2013-06-20 08:25:49 -04:00
|
|
|
void
|
|
|
|
_cogl_pipeline_hash_non_zero_point_size_state (CoglPipeline *authority,
|
|
|
|
CoglPipelineHashState *state)
|
|
|
|
{
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean non_zero_point_size = authority->big_state->non_zero_point_size;
|
2013-06-20 08:25:49 -04:00
|
|
|
|
|
|
|
state->hash = _cogl_util_one_at_a_time_hash (state->hash,
|
|
|
|
&non_zero_point_size,
|
|
|
|
sizeof (non_zero_point_size));
|
|
|
|
}
|
|
|
|
|
2011-09-07 18:44:37 -04:00
|
|
|
void
|
|
|
|
_cogl_pipeline_hash_point_size_state (CoglPipeline *authority,
|
|
|
|
CoglPipelineHashState *state)
|
|
|
|
{
|
|
|
|
float point_size = authority->big_state->point_size;
|
|
|
|
state->hash = _cogl_util_one_at_a_time_hash (state->hash, &point_size,
|
|
|
|
sizeof (point_size));
|
|
|
|
}
|
|
|
|
|
2012-11-08 11:56:02 -05:00
|
|
|
void
|
|
|
|
_cogl_pipeline_hash_per_vertex_point_size_state (CoglPipeline *authority,
|
|
|
|
CoglPipelineHashState *state)
|
|
|
|
{
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean per_vertex_point_size = authority->big_state->per_vertex_point_size;
|
2012-11-08 11:56:02 -05:00
|
|
|
state->hash = _cogl_util_one_at_a_time_hash (state->hash,
|
|
|
|
&per_vertex_point_size,
|
|
|
|
sizeof (per_vertex_point_size));
|
|
|
|
}
|
|
|
|
|
2011-09-15 06:25:39 -04:00
|
|
|
void
|
|
|
|
_cogl_pipeline_hash_cull_face_state (CoglPipeline *authority,
|
|
|
|
CoglPipelineHashState *state)
|
|
|
|
{
|
|
|
|
CoglPipelineCullFaceState *cull_face_state
|
|
|
|
= &authority->big_state->cull_face_state;
|
|
|
|
|
|
|
|
/* The cull face state is considered equal if two pipelines are both
|
|
|
|
set to no culling. If the front winding property is ever used for
|
|
|
|
anything else or the hashing is used not just for drawing then
|
|
|
|
this would have to change */
|
|
|
|
if (cull_face_state->mode == COGL_PIPELINE_CULL_FACE_MODE_NONE)
|
|
|
|
state->hash =
|
|
|
|
_cogl_util_one_at_a_time_hash (state->hash,
|
|
|
|
&cull_face_state->mode,
|
|
|
|
sizeof (CoglPipelineCullFaceMode));
|
|
|
|
else
|
|
|
|
state->hash =
|
|
|
|
_cogl_util_one_at_a_time_hash (state->hash,
|
|
|
|
cull_face_state,
|
|
|
|
sizeof (CoglPipelineCullFaceState));
|
|
|
|
}
|
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 13:20:43 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pipeline_hash_uniforms_state (CoglPipeline *authority,
|
|
|
|
CoglPipelineHashState *state)
|
|
|
|
{
|
|
|
|
/* This isn't used anywhere yet because the uniform state doesn't
|
|
|
|
affect program generation. It's quite a hassle to implement so
|
|
|
|
let's just leave it until something actually needs it */
|
|
|
|
g_warn_if_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pipeline_compare_uniform_differences (unsigned long *differences,
|
|
|
|
CoglPipeline *pipeline0,
|
|
|
|
CoglPipeline *pipeline1)
|
|
|
|
{
|
|
|
|
GSList *head0 = NULL;
|
|
|
|
GSList *head1 = NULL;
|
|
|
|
CoglPipeline *node0;
|
|
|
|
CoglPipeline *node1;
|
|
|
|
int len0 = 0;
|
|
|
|
int len1 = 0;
|
|
|
|
int count;
|
|
|
|
GSList *common_ancestor0;
|
|
|
|
GSList *common_ancestor1;
|
|
|
|
|
|
|
|
/* This algorithm is copied from
|
|
|
|
_cogl_pipeline_compare_differences(). It might be nice to share
|
|
|
|
the code more */
|
|
|
|
|
|
|
|
for (node0 = pipeline0; node0; node0 = _cogl_pipeline_get_parent (node0))
|
|
|
|
{
|
|
|
|
GSList *link = alloca (sizeof (GSList));
|
|
|
|
link->next = head0;
|
|
|
|
link->data = node0;
|
|
|
|
head0 = link;
|
|
|
|
len0++;
|
|
|
|
}
|
|
|
|
for (node1 = pipeline1; node1; node1 = _cogl_pipeline_get_parent (node1))
|
|
|
|
{
|
|
|
|
GSList *link = alloca (sizeof (GSList));
|
|
|
|
link->next = head1;
|
|
|
|
link->data = node1;
|
|
|
|
head1 = link;
|
|
|
|
len1++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NB: There's no point looking at the head entries since we know both
|
|
|
|
* pipelines must have the same default pipeline as their root node. */
|
|
|
|
common_ancestor0 = head0;
|
|
|
|
common_ancestor1 = head1;
|
|
|
|
head0 = head0->next;
|
|
|
|
head1 = head1->next;
|
|
|
|
count = MIN (len0, len1) - 1;
|
|
|
|
while (count--)
|
|
|
|
{
|
|
|
|
if (head0->data != head1->data)
|
|
|
|
break;
|
|
|
|
common_ancestor0 = head0;
|
|
|
|
common_ancestor1 = head1;
|
|
|
|
head0 = head0->next;
|
|
|
|
head1 = head1->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (head0 = common_ancestor0->next; head0; head0 = head0->next)
|
|
|
|
{
|
|
|
|
node0 = head0->data;
|
|
|
|
if ((node0->differences & COGL_PIPELINE_STATE_UNIFORMS))
|
|
|
|
{
|
|
|
|
const CoglPipelineUniformsState *uniforms_state =
|
|
|
|
&node0->big_state->uniforms_state;
|
|
|
|
_cogl_bitmask_set_flags (&uniforms_state->override_mask,
|
|
|
|
differences);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (head1 = common_ancestor1->next; head1; head1 = head1->next)
|
|
|
|
{
|
|
|
|
node1 = head1->data;
|
|
|
|
if ((node1->differences & COGL_PIPELINE_STATE_UNIFORMS))
|
|
|
|
{
|
|
|
|
const CoglPipelineUniformsState *uniforms_state =
|
|
|
|
&node1->big_state->uniforms_state;
|
|
|
|
_cogl_bitmask_set_flags (&uniforms_state->override_mask,
|
|
|
|
differences);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-17 11:52:21 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pipeline_hash_vertex_snippets_state (CoglPipeline *authority,
|
|
|
|
CoglPipelineHashState *state)
|
|
|
|
{
|
|
|
|
_cogl_pipeline_snippet_list_hash (&authority->big_state->vertex_snippets,
|
2011-11-25 12:36:03 -05:00
|
|
|
&state->hash);
|
2011-11-17 11:52:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pipeline_hash_fragment_snippets_state (CoglPipeline *authority,
|
|
|
|
CoglPipelineHashState *state)
|
|
|
|
{
|
|
|
|
_cogl_pipeline_snippet_list_hash (&authority->big_state->fragment_snippets,
|
2011-11-25 12:36:03 -05:00
|
|
|
&state->hash);
|
2011-11-17 11:52:21 -05:00
|
|
|
}
|
2013-09-02 10:30:29 -04:00
|
|
|
|
|
|
|
UNIT_TEST (check_blend_constant_ancestry,
|
|
|
|
0 /* no requirements */,
|
|
|
|
0 /* no known failures */)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
|
|
|
|
CoglNode *node;
|
|
|
|
int pipeline_length = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Repeatedly making a copy of a pipeline and changing the same
|
|
|
|
* state (in this case the blend constant) shouldn't cause a long
|
|
|
|
* chain of pipelines to be created because the redundant ancestry
|
|
|
|
* should be pruned. */
|
|
|
|
|
|
|
|
for (i = 0; i < 20; i++)
|
|
|
|
{
|
|
|
|
CoglColor color;
|
|
|
|
CoglPipeline *tmp_pipeline;
|
|
|
|
|
|
|
|
cogl_color_init_from_4f (&color, i / 20.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
tmp_pipeline = cogl_pipeline_copy (pipeline);
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
pipeline = tmp_pipeline;
|
|
|
|
|
|
|
|
cogl_pipeline_set_blend_constant (pipeline, &color);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (node = (CoglNode *) pipeline; node; node = node->parent)
|
|
|
|
pipeline_length++;
|
|
|
|
|
|
|
|
g_assert_cmpint (pipeline_length, <=, 2);
|
|
|
|
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
}
|
|
|
|
|
|
|
|
UNIT_TEST (check_uniform_ancestry,
|
|
|
|
0 /* no requirements */,
|
|
|
|
TEST_KNOWN_FAILURE)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
|
|
|
|
CoglNode *node;
|
|
|
|
int pipeline_length = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Repeatedly making a copy of a pipeline and changing a uniform
|
|
|
|
* shouldn't cause a long chain of pipelines to be created */
|
|
|
|
|
|
|
|
for (i = 0; i < 20; i++)
|
|
|
|
{
|
|
|
|
CoglPipeline *tmp_pipeline;
|
|
|
|
int uniform_location;
|
|
|
|
|
|
|
|
tmp_pipeline = cogl_pipeline_copy (pipeline);
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
pipeline = tmp_pipeline;
|
|
|
|
|
|
|
|
uniform_location =
|
|
|
|
cogl_pipeline_get_uniform_location (pipeline, "a_uniform");
|
|
|
|
|
|
|
|
cogl_pipeline_set_uniform_1i (pipeline, uniform_location, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (node = (CoglNode *) pipeline; node; node = node->parent)
|
|
|
|
pipeline_length++;
|
|
|
|
|
|
|
|
g_assert_cmpint (pipeline_length, <=, 2);
|
|
|
|
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
}
|