Quote: "Any idea on the performance increase? Is it significant?"
It's almost impossible to guess what the performance difference will be.
But the difference should be greater, the slower your device is!
I've thrown together a small TIER1 benchmark for you. It's based on the Benchmarking demo included with AppGameKit, but allows you to use keyboard controls to change a few settings on the fly. This should help you see if "EnableClearColor" makes any difference. The benchmark has built-in keyboard help, so it should be easy to figure out.
(But it's sort of difficult to use on a touch screen without a keyboard! Sorry. You might need to add UI controls to the code...)
And I recommend grabbing the attached zip.. because there are a few media files included, so the source alone is pretty useless.
//=============================================================================
//### FILEHEADER
//-----------------------------------------------------------------------------
//
// Filename: main.agc
// Title: AGK EXAMPLE - Benchmarking
//
// Version: 1.00, Build 0002
// Created: 2013-05-28 by AgentSam (based on AGK Benchmark example)
// Last modified: 2013-05-28 by AgentSam
//
// Project state: Published on the AGK forums
// Release type: Public domain
//
// Compatibility: Tested with AGK 107.06, AGK 108.11, AGK 108.12
//
// Programmer's notes
// ==================
//
// o The benchmarking commands within AGK can be used to get
// information about what's happening at runtime, such as
// the number of sprites being drawn or the amount of time
// that the physics simulation is using.
//
// o This version of the benchmarking test was modified to
// answer a question posted on the AGK forums:
// http://forum.thegamecreators.com/?m=forum_view&t=205733&b=41&msg=2459099#m2459099
//
// Revision History
// ================
//
// o 2013-05-28, AgentSam
// - NEW BUILD: 1.00, Build 0002
// - NOTES: Project started
//
// To Do
// =====
//
// o 2013-05-28, AgentSam
// - No pending tasks.
//
//---------------------------------------------------------------------------
//=============================================================================
//### SECTION - DISPLAY SETUP (VIRTUAL RESOLUTION)
//-----------------------------------------------------------------------------
// Portrait orientation using pixel based coordinates
SetVirtualResolution (320, 480)
// Set mipmaps and filters
SetGenerateMipmaps (0)
SetDefaultMinFilter (1)
SetDefaultMagFilter (1)
// Set text output properties
SetPrintSize (12)
SetPrintColor (255, 255, 255)
// Set backbuffer properties
SetClearColor (255, 0, 0)
SetBorderColor ( 32, 32, 255)
//=============================================================================
//### SECTION - CONSTANTS
//-----------------------------------------------------------------------------
// Sprite limit
#constant C_MAXSPRITES 10
// Boolean truth values
#constant TRUE 1
#constant FALSE 0
// String constants
#constant C_QUOTE Chr(34)
#constant C_CR Chr(13)
#constant C_LF Chr(10)
#constant C_CRLF Chr(13)+Chr(10)
// Keyboard scancodes
#constant KEY_F1 0x70
#constant KEY_ESCAPE 0x1B
#constant KEY_A 0x41
#constant KEY_B 0x42
#constant KEY_C 0x43
#constant KEY_D 0x44
#constant KEY_E 0x45
#constant KEY_F 0x46
#constant KEY_G 0x47
#constant KEY_H 0x48
#constant KEY_I 0x49
#constant KEY_J 0x4A
#constant KEY_K 0x4B
#constant KEY_L 0x4C
#constant KEY_M 0x4D
#constant KEY_N 0x4E
#constant KEY_O 0x4F
#constant KEY_P 0x50
#constant KEY_Q 0x51
#constant KEY_R 0x52
#constant KEY_S 0x53
#constant KEY_T 0x54
#constant KEY_U 0x55
#constant KEY_V 0x56
#constant KEY_W 0x57
#constant KEY_X 0x58
#constant KEY_Y 0x59
#constant KEY_Z 0x5A
// Step values
#constant C_STEP_ALPHA 40
#constant C_STEP_DEPTH 20
#constant C_STEP_SYNCRATE 10
//=============================================================================
//### SECTION - DATA TYPES
//-----------------------------------------------------------------------------
type TBackground
iSpriteID as integer
iAlpha as integer
iDepth as integer
bVisible as integer
endtype
//=============================================================================
//### SECTION - DECLARE GLOBAL VARIABLES
//-----------------------------------------------------------------------------
// Arrays for sprites
global dim g_fSpeed [C_MAXSPRITES] as float // Sprite speed
global dim g_fMove [C_MAXSPRITES] as float // Movement position along the cosine curve
// State flags
global g_bReadyToFire as integer
global g_bEnableClearColor as integer
global g_bEnableClearDepth as integer
global g_iSyncRate as integer
global g_bShowInfo as integer
// Min/Max offscreen positions for the right-edge
global g_iMinOffscreenX as integer
global g_iMaxOffscreenX as integer
// Image IDs
global g_imgParticle as integer
global g_imgBall as integer
// Particle generator IDs
global g_peParticles as integer
// Sprite IDs
global dim g_sprBalls[C_MAXSPRITES] as integer
global g_sprBackground as TBackground
// Temporary variables
global g_fXPos as float
global g_fYPos as float
// Last keypress
global g_iKBLastKeypress as integer
//=============================================================================
//### SECTION - INITIALIZE GLOBAL VARIABLES
//-----------------------------------------------------------------------------
// Set the "ready" flag for particles
g_bReadyToFire = 1
// Min/Max offscreen positions for the right-edge
g_iMinOffscreenX = GetVirtualWidth()
g_iMaxOffscreenX = GetVirtualWidth() + 200
// Initialize background properties
g_sprBackground.iAlpha = 15
g_sprBackground.iDepth = 0
g_sprBackground.bVisible = TRUE
// Initialize "clear" flags and sync rate
g_bShowInfo = TRUE
g_bEnableClearColor = FALSE
g_bEnableClearDepth = FALSE
g_iSyncRate = 60
//=============================================================================
//### SECTION - INITIALIZE VARIOUS GRAPHICS
//-----------------------------------------------------------------------------
// Display a background
g_sprBackground.iSpriteID = CreateSprite(LoadImage("background1.jpg"))
SetSpriteSize(g_sprBackground.iSpriteID, GetVirtualWidth(), GetVirtualHeight())
// Apply settings
InitSettings()
// Load an image for the particles
g_imgParticle = LoadImage("shrapnel3.png")
// Create particles off screen
g_peParticles = CreateParticles(-100, -100)
// Load image for sprites
g_imgBall = LoadImage("ball1.png")
// Create a batch of sprites
for i = 1 to C_MAXSPRITES
// Create new sprite
g_sprBalls[i] = CreateSprite(g_imgBall)
// Set initial sprite position offscreen (beyond the right edge)
RandomizeSpritePosition(g_sprBalls[i])
// Set random color
SetSpriteColor(g_sprBalls[i], Random(0, 255), Random(0, 255), Random(0, 255), Random(50, 255))
// Initialize speed and movement arrays
g_fSpeed [i] = Random(10, 40) / 10.0 // Sprite has random initial speed
g_fMove [i] = 0.0 // Y-position is always initially 0
next i
//=============================================================================
//### SECTION - MAIN LOOP
//-----------------------------------------------------------------------------
do
// Show info
if (g_bShowInfo)
Print("FPS = " + str(screenFPS ()) )
Print("")
Print("PERFORMANCE:")
Print(" Drawing set up time = " + str(GetDrawingSetupTime ()) )
Print(" Drawing time = " + str(GetDrawingTime ()) )
Print(" Sprites drawn = " + str(GetManagedSpriteDrawnCount ()) )
Print(" Particles drawn = " + str(GetParticleDrawnQuadCount ()) )
Print(" Get pixels drawn = " + str(GetPixelsDrawn ()) )
Print(" Get managed sprite calls = " + str(GetManagedSpriteDrawCalls ()) )
Print("")
Print("SETTINGS:")
Print(" Number of sprites = " + str(C_MAXSPRITES) )
Print(" Background Alpha = " + str(g_sprBackground.iAlpha) )
Print(" Background Depth = " + str(g_sprBackground.iDepth) )
Print(" Background Visible = " + str(GetSpriteVisible(g_sprBackground.iSpriteID)))
Print(" Clear Color Enabled = " + str(g_bEnableClearColor) )
Print(" Clear Depth Enabled = " + str(g_bEnableClearDepth) )
Print(" SyncRate = " + str(g_iSyncRate) )
Print("")
Print("KEYBOARD:")
Print(" ESCAPE ... QUIT")
Print(" F1 ....... TOGGLE THIS INFO")
Print("")
Print(" Q ........ Increase background ALPHA")
Print(" A ........ Decrease background ALPHA")
Print(" W ........ Increase background DEPTH")
Print(" S ........ Decrease background DEPTH")
Print(" E ........ SHOW background")
Print(" D ........ HIDE background")
Print(" R ........ ENABLE CLEAR COLOR")
Print(" F ........ DISABLE CLEAR COLOR")
Print(" T ........ ENABLE CLEAR DEPTH")
Print(" G ........ DISABLE CLEAR DEPTH")
Print(" Y ........ INCREASE SYNC RATE")
Print(" H ........ DECREASE SYNC RATE")
endif
// Move all sprites
MoveSprites()
// Fire particles when ready
if (g_bReadyToFire = 1) then MakeParticles()
// When current particle emitter has finished, allow another
if (GetParticlesMaxReached(g_peParticles) = 1) then g_bReadyToFire = 1
// Update the screen
Sync()
// Handle input
HandleInput()
loop
//=============================================================================
//# FUNCTION - MoveSprites
//-----------------------------------------------------------------------------
function MoveSprites()
// Declare local variables
v_iSprite as integer
// Move all sprites
for v_iSprite = 1 to C_MAXSPRITES
// Get current location
g_fXPos = GetSpriteX(g_sprBalls[v_iSprite])
g_fYPos = GetSpriteY(g_sprBalls[v_iSprite])
// Calculate new position
g_fYPos = g_fYPos + cos(g_fMove[v_iSprite])
g_fMove[v_iSprite] = g_fMove[v_iSprite] + g_fSpeed[v_iSprite]
// Set new position and angle
SetSpritePosition(g_sprBalls[v_iSprite], g_fXPos - g_fSpeed[v_iSprite], g_fYPos)
SetSpriteAngle(g_sprBalls[v_iSprite], GetSpriteAngle(g_sprBalls[v_iSprite]) - g_fSpeed[v_iSprite])
// If sprite has passed left edge, then ...
if (g_fXPos < -100)
// Reposition it offscreen to the right...
RandomizeSpritePosition(g_sprBalls[v_iSprite])
endif
next
endfunction
//=============================================================================
//# FUNCTION - RandomizeSpritePosition
//-----------------------------------------------------------------------------
function RandomizeSpritePosition(a_iSpriteID as integer)
SetSpritePosition(a_iSpriteID, Random(g_iMinOffscreenX, g_iMaxOffscreenX), Random(0, GetVirtualHeight()))
endfunction
//=============================================================================
//# FUNCTION - MakeParticles
//-----------------------------------------------------------------------------
function MakeParticles()
// Set draw depth (draws particles in front of the sprites)
SetParticlesDepth (g_peParticles, 0)
// Set up particles
SetParticlesPosition (g_peParticles, Random(GetVirtualWidth() * 0.2, GetVirtualWidth() * 0.8), Random(GetVirtualHeight() * 0.2, GetVirtualHeight() * 0.8))
ResetParticleCount (g_peParticles)
// Set particle properties
SetParticlesFrequency (g_peParticles, 10000)
SetParticlesLife (g_peParticles, 3.0)
SetParticlesSize (g_peParticles, 32)
SetParticlesStartZone (g_peParticles, -10, -10, 10, 10)
SetParticlesImage (g_peParticles, g_imgParticle)
SetParticlesDirection (g_peParticles, 40, 50)
SetParticlesAngle (g_peParticles, 360)
SetParticlesVelocityRange (g_peParticles, 1.0, 2.5)
SetParticlesMax (g_peParticles, 500)
// Set color frame properties
AddParticlesColorKeyFrame (g_peParticles, 0.0, 255, 255, 255, 0 )
AddParticlesColorKeyFrame (g_peParticles, 0.4, 255, 255, 255, 128)
AddParticlesColorKeyFrame (g_peParticles, 0.8, 255, 255, 0, 255)
AddParticlesColorKeyFrame (g_peParticles, 2.8, 255, 0, 0, 255)
// Apply force
AddParticlesForce (g_peParticles, 2.0, 2.8, 25, -25)
// Clear the ready flag...
g_bReadyToFire = 0
endfunction
//=============================================================================
//# FUNCTION - HandleInput
//-----------------------------------------------------------------------------
function HandleInput()
// Declare local variables
v_iKeypress as integer
// Check for keypress
v_iKeypress = GetAnyKey()
select v_iKeypress
case KEY_ESCAPE: end : endcase
case KEY_Q: g_sprBackground.iAlpha = Clamp(g_sprBackground.iAlpha + C_STEP_ALPHA, 0, 255) : endcase
case KEY_A: g_sprBackground.iAlpha = Clamp(g_sprBackground.iAlpha - C_STEP_ALPHA, 0, 255) : endcase
case KEY_W: g_sprBackground.iDepth = Clamp(g_sprBackground.iDepth + C_STEP_DEPTH, 0, 10000) : endcase
case KEY_S: g_sprBackground.iDepth = Clamp(g_sprBackground.iDepth - C_STEP_DEPTH, 0, 10000) : endcase
case KEY_E: g_sprBackground.bVisible = TRUE : endcase
case KEY_D: g_sprBackground.bVisible = FALSE : endcase
case KEY_R: g_bEnableClearColor = TRUE : endcase
case KEY_F: g_bEnableClearColor = FALSE : endcase
case KEY_T: g_bEnableClearDepth = TRUE : endcase
case KEY_G: g_bEnableClearDepth = FALSE : endcase
case KEY_Y: g_iSyncRate = Clamp(g_iSyncRate + C_STEP_SYNCRATE, 0, 5000) : endcase
case KEY_H: g_iSyncRate = Clamp(g_iSyncRate - C_STEP_SYNCRATE, 0, 5000) : endcase
case KEY_F1: g_bShowInfo = Mod(g_bShowInfo+1, 2) : endcase
endselect
// Set new values
InitSettings()
endfunction
//=============================================================================
//# FUNCTION - InitSettings
//-----------------------------------------------------------------------------
function InitSettings()
// We're changing all settings at once (sort of unnecessary, but keeps this simple)
SetSpriteColorAlpha (g_sprBackground.iSpriteID, g_sprBackground.iAlpha)
SetSpriteDepth (g_sprBackground.iSpriteID, g_sprBackground.iDepth)
SetSpriteVisible (g_sprBackground.iSpriteID, g_sprBackground.bVisible)
EnableClearColor (g_bEnableClearColor)
EnableClearDepth (g_bEnableClearDepth)
SetSyncRate (g_iSyncRate, 0)
endfunction
//=============================================================================
//# FUNCTION - GetAnyKey
//-----------------------------------------------------------------------------
function GetAnyKey()
// Declare local variables
v_Scancode as integer
v_Result as integer
// Initialize local variables
v_Result = 0 // 0 = Keypress has not been detected...
// Reset last keypress
g_iKBLastKeypress = 0
// Get last key pressed (and save it in the global variable)
v_Scancode = GetRawLastKey()
// If key has been released... Key DOWN + Key UP event has occurred.
if (GetRawKeyReleased(v_Scancode))
// Save last keypress
g_iKBLastKeypress = v_Scancode
// Return this scancode!
v_Result = v_Scancode
endif
endfunction v_Result
//=============================================================================
//# FUNCTION - Clamp
//-----------------------------------------------------------------------------
function Clamp(a_fValue as float, a_fMin as float, a_fMax as float)
if a_fValue < a_fMin then exitfunction a_fMin
if a_fValue > a_fMax then exitfunction a_fMax
endfunction a_fValue
Cheers,
AgentSam