Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/glsl_variables/parser.ts>parse

Read a GLSL string and return a parsed list of its variables. Only supports WebGL 2.0.
Latest
function parse
import { parse } from "https://deno.land/x/glsl_variables@v1.0.2/parser.ts";

This function returns the list of parsed input/output variables in a shader code string.

It returns the array of all variables processed. These include the shader input and output variables as well as any structs declared on the shader. The structs might be useful if they are referenced as a type in a Uniform Buffer Object. The structs are placed at the end of the returned array.

It works in three stages:

  1. Remove comments from the shader (their contents might interfere w/ parser)
  2. Read and remove all blocks content - strings inside "(",")" and inside "{","}" get removed and placed in an array to be used later. Their contents get replaced by their index on the array.
  3. On this string read all expressions (these end with ';') and parse the possible variable declarations in them.

A bit of extra work is done between step 2 and 3 to handle structs and their possible usage in Uniform Buffer Objects.

Parameters

code: string

the string with the GLSL shader code to analyze and parse