summaryrefslogtreecommitdiffstats
path: root/libs/rs/scriptc
diff options
context:
space:
mode:
Diffstat (limited to 'libs/rs/scriptc')
-rw-r--r--libs/rs/scriptc/rs_cl.rsh785
-rw-r--r--libs/rs/scriptc/rs_core.rsh892
-rw-r--r--libs/rs/scriptc/rs_graphics.rsh163
-rw-r--r--libs/rs/scriptc/rs_math.rsh505
-rw-r--r--libs/rs/scriptc/rs_types.rsh59
5 files changed, 2028 insertions, 376 deletions
diff --git a/libs/rs/scriptc/rs_cl.rsh b/libs/rs/scriptc/rs_cl.rsh
new file mode 100644
index 0000000..64844a4
--- /dev/null
+++ b/libs/rs/scriptc/rs_cl.rsh
@@ -0,0 +1,785 @@
+#ifndef __RS_CL_RSH__
+#define __RS_CL_RSH__
+
+#define M_PI 3.14159265358979323846264338327950288f /* pi */
+
+
+// Conversions
+#define CVT_FUNC_2(typeout, typein) \
+static typeout##2 __attribute__((overloadable)) convert_##typeout##2(typein##2 v) { \
+ typeout##2 r = {(typeout)v.x, (typeout)v.y}; \
+ return r; \
+} \
+static typeout##3 __attribute__((overloadable)) convert_##typeout##3(typein##3 v) { \
+ typeout##3 r = {(typeout)v.x, (typeout)v.y, (typeout)v.z}; \
+ return r; \
+} \
+static typeout##4 __attribute__((overloadable)) convert_##typeout##4(typein##4 v) { \
+ typeout##4 r = {(typeout)v.x, (typeout)v.y, (typeout)v.z, (typeout)v.w}; \
+ return r; \
+}
+
+#define CVT_FUNC(type) CVT_FUNC_2(type, uchar) \
+ CVT_FUNC_2(type, char) \
+ CVT_FUNC_2(type, ushort) \
+ CVT_FUNC_2(type, short) \
+ CVT_FUNC_2(type, int) \
+ CVT_FUNC_2(type, uint) \
+ CVT_FUNC_2(type, float)
+
+CVT_FUNC(char)
+CVT_FUNC(uchar)
+CVT_FUNC(short)
+CVT_FUNC(ushort)
+CVT_FUNC(int)
+CVT_FUNC(uint)
+CVT_FUNC(float)
+
+
+
+// Float ops, 6.11.2
+
+#define DEF_FUNC_1(fnc) \
+static float2 __attribute__((overloadable)) fnc(float2 v) { \
+ float2 r; \
+ r.x = fnc(v.x); \
+ r.y = fnc(v.y); \
+ return r; \
+} \
+static float3 __attribute__((overloadable)) fnc(float3 v) { \
+ float3 r; \
+ r.x = fnc(v.x); \
+ r.y = fnc(v.y); \
+ r.z = fnc(v.z); \
+ return r; \
+} \
+static float4 __attribute__((overloadable)) fnc(float4 v) { \
+ float4 r; \
+ r.x = fnc(v.x); \
+ r.y = fnc(v.y); \
+ r.z = fnc(v.z); \
+ r.w = fnc(v.w); \
+ return r; \
+}
+
+#define DEF_FUNC_2(fnc) \
+static float2 __attribute__((overloadable)) fnc(float2 v1, float2 v2) { \
+ float2 r; \
+ r.x = fnc(v1.x, v2.x); \
+ r.y = fnc(v1.y, v2.y); \
+ return r; \
+} \
+static float3 __attribute__((overloadable)) fnc(float3 v1, float3 v2) { \
+ float3 r; \
+ r.x = fnc(v1.x, v2.x); \
+ r.y = fnc(v1.y, v2.y); \
+ r.z = fnc(v1.z, v2.z); \
+ return r; \
+} \
+static float4 __attribute__((overloadable)) fnc(float4 v1, float4 v2) { \
+ float4 r; \
+ r.x = fnc(v1.x, v2.x); \
+ r.y = fnc(v1.y, v2.y); \
+ r.z = fnc(v1.z, v2.z); \
+ r.w = fnc(v1.w, v2.z); \
+ return r; \
+}
+
+#define DEF_FUNC_2F(fnc) \
+static float2 __attribute__((overloadable)) fnc(float2 v1, float v2) { \
+ float2 r; \
+ r.x = fnc(v1.x, v2); \
+ r.y = fnc(v1.y, v2); \
+ return r; \
+} \
+static float3 __attribute__((overloadable)) fnc(float3 v1, float v2) { \
+ float3 r; \
+ r.x = fnc(v1.x, v2); \
+ r.y = fnc(v1.y, v2); \
+ r.z = fnc(v1.z, v2); \
+ return r; \
+} \
+static float4 __attribute__((overloadable)) fnc(float4 v1, float v2) { \
+ float4 r; \
+ r.x = fnc(v1.x, v2); \
+ r.y = fnc(v1.y, v2); \
+ r.z = fnc(v1.z, v2); \
+ r.w = fnc(v1.w, v2); \
+ return r; \
+}
+
+
+extern float __attribute__((overloadable)) acos(float);
+DEF_FUNC_1(acos)
+
+extern float __attribute__((overloadable)) acosh(float);
+DEF_FUNC_1(acosh)
+
+static float __attribute__((overloadable)) acospi(float v) {
+ return acos(v) / M_PI;
+}
+DEF_FUNC_1(acospi)
+
+extern float __attribute__((overloadable)) asin(float);
+DEF_FUNC_1(asin)
+
+extern float __attribute__((overloadable)) asinh(float);
+DEF_FUNC_1(asinh)
+
+static float __attribute__((overloadable)) asinpi(float v) {
+ return asin(v) / M_PI;
+}
+DEF_FUNC_1(asinpi)
+
+extern float __attribute__((overloadable)) atan(float);
+DEF_FUNC_1(atan)
+
+extern float __attribute__((overloadable)) atan2(float, float);
+DEF_FUNC_2(atan2)
+
+extern float __attribute__((overloadable)) atanh(float);
+DEF_FUNC_1(atanh)
+
+static float __attribute__((overloadable)) atanpi(float v) {
+ return atan(v) / M_PI;
+}
+DEF_FUNC_1(atanpi)
+
+static float __attribute__((overloadable)) atan2pi(float y, float x) {
+ return atan2(y, x) / M_PI;
+}
+DEF_FUNC_2(atan2pi)
+
+extern float __attribute__((overloadable)) cbrt(float);
+DEF_FUNC_1(cbrt)
+
+extern float __attribute__((overloadable)) ceil(float);
+DEF_FUNC_1(ceil)
+
+extern float __attribute__((overloadable)) copysign(float, float);
+DEF_FUNC_2(copysign)
+
+extern float __attribute__((overloadable)) cos(float);
+DEF_FUNC_1(cos)
+
+extern float __attribute__((overloadable)) cosh(float);
+DEF_FUNC_1(cosh)
+
+static float __attribute__((overloadable)) cospi(float v) {
+ return cos(v * M_PI);
+}
+DEF_FUNC_1(cospi)
+
+extern float __attribute__((overloadable)) erfc(float);
+DEF_FUNC_1(erfc)
+
+extern float __attribute__((overloadable)) erf(float);
+DEF_FUNC_1(erf)
+
+extern float __attribute__((overloadable)) exp(float);
+DEF_FUNC_1(exp)
+
+extern float __attribute__((overloadable)) exp2(float);
+DEF_FUNC_1(exp2)
+
+extern float __attribute__((overloadable)) pow(float, float);
+static float __attribute__((overloadable)) exp10(float v) {
+ return pow(10.f, v);
+}
+DEF_FUNC_1(exp10)
+
+extern float __attribute__((overloadable)) expm1(float);
+DEF_FUNC_1(expm1)
+
+extern float __attribute__((overloadable)) fabs(float);
+DEF_FUNC_1(fabs)
+
+extern float __attribute__((overloadable)) fdim(float, float);
+DEF_FUNC_2(fdim)
+
+extern float __attribute__((overloadable)) floor(float);
+DEF_FUNC_1(floor)
+
+extern float __attribute__((overloadable)) fma(float, float, float);
+extern float2 __attribute__((overloadable)) fma(float2, float2, float2);
+extern float3 __attribute__((overloadable)) fma(float3, float3, float3);
+extern float4 __attribute__((overloadable)) fma(float4, float4, float4);
+
+extern float __attribute__((overloadable)) fmax(float, float);
+DEF_FUNC_2(fmax);
+DEF_FUNC_2F(fmax);
+
+extern float __attribute__((overloadable)) fmin(float, float);
+DEF_FUNC_2(fmin);
+DEF_FUNC_2F(fmin);
+
+extern float __attribute__((overloadable)) fmod(float, float);
+DEF_FUNC_2(fmod)
+
+static float __attribute__((overloadable)) fract(float v, float *iptr) {
+ int i = (int)floor(v);
+ iptr[0] = i;
+ return fmin(v - i, 0x1.fffffep-1f);
+}
+static float2 __attribute__((overloadable)) fract(float2 v, float2 *iptr) {
+ float t[2];
+ float2 r;
+ r.x = fract(v.x, &t[0]);
+ r.y = fract(v.y, &t[1]);
+ iptr[0] = t[0];
+ iptr[1] = t[1];
+ return r;
+}
+static float3 __attribute__((overloadable)) fract(float3 v, float3 *iptr) {
+ float t[3];
+ float3 r;
+ r.x = fract(v.x, &t[0]);
+ r.y = fract(v.y, &t[1]);
+ r.z = fract(v.z, &t[2]);
+ iptr[0] = t[0];
+ iptr[1] = t[1];
+ iptr[2] = t[2];
+ return r;
+}
+static float4 __attribute__((overloadable)) fract(float4 v, float4 *iptr) {
+ float t[4];
+ float4 r;
+ r.x = fract(v.x, &t[0]);
+ r.y = fract(v.y, &t[1]);
+ r.z = fract(v.z, &t[2]);
+ r.w = fract(v.w, &t[3]);
+ iptr[0] = t[0];
+ iptr[1] = t[1];
+ iptr[2] = t[2];
+ iptr[3] = t[3];
+ return r;
+}
+
+extern float __attribute__((overloadable)) frexp(float, float *);
+extern float2 __attribute__((overloadable)) frexp(float2, float2 *);
+extern float3 __attribute__((overloadable)) frexp(float3, float3 *);
+extern float4 __attribute__((overloadable)) frexp(float4, float4 *);
+
+extern float __attribute__((overloadable)) hypot(float, float);
+DEF_FUNC_2(hypot)
+
+extern int __attribute__((overloadable)) ilogb(float);
+DEF_FUNC_1(ilogb)
+
+extern float __attribute__((overloadable)) ldexp(float, int);
+extern float2 __attribute__((overloadable)) ldexp(float2, int2);
+extern float3 __attribute__((overloadable)) ldexp(float3, int3);
+extern float4 __attribute__((overloadable)) ldexp(float4, int4);
+extern float2 __attribute__((overloadable)) ldexp(float2, int);
+extern float3 __attribute__((overloadable)) ldexp(float3, int);
+extern float4 __attribute__((overloadable)) ldexp(float4, int);
+
+extern float __attribute__((overloadable)) lgamma(float);
+DEF_FUNC_1(lgamma)
+extern float __attribute__((overloadable)) lgamma(float, float *);
+extern float2 __attribute__((overloadable)) lgamma(float2, float2 *);
+extern float3 __attribute__((overloadable)) lgamma(float3, float3 *);
+extern float4 __attribute__((overloadable)) lgamma(float4, float4 *);
+
+extern float __attribute__((overloadable)) log(float);
+DEF_FUNC_1(log)
+
+
+extern float __attribute__((overloadable)) log10(float);
+DEF_FUNC_1(log10)
+
+static float __attribute__((overloadable)) log2(float v) {
+ return log10(v) / log10(2.f);
+}
+DEF_FUNC_1(log2)
+
+extern float __attribute__((overloadable)) log1p(float);
+DEF_FUNC_1(log1p)
+
+extern float __attribute__((overloadable)) logb(float);
+DEF_FUNC_1(logb)
+
+extern float __attribute__((overloadable)) mad(float, float, float);
+extern float2 __attribute__((overloadable)) mad(float2, float2, float2);
+extern float3 __attribute__((overloadable)) mad(float3, float3, float3);
+extern float4 __attribute__((overloadable)) mad(float4, float4, float4);
+
+extern float __attribute__((overloadable)) modf(float, float *);
+extern float2 __attribute__((overloadable)) modf(float2, float2 *);
+extern float3 __attribute__((overloadable)) modf(float3, float3 *);
+extern float4 __attribute__((overloadable)) modf(float4, float4 *);
+
+//extern float __attribute__((overloadable)) nan(uint);
+
+extern float __attribute__((overloadable)) nextafter(float, float);
+DEF_FUNC_2(nextafter)
+
+DEF_FUNC_2(pow)
+
+static float __attribute__((overloadable)) pown(float v, int p) {
+ return pow(v, (float)p);
+}
+static float2 __attribute__((overloadable)) pown(float2 v, int2 p) {
+ return pow(v, (float2)p);
+}
+static float3 __attribute__((overloadable)) pown(float3 v, int3 p) {
+ return pow(v, (float3)p);
+}
+static float4 __attribute__((overloadable)) pown(float4 v, int4 p) {
+ return pow(v, (float4)p);
+}
+
+static float __attribute__((overloadable)) powr(float v, float p) {
+ return pow(v, p);
+}
+static float2 __attribute__((overloadable)) powr(float2 v, float2 p) {
+ return pow(v, p);
+}
+static float3 __attribute__((overloadable)) powr(float3 v, float3 p) {
+ return pow(v, p);
+}
+static float4 __attribute__((overloadable)) powr(float4 v, float4 p) {
+ return pow(v, p);
+}
+
+extern float __attribute__((overloadable)) remainder(float, float);
+DEF_FUNC_2(remainder)
+
+extern float __attribute__((overloadable)) remquo(float, float, float *);
+extern float2 __attribute__((overloadable)) remquo(float2, float2, float2 *);
+extern float3 __attribute__((overloadable)) remquo(float3, float3, float3 *);
+extern float4 __attribute__((overloadable)) remquo(float4, float4, float4 *);
+
+extern float __attribute__((overloadable)) rint(float);
+DEF_FUNC_1(rint)
+
+static float __attribute__((overloadable)) rootn(float v, int r) {
+ return pow(v, 1.f / r);
+}
+static float2 __attribute__((overloadable)) rootn(float2 v, int2 r) {
+ float2 t = {1.f / r.x, 1.f / r.y};
+ return pow(v, t);
+}
+static float3 __attribute__((overloadable)) rootn(float3 v, int3 r) {
+ float3 t = {1.f / r.x, 1.f / r.y, 1.f / r.z};
+ return pow(v, t);
+}
+static float4 __attribute__((overloadable)) rootn(float4 v, int4 r) {
+ float4 t = {1.f / r.x, 1.f / r.y, 1.f / r.z, 1.f / r.w};
+ return pow(v, t);
+}
+
+extern float __attribute__((overloadable)) round(float);
+DEF_FUNC_1(round)
+
+extern float __attribute__((overloadable)) sqrt(float);
+/*static float __attribute__((overloadable)) rsqrt(float v) {
+ return 1.f / sqrt(v);
+}
+DEF_FUNC_1(rsqrt)*/
+
+extern float __attribute__((overloadable)) sin(float);
+DEF_FUNC_1(sin)
+
+static float __attribute__((overloadable)) sincos(float v, float *cosptr) {
+ *cosptr = cos(v);
+ return sin(v);
+}
+static float2 __attribute__((overloadable)) sincos(float2 v, float2 *cosptr) {
+ *cosptr = cos(v);
+ return sin(v);
+}
+static float3 __attribute__((overloadable)) sincos(float3 v, float3 *cosptr) {
+ *cosptr = cos(v);
+ return sin(v);
+}
+static float4 __attribute__((overloadable)) sincos(float4 v, float4 *cosptr) {
+ *cosptr = cos(v);
+ return sin(v);
+}
+
+extern float __attribute__((overloadable)) sinh(float);
+DEF_FUNC_1(sinh)
+
+static float __attribute__((overloadable)) sinpi(float v) {
+ return sin(v * M_PI);
+}
+DEF_FUNC_1(sinpi)
+
+DEF_FUNC_1(sqrt)
+
+extern float __attribute__((overloadable)) tan(float);
+DEF_FUNC_1(tan)
+
+extern float __attribute__((overloadable)) tanh(float);
+DEF_FUNC_1(tanh)
+
+static float __attribute__((overloadable)) tanpi(float v) {
+ return tan(v * M_PI);
+}
+DEF_FUNC_1(tanpi)
+
+extern float __attribute__((overloadable)) tgamma(float);
+DEF_FUNC_1(tgamma)
+
+extern float __attribute__((overloadable)) trunc(float);
+DEF_FUNC_1(trunc)
+
+// Int ops (partial), 6.11.3
+extern uint __attribute__((overloadable)) abs(int);
+extern ushort __attribute__((overloadable)) abs(short);
+extern uchar __attribute__((overloadable)) abs(char);
+
+extern uint __attribute__((overloadable)) clz(uint);
+extern int __attribute__((overloadable)) clz(int);
+extern ushort __attribute__((overloadable)) clz(ushort);
+extern short __attribute__((overloadable)) clz(short);
+extern uchar __attribute__((overloadable)) clz(uchar);
+extern char __attribute__((overloadable)) clz(char);
+
+static uint __attribute__((overloadable)) min(uint v1, uint v2) {
+ return v1 < v2 ? v1 : v2;
+}
+static int __attribute__((overloadable)) min(int v1, int v2) {
+ return v1 < v2 ? v1 : v2;
+}
+static ushort __attribute__((overloadable)) min(ushort v1, ushort v2) {
+ return v1 < v2 ? v1 : v2;
+}
+static short __attribute__((overloadable)) min(short v1, short v2) {
+ return v1 < v2 ? v1 : v2;
+}
+static uchar __attribute__((overloadable)) min(uchar v1, uchar v2) {
+ return v1 < v2 ? v1 : v2;
+}
+static char __attribute__((overloadable)) min(char v1, char v2) {
+ return v1 < v2 ? v1 : v2;
+}
+
+static uint __attribute__((overloadable)) max(uint v1, uint v2) {
+ return v1 > v2 ? v1 : v2;
+}
+static int __attribute__((overloadable)) max(int v1, int v2) {
+ return v1 > v2 ? v1 : v2;
+}
+static ushort __attribute__((overloadable)) max(ushort v1, ushort v2) {
+ return v1 > v2 ? v1 : v2;
+}
+static short __attribute__((overloadable)) max(short v1, short v2) {
+ return v1 > v2 ? v1 : v2;
+}
+static uchar __attribute__((overloadable)) max(uchar v1, uchar v2) {
+ return v1 > v2 ? v1 : v2;
+}
+static char __attribute__((overloadable)) max(char v1, char v2) {
+ return v1 > v2 ? v1 : v2;
+}
+
+
+
+
+// 6.11.4
+
+static float __attribute__((overloadable)) clamp(float amount, float low, float high) {
+ return amount < low ? low : (amount > high ? high : amount);
+}
+static float2 __attribute__((overloadable)) clamp(float2 amount, float2 low, float2 high) {
+ float2 r;
+ r.x = amount.x < low.x ? low.x : (amount.x > high.x ? high.x : amount.x);
+ r.y = amount.y < low.y ? low.y : (amount.y > high.y ? high.y : amount.y);
+ return r;
+}
+static float3 __attribute__((overloadable)) clamp(float3 amount, float3 low, float3 high) {
+ float3 r;
+ r.x = amount.x < low.x ? low.x : (amount.x > high.x ? high.x : amount.x);
+ r.y = amount.y < low.y ? low.y : (amount.y > high.y ? high.y : amount.y);
+ r.z = amount.z < low.z ? low.z : (amount.z > high.z ? high.z : amount.z);
+ return r;
+}
+static float4 __attribute__((overloadable)) clamp(float4 amount, float4 low, float4 high) {
+ float4 r;
+ r.x = amount.x < low.x ? low.x : (amount.x > high.x ? high.x : amount.x);
+ r.y = amount.y < low.y ? low.y : (amount.y > high.y ? high.y : amount.y);
+ r.z = amount.z < low.z ? low.z : (amount.z > high.z ? high.z : amount.z);
+ r.w = amount.w < low.w ? low.w : (amount.w > high.w ? high.w : amount.w);
+ return r;
+}
+static float2 __attribute__((overloadable)) clamp(float2 amount, float low, float high) {
+ float2 r;
+ r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
+ r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
+ return r;
+}
+static float3 __attribute__((overloadable)) clamp(float3 amount, float low, float high) {
+ float3 r;
+ r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
+ r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
+ r.z = amount.z < low ? low : (amount.z > high ? high : amount.z);
+ return r;
+}
+static float4 __attribute__((overloadable)) clamp(float4 amount, float low, float high) {
+ float4 r;
+ r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
+ r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
+ r.z = amount.z < low ? low : (amount.z > high ? high : amount.z);
+ r.w = amount.w < low ? low : (amount.w > high ? high : amount.w);
+ return r;
+}
+
+static float __attribute__((overloadable)) degrees(float radians) {
+ return radians * (180.f / M_PI);
+}
+DEF_FUNC_1(degrees)
+
+static float __attribute__((overloadable)) max(float v1, float v2) {
+ return v1 > v2 ? v1 : v2;
+}
+static float2 __attribute__((overloadable)) max(float2 v1, float2 v2) {
+ float2 r;
+ r.x = v1.x > v2.x ? v1.x : v2.x;
+ r.y = v1.y > v2.y ? v1.y : v2.y;
+ return r;
+}
+static float3 __attribute__((overloadable)) max(float3 v1, float3 v2) {
+ float3 r;
+ r.x = v1.x > v2.x ? v1.x : v2.x;
+ r.y = v1.y > v2.y ? v1.y : v2.y;
+ r.z = v1.z > v2.z ? v1.z : v2.z;
+ return r;
+}
+static float4 __attribute__((overloadable)) max(float4 v1, float4 v2) {
+ float4 r;
+ r.x = v1.x > v2.x ? v1.x : v2.x;
+ r.y = v1.y > v2.y ? v1.y : v2.y;
+ r.z = v1.z > v2.z ? v1.z : v2.z;
+ r.w = v1.w > v2.w ? v1.w : v2.w;
+ return r;
+}
+static float2 __attribute__((overloadable)) max(float2 v1, float v2) {
+ float2 r;
+ r.x = v1.x > v2 ? v1.x : v2;
+ r.y = v1.y > v2 ? v1.y : v2;
+ return r;
+}
+static float3 __attribute__((overloadable)) max(float3 v1, float v2) {
+ float3 r;
+ r.x = v1.x > v2 ? v1.x : v2;
+ r.y = v1.y > v2 ? v1.y : v2;
+ r.z = v1.z > v2 ? v1.z : v2;
+ return r;
+}
+static float4 __attribute__((overloadable)) max(float4 v1, float v2) {
+ float4 r;
+ r.x = v1.x > v2 ? v1.x : v2;
+ r.y = v1.y > v2 ? v1.y : v2;
+ r.z = v1.z > v2 ? v1.z : v2;
+ r.w = v1.w > v2 ? v1.w : v2;
+ return r;
+}
+
+static float __attribute__((overloadable)) min(float v1, float v2) {
+ return v1 < v2 ? v1 : v2;
+}
+static float2 __attribute__((overloadable)) min(float2 v1, float2 v2) {
+ float2 r;
+ r.x = v1.x < v2.x ? v1.x : v2.x;
+ r.y = v1.y < v2.y ? v1.y : v2.y;
+ return r;
+}
+static float3 __attribute__((overloadable)) min(float3 v1, float3 v2) {
+ float3 r;
+ r.x = v1.x < v2.x ? v1.x : v2.x;
+ r.y = v1.y < v2.y ? v1.y : v2.y;
+ r.z = v1.z < v2.z ? v1.z : v2.z;
+ return r;
+}
+static float4 __attribute__((overloadable)) min(float4 v1, float4 v2) {
+ float4 r;
+ r.x = v1.x < v2.x ? v1.x : v2.x;
+ r.y = v1.y < v2.y ? v1.y : v2.y;
+ r.z = v1.z < v2.z ? v1.z : v2.z;
+ r.w = v1.w < v2.w ? v1.w : v2.w;
+ return r;
+}
+static float2 __attribute__((overloadable)) min(float2 v1, float v2) {
+ float2 r;
+ r.x = v1.x < v2 ? v1.x : v2;
+ r.y = v1.y < v2 ? v1.y : v2;
+ return r;
+}
+static float3 __attribute__((overloadable)) min(float3 v1, float v2) {
+ float3 r;
+ r.x = v1.x < v2 ? v1.x : v2;
+ r.y = v1.y < v2 ? v1.y : v2;
+ r.z = v1.z < v2 ? v1.z : v2;
+ return r;
+}
+static float4 __attribute__((overloadable)) min(float4 v1, float v2) {
+ float4 r;
+ r.x = v1.x < v2 ? v1.x : v2;
+ r.y = v1.y < v2 ? v1.y : v2;
+ r.z = v1.z < v2 ? v1.z : v2;
+ r.w = v1.w < v2 ? v1.w : v2;
+ return r;
+}
+
+static float __attribute__((overloadable)) mix(float start, float stop, float amount) {
+ return start + (stop - start) * amount;
+}
+static float2 __attribute__((overloadable)) mix(float2 start, float2 stop, float2 amount) {
+ return start + (stop - start) * amount;
+}
+static float3 __attribute__((overloadable)) mix(float3 start, float3 stop, float3 amount) {
+ return start + (stop - start) * amount;
+}
+static float4 __attribute__((overloadable)) mix(float4 start, float4 stop, float4 amount) {
+ return start + (stop - start) * amount;
+}
+static float2 __attribute__((overloadable)) mix(float2 start, float2 stop, float amount) {
+ return start + (stop - start) * amount;
+}
+static float3 __attribute__((overloadable)) mix(float3 start, float3 stop, float amount) {
+ return start + (stop - start) * amount;
+}
+static float4 __attribute__((overloadable)) mix(float4 start, float4 stop, float amount) {
+ return start + (stop - start) * amount;
+}
+
+static float __attribute__((overloadable)) radians(float degrees) {
+ return degrees * (M_PI / 180.f);
+}
+DEF_FUNC_1(radians)
+
+static float __attribute__((overloadable)) step(float edge, float v) {
+ return (v < edge) ? 0.f : 1.f;
+}
+static float2 __attribute__((overloadable)) step(float2 edge, float2 v) {
+ float2 r;
+ r.x = (v.x < edge.x) ? 0.f : 1.f;
+ r.y = (v.y < edge.y) ? 0.f : 1.f;
+ return r;
+}
+static float3 __attribute__((overloadable)) step(float3 edge, float3 v) {
+ float3 r;
+ r.x = (v.x < edge.x) ? 0.f : 1.f;
+ r.y = (v.y < edge.y) ? 0.f : 1.f;
+ r.z = (v.z < edge.z) ? 0.f : 1.f;
+ return r;
+}
+static float4 __attribute__((overloadable)) step(float4 edge, float4 v) {
+ float4 r;
+ r.x = (v.x < edge.x) ? 0.f : 1.f;
+ r.y = (v.y < edge.y) ? 0.f : 1.f;
+ r.z = (v.z < edge.z) ? 0.f : 1.f;
+ r.w = (v.w < edge.w) ? 0.f : 1.f;
+ return r;
+}
+static float2 __attribute__((overloadable)) step(float2 edge, float v) {
+ float2 r;
+ r.x = (v < edge.x) ? 0.f : 1.f;
+ r.y = (v < edge.y) ? 0.f : 1.f;
+ return r;
+}
+static float3 __attribute__((overloadable)) step(float3 edge, float v) {
+ float3 r;
+ r.x = (v < edge.x) ? 0.f : 1.f;
+ r.y = (v < edge.y) ? 0.f : 1.f;
+ r.z = (v < edge.z) ? 0.f : 1.f;
+ return r;
+}
+static float4 __attribute__((overloadable)) step(float4 edge, float v) {
+ float4 r;
+ r.x = (v < edge.x) ? 0.f : 1.f;
+ r.y = (v < edge.y) ? 0.f : 1.f;
+ r.z = (v < edge.z) ? 0.f : 1.f;
+ r.w = (v < edge.w) ? 0.f : 1.f;
+ return r;
+}
+
+extern float __attribute__((overloadable)) smoothstep(float, float, float);
+extern float2 __attribute__((overloadable)) smoothstep(float2, float2, float2);
+extern float3 __attribute__((overloadable)) smoothstep(float3, float3, float3);
+extern float4 __attribute__((overloadable)) smoothstep(float4, float4, float4);
+extern float2 __attribute__((overloadable)) smoothstep(float, float, float2);
+extern float3 __attribute__((overloadable)) smoothstep(float, float, float3);
+extern float4 __attribute__((overloadable)) smoothstep(float, float, float4);
+
+static float __attribute__((overloadable)) sign(float v) {
+ if (v > 0) return 1.f;
+ if (v < 0) return -1.f;
+ return v;
+}
+DEF_FUNC_1(sign)
+
+// 6.11.5
+static float3 __attribute__((overloadable)) cross(float3 lhs, float3 rhs) {
+ float3 r;
+ r.x = lhs.y * rhs.z - lhs.z * rhs.y;
+ r.y = lhs.z * rhs.x - lhs.x * rhs.z;
+ r.z = lhs.x * rhs.y - lhs.y * rhs.x;
+ return r;
+}
+
+static float4 __attribute__((overloadable)) cross(float4 lhs, float4 rhs) {
+ float4 r;
+ r.x = lhs.y * rhs.z - lhs.z * rhs.y;
+ r.y = lhs.z * rhs.x - lhs.x * rhs.z;
+ r.z = lhs.x * rhs.y - lhs.y * rhs.x;
+ r.w = 0.f;
+ return r;
+}
+
+static float __attribute__((overloadable)) dot(float lhs, float rhs) {
+ return lhs * rhs;
+}
+static float __attribute__((overloadable)) dot(float2 lhs, float2 rhs) {
+ return lhs.x*rhs.x + lhs.y*rhs.y;
+}
+static float __attribute__((overloadable)) dot(float3 lhs, float3 rhs) {
+ return lhs.x*rhs.x + lhs.y*rhs.y + lhs.z*rhs.z;
+}
+static float __attribute__((overloadable)) dot(float4 lhs, float4 rhs) {
+ return lhs.x*rhs.x + lhs.y*rhs.y + lhs.z*rhs.z + lhs.w*rhs.w;
+}
+
+static float __attribute__((overloadable)) length(float v) {
+ return v;
+}
+static float __attribute__((overloadable)) length(float2 v) {
+ return sqrt(v.x*v.x + v.y*v.y);
+}
+static float __attribute__((overloadable)) length(float3 v) {
+ return sqrt(v.x*v.x + v.y*v.y + v.z*v.z);
+}
+static float __attribute__((overloadable)) length(float4 v) {
+ return sqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w);
+}
+
+static float __attribute__((overloadable)) distance(float lhs, float rhs) {
+ return length(lhs - rhs);
+}
+static float __attribute__((overloadable)) distance(float2 lhs, float2 rhs) {
+ return length(lhs - rhs);
+}
+static float __attribute__((overloadable)) distance(float3 lhs, float3 rhs) {
+ return length(lhs - rhs);
+}
+static float __attribute__((overloadable)) distance(float4 lhs, float4 rhs) {
+ return length(lhs - rhs);
+}
+
+static float __attribute__((overloadable)) normalize(float v) {
+ return 1.f;
+}
+static float2 __attribute__((overloadable)) normalize(float2 v) {
+ return v / length(v);
+}
+static float3 __attribute__((overloadable)) normalize(float3 v) {
+ return v / length(v);
+}
+static float4 __attribute__((overloadable)) normalize(float4 v) {
+ return v / length(v);
+}
+
+
+#endif
diff --git a/libs/rs/scriptc/rs_core.rsh b/libs/rs/scriptc/rs_core.rsh
new file mode 100644
index 0000000..99fc166
--- /dev/null
+++ b/libs/rs/scriptc/rs_core.rsh
@@ -0,0 +1,892 @@
+#ifndef __RS_CORE_RSH__
+#define __RS_CORE_RSH__
+
+static void __attribute__((overloadable)) rsDebug(const char *s, float2 v) {
+ rsDebug(s, v.x, v.y);
+}
+static void __attribute__((overloadable)) rsDebug(const char *s, float3 v) {
+ rsDebug(s, v.x, v.y, v.z);
+}
+static void __attribute__((overloadable)) rsDebug(const char *s, float4 v) {
+ rsDebug(s, v.x, v.y, v.z, v.w);
+}
+
+static uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b)
+{
+ uchar4 c;
+ c.x = (uchar)(r * 255.f);
+ c.y = (uchar)(g * 255.f);
+ c.z = (uchar)(b * 255.f);
+ c.w = 255;
+ return c;
+}
+
+static uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b, float a)
+{
+ uchar4 c;
+ c.x = (uchar)(r * 255.f);
+ c.y = (uchar)(g * 255.f);
+ c.z = (uchar)(b * 255.f);
+ c.w = (uchar)(a * 255.f);
+ return c;
+}
+
+static uchar4 __attribute__((overloadable)) rsPackColorTo8888(float3 color)
+{
+ color *= 255.f;
+ uchar4 c = {color.x, color.y, color.z, 255};
+ return c;
+}
+
+static uchar4 __attribute__((overloadable)) rsPackColorTo8888(float4 color)
+{
+ color *= 255.f;
+ uchar4 c = {color.x, color.y, color.z, color.w};
+ return c;
+}
+
+static float4 rsUnpackColor8888(uchar4 c)
+{
+ float4 ret = (float4)0.0039156862745f;
+ ret *= convert_float4(c);
+ return ret;
+}
+
+//extern uchar4 __attribute__((overloadable)) rsPackColorTo565(float r, float g, float b);
+//extern uchar4 __attribute__((overloadable)) rsPackColorTo565(float3);
+//extern float4 rsUnpackColor565(uchar4);
+
+
+/////////////////////////////////////////////////////
+// Matrix ops
+/////////////////////////////////////////////////////
+
+static void __attribute__((overloadable))
+rsMatrixSet(rs_matrix4x4 *m, uint32_t row, uint32_t col, float v) {
+ m->m[row * 4 + col] = v;
+}
+
+static float __attribute__((overloadable))
+rsMatrixGet(const rs_matrix4x4 *m, uint32_t row, uint32_t col) {
+ return m->m[row * 4 + col];
+}
+
+static void __attribute__((overloadable))
+rsMatrixSet(rs_matrix3x3 *m, uint32_t row, uint32_t col, float v) {
+ m->m[row * 3 + col] = v;
+}
+
+static float __attribute__((overloadable))
+rsMatrixGet(const rs_matrix3x3 *m, uint32_t row, uint32_t col) {
+ return m->m[row * 3 + col];
+}
+
+static void __attribute__((overloadable))
+rsMatrixSet(rs_matrix2x2 *m, uint32_t row, uint32_t col, float v) {
+ m->m[row * 2 + col] = v;
+}
+
+static float __attribute__((overloadable))
+rsMatrixGet(const rs_matrix2x2 *m, uint32_t row, uint32_t col) {
+ return m->m[row * 2 + col];
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoadIdentity(rs_matrix4x4 *m) {
+ m->m[0] = 1.f;
+ m->m[1] = 0.f;
+ m->m[2] = 0.f;
+ m->m[3] = 0.f;
+ m->m[4] = 0.f;
+ m->m[5] = 1.f;
+ m->m[6] = 0.f;
+ m->m[7] = 0.f;
+ m->m[8] = 0.f;
+ m->m[9] = 0.f;
+ m->m[10] = 1.f;
+ m->m[11] = 0.f;
+ m->m[12] = 0.f;
+ m->m[13] = 0.f;
+ m->m[14] = 0.f;
+ m->m[15] = 1.f;
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoadIdentity(rs_matrix3x3 *m) {
+ m->m[0] = 1.f;
+ m->m[1] = 0.f;
+ m->m[2] = 0.f;
+ m->m[3] = 0.f;
+ m->m[4] = 1.f;
+ m->m[5] = 0.f;
+ m->m[6] = 0.f;
+ m->m[7] = 0.f;
+ m->m[8] = 1.f;
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoadIdentity(rs_matrix2x2 *m) {
+ m->m[0] = 1.f;
+ m->m[1] = 0.f;
+ m->m[2] = 0.f;
+ m->m[3] = 1.f;
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoad(rs_matrix4x4 *m, const float *v) {
+ m->m[0] = v[0];
+ m->m[1] = v[1];
+ m->m[2] = v[2];
+ m->m[3] = v[3];
+ m->m[4] = v[4];
+ m->m[5] = v[5];
+ m->m[6] = v[6];
+ m->m[7] = v[7];
+ m->m[8] = v[8];
+ m->m[9] = v[9];
+ m->m[10] = v[10];
+ m->m[11] = v[11];
+ m->m[12] = v[12];
+ m->m[13] = v[13];
+ m->m[14] = v[14];
+ m->m[15] = v[15];
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoad(rs_matrix3x3 *m, const float *v) {
+ m->m[0] = v[0];
+ m->m[1] = v[1];
+ m->m[2] = v[2];
+ m->m[3] = v[3];
+ m->m[4] = v[4];
+ m->m[5] = v[5];
+ m->m[6] = v[6];
+ m->m[7] = v[7];
+ m->m[8] = v[8];
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoad(rs_matrix2x2 *m, const float *v) {
+ m->m[0] = v[0];
+ m->m[1] = v[1];
+ m->m[2] = v[2];
+ m->m[3] = v[3];
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoad(rs_matrix4x4 *m, const rs_matrix4x4 *v) {
+ m->m[0] = v->m[0];
+ m->m[1] = v->m[1];
+ m->m[2] = v->m[2];
+ m->m[3] = v->m[3];
+ m->m[4] = v->m[4];
+ m->m[5] = v->m[5];
+ m->m[6] = v->m[6];
+ m->m[7] = v->m[7];
+ m->m[8] = v->m[8];
+ m->m[9] = v->m[9];
+ m->m[10] = v->m[10];
+ m->m[11] = v->m[11];
+ m->m[12] = v->m[12];
+ m->m[13] = v->m[13];
+ m->m[14] = v->m[14];
+ m->m[15] = v->m[15];
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoad(rs_matrix4x4 *m, const rs_matrix3x3 *v) {
+ m->m[0] = v->m[0];
+ m->m[1] = v->m[1];
+ m->m[2] = v->m[2];
+ m->m[3] = 0.f;
+ m->m[4] = v->m[3];
+ m->m[5] = v->m[4];
+ m->m[6] = v->m[5];
+ m->m[7] = 0.f;
+ m->m[8] = v->m[6];
+ m->m[9] = v->m[7];
+ m->m[10] = v->m[8];
+ m->m[11] = 0.f;
+ m->m[12] = 0.f;
+ m->m[13] = 0.f;
+ m->m[14] = 0.f;
+ m->m[15] = 1.f;
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoad(rs_matrix4x4 *m, const rs_matrix2x2 *v) {
+ m->m[0] = v->m[0];
+ m->m[1] = v->m[1];
+ m->m[2] = 0.f;
+ m->m[3] = 0.f;
+ m->m[4] = v->m[3];
+ m->m[5] = v->m[4];
+ m->m[6] = 0.f;
+ m->m[7] = 0.f;
+ m->m[8] = v->m[6];
+ m->m[9] = v->m[7];
+ m->m[10] = 1.f;
+ m->m[11] = 0.f;
+ m->m[12] = 0.f;
+ m->m[13] = 0.f;
+ m->m[14] = 0.f;
+ m->m[15] = 1.f;
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoad(rs_matrix3x3 *m, const rs_matrix3x3 *v) {
+ m->m[0] = v->m[0];
+ m->m[1] = v->m[1];
+ m->m[2] = v->m[2];
+ m->m[3] = v->m[3];
+ m->m[4] = v->m[4];
+ m->m[5] = v->m[5];
+ m->m[6] = v->m[6];
+ m->m[7] = v->m[7];
+ m->m[8] = v->m[8];
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoad(rs_matrix2x2 *m, const rs_matrix2x2 *v) {
+ m->m[0] = v->m[0];
+ m->m[1] = v->m[1];
+ m->m[2] = v->m[2];
+ m->m[3] = v->m[3];
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoadRotate(rs_matrix4x4 *m, float rot, float x, float y, float z) {
+ float c, s;
+ m->m[3] = 0;
+ m->m[7] = 0;
+ m->m[11]= 0;
+ m->m[12]= 0;
+ m->m[13]= 0;
+ m->m[14]= 0;
+ m->m[15]= 1;
+ rot *= (float)(M_PI / 180.0f);
+ c = cos(rot);
+ s = sin(rot);
+
+ const float len = x*x + y*y + z*z;
+ if (len != 1) {
+ const float recipLen = 1.f / sqrt(len);
+ x *= recipLen;
+ y *= recipLen;
+ z *= recipLen;
+ }
+ const float nc = 1.0f - c;
+ const float xy = x * y;
+ const float yz = y * z;
+ const float zx = z * x;
+ const float xs = x * s;
+ const float ys = y * s;
+ const float zs = z * s;
+ m->m[ 0] = x*x*nc + c;
+ m->m[ 4] = xy*nc - zs;
+ m->m[ 8] = zx*nc + ys;
+ m->m[ 1] = xy*nc + zs;
+ m->m[ 5] = y*y*nc + c;
+ m->m[ 9] = yz*nc - xs;
+ m->m[ 2] = zx*nc - ys;
+ m->m[ 6] = yz*nc + xs;
+ m->m[10] = z*z*nc + c;
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoadScale(rs_matrix4x4 *m, float x, float y, float z) {
+ rsMatrixLoadIdentity(m);
+ m->m[0] = x;
+ m->m[5] = y;
+ m->m[10] = z;
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoadTranslate(rs_matrix4x4 *m, float x, float y, float z) {
+ rsMatrixLoadIdentity(m);
+ m->m[12] = x;
+ m->m[13] = y;
+ m->m[14] = z;
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoadMultiply(rs_matrix4x4 *m, const rs_matrix4x4 *lhs, const rs_matrix4x4 *rhs) {
+ for (int i=0 ; i<4 ; i++) {
+ float ri0 = 0;
+ float ri1 = 0;
+ float ri2 = 0;
+ float ri3 = 0;
+ for (int j=0 ; j<4 ; j++) {
+ const float rhs_ij = rsMatrixGet(rhs, i,j);
+ ri0 += rsMatrixGet(lhs, j, 0) * rhs_ij;
+ ri1 += rsMatrixGet(lhs, j, 1) * rhs_ij;
+ ri2 += rsMatrixGet(lhs, j, 2) * rhs_ij;
+ ri3 += rsMatrixGet(lhs, j, 3) * rhs_ij;
+ }
+ rsMatrixSet(m, i, 0, ri0);
+ rsMatrixSet(m, i, 1, ri1);
+ rsMatrixSet(m, i, 2, ri2);
+ rsMatrixSet(m, i, 3, ri3);
+ }
+}
+
+static void __attribute__((overloadable))
+rsMatrixMultiply(rs_matrix4x4 *m, const rs_matrix4x4 *rhs) {
+ rs_matrix4x4 mt;
+ rsMatrixLoadMultiply(&mt, m, rhs);
+ rsMatrixLoad(m, &mt);
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoadMultiply(rs_matrix3x3 *m, const rs_matrix3x3 *lhs, const rs_matrix3x3 *rhs) {
+ for (int i=0 ; i<3 ; i++) {
+ float ri0 = 0;
+ float ri1 = 0;
+ float ri2 = 0;
+ for (int j=0 ; j<3 ; j++) {
+ const float rhs_ij = rsMatrixGet(rhs, i,j);
+ ri0 += rsMatrixGet(lhs, j, 0) * rhs_ij;
+ ri1 += rsMatrixGet(lhs, j, 1) * rhs_ij;
+ ri2 += rsMatrixGet(lhs, j, 2) * rhs_ij;
+ }
+ rsMatrixSet(m, i, 0, ri0);
+ rsMatrixSet(m, i, 1, ri1);
+ rsMatrixSet(m, i, 2, ri2);
+ }
+}
+
+static void __attribute__((overloadable))
+rsMatrixMultiply(rs_matrix3x3 *m, const rs_matrix3x3 *rhs) {
+ rs_matrix3x3 mt;
+ rsMatrixLoadMultiply(&mt, m, rhs);
+ rsMatrixLoad(m, &mt);
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoadMultiply(rs_matrix2x2 *m, const rs_matrix2x2 *lhs, const rs_matrix2x2 *rhs) {
+ for (int i=0 ; i<2 ; i++) {
+ float ri0 = 0;
+ float ri1 = 0;
+ for (int j=0 ; j<2 ; j++) {
+ const float rhs_ij = rsMatrixGet(rhs, i,j);
+ ri0 += rsMatrixGet(lhs, j, 0) * rhs_ij;
+ ri1 += rsMatrixGet(lhs, j, 1) * rhs_ij;
+ }
+ rsMatrixSet(m, i, 0, ri0);
+ rsMatrixSet(m, i, 1, ri1);
+ }
+}
+
+static void __attribute__((overloadable))
+rsMatrixMultiply(rs_matrix2x2 *m, const rs_matrix2x2 *rhs) {
+ rs_matrix2x2 mt;
+ rsMatrixLoadMultiply(&mt, m, rhs);
+ rsMatrixLoad(m, &mt);
+}
+
+static void __attribute__((overloadable))
+rsMatrixRotate(rs_matrix4x4 *m, float rot, float x, float y, float z) {
+ rs_matrix4x4 m1;
+ rsMatrixLoadRotate(&m1, rot, x, y, z);
+ rsMatrixMultiply(m, &m1);
+}
+
+static void __attribute__((overloadable))
+rsMatrixScale(rs_matrix4x4 *m, float x, float y, float z) {
+ rs_matrix4x4 m1;
+ rsMatrixLoadScale(&m1, x, y, z);
+ rsMatrixMultiply(m, &m1);
+}
+
+static void __attribute__((overloadable))
+rsMatrixTranslate(rs_matrix4x4 *m, float x, float y, float z) {
+ rs_matrix4x4 m1;
+ rsMatrixLoadTranslate(&m1, x, y, z);
+ rsMatrixMultiply(m, &m1);
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoadOrtho(rs_matrix4x4 *m, float left, float right, float bottom, float top, float near, float far) {
+ rsMatrixLoadIdentity(m);
+ m->m[0] = 2.f / (right - left);
+ m->m[5] = 2.f / (top - bottom);
+ m->m[10]= -2.f / (far - near);
+ m->m[12]= -(right + left) / (right - left);
+ m->m[13]= -(top + bottom) / (top - bottom);
+ m->m[14]= -(far + near) / (far - near);
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoadFrustum(rs_matrix4x4 *m, float left, float right, float bottom, float top, float near, float far) {
+ rsMatrixLoadIdentity(m);
+ m->m[0] = 2.f * near / (right - left);
+ m->m[5] = 2.f * near / (top - bottom);
+ m->m[8] = (right + left) / (right - left);
+ m->m[9] = (top + bottom) / (top - bottom);
+ m->m[10]= -(far + near) / (far - near);
+ m->m[11]= -1.f;
+ m->m[14]= -2.f * far * near / (far - near);
+ m->m[15]= 0.f;
+}
+
+static void __attribute__((overloadable))
+rsMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far) {
+ float top = near * tan((float) (fovy * M_PI / 360.0f));
+ float bottom = -top;
+ float left = bottom * aspect;
+ float right = top * aspect;
+ rsMatrixLoadFrustum(m, left, right, bottom, top, near, far);
+}
+
+static float4 __attribute__((overloadable))
+rsMatrixMultiply(rs_matrix4x4 *m, float4 in) {
+ float4 ret;
+ ret.x = (m->m[0] * in.x) + (m->m[4] * in.y) + (m->m[8] * in.z) + (m->m[12] * in.w);
+ ret.y = (m->m[1] * in.x) + (m->m[5] * in.y) + (m->m[9] * in.z) + (m->m[13] * in.w);
+ ret.z = (m->m[2] * in.x) + (m->m[6] * in.y) + (m->m[10] * in.z) + (m->m[14] * in.w);
+ ret.w = (m->m[3] * in.x) + (m->m[7] * in.y) + (m->m[11] * in.z) + (m->m[15] * in.w);
+ return ret;
+}
+
+static float4 __attribute__((overloadable))
+rsMatrixMultiply(rs_matrix4x4 *m, float3 in) {
+ float4 ret;
+ ret.x = (m->m[0] * in.x) + (m->m[4] * in.y) + (m->m[8] * in.z) + m->m[12];
+ ret.y = (m->m[1] * in.x) + (m->m[5] * in.y) + (m->m[9] * in.z) + m->m[13];
+ ret.z = (m->m[2] * in.x) + (m->m[6] * in.y) + (m->m[10] * in.z) + m->m[14];
+ ret.w = (m->m[3] * in.x) + (m->m[7] * in.y) + (m->m[11] * in.z) + m->m[15];
+ return ret;
+}
+
+static float4 __attribute__((overloadable))
+rsMatrixMultiply(rs_matrix4x4 *m, float2 in) {
+ float4 ret;
+ ret.x = (m->m[0] * in.x) + (m->m[4] * in.y) + m->m[12];
+ ret.y = (m->m[1] * in.x) + (m->m[5] * in.y) + m->m[13];
+ ret.z = (m->m[2] * in.x) + (m->m[6] * in.y) + m->m[14];
+ ret.w = (m->m[3] * in.x) + (m->m[7] * in.y) + m->m[15];
+ return ret;
+}
+
+static float3 __attribute__((overloadable))
+rsMatrixMultiply(rs_matrix3x3 *m, float3 in) {
+ float3 ret;
+ ret.x = (m->m[0] * in.x) + (m->m[3] * in.y) + (m->m[6] * in.z);
+ ret.y = (m->m[1] * in.x) + (m->m[4] * in.y) + (m->m[7] * in.z);
+ ret.z = (m->m[2] * in.x) + (m->m[5] * in.y) + (m->m[8] * in.z);
+ return ret;
+}
+
+static float3 __attribute__((overloadable))
+rsMatrixMultiply(rs_matrix3x3 *m, float2 in) {
+ float3 ret;
+ ret.x = (m->m[0] * in.x) + (m->m[3] * in.y);
+ ret.y = (m->m[1] * in.x) + (m->m[4] * in.y);
+ ret.z = (m->m[2] * in.x) + (m->m[5] * in.y);
+ return ret;
+}
+
+static float2 __attribute__((overloadable))
+rsMatrixMultiply(rs_matrix2x2 *m, float2 in) {
+ float2 ret;
+ ret.x = (m->m[0] * in.x) + (m->m[2] * in.y);
+ ret.y = (m->m[1] * in.x) + (m->m[3] * in.y);
+ return ret;
+}
+
+// Returns true if the matrix was successfully inversed
+static bool __attribute__((overloadable))
+rsMatrixInverse(rs_matrix4x4 *m) {
+ rs_matrix4x4 result;
+
+ int i, j;
+ for (i = 0; i < 4; ++i) {
+ for (j = 0; j < 4; ++j) {
+ // computeCofactor for int i, int j
+ int c0 = (i+1) % 4;
+ int c1 = (i+2) % 4;
+ int c2 = (i+3) % 4;
+ int r0 = (j+1) % 4;
+ int r1 = (j+2) % 4;
+ int r2 = (j+3) % 4;
+
+ float minor = (m->m[c0 + 4*r0] * (m->m[c1 + 4*r1] * m->m[c2 + 4*r2] - m->m[c1 + 4*r2] * m->m[c2 + 4*r1]))
+ - (m->m[c0 + 4*r1] * (m->m[c1 + 4*r0] * m->m[c2 + 4*r2] - m->m[c1 + 4*r2] * m->m[c2 + 4*r0]))
+ + (m->m[c0 + 4*r2] * (m->m[c1 + 4*r0] * m->m[c2 + 4*r1] - m->m[c1 + 4*r1] * m->m[c2 + 4*r0]));
+
+ float cofactor = (i+j) & 1 ? -minor : minor;
+
+ result.m[4*i + j] = cofactor;
+ }
+ }
+
+ // Dot product of 0th column of source and 0th row of result
+ float det = m->m[0]*result.m[0] + m->m[4]*result.m[1] +
+ m->m[8]*result.m[2] + m->m[12]*result.m[3];
+
+ if (fabs(det) < 1e-6) {
+ return false;
+ }
+
+ det = 1.0f / det;
+ for (i = 0; i < 16; ++i) {
+ m->m[i] = result.m[i] * det;
+ }
+
+ return true;
+}
+
+// Returns true if the matrix was successfully inversed
+static bool __attribute__((overloadable))
+rsMatrixInverseTranspose(rs_matrix4x4 *m) {
+ rs_matrix4x4 result;
+
+ int i, j;
+ for (i = 0; i < 4; ++i) {
+ for (j = 0; j < 4; ++j) {
+ // computeCofactor for int i, int j
+ int c0 = (i+1) % 4;
+ int c1 = (i+2) % 4;
+ int c2 = (i+3) % 4;
+ int r0 = (j+1) % 4;
+ int r1 = (j+2) % 4;
+ int r2 = (j+3) % 4;
+
+ float minor = (m->m[c0 + 4*r0] * (m->m[c1 + 4*r1] * m->m[c2 + 4*r2] - m->m[c1 + 4*r2] * m->m[c2 + 4*r1]))
+ - (m->m[c0 + 4*r1] * (m->m[c1 + 4*r0] * m->m[c2 + 4*r2] - m->m[c1 + 4*r2] * m->m[c2 + 4*r0]))
+ + (m->m[c0 + 4*r2] * (m->m[c1 + 4*r0] * m->m[c2 + 4*r1] - m->m[c1 + 4*r1] * m->m[c2 + 4*r0]));
+
+ float cofactor = (i+j) & 1 ? -minor : minor;
+
+ result.m[4*j + i] = cofactor;
+ }
+ }
+
+ // Dot product of 0th column of source and 0th column of result
+ float det = m->m[0]*result.m[0] + m->m[4]*result.m[4] +
+ m->m[8]*result.m[8] + m->m[12]*result.m[12];
+
+ if (fabs(det) < 1e-6) {
+ return false;
+ }
+
+ det = 1.0f / det;
+ for (i = 0; i < 16; ++i) {
+ m->m[i] = result.m[i] * det;
+ }
+
+ return true;
+}
+
+static void __attribute__((overloadable))
+rsMatrixTranspose(rs_matrix4x4 *m) {
+ int i, j;
+ float temp;
+ for (i = 0; i < 3; ++i) {
+ for (j = i + 1; j < 4; ++j) {
+ temp = m->m[i*4 + j];
+ m->m[i*4 + j] = m->m[j*4 + i];
+ m->m[j*4 + i] = temp;
+ }
+ }
+}
+
+static void __attribute__((overloadable))
+rsMatrixTranspose(rs_matrix3x3 *m) {
+ int i, j;
+ float temp;
+ for (i = 0; i < 2; ++i) {
+ for (j = i + 1; j < 3; ++j) {
+ temp = m->m[i*3 + j];
+ m->m[i*3 + j] = m->m[j*4 + i];
+ m->m[j*3 + i] = temp;
+ }
+ }
+}
+
+static void __attribute__((overloadable))
+rsMatrixTranspose(rs_matrix2x2 *m) {
+ float temp = m->m[1];
+ m->m[1] = m->m[2];
+ m->m[2] = temp;
+}
+
+/////////////////////////////////////////////////////
+// quaternion ops
+/////////////////////////////////////////////////////
+
+static void __attribute__((overloadable))
+rsQuaternionSet(rs_quaternion *q, float w, float x, float y, float z) {
+ q->w = w;
+ q->x = x;
+ q->y = y;
+ q->z = z;
+}
+
+static void __attribute__((overloadable))
+rsQuaternionSet(rs_quaternion *q, const rs_quaternion *rhs) {
+ q->w = rhs->w;
+ q->x = rhs->x;
+ q->y = rhs->y;
+ q->z = rhs->z;
+}
+
+static void __attribute__((overloadable))
+rsQuaternionMultiply(rs_quaternion *q, float s) {
+ q->w *= s;
+ q->x *= s;
+ q->y *= s;
+ q->z *= s;
+}
+
+static void __attribute__((overloadable))
+rsQuaternionMultiply(rs_quaternion *q, const rs_quaternion *rhs) {
+ q->w = -q->x*rhs->x - q->y*rhs->y - q->z*rhs->z + q->w*rhs->w;
+ q->x = q->x*rhs->w + q->y*rhs->z - q->z*rhs->y + q->w*rhs->x;
+ q->y = -q->x*rhs->z + q->y*rhs->w + q->z*rhs->z + q->w*rhs->y;
+ q->z = q->x*rhs->y - q->y*rhs->x + q->z*rhs->w + q->w*rhs->z;
+}
+
+static void
+rsQuaternionAdd(rs_quaternion *q, const rs_quaternion *rhs) {
+ q->w *= rhs->w;
+ q->x *= rhs->x;
+ q->y *= rhs->y;
+ q->z *= rhs->z;
+}
+
+static void
+rsQuaternionLoadRotateUnit(rs_quaternion *q, float rot, float x, float y, float z) {
+ rot *= (float)(M_PI / 180.0f) * 0.5f;
+ float c = cos(rot);
+ float s = sin(rot);
+
+ q->w = c;
+ q->x = x * s;
+ q->y = y * s;
+ q->z = z * s;
+}
+
+static void
+rsQuaternionLoadRotate(rs_quaternion *q, float rot, float x, float y, float z) {
+ const float len = x*x + y*y + z*z;
+ if (len != 1) {
+ const float recipLen = 1.f / sqrt(len);
+ x *= recipLen;
+ y *= recipLen;
+ z *= recipLen;
+ }
+ rsQuaternionLoadRotateUnit(q, rot, x, y, z);
+}
+
+static void
+rsQuaternionConjugate(rs_quaternion *q) {
+ q->x = -q->x;
+ q->y = -q->y;
+ q->z = -q->z;
+}
+
+static float
+rsQuaternionDot(const rs_quaternion *q0, const rs_quaternion *q1) {
+ return q0->w*q1->w + q0->x*q1->x + q0->y*q1->y + q0->z*q1->z;
+}
+
+static void
+rsQuaternionNormalize(rs_quaternion *q) {
+ const float len = rsQuaternionDot(q, q);
+ if (len != 1) {
+ const float recipLen = 1.f / sqrt(len);
+ rsQuaternionMultiply(q, recipLen);
+ }
+}
+
+static void
+rsQuaternionSlerp(rs_quaternion *q, const rs_quaternion *q0, const rs_quaternion *q1, float t) {
+ if(t <= 0.0f) {
+ rsQuaternionSet(q, q0);
+ return;
+ }
+ if(t >= 1.0f) {
+ rsQuaternionSet(q, q1);
+ return;
+ }
+
+ rs_quaternion tempq0, tempq1;
+ rsQuaternionSet(&tempq0, q0);
+ rsQuaternionSet(&tempq1, q1);
+
+ float angle = rsQuaternionDot(q0, q1);
+ if(angle < 0) {
+ rsQuaternionMultiply(&tempq0, -1.0f);
+ angle *= -1.0f;
+ }
+
+ float scale, invScale;
+ if (angle + 1.0f > 0.05f) {
+ if (1.0f - angle >= 0.05f) {
+ float theta = acos(angle);
+ float invSinTheta = 1.0f / sin(theta);
+ scale = sin(theta * (1.0f - t)) * invSinTheta;
+ invScale = sin(theta * t) * invSinTheta;
+ }
+ else {
+ scale = 1.0f - t;
+ invScale = t;
+ }
+ }
+ else {
+ rsQuaternionSet(&tempq1, tempq0.z, -tempq0.y, tempq0.x, -tempq0.w);
+ scale = sin(M_PI * (0.5f - t));
+ invScale = sin(M_PI * t);
+ }
+
+ rsQuaternionSet(q, tempq0.w*scale + tempq1.w*invScale, tempq0.x*scale + tempq1.x*invScale,
+ tempq0.y*scale + tempq1.y*invScale, tempq0.z*scale + tempq1.z*invScale);
+}
+
+static void rsQuaternionGetMatrixUnit(rs_matrix4x4 *m, const rs_quaternion *q) {
+ float x2 = 2.0f * q->x * q->x;
+ float y2 = 2.0f * q->y * q->y;
+ float z2 = 2.0f * q->z * q->z;
+ float xy = 2.0f * q->x * q->y;
+ float wz = 2.0f * q->w * q->z;
+ float xz = 2.0f * q->x * q->z;
+ float wy = 2.0f * q->w * q->y;
+ float wx = 2.0f * q->w * q->x;
+ float yz = 2.0f * q->y * q->z;
+
+ m->m[0] = 1.0f - y2 - z2;
+ m->m[1] = xy - wz;
+ m->m[2] = xz + wy;
+ m->m[3] = 0.0f;
+
+ m->m[4] = xy + wz;
+ m->m[5] = 1.0f - x2 - z2;
+ m->m[6] = yz - wx;
+ m->m[7] = 0.0f;
+
+ m->m[8] = xz - wy;
+ m->m[9] = yz - wx;
+ m->m[10] = 1.0f - x2 - y2;
+ m->m[11] = 0.0f;
+
+ m->m[12] = 0.0f;
+ m->m[13] = 0.0f;
+ m->m[14] = 0.0f;
+ m->m[15] = 1.0f;
+}
+
+/////////////////////////////////////////////////////
+// utility funcs
+/////////////////////////////////////////////////////
+void __attribute__((overloadable))
+rsExtractFrustumPlanes(const rs_matrix4x4 *modelViewProj,
+ float4 *left, float4 *right,
+ float4 *top, float4 *bottom,
+ float4 *near, float4 *far) {
+ // x y z w = a b c d in the plane equation
+ left->x = modelViewProj->m[3] + modelViewProj->m[0];
+ left->y = modelViewProj->m[7] + modelViewProj->m[4];
+ left->z = modelViewProj->m[11] + modelViewProj->m[8];
+ left->w = modelViewProj->m[15] + modelViewProj->m[12];
+
+ right->x = modelViewProj->m[3] - modelViewProj->m[0];
+ right->y = modelViewProj->m[7] - modelViewProj->m[4];
+ right->z = modelViewProj->m[11] - modelViewProj->m[8];
+ right->w = modelViewProj->m[15] - modelViewProj->m[12];
+
+ top->x = modelViewProj->m[3] - modelViewProj->m[1];
+ top->y = modelViewProj->m[7] - modelViewProj->m[5];
+ top->z = modelViewProj->m[11] - modelViewProj->m[9];
+ top->w = modelViewProj->m[15] - modelViewProj->m[13];
+
+ bottom->x = modelViewProj->m[3] + modelViewProj->m[1];
+ bottom->y = modelViewProj->m[7] + modelViewProj->m[5];
+ bottom->z = modelViewProj->m[11] + modelViewProj->m[9];
+ bottom->w = modelViewProj->m[15] + modelViewProj->m[13];
+
+ near->x = modelViewProj->m[3] + modelViewProj->m[2];
+ near->y = modelViewProj->m[7] + modelViewProj->m[6];
+ near->z = modelViewProj->m[11] + modelViewProj->m[10];
+ near->w = modelViewProj->m[15] + modelViewProj->m[14];
+
+ far->x = modelViewProj->m[3] - modelViewProj->m[2];
+ far->y = modelViewProj->m[7] - modelViewProj->m[6];
+ far->z = modelViewProj->m[11] - modelViewProj->m[10];
+ far->w = modelViewProj->m[15] - modelViewProj->m[14];
+
+ float len = length(left->xyz);
+ *left /= len;
+ len = length(right->xyz);
+ *right /= len;
+ len = length(top->xyz);
+ *top /= len;
+ len = length(bottom->xyz);
+ *bottom /= len;
+ len = length(near->xyz);
+ *near /= len;
+ len = length(far->xyz);
+ *far /= len;
+}
+
+bool __attribute__((overloadable))
+rsIsSphereInFrustum(float4 *sphere,
+ float4 *left, float4 *right,
+ float4 *top, float4 *bottom,
+ float4 *near, float4 *far) {
+
+ float distToCenter = dot(left->xyz, sphere->xyz) + left->w;
+ if(distToCenter < -sphere->w) {
+ return false;
+ }
+ distToCenter = dot(right->xyz, sphere->xyz) + right->w;
+ if(distToCenter < -sphere->w) {
+ return false;
+ }
+ distToCenter = dot(top->xyz, sphere->xyz) + top->w;
+ if(distToCenter < -sphere->w) {
+ return false;
+ }
+ distToCenter = dot(bottom->xyz, sphere->xyz) + bottom->w;
+ if(distToCenter < -sphere->w) {
+ return false;
+ }
+ distToCenter = dot(near->xyz, sphere->xyz) + near->w;
+ if(distToCenter < -sphere->w) {
+ return false;
+ }
+ distToCenter = dot(far->xyz, sphere->xyz) + far->w;
+ if(distToCenter < -sphere->w) {
+ return false;
+ }
+ return true;
+}
+
+
+/////////////////////////////////////////////////////
+// int ops
+/////////////////////////////////////////////////////
+
+__inline__ static uint __attribute__((overloadable, always_inline)) rsClamp(uint amount, uint low, uint high) {
+ return amount < low ? low : (amount > high ? high : amount);
+}
+__inline__ static int __attribute__((overloadable, always_inline)) rsClamp(int amount, int low, int high) {
+ return amount < low ? low : (amount > high ? high : amount);
+}
+__inline__ static ushort __attribute__((overloadable, always_inline)) rsClamp(ushort amount, ushort low, ushort high) {
+ return amount < low ? low : (amount > high ? high : amount);
+}
+__inline__ static short __attribute__((overloadable, always_inline)) rsClamp(short amount, short low, short high) {
+ return amount < low ? low : (amount > high ? high : amount);
+}
+__inline__ static uchar __attribute__((overloadable, always_inline)) rsClamp(uchar amount, uchar low, uchar high) {
+ return amount < low ? low : (amount > high ? high : amount);
+}
+__inline__ static char __attribute__((overloadable, always_inline)) rsClamp(char amount, char low, char high) {
+ return amount < low ? low : (amount > high ? high : amount);
+}
+
+
+
+#endif
+
diff --git a/libs/rs/scriptc/rs_graphics.rsh b/libs/rs/scriptc/rs_graphics.rsh
index 70cd562..c0b2d2d 100644
--- a/libs/rs/scriptc/rs_graphics.rsh
+++ b/libs/rs/scriptc/rs_graphics.rsh
@@ -1,65 +1,106 @@
-
-
-extern float2 vec2Rand(float len);
-
-extern float3 float3Norm(float3);
-extern float float3Length(float3);
-extern float3 float3Add(float3 lhs, float3 rhs);
-extern float3 float3Sub(float3 lhs, float3 rhs);
-extern float3 float3Cross(float3 lhs, float3 rhs);
-extern float float3Dot(float3 lhs, float3 rhs);
-extern float3 float3Scale(float3 v, float scale);
-
-extern float4 float4Add(float4 lhs, float4 rhs);
-extern float4 float4Sub(float4 lhs, float4 rhs);
-extern float4 float4Cross(float4 lhs, float4 rhs);
-extern float float4Dot(float4 lhs, float4 rhs);
-extern float4 float4Scale(float4 v, float scale);
-
- // context
-extern void bindProgramFragment(rs_program_fragment);
-extern void bindProgramStore(rs_program_store);
-extern void bindProgramVertex(rs_program_vertex);
-
-extern void bindSampler(rs_program_fragment, int slot, rs_sampler);
-extern void bindSampler(rs_program_fragment, int slot, rs_allocation);
-
-extern void vpLoadModelMatrix(const float *);
-extern void vpLoadTextureMatrix(const float *);
-
-
-// drawing
-extern void drawRect(float x1, float y1, float x2, float y2, float z);
-extern void drawQuad(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4);
-extern void drawQuadTexCoords(float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3, float x4, float y4, float z4, float u4, float v4);
-extern void drawSprite(float x, float y, float z, float w, float h);
-extern void drawSpriteScreenspace(float x, float y, float z, float w, float h);
-extern void drawLine(float x1, float y1, float z1, float x2, float y2, float z2);
-extern void drawPoint(float x1, float y1, float z1);
-extern void drawSimpleMesh(int ism);
-extern void drawSimpleMeshRange(int ism, int start, int len);
-
+#ifndef __RS_GRAPHICS_RSH__
+#define __RS_GRAPHICS_RSH__
+
+#include "rs_math.rsh"
+
+
+// Bind a ProgramFragment to the RS context.
+extern void __attribute__((overloadable))
+ rsgBindProgramFragment(rs_program_fragment);
+extern void __attribute__((overloadable))
+ rsgBindProgramStore(rs_program_store);
+extern void __attribute__((overloadable))
+ rsgBindProgramVertex(rs_program_vertex);
+extern void __attribute__((overloadable))
+ rsgBindProgramRaster(rs_program_raster);
+
+extern void __attribute__((overloadable))
+ rsgBindSampler(rs_program_fragment, uint slot, rs_sampler);
+extern void __attribute__((overloadable))
+ rsgBindTexture(rs_program_fragment, uint slot, rs_allocation);
+
+extern void __attribute__((overloadable))
+ rsgProgramVertexLoadProjectionMatrix(const rs_matrix4x4 *);
+extern void __attribute__((overloadable))
+ rsgProgramVertexLoadModelMatrix(const rs_matrix4x4 *);
+extern void __attribute__((overloadable))
+ rsgProgramVertexLoadTextureMatrix(const rs_matrix4x4 *);
+
+extern void __attribute__((overloadable))
+ rsgProgramVertexGetProjectionMatrix(rs_matrix4x4 *);
+
+extern void __attribute__((overloadable))
+ rsgProgramFragmentConstantColor(rs_program_fragment, float, float, float, float);
+
+extern uint __attribute__((overloadable))
+ rsgGetWidth(void);
+extern uint __attribute__((overloadable))
+ rsgGetHeight(void);
+
+extern void __attribute__((overloadable))
+ rsgUploadToTexture(rs_allocation);
+extern void __attribute__((overloadable))
+ rsgUploadToTexture(rs_allocation, uint mipLevel);
+extern void __attribute__((overloadable))
+ rsgUploadToBufferObject(rs_allocation);
+
+extern void __attribute__((overloadable))
+ rsgDrawRect(float x1, float y1, float x2, float y2, float z);
+extern void __attribute__((overloadable))
+ rsgDrawQuad(float x1, float y1, float z1,
+ float x2, float y2, float z2,
+ float x3, float y3, float z3,
+ float x4, float y4, float z4);
+extern void __attribute__((overloadable))
+ rsgDrawQuadTexCoords(float x1, float y1, float z1, float u1, float v1,
+ float x2, float y2, float z2, float u2, float v2,
+ float x3, float y3, float z3, float u3, float v3,
+ float x4, float y4, float z4, float u4, float v4);
+extern void __attribute__((overloadable))
+ rsgDrawSpriteScreenspace(float x, float y, float z, float w, float h);
+
+extern void __attribute__((overloadable))
+ rsgDrawMesh(rs_mesh ism);
+extern void __attribute__((overloadable))
+ rsgDrawMesh(rs_mesh ism, uint primitiveIndex);
+extern void __attribute__((overloadable))
+ rsgDrawMesh(rs_mesh ism, uint primitiveIndex, uint start, uint len);
+
+extern void __attribute__((overloadable))
+ rsgClearColor(float, float, float, float);
+extern void __attribute__((overloadable))
+ rsgClearDepth(float);
+
+extern void __attribute__((overloadable))
+ rsgDrawText(const char *, int x, int y);
+extern void __attribute__((overloadable))
+ rsgDrawText(rs_allocation, int x, int y);
+extern void __attribute__((overloadable))
+ rsgBindFont(rs_font);
+extern void __attribute__((overloadable))
+ rsgFontColor(float, float, float, float);
+
+extern void __attribute__((overloadable))
+ rsgMeshComputeBoundingBox(rs_mesh mesh, float *minX, float *minY, float *minZ,
+ float *maxX, float *maxY, float *maxZ);
+void __attribute__((overloadable))
+rsgMeshComputeBoundingBox(rs_mesh mesh, float3 *bBoxMin, float3 *bBoxMax) {
+ float x1, y1, z1, x2, y2, z2;
+ rsgMeshComputeBoundingBox(mesh, &x1, &y1, &z1, &x2, &y2, &z2);
+ bBoxMin->x = x1;
+ bBoxMin->y = y1;
+ bBoxMin->z = z1;
+ bBoxMax->x = x2;
+ bBoxMax->y = y2;
+ bBoxMax->z = z2;
+}
+
+///////////////////////////////////////////////////////
// misc
-extern void pfClearColor(float, float, float, float);
-extern void color(float, float, float, float);
-extern void hsb(float, float, float, float);
-extern void hsbToRgb(float, float, float, float*);
-extern int hsbToAbgr(float, float, float, float);
-
-extern void uploadToTexture(int, int);
-extern void uploadToBufferObject(int);
-
-extern int colorFloatRGBAtoUNorm8(float, float, float, float);
-extern int colorFloatRGBto565(float, float, float);
-
-extern int getWidth();
-extern int getHeight();
-
-extern int sendToClient(void *data, int cmdID, int len, int waitForSpace);
-
-extern void debugF(const char *, float);
-extern void debugI32(const char *, int);
-extern void debugHexI32(const char *, int);
+// Depricated
+extern void __attribute__((overloadable))
+ color(float, float, float, float);
+#endif
diff --git a/libs/rs/scriptc/rs_math.rsh b/libs/rs/scriptc/rs_math.rsh
index 613c7ca..c842ef1 100644
--- a/libs/rs/scriptc/rs_math.rsh
+++ b/libs/rs/scriptc/rs_math.rsh
@@ -1,287 +1,218 @@
-// Float ops
-
-extern float __attribute__((overloadable)) abs(float);
-extern float2 __attribute__((overloadable)) abs(float2);
-extern float3 __attribute__((overloadable)) abs(float3);
-extern float4 __attribute__((overloadable)) abs(float4);
-extern float8 __attribute__((overloadable)) abs(float8);
-extern float16 __attribute__((overloadable)) abs(float16);
-
-extern float __attribute__((overloadable)) acos(float);
-extern float2 __attribute__((overloadable)) acos(float2);
-extern float3 __attribute__((overloadable)) acos(float3);
-extern float4 __attribute__((overloadable)) acos(float4);
-extern float8 __attribute__((overloadable)) acos(float8);
-extern float16 __attribute__((overloadable)) acos(float16);
-
-extern float __attribute__((overloadable)) asin(float);
-extern float2 __attribute__((overloadable)) asin(float2);
-extern float3 __attribute__((overloadable)) asin(float3);
-extern float4 __attribute__((overloadable)) asin(float4);
-extern float8 __attribute__((overloadable)) asin(float8);
-extern float16 __attribute__((overloadable)) asin(float16);
-
-extern float __attribute__((overloadable)) atan(float);
-extern float2 __attribute__((overloadable)) atan(float2);
-extern float3 __attribute__((overloadable)) atan(float3);
-extern float4 __attribute__((overloadable)) atan(float4);
-extern float8 __attribute__((overloadable)) atan(float8);
-extern float16 __attribute__((overloadable)) atan(float16);
-
-extern float __attribute__((overloadable)) atan2(float, float);
-extern float2 __attribute__((overloadable)) atan2(float2, float2);
-extern float3 __attribute__((overloadable)) atan2(float3, float3);
-extern float4 __attribute__((overloadable)) atan2(float4, float4);
-extern float8 __attribute__((overloadable)) atan2(float8, float8);
-extern float16 __attribute__((overloadable)) atan2(float16, float16);
-
-extern float __attribute__((overloadable)) ceil(float);
-extern float2 __attribute__((overloadable)) ceil(float2);
-extern float3 __attribute__((overloadable)) ceil(float3);
-extern float4 __attribute__((overloadable)) ceil(float4);
-extern float8 __attribute__((overloadable)) ceil(float8);
-extern float16 __attribute__((overloadable)) ceil(float16);
-
-extern float __attribute__((overloadable)) clamp(float, float, float);
-extern float2 __attribute__((overloadable)) clamp(float2, float2, float2);
-extern float3 __attribute__((overloadable)) clamp(float3, float3, float3);
-extern float4 __attribute__((overloadable)) clamp(float4, float4, float4);
-extern float8 __attribute__((overloadable)) clamp(float8, float8, float8);
-extern float16 __attribute__((overloadable)) clamp(float16, float16, float16);
-extern float __attribute__((overloadable)) clamp(float, float, float);
-extern float2 __attribute__((overloadable)) clamp(float2, float, float);
-extern float3 __attribute__((overloadable)) clamp(float3, float, float);
-extern float4 __attribute__((overloadable)) clamp(float4, float, float);
-extern float8 __attribute__((overloadable)) clamp(float8, float, float);
-extern float16 __attribute__((overloadable)) clamp(float16, float, float);
-
-extern float __attribute__((overloadable)) copysign(float, float);
-extern float2 __attribute__((overloadable)) copysign(float2, float2);
-extern float3 __attribute__((overloadable)) copysign(float3, float3);
-extern float4 __attribute__((overloadable)) copysign(float4, float4);
-extern float8 __attribute__((overloadable)) copysign(float8, float8);
-extern float16 __attribute__((overloadable)) copysign(float16, float16);
-
-extern float __attribute__((overloadable)) cos(float);
-extern float2 __attribute__((overloadable)) cos(float2);
-extern float3 __attribute__((overloadable)) cos(float3);
-extern float4 __attribute__((overloadable)) cos(float4);
-extern float8 __attribute__((overloadable)) cos(float8);
-extern float16 __attribute__((overloadable)) cos(float16);
-
-extern float __attribute__((overloadable)) degrees(float);
-extern float2 __attribute__((overloadable)) degrees(float2);
-extern float3 __attribute__((overloadable)) degrees(float3);
-extern float4 __attribute__((overloadable)) degrees(float4);
-extern float8 __attribute__((overloadable)) degrees(float8);
-extern float16 __attribute__((overloadable)) degrees(float16);
-
-extern float __attribute__((overloadable)) exp(float);
-extern float2 __attribute__((overloadable)) exp(float2);
-extern float3 __attribute__((overloadable)) exp(float3);
-extern float4 __attribute__((overloadable)) exp(float4);
-extern float8 __attribute__((overloadable)) exp(float8);
-extern float16 __attribute__((overloadable)) exp(float16);
-
-extern float __attribute__((overloadable)) exp2(float);
-extern float2 __attribute__((overloadable)) exp2(float2);
-extern float3 __attribute__((overloadable)) exp2(float3);
-extern float4 __attribute__((overloadable)) exp2(float4);
-extern float8 __attribute__((overloadable)) exp2(float8);
-extern float16 __attribute__((overloadable)) exp2(float16);
-
-extern float __attribute__((overloadable)) exp10(float);
-extern float2 __attribute__((overloadable)) exp10(float2);
-extern float3 __attribute__((overloadable)) exp10(float3);
-extern float4 __attribute__((overloadable)) exp10(float4);
-extern float8 __attribute__((overloadable)) exp10(float8);
-extern float16 __attribute__((overloadable)) exp10(float16);
-
-extern float __attribute__((overloadable)) fabs(float);
-extern float2 __attribute__((overloadable)) fabs(float2);
-extern float3 __attribute__((overloadable)) fabs(float3);
-extern float4 __attribute__((overloadable)) fabs(float4);
-extern float8 __attribute__((overloadable)) fabs(float8);
-extern float16 __attribute__((overloadable)) fabs(float16);
-
-extern float __attribute__((overloadable)) floor(float);
-extern float2 __attribute__((overloadable)) floor(float2);
-extern float3 __attribute__((overloadable)) floor(float3);
-extern float4 __attribute__((overloadable)) floor(float4);
-extern float8 __attribute__((overloadable)) floor(float8);
-extern float16 __attribute__((overloadable)) floor(float16);
-
-extern float __attribute__((overloadable)) fmax(float, float);
-extern float2 __attribute__((overloadable)) fmax(float2, float2);
-extern float3 __attribute__((overloadable)) fmax(float3, float3);
-extern float4 __attribute__((overloadable)) fmax(float4, float4);
-extern float8 __attribute__((overloadable)) fmax(float8, float8);
-extern float16 __attribute__((overloadable)) fmax(float16, float16);
-extern float2 __attribute__((overloadable)) fmax(float2, float);
-extern float3 __attribute__((overloadable)) fmax(float3, float);
-extern float4 __attribute__((overloadable)) fmax(float4, float);
-extern float8 __attribute__((overloadable)) fmax(float8, float);
-extern float16 __attribute__((overloadable)) fmax(float16, float);
-
-extern float __attribute__((overloadable)) fmin(float, float);
-extern float2 __attribute__((overloadable)) fmin(float2, float2);
-extern float3 __attribute__((overloadable)) fmin(float3, float3);
-extern float4 __attribute__((overloadable)) fmin(float4, float4);
-extern float8 __attribute__((overloadable)) fmin(float8, float8);
-extern float16 __attribute__((overloadable)) fmin(float16, float16);
-extern float2 __attribute__((overloadable)) fmin(float2, float);
-extern float3 __attribute__((overloadable)) fmin(float3, float);
-extern float4 __attribute__((overloadable)) fmin(float4, float);
-extern float8 __attribute__((overloadable)) fmin(float8, float);
-extern float16 __attribute__((overloadable)) fmin(float16, float);
-
-extern float __attribute__((overloadable)) fmod(float, float);
-extern float2 __attribute__((overloadable)) fmod(float2, float2);
-extern float3 __attribute__((overloadable)) fmod(float3, float3);
-extern float4 __attribute__((overloadable)) fmod(float4, float4);
-extern float8 __attribute__((overloadable)) fmod(float8, float8);
-extern float16 __attribute__((overloadable)) fmod(float16, float16);
-
-extern float __attribute__((overloadable)) log(float);
-extern float2 __attribute__((overloadable)) log(float2);
-extern float3 __attribute__((overloadable)) log(float3);
-extern float4 __attribute__((overloadable)) log(float4);
-extern float8 __attribute__((overloadable)) log(float8);
-extern float16 __attribute__((overloadable)) log(float16);
-
-extern float __attribute__((overloadable)) log2(float);
-extern float2 __attribute__((overloadable)) log2(float2);
-extern float3 __attribute__((overloadable)) log2(float3);
-extern float4 __attribute__((overloadable)) log2(float4);
-extern float8 __attribute__((overloadable)) log2(float8);
-extern float16 __attribute__((overloadable)) log2(float16);
-
-extern float __attribute__((overloadable)) log10(float);
-extern float2 __attribute__((overloadable)) log10(float2);
-extern float3 __attribute__((overloadable)) log10(float3);
-extern float4 __attribute__((overloadable)) log10(float4);
-extern float8 __attribute__((overloadable)) log10(float8);
-extern float16 __attribute__((overloadable)) log10(float16);
-
-extern float __attribute__((overloadable)) max(float, float);
-extern float2 __attribute__((overloadable)) max(float2, float2);
-extern float3 __attribute__((overloadable)) max(float3, float3);
-extern float4 __attribute__((overloadable)) max(float4, float4);
-extern float8 __attribute__((overloadable)) max(float8, float8);
-extern float16 __attribute__((overloadable)) max(float16, float16);
-
-extern float __attribute__((overloadable)) min(float, float);
-extern float2 __attribute__((overloadable)) min(float2, float2);
-extern float3 __attribute__((overloadable)) min(float3, float3);
-extern float4 __attribute__((overloadable)) min(float4, float4);
-extern float8 __attribute__((overloadable)) min(float8, float8);
-extern float16 __attribute__((overloadable)) min(float16, float16);
-
-extern float __attribute__((overloadable)) mix(float, float, float);
-extern float2 __attribute__((overloadable)) mix(float2, float2, float2);
-extern float3 __attribute__((overloadable)) mix(float3, float3, float3);
-extern float4 __attribute__((overloadable)) mix(float4, float4, float4);
-extern float8 __attribute__((overloadable)) mix(float8, float8, float8);
-extern float16 __attribute__((overloadable)) mix(float16, float16, float16);
-extern float __attribute__((overloadable)) mix(float, float, float);
-extern float2 __attribute__((overloadable)) mix(float2, float2, float);
-extern float3 __attribute__((overloadable)) mix(float3, float3, float);
-extern float4 __attribute__((overloadable)) mix(float4, float4, float);
-extern float8 __attribute__((overloadable)) mix(float8, float8, float);
-extern float16 __attribute__((overloadable)) mix(float16, float16, float);
-
-extern float __attribute__((overloadable)) pow(float, float);
-extern float2 __attribute__((overloadable)) pow(float2, float2);
-extern float3 __attribute__((overloadable)) pow(float3, float3);
-extern float4 __attribute__((overloadable)) pow(float4, float4);
-extern float8 __attribute__((overloadable)) pow(float8, float8);
-extern float16 __attribute__((overloadable)) pow(float16, float16);
-
-extern float __attribute__((overloadable)) radians(float);
-extern float2 __attribute__((overloadable)) radians(float2);
-extern float3 __attribute__((overloadable)) radians(float3);
-extern float4 __attribute__((overloadable)) radians(float4);
-extern float8 __attribute__((overloadable)) radians(float8);
-extern float16 __attribute__((overloadable)) radians(float16);
-
-extern float __attribute__((overloadable)) rint(float);
-extern float2 __attribute__((overloadable)) rint(float2);
-extern float3 __attribute__((overloadable)) rint(float3);
-extern float4 __attribute__((overloadable)) rint(float4);
-extern float8 __attribute__((overloadable)) rint(float8);
-extern float16 __attribute__((overloadable)) rint(float16);
-
-extern float __attribute__((overloadable)) round(float);
-extern float2 __attribute__((overloadable)) round(float2);
-extern float3 __attribute__((overloadable)) round(float3);
-extern float4 __attribute__((overloadable)) round(float4);
-extern float8 __attribute__((overloadable)) round(float8);
-extern float16 __attribute__((overloadable)) round(float16);
-
-extern float __attribute__((overloadable)) rsqrt(float);
-extern float2 __attribute__((overloadable)) rsqrt(float2);
-extern float3 __attribute__((overloadable)) rsqrt(float3);
-extern float4 __attribute__((overloadable)) rsqrt(float4);
-extern float8 __attribute__((overloadable)) rsqrt(float8);
-extern float16 __attribute__((overloadable)) rsqrt(float16);
-
-extern float __attribute__((overloadable)) sign(float);
-extern float2 __attribute__((overloadable)) sign(float2);
-extern float3 __attribute__((overloadable)) sign(float3);
-extern float4 __attribute__((overloadable)) sign(float4);
-extern float8 __attribute__((overloadable)) sign(float8);
-extern float16 __attribute__((overloadable)) sign(float16);
-
-extern float __attribute__((overloadable)) sin(float);
-extern float2 __attribute__((overloadable)) sin(float2);
-extern float3 __attribute__((overloadable)) sin(float3);
-extern float4 __attribute__((overloadable)) sin(float4);
-extern float8 __attribute__((overloadable)) sin(float8);
-extern float16 __attribute__((overloadable)) sin(float16);
-
-extern float __attribute__((overloadable)) sqrt(float);
-extern float2 __attribute__((overloadable)) sqrt(float2);
-extern float3 __attribute__((overloadable)) sqrt(float3);
-extern float4 __attribute__((overloadable)) sqrt(float4);
-extern float8 __attribute__((overloadable)) sqrt(float8);
-extern float16 __attribute__((overloadable)) sqrt(float16);
-
-extern float __attribute__((overloadable)) tan(float);
-extern float2 __attribute__((overloadable)) tan(float2);
-extern float3 __attribute__((overloadable)) tan(float3);
-extern float4 __attribute__((overloadable)) tan(float4);
-extern float8 __attribute__((overloadable)) tan(float8);
-extern float16 __attribute__((overloadable)) tan(float16);
-
-extern float __attribute__((overloadable)) trunc(float);
-extern float2 __attribute__((overloadable)) trunc(float2);
-extern float3 __attribute__((overloadable)) trunc(float3);
-extern float4 __attribute__((overloadable)) trunc(float4);
-extern float8 __attribute__((overloadable)) trunc(float8);
-extern float16 __attribute__((overloadable)) trunc(float16);
-
-
-
-
-
-
-// Int ops
-
-extern int __attribute__((overloadable)) abs(int);
-extern int2 __attribute__((overloadable)) abs(int2);
-extern int3 __attribute__((overloadable)) abs(int3);
-extern int4 __attribute__((overloadable)) abs(int4);
-extern int8 __attribute__((overloadable)) abs(int8);
-extern int16 __attribute__((overloadable)) abs(int16);
-
-
-
-/*
-extern float modf(float, float);
-extern float randf(float);
-extern float randf2(float, float);
-extern float fracf(float);
-extern float lerpf(float, float, float);
-extern float mapf(float, float, float, float, float);
-*/
-
+#ifndef __RS_MATH_RSH__
+#define __RS_MATH_RSH__
+
+// Debugging, print to the LOG a description string and a value.
+extern void __attribute__((overloadable))
+ rsDebug(const char *, float);
+extern void __attribute__((overloadable))
+ rsDebug(const char *, float, float);
+extern void __attribute__((overloadable))
+ rsDebug(const char *, float, float, float);
+extern void __attribute__((overloadable))
+ rsDebug(const char *, float, float, float, float);
+extern void __attribute__((overloadable))
+ rsDebug(const char *, const rs_matrix4x4 *);
+extern void __attribute__((overloadable))
+ rsDebug(const char *, const rs_matrix3x3 *);
+extern void __attribute__((overloadable))
+ rsDebug(const char *, const rs_matrix2x2 *);
+extern void __attribute__((overloadable))
+ rsDebug(const char *, int);
+extern void __attribute__((overloadable))
+ rsDebug(const char *, uint);
+extern void __attribute__((overloadable))
+ rsDebug(const char *, const void *);
+#define RS_DEBUG(a) rsDebug(#a, a)
+#define RS_DEBUG_MARKER rsDebug(__FILE__, __LINE__)
+
+
+#include "rs_cl.rsh"
+#include "rs_core.rsh"
+
+extern void __attribute__((overloadable))
+ rsSetObject(rs_element *dst, rs_element src);
+extern void __attribute__((overloadable))
+ rsSetObject(rs_type *dst, rs_type src);
+extern void __attribute__((overloadable))
+ rsSetObject(rs_allocation *dst, rs_allocation src);
+extern void __attribute__((overloadable))
+ rsSetObject(rs_sampler *dst, rs_sampler src);
+extern void __attribute__((overloadable))
+ rsSetObject(rs_script *dst, rs_script src);
+extern void __attribute__((overloadable))
+ rsSetObject(rs_mesh *dst, rs_mesh src);
+extern void __attribute__((overloadable))
+ rsSetObject(rs_program_fragment *dst, rs_program_fragment src);
+extern void __attribute__((overloadable))
+ rsSetObject(rs_program_vertex *dst, rs_program_vertex src);
+extern void __attribute__((overloadable))
+ rsSetObject(rs_program_raster *dst, rs_program_raster src);
+extern void __attribute__((overloadable))
+ rsSetObject(rs_program_store *dst, rs_program_store src);
+extern void __attribute__((overloadable))
+ rsSetObject(rs_font *dst, rs_font src);
+
+extern void __attribute__((overloadable))
+ rsClearObject(rs_element *dst);
+extern void __attribute__((overloadable))
+ rsClearObject(rs_type *dst);
+extern void __attribute__((overloadable))
+ rsClearObject(rs_allocation *dst);
+extern void __attribute__((overloadable))
+ rsClearObject(rs_sampler *dst);
+extern void __attribute__((overloadable))
+ rsClearObject(rs_script *dst);
+extern void __attribute__((overloadable))
+ rsClearObject(rs_mesh *dst);
+extern void __attribute__((overloadable))
+ rsClearObject(rs_program_fragment *dst);
+extern void __attribute__((overloadable))
+ rsClearObject(rs_program_vertex *dst);
+extern void __attribute__((overloadable))
+ rsClearObject(rs_program_raster *dst);
+extern void __attribute__((overloadable))
+ rsClearObject(rs_program_store *dst);
+extern void __attribute__((overloadable))
+ rsClearObject(rs_font *dst);
+
+extern bool __attribute__((overloadable))
+ rsIsObject(rs_element);
+extern bool __attribute__((overloadable))
+ rsIsObject(rs_type);
+extern bool __attribute__((overloadable))
+ rsIsObject(rs_allocation);
+extern bool __attribute__((overloadable))
+ rsIsObject(rs_sampler);
+extern bool __attribute__((overloadable))
+ rsIsObject(rs_script);
+extern bool __attribute__((overloadable))
+ rsIsObject(rs_mesh);
+extern bool __attribute__((overloadable))
+ rsIsObject(rs_program_fragment);
+extern bool __attribute__((overloadable))
+ rsIsObject(rs_program_vertex);
+extern bool __attribute__((overloadable))
+ rsIsObject(rs_program_raster);
+extern bool __attribute__((overloadable))
+ rsIsObject(rs_program_store);
+extern bool __attribute__((overloadable))
+ rsIsObject(rs_font);
+
+
+
+// Allocations
+
+// Return the rs_allocation associated with a bound data
+// pointer.
+extern rs_allocation __attribute__((overloadable))
+ rsGetAllocation(const void *);
+
+// Return the dimensions associated with an allocation.
+extern uint32_t __attribute__((overloadable))
+ rsAllocationGetDimX(rs_allocation);
+extern uint32_t __attribute__((overloadable))
+ rsAllocationGetDimY(rs_allocation);
+extern uint32_t __attribute__((overloadable))
+ rsAllocationGetDimZ(rs_allocation);
+extern uint32_t __attribute__((overloadable))
+ rsAllocationGetDimLOD(rs_allocation);
+extern uint32_t __attribute__((overloadable))
+ rsAllocationGetDimFaces(rs_allocation);
+
+// Extract a single element from an allocation.
+extern const void * __attribute__((overloadable))
+ rsGetElementAt(rs_allocation, uint32_t x);
+extern const void * __attribute__((overloadable))
+ rsGetElementAt(rs_allocation, uint32_t x, uint32_t y);
+extern const void * __attribute__((overloadable))
+ rsGetElementAt(rs_allocation, uint32_t x, uint32_t y, uint32_t z);
+
+// Return a random value between 0 (or min_value) and max_malue.
+extern int __attribute__((overloadable))
+ rsRand(int max_value);
+extern int __attribute__((overloadable))
+ rsRand(int min_value, int max_value);
+extern float __attribute__((overloadable))
+ rsRand(float max_value);
+extern float __attribute__((overloadable))
+ rsRand(float min_value, float max_value);
+
+// return the fractional part of a float
+// min(v - ((int)floor(v)), 0x1.fffffep-1f);
+extern float __attribute__((overloadable))
+ rsFrac(float);
+
+// time
+extern int32_t __attribute__((overloadable))
+ rsSecond(void);
+extern int32_t __attribute__((overloadable))
+ rsMinute(void);
+extern int32_t __attribute__((overloadable))
+ rsHour(void);
+extern int32_t __attribute__((overloadable))
+ rsDay(void);
+extern int32_t __attribute__((overloadable))
+ rsMonth(void);
+extern int32_t __attribute__((overloadable))
+ rsYear(void);
+
+// Return the current system clock in milliseconds
+extern int64_t __attribute__((overloadable))
+ rsUptimeMillis(void);
+
+// Return the current system clock in nanoseconds
+extern int64_t __attribute__((overloadable))
+ rsUptimeNanos(void);
+
+// Return the time in seconds since function was last called in this script.
+extern float __attribute__((overloadable))
+ rsGetDt(void);
+
+// Send a message back to the client. Will not block and returns true
+// if the message was sendable and false if the fifo was full.
+// A message ID is required. Data payload is optional.
+extern bool __attribute__((overloadable))
+ rsSendToClient(int cmdID);
+extern bool __attribute__((overloadable))
+ rsSendToClient(int cmdID, const void *data, uint len);
+
+// Send a message back to the client, blocking until the message is queued.
+// A message ID is required. Data payload is optional.
+extern void __attribute__((overloadable))
+ rsSendToClientBlocking(int cmdID);
+extern void __attribute__((overloadable))
+ rsSendToClientBlocking(int cmdID, const void *data, uint len);
+
+
+// Script to Script
+enum rs_for_each_strategy {
+ RS_FOR_EACH_STRATEGY_SERIAL,
+ RS_FOR_EACH_STRATEGY_DONT_CARE,
+ RS_FOR_EACH_STRATEGY_DST_LINEAR,
+ RS_FOR_EACH_STRATEGY_TILE_SMALL,
+ RS_FOR_EACH_STRATEGY_TILE_MEDIUM,
+ RS_FOR_EACH_STRATEGY_TILE_LARGE
+};
+
+typedef struct rs_script_call {
+ enum rs_for_each_strategy strategy;
+ uint32_t xStart;
+ uint32_t xEnd;
+ uint32_t yStart;
+ uint32_t yEnd;
+ uint32_t zStart;
+ uint32_t zEnd;
+ uint32_t arrayStart;
+ uint32_t arrayEnd;
+} rs_script_call_t;
+
+extern void __attribute__((overloadable))
+ rsForEach(rs_script script, rs_allocation input,
+ rs_allocation output, const void * usrData);
+
+extern void __attribute__((overloadable))
+ rsForEach(rs_script script, rs_allocation input,
+ rs_allocation output, const void * usrData,
+ const rs_script_call_t *);
+
+#endif
diff --git a/libs/rs/scriptc/rs_types.rsh b/libs/rs/scriptc/rs_types.rsh
index 4198a74..dd42972 100644
--- a/libs/rs/scriptc/rs_types.rsh
+++ b/libs/rs/scriptc/rs_types.rsh
@@ -2,70 +2,73 @@
typedef char int8_t;
typedef short int16_t;
typedef int int32_t;
-//typedef long int64_t;
+typedef long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
-//typedef long uint64_t;
+typedef unsigned long long uint64_t;
typedef uint8_t uchar;
typedef uint16_t ushort;
typedef uint32_t uint;
-//typedef uint64_t ulong;
-
-typedef int rs_element;
-typedef int rs_type;
-typedef int rs_allocation;
-typedef int rs_sampler;
-typedef int rs_script;
-typedef int rs_mesh;
-typedef int rs_program_fragment;
-typedef int rs_program_vertex;
-typedef int rs_program_raster;
-typedef int rs_program_store;
+typedef uint64_t ulong;
+
+typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_element;
+typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_type;
+typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_allocation;
+typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_sampler;
+typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_script;
+typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_mesh;
+typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_fragment;
+typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_vertex;
+typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_raster;
+typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_store;
+typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_font;
+
typedef float float2 __attribute__((ext_vector_type(2)));
typedef float float3 __attribute__((ext_vector_type(3)));
typedef float float4 __attribute__((ext_vector_type(4)));
-typedef float float8 __attribute__((ext_vector_type(8)));
-typedef float float16 __attribute__((ext_vector_type(16)));
typedef uchar uchar2 __attribute__((ext_vector_type(2)));
typedef uchar uchar3 __attribute__((ext_vector_type(3)));
typedef uchar uchar4 __attribute__((ext_vector_type(4)));
-typedef uchar uchar8 __attribute__((ext_vector_type(8)));
-typedef uchar uchar16 __attribute__((ext_vector_type(16)));
typedef ushort ushort2 __attribute__((ext_vector_type(2)));
typedef ushort ushort3 __attribute__((ext_vector_type(3)));
typedef ushort ushort4 __attribute__((ext_vector_type(4)));
-typedef ushort ushort8 __attribute__((ext_vector_type(8)));
-typedef ushort ushort16 __attribute__((ext_vector_type(16)));
typedef uint uint2 __attribute__((ext_vector_type(2)));
typedef uint uint3 __attribute__((ext_vector_type(3)));
typedef uint uint4 __attribute__((ext_vector_type(4)));
-typedef uint uint8 __attribute__((ext_vector_type(8)));
-typedef uint uint16 __attribute__((ext_vector_type(16)));
typedef char char2 __attribute__((ext_vector_type(2)));
typedef char char3 __attribute__((ext_vector_type(3)));
typedef char char4 __attribute__((ext_vector_type(4)));
-typedef char char8 __attribute__((ext_vector_type(8)));
-typedef char char16 __attribute__((ext_vector_type(16)));
typedef short short2 __attribute__((ext_vector_type(2)));
typedef short short3 __attribute__((ext_vector_type(3)));
typedef short short4 __attribute__((ext_vector_type(4)));
-typedef short short8 __attribute__((ext_vector_type(8)));
-typedef short short16 __attribute__((ext_vector_type(16)));
typedef int int2 __attribute__((ext_vector_type(2)));
typedef int int3 __attribute__((ext_vector_type(3)));
typedef int int4 __attribute__((ext_vector_type(4)));
-typedef int int8 __attribute__((ext_vector_type(8)));
-typedef int int16 __attribute__((ext_vector_type(16)));
+typedef struct {
+ float m[16];
+} rs_matrix4x4;
+
+typedef struct {
+ float m[9];
+} rs_matrix3x3;
+
+typedef struct {
+ float m[4];
+} rs_matrix2x2;
+
+typedef float4 rs_quaternion;
+
+#define RS_PACKED __attribute__((packed, aligned(4)))