Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2003:
[Freeciv-Dev] NEW BUFFER CODE TO SDLClient
Home

[Freeciv-Dev] NEW BUFFER CODE TO SDLClient

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: "freeciv-dev@xxxxxxxxxxx" <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] NEW BUFFER CODE TO SDLClient
From: Rafał Bursig <bursig@xxxxxxxxx>
Date: Mon, 10 Feb 2003 00:43:44 +0100

Hi

  Attached code is new buffer engine to SDLClient.

Till now SDLClient has only one buffer
- main client buffer.

 draw :
                                                flush
  sprite -> main client buffer    ->     framebuffer.

All draw was done to this buffer, then we had to call flush function ( manualy ) tu copy this buffer to framebuffer. This method was fast but have big overwrite problem ( when you redraw somthing you overwrite city text or gui widget ) and there still lack redraw sdl widget callback ( after redraw full screen map )

New code obsolete almost all of those problems but for price of speed. :(

Basic idea of new code is simple, there are 4 main screen buffers :
- main client buffer.
- map buffer ( for terrain, specials, unit, cities, etc )
- city desciption buffer ( for city text )
- gui/widgets buffer ( here is draw entire gui )

draw sequence : 1 , 2, 3, 4 , 5

 draw map buffer to main buffer
 draw city text buffer to main buffer
 draw gui buffer to main buffer
 draw main buffer to framebuffer.

I) unit or terrain

gui buffer 4)-> city text buffer 3) -> map buffer 2) -> main buffer 5) -> framebuffer
                                                              /\
| 1) unit or terrain sprite

II) update city text

gui buffer 4) -> city text buffer 3) -> map buffer 2) -> main buffer 5) -> framebuffer
                                   /\
| 1) clear buffer and redraw city texts

III) widget action ( exp. press button )

gui buffer 4) -> city text buffer 3) -> map buffer 2) -> main buffer 5) -> framebuffer
           /\
            | 1)                    widget acction

Create map buffer didn't make any trouble. It has screen pixel coding and draw to screen is fast.

City description buffer create on big problem becouse SDLClient use AA text. This AA is reslut of use alpha chanel on font color. When we want use buffored text then this buffor must have alpha chanel (RGBA surface 32bit pixel coding) to proper store AA text info. And this will cost during blit(draw) operation becouse there is alpha calculation. Additonal problem give SDL lib becouse all Alpha blit operation "lock" destination pixel alpha value and all result of Alpha draw has old dest alpha value.

exp.
Buffer was filed partial transparent white ( r = 255, g = 255, b = 244, a = 128 ). Next we blit (draw) on it notransparent black (r =0, g =0, b=0, a = 255 ) rect.
    Result is rect filed with color r = 0, g = 0, b = 0 , a = 128.
When you blit this buffer to screen you see partial transparent white area with partial transparetn
    black area.

This is big problem becouse entire text buffer is filed with total transparent black ( r = 0, g = 0, b = 0, a = 0). All draw to such buffer must be done with disabled alpha calculation but this work fine if we use only freeciv text style ( no background ). When we want have civ3 text style we fill text arrea partial transparent background color and blit on it ( with alpha calculation ) text . I this way we get partial transparent text and that is wrong. Solution on this problem is fix to SDL_ttf lib that make avilable createing AA text with partial transparent colored background. ( blended_shaded_2.diff). I send this patch to SDL_ttf lib maintainer but has no response. Any way If you want use this new buffered code you must patch SDL_ttf lib code and rebuild it.

GUI buffer has the same problem that city desciption buffer ( must be RGBA ) but is solved by patching SDL_ttf lib. Other problem here is that entire gui code has hard coded destination draw to main client buffer, and must be rewriten to new buffer code ( this take lots of work ). Here is another problem with partial transparent dialogs/window. When those are draw above other dialogs/window, this draw must be done with disable alpha calculation and all other dlg/window areas are redrawed by upper dlg/windows, but this is current must be acceptable.

SPEED.
This is important aspect of this code becouse if you want redraw somthing on map you must atomaticaly redraw all buffers, and this take time.

                     alpha callc.
gui buffer -------------------- slow \
                                               \
                       alpha callc.       \
text buffer  --------------------------- > main buffer -> frame buffer
slow / /
map buffer   ---------------
                         fast

All those buffer draw is make during flush time. To optimize ( speedup ) this flush I create new flush code that is attached to this new buffer code. ( All draw are made only to buffers and draw area are saved in store rect. array. After last net packed come there is called flush function that flush all stored rects in one call)

Please send me timing output of this code.

Rafal


----------------------------------------------------------------------
Powiedz sobie dobre "Dzien dobry"! >>> http://link.interia.pl/f168b

Attachment: 4buffer.diff.bz2
Description: application/bzip

Attachment: blended_shaded_2.diff
Description: Text document


[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] NEW BUFFER CODE TO SDLClient, Rafał Bursig <=