gl renderer: Keep track of current program color value

This commit is contained in:
Timm Bäder 2017-11-24 13:18:45 +01:00
parent 2865ab84a9
commit 19700fccb2
3 changed files with 26 additions and 11 deletions

View File

@ -646,12 +646,8 @@ gsk_gl_renderer_add_render_ops (GskGLRenderer *self,
case GSK_COLOR_NODE:
{
RenderOp op;
ops_set_program (builder, &self->color_program);
op.op = OP_CHANGE_COLOR;
op.color = *gsk_color_node_peek_color (node);
ops_add (builder, &op);
ops_set_color (builder, gsk_color_node_peek_color (node));
ops_draw (builder, vertex_data);
}
break;
@ -851,13 +847,8 @@ gsk_gl_renderer_add_render_ops (GskGLRenderer *self,
}
else
{
RenderOp op;
ops_set_program (builder, &self->coloring_program);
op.op = OP_CHANGE_COLOR;
op.color = *gsk_text_node_peek_color (node);
ops_add (builder, &op);
ops_set_color (builder, gsk_text_node_peek_color (node));
}
/* We use one quad per character, unlike the other nodes which

View File

@ -210,6 +210,24 @@ ops_set_opacity (RenderOpBuilder *builder,
return prev_opacity;
}
void
ops_set_color (RenderOpBuilder *builder,
const GdkRGBA *color)
{
RenderOp op;
g_assert (builder->current_program->color_location != 0);
if (gdk_rgba_equal (color, &builder->program_state[builder->current_program->index].color))
return;
builder->program_state[builder->current_program->index].color = *color;
op.op = OP_CHANGE_COLOR;
op.color = *color;
g_array_append_val (builder->render_ops, op);
}
void
ops_draw (RenderOpBuilder *builder,
const GskQuadVertex vertex_data[GL_N_VERTICES])

View File

@ -116,6 +116,10 @@ typedef struct
graphene_matrix_t projection;
int source_texture;
graphene_rect_t viewport;
/* Per-program state */
union {
GdkRGBA color;
};
} program_state[GL_N_PROGRAMS];
/* Current global state */
@ -160,6 +164,8 @@ int ops_set_render_target (RenderOpBuilder *builder,
float ops_set_opacity (RenderOpBuilder *builder,
float opacity);
void ops_set_color (RenderOpBuilder *builder,
const GdkRGBA *color);
void ops_draw (RenderOpBuilder *builder,
const GskQuadVertex vertex_data[GL_N_VERTICES]);