Blitz3D+ Command Reference

RenderBoneMatrices ( )

Parameters

None.

Description

Returns how many bone matrices were uploaded for GPU-skinned draws in the last completed frame.

Every GPU-skinned instance sends the graphics card a palette of bone matrices, and this is the total across all of them. It is the size of the per-frame skinning upload, so it grows both with the number of animated characters on screen and with how many joints each of their skeletons has.

That makes it the counter to watch when a crowd starts to hurt. Twenty characters with a 30 bone skeleton report around 600; the same twenty rigged with 120 bones report around 2,400 for exactly the same picture. If this number is climbing faster than your character count, the answer is usually a simpler rig rather than fewer characters.

It is also a quick check on instancing. Because instanced skinned draws still upload one palette per instance, dividing this by RenderGPUSkinnedDraws tells you roughly how many characters are riding along in each grouped draw.

Gotcha: this describes the most recently completed frame's main colour pass, so read it after Flip. Only GPU-skinned draws contribute - characters that fell back to CPU skinning are counted by RenderCPUSkinnedDraws and add nothing here, so a suspiciously low figure may mean the fallback is in use rather than that your rigs are lean.

Requires Extended mode.

See also: RenderGPUSkinnedDraws, RenderCPUSkinnedDraws, RenderDrawCalls, Animate, LoadAnimMesh.

Example

; RenderBoneMatrices Example
; --------------------------
; Requires Extended mode.

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

camera=CreateCamera()
PositionEntity camera,0,3,-10
CameraClsColor camera,20,30,50

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

AmbientLight 120,120,120

; A skinned, bone-animated fox from the glTF samples
template=LoadAnimMesh("../../../samples/glTF/assets/Fox/Fox.glb")
If template=0 Then RuntimeError "Could not load Fox.glb: "+ModelLoadError()
FitMesh template,-0.7,0,-0.7,1.4,1.4,1.4,True

; A crowd of copies - every GPU-skinned fox uploads its own bone palette
Dim foxes(19)
For n=0 To 19
    foxes(n)=CopyEntity(template)
    PositionEntity foxes(n),(n Mod 5)*3-6,0,(n/5)*3
    Animate foxes(n),1,0.6+(n Mod 4)*0.1,FindAnimSeq(foxes(n),"Run")
Next
HideEntity template

crowd_on=True

While Not KeyDown(1)

    ; Space hides or shows the back ten foxes - fewer palettes are uploaded
    If KeyHit(57)
        crowd_on=Not crowd_on
        For n=10 To 19
            If crowd_on Then ShowEntity foxes(n) Else HideEntity foxes(n)
        Next
    EndIf

    ; 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

    UpdateWorld
    RenderWorld

    ; Bone matrices uploaded for GPU-skinned instances last frame
    Text 0,0,"Arrow keys: move camera   Space: toggle 10 foxes   Esc: exit"
    Text 0,20,"RenderBoneMatrices() = "+RenderBoneMatrices()
    Text 0,40,"Each fox skeleton has "+CountBones(foxes(0))+" bones"

    Flip

Wend

End

Index