1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
/*
* Copyright (C) 2011-2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
#include <cutils/compiler.h>
#endif
#include "rsContext.h"
#include "rsScriptC.h"
#include "rsMatrix4x4.h"
#include "rsMatrix3x3.h"
#include "rsMatrix2x2.h"
#include "rsCpuCore.h"
#include "rsCpuScript.h"
using namespace android;
using namespace android::renderscript;
#define EXPORT_F32_FN_F32(func) \
float __attribute__((overloadable)) SC_##func(float v) { \
return func(v); \
}
#define EXPORT_F32_FN_F32_F32(func) \
float __attribute__((overloadable)) SC_##func(float t, float v) { \
return func(t, v); \
}
//////////////////////////////////////////////////////////////////////////////
// Float util
//////////////////////////////////////////////////////////////////////////////
// Handle missing Gingerbread functions like tgammaf.
float SC_tgammaf(float x) {
#ifdef RS_COMPATIBILITY_LIB
return tgamma(x);
#else
return tgammaf(x);
#endif
}
uint32_t SC_abs_i32(int32_t v) {return abs(v);}
static void SC_MatrixLoadRotate(Matrix4x4 *m, float rot, float x, float y, float z) {
m->loadRotate(rot, x, y, z);
}
static void SC_MatrixLoadScale(Matrix4x4 *m, float x, float y, float z) {
m->loadScale(x, y, z);
}
static void SC_MatrixLoadTranslate(Matrix4x4 *m, float x, float y, float z) {
m->loadTranslate(x, y, z);
}
static void SC_MatrixRotate(Matrix4x4 *m, float rot, float x, float y, float z) {
m->rotate(rot, x, y, z);
}
static void SC_MatrixScale(Matrix4x4 *m, float x, float y, float z) {
m->scale(x, y, z);
}
static void SC_MatrixTranslate(Matrix4x4 *m, float x, float y, float z) {
m->translate(x, y, z);
}
static void SC_MatrixLoadOrtho(Matrix4x4 *m, float l, float r, float b, float t, float n, float f) {
m->loadOrtho(l, r, b, t, n, f);
}
static void SC_MatrixLoadFrustum(Matrix4x4 *m, float l, float r, float b, float t, float n, float f) {
m->loadFrustum(l, r, b, t, n, f);
}
static void SC_MatrixLoadPerspective(Matrix4x4 *m, float fovy, float aspect, float near, float far) {
m->loadPerspective(fovy, aspect, near, far);
}
static bool SC_MatrixInverse_4x4(Matrix4x4 *m) {
return m->inverse();
}
static bool SC_MatrixInverseTranspose_4x4(Matrix4x4 *m) {
return m->inverseTranspose();
}
static void SC_MatrixTranspose_4x4(Matrix4x4 *m) {
m->transpose();
}
static void SC_MatrixTranspose_3x3(Matrix3x3 *m) {
m->transpose();
}
static void SC_MatrixTranspose_2x2(Matrix2x2 *m) {
m->transpose();
}
float SC_randf2(float min, float max) {
float r = (float)rand();
r /= RAND_MAX;
r = r * (max - min) + min;
return r;
}
static float SC_frac(float v) {
int i = (int)floor(v);
return fmin(v - i, 0x1.fffffep-1f);
}
EXPORT_F32_FN_F32(acosf)
EXPORT_F32_FN_F32(acoshf)
EXPORT_F32_FN_F32(asinf)
EXPORT_F32_FN_F32(asinhf)
EXPORT_F32_FN_F32(atanf)
EXPORT_F32_FN_F32_F32(atan2f)
EXPORT_F32_FN_F32(atanhf)
EXPORT_F32_FN_F32(cbrtf)
EXPORT_F32_FN_F32(ceilf)
EXPORT_F32_FN_F32_F32(copysignf)
EXPORT_F32_FN_F32(cosf)
EXPORT_F32_FN_F32(coshf)
EXPORT_F32_FN_F32(erfcf)
EXPORT_F32_FN_F32(erff)
EXPORT_F32_FN_F32(expf)
EXPORT_F32_FN_F32(exp2f)
EXPORT_F32_FN_F32(expm1f)
EXPORT_F32_FN_F32_F32(fdimf)
EXPORT_F32_FN_F32(floorf)
float SC_fmaf(float u, float t, float v) {return fmaf(u, t, v);}
EXPORT_F32_FN_F32_F32(fmaxf)
EXPORT_F32_FN_F32_F32(fminf)
EXPORT_F32_FN_F32_F32(fmodf)
float SC_frexpf(float v, int* ptr) {return frexpf(v, ptr);}
EXPORT_F32_FN_F32_F32(hypotf)
int SC_ilogbf(float v) {return ilogbf(v); }
float SC_ldexpf(float v, int i) {return ldexpf(v, i);}
EXPORT_F32_FN_F32(lgammaf)
float SC_lgammaf_r(float v, int* ptr) {return lgammaf_r(v, ptr);}
EXPORT_F32_FN_F32(logf)
EXPORT_F32_FN_F32(log10f)
EXPORT_F32_FN_F32(log1pf)
EXPORT_F32_FN_F32(logbf)
float SC_modff(float v, float* ptr) {return modff(v, ptr);}
EXPORT_F32_FN_F32_F32(nextafterf)
EXPORT_F32_FN_F32_F32(powf)
EXPORT_F32_FN_F32_F32(remainderf)
float SC_remquof(float t, float v, int* ptr) {return remquof(t, v, ptr);}
EXPORT_F32_FN_F32(rintf)
EXPORT_F32_FN_F32(roundf)
EXPORT_F32_FN_F32(sinf)
EXPORT_F32_FN_F32(sinhf)
EXPORT_F32_FN_F32(sqrtf)
EXPORT_F32_FN_F32(tanf)
EXPORT_F32_FN_F32(tanhf)
EXPORT_F32_FN_F32(truncf)
float __attribute__((overloadable)) rsFrac(float f) {
return SC_frac(f);
}
void __attribute__((overloadable)) rsMatrixLoadRotate(rs_matrix4x4 *m,
float rot, float x, float y, float z) {
SC_MatrixLoadRotate((Matrix4x4 *) m, rot, x, y, z);
}
void __attribute__((overloadable)) rsMatrixLoadScale(rs_matrix4x4 *m,
float x, float y, float z) {
SC_MatrixLoadScale((Matrix4x4 *) m, x, y, z);
}
void __attribute__((overloadable)) rsMatrixLoadTranslate(rs_matrix4x4 *m,
float x, float y, float z) {
SC_MatrixLoadTranslate((Matrix4x4 *) m, x, y, z);
}
void __attribute__((overloadable)) rsMatrixRotate(rs_matrix4x4 *m, float rot,
float x, float y, float z) {
SC_MatrixRotate((Matrix4x4 *) m, rot, x, y, z);
}
void __attribute__((overloadable)) rsMatrixScale(rs_matrix4x4 *m, float x,
float y, float z) {
SC_MatrixScale((Matrix4x4 *) m, x, y, z);
}
void __attribute__((overloadable)) rsMatrixTranslate(rs_matrix4x4 *m, float x,
float y, float z) {
SC_MatrixTranslate((Matrix4x4 *) m, x, y, z);
}
void __attribute__((overloadable)) rsMatrixLoadOrtho(rs_matrix4x4 *m, float l,
float r, float b, float t, float n, float f) {
SC_MatrixLoadOrtho((Matrix4x4 *) m, l, r, b, t, n, f);
}
void __attribute__((overloadable)) rsMatrixLoadFrustum(rs_matrix4x4 *m,
float l, float r, float b, float t, float n, float f) {
SC_MatrixLoadFrustum((Matrix4x4 *) m, l, r, b, t, n, f);
}
void __attribute__((overloadable)) rsMatrixLoadPerspective(rs_matrix4x4 *m,
float fovy, float aspect, float near, float far) {
SC_MatrixLoadPerspective((Matrix4x4 *) m, fovy, aspect, near, far);
}
bool __attribute__((overloadable)) rsMatrixInverse(rs_matrix4x4 *m) {
return SC_MatrixInverse_4x4((Matrix4x4 *) m);
}
bool __attribute__((overloadable)) rsMatrixInverseTranspose(rs_matrix4x4 *m) {
return SC_MatrixInverseTranspose_4x4((Matrix4x4 *) m);
}
void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix4x4 *m) {
SC_MatrixTranspose_4x4((Matrix4x4 *) m);
}
void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix3x3 *m) {
SC_MatrixTranspose_3x3((Matrix3x3 *) m);
}
void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix2x2 *m) {
SC_MatrixTranspose_2x2((Matrix2x2 *) m);
}
|