Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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 texture.ml with:

let activate_texture tex = 
  let target = `texture_2d in
  let t = GlTex.gen_texture () in
  GlTex.bind_texture ~target t;
  GlPix.store (`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);
  t;;

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 =
      try
	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 GlList.call(Hashtbl.find m key) with Not_found ->
      let list = GlList.create `compile in
      draw_frame_triangles a b c d;
      GlList.ends();
      GlList.call list;
      Hashtbl.add m key list

then I'm back up to ~600fps.

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The OCaml Journal
http://www.ffconsultancy.com/products/ocaml_journal/?e