Vector swizzling a-la GPU shaders in D
Denis 'GeneralGDA' Gladkiy via Digitalmars-d
digitalmars-d at puremagic.com
Tue Feb 24 07:38:53 PST 2015
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.
More information about the Digitalmars-d
mailing list