Subject: Re: [boost] QVM Review
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2015-12-16 22:21:09
On Wed, Dec 16, 2015 at 7:01 PM, Rene Rivera <grafikrobot_at_[hidden]> wrote:
> On Wed, Dec 16, 2015 at 8:51 PM, Emil Dotchevski <emildotchevski_at_[hidden]
> > On Wed, Dec 16, 2015 at 1:38 PM, Rainer Deyke <rainerd_at_[hidden]>
> > > On 16.12.2015 22:21, Emil Dotchevski wrote:
> > >
> > > > The swizzling syntax must be terse or else it's useless. If you've
> > > written
> > > > shader code you'll know utterly inadequate it is to require a syntax
> > like
> > > > swizzle<1,0,3,2>(vec) instead of (vec,YXWZ). At any rate, swizzling
> > > > defined in a separate header, don't include it if you don't want it.
> > >
> > > YXWZ(vec) is not only much more readable than (vec,YXWZ), it's also one
> > > character shorter.
> > >
> > It's less conventional, in GLSL you just use vec.yxwz, and (vec,YXWZ) is
> > quite close.
> > Also, let's say you want to access the X coordinate of a vector, (vec,X)
> > more readable than X(vec).
> > I do appreciate the concerns about overloading operator comma, I was also
> > skeptical since this wasn't my idea. FWIW after years of use in actual
> > development this overload hasn't caused any problems.
> > That said, I'm fine with using a different notation for swizzling.
> IIRC the conclusion in SG14 was that swizzling is uncommon enough in
> regular programming to not warrant out-of-the-way special operators. In
> that most cases of its use are in shader languages and not in C++ itself.
A somewhat common use case is to change the dimensions of a vector:
- (v,XYZ) to get a 3D view of a 4D vector, or (v,XZ) to get a 2D view of a
3D or 4D vector;
- (v,XYZ0) or (v,XYZ1) to get a 4D view of a 3D vector.
Its use in C++ for actual swapping of elements is not as common -- that's
why it is defined in a separate header file. Yet when it is needed its use
is usually intensive. It occurs at the boundaries between different
components which sometimes require change of coordinates. QVM provides some
additional view proxies for this use case: negr/negc that can be used to
negate a row or column of a matrix, and swapr/swapc that can be used to
swap two rows or columns of a matrix.
> Did you consider the the array op: vec[X], vec[YXWZ]? It has the properties
> of both you and Rainer's ideas.
Yes, there have been numerous discussions on this list about what operator
to use for swizzling. Op[ ] is ideal except that it must be a member
function and thus it can't be defined non-intrusively.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk