Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 1.92 KB

README.md

File metadata and controls

56 lines (42 loc) · 1.92 KB

Glslang.js

Last Release

Real-time GLSL to SPIR-V translator. Powered by Glslang and Khronos' SPIR-V Tools.

Compiled into JavaScript via Emscripten.

Installation

To add Glslang.js to your web application, include it with:

<script src="glslang.min.js"></script>

or install it with the Bower command:

bower install glslangjs

Usage

// Input: GLSL source code and shader type
var type = glslang.EShLangFragment;
var source = `
    #version 150
    out vec4 finalColor;
    void main() {
        finalColor = vec4(1.0, 1.0, 1.0, 1.0);
    }`;

// Initialize Glslang
glslang.initialize();

// Compile shader
var shader = new glslang.Shader(type, source);

// Output: SPIR-V binary and disassembly
var binary = shader.data();
var disassembly = shader.disasm();

// Delete shader
shader.delete();

// Finalize Glslang
glslang.finalize();

Building

To build the Glslang.js library, clone the master branch of this repository, and do the following:

  1. Initialize the Glslang and SPIR-V Tools submodules: git submodule update --init.

  2. Install the development and client dependencies with: npm install and bower install.

  3. Install the lastest Python 2.x (64-bit), CMake and the Emscripten SDK. Follow the respective instructions and make sure all environment variables are configured correctly. Under Windows MinGW (specifically mingw32-make) is required.

  4. Finally, build the source with: grunt build.