Blitz3D+ Command Reference

RenderCPUTime# ( )

Parameters

None.

Description

Returns the CPU milliseconds spent preparing and submitting the last completed frame.

RenderCPUTime isolates the renderer's share of the processor: walking the scene, sorting, skinning on the CPU where needed, filling buffers and issuing the frame's draw calls. It deliberately excludes time spent waiting for VSync or a frame limiter, and it excludes your own game logic.

That makes the comparison with FrameTime the useful move. A 30 ms FrameTime with a 3 ms RenderCPUTime says the frame is going somewhere other than render submission - usually your BASIC code, or simply pacing. A RenderCPUTime that rises with the number of entities points at scene complexity: consider fewer visible entities, instancing-friendly setups, or LOD.

Read it after RenderWorld and Flip; it describes the most recently completed frame. It returns -1 before the renderer exists (call Graphics3D first). Pair it with RenderGPUTime to decide whether the processor or the graphics card is the bottleneck.

Requires Extended mode.

See also: RenderGPUTime, FrameTime, RenderTriangles, DrawRenderStats.

Example

; RenderCPUTime Example
; ---------------------
; Requires Extended mode.

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

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

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

; An asteroid ring the player can switch off to lighten the renderer's work
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

heavy=True

While Not KeyDown(1)

    ; Space toggles the asteroid ring on and off
    If KeyHit(57) Then
        heavy=Not heavy
        For n=0 To 29
            If heavy Then ShowEntity rocks(n) Else HideEntity rocks(n)
        Next
    EndIf

    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

    ; RenderCPUTime is CPU work spent preparing and submitting the last frame
    Text 0,0,"Arrow keys: move camera   Space: toggle asteroids   Esc: exit"
    Text 0,20,"RenderCPUTime() = "+RenderCPUTime()+" ms"
    Text 0,40,"Frame pacing is excluded, so this is pure renderer CPU cost"

    Flip

Wend

End

Index