caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] f#/mono vs ocaml runtime system - open gl animation screen tearing.
@ 2011-04-26 19:15 Peter Ronnquist
  2011-04-26 19:30 ` Gabriel Scherer
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Peter Ronnquist @ 2011-04-26 19:15 UTC (permalink / raw)
  To: caml-list

Hi all,

I have been experimenting with f# and mono on debian linux and
compared it with ocaml.
I am interested in visual presentations for example games and in my
tests f# + mono + opentk was able to make completely smooth animations
using opengl (opentk) on debian 6.0 (squeeze).

Ocaml + lablgl gives "stutters" in the animation within the period of
a couple of seconds. The animation runs smooth for a couple of seconds
and then the animation update is disturbed with the result that the
image is "teared". The tearing lasts only for a fraction of second but
is visible for a trained eye.

I suspected that the GC could be a cause for this and I tried to
manipulate the GC settings but I could not get a completely smooth
animation for a longer period of time.

This is completely acceptable for many applications but for making a
game or for the meticulous graphical applicaton user it is not ideal.

My thought is that maybe f#/mono unboxes more values than ocaml and in
this way the GC doesn't need to work as hard?

My question really is if you think it is worthwhile to investigate the
runtime system for mono and compare it with the runtime system for
ocaml to locate the differences that might influence the animation and
then even update the ocaml runtime system to use a similar strategy
as the f# runtime system?

I would be interested in this but it would be nice to first hear from
the list if this is a good idea. I also read in the Jane Street blog
(http://ocaml.janestreet.com/?q=node/89) that ocamlpro might work on
the ocaml runtime system (including unboxing).

Best Regards
Peter Ronnquist

^ permalink raw reply	[flat|nested] 10+ messages in thread
[parent not found: <fa.bAPY0rzAUUqrEHcCwn9toRc5oMo@ifi.uio.no>]
* [Caml-list] f#/mono vs ocaml runtime system - open gl animation screen tearing.
@ 2011-05-01 14:24 Peter Ronnquist
  0 siblings, 0 replies; 10+ messages in thread
From: Peter Ronnquist @ 2011-05-01 14:24 UTC (permalink / raw)
  To: caml-list

While making the simple examples for SDL+opengl for the C language I
realized that even the C version showed "stuttering" but the fsharp
version is completely smooth and synced to the vblank.
Appearantly the fsharp version somehow manages to sync to the vblank
probably thanks to  the openTK api:

  do base.VSync <- VSyncMode.On

I had to configure the nvidia driver with
X Server XVideo Settings:
Video Texture Adaptor -> Sync to VBlank
Video Blitter Adaptor Settings -> Sync to VBlank

OpenGL Settings
Performance -> Sync to VBlank
                   -> Allow Flipping

then both the C sdl opengl version and ocaml sdl openg version worked smoothly.

So to sum it up, I had the wrong setting of the nvidia driver and was
fooled sinced the fsharp version still synced with the vblank.

I am posting the ocaml sdl openg test program here in case someone
would like to try it on debian 6 squeeze:

Sorry for the "false alarm", it was not ocamls fault,  and thank you
for the good advice.

(*

 Using opengl, sdl and revised syntax.

 Compile with:

 camlopt -pp camlp4r -I . -I +sdl -I +lablgl bigarray.cmxa sdl.cmxa
lablgl.cmxa unix.cmxa  str.cmxa simple2.ml -o simple2

*)

open Sdlevent;
open Sdlkey;
open Sdlgl;

(* Window size in pixels *)
value x_size_window = 512;
value y_size_window = 512;

(* Space coordinates *)
value upper_size = 1.5;
value lower_size = -1.5;
value left_size = -1.5;
value right_size = 1.5;

value init_gl width height = do {
  GlDraw.viewport ~x:0 ~y:0 ~w:width ~h:height;
  GlClear.color (0.0, 0.0, 0.0) ~alpha:0.0;
  GlClear.clear [`color; `depth];
  GlDraw.shade_model `smooth;
  GlMat.load_identity ();

  GlClear.color (0.1, 0.3, 0.1);
  GlDraw.shade_model `smooth;
};

value time =
  let start = Unix.gettimeofday () in fun () -> Unix.gettimeofday () -. start
;

value key_left_is_down = ref False;
value key_right_is_down = ref False;


(* Start of program *)
value () =

    do {

    Sdl.init [`VIDEO];
    at_exit Sdl.quit;


    set_attr [DOUBLEBUFFER True];
    ignore (Sdlvideo.set_video_mode x_size_window y_size_window
[`OPENGL ; `DOUBLEBUF ; `RESIZABLE ; `HWSURFACE]);
    init_gl x_size_window y_size_window;

    let render () =
      do {

    GlMat.mode `projection;
    GlMat.load_identity ();
    GluMat.ortho2d ~x:(-1.5, 1.5) ~y:(-1.5, 1.5);
    GlMat.mode `modelview;
    GlMat.load_identity ();
    GlClear.clear [ `color ; `depth];

    GlMat.translate ~x:(sin (time ()*.2.0) *. 1.) ~z:1. ();
    GlDraw.begins `quads;
      List.iter GlDraw.vertex2 [
        ( -0.2, -0.5);
	  (0.2, -0.5);
	    (0.2, 0.5);
	      (-0.2, 0.5)];

    GlDraw.ends ();
    Gl.flush ();
    Sdlgl.swap_buffers ();

    }
    in
      let quit_loop = ref False in
      while not quit_loop.val  do {
	(* Calculate elapsed time since last rendering *)
	  render ();
	

        match Sdlevent.poll () with
        [ Some( KEYDOWN {keysym = KEY_ESCAPE} ) -> do {
          print_endline "You pressed escape! The fun is over now.";
          quit_loop.val := True
        }
        | Some( KEYDOWN {keysym = KEY_LEFT} ) -> do {
          key_left_is_down.val := True;
        }
        | Some( KEYDOWN {keysym = KEY_RIGHT} ) -> do {
          key_right_is_down.val := True;
        }
        | Some( KEYUP {keysym = KEY_LEFT} ) -> do {
          key_left_is_down.val := False;
        }
        | Some( KEYUP {keysym = KEY_RIGHT} ) -> do {
          key_right_is_down.val := False;
        }
        | Some event -> do {
          print_endline (string_of_event event);
        }
        | None -> ()
        ]

      };

};

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-05-01 14:24 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-26 19:15 [Caml-list] f#/mono vs ocaml runtime system - open gl animation screen tearing Peter Ronnquist
2011-04-26 19:30 ` Gabriel Scherer
2011-04-26 20:16   ` Peter Ronnquist
2011-04-26 19:39 ` Török Edwin
2011-04-26 20:37   ` Anthony Tavener
2011-04-27  6:51 ` rixed
2011-04-27 10:02 ` Jon Harrop
2011-04-27 21:08   ` Peter Ronnquist
     [not found] <fa.bAPY0rzAUUqrEHcCwn9toRc5oMo@ifi.uio.no>
2011-04-26 20:38 ` Ethan Burns
2011-05-01 14:24 Peter Ronnquist

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).