Blitz3D+ Command Reference

ActiveTextures ( )

Parameters

None.

Description

Returns the number of texture images currently held in memory.

Every CreateTexture and every texture loaded from disk adds one to this count, and freeing a texture takes one away again. It is a diagnostic counter: put it on a debug overlay and watch it while your game runs. If the number climbs a little every time you reload a level or respawn a pickup, somewhere a texture is being created and never freed.

The count tracks actual texture images, not handles. Loading the same file twice with LoadTexture shares one cached image between both handles, so the second load does not increase the count. In the same way, the copy handles returned by GetBrushTexture share the original image - but each copy still keeps that image alive, so an unfreed copy shows up here as a count that never comes back down.

The counter is global and lives for the whole program run - ClearWorld and level changes only lower it as far as the textures they actually release.

See also: LoadTexture, CreateTexture, FreeTexture, TextureName, TrisRendered.

Example

; ActiveTextures Example
; ----------------------

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

camera=CreateCamera()
PositionEntity camera,0,1,-8

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

; A textured crate for the basic scene
crate=CreateCube()
PositionEntity crate,0,1,0
crate_tex=LoadTexture("media/b3dlogo.jpg")
EntityTexture crate,crate_tex

; Loading the same file again shares the cached image, so this
; second handle does NOT add another active texture
crate_tex2=LoadTexture("media/b3dlogo.jpg")

loaded=0
Dim tile(7)
Dim tile_tex(7)

While Not KeyDown(1)

    ; Space toggles a batch of eight code-built textures
    If KeyHit(57)
        If loaded=0
            loaded=1
            For i=0 To 7
                ; Every CreateTexture adds one active texture
                tile_tex(i)=CreateTexture(64,64)
                SetBuffer TextureBuffer(tile_tex(i))
                ClsColor 30*i,255-30*i,128
                Cls
                SetBuffer BackBuffer()
                tile(i)=CreateCube()
                ScaleEntity tile(i),0.5,0.5,0.5
                PositionEntity tile(i),(i-3.5)*1.5,-1,0
                EntityTexture tile(i),tile_tex(i)
            Next
        Else
            loaded=0
            For i=0 To 7
                FreeEntity tile(i)
                ; Freeing the texture releases its cached image
                FreeTexture tile_tex(i)
            Next
        EndIf
    EndIf

    TurnEntity crate,0,1,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

    Text 0,0,"Space: load/free 8 textures   Arrows: camera   Esc: exit"
    Text 0,20,"ActiveTextures() = "+ActiveTextures()

    Flip

Wend

End

Index