Difference between revisions of "love.graphics.getStats"

m (Added New feature template)
(Undo revision 23662 by Andlac028 (talk) - the page is much easier to understand when the second variant is listed separately, since the table argument is not required.)
Line 8: Line 8:
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
stats = love.graphics.getStats( stats )
+
stats = love.graphics.getStats( )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{New feature|11.0|
+
None.
{{param|table|stats|A table which will be filled in with the stat fields below.}}
 
}}
 
 
=== Returns ===
 
=== Returns ===
 
{{param|table|stats|A table with the following fields:}}
 
{{param|table|stats|A table with the following fields:}}
Line 27: Line 25:
 
{{subparam|number|drawcallsbatched|The number of draw calls that were saved by LÖVE's automatic batching, since the start of the frame.}}
 
{{subparam|number|drawcallsbatched|The number of draw calls that were saved by LÖVE's automatic batching, since the start of the frame.}}
 
}}
 
}}
 +
 +
== Function ==
 +
{{newin|[[11.0]]|110|type=variant}}
 +
This variant accepts an existing table to fill in, instead of creating a new one.
 +
=== Synopsis ===
 +
<source lang="lua">
 +
stats = love.graphics.getStats( stats )
 +
</source>
 +
=== Arguments ===
 +
{{param|table|stats|A table which will be filled in with the stat fields below.}}
 +
=== Returns ===
 +
{{param|table|stats|The table that was passed in above, now containing the following fields:}}
 +
{{subparam|number|drawcalls|The number of draw calls made so far during the current frame.}}
 +
{{subparam|number|canvasswitches|The number of times the active [[Canvas]] has been switched so far during the current frame.}}
 +
{{subparam|number|texturememory|The estimated total size in bytes of video memory used by all loaded [[Image]]s, [[Canvas]]es, and [[Font]]s.}}
 +
{{subparam|number|images|The number of [[Image]] objects currently loaded.}}
 +
{{subparam|number|canvases|The number of [[Canvas]] objects currently loaded.}}
 +
{{subparam|number|fonts|The number of [[Font]] objects currently loaded.}}
 +
{{subparam|number|shaderswitches|The number of times the active [[Shader]] has been changed so far during the current frame.}}
 +
{{subparam|number|drawcallsbatched|The number of draw calls that were saved by LÖVE's automatic batching, since the start of the frame.}}
  
 
== Examples ==
 
== Examples ==

Revision as of 11:32, 10 October 2019

Available since LÖVE 0.9.2
This function is not supported in earlier versions.

Gets performance-related rendering statistics.


O.png The per-frame metrics (drawcalls, canvasswitches, shaderswitches) are reset by love.graphics.present, which for the default implementation of love.run is called right after the execution of love.draw. Therefore this function should probably be called at the end of love.draw.  


Function

Synopsis

stats = love.graphics.getStats( )

Arguments

None.

Returns

table stats
A table with the following fields:
number drawcalls
The number of draw calls made so far during the current frame.
number canvasswitches
The number of times the active Canvas has been switched so far during the current frame.
number texturememory
The estimated total size in bytes of video memory used by all loaded Images, Canvases, and Fonts.
number images
The number of Image objects currently loaded.
number canvases
The number of Canvas objects currently loaded.
number fonts
The number of Font objects currently loaded.
Available since LÖVE 0.10.2
number shaderswitches
The number of times the active Shader has been changed so far during the current frame.
Available since LÖVE 11.0
number drawcallsbatched
The number of draw calls that were saved by LÖVE's automatic batching, since the start of the frame.


Function

Available since LÖVE 11.0
This variant is not supported in earlier versions.

This variant accepts an existing table to fill in, instead of creating a new one.

Synopsis

stats = love.graphics.getStats( stats )

Arguments

table stats
A table which will be filled in with the stat fields below.

Returns

table stats
The table that was passed in above, now containing the following fields:
number drawcalls
The number of draw calls made so far during the current frame.
number canvasswitches
The number of times the active Canvas has been switched so far during the current frame.
number texturememory
The estimated total size in bytes of video memory used by all loaded Images, Canvases, and Fonts.
number images
The number of Image objects currently loaded.
number canvases
The number of Canvas objects currently loaded.
number fonts
The number of Font objects currently loaded.
number shaderswitches
The number of times the active Shader has been changed so far during the current frame.
number drawcallsbatched
The number of draw calls that were saved by LÖVE's automatic batching, since the start of the frame.

Examples

display the estimated amount of video memory used for textures

function love.load()
    love.graphics.setNewFont(24)
end

function love.draw()
    local stats = love.graphics.getStats()

    local str = string.format("Estimated amount of texture memory used: %.2f MB", stats.texturememory / 1024 / 1024)
    love.graphics.print(str, 10, 10)
end

See Also


Other Languages