15a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#include "rs_core.rsh" 25a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#include "rs_structs.h" 35a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 45a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/* Function declarations from libRS */ 55a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) convert_float4(uchar4 c); 65a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 75a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/* Implementation of Core Runtime */ 85a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 95a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines///////////////////////////////////////////////////// 115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// Matrix ops 125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines///////////////////////////////////////////////////// 135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 165a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixLoadIdentity(rs_matrix4x4 *m) { 175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[0] = 1.f; 185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[1] = 0.f; 195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[2] = 0.f; 205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[3] = 0.f; 215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[4] = 0.f; 225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[5] = 1.f; 235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[6] = 0.f; 245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[7] = 0.f; 255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[8] = 0.f; 265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[9] = 0.f; 275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[10] = 1.f; 285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[11] = 0.f; 295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[12] = 0.f; 305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[13] = 0.f; 315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[14] = 0.f; 325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[15] = 1.f; 335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 365a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixLoadIdentity(rs_matrix3x3 *m) { 375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[0] = 1.f; 385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[1] = 0.f; 395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[2] = 0.f; 405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[3] = 0.f; 415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[4] = 1.f; 425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[5] = 0.f; 435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[6] = 0.f; 445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[7] = 0.f; 455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[8] = 1.f; 465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 485a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixLoadIdentity(rs_matrix2x2 *m) { 495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[0] = 1.f; 505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[1] = 0.f; 515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[2] = 0.f; 525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[3] = 1.f; 535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 565a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixLoad(rs_matrix4x4 *m, const float *f) { 575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[0] = f[0]; 585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[1] = f[1]; 595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[2] = f[2]; 605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[3] = f[3]; 615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[4] = f[4]; 625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[5] = f[5]; 635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[6] = f[6]; 645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[7] = f[7]; 655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[8] = f[8]; 665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[9] = f[9]; 675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[10] = f[10]; 685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[11] = f[11]; 695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[12] = f[12]; 705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[13] = f[13]; 715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[14] = f[14]; 725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[15] = f[15]; 735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 755a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixLoad(rs_matrix3x3 *m, const float *f) { 765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[0] = f[0]; 775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[1] = f[1]; 785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[2] = f[2]; 795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[3] = f[3]; 805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[4] = f[4]; 815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[5] = f[5]; 825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[6] = f[6]; 835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[7] = f[7]; 845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[8] = f[8]; 855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 875a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixLoad(rs_matrix2x2 *m, const float *f) { 885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[0] = f[0]; 895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[1] = f[1]; 905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[2] = f[2]; 915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[3] = f[3]; 925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 955a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixLoad(rs_matrix4x4 *m, const rs_matrix4x4 *s) { 965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[0] = s->m[0]; 975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[1] = s->m[1]; 985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[2] = s->m[2]; 995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[3] = s->m[3]; 1005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[4] = s->m[4]; 1015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[5] = s->m[5]; 1025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[6] = s->m[6]; 1035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[7] = s->m[7]; 1045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[8] = s->m[8]; 1055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[9] = s->m[9]; 1065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[10] = s->m[10]; 1075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[11] = s->m[11]; 1085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[12] = s->m[12]; 1095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[13] = s->m[13]; 1105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[14] = s->m[14]; 1115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[15] = s->m[15]; 1125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 1145a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixLoad(rs_matrix4x4 *m, const rs_matrix3x3 *v) { 1155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[0] = v->m[0]; 1165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[1] = v->m[1]; 1175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[2] = v->m[2]; 1185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[3] = 0.f; 1195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[4] = v->m[3]; 1205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[5] = v->m[4]; 1215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[6] = v->m[5]; 1225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[7] = 0.f; 1235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[8] = v->m[6]; 1245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[9] = v->m[7]; 1255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[10] = v->m[8]; 1265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[11] = 0.f; 1275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[12] = 0.f; 1285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[13] = 0.f; 1295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[14] = 0.f; 1305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[15] = 1.f; 1315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 1335a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixLoad(rs_matrix4x4 *m, const rs_matrix2x2 *v) { 1345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[0] = v->m[0]; 1355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[1] = v->m[1]; 1365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[2] = 0.f; 1375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[3] = 0.f; 1385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[4] = v->m[2]; 1395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[5] = v->m[3]; 1405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[6] = 0.f; 1415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[7] = 0.f; 1425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[8] = 0.f; 1435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[9] = 0.f; 1445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[10] = 1.f; 1455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[11] = 0.f; 1465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[12] = 0.f; 1475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[13] = 0.f; 1485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[14] = 0.f; 1495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[15] = 1.f; 1505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 1525a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixLoad(rs_matrix3x3 *m, const rs_matrix3x3 *s) { 1535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[0] = s->m[0]; 1545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[1] = s->m[1]; 1555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[2] = s->m[2]; 1565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[3] = s->m[3]; 1575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[4] = s->m[4]; 1585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[5] = s->m[5]; 1595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[6] = s->m[6]; 1605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[7] = s->m[7]; 1615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[8] = s->m[8]; 1625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 1645a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixLoad(rs_matrix2x2 *m, const rs_matrix2x2 *s) { 1655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[0] = s->m[0]; 1665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[1] = s->m[1]; 1675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[2] = s->m[2]; 1685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines m->m[3] = s->m[3]; 1695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 1731bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc BrouilletrsMatrixSet(rs_matrix4x4 *m, uint32_t col, uint32_t row, float v) { 1741bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet m->m[col * 4 + row] = v; 1755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) 1781bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc BrouilletrsMatrixGet(const rs_matrix4x4 *m, uint32_t col, uint32_t row) { 1791bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet return m->m[col * 4 + row]; 1805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 1831bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc BrouilletrsMatrixSet(rs_matrix3x3 *m, uint32_t col, uint32_t row, float v) { 1841bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet m->m[col * 3 + row] = v; 1855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) 1881bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc BrouilletrsMatrixGet(const rs_matrix3x3 *m, uint32_t col, uint32_t row) { 1891bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet return m->m[col * 3 + row]; 1905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 1931bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc BrouilletrsMatrixSet(rs_matrix2x2 *m, uint32_t col, uint32_t row, float v) { 1941bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet m->m[col * 2 + row] = v; 1955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) 1981bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc BrouilletrsMatrixGet(const rs_matrix2x2 *m, uint32_t col, uint32_t row) { 1991bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet return m->m[col * 2 + row]; 2005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) 2035a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixMultiply(const rs_matrix2x2 *m, float2 in) { 2045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 ret; 2055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ret.x = (m->m[0] * in.x) + (m->m[2] * in.y); 2065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ret.y = (m->m[1] * in.x) + (m->m[3] * in.y); 2075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return ret; 2085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) 2105a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixMultiply(rs_matrix2x2 *m, float2 in) { 2115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return rsMatrixMultiply((const rs_matrix2x2 *)m, in); 2125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) 2155a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixMultiply(rs_matrix4x4 *m, float4 in) { 2165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return rsMatrixMultiply((const rs_matrix4x4 *)m, in); 2175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) 2205a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixMultiply(rs_matrix4x4 *m, float3 in) { 2215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return rsMatrixMultiply((const rs_matrix4x4 *)m, in); 2225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) 2255a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixMultiply(rs_matrix4x4 *m, float2 in) { 2265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return rsMatrixMultiply((const rs_matrix4x4 *)m, in); 2275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) 2305a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixMultiply(rs_matrix3x3 *m, float3 in) { 2315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return rsMatrixMultiply((const rs_matrix3x3 *)m, in); 2325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) 2355a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixMultiply(rs_matrix3x3 *m, float2 in) { 2365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return rsMatrixMultiply((const rs_matrix3x3 *)m, in); 2375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 2405a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixLoadMultiply(rs_matrix4x4 *ret, const rs_matrix4x4 *lhs, const rs_matrix4x4 *rhs) { 2411bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet // Use a temporary variable to support the case where one of the inputs 2421bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet // is also the destination, e.g. rsMatrixLoadMultiply(&left, &left, &right); 2431bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet rs_matrix4x4 result; 2445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines for (int i=0 ; i<4 ; i++) { 2455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float ri0 = 0; 2465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float ri1 = 0; 2475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float ri2 = 0; 2485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float ri3 = 0; 2495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines for (int j=0 ; j<4 ; j++) { 2505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const float rhs_ij = rsMatrixGet(rhs, i, j); 2515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ri0 += rsMatrixGet(lhs, j, 0) * rhs_ij; 2525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ri1 += rsMatrixGet(lhs, j, 1) * rhs_ij; 2535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ri2 += rsMatrixGet(lhs, j, 2) * rhs_ij; 2545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ri3 += rsMatrixGet(lhs, j, 3) * rhs_ij; 2555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 2561bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet rsMatrixSet(&result, i, 0, ri0); 2571bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet rsMatrixSet(&result, i, 1, ri1); 2581bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet rsMatrixSet(&result, i, 2, ri2); 2591bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet rsMatrixSet(&result, i, 3, ri3); 2605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 2611bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet rsMatrixLoad(ret, &result); 2625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 2655a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixMultiply(rs_matrix4x4 *lhs, const rs_matrix4x4 *rhs) { 2661bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet rsMatrixLoadMultiply(lhs, lhs, rhs); 2675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 2705a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixLoadMultiply(rs_matrix3x3 *ret, const rs_matrix3x3 *lhs, const rs_matrix3x3 *rhs) { 2711bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet // Use a temporary variable to support the case where one of the inputs 2721bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet // is also the destination, e.g. rsMatrixLoadMultiply(&left, &left, &right); 2731bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet rs_matrix3x3 result; 2745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines for (int i=0 ; i<3 ; i++) { 2755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float ri0 = 0; 2765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float ri1 = 0; 2775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float ri2 = 0; 2785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines for (int j=0 ; j<3 ; j++) { 2795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const float rhs_ij = rsMatrixGet(rhs, i, j); 2805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ri0 += rsMatrixGet(lhs, j, 0) * rhs_ij; 2815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ri1 += rsMatrixGet(lhs, j, 1) * rhs_ij; 2825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ri2 += rsMatrixGet(lhs, j, 2) * rhs_ij; 2835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 2841bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet rsMatrixSet(&result, i, 0, ri0); 2851bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet rsMatrixSet(&result, i, 1, ri1); 2861bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet rsMatrixSet(&result, i, 2, ri2); 2875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 2881bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet rsMatrixLoad(ret, &result); 2895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 2925a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixMultiply(rs_matrix3x3 *lhs, const rs_matrix3x3 *rhs) { 2931bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet rsMatrixLoadMultiply(lhs, lhs, rhs); 2945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 2975a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixLoadMultiply(rs_matrix2x2 *ret, const rs_matrix2x2 *lhs, const rs_matrix2x2 *rhs) { 2981bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet // Use a temporary variable to support the case where one of the inputs 2991bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet // is also the destination, e.g. rsMatrixLoadMultiply(&left, &left, &right); 3001bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet rs_matrix2x2 result; 3015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines for (int i=0 ; i<2 ; i++) { 3025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float ri0 = 0; 3035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float ri1 = 0; 3045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines for (int j=0 ; j<2 ; j++) { 3055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const float rhs_ij = rsMatrixGet(rhs, i, j); 3065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ri0 += rsMatrixGet(lhs, j, 0) * rhs_ij; 3075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ri1 += rsMatrixGet(lhs, j, 1) * rhs_ij; 3085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 3091bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet rsMatrixSet(&result, i, 0, ri0); 3101bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet rsMatrixSet(&result, i, 1, ri1); 3115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 3121bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet rsMatrixLoad(ret, &result); 3135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 3165a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesrsMatrixMultiply(rs_matrix2x2 *lhs, const rs_matrix2x2 *rhs) { 3171bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet rsMatrixLoadMultiply(lhs, lhs, rhs); 3185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 320