Lazy Benchmark: Toggling GFX_ALPHA_PRIMITIVES

Post your FreeBASIC tips and tricks here. Please don’t post your code without including an explanation.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Lazy Benchmark: Toggling GFX_ALPHA_PRIMITIVES

Postby anonymous1337 » Aug 18, 2010 14:07

Preliminary Results:

Code: Select all

Alpha Enabled: 1.675214677326039
Alpha Disabled: 0.2554196185609499

Screenres is called with alpha enabled. Alpha is then disabled and the test repeats.

Code: Select all

#include once "fbgfx.bi"
#macro GFX_toggleAlpha()
    scope
        '' Get if alpha primitives are enabled
        dim as integer alphaEnabled = any
        ..screenControl( fb.GET_ALPHA_PRIMITIVES, alphaEnabled )
       
        '' Toggle alpha
        alphaEnabled = not alphaEnabled
        ..screenControl( fb.SET_ALPHA_PRIMITIVES, alphaEnabled )
    end scope
#endmacro
#macro GFX_alphaOff()
    screenControl( fb.SET_ALPHA_PRIMITIVES, 0 )
#endmacro
#macro GFX_alphaOn()
    screenControl( fb.SET_ALPHA_PRIMITIVES, -1 )
#endmacro


screenres 640, 480, 32,,fb.GFX_ALPHA_PRIMITIVES
randomize( timer() )
dim as double timerBegin, time1, time2
print "Hit any key to start the test."
sleep


'' Test alpha on
timerBegin = timer()
for i as integer = 0 to 10000
    line (rnd() * 640, rnd() * 480) - (rnd() * 640, rnd() * 480), (rnd() * 256^3) or rgba(0, 0, 0, rnd() * 255), bf
next
time1 = timer() - timerBegin

'' Turn off alpha
GFX_alphaOff()

'' Test alpha off - GFX_ALPHA_ENABLED declared to ScreenRes but disabled for the following primitives
timerBegin = timer()
for i as integer = 0 to 10000
    line (rnd() * 640, rnd() * 480) - (rnd() * 640, rnd() * 480), (rnd() * 256^3) or rgba(0, 0, 0, rnd() * 255), bf
next
time2 = timer() - timerBegin


'' Display results
print "Alpha Enabled: "  & time1
print "Alpha Disabled: " & time2
open cons for output as #1
    print #1, "Alpha Enabled: "  & time1
    print #1, "Alpha Disabled: " & time2
close #1
sleep
Definitely good news - this feels more like OpenGL.
Call screenres with alpha, disable it, then enable it as needed.

My benchmark for screenres with alpha then disabled alpha == screenres without alpha.
Landeel
Posts: 704
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Postby Landeel » Aug 18, 2010 17:44

Alpha Enabled: 1.5934898853302
Alpha Disabled: 0.6953749656677246
badmrbox
Posts: 659
Joined: Oct 27, 2005 14:40
Location: Sweden
Contact:

Postby badmrbox » Aug 19, 2010 14:23

Alpha Enabled: 0.7846841505203774
Alpha Disabled: 0.1156998466391843
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Postby vdecampo » Aug 19, 2010 14:58

Alpha Enabled: 1.360305980488192
Alpha Disabled: 0.2043955074041151


-Vince
kiyotewolf
Posts: 1009
Joined: Oct 11, 2008 7:42
Location: ABQ, NM
Contact:

Postby kiyotewolf » Aug 21, 2010 4:43

O.O!!

You can turn that off and on mid-program?

I was just thinking this was impossible!

Oooh awesome.



~Kiyote!
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Postby anonymous1337 » Aug 21, 2010 16:01

Yup, that's why I posted. I'm hoping more people will turn GFX_ALPHA_PRIMTIVES on by default, and simply turn it off until they need it.

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 1 guest