DrawRenderStats [x][,y][,flags]

Parameters

x (optional) - left edge of the overlay in pixels; 8 (default)

y (optional) - top edge of the overlay in pixels; 8 (default)

flags (optional) - bit mask choosing which rows to draw; add the bits you want; 255 (default)
1: timing - FPS, frame ms, render CPU ms, render GPU ms
2: geometry - triangles, draw calls, instances, plus a decal row
4: memory - texture and geometry memory in KB
8: shadows - shadow draws, triangles, cascades and GPU ms
16: detail - culled entities, LOD selections, terrain chunks and uploads
32: animation - GPU and CPU skinned draws, bone matrices
64: particles - live particle total
128: diagnostics - counts of information, warning and error records
256: async loading - world-loading memory, cache and finalizer rows
512: post-processing - post passes, target memory, HDR/TAA and history
1024: classic Box3D collisions - worlds, bodies, shapes, contacts, cooks, substeps and reporting casts
2048: world streaming - data loaded, parked and unloaded, loads waiting, loads on the spot and camera cuts, against the memory budget

Description

Draws a renderer statistics overlay on the current buffer.

DrawRenderStats is the fastest way to see what a frame costs. Drop it between RenderWorld and Flip and you get live rows built from the same counters the individual query commands return - FrameTime, RenderTriangles, RenderTextureMemoryKB and friends - without writing any Text calls yourself.

The flags parameter picks rows by adding bits together: 1+2+4 (=7) shows timing, geometry and memory; the default 255 shows the eight everyday rows (bits 1 through 128); 4095 shows everything including async loading, post-processing, the hidden classic-collision backend and world streaming. Negative flags stop the program with a runtime error. Times shown as "n/a" mean no reading is available - RenderGPUTime, for example, returns -1 until a GPU timestamp completes.

The overlay is state-preserving: your current drawing Color, Origin and Viewport are untouched, and it prints with the current font into the current buffer. Rows too long for the screen are trimmed with "...".

Keep it on a debug key rather than shipping it switched on - the readout is for you, not the player.

For the full story, see the Prototyping and Diagnostics guide.


See also: FrameTime, RenderTriangles, RenderTextureMemoryKB, DrawDiagnostics, RenderDrawCalls.

Example

; DrawRenderStats Example
; -----------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,3,-14

light=CreateLight()
RotateEntity light,45,45,0

; An asteroid ring so the overlay has something to measure
hub=CreatePivot()
Dim rocks(29)
For n=0 To 29
    rocks(n)=CreateSphere(24)
    ScaleEntity rocks(n),0.6,0.6,0.6
    PositionEntity rocks(n),6*Cos(n*12),2*Sin(n*47),6*Sin(n*12)
    EntityParent rocks(n),hub
    EntityColor rocks(n),130,120,110
Next

preset=3

While Not KeyDown(1)

    ; [ and ] cycle through flag presets for the overlay
    If KeyHit(26) And preset>0 Then preset=preset-1
    If KeyHit(27) And preset<4 Then preset=preset+1

    ; Each flag bit adds a group of rows: 1 timing, 2 geometry, 4 memory...
    Select preset
        Case 0
            flags=1
            label$="timing only"
        Case 1
            flags=3
            label$="timing + geometry"
        Case 2
            flags=7
            label$="timing + geometry + memory"
        Case 3
            flags=255
            label$="standard set"
        Case 4
            flags=1023
            label$="every row"
    End Select

    TurnEntity hub,0,0.5,0

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    ; DrawRenderStats paints the renderer overlay without changing drawing state
    DrawRenderStats 8,50,flags

    Text 0,0,"Arrow keys: move camera   [ / ] : flag preset   Esc: exit"
    Text 0,20,"DrawRenderStats 8,50,"+flags+"   ("+label+")"

    Flip

Wend

End

Index