Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
ANN: Chess III Arena 0.5
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-07-05 (12:58)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] ANN: Chess III Arena 0.5
On Thursday 05 July 2007 08:45:49 Daniel Bünzli wrote:
> No, it can result in a slow down even if it is harwdare rendered, the
> effect of your "optimization" is implementation dependent.

Can you quantify that: what implementations? how much slow down?

> The  
> problem is that glTexImage2d cannot be compiled efficently in a
> display list (see the bottom of this page [1] for why this is the
> case).

If "glTexImage2d cannot be compiled efficently in a display list" why does 
this optimization show an enormous performance improvement here?

Anyway, you can use texture objects by supplementing with:

let activate_texture tex = 
  let target = `texture_2d in
  let t = GlTex.gen_texture () in
  GlTex.bind_texture ~target t; (`unpack_alignment 1);
  GlTex.image2d tex;
  List.iter (GlTex.parameter ~target)
      [ `wrap_s `clamp;
        `wrap_t `clamp;
        `mag_filter `linear;
        `min_filter `linear ];
  GlTex.env (`mode `modulate);

let m = Hashtbl.create 1

let set_current_texture texname =
  try GlTex.bind_texture ~target:`texture_2d (Hashtbl.find m texname)
  with Not_found ->
    let tex =
	activate_texture (Hashtbl.find textures texname)
      with Not_found ->
	activate_texture (Hashtbl.find textures "unknown") in
    Hashtbl.add m texname tex

This gives me ~50fps without any display lists. If I memoize vertex data 
generated by Md3.draw_frame_triangles as well:

let draw_frame_triangles =
  let m = Hashtbl.create 1 in
  fun a b c d ->
    let key = (a, b, c, d) in
    try m key) with Not_found ->
      let list = GlList.create `compile in
      draw_frame_triangles a b c d;
      GlList.ends(); list;
      Hashtbl.add m key list

then I'm back up to ~600fps.

Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The OCaml Journal