Aeva / m.grl

Midnight Graphics & Recreation Library
http://mgrl.midnightsisters.org
GNU Lesser General Public License v3.0
44 stars 3 forks source link

bundled glsl assets must be loaded in order #218

Closed wijnen closed 8 years ago

wijnen commented 8 years ago

The bundles glsl assets are loaded in arbitrary order (because they are unordered attributes of an object), but they have a dependency tree, so dependencies must be loaded before they are used. In particular, normalize_screen_coord.glsl is requested from the server every time my browser opens an m.grl page.

Either the dependencies should be parsed, and the loading should be done in the correct order, or the order should somehow be set manually (for example by using an array of [name,content] arrays instead of an object).

Aeva commented 8 years ago

I think I'm going to opt for some kind of lazy loading mechanism. Currently when an asset is loaded, a callback is triggered and any extra processing that is needed happens immediately (eg, jta turns the data into something usable, glsl sources get partially compiled, etc).

Instead, I think how this should work is when something is lazy loaded, the post processing callback is instead triggered upon first access. That way, as long as there are no dependency cycles (which there shouldn't be anyway), it'll resolve the assets in the correct order as needed.

wijnen commented 8 years ago

That sounds like it would work. Is there anything where the handling takes long? If there is, it would be good to force the processing before triggering mgrl_media_ready.

Aeva commented 8 years ago

JTA is probably the most involved of them. I think media_ready is triggered afterwards, but I'm not sure entirely.

From the looks of things, the asset pre-loading doesn't make use of please.load to insert the shader data, so I think the easy mechanism here is if please.access finds a function instead of an asset, it calls the function and replaces it with its return result. If for some reason we want to provide an explicit mechanism for this later on, it'll be easy to implement on top of that.

Aeva commented 8 years ago

d82c36883e6cf131ab69 might be a fix for this, but I don't know how to test it since things were already working ok on my machine?

my telephone complains that it can't build the shader, but I don't know how to see the console on mobile firefox >_>

wijnen commented 8 years ago

Yes, this seems to have fixed the problem.