Revert "[rectangle] Avoid modifying materials mid scene"

This reverts commit 8cf42ea8ac5c05f6b443c453f9c6c2a3cd75acfa.

Since the journal puts material colors in the vertex array accumulated for
drawing we don't need to flush the journal simply due to color changes which
means using cogl_set_source_color4ub is no longer a concern.
This commit is contained in:
Robert Bragg 2009-06-24 18:24:58 +01:00
parent 5ffbe05248
commit 6ee8e15654

View File

@ -60,10 +60,8 @@ enum
struct _ClutterRectanglePrivate
{
ClutterColor primary_color;
CoglHandle primary_material;
ClutterColor border_color;
CoglHandle border_material;
ClutterColor color;
ClutterColor border_color;
guint border_width;
@ -80,7 +78,6 @@ clutter_rectangle_paint (ClutterActor *self)
ClutterRectanglePrivate *priv;
ClutterGeometry geom;
guint8 tmp_alpha;
guint8 opacity;
rectangle = CLUTTER_RECTANGLE(self);
priv = rectangle->priv;
@ -91,8 +88,6 @@ clutter_rectangle_paint (ClutterActor *self)
: "unknown");
clutter_actor_get_allocation_geometry (self, &geom);
opacity = clutter_actor_get_paint_opacity (self);
/* parent paint call will have translated us into position so
* paint from 0, 0
*/
@ -101,26 +96,15 @@ clutter_rectangle_paint (ClutterActor *self)
/* compute the composited opacity of the actor taking into
* account the opacity of the color set by the user
*/
tmp_alpha = opacity * priv->border_color.alpha / 255;
tmp_alpha = clutter_actor_get_paint_opacity (self)
* priv->border_color.alpha
/ 255;
/* paint the border */
/* We are assuming this is a NOP when the color doesn't change.
* This is important since we should aim to never modify
* materials mid-scene. */
cogl_material_set_color4ub (priv->border_material,
priv->border_color.red,
priv->border_color.green,
priv->border_color.blue,
tmp_alpha);
cogl_set_source (priv->border_material);
cogl_material_set_color4ub (priv->border_material,
priv->border_color.red,
priv->border_color.green,
priv->border_color.blue,
tmp_alpha);
cogl_set_source_color4ub (priv->border_color.red,
priv->border_color.green,
priv->border_color.blue,
tmp_alpha);
/* this sucks, but it's the only way to make a border */
cogl_rectangle (priv->border_width, 0,
@ -140,16 +124,15 @@ clutter_rectangle_paint (ClutterActor *self)
priv->border_width,
geom.height - priv->border_width);
tmp_alpha = opacity * priv->primary_color.alpha / 255;
tmp_alpha = clutter_actor_get_paint_opacity (self)
* priv->color.alpha
/ 255;
/* now paint the rectangle */
cogl_set_source (priv->primary_material);
cogl_material_set_color4ub (priv->primary_material,
priv->primary_color.red,
priv->primary_color.green,
priv->primary_color.blue,
tmp_alpha);
cogl_set_source_color4ub (priv->color.red,
priv->color.green,
priv->color.blue,
tmp_alpha);
cogl_rectangle (priv->border_width, priv->border_width,
geom.width - priv->border_width,
@ -160,16 +143,14 @@ clutter_rectangle_paint (ClutterActor *self)
/* compute the composited opacity of the actor taking into
* account the opacity of the color set by the user
*/
tmp_alpha = opacity * priv->primary_color.alpha / 255;
tmp_alpha = clutter_actor_get_paint_opacity (self)
* priv->color.alpha
/ 255;
/* now paint the rectangle */
cogl_set_source (priv->primary_material);
cogl_material_set_color4ub (priv->primary_material,
priv->primary_color.red,
priv->primary_color.green,
priv->primary_color.blue,
tmp_alpha);
cogl_set_source_color4ub (priv->color.red,
priv->color.green,
priv->color.blue,
tmp_alpha);
cogl_rectangle (0, 0, geom.width, geom.height);
}
@ -216,7 +197,7 @@ clutter_rectangle_get_property (GObject *object,
switch (prop_id)
{
case PROP_COLOR:
clutter_value_set_color (value, &priv->primary_color);
clutter_value_set_color (value, &priv->color);
break;
case PROP_BORDER_COLOR:
clutter_value_set_color (value, &priv->border_color);
@ -327,10 +308,8 @@ clutter_rectangle_init (ClutterRectangle *self)
self->priv = priv = CLUTTER_RECTANGLE_GET_PRIVATE (self);
priv->primary_color = default_color;
priv->color = default_color;
priv->border_color = default_border_color;
priv->primary_material = cogl_material_new ();
priv->border_material = cogl_material_new ();
priv->border_width = 0;
@ -385,10 +364,10 @@ clutter_rectangle_get_color (ClutterRectangle *rectangle,
priv = rectangle->priv;
color->red = priv->primary_color.red;
color->green = priv->primary_color.green;
color->blue = priv->primary_color.blue;
color->alpha = priv->primary_color.alpha;
color->red = priv->color.red;
color->green = priv->color.green;
color->blue = priv->color.blue;
color->alpha = priv->color.alpha;
}
/**
@ -411,10 +390,10 @@ clutter_rectangle_set_color (ClutterRectangle *rectangle,
priv = rectangle->priv;
priv->primary_color.red = color->red;
priv->primary_color.green = color->green;
priv->primary_color.blue = color->blue;
priv->primary_color.alpha = color->alpha;
priv->color.red = color->red;
priv->color.green = color->green;
priv->color.blue = color->blue;
priv->color.alpha = color->alpha;
#if 0
/* FIXME - appears to be causing border to always get drawn */
@ -546,7 +525,7 @@ clutter_rectangle_set_border_color (ClutterRectangle *rectangle,
priv->border_color.blue = color->blue;
priv->border_color.alpha = color->alpha;
if (clutter_color_equal (&priv->primary_color, &priv->border_color))
if (clutter_color_equal (&priv->color, &priv->border_color))
priv->has_border = FALSE;
else
priv->has_border = TRUE;