HTML and CSS Reference
In-Depth Information
// Construct the URL to request the asset
var requestURL = urlPrefix + assetName;
// Make the request using XHR
var xhr = new window.XMLHttpRequest();
xhr.open('GET', requestURL, true);
if (callback) {
xhr.onreadystatechange = httpRequestCallback;
}
xhr.send(null);
return true;
}
/**
* Generate the callback function for this particular shader.
* The function will also process the shader in the callback.
*/
function shaderResponseCallback(shaderName) {
var sourceName = shaderName;
return function shaderResponseFn(responseText, status) {
// If the server returns 200, then the asset is included as responseText and can be
processed.
if (status === 200) {
try {
shaderMapping[sourceName] = JSON.parse(responseText);
}
catch (e) {
console.error("Failed to parse shader with error: " + e);
}
}
else {
console.error("Failed to load shader with status: " + status);
}
};
}
/**
* Actual request for the asset.
* The request should be made if there is no entry for shaderName in the shaderMapping.
* The allows the mapping to be set to null to force the shader to be re-requested.
*/
var shaderName = "shaders/debug.cgfx";
if (!shaderMapping[shaderName]) {
if (!requestStaticAssetFn(shaderName, shaderResponseCallback(shaderName))) {
console.error("Failed to make a request for: " + shaderName);
}
}
Search WWH ::




Custom Search