Source

clutter-ocaml / src / ml_cogl.c

#include "wrappers.h"
#include "cogl_tags.h"
#include "cogl_tags.c"
#include "ml_coglbox.h"
#include "ml_clutter.h"
#include <caml/bigarray.h>
#include <assert.h>

#define Fixed_val Int_val
#define Angle_val Int_val

/** Util API */
ML_0(cogl_create_context, Val_bool)
ML_0(cogl_destroy_context, Unit)
ML_1(cogl_paint_init, ClutterColor_val, Unit)
ML_2(cogl_check_extension, String_val, String_val, Val_bool)
// cogl_features_available

/** General API */
ML_4(cogl_perspective, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Unit)
ML_6(cogl_setup_viewport, Int_val, Int_val, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Unit)
ML_bc6(ml_cogl_setup_viewport)
// get_modelview_matrix,
// get_projection_matrix
// get_viewport
ML_0(cogl_pop_matrix, Unit)
ML_0(cogl_push_matrix, Unit)
ML_2(cogl_scale, Fixed_val, Fixed_val, Unit)
ML_3(cogl_translatex, Fixed_val, Fixed_val, Fixed_val, Unit)
ML_3(cogl_translate, Int_val, Int_val, Int_val, Unit)
ML_4(cogl_rotatex, Fixed_val, Int_val, Int_val, Int_val, Unit)
ML_4(cogl_rotate, Int_val, Int_val, Int_val, Int_val, Unit)
ML_4(cogl_clip_set, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Unit)
ML_0(cogl_clip_unset, Unit)
ML_1(cogl_enable_depth_test, Bool_val, Unit)
ML_2(cogl_alpha_func, Alpha_func_val, Fixed_val, Unit)
ML_4(cogl_fog_set, ClutterColor_val, Fixed_val, Fixed_val, Fixed_val, Unit)

/** PATH API */
ML_1(cogl_color, ClutterColor_val, Unit)
ML_0(cogl_path_fill, Unit)
ML_0(cogl_path_stroke, Unit)
ML_2(cogl_path_move_to, Fixed_val, Fixed_val, Unit)
ML_0(cogl_path_close, Unit)
ML_2(cogl_path_line_to, Fixed_val, Fixed_val, Unit)
ML_6(cogl_path_curve_to, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Unit)
ML_bc6(ml_cogl_path_curve_to)
ML_6(cogl_path_arc, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Angle_val, Angle_val, Unit)
ML_bc6(ml_cogl_path_arc)
ML_2(cogl_path_rel_move_to, Fixed_val, Fixed_val, Unit)
ML_2(cogl_path_rel_line_to, Fixed_val, Fixed_val, Unit)
ML_6(cogl_path_rel_curve_to, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Unit)
ML_bc6(ml_cogl_path_rel_curve_to)
ML_4(cogl_path_line, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Unit)
// cogl_path_polyline
// cogl_path_polygon
ML_4(cogl_path_rectangle, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Unit)
ML_6(cogl_path_round_rectangle, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Angle_val, Unit)
ML_bc6(ml_cogl_path_round_rectangle)
ML_4(cogl_path_ellipse, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Unit)
ML_4(cogl_rectangle, Int_val, Int_val, Int_val, Int_val, Unit)
ML_4(cogl_rectanglex, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Unit)

/** Texture API */
Make_Val_final_pointer_ext(CoglHandle, _new, Ignore, cogl_texture_unref, 5)
ML_5(cogl_texture_new_with_size, Int_val, Int_val, Int_val, Bool_val, Pixel_format_val, Val_CoglHandle_new)

CAMLprim value
ml_cogl_texture_new_from_file(value file, value max_waste, value mipmap, value format) {
  CAMLparam4(file, max_waste, mipmap, format);
  GError *err = NULL;
  CoglHandle h = cogl_texture_new_from_file
    (String_val(file), Int_val(max_waste), Bool_val(mipmap),
     Pixel_format_val(format), &err);
  if (err) ml_raise_gerror(err);
  CAMLreturn(Val_CoglHandle_new(h));
}

CAMLprim value
ml_cogl_texture_polygon(value _handle, value _vertices, value _use_color)
{
  CAMLparam3(_handle, _vertices, _use_color);
  assert(Tag_val(_vertices) == 0);
  int n = Wosize_val(_vertices);
  static CoglTextureVertex verts[32];
  int i;
  for (i=0; i<n; i++) {
    value v = Field(_vertices,i);
    assert(Tag_val(v) == 0);
    assert(Wosize_val(v) == 6);
    verts[i].x = Int_val(Field(v,0));
    verts[i].y = Int_val(Field(v,1));
    verts[i].z = Int_val(Field(v,2));
    verts[i].tx = Int_val(Field(v,3));
    verts[i].ty = Int_val(Field(v,4));
    printf("vertex: %d,%d,%d  %d,%d  %d (%d)\n", verts[i].x, verts[i].y, verts[i].z,
	   verts[i].tx, verts[i].ty, CFX_ONE, CLUTTER_INT_TO_FIXED(320));
    verts[i].color = *(ClutterColor*)Pointer_val(Field(v,5));
  }
  cogl_texture_polygon(Pointer_val(_handle), n, verts, Bool_val(_use_color));
  CAMLreturn(Val_unit);
}

CAMLprim value
ml_cogl_texture_new_from_data(value _w, value _h, value _max_waste,
			      value _auto_mipmap, value _format,
			      value _internal_format, value _rowstride,
			      value _data)
{
  CAMLparam5(_w, _h, _max_waste, _auto_mipmap, _format);
  CAMLxparam3(_internal_format, _rowstride, _data);
  struct caml_ba_array* ba = Caml_ba_array_val(_data);
  CoglHandle t = cogl_texture_new_from_data
    (Int_val(_w), Int_val(_h), Int_val(_max_waste), Bool_val(_auto_mipmap),
     Pixel_format_val(_format), Pixel_format_val(_internal_format),
     Int_val(_rowstride), ba->data);
  CAMLreturn(Val_CoglHandle_new(t));
}
			
// IS pointer_val what we want here? or just an opaque type?
//ML_8(cogl_texture_new_from_data, Int_val, Int_val, Int_val, Bool_val, Pixel_format_val, Pixel_format_val, Int_val, Pointer_val, Val_CoglHandle_new)
ML_bc8(ml_cogl_texture_new_from_data)
// cogl_texture_new_from_foreign
ML_1(cogl_is_texture, Pointer_val, Val_bool)
ML_1(cogl_texture_get_width, Pointer_val, Val_int)
ML_1(cogl_texture_get_height, Pointer_val, Val_int)
ML_1(cogl_texture_get_format, Pointer_val, Val_pixel_format)
ML_1(cogl_texture_get_rowstride, Pointer_val, Val_int)
ML_1(cogl_texture_get_max_waste, Pointer_val, Val_int)
// get_min_filter
// get_max_filter
ML_1(cogl_texture_is_sliced, Pointer_val, Val_bool)
// get_gl_texture
// get_data
// set_filters
// set_region
ML_1(cogl_texture_ref, Pointer_val, Val_CoglHandle_new) // ? 
ML_1(cogl_texture_unref, Pointer_val, Unit)
ML_9(cogl_texture_rectangle, Pointer_val, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Fixed_val, Unit)
ML_bc9(ml_cogl_texture_rectangle)
// texture_polygon