[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] WebGLSL Media Type Proposal




Mock <scripttag> kind of API:
   var script = document.createElement('script');
   script.onload = function(){
     gl.shaderSource(shader, script.innerText);
   }
   script.defer = 'defer';
   script.src = 'sometext.txt';
   var head = document.head;
   head.appendChildElement(script);

Are you deliberately trying to make this look harder than it is?

<script id="foo" type="x-shader/x-vertex" src="file"></script>

<script type="text/javascript">
  function init() {
    // WebGL init code here

    gl.shaderSource(shader, document.getElementById("foo").innerText);
  }
</script>

<body onload="init()"></body>

2 lines added to your document (the rest is boilerplate), and you've got your shader loaded, and switching between sourced and embedded code is dirt simple.

onload triggers when document has been loaded. This includes any sourced files. Most web developers will avoid touching the DOM until everything is loaded if they can do so.

I know everyone's in love with asynchronous APIs these days, but sometimes, you want something with less bloat.

Thor




----------------------------------------------------------- You are currently subscribed to public_webgl@khronos.org. To unsubscribe, send an email to majordomo@khronos.org with the following command in the body of your email: unsubscribe public_webgl -----------------------------------------------------------