GLSL Swizzling 如何用 C++实现?
黄舟
黄舟 2017-04-17 13:06:40
0
1
534
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
黄舟

There is no way to implement it directly. If you don’t want to enumerate, then there are only two ways that come to my mind:

  1. Macro

    SWIZZLING(v1,X,X,X,X) + SWIZZLING(v2,Z,Y,X,X)
    
  2. Template

    v1._<X,X,X,X>() + v2._<Z,Y,X,X>()
    

Variadic argument templates are actually simpler to make than macros with variable parameters. You can try it. The main idea is to first create a type of function F such that F(point<3>) == F(point<4>), and secondly to construct a type of piecewise function G to link G(v, X) to v.x Above, finally use variadic argument to do recursion, first get point<1>, then add a field to become point<2>, and do it until it is complete.

Finally, remember to use using + full specialization to point point<X> to type vecX.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template