Move need_texture_combine_separate to cogl-pipeline

need_texture_combine_separate is moved to cogl-pipeline.c and renamed
to _cogl_pipeline_need_texture_combine_separate. The function is
needed by both the ARBfp and GLSL codegen backends so it makes sense to
share it.
This commit is contained in:
Neil Roberts 2010-11-19 15:42:26 +00:00
parent fac7338fdd
commit 0b28018873
3 changed files with 79 additions and 74 deletions

View File

@ -284,79 +284,6 @@ _cogl_pipeline_backend_arbfp_start (CoglPipeline *pipeline,
return TRUE;
}
/* Determines if we need to handle the RGB and A texture combining
* separately or is the same function used for both channel masks and
* with the same arguments...
*/
static gboolean
need_texture_combine_separate (CoglPipelineLayer *combine_authority)
{
CoglPipelineLayerBigState *big_state = combine_authority->big_state;
int n_args;
int i;
if (big_state->texture_combine_rgb_func !=
big_state->texture_combine_alpha_func)
return TRUE;
n_args = _cogl_get_n_args_for_combine_func (big_state->texture_combine_rgb_func);
for (i = 0; i < n_args; i++)
{
if (big_state->texture_combine_rgb_src[i] !=
big_state->texture_combine_alpha_src[i])
return TRUE;
/*
* We can allow some variation of the source operands without
* needing a separation...
*
* "A = REPLACE (CONSTANT[A])" + either of the following...
* "RGB = REPLACE (CONSTANT[RGB])"
* "RGB = REPLACE (CONSTANT[A])"
*
* can be combined as:
* "RGBA = REPLACE (CONSTANT)" or
* "RGBA = REPLACE (CONSTANT[A])" or
*
* And "A = REPLACE (1-CONSTANT[A])" + either of the following...
* "RGB = REPLACE (1-CONSTANT)" or
* "RGB = REPLACE (1-CONSTANT[A])"
*
* can be combined as:
* "RGBA = REPLACE (1-CONSTANT)" or
* "RGBA = REPLACE (1-CONSTANT[A])"
*/
switch (big_state->texture_combine_alpha_op[i])
{
case GL_SRC_ALPHA:
switch (big_state->texture_combine_rgb_op[i])
{
case GL_SRC_COLOR:
case GL_SRC_ALPHA:
break;
default:
return FALSE;
}
break;
case GL_ONE_MINUS_SRC_ALPHA:
switch (big_state->texture_combine_rgb_op[i])
{
case GL_ONE_MINUS_SRC_COLOR:
case GL_ONE_MINUS_SRC_ALPHA:
break;
default:
return FALSE;
}
break;
default:
return FALSE; /* impossible */
}
}
return FALSE;
}
static const char *
gl_target_to_arbfp_string (GLenum gl_target)
{
@ -784,7 +711,7 @@ _cogl_pipeline_backend_arbfp_add_layer (CoglPipeline *pipeline,
if (!arbfp_program_state->source)
return TRUE;
if (!need_texture_combine_separate (combine_authority))
if (!_cogl_pipeline_need_texture_combine_separate (combine_authority))
{
append_masked_combine (pipeline,
layer,

View File

@ -956,6 +956,10 @@ _cogl_pipeline_foreach_layer_internal (CoglPipeline *pipeline,
int
_cogl_pipeline_layer_get_unit_index (CoglPipelineLayer *layer);
gboolean
_cogl_pipeline_need_texture_combine_separate
(CoglPipelineLayer *combine_authority);
CoglPipeline *
_cogl_pipeline_find_codegen_authority (CoglPipeline *pipeline,
CoglHandle user_program);

View File

@ -5656,6 +5656,80 @@ layers_codegen_would_differ (CoglPipelineLayer **pipeline0_layers,
return FALSE;
}
/* Determines if we need to handle the RGB and A texture combining
* separately or is the same function used for both channel masks and
* with the same arguments...
*/
gboolean
_cogl_pipeline_need_texture_combine_separate
(CoglPipelineLayer *combine_authority)
{
CoglPipelineLayerBigState *big_state = combine_authority->big_state;
int n_args;
int i;
if (big_state->texture_combine_rgb_func !=
big_state->texture_combine_alpha_func)
return TRUE;
n_args = _cogl_get_n_args_for_combine_func (big_state->texture_combine_rgb_func);
for (i = 0; i < n_args; i++)
{
if (big_state->texture_combine_rgb_src[i] !=
big_state->texture_combine_alpha_src[i])
return TRUE;
/*
* We can allow some variation of the source operands without
* needing a separation...
*
* "A = REPLACE (CONSTANT[A])" + either of the following...
* "RGB = REPLACE (CONSTANT[RGB])"
* "RGB = REPLACE (CONSTANT[A])"
*
* can be combined as:
* "RGBA = REPLACE (CONSTANT)" or
* "RGBA = REPLACE (CONSTANT[A])" or
*
* And "A = REPLACE (1-CONSTANT[A])" + either of the following...
* "RGB = REPLACE (1-CONSTANT)" or
* "RGB = REPLACE (1-CONSTANT[A])"
*
* can be combined as:
* "RGBA = REPLACE (1-CONSTANT)" or
* "RGBA = REPLACE (1-CONSTANT[A])"
*/
switch (big_state->texture_combine_alpha_op[i])
{
case GL_SRC_ALPHA:
switch (big_state->texture_combine_rgb_op[i])
{
case GL_SRC_COLOR:
case GL_SRC_ALPHA:
break;
default:
return FALSE;
}
break;
case GL_ONE_MINUS_SRC_ALPHA:
switch (big_state->texture_combine_rgb_op[i])
{
case GL_ONE_MINUS_SRC_COLOR:
case GL_ONE_MINUS_SRC_ALPHA:
break;
default:
return FALSE;
}
break;
default:
return FALSE; /* impossible */
}
}
return FALSE;
}
/* This tries to find the oldest ancestor whos state would generate
* the same shader program as the current pipeline. This is a simple
* mechanism for reducing the number of programs we have to generate.