Add support for per-vertex point sizes

This adds a new function to enable per-vertex point size on a
pipeline. This can be set with
cogl_pipeline_set_per_vertex_point_size(). Once enabled the point size
can be set either by drawing with an attribute named
'cogl_point_size_in' or by writing to the 'cogl_point_size_out'
builtin from a snippet.

There is a feature flag which must be checked for before using
per-vertex point sizes. This will only be set on GL >= 2.0 or on GLES
2.0. GL will only let you set a per-vertex point size from GLSL by
writing to gl_PointSize. This is only available in GL2 and not in the
older GLSL extensions.

The per-vertex point size has its own pipeline state flag so that it
can be part of the state that affects vertex shader generation.

Having to enable the per vertex point size with a separate function is
a bit awkward. Ideally it would work like the color attribute where
you can just set it for every vertex in your primitive with
cogl_pipeline_set_color or set it per-vertex by just using the
attribute. This is harder to get working with the point size because
we need to generate a different vertex shader depending on what
attributes are bound. I think if we wanted to make this work
transparently we would still want to internally have a pipeline
property describing whether the shader was generated with per-vertex
support so that it would work with the shader cache correctly.
Potentially we could make the per-vertex property internal and
automatically make a weak pipeline whenever the attribute is bound.
However we would then also need to automatically detect when an
application is writing to cogl_point_size_out from a snippet.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 8495d9c1c15ce389885a9356d965eabd97758115)

Conflicts:
	cogl/cogl-context.c
	cogl/cogl-pipeline-private.h
	cogl/cogl-pipeline.c
	cogl/cogl-private.h
	cogl/driver/gl/cogl-pipeline-progend-fixed.c
	cogl/driver/gl/gl/cogl-pipeline-progend-fixed-arbfp.c
This commit is contained in:
Neil Roberts
2012-11-08 16:56:02 +00:00
parent 2d24248a3c
commit 6d51a18e7c
26 changed files with 493 additions and 13 deletions

View File

@ -196,6 +196,14 @@ _cogl_pipeline_point_size_equal (CoglPipeline *authority0,
return authority0->big_state->point_size == authority1->big_state->point_size;
}
CoglBool
_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);
}
CoglBool
_cogl_pipeline_logic_ops_state_equal (CoglPipeline *authority0,
CoglPipeline *authority1)
@ -1398,6 +1406,63 @@ cogl_pipeline_set_point_size (CoglPipeline *pipeline,
_cogl_pipeline_point_size_equal);
}
CoglBool
cogl_pipeline_set_per_vertex_point_size (CoglPipeline *pipeline,
CoglBool enable,
CoglError **error)
{
CoglPipelineState state = COGL_PIPELINE_STATE_PER_VERTEX_POINT_SIZE;
CoglPipeline *authority;
_COGL_GET_CONTEXT (ctx, FALSE);
_COGL_RETURN_VAL_IF_FAIL (cogl_is_pipeline (pipeline), FALSE);
authority = _cogl_pipeline_get_authority (pipeline, state);
enable = !!enable;
if (authority->big_state->per_vertex_point_size == enable)
return TRUE;
if (enable && !cogl_has_feature (ctx, COGL_FEATURE_ID_PER_VERTEX_POINT_SIZE))
{
_cogl_set_error (error,
COGL_SYSTEM_ERROR,
COGL_SYSTEM_ERROR_UNSUPPORTED,
"Per-vertex point size is not supported");
return FALSE;
}
/* - 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;
}
CoglBool
cogl_pipeline_get_per_vertex_point_size (CoglPipeline *pipeline)
{
CoglPipeline *authority;
_COGL_RETURN_VAL_IF_FAIL (cogl_is_pipeline (pipeline), FALSE);
authority =
_cogl_pipeline_get_authority (pipeline,
COGL_PIPELINE_STATE_PER_VERTEX_POINT_SIZE);
return authority->big_state->per_vertex_point_size;
}
static CoglBoxedValue *
_cogl_pipeline_override_uniform (CoglPipeline *pipeline,
int location)
@ -1832,6 +1897,16 @@ _cogl_pipeline_hash_point_size_state (CoglPipeline *authority,
sizeof (point_size));
}
void
_cogl_pipeline_hash_per_vertex_point_size_state (CoglPipeline *authority,
CoglPipelineHashState *state)
{
CoglBool per_vertex_point_size = authority->big_state->per_vertex_point_size;
state->hash = _cogl_util_one_at_a_time_hash (state->hash,
&per_vertex_point_size,
sizeof (per_vertex_point_size));
}
void
_cogl_pipeline_hash_logic_ops_state (CoglPipeline *authority,
CoglPipelineHashState *state)