void test_wrap_rectangle_textures (void) { float fb_width = cogl_framebuffer_get_width (test_fb); float fb_height = cogl_framebuffer_get_height (test_fb); CoglPipeline *base_pipeline; CoglPipeline *clamp_pipeline; CoglPipeline *repeat_pipeline; /* The textures are drawn with the texture coordinates from * -0.5→1.5. That means we get one complete copy of the texture and * an extra half of the texture surrounding it. The drawing is * tested against a 4x4 grid of colors. The center 2x2 colours * specify the normal texture colors and the other colours specify * what the wrap mode should generate */ static const uint8_t clamp_colors[] = { 0x44, 0x44, 0x88, 0x88, 0x44, 0x44, 0x88, 0x88, 0xcc, 0xcc, 0xff, 0xff, 0xcc, 0xcc, 0xff, 0xff }; static const uint8_t repeat_colors[] = { 0xff, 0xcc, 0xff, 0xcc, 0x88, 0x44, 0x88, 0x44, 0xff, 0xcc, 0xff, 0xcc, 0x88, 0x44, 0x88, 0x44 }; cogl_framebuffer_orthographic (test_fb, 0, 0, /* x_1, y_1 */ fb_width, /* x_2 */ fb_height /* y_2 */, -1, 100 /* near/far */); base_pipeline = create_base_pipeline (); clamp_pipeline = cogl_pipeline_copy (base_pipeline); cogl_pipeline_set_layer_wrap_mode (clamp_pipeline, 0, /* layer */ COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE); repeat_pipeline = cogl_pipeline_copy (base_pipeline); cogl_pipeline_set_layer_wrap_mode (repeat_pipeline, 0, /* layer */ COGL_PIPELINE_WRAP_MODE_REPEAT); test_pipeline (clamp_pipeline, 0, 0, /* x/y offset */ clamp_colors); test_pipeline (repeat_pipeline, 0, DRAW_SIZE * 2, /* x/y offset */ repeat_colors); cogl_object_unref (repeat_pipeline); cogl_object_unref (clamp_pipeline); cogl_object_unref (base_pipeline); }
/*< private > * _clutter_paint_node_init_types: * * Initializes the required types for ClutterPaintNode subclasses */ void _clutter_paint_node_init_types (void) { CoglContext *ctx; CoglColor cogl_color; GType node_type G_GNUC_UNUSED; if (G_LIKELY (default_color_pipeline != NULL)) return; ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ()); node_type = clutter_paint_node_get_type (); cogl_color_init_from_4f (&cogl_color, 1.0, 1.0, 1.0, 1.0); default_color_pipeline = cogl_pipeline_new (ctx); cogl_pipeline_set_color (default_color_pipeline, &cogl_color); default_texture_pipeline = cogl_pipeline_new (ctx); cogl_pipeline_set_layer_null_texture (default_texture_pipeline, 0, COGL_TEXTURE_TYPE_2D); cogl_pipeline_set_color (default_texture_pipeline, &cogl_color); cogl_pipeline_set_layer_wrap_mode (default_texture_pipeline, 0, COGL_PIPELINE_WRAP_MODE_AUTOMATIC); }
static CoglPipeline * get_base_texture_rgba_pipeline (CoglPangoPipelineCache *cache) { if (cache->base_texture_rgba_pipeline == NULL) { CoglPipeline *pipeline; pipeline = cache->base_texture_rgba_pipeline = cogl_pipeline_new (); cogl_pipeline_set_layer_wrap_mode (pipeline, 0, COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE); if (cache->use_mipmapping) cogl_pipeline_set_layer_filters (pipeline, 0, COGL_PIPELINE_FILTER_LINEAR_MIPMAP_LINEAR, COGL_PIPELINE_FILTER_LINEAR); } return cache->base_texture_rgba_pipeline; }
static void create_pipeline (CoglTexture **tex_out, CoglPipeline **pipeline_out) { CoglTexture2D *tex; CoglPipeline *pipeline; static const uint8_t tex_data[] = { 0x00, 0x44, 0x88, 0xcc }; tex = cogl_texture_2d_new_from_data (test_ctx, 2, 2, /* width/height */ COGL_PIXEL_FORMAT_A_8, /* format */ COGL_PIXEL_FORMAT_ANY, /* int. format */ 2, /* rowstride */ tex_data, NULL); pipeline = cogl_pipeline_new (test_ctx); cogl_pipeline_set_layer_filters (pipeline, 0, /* layer */ COGL_PIPELINE_FILTER_NEAREST, COGL_PIPELINE_FILTER_NEAREST); cogl_pipeline_set_layer_wrap_mode (pipeline, 0, /* layer */ COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE); /* This is the layer combine used by cogl-pango */ cogl_pipeline_set_layer_combine (pipeline, 0, /* layer */ "RGBA = MODULATE (PREVIOUS, TEXTURE[A])", NULL); cogl_pipeline_set_layer_texture (pipeline, 0, /* layer */ COGL_TEXTURE (tex)); *pipeline_out = pipeline; *tex_out = COGL_TEXTURE (tex); }
static void st_background_effect_init (StBackgroundEffect *self) { CoglContext *ctx; StBackgroundEffectClass *klass = ST_BACKGROUND_EFFECT_GET_CLASS (self); if (G_UNLIKELY (klass->base_pipeline == NULL)) { ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ()); klass->base_pipeline = cogl_pipeline_new (ctx); } self->pipeline0 = cogl_pipeline_copy (klass->base_pipeline); self->pipeline1 = cogl_pipeline_copy (klass->base_pipeline); self->pipeline2 = cogl_pipeline_copy (klass->base_pipeline); self->pipeline3 = cogl_pipeline_copy (klass->base_pipeline); self->pipeline4 = cogl_pipeline_copy (klass->base_pipeline); CoglSnippet *snippet; snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_TEXTURE_LOOKUP, box_blur_glsl_declarations, NULL); cogl_snippet_set_replace (snippet, box_blur_glsl_shader); cogl_pipeline_add_layer_snippet (self->pipeline0, 0, snippet); cogl_pipeline_add_layer_snippet (self->pipeline1, 0, snippet); cogl_pipeline_add_layer_snippet (self->pipeline3, 0, snippet); cogl_object_unref (snippet); cogl_pipeline_set_layer_wrap_mode (self->pipeline0, 0, COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE); cogl_pipeline_set_layer_wrap_mode (self->pipeline0, 1, COGL_PIPELINE_WRAP_MODE_REPEAT); cogl_pipeline_set_layer_wrap_mode (self->pipeline1, 0, COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE); cogl_pipeline_set_layer_wrap_mode (self->pipeline2, 0, COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE); cogl_pipeline_set_layer_wrap_mode (self->pipeline3, 0, COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE); cogl_pipeline_set_layer_wrap_mode (self->pipeline4, 0, COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE); cogl_pipeline_set_cull_face_mode (self->pipeline0, COGL_PIPELINE_CULL_FACE_MODE_NONE); cogl_pipeline_set_cull_face_mode (self->pipeline1, COGL_PIPELINE_CULL_FACE_MODE_NONE); cogl_pipeline_set_cull_face_mode (self->pipeline2, COGL_PIPELINE_CULL_FACE_MODE_NONE); cogl_pipeline_set_cull_face_mode (self->pipeline3, COGL_PIPELINE_CULL_FACE_MODE_NONE); cogl_pipeline_set_cull_face_mode (self->pipeline4, COGL_PIPELINE_CULL_FACE_MODE_NONE); cogl_pipeline_set_layer_filters (self->pipeline0, 0, COGL_PIPELINE_FILTER_LINEAR, COGL_PIPELINE_FILTER_LINEAR); cogl_pipeline_set_layer_filters (self->pipeline0, 1, COGL_PIPELINE_FILTER_NEAREST, COGL_PIPELINE_FILTER_NEAREST); cogl_pipeline_set_layer_filters (self->pipeline1, 0, COGL_PIPELINE_FILTER_LINEAR, COGL_PIPELINE_FILTER_LINEAR); cogl_pipeline_set_layer_filters (self->pipeline2, 0, COGL_PIPELINE_FILTER_LINEAR, COGL_PIPELINE_FILTER_LINEAR); cogl_pipeline_set_layer_filters (self->pipeline3, 0, COGL_PIPELINE_FILTER_LINEAR, COGL_PIPELINE_FILTER_LINEAR); cogl_pipeline_set_layer_filters (self->pipeline4, 0, COGL_PIPELINE_FILTER_LINEAR, COGL_PIPELINE_FILTER_LINEAR); cogl_pipeline_set_layer_null_texture (self->pipeline0, 0, COGL_TEXTURE_TYPE_2D); cogl_pipeline_set_layer_null_texture (self->pipeline1, 0, COGL_TEXTURE_TYPE_2D); cogl_pipeline_set_layer_null_texture (self->pipeline2, 0, COGL_TEXTURE_TYPE_2D); cogl_pipeline_set_layer_null_texture (self->pipeline3, 0, COGL_TEXTURE_TYPE_2D); cogl_pipeline_set_layer_null_texture (self->pipeline4, 0, COGL_TEXTURE_TYPE_2D); self->pixel_step_uniform0 = cogl_pipeline_get_uniform_location (self->pipeline0, "pixel_step"); self->BumpTex_uniform = cogl_pipeline_get_uniform_location (self->pipeline0, "BumpTex"); self->bump_step_uniform = cogl_pipeline_get_uniform_location (self->pipeline0, "bump_step"); self->pixel_step_uniform1 = cogl_pipeline_get_uniform_location (self->pipeline1, "pixel_step"); self->pixel_step_uniform2 = cogl_pipeline_get_uniform_location (self->pipeline3, "pixel_step"); cogl_pipeline_set_blend (self->pipeline0, "RGBA = ADD(SRC_COLOR, DST_COLOR*0)", NULL); cogl_pipeline_set_blend (self->pipeline1, "RGBA = ADD (SRC_COLOR*DST_COLOR[A], DST_COLOR*(1-DST_COLOR[A]))", NULL); cogl_pipeline_set_color4ub (self->pipeline1, 0xff, 0xff, 0xff, 0xff); cogl_pipeline_set_alpha_test_function (self->pipeline2, COGL_PIPELINE_ALPHA_FUNC_LESS, 0.004f); cogl_pipeline_set_color_mask (self->pipeline2, COGL_COLOR_MASK_ALPHA); cogl_pipeline_set_blend (self->pipeline2, "RGBA = ADD(SRC_COLOR, DST_COLOR*0)", NULL); cogl_pipeline_set_alpha_test_function (self->pipeline3, COGL_PIPELINE_ALPHA_FUNC_GEQUAL, 0.004f); cogl_pipeline_set_color_mask (self->pipeline3, COGL_COLOR_MASK_ALL); cogl_pipeline_set_blend (self->pipeline3, "RGBA = ADD (SRC_COLOR, DST_COLOR*(1-SRC_COLOR[A]))", NULL); cogl_pipeline_set_alpha_test_function (self->pipeline4, COGL_PIPELINE_ALPHA_FUNC_GEQUAL, 0.004f); cogl_pipeline_set_color_mask (self->pipeline4, COGL_COLOR_MASK_ALL); cogl_pipeline_set_blend (self->pipeline4, "RGBA = ADD (SRC_COLOR, DST_COLOR*(1-SRC_COLOR[A]))", NULL); self->bg_texture = NULL; self->bg_sub_texture = NULL; self->bumpmap_location = "/usr/share/cinnamon/bumpmaps/frost.png"; self->bg_bumpmap = st_cogl_texture_new_from_file_wrapper (self->bumpmap_location, COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_RGBA_8888_PRE); if (self->bg_bumpmap != NULL) { self->bumptex_width_i = cogl_texture_get_width (self->bg_bumpmap); self->bumptex_height_i = cogl_texture_get_height (self->bg_bumpmap); cogl_pipeline_set_layer_texture (self->pipeline0, 1, self->bg_bumpmap); } else { cogl_pipeline_set_layer_null_texture (self->pipeline0, 1, COGL_TEXTURE_TYPE_2D); } cogl_pipeline_set_layer_combine (self->pipeline0,1, "RGBA = REPLACE (PREVIOUS)", NULL); self->old_time = 0; self->opacity = 0; }
static CoglPipeline * create_1d_gaussian_blur_pipeline (RutContext *ctx, int n_taps) { static GHashTable *pipeline_cache = NULL; CoglPipeline *pipeline; CoglSnippet *snippet; GString *shader; CoglDepthState depth_state; int i; /* initialize the pipeline cache. The shaders are only dependent on the * number of taps, not the sigma, so we cache the corresponding pipelines * in a hash table 'n_taps' => 'pipeline' */ if (G_UNLIKELY (pipeline_cache == NULL)) { pipeline_cache = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, /* key destroy notify */ (GDestroyNotify) cogl_object_unref); } pipeline = g_hash_table_lookup (pipeline_cache, GINT_TO_POINTER (n_taps)); if (pipeline) return cogl_object_ref (pipeline); shader = g_string_new (NULL); g_string_append_printf (shader, "uniform vec2 pixel_step;\n" "uniform float factors[%i];\n", n_taps); snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_TEXTURE_LOOKUP, shader->str, NULL /* post */); g_string_set_size (shader, 0); pipeline = cogl_pipeline_new (ctx->cogl_context); cogl_pipeline_set_layer_null_texture (pipeline, 0, /* layer_num */ COGL_TEXTURE_TYPE_2D); cogl_pipeline_set_layer_wrap_mode (pipeline, 0, /* layer_num */ COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE); cogl_pipeline_set_layer_filters (pipeline, 0, /* layer_num */ COGL_PIPELINE_FILTER_NEAREST, COGL_PIPELINE_FILTER_NEAREST); for (i = 0; i < n_taps; i++) { g_string_append (shader, "cogl_texel "); if (i == 0) g_string_append (shader, "="); else g_string_append (shader, "+="); g_string_append_printf (shader, " texture2D (cogl_sampler, " "cogl_tex_coord.st"); if (i != (n_taps - 1) / 2) g_string_append_printf (shader, " + pixel_step * %f", (float) (i - ((n_taps - 1) / 2))); g_string_append_printf (shader, ") * factors[%i];\n", i); } cogl_snippet_set_replace (snippet, shader->str); g_string_free (shader, TRUE); cogl_pipeline_add_layer_snippet (pipeline, 0, snippet); cogl_object_unref (snippet); cogl_pipeline_set_blend (pipeline, "RGBA=ADD(SRC_COLOR, 0)", NULL); cogl_depth_state_init (&depth_state); cogl_depth_state_set_write_enabled (&depth_state, FALSE); cogl_depth_state_set_test_enabled (&depth_state, FALSE); cogl_pipeline_set_depth_state (pipeline, &depth_state, NULL); g_hash_table_insert (pipeline_cache, GINT_TO_POINTER (n_taps), pipeline); return pipeline; }
void test_map_buffer_range (void) { CoglTexture2D *tex; CoglPipeline *pipeline; int fb_width, fb_height; CoglAttributeBuffer *buffer; CoglVertexP2T2 *data; CoglAttribute *pos_attribute; CoglAttribute *tex_coord_attribute; CoglPrimitive *primitive; tex = cogl_texture_2d_new_from_data (test_ctx, 2, 2, /* width/height */ COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_ANY, 2 * 4, /* rowstride */ tex_data, NULL /* error */); pipeline = cogl_pipeline_new (test_ctx); cogl_pipeline_set_layer_texture (pipeline, 0, COGL_TEXTURE (tex)); cogl_pipeline_set_layer_filters (pipeline, 0, /* layer */ COGL_PIPELINE_FILTER_NEAREST, COGL_PIPELINE_FILTER_NEAREST); cogl_pipeline_set_layer_wrap_mode (pipeline, 0, /* layer */ COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE); fb_width = cogl_framebuffer_get_width (test_fb); fb_height = cogl_framebuffer_get_height (test_fb); buffer = cogl_attribute_buffer_new (test_ctx, sizeof (vertex_data), vertex_data); /* Replace the texture coordinates of the third vertex with the * coordinates for a green texel */ data = cogl_buffer_map_range (COGL_BUFFER (buffer), sizeof (vertex_data[0]) * 2, sizeof (vertex_data[0]), COGL_BUFFER_ACCESS_WRITE, COGL_BUFFER_MAP_HINT_DISCARD_RANGE, NULL); /* don't catch errors */ g_assert (data != NULL); data->x = vertex_data[2].x; data->y = vertex_data[2].y; data->s = 1.0f; data->t = 0.0f; cogl_buffer_unmap (COGL_BUFFER (buffer)); pos_attribute = cogl_attribute_new (buffer, "cogl_position_in", sizeof (vertex_data[0]), offsetof (CoglVertexP2T2, x), 2, /* n_components */ COGL_ATTRIBUTE_TYPE_FLOAT); tex_coord_attribute = cogl_attribute_new (buffer, "cogl_tex_coord_in", sizeof (vertex_data[0]), offsetof (CoglVertexP2T2, s), 2, /* n_components */ COGL_ATTRIBUTE_TYPE_FLOAT); cogl_framebuffer_clear4f (test_fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1); primitive = cogl_primitive_new (COGL_VERTICES_MODE_TRIANGLE_STRIP, 4, /* n_vertices */ pos_attribute, tex_coord_attribute, NULL); cogl_primitive_draw (primitive, test_fb, pipeline); cogl_object_unref (primitive); /* Top left pixel should be the one that is replaced to be green */ test_utils_check_pixel (test_fb, 1, 1, 0x00ff00ff); /* The other three corners should be left as red */ test_utils_check_pixel (test_fb, fb_width - 2, 1, 0xff0000ff); test_utils_check_pixel (test_fb, 1, fb_height - 2, 0xff0000ff); test_utils_check_pixel (test_fb, fb_width - 2, fb_height - 2, 0xff0000ff); cogl_object_unref (buffer); cogl_object_unref (pos_attribute); cogl_object_unref (tex_coord_attribute); cogl_object_unref (pipeline); cogl_object_unref (tex); if (cogl_test_verbose ()) g_print ("OK\n"); }