rust-gpu
rust-gpu copied to clipboard
need to assign the result of texture fetches to an explicitly Vec4 variable, before actually using it as something smaller
Currently, this doesn't work:
let pixel = image.fetch(coords);
Because fetch needs to infer the return type. So you have to write this:
let pixel: Vec4 = image.fetch(coords);
This also implies you cannot do something like:
let result = calculate(image.fetch(coords).xy + somevec);
Although it's nice to be able to use your own vector library with rust-gpu, this inconvenience makes writing shaders a bit of a pain in the rear end.
But there is a solution. As fetch and similar functions require some input, we can combine the different vector types into a single "vector type library" type that's referenced by all vector types. So by having a certain implementation of Vertor<T,N>, we can look up another Vector<T2,N2> from the same implementing library.
This way, in above example, fetch can simply return a concrete Vector<f32,4> type based on the concrete type of coords, which is likely coming from the same vector library.