Add matrix ops to RSH headers.
Change-Id: I7e2843983a12e0155114b4a18813799e4341d26f
This commit is contained in:
@@ -244,7 +244,7 @@ public class FieldPacker {
|
||||
addU32(v.w);
|
||||
}
|
||||
|
||||
public void addBoolean(Boolean v) {
|
||||
public void addBoolean(boolean v) {
|
||||
addI8((byte)(v ? 1 : 0));
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
#include "../../../../scriptc/rs_math.rsh"
|
||||
#include "../../../../scriptc/rs_graphics.rsh"
|
||||
|
||||
#pragma rs java_package_name(com.android.rs.image)
|
||||
|
||||
|
||||
#define MAX_RADIUS 25
|
||||
|
||||
int height;
|
||||
@@ -32,7 +35,7 @@ static float overInWMinInB;
|
||||
|
||||
// Store our coefficients here
|
||||
static float gaussian[MAX_RADIUS * 2 + 1];
|
||||
static float colorMat[4][4];
|
||||
static rs_matrix3x3 colorMat;
|
||||
|
||||
static void computeColorMatrix() {
|
||||
// Saturation
|
||||
@@ -48,17 +51,15 @@ static void computeColorMatrix() {
|
||||
|
||||
float oneMinusS = 1.0f - saturation;
|
||||
|
||||
rsMatrixLoadIdentity((rs_matrix4x4 *)colorMat);
|
||||
|
||||
colorMat[0][0] = oneMinusS * rWeight + saturation;
|
||||
colorMat[0][1] = oneMinusS * rWeight;
|
||||
colorMat[0][2] = oneMinusS * rWeight;
|
||||
colorMat[1][0] = oneMinusS * gWeight;
|
||||
colorMat[1][1] = oneMinusS * gWeight + saturation;
|
||||
colorMat[1][2] = oneMinusS * gWeight;
|
||||
colorMat[2][0] = oneMinusS * bWeight;
|
||||
colorMat[2][1] = oneMinusS * bWeight;
|
||||
colorMat[2][2] = oneMinusS * bWeight + saturation;
|
||||
rsMatrixSet(&colorMat, 0, 0, oneMinusS * rWeight + saturation);
|
||||
rsMatrixSet(&colorMat, 0, 1, oneMinusS * rWeight);
|
||||
rsMatrixSet(&colorMat, 0, 2, oneMinusS * rWeight);
|
||||
rsMatrixSet(&colorMat, 1, 0, oneMinusS * gWeight);
|
||||
rsMatrixSet(&colorMat, 1, 1, oneMinusS * gWeight + saturation);
|
||||
rsMatrixSet(&colorMat, 1, 2, oneMinusS * gWeight);
|
||||
rsMatrixSet(&colorMat, 2, 0, oneMinusS * bWeight);
|
||||
rsMatrixSet(&colorMat, 2, 1, oneMinusS * bWeight);
|
||||
rsMatrixSet(&colorMat, 2, 2, oneMinusS * bWeight + saturation);
|
||||
|
||||
inWMinInB = inWhite - inBlack;
|
||||
outWMinOutB = outWhite - outBlack;
|
||||
@@ -107,48 +108,10 @@ static void computeGaussianWeights() {
|
||||
|
||||
// This needs to be inline
|
||||
static float4 levelsSaturation(float4 currentPixel) {
|
||||
#if 0
|
||||
// Color matrix multiply
|
||||
float tempX = colorMat[0][0] * currentPixel.x + colorMat[1][0] * currentPixel.y + colorMat[2][0] * currentPixel.z;
|
||||
float tempY = colorMat[0][1] * currentPixel.x + colorMat[1][1] * currentPixel.y + colorMat[2][1] * currentPixel.z;
|
||||
float tempZ = colorMat[0][2] * currentPixel.x + colorMat[1][2] * currentPixel.y + colorMat[2][2] * currentPixel.z;
|
||||
|
||||
currentPixel.x = tempX;
|
||||
currentPixel.y = tempY;
|
||||
currentPixel.z = tempZ;
|
||||
|
||||
// Clamp to 0..255
|
||||
// Inline the code here to avoid funciton calls
|
||||
currentPixel.x = currentPixel.x > 255.0f ? 255.0f : currentPixel.x;
|
||||
currentPixel.y = currentPixel.y > 255.0f ? 255.0f : currentPixel.y;
|
||||
currentPixel.z = currentPixel.z > 255.0f ? 255.0f : currentPixel.z;
|
||||
|
||||
currentPixel.x = currentPixel.x <= 0.0f ? 0.1f : currentPixel.x;
|
||||
currentPixel.y = currentPixel.y <= 0.0f ? 0.1f : currentPixel.y;
|
||||
currentPixel.z = currentPixel.z <= 0.0f ? 0.1f : currentPixel.z;
|
||||
|
||||
currentPixel.x = pow( (currentPixel.x - inBlack) * overInWMinInB, gamma) * outWMinOutB + outBlack;
|
||||
currentPixel.y = pow( (currentPixel.y - inBlack) * overInWMinInB, gamma) * outWMinOutB + outBlack;
|
||||
currentPixel.z = pow( (currentPixel.z - inBlack) * overInWMinInB, gamma) * outWMinOutB + outBlack;
|
||||
|
||||
currentPixel.x = currentPixel.x > 255.0f ? 255.0f : currentPixel.x;
|
||||
currentPixel.y = currentPixel.y > 255.0f ? 255.0f : currentPixel.y;
|
||||
currentPixel.z = currentPixel.z > 255.0f ? 255.0f : currentPixel.z;
|
||||
|
||||
currentPixel.x = currentPixel.x <= 0.0f ? 0.1f : currentPixel.x;
|
||||
currentPixel.y = currentPixel.y <= 0.0f ? 0.1f : currentPixel.y;
|
||||
currentPixel.z = currentPixel.z <= 0.0f ? 0.1f : currentPixel.z;
|
||||
#else
|
||||
float3 temp;
|
||||
// Color matrix multiply
|
||||
temp.x = colorMat[0][0] * currentPixel.x + colorMat[1][0] * currentPixel.y + colorMat[2][0] * currentPixel.z;
|
||||
temp.y = colorMat[0][1] * currentPixel.x + colorMat[1][1] * currentPixel.y + colorMat[2][1] * currentPixel.z;
|
||||
temp.z = colorMat[0][2] * currentPixel.x + colorMat[1][2] * currentPixel.y + colorMat[2][2] * currentPixel.z;
|
||||
float3 temp = rsMatrixMultiply(&colorMat, currentPixel.xyz);
|
||||
temp = (clamp(temp, 0.1f, 255.f) - inBlack) * overInWMinInB;
|
||||
temp = pow(temp, (float3)gamma);
|
||||
currentPixel.xyz = clamp(temp * outWMinOutB + outBlack, 0.1f, 255.f);
|
||||
#endif
|
||||
|
||||
return currentPixel;
|
||||
}
|
||||
|
||||
@@ -188,8 +151,10 @@ static void horizontalBlur() {
|
||||
// Horizontal blur
|
||||
int w, h, r;
|
||||
for(h = 0; h < height; h ++) {
|
||||
for(w = 0; w < width; w ++) {
|
||||
uchar4 *input = InPixel + h*width;
|
||||
uchar4 *output = ScratchPixel + h*width;
|
||||
|
||||
for(w = 0; w < width; w ++) {
|
||||
blurredPixel = 0;
|
||||
|
||||
for(r = -radius; r <= radius; r ++) {
|
||||
@@ -202,23 +167,22 @@ static void horizontalBlur() {
|
||||
if(validW > width - 1) {
|
||||
validW = width - 1;
|
||||
}
|
||||
|
||||
uchar4 *input = InPixel + h*width + validW;
|
||||
//int validW = rsClamp(w + r, 0, width - 1);
|
||||
|
||||
float weight = gaussian[r + radius];
|
||||
currentPixel.x = (float)(input->x);
|
||||
currentPixel.y = (float)(input->y);
|
||||
currentPixel.z = (float)(input->z);
|
||||
currentPixel.x = (float)(input[validW].x);
|
||||
currentPixel.y = (float)(input[validW].y);
|
||||
currentPixel.z = (float)(input[validW].z);
|
||||
//currentPixel.w = (float)(input->a);
|
||||
|
||||
blurredPixel += currentPixel*weight;
|
||||
}
|
||||
|
||||
uchar4 *output = ScratchPixel + h*width + w;
|
||||
output->x = (uint8_t)blurredPixel.x;
|
||||
output->y = (uint8_t)blurredPixel.y;
|
||||
output->z = (uint8_t)blurredPixel.z;
|
||||
//output->a = (uint8_t)blurredPixel.w;
|
||||
output++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -229,8 +193,9 @@ static void horizontalBlurLevels() {
|
||||
// Horizontal blur
|
||||
int w, h, r;
|
||||
for(h = 0; h < height; h ++) {
|
||||
for(w = 0; w < width; w ++) {
|
||||
uchar4 *output = OutPixel + h*width;
|
||||
|
||||
for(w = 0; w < width; w ++) {
|
||||
blurredPixel = 0;
|
||||
|
||||
for(r = -radius; r <= radius; r ++) {
|
||||
@@ -243,6 +208,7 @@ static void horizontalBlurLevels() {
|
||||
if(validW > width - 1) {
|
||||
validW = width - 1;
|
||||
}
|
||||
//int validW = rsClamp(w + r, 0, width - 1);
|
||||
|
||||
uchar4 *input = InPixel + h*width + validW;
|
||||
|
||||
@@ -252,16 +218,16 @@ static void horizontalBlurLevels() {
|
||||
currentPixel.z = (float)(input->z);
|
||||
//currentPixel.w = (float)(input->a);
|
||||
|
||||
blurredPixel += currentPixel*weight;
|
||||
blurredPixel.xyz += currentPixel.xyz * weight;
|
||||
}
|
||||
|
||||
blurredPixel = levelsSaturation(blurredPixel);
|
||||
|
||||
uchar4 *output = ScratchPixel + h*width + w;
|
||||
output->x = (uint8_t)blurredPixel.x;
|
||||
output->y = (uint8_t)blurredPixel.y;
|
||||
output->z = (uint8_t)blurredPixel.z;
|
||||
//output->a = (uint8_t)blurredPixel.w;
|
||||
output++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -272,10 +238,13 @@ static void verticalBlur() {
|
||||
// Vertical blur
|
||||
int w, h, r;
|
||||
for(h = 0; h < height; h ++) {
|
||||
uchar4 *output = OutPixel + h*width;
|
||||
|
||||
for(w = 0; w < width; w ++) {
|
||||
|
||||
blurredPixel = 0;
|
||||
for(r = -radius; r <= radius; r ++) {
|
||||
#if 1
|
||||
int validH = h + r;
|
||||
// Clamp to zero and width
|
||||
if(validH < 0) {
|
||||
@@ -292,17 +261,21 @@ static void verticalBlur() {
|
||||
currentPixel.x = (float)(input->x);
|
||||
currentPixel.y = (float)(input->y);
|
||||
currentPixel.z = (float)(input->z);
|
||||
//currentPixel.w = (float)(input->a);
|
||||
|
||||
blurredPixel += currentPixel*weight;
|
||||
blurredPixel.xyz += currentPixel.xyz * weight;
|
||||
#else
|
||||
int validH = rsClamp(h + r, 0, height - 1);
|
||||
uchar4 *input = ScratchPixel + validH*width + w;
|
||||
blurredPixel.xyz += convert_float3(input->xyz) * gaussian[r + radius];
|
||||
#endif
|
||||
}
|
||||
|
||||
uchar4 *output = OutPixel + h*width + w;
|
||||
|
||||
//output->xyz = convert_uchar3(blurredPixel.xyz);
|
||||
output->x = (uint8_t)blurredPixel.x;
|
||||
output->y = (uint8_t)blurredPixel.y;
|
||||
output->z = (uint8_t)blurredPixel.z;
|
||||
//output->a = (uint8_t)blurredPixel.w;
|
||||
output++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -311,12 +284,6 @@ void filter() {
|
||||
RS_DEBUG(height);
|
||||
RS_DEBUG(width);
|
||||
RS_DEBUG(radius);
|
||||
RS_DEBUG(inBlack);
|
||||
RS_DEBUG(outBlack);
|
||||
RS_DEBUG(inWhite);
|
||||
RS_DEBUG(outWhite);
|
||||
RS_DEBUG(gamma);
|
||||
RS_DEBUG(saturation);
|
||||
|
||||
computeColorMatrix();
|
||||
|
||||
|
||||
Binary file not shown.
@@ -32,133 +32,6 @@ using namespace android::renderscript;
|
||||
ScriptC * sc = (ScriptC *) tls->mScript
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Non-Updated code below
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
} vec3_t;
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float w;
|
||||
} vec4_t;
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
} vec2_t;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Vec3 routines
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void SC_vec3Norm(vec3_t *v)
|
||||
{
|
||||
float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
|
||||
len = 1 / len;
|
||||
v->x *= len;
|
||||
v->y *= len;
|
||||
v->z *= len;
|
||||
}
|
||||
|
||||
static float SC_vec3Length(const vec3_t *v)
|
||||
{
|
||||
return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
|
||||
}
|
||||
|
||||
static void SC_vec3Add(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
|
||||
{
|
||||
dest->x = lhs->x + rhs->x;
|
||||
dest->y = lhs->y + rhs->y;
|
||||
dest->z = lhs->z + rhs->z;
|
||||
}
|
||||
|
||||
static void SC_vec3Sub(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
|
||||
{
|
||||
dest->x = lhs->x - rhs->x;
|
||||
dest->y = lhs->y - rhs->y;
|
||||
dest->z = lhs->z - rhs->z;
|
||||
}
|
||||
|
||||
static void SC_vec3Cross(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
|
||||
{
|
||||
float x = lhs->y * rhs->z - lhs->z * rhs->y;
|
||||
float y = lhs->z * rhs->x - lhs->x * rhs->z;
|
||||
float z = lhs->x * rhs->y - lhs->y * rhs->x;
|
||||
dest->x = x;
|
||||
dest->y = y;
|
||||
dest->z = z;
|
||||
}
|
||||
|
||||
static float SC_vec3Dot(const vec3_t *lhs, const vec3_t *rhs)
|
||||
{
|
||||
return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z;
|
||||
}
|
||||
|
||||
static void SC_vec3Scale(vec3_t *lhs, float scale)
|
||||
{
|
||||
lhs->x *= scale;
|
||||
lhs->y *= scale;
|
||||
lhs->z *= scale;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Vec4 routines
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void SC_vec4Norm(vec4_t *v)
|
||||
{
|
||||
float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w);
|
||||
len = 1 / len;
|
||||
v->x *= len;
|
||||
v->y *= len;
|
||||
v->z *= len;
|
||||
v->w *= len;
|
||||
}
|
||||
|
||||
static float SC_vec4Length(const vec4_t *v)
|
||||
{
|
||||
return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w);
|
||||
}
|
||||
|
||||
static void SC_vec4Add(vec4_t *dest, const vec4_t *lhs, const vec4_t *rhs)
|
||||
{
|
||||
dest->x = lhs->x + rhs->x;
|
||||
dest->y = lhs->y + rhs->y;
|
||||
dest->z = lhs->z + rhs->z;
|
||||
dest->w = lhs->w + rhs->w;
|
||||
}
|
||||
|
||||
static void SC_vec4Sub(vec4_t *dest, const vec4_t *lhs, const vec4_t *rhs)
|
||||
{
|
||||
dest->x = lhs->x - rhs->x;
|
||||
dest->y = lhs->y - rhs->y;
|
||||
dest->z = lhs->z - rhs->z;
|
||||
dest->w = lhs->w - rhs->w;
|
||||
}
|
||||
|
||||
static float SC_vec4Dot(const vec4_t *lhs, const vec4_t *rhs)
|
||||
{
|
||||
return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z + lhs->w * rhs->w;
|
||||
}
|
||||
|
||||
static void SC_vec4Scale(vec4_t *lhs, float scale)
|
||||
{
|
||||
lhs->x *= scale;
|
||||
lhs->y *= scale;
|
||||
lhs->z *= scale;
|
||||
lhs->w *= scale;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Math routines
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
@@ -224,41 +97,6 @@ static int SC_randi2(int min, int max)
|
||||
return (int)SC_randf2(min, max);
|
||||
}
|
||||
|
||||
static int SC_clamp(int amount, int low, int high)
|
||||
{
|
||||
return amount < low ? low : (amount > high ? high : amount);
|
||||
}
|
||||
|
||||
static float SC_roundf(float v)
|
||||
{
|
||||
return floorf(v + 0.4999999999);
|
||||
}
|
||||
|
||||
static float SC_distf2(float x1, float y1, float x2, float y2)
|
||||
{
|
||||
float x = x2 - x1;
|
||||
float y = y2 - y1;
|
||||
return sqrtf(x * x + y * y);
|
||||
}
|
||||
|
||||
static float SC_distf3(float x1, float y1, float z1, float x2, float y2, float z2)
|
||||
{
|
||||
float x = x2 - x1;
|
||||
float y = y2 - y1;
|
||||
float z = z2 - z1;
|
||||
return sqrtf(x * x + y * y + z * z);
|
||||
}
|
||||
|
||||
static float SC_magf2(float a, float b)
|
||||
{
|
||||
return sqrtf(a * a + b * b);
|
||||
}
|
||||
|
||||
static float SC_magf3(float a, float b, float c)
|
||||
{
|
||||
return sqrtf(a * a + b * b + c * c);
|
||||
}
|
||||
|
||||
static float SC_frac(float v)
|
||||
{
|
||||
int i = (int)floor(v);
|
||||
@@ -512,24 +350,6 @@ static void SC_debugI32(const char *s, int32_t i) {
|
||||
LOGE("%s %i 0x%x", s, i, i);
|
||||
}
|
||||
|
||||
static uchar4 SC_convertColorTo8888_f3(float r, float g, float b) {
|
||||
uchar4 t;
|
||||
t.f[0] = (uint8_t)(r * 255.f);
|
||||
t.f[1] = (uint8_t)(g * 255.f);
|
||||
t.f[2] = (uint8_t)(b * 255.f);
|
||||
t.f[3] = 0xff;
|
||||
return t;
|
||||
}
|
||||
|
||||
static uchar4 SC_convertColorTo8888_f4(float r, float g, float b, float a) {
|
||||
uchar4 t;
|
||||
t.f[0] = (uint8_t)(r * 255.f);
|
||||
t.f[1] = (uint8_t)(g * 255.f);
|
||||
t.f[2] = (uint8_t)(b * 255.f);
|
||||
t.f[3] = (uint8_t)(a * 255.f);
|
||||
return t;
|
||||
}
|
||||
|
||||
static uint32_t SC_toClient(void *data, int cmdID, int len, int waitForSpace)
|
||||
{
|
||||
GET_TLS();
|
||||
@@ -640,16 +460,6 @@ static ScriptCState::SymbolTable_t gSyms[] = {
|
||||
{ "rsAllocationGetDimFaces", (void *)&SC_allocGetDimFaces },
|
||||
{ "rsGetAllocation", (void *)&SC_getAllocation },
|
||||
|
||||
// color
|
||||
{ "_Z17rsPackColorTo8888fff", (void *)&SC_convertColorTo8888_f3 },
|
||||
{ "_Z17rsPackColorTo8888ffff", (void *)&SC_convertColorTo8888_f4 },
|
||||
//extern uchar4 __attribute__((overloadable)) rsPackColorTo8888(float3);
|
||||
//extern uchar4 __attribute__((overloadable)) rsPackColorTo8888(float4);
|
||||
//extern float4 rsUnpackColor8888(uchar4);
|
||||
//extern uchar4 __attribute__((overloadable)) rsPackColorTo565(float r, float g, float b);
|
||||
//extern uchar4 __attribute__((overloadable)) rsPackColorTo565(float3);
|
||||
//extern float4 rsUnpackColor565(uchar4);
|
||||
|
||||
// Debug
|
||||
{ "_Z7rsDebugPKcf", (void *)&SC_debugF },
|
||||
{ "_Z7rsDebugPKcDv2_f", (void *)&SC_debugFv2 },
|
||||
@@ -703,12 +513,6 @@ static ScriptCState::SymbolTable_t gSyms[] = {
|
||||
|
||||
//{ "sinf_fast", (void *)&SC_sinf_fast },
|
||||
//{ "cosf_fast", (void *)&SC_cosf_fast },
|
||||
//{ "clamp", (void *)&SC_clamp },
|
||||
//{ "distf2", (void *)&SC_distf2 },
|
||||
//{ "distf3", (void *)&SC_distf3 },
|
||||
//{ "magf2", (void *)&SC_magf2 },
|
||||
//{ "magf3", (void *)&SC_magf3 },
|
||||
//{ "mapf", (void *)&SC_mapf },
|
||||
|
||||
{ "scriptCall", (void *)&SC_scriptCall },
|
||||
|
||||
|
||||
@@ -48,6 +48,457 @@ static float4 rsUnpackColor8888(uchar4 c)
|
||||
//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 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;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// int ops
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
__inline__ static float __attribute__((overloadable, always_inline)) rsClamp(uint amount, uint low, uint high) {
|
||||
return amount < low ? low : (amount > high ? high : amount);
|
||||
}
|
||||
__inline__ static float __attribute__((overloadable, always_inline)) rsClamp(int amount, int low, int high) {
|
||||
return amount < low ? low : (amount > high ? high : amount);
|
||||
}
|
||||
__inline__ static float __attribute__((overloadable, always_inline)) rsClamp(ushort amount, ushort low, ushort high) {
|
||||
return amount < low ? low : (amount > high ? high : amount);
|
||||
}
|
||||
__inline__ static float __attribute__((overloadable, always_inline)) rsClamp(short amount, short low, short high) {
|
||||
return amount < low ? low : (amount > high ? high : amount);
|
||||
}
|
||||
__inline__ static float __attribute__((overloadable, always_inline)) rsClamp(uchar amount, uchar low, uchar high) {
|
||||
return amount < low ? low : (amount > high ? high : amount);
|
||||
}
|
||||
__inline__ static float __attribute__((overloadable, always_inline)) rsClamp(char amount, char low, char high) {
|
||||
return amount < low ? low : (amount > high ? high : amount);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -44,18 +44,6 @@ extern int64_t rsElapsedTimeMillis();
|
||||
|
||||
extern int rsSendToClient(void *data, int cmdID, int len, int waitForSpace);
|
||||
|
||||
extern void rsMatrixLoadIdentity(rs_matrix4x4 *mat);
|
||||
extern void rsMatrixLoadFloat(rs_matrix4x4 *mat, const float *f);
|
||||
extern void rsMatrixLoadMat(rs_matrix4x4 *mat, const rs_matrix4x4 *newmat);
|
||||
extern void rsMatrixLoadRotate(rs_matrix4x4 *mat, float rot, float x, float y, float z);
|
||||
extern void rsMatrixLoadScale(rs_matrix4x4*mat, float x, float y, float z);
|
||||
extern void rsMatrixLoadTranslate(rs_matrix4x4 *mat, float x, float y, float z);
|
||||
extern void rsMatrixLoadMultiply(rs_matrix4x4 *mat, const rs_matrix4x4 *lhs, const rs_matrix4x4 *rhs);
|
||||
extern void rsMatrixMultiply(rs_matrix4x4 *mat, const rs_matrix4x4 *rhs);
|
||||
extern void rsMatrixRotate(rs_matrix4x4 *mat, float rot, float x, float y, float z);
|
||||
extern void rsMatrixScale(rs_matrix4x4 *mat, float x, float y, float z);
|
||||
extern void rsMatrixTranslate(rs_matrix4x4 *mat, float x, float y, float z);
|
||||
|
||||
// Script to Script
|
||||
extern void __attribute__((overloadable))rsForEach(rs_script, rs_allocation input);
|
||||
extern void __attribute__((overloadable))rsForEach(rs_script, rs_allocation input, rs_allocation output);
|
||||
@@ -65,23 +53,3 @@ extern void __attribute__((overloadable))rsForEach(rs_script, rs_allocation inpu
|
||||
extern void __attribute__((overloadable))rsForEach(rs_script, rs_allocation input, rs_allocation output, int xStart, int yStart, int xEnd, int yEnd);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// non update funcs
|
||||
|
||||
/*
|
||||
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);
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@@ -58,5 +58,14 @@ typedef struct {
|
||||
float m[16];
|
||||
} rs_matrix4x4;
|
||||
|
||||
typedef struct {
|
||||
float m[9];
|
||||
} rs_matrix3x3;
|
||||
|
||||
typedef struct {
|
||||
float m[4];
|
||||
} rs_matrix2x2;
|
||||
|
||||
|
||||
#define RS_PACKED __attribute__((packed, aligned(4)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user