Skip to content

Support vertex attrib parsing at crates/jsbindings/webgl #392

@yorkie

Description

@yorkie

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

  1. 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.
  2. 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.
  3. 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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions