I am learning WebGL and I want to know the formula of calculating vram usage size from a image(jpg/png).
Thanks.
I am learning WebGL and I want to know the formula of calculating vram usage size from a image(jpg/png).
Thanks.
Copyright © 2021 Jogjafile Inc.
jpg or png make no difference. They are expanded to uncompressed data before being uploaded to WebGL. There is no perfect way to compute the vram usage because what the driver actually stores internally is unknown but you can estimate.
Where
bytesPerPixelis derived from theformat/typeyou pass togl.texImage2Das inor
In WebGL2 you'd compute from the
interalFormatpassed to the same function (see table here)for WebGL1 common values are
Then, if you upload a mipmap or generate one with
gl.generateMipmapyou need to multply by about 33%. Example, a 16x16 pixel texture will haveBut like I mentioned it's up to the driver. Some (most drivers?) will expand RGB to RGBA as one example. Some drivers will expand the various 2 byte per pixel RGB/RGBA formats to 4 bytes.