search

Home  >  Q&A  >  body text

GLSL Swizzling 如何用 C++实现?

黄舟黄舟2804 days ago552

reply all(1)I'll reply

  • 黄舟

    黄舟2017-04-17 13:08:40

    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.

    reply
    0
  • Cancelreply