Summary
We plan to use the Rust crate glsl-lang in crates/jsbindings/webgl.rs to parse vertex shader source code, extract all attribute metadata, and expose the results to C/C++ so they can be used for attrib location management (e.g., for getAttribLocation).
Implementation Steps
-
Use glsl-lang for GLSL parsing in Rust
- Integrate glsl-lang as a dependency in the Rust workspace.
- Implement a Rust struct (e.g.,
MyGLSLParser) that takes vertex shader source code and uses glsl-lang to parse and extract all attribute declarations, including name, type, and order.
- Store the attributes in a struct with ordered locations (location assignment based on appearance).
- Provide methods to query attrib metadata and location by name.
-
Expose the attribute info to C/C++
- Use Rust's FFI (e.g.,
#[no_mangle] extern "C" functions) to expose functions for C/C++ to parse shader source and retrieve attribute info (names/types/locations).
- Design C-compatible structs for the attribs and provide functions to allocate and free them from C/C++.
- Document the FFI interface and expected usage from the C/C++ side.
-
Testing
- Add tests for parsing and location assignment (covering various GLSL syntax cases).
Reference
Related Code
crates/jsbindings/webgl.rs (Rust binding and FFI interface)
- C++: WebGL shader/program management code
Please comment if you have suggestions about the FFI design or want to discuss specific integration details.
Summary
We plan to use the Rust crate glsl-lang in
crates/jsbindings/webgl.rsto parse vertex shader source code, extract all attribute metadata, and expose the results to C/C++ so they can be used for attrib location management (e.g., forgetAttribLocation).Implementation Steps
Use glsl-lang for GLSL parsing in Rust
MyGLSLParser) that takes vertex shader source code and uses glsl-lang to parse and extract allattributedeclarations, including name, type, and order.Expose the attribute info to C/C++
#[no_mangle] extern "C"functions) to expose functions for C/C++ to parse shader source and retrieve attribute info (names/types/locations).Testing
Reference
Related Code
crates/jsbindings/webgl.rs(Rust binding and FFI interface)Please comment if you have suggestions about the FFI design or want to discuss specific integration details.