-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
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 allattributedeclarations, 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.
- Use Rust's FFI (e.g.,
-
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.
Copilot
Metadata
Metadata
Assignees
Labels
No labels