+/*
+ * Mesa 3-D graphics library
+ * Version: 6.5
+ *
+ * Copyright (C) 2006 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
-//
-// This file defines nearly all constructors and operators for built-in data types, using
-// extended language syntax. In general, compiler treats constructors and operators as
-// ordinary functions with some exceptions. For example, the language does not allow
-// functions to be called in constant expressions - here the exception is made to allow it.
-//
-// Each implementation provides its own version of this file. Each implementation can define
-// the required set of operators and constructors in its own fashion.
-//
-// The extended language syntax is only present when compiling this file. It is implicitly
-// included at the very beginning of the compiled shader, so no built-in functions can be
-// used.
-//
-// To communicate with the implementation, a special extended "__asm" keyword is used, followed
-// by an instruction name (any valid identifier), a destination variable identifier and a
-// a list of zero or more source variable identifiers. A variable identifier is a variable name
-// declared earlier in the code (as a function parameter, local or global variable).
-// An instruction name designates an instruction that must be exported by the implementation.
-// Each instruction receives data from source variable identifiers and returns data in the\r
-// destination variable identifier.
-//
-// It is up to the implementation how to define a particular operator or constructor. If it is
-// expected to being used rarely, it can be defined in terms of other operators and constructors,
+//
+// This file defines nearly all constructors and operators for built-in data
+// types, using extended language syntax. In general, compiler treats
+// constructors and operators as ordinary functions with some exceptions.
+// For example, the language does not allow functions to be called in
+// constant expressions - here the exception is made to allow it.
+//
+// Each implementation provides its own version of this file. Each
+// implementation can define the required set of operators and constructors
+// in its own fashion.
+//
+// The extended language syntax is only present when compiling this file.
+// It is implicitly included at the very beginning of the compiled shader,
+// so no built-in functions can be used.
+//
+// To communicate with the implementation, a special extended "__asm" keyword
+// is used, followed by an instruction name (any valid identifier), a
+// destination variable identifier and a list of zero or more source
+// variable identifiers.
+//
+// A variable identifier is a variable name declared earlier in the code
+// (as a function parameter, local or global variable).
+//
+// An instruction name designates an instruction that must be exported
+// by the implementation. Each instruction receives data from source
+// variable identifiers and returns data in the destination variable
+// identifier.
+//
+// It is up to the implementation how to define a particular operator
+// or constructor. If it is expected to being used rarely, it can be
+// defined in terms of other operators and constructors,
// for example:
-//
+//
// ivec2 __operator + (const ivec2 x, const ivec2 y) {
// return ivec2 (x[0] + y[0], x[1] + y[1]);
// }
-//
-// If a particular operator or constructor is expected to be used very often or is an atomic
-// operation (that is, an operation that cannot be expressed in terms of other operations or
-// would create a dependency cycle) it must be defined using one or more __asm constructs.
-//
-// Each implementation must define constructors for all scalar types (bool, float, int).
-// There are 9 scalar-to-scalar constructors (including identity constructors). However,
-// since the language introduces special constructors (like matrix constructor with a single
+//
+// If a particular operator or constructor is expected to be used very
+// often or is an atomic operation (that is, an operation that cannot be
+// expressed in terms of other operations or would create a dependency
+// cycle) it must be defined using one or more __asm constructs.
+//
+// Each implementation must define constructors for all scalar types
+// (bool, float, int). There are 9 scalar-to-scalar constructors
+// (including identity constructors). However, since the language
+// introduces special constructors (like matrix constructor with a single
// scalar value), implementations must also implement these cases.
// The compiler provides the following algorithm when resolving a constructor:
// - try to find a constructor with a prototype matching ours,
-// - if no constructor is found and this is a scalar-to-scalar constructor, raise an error,
+// - if no constructor is found and this is a scalar-to-scalar constructor,
+// raise an error,
// - if a constructor is found, execute it and return,
-// - count the size of the constructor parameter list - if it is less than the size of
-// our constructor's type, raise an error,
-// - for each parameter in the list do a recursive constructor matching for appropriate
-// scalar fields in the constructed variable,
-//
-// Each implementation must also define a set of operators that deal with built-in data types.
+// - count the size of the constructor parameter list - if it is less than
+// the size of our constructor's type, raise an error,
+// - for each parameter in the list do a recursive constructor matching for
+// appropriate scalar fields in the constructed variable,
+//
+// Each implementation must also define a set of operators that deal with
+// built-in data types.
// There are four kinds of operators:
-// 1) Operators that are implemented only by the compiler: "()" (function call), "," (sequence)
-// and "?:" (selection).
-// 2) Operators that are implemented by the compiler by expressing it in terms of other operators:
+// 1) Operators that are implemented only by the compiler: "()" (function
+// call), "," (sequence) and "?:" (selection).
+// 2) Operators that are implemented by the compiler by expressing it in
+// terms of other operators:
// - "." (field selection) - translated to subscript access,
-// - "&&" (logical and) - translated to "<left_expr> ? <right_expr> : false",
+// - "&&" (logical and) - translated to "<left_expr> ? <right_expr> :
+// false",
// - "||" (logical or) - translated to "<left_expr> ? true : <right_expr>",
-// 3) Operators that can be defined by the implementation and if the required prototype is not
-// found, standard behaviour is used:
-// - "==", "!=", "=" (equality, assignment) - compare or assign matching fields one-by-one;
-// note that at least operators for scalar data types must be defined by the implementation
-// to get it work,
-// 4) All other operators not mentioned above. If no required prototype is found, an error is
-// raised. An implementation must follow the language specification to provide all valid
-// operator prototypes.
-//
+// 3) Operators that can be defined by the implementation and if the required
+// prototype is not found, standard behaviour is used:
+// - "==", "!=", "=" (equality, assignment) - compare or assign
+// matching fields one-by-one;
+// note that at least operators for scalar data types must be defined
+// by the implementation to get it work,
+// 4) All other operators not mentioned above. If no required prototype is
+// found, an error is raised. An implementation must follow the language
+// specification to provide all valid operator prototypes.
+//
-//
-// From Shader Spec, ver. 1.10, rev. 59
-//
-//
-// 5.4.1 Conversion and Scalar Constructors
-//
-//
-// When constructors are used to convert a float to an int, the fractional part of the
-// floating-point value is dropped.
-//
+//// Basic, scalar constructors/casts
-int __constructor (const float _f) {
- int _i;
- __asm float_to_int _i, _f;
- return _i;
+int __constructor(const float f)
+{
+ __asm vec4_to_ivec4 __retVal, f;
}
-//
-// When a constructor is used to convert an int or a float to bool, 0 and 0.0 are converted to
-// false, and nonzero values are converted to true.
-//
+int __constructor(const bool b)
+{
+ __retVal = b;
+}
-bool __constructor (const int _i) {
- return _i != 0;
+int __constructor(const int i)
+{
+ __retVal = i;
}
-bool __constructor (const float _f) {
- return _f != 0.0;
+bool __constructor(const int i)
+{
+ __asm vec4_sne __retVal, i, 0.0;
}
-//
-// When a constructor is used to convert a bool to an int or float, false is converted to 0 or
-// 0.0, and true is converted to 1 or 1.0.
-//
+bool __constructor(const float f)
+{
+ __asm vec4_sne __retVal, f, 0.0;
+}
-int __constructor (const bool _b) {
- return _b ? 1 : 0;
+bool __constructor(const bool b)
+{
+ __retVal = b;
}
-float __constructor (const bool _b) {
- return _b ? 1.0 : 0.0;
+float __constructor(const int i)
+{
+ __asm ivec4_to_vec4 __retVal, i;
}
-//
-// Int to float constructor.
-//
+float __constructor(const bool b)
+{
+ __asm ivec4_to_vec4 __retVal, b;
+}
-float __constructor (const int _i) {
- float _f;
- __asm int_to_float _f, _i;
- return _f;
+float __constructor(const float f)
+{
+ __retVal = f;
}
-//
-// Identity constructors, like float(float) are also legal, but of little use.
-//
-bool __constructor (const bool _b) {
- return _b;
-}
+//// vec2 constructors
-int __constructor (const int _i) {
- return _i;
+vec2 __constructor(const float x, const float y)
+{
+ __retVal.x = x;
+ __retVal.y = y;
}
-float __constructor (const float _f) {
- return _f;
+vec2 __constructor(const float f)
+{
+ __asm vec4_move __retVal.xy, f;
}
-//
-// Scalar constructors with non-scalar parameters can be used to take the first element from
-// a non-scalar. For example, the constructor float(vec3) will select the first component of the
-// vec3 parameter.
-//
+vec2 __constructor(const int i)
+{
+ __asm ivec4_to_vec4 __retVal.xy, i;
+}
-// [These scalar conversions will be handled internally by the compiler.]
+vec2 __constructor(const bool b)
+{
+ __asm ivec4_to_vec4 __retVal.xy, b;
+}
-//
-// 5.4.2 Vector and Matrix Constructors
-//
-// Constructors can be used to create vectors or matrices from a set of scalars, vectors,
-// or matrices. This includes the ability to shorten vectors.
-//
+vec2 __constructor(const bvec2 b)
+{
+// __retVal = b;
+ __asm ivec4_to_vec4 __retVal.xy, b;
+}
-//
-// If there is a single scalar parameter to a vector constructor, it is used to initialize all
-// components of the constructed vector to that scalar's value.
-//
-// If the basic type (bool, int, or float) of a parameter to a constructor does not match the basic
-// type of the object being constructed, the scalar construction rules (above) are used to convert
-// the parameters.
-//
+vec2 __constructor(const vec3 v)
+{
+ __asm vec4_move __retVal.xy, v.xy;
+}
-vec2 __constructor (const float _f) {
- return vec2 (_f, _f);
+vec2 __constructor(const vec4 v)
+{
+ __asm vec4_move __retVal.xy, v.xy;
}
-vec2 __constructor (const int _i) {
- return vec2 (_i, _i);
+
+//// vec3 constructors
+
+vec3 __constructor(const float x, const float y, const float z)
+{
+ __retVal.x = x;
+ __retVal.y = y;
+ __retVal.z = z;
}
-vec2 __constructor (const bool _b) {
- return vec2 (_b, _b);
+vec3 __constructor(const float f)
+{
+ // Note: this could be "__retVal.xyz = f" but that's an illegal assignment
+ __asm vec4_move __retVal.xyz, f;
}
-vec3 __constructor (const float _f) {
- return vec3 (_f, _f, _f);
+vec3 __constructor(const int i)
+{
+ __asm ivec4_to_vec4 __retVal.xyz, i;
}
-vec3 __constructor (const int _i) {
- return vec3 (_i, _i, _i);
+vec3 __constructor(const bool b)
+{
+ __asm ivec4_to_vec4 __retVal.xyz, b;
}
-vec3 __constructor (const bool _b) {
- return vec3 (_b, _b, _b);
+vec3 __constructor(const bvec3 b)
+{
+ __asm ivec4_to_vec4 __retVal.xyz, b;
}
-vec4 __constructor (const float _f) {
- return vec4 (_f, _f, _f, _f);
+vec3 __constructor(const vec4 v)
+{
+ __asm vec4_move __retVal.xyz, v;
}
-vec4 __constructor (const int _i) {
- return vec4 (_i, _i, _i, _i);
+
+//// vec4 constructors
+
+vec4 __constructor(const float x, const float y, const float z, const float w)
+{
+ __retVal.x = x;
+ __retVal.y = y;
+ __retVal.z = z;
+ __retVal.w = w;
}
-vec4 __constructor (const bool _b) {
- return vec4 (_b, _b, _b, _b);
+vec4 __constructor(const float f)
+{
+ // Note: this could be "__retVal = f" but that's an illegal assignment
+ __asm vec4_move __retVal, f;
}
-ivec2 __constructor (const int _i) {
- return ivec2 (_i, _i);
+vec4 __constructor(const int i)
+{
+ __asm ivec4_to_vec4 __retVal, i;
}
-ivec2 __constructor (const float _f) {
- return ivec2 (_f, _f);
+vec4 __constructor(const bool b)
+{
+ __asm ivec4_to_vec4 __retVal, b;
}
-ivec2 __constructor (const bool _b) {
- return ivec2 (_b, _b);
+vec4 __constructor(const bvec4 b)
+{
+ __asm ivec4_to_vec4 __retVal, b;
}
-ivec3 __constructor (const int _i) {
- return ivec3 (_i, _i, _i);
+vec4 __constructor(const ivec4 i)
+{
+ __asm ivec4_to_vec4 __retVal, i;
}
-ivec3 __constructor (const float _f) {
- return ivec3 (_f, _f, _f);
+vec4 __constructor(const vec3 v3, const float f)
+{
+ // XXX this constructor shouldn't be needed anymore
+ __retVal.xyz = v3;
+ __retVal.w = f;
}
-ivec3 __constructor (const bool _b) {
- return ivec3 (_b, _b, _b);
+vec4 __constructor(const vec2 v2, const float f1, const float f2)
+{
+ // XXX this constructor shouldn't be needed anymore
+ __retVal.xy = v2;
+ __retVal.z = f1;
+ __retVal.w = f2;
}
-ivec4 __constructor (const int _i) {
- return ivec4 (_i, _i, _i, _i);
+
+//// ivec2 constructors
+
+ivec2 __constructor(const int i, const int j)
+{
+ __retVal.x = i;
+ __retVal.y = j;
}
-ivec4 __constructor (const float _f) {
- return ivec4 (_f, _f, _f, _f);
+ivec2 __constructor(const int i)
+{
+ __asm vec4_move __retVal.xy, i;
}
-ivec4 __constructor (const bool _b) {
- return ivec4 (_b, _b, _b, _b);
+ivec2 __constructor(const float f)
+{
+ __asm vec4_to_ivec4 __retVal.xy, f;
}
-bvec2 __constructor (const bool _b) {
- return bvec2 (_b, _b);
+ivec2 __constructor(const bool b)
+{
+ __asm vec4_to_ivec4 __retVal.xy, b;
}
-bvec2 __constructor (const float _f) {
- return bvec2 (_f, _f);
+
+//// ivec3 constructors
+
+ivec3 __constructor(const int i, const int j, const int k)
+{
+ __retVal.x = i;
+ __retVal.y = j;
+ __retVal.z = k;
}
-bvec2 __constructor (const int _i) {
- return bvec2 (_i, _i);
+ivec3 __constructor(const int i)
+{
+ __asm vec4_move __retVal.xyz, i;
}
-bvec3 __constructor (const bool _b) {
- return bvec3 (_b, _b, _b);
+ivec3 __constructor(const float f)
+{
+ __asm vec4_to_ivec4 __retVal.xyz, f;
}
-bvec3 __constructor (const float _f) {
- return bvec3 (_f, _f, _f);
+ivec3 __constructor(const bool b)
+{
+ __asm vec4_move __retVal.xyz, b;
}
-bvec3 __constructor (const int _i) {
- return bvec3 (_i, _i, _i);
+
+//// ivec4 constructors
+
+ivec4 __constructor(const int x, const int y, const int z, const int w)
+{
+ __retVal.x = x;
+ __retVal.y = y;
+ __retVal.z = z;
+ __retVal.w = w;
}
-bvec4 __constructor (const bool _b) {
- return bvec4 (_b, _b, _b, _b);
+ivec4 __constructor(const int i)
+{
+ __asm vec4_move __retVal, i;
}
-bvec4 __constructor (const float _f) {
- return bvec4 (_f, _f, _f, _f);
+ivec4 __constructor(const float f)
+{
+ __asm vec4_to_ivec4 __retVal, f;
}
-bvec4 __constructor (const int _i) {
- return bvec4 (_i, _i, _i, _i);
+ivec4 __constructor(const bool b)
+{
+ __asm vec4_to_ivec4 __retVal, b;
}
-//
-// If there is a single scalar parameter to a matrix constructor, it is used to initialize all the
-// components on the matrix's diagonal, with the remaining components initialized to 0.0.
-// (...) Matrices will be constructed in column major order. It is an error to construct matrices
-// from other matrices. This is reserved for future use.
-//
-// If the basic type (bool, int, or float) of a parameter to a constructor does not match the basic
-// type of the object being constructed, the scalar construction rules (above) are used to convert
-// the parameters.
-//
-mat2 __constructor (const float _f) {
- return mat2 (
- _f, .0,
- .0, _f
- );
+//// bvec2 constructors
+
+bvec2 __constructor(const bool b1, const bool b2)
+{
+ __retVal.x = b1;
+ __retVal.y = b2;
+}
+
+bvec2 __constructor(const int i1, const int i2)
+{
+ __asm vec4_sne __retVal.x, i1, 0.0;
+ __asm vec4_sne __retVal.y, i2, 0.0;
}
-mat2 __constructor (const int _i) {
- return mat2 (
- _i, .0,
- .0, _i
- );
+
+bvec2 __constructor(const bool b)
+{
+ __asm vec4_move __retVal.xy, b;
}
-mat2 __constructor (const bool _b) {
- return mat2 (
- _b, .0,
- .0, _b
- );
+bvec2 __constructor(const float f)
+{
+ __asm vec4_sne __retVal.xy, f, 0.0;
}
-mat3 __constructor (const float _f) {
- return mat3 (
- _f, .0, .0,
- .0, _f, .0,
- .0, .0, _f
- );
+bvec2 __constructor(const int i)
+{
+ __asm vec4_sne __retVal.xy, i, 0.0;
}
-mat3 __constructor (const int _i) {
- return mat3 (
- _i, .0, .0,
- .0, _i, .0,
- .0, .0, _i
- );
+bvec2 __constructor(const vec2 v)
+{
+ __asm vec4_sne __retVal.xy, v, 0.0;
}
-mat3 __constructor (const bool _b) {
- return mat3 (
- _b, .0, .0,
- .0, _b, .0,
- .0, .0, _b
- );
+bvec2 __constructor(const ivec2 v)
+{
+ __asm vec4_sne __retVal.xy, v, 0.0;
}
-mat4 __constructor (const float _f) {
- return mat4 (
- _f, .0, .0, .0,
- .0, _f, .0, .0,
- .0, .0, _f, .0,
- .0, .0, .0, _f
- );
+
+
+//// bvec3 constructors
+
+bvec3 __constructor(const bool b1, const bool b2, const bool b3)
+{
+ __retVal.x = b1;
+ __retVal.y = b2;
+ __retVal.z = b3;
}
-mat4 __constructor (const int _i) {
- return mat4 (
- _i, .0, .0, .0,
- .0, _i, .0, .0,
- .0, .0, _i, .0,
- .0, .0, .0, _i
- );
+bvec3 __constructor(const float f1, const float f2, const float f3)
+{
+ __asm vec4_sne __retVal.x, f1, 0.0;
+ __asm vec4_sne __retVal.y, f2, 0.0;
+ __asm vec4_sne __retVal.z, f3, 0.0;
}
-mat4 __constructor (const bool _b) {
- return mat4 (
- _b, .0, .0, .0,
- .0, _b, .0, .0,
- .0, .0, _b, .0,
- .0, .0, .0, _b
- );
+bvec3 __constructor(const bool b)
+{
+ __asm vec4_move __retVal.xyz, b;
}
-//
-// 5.8 Assignments
-//
-// Assignments of values to variable names are done with the assignment operator ( = ), like
-//
-// lvalue = expression
-//
-// The assignment operator stores the value of expression into lvalue. It will compile only if
-// expression and lvalue have the same type. All desired type-conversions must be specified
-// explicitly via a constructor. Lvalues must be writable. Variables that are built-in types,
-// entire structures, structure fields, l-values with the field selector ( . ) applied to select
-// components or swizzles without repeated fields, and l-values dereferenced with the array
-// subscript operator ( [ ] ) are all possible l-values. Other binary or unary expressions,
-// non-dereferenced arrays, function names, swizzles with repeated fields, and constants cannot
-// be l-values.
-//
-// Expressions on the left of an assignment are evaluated before expressions on the right of the
-// assignment.
-//
+bvec3 __constructor(const float f)
+{
+ __asm vec4_sne __retVal.xyz, f, 0.0;
+}
-void __operator = (out float a, const float b) {
- __asm float_copy a, b;
+bvec3 __constructor(const int i)
+{
+ __asm vec4_sne __retVal.xyz, i, 0.0;
}
-void __operator = (out int a, const int b) {
- __asm int_copy a, b;
+bvec3 __constructor(const vec3 v)
+{
+ __asm vec4_sne __retVal.xyz, v, 0.0;
}
-void __operator = (out bool a, const bool b) {
- __asm bool_copy a, b;
+bvec3 __constructor(const ivec3 v)
+{
+ __asm vec4_sne __retVal.xyz, v, 0.0;
}
-void __operator = (out vec2 v, const vec2 u) {
- v.x = u.x, v.y = u.y;
+
+
+//// bvec4 constructors
+
+bvec4 __constructor(const bool b1, const bool b2, const bool b3, const bool b4)
+{
+ __retVal.x = b1;
+ __retVal.y = b2;
+ __retVal.z = b3;
+ __retVal.w = b4;
}
-void __operator = (out vec3 v, const vec3 u) {
- v.x = u.x, v.y = u.y, v.z = u.z;
+bvec4 __constructor(const float f1, const float f2, const float f3, const float f4)
+{
+ const float zero = 0.0;
+ __asm vec4_sne __retVal.x, f1, zero;
+ __asm vec4_sne __retVal.y, f2, zero;
+ __asm vec4_sne __retVal.z, f3, zero;
+ __asm vec4_sne __retVal.w, f4, zero;
}
-void __operator = (out vec4 v, const vec4 u) {
- v.x = u.x, v.y = u.y, v.z = u.z, v.w = u.w;
+bvec4 __constructor(const bool b)
+{
+ __asm vec4_move __retVal.xyzw, b;
}
-void __operator = (out ivec2 v, const ivec2 u) {
- v.x = u.x, v.y = u.y;
+bvec4 __constructor(const float f)
+{
+ __asm vec4_sne __retVal.xyzw, f, 0.0;
}
-void __operator = (out ivec3 v, const ivec3 u) {
- v.x = u.x, v.y = u.y, v.z = u.z;
+bvec4 __constructor(const int i)
+{
+ __asm vec4_sne __retVal.xyzw, i, 0.0;
}
-void __operator = (out ivec4 v, const ivec4 u) {
- v.x = u.x, v.y = u.y, v.z = u.z, v.w = u.w;
+bvec4 __constructor(const vec4 v)
+{
+ __asm vec4_sne __retVal.xyzw, v, 0.0;
}
-void __operator = (out bvec2 v, const bvec2 u) {
- v.x = u.x, v.y = u.y;
+bvec4 __constructor(const ivec4 v)
+{
+ __asm vec4_sne __retVal.xyzw, v, 0.0;
}
-void __operator = (out bvec3 v, const bvec3 u) {
- v.x = u.x, v.y = u.y, v.z = u.z;
+
+
+//// mat2 constructors
+
+mat2 __constructor(const float m00, const float m10,
+ const float m01, const float m11)
+{
+ __retVal[0].x = m00;
+ __retVal[0].y = m10;
+ __retVal[1].x = m01;
+ __retVal[1].y = m11;
}
-void __operator = (out bvec4 v, const bvec4 u) {
- v.x = u.x, v.y = u.y, v.z = u.z, v.w = u.w;
+mat2 __constructor(const float f)
+{
+ __retVal[0].x = f;
+ __retVal[0].y = 0.0;
+ __retVal[1].x = 0.0;
+ __retVal[1].y = f;
}
-void __operator = (out mat2 m, const mat2 n) {
- m[0] = n[0], m[1] = n[1];
+mat2 __constructor(const int i)
+{
+ return mat2(float(i));
}
-void __operator = (out mat3 m, const mat3 n) {
- m[0] = n[0], m[1] = n[1], m[2] = n[2];
+mat2 __constructor(const bool b)
+{
+ return mat2(float(b));
}
-void __operator = (out mat4 m, const mat4 n) {
- m[0] = n[0], m[1] = n[1], m[2] = n[2], m[3] = n[3];
+mat2 __constructor(const vec2 c0, const vec2 c1)
+{
+ __retVal[0] = c0;
+ __retVal[1] = c1;
}
-//
-// * The arithmetic assignments add into (+=), subtract from (-=), multiply into (*=), and divide
-// into (/=). The variable and expression must be the same floating-point or integer type, ...
-//
-void __operator += (inout float a, const float b) {
- __asm float_add a, a, b;
+//// mat3 constructors
+
+mat3 __constructor(const float m00, const float m10, const float m20,
+ const float m01, const float m11, const float m21,
+ const float m02, const float m12, const float m22)
+{
+ __retVal[0].x = m00;
+ __retVal[0].y = m10;
+ __retVal[0].z = m20;
+ __retVal[1].x = m01;
+ __retVal[1].y = m11;
+ __retVal[1].z = m21;
+ __retVal[2].x = m02;
+ __retVal[2].y = m12;
+ __retVal[2].z = m22;
}
-void __operator -= (inout float a, const float b) {
- a += -b;
+mat3 __constructor(const float f)
+{
+ vec2 v = vec2(f, 0.0);
+ __retVal[0] = v.xyy;
+ __retVal[1] = v.yxy;
+ __retVal[2] = v.yyx;
}
-void __operator *= (inout float a, const float b) {
- __asm float_multiply a, a, b;
+mat3 __constructor(const int i)
+{
+ return mat3(float(i));
}
-void __operator /= (inout float a, const float b) {
- __asm float_divide a, a, b;
+mat3 __constructor(const bool b)
+{
+ return mat3(float(b));
}
-void __operator += (inout int x, const int y) {
- x = int (float (x) + float (y));
+mat3 __constructor(const vec3 c0, const vec3 c1, const vec3 c2)
+{
+ __retVal[0] = c0;
+ __retVal[1] = c1;
+ __retVal[2] = c2;
}
-void __operator -= (inout int x, const int y) {
- x += -y;
+
+//// mat4 constructors
+
+mat4 __constructor(const float m00, const float m10, const float m20, const float m30,
+ const float m01, const float m11, const float m21, const float m31,
+ const float m02, const float m12, const float m22, const float m32,
+ const float m03, const float m13, const float m23, const float m33)
+{
+ __retVal[0].x = m00;
+ __retVal[0].y = m10;
+ __retVal[0].z = m20;
+ __retVal[0].w = m30;
+ __retVal[1].x = m01;
+ __retVal[1].y = m11;
+ __retVal[1].z = m21;
+ __retVal[1].w = m31;
+ __retVal[2].x = m02;
+ __retVal[2].y = m12;
+ __retVal[2].z = m22;
+ __retVal[2].w = m32;
+ __retVal[3].x = m03;
+ __retVal[3].y = m13;
+ __retVal[3].z = m23;
+ __retVal[3].w = m33;
}
-void __operator *= (inout int x, const int y) {
- x = int (float (x) * float (y));
+
+mat4 __constructor(const float f)
+{
+ vec2 v = vec2(f, 0.0);
+ __retVal[0] = v.xyyy;
+ __retVal[1] = v.yxyy;
+ __retVal[2] = v.yyxy;
+ __retVal[3] = v.yyyx;
}
-void __operator /= (inout int x, const int y) {
- x = int (float (x) / float (y));
+mat4 __constructor(const int i)
+{
+ return mat4(float(i));
}
-void __operator += (inout vec2 v, const vec2 u) {
- v.x += u.x, v.y += u.y;
+mat4 __constructor(const bool b)
+{
+ return mat4(float(b));
}
-void __operator -= (inout vec2 v, const vec2 u) {
- v.x -= u.x, v.y -= u.y;
+mat4 __constructor(const vec4 c0, const vec4 c1, const vec4 c2, const vec4 c3)
+{
+ __retVal[0] = c0;
+ __retVal[1] = c1;
+ __retVal[2] = c2;
+ __retVal[3] = c3;
}
-void __operator *= (inout vec2 v, const vec2 u) {
- v.x *= u.x, v.y *= u.y;
+
+
+//// Basic int operators
+
+int __operator + (const int a, const int b)
+{
+ __asm vec4_add __retVal, a, b;
}
-void __operator /= (inout vec2 v, const vec2 u) {
- v.x /= u.x, v.y /= u.y;
+int __operator - (const int a, const int b)
+{
+ __asm vec4_subtract __retVal, a, b;
}
-void __operator += (inout vec3 v, const vec3 u) {
- v.x += u.x, v.y += u.y, v.z += u.z;
+int __operator * (const int a, const int b)
+{
+ __asm vec4_multiply __retVal, a, b;
}
-void __operator -= (inout vec3 v, const vec3 u) {
- v.x -= u.x, v.y -= u.y, v.z -= u.z;
+int __operator / (const int a, const int b)
+{
+ float bInv, x;
+ __asm float_rcp bInv, b;
+ __asm vec4_multiply x, a, bInv;
+ __asm vec4_to_ivec4 __retVal, x;
}
-void __operator *= (inout vec3 v, const vec3 u) {
- v.x *= u.x, v.y *= u.y, v.z *= u.z;
+
+//// Basic ivec2 operators
+
+ivec2 __operator + (const ivec2 a, const ivec2 b)
+{
+ __asm vec4_add __retVal, a, b;
}
-void __operator /= (inout vec3 v, const vec3 u) {
- v.x /= u.x, v.y /= u.y, v.z /= u.z;
+ivec2 __operator - (const ivec2 a, const ivec2 b)
+{
+ __asm vec4_subtract __retVal, a, b;
}
-void __operator += (inout vec4 v, const vec4 u) {
- v.x += u.x, v.y += u.y, v.z += u.z, v.w += u.w;
+ivec2 __operator * (const ivec2 a, const ivec2 b)
+{
+ __asm vec4_multiply __retVal, a, b;
}
-void __operator -= (inout vec4 v, const vec4 u) {
- v.x -= u.x, v.y -= u.y, v.z -= u.z, v.w -= u.w;
+ivec2 __operator / (const ivec2 a, const ivec2 b)
+{
+ vec2 bInv, x;
+ __asm float_rcp bInv.x, b.x;
+ __asm float_rcp bInv.y, b.y;
+ __asm vec4_multiply x, a, bInv;
+ __asm vec4_to_ivec4 __retVal, x;
}
-void __operator *= (inout vec4 v, const vec4 u) {
- v.x *= u.x, v.y *= u.y, v.z *= u.z, v.w *= u.w;
+
+//// Basic ivec3 operators
+
+ivec3 __operator + (const ivec3 a, const ivec3 b)
+{
+ __asm vec4_add __retVal, a, b;
}
-void __operator /= (inout vec4 v, const vec4 u) {
- v.x /= u.x, v.y /= u.y, v.z /= u.z, v.w /= u.w;
+ivec3 __operator - (const ivec3 a, const ivec3 b)
+{
+ __asm vec4_subtract __retVal, a, b;
}
-void __operator += (inout ivec2 v, const ivec2 u) {
- v.x += u.x, v.y += u.y;
+ivec3 __operator * (const ivec3 a, const ivec3 b)
+{
+ __asm vec4_multiply __retVal, a, b;
}
-void __operator -= (inout ivec2 v, const ivec2 u) {
- v.x -= u.x, v.y -= u.y;
+ivec3 __operator / (const ivec3 a, const ivec3 b)
+{
+ vec3 bInv, x;
+ __asm float_rcp bInv.x, b.x;
+ __asm float_rcp bInv.y, b.y;
+ __asm float_rcp bInv.z, b.z;
+ __asm vec4_multiply x, a, bInv;
+ __asm vec4_to_ivec4 __retVal, x;
}
-void __operator *= (inout ivec2 v, const ivec2 u) {
- v.x *= u.x, v.y *= u.y;
+
+//// Basic ivec4 operators
+
+ivec4 __operator + (const ivec4 a, const ivec4 b)
+{
+ __asm vec4_add __retVal, a, b;
}
-void __operator /= (inout ivec2 v, const ivec2 u) {
- v.x /= u.x, v.y /= u.y;
+ivec4 __operator - (const ivec4 a, const ivec4 b)
+{
+ __asm vec4_subtract __retVal, a, b;
}
-void __operator += (inout ivec3 v, const ivec3 u) {
- v.x += u.x, v.y += u.y, v.z += u.z;
+ivec4 __operator * (const ivec4 a, const ivec4 b)
+{
+ __asm vec4_multiply __retVal, a, b;
}
-void __operator -= (inout ivec3 v, const ivec3 u) {
- v.x -= u.x, v.y -= u.y, v.z -= u.z;
+ivec4 __operator / (const ivec4 a, const ivec4 b)
+{
+ vec4 bInv, x;
+ __asm float_rcp bInv.x, b.x;
+ __asm float_rcp bInv.y, b.y;
+ __asm float_rcp bInv.z, b.z;
+ __asm float_rcp bInv.w, b.w;
+ __asm vec4_multiply x, a, bInv;
+ __asm vec4_to_ivec4 __retVal, x;
}
-void __operator *= (inout ivec3 v, const ivec3 u) {
- v.x *= u.x, v.y *= u.y, v.z *= u.z;
+
+//// Basic float operators
+
+float __operator + (const float a, const float b)
+{
+ __asm vec4_add __retVal, a, b;
}
-void __operator /= (inout ivec3 v, const ivec3 u) {
- v.x /= u.x, v.y /= u.y, v.z /= u.z;
+float __operator - (const float a, const float b)
+{
+ __asm vec4_subtract __retVal, a, b;
}
-void __operator += (inout ivec4 v, const ivec4 u) {
- v.x += u.x, v.y += u.y, v.z += u.z, v.w += u.w;
+float __operator * (const float a, const float b)
+{
+ __asm vec4_multiply __retVal, a, b;
}
-void __operator -= (inout ivec4 v, const ivec4 u) {
- v.x -= u.x, v.y -= u.y, v.z -= u.z, v.w -= u.w;
+float __operator / (const float a, const float b)
+{
+ float bInv;
+ __asm float_rcp bInv.x, b;
+ __asm vec4_multiply __retVal, a, bInv;
}
-void __operator *= (inout ivec4 v, const ivec4 u) {
- v.x *= u.x, v.y *= u.y, v.z *= u.z, v.w *= u.w;
+
+//// Basic vec2 operators
+
+vec2 __operator + (const vec2 v, const vec2 u)
+{
+ __asm vec4_add __retVal.xy, v, u;
}
-void __operator /= (inout ivec4 v, const ivec4 u) {
- v.x /= u.x, v.y /= u.y, v.z /= u.z, v.w /= u.w;
+vec2 __operator - (const vec2 v, const vec2 u)
+{
+ __asm vec4_subtract __retVal.xy, v, u;
}
-void __operator += (inout mat2 m, const mat2 n) {
- m[0] += n[0], m[1] += n[1];
+vec2 __operator * (const vec2 v, const vec2 u)
+{
+ __asm vec4_multiply __retVal.xy, v, u;
}
-void __operator -= (inout mat2 v, const mat2 n) {
- m[0] -= n[0], m[1] -= n[1];
+vec2 __operator / (const vec2 v, const vec2 u)
+{
+ vec2 w; // = 1 / u
+ __asm float_rcp w.x, u.x;
+ __asm float_rcp w.y, u.y;
+ __asm vec4_multiply __retVal.xy, v, w;
}
-void __operator *= (inout mat2 m, const mat2 n) {
- m = m * n;
+
+//// Basic vec3 operators
+
+vec3 __operator + (const vec3 v, const vec3 u)
+{
+ __asm vec4_add __retVal.xyz, v, u;
}
-void __operator /= (inout mat2 m, const mat2 n) {
- m[0] /= n[0], m[1] /= n[1];
+vec3 __operator - (const vec3 v, const vec3 u)
+{
+ __asm vec4_subtract __retVal.xyz, v, u;
}
-void __operator += (inout mat3 m, const mat3 n) {
- m[0] += n[0], m[1] += n[1], m[2] += n[2];
+vec3 __operator * (const vec3 v, const vec3 u)
+{
+ __asm vec4_multiply __retVal.xyz, v, u;
}
-void __operator -= (inout mat3 m, const mat3 n) {
- m[0] -= n[0], m[1] -= n[1], m[2] -= n[2];
+vec3 __operator / (const vec3 v, const vec3 u)
+{
+ vec3 w; // = 1 / u
+ __asm float_rcp w.x, u.x;
+ __asm float_rcp w.y, u.y;
+ __asm float_rcp w.z, u.z;
+ __asm vec4_multiply __retVal.xyz, v, w;
}
-void __operator *= (inout mat3 m, const mat3 n) {
- m = m * n;
+
+//// Basic vec4 operators
+
+vec4 __operator + (const vec4 v, const vec4 u)
+{
+ __asm vec4_add __retVal, v, u;
}
-void __operator /= (inout mat3 m, const mat3 n) {
- m[0] /= n[0], m[1] /= n[1], m[2] /= n[2];
+vec4 __operator - (const vec4 v, const vec4 u)
+{
+ __asm vec4_subtract __retVal, v, u;
}
-void __operator += (inout mat4 m, const mat4 n) {
- m[0] += n[0], m[1] += n[1], m[2] += n[2], m[3] += n[3];
+vec4 __operator * (const vec4 v, const vec4 u)
+{
+ __asm vec4_multiply __retVal, v, u;
}
-void __operator -= (inout mat4 m, const mat4 n) {
- m[0] -= n[0], m[1] -= n[1], m[2] -= n[2], m[3] -= n[3];
+vec4 __operator / (const vec4 v, const vec4 u)
+{
+ vec4 w; // = 1 / u
+ __asm float_rcp w.x, u.x;
+ __asm float_rcp w.y, u.y;
+ __asm float_rcp w.z, u.z;
+ __asm float_rcp w.w, u.w;
+ __asm vec4_multiply __retVal, v, w;
}
-void __operator *= (inout mat4 m, const mat4 n) {
- m = m * n;
+
+
+
+//// Basic vec2/float operators
+
+vec2 __operator + (const float a, const vec2 u)
+{
+ __asm vec4_add __retVal.xy, a, u.xy;
}
-void __operator /= (inout mat4 m, const mat4 n) {
- m[0] /= n[0], m[1] /= n[1], m[2] /= n[2], m[3] /= n[3];
+vec2 __operator + (const vec2 v, const float b)
+{
+ __asm vec4_add __retVal.xy, v.xy, b;
}
-//
-// ... or if the expression is a float, then the variable can be floating-point, a vector, or
-// a matrix, ...
-//
+vec2 __operator - (const float a, const vec2 u)
+{
+ __asm vec4_subtract __retVal.xy, a, u.xy;
+}
-void __operator += (inout vec2 v, const float a) {
- v.x += a, v.y += a;
+vec2 __operator - (const vec2 v, const float b)
+{
+ __asm vec4_subtract __retVal.xy, v.xy, b;
}
-void __operator -= (inout vec2 v, const float a) {
- v.x -= a, v.y -= a;
+vec2 __operator * (const float a, const vec2 u)
+{
+ __asm vec4_multiply __retVal.xy, a, u.xy;
}
-void __operator *= (inout vec2 v, const float a) {
- v.x *= a, v.y *= a;
+vec2 __operator * (const vec2 v, const float b)
+{
+ __asm vec4_multiply __retVal.xy, v.xy, b;
}
-void __operator /= (inout vec2 v, const float a) {
- v.x /= a, v.y /= a;
+vec2 __operator / (const float a, const vec2 u)
+{
+ vec2 invU;
+ __asm float_rcp invU.x, u.x;
+ __asm float_rcp invU.y, u.y;
+ __asm vec4_multiply __retVal.xy, a, invU.xy;
}
-void __operator += (inout vec3 v, const float a) {
- v.x += a, v.y += a, v.z += a;
+vec2 __operator / (const vec2 v, const float b)
+{
+ float invB;
+ __asm float_rcp invB, b;
+ __asm vec4_multiply __retVal.xy, v.xy, invB;
}
-void __operator -= (inout vec3 v, const float a) {
- v.x -= a, v.y -= a, v.z -= a;
+
+//// Basic vec3/float operators
+
+vec3 __operator + (const float a, const vec3 u)
+{
+ __asm vec4_add __retVal.xyz, a, u.xyz;
}
-void __operator *= (inout vec3 v, const float a) {
- v.x *= a, v.y *= a, v.z *= a;
+vec3 __operator + (const vec3 v, const float b)
+{
+ __asm vec4_add __retVal.xyz, v.xyz, b;
}
-void __operator /= (inout vec3 v, const float a) {
- v.x /= a, v.y /= a, v.z /= a;
+vec3 __operator - (const float a, const vec3 u)
+{
+ __asm vec4_subtract __retVal.xyz, a, u.xyz;
}
-void __operator += (inout vec4 v, const float a) {
- v.x += a, v.y += a, v.z += a, v.w += a;
+vec3 __operator - (const vec3 v, const float b)
+{
+ __asm vec4_subtract __retVal.xyz, v.xyz, b;
}
-void __operator -= (inout vec4 v, const float a) {
- v.x -= a, v.y -= a, v.z -= a, v.w -= a;
+vec3 __operator * (const float a, const vec3 u)
+{
+ __asm vec4_multiply __retVal.xyz, a, u.xyz;
}
-void __operator *= (inout vec4 v, const float a) {
- v.x *= a, v.y *= a, v.z *= a, v.w *= a;
+vec3 __operator * (const vec3 v, const float b)
+{
+ __asm vec4_multiply __retVal.xyz, v.xyz, b;
}
-void __operator /= (inout vec4 v, const float a) {
- v.x /= a, v.y /= a, v.z /= a, v.w /= a;
+vec3 __operator / (const float a, const vec3 u)
+{
+ vec3 invU;
+ __asm float_rcp invU.x, u.x;
+ __asm float_rcp invU.y, u.y;
+ __asm float_rcp invU.z, u.z;
+ __asm vec4_multiply __retVal.xyz, a, invU.xyz;
}
-void __operator += (inout mat2 m, const float a) {
- m[0] += a, m[1] += a;
+vec3 __operator / (const vec3 v, const float b)
+{
+ float invB;
+ __asm float_rcp invB, b;
+ __asm vec4_multiply __retVal.xyz, v.xyz, invB;
}
-void __operator -= (inout mat2 m, const float a) {
- m[0] -= a, m[1] -= a;
+
+//// Basic vec4/float operators
+
+vec4 __operator + (const float a, const vec4 u)
+{
+ __asm vec4_add __retVal, a, u;
}
-void __operator *= (inout mat2 m, const float a) {
- m[0] *= a, m[1] *= a;
+vec4 __operator + (const vec4 v, const float b)
+{
+ __asm vec4_add __retVal, v, b;
}
-void __operator /= (inout mat2 m, const float a) {
- m[0] /= a, m[1] /= a;
+vec4 __operator - (const float a, const vec4 u)
+{
+ __asm vec4_subtract __retVal, a, u;
}
-void __operator += (inout mat3 m, const float a) {
- m[0] += a, m[1] += a, m[2] += a;
+vec4 __operator - (const vec4 v, const float b)
+{
+ __asm vec4_subtract __retVal, v, b;
}
-void __operator -= (inout mat3 m, const float a) {
- m[0] -= a, m[1] -= a, m[2] -= a;
+vec4 __operator * (const float a, const vec4 u)
+{
+ __asm vec4_multiply __retVal, a, u;
}
-void __operator *= (inout mat3 m, const float a) {
- m[0] *= a, m[1] *= a, m[2] *= a;
+vec4 __operator * (const vec4 v, const float b)
+{
+ __asm vec4_multiply __retVal, v, b;
}
-void __operator /= (inout mat3 m, const float a) {
- m[0] /= a, m[1] /= a, m[2] /= a;
+vec4 __operator / (const float a, const vec4 u)
+{
+ vec4 invU;
+ __asm float_rcp invU.x, u.x;
+ __asm float_rcp invU.y, u.y;
+ __asm float_rcp invU.z, u.z;
+ __asm float_rcp invU.w, u.w;
+ __asm vec4_multiply __retVal, a, invU;
}
-void __operator += (inout mat4 m, const float a) {
- m[0] += a, m[1] += a, m[2] += a, m[3] += a;
+vec4 __operator / (const vec4 v, const float b)
+{
+ float invB;
+ __asm float_rcp invB, b;
+ __asm vec4_multiply __retVal, v, invB;
}
-void __operator -= (inout mat4 m, const float a) {
- m[0] -= a, m[1] -= a, m[2] -= a, m[3] -= a;
+
+
+//// Basic ivec2/int operators
+
+ivec2 __operator + (const int a, const ivec2 u)
+{
+ __retVal = ivec2(a) + u;
}
-void __operator *= (inout mat4 m, const float a) {
- m[0] *= a, m[1] *= a, m[2] *= a, m[3] *= a;
+ivec2 __operator + (const ivec2 v, const int b)
+{
+ __retVal = v + ivec2(b);
}
-void __operator /= (inout mat4 m, const float a) {
- m[0] /= a, m[1] /= a, m[2] /= a, m[3] /= a;
+ivec2 __operator - (const int a, const ivec2 u)
+{
+ __retVal = ivec2(a) - u;
}
-//
-// ... or if the operation is multiply into (*=), then the variable can be a vector and the
-// expression can be a matrix of matching size.
-//
+ivec2 __operator - (const ivec2 v, const int b)
+{
+ __retVal = v - ivec2(b);
+}
-void __operator *= (inout vec2 v, const mat2 m) {
- v = v * m;
+ivec2 __operator * (const int a, const ivec2 u)
+{
+ __retVal = ivec2(a) * u;
}
-void __operator *= (inout vec3 v, const mat3 m) {
- v = v * m;
+ivec2 __operator * (const ivec2 v, const int b)
+{
+ __retVal = v * ivec2(b);
}
-void __operator *= (inout vec4 v, const mat4 m) {
- v = v * m;
+ivec2 __operator / (const int a, const ivec2 u)
+{
+ __retVal = ivec2(a) / u;
+}
+
+ivec2 __operator / (const ivec2 v, const int b)
+{
+ __retVal = v / ivec2(b);
}
-//
-// 5.9 Expressions
-//
-// Expressions in the shading language include the following:
-//
-//
-// * The arithmetic binary operators add (+), subtract (-), multiply (*), and divide (/), that
-// operate on integer and floating-point typed expressions (including vectors and matrices).
-// The two operands must be the same type, (...) Additionally, for multiply (*) (...) If one
-// operand is scalar and the other is a vector or matrix, the scalar is applied component-wise
-// to the vector or matrix, resulting in the same type as the vector or matrix.
-//
+//// Basic ivec3/int operators
-float __operator + (const float a, const float b) {
- float c = a;
- return c += b;
+ivec3 __operator + (const int a, const ivec3 u)
+{
+ __retVal = ivec3(a) + u;
}
-float __operator - (const float a, const float b) {
- return a + -b;
+ivec3 __operator + (const ivec3 v, const int b)
+{
+ __retVal = v + ivec3(b);
}
-float __operator * (const float a, const float b) {
- float c = a;
- return c *= b;
+ivec3 __operator - (const int a, const ivec3 u)
+{
+ __retVal = ivec3(a) - u;
}
-float __operator / (const float a, const float b) {
- float c = a;
- return c /= b;
+ivec3 __operator - (const ivec3 v, const int b)
+{
+ __retVal = v - ivec3(b);
}
-int __operator + (const int a, const int b) {
- int c = a;
- return c += b;
+ivec3 __operator * (const int a, const ivec3 u)
+{
+ __retVal = ivec3(a) * u;
}
-int __operator - (const int x, const int y) {
- return x + -y;
+ivec3 __operator * (const ivec3 v, const int b)
+{
+ __retVal = v * ivec3(b);
}
-int __operator * (const int x, const int y) {
- int z = x;
- return z *= y;
+ivec3 __operator / (const int a, const ivec3 u)
+{
+ __retVal = ivec3(a) / u;
}
-int __operator / (const int x, const int y) {
- int z = x;
- return z /= y;
+ivec3 __operator / (const ivec3 v, const int b)
+{
+ __retVal = v / ivec3(b);
}
-vec2 __operator + (const vec2 v, const vec2 u) {
- return vec2 (v.x + u.x, v.y + u.y);
+
+//// Basic ivec4/int operators
+
+ivec4 __operator + (const int a, const ivec4 u)
+{
+ __retVal = ivec4(a) + u;
+}
+
+ivec4 __operator + (const ivec4 v, const int b)
+{
+ __retVal = v + ivec4(b);
}
-vec2 __operator - (const vec2 v, const vec2 u) {
- return vec2 (v.x - u.x, v.y - u.y);
+ivec4 __operator - (const int a, const ivec4 u)
+{
+ __retVal = ivec4(a) - u;
}
-vec3 __operator + (const vec3 v, const vec3 u) {
- return vec3 (v.x + u.x, v.y + u.y, v.z + u.z);
+ivec4 __operator - (const ivec4 v, const int b)
+{
+ __retVal = v - ivec4(b);
}
-vec3 __operator - (const vec3 v, const vec3 u) {
- return vec3 (v.x - u.x, v.y - u.y, v.z - u.z);
+ivec4 __operator * (const int a, const ivec4 u)
+{
+ __retVal = ivec4(a) * u;
}
-vec4 __operator + (const vec4 v, const vec4 u) {
- return vec4 (v.x + u.x, v.y + u.y, v.z + u.z, v.w + u.w);
+ivec4 __operator * (const ivec4 v, const int b)
+{
+ __retVal = v * ivec4(b);
}
-vec4 __operator - (const vec4 v, const vec4 u) {
- return vec4 (v.x - u.x, v.y - u.y, v.z - u.z, v.w - u.w);
+ivec4 __operator / (const int a, const ivec4 u)
+{
+ __retVal = ivec4(a) / u;
}
-ivec2 __operator + (const ivec2 v, const ivec2 u) {
- return ivec2 (v.x + u.x, v.y + u.y);
+ivec4 __operator / (const ivec4 v, const int b)
+{
+ __retVal = v / ivec4(b);
}
-ivec2 __operator - (const ivec2 v, const ivec2 u) {
- return ivec2 (v.x - u.x, v.y - u.y);
+
+
+
+//// Unary negation operator
+
+int __operator - (const int a)
+{
+ __asm vec4_negate __retVal.x, a;
}
-ivec3 __operator + (const ivec3 v, const ivec3 u) {
- return ivec3 (v.x + u.x, v.y + u.y, v.z + u.z);
+ivec2 __operator - (const ivec2 v)
+{
+ __asm vec4_negate __retVal, v;
}
-ivec3 __operator - (const ivec3 v, const ivec3 u) {
- return ivec3 (v.x - u.x, v.y - u.y, v.z - u.z);
+ivec3 __operator - (const ivec3 v)
+{
+ __asm vec4_negate __retVal, v;
}
-ivec4 __operator + (const ivec4 v, const ivec4 u) {
- return ivec4 (v.x + u.x, v.y + u.y, v.z + u.z, v.w + u.w);
+ivec4 __operator - (const ivec4 v)
+{
+ __asm vec4_negate __retVal, v;
}
-ivec4 __operator - (const ivec4 v, const ivec4 u) {
- return ivec4 (v.x - u.x, v.y - u.y, v.z - u.z, v.w - u.w);
+float __operator - (const float a)
+{
+ __asm vec4_negate __retVal.x, a;
}
-mat2 __operator + (const mat2 m, const mat2 n) {
- return mat2 (m[0] + n[0], m[1] + n[1]);
+vec2 __operator - (const vec2 v)
+{
+ __asm vec4_negate __retVal.xy, v.xy;
}
-mat2 __operator - (const mat2 m, const mat2 n) {
- return mat2 (m[0] - n[0], m[1] - n[1]);
+vec3 __operator - (const vec3 v)
+{
+ __asm vec4_negate __retVal.xyz, v.xyz;
}
-mat3 __operator + (const mat3 m, const mat3 n) {
- return mat3 (m[0] + n[0], m[1] + n[1], m[2] + n[2]);
+vec4 __operator - (const vec4 v)
+{
+ __asm vec4_negate __retVal, v;
}
-mat3 __operator - (const mat3 m, const mat3 n) {
- return mat3 (m[0] - n[0], m[1] - n[1], m[2] - n[2]);
+mat2 __operator - (const mat2 m)
+{
+ __retVal[0] = -m[0];
+ __retVal[1] = -m[1];
}
-mat4 __operator + (const mat4 m, const mat4 n) {
- return mat4 (m[0] + n[0], m[1] + n[1], m[2] + n[2], m[3] + n[3]);
+mat3 __operator - (const mat3 m)
+{
+ __retVal[0] = -m[0];
+ __retVal[1] = -m[1];
+ __retVal[2] = -m[2];
}
-mat4 __operator - (const mat4 m, const mat4 n) {
- return mat4 (m[0] - n[0], m[1] - n[1], m[2] - n[2], m[3] - n[3]);
+mat4 __operator - (const mat4 m)
+{
+ __retVal[0] = -m[0];
+ __retVal[1] = -m[1];
+ __retVal[2] = -m[2];
+ __retVal[3] = -m[3];
}
-//
-// ... or one can be a scalar float and the other a float vector or matrix, ...
-//
-vec2 __operator + (const float a, const vec2 u) {
- return vec2 (a + u.x, a + u.y);
+
+//// dot product
+
+float dot(const float a, const float b)
+{
+ __retVal = a * b;
+}
+
+float dot(const vec2 a, const vec2 b)
+{
+ __retVal = a.x * b.x + a.y * b.y;
}
-vec2 __operator + (const vec2 v, const float b) {
- return vec2 (v.x + b, v.y + b);
+float dot(const vec3 a, const vec3 b)
+{
+ __asm vec3_dot __retVal, a, b;
}
-vec2 __operator - (const float a, const vec2 u) {
- return vec2 (a - u.x, a - u.y);
+float dot(const vec4 a, const vec4 b)
+{
+ __asm vec4_dot __retVal, a, b;
}
-vec2 __operator - (const vec2 v, const float b) {
- return vec2 (v.x - b, v.y - b);
+
+
+//// int assignment operators
+
+void __operator += (inout int a, const int b)
+{
+ __asm vec4_add a, a, b;
}
-vec2 __operator * (const float a, const vec2 u) {
- return vec2 (a * u.x, a * u.y);
+void __operator -= (inout int a, const int b)
+{
+ __asm vec4_subtract a, a, b;
}
-vec2 __operator * (const vec2 v, const float b) {
- return vec2 (v.x * b, v.y * b);
+void __operator *= (inout int a, const int b)
+{
+ __asm vec4_multiply a, a, b;
}
-vec2 __operator / (const float a, const vec2 u) {
- return vec2 (a / u.x, a / u.y);
+void __operator /= (inout int a, const int b)
+{
+ float invB;
+ __asm float_rcp invB, b;
+ __asm vec4_multiply a, a, invB;
+ __asm vec4_to_ivec4 a, a;
}
-vec2 __operator / (const vec2 v, const float b) {
- return vec2 (v.x / b, v.y / b);
+
+//// ivec2 assignment operators
+
+void __operator += (inout ivec2 v, const ivec2 u)
+{
+ __asm vec4_add v, v, u;
}
-vec3 __operator + (const float a, const vec3 u) {
- return vec3 (a + u.x, a + u.y, a + u.z);
+void __operator -= (inout ivec2 v, const ivec2 u)
+{
+ __asm vec4_subtract v, v, u;
}
-vec3 __operator + (const vec3 v, const float b) {
- return vec3 (v.x + b, v.y + b, v.z + b);
+void __operator *= (inout ivec2 v, const ivec2 u)
+{
+ __asm vec4_multiply v, v, u;
}
-vec3 __operator - (const float a, const vec3 u) {
- return vec3 (a - u.x, a - u.y, a - u.z);
+void __operator /= (inout ivec2 v, const ivec2 u)
+{
+ ivec2 inv, z;
+ __asm float_rcp inv.x, u.x;
+ __asm float_rcp inv.y, u.y;
+ __asm vec4_multiply z, v, inv;
+ __asm vec4_to_ivec4 v, z;
}
-vec3 __operator - (const vec3 v, const float b) {
- return vec3 (v.x - b, v.y - b, v.z - b);
+
+//// ivec3 assignment operators
+
+void __operator += (inout ivec3 v, const ivec3 u)
+{
+ __asm vec4_add v, v, u;
}
-vec3 __operator * (const float a, const vec3 u) {
- return vec3 (a * u.x, a * u.y, a * u.z);
+void __operator -= (inout ivec3 v, const ivec3 u)
+{
+ __asm vec4_subtract v, v, u;
}
-vec3 __operator * (const vec3 v, const float b) {
- return vec3 (v.x * b, v.y * b, v.z * b);
+void __operator *= (inout ivec3 v, const ivec3 u)
+{
+ __asm vec4_multiply v, v, u;
}
-vec3 __operator / (const float a, const vec3 u) {
- return vec3 (a / u.x, a / u.y, a / u.z);
+void __operator /= (inout ivec3 v, const ivec3 u)
+{
+ ivec3 inv, z;
+ __asm float_rcp inv.x, u.x;
+ __asm float_rcp inv.y, u.y;
+ __asm vec4_multiply z, v, inv;
+ __asm vec4_to_ivec4 v, z;
}
-vec3 __operator / (const vec3 v, const float b) {
- return vec3 (v.x / b, v.y / b, v.z / b);
+
+//// ivec4 assignment operators
+
+void __operator += (inout ivec4 v, const ivec4 u)
+{
+ __asm vec4_add v, v, u;
}
-vec4 __operator + (const float a, const vec4 u) {
- return vec4 (a + u.x, a + u.y, a + u.z, a + u.w);
+void __operator -= (inout ivec4 v, const ivec4 u)
+{
+ __asm vec4_subtract v, v, u;
}
-vec4 __operator + (const vec4 v, const float b) {
- return vec4 (v.x + b, v.y + b, v.z + b, v.w + b);
+void __operator *= (inout ivec4 v, const ivec4 u)
+{
+ __asm vec4_multiply v, v, u;
}
-vec4 __operator - (const float a, const vec4 u) {
- return vec4 (a - u.x, a - u.y, a - u.z, a - u.w);
+void __operator /= (inout ivec4 v, const ivec4 u)
+{
+ ivec4 inv, z;
+ __asm float_rcp inv.x, u.x;
+ __asm float_rcp inv.y, u.y;
+ __asm vec4_multiply z, v, inv;
+ __asm vec4_to_ivec4 v, z;
}
-vec4 __operator - (const vec4 v, const float b) {
- return vec4 (v.x - b, v.y - b, v.z - b, v.w - b);
+
+//// float assignment operators
+
+void __operator += (inout float a, const float b)
+{
+ __asm vec4_add a.x, a.x, b.x;
}
-vec4 __operator * (const float a, const vec4 u) {
- return vec4 (a * u.x, a * u.y, a * u.z, a * u.w);
+void __operator -= (inout float a, const float b)
+{
+ __asm vec4_subtract a.x, a, b;
}
-vec4 __operator * (const vec4 v, const float b) {
- return vec4 (v.x * b, v.y * b, v.z * b, v.w * b);
+void __operator *= (inout float a, const float b)
+{
+ __asm vec4_multiply a.x, a, b;
}
-vec4 __operator / (const float a, const vec4 u) {
- return vec4 (a / u.x, a / u.y, a / u.z, a / u.w);
+void __operator /= (inout float a, const float b)
+{
+ float w; // = 1 / b
+ __asm float_rcp w.x, b;
+ __asm vec4_multiply a.x, a, w;
}
-vec4 __operator / (const vec4 v, const float b) {
- return vec4 (v.x / b, v.y / b, v.z / b, v.w / b);
+
+//// vec2 assignment operators
+
+void __operator += (inout vec2 v, const vec2 u)
+{
+ __asm vec4_add v.xy, v.xy, u.xy;
}
-mat2 __operator + (const float a, const mat2 n) {
- return mat2 (a + n[0], a + n[1]);
+void __operator -= (inout vec2 v, const vec2 u)
+{
+ __asm vec4_subtract v.xy, v.xy, u.xy;
}
-mat2 __operator + (const mat2 m, const float b) {
- return mat2 (m[0] + b, m[1] + b);
+void __operator *= (inout vec2 v, const vec2 u)
+{
+ __asm vec4_multiply v.xy, v.xy, u.xy;
}
-mat2 __operator - (const float a, const mat2 n) {
- return mat2 (a - n[0], a - n[1]);
+void __operator /= (inout vec2 v, const vec2 u)
+{
+ vec2 w;
+ __asm float_rcp w.x, u.x;
+ __asm float_rcp w.y, u.y;
+ __asm vec4_multiply v.xy, v.xy, w.xy;
}
-mat2 __operator - (const mat2 m, const float b) {
- return mat2 (m[0] - b, m[1] - b);
+
+//// vec3 assignment operators
+
+void __operator += (inout vec3 v, const vec3 u)
+{
+ __asm vec4_add v.xyz, v, u;
}
-mat2 __operator * (const float a, const mat2 n) {
- return mat2 (a * n[0], a * n[1]);
+void __operator -= (inout vec3 v, const vec3 u)
+{
+ __asm vec4_subtract v.xyz, v, u;
}
-mat2 __operator * (const mat2 m, const float b) {
- return mat2 (m[0] * b, m[1] * b);
+void __operator *= (inout vec3 v, const vec3 u)
+{
+ __asm vec4_multiply v.xyz, v, u;
}
-mat2 __operator / (const float a, const mat2 n) {
- return mat2 (a / n[0], a / n[1]);
+void __operator /= (inout vec3 v, const vec3 u)
+{
+ vec3 w;
+ __asm float_rcp w.x, u.x;
+ __asm float_rcp w.y, u.y;
+ __asm float_rcp w.z, u.z;
+ __asm vec4_multiply v.xyz, v.xyz, w.xyz;
}
-mat2 __operator / (const mat2 m, const float b) {
- return mat2 (m[0] / b, m[1] / b);
+
+//// vec4 assignment operators
+
+void __operator += (inout vec4 v, const vec4 u)
+{
+ __asm vec4_add v, v, u;
}
-mat3 __operator + (const float a, const mat3 n) {
- return mat3 (a + n[0], a + n[1], a + n[2]);
+void __operator -= (inout vec4 v, const vec4 u)
+{
+ __asm vec4_subtract v, v, u;
}
-mat3 __operator + (const mat3 m, const float b) {
- return mat3 (m[0] + b, m[1] + b, m[2] + b);
+void __operator *= (inout vec4 v, const vec4 u)
+{
+ __asm vec4_multiply v, v, u;
}
-mat3 __operator - (const float a, const mat3 n) {
- return mat3 (a - n[0], a - n[1], a - n[2]);
+void __operator /= (inout vec4 v, const vec4 u)
+{
+ vec4 w;
+ __asm float_rcp w.x, u.x;
+ __asm float_rcp w.y, u.y;
+ __asm float_rcp w.z, u.z;
+ __asm float_rcp w.w, u.w;
+ __asm vec4_multiply v, v, w;
}
-mat3 __operator - (const mat3 m, const float b) {
- return mat3 (m[0] - b, m[1] - b, m[2] - b);
+
+
+//// ivec2/int assignment operators
+
+void __operator += (inout ivec2 v, const int a)
+{
+ __asm vec4_add v.xy, v.xy, a;
}
-mat3 __operator * (const float a, const mat3 n) {
- return mat3 (a * n[0], a * n[1], a * n[2]);
+void __operator -= (inout ivec2 v, const int a)
+{
+ __asm vec4_subtract v.xy, v.xy, a;
}
-mat3 __operator * (const mat3 m, const float b) {
- return mat3 (m[0] * b, m[1] * b, m[2] * b);
+void __operator *= (inout ivec2 v, const int a)
+{
+ __asm vec4_multiply v.xy, v.xy, a;
+ v.x *= a;
+ v.y *= a;
}
-mat3 __operator / (const float a, const mat3 n) {
- return mat3 (a / n[0], a / n[1], a / n[2]);
+void __operator /= (inout ivec2 v, const int a)
+{
+// XXX rcp
+ v.x /= a;
+ v.y /= a;
}
-mat3 __operator / (const mat3 m, const float b) {
- return mat3 (m[0] / b, m[1] / b, m[2] / b);
+
+//// ivec3/int assignment operators
+
+void __operator += (inout ivec3 v, const int a)
+{
+ __asm vec4_add v.xyz, v.xyz, a;
}
-mat4 __operator + (const float a, const mat4 n) {
- return mat4 (a + n[0], a + n[1], a + n[2], a + n[3]);
+void __operator -= (inout ivec3 v, const int a)
+{
+ __asm vec4_subtract v.xyz, v.xyz, a;
}
-mat4 __operator + (const mat4 m, const float b) {
- return mat4 (m[0] + b, m[1] + b, m[2] + b, m[3] + b);
+void __operator *= (inout ivec3 v, const int a)
+{
+ __asm vec4_multiply v.xyz, v.xyz, a;
}
-mat4 __operator - (const float a, const mat4 n) {
- return mat4 (a - n[0], a - n[1], a - n[2], a - n[3]);
+void __operator /= (inout ivec3 v, const int a)
+{
+ // XXX rcp
+ v.x /= a;
+ v.y /= a;
+ v.z /= a;
}
-mat4 __operator - (const mat4 m, const float b) {
- return mat4 (m[0] - b, m[1] - b, m[2] - b, m[3] - b);
+
+//// ivec4/int assignment operators
+
+void __operator += (inout ivec4 v, const int a)
+{
+ __asm vec4_add v, v, a;
}
-mat4 __operator * (const float a, const mat4 n) {
- return mat4 (a * n[0], a * n[1], a * n[2], a * n[3]);
+void __operator -= (inout ivec4 v, const int a)
+{
+ __asm vec4_subtract v, v, a;
}
-mat4 __operator * (const mat4 m, const float b) {
- return mat4 (m[0] * b, m[1] * b, m[2] * b, m[3] * b);
+void __operator *= (inout ivec4 v, const int a)
+{
+ __asm vec4_multiply v, v, a;
}
-mat4 __operator / (const float a, const mat4 n) {
- return mat4 (a / n[0], a / n[1], a / n[2], a / n[3]);
+void __operator /= (inout ivec4 v, const int a)
+{
+ v.x /= a;
+ v.y /= a;
+ v.z /= a;
+ v.w /= a;
}
-mat4 __operator / (const mat4 m, const float b) {
- return mat4 (m[0] / b, m[1] / b, m[2] / b, m[3] / b);
+
+
+//// vec2/float assignment operators
+
+void __operator += (inout vec2 v, const float a)
+{
+ __asm vec4_add v.xy, v, a;
}
-//
-// ... or one can be a scalar integer and the other an integer vector.
-//
+void __operator -= (inout vec2 v, const float a)
+{
+ __asm vec4_subtract v.xy, v, a;
+}
-ivec2 __operator + (const int a, const ivec2 u) {
- return ivec2 (a + u.x, a + u.y);
+void __operator *= (inout vec2 v, const float a)
+{
+ __asm vec4_multiply v.xy, v, a;
}
-ivec2 __operator + (const ivec2 v, const int b) {
- return ivec2 (v.x + b, v.y + b);
+void __operator /= (inout vec2 v, const float a)
+{
+ float invA;
+ __asm float_rcp invA, a;
+ __asm vec4_multiply v.xy, v.xy, invA;
}
-ivec2 __operator - (const int a, const ivec2 u) {
- return ivec2 (a - u.x, a - u.y);
+
+//// vec3/float assignment operators
+
+void __operator += (inout vec3 v, const float a)
+{
+ __asm vec4_add v.xyz, v, a;
}
-ivec2 __operator - (const ivec2 v, const int b) {
- return ivec2 (v.x - b, v.y - b);
+void __operator -= (inout vec3 v, const float a)
+{
+ __asm vec4_subtract v.xyz, v, a;
}
-ivec2 __operator * (const int a, const ivec2 u) {
- return ivec2 (a * u.x, a * u.y);
+void __operator *= (inout vec3 v, const float a)
+{
+ __asm vec4_multiply v.xyz, v, a;
}
-ivec2 __operator * (const ivec2 v, const int b) {
- return ivec2 (v.x * b, v.y * b);
+void __operator /= (inout vec3 v, const float a)
+{
+ float invA;
+ __asm float_rcp invA, a;
+ __asm vec4_multiply v.xyz, v.xyz, invA;
}
-ivec2 __operator / (const int a, const ivec2 u) {
- return ivec2 (a / u.x, a / u.y);
+
+//// vec4/float assignment operators
+
+void __operator += (inout vec4 v, const float a)
+{
+ __asm vec4_add v, v, a;
}
-ivec2 __operator / (const ivec2 v, const int b) {
- return ivec2 (v.x / b, v.y / b);
+void __operator -= (inout vec4 v, const float a)
+{
+ __asm vec4_subtract v, v, a;
}
-ivec3 __operator + (const int a, const ivec3 u) {
- return ivec3 (a + u.x, a + u.y, a + u.z);
+void __operator *= (inout vec4 v, const float a)
+{
+ __asm vec4_multiply v, v, a;
}
-ivec3 __operator + (const ivec3 v, const int b) {
- return ivec3 (v.x + b, v.y + b, v.z + b);
+void __operator /= (inout vec4 v, const float a)
+{
+ float invA;
+ __asm float_rcp invA, a;
+ __asm vec4_multiply v, v, invA;
}
-ivec3 __operator - (const int a, const ivec3 u) {
- return ivec3 (a - u.x, a - u.y, a - u.z);
+
+
+
+
+//// Basic mat2 operations
+
+mat2 __operator + (const mat2 m, const mat2 n)
+{
+ __retVal[0] = m[0] + n[0];
+ __retVal[1] = m[1] + n[1];
}
-ivec3 __operator - (const ivec3 v, const int b) {
- return ivec3 (v.x - b, v.y - b, v.z - b);
+mat2 __operator - (const mat2 m, const mat2 n)
+{
+ __retVal[0] = m[0] - n[0];
+ __retVal[1] = m[1] - n[1];
}
-ivec3 __operator * (const int a, const ivec3 u) {
- return ivec3 (a * u.x, a * u.y, a * u.z);
+mat2 __operator * (const mat2 m, const mat2 n)
+{
+ __retVal[0] = m[0] * n[0].xx + m[1] * n[0].yy;
+ __retVal[1] = m[0] * n[1].xx + m[1] * n[1].yy;
}
-ivec3 __operator * (const ivec3 v, const int b) {
- return ivec3 (v.x * b, v.y * b, v.z * b);
+mat2 __operator / (const mat2 m, const mat2 n)
+{
+ __retVal[0] = m[0] / n[0];
+ __retVal[1] = m[1] / n[1];
}
-ivec3 __operator / (const int a, const ivec3 u) {
- return ivec3 (a / u.x, a / u.y, a / u.z);
+
+//// Basic mat3 operations
+
+mat3 __operator + (const mat3 m, const mat3 n)
+{
+ __retVal[0] = m[0] + n[0];
+ __retVal[1] = m[1] + n[1];
+ __retVal[2] = m[2] + n[2];
}
-ivec3 __operator / (const ivec3 v, const int b) {
- return ivec3 (v.x / b, v.y / b, v.z / b);
+mat3 __operator - (const mat3 m, const mat3 n)
+{
+ __retVal[0] = m[0] - n[0];
+ __retVal[1] = m[1] - n[1];
+ __retVal[2] = m[2] - n[2];
}
-ivec4 __operator + (const int a, const ivec4 u) {
- return ivec4 (a + u.x, a + u.y, a + u.z, a + u.w);
+mat3 __operator * (const mat3 m, const mat3 n)
+{
+ __retVal[0] = m[0] * n[0].xxx + m[1] * n[0].yyy + m[2] * n[0].zzz;
+ __retVal[1] = m[0] * n[1].xxx + m[1] * n[1].yyy + m[2] * n[1].zzz;
+ __retVal[2] = m[0] * n[2].xxx + m[1] * n[2].yyy + m[2] * n[2].zzz;
}
-ivec4 __operator + (const ivec4 v, const int b) {
- return ivec4 (v.x + b, v.y + b, v.z + b, v.w + b);
+mat3 __operator / (const mat3 m, const mat3 n)
+{
+ __retVal[0] = m[0] / n[0];
+ __retVal[1] = m[1] / n[1];
+ __retVal[2] = m[2] / n[2];
}
-ivec4 __operator - (const int a, const ivec4 u) {
- return ivec4 (a - u.x, a - u.y, a - u.z, a - u.w);
+
+//// Basic mat4 operations
+
+mat4 __operator + (const mat4 m, const mat4 n)
+{
+ __retVal[0] = m[0] + n[0];
+ __retVal[1] = m[1] + n[1];
+ __retVal[2] = m[2] + n[2];
+ __retVal[3] = m[3] + n[3];
}
-ivec4 __operator - (const ivec4 v, const int b) {
- return ivec4 (v.x - b, v.y - b, v.z - b, v.w - b);
+mat4 __operator - (const mat4 m, const mat4 n)
+{
+ __retVal[0] = m[0] - n[0];
+ __retVal[1] = m[1] - n[1];
+ __retVal[2] = m[2] - n[2];
+ __retVal[3] = m[3] - n[3];
}
-ivec4 __operator * (const int a, const ivec4 u) {
- return ivec4 (a * u.x, a * u.y, a * u.z, a * u.w);
+mat4 __operator * (const mat4 m, const mat4 n)
+{
+ __retVal[0] = m[0] * n[0].xxxx + m[1] * n[0].yyyy + m[2] * n[0].zzzz + m[3] * n[0].wwww;
+ __retVal[1] = m[0] * n[1].xxxx + m[1] * n[1].yyyy + m[2] * n[1].zzzz + m[3] * n[1].wwww;
+ __retVal[2] = m[0] * n[2].xxxx + m[1] * n[2].yyyy + m[2] * n[2].zzzz + m[3] * n[2].wwww;
+ __retVal[3] = m[0] * n[3].xxxx + m[1] * n[3].yyyy + m[2] * n[3].zzzz + m[3] * n[3].wwww;
}
-ivec4 __operator * (const ivec4 v, const int b) {
- return ivec4 (v.x * b, v.y * b, v.z * b, v.w * b);
+mat4 __operator / (const mat4 m, const mat4 n)
+{
+ __retVal[0] = m[0] / n[0];
+ __retVal[1] = m[1] / n[1];
+ __retVal[2] = m[2] / n[2];
+ __retVal[3] = m[3] / n[3];
}
-ivec4 __operator / (const int a, const ivec4 u) {
- return ivec4 (a / u.x, a / u.y, a / u.z, a / u.w);
+
+//// mat2/float operations
+
+mat2 __operator + (const float a, const mat2 n)
+{
+ __retVal[0] = a + n[0];
+ __retVal[1] = a + n[1];
}
-ivec4 __operator / (const ivec4 v, const int b) {
- return ivec4 (v.x / b, v.y / b, v.z / b, v.w / b);
+mat2 __operator + (const mat2 m, const float b)
+{
+ __retVal[0] = m[0] + b;
+ __retVal[1] = m[1] + b;
}
-//
-// Additionally, for multiply (*) one can be a vector and the other a matrix with the same
-// dimensional size of the vector. These result in the same fundamental type (integer or float)
-// as the expressions they operate on.
-//
-// [When:]
-// * the left argument is a floating-point vector and the right is a matrix with a compatible
-// dimension in which case the * operator will do a row vector matrix multiplication.
-// * the left argument is a matrix and the right is a floating-point vector with a compatible
-// dimension in which case the * operator will do a column vector matrix multiplication.
-//
+mat2 __operator - (const float a, const mat2 n)
+{
+ __retVal[0] = a - n[0];
+ __retVal[1] = a - n[1];
+}
-vec2 __operator * (const mat2 m, const vec2 v) {
- return vec2 (
- v.x * m[0].x + v.y * m[1].x,
- v.x * m[0].y + v.y * m[1].y
- );
+mat2 __operator - (const mat2 m, const float b)
+{
+ __retVal[0] = m[0] - b;
+ __retVal[1] = m[1] - b;
}
-vec2 __operator * (const vec2 v, const mat2 m) {
- return vec2 (
- v.x * m[0].x + v.y * m[0].y,
- v.x * m[1].x + v.y * m[1].y
- );
+mat2 __operator * (const float a, const mat2 n)
+{
+ __retVal[0] = a * n[0];
+ __retVal[1] = a * n[1];
}
-vec3 __operator * (const mat3 m, const vec3 v) {
- return vec3 (
- v.x * m[0].x + v.y * m[1].x + v.z * m[2].x,
- v.x * m[0].y + v.y * m[1].y + v.z * m[2].y,
- v.x * m[0].z + v.y * m[1].z + v.z * m[2].z
- );
+mat2 __operator * (const mat2 m, const float b)
+{
+ __retVal[0] = m[0] * b;
+ __retVal[1] = m[1] * b;
}
-vec3 __operator * (const vec3 v, const mat3 m) {
- return vec3 (
- v.x * m[0].x + v.y * m[0].y + v.z * m[0].z,
- v.x * m[1].x + v.y * m[1].y + v.z * m[1].z,
- v.x * m[2].x + v.y * m[2].y + v.z * m[2].z
- );
+mat2 __operator / (const float a, const mat2 n)
+{
+ __retVal[0] = a / n[0];
+ __retVal[1] = a / n[1];
}
-vec4 __operator * (const mat4 m, const vec4 v) {
- return vec4 (
- v.x * m[0].x + v.y * m[1].x + v.z * m[2].x + v.w * m[3].x,
- v.x * m[0].y + v.y * m[1].y + v.z * m[2].y + v.w * m[3].y,
- v.x * m[0].z + v.y * m[1].z + v.z * m[2].z + v.w * m[3].z,
- v.x * m[0].w + v.y * m[1].w + v.z * m[2].w + v.w * m[3].w
- );
+mat2 __operator / (const mat2 m, const float b)
+{
+ __retVal[0] = m[0] / b;
+ __retVal[1] = m[1] / b;
}
-vec4 __operator * (const vec4 v, const mat4 m) {
- return vec4 (
- v.x * m[0].x + v.y * m[0].y + v.z * m[0].z + v.w * m[0].w,
- v.x * m[1].x + v.y * m[1].y + v.z * m[1].z + v.w * m[1].w,
- v.x * m[2].x + v.y * m[2].y + v.z * m[2].z + v.w * m[2].w,
- v.x * m[3].x + v.y * m[3].y + v.z * m[3].z + v.w * m[3].w
- );
+
+//// mat3/float operations
+
+mat3 __operator + (const float a, const mat3 n)
+{
+ __retVal[0] = a + n[0];
+ __retVal[1] = a + n[1];
+ __retVal[2] = a + n[2];
}
-//
-// Multiply (*) applied to two vectors yields a component-wise multiply.
-//
+mat3 __operator + (const mat3 m, const float b)
+{
+ __retVal[0] = m[0] + b;
+ __retVal[1] = m[1] + b;
+ __retVal[2] = m[2] + b;
+}
-vec2 __operator * (const vec2 v, const vec2 u) {
- return vec2 (v.x * u.x, v.y * u.y);
+mat3 __operator - (const float a, const mat3 n)
+{
+ __retVal[0] = a - n[0];
+ __retVal[1] = a - n[1];
+ __retVal[2] = a - n[2];
}
-vec3 __operator * (const vec3 v, const vec3 u) {
- return vec3 (v.x * u.x, v.y * u.y, v.z * u.z);
+mat3 __operator - (const mat3 m, const float b)
+{
+ __retVal[0] = m[0] - b;
+ __retVal[1] = m[1] - b;
+ __retVal[2] = m[2] - b;
}
-vec4 __operator * (const vec4 v, const vec4 u) {
- return vec4 (v.x * u.x, v.y * u.y, v.z * u.z, v.w * u.w);
+mat3 __operator * (const float a, const mat3 n)
+{
+ __retVal[0] = a * n[0];
+ __retVal[1] = a * n[1];
+ __retVal[2] = a * n[2];
}
-ivec2 __operator * (const ivec2 v, const ivec2 u) {
- return ivec2 (v.x * u.x, v.y * u.y);
+mat3 __operator * (const mat3 m, const float b)
+{
+ __retVal[0] = m[0] * b;
+ __retVal[1] = m[1] * b;
+ __retVal[2] = m[2] * b;
}
-ivec3 __operator * (const ivec3 v, const ivec3 u) {
- return ivec3 (v.x * u.x, v.y * u.y, v.z * u.z);
+mat3 __operator / (const float a, const mat3 n)
+{
+ __retVal[0] = a / n[0];
+ __retVal[1] = a / n[1];
+ __retVal[2] = a / n[2];
}
-ivec4 __operator * (const ivec4 v, const ivec4 u) {
- return ivec4 (v.x * u.x, v.y * u.y, v.z * u.z, v.w * u.w);
+mat3 __operator / (const mat3 m, const float b)
+{
+ __retVal[0] = m[0] / b;
+ __retVal[1] = m[1] / b;
+ __retVal[2] = m[2] / b;
}
-//
-// Dividing by zero does not cause an exception but does result in an unspecified value.
-//
-vec2 __operator / (const vec2 v, const vec2 u) {
- return vec2 (v.x / u.x, v.y / u.y);
+//// mat4/float operations
+
+mat4 __operator + (const float a, const mat4 n)
+{
+ __retVal[0] = a + n[0];
+ __retVal[1] = a + n[1];
+ __retVal[2] = a + n[2];
+ __retVal[3] = a + n[3];
+}
+
+mat4 __operator + (const mat4 m, const float b)
+{
+ __retVal[0] = m[0] + b;
+ __retVal[1] = m[1] + b;
+ __retVal[2] = m[2] + b;
+ __retVal[3] = m[3] + b;
}
-vec3 __operator / (const vec3 v, const vec3 u) {
- return vec3 (v.x / u.x, v.y / u.y, v.z / u.z);
+mat4 __operator - (const float a, const mat4 n)
+{
+ __retVal[0] = a - n[0];
+ __retVal[1] = a - n[1];
+ __retVal[2] = a - n[2];
+ __retVal[3] = a - n[3];
}
-vec4 __operator / (const vec4 v, const vec4 u) {
- return vec4 (v.x / u.x, v.y / u.y, v.z / u.z, v.w / u.w);
+mat4 __operator - (const mat4 m, const float b)
+{
+ __retVal[0] = m[0] - b;
+ __retVal[1] = m[1] - b;
+ __retVal[2] = m[2] - b;
+ __retVal[3] = m[3] - b;
}
-ivec2 __operator / (const ivec2 v, const ivec2 u) {
- return ivec2 (v.x / u.x, v.y / u.y);
+mat4 __operator * (const float a, const mat4 n)
+{
+ __retVal[0] = a * n[0];
+ __retVal[1] = a * n[1];
+ __retVal[2] = a * n[2];
+ __retVal[3] = a * n[3];
}
-ivec3 __operator / (const ivec3 v, const ivec3 u) {
- return ivec3 (v.x / u.x, v.y / u.y, v.z / u.z);
+mat4 __operator * (const mat4 m, const float b)
+{
+ __retVal[0] = m[0] * b;
+ __retVal[1] = m[1] * b;
+ __retVal[2] = m[2] * b;
+ __retVal[3] = m[3] * b;
}
-ivec4 __operator / (const ivec4 v, const ivec4 u) {
- return ivec4 (v.x / u.x, v.y / u.y, v.z / u.z, v.w / u.w);
+mat4 __operator / (const float a, const mat4 n)
+{
+ __retVal[0] = a / n[0];
+ __retVal[1] = a / n[1];
+ __retVal[2] = a / n[2];
+ __retVal[3] = a / n[3];
}
-mat2 __operator / (const mat2 m, const mat2 n) {
- return mat2 (m[0] / n[0], m[1] / n[1]);
+mat4 __operator / (const mat4 m, const float b)
+{
+ __retVal[0] = m[0] / b;
+ __retVal[1] = m[1] / b;
+ __retVal[2] = m[2] / b;
+ __retVal[3] = m[3] / b;
}
-mat3 __operator / (const mat3 m, const mat3 n) {
- return mat3 (m[0] / n[0], m[1] / n[1], m[2] / n[2]);
+
+
+//// matrix / vector products
+
+vec2 __operator * (const mat2 m, const vec2 v)
+{
+ __retVal = m[0] * v.xx
+ + m[1] * v.yy;
}
-mat4 __operator / (const mat4 m, const mat4 n) {
- return mat4 (m[0] / n[0], m[1] / n[1], m[2] / n[2], m[3] / n[3]);
+vec2 __operator * (const vec2 v, const mat2 m)
+{
+ __retVal.x = dot(v, m[0]);
+ __retVal.y = dot(v, m[1]);
}
-//
-// Multiply (*) applied to two matrices yields a linear algebraic matrix multiply, not
-// a component-wise multiply.
-//
+vec3 __operator * (const mat3 m, const vec3 v)
+{
+ __retVal = m[0] * v.xxx
+ + m[1] * v.yyy
+ + m[2] * v.zzz;
+}
-mat2 __operator * (const mat2 m, const mat2 n) {
- return mat2 (m * n[0], m * n[1]);
+vec3 __operator * (const vec3 v, const mat3 m)
+{
+ __retVal.x = dot(v, m[0]);
+ __retVal.y = dot(v, m[1]);
+ __retVal.z = dot(v, m[2]);
}
-mat3 __operator * (const mat3 m, const mat3 n) {
- return mat3 (m * n[0], m * n[1], m * n[2]);
+vec4 __operator * (const mat4 m, const vec4 v)
+{
+ __retVal = m[0] * v.xxxx
+ + m[1] * v.yyyy
+ + m[2] * v.zzzz
+ + m[3] * v.wwww;
}
-mat4 __operator * (const mat4 m, const mat4 n) {
- return mat4 (m * n[0], m * n[1], m * n[2], m * n[3]);
+vec4 __operator * (const vec4 v, const mat4 m)
+{
+ __retVal.x = dot(v, m[0]);
+ __retVal.y = dot(v, m[1]);
+ __retVal.z = dot(v, m[2]);
+ __retVal.w = dot(v, m[3]);
}
-//
-// * The arithmetic unary operators negate (-), post- and pre-increment and decrement (-- and
-// ++) that operate on integer or floating-point values (including vectors and matrices). These
-// result with the same type they operated on. For post- and pre-increment and decrement, the
-// expression must be one that could be assigned to (an l-value). Pre-increment and predecrement
-// add or subtract 1 or 1.0 to the contents of the expression they operate on, and the
-// value of the pre-increment or pre-decrement expression is the resulting value of that
-// modification. Post-increment and post-decrement expressions add or subtract 1 or 1.0 to
-// the contents of the expression they operate on, but the resulting expression has the
-// expression's value before the post-increment or post-decrement was executed.
-//
-// [NOTE: postfix increment and decrement operators take additional dummy int parameter to
-// distinguish their prototypes from prefix ones.]
-//
-float __operator - (const float a) {
- float c;
- __asm float_negate c, a;
- return c;
+
+//// mat2 assignment operators
+
+void __operator += (inout mat2 m, const mat2 n)
+{
+ m[0] += n[0];
+ m[1] += n[1];
}
-int __operator - (const int a) {
- return int (-float (a));
+void __operator -= (inout mat2 m, const mat2 n)
+{
+ m[0] -= n[0];
+ m[1] -= n[1];
}
-vec2 __operator - (const vec2 v) {
- return vec2 (-v.x, -v.y);
+void __operator *= (inout mat2 m, const mat2 n)
+{
+ m = m * n;
}
-vec3 __operator - (const vec3 v) {
- return vec3 (-v.x, -v.y, -v.z);
+void __operator /= (inout mat2 m, const mat2 n)
+{
+ m[0] /= n[0];
+ m[1] /= n[1];
}
-vec4 __operator - (const vec4 v) {
- return vec4 (-v.x, -v.y, -v.z, -v.w);
+
+//// mat3 assignment operators
+
+void __operator += (inout mat3 m, const mat3 n)
+{
+ m[0] += n[0];
+ m[1] += n[1];
+ m[2] += n[2];
}
-ivec2 __operator - (const ivec2 v) {
- return ivec2 (-v.x, -v.y);
+void __operator -= (inout mat3 m, const mat3 n)
+{
+ m[0] -= n[0];
+ m[1] -= n[1];
+ m[2] -= n[2];
}
-ivec3 __operator - (const ivec3 v) {
- return ivec3 (-v.x, -v.y, -v.z);
+void __operator *= (inout mat3 m, const mat3 n)
+{
+ m = m * n;
}
-ivec4 __operator - (const ivec4 v) {
- return ivec4 (-v.x, -v.y, -v.z, -v.w);
+void __operator /= (inout mat3 m, const mat3 n)
+{
+ m[0] /= n[0];
+ m[1] /= n[1];
+ m[2] /= n[2];
}
-mat2 __operator - (const mat2 m) {
- return mat2 (-m[0], -m[1]);
+
+// mat4 assignment operators
+
+void __operator += (inout mat4 m, const mat4 n)
+{
+ m[0] += n[0];
+ m[1] += n[1];
+ m[2] += n[2];
+ m[3] += n[3];
}
-mat3 __operator - (const mat3 m) {
- return mat3 (-m[0], -m[1], -m[2]);
+void __operator -= (inout mat4 m, const mat4 n) {
+ m[0] -= n[0];
+ m[1] -= n[1];
+ m[2] -= n[2];
+ m[3] -= n[3];
}
-mat4 __operator - (const mat4 m) {
- return mat4 (-m[0], -m[1], -m[2], -m[3]);
+void __operator *= (inout mat4 m, const mat4 n)
+{
+ m = m * n;
}
-void __operator -- (inout float a) {
- a -= 1.0;
+void __operator /= (inout mat4 m, const mat4 n)
+{
+ m[0] /= n[0];
+ m[1] /= n[1];
+ m[2] /= n[2];
+ m[3] /= n[3];
}
-void __operator -- (inout int a) {
- a -= 1;
+
+//// mat2/float assignment operators
+
+void __operator += (inout mat2 m, const float a) {
+ m[0] += a;
+ m[1] += a;
}
-void __operator -- (inout vec2 v) {
- --v.x, --v.y;
+void __operator -= (inout mat2 m, const float a) {
+ m[0] -= a;
+ m[1] -= a;
}
-void __operator -- (inout vec3 v) {
- --v.x, --v.y, --v.z;
+void __operator *= (inout mat2 m, const float a) {
+ m[0] *= a;
+ m[1] *= a;
}
-void __operator -- (inout vec4 v) {
- --v.x, --v.y, --v.z, --v.w;
+void __operator /= (inout mat2 m, const float a) {
+ m[0] /= a;
+ m[1] /= a;
}
-void __operator -- (inout ivec2 v) {
- --v.x, --v.y;
+
+//// mat3/float assignment operators
+
+void __operator += (inout mat3 m, const float a) {
+ m[0] += a;
+ m[1] += a;
+ m[2] += a;
}
-void __operator -- (inout ivec3 v) {
- --v.x, --v.y, --v.z;
+void __operator -= (inout mat3 m, const float a) {
+ m[0] -= a;
+ m[1] -= a;
+ m[2] -= a;
}
-void __operator -- (inout ivec4 v) {
- --v.x, --v.y, --v.z, --v.w;
+void __operator *= (inout mat3 m, const float a) {
+ m[0] *= a;
+ m[1] *= a;
+ m[2] *= a;
}
-void __operator -- (inout mat2 m) {
- --m[0], --m[1];
+void __operator /= (inout mat3 m, const float a) {
+ m[0] /= a;
+ m[1] /= a;
+ m[2] /= a;
}
-void __operator -- (inout mat3 m) {
- --m[0], --m[1], --m[2];
+
+//// mat4/float assignment operators
+
+void __operator += (inout mat4 m, const float a) {
+ m[0] += a;
+ m[1] += a;
+ m[2] += a;
+ m[3] += a;
}
-void __operator -- (inout mat4 m) {
- --m[0], --m[1], --m[2], --m[3];
+void __operator -= (inout mat4 m, const float a) {
+ m[0] -= a;
+ m[1] -= a;
+ m[2] -= a;
+ m[3] -= a;
}
-void __operator ++ (inout float a) {
- a += 1.0;
+void __operator *= (inout mat4 m, const float a) {
+ m[0] *= a;
+ m[1] *= a;
+ m[2] *= a;
+ m[3] *= a;
}
-void __operator ++ (inout int a) {
- a += 1;
+void __operator /= (inout mat4 m, const float a) {
+ m[0] /= a;
+ m[1] /= a;
+ m[2] /= a;
+ m[3] /= a;
}
-void __operator ++ (inout vec2 v) {
- ++v.x, ++v.y;
+
+
+//// vec/mat assignment operators
+
+void __operator *= (inout vec2 v, const mat2 m)
+{
+ v = v * m;
}
-void __operator ++ (inout vec3 v) {
- ++v.x, ++v.y, ++v.z;
+void __operator *= (inout vec3 v, const mat3 m)
+{
+ v = v * m;
}
-void __operator ++ (inout vec4 v) {
- ++v.x, ++v.y, ++v.z, ++v.w;
+void __operator *= (inout vec4 v, const mat4 m)
+{
+ v = v * m;
}
-void __operator ++ (inout ivec2 v) {
- ++v.x, ++v.y;
+
+
+//// pre-decrement operators
+
+int __operator --(inout int a)
+{
+ a = a - 1;
+ __retVal = a;
}
-void __operator ++ (inout ivec3 v) {
- ++v.x, ++v.y, ++v.z;
+ivec2 __operator --(inout ivec2 v)
+{
+ v = v - ivec2(1);
+ __retVal = v;
}
-void __operator ++ (inout ivec4 v) {
- ++v.x, ++v.y, ++v.z, ++v.w;
+ivec3 __operator --(inout ivec3 v)
+{
+ v = v - ivec3(1);
+ __retVal = v;
}
-void __operator ++ (inout mat2 m) {
- ++m[0], ++m[1];
+ivec4 __operator --(inout ivec4 v)
+{
+ v = v - ivec4(1);
+ __retVal = v;
}
-void __operator ++ (inout mat3 m) {
- ++m[0], ++m[1], ++m[2];
+
+float __operator --(inout float a)
+{
+ a = a - 1.0;
+ __retVal = a;
}
-void __operator ++ (inout mat4 m) {
- ++m[0], ++m[1], ++m[2], ++m[3];
+vec2 __operator --(inout vec2 v)
+{
+ v = v - vec2(1.0);
+ __retVal = v;
}
-float __operator -- (inout float a, const int) {
- const float c = a;
- --a;
- return c;
+vec3 __operator --(inout vec3 v)
+{
+ v = v - vec3(1.0);
+ __retVal = v;
}
-int __operator -- (inout int a, const int) {
- const int c = a;
- --a;
- return c;
+vec4 __operator --(inout vec4 v)
+{
+ v = v - vec4(1.0);
+ __retVal = v;
}
-vec2 __operator -- (inout vec2 v, const int) {
- return vec2 (v.x--, v.y--);
+
+mat2 __operator --(inout mat2 m)
+{
+ m[0] = m[0] - vec2(1.0);
+ m[1] = m[1] - vec2(1.0);
+ __retVal = m;
}
-vec3 __operator -- (inout vec3 v, const int) {
- return vec3 (v.x--, v.y--, v.z--);
+mat3 __operator --(inout mat3 m)
+{
+ m[0] = m[0] - vec3(1.0);
+ m[1] = m[1] - vec3(1.0);
+ m[2] = m[2] - vec3(1.0);
+ __retVal = m;
}
-vec4 __operator -- (inout vec4 v, const int) {
- return vec4 (v.x--, v.y--, v.z--, v.w--);
+mat4 __operator --(inout mat4 m)
+{
+ m[0] = m[0] - vec4(1.0);
+ m[1] = m[1] - vec4(1.0);
+ m[2] = m[2] - vec4(1.0);
+ m[3] = m[3] - vec4(1.0);
+ __retVal = m;
}
-ivec2 __operator -- (inout ivec2 v, const int) {
- return ivec2 (v.x--, v.y--);
+
+//// pre-increment operators
+
+int __operator ++(inout int a)
+{
+ a = a + 1;
+ __retVal = a;
}
-ivec3 __operator -- (inout ivec3 v, const int) {
- return ivec3 (v.x--, v.y--, v.z--);
+ivec2 __operator ++(inout ivec2 v)
+{
+ v = v + ivec2(1);
+ __retVal = v;
}
-ivec4 __operator -- (inout ivec4 v, const int) {
- return ivec4 (v.x--, v.y--, v.z--, v.w--);
+ivec3 __operator ++(inout ivec3 v)
+{
+ v = v + ivec3(1);
+ __retVal = v;
}
-mat2 __operator -- (inout mat2 m, const int) {
- return mat2 (m[0]--, m[1]--);
+ivec4 __operator ++(inout ivec4 v)
+{
+ v = v + ivec4(1);
+ __retVal = v;
}
-mat3 __operator -- (inout mat3 m, const int) {
- return mat3 (m[0]--, m[1]--, m[2]--);
+
+float __operator ++(inout float a)
+{
+ a = a + 1.0;
+ __retVal = a;
}
-mat4 __operator -- (inout mat4 m, const int) {
- return mat4 (m[0]--, m[1]--, m[2]--, m[3]--);
+vec2 __operator ++(inout vec2 v)
+{
+ v = v + vec2(1.0);
+ __retVal = v;
}
-float __operator ++ (inout float a, const int) {
- const float c = a;
- ++a;
- return c;
+vec3 __operator ++(inout vec3 v)
+{
+ v = v + vec3(1.0);
+ __retVal = v;
}
-int __operator ++ (inout int a, const int) {
- const int c = a;
- ++a;
- return c;
+vec4 __operator ++(inout vec4 v)
+{
+ v = v + vec4(1.0);
+ __retVal = v;
}
-vec2 __operator ++ (inout vec2 v, const int) {
- return vec2 (v.x++, v.y++);
+
+mat2 __operator ++(inout mat2 m)
+{
+ m[0] = m[0] + vec2(1.0);
+ m[1] = m[1] + vec2(1.0);
+ __retVal = m;
}
-vec3 __operator ++ (inout vec3 v, const int) {
- return vec3 (v.x++, v.y++, v.z++);
+mat3 __operator ++(inout mat3 m)
+{
+ m[0] = m[0] + vec3(1.0);
+ m[1] = m[1] + vec3(1.0);
+ m[2] = m[2] + vec3(1.0);
+ __retVal = m;
}
-vec4 __operator ++ (inout vec4 v, const int) {
- return vec4 (v.x++, v.y++, v.z++, v.w++);
+mat4 __operator ++(inout mat4 m)
+{
+ m[0] = m[0] + vec4(1.0);
+ m[1] = m[1] + vec4(1.0);
+ m[2] = m[2] + vec4(1.0);
+ m[3] = m[3] + vec4(1.0);
+ __retVal = m;
}
-ivec2 __operator ++ (inout ivec2 v, const int) {
- return ivec2 (v.x++, v.y++);
+
+
+//// post-decrement
+
+int __postDecr(inout int a)
+{
+ __retVal = a;
+ a = a - 1;
}
-ivec3 __operator ++ (inout ivec3 v, const int) {
- return ivec3 (v.x++, v.y++, v.z++);
+ivec2 __postDecr(inout ivec2 v)
+{
+ __retVal = v;
+ v = v - ivec2(1);
}
-ivec4 __operator ++ (inout ivec4 v, const int) {
- return ivec4 (v.x++, v.y++, v.z++, v.w++);
+ivec3 __postDecr(inout ivec3 v)
+{
+ __retVal = v;
+ v = v - ivec3(1);
}
-mat2 __operator ++ (inout mat2 m, const int) {
- return mat2 (m[0]++, m[1]++);
+ivec4 __postDecr(inout ivec4 v)
+{
+ __retVal = v;
+ v = v - ivec4(1);
}
-mat3 __operator ++ (inout mat3 m, const int) {
- return mat3 (m[0]++, m[1]++, m[2]++);
+
+float __postDecr(inout float a)
+{
+ __retVal = a;
+ a = a - 1.0;
}
-mat4 __operator ++ (inout mat4 m, const int) {
- return mat4 (m[0]++, m[1]++, m[2]++, m[3]++);
+vec2 __postDecr(inout vec2 v)
+{
+ __retVal = v;
+ v = v - vec2(1.0);
}
-//
-// * The relational operators greater than (>), less than (<), greater than or equal (>=), and less
-// than or equal (<=) operate only on scalar integer and scalar floating-point expressions. The
-// result is scalar Boolean. The operands' types must match. To do component-wise
-// comparisons on vectors, use the built-in functions lessThan, lessThanEqual,
-// greaterThan, and greaterThanEqual.
-//
+vec3 __postDecr(inout vec3 v)
+{
+ __retVal = v;
+ v = v - vec3(1.0);
+}
-bool __operator < (const float a, const float b) {
- bool c;
- __asm float_less c, a, b;
- return c;
+vec4 __postDecr(inout vec4 v)
+{
+ __retVal = v;
+ v = v - vec4(1.0);
}
-bool __operator < (const int a, const int b) {
- return float (a) < float (b);
+
+mat2 __postDecr(inout mat2 m)
+{
+ __retVal = m;
+ m[0] = m[0] - vec2(1.0);
+ m[1] = m[1] - vec2(1.0);
}
-bool __operator > (const float a, const float b) {
- return b < a;
+mat3 __postDecr(inout mat3 m)
+{
+ __retVal = m;
+ m[0] = m[0] - vec3(1.0);
+ m[1] = m[1] - vec3(1.0);
+ m[2] = m[2] - vec3(1.0);
}
-bool __operator > (const int a, const int b) {
- return b < a;
+mat4 __postDecr(inout mat4 m)
+{
+ __retVal = m;
+ m[0] = m[0] - vec4(1.0);
+ m[1] = m[1] - vec4(1.0);
+ m[2] = m[2] - vec4(1.0);
+ m[3] = m[3] - vec4(1.0);
}
-bool __operator >= (const float a, const float b) {
- return a > b || a == b;
+
+//// post-increment
+
+float __postIncr(inout float a)
+{
+ __retVal = a;
+ a = a + 1;
}
-bool __operator >= (const int a, const int b) {
- return a > b || a == b;
+vec2 __postIncr(inout vec2 v)
+{
+ __retVal = v;
+ v = v + vec2(1.0);
}
-bool __operator <= (const float a, const float b) {
- return a < b || a == b;
+vec3 __postIncr(inout vec3 v)
+{
+ __retVal = v;
+ v = v + vec3(1.0);
}
-bool __operator <= (const int a, const int b) {
- return a < b || a == b;
+vec4 __postIncr(inout vec4 v)
+{
+ __retVal = v;
+ v = v + vec4(1.0);
}
-//
-// * The equality operators equal (==), and not equal (!=) operate on all types except arrays.
-// They result in a scalar Boolean. For vectors, matrices, and structures, all components of the
-// operands must be equal for the operands to be considered equal. To get component-wise
-// equality results for vectors, use the built-in functions equal and notEqual.
-//
-bool __operator == (const float a, const float b) {
- bool c;
- __asm float_equal c, a, b;
- return c;
+int __postIncr(inout int a)
+{
+ __retVal = a;
+ a = a + 1;
}
-bool __operator == (const int a, const int b) {
- return float (a) == float (b);
+ivec2 __postIncr(inout ivec2 v)
+{
+ __retVal = v;
+ v = v + ivec2(1);
}
-bool __operator == (const bool a, const bool b) {
- return float (a) == float (b);
+ivec3 __postIncr(inout ivec3 v)
+{
+ __retVal = v;
+ v = v + ivec3(1);
}
-bool __operator == (const vec2 v, const vec2 u) {
- return v.x == u.x && v.y == u.y;
+ivec4 __postIncr(inout ivec4 v)
+{
+ __retVal = v;
+ v = v + ivec3(1);
}
-bool __operator == (const vec3 v, const vec3 u) {
- return v.x == u.x && v.y == u.y && v.z == u.z;
+
+mat2 __postIncr(inout mat2 m)
+{
+ mat2 n = m;
+ m[0] = m[0] + vec2(1.0);
+ m[1] = m[1] + vec2(1.0);
+ return n;
+}
+
+mat3 __postIncr(inout mat3 m)
+{
+ mat3 n = m;
+ m[0] = m[0] + vec3(1.0);
+ m[1] = m[1] + vec3(1.0);
+ m[2] = m[2] + vec3(1.0);
+ return n;
}
-bool __operator == (const vec4 v, const vec4 u) {
- return v.x == u.x && v.y == u.y && v.z == u.z && v.w == u.w;
+mat4 __postIncr(inout mat4 m)
+{
+ mat4 n = m;
+ m[0] = m[0] + vec4(1.0);
+ m[1] = m[1] + vec4(1.0);
+ m[2] = m[2] + vec4(1.0);
+ m[3] = m[3] + vec4(1.0);
+ return n;
}
-bool __operator == (const ivec2 v, const ivec2 u) {
- return v.x == u.x && v.y == u.y;
+
+
+//// inequality operators
+
+
+// XXX are the inequality operators for floats/ints really needed????
+bool __operator < (const float a, const float b)
+{
+ __asm vec4_sgt __retVal.x, b, a;
}
-bool __operator == (const ivec3 v, const ivec3 u) {
- return v.x == u.x && v.y == u.y && v.z == u.z;
+
+bool __operator < (const int a, const int b) {
+ return float (a) < float (b);
}
-bool __operator == (const ivec4 v, const ivec4 u) {
- return v.x == u.x && v.y == u.y && v.z == u.z && v.w == u.w;
+bool __operator > (const float a, const float b) {
+ bool c;
+ __asm float_less c, b, a;
+ return c;
}
-bool __operator == (const bvec2 v, const bvec2 u) {
- return v.x == u.x && v.y == u.y;
+bool __operator > (const int a, const int b) {
+ return float (a) > float (b);
}
-bool __operator == (const bvec3 v, const bvec3 u) {
- return v.x == u.x && v.y == u.y && v.z == u.z;
+bool __operator >= (const float a, const float b) {
+ bool g, e;
+ __asm float_less g, b, a;
+ __asm float_equal e, a, b;
+ return g || e;
}
-bool __operator == (const bvec4 v, const bvec4 u) {
- return v.x == u.x && v.y == u.y && v.z == u.z && v.w == u.w;
+bool __operator >= (const int a, const int b) {
+ return float (a) >= float (b);
}
-bool __operator == (const mat2 m, const mat2 n) {
- return m[0] == n[0] && m[1] == n[1];
+bool __operator <= (const float a, const float b) {
+ bool g, e;
+ __asm float_less g, a, b;
+ __asm float_equal e, a, b;
+ return g || e;
}
-bool __operator == (const mat3 m, const mat3 n) {
- return m[0] == n[0] && m[1] == n[1] && m[2] == n[2];
+bool __operator <= (const int a, const int b) {
+ return float (a) <= float (b);
}
-bool __operator == (const mat4 m, const mat4 n) {
- return m[0] == n[0] && m[1] == n[1] && m[2] == n[2] && m[3] == n[3];
+
+
+//
+// MESA-specific extension functions.
+//
+
+void printMESA (const float f) {
+ __asm float_print f;
}
-bool __operator != (const float a, const float b) {
- return !(a == b);
+void printMESA (const int i) {
+ __asm int_print i;
}
-bool __operator != (const int a, const int b) {
- return !(a == b);
+void printMESA (const bool b) {
+ __asm bool_print b;
}
-bool __operator != (const bool a, const bool b) {
- return !(a == b);
+void printMESA (const vec2 v) {
+ printMESA (v.x);
+ printMESA (v.y);
}
-bool __operator != (const vec2 v, const vec2 u) {
- return v.x != u.x || v.y != u.y;
+void printMESA (const vec3 v) {
+ printMESA (v.x);
+ printMESA (v.y);
+ printMESA (v.z);
}
-bool __operator != (const vec3 v, const vec3 u) {
- return v.x != u.x || v.y != u.y || v.z != u.z;
+void printMESA (const vec4 v) {
+ printMESA (v.x);
+ printMESA (v.y);
+ printMESA (v.z);
+ printMESA (v.w);
}
-bool __operator != (const vec4 v, const vec4 u) {
- return v.x != u.x || v.y != u.y || v.z != u.z || v.w != u.w;
+void printMESA (const ivec2 v) {
+ printMESA (v.x);
+ printMESA (v.y);
}
-bool __operator != (const ivec2 v, const ivec2 u) {
- return v.x != u.x || v.y != u.y;
+void printMESA (const ivec3 v) {
+ printMESA (v.x);
+ printMESA (v.y);
+ printMESA (v.z);
}
-bool __operator != (const ivec3 v, const ivec3 u) {
- return v.x != u.x || v.y != u.y || v.z != u.z;
+void printMESA (const ivec4 v) {
+ printMESA (v.x);
+ printMESA (v.y);
+ printMESA (v.z);
+ printMESA (v.w);
}
-bool __operator != (const ivec4 v, const ivec4 u) {
- return v.x != u.x || v.y != u.y || v.z != u.z || v.w != u.w;
+void printMESA (const bvec2 v) {
+ printMESA (v.x);
+ printMESA (v.y);
}
-bool __operator != (const bvec2 v, const bvec2 u) {
- return v.x != u.x || v.y != u.y;
+void printMESA (const bvec3 v) {
+ printMESA (v.x);
+ printMESA (v.y);
+ printMESA (v.z);
}
-bool __operator != (const bvec3 v, const bvec3 u) {
- return v.x != u.x || v.y != u.y || v.z != u.z;
+void printMESA (const bvec4 v) {
+ printMESA (v.x);
+ printMESA (v.y);
+ printMESA (v.z);
+ printMESA (v.w);
}
-bool __operator != (const bvec4 v, const bvec4 u) {
- return v.x != u.x || v.y != u.y || v.z != u.z || v.w != u.w;
+void printMESA (const mat2 m) {
+ printMESA (m[0]);
+ printMESA (m[1]);
}
-bool __operator != (const mat2 m, const mat2 n) {
- return m[0] != n[0] || m[1] != n[1];
+void printMESA (const mat3 m) {
+ printMESA (m[0]);
+ printMESA (m[1]);
+ printMESA (m[2]);
}
-bool __operator != (const mat3 m, const mat3 n) {
- return m[0] != n[0] || m[1] != n[1] || m[2] != n[2];
+void printMESA (const mat4 m) {
+ printMESA (m[0]);
+ printMESA (m[1]);
+ printMESA (m[2]);
+ printMESA (m[3]);
}
-bool __operator != (const mat4 m, const mat4 n) {
- return m[0] != n[0] || m[1] != n[1] || m[2] != n[2] || m[3] != n[3];
+void printMESA (const sampler1D e) {
+ __asm int_print e;
}
-//
-// * The logical binary operators and (&&), or ( | | ), and exclusive or (^^). They operate only
-// on two Boolean expressions and result in a Boolean expression. And (&&) will only
-// evaluate the right hand operand if the left hand operand evaluated to true. Or ( | | ) will
-// only evaluate the right hand operand if the left hand operand evaluated to false. Exclusive or
-// (^^) will always evaluate both operands.
-//
+void printMESA (const sampler2D e) {
+ __asm int_print e;
+}
-bool __operator ^^ (const bool a, const bool b) {
- return a != b;
+void printMESA (const sampler3D e) {
+ __asm int_print e;
}
-//
-// [These operators are handled internally by the compiler:]
-//
-// bool __operator && (bool a, bool b) {
-// return a ? b : false;
-// }
-// bool __operator || (bool a, bool b) {
-// return a ? true : b;
-// }
-//
+void printMESA (const samplerCube e) {
+ __asm int_print e;
+}
-//
-// * The logical unary operator not (!). It operates only on a Boolean expression and results in a
-// Boolean expression. To operate on a vector, use the built-in function not.
-//
+void printMESA (const sampler1DShadow e) {
+ __asm int_print e;
+}
-bool __operator ! (const bool a) {
- return a == false;
+void printMESA (const sampler2DShadow e) {
+ __asm int_print e;
}
-\r
+