grovesNL / glow

GL on Whatever: a set of bindings to run GL anywhere and avoid target-specific code
Apache License 2.0
1.2k stars 130 forks source link

Converting raw u32 to glow::Texture #200

Closed Colecf closed 2 years ago

Colecf commented 2 years ago

Hi, is it possible to take a texture id given as a u32 and wrap it as a glow::Texture? I'm using the openxr crate, which gives you textures to render to as u32s, and I can't figure out how to make them into a glow::Texture, considering NativeTexture's field is private.

error[E0423]: cannot initialize a tuple struct which contains private fields
   --> src\vr.rs:163:26
    |
163 |                 texture: glow::NativeTexture(NonZeroU32::new(texture).unwrap()),
    |                          ^^^^^^^^^^^^^^^^^^^
    |
note: constructor is not visible here due to private fields
   --> C:\Users\Cole\.cargo\registry\src\github.com-1ecc6299db9ec823\glow-0.11.0\src\native.rs:97:26
    |
97  | pub struct NativeTexture(NonZeroU32);
    |                          ^^^^^^^^^^ private field
grovesNL commented 2 years ago

Hi! 👋 This isn't possible at the moment but you might be able to work around it using transmute temporarily.

I think we could definitely add a function to create a NativeTexture from a u32 handle to support this case. Feel free to add a PR if you'd like, otherwise I'll try to add something soon!

Colecf commented 2 years ago

Ah thanks for the tip, transmute does actually work perfectly.

It's kindof a hassle for me to get permission from the company I work for to contribute to open source projects, so I don't think it's worth it for something so small. But thanks for the tip, I'll keep an eye on future releases to see if this gets improved.

Colecf commented 2 years ago

Wow that was fast, thanks again!

grovesNL commented 2 years ago

No problem! The fix is included in the newest release (0.11.2). Please let me know if you run into any other problems with OpenXR integration