void _st_paint_shadow_with_opacity (StShadow *shadow_spec, CoglPipeline *shadow_pipeline, ClutterActorBox *box, guint8 paint_opacity) { CoglFramebuffer *fb = cogl_get_draw_framebuffer (); ClutterActorBox shadow_box; CoglColor color; g_return_if_fail (shadow_spec != NULL); g_return_if_fail (shadow_pipeline != NULL); st_shadow_get_box (shadow_spec, box, &shadow_box); cogl_color_init_from_4ub (&color, shadow_spec->color.red * paint_opacity / 255, shadow_spec->color.green * paint_opacity / 255, shadow_spec->color.blue * paint_opacity / 255, shadow_spec->color.alpha * paint_opacity / 255); cogl_color_premultiply (&color); cogl_pipeline_set_layer_combine_constant (shadow_pipeline, 0, &color); cogl_framebuffer_draw_rectangle (fb, shadow_pipeline, shadow_box.x1, shadow_box.y1, shadow_box.x2, shadow_box.y2); }
static void test_tex_combine (TestState *state, int x, int y, uint32_t tex0_color, uint32_t tex1_color, uint32_t combine_constant, const char *combine_string, uint32_t expected_result) { CoglTexture *tex0, *tex1; /* combine constant - when applicable */ uint8_t Cr = MASK_RED (combine_constant); uint8_t Cg = MASK_GREEN (combine_constant); uint8_t Cb = MASK_BLUE (combine_constant); uint8_t Ca = MASK_ALPHA (combine_constant); CoglColor combine_const_color; CoglPipeline *pipeline; CoglBool status; CoglError *error = NULL; int y_off; int x_off; tex0 = make_texture (tex0_color); tex1 = make_texture (tex1_color); pipeline = cogl_pipeline_new (test_ctx); cogl_pipeline_set_color4ub (pipeline, 0x80, 0x80, 0x80, 0x80); cogl_pipeline_set_blend (pipeline, "RGBA = ADD (SRC_COLOR, 0)", NULL); cogl_pipeline_set_layer_texture (pipeline, 0, tex0); cogl_pipeline_set_layer_combine (pipeline, 0, "RGBA = REPLACE (TEXTURE)", NULL); cogl_pipeline_set_layer_texture (pipeline, 1, tex1); status = cogl_pipeline_set_layer_combine (pipeline, 1, combine_string, &error); if (!status) { /* It's not strictly a test failure; you need a more capable GPU or * driver to test this texture combine string. */ g_debug ("Failed to test texture combine string %s: %s", combine_string, error->message); } cogl_color_init_from_4ub (&combine_const_color, Cr, Cg, Cb, Ca); cogl_pipeline_set_layer_combine_constant (pipeline, 1, &combine_const_color); cogl_framebuffer_draw_rectangle (test_fb, pipeline, x * QUAD_WIDTH, y * QUAD_WIDTH, x * QUAD_WIDTH + QUAD_WIDTH, y * QUAD_WIDTH + QUAD_WIDTH); cogl_object_unref (pipeline); cogl_object_unref (tex0); cogl_object_unref (tex1); /* See what we got... */ y_off = y * QUAD_WIDTH + (QUAD_WIDTH / 2); x_off = x * QUAD_WIDTH + (QUAD_WIDTH / 2); if (cogl_test_verbose ()) { g_print ("test_tex_combine (%d, %d):\n%s\n", x, y, combine_string); g_print (" texture 0 color = 0x%08lX\n", (unsigned long)tex0_color); g_print (" texture 1 color = 0x%08lX\n", (unsigned long)tex1_color); if (combine_constant != TEX_CONSTANT_UNUSED) g_print (" combine constant = %02x, %02x, %02x, %02x\n", Cr, Cg, Cb, Ca); else g_print (" combine constant = UNUSED\n"); } test_utils_check_pixel (test_fb, x_off, y_off, expected_result); }
void test_layer_remove (void) { CoglPipeline *pipeline0, *pipeline1; CoglColor color; int pos = 0; cogl_framebuffer_orthographic (test_fb, 0, 0, cogl_framebuffer_get_width (test_fb), cogl_framebuffer_get_height (test_fb), -1, 100); /** TEST 1 **/ /* Basic sanity check that the pipeline combines the two colors * together properly */ pipeline0 = create_two_layer_pipeline (); test_color (pipeline0, 0xffff00ff, pos++); cogl_object_unref (pipeline0); /** TEST 2 **/ /* Check that we can remove the second layer */ pipeline0 = create_two_layer_pipeline (); cogl_pipeline_remove_layer (pipeline0, 1); test_color (pipeline0, 0xff0000ff, pos++); cogl_object_unref (pipeline0); /** TEST 3 **/ /* Check that we can remove the first layer */ pipeline0 = create_two_layer_pipeline (); cogl_pipeline_remove_layer (pipeline0, 0); test_color (pipeline0, 0x00ff00ff, pos++); cogl_object_unref (pipeline0); /** TEST 4 **/ /* Check that we can make a copy and remove a layer from the * original pipeline */ pipeline0 = create_two_layer_pipeline (); pipeline1 = cogl_pipeline_copy (pipeline0); cogl_pipeline_remove_layer (pipeline0, 1); test_color (pipeline0, 0xff0000ff, pos++); test_color (pipeline1, 0xffff00ff, pos++); cogl_object_unref (pipeline0); cogl_object_unref (pipeline1); /** TEST 5 **/ /* Check that we can make a copy and remove the second layer from the * new pipeline */ pipeline0 = create_two_layer_pipeline (); pipeline1 = cogl_pipeline_copy (pipeline0); cogl_pipeline_remove_layer (pipeline1, 1); test_color (pipeline0, 0xffff00ff, pos++); test_color (pipeline1, 0xff0000ff, pos++); cogl_object_unref (pipeline0); cogl_object_unref (pipeline1); /** TEST 6 **/ /* Check that we can make a copy and remove the first layer from the * new pipeline */ pipeline0 = create_two_layer_pipeline (); pipeline1 = cogl_pipeline_copy (pipeline0); cogl_pipeline_remove_layer (pipeline1, 0); test_color (pipeline0, 0xffff00ff, pos++); test_color (pipeline1, 0x00ff00ff, pos++); cogl_object_unref (pipeline0); cogl_object_unref (pipeline1); /** TEST 7 **/ /* Check that we can modify a layer in a child pipeline */ pipeline0 = create_two_layer_pipeline (); pipeline1 = cogl_pipeline_copy (pipeline0); cogl_color_init_from_4ub (&color, 0, 0, 255, 255); cogl_pipeline_set_layer_combine_constant (pipeline1, 0, &color); test_color (pipeline0, 0xffff00ff, pos++); test_color (pipeline1, 0x00ffffff, pos++); cogl_object_unref (pipeline0); cogl_object_unref (pipeline1); /** TEST 8 **/ /* Check that we can modify a layer in a child pipeline but then remove it */ pipeline0 = create_two_layer_pipeline (); pipeline1 = cogl_pipeline_copy (pipeline0); cogl_color_init_from_4ub (&color, 0, 0, 255, 255); cogl_pipeline_set_layer_combine_constant (pipeline1, 0, &color); cogl_pipeline_remove_layer (pipeline1, 0); test_color (pipeline0, 0xffff00ff, pos++); test_color (pipeline1, 0x00ff00ff, pos++); cogl_object_unref (pipeline0); cogl_object_unref (pipeline1); if (cogl_test_verbose ()) g_print ("OK\n"); }