Vector swizzling a-la GPU shaders in D

ponce via Digitalmars-d digitalmars-d at puremagic.com
Tue Feb 24 07:43:55 PST 2015


On Tuesday, 24 February 2015 at 15:38:55 UTC, Denis 'GeneralGDA' 
Gladkiy wrote:
> I was playing with D for a several weeks and came up with a 
> swizzling implementation for a vector class. The feature is 
> common for languages like GLSL or HLSL. One of the use cases is 
> a vector cross product with only two GPU instructions.
>
> Here is the idea:
> http://pastebin.com/Hvntey0s
>
> Here is the full source of the vector:
> http://pastebin.com/AnJKXBry
>
> The code allows you to write something like "const foo = 
> bar.yyzx" where bar is a vector and ".yyzx" constructs a new 
> one from it.
>
> This is not a production code. I believe one could make it much 
> better. But the idea seems to be interesting in the area of 
> inner DSLs for D.

I'm sorry this is nothing new.
https://github.com/Dav1dde/gl3n/blob/master/gl3n/linalg.d#L390
https://github.com/d-gamedev-team/gfm/blob/master/math/gfm/math/vector.d#L297


More information about the Digitalmars-d mailing list