Re: [AD] set_display_mode and screen update handling

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Fri, 2004-07-30 at 20:45 -0700, Chris wrote:
> As I mentioned before I had a couple functions lying around that would 
> handle setting a video mode with a screen update method and an 
> acompanying screen update function. I attached a C source file that has 
> these functions.
> 

> Plain text document attachment (modefuncs.c)
> /* The bitmaps we'll be drawing to */
> static BITMAP *page[3];

I don't know, in my implementations of this function (I guess everyone
uses a wrapper around set_gfx_mode :), I use this:

BITMAP *front_buffer, *back_buffer, *middle_buffer;

And swap those variables around. No need for a current_page variable,
and the code gets cleaner IMO.

> static int current_page;
> 
> #define DOUBLE_BUFFER  0x00000001
> #define PAGE_FLIP      0x00000002
> #define TRIPLE_BUFFER  0x00000004
> #define WINDOWED       0x00000008
> #define FULLSCREEN     0x00000010
> 

If you request: TRIPLE_BUFFER | PAGE_FLIP, should it do page flipping if
triple buffering isn't possible?

> /* Sets the requested mode, returning the bitmap you should start drawing on.
>  * Pass 0 for all four arguments to properly shutdown the gfx mode.
>  */
> BITMAP *set_display_mode(int w, int h, int bpp, int flags)
> {

I think, the bpp could be defines as well. E.g. I'd like to do:

set_display_mode (640, 480, DEPTH_TRUECOLOR, 0);

DEPTH_TRUECOLOR would be DEPTH_16_BIT | DEPTH_15_BIT | DEPTH_24_BIT |
DEPTH_32_BIT

Almost all my programs work in any color depth (even 8-bit). So it would
be a shame if I'd still need the:

if (set_display_mode (...,8,))
  if (set_display_mode (...,15,)) ..
    ...

There could even be a AL_TRY_DESKTOP_DEPTH_FIRST, and it would detect
the desktop color depth and try with that first. Very useful e.g. for
windowed modes, where you don't want color onversion, but don't care
about the depth otherwise.


> /* Displays what was drawn to the page last returned by this function. If
>  * vs is true, vsync() will be called before blitting in double buffer
>  * mode. Returns the next bitmap you should start drawing on.
>  */
> BITMAP *show_page(int vs)
> {

I guess the vs should be not a parameter here, but specified in the call
to set_display_mode. After all, it has no meaning for anything but
double buffer.

> 
> /* Returns the current screen bitmap buffer. This is not gauranteed to remain
>  * constant across show_page() calls. */

Very often, you also need the front buffer. E.g. when doing page
flipping, but then you use the GUI file selector. screen could be the
back page in that case. With my method, there'd be 3 global variables to
get up to 3 pages (or just a wrapper get_front_page would do as well).

-- 
Elias Pschernig





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/