www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Vector swizzling a-la GPU shaders in D

reply "Denis 'GeneralGDA' Gladkiy" <denis.gladkiy yahoo.com> writes:
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.
Feb 24 2015
parent "ponce" <contact gam3sfrommars.fr> writes:
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
Feb 24 2015