예제 #1
0
static void
shared_variable_pre_post(TestState *state)
{
    cg_pipeline_t *pipeline;
    cg_snippet_t *snippet;

    /* Test that the pre string can declare variables used by the post
       string */
    pipeline = cg_pipeline_new(test_dev);

    cg_pipeline_set_color4ub(pipeline, 255, 255, 255, 255);

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

    cg_framebuffer_draw_rectangle(test_fb, pipeline, 40, 0, 50, 10);

    cg_object_unref(pipeline);

    test_cg_check_pixel(test_fb, 45, 5, 0xff0000ff);
}
예제 #2
0
static void
test_pipeline_caching(TestState *state)
{
    cg_pipeline_t *pipeline;
    cg_snippet_t *snippet;

    /* Check that the pipeline caching works when unrelated pipelines
       share snippets state. It's too hard to actually assert this in
       the conformance test but at least it should be possible to see by
       setting CG_DEBUG=show-source to check whether this shader gets
       generated twice */
    snippet = cg_snippet_new(CG_SNIPPET_HOOK_FRAGMENT,
                             "/* This comment should only be seen ONCE\n"
                             "   when CG_DEBUG=show-source is true\n"
                             "   even though it is used in two different\n"
                             "   unrelated pipelines */",
                             "cg_color_out = vec4(0.0, 1.0, 0.0, 1.0);\n");

    pipeline = cg_pipeline_new(test_dev);
    cg_pipeline_add_snippet(pipeline, snippet);
    cg_framebuffer_draw_rectangle(test_fb, pipeline, 50, 0, 60, 10);
    cg_object_unref(pipeline);

    pipeline = cg_pipeline_new(test_dev);
    cg_pipeline_add_snippet(pipeline, snippet);
    cg_framebuffer_draw_rectangle(test_fb, pipeline, 60, 0, 70, 10);
    cg_object_unref(pipeline);

    cg_object_unref(snippet);

    test_cg_check_pixel(test_fb, 55, 5, 0x00ff00ff);
    test_cg_check_pixel(test_fb, 65, 5, 0x00ff00ff);
}
예제 #3
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);
}
예제 #4
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);
}
예제 #5
0
static void
test_multiple_samples(TestState *state)
{
    cg_pipeline_t *pipeline;
    cg_snippet_t *snippet;

    /* Check that we can use the passed in sampler in the texture lookup
       to sample multiple times */
    snippet = cg_snippet_new(CG_SNIPPET_HOOK_TEXTURE_LOOKUP,
                             NULL,
                             NULL);
    cg_snippet_set_replace(snippet,
                           "cg_texel = "
                           "texture2D(cg_sampler, vec2(0.25, 0.25)) + "
                           "texture2D(cg_sampler, vec2(0.75, 0.25));");

    pipeline = create_texture_pipeline(state);
    cg_pipeline_add_layer_snippet(pipeline, 0, snippet);
    cg_framebuffer_draw_rectangle(test_fb, pipeline, 0, 0, 10, 10);
    cg_object_unref(pipeline);

    cg_object_unref(snippet);

    test_cg_check_pixel(test_fb, 5, 5, 0xffff00ff);
}
예제 #6
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);
}
예제 #7
0
static void
shared_uniform(TestState *state)
{
    cg_pipeline_t *pipeline;
    cg_snippet_t *snippet;
    int location;

    /* Snippets sharing a uniform across the vertex and fragment
       hooks */
    pipeline = cg_pipeline_new(test_dev);

    location = cg_pipeline_get_uniform_location(pipeline, "a_value");
    cg_pipeline_set_uniform_1f(pipeline, location, 0.25f);

    cg_pipeline_set_color4ub(pipeline, 255, 0, 0, 255);

    snippet = cg_snippet_new(CG_SNIPPET_HOOK_VERTEX,
                             "uniform float a_value;",
                             "cg_color_out.b += a_value;");
    cg_pipeline_add_snippet(pipeline, snippet);
    cg_object_unref(snippet);
    snippet = cg_snippet_new(CG_SNIPPET_HOOK_FRAGMENT,
                             "uniform float a_value;",
                             "cg_color_out.b += a_value;");
    cg_pipeline_add_snippet(pipeline, snippet);
    cg_object_unref(snippet);

    cg_framebuffer_draw_rectangle(test_fb,
                                  pipeline,
                                  20, 0, 30, 10);

    cg_object_unref(pipeline);

    test_cg_check_pixel(test_fb, 25, 5, 0xff0080ff);
}
예제 #8
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);
}
예제 #9
0
cg_indices_t *
cg_indices_new(cg_device_t *dev,
               cg_indices_type_t type,
               const void *indices_data,
               int n_indices)
{
    size_t buffer_bytes = sizeof_indices_type(type) * n_indices;
    cg_index_buffer_t *index_buffer =
        cg_index_buffer_new(dev, buffer_bytes);
    cg_buffer_t *buffer = CG_BUFFER(index_buffer);
    cg_indices_t *indices;
    cg_error_t *ignore_error = NULL;

    cg_buffer_set_data(buffer, 0, indices_data, buffer_bytes, &ignore_error);
    if (ignore_error) {
        cg_error_free(ignore_error);
        cg_object_unref(index_buffer);
        return NULL;
    }

    indices = cg_indices_new_for_buffer(type, index_buffer, 0);
    cg_object_unref(index_buffer);

    return indices;
}
예제 #10
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);
}
예제 #11
0
static void
texture_unit_free(cg_texture_unit_t *unit)
{
    if (unit->layer)
        cg_object_unref(unit->layer);
    cg_object_unref(unit->matrix_stack);
}
예제 #12
0
static void
test_replace_string(TestState *state)
{
    cg_pipeline_t *pipeline;
    cg_snippet_t *snippet;

    /* Check the replace string */
    snippet = cg_snippet_new(CG_SNIPPET_HOOK_FRAGMENT, NULL, NULL);
    cg_snippet_set_pre(snippet,
                       "cg_color_out = vec4(0.0, 0.5, 0.0, 1.0);");
    /* Remove the generated output. If the replace string isn't working
       then the code from the pre string would get overwritten with
       white */
    cg_snippet_set_replace(snippet, "/* do nothing */");
    cg_snippet_set_post(snippet,
                        "cg_color_out += vec4(0.5, 0.0, 0.0, 1.0);");

    pipeline = cg_pipeline_new(test_dev);
    cg_pipeline_add_snippet(pipeline, snippet);
    cg_framebuffer_draw_rectangle(test_fb, pipeline, 70, 0, 80, 10);
    cg_object_unref(pipeline);

    cg_object_unref(snippet);

    test_cg_check_pixel(test_fb, 75, 5, 0x808000ff);
}
예제 #13
0
static void
test_global_vertex_hook(TestState *state)
{
    cg_pipeline_t *pipeline;
    cg_snippet_t *snippet;

    pipeline = cg_pipeline_new(test_dev);

    /* Creates a function in the global declarations hook which is used
     * by a subsequent snippet. The subsequent snippets replace any
     * previous snippets but this shouldn't prevent the global
     * declarations from being generated */

    snippet = cg_snippet_new(CG_SNIPPET_HOOK_VERTEX_GLOBALS,
                             /* declarations */
                             "float\n"
                             "multiply_by_two(float number)\n"
                             "{\n"
                             "  return number * 2.0;\n"
                             "}\n",
                             /* post */
                             "This string shouldn't be used so "
                             "we can safely put garbage in here.");
    cg_snippet_set_pre(snippet,
                       "This string shouldn't be used so "
                       "we can safely put garbage in here.");
    cg_snippet_set_replace(snippet,
                           "This string shouldn't be used so "
                           "we can safely put garbage in here.");
    cg_pipeline_add_snippet(pipeline, snippet);
    cg_object_unref(snippet);

    snippet = cg_snippet_new(CG_SNIPPET_HOOK_VERTEX,
                             NULL, /* declarations */
                             NULL /* replace */);
    cg_snippet_set_replace(snippet,
                           "cg_color_out.r = multiply_by_two(0.5);\n"
                           "cg_color_out.gba = vec3(0.0, 0.0, 1.0);\n"
                           "cg_position_out = cg_position_in;\n");
    cg_pipeline_add_snippet(pipeline, snippet);
    cg_object_unref(snippet);

    cg_framebuffer_draw_rectangle(test_fb,
                                  pipeline,
                                  -1, 1,
                                  10.0f * 2.0f / state->fb_width - 1.0f,
                                  10.0f * 2.0f / state->fb_height - 1.0f);

    cg_object_unref(pipeline);

    test_cg_check_pixel(test_fb, 5, 5, 0xff0000ff);
}
예제 #14
0
static cg_pipeline_t *
create_texture_pipeline(TestState *state)
{
    cg_pipeline_t *pipeline;
    cg_texture_t *tex;
    static const uint8_t tex_data[] = {
        0xff, 0x00, 0x00, 0xff, /* red */  0x00, 0xff, 0x00, 0xff, /* green */
        0x00, 0x00, 0xff, 0xff, /* blue */ 0xff, 0xff, 0x00, 0xff, /* yellow */
    };

    tex = test_cg_texture_new_from_data(test_dev,
                                        2, 2, /* width/height */
                                        TEST_CG_TEXTURE_NO_ATLAS,
                                        CG_PIXEL_FORMAT_RGBA_8888_PRE,
                                        8, /* rowstride */
                                        tex_data);

    pipeline = cg_pipeline_new(test_dev);

    cg_pipeline_set_layer_texture(pipeline, 0, tex);

    cg_pipeline_set_layer_filters(pipeline, 0,
                                  CG_PIPELINE_FILTER_NEAREST,
                                  CG_PIPELINE_FILTER_NEAREST);

    cg_object_unref(tex);

    return pipeline;
}
예제 #15
0
static void
create_pipelines(cg_pipeline_t **pipelines, int n_pipelines)
{
    int i;

    for (i = 0; i < n_pipelines; i++) {
        char *source = c_strdup_printf("  cg_color_out = "
                                       "vec4 (%f, 0.0, 0.0, 1.0);\n",
                                       i / 255.0f);
        cg_snippet_t *snippet = cg_snippet_new(CG_SNIPPET_HOOK_FRAGMENT,
                                               NULL, /* declarations */
                                               source);

        c_free(source);

        pipelines[i] = cg_pipeline_new(test_dev);
        cg_pipeline_add_snippet(pipelines[i], snippet);
        cg_object_unref(snippet);
    }

    /* Test that drawing with them works. This should create the entries
     * in the cache */
    for (i = 0; i < n_pipelines; i++) {
        cg_framebuffer_draw_rectangle(test_fb, pipelines[i], i, 0, i + 1, 1);
        test_cg_check_pixel_rgb(test_fb, i, 0, i, 0, 0);
    }
}
예제 #16
0
static void
create_box_control(entity_state_t *entity_state, float x, float y, float z)
{
    rig_selection_tool_t *tool = entity_state->tool;
    cg_texture_t *tex =
        rut_load_texture_from_data_file(tool->shell, "dot.png", NULL);
    control_point_t *point;

    point = c_slice_new0(control_point_t);
    point->entity_state = entity_state;
    point->x = x;
    point->y = y;
    point->z = z;

    point->transform = rut_transform_new(tool->shell);
    rut_graphable_add_child(tool->tool_overlay, point->transform);
    rut_object_unref(point->transform);

    point->marker = rut_nine_slice_new(tool->shell, tex, 0, 0, 0, 0, 10, 10);
    rut_graphable_add_child(point->transform, point->marker);
    rut_object_unref(point->marker);

    point->input_region =
        rut_input_region_new_circle(0, 0, 5, control_point_input_cb, point);
    rut_graphable_add_child(tool->tool_overlay, point->input_region);
    rut_object_unref(point->input_region);
    entity_state->control_points =
        c_llist_prepend(entity_state->control_points, point);

    cg_object_unref(tex);
}
예제 #17
0
cg_pixel_buffer_t *cg_pixel_buffer_new(cg_device_t *dev,
                                       size_t size,
                                       const void *data,
                                       cg_error_t **error)
{
    cg_pixel_buffer_t *pixel_buffer = c_slice_new0(cg_pixel_buffer_t);
    cg_buffer_t *buffer = CG_BUFFER(pixel_buffer);

    /* parent's constructor */
    _cg_buffer_initialize(buffer,
                          dev,
                          size,
                          CG_BUFFER_BIND_TARGET_PIXEL_UNPACK,
                          CG_BUFFER_USAGE_HINT_TEXTURE,
                          CG_BUFFER_UPDATE_HINT_STATIC);

    _cg_pixel_buffer_object_new(pixel_buffer);

    if (data) {
        if (!cg_buffer_set_data(
                CG_BUFFER(pixel_buffer), 0, data, size, error)) {
            cg_object_unref(pixel_buffer);
            return NULL;
        }
    }

    return pixel_buffer;
}
예제 #18
0
static void
test_vertex_transform_hook(TestState *state)
{
    cg_pipeline_t *pipeline;
    cg_snippet_t *snippet;
    c_matrix_t identity_matrix;
    c_matrix_t matrix;
    int location;

    /* Test the vertex transform hook */

    c_matrix_init_identity(&identity_matrix);

    pipeline = cg_pipeline_new(test_dev);

    cg_pipeline_set_color4ub(pipeline, 255, 0, 255, 255);

    snippet = cg_snippet_new(CG_SNIPPET_HOOK_VERTEX_TRANSFORM,
                             "uniform mat4 pmat;",
                             NULL);
    cg_snippet_set_replace(snippet, "cg_position_out = "
                           "pmat * cg_position_in;");
    cg_pipeline_add_snippet(pipeline, snippet);
    cg_object_unref(snippet);

    /* Copy the current projection matrix to a uniform */
    cg_framebuffer_get_projection_matrix(test_fb, &matrix);
    location = cg_pipeline_get_uniform_location(pipeline, "pmat");
    cg_pipeline_set_uniform_matrix(pipeline,
                                   location,
                                   4, /* dimensions */
                                   1, /* count */
                                   false, /* don't transpose */
                                   c_matrix_get_array(&matrix));

    /* Replace the real projection matrix with the identity. This should
       mess up the drawing unless the snippet replacement is working */
    cg_framebuffer_set_projection_matrix(test_fb, &identity_matrix);

    cg_framebuffer_draw_rectangle(test_fb, pipeline, 150, 0, 160, 10);
    cg_object_unref(pipeline);

    /* Restore the projection matrix */
    cg_framebuffer_set_projection_matrix(test_fb, &matrix);

    test_cg_check_pixel(test_fb, 155, 5, 0xff00ffff);
}
예제 #19
0
static bool
draw_rectangle (TestState *state,
                int x,
                int y,
                TestDepthState *rect_state)
{
  uint8_t Cr = MASK_RED (rect_state->color);
  uint8_t Cg = MASK_GREEN (rect_state->color);
  uint8_t Cb = MASK_BLUE (rect_state->color);
  uint8_t Ca = MASK_ALPHA (rect_state->color);
  cg_pipeline_t *pipeline;
  cg_depth_state_t depth_state;

  cg_depth_state_init (&depth_state);
  cg_depth_state_set_test_enabled (&depth_state, rect_state->test_enable);
  cg_depth_state_set_test_function (&depth_state, rect_state->test_function);
  cg_depth_state_set_write_enabled (&depth_state, rect_state->write_enable);
  cg_depth_state_set_range (&depth_state,
                              rect_state->range_near,
                              rect_state->range_far);

  pipeline = cg_pipeline_new (test_dev);
  if (!cg_pipeline_set_depth_state (pipeline, &depth_state, NULL))
    {
      cg_object_unref (pipeline);
      return false;
    }

  cg_pipeline_set_color4ub (pipeline, Cr, Cg, Cb, Ca);

  cg_framebuffer_set_depth_write_enabled (test_fb, rect_state->fb_write_enable);
  cg_framebuffer_push_matrix (test_fb);
  cg_framebuffer_translate (test_fb, 0, 0, rect_state->depth);
  cg_framebuffer_draw_rectangle (test_fb,
                                   pipeline,
                                   x * QUAD_WIDTH,
                                   y * QUAD_WIDTH,
                                   x * QUAD_WIDTH + QUAD_WIDTH,
                                   y * QUAD_WIDTH + QUAD_WIDTH);
  cg_framebuffer_pop_matrix (test_fb);

  cg_object_unref (pipeline);

  return true;
}
예제 #20
0
static void
_rig_downsampler_reset(rig_downsampler_t *downsampler)
{
    if (downsampler->dest) {
        cg_object_unref(downsampler->dest);
        downsampler->dest = NULL;
    }

    if (downsampler->fb) {
        cg_object_unref(downsampler->fb);
        downsampler->fb = NULL;
    }

    if (downsampler->camera) {
        rut_object_unref(downsampler->camera);
        downsampler->camera = NULL;
    }
}
예제 #21
0
bool
_cg_texture_2d_gl_copy_from_bitmap(cg_texture_2d_t *tex_2d,
                                   int src_x,
                                   int src_y,
                                   int width,
                                   int height,
                                   cg_bitmap_t *bmp,
                                   int dst_x,
                                   int dst_y,
                                   int level,
                                   cg_error_t **error)
{
    cg_texture_t *tex = CG_TEXTURE(tex_2d);
    cg_device_t *dev = tex->dev;
    cg_bitmap_t *upload_bmp;
    cg_pixel_format_t upload_format;
    GLenum gl_format;
    GLenum gl_type;
    bool status = true;

    upload_bmp =
        _cg_bitmap_convert_for_upload(bmp,
                                      _cg_texture_get_format(tex),
                                      false, /* can't convert in place */
                                      error);
    if (upload_bmp == NULL)
        return false;

    upload_format = cg_bitmap_get_format(upload_bmp);

    dev->driver_vtable->pixel_format_to_gl(dev,
                                           upload_format,
                                           NULL, /* internal format */
                                           &gl_format,
                                           &gl_type);

    status = dev->texture_driver->upload_subregion_to_gl(dev,
                                                         tex,
                                                         false,
                                                         src_x,
                                                         src_y,
                                                         dst_x,
                                                         dst_y,
                                                         width,
                                                         height,
                                                         level,
                                                         upload_bmp,
                                                         gl_format,
                                                         gl_type,
                                                         error);

    cg_object_unref(upload_bmp);

    _cg_texture_gl_maybe_update_max_level(tex, level);

    return status;
}
예제 #22
0
static void
lots_snippets(TestState *state)
{
    cg_pipeline_t *pipeline;
    cg_snippet_t *snippet;
    int location;
    int i;

    /* Lots of snippets on one pipeline */
    pipeline = cg_pipeline_new(test_dev);

    cg_pipeline_set_color4ub(pipeline, 0, 0, 0, 255);

    for(i = 0; i < 3; i++) {
        char letter = 'x' + i;
        char *uniform_name = c_strdup_printf("%c_value", letter);
        char *declarations = c_strdup_printf("uniform float %s;\n",
                                             uniform_name);
        char *code = c_strdup_printf("cg_color_out.%c = %s;\n",
                                     letter,
                                     uniform_name);

        location = cg_pipeline_get_uniform_location(pipeline, uniform_name);
        cg_pipeline_set_uniform_1f(pipeline, location,(i + 1) * 0.1f);

        snippet = cg_snippet_new(CG_SNIPPET_HOOK_FRAGMENT,
                                 declarations,
                                 code);
        cg_pipeline_add_snippet(pipeline, snippet);
        cg_object_unref(snippet);

        c_free(code);
        c_free(uniform_name);
        c_free(declarations);
    }

    cg_framebuffer_draw_rectangle(test_fb, pipeline, 30, 0, 40, 10);

    cg_object_unref(pipeline);

    test_cg_check_pixel(test_fb, 35, 5, 0x19334cff);
}
예제 #23
0
void
cg_device_set_renderer(cg_device_t *dev, cg_renderer_t *renderer)
{
    if (renderer)
        cg_object_ref(renderer);

    if (dev->renderer)
        cg_object_unref(dev->renderer);

    dev->renderer = renderer;
}
예제 #24
0
void
cg_device_set_display(cg_device_t *dev, cg_display_t *display)
{
    if (display)
        cg_object_ref(display);

    if (dev->display)
        cg_object_unref(dev->display);

    dev->display = display;
}
예제 #25
0
static void
_rut_rectangle_free(void *object)
{
    rut_rectangle_t *rectangle = object;

    cg_object_unref(rectangle->pipeline);

    rut_graphable_destroy(rectangle);

    rut_object_free(rut_rectangle_t, object);
}
예제 #26
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);
}
예제 #27
0
static void
free_slices(cg_texture_2d_sliced_t *tex_2ds)
{
    if (tex_2ds->slice_textures != NULL) {
        int i;

        for (i = 0; i < tex_2ds->slice_textures->len; i++) {
            cg_texture_2d_t *slice_tex =
                c_array_index(tex_2ds->slice_textures, cg_texture_2d_t *, i);
            cg_object_unref(slice_tex);
        }

        c_array_free(tex_2ds->slice_textures, true);
    }
예제 #28
0
static void
simple_vertex_snippet(TestState *state)
{
    cg_pipeline_t *pipeline;
    cg_snippet_t *snippet;

    /* Simple vertex snippet */
    pipeline = cg_pipeline_new(test_dev);

    cg_pipeline_set_color4ub(pipeline, 255, 0, 0, 255);

    snippet = cg_snippet_new(CG_SNIPPET_HOOK_VERTEX,
                             NULL,
                             "cg_color_out.b += 1.0;");
    cg_pipeline_add_snippet(pipeline, snippet);
    cg_object_unref(snippet);

    cg_framebuffer_draw_rectangle(test_fb, pipeline, 10, 0, 20, 10);

    cg_object_unref(pipeline);

    test_cg_check_pixel(test_fb, 15, 5, 0xff00ffff);
}
예제 #29
0
static void
simple_fragment_snippet(TestState *state)
{
    cg_pipeline_t *pipeline;
    cg_snippet_t *snippet;

    /* Simple fragment snippet */
    pipeline = cg_pipeline_new(test_dev);

    cg_pipeline_set_color4ub(pipeline, 255, 0, 0, 255);

    snippet = cg_snippet_new(CG_SNIPPET_HOOK_FRAGMENT,
                             NULL, /* declarations */
                             "cg_color_out.g += 1.0;");
    cg_pipeline_add_snippet(pipeline, snippet);
    cg_object_unref(snippet);

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

    cg_object_unref(pipeline);

    test_cg_check_pixel(test_fb, 5, 5, 0xffff00ff);
}
예제 #30
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);
}