Efficient reflections in Clutter/COGL?

278 views Asked by At

I'm working on a program that uses Clutter (1.10) and COGL to render elements to the display.

I've created a set of ClutterTextures that I am rendering video to, and I'd like the video textures to have reflections.

The "standard" way to implement this seems to be a callback every time the texture is painted, with code similar to:

static void texture_paint_cb (ClutterActor *actor ) {
    ClutterGeometry geom;
    CoglHandle cmaterial;
    CoglHandle ctexture;
    gfloat squish = 1.5;

    cogl_push_matrix ();

    clutter_actor_get_allocation_geometry (actor, &geom);

    guint8 opacity = clutter_actor_get_paint_opacity (actor);
    opacity /= 2;

    CoglTextureVertex vertices[] =
    { 
        { geom.width, geom.height,     0,  1, 1 },
        { 0,          geom.height,     0,  0, 1 },
        { 0,          geom.height*squish, 0,  0, 0 },
        { geom.width, geom.height*squish, 0,  1, 0 } 
    };

    cogl_color_set_from_4ub (&vertices[0].color, opacity, opacity, opacity, opacity);
    cogl_color_set_from_4ub (&vertices[1].color, opacity, opacity, opacity, opacity);
    cogl_color_set_from_4ub (&vertices[2].color, 0, 0, 0, 0);
    cogl_color_set_from_4ub (&vertices[3].color, 0, 0, 0, 0);

    cmaterial = clutter_texture_get_cogl_material (CLUTTER_TEXTURE (actor));
    ctexture  = clutter_texture_get_cogl_texture  (CLUTTER_TEXTURE (actor));

    cogl_material_set_layer (cmaterial, 0, ctexture);
    cogl_set_source(cmaterial);
    cogl_set_source_texture(ctexture);
    cogl_polygon (vertices, G_N_ELEMENTS (vertices), TRUE);

    cogl_pop_matrix ();
}

This is then hooked to the paint signal on the ClutterTexture. There's a similar bit of code here that does something similar. (Google cache, since the page has been down today)

The problem that I'm having is that the reflection effect is causing a performance hit - 5~7 fps is being lost when I enable it. Part of the problem is likely the low-power hardware I'm using (a Raspberry Pi).

I've managed to do something similar to what this code does, by setting up a clone of the texture and making it somewhat transparent. This causes no performance hit whatsoever. However, unlike the paint callback method, the reflection has hard edges and doesn't fade out.

I'd like to get a better looking reflection effect without the performance hit. I'm wondering if there's some way to get a similar effect that doesn't require so much work per paint... There are a bunch of other Clutter and COGL methods that manipulate materials, shaders, and so forth, but I have little to no OpenGL expertise so I don't have any idea if I could get something along those lines to do what I want, or even how to find examples of something similar I could work off of.

Is it possible to get a better looking, high performance reflection effect via Clutter/COGL?

0

There are 0 answers