brendanzab / gl-rs

An OpenGL function pointer loader for Rust
Apache License 2.0
678 stars 117 forks source link

GLenum is unsigned, but some GL functions needing enum values use a (signed) GLint #515

Closed hikari-no-yume closed 1 year ago

hikari-no-yume commented 4 years ago

GLenum is an unsigned integer type, c_uint, but some GL functions that need GL enum values take a GLint, and rustc complains about this. An example is glTexParameteri:

error[E0308]: mismatched types
  --> src/texture.rs:58:63
   |
58 |         gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE);
   |                                                               ^^^^^^^^^^^^^^^^^ expected i32, found u32
help: you can convert an `u32` to `i32` and panic if the converted value wouldn't fit
   |
58 |         gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE.try_into().unwrap());
   |                                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Having to write as GLint isn't the worst thing in the world, but it is a little annoying. I wonder if there could be a nice solution to make such cases work without casting?

Obviously this is a very low-priority issue, especially since such cases are probably handled by higher-level libraries, and I don't expect anyone to fix it for me.

Lokathor commented 4 years ago

This is unfortunately a "bug" in how the GL.xml file specifies the functions and the fact that C will automatically convert values between types.

There is not much that can be done about this at the Rust layer

hikari-no-yume commented 1 year ago

Yeah that's fair.