Blitz3D+ Command Reference

RenderTriangles ( )

Parameters

None.

Description

Returns the triangles actually drawn by the main scene in the last completed frame.

GPU particle contributions are resolved asynchronously. Returns -1 while the relevant GPU counts are pending; display this as pending and query again after later frames. Reading this statistic never forces a GPU counter wait. CPU-only frames retain their existing immediate behaviour.

RenderTriangles counts executed main-scene triangles - what the GPU really drew after culling, with instancing multiplied out (one mesh drawn 100 times as instances counts all 100 copies' triangles). It excludes shadow-pass triangles, debug lines and 2D overlay drawing, so the number tracks your visible scene itself.

Read it after RenderWorld and Flip and it becomes your scene-complexity dial. Spin the camera around the level and watch it move: a spike when facing one direction pinpoints the expensive corner of your map. If the count barely drops when most of the level is behind the player, your culling setup deserves a look. And when the frame rate dips, comparing this number against a known-good scene tells you whether raw triangle count is even the problem.

Before the first RenderWorld the count is 0.

Requires Extended mode.

See also: FrameTime, RenderGPUTime, RenderDrawCalls, RenderCulledEntities, DrawRenderStats.

Example

; RenderTriangles 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 change the triangle count
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

    ; RenderTriangles counts main-scene triangles executed in the last frame
    Text 0,0,"Arrow keys: move camera   Space: toggle asteroids   Esc: exit"
    Text 0,20,"RenderTriangles() = "+RenderTriangles()
    Text 0,40,"Shadows and this 2D text are not included in the count"

    Flip

Wend

End

Index