Exemple #1
0
static cg_texture_t *
make_texture (void)
{
  void *tex_data;
  uint32_t *p;
  cg_texture_t *tex;
  int partx, party, width, height;

  p = tex_data = c_malloc (TEXTURE_SIZE * TEXTURE_SIZE * 4);

  /* Make a texture with a different color for each part */
  for (party = 0; party < PARTS; party++)
    {
      height = (party < PARTS - 1
                ? PART_SIZE
                : TEXTURE_SIZE - PART_SIZE * (PARTS - 1));

      for (partx = 0; partx < PARTS; partx++)
        {
          uint32_t color = corner_colors[party * PARTS + partx];
          width = (partx < PARTS - 1
                   ? PART_SIZE
                   : TEXTURE_SIZE - PART_SIZE * (PARTS - 1));

          while (width-- > 0)
            *(p++) = C_UINT32_TO_BE (color);
        }

      while (--height > 0)
        {
          memcpy (p, p - TEXTURE_SIZE, TEXTURE_SIZE * 4);
          p += TEXTURE_SIZE;
        }
    }

  tex = test_cg_texture_new_from_data (test_dev,
                                          TEXTURE_SIZE,
                                          TEXTURE_SIZE,
                                          TEST_CG_TEXTURE_NO_ATLAS,
                                          CG_PIXEL_FORMAT_RGBA_8888_PRE,
                                          TEXTURE_SIZE * 4,
                                          tex_data);

  c_free (tex_data);

  if (test_verbose ())
    {
      if (cg_texture_is_sliced (tex))
        c_print ("Texture is sliced\n");
      else
        c_print ("Texture is not sliced\n");
    }

  /* The texture should be sliced unless NPOTs are supported */
  c_assert (cg_has_feature (test_dev, CG_FEATURE_ID_TEXTURE_NPOT)
            ? !cg_texture_is_sliced (tex)
            : cg_texture_is_sliced (tex));

  return tex;
}
Exemple #2
0
static void
print_statement(int num, cg_blend_string_statement_t *statement)
{
    const char *mask_names[] = { "RGB", "A", "RGBA" };
    int i;
    c_print("Statement %d:\n", num);
    c_print(" Destination channel mask = %s\n", mask_names[statement->mask]);
    c_print(" Function = %s\n", statement->function->name);
    for (i = 0; i < statement->function->argc; i++)
        print_argument(&statement->args[i]);
}
Exemple #3
0
void
test_primitive_and_journal (void)
{
  cg_primitive_t *primitives[2];
  cg_pipeline_t *pipeline;

  setup_orthographic_modelview ();
  create_primitives (primitives);
  pipeline = create_pipeline ();

  /* Set a clip to clip all three rectangles to just the bottom half.
   * The journal flushes its own clip state so this verifies that the
   * clip state is correctly restored for the second primitive. */
  cg_framebuffer_push_rectangle_clip (test_fb,
                                        0, 50, 300, 100);

  cg_primitive_draw (primitives[0], test_fb, pipeline);

  /* Draw a rectangle using the journal in-between the two primitives.
   * This should test that the journal gets flushed correctly and that
   * the modelview matrix is restored. Half of the rectangle should be
   * overriden by the second primitive */
  cg_framebuffer_draw_rectangle (test_fb,
                                   pipeline,
                                   100, 0, /* x1/y1 */
                                   300, 100 /* x2/y2 */);

  cg_primitive_draw (primitives[1], test_fb, pipeline);

  /* Check the three rectangles */
  test_cg_check_region (test_fb,
                           1, 51,
                           98, 48,
                           0xff0000ff);
  test_cg_check_region (test_fb,
                           101, 51,
                           98, 48,
                           0x00ff00ff);
  test_cg_check_region (test_fb,
                           201, 51,
                           98, 48,
                           0x0000ffff);

  /* Check that the top half of all of the rectangles was clipped */
  test_cg_check_region (test_fb,
                           1, 1,
                           298, 48,
                           0x000000ff);

  cg_framebuffer_pop_clip (test_fb);

  if (test_verbose ())
    c_print ("OK\n");
}
Exemple #4
0
void
test_npot_texture (void)
{
  if (test_verbose ())
    {
      if (cg_has_feature (test_dev, CG_FEATURE_ID_TEXTURE_NPOT))
        c_print ("NPOT textures are supported\n");
      else
        c_print ("NPOT textures are not supported\n");
    }

  cg_framebuffer_orthographic (test_fb,
                                 0, 0,
                                 cg_framebuffer_get_width (test_fb),
                                 cg_framebuffer_get_height (test_fb),
                                 -1,
                                 100);

  paint ();
  validate_result ();

  if (test_verbose ())
    c_print ("OK\n");
}
Exemple #5
0
void
test_depth_test (void)
{
  TestState state;

  cg_framebuffer_orthographic (test_fb, 0, 0,
                                 cg_framebuffer_get_width (test_fb),
                                 cg_framebuffer_get_height (test_fb),
                                 -1,
                                 100);

  paint (&state);

  if (test_verbose ())
    c_print ("OK\n");
}
Exemple #6
0
int mandelbrot ( _c c, int iter )
{
    _c x = {0.0, 0.0};
    int k;
    double m;

    for ( k=0; k<iter; ++k )
    {
        mfunc(x,c);
        m = sq_mod(x);
        if ( m>=4.0 )
        {
            break;
        }
    }
    c_print(x);
    printf("m = %f (%d)\n",m,k);

    return k;
}
Exemple #7
0
void
test_snippets(void)
{
    TestState state;

    state.fb_width = cg_framebuffer_get_width(test_fb);
    state.fb_height = cg_framebuffer_get_height(test_fb);

    cg_framebuffer_orthographic(test_fb,
                                0, 0,
                                state.fb_width,
                                state.fb_height,
                                -1,
                                100);

    run_tests(&state);

    if(test_verbose())
        c_print("OK\n");
}
Exemple #8
0
void
test_texture_mipmap_get_set (void)
{
  cg_texture_t *texture = make_texture ();

  cg_framebuffer_orthographic (test_fb,
                                 0, 0,
                                 cg_framebuffer_get_width (test_fb),
                                 cg_framebuffer_get_height (test_fb),
                                 -1,
                                 100);

  update_mipmap_levels (texture);
  paint (texture);

  validate_results ();

  if (test_verbose ())
    c_print ("OK\n");
}
void
_cg_debug_dump_pipelines_dot_file(const char *filename)
{
    c_string_t *graph;
    print_debug_state_t layer_state;
    print_debug_state_t pipeline_state;
    int layer_id = 0;
    int pipeline_id = 0;

    _CG_GET_DEVICE(dev, NO_RETVAL);

    if (!dev->default_pipeline)
        return;

    graph = c_string_new("");
    c_string_append_printf(graph, "digraph {\n");

    layer_state.graph = graph;
    layer_state.parent_id = -1;
    layer_state.node_id_ptr = &layer_id;
    layer_state.indent = 0;
    dump_layer_cb((cg_node_t *)dev->default_layer_0, &layer_state);

    pipeline_state.graph = graph;
    pipeline_state.parent_id = -1;
    pipeline_state.node_id_ptr = &pipeline_id;
    pipeline_state.indent = 0;
    dump_pipeline_cb((cg_node_t *)dev->default_pipeline, &pipeline_state);

    c_string_append_printf(graph, "}\n");

    if (filename)
        c_file_set_contents(filename, graph->str, -1, NULL);
    else
        c_print("%s", graph->str);

    c_string_free(graph, true);
}
Exemple #10
0
static void
print_argument(cg_blend_string_argument_t *arg)
{
    const char *mask_names[] = { "RGB", "A", "RGBA" };

    c_print(" Arg:\n");
    c_print("  is zero = %s\n", arg->source.is_zero ? "yes" : "no");
    if (!arg->source.is_zero) {
        c_print("  color source = %s\n", arg->source.info->name);
        c_print("  one minus = %s\n", arg->source.one_minus ? "yes" : "no");
        c_print("  mask = %s\n", mask_names[arg->source.mask]);
        c_print("  texture = %d\n", arg->source.texture);
        c_print("\n");
        c_print("  factor is_one = %s\n", arg->factor.is_one ? "yes" : "no");
        c_print("  factor is_src_alpha_saturate = %s\n",
                arg->factor.is_src_alpha_saturate ? "yes" : "no");
        c_print("  factor is_color = %s\n",
                arg->factor.is_color ? "yes" : "no");
        if (arg->factor.is_color) {
            c_print("  factor color:is zero = %s\n",
                    arg->factor.source.is_zero ? "yes" : "no");
            c_print("  factor color:color source = %s\n",
                    arg->factor.source.info->name);
            c_print("  factor color:one minus = %s\n",
                    arg->factor.source.one_minus ? "yes" : "no");
            c_print("  factor color:mask = %s\n",
                    mask_names[arg->factor.source.mask]);
            c_print("  factor color:texture = %d\n",
                    arg->factor.source.texture);
        }
    }
}
Exemple #11
0
void
test_allow_failure(void)
{
    c_print("WARNING: Test is known to fail\n");
}