| #ifndef __RS_CORE_RSH__ |
| #define __RS_CORE_RSH__ |
| |
| #ifdef BCC_PREPARE_BC |
| #define _RS_STATIC extern |
| #else |
| #define _RS_STATIC static |
| #endif |
| |
| // 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 *, double); |
| 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 *, long); |
| extern void __attribute__((overloadable)) |
| rsDebug(const char *, unsigned long); |
| extern void __attribute__((overloadable)) |
| rsDebug(const char *, long long); |
| extern void __attribute__((overloadable)) |
| rsDebug(const char *, unsigned long long); |
| extern void __attribute__((overloadable)) |
| rsDebug(const char *, const void *); |
| #define RS_DEBUG(a) rsDebug(#a, a) |
| #define RS_DEBUG_MARKER rsDebug(__FILE__, __LINE__) |
| |
| _RS_STATIC void __attribute__((overloadable)) rsDebug(const char *s, float2 v) { |
| rsDebug(s, v.x, v.y); |
| } |
| _RS_STATIC void __attribute__((overloadable)) rsDebug(const char *s, float3 v) { |
| rsDebug(s, v.x, v.y, v.z); |
| } |
| _RS_STATIC void __attribute__((overloadable)) rsDebug(const char *s, float4 v) { |
| rsDebug(s, v.x, v.y, v.z, v.w); |
| } |
| |
| _RS_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; |
| } |
| |
| _RS_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; |
| } |
| |
| _RS_STATIC uchar4 __attribute__((overloadable)) rsPackColorTo8888(float3 color) |
| { |
| color *= 255.f; |
| uchar4 c = {color.x, color.y, color.z, 255}; |
| return c; |
| } |
| |
| _RS_STATIC uchar4 __attribute__((overloadable)) rsPackColorTo8888(float4 color) |
| { |
| color *= 255.f; |
| uchar4 c = {color.x, color.y, color.z, color.w}; |
| return c; |
| } |
| |
| _RS_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 |
| ///////////////////////////////////////////////////// |
| |
| _RS_STATIC void __attribute__((overloadable)) |
| rsMatrixSet(rs_matrix4x4 *m, uint32_t row, uint32_t col, float v) { |
| m->m[row * 4 + col] = v; |
| } |
| |
| _RS_STATIC float __attribute__((overloadable)) |
| rsMatrixGet(const rs_matrix4x4 *m, uint32_t row, uint32_t col) { |
| return m->m[row * 4 + col]; |
| } |
| |
| _RS_STATIC void __attribute__((overloadable)) |
| rsMatrixSet(rs_matrix3x3 *m, uint32_t row, uint32_t col, float v) { |
| m->m[row * 3 + col] = v; |
| } |
| |
| _RS_STATIC float __attribute__((overloadable)) |
| rsMatrixGet(const rs_matrix3x3 *m, uint32_t row, uint32_t col) { |
| return m->m[row * 3 + col]; |
| } |
| |
| _RS_STATIC void __attribute__((overloadable)) |
| rsMatrixSet(rs_matrix2x2 *m, uint32_t row, uint32_t col, float v) { |
| m->m[row * 2 + col] = v; |
| } |
| |
| _RS_STATIC float __attribute__((overloadable)) |
| rsMatrixGet(const rs_matrix2x2 *m, uint32_t row, uint32_t col) { |
| return m->m[row * 2 + col]; |
| } |
| |
| extern void __attribute__((overloadable)) rsMatrixLoadIdentity(rs_matrix4x4 *m); |
| extern void __attribute__((overloadable)) rsMatrixLoadIdentity(rs_matrix3x3 *m); |
| extern void __attribute__((overloadable)) rsMatrixLoadIdentity(rs_matrix2x2 *m); |
| extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix4x4 *m, const float *v); |
| extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix3x3 *m, const float *v); |
| extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix2x2 *m, const float *v); |
| extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix4x4 *m, const rs_matrix4x4 *v); |
| extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix4x4 *m, const rs_matrix3x3 *v); |
| extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix4x4 *m, const rs_matrix2x2 *v); |
| extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix3x3 *m, const rs_matrix3x3 *v); |
| extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix2x2 *m, const rs_matrix2x2 *v); |
| |
| extern void __attribute__((overloadable)) |
| rsMatrixLoadRotate(rs_matrix4x4 *m, float rot, float x, float y, float z); |
| |
| extern void __attribute__((overloadable)) |
| rsMatrixLoadScale(rs_matrix4x4 *m, float x, float y, float z); |
| |
| extern void __attribute__((overloadable)) |
| rsMatrixLoadTranslate(rs_matrix4x4 *m, float x, float y, float z); |
| |
| extern void __attribute__((overloadable)) |
| rsMatrixLoadMultiply(rs_matrix4x4 *m, const rs_matrix4x4 *lhs, const rs_matrix4x4 *rhs); |
| |
| extern void __attribute__((overloadable)) |
| rsMatrixMultiply(rs_matrix4x4 *m, const rs_matrix4x4 *rhs); |
| |
| extern void __attribute__((overloadable)) |
| rsMatrixLoadMultiply(rs_matrix3x3 *m, const rs_matrix3x3 *lhs, const rs_matrix3x3 *rhs); |
| |
| extern void __attribute__((overloadable)) |
| rsMatrixMultiply(rs_matrix3x3 *m, const rs_matrix3x3 *rhs); |
| |
| extern void __attribute__((overloadable)) |
| rsMatrixLoadMultiply(rs_matrix2x2 *m, const rs_matrix2x2 *lhs, const rs_matrix2x2 *rhs); |
| |
| extern void __attribute__((overloadable)) |
| rsMatrixMultiply(rs_matrix2x2 *m, const rs_matrix2x2 *rhs); |
| |
| extern void __attribute__((overloadable)) |
| rsMatrixRotate(rs_matrix4x4 *m, float rot, float x, float y, float z); |
| |
| extern void __attribute__((overloadable)) |
| rsMatrixScale(rs_matrix4x4 *m, float x, float y, float z); |
| |
| extern void __attribute__((overloadable)) |
| rsMatrixTranslate(rs_matrix4x4 *m, float x, float y, float z); |
| |
| extern void __attribute__((overloadable)) |
| rsMatrixLoadOrtho(rs_matrix4x4 *m, float left, float right, float bottom, float top, float near, float far); |
| |
| extern void __attribute__((overloadable)) |
| rsMatrixLoadFrustum(rs_matrix4x4 *m, float left, float right, float bottom, float top, float near, float far); |
| |
| extern void __attribute__((overloadable)) |
| rsMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far); |
| |
| _RS_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; |
| } |
| |
| _RS_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; |
| } |
| |
| _RS_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; |
| } |
| |
| _RS_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; |
| } |
| |
| _RS_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; |
| } |
| |
| _RS_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 |
| extern bool __attribute__((overloadable)) rsMatrixInverse(rs_matrix4x4 *m); |
| extern bool __attribute__((overloadable)) rsMatrixInverseTranspose(rs_matrix4x4 *m); |
| extern void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix4x4 *m); |
| extern void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix3x3 *m); |
| extern void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix2x2 *m); |
| |
| ///////////////////////////////////////////////////// |
| // int ops |
| ///////////////////////////////////////////////////// |
| |
| __inline__ _RS_STATIC uint __attribute__((overloadable, always_inline)) rsClamp(uint amount, uint low, uint high) { |
| return amount < low ? low : (amount > high ? high : amount); |
| } |
| __inline__ _RS_STATIC int __attribute__((overloadable, always_inline)) rsClamp(int amount, int low, int high) { |
| return amount < low ? low : (amount > high ? high : amount); |
| } |
| __inline__ _RS_STATIC ushort __attribute__((overloadable, always_inline)) rsClamp(ushort amount, ushort low, ushort high) { |
| return amount < low ? low : (amount > high ? high : amount); |
| } |
| __inline__ _RS_STATIC short __attribute__((overloadable, always_inline)) rsClamp(short amount, short low, short high) { |
| return amount < low ? low : (amount > high ? high : amount); |
| } |
| __inline__ _RS_STATIC uchar __attribute__((overloadable, always_inline)) rsClamp(uchar amount, uchar low, uchar high) { |
| return amount < low ? low : (amount > high ? high : amount); |
| } |
| __inline__ _RS_STATIC char __attribute__((overloadable, always_inline)) rsClamp(char amount, char low, char high) { |
| return amount < low ? low : (amount > high ? high : amount); |
| } |
| |
| #undef _RS_STATIC |
| |
| #endif |
| |