blob: 0ecdf9a06998a29c69cfc0a0ceeccff9660ffaf6 [file] [log] [blame]
Jason Samsc97bb882009-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 Guyecc7ca032009-08-03 21:12:51 -070020#include "rsNoise.h"
Jason Samsc97bb882009-07-20 14:31:06 -070021
22#include "acc/acc.h"
Joe Onorato3370ec92009-08-09 11:39:02 -070023#include "utils/Timers.h"
Jason Samsc97bb882009-07-20 14:31:06 -070024
25#include <GLES/gl.h>
26#include <GLES/glext.h>
27
Romain Guy584a3752009-07-30 18:45:01 -070028#include <time.h>
29#include <cutils/tztime.h>
30
Jason Samsc97bb882009-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
39
40//////////////////////////////////////////////////////////////////////////////
41// IO routines
42//////////////////////////////////////////////////////////////////////////////
43
44static float SC_loadF(uint32_t bank, uint32_t offset)
45{
46 GET_TLS();
47 const void *vp = sc->mSlots[bank]->getPtr();
48 const float *f = static_cast<const float *>(vp);
49 //LOGE("loadF %i %i = %f %x", bank, offset, f, ((int *)&f)[0]);
50 return f[offset];
51}
52
53static int32_t SC_loadI32(uint32_t bank, uint32_t offset)
54{
55 GET_TLS();
56 const void *vp = sc->mSlots[bank]->getPtr();
57 const int32_t *i = static_cast<const int32_t *>(vp);
58 //LOGE("loadI32 %i %i = %i", bank, offset, t);
59 return i[offset];
60}
61
Romain Guyf8e136d2009-08-06 12:40:41 -070062static float* SC_loadArrayF(uint32_t bank, uint32_t offset)
Romain Guya2136d62009-08-04 17:19:48 -070063{
64 GET_TLS();
65 void *vp = sc->mSlots[bank]->getPtr();
66 float *f = static_cast<float *>(vp);
Romain Guyf8e136d2009-08-06 12:40:41 -070067 return f + offset;
Romain Guya2136d62009-08-04 17:19:48 -070068}
69
Romain Guyf8e136d2009-08-06 12:40:41 -070070static int32_t* SC_loadArrayI32(uint32_t bank, uint32_t offset)
Romain Guya2136d62009-08-04 17:19:48 -070071{
72 GET_TLS();
73 void *vp = sc->mSlots[bank]->getPtr();
74 int32_t *i = static_cast<int32_t *>(vp);
Romain Guyf8e136d2009-08-06 12:40:41 -070075 return i + offset;
Romain Guya2136d62009-08-04 17:19:48 -070076}
77
Romain Guyb62627e2009-08-06 22:52:13 -070078static float* SC_loadTriangleMeshVerticesF(RsTriangleMesh mesh)
79{
80 TriangleMesh *tm = static_cast<TriangleMesh *>(mesh);
81 void *vp = tm->mVertexData;
82 float *f = static_cast<float *>(vp);
83 return f;
84}
85
86static void SC_updateTriangleMesh(RsTriangleMesh mesh)
87{
88 TriangleMesh *tm = static_cast<TriangleMesh *>(mesh);
89 glBindBuffer(GL_ARRAY_BUFFER, tm->mBufferObjects[0]);
90 glBufferData(GL_ARRAY_BUFFER, tm->mVertexDataSize, tm->mVertexData, GL_STATIC_DRAW);
91 glBindBuffer(GL_ARRAY_BUFFER, 0);
Jason Sams1bada8c2009-08-09 17:01:55 -070092
Romain Guyb62627e2009-08-06 22:52:13 -070093 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]);
94 glBufferData(GL_ELEMENT_ARRAY_BUFFER, tm->mIndexDataSize, tm->mIndexData, GL_STATIC_DRAW);
Jason Sams1bada8c2009-08-09 17:01:55 -070095 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
Romain Guyb62627e2009-08-06 22:52:13 -070096}
Romain Guyf8e136d2009-08-06 12:40:41 -070097
Jason Samsc97bb882009-07-20 14:31:06 -070098static uint32_t SC_loadU32(uint32_t bank, uint32_t offset)
99{
100 GET_TLS();
101 const void *vp = sc->mSlots[bank]->getPtr();
102 const uint32_t *i = static_cast<const uint32_t *>(vp);
103 return i[offset];
104}
105
106static void SC_loadVec4(uint32_t bank, uint32_t offset, rsc_Vector4 *v)
107{
108 GET_TLS();
109 const void *vp = sc->mSlots[bank]->getPtr();
110 const float *f = static_cast<const float *>(vp);
111 memcpy(v, &f[offset], sizeof(rsc_Vector4));
112}
113
114static void SC_loadMatrix(uint32_t bank, uint32_t offset, rsc_Matrix *m)
115{
116 GET_TLS();
117 const void *vp = sc->mSlots[bank]->getPtr();
118 const float *f = static_cast<const float *>(vp);
119 memcpy(m, &f[offset], sizeof(rsc_Matrix));
120}
121
122
123static void SC_storeF(uint32_t bank, uint32_t offset, float v)
124{
125 //LOGE("storeF %i %i %f", bank, offset, v);
126 GET_TLS();
127 void *vp = sc->mSlots[bank]->getPtr();
128 float *f = static_cast<float *>(vp);
129 f[offset] = v;
130}
131
132static void SC_storeI32(uint32_t bank, uint32_t offset, int32_t v)
133{
134 GET_TLS();
135 void *vp = sc->mSlots[bank]->getPtr();
136 int32_t *f = static_cast<int32_t *>(vp);
137 static_cast<int32_t *>(sc->mSlots[bank]->getPtr())[offset] = v;
138}
139
140static void SC_storeU32(uint32_t bank, uint32_t offset, uint32_t v)
141{
142 GET_TLS();
143 void *vp = sc->mSlots[bank]->getPtr();
144 uint32_t *f = static_cast<uint32_t *>(vp);
145 static_cast<uint32_t *>(sc->mSlots[bank]->getPtr())[offset] = v;
146}
147
148static void SC_storeVec4(uint32_t bank, uint32_t offset, const rsc_Vector4 *v)
149{
150 GET_TLS();
151 void *vp = sc->mSlots[bank]->getPtr();
152 float *f = static_cast<float *>(vp);
153 memcpy(&f[offset], v, sizeof(rsc_Vector4));
154}
155
156static void SC_storeMatrix(uint32_t bank, uint32_t offset, const rsc_Matrix *m)
157{
158 GET_TLS();
159 void *vp = sc->mSlots[bank]->getPtr();
160 float *f = static_cast<float *>(vp);
161 memcpy(&f[offset], m, sizeof(rsc_Matrix));
162}
163
164
165//////////////////////////////////////////////////////////////////////////////
166// Math routines
167//////////////////////////////////////////////////////////////////////////////
168
Romain Guy8839ca52009-07-31 11:20:59 -0700169#define PI 3.1415926f
170#define DEG_TO_RAD PI / 180.0f
171#define RAD_TO_DEG 180.0f / PI
172
Jason Samsc97bb882009-07-20 14:31:06 -0700173static float SC_randf(float max)
174{
175 float r = (float)rand();
176 return r / RAND_MAX * max;
177}
178
Romain Guy8839ca52009-07-31 11:20:59 -0700179static float SC_randf2(float min, float max)
180{
181 float r = (float)rand();
182 return r / RAND_MAX * (max - min) + min;
183}
184
185static float SC_clampf(float amount, float low, float high)
186{
187 return amount < low ? low : (amount > high ? high : amount);
188}
189
Romain Guya9d2d5e2009-08-09 17:04:54 -0700190static int SC_clamp(int amount, int low, int high)
191{
192 return amount < low ? low : (amount > high ? high : amount);
193}
194
Romain Guy8839ca52009-07-31 11:20:59 -0700195static float SC_maxf(float a, float b)
196{
Jason Sams1bada8c2009-08-09 17:01:55 -0700197 return a > b ? a : b;
Romain Guy8839ca52009-07-31 11:20:59 -0700198}
199
200static float SC_minf(float a, float b)
201{
Jason Sams1bada8c2009-08-09 17:01:55 -0700202 return a < b ? a : b;
Romain Guy8839ca52009-07-31 11:20:59 -0700203}
204
205static float SC_sqrf(float v)
206{
Jason Sams1bada8c2009-08-09 17:01:55 -0700207 return v * v;
Romain Guy8839ca52009-07-31 11:20:59 -0700208}
209
Romain Guy8f5c94b2009-08-08 18:30:19 -0700210static int SC_sqr(int v)
211{
212 return v * v;
213}
214
Romain Guy8839ca52009-07-31 11:20:59 -0700215static float SC_distf2(float x1, float y1, float x2, float y2)
216{
217 float x = x2 - x1;
218 float y = y2 - y1;
Jason Sams1bada8c2009-08-09 17:01:55 -0700219 return sqrtf(x * x + y * y);
Romain Guy8839ca52009-07-31 11:20:59 -0700220}
221
222static float SC_distf3(float x1, float y1, float z1, float x2, float y2, float z2)
223{
224 float x = x2 - x1;
225 float y = y2 - y1;
226 float z = z2 - z1;
Jason Sams1bada8c2009-08-09 17:01:55 -0700227 return sqrtf(x * x + y * y + z * z);
Romain Guy8839ca52009-07-31 11:20:59 -0700228}
229
230static float SC_magf2(float a, float b)
231{
232 return sqrtf(a * a + b * b);
233}
234
235static float SC_magf3(float a, float b, float c)
236{
237 return sqrtf(a * a + b * b + c * c);
238}
239
240static float SC_radf(float degrees)
241{
Jason Sams1bada8c2009-08-09 17:01:55 -0700242 return degrees * DEG_TO_RAD;
Romain Guy8839ca52009-07-31 11:20:59 -0700243}
244
245static float SC_degf(float radians)
246{
Jason Sams1bada8c2009-08-09 17:01:55 -0700247 return radians * RAD_TO_DEG;
Romain Guy8839ca52009-07-31 11:20:59 -0700248}
249
250static float SC_lerpf(float start, float stop, float amount)
251{
252 return start + (stop - start) * amount;
253}
254
255static float SC_normf(float start, float stop, float value)
256{
257 return (value - start) / (stop - start);
258}
259
260static float SC_mapf(float minStart, float minStop, float maxStart, float maxStop, float value)
261{
262 return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart));
263}
Jason Samsc97bb882009-07-20 14:31:06 -0700264
Romain Guy584a3752009-07-30 18:45:01 -0700265//////////////////////////////////////////////////////////////////////////////
266// Time routines
267//////////////////////////////////////////////////////////////////////////////
Jason Samsc97bb882009-07-20 14:31:06 -0700268
Joe Onorato3370ec92009-08-09 11:39:02 -0700269static int32_t SC_second()
Romain Guy584a3752009-07-30 18:45:01 -0700270{
271 GET_TLS();
272
273 time_t rawtime;
274 time(&rawtime);
275
276 if (sc->mEnviroment.mTimeZone) {
277 struct tm timeinfo;
278 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
279 return timeinfo.tm_sec;
280 } else {
281 struct tm *timeinfo;
282 timeinfo = localtime(&rawtime);
283 return timeinfo->tm_sec;
284 }
285}
286
Joe Onorato3370ec92009-08-09 11:39:02 -0700287static int32_t SC_minute()
Romain Guy584a3752009-07-30 18:45:01 -0700288{
289 GET_TLS();
Jason Sams1bada8c2009-08-09 17:01:55 -0700290
Romain Guy584a3752009-07-30 18:45:01 -0700291 time_t rawtime;
292 time(&rawtime);
Jason Sams1bada8c2009-08-09 17:01:55 -0700293
Romain Guy584a3752009-07-30 18:45:01 -0700294 if (sc->mEnviroment.mTimeZone) {
295 struct tm timeinfo;
296 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
297 return timeinfo.tm_min;
298 } else {
299 struct tm *timeinfo;
300 timeinfo = localtime(&rawtime);
301 return timeinfo->tm_min;
302 }
Jason Sams1bada8c2009-08-09 17:01:55 -0700303}
Romain Guy584a3752009-07-30 18:45:01 -0700304
Joe Onorato3370ec92009-08-09 11:39:02 -0700305static int32_t SC_hour()
Romain Guy584a3752009-07-30 18:45:01 -0700306{
307 GET_TLS();
Jason Sams1bada8c2009-08-09 17:01:55 -0700308
Romain Guy584a3752009-07-30 18:45:01 -0700309 time_t rawtime;
310 time(&rawtime);
Jason Sams1bada8c2009-08-09 17:01:55 -0700311
Romain Guy584a3752009-07-30 18:45:01 -0700312 if (sc->mEnviroment.mTimeZone) {
313 struct tm timeinfo;
314 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
315 return timeinfo.tm_hour;
316 } else {
317 struct tm *timeinfo;
318 timeinfo = localtime(&rawtime);
319 return timeinfo->tm_hour;
320 }
Romain Guy8839ca52009-07-31 11:20:59 -0700321}
322
Joe Onorato3370ec92009-08-09 11:39:02 -0700323static int32_t SC_day()
Romain Guy8839ca52009-07-31 11:20:59 -0700324{
325 GET_TLS();
Jason Sams1bada8c2009-08-09 17:01:55 -0700326
Romain Guy8839ca52009-07-31 11:20:59 -0700327 time_t rawtime;
328 time(&rawtime);
Jason Sams1bada8c2009-08-09 17:01:55 -0700329
Romain Guy8839ca52009-07-31 11:20:59 -0700330 if (sc->mEnviroment.mTimeZone) {
331 struct tm timeinfo;
332 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
333 return timeinfo.tm_mday;
334 } else {
335 struct tm *timeinfo;
336 timeinfo = localtime(&rawtime);
337 return timeinfo->tm_mday;
338 }
Jason Sams1bada8c2009-08-09 17:01:55 -0700339}
Jason Samsc97bb882009-07-20 14:31:06 -0700340
Joe Onorato3370ec92009-08-09 11:39:02 -0700341static int32_t SC_month()
Romain Guy8839ca52009-07-31 11:20:59 -0700342{
343 GET_TLS();
Jason Sams1bada8c2009-08-09 17:01:55 -0700344
Romain Guy8839ca52009-07-31 11:20:59 -0700345 time_t rawtime;
346 time(&rawtime);
Jason Sams1bada8c2009-08-09 17:01:55 -0700347
Romain Guy8839ca52009-07-31 11:20:59 -0700348 if (sc->mEnviroment.mTimeZone) {
349 struct tm timeinfo;
350 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
351 return timeinfo.tm_mon;
352 } else {
353 struct tm *timeinfo;
354 timeinfo = localtime(&rawtime);
355 return timeinfo->tm_mon;
356 }
Jason Sams1bada8c2009-08-09 17:01:55 -0700357}
Romain Guy8839ca52009-07-31 11:20:59 -0700358
Joe Onorato3370ec92009-08-09 11:39:02 -0700359static int32_t SC_year()
Romain Guy8839ca52009-07-31 11:20:59 -0700360{
361 GET_TLS();
Jason Sams1bada8c2009-08-09 17:01:55 -0700362
Romain Guy8839ca52009-07-31 11:20:59 -0700363 time_t rawtime;
364 time(&rawtime);
Jason Sams1bada8c2009-08-09 17:01:55 -0700365
Romain Guy8839ca52009-07-31 11:20:59 -0700366 if (sc->mEnviroment.mTimeZone) {
367 struct tm timeinfo;
368 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
369 return timeinfo.tm_year;
370 } else {
371 struct tm *timeinfo;
372 timeinfo = localtime(&rawtime);
373 return timeinfo->tm_year;
374 }
375}
376
Joe Onorato3370ec92009-08-09 11:39:02 -0700377static int32_t SC_uptimeMillis()
378{
379 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
380}
381
382static int32_t SC_startTimeMillis()
383{
384 GET_TLS();
385 return sc->mEnviroment.mStartTimeMillis;
386}
387
388static int32_t SC_elapsedTimeMillis()
389{
390 GET_TLS();
391 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC))
392 - sc->mEnviroment.mStartTimeMillis;
393}
394
Jason Samsc97bb882009-07-20 14:31:06 -0700395//////////////////////////////////////////////////////////////////////////////
396// Matrix routines
397//////////////////////////////////////////////////////////////////////////////
398
399
400static void SC_matrixLoadIdentity(rsc_Matrix *mat)
401{
402 Matrix *m = reinterpret_cast<Matrix *>(mat);
403 m->loadIdentity();
404}
405
406static void SC_matrixLoadFloat(rsc_Matrix *mat, const float *f)
407{
408 Matrix *m = reinterpret_cast<Matrix *>(mat);
409 m->load(f);
410}
411
412static void SC_matrixLoadMat(rsc_Matrix *mat, const rsc_Matrix *newmat)
413{
414 Matrix *m = reinterpret_cast<Matrix *>(mat);
415 m->load(reinterpret_cast<const Matrix *>(newmat));
416}
417
418static void SC_matrixLoadRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
419{
420 Matrix *m = reinterpret_cast<Matrix *>(mat);
421 m->loadRotate(rot, x, y, z);
422}
423
424static void SC_matrixLoadScale(rsc_Matrix *mat, float x, float y, float z)
425{
426 Matrix *m = reinterpret_cast<Matrix *>(mat);
427 m->loadScale(x, y, z);
428}
429
430static void SC_matrixLoadTranslate(rsc_Matrix *mat, float x, float y, float z)
431{
432 Matrix *m = reinterpret_cast<Matrix *>(mat);
433 m->loadTranslate(x, y, z);
434}
435
436static void SC_matrixLoadMultiply(rsc_Matrix *mat, const rsc_Matrix *lhs, const rsc_Matrix *rhs)
437{
438 Matrix *m = reinterpret_cast<Matrix *>(mat);
439 m->loadMultiply(reinterpret_cast<const Matrix *>(lhs),
440 reinterpret_cast<const Matrix *>(rhs));
441}
442
443static void SC_matrixMultiply(rsc_Matrix *mat, const rsc_Matrix *rhs)
444{
445 Matrix *m = reinterpret_cast<Matrix *>(mat);
446 m->multiply(reinterpret_cast<const Matrix *>(rhs));
447}
448
449static void SC_matrixRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
450{
451 Matrix *m = reinterpret_cast<Matrix *>(mat);
452 m->rotate(rot, x, y, z);
453}
454
455static void SC_matrixScale(rsc_Matrix *mat, float x, float y, float z)
456{
457 Matrix *m = reinterpret_cast<Matrix *>(mat);
458 m->scale(x, y, z);
459}
460
461static void SC_matrixTranslate(rsc_Matrix *mat, float x, float y, float z)
462{
463 Matrix *m = reinterpret_cast<Matrix *>(mat);
464 m->translate(x, y, z);
465}
466
467
Jason Sams334ea0c2009-08-17 13:56:09 -0700468static void SC_vec2Rand(float *vec, float maxLen)
469{
470 float angle = SC_randf(PI * 2);
471 float len = SC_randf(maxLen);
472 vec[0] = len * sinf(angle);
473 vec[1] = len * cosf(angle);
474}
475
Jason Samsc97bb882009-07-20 14:31:06 -0700476
477
478//////////////////////////////////////////////////////////////////////////////
479// Context
480//////////////////////////////////////////////////////////////////////////////
481
482static void SC_bindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va)
483{
484 GET_TLS();
485 rsi_ProgramFragmentBindTexture(rsc,
486 static_cast<ProgramFragment *>(vpf),
487 slot,
488 static_cast<Allocation *>(va));
489
490}
491
492static void SC_bindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs)
493{
494 GET_TLS();
495 rsi_ProgramFragmentBindSampler(rsc,
496 static_cast<ProgramFragment *>(vpf),
497 slot,
498 static_cast<Sampler *>(vs));
499
500}
501
502static void SC_bindProgramFragmentStore(RsProgramFragmentStore pfs)
503{
504 GET_TLS();
505 rsi_ContextBindProgramFragmentStore(rsc, pfs);
506
507}
508
509static void SC_bindProgramFragment(RsProgramFragment pf)
510{
511 GET_TLS();
512 rsi_ContextBindProgramFragment(rsc, pf);
513
514}
515
Jason Samsee411122009-07-21 12:20:54 -0700516static void SC_bindProgramVertex(RsProgramVertex pv)
517{
518 GET_TLS();
519 rsi_ContextBindProgramVertex(rsc, pv);
520
521}
Jason Samsc97bb882009-07-20 14:31:06 -0700522
523//////////////////////////////////////////////////////////////////////////////
Jason Samsb0ec1b42009-07-28 12:02:16 -0700524// VP
525//////////////////////////////////////////////////////////////////////////////
526
527static void SC_vpLoadModelMatrix(const rsc_Matrix *m)
528{
529 GET_TLS();
530 rsc->getVertex()->setModelviewMatrix(m);
531}
532
533static void SC_vpLoadTextureMatrix(const rsc_Matrix *m)
534{
535 GET_TLS();
536 rsc->getVertex()->setTextureMatrix(m);
537}
538
539
540
541//////////////////////////////////////////////////////////////////////////////
Jason Samsc97bb882009-07-20 14:31:06 -0700542// Drawing
543//////////////////////////////////////////////////////////////////////////////
544
545static void SC_drawTriangleMesh(RsTriangleMesh mesh)
546{
547 GET_TLS();
548 rsi_TriangleMeshRender(rsc, mesh);
549}
550
551static void SC_drawTriangleMeshRange(RsTriangleMesh mesh, uint32_t start, uint32_t count)
552{
553 GET_TLS();
554 rsi_TriangleMeshRenderRange(rsc, mesh, start, count);
555}
556
Romain Guy6c0cc6d2009-08-07 15:40:32 -0700557static void SC_drawLine(float x1, float y1, float z1,
558 float x2, float y2, float z2)
559{
560 GET_TLS();
561 rsc->setupCheck();
562
563 float vtx[] = { x1, y1, z1, x2, y2, z2 };
564
565 glBindBuffer(GL_ARRAY_BUFFER, 0);
566 glEnableClientState(GL_VERTEX_ARRAY);
567 glVertexPointer(3, GL_FLOAT, 0, vtx);
568
569 glDisableClientState(GL_NORMAL_ARRAY);
570 glDisableClientState(GL_COLOR_ARRAY);
571
572 glDrawArrays(GL_LINES, 0, 2);
573}
574
Romain Guy8f5c94b2009-08-08 18:30:19 -0700575static void SC_drawQuadTexCoords(float x1, float y1, float z1,
576 float u1, float v1,
577 float x2, float y2, float z2,
578 float u2, float v2,
579 float x3, float y3, float z3,
580 float u3, float v3,
581 float x4, float y4, float z4,
582 float u4, float v4)
Jason Samsc97bb882009-07-20 14:31:06 -0700583{
584 GET_TLS();
Jason Sams40a29e82009-08-10 14:55:26 -0700585
Jason Samsc97bb882009-07-20 14:31:06 -0700586 //LOGE("Quad");
587 //LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1);
588 //LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2);
589 //LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3);
590 //LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4);
Jason Sams40a29e82009-08-10 14:55:26 -0700591
Jason Samsc97bb882009-07-20 14:31:06 -0700592 float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4};
Romain Guy8f5c94b2009-08-08 18:30:19 -0700593 const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4};
Jason Samsc97bb882009-07-20 14:31:06 -0700594
595 rsc->setupCheck();
596
597 glBindBuffer(GL_ARRAY_BUFFER, 0);
598 //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]);
599
600 glEnableClientState(GL_VERTEX_ARRAY);
601 glVertexPointer(3, GL_FLOAT, 0, vtx);
602
603 glClientActiveTexture(GL_TEXTURE0);
604 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
605 glTexCoordPointer(2, GL_FLOAT, 0, tex);
606 glClientActiveTexture(GL_TEXTURE1);
607 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
608 glTexCoordPointer(2, GL_FLOAT, 0, tex);
609 glClientActiveTexture(GL_TEXTURE0);
610
611 glDisableClientState(GL_NORMAL_ARRAY);
612 glDisableClientState(GL_COLOR_ARRAY);
613
614 //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr);
615
616 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
617}
618
Romain Guy8f5c94b2009-08-08 18:30:19 -0700619static void SC_drawQuad(float x1, float y1, float z1,
620 float x2, float y2, float z2,
621 float x3, float y3, float z3,
622 float x4, float y4, float z4)
623{
624 SC_drawQuadTexCoords(x1, y1, z1, 0, 1,
625 x2, y2, z2, 1, 1,
626 x3, y3, z3, 1, 0,
627 x4, y4, z4, 0, 0);
628}
629
Jason Sams6f5c61c2009-07-28 17:20:11 -0700630static void SC_drawRect(float x1, float y1,
631 float x2, float y2, float z)
632{
633 SC_drawQuad(x1, y2, z,
634 x2, y2, z,
635 x2, y1, z,
636 x1, y1, z);
637}
638
Jason Sams1bada8c2009-08-09 17:01:55 -0700639static void SC_drawSimpleMesh(RsSimpleMesh vsm)
640{
641 GET_TLS();
642 SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
643 rsc->setupCheck();
644 sm->render();
645}
646
647static void SC_drawSimpleMeshRange(RsSimpleMesh vsm, uint32_t start, uint32_t len)
648{
649 GET_TLS();
650 SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
651 rsc->setupCheck();
652 sm->renderRange(start, len);
653}
654
655
Jason Samsc97bb882009-07-20 14:31:06 -0700656//////////////////////////////////////////////////////////////////////////////
657//
658//////////////////////////////////////////////////////////////////////////////
659
Jason Samsc97bb882009-07-20 14:31:06 -0700660static void SC_color(float r, float g, float b, float a)
661{
662 glColor4f(r, g, b, a);
663}
664
Romain Guyb62627e2009-08-06 22:52:13 -0700665static void SC_ambient(float r, float g, float b, float a)
666{
667 GLfloat params[] = { r, g, b, a };
668 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, params);
669}
670
671static void SC_diffuse(float r, float g, float b, float a)
672{
673 GLfloat params[] = { r, g, b, a };
674 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, params);
675}
676
677static void SC_specular(float r, float g, float b, float a)
678{
679 GLfloat params[] = { r, g, b, a };
680 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, params);
681}
682
683static void SC_emission(float r, float g, float b, float a)
684{
685 GLfloat params[] = { r, g, b, a };
686 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, params);
687}
688
Romain Guy6c0cc6d2009-08-07 15:40:32 -0700689static void SC_shininess(float s)
Romain Guyb62627e2009-08-06 22:52:13 -0700690{
Romain Guy6c0cc6d2009-08-07 15:40:32 -0700691 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, s);
Romain Guyb62627e2009-08-06 22:52:13 -0700692}
693
Romain Guya32d1002009-07-31 15:33:59 -0700694static void SC_hsb(float h, float s, float b, float a)
695{
696 float red = 0.0f;
697 float green = 0.0f;
698 float blue = 0.0f;
Jason Sams1bada8c2009-08-09 17:01:55 -0700699
Romain Guya32d1002009-07-31 15:33:59 -0700700 float x = h;
701 float y = s;
702 float z = b;
Jason Sams1bada8c2009-08-09 17:01:55 -0700703
Romain Guya32d1002009-07-31 15:33:59 -0700704 float hf = (x - (int) x) * 6.0f;
705 int ihf = (int) hf;
706 float f = hf - ihf;
707 float pv = z * (1.0f - y);
708 float qv = z * (1.0f - y * f);
709 float tv = z * (1.0f - y * (1.0f - f));
Jason Sams1bada8c2009-08-09 17:01:55 -0700710
Romain Guya32d1002009-07-31 15:33:59 -0700711 switch (ihf) {
712 case 0: // Red is the dominant color
713 red = z;
714 green = tv;
715 blue = pv;
716 break;
717 case 1: // Green is the dominant color
718 red = qv;
719 green = z;
720 blue = pv;
721 break;
722 case 2:
723 red = pv;
724 green = z;
725 blue = tv;
726 break;
727 case 3: // Blue is the dominant color
728 red = pv;
729 green = qv;
730 blue = z;
731 break;
732 case 4:
733 red = tv;
734 green = pv;
735 blue = z;
736 break;
737 case 5: // Red is the dominant color
738 red = z;
739 green = pv;
740 blue = qv;
741 break;
742 }
Jason Sams1bada8c2009-08-09 17:01:55 -0700743
Romain Guya32d1002009-07-31 15:33:59 -0700744 glColor4f(red, green, blue, a);
745}
746
Jason Samsb0ec1b42009-07-28 12:02:16 -0700747static void SC_uploadToTexture(RsAllocation va, uint32_t baseMipLevel)
Jason Samsc97bb882009-07-20 14:31:06 -0700748{
749 GET_TLS();
750 rsi_AllocationUploadToTexture(rsc, va, baseMipLevel);
751}
752
Jason Sams1bada8c2009-08-09 17:01:55 -0700753static void SC_uploadToBufferObject(RsAllocation va)
754{
755 GET_TLS();
756 rsi_AllocationUploadToBufferObject(rsc, va);
757}
758
Jason Samsc97bb882009-07-20 14:31:06 -0700759static void SC_ClearColor(float r, float g, float b, float a)
760{
761 //LOGE("c %f %f %f %f", r, g, b, a);
762 GET_TLS();
763 sc->mEnviroment.mClearColor[0] = r;
764 sc->mEnviroment.mClearColor[1] = g;
765 sc->mEnviroment.mClearColor[2] = b;
766 sc->mEnviroment.mClearColor[3] = a;
767}
768
Jason Samsb0ec1b42009-07-28 12:02:16 -0700769static void SC_debugF(const char *s, float f)
770{
771 LOGE("%s %f", s, f);
772}
773
774static void SC_debugI32(const char *s, int32_t i)
775{
776 LOGE("%s %i", s, i);
777}
778
Jason Sams40a29e82009-08-10 14:55:26 -0700779static uint32_t SC_getWidth()
780{
781 GET_TLS();
782 return rsc->getWidth();
783}
Jason Samsc97bb882009-07-20 14:31:06 -0700784
Jason Sams40a29e82009-08-10 14:55:26 -0700785static uint32_t SC_getHeight()
786{
787 GET_TLS();
788 return rsc->getHeight();
789}
Jason Samsc97bb882009-07-20 14:31:06 -0700790
Jason Sams334ea0c2009-08-17 13:56:09 -0700791static uint32_t SC_colorFloatRGBAtoUNorm8(float r, float g, float b, float a)
792{
793 uint32_t c = 0;
794 c |= (uint32_t)(r * 255.f + 0.5f);
795 c |= ((uint32_t)(g * 255.f + 0.5f)) << 8;
796 c |= ((uint32_t)(b * 255.f + 0.5f)) << 16;
797 c |= ((uint32_t)(a * 255.f + 0.5f)) << 24;
798 return c;
799}
800
801static uint32_t SC_colorFloatRGBAto565(float r, float g, float b)
802{
803 uint32_t ir = (uint32_t)(r * 255.f + 0.5f);
804 uint32_t ig = (uint32_t)(g * 255.f + 0.5f);
805 uint32_t ib = (uint32_t)(b * 255.f + 0.5f);
806 return rs888to565(ir, ig, ib);
807}
808
Jason Samsc97bb882009-07-20 14:31:06 -0700809//////////////////////////////////////////////////////////////////////////////
810// Class implementation
811//////////////////////////////////////////////////////////////////////////////
812
813ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
814 // IO
815 { "loadI32", (void *)&SC_loadI32,
816 "int", "(int, int)" },
817 //{ "loadU32", (void *)&SC_loadU32, "unsigned int", "(int, int)" },
818 { "loadF", (void *)&SC_loadF,
819 "float", "(int, int)" },
Romain Guya2136d62009-08-04 17:19:48 -0700820 { "loadArrayF", (void *)&SC_loadArrayF,
Romain Guyf8e136d2009-08-06 12:40:41 -0700821 "float*", "(int, int)" },
Romain Guya2136d62009-08-04 17:19:48 -0700822 { "loadArrayI32", (void *)&SC_loadArrayI32,
Romain Guyf8e136d2009-08-06 12:40:41 -0700823 "int*", "(int, int)" },
Jason Samsc97bb882009-07-20 14:31:06 -0700824 { "loadVec4", (void *)&SC_loadVec4,
825 "void", "(int, int, float *)" },
826 { "loadMatrix", (void *)&SC_loadMatrix,
827 "void", "(int, int, float *)" },
828 { "storeI32", (void *)&SC_storeI32,
829 "void", "(int, int, int)" },
830 //{ "storeU32", (void *)&SC_storeU32, "void", "(int, int, unsigned int)" },
831 { "storeF", (void *)&SC_storeF,
832 "void", "(int, int, float)" },
833 { "storeVec4", (void *)&SC_storeVec4,
834 "void", "(int, int, float *)" },
835 { "storeMatrix", (void *)&SC_storeMatrix,
836 "void", "(int, int, float *)" },
Romain Guyb62627e2009-08-06 22:52:13 -0700837 { "loadTriangleMeshVerticesF", (void *)&SC_loadTriangleMeshVerticesF,
838 "float*", "(int)" },
839 { "updateTriangleMesh", (void *)&SC_updateTriangleMesh,
840 "void", "(int)" },
Jason Samsc97bb882009-07-20 14:31:06 -0700841
842 // math
Romain Guya9d2d5e2009-08-09 17:04:54 -0700843 { "modf", (void *)&fmod,
844 "float", "(float, float)" },
Romain Guy8f5c94b2009-08-08 18:30:19 -0700845 { "abs", (void *)&abs,
846 "int", "(int)" },
847 { "absf", (void *)&fabs,
848 "float", "(float)" },
Jason Samsc97bb882009-07-20 14:31:06 -0700849 { "sinf", (void *)&sinf,
850 "float", "(float)" },
851 { "cosf", (void *)&cosf,
852 "float", "(float)" },
Romain Guy8839ca52009-07-31 11:20:59 -0700853 { "asinf", (void *)&asinf,
854 "float", "(float)" },
855 { "acosf", (void *)&acosf,
856 "float", "(float)" },
857 { "atanf", (void *)&atanf,
858 "float", "(float)" },
859 { "atan2f", (void *)&atan2f,
Romain Guya32d1002009-07-31 15:33:59 -0700860 "float", "(float, float)" },
Jason Sams6f5c61c2009-07-28 17:20:11 -0700861 { "fabsf", (void *)&fabsf,
Jason Samsc97bb882009-07-20 14:31:06 -0700862 "float", "(float)" },
863 { "randf", (void *)&SC_randf,
864 "float", "(float)" },
Romain Guy8839ca52009-07-31 11:20:59 -0700865 { "randf2", (void *)&SC_randf2,
866 "float", "(float, float)" },
Jason Samsb0ec1b42009-07-28 12:02:16 -0700867 { "floorf", (void *)&floorf,
868 "float", "(float)" },
869 { "ceilf", (void *)&ceilf,
870 "float", "(float)" },
Romain Guy8839ca52009-07-31 11:20:59 -0700871 { "expf", (void *)&expf,
872 "float", "(float)" },
873 { "logf", (void *)&logf,
874 "float", "(float)" },
875 { "powf", (void *)&powf,
876 "float", "(float, float)" },
877 { "maxf", (void *)&SC_maxf,
878 "float", "(float, float)" },
879 { "minf", (void *)&SC_minf,
880 "float", "(float, float)" },
Romain Guy8f5c94b2009-08-08 18:30:19 -0700881 { "sqrt", (void *)&sqrt,
882 "int", "(int)" },
Romain Guy8839ca52009-07-31 11:20:59 -0700883 { "sqrtf", (void *)&sqrtf,
884 "float", "(float)" },
Romain Guy8f5c94b2009-08-08 18:30:19 -0700885 { "sqr", (void *)&SC_sqr,
886 "int", "(int)" },
Romain Guy8839ca52009-07-31 11:20:59 -0700887 { "sqrf", (void *)&SC_sqrf,
888 "float", "(float)" },
Romain Guya9d2d5e2009-08-09 17:04:54 -0700889 { "clamp", (void *)&SC_clamp,
890 "int", "(int, int, int)" },
Romain Guy8839ca52009-07-31 11:20:59 -0700891 { "clampf", (void *)&SC_clampf,
892 "float", "(float, float, float)" },
893 { "distf2", (void *)&SC_distf2,
894 "float", "(float, float, float, float)" },
895 { "distf3", (void *)&SC_distf3,
896 "float", "(float, float, float, float, float, float)" },
897 { "magf2", (void *)&SC_magf2,
898 "float", "(float, float)" },
899 { "magf3", (void *)&SC_magf3,
900 "float", "(float, float, float)" },
901 { "radf", (void *)&SC_radf,
902 "float", "(float)" },
903 { "degf", (void *)&SC_degf,
904 "float", "(float)" },
905 { "lerpf", (void *)&SC_lerpf,
906 "float", "(float, float, float)" },
907 { "normf", (void *)&SC_normf,
908 "float", "(float, float, float)" },
909 { "mapf", (void *)&SC_mapf,
910 "float", "(float, float, float, float, float)" },
Romain Guyecc7ca032009-08-03 21:12:51 -0700911 { "noisef", (void *)&SC_noisef,
912 "float", "(float)" },
913 { "noisef2", (void *)&SC_noisef2,
914 "float", "(float, float)" },
915 { "noisef3", (void *)&SC_noisef3,
916 "float", "(float, float, float)" },
917 { "turbulencef2", (void *)&SC_turbulencef2,
918 "float", "(float, float, float)" },
919 { "turbulencef3", (void *)&SC_turbulencef3,
920 "float", "(float, float, float, float)" },
Jason Samsc97bb882009-07-20 14:31:06 -0700921
Romain Guy584a3752009-07-30 18:45:01 -0700922 // time
923 { "second", (void *)&SC_second,
924 "int", "()" },
925 { "minute", (void *)&SC_minute,
926 "int", "()" },
927 { "hour", (void *)&SC_hour,
928 "int", "()" },
Romain Guy8839ca52009-07-31 11:20:59 -0700929 { "day", (void *)&SC_day,
930 "int", "()" },
931 { "month", (void *)&SC_month,
932 "int", "()" },
933 { "year", (void *)&SC_year,
934 "int", "()" },
Joe Onorato3370ec92009-08-09 11:39:02 -0700935 { "uptimeMillis", (void*)&SC_uptimeMillis,
936 "int", "()" }, // TODO: use long instead
937 { "startTimeMillis", (void*)&SC_startTimeMillis,
938 "int", "()" }, // TODO: use long instead
939 { "elapsedTimeMillis", (void*)&SC_elapsedTimeMillis,
940 "int", "()" }, // TODO: use long instead
Romain Guy584a3752009-07-30 18:45:01 -0700941
Jason Samsc97bb882009-07-20 14:31:06 -0700942 // matrix
943 { "matrixLoadIdentity", (void *)&SC_matrixLoadIdentity,
944 "void", "(float *mat)" },
945 { "matrixLoadFloat", (void *)&SC_matrixLoadFloat,
946 "void", "(float *mat, float *f)" },
947 { "matrixLoadMat", (void *)&SC_matrixLoadMat,
948 "void", "(float *mat, float *newmat)" },
949 { "matrixLoadRotate", (void *)&SC_matrixLoadRotate,
950 "void", "(float *mat, float rot, float x, float y, float z)" },
951 { "matrixLoadScale", (void *)&SC_matrixLoadScale,
952 "void", "(float *mat, float x, float y, float z)" },
953 { "matrixLoadTranslate", (void *)&SC_matrixLoadTranslate,
954 "void", "(float *mat, float x, float y, float z)" },
955 { "matrixLoadMultiply", (void *)&SC_matrixLoadMultiply,
956 "void", "(float *mat, float *lhs, float *rhs)" },
957 { "matrixMultiply", (void *)&SC_matrixMultiply,
958 "void", "(float *mat, float *rhs)" },
959 { "matrixRotate", (void *)&SC_matrixRotate,
960 "void", "(float *mat, float rot, float x, float y, float z)" },
961 { "matrixScale", (void *)&SC_matrixScale,
962 "void", "(float *mat, float x, float y, float z)" },
963 { "matrixTranslate", (void *)&SC_matrixTranslate,
964 "void", "(float *mat, float x, float y, float z)" },
965
Jason Sams334ea0c2009-08-17 13:56:09 -0700966 // vector
967 { "vec2Rand", (void *)&SC_vec2Rand,
968 "void", "(float *vec, float maxLen)" },
969
Jason Samsc97bb882009-07-20 14:31:06 -0700970 // context
971 { "bindProgramFragment", (void *)&SC_bindProgramFragment,
972 "void", "(int)" },
973 { "bindProgramFragmentStore", (void *)&SC_bindProgramFragmentStore,
974 "void", "(int)" },
Jason Samsee411122009-07-21 12:20:54 -0700975 { "bindProgramVertex", (void *)&SC_bindProgramVertex,
976 "void", "(int)" },
Jason Samsc97bb882009-07-20 14:31:06 -0700977 { "bindSampler", (void *)&SC_bindSampler,
978 "void", "(int, int, int)" },
979 { "bindTexture", (void *)&SC_bindTexture,
980 "void", "(int, int, int)" },
981
Jason Samsb0ec1b42009-07-28 12:02:16 -0700982 // vp
Jason Samsfaf15202009-07-29 20:55:44 -0700983 { "vpLoadModelMatrix", (void *)&SC_vpLoadModelMatrix,
Jason Samsb0ec1b42009-07-28 12:02:16 -0700984 "void", "(void *)" },
Jason Samsfaf15202009-07-29 20:55:44 -0700985 { "vpLoadTextureMatrix", (void *)&SC_vpLoadTextureMatrix,
Jason Samsb0ec1b42009-07-28 12:02:16 -0700986 "void", "(void *)" },
987
988
989
Jason Samsc97bb882009-07-20 14:31:06 -0700990 // drawing
Jason Sams6f5c61c2009-07-28 17:20:11 -0700991 { "drawRect", (void *)&SC_drawRect,
992 "void", "(float x1, float y1, float x2, float y2, float z)" },
Jason Samsc97bb882009-07-20 14:31:06 -0700993 { "drawQuad", (void *)&SC_drawQuad,
994 "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 Guy8f5c94b2009-08-08 18:30:19 -0700995 { "drawQuadTexCoords", (void *)&SC_drawQuadTexCoords,
996 "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 Samsc97bb882009-07-20 14:31:06 -0700997 { "drawTriangleMesh", (void *)&SC_drawTriangleMesh,
998 "void", "(int mesh)" },
999 { "drawTriangleMeshRange", (void *)&SC_drawTriangleMeshRange,
1000 "void", "(int mesh, int start, int count)" },
Romain Guy6c0cc6d2009-08-07 15:40:32 -07001001 { "drawLine", (void *)&SC_drawLine,
1002 "void", "(float x1, float y1, float z1, float x2, float y2, float z2)" },
Jason Sams1bada8c2009-08-09 17:01:55 -07001003 { "drawSimpleMesh", (void *)&SC_drawSimpleMesh,
1004 "void", "(int ism)" },
1005 { "drawSimpleMeshRange", (void *)&SC_drawSimpleMeshRange,
1006 "void", "(int ism, int start, int len)" },
Jason Samsc97bb882009-07-20 14:31:06 -07001007
1008
1009 // misc
1010 { "pfClearColor", (void *)&SC_ClearColor,
1011 "void", "(float, float, float, float)" },
Jason Samsc97bb882009-07-20 14:31:06 -07001012 { "color", (void *)&SC_color,
1013 "void", "(float, float, float, float)" },
Romain Guya32d1002009-07-31 15:33:59 -07001014 { "hsb", (void *)&SC_hsb,
1015 "void", "(float, float, float, float)" },
Romain Guyb62627e2009-08-06 22:52:13 -07001016 { "ambient", (void *)&SC_ambient,
1017 "void", "(float, float, float, float)" },
1018 { "diffuse", (void *)&SC_diffuse,
1019 "void", "(float, float, float, float)" },
1020 { "specular", (void *)&SC_specular,
1021 "void", "(float, float, float, float)" },
1022 { "emission", (void *)&SC_emission,
1023 "void", "(float, float, float, float)" },
1024 { "shininess", (void *)&SC_shininess,
Romain Guy6c0cc6d2009-08-07 15:40:32 -07001025 "void", "(float)" },
Jason Samsc97bb882009-07-20 14:31:06 -07001026
Jason Samsb0ec1b42009-07-28 12:02:16 -07001027 { "uploadToTexture", (void *)&SC_uploadToTexture,
1028 "void", "(int, int)" },
Jason Sams1bada8c2009-08-09 17:01:55 -07001029 { "uploadToBufferObject", (void *)&SC_uploadToBufferObject,
1030 "void", "(int)" },
Jason Samsb0ec1b42009-07-28 12:02:16 -07001031
Jason Sams334ea0c2009-08-17 13:56:09 -07001032 { "colorFloatRGBAtoUNorm8", (void *)&SC_colorFloatRGBAtoUNorm8,
1033 "int", "(float, float, float, float)" },
1034 { "colorFloatRGBto565", (void *)&SC_colorFloatRGBAto565,
1035 "int", "(float, float, float)" },
1036
1037
Jason Sams40a29e82009-08-10 14:55:26 -07001038 { "getWidth", (void *)&SC_getWidth,
1039 "int", "()" },
1040 { "getHeight", (void *)&SC_getHeight,
1041 "int", "()" },
1042
1043
Jason Samsb0ec1b42009-07-28 12:02:16 -07001044
1045 { "debugF", (void *)&SC_debugF,
1046 "void", "(void *, float)" },
1047 { "debugI32", (void *)&SC_debugI32,
1048 "void", "(void *, int)" },
1049
1050
Jason Samsc97bb882009-07-20 14:31:06 -07001051 { NULL, NULL, NULL, NULL }
1052};
1053
1054const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym)
1055{
1056 ScriptCState::SymbolTable_t *syms = gSyms;
1057
1058 while (syms->mPtr) {
1059 if (!strcmp(syms->mName, sym)) {
1060 return syms;
1061 }
1062 syms++;
1063 }
1064 return NULL;
1065}
1066
1067void ScriptCState::appendDecls(String8 *str)
1068{
1069 ScriptCState::SymbolTable_t *syms = gSyms;
1070 while (syms->mPtr) {
1071 str->append(syms->mRet);
1072 str->append(" ");
1073 str->append(syms->mName);
1074 str->append(syms->mParam);
1075 str->append(";\n");
1076 syms++;
1077 }
1078}
1079
1080