Remove the varying array for tex_coords
This removes the need to maintain an array of tex_coord varyings and instead we now just emit a varying per-layer uniquely named using a layer_number infix like cogl_tex_coord0_out and cogl_tex_coord0_in. Notable this patch also had to change the journal flushing code to use pipeline layer numbers to determine the name of texture coordinate attributes. We now also break batches by using a deeper comparison of layers so such that two pipelines with the same number of layers can now cause a batch break if they use different layer numbers. This adds an internal _cogl_pipeline_layer_numbers_equal() function that takes two pipelines and returns TRUE if they have the same number of layers and all the layer numbers are the same too, otherwise it returns FALSE. Where we used to break batches based on changes to the number of layers we now break according to the status of _cogl_pipeline_layer_numbers_equal Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit e55b64a9cdc93285049d9b969bef67484c2d9fb3) Note: this will cause a temporary regression for the Cogl 1.x CoglShader api since it will break compatibility with existing shaders that reference the texture varyings from the fragment shader. The intention is to follow up with another patch to add back CoglShader compatibility.
This commit is contained in:
parent
14d8ec7cca
commit
1c449c67f6
@ -48,7 +48,7 @@ typedef struct _CoglAttributeNameState
|
|||||||
CoglAttributeNameID name_id;
|
CoglAttributeNameID name_id;
|
||||||
int name_index;
|
int name_index;
|
||||||
CoglBool normalized_default;
|
CoglBool normalized_default;
|
||||||
int texture_unit;
|
int layer_number;
|
||||||
} CoglAttributeNameState;
|
} CoglAttributeNameState;
|
||||||
|
|
||||||
struct _CoglAttribute
|
struct _CoglAttribute
|
||||||
|
@ -64,12 +64,12 @@ validate_cogl_attribute_name (const char *name,
|
|||||||
char **real_attribute_name,
|
char **real_attribute_name,
|
||||||
CoglAttributeNameID *name_id,
|
CoglAttributeNameID *name_id,
|
||||||
CoglBool *normalized,
|
CoglBool *normalized,
|
||||||
int *texture_unit)
|
int *layer_number)
|
||||||
{
|
{
|
||||||
name = name + 5; /* skip "cogl_" */
|
name = name + 5; /* skip "cogl_" */
|
||||||
|
|
||||||
*normalized = FALSE;
|
*normalized = FALSE;
|
||||||
*texture_unit = 0;
|
*layer_number = 0;
|
||||||
|
|
||||||
if (strcmp (name, "position_in") == 0)
|
if (strcmp (name, "position_in") == 0)
|
||||||
*name_id = COGL_ATTRIBUTE_NAME_ID_POSITION_ARRAY;
|
*name_id = COGL_ATTRIBUTE_NAME_ID_POSITION_ARRAY;
|
||||||
@ -86,7 +86,7 @@ validate_cogl_attribute_name (const char *name,
|
|||||||
else if (strncmp (name, "tex_coord", strlen ("tex_coord")) == 0)
|
else if (strncmp (name, "tex_coord", strlen ("tex_coord")) == 0)
|
||||||
{
|
{
|
||||||
char *endptr;
|
char *endptr;
|
||||||
*texture_unit = strtoul (name + 9, &endptr, 10);
|
*layer_number = strtoul (name + 9, &endptr, 10);
|
||||||
if (strcmp (endptr, "_in") != 0)
|
if (strcmp (endptr, "_in") != 0)
|
||||||
{
|
{
|
||||||
g_warning ("Texture coordinate attributes should either be named "
|
g_warning ("Texture coordinate attributes should either be named "
|
||||||
@ -126,14 +126,14 @@ _cogl_attribute_register_attribute_name (CoglContext *context,
|
|||||||
&name_state->name,
|
&name_state->name,
|
||||||
&name_state->name_id,
|
&name_state->name_id,
|
||||||
&name_state->normalized_default,
|
&name_state->normalized_default,
|
||||||
&name_state->texture_unit))
|
&name_state->layer_number))
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
name_state->name_id = COGL_ATTRIBUTE_NAME_ID_CUSTOM_ARRAY;
|
name_state->name_id = COGL_ATTRIBUTE_NAME_ID_CUSTOM_ARRAY;
|
||||||
name_state->normalized_default = FALSE;
|
name_state->normalized_default = FALSE;
|
||||||
name_state->texture_unit = 0;
|
name_state->layer_number = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name_state->name == NULL)
|
if (name_state->name == NULL)
|
||||||
|
@ -44,7 +44,6 @@
|
|||||||
_COGL_COMMON_SHADER_BOILERPLATE \
|
_COGL_COMMON_SHADER_BOILERPLATE \
|
||||||
"#define cogl_color_out _cogl_color\n" \
|
"#define cogl_color_out _cogl_color\n" \
|
||||||
"varying vec4 _cogl_color;\n" \
|
"varying vec4 _cogl_color;\n" \
|
||||||
"#define cogl_tex_coord_out _cogl_tex_coord\n" \
|
|
||||||
"#define cogl_position_out gl_Position\n" \
|
"#define cogl_position_out gl_Position\n" \
|
||||||
"#define cogl_point_size_out gl_PointSize\n" \
|
"#define cogl_point_size_out gl_PointSize\n" \
|
||||||
"\n" \
|
"\n" \
|
||||||
@ -62,7 +61,6 @@
|
|||||||
"varying vec4 _cogl_color;\n" \
|
"varying vec4 _cogl_color;\n" \
|
||||||
"\n" \
|
"\n" \
|
||||||
"#define cogl_color_in _cogl_color\n" \
|
"#define cogl_color_in _cogl_color\n" \
|
||||||
"#define cogl_tex_coord_in _cogl_tex_coord\n" \
|
|
||||||
"\n" \
|
"\n" \
|
||||||
"#define cogl_color_out gl_FragColor\n" \
|
"#define cogl_color_out gl_FragColor\n" \
|
||||||
"#define cogl_depth_out gl_FragDepth\n" \
|
"#define cogl_depth_out gl_FragDepth\n" \
|
||||||
|
@ -28,7 +28,6 @@ _cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx,
|
|||||||
const char *version_string,
|
const char *version_string,
|
||||||
GLuint shader_gl_handle,
|
GLuint shader_gl_handle,
|
||||||
GLenum shader_gl_type,
|
GLenum shader_gl_type,
|
||||||
int n_tex_coord_attribs,
|
|
||||||
GLsizei count_in,
|
GLsizei count_in,
|
||||||
const char **strings_in,
|
const char **strings_in,
|
||||||
const GLint *lengths_in);
|
const GLint *lengths_in);
|
||||||
|
@ -44,7 +44,6 @@ _cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx,
|
|||||||
const char *version_string,
|
const char *version_string,
|
||||||
GLuint shader_gl_handle,
|
GLuint shader_gl_handle,
|
||||||
GLenum shader_gl_type,
|
GLenum shader_gl_type,
|
||||||
int n_tex_coord_attribs,
|
|
||||||
GLsizei count_in,
|
GLsizei count_in,
|
||||||
const char **strings_in,
|
const char **strings_in,
|
||||||
const GLint *lengths_in)
|
const GLint *lengths_in)
|
||||||
@ -86,33 +85,6 @@ _cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx,
|
|||||||
lengths[count++] = strlen (fragment_boilerplate);
|
lengths[count++] = strlen (fragment_boilerplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n_tex_coord_attribs)
|
|
||||||
{
|
|
||||||
GString *declarations = g_string_new (NULL);
|
|
||||||
|
|
||||||
g_string_append_printf (declarations,
|
|
||||||
"varying vec4 _cogl_tex_coord[%d];\n",
|
|
||||||
n_tex_coord_attribs);
|
|
||||||
|
|
||||||
if (shader_gl_type == GL_VERTEX_SHADER)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
g_string_append_printf (declarations,
|
|
||||||
"uniform mat4 cogl_texture_matrix[%d];\n",
|
|
||||||
n_tex_coord_attribs);
|
|
||||||
|
|
||||||
for (i = 0; i < n_tex_coord_attribs; i++)
|
|
||||||
g_string_append_printf (declarations,
|
|
||||||
"attribute vec4 cogl_tex_coord%d_in;\n",
|
|
||||||
i);
|
|
||||||
}
|
|
||||||
|
|
||||||
tex_coord_declarations = g_string_free (declarations, FALSE);
|
|
||||||
strings[count] = tex_coord_declarations;
|
|
||||||
lengths[count++] = -1; /* null terminated */
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy (strings + count, strings_in, sizeof (char *) * count_in);
|
memcpy (strings + count, strings_in, sizeof (char *) * count_in);
|
||||||
if (lengths_in)
|
if (lengths_in)
|
||||||
memcpy (lengths + count, lengths_in, sizeof (GLint) * count_in);
|
memcpy (lengths + count, lengths_in, sizeof (GLint) * count_in);
|
||||||
|
@ -465,39 +465,23 @@ compare_entry_pipelines (CoglJournalEntry *entry0, CoglJournalEntry *entry1)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Since the stride may not reflect the number of texture layers in use
|
typedef struct _CreateAttributeState
|
||||||
* (due to padding) we deal with texture coordinate offsets separately
|
|
||||||
* from vertex and color offsets... */
|
|
||||||
static void
|
|
||||||
_cogl_journal_flush_texcoord_vbo_offsets_and_entries (
|
|
||||||
CoglJournalEntry *batch_start,
|
|
||||||
int batch_len,
|
|
||||||
void *data)
|
|
||||||
{
|
{
|
||||||
CoglJournalFlushState *state = data;
|
int current;
|
||||||
int i;
|
CoglJournalFlushState *flush_state;
|
||||||
COGL_STATIC_TIMER (time_flush_texcoord_pipeline_entries,
|
} CreateAttributeState;
|
||||||
"flush: vbo+texcoords+pipeline+entries", /* parent */
|
|
||||||
"flush: texcoords+pipeline+entries",
|
|
||||||
"The time spent flushing texcoord offsets + pipeline "
|
|
||||||
"+ entries",
|
|
||||||
0 /* no application private data */);
|
|
||||||
|
|
||||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
static CoglBool
|
||||||
|
create_attribute_cb (CoglPipeline *pipeline,
|
||||||
COGL_TIMER_START (_cogl_uprof_context, time_flush_texcoord_pipeline_entries);
|
int layer_number,
|
||||||
|
void *user_data)
|
||||||
/* NB: attributes 0 and 1 are position and color */
|
{
|
||||||
|
CreateAttributeState *state = user_data;
|
||||||
for (i = 2; i < state->attributes->len; i++)
|
CoglJournalFlushState *flush_state = state->flush_state;
|
||||||
cogl_object_unref (g_array_index (state->attributes, CoglAttribute *, i));
|
|
||||||
|
|
||||||
g_array_set_size (state->attributes, batch_start->n_layers + 2);
|
|
||||||
|
|
||||||
for (i = 0; i < batch_start->n_layers; i++)
|
|
||||||
{
|
|
||||||
CoglAttribute **attribute_entry =
|
CoglAttribute **attribute_entry =
|
||||||
&g_array_index (state->attributes, CoglAttribute *, i + 2);
|
&g_array_index (flush_state->attributes,
|
||||||
|
CoglAttribute *,
|
||||||
|
state->current + 2);
|
||||||
const char *names[] = {
|
const char *names[] = {
|
||||||
"cogl_tex_coord0_in",
|
"cogl_tex_coord0_in",
|
||||||
"cogl_tex_coord1_in",
|
"cogl_tex_coord1_in",
|
||||||
@ -519,24 +503,65 @@ _cogl_journal_flush_texcoord_vbo_offsets_and_entries (
|
|||||||
* (though n_layers may be padded; see definition of
|
* (though n_layers may be padded; see definition of
|
||||||
* GET_JOURNAL_VB_STRIDE_FOR_N_LAYERS for details)
|
* GET_JOURNAL_VB_STRIDE_FOR_N_LAYERS for details)
|
||||||
*/
|
*/
|
||||||
name = i < 8 ? (char *)names[i] :
|
name = layer_number < 8 ? (char *)names[layer_number] :
|
||||||
g_strdup_printf ("cogl_tex_coord%d_in", i);
|
g_strdup_printf ("cogl_tex_coord%d_in", layer_number);
|
||||||
|
|
||||||
/* XXX: it may be worth having some form of static initializer for
|
/* XXX: it may be worth having some form of static initializer for
|
||||||
* attributes... */
|
* attributes... */
|
||||||
*attribute_entry =
|
*attribute_entry =
|
||||||
cogl_attribute_new (state->attribute_buffer,
|
cogl_attribute_new (flush_state->attribute_buffer,
|
||||||
name,
|
name,
|
||||||
state->stride,
|
flush_state->stride,
|
||||||
state->array_offset +
|
flush_state->array_offset +
|
||||||
(POS_STRIDE + COLOR_STRIDE) * 4 +
|
(POS_STRIDE + COLOR_STRIDE) * 4 +
|
||||||
TEX_STRIDE * 4 * i,
|
TEX_STRIDE * 4 * state->current,
|
||||||
2,
|
2,
|
||||||
COGL_ATTRIBUTE_TYPE_FLOAT);
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
||||||
|
|
||||||
if (i >= 8)
|
if (layer_number >= 8)
|
||||||
g_free (name);
|
g_free (name);
|
||||||
}
|
|
||||||
|
state->current++;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Since the stride may not reflect the number of texture layers in use
|
||||||
|
* (due to padding) we deal with texture coordinate offsets separately
|
||||||
|
* from vertex and color offsets... */
|
||||||
|
static void
|
||||||
|
_cogl_journal_flush_texcoord_vbo_offsets_and_entries (
|
||||||
|
CoglJournalEntry *batch_start,
|
||||||
|
int batch_len,
|
||||||
|
void *data)
|
||||||
|
{
|
||||||
|
CoglJournalFlushState *state = data;
|
||||||
|
CreateAttributeState create_attrib_state;
|
||||||
|
int i;
|
||||||
|
COGL_STATIC_TIMER (time_flush_texcoord_pipeline_entries,
|
||||||
|
"flush: vbo+texcoords+pipeline+entries", /* parent */
|
||||||
|
"flush: texcoords+pipeline+entries",
|
||||||
|
"The time spent flushing texcoord offsets + pipeline "
|
||||||
|
"+ entries",
|
||||||
|
0 /* no application private data */);
|
||||||
|
|
||||||
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||||
|
|
||||||
|
COGL_TIMER_START (_cogl_uprof_context, time_flush_texcoord_pipeline_entries);
|
||||||
|
|
||||||
|
/* NB: attributes 0 and 1 are position and color */
|
||||||
|
|
||||||
|
for (i = 2; i < state->attributes->len; i++)
|
||||||
|
cogl_object_unref (g_array_index (state->attributes, CoglAttribute *, i));
|
||||||
|
|
||||||
|
g_array_set_size (state->attributes, batch_start->n_layers + 2);
|
||||||
|
|
||||||
|
create_attrib_state.current = 0;
|
||||||
|
create_attrib_state.flush_state = state;
|
||||||
|
|
||||||
|
cogl_pipeline_foreach_layer (batch_start->pipeline,
|
||||||
|
create_attribute_cb,
|
||||||
|
&create_attrib_state);
|
||||||
|
|
||||||
batch_and_call (batch_start,
|
batch_and_call (batch_start,
|
||||||
batch_len,
|
batch_len,
|
||||||
@ -547,9 +572,9 @@ _cogl_journal_flush_texcoord_vbo_offsets_and_entries (
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CoglBool
|
static CoglBool
|
||||||
compare_entry_n_layers (CoglJournalEntry *entry0, CoglJournalEntry *entry1)
|
compare_entry_layer_numbers (CoglJournalEntry *entry0, CoglJournalEntry *entry1)
|
||||||
{
|
{
|
||||||
if (entry0->n_layers == entry1->n_layers)
|
if (_cogl_pipeline_layer_numbers_equal (entry0->pipeline, entry1->pipeline))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
else
|
else
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -646,7 +671,7 @@ _cogl_journal_flush_vbo_offsets_and_entries (CoglJournalEntry *batch_start,
|
|||||||
|
|
||||||
batch_and_call (batch_start,
|
batch_and_call (batch_start,
|
||||||
batch_len,
|
batch_len,
|
||||||
compare_entry_n_layers,
|
compare_entry_layer_numbers,
|
||||||
_cogl_journal_flush_texcoord_vbo_offsets_and_entries,
|
_cogl_journal_flush_texcoord_vbo_offsets_and_entries,
|
||||||
data);
|
data);
|
||||||
|
|
||||||
|
@ -489,8 +489,7 @@ typedef struct _CoglPipelineFragend
|
|||||||
{
|
{
|
||||||
void (*start) (CoglPipeline *pipeline,
|
void (*start) (CoglPipeline *pipeline,
|
||||||
int n_layers,
|
int n_layers,
|
||||||
unsigned long pipelines_difference,
|
unsigned long pipelines_difference);
|
||||||
int n_tex_coord_attribs);
|
|
||||||
CoglBool (*add_layer) (CoglPipeline *pipeline,
|
CoglBool (*add_layer) (CoglPipeline *pipeline,
|
||||||
CoglPipelineLayer *layer,
|
CoglPipelineLayer *layer,
|
||||||
unsigned long layers_difference);
|
unsigned long layers_difference);
|
||||||
@ -511,8 +510,7 @@ typedef struct _CoglPipelineVertend
|
|||||||
{
|
{
|
||||||
void (*start) (CoglPipeline *pipeline,
|
void (*start) (CoglPipeline *pipeline,
|
||||||
int n_layers,
|
int n_layers,
|
||||||
unsigned long pipelines_difference,
|
unsigned long pipelines_difference);
|
||||||
int n_tex_coord_attribs);
|
|
||||||
CoglBool (*add_layer) (CoglPipeline *pipeline,
|
CoglBool (*add_layer) (CoglPipeline *pipeline,
|
||||||
CoglPipelineLayer *layer,
|
CoglPipelineLayer *layer,
|
||||||
unsigned long layers_difference,
|
unsigned long layers_difference,
|
||||||
@ -534,8 +532,7 @@ typedef struct
|
|||||||
int fragend;
|
int fragend;
|
||||||
CoglBool (*start) (CoglPipeline *pipeline);
|
CoglBool (*start) (CoglPipeline *pipeline);
|
||||||
void (*end) (CoglPipeline *pipeline,
|
void (*end) (CoglPipeline *pipeline,
|
||||||
unsigned long pipelines_difference,
|
unsigned long pipelines_difference);
|
||||||
int n_tex_coord_attribs);
|
|
||||||
void (*pipeline_pre_change_notify) (CoglPipeline *pipeline,
|
void (*pipeline_pre_change_notify) (CoglPipeline *pipeline,
|
||||||
CoglPipelineState change,
|
CoglPipelineState change,
|
||||||
const CoglColor *new_color);
|
const CoglColor *new_color);
|
||||||
@ -928,6 +925,10 @@ _cogl_pipeline_foreach_layer_internal (CoglPipeline *pipeline,
|
|||||||
CoglPipelineInternalLayerCallback callback,
|
CoglPipelineInternalLayerCallback callback,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
|
CoglBool
|
||||||
|
_cogl_pipeline_layer_numbers_equal (CoglPipeline *pipeline0,
|
||||||
|
CoglPipeline *pipeline1);
|
||||||
|
|
||||||
CoglBool
|
CoglBool
|
||||||
_cogl_pipeline_need_texture_combine_separate
|
_cogl_pipeline_need_texture_combine_separate
|
||||||
(CoglPipelineLayer *combine_authority);
|
(CoglPipelineLayer *combine_authority);
|
||||||
|
@ -617,6 +617,35 @@ _cogl_pipeline_foreach_layer_internal (CoglPipeline *pipeline,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CoglBool
|
||||||
|
_cogl_pipeline_layer_numbers_equal (CoglPipeline *pipeline0,
|
||||||
|
CoglPipeline *pipeline1)
|
||||||
|
{
|
||||||
|
CoglPipeline *authority0 =
|
||||||
|
_cogl_pipeline_get_authority (pipeline0, COGL_PIPELINE_STATE_LAYERS);
|
||||||
|
CoglPipeline *authority1 =
|
||||||
|
_cogl_pipeline_get_authority (pipeline1, COGL_PIPELINE_STATE_LAYERS);
|
||||||
|
int n_layers = authority0->n_layers;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (authority1->n_layers != n_layers)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
_cogl_pipeline_update_layers_cache (authority0);
|
||||||
|
_cogl_pipeline_update_layers_cache (authority1);
|
||||||
|
|
||||||
|
for (i = 0; i < n_layers; i++)
|
||||||
|
{
|
||||||
|
CoglPipelineLayer *layer0 = authority0->layers_cache[i];
|
||||||
|
CoglPipelineLayer *layer1 = authority1->layers_cache[i];
|
||||||
|
|
||||||
|
if (layer0->index != layer1->index)
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -253,7 +253,6 @@ _cogl_shader_compile_real (CoglHandle handle,
|
|||||||
version,
|
version,
|
||||||
shader->gl_handle,
|
shader->gl_handle,
|
||||||
gl_type,
|
gl_type,
|
||||||
n_tex_coord_attribs,
|
|
||||||
1,
|
1,
|
||||||
(const char **)
|
(const char **)
|
||||||
&shader->source,
|
&shader->source,
|
||||||
|
@ -431,8 +431,7 @@ cogl_begin_gl (void)
|
|||||||
pipeline = cogl_get_source ();
|
pipeline = cogl_get_source ();
|
||||||
_cogl_pipeline_flush_gl_state (pipeline,
|
_cogl_pipeline_flush_gl_state (pipeline,
|
||||||
cogl_get_draw_framebuffer (),
|
cogl_get_draw_framebuffer (),
|
||||||
FALSE,
|
FALSE);
|
||||||
cogl_pipeline_get_n_layers (pipeline));
|
|
||||||
|
|
||||||
/* Disable any cached vertex arrays */
|
/* Disable any cached vertex arrays */
|
||||||
_cogl_gl_disable_all_attributes (ctx);
|
_cogl_gl_disable_all_attributes (ctx);
|
||||||
|
@ -218,7 +218,6 @@ _cogl_gl_flush_attributes_state (CoglFramebuffer *framebuffer,
|
|||||||
int i;
|
int i;
|
||||||
CoglBool skip_gl_color = FALSE;
|
CoglBool skip_gl_color = FALSE;
|
||||||
CoglPipeline *copy = NULL;
|
CoglPipeline *copy = NULL;
|
||||||
int n_tex_coord_attribs = 0;
|
|
||||||
|
|
||||||
/* Iterate the attributes to work out whether blending needs to be
|
/* Iterate the attributes to work out whether blending needs to be
|
||||||
enabled and how many texture coords there are. We need to do this
|
enabled and how many texture coords there are. We need to do this
|
||||||
@ -239,10 +238,6 @@ _cogl_gl_flush_attributes_state (CoglFramebuffer *framebuffer,
|
|||||||
skip_gl_color = TRUE;
|
skip_gl_color = TRUE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COGL_ATTRIBUTE_NAME_ID_TEXTURE_COORD_ARRAY:
|
|
||||||
n_tex_coord_attribs++;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -293,8 +288,7 @@ _cogl_gl_flush_attributes_state (CoglFramebuffer *framebuffer,
|
|||||||
|
|
||||||
_cogl_pipeline_flush_gl_state (pipeline,
|
_cogl_pipeline_flush_gl_state (pipeline,
|
||||||
framebuffer,
|
framebuffer,
|
||||||
skip_gl_color,
|
skip_gl_color);
|
||||||
n_tex_coord_attribs);
|
|
||||||
|
|
||||||
_cogl_bitmask_clear_all (&ctx->enable_builtin_attributes_tmp);
|
_cogl_bitmask_clear_all (&ctx->enable_builtin_attributes_tmp);
|
||||||
_cogl_bitmask_clear_all (&ctx->enable_texcoord_attributes_tmp);
|
_cogl_bitmask_clear_all (&ctx->enable_texcoord_attributes_tmp);
|
||||||
@ -353,11 +347,14 @@ _cogl_gl_flush_attributes_state (CoglFramebuffer *framebuffer,
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
int layer_number = attribute->name_state->layer_number;
|
||||||
|
CoglPipelineLayer *layer =
|
||||||
|
_cogl_pipeline_get_layer (pipeline, layer_number);
|
||||||
|
int unit = _cogl_pipeline_layer_get_unit_index (layer);
|
||||||
|
|
||||||
_cogl_bitmask_set (&ctx->enable_texcoord_attributes_tmp,
|
_cogl_bitmask_set (&ctx->enable_texcoord_attributes_tmp,
|
||||||
attribute->name_state->texture_unit, TRUE);
|
unit, TRUE);
|
||||||
GE (ctx,
|
GE (ctx, glClientActiveTexture (GL_TEXTURE0 + unit));
|
||||||
glClientActiveTexture (GL_TEXTURE0 +
|
|
||||||
attribute->name_state->texture_unit));
|
|
||||||
GE (ctx, glTexCoordPointer (attribute->n_components,
|
GE (ctx, glTexCoordPointer (attribute->n_components,
|
||||||
attribute->type,
|
attribute->type,
|
||||||
attribute->stride,
|
attribute->stride,
|
||||||
|
@ -286,7 +286,7 @@ add_stencil_clip_silhouette (CoglFramebuffer *framebuffer,
|
|||||||
projection_stack->last_entry);
|
projection_stack->last_entry);
|
||||||
_cogl_context_set_current_modelview_entry (ctx, modelview_entry);
|
_cogl_context_set_current_modelview_entry (ctx, modelview_entry);
|
||||||
|
|
||||||
_cogl_pipeline_flush_gl_state (ctx->stencil_pipeline, framebuffer, FALSE, 0);
|
_cogl_pipeline_flush_gl_state (ctx->stencil_pipeline, framebuffer, FALSE);
|
||||||
|
|
||||||
GE( ctx, glEnable (GL_STENCIL_TEST) );
|
GE( ctx, glEnable (GL_STENCIL_TEST) );
|
||||||
|
|
||||||
|
@ -92,8 +92,7 @@ get_max_texture_units (void)
|
|||||||
static void
|
static void
|
||||||
_cogl_pipeline_fragend_fixed_start (CoglPipeline *pipeline,
|
_cogl_pipeline_fragend_fixed_start (CoglPipeline *pipeline,
|
||||||
int n_layers,
|
int n_layers,
|
||||||
unsigned long pipelines_difference,
|
unsigned long pipelines_difference)
|
||||||
int n_tex_coord_attribs)
|
|
||||||
{
|
{
|
||||||
_cogl_use_fragment_program (0, COGL_PIPELINE_PROGRAM_TYPE_FIXED);
|
_cogl_use_fragment_program (0, COGL_PIPELINE_PROGRAM_TYPE_FIXED);
|
||||||
}
|
}
|
||||||
|
@ -107,9 +107,6 @@ typedef struct
|
|||||||
a shader at all */
|
a shader at all */
|
||||||
unsigned int user_program_age;
|
unsigned int user_program_age;
|
||||||
|
|
||||||
/* The number of tex coord attributes that the shader was generated
|
|
||||||
* for. If this changes then we need to regenerate the shader */
|
|
||||||
int n_tex_coord_attribs;
|
|
||||||
} CoglPipelineShaderState;
|
} CoglPipelineShaderState;
|
||||||
|
|
||||||
static CoglUserDataKey shader_state_key;
|
static CoglUserDataKey shader_state_key;
|
||||||
@ -219,8 +216,7 @@ has_replace_hook (CoglPipelineLayer *layer,
|
|||||||
static void
|
static void
|
||||||
_cogl_pipeline_fragend_glsl_start (CoglPipeline *pipeline,
|
_cogl_pipeline_fragend_glsl_start (CoglPipeline *pipeline,
|
||||||
int n_layers,
|
int n_layers,
|
||||||
unsigned long pipelines_difference,
|
unsigned long pipelines_difference)
|
||||||
int n_tex_coord_attribs)
|
|
||||||
{
|
{
|
||||||
CoglPipelineShaderState *shader_state;
|
CoglPipelineShaderState *shader_state;
|
||||||
CoglPipeline *authority;
|
CoglPipeline *authority;
|
||||||
@ -294,15 +290,11 @@ _cogl_pipeline_fragend_glsl_start (CoglPipeline *pipeline,
|
|||||||
|
|
||||||
if (shader_state->gl_shader)
|
if (shader_state->gl_shader)
|
||||||
{
|
{
|
||||||
/* If we already have a valid GLSL shader then we don't need to
|
/* If we already have a valid GLSL shader then we don't need to generate
|
||||||
generate a new one. However if there's a user program and it
|
* a new one. However if there's a user program and it has changed since
|
||||||
has changed since the last link then we do need a new
|
* the last link then we do need a new shader. */
|
||||||
shader. Also if the number of tex coord attribs changes
|
if (user_program == NULL ||
|
||||||
then we need to regenerate the shader with a different boiler
|
|
||||||
plate */
|
|
||||||
if ((user_program == NULL ||
|
|
||||||
shader_state->user_program_age == user_program->age)
|
shader_state->user_program_age == user_program->age)
|
||||||
&& shader_state->n_tex_coord_attribs == n_tex_coord_attribs)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* We need to recreate the shader so destroy the existing one */
|
/* We need to recreate the shader so destroy the existing one */
|
||||||
@ -315,15 +307,14 @@ _cogl_pipeline_fragend_glsl_start (CoglPipeline *pipeline,
|
|||||||
encountered it or because the user program has changed */
|
encountered it or because the user program has changed */
|
||||||
|
|
||||||
if (user_program)
|
if (user_program)
|
||||||
|
{
|
||||||
shader_state->user_program_age = user_program->age;
|
shader_state->user_program_age = user_program->age;
|
||||||
|
|
||||||
shader_state->n_tex_coord_attribs = n_tex_coord_attribs;
|
|
||||||
|
|
||||||
/* If the user program contains a fragment shader then we don't need
|
/* If the user program contains a fragment shader then we don't need
|
||||||
to generate one */
|
to generate one */
|
||||||
if (user_program &&
|
if (_cogl_program_has_fragment_shader (user_program))
|
||||||
_cogl_program_has_fragment_shader (user_program))
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* We reuse two grow-only GStrings for code-gen. One string
|
/* We reuse two grow-only GStrings for code-gen. One string
|
||||||
contains the uniform and attribute declarations while the
|
contains the uniform and attribute declarations while the
|
||||||
@ -440,8 +431,8 @@ ensure_texture_lookup_generated (CoglPipelineShaderState *shader_state,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
g_string_append_printf (shader_state->source,
|
g_string_append_printf (shader_state->source,
|
||||||
"cogl_tex_coord_in[%d]",
|
"cogl_tex_coord%i_in",
|
||||||
unit_index);
|
layer->index);
|
||||||
|
|
||||||
g_string_append (shader_state->source, ");\n");
|
g_string_append (shader_state->source, ");\n");
|
||||||
|
|
||||||
@ -1026,7 +1017,12 @@ _cogl_pipeline_fragend_glsl_end (CoglPipeline *pipeline,
|
|||||||
get_texture_target_string (texture_type, &target_string, NULL);
|
get_texture_target_string (texture_type, &target_string, NULL);
|
||||||
|
|
||||||
g_string_append_printf (shader_state->header,
|
g_string_append_printf (shader_state->header,
|
||||||
|
"varying vec4 _cogl_tex_coord%i;\n"
|
||||||
|
"#define cogl_tex_coord%i_in _cogl_tex_coord%i\n"
|
||||||
"uniform sampler%s cogl_sampler%i;\n",
|
"uniform sampler%s cogl_sampler%i;\n",
|
||||||
|
layer->index,
|
||||||
|
layer->index,
|
||||||
|
layer->index,
|
||||||
target_string,
|
target_string,
|
||||||
layer->index);
|
layer->index);
|
||||||
}
|
}
|
||||||
@ -1081,8 +1077,6 @@ _cogl_pipeline_fragend_glsl_end (CoglPipeline *pipeline,
|
|||||||
_cogl_glsl_shader_set_source_with_boilerplate (ctx,
|
_cogl_glsl_shader_set_source_with_boilerplate (ctx,
|
||||||
version_string,
|
version_string,
|
||||||
shader, GL_FRAGMENT_SHADER,
|
shader, GL_FRAGMENT_SHADER,
|
||||||
shader_state
|
|
||||||
->n_tex_coord_attribs,
|
|
||||||
2, /* count */
|
2, /* count */
|
||||||
source_strings, lengths);
|
source_strings, lengths);
|
||||||
|
|
||||||
|
@ -144,8 +144,7 @@ _cogl_delete_gl_texture (GLuint gl_texture);
|
|||||||
void
|
void
|
||||||
_cogl_pipeline_flush_gl_state (CoglPipeline *pipeline,
|
_cogl_pipeline_flush_gl_state (CoglPipeline *pipeline,
|
||||||
CoglFramebuffer *framebuffer,
|
CoglFramebuffer *framebuffer,
|
||||||
CoglBool skip_gl_state,
|
CoglBool skip_gl_state);
|
||||||
int n_tex_coord_attribs);
|
|
||||||
|
|
||||||
#endif /* __COGL_PIPELINE_OPENGL_PRIVATE_H */
|
#endif /* __COGL_PIPELINE_OPENGL_PRIVATE_H */
|
||||||
|
|
||||||
|
@ -1147,8 +1147,7 @@ fragend_add_layer_cb (CoglPipelineLayer *layer,
|
|||||||
void
|
void
|
||||||
_cogl_pipeline_flush_gl_state (CoglPipeline *pipeline,
|
_cogl_pipeline_flush_gl_state (CoglPipeline *pipeline,
|
||||||
CoglFramebuffer *framebuffer,
|
CoglFramebuffer *framebuffer,
|
||||||
CoglBool skip_gl_color,
|
CoglBool skip_gl_color)
|
||||||
int n_tex_coord_attribs)
|
|
||||||
{
|
{
|
||||||
unsigned long pipelines_difference;
|
unsigned long pipelines_difference;
|
||||||
int n_layers;
|
int n_layers;
|
||||||
@ -1203,16 +1202,6 @@ _cogl_pipeline_flush_gl_state (CoglPipeline *pipeline,
|
|||||||
else
|
else
|
||||||
layer_differences = NULL;
|
layer_differences = NULL;
|
||||||
|
|
||||||
/* Make sure we generate the texture coordinate array to be at least
|
|
||||||
the number of layers. This is important because the vertend will
|
|
||||||
try to pass along the corresponding varying for each layer
|
|
||||||
regardless of whether the fragment shader is actually using
|
|
||||||
it. Also it is possible that the application is assuming that if
|
|
||||||
the attribute isn't passed then it will default to 0,0. This is
|
|
||||||
what test-cogl-primitive does */
|
|
||||||
if (n_layers > n_tex_coord_attribs)
|
|
||||||
n_tex_coord_attribs = n_layers;
|
|
||||||
|
|
||||||
/* First flush everything that's the same regardless of which
|
/* First flush everything that's the same regardless of which
|
||||||
* pipeline backend is being used...
|
* pipeline backend is being used...
|
||||||
*
|
*
|
||||||
@ -1266,8 +1255,7 @@ _cogl_pipeline_flush_gl_state (CoglPipeline *pipeline,
|
|||||||
|
|
||||||
vertend->start (pipeline,
|
vertend->start (pipeline,
|
||||||
n_layers,
|
n_layers,
|
||||||
pipelines_difference,
|
pipelines_difference);
|
||||||
n_tex_coord_attribs);
|
|
||||||
|
|
||||||
state.framebuffer = framebuffer;
|
state.framebuffer = framebuffer;
|
||||||
state.vertend = vertend;
|
state.vertend = vertend;
|
||||||
@ -1298,8 +1286,7 @@ _cogl_pipeline_flush_gl_state (CoglPipeline *pipeline,
|
|||||||
|
|
||||||
fragend->start (pipeline,
|
fragend->start (pipeline,
|
||||||
n_layers,
|
n_layers,
|
||||||
pipelines_difference,
|
pipelines_difference);
|
||||||
n_tex_coord_attribs);
|
|
||||||
|
|
||||||
_cogl_pipeline_foreach_layer_internal (pipeline,
|
_cogl_pipeline_foreach_layer_internal (pipeline,
|
||||||
fragend_add_layer_cb,
|
fragend_add_layer_cb,
|
||||||
@ -1319,7 +1306,7 @@ _cogl_pipeline_flush_gl_state (CoglPipeline *pipeline,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (progend->end)
|
if (progend->end)
|
||||||
progend->end (pipeline, pipelines_difference, n_tex_coord_attribs);
|
progend->end (pipeline, pipelines_difference);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,15 +109,6 @@ typedef struct
|
|||||||
|
|
||||||
GLuint program;
|
GLuint program;
|
||||||
|
|
||||||
/* To allow writing shaders that are portable between GLES 2 and
|
|
||||||
* OpenGL Cogl prepends a number of boilerplate #defines and
|
|
||||||
* declarations to user shaders. One of those declarations is an
|
|
||||||
* array of texture coordinate varyings, but to know how to emit the
|
|
||||||
* declaration we need to know how many texture coordinate
|
|
||||||
* attributes are in use. The boilerplate also needs to be changed
|
|
||||||
* if this changes. */
|
|
||||||
int n_tex_coord_attribs;
|
|
||||||
|
|
||||||
unsigned long dirty_builtin_uniforms;
|
unsigned long dirty_builtin_uniforms;
|
||||||
GLint builtin_uniform_locations[G_N_ELEMENTS (builtin_uniforms)];
|
GLint builtin_uniform_locations[G_N_ELEMENTS (builtin_uniforms)];
|
||||||
|
|
||||||
@ -244,7 +235,6 @@ program_state_new (int n_layers)
|
|||||||
program_state = g_slice_new (CoglPipelineProgramState);
|
program_state = g_slice_new (CoglPipelineProgramState);
|
||||||
program_state->ref_count = 1;
|
program_state->ref_count = 1;
|
||||||
program_state->program = 0;
|
program_state->program = 0;
|
||||||
program_state->n_tex_coord_attribs = 0;
|
|
||||||
program_state->unit_state = g_new (UnitState, n_layers);
|
program_state->unit_state = g_new (UnitState, n_layers);
|
||||||
program_state->uniform_locations = NULL;
|
program_state->uniform_locations = NULL;
|
||||||
program_state->attribute_locations = NULL;
|
program_state->attribute_locations = NULL;
|
||||||
@ -387,7 +377,7 @@ get_uniform_cb (CoglPipeline *pipeline,
|
|||||||
|
|
||||||
g_string_set_size (ctx->codegen_source_buffer, 0);
|
g_string_set_size (ctx->codegen_source_buffer, 0);
|
||||||
g_string_append_printf (ctx->codegen_source_buffer,
|
g_string_append_printf (ctx->codegen_source_buffer,
|
||||||
"cogl_texture_matrix[%i]", state->unit);
|
"cogl_texture_matrix%i", layer_index);
|
||||||
|
|
||||||
GE_RET( uniform_location,
|
GE_RET( uniform_location,
|
||||||
ctx, glGetUniformLocation (state->gl_program,
|
ctx, glGetUniformLocation (state->gl_program,
|
||||||
@ -644,8 +634,7 @@ _cogl_pipeline_progend_glsl_start (CoglPipeline *pipeline)
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
_cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline,
|
_cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline,
|
||||||
unsigned long pipelines_difference,
|
unsigned long pipelines_difference)
|
||||||
int n_tex_coord_attribs)
|
|
||||||
{
|
{
|
||||||
CoglPipelineProgramState *program_state;
|
CoglPipelineProgramState *program_state;
|
||||||
GLuint gl_program;
|
GLuint gl_program;
|
||||||
@ -714,14 +703,9 @@ _cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If the program has changed since the last link then we do
|
/* If the program has changed since the last link then we do
|
||||||
* need to relink
|
* need to relink */
|
||||||
*
|
if (program_state->program && user_program &&
|
||||||
* Also if the number of texture coordinate attributes in use has
|
user_program->age != program_state->user_program_age)
|
||||||
* changed, then delete the program so we can prepend a new
|
|
||||||
* _cogl_tex_coord[] varying array declaration. */
|
|
||||||
if ((program_state->program && user_program &&
|
|
||||||
user_program->age != program_state->user_program_age) ||
|
|
||||||
n_tex_coord_attribs != program_state->n_tex_coord_attribs)
|
|
||||||
{
|
{
|
||||||
GE( ctx, glDeleteProgram (program_state->program) );
|
GE( ctx, glDeleteProgram (program_state->program) );
|
||||||
program_state->program = 0;
|
program_state->program = 0;
|
||||||
@ -741,7 +725,7 @@ _cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline,
|
|||||||
{
|
{
|
||||||
CoglShader *shader = l->data;
|
CoglShader *shader = l->data;
|
||||||
|
|
||||||
_cogl_shader_compile_real (shader, n_tex_coord_attribs);
|
_cogl_shader_compile_real (shader, 4);
|
||||||
|
|
||||||
g_assert (shader->language == COGL_SHADER_LANGUAGE_GLSL);
|
g_assert (shader->language == COGL_SHADER_LANGUAGE_GLSL);
|
||||||
|
|
||||||
@ -761,8 +745,6 @@ _cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline,
|
|||||||
link_program (program_state->program);
|
link_program (program_state->program);
|
||||||
|
|
||||||
program_changed = TRUE;
|
program_changed = TRUE;
|
||||||
|
|
||||||
program_state->n_tex_coord_attribs = n_tex_coord_attribs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gl_program = program_state->program;
|
gl_program = program_state->program;
|
||||||
|
@ -47,8 +47,7 @@ const CoglPipelineVertend _cogl_pipeline_fixed_vertend;
|
|||||||
static void
|
static void
|
||||||
_cogl_pipeline_vertend_fixed_start (CoglPipeline *pipeline,
|
_cogl_pipeline_vertend_fixed_start (CoglPipeline *pipeline,
|
||||||
int n_layers,
|
int n_layers,
|
||||||
unsigned long pipelines_difference,
|
unsigned long pipelines_difference)
|
||||||
int n_tex_coord_attribs)
|
|
||||||
{
|
{
|
||||||
_cogl_use_vertex_program (0, COGL_PIPELINE_PROGRAM_TYPE_FIXED);
|
_cogl_use_vertex_program (0, COGL_PIPELINE_PROGRAM_TYPE_FIXED);
|
||||||
}
|
}
|
||||||
|
@ -60,9 +60,6 @@ typedef struct
|
|||||||
a shader at all */
|
a shader at all */
|
||||||
unsigned int user_program_age;
|
unsigned int user_program_age;
|
||||||
|
|
||||||
/* The number of tex coord attributes that the shader was generated
|
|
||||||
* for. If this changes then we need to regenerate the shader */
|
|
||||||
int n_tex_coord_attribs;
|
|
||||||
} CoglPipelineShaderState;
|
} CoglPipelineShaderState;
|
||||||
|
|
||||||
static CoglUserDataKey shader_state_key;
|
static CoglUserDataKey shader_state_key;
|
||||||
@ -152,8 +149,7 @@ get_layer_vertex_snippets (CoglPipelineLayer *layer)
|
|||||||
static void
|
static void
|
||||||
_cogl_pipeline_vertend_glsl_start (CoglPipeline *pipeline,
|
_cogl_pipeline_vertend_glsl_start (CoglPipeline *pipeline,
|
||||||
int n_layers,
|
int n_layers,
|
||||||
unsigned long pipelines_difference,
|
unsigned long pipelines_difference)
|
||||||
int n_tex_coord_attribs)
|
|
||||||
{
|
{
|
||||||
CoglPipelineShaderState *shader_state;
|
CoglPipelineShaderState *shader_state;
|
||||||
CoglPipeline *template_pipeline = NULL;
|
CoglPipeline *template_pipeline = NULL;
|
||||||
@ -217,13 +213,11 @@ _cogl_pipeline_vertend_glsl_start (CoglPipeline *pipeline,
|
|||||||
if (shader_state->gl_shader)
|
if (shader_state->gl_shader)
|
||||||
{
|
{
|
||||||
/* If we already have a valid GLSL shader then we don't need to
|
/* If we already have a valid GLSL shader then we don't need to
|
||||||
generate a new one. However if there's a user program and it
|
* generate a new one. However if there's a user program and it
|
||||||
has changed since the last link then we do need a new shader.
|
* has changed since the last link then we do need a new shader.
|
||||||
Also if the number of tex coord attribs changes then we need
|
*/
|
||||||
to regenerate the shader with a different boiler plate */
|
if (user_program == NULL ||
|
||||||
if ((user_program == NULL ||
|
|
||||||
shader_state->user_program_age == user_program->age)
|
shader_state->user_program_age == user_program->age)
|
||||||
&& shader_state->n_tex_coord_attribs == n_tex_coord_attribs)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* We need to recreate the shader so destroy the existing one */
|
/* We need to recreate the shader so destroy the existing one */
|
||||||
@ -236,15 +230,14 @@ _cogl_pipeline_vertend_glsl_start (CoglPipeline *pipeline,
|
|||||||
because the user program has changed */
|
because the user program has changed */
|
||||||
|
|
||||||
if (user_program)
|
if (user_program)
|
||||||
|
{
|
||||||
shader_state->user_program_age = user_program->age;
|
shader_state->user_program_age = user_program->age;
|
||||||
|
|
||||||
shader_state->n_tex_coord_attribs = n_tex_coord_attribs;
|
|
||||||
|
|
||||||
/* If the user program contains a vertex shader then we don't need
|
/* If the user program contains a vertex shader then we don't need
|
||||||
to generate one */
|
to generate one */
|
||||||
if (user_program &&
|
if (_cogl_program_has_vertex_shader (user_program))
|
||||||
_cogl_program_has_vertex_shader (user_program))
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* We reuse two grow-only GStrings for code-gen. One string
|
/* We reuse two grow-only GStrings for code-gen. One string
|
||||||
contains the uniform and attribute declarations while the
|
contains the uniform and attribute declarations while the
|
||||||
@ -277,17 +270,26 @@ _cogl_pipeline_vertend_glsl_add_layer (CoglPipeline *pipeline,
|
|||||||
{
|
{
|
||||||
CoglPipelineShaderState *shader_state;
|
CoglPipelineShaderState *shader_state;
|
||||||
CoglPipelineSnippetData snippet_data;
|
CoglPipelineSnippetData snippet_data;
|
||||||
int unit_index;
|
int layer_index = layer->index;
|
||||||
|
|
||||||
_COGL_GET_CONTEXT (ctx, FALSE);
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
||||||
|
|
||||||
shader_state = get_shader_state (pipeline);
|
shader_state = get_shader_state (pipeline);
|
||||||
|
|
||||||
unit_index = _cogl_pipeline_layer_get_unit_index (layer);
|
|
||||||
|
|
||||||
if (shader_state->source == NULL)
|
if (shader_state->source == NULL)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
g_string_append_printf (shader_state->header,
|
||||||
|
"uniform mat4 cogl_texture_matrix%i;\n"
|
||||||
|
"attribute vec4 cogl_tex_coord%i_in;\n"
|
||||||
|
"varying vec4 _cogl_tex_coord%i;\n"
|
||||||
|
"#define cogl_tex_coord%i_out _cogl_tex_coord%i\n",
|
||||||
|
layer_index,
|
||||||
|
layer_index,
|
||||||
|
layer_index,
|
||||||
|
layer_index,
|
||||||
|
layer_index);
|
||||||
|
|
||||||
/* Transform the texture coordinates by the layer's user matrix.
|
/* Transform the texture coordinates by the layer's user matrix.
|
||||||
*
|
*
|
||||||
* FIXME: this should avoid doing the transform if there is no user
|
* FIXME: this should avoid doing the transform if there is no user
|
||||||
@ -306,18 +308,18 @@ _cogl_pipeline_vertend_glsl_add_layer (CoglPipeline *pipeline,
|
|||||||
"{\n"
|
"{\n"
|
||||||
" return matrix * tex_coord;\n"
|
" return matrix * tex_coord;\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
unit_index);
|
layer_index);
|
||||||
|
|
||||||
/* Wrap the layer code in any snippets that have been hooked */
|
/* Wrap the layer code in any snippets that have been hooked */
|
||||||
memset (&snippet_data, 0, sizeof (snippet_data));
|
memset (&snippet_data, 0, sizeof (snippet_data));
|
||||||
snippet_data.snippets = get_layer_vertex_snippets (layer);
|
snippet_data.snippets = get_layer_vertex_snippets (layer);
|
||||||
snippet_data.hook = COGL_SNIPPET_HOOK_TEXTURE_COORD_TRANSFORM;
|
snippet_data.hook = COGL_SNIPPET_HOOK_TEXTURE_COORD_TRANSFORM;
|
||||||
snippet_data.chain_function = g_strdup_printf ("cogl_real_transform_layer%i",
|
snippet_data.chain_function = g_strdup_printf ("cogl_real_transform_layer%i",
|
||||||
unit_index);
|
layer_index);
|
||||||
snippet_data.final_name = g_strdup_printf ("cogl_transform_layer%i",
|
snippet_data.final_name = g_strdup_printf ("cogl_transform_layer%i",
|
||||||
unit_index);
|
layer_index);
|
||||||
snippet_data.function_prefix = g_strdup_printf ("cogl_transform_layer%i",
|
snippet_data.function_prefix = g_strdup_printf ("cogl_transform_layer%i",
|
||||||
unit_index);
|
layer_index);
|
||||||
snippet_data.return_type = "vec4";
|
snippet_data.return_type = "vec4";
|
||||||
snippet_data.return_variable = "cogl_tex_coord";
|
snippet_data.return_variable = "cogl_tex_coord";
|
||||||
snippet_data.return_variable_is_argument = TRUE;
|
snippet_data.return_variable_is_argument = TRUE;
|
||||||
@ -332,14 +334,14 @@ _cogl_pipeline_vertend_glsl_add_layer (CoglPipeline *pipeline,
|
|||||||
g_free ((char *) snippet_data.function_prefix);
|
g_free ((char *) snippet_data.function_prefix);
|
||||||
|
|
||||||
g_string_append_printf (shader_state->source,
|
g_string_append_printf (shader_state->source,
|
||||||
" cogl_tex_coord_out[%i] = "
|
" cogl_tex_coord%i_out = "
|
||||||
"cogl_transform_layer%i (cogl_texture_matrix[%i],\n"
|
"cogl_transform_layer%i (cogl_texture_matrix%i,\n"
|
||||||
" "
|
" "
|
||||||
" cogl_tex_coord%i_in);\n",
|
" cogl_tex_coord%i_in);\n",
|
||||||
unit_index,
|
layer_index,
|
||||||
unit_index,
|
layer_index,
|
||||||
unit_index,
|
layer_index,
|
||||||
unit_index);
|
layer_index);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -437,8 +439,6 @@ _cogl_pipeline_vertend_glsl_end (CoglPipeline *pipeline,
|
|||||||
_cogl_glsl_shader_set_source_with_boilerplate (ctx,
|
_cogl_glsl_shader_set_source_with_boilerplate (ctx,
|
||||||
NULL,
|
NULL,
|
||||||
shader, GL_VERTEX_SHADER,
|
shader, GL_VERTEX_SHADER,
|
||||||
shader_state
|
|
||||||
->n_tex_coord_attribs,
|
|
||||||
2, /* count */
|
2, /* count */
|
||||||
source_strings, lengths);
|
source_strings, lengths);
|
||||||
|
|
||||||
|
@ -158,8 +158,7 @@ dirty_shader_state (CoglPipeline *pipeline)
|
|||||||
static void
|
static void
|
||||||
_cogl_pipeline_fragend_arbfp_start (CoglPipeline *pipeline,
|
_cogl_pipeline_fragend_arbfp_start (CoglPipeline *pipeline,
|
||||||
int n_layers,
|
int n_layers,
|
||||||
unsigned long pipelines_difference,
|
unsigned long pipelines_difference)
|
||||||
int n_tex_coord_attribs)
|
|
||||||
{
|
{
|
||||||
CoglPipelineShaderState *shader_state;
|
CoglPipelineShaderState *shader_state;
|
||||||
CoglPipeline *authority;
|
CoglPipeline *authority;
|
||||||
|
Loading…
Reference in New Issue
Block a user