Macro to generate MeshVertexAttributeId from call site info
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## What problem does this solve or what need does it fill?
Currently the recommended way to get a unique `MeshVertexAttributeId` seems to be to hardcode an arbitrary number, which is clunky and error-prone (human-picked numbers are generally not very random). We can do better than this, with a macro that generates a unique id using the `file!()`, `line!()` and `column!()` macros in Rust. That would make it essentially impossible for an id collision,
## What solution would you like?
Currently, in the [`custom_vertex_attribute` example](https://github.com/bevyengine/bevy/blob/87722d135fcc7e6058aa4710e7fe5be5f2a6e594/examples/shader/custom_vertex_attribute.rs#L27), the id for the BlendColor attribute is hardcoded to 988540917. A more ergonomic and less error-prone way to do this might look like the following:
```rs
const ATTRIBUTE_BLEND_COLOR: MeshVertexAttribute =
MeshVertexAttribute::new("BlendColor", id_from_callsite!(), VertexFormat::Float32x4);
```
## What alternative(s) have you considered?
This seems like a good use case for a UUID, but doing that automatically would make the ordering of `MeshVertexAttribute`s non-deterministic, which could lead to extremely difficult to find bugs.
## Additional context
[`examples/custom_vertex_attribute`](https://github.com/bevyengine/bevy/blob/latest/examples/shader/custom_vertex_attribute.rs)
[`MeshVertexAttributeId`](https://docs.rs/bevy/latest/bevy/render/mesh/struct.MeshVertexAttributeId.html)
Note: need suggestions for a good name for this macro.
Contributor guide
Assessment
This issue has not been assessed yet.