Esempio n. 1
0
static void
paint (void)
{
  cg_pipeline_t *pipeline = cg_pipeline_new (test_dev);
  cg_texture_t *texture = make_texture ();
  int y, x;

  cg_pipeline_set_layer_texture (pipeline, 0, texture);

  /* Just render the texture in the top left corner */
  /* Render the texture using four separate rectangles */
  for (y = 0; y < 2; y++)
    for (x = 0; x < 2; x++)
      cg_framebuffer_draw_textured_rectangle (test_fb,
                                                pipeline,
                                                x * TEXTURE_RENDER_SIZE / 2,
                                                y * TEXTURE_RENDER_SIZE / 2,
                                                (x + 1) *
                                                TEXTURE_RENDER_SIZE / 2,
                                                (y + 1) *
                                                TEXTURE_RENDER_SIZE / 2,
                                                x / 2.0f,
                                                y / 2.0f,
                                                (x + 1) / 2.0f,
                                                (y + 1) / 2.0f);

  cg_object_unref (pipeline);
  cg_object_unref (texture);
}
Esempio n. 2
0
static void
test_modify_fragment_layer(TestState *state)
{
    cg_pipeline_t *pipeline;
    cg_snippet_t *snippet;

    /* Test modifying the fragment layer code */
    pipeline = cg_pipeline_new(test_dev);

    cg_pipeline_set_uniform_1f(pipeline,
                               cg_pipeline_get_uniform_location(pipeline,
                                                                "a_value"),
                               0.5);

    snippet = cg_snippet_new(CG_SNIPPET_HOOK_LAYER_FRAGMENT,
                             "uniform float a_value;",
                             "frag.g = a_value;");
    cg_pipeline_add_layer_snippet(pipeline, 0, snippet);
    cg_object_unref(snippet);

    cg_framebuffer_draw_textured_rectangle(test_fb,
                                           pipeline,
                                           120, 0, 130, 10,
                                           0, 0, 0, 0);
    cg_object_unref(pipeline);

    test_cg_check_pixel(test_fb, 125, 5, 0xff80ffff);
}
Esempio n. 3
0
static void
test_replace_fragment_layer(TestState *state)
{
    cg_pipeline_t *pipeline;
    cg_snippet_t *snippet;

    /* Test replacing the fragment layer code */
    pipeline = create_texture_pipeline(state);

    snippet = cg_snippet_new(CG_SNIPPET_HOOK_LAYER_FRAGMENT, NULL, NULL);
    cg_snippet_set_replace(snippet, "frag = vec4(0.0, 0.0, 1.0, 1.0);\n");
    cg_pipeline_add_layer_snippet(pipeline, 0, snippet);
    cg_object_unref(snippet);

    /* Add a second layer which references the texture of the first
     * layer. Even though the first layer is ignoring that layer's
     * texture sample we should still be able to reference it in a
     * another layer...
     */
    snippet = cg_snippet_new(CG_SNIPPET_HOOK_LAYER_FRAGMENT, NULL, NULL);
    cg_snippet_set_replace(snippet, "frag += cg_texel0;\n");
    cg_pipeline_add_layer_snippet(pipeline, 1, snippet);
    cg_object_unref(snippet);

    cg_framebuffer_draw_textured_rectangle(test_fb,
                                           pipeline,
                                           110, 0, 120, 10,
                                           0, 0, 0, 0);
    cg_object_unref(pipeline);

    test_cg_check_pixel(test_fb, 115, 5, 0xff00ffff);
}
Esempio n. 4
0
static void
test_replace_snippet(TestState *state)
{
    cg_pipeline_t *pipeline;
    cg_snippet_t *snippet;

    /* Test replacing a previous snippet */
    pipeline = create_texture_pipeline(state);

    snippet = cg_snippet_new(CG_SNIPPET_HOOK_FRAGMENT,
                             NULL,
                             "cg_color_out = vec4(0.5, 0.5, 0.5, 1.0);");
    cg_pipeline_add_snippet(pipeline, snippet);
    cg_object_unref(snippet);

    snippet = cg_snippet_new(CG_SNIPPET_HOOK_FRAGMENT, NULL, NULL);
    cg_snippet_set_pre(snippet, "cg_color_out = vec4(1.0, 1.0, 1.0, 1.0);");
    cg_snippet_set_replace(snippet,
                           "cg_color_out *= vec4(1.0, 0.0, 0.0, 1.0);");
    cg_pipeline_add_snippet(pipeline, snippet);
    cg_object_unref(snippet);

    cg_framebuffer_draw_textured_rectangle(test_fb,
                                           pipeline,
                                           100, 0, 110, 10,
                                           0, 0, 0, 0);
    cg_object_unref(pipeline);

    test_cg_check_pixel(test_fb, 105, 5, 0xff0000ff);
}
Esempio n. 5
0
static void
test_texture_lookup_hook(TestState *state)
{
    cg_pipeline_t *pipeline;
    cg_snippet_t *snippet;

    /* Check the texture lookup hook */
    snippet = cg_snippet_new(CG_SNIPPET_HOOK_TEXTURE_LOOKUP,
                             NULL,
                             "cg_texel.b += 1.0;");

    /* Flip the texture coordinates around the y axis so that it will
     * get the green texel.
     *
     * XXX: the - 0.1 to avoid sampling at the texture border since we aren't
     * sure there won't be some inprecision in flipping the coordinate and we
     * might sample the wrong texel with the default _REPEAT wrap mode.
     */
    cg_snippet_set_pre(snippet, "cg_tex_coord.x =(1.0 - cg_tex_coord.x) - 0.1;");

    pipeline = create_texture_pipeline(state);
    cg_pipeline_add_layer_snippet(pipeline, 0, snippet);
    cg_framebuffer_draw_textured_rectangle(test_fb,
                                           pipeline,
                                           80, 0, 90, 10,
                                           0, 0, 0, 0);
    cg_object_unref(pipeline);

    cg_object_unref(snippet);

    test_cg_check_pixel(test_fb, 85, 5, 0x00ffffff);
}
Esempio n. 6
0
static void
test_replace_lookup_hook(TestState *state)
{
    cg_pipeline_t *pipeline;
    cg_snippet_t *snippet;

    /* Check replacing the texture lookup hook */
    snippet = cg_snippet_new(CG_SNIPPET_HOOK_TEXTURE_LOOKUP, NULL, NULL);
    cg_snippet_set_replace(snippet, "cg_texel = vec4(0.0, 0.0, 1.0, 0.0);");

    pipeline = create_texture_pipeline(state);
    cg_pipeline_add_layer_snippet(pipeline, 0, snippet);
    cg_framebuffer_draw_textured_rectangle(test_fb,
                                           pipeline,
                                           90, 0, 100, 10,
                                           0, 0, 0, 0);
    cg_object_unref(pipeline);

    cg_object_unref(snippet);

    test_cg_check_pixel(test_fb, 95, 5, 0x0000ffff);
}
Esempio n. 7
0
static void
test_modify_vertex_layer(TestState *state)
{
    cg_pipeline_t *pipeline;
    cg_snippet_t *snippet;

    /* Test modifying the vertex layer code */
    pipeline = create_texture_pipeline(state);

    snippet = cg_snippet_new(CG_SNIPPET_HOOK_TEXTURE_COORD_TRANSFORM,
                             NULL,
                             "cg_tex_coord.x = 1.0;");
    cg_pipeline_add_layer_snippet(pipeline, 0, snippet);
    cg_object_unref(snippet);

    cg_framebuffer_draw_textured_rectangle(test_fb,
                                           pipeline,
                                           130, 0, 140, 10,
                                           0, 1, 0, 1);
    cg_object_unref(pipeline);

    test_cg_check_pixel(test_fb, 135, 5, 0xffff00ff);
}
Esempio n. 8
0
static void
test_replace_vertex_layer(TestState *state)
{
    cg_pipeline_t *pipeline;
    cg_snippet_t *snippet;

    /* Test replacing the vertex layer code */
    pipeline = create_texture_pipeline(state);

    snippet = cg_snippet_new(CG_SNIPPET_HOOK_TEXTURE_COORD_TRANSFORM,
                             NULL,
                             NULL);
    cg_snippet_set_replace(snippet, "cg_tex_coord.xy = vec2(1.0, 0.0);\n");
    cg_pipeline_add_layer_snippet(pipeline, 0, snippet);
    cg_object_unref(snippet);

    cg_framebuffer_draw_textured_rectangle(test_fb,
                                           pipeline,
                                           140, 0, 150, 10,
                                           1, 1, 1, 1);
    cg_object_unref(pipeline);

    test_cg_check_pixel(test_fb, 145, 5, 0x00ff00ff);
}