grovesNL / glow

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

No way to construct `UniformLocation` without using `NativeUniformLocation` #243

Closed kovaxis closed 1 year ago

kovaxis commented 1 year ago

There is currently no way to construct a UniformLocation from a raw index without hardcoding a reference to NativeUniformLocation.

The following code fails to compile:

let x = glow::UniformLocation(0);

With:

expected function, tuple struct or tuple variant, found type alias `glow::UniformLocation`
can't use a type alias as a constructor

Is this intended?

notgull commented 1 year ago

Yes, this is intentional. If you use another type that implements Context, like the WebGL version, this code wouldn't work.

grovesNL commented 1 year ago

Right, the uniform location is an opaque type on WebGL (see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getUniformLocation) so we can't construct it directly. Instead we can query the uniform location and use that instead.

kovaxis commented 1 year ago

Oh, I see, I was confusing uniform locations with uniform indices, since they are the same in practice. Seems like in order to do shader introspection correctly, one must round-trip through uniform names.

Thanks!