What does texture onLoadedObservable actually mean?

Good morning!

I have a (hopefully) quick question regarding texture loading and the onLoadedObservable. Does this get fired when the texture is finished downloading (as in, an Image object from the network) or does it wait until it is also actually uploaded to the GPU in WebGL and available for use?

Long story short, I’m having an issue with a custom shader material flashing while loading and am trying to narrow down the root cause. Basically, the texture is applied by doing something like this, but it doesn’t seem to set right away:

texture.onLoadedObservable.addOnce((tex) => this.buildMaterial.setTexture("metallicGlossMap", tex));

It’s more obvious with a 1024p texture than a 128p texture, if that matters.

I can’t post a full example unfortunately as the codebase powering this is fairly large.

Using version 4.2.

Thank you in advance for your help!

Hi @travisvroman and welcome to the Babylon.js Community! Pinging @sebavan to see if he has an idea.

Onloaded happens once the texture has been uploaded to the gpu and is fully ready to be displayed. A repro would be awesome :slight_smile:

Thank you for the answers! A repro is a bit difficult in my case since the codebase I am using is all custom materials and there’s a lot of logic around it. This does answer my question though; thank you!

1 Like