brendanzab / gl-rs

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

glGetPointerv's pointer argument gets the wrong mutability #541

Open hikari-no-yume opened 1 year ago

hikari-no-yume commented 1 year ago

Example usage:

let mut pointer: *mut GLvoid = std::ptr::null_mut();
gl21::GetPointerv(gl21::NORMAL_ARRAY_POINTER, &mut pointer);

I was surprised when Clippy gave me this warning:

warning: the function gl21::GetPointerv doesn't need a mutable reference

Looking at the generated documentation, it seems that gl_generator produced this signature:

pub unsafe fn GetPointerv(pname: u32, params: *const *mut c_void)

I think the mutability here is the exact opposite of what it should be: the pointer returned is *const so far as the API should care, but it needs a *mut pointer to be able to write it out. Though I see that the Khronos C headers use void** so *mut *mut might be more faithful to the original API.

This happens for at least OpenGL 2.1 compatibility profile and OpenGL ES 1.1.

I might eventually attempt to fix this myself, I assume it's something simple.

Lokathor commented 1 year ago

*mut *mut is probably the best way in this situation.