blob: 6dc3e8bcea8ba957dc717f9967702279fd8177ed [file] [log] [blame]
Jason Samse45ac6e2009-07-20 14:31:06 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "rsContext.h"
18#include "rsScriptC.h"
19#include "rsMatrix.h"
Romain Guyb7f1a6d2009-08-03 21:12:51 -070020#include "rsNoise.h"
Jason Samse45ac6e2009-07-20 14:31:06 -070021
22#include "acc/acc.h"
Joe Onorato9c4e4ca2009-08-09 11:39:02 -070023#include "utils/Timers.h"
Jason Samse45ac6e2009-07-20 14:31:06 -070024
25#include <GLES/gl.h>
26#include <GLES/glext.h>
27
Romain Guy98e10fd2009-07-30 18:45:01 -070028#include <time.h>
29#include <cutils/tztime.h>
30
Jason Samse45ac6e2009-07-20 14:31:06 -070031using namespace android;
32using namespace android::renderscript;
33
34#define GET_TLS() Context::ScriptTLSStruct * tls = \
35 (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \
36 Context * rsc = tls->mContext; \
37 ScriptC * sc = (ScriptC *) tls->mScript
38
Jason Samsa57c0a72009-09-04 14:42:41 -070039typedef struct {
40 float x;
41 float y;
42 float z;
43} vec3_t;
44
45typedef struct {
46 float x;
47 float y;
48 float z;
49 float w;
50} vec4_t;
51
52typedef struct {
53 float x;
54 float y;
55} vec2_t;
Jason Samse45ac6e2009-07-20 14:31:06 -070056
57//////////////////////////////////////////////////////////////////////////////
58// IO routines
59//////////////////////////////////////////////////////////////////////////////
60
61static float SC_loadF(uint32_t bank, uint32_t offset)
62{
63 GET_TLS();
64 const void *vp = sc->mSlots[bank]->getPtr();
65 const float *f = static_cast<const float *>(vp);
66 //LOGE("loadF %i %i = %f %x", bank, offset, f, ((int *)&f)[0]);
67 return f[offset];
68}
69
70static int32_t SC_loadI32(uint32_t bank, uint32_t offset)
71{
72 GET_TLS();
73 const void *vp = sc->mSlots[bank]->getPtr();
74 const int32_t *i = static_cast<const int32_t *>(vp);
75 //LOGE("loadI32 %i %i = %i", bank, offset, t);
76 return i[offset];
77}
78
Romain Guy06f7c932009-08-06 12:40:41 -070079static float* SC_loadArrayF(uint32_t bank, uint32_t offset)
Romain Guy36401002009-08-04 17:19:48 -070080{
81 GET_TLS();
82 void *vp = sc->mSlots[bank]->getPtr();
83 float *f = static_cast<float *>(vp);
Romain Guy06f7c932009-08-06 12:40:41 -070084 return f + offset;
Romain Guy36401002009-08-04 17:19:48 -070085}
86
Romain Guy06f7c932009-08-06 12:40:41 -070087static int32_t* SC_loadArrayI32(uint32_t bank, uint32_t offset)
Romain Guy36401002009-08-04 17:19:48 -070088{
89 GET_TLS();
90 void *vp = sc->mSlots[bank]->getPtr();
91 int32_t *i = static_cast<int32_t *>(vp);
Romain Guy06f7c932009-08-06 12:40:41 -070092 return i + offset;
Romain Guy36401002009-08-04 17:19:48 -070093}
94
Romain Guy48b7edc2009-08-06 22:52:13 -070095static float* SC_loadTriangleMeshVerticesF(RsTriangleMesh mesh)
96{
97 TriangleMesh *tm = static_cast<TriangleMesh *>(mesh);
98 void *vp = tm->mVertexData;
99 float *f = static_cast<float *>(vp);
100 return f;
101}
102
103static void SC_updateTriangleMesh(RsTriangleMesh mesh)
104{
105 TriangleMesh *tm = static_cast<TriangleMesh *>(mesh);
106 glBindBuffer(GL_ARRAY_BUFFER, tm->mBufferObjects[0]);
107 glBufferData(GL_ARRAY_BUFFER, tm->mVertexDataSize, tm->mVertexData, GL_STATIC_DRAW);
108 glBindBuffer(GL_ARRAY_BUFFER, 0);
Jason Samse5ffb872009-08-09 17:01:55 -0700109
Romain Guy48b7edc2009-08-06 22:52:13 -0700110 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]);
111 glBufferData(GL_ELEMENT_ARRAY_BUFFER, tm->mIndexDataSize, tm->mIndexData, GL_STATIC_DRAW);
Jason Samse5ffb872009-08-09 17:01:55 -0700112 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
Romain Guy48b7edc2009-08-06 22:52:13 -0700113}
Romain Guy06f7c932009-08-06 12:40:41 -0700114
Jason Samse45ac6e2009-07-20 14:31:06 -0700115static uint32_t SC_loadU32(uint32_t bank, uint32_t offset)
116{
117 GET_TLS();
118 const void *vp = sc->mSlots[bank]->getPtr();
119 const uint32_t *i = static_cast<const uint32_t *>(vp);
120 return i[offset];
121}
122
123static void SC_loadVec4(uint32_t bank, uint32_t offset, rsc_Vector4 *v)
124{
125 GET_TLS();
126 const void *vp = sc->mSlots[bank]->getPtr();
127 const float *f = static_cast<const float *>(vp);
128 memcpy(v, &f[offset], sizeof(rsc_Vector4));
129}
130
131static void SC_loadMatrix(uint32_t bank, uint32_t offset, rsc_Matrix *m)
132{
133 GET_TLS();
134 const void *vp = sc->mSlots[bank]->getPtr();
135 const float *f = static_cast<const float *>(vp);
136 memcpy(m, &f[offset], sizeof(rsc_Matrix));
137}
138
139
140static void SC_storeF(uint32_t bank, uint32_t offset, float v)
141{
142 //LOGE("storeF %i %i %f", bank, offset, v);
143 GET_TLS();
144 void *vp = sc->mSlots[bank]->getPtr();
145 float *f = static_cast<float *>(vp);
146 f[offset] = v;
147}
148
149static void SC_storeI32(uint32_t bank, uint32_t offset, int32_t v)
150{
151 GET_TLS();
152 void *vp = sc->mSlots[bank]->getPtr();
153 int32_t *f = static_cast<int32_t *>(vp);
154 static_cast<int32_t *>(sc->mSlots[bank]->getPtr())[offset] = v;
155}
156
157static void SC_storeU32(uint32_t bank, uint32_t offset, uint32_t v)
158{
159 GET_TLS();
160 void *vp = sc->mSlots[bank]->getPtr();
161 uint32_t *f = static_cast<uint32_t *>(vp);
162 static_cast<uint32_t *>(sc->mSlots[bank]->getPtr())[offset] = v;
163}
164
165static void SC_storeVec4(uint32_t bank, uint32_t offset, const rsc_Vector4 *v)
166{
167 GET_TLS();
168 void *vp = sc->mSlots[bank]->getPtr();
169 float *f = static_cast<float *>(vp);
170 memcpy(&f[offset], v, sizeof(rsc_Vector4));
171}
172
173static void SC_storeMatrix(uint32_t bank, uint32_t offset, const rsc_Matrix *m)
174{
175 GET_TLS();
176 void *vp = sc->mSlots[bank]->getPtr();
177 float *f = static_cast<float *>(vp);
178 memcpy(&f[offset], m, sizeof(rsc_Matrix));
179}
180
Jason Samsa57c0a72009-09-04 14:42:41 -0700181//////////////////////////////////////////////////////////////////////////////
182// Vec3 routines
183//////////////////////////////////////////////////////////////////////////////
184
185static void SC_vec3Norm(vec3_t *v)
186{
187 float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
188 len = 1 / len;
189 v->x *= len;
190 v->y *= len;
191 v->z *= len;
192}
193
194static float SC_vec3Length(const vec3_t *v)
195{
196 return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
197}
198
199static void SC_vec3Add(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
200{
201 dest->x = lhs->x + rhs->x;
202 dest->y = lhs->y + rhs->y;
203 dest->z = lhs->z + rhs->z;
204}
205
206static void SC_vec3Sub(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
207{
208 dest->x = lhs->x - rhs->x;
209 dest->y = lhs->y - rhs->y;
210 dest->z = lhs->z - rhs->z;
211}
212
213static void SC_vec3Cross(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
214{
215 float x = lhs->y * rhs->z - lhs->z * rhs->y;
216 float y = lhs->z * rhs->x - lhs->x * rhs->z;
217 float z = lhs->x * rhs->y - lhs->y * rhs->x;
218 dest->x = x;
219 dest->y = y;
220 dest->z = z;
221}
222
223static float SC_vec3Dot(const vec3_t *lhs, const vec3_t *rhs)
224{
225 return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z;
226}
227
228static void SC_vec3Scale(vec3_t *lhs, float scale)
229{
230 lhs->x *= scale;
231 lhs->y *= scale;
232 lhs->z *= scale;
233}
234
Jason Samse45ac6e2009-07-20 14:31:06 -0700235
236//////////////////////////////////////////////////////////////////////////////
237// Math routines
238//////////////////////////////////////////////////////////////////////////////
239
Romain Guy39dbc802009-07-31 11:20:59 -0700240#define PI 3.1415926f
241#define DEG_TO_RAD PI / 180.0f
242#define RAD_TO_DEG 180.0f / PI
243
Romain Guy2275d632009-08-18 11:39:17 -0700244static float SC_sinf_fast(float x)
245{
246 const float A = 1.0f / (2.0f * M_PI);
247 const float B = -16.0f;
248 const float C = 8.0f;
Jason Samsa57c0a72009-09-04 14:42:41 -0700249
Romain Guy2275d632009-08-18 11:39:17 -0700250 // scale angle for easy argument reduction
251 x *= A;
Jason Samsa57c0a72009-09-04 14:42:41 -0700252
Romain Guy2275d632009-08-18 11:39:17 -0700253 if (fabsf(x) >= 0.5f) {
254 // argument reduction
255 x = x - ceilf(x + 0.5f) + 1.0f;
256 }
Jason Samsa57c0a72009-09-04 14:42:41 -0700257
Romain Guy2275d632009-08-18 11:39:17 -0700258 const float y = B * x * fabsf(x) + C * x;
259 return 0.2215f * (y * fabsf(y) - y) + y;
260}
261
262static float SC_cosf_fast(float x)
263{
264 x += float(M_PI / 2);
265
266 const float A = 1.0f / (2.0f * M_PI);
267 const float B = -16.0f;
268 const float C = 8.0f;
Jason Samsa57c0a72009-09-04 14:42:41 -0700269
Romain Guy2275d632009-08-18 11:39:17 -0700270 // scale angle for easy argument reduction
271 x *= A;
Jason Samsa57c0a72009-09-04 14:42:41 -0700272
Romain Guy2275d632009-08-18 11:39:17 -0700273 if (fabsf(x) >= 0.5f) {
274 // argument reduction
275 x = x - ceilf(x + 0.5f) + 1.0f;
276 }
Jason Samsa57c0a72009-09-04 14:42:41 -0700277
Romain Guy2275d632009-08-18 11:39:17 -0700278 const float y = B * x * fabsf(x) + C * x;
279 return 0.2215f * (y * fabsf(y) - y) + y;
280}
281
Jason Samse45ac6e2009-07-20 14:31:06 -0700282static float SC_randf(float max)
283{
284 float r = (float)rand();
285 return r / RAND_MAX * max;
286}
287
Romain Guy39dbc802009-07-31 11:20:59 -0700288static float SC_randf2(float min, float max)
289{
290 float r = (float)rand();
291 return r / RAND_MAX * (max - min) + min;
292}
293
294static float SC_clampf(float amount, float low, float high)
295{
296 return amount < low ? low : (amount > high ? high : amount);
297}
298
Romain Guy27162ab2009-08-09 17:04:54 -0700299static int SC_clamp(int amount, int low, int high)
300{
301 return amount < low ? low : (amount > high ? high : amount);
302}
303
Romain Guy39dbc802009-07-31 11:20:59 -0700304static float SC_maxf(float a, float b)
305{
Jason Samse5ffb872009-08-09 17:01:55 -0700306 return a > b ? a : b;
Romain Guy39dbc802009-07-31 11:20:59 -0700307}
308
309static float SC_minf(float a, float b)
310{
Jason Samse5ffb872009-08-09 17:01:55 -0700311 return a < b ? a : b;
Romain Guy39dbc802009-07-31 11:20:59 -0700312}
313
314static float SC_sqrf(float v)
315{
Jason Samse5ffb872009-08-09 17:01:55 -0700316 return v * v;
Romain Guy39dbc802009-07-31 11:20:59 -0700317}
318
Romain Guyfcc1c2b2009-08-08 18:30:19 -0700319static int SC_sqr(int v)
320{
321 return v * v;
322}
323
Jason Samsdac98f52009-09-18 14:24:24 -0700324static float SC_fracf(float v)
325{
326 return v - floorf(v);
327}
328
329static float SC_roundf(float v)
330{
331 return floorf(v + 0.4999999999);
332}
333
Romain Guy39dbc802009-07-31 11:20:59 -0700334static float SC_distf2(float x1, float y1, float x2, float y2)
335{
336 float x = x2 - x1;
337 float y = y2 - y1;
Jason Samse5ffb872009-08-09 17:01:55 -0700338 return sqrtf(x * x + y * y);
Romain Guy39dbc802009-07-31 11:20:59 -0700339}
340
341static float SC_distf3(float x1, float y1, float z1, float x2, float y2, float z2)
342{
343 float x = x2 - x1;
344 float y = y2 - y1;
345 float z = z2 - z1;
Jason Samse5ffb872009-08-09 17:01:55 -0700346 return sqrtf(x * x + y * y + z * z);
Romain Guy39dbc802009-07-31 11:20:59 -0700347}
348
349static float SC_magf2(float a, float b)
350{
351 return sqrtf(a * a + b * b);
352}
353
354static float SC_magf3(float a, float b, float c)
355{
356 return sqrtf(a * a + b * b + c * c);
357}
358
359static float SC_radf(float degrees)
360{
Jason Samse5ffb872009-08-09 17:01:55 -0700361 return degrees * DEG_TO_RAD;
Romain Guy39dbc802009-07-31 11:20:59 -0700362}
363
364static float SC_degf(float radians)
365{
Jason Samse5ffb872009-08-09 17:01:55 -0700366 return radians * RAD_TO_DEG;
Romain Guy39dbc802009-07-31 11:20:59 -0700367}
368
369static float SC_lerpf(float start, float stop, float amount)
370{
371 return start + (stop - start) * amount;
372}
373
374static float SC_normf(float start, float stop, float value)
375{
376 return (value - start) / (stop - start);
377}
378
379static float SC_mapf(float minStart, float minStop, float maxStart, float maxStop, float value)
380{
381 return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart));
382}
Jason Samse45ac6e2009-07-20 14:31:06 -0700383
Romain Guy98e10fd2009-07-30 18:45:01 -0700384//////////////////////////////////////////////////////////////////////////////
385// Time routines
386//////////////////////////////////////////////////////////////////////////////
Jason Samse45ac6e2009-07-20 14:31:06 -0700387
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700388static int32_t SC_second()
Romain Guy98e10fd2009-07-30 18:45:01 -0700389{
390 GET_TLS();
391
392 time_t rawtime;
393 time(&rawtime);
394
395 if (sc->mEnviroment.mTimeZone) {
396 struct tm timeinfo;
397 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
398 return timeinfo.tm_sec;
399 } else {
400 struct tm *timeinfo;
401 timeinfo = localtime(&rawtime);
402 return timeinfo->tm_sec;
403 }
404}
405
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700406static int32_t SC_minute()
Romain Guy98e10fd2009-07-30 18:45:01 -0700407{
408 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700409
Romain Guy98e10fd2009-07-30 18:45:01 -0700410 time_t rawtime;
411 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700412
Romain Guy98e10fd2009-07-30 18:45:01 -0700413 if (sc->mEnviroment.mTimeZone) {
414 struct tm timeinfo;
415 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
416 return timeinfo.tm_min;
417 } else {
418 struct tm *timeinfo;
419 timeinfo = localtime(&rawtime);
420 return timeinfo->tm_min;
421 }
Jason Samse5ffb872009-08-09 17:01:55 -0700422}
Romain Guy98e10fd2009-07-30 18:45:01 -0700423
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700424static int32_t SC_hour()
Romain Guy98e10fd2009-07-30 18:45:01 -0700425{
426 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700427
Romain Guy98e10fd2009-07-30 18:45:01 -0700428 time_t rawtime;
429 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700430
Romain Guy98e10fd2009-07-30 18:45:01 -0700431 if (sc->mEnviroment.mTimeZone) {
432 struct tm timeinfo;
433 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
434 return timeinfo.tm_hour;
435 } else {
436 struct tm *timeinfo;
437 timeinfo = localtime(&rawtime);
438 return timeinfo->tm_hour;
439 }
Romain Guy39dbc802009-07-31 11:20:59 -0700440}
441
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700442static int32_t SC_day()
Romain Guy39dbc802009-07-31 11:20:59 -0700443{
444 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700445
Romain Guy39dbc802009-07-31 11:20:59 -0700446 time_t rawtime;
447 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700448
Romain Guy39dbc802009-07-31 11:20:59 -0700449 if (sc->mEnviroment.mTimeZone) {
450 struct tm timeinfo;
451 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
452 return timeinfo.tm_mday;
453 } else {
454 struct tm *timeinfo;
455 timeinfo = localtime(&rawtime);
456 return timeinfo->tm_mday;
457 }
Jason Samse5ffb872009-08-09 17:01:55 -0700458}
Jason Samse45ac6e2009-07-20 14:31:06 -0700459
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700460static int32_t SC_month()
Romain Guy39dbc802009-07-31 11:20:59 -0700461{
462 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700463
Romain Guy39dbc802009-07-31 11:20:59 -0700464 time_t rawtime;
465 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700466
Romain Guy39dbc802009-07-31 11:20:59 -0700467 if (sc->mEnviroment.mTimeZone) {
468 struct tm timeinfo;
469 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
470 return timeinfo.tm_mon;
471 } else {
472 struct tm *timeinfo;
473 timeinfo = localtime(&rawtime);
474 return timeinfo->tm_mon;
475 }
Jason Samse5ffb872009-08-09 17:01:55 -0700476}
Romain Guy39dbc802009-07-31 11:20:59 -0700477
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700478static int32_t SC_year()
Romain Guy39dbc802009-07-31 11:20:59 -0700479{
480 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700481
Romain Guy39dbc802009-07-31 11:20:59 -0700482 time_t rawtime;
483 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700484
Romain Guy39dbc802009-07-31 11:20:59 -0700485 if (sc->mEnviroment.mTimeZone) {
486 struct tm timeinfo;
487 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
488 return timeinfo.tm_year;
489 } else {
490 struct tm *timeinfo;
491 timeinfo = localtime(&rawtime);
492 return timeinfo->tm_year;
493 }
494}
495
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700496static int32_t SC_uptimeMillis()
497{
498 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
499}
500
501static int32_t SC_startTimeMillis()
502{
503 GET_TLS();
504 return sc->mEnviroment.mStartTimeMillis;
505}
506
507static int32_t SC_elapsedTimeMillis()
508{
509 GET_TLS();
510 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC))
511 - sc->mEnviroment.mStartTimeMillis;
512}
513
Jason Samse45ac6e2009-07-20 14:31:06 -0700514//////////////////////////////////////////////////////////////////////////////
515// Matrix routines
516//////////////////////////////////////////////////////////////////////////////
517
518
519static void SC_matrixLoadIdentity(rsc_Matrix *mat)
520{
521 Matrix *m = reinterpret_cast<Matrix *>(mat);
522 m->loadIdentity();
523}
524
525static void SC_matrixLoadFloat(rsc_Matrix *mat, const float *f)
526{
527 Matrix *m = reinterpret_cast<Matrix *>(mat);
528 m->load(f);
529}
530
531static void SC_matrixLoadMat(rsc_Matrix *mat, const rsc_Matrix *newmat)
532{
533 Matrix *m = reinterpret_cast<Matrix *>(mat);
534 m->load(reinterpret_cast<const Matrix *>(newmat));
535}
536
537static void SC_matrixLoadRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
538{
539 Matrix *m = reinterpret_cast<Matrix *>(mat);
540 m->loadRotate(rot, x, y, z);
541}
542
543static void SC_matrixLoadScale(rsc_Matrix *mat, float x, float y, float z)
544{
545 Matrix *m = reinterpret_cast<Matrix *>(mat);
546 m->loadScale(x, y, z);
547}
548
549static void SC_matrixLoadTranslate(rsc_Matrix *mat, float x, float y, float z)
550{
551 Matrix *m = reinterpret_cast<Matrix *>(mat);
552 m->loadTranslate(x, y, z);
553}
554
555static void SC_matrixLoadMultiply(rsc_Matrix *mat, const rsc_Matrix *lhs, const rsc_Matrix *rhs)
556{
557 Matrix *m = reinterpret_cast<Matrix *>(mat);
558 m->loadMultiply(reinterpret_cast<const Matrix *>(lhs),
559 reinterpret_cast<const Matrix *>(rhs));
560}
561
562static void SC_matrixMultiply(rsc_Matrix *mat, const rsc_Matrix *rhs)
563{
564 Matrix *m = reinterpret_cast<Matrix *>(mat);
565 m->multiply(reinterpret_cast<const Matrix *>(rhs));
566}
567
568static void SC_matrixRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
569{
570 Matrix *m = reinterpret_cast<Matrix *>(mat);
571 m->rotate(rot, x, y, z);
572}
573
574static void SC_matrixScale(rsc_Matrix *mat, float x, float y, float z)
575{
576 Matrix *m = reinterpret_cast<Matrix *>(mat);
577 m->scale(x, y, z);
578}
579
580static void SC_matrixTranslate(rsc_Matrix *mat, float x, float y, float z)
581{
582 Matrix *m = reinterpret_cast<Matrix *>(mat);
583 m->translate(x, y, z);
584}
585
586
Jason Sams90b36a82009-08-17 13:56:09 -0700587static void SC_vec2Rand(float *vec, float maxLen)
588{
589 float angle = SC_randf(PI * 2);
590 float len = SC_randf(maxLen);
591 vec[0] = len * sinf(angle);
592 vec[1] = len * cosf(angle);
593}
594
Jason Samse45ac6e2009-07-20 14:31:06 -0700595
596
597//////////////////////////////////////////////////////////////////////////////
598// Context
599//////////////////////////////////////////////////////////////////////////////
600
601static void SC_bindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va)
602{
603 GET_TLS();
604 rsi_ProgramFragmentBindTexture(rsc,
605 static_cast<ProgramFragment *>(vpf),
606 slot,
607 static_cast<Allocation *>(va));
608
609}
610
611static void SC_bindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs)
612{
613 GET_TLS();
614 rsi_ProgramFragmentBindSampler(rsc,
615 static_cast<ProgramFragment *>(vpf),
616 slot,
617 static_cast<Sampler *>(vs));
618
619}
620
621static void SC_bindProgramFragmentStore(RsProgramFragmentStore pfs)
622{
623 GET_TLS();
624 rsi_ContextBindProgramFragmentStore(rsc, pfs);
625
626}
627
628static void SC_bindProgramFragment(RsProgramFragment pf)
629{
630 GET_TLS();
631 rsi_ContextBindProgramFragment(rsc, pf);
632
633}
634
Jason Samsb5909ce2009-07-21 12:20:54 -0700635static void SC_bindProgramVertex(RsProgramVertex pv)
636{
637 GET_TLS();
638 rsi_ContextBindProgramVertex(rsc, pv);
639
640}
Jason Samse45ac6e2009-07-20 14:31:06 -0700641
642//////////////////////////////////////////////////////////////////////////////
Jason Samsc9d43db2009-07-28 12:02:16 -0700643// VP
644//////////////////////////////////////////////////////////////////////////////
645
646static void SC_vpLoadModelMatrix(const rsc_Matrix *m)
647{
648 GET_TLS();
649 rsc->getVertex()->setModelviewMatrix(m);
650}
651
652static void SC_vpLoadTextureMatrix(const rsc_Matrix *m)
653{
654 GET_TLS();
655 rsc->getVertex()->setTextureMatrix(m);
656}
657
658
659
660//////////////////////////////////////////////////////////////////////////////
Jason Samse45ac6e2009-07-20 14:31:06 -0700661// Drawing
662//////////////////////////////////////////////////////////////////////////////
663
664static void SC_drawTriangleMesh(RsTriangleMesh mesh)
665{
666 GET_TLS();
667 rsi_TriangleMeshRender(rsc, mesh);
668}
669
670static void SC_drawTriangleMeshRange(RsTriangleMesh mesh, uint32_t start, uint32_t count)
671{
672 GET_TLS();
673 rsi_TriangleMeshRenderRange(rsc, mesh, start, count);
674}
675
Romain Guyd369e272009-08-07 15:40:32 -0700676static void SC_drawLine(float x1, float y1, float z1,
677 float x2, float y2, float z2)
678{
679 GET_TLS();
680 rsc->setupCheck();
681
682 float vtx[] = { x1, y1, z1, x2, y2, z2 };
683
684 glBindBuffer(GL_ARRAY_BUFFER, 0);
685 glEnableClientState(GL_VERTEX_ARRAY);
686 glVertexPointer(3, GL_FLOAT, 0, vtx);
687
688 glDisableClientState(GL_NORMAL_ARRAY);
689 glDisableClientState(GL_COLOR_ARRAY);
690
691 glDrawArrays(GL_LINES, 0, 2);
692}
693
Romain Guyfcc1c2b2009-08-08 18:30:19 -0700694static void SC_drawQuadTexCoords(float x1, float y1, float z1,
695 float u1, float v1,
696 float x2, float y2, float z2,
697 float u2, float v2,
698 float x3, float y3, float z3,
699 float u3, float v3,
700 float x4, float y4, float z4,
701 float u4, float v4)
Jason Samse45ac6e2009-07-20 14:31:06 -0700702{
703 GET_TLS();
Jason Samse579df42009-08-10 14:55:26 -0700704
Jason Samse45ac6e2009-07-20 14:31:06 -0700705 //LOGE("Quad");
706 //LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1);
707 //LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2);
708 //LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3);
709 //LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4);
Jason Samse579df42009-08-10 14:55:26 -0700710
Jason Samse45ac6e2009-07-20 14:31:06 -0700711 float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4};
Romain Guyfcc1c2b2009-08-08 18:30:19 -0700712 const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4};
Jason Samse45ac6e2009-07-20 14:31:06 -0700713
714 rsc->setupCheck();
715
716 glBindBuffer(GL_ARRAY_BUFFER, 0);
717 //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]);
718
719 glEnableClientState(GL_VERTEX_ARRAY);
720 glVertexPointer(3, GL_FLOAT, 0, vtx);
721
722 glClientActiveTexture(GL_TEXTURE0);
723 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
724 glTexCoordPointer(2, GL_FLOAT, 0, tex);
725 glClientActiveTexture(GL_TEXTURE1);
726 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
727 glTexCoordPointer(2, GL_FLOAT, 0, tex);
728 glClientActiveTexture(GL_TEXTURE0);
729
730 glDisableClientState(GL_NORMAL_ARRAY);
731 glDisableClientState(GL_COLOR_ARRAY);
732
733 //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr);
734
735 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
736}
737
Romain Guyfcc1c2b2009-08-08 18:30:19 -0700738static void SC_drawQuad(float x1, float y1, float z1,
739 float x2, float y2, float z2,
740 float x3, float y3, float z3,
741 float x4, float y4, float z4)
742{
743 SC_drawQuadTexCoords(x1, y1, z1, 0, 1,
744 x2, y2, z2, 1, 1,
745 x3, y3, z3, 1, 0,
746 x4, y4, z4, 0, 0);
747}
748
Jason Samse9f5c532009-07-28 17:20:11 -0700749static void SC_drawRect(float x1, float y1,
750 float x2, float y2, float z)
751{
752 SC_drawQuad(x1, y2, z,
753 x2, y2, z,
754 x2, y1, z,
755 x1, y1, z);
756}
757
Jason Samse5ffb872009-08-09 17:01:55 -0700758static void SC_drawSimpleMesh(RsSimpleMesh vsm)
759{
760 GET_TLS();
761 SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
762 rsc->setupCheck();
763 sm->render();
764}
765
766static void SC_drawSimpleMeshRange(RsSimpleMesh vsm, uint32_t start, uint32_t len)
767{
768 GET_TLS();
769 SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
770 rsc->setupCheck();
771 sm->renderRange(start, len);
772}
773
774
Jason Samse45ac6e2009-07-20 14:31:06 -0700775//////////////////////////////////////////////////////////////////////////////
776//
777//////////////////////////////////////////////////////////////////////////////
778
Jason Samse45ac6e2009-07-20 14:31:06 -0700779static void SC_color(float r, float g, float b, float a)
780{
781 glColor4f(r, g, b, a);
782}
783
Romain Guy48b7edc2009-08-06 22:52:13 -0700784static void SC_ambient(float r, float g, float b, float a)
785{
786 GLfloat params[] = { r, g, b, a };
787 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, params);
788}
789
790static void SC_diffuse(float r, float g, float b, float a)
791{
792 GLfloat params[] = { r, g, b, a };
793 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, params);
794}
795
796static void SC_specular(float r, float g, float b, float a)
797{
798 GLfloat params[] = { r, g, b, a };
799 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, params);
800}
801
802static void SC_emission(float r, float g, float b, float a)
803{
804 GLfloat params[] = { r, g, b, a };
805 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, params);
806}
807
Romain Guyd369e272009-08-07 15:40:32 -0700808static void SC_shininess(float s)
Romain Guy48b7edc2009-08-06 22:52:13 -0700809{
Romain Guyd369e272009-08-07 15:40:32 -0700810 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, s);
Romain Guy48b7edc2009-08-06 22:52:13 -0700811}
812
Romain Guye62cc902009-09-04 17:55:41 -0700813static void SC_pointAttenuation(float a, float b, float c)
814{
815 GLfloat params[] = { a, b, c };
816 glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, params);
817}
818
Romain Guy370ed152009-08-20 17:08:33 -0700819static void SC_hsbToRgb(float h, float s, float b, float* rgb)
Romain Guy9c59d022009-07-31 15:33:59 -0700820{
821 float red = 0.0f;
822 float green = 0.0f;
823 float blue = 0.0f;
Jason Samse5ffb872009-08-09 17:01:55 -0700824
Romain Guy9c59d022009-07-31 15:33:59 -0700825 float x = h;
826 float y = s;
827 float z = b;
Jason Samse5ffb872009-08-09 17:01:55 -0700828
Romain Guy9c59d022009-07-31 15:33:59 -0700829 float hf = (x - (int) x) * 6.0f;
830 int ihf = (int) hf;
831 float f = hf - ihf;
832 float pv = z * (1.0f - y);
833 float qv = z * (1.0f - y * f);
834 float tv = z * (1.0f - y * (1.0f - f));
Jason Samse5ffb872009-08-09 17:01:55 -0700835
Romain Guy9c59d022009-07-31 15:33:59 -0700836 switch (ihf) {
837 case 0: // Red is the dominant color
838 red = z;
839 green = tv;
840 blue = pv;
841 break;
842 case 1: // Green is the dominant color
843 red = qv;
844 green = z;
845 blue = pv;
846 break;
847 case 2:
848 red = pv;
849 green = z;
850 blue = tv;
851 break;
852 case 3: // Blue is the dominant color
853 red = pv;
854 green = qv;
855 blue = z;
856 break;
857 case 4:
858 red = tv;
859 green = pv;
860 blue = z;
861 break;
862 case 5: // Red is the dominant color
863 red = z;
864 green = pv;
865 blue = qv;
866 break;
867 }
Jason Samse5ffb872009-08-09 17:01:55 -0700868
Romain Guy370ed152009-08-20 17:08:33 -0700869 rgb[0] = red;
870 rgb[1] = green;
871 rgb[2] = blue;
872}
873
874static int SC_hsbToAbgr(float h, float s, float b, float a)
875{
876 float rgb[3];
877 SC_hsbToRgb(h, s, b, rgb);
878 return int(a * 255.0f) << 24 |
879 int(rgb[2] * 255.0f) << 16 |
880 int(rgb[1] * 255.0f) << 8 |
881 int(rgb[0] * 255.0f);
882}
883
884static void SC_hsb(float h, float s, float b, float a)
885{
886 float rgb[3];
887 SC_hsbToRgb(h, s, b, rgb);
888 glColor4f(rgb[0], rgb[1], rgb[2], a);
Romain Guy9c59d022009-07-31 15:33:59 -0700889}
890
Jason Samsc9d43db2009-07-28 12:02:16 -0700891static void SC_uploadToTexture(RsAllocation va, uint32_t baseMipLevel)
Jason Samse45ac6e2009-07-20 14:31:06 -0700892{
893 GET_TLS();
894 rsi_AllocationUploadToTexture(rsc, va, baseMipLevel);
895}
896
Jason Samse5ffb872009-08-09 17:01:55 -0700897static void SC_uploadToBufferObject(RsAllocation va)
898{
899 GET_TLS();
900 rsi_AllocationUploadToBufferObject(rsc, va);
901}
902
Jason Samse45ac6e2009-07-20 14:31:06 -0700903static void SC_ClearColor(float r, float g, float b, float a)
904{
905 //LOGE("c %f %f %f %f", r, g, b, a);
906 GET_TLS();
907 sc->mEnviroment.mClearColor[0] = r;
908 sc->mEnviroment.mClearColor[1] = g;
909 sc->mEnviroment.mClearColor[2] = b;
910 sc->mEnviroment.mClearColor[3] = a;
911}
912
Jason Samsc9d43db2009-07-28 12:02:16 -0700913static void SC_debugF(const char *s, float f)
914{
915 LOGE("%s %f", s, f);
916}
917
Romain Guy370ed152009-08-20 17:08:33 -0700918static void SC_debugHexF(const char *s, float f)
919{
920 LOGE("%s 0x%x", s, *((int *) (&f)));
921}
922
Jason Samsc9d43db2009-07-28 12:02:16 -0700923static void SC_debugI32(const char *s, int32_t i)
924{
925 LOGE("%s %i", s, i);
926}
927
Romain Guy370ed152009-08-20 17:08:33 -0700928static void SC_debugHexI32(const char *s, int32_t i)
929{
930 LOGE("%s 0x%x", s, i);
931}
932
Jason Samse579df42009-08-10 14:55:26 -0700933static uint32_t SC_getWidth()
934{
935 GET_TLS();
936 return rsc->getWidth();
937}
Jason Samse45ac6e2009-07-20 14:31:06 -0700938
Jason Samse579df42009-08-10 14:55:26 -0700939static uint32_t SC_getHeight()
940{
941 GET_TLS();
942 return rsc->getHeight();
943}
Jason Samse45ac6e2009-07-20 14:31:06 -0700944
Jason Sams90b36a82009-08-17 13:56:09 -0700945static uint32_t SC_colorFloatRGBAtoUNorm8(float r, float g, float b, float a)
946{
947 uint32_t c = 0;
948 c |= (uint32_t)(r * 255.f + 0.5f);
949 c |= ((uint32_t)(g * 255.f + 0.5f)) << 8;
950 c |= ((uint32_t)(b * 255.f + 0.5f)) << 16;
951 c |= ((uint32_t)(a * 255.f + 0.5f)) << 24;
952 return c;
953}
954
955static uint32_t SC_colorFloatRGBAto565(float r, float g, float b)
956{
957 uint32_t ir = (uint32_t)(r * 255.f + 0.5f);
958 uint32_t ig = (uint32_t)(g * 255.f + 0.5f);
959 uint32_t ib = (uint32_t)(b * 255.f + 0.5f);
960 return rs888to565(ir, ig, ib);
961}
962
Jason Samse45ac6e2009-07-20 14:31:06 -0700963//////////////////////////////////////////////////////////////////////////////
964// Class implementation
965//////////////////////////////////////////////////////////////////////////////
966
967ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
968 // IO
969 { "loadI32", (void *)&SC_loadI32,
970 "int", "(int, int)" },
971 //{ "loadU32", (void *)&SC_loadU32, "unsigned int", "(int, int)" },
972 { "loadF", (void *)&SC_loadF,
973 "float", "(int, int)" },
Romain Guy36401002009-08-04 17:19:48 -0700974 { "loadArrayF", (void *)&SC_loadArrayF,
Romain Guy06f7c932009-08-06 12:40:41 -0700975 "float*", "(int, int)" },
Romain Guy36401002009-08-04 17:19:48 -0700976 { "loadArrayI32", (void *)&SC_loadArrayI32,
Romain Guy06f7c932009-08-06 12:40:41 -0700977 "int*", "(int, int)" },
Jason Samse45ac6e2009-07-20 14:31:06 -0700978 { "loadVec4", (void *)&SC_loadVec4,
979 "void", "(int, int, float *)" },
980 { "loadMatrix", (void *)&SC_loadMatrix,
981 "void", "(int, int, float *)" },
982 { "storeI32", (void *)&SC_storeI32,
983 "void", "(int, int, int)" },
984 //{ "storeU32", (void *)&SC_storeU32, "void", "(int, int, unsigned int)" },
985 { "storeF", (void *)&SC_storeF,
986 "void", "(int, int, float)" },
987 { "storeVec4", (void *)&SC_storeVec4,
988 "void", "(int, int, float *)" },
989 { "storeMatrix", (void *)&SC_storeMatrix,
990 "void", "(int, int, float *)" },
Romain Guy48b7edc2009-08-06 22:52:13 -0700991 { "loadTriangleMeshVerticesF", (void *)&SC_loadTriangleMeshVerticesF,
992 "float*", "(int)" },
993 { "updateTriangleMesh", (void *)&SC_updateTriangleMesh,
994 "void", "(int)" },
Jason Samse45ac6e2009-07-20 14:31:06 -0700995
996 // math
Romain Guy27162ab2009-08-09 17:04:54 -0700997 { "modf", (void *)&fmod,
998 "float", "(float, float)" },
Romain Guyfcc1c2b2009-08-08 18:30:19 -0700999 { "abs", (void *)&abs,
1000 "int", "(int)" },
1001 { "absf", (void *)&fabs,
1002 "float", "(float)" },
Romain Guy2275d632009-08-18 11:39:17 -07001003 { "sinf_fast", (void *)&SC_sinf_fast,
1004 "float", "(float)" },
1005 { "cosf_fast", (void *)&SC_cosf_fast,
1006 "float", "(float)" },
Jason Samse45ac6e2009-07-20 14:31:06 -07001007 { "sinf", (void *)&sinf,
1008 "float", "(float)" },
1009 { "cosf", (void *)&cosf,
1010 "float", "(float)" },
Romain Guy39dbc802009-07-31 11:20:59 -07001011 { "asinf", (void *)&asinf,
1012 "float", "(float)" },
1013 { "acosf", (void *)&acosf,
1014 "float", "(float)" },
1015 { "atanf", (void *)&atanf,
1016 "float", "(float)" },
1017 { "atan2f", (void *)&atan2f,
Romain Guy9c59d022009-07-31 15:33:59 -07001018 "float", "(float, float)" },
Jason Samse9f5c532009-07-28 17:20:11 -07001019 { "fabsf", (void *)&fabsf,
Jason Samse45ac6e2009-07-20 14:31:06 -07001020 "float", "(float)" },
1021 { "randf", (void *)&SC_randf,
1022 "float", "(float)" },
Romain Guy39dbc802009-07-31 11:20:59 -07001023 { "randf2", (void *)&SC_randf2,
1024 "float", "(float, float)" },
Jason Samsc9d43db2009-07-28 12:02:16 -07001025 { "floorf", (void *)&floorf,
1026 "float", "(float)" },
Jason Samsdac98f52009-09-18 14:24:24 -07001027 { "fracf", (void *)&SC_fracf,
1028 "float", "(float)" },
Jason Samsc9d43db2009-07-28 12:02:16 -07001029 { "ceilf", (void *)&ceilf,
1030 "float", "(float)" },
Jason Samsdac98f52009-09-18 14:24:24 -07001031 { "roundf", (void *)&SC_roundf,
1032 "float", "(float)" },
Romain Guy39dbc802009-07-31 11:20:59 -07001033 { "expf", (void *)&expf,
1034 "float", "(float)" },
1035 { "logf", (void *)&logf,
1036 "float", "(float)" },
1037 { "powf", (void *)&powf,
1038 "float", "(float, float)" },
1039 { "maxf", (void *)&SC_maxf,
1040 "float", "(float, float)" },
1041 { "minf", (void *)&SC_minf,
1042 "float", "(float, float)" },
Romain Guyfcc1c2b2009-08-08 18:30:19 -07001043 { "sqrt", (void *)&sqrt,
1044 "int", "(int)" },
Romain Guy39dbc802009-07-31 11:20:59 -07001045 { "sqrtf", (void *)&sqrtf,
1046 "float", "(float)" },
Romain Guyfcc1c2b2009-08-08 18:30:19 -07001047 { "sqr", (void *)&SC_sqr,
1048 "int", "(int)" },
Romain Guy39dbc802009-07-31 11:20:59 -07001049 { "sqrf", (void *)&SC_sqrf,
1050 "float", "(float)" },
Romain Guy27162ab2009-08-09 17:04:54 -07001051 { "clamp", (void *)&SC_clamp,
1052 "int", "(int, int, int)" },
Romain Guy39dbc802009-07-31 11:20:59 -07001053 { "clampf", (void *)&SC_clampf,
1054 "float", "(float, float, float)" },
1055 { "distf2", (void *)&SC_distf2,
1056 "float", "(float, float, float, float)" },
1057 { "distf3", (void *)&SC_distf3,
1058 "float", "(float, float, float, float, float, float)" },
1059 { "magf2", (void *)&SC_magf2,
1060 "float", "(float, float)" },
1061 { "magf3", (void *)&SC_magf3,
1062 "float", "(float, float, float)" },
1063 { "radf", (void *)&SC_radf,
1064 "float", "(float)" },
1065 { "degf", (void *)&SC_degf,
1066 "float", "(float)" },
1067 { "lerpf", (void *)&SC_lerpf,
1068 "float", "(float, float, float)" },
1069 { "normf", (void *)&SC_normf,
1070 "float", "(float, float, float)" },
1071 { "mapf", (void *)&SC_mapf,
1072 "float", "(float, float, float, float, float)" },
Romain Guyb7f1a6d2009-08-03 21:12:51 -07001073 { "noisef", (void *)&SC_noisef,
1074 "float", "(float)" },
1075 { "noisef2", (void *)&SC_noisef2,
1076 "float", "(float, float)" },
1077 { "noisef3", (void *)&SC_noisef3,
1078 "float", "(float, float, float)" },
1079 { "turbulencef2", (void *)&SC_turbulencef2,
1080 "float", "(float, float, float)" },
1081 { "turbulencef3", (void *)&SC_turbulencef3,
1082 "float", "(float, float, float, float)" },
Jason Samse45ac6e2009-07-20 14:31:06 -07001083
Romain Guy98e10fd2009-07-30 18:45:01 -07001084 // time
1085 { "second", (void *)&SC_second,
1086 "int", "()" },
1087 { "minute", (void *)&SC_minute,
1088 "int", "()" },
1089 { "hour", (void *)&SC_hour,
1090 "int", "()" },
Romain Guy39dbc802009-07-31 11:20:59 -07001091 { "day", (void *)&SC_day,
1092 "int", "()" },
1093 { "month", (void *)&SC_month,
1094 "int", "()" },
1095 { "year", (void *)&SC_year,
1096 "int", "()" },
Joe Onorato9c4e4ca2009-08-09 11:39:02 -07001097 { "uptimeMillis", (void*)&SC_uptimeMillis,
1098 "int", "()" }, // TODO: use long instead
1099 { "startTimeMillis", (void*)&SC_startTimeMillis,
1100 "int", "()" }, // TODO: use long instead
1101 { "elapsedTimeMillis", (void*)&SC_elapsedTimeMillis,
1102 "int", "()" }, // TODO: use long instead
Romain Guy98e10fd2009-07-30 18:45:01 -07001103
Jason Samse45ac6e2009-07-20 14:31:06 -07001104 // matrix
1105 { "matrixLoadIdentity", (void *)&SC_matrixLoadIdentity,
1106 "void", "(float *mat)" },
1107 { "matrixLoadFloat", (void *)&SC_matrixLoadFloat,
1108 "void", "(float *mat, float *f)" },
1109 { "matrixLoadMat", (void *)&SC_matrixLoadMat,
1110 "void", "(float *mat, float *newmat)" },
1111 { "matrixLoadRotate", (void *)&SC_matrixLoadRotate,
1112 "void", "(float *mat, float rot, float x, float y, float z)" },
1113 { "matrixLoadScale", (void *)&SC_matrixLoadScale,
1114 "void", "(float *mat, float x, float y, float z)" },
1115 { "matrixLoadTranslate", (void *)&SC_matrixLoadTranslate,
1116 "void", "(float *mat, float x, float y, float z)" },
1117 { "matrixLoadMultiply", (void *)&SC_matrixLoadMultiply,
1118 "void", "(float *mat, float *lhs, float *rhs)" },
1119 { "matrixMultiply", (void *)&SC_matrixMultiply,
1120 "void", "(float *mat, float *rhs)" },
1121 { "matrixRotate", (void *)&SC_matrixRotate,
1122 "void", "(float *mat, float rot, float x, float y, float z)" },
1123 { "matrixScale", (void *)&SC_matrixScale,
1124 "void", "(float *mat, float x, float y, float z)" },
1125 { "matrixTranslate", (void *)&SC_matrixTranslate,
1126 "void", "(float *mat, float x, float y, float z)" },
1127
Jason Sams90b36a82009-08-17 13:56:09 -07001128 // vector
1129 { "vec2Rand", (void *)&SC_vec2Rand,
1130 "void", "(float *vec, float maxLen)" },
1131
Jason Samsa57c0a72009-09-04 14:42:41 -07001132 // vec3
1133 { "vec3Norm", (void *)&SC_vec3Norm,
1134 "void", "(struct vec3_s *)" },
1135 { "vec3Length", (void *)&SC_vec3Length,
1136 "float", "(struct vec3_s *)" },
1137 { "vec3Add", (void *)&SC_vec3Add,
1138 "void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" },
1139 { "vec3Sub", (void *)&SC_vec3Sub,
1140 "void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" },
1141 { "vec3Cross", (void *)&SC_vec3Cross,
1142 "void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" },
1143 { "vec3Dot", (void *)&SC_vec3Dot,
1144 "float", "(struct vec3_s *lhs, struct vec3_s *rhs)" },
1145 { "vec3Scale", (void *)&SC_vec3Scale,
1146 "void", "(struct vec3_s *lhs, float scale)" },
1147
Jason Samse45ac6e2009-07-20 14:31:06 -07001148 // context
1149 { "bindProgramFragment", (void *)&SC_bindProgramFragment,
1150 "void", "(int)" },
1151 { "bindProgramFragmentStore", (void *)&SC_bindProgramFragmentStore,
1152 "void", "(int)" },
Jason Samsb5909ce2009-07-21 12:20:54 -07001153 { "bindProgramVertex", (void *)&SC_bindProgramVertex,
1154 "void", "(int)" },
Jason Samse45ac6e2009-07-20 14:31:06 -07001155 { "bindSampler", (void *)&SC_bindSampler,
1156 "void", "(int, int, int)" },
1157 { "bindTexture", (void *)&SC_bindTexture,
1158 "void", "(int, int, int)" },
1159
Jason Samsc9d43db2009-07-28 12:02:16 -07001160 // vp
Jason Sams50253db2009-07-29 20:55:44 -07001161 { "vpLoadModelMatrix", (void *)&SC_vpLoadModelMatrix,
Jason Samsc9d43db2009-07-28 12:02:16 -07001162 "void", "(void *)" },
Jason Sams50253db2009-07-29 20:55:44 -07001163 { "vpLoadTextureMatrix", (void *)&SC_vpLoadTextureMatrix,
Jason Samsc9d43db2009-07-28 12:02:16 -07001164 "void", "(void *)" },
1165
1166
1167
Jason Samse45ac6e2009-07-20 14:31:06 -07001168 // drawing
Jason Samse9f5c532009-07-28 17:20:11 -07001169 { "drawRect", (void *)&SC_drawRect,
1170 "void", "(float x1, float y1, float x2, float y2, float z)" },
Jason Samse45ac6e2009-07-20 14:31:06 -07001171 { "drawQuad", (void *)&SC_drawQuad,
1172 "void", "(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4)" },
Romain Guyfcc1c2b2009-08-08 18:30:19 -07001173 { "drawQuadTexCoords", (void *)&SC_drawQuadTexCoords,
1174 "void", "(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)" },
Jason Samse45ac6e2009-07-20 14:31:06 -07001175 { "drawTriangleMesh", (void *)&SC_drawTriangleMesh,
1176 "void", "(int mesh)" },
1177 { "drawTriangleMeshRange", (void *)&SC_drawTriangleMeshRange,
1178 "void", "(int mesh, int start, int count)" },
Romain Guyd369e272009-08-07 15:40:32 -07001179 { "drawLine", (void *)&SC_drawLine,
1180 "void", "(float x1, float y1, float z1, float x2, float y2, float z2)" },
Jason Samse5ffb872009-08-09 17:01:55 -07001181 { "drawSimpleMesh", (void *)&SC_drawSimpleMesh,
1182 "void", "(int ism)" },
1183 { "drawSimpleMeshRange", (void *)&SC_drawSimpleMeshRange,
1184 "void", "(int ism, int start, int len)" },
Jason Samse45ac6e2009-07-20 14:31:06 -07001185
1186
1187 // misc
1188 { "pfClearColor", (void *)&SC_ClearColor,
1189 "void", "(float, float, float, float)" },
Jason Samse45ac6e2009-07-20 14:31:06 -07001190 { "color", (void *)&SC_color,
1191 "void", "(float, float, float, float)" },
Romain Guy9c59d022009-07-31 15:33:59 -07001192 { "hsb", (void *)&SC_hsb,
1193 "void", "(float, float, float, float)" },
Romain Guy370ed152009-08-20 17:08:33 -07001194 { "hsbToRgb", (void *)&SC_hsbToRgb,
1195 "void", "(float, float, float, float*)" },
1196 { "hsbToAbgr", (void *)&SC_hsbToAbgr,
1197 "int", "(float, float, float, float)" },
Romain Guy48b7edc2009-08-06 22:52:13 -07001198 { "ambient", (void *)&SC_ambient,
1199 "void", "(float, float, float, float)" },
1200 { "diffuse", (void *)&SC_diffuse,
1201 "void", "(float, float, float, float)" },
1202 { "specular", (void *)&SC_specular,
1203 "void", "(float, float, float, float)" },
1204 { "emission", (void *)&SC_emission,
1205 "void", "(float, float, float, float)" },
1206 { "shininess", (void *)&SC_shininess,
Romain Guyd369e272009-08-07 15:40:32 -07001207 "void", "(float)" },
Romain Guye62cc902009-09-04 17:55:41 -07001208 { "pointAttenuation", (void *)&SC_pointAttenuation,
1209 "void", "(float, float, float)" },
Jason Samse45ac6e2009-07-20 14:31:06 -07001210
Jason Samsc9d43db2009-07-28 12:02:16 -07001211 { "uploadToTexture", (void *)&SC_uploadToTexture,
1212 "void", "(int, int)" },
Jason Samse5ffb872009-08-09 17:01:55 -07001213 { "uploadToBufferObject", (void *)&SC_uploadToBufferObject,
1214 "void", "(int)" },
Jason Samsc9d43db2009-07-28 12:02:16 -07001215
Jason Sams90b36a82009-08-17 13:56:09 -07001216 { "colorFloatRGBAtoUNorm8", (void *)&SC_colorFloatRGBAtoUNorm8,
1217 "int", "(float, float, float, float)" },
1218 { "colorFloatRGBto565", (void *)&SC_colorFloatRGBAto565,
1219 "int", "(float, float, float)" },
1220
1221
Jason Samse579df42009-08-10 14:55:26 -07001222 { "getWidth", (void *)&SC_getWidth,
1223 "int", "()" },
1224 { "getHeight", (void *)&SC_getHeight,
1225 "int", "()" },
1226
1227
Jason Samsc9d43db2009-07-28 12:02:16 -07001228
1229 { "debugF", (void *)&SC_debugF,
1230 "void", "(void *, float)" },
1231 { "debugI32", (void *)&SC_debugI32,
1232 "void", "(void *, int)" },
Romain Guy370ed152009-08-20 17:08:33 -07001233 { "debugHexF", (void *)&SC_debugHexF,
1234 "void", "(void *, float)" },
1235 { "debugHexI32", (void *)&SC_debugHexI32,
1236 "void", "(void *, int)" },
Jason Samsc9d43db2009-07-28 12:02:16 -07001237
1238
Jason Samse45ac6e2009-07-20 14:31:06 -07001239 { NULL, NULL, NULL, NULL }
1240};
1241
1242const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym)
1243{
1244 ScriptCState::SymbolTable_t *syms = gSyms;
1245
1246 while (syms->mPtr) {
1247 if (!strcmp(syms->mName, sym)) {
1248 return syms;
1249 }
1250 syms++;
1251 }
1252 return NULL;
1253}
1254
1255void ScriptCState::appendDecls(String8 *str)
1256{
1257 ScriptCState::SymbolTable_t *syms = gSyms;
1258 while (syms->mPtr) {
1259 str->append(syms->mRet);
1260 str->append(" ");
1261 str->append(syms->mName);
1262 str->append(syms->mParam);
1263 str->append(";\n");
1264 syms++;
1265 }
1266}
1267
1268