rustwasm / wasm-bindgen

Facilitating high-level interactions between Wasm modules and JavaScript
https://rustwasm.github.io/docs/wasm-bindgen/
Apache License 2.0
7.74k stars 1.07k forks source link

tex_image_2d overload taking an HtmlImageElement should have the same name in WebGL 1 and 2 #1195

Open nstoddard opened 5 years ago

nstoddard commented 5 years ago

I'm trying to use tex_image_2d_with_u32_and_u32_and_image in WebGL 2, but it seems to only be available in WebGL 1: https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.WebGlRenderingContext.html?search=tex_image_2d_with_u32_and_u32_and_image.

From the IDL, it looks like WebGL 2 also adds another overload that takes HtmlImageElement plus some new parameters. Why isn't this overload available in web-sys?

nstoddard commented 5 years ago

Looks like it actually does exist, but it's named tex_image_2d_with_u32_and_u32_and_html_image_element.

It's unfortunate that the same function has a different name in different versions of WebGL. Would it be possible to use the same name for both?

alexcrichton commented 5 years ago

Thanks for the report! Currently though this crate is entirely procedurally generated from the associated WebIDL. We do approximations for overloads like this given the IDL that we have, often producing weird names like this that can be somewhat inconsistent.

Here I think it's because texImage2d perhaps has different overloads in the 1/2 versions?

nstoddard commented 5 years ago

Yep, WebGL 2 adds several more overloads for texImage2d. But all the overloads from version 1 are still available, and ideally those would have the same name in both versions. Looks like the only difference between the two versions is that the parameter name is different between WebGL 1 and 2, which could be the cause.

alexcrichton commented 5 years ago

We could try to update the WebIDL directly, but that unfortunately may be a breaking change :(

We sort of just do our best in terms of naming and it doesn't always turn out as well as one might expect! Otherwise though it's roughly intended that web-sys is generally how APIs are built rather than the end-point of usage