0

i am in the middle of a project to make a webgl version of some java code i have that is written in opengl. I am using GWT to do this. I have a canvas generated and i can load resources via xhr requests but my issue is i don't know how to go from loading a bunch of resources to getting to a point that i know they are loaded and can be used.

The xhr requests are all setup to run (there is an undetermined number of these, but known at run time), if i stick a while loop in afterwards it will block the processing of the xhr requests so i basically get a an unresposive browser from that point onwards. So the while loop is a bad idea, so the question is how best to design the code such that i can fire off a lot of xhr requests and effectively sleep in the main loop until they are done? The second question is, assuming there is an answer to the first, how best to implement the previous answer in GWT.

To give some more context, i want to load 10 textures and then build the scene data to send to webgl. For a cube texture as an example i would need to wait for 6 textures to build the webgl cube texture

abcdef
  • 441
  • 3
  • 13
  • 4
    you're not really asking a WebGL question you're asking a basic JavaScript question. There are probably 1000 answers on how to wait for a bunch of async tasks to finish in JavaScript. It feels like this should be closed as dupe. Here one answer, https://stackoverflow.com/questions/10004112/how-can-i-wait-for-set-of-asynchronous-callback-functions. Searching for the gwt version this comes up: https://stackoverflow.com/questions/2993085/clean-way-in-gwt-java-to-wait-for-multiple-asynchronous-events-to-finish – gman Nov 28 '17 at 16:24
  • I'm asking from a webgl perspective because I specifically want to know the design patterns webgl people have used for this. The answers I have seen are very messy (I have seen your links before), they all revolve around – abcdef Nov 28 '17 at 17:03
  • Callbacks, which is not ideal. If it's the only way then fine. But I would like to hear from webgl people for how they design things – abcdef Nov 28 '17 at 17:14
  • 3
    callbacks is all there is in JavaScript. It's the way the browser works. Callbacks rule in JavaScript. If you hate them it's because they suck in Java (and C and C++). Embrace them. They're what JavaScript is all about. All WebGL apps use lots of callbacks for loading resources. – gman Nov 28 '17 at 17:38

0 Answers0