Path: blob/main_old/doc/CompilingTranslatorWithEmscripten.md
1693 views
Introduction
There are many situations in which it's useful for WebGL applications to transform shaders in various ways. ANGLE's shader translator can be used for this purpose: compiling it with Emscripten allows it to be invoked from a web page. This wiki page provides some preliminary details about how to do this.
Details
Pull top of tree ANGLE.
Install the Emscripten toolchain per the instructions.
Symlink (preferred) or copy the ANGLE directory into ...emsdk/emscripten/master.
Put a shader to compile into a file (named with .vert or .frag suffix) in the same directory. For example, put the following shader from the [WebGL Aquarium] (http://webglsamples.org/aquarium/aquarium.html) into aq-fish-nm.frag
:
Compile the shader translator, the translator sample, and the shader all together:
Serve up the resulting translator.html via python -m SimpleHTTPServer
. Navigate the browser to localhost:8000.
The translator sample will run, displaying its output into the text area on the page. Since it isn't receiving any input, it simply outputs a help message and exits.
To invoke the translator again, processing the shader we included along with the source code, open the JavaScript console and type:
The active uniforms and their types will be printed to the text area after the translator sample processes the shader.
Issues and Next Steps
It's clearly not useful to have to compile the shader in to the Emscripten-translated executable. It would be helpful to define a simple wrapper function which can easily be called from JavaScript and which defines enough parameters to pass in a shader as a string, transform it somehow or compile it to another language target, and return the compiled result (or other information). A simple JavaScript library that wraps all of the interactions with the Emscripten binary would be useful.
It's not feasible to interact with the translator's data structures, nor traverse the AST from JavaScript. The code that operates upon the shader must be written in C++ and compiled in to the shader translator.
emcc should be integrated better with ANGLE's build system.