Asynchronous loading of GLSL files. Currently unused.
Asynchronous loading of GLSL files. Currently unused.

To use this functionality perform the following :

< window.onload = function init()

> var vert_url = "vertex.glsl";
> var frag_url = "fragment.glsl";
>
> window.onload = load_shaders(vert_url , frag_url , init);
>
> function init()

Move the vertex shader and fragment shader into their own files.

Replace the window.onload function with a call to load_shaders whose arguments are 1. vertex shader URL 2. fragment shader URL 3. callback function (in this example the init function declared in the JavaScript file.

<     program = init_program(gl , "vertex-shader" , "fragment-shader");

>     var vert_shader = shader_from_txt
>     (
> 	gl , shaders[vert_url] , gl.VERTEX_SHADER
>     );
>     var frag_shader = shader_from_txt
>     (
> 	gl , shaders[frag_url] , gl.FRAGMENT_SHADER
>     );
>     program = create_program(gl , vert_shader , frag_shader);

Inside the init function remove the call to the init_program function, load the shaders using the shader_from_txt function, the second argument of which gets the text for the shader from the shaders hash in ajax_shader_utils using the URL as a key. Replace the call to the init_program function with the create_program function which takes the compiled shader objects as arguments.

This file is not currently used due to a potential race condition in the ajax_barrier function, I cannot see at the moment a clear way of reading or modifying the loading array safely. I do know how to write safe locks so with a little intrspection I may find a reasonable solution soon, but not today.

It has to be said that despite the potential for a race condition I haven't managed to trip it, despite my best efforts, however just because it appears safe doesn't mean it is, YMMV. I suppose if anyone did trip it, refreshing the page would probably clear it, but it seems unprofessional to allow it.

Another good reason for not using this code right now is that it cannot be used from the local file system due restrictions preventing cross site scripting; firing up an HTTP daemon each time I do some work on this project is a little tiresome, I may change all this later.

This file has been committed in order not to lose the work and to keep my workspace (relatively) tidy. Use this file at your own risk.

wsdhart/webgl,wsdhart/webgl