Blitz3D+ Command Reference

TerrainUploadBytes ( terrain )

Parameters

terrain - terrain entity to query

Description

Returns the vertex and index bytes generated for rebuilt terrain chunks in the last render pass.

It is the companion to TerrainRebuiltChunks, measured in bytes rather than chunks. Every time a chunk mesh has to be built, the size of its vertex data plus its index data is added here. A warm pass - camera settled, nothing edited, every chunk finding its mesh in the cache - reports 0.

Chunks are the reason this number stays sensible: a rebuild costs one chunk's worth of geometry, not the whole landscape. That is what makes runtime deformation practical, and this is the counter that tells you whether your particular deformation is going to hurt. A crater that dirties four chunks moves a modest amount once. A script that edits a wide region every frame shows up as a constant stream of kilobytes, and that bandwidth comes out of the same budget as the rest of your frame.

Leave it on a debug key while you are building a digging, explosion or terraforming feature. If the per-second figure looks heavy, shrink the edited region, batch the edits inside BeginTerrainUpdate and EndTerrainUpdate so one rectangle is committed instead of many, or spread the work over several frames rather than doing it in one.

Gotcha: read it after RenderWorld - it is cleared at the start of every render pass. And this is generated geometry for rebuilt cache entries, not the terrain's resident memory: a terrain that never changes can be using plenty of memory while reporting 0 here forever.

See also: TerrainRebuiltChunks, BeginTerrainUpdate, EndTerrainUpdate, TerrainTriangles, ModifyTerrain.

Example

; TerrainUploadBytes Example
; --------------------------

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

camera=CreateCamera()
PositionEntity camera,0,6,-40
CameraClsColor camera,110,150,200

light=CreateLight(1)
RotateEntity light,50,-30,0

; Rolling hills built from a sine-wave height field
terrain=CreateTerrain(128)
For z=0 To 127
    For x=0 To 127
        ModifyTerrain terrain,x,z,0.2+Sin(x*10)*Cos(z*10)*0.12
    Next
Next
ScaleEntity terrain,0.5,20,0.5
PositionEntity terrain,-32,-5,-32
TerrainShading terrain,True
TerrainDetail terrain,8000,True

; Plain grass texture drawn in code
grass=CreateTexture(8,8,1+8)
SetBuffer TextureBuffer(grass) : ClsColor 75,135,60 : Cls : SetBuffer BackBuffer()
EntityTexture terrain,grass

phase#=0
sun_angle#=-30

While Not KeyDown(1)

    ; Hold Space to keep deforming a patch - rebuilt chunks upload data
    If KeyDown(57)
        phase=phase+6
        BeginTerrainUpdate terrain
        For z=52 To 75
            For x=52 To 75
                ripple#=Sin((x-52)*7.8)*Sin((z-52)*7.8)*Sin((x+z)*15+phase)*0.06
                ModifyTerrain terrain,x,z,0.2+Sin(x*10)*Cos(z*10)*0.12+ripple
            Next
        Next
        EndTerrainUpdate terrain
    EndIf

    ; The sun slowly circles so the hills' shading shifts
    sun_angle=sun_angle+0.2
    RotateEntity light,50,sun_angle,0

    ; Arrow keys move the camera - LOD switches also rebuild chunks
    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

    ; Vertex and index bytes generated for rebuilt chunks this pass
    uploaded=TerrainUploadBytes(terrain)

    Text 0,0,"Arrow keys: fly   Hold Space: deform terrain   Esc: exit"
    Text 0,20,"TerrainUploadBytes(terrain) = "+uploaded+" bytes"
    Text 0,40,"Rebuilt chunks: "+TerrainRebuiltChunks(terrain)+" (warm passes report 0)"

    Flip

Wend

End

Index