-- One image used by several maps of a glTF is uploaded once for each way the maps read it, not once -- a map: Models/OneImage.gltf uses its 256x256 picture once, as a base colour, which sets the size -- of an upload; Models/SharedImage.gltf has two materials that each use the same picture for all -- five maps, which is two uploads (the base and emissive maps read it as sRGB, the other three as -- data), not ten. Deleting each model has to give every byte back, which proves the shared texture -- outlives the first material to let go of it and goes with the last. Each check prints -- "SHARED ok" or "SHARED FAIL". No disc: run with -C 720x480. dofile("Singe/Framework.singe") local font = fontLoad("Singe/FreeSansBold.ttf", 14) local camera = nodeNew() local sun = lightNew(LIGHT_DIRECTIONAL) local frames = 0 local failures = 0 local before = 0 local single = 0 local model = nil local LAST = 12 local function check(name, ok, detail) if ok then debugPrint("SHARED ok " .. name) else failures = failures + 1 debugPrint("SHARED FAIL " .. name .. (detail and (" (" .. detail .. ")") or "")) end end -- Kilobytes of texture the scene holds now. local function textureKb() local _, _, _, kb = sceneGetStats() return kb end fontSelect(font) overlaySetResolution(720, 480) sceneEnable(true) cameraSet(camera) nodeSetPosition(camera, 0.5, 0.5, 2) nodeLookAt(camera, 0.5, 0.5, 0) nodeLookAt(sun, -1, -2, -1) function onOverlayUpdate() frames = frames + 1 overlayClear() fontPrint(8, 6, string.format("frame %d textures %d KB failures %d", frames, textureKb(), failures)) if frames == 2 then before = textureKb() model = modelLoad("testScripts/Models/OneImage.gltf") modelInstance(model) elseif frames == 4 then single = textureKb() - before check("one upload costs something", single > 0, single .. " KB") modelDelete(model) elseif frames == 6 then check("modelDelete gives the one upload back", textureKb() == before, textureKb() .. " KB against " .. before) model = modelLoad("testScripts/Models/SharedImage.gltf") modelInstance(model) elseif frames == 8 then local shared = textureKb() - before check("ten maps of one image are two uploads", shared == 2 * single, shared .. " KB against " .. (2 * single)) singeScreenshot("shared") modelDelete(model) elseif frames == 10 then check("modelDelete gives the shared uploads back", textureKb() == before, textureKb() .. " KB against " .. before) elseif frames == LAST then debugPrint(string.format("SHARED RESULT failures=%d", failures)) singeQuit() end return OVERLAY_UPDATED end