Blitz3D+ Command Reference

RenderTextureMemoryKB ( )

Parameters

None.

Description

Returns the renderer's tracked texture-related memory, in kilobytes.

The figure totals the committed allocations behind everything texture-shaped: the textures you loaded and created, render targets, depth buffers, shadow maps, and in-flight texture uploads. It is a real allocation count, not an estimate, so it moves when the truth moves: load a big texture and watch it rise, FreeTexture it and watch it fall.

That rise-and-fall is the point. Print it while play-testing and a slow climb that never comes back down is a texture leak - somewhere you load textures without freeing the old ones. It also keeps level-asset budgets honest: check the number after each level load and you know what your art really costs before low-memory machines tell you the hard way.

Read it after RenderWorld and Flip for the latest frame's value; it returns 0 before Graphics3D. Geometry has its own counter in RenderGeometryMemoryKB.

Requires Extended mode.

See also: RenderGeometryMemoryKB, LoadTexture, CreateTexture, DrawRenderStats.

Example

; RenderTextureMemoryKB Example
; -----------------------------
; Requires Extended mode.

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

SeedRnd MilliSecs()

camera=CreateCamera()
PositionEntity camera,0,2,-12

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

; Space spawns crates with unique 256x256 textures; C frees them all again
Dim crates(19),skins(19)
count=0

While Not KeyDown(1)

    ; Each press creates a NEW texture, so tracked texture memory grows
    If KeyHit(57) And count<20 Then
        skins(count)=CreateTexture(256,256)
        SetBuffer TextureBuffer(skins(count))
        ClsColor Rand(60,255),Rand(60,255),Rand(60,255)
        Cls
        SetBuffer BackBuffer()
        crates(count)=CreateCube()
        EntityTexture crates(count),skins(count)
        PositionEntity crates(count),Rnd(-6,6),Rnd(-2,2),Rnd(0,8)
        count=count+1
    EndIf

    ; C frees every crate and its texture, releasing the memory
    If KeyHit(46) Then
        For n=0 To count-1
            FreeEntity crates(n)
            FreeTexture skins(n)
        Next
        count=0
    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

    RenderWorld

    ; RenderTextureMemoryKB tracks targets, shadows, cached textures and uploads
    Text 0,0,"Space: spawn textured crate   C: free all   Arrows: camera   Esc: exit"
    Text 0,20,"Unique textures: "+count+"   RenderTextureMemoryKB() = "+RenderTextureMemoryKB()+" KiB"

    Flip

Wend

End

Index