Playing around.. (Triple Buffer Display)

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
Rattrapmax6
Posts: 334
Joined: May 29, 2005 1:45
Location: At my Computer
Contact:

Playing around.. (Triple Buffer Display)

Post by Rattrapmax6 »

No,. I don't have a problem with a double buffer display, but, I got curious what would happen if I had a 3rd page to clean off the buffers insted of cleaning off the buffer then drawing on it at the same time..

It's the same effect as an Double buffer as far as maybe flicker,. tho in theory, it would sound as tho refresh rates might improve since it's cleaning, buffering, and viewing is done at the same time, opposed to cleaing and then drawing while viewing....

Oh well,. judge for yourself.. as I might be wrong.. =)

Code: Select all

'Triple Buffer Experament by Rattrapmax6
'  3Cylcle Page Buffer 

'In this buffer, pages are pre-cleaned before
' being drawn to, and pre-drawn before viewed on the 
' monitor. This was made with the goal of having a 
' fresh clean buffer page to draw on, oppose to cleaning
' and then drawing on a buffer page.. 

'3Cycle Example
'Page 0 gets cleaned, Page 1 gets graphics drawn on it, Page 2 is seen by the user
'Page 2 gets cleaned, Page 0 gets graphics drawn on it, Page 1 is seen by the user
' ... and so on

SCREENRES 640,480, 32, 3 ' Set 3 pages insted of 2

DIM SHARED AS INTEGER CP = 0, WP = 1, VP = 2 'Give the pages names

T! = TIMER
DO
    SCREENSET CP, VP ' Set screen that will clean
    CLS 'Pre-Clean the screen
    SCREENSET WP, VP 'Set screen to draw to, and the active video page
    SWAP VP, CP ' Swap the buffers for the next loop
    SWAP VP, WP ' 
    
    ' Draw the graphics...
    X! += V!
    IF X! > 640 THEN X! = 0
    CIRCLE (X!, 240), 50, RGB(255, 0, 0)
    L += 1
    FPS! = L / (TIMER - T!)
    V! = 500 / FPS!
LOOP UNTIL INKEY$ <> ""
cha0s
Site Admin
Posts: 5319
Joined: May 27, 2005 6:42
Location: USA
Contact:

Post by cha0s »

since you're doing 2 screensets and 2 swaps per cycle, i don't think you can expect to see any real improvement in performance, but.. i could be wrong
tunginobi
Posts: 655
Joined: Jan 10, 2006 0:44
Contact:

Post by tunginobi »

AFAIK, triple buffering works by giving the computer an opportunity to work on graphics pages which aren't in use.

Yes, there's the display page, and page being cleared and the working page, but I thought the whole idea behind triple buffering was to let the working page be drawn to while the clear page was being cleared. Operating on a single thread, I'm not sure if that's possible the way you've set it up here.

And that's all on the assumption that page flipping isn't being emulated internally by FreeBASIC using double buffering on some platforms. It probably isn't, but it's a point to consider.
Rattrapmax6
Posts: 334
Joined: May 29, 2005 1:45
Location: At my Computer
Contact:

Post by Rattrapmax6 »

So I just have an Hyped up double buffer here? lol .. I was starting to think that since code structure wise CLS still comes b4 the drawing,.. like I said above, I might be wrong,.. =)

How hard is threading neway? ^_-
tunginobi
Posts: 655
Joined: Jan 10, 2006 0:44
Contact:

Post by tunginobi »

I'm ont 100% sure you even have to have a multithreaded solution, or if it's even the best way to approach it.

If you're really interested in threads, here's a place to start:
http://www.freebasic.net/wiki/wikka.php ... utexCreate

In your code, CLS would have to operate more or less concurrently with the drawing code. But don't quote me on that.
DrV
Site Admin
Posts: 2116
Joined: May 27, 2005 18:39
Location: Midwestern USA
Contact:

Post by DrV »

Actually, FB does not use any hardware acceleration for "page flipping" - all surfaces are just normal system memory. The gfxlib internally double buffers the screen already. True triple buffering requires hardware page flipping to be effective.
Post Reply