While in the last tutorial we added a texture - this texture was procedural - we didn't load it from a file. We created a WebGPU texture buffer - and filled it with a test pattern. Now, we take it a bit further by showing you how to load a texture from a URL.
The first thing you have to be aware of, is that you're downloading your images over an internet connection - and your internet connection will have a delay - so be careful of delays. Especially for large file - they won't just download instantly!
In the
loadTexture
function - we use the async/wait so that we can be sure the image has fully downloaded before we try and copy it to the WebGPU texture buffer.
A nifty little trick to check that the image is good to go, is
img.decode()
- which will only be finished when the image has been loaded and decoded - so if this has finished the image is safe to use.
Visitor:
Copyright (c) 2002-2025 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.