vulkano-rs / vulkano

Safe and rich Rust wrapper around the Vulkan API
Apache License 2.0
4.48k stars 433 forks source link

Replace cgmath with glam in the examples #2475

Closed stefnotch closed 6 months ago

stefnotch commented 6 months ago
  1. [x] Update documentation to reflect any user-facing changes - in this repository.

  2. [x] Make sure that the changes are covered by unit-tests.

  3. [x] Run cargo clippy on the changes.

  4. [x] Run cargo +nightly fmt on the changes.

  5. [x] Please put changelog entries in the description of this Pull Request if knowledge of this change could be valuable to users. No need to put the entries to the changelog directly, they will be transferred to the changelog file by maintainers right after the Pull Request merge.

    Please remove any items from the template below that are not applicable.

  6. [x] Describe in common words what is the purpose of this change, related Github Issues, and highlight important implementation aspects.

Changelog:

### Additions
- Support for the `glam` crate in the type_for_format! macro.

Changes the examples to use glam instead of cgmath.

I also added support for the glam crate in the type_for_format! macro. However, I did not do any checking. Which means that code like

let x: vulkano::type_for_format!(glam, R16G16B16_SFLOAT) = Default::default();

will fail, since glam doesn't have a f16 floating point type. Is that fine?

The error message does tell the user roughly what went wrong, which is better than nothing.

   Compiling teapot v0.0.0 (C:\Coding\GitHub\Libraries\vulkano\examples\teapot)
error[E0433]: failed to resolve: could not find `f16` in `glam`
  --> examples\teapot\main.rs:62:12
   |
62 |     let x: vulkano::type_for_format!(glam, R16G16B16_SFLOAT) = Default::default();
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `f16` in `glam`
   |
   = note: this error originates in the macro `vulkano::type_for_format` (in Nightly
stefnotch commented 6 months ago

I fixed and tested the glam type_for_format code.

I used this for testing. I'll happily add some testing code along these lines, but am unsure of where one would add it.

fn print_type_of<T>(_: &T) {
    println!("{}", std::any::type_name::<T>())
}

    let x: vulkano::type_for_format!(glam, R8G8_UNORM) = Default::default();
    print_type_of(&x); // [u8; 2]
    let x: vulkano::type_for_format!(glam, R16G16_UNORM) = Default::default();
    print_type_of(&x); // glam::u16::u16vec2::U16Vec2
    let x: vulkano::type_for_format!(glam, R16G16_UINT) = Default::default();
    print_type_of(&x); // glam::u16::u16vec2::U16Vec2
    let x: vulkano::type_for_format!(glam, R16G16_SINT) = Default::default();
    print_type_of(&x); // glam::i16::i16vec2::I16Vec2

    // let x: vulkano::type_for_format!(glam, R16G16_SFLOAT) = Default::default();
    // print_type_of(&x); // Rust doesn't have a f16 type

    let x: vulkano::type_for_format!(glam, R32G32_UINT) = Default::default();
    print_type_of(&x); // glam::u32::uvec2::UVec2
    let x: vulkano::type_for_format!(glam, R32G32_SINT) = Default::default();
    print_type_of(&x); // glam::i32::ivec2::IVec2
    let x: vulkano::type_for_format!(glam, R32G32_SFLOAT) = Default::default();
    print_type_of(&x); // glam::f32::vec2::Vec2

    let x: vulkano::type_for_format!(glam, R64G64B64_UINT) = Default::default();
    print_type_of(&x); // glam::u64::u64vec3::U64Vec3
    let x: vulkano::type_for_format!(glam, R64G64B64_SINT) = Default::default();
    print_type_of(&x); // glam::i64::i64vec3::I64Vec3
    let x: vulkano::type_for_format!(glam, R64G64B64_SFLOAT) = Default::default();
    print_type_of(&x); // glam::f64::dvec3::DVec3

    let x: vulkano::type_for_format!(glam, ASTC_12x10_SFLOAT_BLOCK) = Default::default();
    print_type_of(&x); // [u8; 16]
marc0246 commented 6 months ago

We used to have a doc test for each of the crates but I removed it because it felt silly to pull in the behemoth that is nalgebra for one test.

marc0246 commented 6 months ago

Thank you for the work!