diff --git a/cogl-color.h b/cogl-color.h index 1e4f9fda2..fbc49d5bb 100644 --- a/cogl-color.h +++ b/cogl-color.h @@ -28,6 +28,10 @@ G_BEGIN_DECLS +CoglColor *cogl_color_new (void); +CoglColor *cogl_color_copy (const CoglColor *color); +void cogl_color_free (CoglColor *color); + /** * cogl_color_set_from_4ub: * @dest: return location for a #CoglColor @@ -36,7 +40,7 @@ G_BEGIN_DECLS * @blue: value of the blue channel, between 0 and 255 * @alpha: value of the alpha channel, between 0 and 255 * - * Sets the values of the passed channel into a #CoglColor. + * Sets the values of the passed channels into a #CoglColor. * * Since: 1.0 */ @@ -46,14 +50,14 @@ void cogl_color_set_from_4ub (CoglColor *dest, guint8 blue, guint8 alpha); /** - * cogl_color_set_from_4ub: + * cogl_color_set_from_4d: * @dest: return location for a #CoglColor * @red: value of the red channel, between 0 and 1 * @green: value of the green channel, between 0 and 1 * @blue: value of the blue channel, between 0 and 1 * @alpha: value of the alpha channel, between 0 and 1 * - * Sets the values of the passed channel into a #CoglColor. + * Sets the values of the passed channels into a #CoglColor. * * Since: 1.0 */ @@ -63,6 +67,24 @@ void cogl_color_set_from_4d (CoglColor *dest, gdouble blue, gdouble alpha); +/** + * cogl_color_set_from_4x: + * @dest: return location for a #CoglColor + * @red: value of the red channel, between 0 and %COGL_FIXED_1 + * @green: value of the green channel, between 0 and %COGL_FIXED_1 + * @blue: value of the blue channel, between 0 and %COGL_FIXED_1 + * @alpha: value of the alpha channel, between 0 and %COGL_FIXED_1 + * + * Sets the values of the passed channels into a #CoglColor + * + * Since: 1.0 + */ +void cogl_color_set_from_4x (CoglColor *dest, + CoglFixed red, + CoglFixed green, + CoglFixed blue, + CoglFixed alpha); + /** * cogl_color_get_red_byte: * @color: a #CoglColor @@ -219,6 +241,61 @@ CoglFixed cogl_color_get_blue (const CoglColor *color); */ CoglFixed cogl_color_get_alpha (const CoglColor *color); +/** + * cogl_set_source_color: + * @color: a #CoglColor + * + * Sets the source color using normalized values for each component. + * This color will be used for any subsequent drawing operation. + * + * See also cogl_set_source_color4ub() and cogl_set_source_color4x() + * if you already have the color components. + * + * Since: 1.0 + */ +void cogl_set_source_color (const CoglColor *color); + +/** + * cogl_set_source_color4ub: + * @red: value of the red channel, between 0 and 255 + * @green: value of the green channel, between 0 and 255 + * @blue: value of the blue channel, between 0 and 255 + * @alpha: value of the alpha channel, between 0 and 255 + * + * Sets the source color using unsigned bytes for each component. This + * color will be used for any subsequent drawing operation. + * + * The value for each component is an unsigned byte in the range + * between 0 and 255. + * + * Since: 1.0 + */ +void cogl_set_source_color4ub (guint8 red, + guint8 green, + guint8 blue, + guint8 alpha); + +/** + * cogl_set_source_color4x: + * @red: value of the red channel, between 0 and %COGL_FIXED_1 + * @green: value of the green channel, between 0 and %COGL_FIXED_1 + * @blue: value of the blue channel, between 0 and %COGL_FIXED_1 + * @alpha: value of the alpha channel, between 0 and %COGL_FIXED_1 + * + * Sets the source color using normalized values for each component. + * This color will be used for any subsequent drawing operation. + * + * The value for each component is a fixed point number in the range + * between 0 and %COGL_FIXED_1. If the values passed in are outside that + * range, they will be clamped. + * + * Since: 1.0 + */ +void cogl_set_source_color4x (CoglFixed red, + CoglFixed green, + CoglFixed blue, + CoglFixed alpha); + G_END_DECLS #endif /* __COGL_COLOR_H__ */ diff --git a/cogl-deprecated.h b/cogl-deprecated.h new file mode 100644 index 000000000..17d1fe4d9 --- /dev/null +++ b/cogl-deprecated.h @@ -0,0 +1,5 @@ +#ifndef COGL_DEPRECATED_H + +#define cogl_color cogl_color_REPLACED_BY_cogl_set_source_color + +#endif diff --git a/cogl-path.h b/cogl-path.h index 310796f97..01867d144 100644 --- a/cogl-path.h +++ b/cogl-path.h @@ -50,16 +50,6 @@ G_BEGIN_DECLS * rather then in the absolute coordinates. */ -/** - * cogl_color: - * @color: new current @CoglColor. - * - * Changes the color of cogl's current paint, which is used for filling and stroking - * primitives. - */ -void cogl_color (const CoglColor *color); - - /** * cogl_rectangle: * @x: X coordinate of the top-left corner diff --git a/cogl-types.h b/cogl-types.h index bb5ed3309..4fb69953a 100644 --- a/cogl-types.h +++ b/cogl-types.h @@ -230,11 +230,11 @@ typedef enum struct _CoglColor { /*< private >*/ - CoglFixed red; - CoglFixed green; - CoglFixed blue; + guint8 red; + guint8 green; + guint8 blue; - CoglFixed alpha; + guint8 alpha; }; /** diff --git a/cogl.h.in b/cogl.h.in index 6b921e73e..224a1fac4 100644 --- a/cogl.h.in +++ b/cogl.h.in @@ -40,6 +40,7 @@ #include #include #include +#include G_BEGIN_DECLS diff --git a/common/cogl-color.c b/common/cogl-color.c index 7bff49780..a248b95c9 100644 --- a/common/cogl-color.c +++ b/common/cogl-color.c @@ -5,6 +5,28 @@ #include "cogl-color.h" #include "cogl-fixed.h" +CoglColor * +cogl_color_new (void) +{ + return g_slice_new (CoglColor); +} + +CoglColor * +cogl_color_copy (const CoglColor *color) +{ + if (G_LIKELY (color)) + return g_slice_dup (CoglColor, color); + + return NULL; +} + +void +cogl_color_free (CoglColor *color) +{ + if (G_LIKELY (color)) + g_slice_free (CoglColor, color); +} + void cogl_color_set_from_4ub (CoglColor *dest, guint8 red, @@ -14,10 +36,10 @@ cogl_color_set_from_4ub (CoglColor *dest, { g_return_if_fail (dest != NULL); - dest->red = COGL_FIXED_FROM_FLOAT ((float) red / 0xff * 1.0); - dest->green = COGL_FIXED_FROM_FLOAT ((float) green / 0xff * 1.0); - dest->blue = COGL_FIXED_FROM_FLOAT ((float) blue / 0xff * 1.0); - dest->alpha = COGL_FIXED_FROM_FLOAT ((float) alpha / 0xff * 1.0); + dest->red = red; + dest->green = green; + dest->blue = blue; + dest->alpha = alpha; } void @@ -29,80 +51,119 @@ cogl_color_set_from_4d (CoglColor *dest, { g_return_if_fail (dest != NULL); - dest->red = COGL_FIXED_FROM_FLOAT (CLAMP (red, 0.0, 1.0)); - dest->green = COGL_FIXED_FROM_FLOAT (CLAMP (green, 0.0, 1.0)); - dest->blue = COGL_FIXED_FROM_FLOAT (CLAMP (blue, 0.0, 1.0)); - dest->alpha = COGL_FIXED_FROM_FLOAT (CLAMP (alpha, 0.0, 1.0)); + dest->red = 255 * red; + dest->green = 255 * green; + dest->blue = 255 * blue; + dest->alpha = 255 * alpha; +} + +void +cogl_color_set_from_4x (CoglColor *dest, + CoglFixed red, + CoglFixed green, + CoglFixed blue, + CoglFixed alpha) +{ + g_return_if_fail (dest != NULL); + + dest->red = COGL_FIXED_TO_INT (red * 255); + dest->green = COGL_FIXED_TO_INT (green * 255); + dest->blue = COGL_FIXED_TO_INT (blue * 255); + dest->alpha = COGL_FIXED_TO_INT (alpha * 255); } unsigned char cogl_color_get_red_byte (const CoglColor *color) { - return COGL_FIXED_TO_INT (color->red * 255); + return color->red; } float cogl_color_get_red_float (const CoglColor *color) { - return COGL_FIXED_TO_FLOAT (color->red); + return (float) color->red / 255.0; } CoglFixed cogl_color_get_red (const CoglColor *color) { - return color->red; + return COGL_FIXED_FROM_FLOAT ((float) color->red / 255.0); } unsigned char cogl_color_get_green_byte (const CoglColor *color) { - return COGL_FIXED_TO_INT (color->green * 255); + return color->green; } float cogl_color_get_green_float (const CoglColor *color) { - return COGL_FIXED_TO_FLOAT (color->green); + return (float) color->green / 255.0; } CoglFixed cogl_color_get_green (const CoglColor *color) { - return color->green; + return COGL_FIXED_FROM_FLOAT ((float) color->green / 255.0); } unsigned char cogl_color_get_blue_byte (const CoglColor *color) { - return COGL_FIXED_TO_INT (color->blue * 255); + return color->blue; } float cogl_color_get_blue_float (const CoglColor *color) { - return COGL_FIXED_TO_FLOAT (color->blue); + return (float) color->blue / 255.0; } CoglFixed cogl_color_get_blue (const CoglColor *color) { - return color->blue; + return COGL_FIXED_FROM_FLOAT ((float) color->blue / 255.0); } unsigned char cogl_color_get_alpha_byte (const CoglColor *color) { - return COGL_FIXED_TO_INT (color->alpha * 255); + return color->alpha; } float cogl_color_get_alpha_float (const CoglColor *color) { - return COGL_FIXED_TO_FLOAT (color->alpha); + return (float) color->alpha / 255.0; } CoglFixed cogl_color_get_alpha (const CoglColor *color) { - return color->alpha; + return COGL_FIXED_FROM_FLOAT ((float) color->alpha / 255.0); +} + +void +cogl_set_source_color4ub (guint8 red, + guint8 green, + guint8 blue, + guint8 alpha) +{ + CoglColor c = { 0, }; + + cogl_color_set_from_4ub (&c, red, green, blue, alpha); + cogl_set_source_color (&c); +} + +void +cogl_set_source_color4x (CoglFixed red, + CoglFixed green, + CoglFixed blue, + CoglFixed alpha) +{ + CoglColor c = { 0, }; + + cogl_color_set_from_4x (&c, red, green, blue, alpha); + cogl_set_source_color (&c); } diff --git a/doc/reference/cogl/cogl-sections.txt b/doc/reference/cogl/cogl-sections.txt index c2c9f40e7..ee5dbad5d 100644 --- a/doc/reference/cogl/cogl-sections.txt +++ b/doc/reference/cogl/cogl-sections.txt @@ -63,9 +63,6 @@ cogl_util_next_p2
cogl-primitives Primitives -cogl_color -cogl_path_fill -cogl_path_stroke cogl_path_move_to cogl_path_close cogl_path_line_to @@ -80,6 +77,15 @@ cogl_path_polygon cogl_path_rectangle cogl_path_round_rectangle cogl_path_ellipse + + +cogl_path_fill +cogl_path_stroke +cogl_set_source_color +cogl_set_source_color4ub +cogl_set_source_color4x + + cogl_rectangle cogl_rectanglex
@@ -236,8 +242,12 @@ cogl_double_to_unit cogl-color Color Type CoglColor +cogl_color_new +cogl_color_copy +cogl_color_free cogl_color_set_from_4ub cogl_color_set_from_4d +cogl_color_set_from_4x cogl_color_get_red @@ -264,11 +274,13 @@ cogl_color_get_alpha_float cogl_mesh_new cogl_mesh_ref cogl_mesh_unref +CoglMeshAttributeFlags cogl_mesh_add_attribute cogl_mesh_delete_attribute cogl_mesh_enable_attribute cogl_mesh_disable_attribute cogl_mesh_draw_arrays cogl_mesh_draw_range_elements +cogl_mesh_submit diff --git a/gl/Makefile.am b/gl/Makefile.am index ec7750f32..2d90ba9c0 100644 --- a/gl/Makefile.am +++ b/gl/Makefile.am @@ -3,6 +3,7 @@ libclutterinclude_HEADERS = \ $(top_builddir)/clutter/cogl/cogl.h \ $(top_builddir)/clutter/cogl/cogl-defines-gl.h \ $(top_builddir)/clutter/cogl/cogl-color.h \ + $(top_builddir)/clutter/cogl/cogl-deprecated.h \ $(top_builddir)/clutter/cogl/cogl-fixed.h \ $(top_builddir)/clutter/cogl/cogl-offscreen.h \ $(top_builddir)/clutter/cogl/cogl-path.h \ @@ -32,6 +33,7 @@ libclutter_cogl_la_SOURCES = \ $(top_builddir)/clutter/cogl/cogl.h \ $(top_builddir)/clutter/cogl/cogl-defines-gl.h \ $(top_builddir)/clutter/cogl/cogl-color.h \ + $(top_builddir)/clutter/cogl/cogl-deprecated.h \ $(top_builddir)/clutter/cogl/cogl-fixed.h \ $(top_builddir)/clutter/cogl/cogl-offscreen.h \ $(top_builddir)/clutter/cogl/cogl-path.h \ diff --git a/gl/cogl-texture.c b/gl/cogl-texture.c index 3477cd66d..c640f27a7 100644 --- a/gl/cogl-texture.c +++ b/gl/cogl-texture.c @@ -2317,7 +2317,7 @@ cogl_texture_polygon (CoglHandle handle, GLfloat tx, ty; if (use_color) - cogl_color (&vertices[vnum].color); + cogl_set_source_color (&vertices[vnum].color); /* Transform the texture co-ordinates so they are relative to the slice */ diff --git a/gl/cogl.c b/gl/cogl.c index e3da3506f..8963e494e 100644 --- a/gl/cogl.c +++ b/gl/cogl.c @@ -380,14 +380,14 @@ cogl_enable_backface_culling (gboolean setting) } void -cogl_color (const CoglColor *color) +cogl_set_source_color (const CoglColor *color) { _COGL_GET_CONTEXT (ctx, NO_RETVAL); - glColor4f (cogl_color_get_red_float (color), - cogl_color_get_green_float (color), - cogl_color_get_blue_float (color), - cogl_color_get_alpha_float (color)); + glColor4ub (cogl_color_get_red_byte (color), + cogl_color_get_green_byte (color), + cogl_color_get_blue_byte (color), + cogl_color_get_alpha_byte (color)); /* Store alpha for proper blending enables */ ctx->color_alpha = cogl_color_get_alpha_byte (color); diff --git a/gles/Makefile.am b/gles/Makefile.am index 19867d986..19cf0a0d7 100644 --- a/gles/Makefile.am +++ b/gles/Makefile.am @@ -3,6 +3,7 @@ libclutterinclude_HEADERS = \ $(top_builddir)/clutter/cogl/cogl.h \ $(top_builddir)/clutter/cogl/cogl-defines-gles.h \ $(top_builddir)/clutter/cogl/cogl-color.h \ + $(top_builddir)/clutter/cogl/cogl-deprecated.h \ $(top_builddir)/clutter/cogl/cogl-fixed.h \ $(top_builddir)/clutter/cogl/cogl-offscreen.h \ $(top_builddir)/clutter/cogl/cogl-path.h \ @@ -32,6 +33,7 @@ libclutter_cogl_la_SOURCES = \ $(top_builddir)/clutter/cogl/cogl.h \ $(top_builddir)/clutter/cogl/cogl-defines-gles.h \ $(top_builddir)/clutter/cogl/cogl-color.h \ + $(top_builddir)/clutter/cogl/cogl-deprecated.h \ $(top_builddir)/clutter/cogl/cogl-fixed.h \ $(top_builddir)/clutter/cogl/cogl-offscreen.h \ $(top_builddir)/clutter/cogl/cogl-path.h \ diff --git a/gles/cogl-texture.c b/gles/cogl-texture.c index dbefa77c8..c7bc4af40 100644 --- a/gles/cogl-texture.c +++ b/gles/cogl-texture.c @@ -505,7 +505,7 @@ _cogl_texture_download_from_gl (CoglTexture *tex, old_dst_factor = ctx->blend_dst_factor; /* Direct copy operation */ - cogl_color (&cwhite); + cogl_set_source_color (&cwhite); cogl_blend_func (CGL_ONE, CGL_ZERO); _cogl_texture_draw_and_read (tex, target_bmp, &cwhite, viewport); @@ -2302,5 +2302,5 @@ cogl_texture_polygon (CoglHandle handle, /* Set the last color so that the cache of the alpha value will work properly */ if (use_color && n_vertices > 0) - cogl_color (&vertices[n_vertices - 1].color); + cogl_set_source_color (&vertices[n_vertices - 1].color); } diff --git a/gles/cogl.c b/gles/cogl.c index 16b8441ef..45bac331a 100644 --- a/gles/cogl.c +++ b/gles/cogl.c @@ -291,7 +291,7 @@ cogl_enable_backface_culling (gboolean setting) } void -cogl_color (const CoglColor *color) +cogl_set_source_color (const CoglColor *color) { _COGL_GET_CONTEXT (ctx, NO_RETVAL);