[wxruby-users] Tearing in my buffered animation test script...

Alex Fenton
Fri, 28 Mar 2008 00:17:24 -0000

Hi Paul

Paul w Florczykowski wrote:
> I have tested your application, and indeed there is great deal of
> flicker as expected. You are not making any particular errors in your
> code; the problem occurs because the drawing, or more precisely, the
> copying of graphics (blit) is not synchronized with the vertical sync
> signal your screen receives from your graphics card. (I''m speaking
in
> terms of analog signal CRT, but actually this applies to any kind of
> digital screen as well, as far the application is concerned)
>
> The usual way to deal with this is:
>
> 1. Draw all the graphics onto an backbuffer (any surface that does not
> appear on the screen yet)
>
> 2. Await the V-blank (the vertical sync signal)
>
> 3. Copy the contents of this backbuffer onto the screen (the
> frontbuffer), or simply swap the buffers if your API supports it
>
> 4. repeat from 1
>
I didn''t know about (2), thanks for this info on
buffering.
> What you are currently doing is similar but lacks the point (2). wxRuby
> aims to support this on a lower level (i think). There is a method
> called "paint_buffered" (in stead of "paint") that
provides a
> BufferedDC-object instead of ClientDC or DC. Drawing to the BufferedDC
> is then not supposed to be visible first after: 1. the actual drawing
> you are making on it is finally completed ie. the block provided to
> "buffered_paint" finishes, and 2. the V-blank occurs.
>
> Sadly enough, this feature does not seem to be working properly with
> wxruby 1.9.5. I have currently similar problem - have not yet decided
> whether to devise another method to signal V-blank to Ruby, or to accept
> the moderate flicker in my application.
>
wxRuby 1.9.5 ''paint_buffered'' method does what you describe,
lacking
point (2). It doesn''t do anything more low-level. It''s
implemented in
pure Ruby,

http://wxruby.rubyforge.org/svn/trunk/wxruby2/lib/wx/classes/window.rb

but it''s a straight conversion of the C++ code that wxWidgets uses to
provide BufferedDC:

http://svn.wxwidgets.org/viewvc/wx/wxWidgets/tags/WX_2_8_7/include/wx/dcbuffer.h?revision=52270&view=markup

If you find any advice on how we can improve this by synchronising with
the V-blank please post this, as this is beyond my expertise.

thanks
alex