Why Small PNG/JPEG GLB Files Still Exhaust Mobile WebGL2 Texture VRAM
Compressed File Weight Versus Uncompressed RGBA8 GPU Allocation
A 4096 × 4096 JPEG albedo map or WebP normal map may add less than 900 KB to a .glb download, yet standard GPUs cannot sampleentropy-coded PNG, JPEG, or WebP bitstreams directly inside fragment shaders. At upload time, the browser decodes every pixel into 32-bit RGBA8 texels (4 bytes per pixel = 67.1 MB for one 4K map) and generates a trilinear mipmap pyramid adding roughly 33.3 percent more memory—pushing a single 4K PBR material set with baseColor, normal, metallicRoughness, and emissive maps past 350 MB of estimated VRAM.
Our Worker parses PNG IHDR chunks, JPEG SOF frame headers, WebP VP8/VP8L/VP8X headers, and KTX2 BasisU level directories directly from binary bufferViews without touching the main-thread WebGL context. For every resolved image, it sums exact integer mip dimensions floor(w / 2^L) × floor(h / 2^L) × 4 across all mip levels and contrasts that against GPU block-compressed BC7/ASTC KTX2 footprints.
- Distinguishes estimated RGBA8 mip VRAM from actual driver-allocated memory clearly in every report.
- Flags non-power-of-two (NPOT) dimensions as informational under WebGL2 while noting KTX2 4×4 block alignment rules.
- Parses KTX2 vkFormat and supercompressionScheme headers via ktx-parse 2.0.0.
Understanding NPOT Advisories Under WebGL2
In scale-texture.glb, image 0 measures 3 × 5 pixels (base 60 B, mip levels 3×5 + 1×2 + 1×1 = 72 B). While WebGL2 natively supports mipmapping and REPEAT wrapping on NPOT textures, Basis Universal KTX2 encoders often require dimensions divisible by four, making early NPOT visibility valuable before texture compression.