Created
July 22, 2014 02:45
-
-
Save indefinit/88dadd770657644c9c82 to your computer and use it in GitHub Desktop.
Functional shader loader. Requires JQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var shadersHolder = { vertex: [], fragment: [] }; | |
/** | |
* Fancy schmancy functional loading of Shaders | |
* @param {Array} shaders Object array of shaders | |
* @return {Jquery.Deferred} | |
*/ | |
function loadShaders(shaders) { | |
return $.when.apply($, $.map(shaders, function(shader) { | |
var def = new $.Deferred(); | |
$.ajax({url:shader.path, dataType: 'text', complete: function(resp){ | |
(shader.type == 'vertex') ? shadersHolder.vertex.push(resp.responseText) : shadersHolder.fragment.push(resp.responseText); | |
def.resolve(); | |
}}); | |
return def; | |
})).promise(); | |
} | |
// First we load our shaders and then init | |
// the scene | |
// init defined elsewhere | |
loadShaders([{path: './shaders/vertex.js', type:'vertex'}, {path: './shaders/frag.js', type:'fragment'}]).then(function(){ | |
init(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment