示例#1
0
/*< 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);
}
示例#2
0
static void
paint (TestState *state)
{
  CoglPipeline *white = cogl_pipeline_new (test_ctx);
  int i;

  cogl_pipeline_set_color4f (white, 1, 1, 1, 1);


  cogl_framebuffer_draw_rectangle (state->fbo[0],
                                   white,
                                   -1.0, -1.0, 1.0, 1.0);

  cogl_framebuffer_draw_rectangle (state->fbo[1],
                                   white,
                                   -1.0, -1.0, 1.0, 1.0);

  cogl_framebuffer_draw_rectangle (state->fbo[2],
                                   white,
                                   -1.0, -1.0, 1.0, 1.0);

  cogl_object_unref (white);

  cogl_framebuffer_clear4f (test_fb,
                            COGL_BUFFER_BIT_COLOR | COGL_BUFFER_BIT_DEPTH,
                            0.5, 0.5, 0.5, 1.0);

  /* Render all of the textures to the screen */
  for (i = 0; i < NUM_FBOS; i++)
    {
      CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
      cogl_pipeline_set_layer_texture (pipeline, 0, state->tex[i]);
      cogl_framebuffer_draw_rectangle (test_fb, pipeline,
                                       2.0f / NUM_FBOS * i - 1.0f, -1.0f,
                                       2.0f / NUM_FBOS * (i + 1) - 1.0f, 1.0f);
      cogl_object_unref (pipeline);
    }

  /* Verify all of the fbos drew the right color */
  for (i = 0; i < NUM_FBOS; i++)
    {
      uint8_t expected_colors[NUM_FBOS][4] =
        { { 0xff, 0x00, 0x00, 0xff },
          { 0x00, 0xff, 0x00, 0xff },
          { 0x00, 0x00, 0xff, 0xff } };

      test_utils_check_pixel_rgb (test_fb,
                                  state->width * (i + 0.5f) / NUM_FBOS,
                                  state->height / 2,
                                  expected_colors[i][0],
                                  expected_colors[i][1],
                                  expected_colors[i][2]);
    }
}
示例#3
0
bool ImGui_ImplGtk3Cogl_CreateDeviceObjects()
{
    g_ColorPipeline = cogl_pipeline_new(g_Context);
    g_ImagePipeline = cogl_pipeline_new(g_Context);

    CoglError *error = NULL;
    if (!cogl_pipeline_set_blend(g_ColorPipeline,
                                 "RGB = ADD(SRC_COLOR*(SRC_COLOR[A]), DST_COLOR*(1-SRC_COLOR[A]))"
                                 "A = ADD(SRC_COLOR[A], DST_COLOR*(1-SRC_COLOR[A]))",
                                 &error))
    {
        g_warning("Blending: %s", error->message);
        g_error_free(error);
        return false;
    }
    cogl_pipeline_set_cull_face_mode(g_ColorPipeline, COGL_PIPELINE_CULL_FACE_MODE_NONE);

    CoglDepthState depth_state;

    cogl_depth_state_init(&depth_state);
    cogl_depth_state_set_test_enabled(&depth_state, FALSE);
    if (!cogl_pipeline_set_depth_state(g_ColorPipeline, &depth_state, &error))
    {
        g_warning("Depth: %s", error->message);
        g_error_free(error);
        return false;
    }

    if (!cogl_pipeline_set_blend(g_ImagePipeline,
                                 "RGB = ADD(SRC_COLOR*(SRC_COLOR[A]), DST_COLOR*(1-SRC_COLOR[A]))"
                                 "A = ADD(SRC_COLOR[A], DST_COLOR*(1-SRC_COLOR[A]))",
                                 &error))
    {
        g_warning("Blending: %s", error->message);
        g_error_free(error);
        return false;
    }
    cogl_pipeline_set_cull_face_mode(g_ImagePipeline, COGL_PIPELINE_CULL_FACE_MODE_NONE);

    if (!cogl_pipeline_set_depth_state(g_ImagePipeline, &depth_state, &error))
    {
        g_warning("Depth: %s", error->message);
        g_error_free(error);
        return false;
    }

    ImGui_ImplGtk3Cogl_CreateFontsTexture();

    /* Disable depth buffer since we're not using it. */
    //cogl_framebuffer_set_depth_write_enabled(g_Framebuffer, FALSE);

    return true;
}
示例#4
0
static void
paint_scene (RigPaintContext *paint_ctx)
{
  RutPaintContext *rut_paint_ctx = &paint_ctx->_parent;
  RigEngine *engine = paint_ctx->engine;
  CoglContext *ctx = engine->ctx->cogl_context;
  CoglFramebuffer *fb = rut_camera_get_framebuffer (rut_paint_ctx->camera);

  if (paint_ctx->pass == RIG_PASS_COLOR_UNBLENDED)
    {
      CoglPipeline *pipeline = cogl_pipeline_new (ctx);
      cogl_pipeline_set_color4f (pipeline,
                                 engine->background_color.red,
                                 engine->background_color.green,
                                 engine->background_color.blue,
                                 engine->background_color.alpha);
      cogl_framebuffer_draw_rectangle (fb,
                                       pipeline,
                                       0, 0,
                                       engine->device_width, engine->device_height);
                                       //0, 0, engine->pane_width, engine->pane_height);
      cogl_object_unref (pipeline);
    }

  rut_graphable_traverse (engine->scene,
                          RUT_TRAVERSE_DEPTH_FIRST,
                          entitygraph_pre_paint_cb,
                          entitygraph_post_paint_cb,
                          paint_ctx);

  rig_journal_flush (engine->journal, paint_ctx);
}
示例#5
0
void
test_path_clip (void)
{
  CoglPath *path;
  CoglPipeline *pipeline;
  int fb_width, fb_height;

  fb_width = cogl_framebuffer_get_width (test_fb);
  fb_height = cogl_framebuffer_get_height (test_fb);

  cogl_framebuffer_orthographic (test_fb,
                                 0, 0, fb_width, fb_height, -1, 100);

  path = cogl_path_new ();

  cogl_framebuffer_clear4f (test_fb,
                            COGL_BUFFER_BIT_COLOR,
                            1.0f, 0.0f, 0.0f, 1.0f);

  /* Make an L-shape with the top right corner left untouched */
  cogl_path_move_to (path, 0, fb_height);
  cogl_path_line_to (path, fb_width, fb_height);
  cogl_path_line_to (path, fb_width, fb_height / 2);
  cogl_path_line_to (path, fb_width / 2, fb_height / 2);
  cogl_path_line_to (path, fb_width / 2, 0);
  cogl_path_line_to (path, 0, 0);
  cogl_path_close (path);

  cogl_framebuffer_push_path_clip (test_fb, path);

  /* Try to fill the framebuffer with a blue rectangle. This should be
   * clipped to leave the top right quadrant as is */
  pipeline = cogl_pipeline_new (test_ctx);
  cogl_pipeline_set_color4ub (pipeline, 0, 0, 255, 255);
  cogl_framebuffer_draw_rectangle (test_fb,
                                   pipeline,
                                   0, 0, fb_width, fb_height);

  cogl_framebuffer_pop_clip (test_fb);

  cogl_object_unref (pipeline);
  cogl_object_unref (path);

  /* Check each of the four quadrants */
  test_utils_check_pixel (test_fb,
                          fb_width / 4, fb_height / 4,
                          0x0000ffff);
  test_utils_check_pixel (test_fb,
                          fb_width * 3 / 4, fb_height / 4,
                          0xff0000ff);
  test_utils_check_pixel (test_fb,
                          fb_width / 4, fb_height * 3 / 4,
                          0x0000ffff);
  test_utils_check_pixel (test_fb,
                          fb_width * 3 / 4, fb_height * 3 / 4,
                          0x0000ffff);

  if (cogl_test_verbose ())
    g_print ("OK\n");
}
示例#6
0
RigSelectionTool *
rig_selection_tool_new (RigCameraView *view,
                        RutObject *overlay)
{
  RigSelectionTool *tool = g_slice_new0 (RigSelectionTool);
  RutContext *ctx = view->context;

  tool->view = view;
  tool->ctx = ctx;

  /* Note: we don't take a reference on this overlay to avoid creating
   * a circular reference. */
  tool->tool_overlay = overlay;

  tool->camera = view->view_camera;
  tool->camera_component =
    rut_entity_get_component (tool->camera, RUT_COMPONENT_TYPE_CAMERA);

  rut_list_init (&tool->selection_event_cb_list);

  /* pipeline to draw the tool */
  tool->default_pipeline = cogl_pipeline_new (rut_cogl_context);

  return tool;
}
void
test_custom_attributes (void)
{
  /* If shaders aren't supported then we can't run the test */
  if (cogl_has_feature (test_ctx, COGL_FEATURE_ID_GLSL))
    {
      CoglSnippet *snippet;
      TestState state;

      cogl_framebuffer_orthographic (test_fb,
                                     0, 0,
                                     cogl_framebuffer_get_width (test_fb),
                                     cogl_framebuffer_get_height (test_fb),
                                     -1,
                                     100);

      state.pipeline = cogl_pipeline_new (test_ctx);
      snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_VERTEX,
                                  "attribute vec4 color;",
                                  "cogl_color_out = color;");
      cogl_pipeline_add_snippet (state.pipeline, snippet);

      paint (&state);

      cogl_object_unref (state.pipeline);
      cogl_object_unref (snippet);

      if (cogl_test_verbose ())
        g_print ("OK\n");
    }
  else if (cogl_test_verbose ())
    g_print ("Skipping\n");
}
示例#8
0
文件: rut-rectangle.c 项目: cee1/rig
RutRectangle *
rut_rectangle_new4f (RutContext *ctx,
                     float width,
                     float height,
                     float red,
                     float green,
                     float blue,
                     float alpha)
{
  RutRectangle *rectangle = g_slice_new0 (RutRectangle);
  static CoglBool initialized = FALSE;

  if (initialized == FALSE)
    {
      _rut_rectangle_init_type ();
      initialized = TRUE;
    }

  rut_object_init (&rectangle->_parent, &rut_rectangle_type);

  rectangle->ref_count = 1;

  rut_graphable_init (rectangle);
  rut_paintable_init (rectangle);

  rectangle->width = width;
  rectangle->height = height;

  rectangle->pipeline = cogl_pipeline_new (ctx->cogl_context);
  cogl_pipeline_set_color4f (rectangle->pipeline,
                             red, green, blue, alpha);

  return rectangle;
}
示例#9
0
static CoglPipeline *
create_two_layer_pipeline (void)
{
  CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
  CoglColor color;

  /* The pipeline is initially black */
  cogl_pipeline_set_color4ub (pipeline, 0, 0, 0, 255);

  /* The first layer adds a full red component */
  cogl_color_init_from_4ub (&color, 255, 0, 0, 255);
  cogl_pipeline_set_layer_combine_constant (pipeline, 0, &color);
  cogl_pipeline_set_layer_combine (pipeline,
                                   0, /* layer_num */
                                   "RGBA=ADD(PREVIOUS,CONSTANT)",
                                   NULL);

  /* The second layer adds a full green component */
  cogl_color_init_from_4ub (&color, 0, 255, 0, 255);
  cogl_pipeline_set_layer_combine_constant (pipeline, 1, &color);
  cogl_pipeline_set_layer_combine (pipeline,
                                   1, /* layer_num */
                                   "RGBA=ADD(PREVIOUS,CONSTANT)",
                                   NULL);

  return pipeline;
}
示例#10
0
static void
meta_overlay_init (MetaOverlay *overlay)
{
  CoglContext *ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());

  overlay->pipeline = cogl_pipeline_new (ctx);
}
示例#11
0
CoglPipeline *
cogl_gst_video_sink_get_pipeline (CoglGstVideoSink *vt)
{
  CoglGstVideoSinkPrivate *priv;

  g_return_val_if_fail (COGL_GST_IS_VIDEO_SINK (vt), NULL);

  priv = vt->priv;

  if (priv->pipeline == NULL)
    {
      priv->pipeline = cogl_pipeline_new (priv->ctx);
      cogl_gst_video_sink_setup_pipeline (vt, priv->pipeline);
      cogl_gst_video_sink_attach_frame (vt, priv->pipeline);
      priv->frame_dirty = FALSE;
    }
  else if (priv->frame_dirty)
    {
      CoglPipeline *pipeline = cogl_pipeline_copy (priv->pipeline);
      cogl_object_unref (priv->pipeline);
      priv->pipeline = pipeline;

      cogl_gst_video_sink_attach_frame (vt, pipeline);
      priv->frame_dirty = FALSE;
    }

  return priv->pipeline;
}
示例#12
0
void
test_custom_attributes (void)
{
  CoglSnippet *snippet;
  TestState state;

  cogl_framebuffer_orthographic (test_fb,
                                 0, 0,
                                 cogl_framebuffer_get_width (test_fb),
                                 cogl_framebuffer_get_height (test_fb),
                                 -1,
                                 100);

  state.pipeline = cogl_pipeline_new (test_ctx);
  snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_VERTEX,
                              "attribute vec4 color;",
                              "cogl_color_out = color;");
  cogl_pipeline_add_snippet (state.pipeline, snippet);

  paint (&state);

  cogl_object_unref (state.pipeline);
  cogl_object_unref (snippet);

  if (cogl_test_verbose ())
    g_print ("OK\n");
}
示例#13
0
CoglPipeline *
_st_create_shadow_pipeline (StShadow    *shadow_spec,
                            CoglTexture *src_texture)
{
    ClutterBackend *backend = clutter_get_default_backend ();
    CoglContext *ctx = clutter_backend_get_cogl_context (backend);

    static CoglPipeline *shadow_pipeline_template = NULL;

    CoglPipeline *pipeline;
    CoglTexture *texture;
    guchar *pixels_in, *pixels_out;
    gint width_in, height_in, rowstride_in;
    gint width_out, height_out, rowstride_out;

    g_return_val_if_fail (shadow_spec != NULL, NULL);
    g_return_val_if_fail (src_texture != NULL, NULL);

    width_in  = cogl_texture_get_width  (src_texture);
    height_in = cogl_texture_get_height (src_texture);
    rowstride_in = (width_in + 3) & ~3;

    pixels_in  = g_malloc0 (rowstride_in * height_in);

    cogl_texture_get_data (src_texture, COGL_PIXEL_FORMAT_A_8,
                           rowstride_in, pixels_in);

    pixels_out = blur_pixels (pixels_in, width_in, height_in, rowstride_in,
                              shadow_spec->blur,
                              &width_out, &height_out, &rowstride_out);
    g_free (pixels_in);

    texture = COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx, width_out, height_out,
                            COGL_PIXEL_FORMAT_A_8,
                            rowstride_out,
                            pixels_out,
                            NULL));

    g_free (pixels_out);

    if (G_UNLIKELY (shadow_pipeline_template == NULL))
    {
        CoglContext *ctx =
            clutter_backend_get_cogl_context (clutter_get_default_backend ());

        shadow_pipeline_template = cogl_pipeline_new (ctx);

        /* We set up the pipeline to blend the shadow texture with the combine
         * constant, but defer setting the latter until painting, so that we can
         * take the actor's overall opacity into account. */
        cogl_pipeline_set_layer_combine (shadow_pipeline_template, 0,
                                         "RGBA = MODULATE (CONSTANT, TEXTURE[A])",
                                         NULL);
    }

    pipeline = cogl_pipeline_copy (shadow_pipeline_template);
    cogl_pipeline_set_layer_texture (pipeline, 0, texture);
    cogl_object_unref (texture);
    return pipeline;
}
static void
shell_anamorphosis_effect_init (ShellAnamorphosisEffect *self)
{
  static CoglPipeline *pipeline_template;

  ShellAnamorphosisEffectPrivate *priv = shell_anamorphosis_effect_get_instance_private (self);

  if (G_UNLIKELY (pipeline_template == NULL))
    {
      CoglSnippet *snippet;
      CoglContext *ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());

      pipeline_template = cogl_pipeline_new (ctx);

      snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_TEXTURE_LOOKUP, anamorphosis_decls, NULL);
      cogl_snippet_set_pre (snippet, anamorphosis_pre);
      cogl_pipeline_add_layer_snippet (pipeline_template, 0, snippet);
      cogl_object_unref (snippet);

      cogl_pipeline_set_layer_null_texture (pipeline_template,
                                            0, /* layer number */
                                            COGL_TEXTURE_TYPE_2D);
    }

  priv->pipeline = cogl_pipeline_copy (pipeline_template);
  priv->tex_width_uniform = cogl_pipeline_get_uniform_location (priv->pipeline, "tex_width");
  priv->tex_height_uniform = cogl_pipeline_get_uniform_location (priv->pipeline, "tex_height");
  priv->_x_uniform = cogl_pipeline_get_uniform_location (priv->pipeline, "_x");
  priv->_y_uniform = cogl_pipeline_get_uniform_location (priv->pipeline, "_y");
  priv->_z_uniform = cogl_pipeline_get_uniform_location (priv->pipeline, "_z");

  update_uniforms (self);
}
示例#15
0
static void
clutter_colorize_effect_init (ClutterColorizeEffect *self)
{
  ClutterColorizeEffectClass *klass = CLUTTER_COLORIZE_EFFECT_GET_CLASS (self);

  if (G_UNLIKELY (klass->base_pipeline == NULL))
    {
      CoglSnippet *snippet;
      CoglContext *ctx =
        clutter_backend_get_cogl_context (clutter_get_default_backend ());

      klass->base_pipeline = cogl_pipeline_new (ctx);

      snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
                                  colorize_glsl_declarations,
                                  colorize_glsl_source);
      cogl_pipeline_add_snippet (klass->base_pipeline, snippet);
      cogl_object_unref (snippet);

      cogl_pipeline_set_layer_null_texture (klass->base_pipeline, 0);
    }

  self->pipeline = cogl_pipeline_copy (klass->base_pipeline);

  self->tint_uniform =
    cogl_pipeline_get_uniform_location (self->pipeline, "tint");

  self->tint = default_tint;

  update_tint_uniform (self);
}
示例#16
0
static void
paint (TestState *state)
{
  CoglPipeline *pipeline;

  paint_test_backface_culling (state, test_fb);

  /*
   * Now repeat the test but rendered to an offscreen
   * framebuffer. Note that by default the conformance tests are
   * always run to an offscreen buffer but we might as well have this
   * check anyway in case it is being run with COGL_TEST_ONSCREEN=1
   */
  paint_test_backface_culling (state, state->offscreen);

  /* Copy the result of the offscreen rendering for validation and
   * also so we can have visual feedback. */
  pipeline = cogl_pipeline_new (test_ctx);
  cogl_pipeline_set_layer_texture (pipeline, 0, state->offscreen_tex);
  cogl_framebuffer_draw_rectangle (test_fb,
                                   pipeline,
                                   0, TEXTURE_RENDER_SIZE * 16,
                                   state->width,
                                   state->height + TEXTURE_RENDER_SIZE * 16);
  cogl_object_unref (pipeline);

  validate_result (test_fb, 0);
  validate_result (test_fb, 16);
}
示例#17
0
static void
create_pipelines (CoglPipeline **pipelines,
                  int n_pipelines)
{
  int i;

  for (i = 0; i < n_pipelines; i++)
    {
      char *source = g_strdup_printf ("  cogl_color_out = "
                                      "vec4 (%f, 0.0, 0.0, 1.0);\n",
                                      i / 255.0f);
      CoglSnippet *snippet =
        cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
                          NULL, /* declarations */
                          source);

      g_free (source);

      pipelines[i] = cogl_pipeline_new (test_ctx);
      cogl_pipeline_add_snippet (pipelines[i], snippet);
      cogl_object_unref (snippet);
    }

  /* Test that drawing with them works. This should create the entries
   * in the cache */
  for (i = 0; i < n_pipelines; i++)
    {
      cogl_framebuffer_draw_rectangle (test_fb,
                                       pipelines[i],
                                       i, 0,
                                       i + 1, 1);
      test_utils_check_pixel_rgb (test_fb, i, 0, i, 0, 0);
    }

}
示例#18
0
static void
create_gles2_context (CoglTexture **offscreen_texture,
                      CoglOffscreen **offscreen,
                      CoglPipeline **pipeline,
                      CoglGLES2Context **gles2_ctx,
                      const CoglGLES2Vtable **gles2)
{
  GError *error = NULL;

  *offscreen_texture = COGL_TEXTURE (
    cogl_texture_2d_new_with_size (test_ctx,
                                   cogl_framebuffer_get_width (test_fb),
                                   cogl_framebuffer_get_height (test_fb),
                                   COGL_PIXEL_FORMAT_ANY,
                                   NULL));
  *offscreen = cogl_offscreen_new_to_texture (*offscreen_texture);

  *pipeline = cogl_pipeline_new (test_ctx);
  cogl_pipeline_set_layer_texture (*pipeline, 0, *offscreen_texture);

  *gles2_ctx = cogl_gles2_context_new (test_ctx, NULL);
  if (!*gles2_ctx)
    g_error ("Failed to create GLES2 context: %s\n", error->message);

  *gles2 = cogl_gles2_context_get_vtable (*gles2_ctx);
}
示例#19
0
/**
 * _st_create_texture_pipeline:
 * @src_texture: The CoglTexture for the pipeline
 *
 * Creates a simple pipeline which contains the given texture as a
 * single layer.
 */
CoglPipeline *
_st_create_texture_pipeline (CoglTexture *src_texture)
{
    static CoglPipeline *texture_pipeline_template = NULL;
    CoglPipeline *pipeline;

    g_return_val_if_fail (src_texture != NULL, NULL);

    /* The only state used in the pipeline that would affect the shader
       generation is the texture type on the layer. Therefore we create
       a template pipeline which sets this state and all texture
       pipelines are created as a copy of this. That way Cogl can find
       the shader state for the pipeline more quickly by looking at the
       pipeline ancestry instead of resorting to the shader cache. */
    if (G_UNLIKELY (texture_pipeline_template == NULL))
    {
        CoglContext *ctx =
            clutter_backend_get_cogl_context (clutter_get_default_backend ());

        texture_pipeline_template = cogl_pipeline_new (ctx);
        cogl_pipeline_set_layer_null_texture (texture_pipeline_template,
                                              0, /* layer */
                                              COGL_TEXTURE_TYPE_2D);
    }

    pipeline = cogl_pipeline_copy (texture_pipeline_template);

    if (src_texture != NULL)
        cogl_pipeline_set_layer_texture (pipeline, 0, src_texture);

    return pipeline;
}
示例#20
0
static void
shell_glsl_quad_constructed (GObject *object)
{
  ShellGLSLQuad *self;
  ShellGLSLQuadClass *klass;
  ShellGLSLQuadPrivate *priv;
  CoglContext *ctx =
    clutter_backend_get_cogl_context (clutter_get_default_backend ());

  G_OBJECT_CLASS (shell_glsl_quad_parent_class)->constructed (object);

  /* Note that, differently from ClutterBlurEffect, we are calling
     this inside constructed, not init, so klass points to the most-derived
     GTypeClass, not ShellGLSLQuadClass.
  */
  klass = SHELL_GLSL_QUAD_GET_CLASS (object);
  self = SHELL_GLSL_QUAD (object);
  priv = shell_glsl_quad_get_instance_private (self);

  if (G_UNLIKELY (klass->base_pipeline == NULL))
    {
      klass->base_pipeline = cogl_pipeline_new (ctx);
      cogl_pipeline_set_blend (klass->base_pipeline, "RGBA = ADD (SRC_COLOR * (SRC_COLOR[A]), DST_COLOR * (1-SRC_COLOR[A]))", NULL);

      if (klass->build_pipeline != NULL)
        klass->build_pipeline (self);
    }

  priv->pipeline = cogl_pipeline_copy (klass->base_pipeline);

  cogl_pipeline_set_layer_null_texture (priv->pipeline, 0, COGL_TEXTURE_TYPE_2D);
}
static void
clutter_desaturate_effect_init (ClutterDesaturateEffect *self)
{
  ClutterDesaturateEffectClass *klass = CLUTTER_DESATURATE_EFFECT_GET_CLASS (self);

  if (G_UNLIKELY (klass->base_pipeline == NULL))
    {
      CoglContext *ctx =
        clutter_backend_get_cogl_context (clutter_get_default_backend ());
      CoglSnippet *snippet;

      klass->base_pipeline = cogl_pipeline_new (ctx);

      snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
                                  desaturate_glsl_declarations,
                                  desaturate_glsl_source);
      cogl_pipeline_add_snippet (klass->base_pipeline, snippet);
      cogl_object_unref (snippet);

      cogl_pipeline_set_layer_null_texture (klass->base_pipeline,
                                            0, /* layer number */
                                            COGL_TEXTURE_TYPE_2D);
    }

  self->pipeline = cogl_pipeline_copy (klass->base_pipeline);

  self->factor_uniform =
    cogl_pipeline_get_uniform_location (self->pipeline, "factor");

  self->factor = 1.0;

  update_factor_uniform (self);
}
示例#22
0
static void
meta_surface_actor_pick (ClutterActor       *actor,
                         const ClutterColor *color)
{
  MetaSurfaceActor *self = META_SURFACE_ACTOR (actor);
  MetaSurfaceActorPrivate *priv =
    meta_surface_actor_get_instance_private (self);
  ClutterActorIter iter;
  ClutterActor *child;

  if (!clutter_actor_should_pick_paint (actor))
    return;

  /* If there is no region then use the regular pick */
  if (priv->input_region == NULL)
    CLUTTER_ACTOR_CLASS (meta_surface_actor_parent_class)->pick (actor, color);
  else
    {
      int n_rects;
      float *rectangles;
      int i;
      CoglPipeline *pipeline;
      CoglContext *ctx;
      CoglFramebuffer *fb;
      CoglColor cogl_color;

      n_rects = cairo_region_num_rectangles (priv->input_region);
      rectangles = g_alloca (sizeof (float) * 4 * n_rects);

      for (i = 0; i < n_rects; i++)
        {
          cairo_rectangle_int_t rect;
          int pos = i * 4;

          cairo_region_get_rectangle (priv->input_region, i, &rect);

          rectangles[pos + 0] = rect.x;
          rectangles[pos + 1] = rect.y;
          rectangles[pos + 2] = rect.x + rect.width;
          rectangles[pos + 3] = rect.y + rect.height;
        }

      ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
      fb = cogl_get_draw_framebuffer ();

      cogl_color_init_from_4ub (&cogl_color, color->red, color->green, color->blue, color->alpha);

      pipeline = cogl_pipeline_new (ctx);
      cogl_pipeline_set_color (pipeline, &cogl_color);
      cogl_framebuffer_draw_rectangles (fb, pipeline, rectangles, n_rects);
      cogl_object_unref (pipeline);
    }

  clutter_actor_iter_init (&iter, actor);

  while (clutter_actor_iter_next (&iter, &child))
    clutter_actor_paint (child);
}
示例#23
0
static void
test_multi_texture (TestState *state)
{
  CoglPipeline *pipeline;
  CoglTexture3D *tex_3d;
  CoglTexture2D *tex_2d;
  uint8_t tex_data[4];

  cogl_framebuffer_clear4f (test_fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);

  /* Tests a pipeline that is using multi-texturing to combine a 3D
     texture with a 2D texture. The texture from another layer is
     sampled with TEXTURE_? just to pick up a specific bug that was
     happening with the ARBfp fragend */

  pipeline = cogl_pipeline_new (test_ctx);

  tex_data[0] = 0xff;
  tex_data[1] = 0x00;
  tex_data[2] = 0x00;
  tex_data[3] = 0xff;
  tex_2d = cogl_texture_2d_new_from_data (test_ctx,
                                          1, 1, /* width/height */
                                          COGL_PIXEL_FORMAT_RGBA_8888_PRE,
                                          4, /* rowstride */
                                          tex_data,
                                          NULL);
  cogl_pipeline_set_layer_texture (pipeline, 0, tex_2d);

  tex_data[0] = 0x00;
  tex_data[1] = 0xff;
  tex_data[2] = 0x00;
  tex_data[3] = 0xff;
  tex_3d = cogl_texture_3d_new_from_data (test_ctx,
                                          1, 1, 1, /* width/height/depth */
                                          COGL_PIXEL_FORMAT_RGBA_8888_PRE,
                                          4, /* rowstride */
                                          4, /* image_stride */
                                          tex_data,
                                          NULL);
  cogl_pipeline_set_layer_texture (pipeline, 1, tex_3d);

  cogl_pipeline_set_layer_combine (pipeline, 0,
                                   "RGBA = REPLACE(PREVIOUS)",
                                   NULL);
  cogl_pipeline_set_layer_combine (pipeline, 1,
                                   "RGBA = ADD(TEXTURE_0, TEXTURE_1)",
                                   NULL);

  cogl_framebuffer_draw_rectangle (test_fb, pipeline, 0, 0, 10, 10);

  test_utils_check_pixel (test_fb, 5, 5, 0xffff00ff);

  cogl_object_unref (tex_2d);
  cogl_object_unref (tex_3d);
  cogl_object_unref (pipeline);
}
static CoglPipeline *
create_pipeline (void)
{
  CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);

  cogl_pipeline_set_color4ub (pipeline, 0, 255, 0, 255);

  return pipeline;
}
示例#25
0
void
test_point_size (void)
{
    int fb_width = cogl_framebuffer_get_width (test_fb);
    int fb_height = cogl_framebuffer_get_height (test_fb);
    int point_size;
    int x_pos;

    cogl_framebuffer_orthographic (test_fb,
                                   0, 0, /* x_1, y_1 */
                                   fb_width, /* x_2 */
                                   fb_height /* y_2 */,
                                   -1, 100 /* near/far */);

    cogl_framebuffer_clear4f (test_fb,
                              COGL_BUFFER_BIT_COLOR,
                              1.0f, 0.0f, 0.0f, 1.0f);

    /* Try a rendering a single point with a few different point
       sizes */
    for (x_pos = 0, point_size = MAX_POINT_SIZE;
            point_size >= 4;
            x_pos += POINT_BOX_SIZE, point_size /= 2)
    {
        CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
        CoglVertexP2 point = { x_pos + POINT_BOX_SIZE / 2,
                               POINT_BOX_SIZE / 2
                             };
        CoglPrimitive *prim =
            cogl_primitive_new_p2 (test_ctx,
                                   COGL_VERTICES_MODE_POINTS,
                                   1, /* n_vertices */
                                   &point);

        cogl_pipeline_set_point_size (pipeline, point_size);
        cogl_pipeline_set_color4ub (pipeline, 0, 255, 0, 255);
        cogl_framebuffer_draw_primitive (test_fb,
                                         pipeline,
                                         prim);

        cogl_object_unref (prim);
        cogl_object_unref (pipeline);
    }

    /* Verify all of the points where drawn at the right size */
    for (x_pos = 0, point_size = MAX_POINT_SIZE;
            point_size >= 4;
            x_pos += POINT_BOX_SIZE, point_size /= 2)
        verify_point_size (test_fb,
                           x_pos + POINT_BOX_SIZE / 2,
                           POINT_BOX_SIZE / 2,
                           point_size);

    if (cogl_test_verbose ())
        g_print ("OK\n");
}
示例#26
0
CoglPipeline *
_cogl_pango_pipeline_cache_get (CoglPangoPipelineCache *cache,
                                CoglHandle texture)
{
  CoglPangoPipelineCacheEntry *entry;
  PipelineDestroyNotifyData *destroy_data;
  static CoglUserDataKey pipeline_destroy_notify_key;

  /* Look for an existing entry */
  entry = g_hash_table_lookup (cache->hash_table, texture);

  if (entry)
    return cogl_object_ref (entry->pipeline);

  /* No existing pipeline was found so let's create another */
  entry = g_slice_new (CoglPangoPipelineCacheEntry);

  if (texture)
    {
      CoglPipeline *base;

      entry->texture = cogl_object_ref (texture);

      if (cogl_texture_get_format (entry->texture) == COGL_PIXEL_FORMAT_A_8)
        base = get_base_texture_alpha_pipeline (cache);
      else
        base = get_base_texture_rgba_pipeline (cache);

      entry->pipeline = cogl_pipeline_copy (base);

      cogl_pipeline_set_layer_texture (entry->pipeline, 0 /* layer */, texture);
    }
  else
    {
      entry->texture = NULL;
      entry->pipeline = cogl_pipeline_new ();
    }

  /* Add a weak reference to the pipeline so we can remove it from the
     hash table when it is destroyed */
  destroy_data = g_slice_new (PipelineDestroyNotifyData);
  destroy_data->cache = cache;
  destroy_data->texture = texture;
  cogl_object_set_user_data (entry->pipeline,
                             &pipeline_destroy_notify_key,
                             destroy_data,
                             pipeline_destroy_notify_cb);

  g_hash_table_insert (cache->hash_table,
                       texture ? cogl_object_ref (texture) : NULL,
                       entry);

  /* This doesn't take a reference on the pipeline so that it will use
     the newly created reference */
  return entry->pipeline;
}
示例#27
0
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");
}
示例#28
0
static void
texture_tower_revalidate_fbo (MetaTextureTower *tower,
                              int               level)
{
  CoglTexture *source_texture = tower->textures[level - 1];
  int source_texture_width = cogl_texture_get_width (source_texture);
  int source_texture_height = cogl_texture_get_height (source_texture);
  CoglTexture *dest_texture = tower->textures[level];
  int dest_texture_width = cogl_texture_get_width (dest_texture);
  int dest_texture_height = cogl_texture_get_height (dest_texture);
  Box *invalid = &tower->invalid[level];
  CoglFramebuffer *fb;
  CoglError *catch_error = NULL;
  CoglPipeline *pipeline;

  if (tower->fbos[level] == NULL)
    tower->fbos[level] = cogl_offscreen_new_with_texture (dest_texture);

  fb = COGL_FRAMEBUFFER (tower->fbos[level]);

  if (!cogl_framebuffer_allocate (fb, &catch_error))
    {
      cogl_error_free (catch_error);
      return;
    }

  cogl_framebuffer_orthographic (fb, 0, 0, dest_texture_width, dest_texture_height, -1., 1.);

  if (!tower->pipeline_template)
    {
      CoglContext *ctx =
        clutter_backend_get_cogl_context (clutter_get_default_backend ());
      tower->pipeline_template = cogl_pipeline_new (ctx);
      cogl_pipeline_set_blend (tower->pipeline_template, "RGBA = ADD (SRC_COLOR, 0)", NULL);
    }

  pipeline = cogl_pipeline_copy (tower->pipeline_template);
  cogl_pipeline_set_layer_texture (pipeline, 0, tower->textures[level - 1]);

  cogl_framebuffer_draw_textured_rectangle (fb, pipeline,
                                            invalid->x1, invalid->y1,
                                            invalid->x2, invalid->y2,
                                            (2. * invalid->x1) / source_texture_width,
                                            (2. * invalid->y1) / source_texture_height,
                                            (2. * invalid->x2) / source_texture_width,
                                            (2. * invalid->y2) / source_texture_height);

  cogl_object_unref (pipeline);
}
示例#29
0
static void
paint (TestState *state)
{
  CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
  CoglTexture *tex;
  CoglError *error = NULL;
  CoglSnippet *snippet;

  cogl_framebuffer_clear4f (test_fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);

  /* Set the primary vertex color as red */
  cogl_pipeline_set_color4f (pipeline, 1, 0, 0, 1);

  /* Override the vertex color in the texture environment with a
     constant green color provided by a texture */
  tex = create_dummy_texture ();
  cogl_pipeline_set_layer_texture (pipeline, 0, tex);
  cogl_object_unref (tex);
  if (!cogl_pipeline_set_layer_combine (pipeline, 0,
                                        "RGBA=REPLACE(TEXTURE)",
                                        &error))
    {
      g_warning ("Error setting layer combine: %s", error->message);
      g_assert_not_reached ();
    }

  /* Set up a dummy vertex shader that does nothing but the usual
     modelview-projection transform */
  snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_VERTEX,
                              NULL, /* no declarations */
                              NULL); /* no "post" code */
  cogl_snippet_set_replace (snippet,
                            "  cogl_position_out = "
                            "cogl_modelview_projection_matrix * "
                            "cogl_position_in;\n"
                            "  cogl_color_out = cogl_color_in;\n"
                            "  cogl_tex_coord0_out = cogl_tex_coord_in;\n");

  /* Draw something without the snippet */
  cogl_framebuffer_draw_rectangle (test_fb, pipeline, 0, 0, 50, 50);

  /* Draw it again using the snippet. It should look exactly the same */
  cogl_pipeline_add_snippet (pipeline, snippet);
  cogl_object_unref (snippet);

  cogl_framebuffer_draw_rectangle (test_fb, pipeline, 50, 0, 100, 50);

  cogl_object_unref (pipeline);
}
示例#30
0
static CoglPipeline *
create_pipeline_for_shader (TestState *state,
                            const char *declarations,
                            const char *fragment_source)
{
  CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
  CoglSnippet *snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
                                           declarations,
                                           NULL);
  cogl_snippet_set_replace (snippet, fragment_source);

  cogl_pipeline_add_snippet (pipeline, snippet);
  cogl_object_unref (snippet);

  return pipeline;
}