void test_alpha_test (void) { CoglTexture *tex = COGL_TEXTURE (create_texture (test_ctx)); CoglPipeline *pipeline = cogl_pipeline_new (test_ctx); int fb_width = cogl_framebuffer_get_width (test_fb); int fb_height = cogl_framebuffer_get_height (test_fb); CoglColor clear_color; cogl_pipeline_set_layer_texture (pipeline, 0, tex); cogl_pipeline_set_layer_filters (pipeline, 0, COGL_PIPELINE_FILTER_NEAREST, COGL_PIPELINE_FILTER_NEAREST); cogl_pipeline_set_alpha_test_function (pipeline, COGL_PIPELINE_ALPHA_FUNC_GEQUAL, 254 / 255.0f /* alpha reference */); cogl_color_init_from_4ub (&clear_color, 0x00, 0x00, 0xff, 0xff); cogl_framebuffer_clear (test_fb, COGL_BUFFER_BIT_COLOR, &clear_color); cogl_framebuffer_draw_rectangle (test_fb, pipeline, -1, -1, 1, 1); cogl_object_unref (pipeline); cogl_object_unref (tex); /* The left side of the framebuffer should use the first pixel from * the texture which is red */ test_utils_check_region (test_fb, 2, 2, fb_width / 2 - 4, fb_height - 4, 0xff0000ff); /* The right side of the framebuffer should use the clear color * because the second pixel from the texture is clipped from the * alpha test */ test_utils_check_region (test_fb, fb_width / 2 + 2, 2, fb_width / 2 - 4, fb_height - 4, 0x0000ffff); if (cogl_test_verbose ()) g_print ("OK\n"); }
static gboolean paint_cb (void *user_data) { CoglandCompositor *compositor = user_data; GList *l; for (l = compositor->outputs; l; l = l->next) { CoglandOutput *output = l->data; CoglFramebuffer *fb = COGL_FRAMEBUFFER (output->onscreen); GList *l2; cogl_push_framebuffer (fb); #if 0 cogl_framebuffer_clear (fb, COGL_BUFFER_BIT_COLOR); #else cogl_clear (&black, COGL_BUFFER_BIT_COLOR); #endif cogl_primitive_draw (compositor->triangle); for (l2 = compositor->surfaces; l2; l2 = l2->next) { CoglandSurface *surface = l2->data; if (surface->buffer) { CoglTexture2D *texture = surface->buffer->texture; cogl_set_source_texture (texture); cogl_rectangle (-1, 1, 1, -1); } wl_display_post_frame (compositor->wayland_display, &surface->wayland_surface, get_time ()); } cogl_framebuffer_swap_buffers (fb); cogl_pop_framebuffer (); } return TRUE; }
CoglPipeline * _st_create_shadow_pipeline_from_actor (StShadow *shadow_spec, ClutterActor *actor) { CoglPipeline *shadow_pipeline = NULL; if (CLUTTER_IS_TEXTURE (actor)) { CoglTexture *texture; texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (actor)); shadow_pipeline = _st_create_shadow_pipeline (shadow_spec, texture); } else { CoglTexture *buffer; CoglOffscreen *offscreen; CoglFramebuffer *fb; ClutterActorBox box; CoglColor clear_color; float width, height; CoglError *catch_error = NULL; clutter_actor_get_allocation_box (actor, &box); clutter_actor_box_get_size (&box, &width, &height); if (width == 0 || height == 0) return NULL; buffer = cogl_texture_new_with_size (width, height, COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_ANY); if (buffer == NULL) return NULL; offscreen = cogl_offscreen_new_with_texture (buffer); fb = COGL_FRAMEBUFFER (offscreen); if (!cogl_framebuffer_allocate (fb, &catch_error)) { cogl_error_free (catch_error); cogl_object_unref (buffer); return NULL; } cogl_color_init_from_4ub (&clear_color, 0, 0, 0, 0); /* XXX: There's no way to render a ClutterActor to an offscreen * as it uses the implicit API. */ G_GNUC_BEGIN_IGNORE_DEPRECATIONS; cogl_push_framebuffer (fb); G_GNUC_END_IGNORE_DEPRECATIONS; cogl_framebuffer_clear (fb, COGL_BUFFER_BIT_COLOR, &clear_color); cogl_framebuffer_translate (fb, -box.x1, -box.y1, 0); cogl_framebuffer_orthographic (fb, 0, 0, width, height, 0, 1.0); clutter_actor_set_opacity_override (actor, 255); clutter_actor_paint (actor); clutter_actor_set_opacity_override (actor, -1); G_GNUC_BEGIN_IGNORE_DEPRECATIONS; cogl_pop_framebuffer (); G_GNUC_END_IGNORE_DEPRECATIONS; cogl_object_unref (fb); shadow_pipeline = _st_create_shadow_pipeline (shadow_spec, buffer); cogl_object_unref (buffer); } return shadow_pipeline; }
/* XXX: it's expected that we'll deprecated this with * cogl_framebuffer_clear at some point. */ void cogl_clear (const CoglColor *color, unsigned long buffers) { cogl_framebuffer_clear (cogl_get_draw_framebuffer (), buffers, color); }