blob: 5f8ee2a9ec807a99e53cc343e146905352604214 [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
Romain Guycac80a62009-08-18 11:39:17 -0700173static float SC_sinf_fast(float x)
174{
175 const float A = 1.0f / (2.0f * M_PI);
176 const float B = -16.0f;
177 const float C = 8.0f;
178
179 // scale angle for easy argument reduction
180 x *= A;
181
182 if (fabsf(x) >= 0.5f) {
183 // argument reduction
184 x = x - ceilf(x + 0.5f) + 1.0f;
185 }
186
187 const float y = B * x * fabsf(x) + C * x;
188 return 0.2215f * (y * fabsf(y) - y) + y;
189}
190
191static float SC_cosf_fast(float x)
192{
193 x += float(M_PI / 2);
194
195 const float A = 1.0f / (2.0f * M_PI);
196 const float B = -16.0f;
197 const float C = 8.0f;
198
199 // scale angle for easy argument reduction
200 x *= A;
201
202 if (fabsf(x) >= 0.5f) {
203 // argument reduction
204 x = x - ceilf(x + 0.5f) + 1.0f;
205 }
206
207 const float y = B * x * fabsf(x) + C * x;
208 return 0.2215f * (y * fabsf(y) - y) + y;
209}
210
Jason Samsc97bb882009-07-20 14:31:06 -0700211static float SC_randf(float max)
212{
213 float r = (float)rand();
214 return r / RAND_MAX * max;
215}
216
Romain Guy8839ca52009-07-31 11:20:59 -0700217static float SC_randf2(float min, float max)
218{
219 float r = (float)rand();
220 return r / RAND_MAX * (max - min) + min;
221}
222
223static float SC_clampf(float amount, float low, float high)
224{
225 return amount < low ? low : (amount > high ? high : amount);
226}
227
Romain Guya9d2d5e2009-08-09 17:04:54 -0700228static int SC_clamp(int amount, int low, int high)
229{
230 return amount < low ? low : (amount > high ? high : amount);
231}
232
Romain Guy8839ca52009-07-31 11:20:59 -0700233static float SC_maxf(float a, float b)
234{
Jason Sams1bada8c2009-08-09 17:01:55 -0700235 return a > b ? a : b;
Romain Guy8839ca52009-07-31 11:20:59 -0700236}
237
238static float SC_minf(float a, float b)
239{
Jason Sams1bada8c2009-08-09 17:01:55 -0700240 return a < b ? a : b;
Romain Guy8839ca52009-07-31 11:20:59 -0700241}
242
243static float SC_sqrf(float v)
244{
Jason Sams1bada8c2009-08-09 17:01:55 -0700245 return v * v;
Romain Guy8839ca52009-07-31 11:20:59 -0700246}
247
Romain Guy8f5c94b2009-08-08 18:30:19 -0700248static int SC_sqr(int v)
249{
250 return v * v;
251}
252
Romain Guy8839ca52009-07-31 11:20:59 -0700253static float SC_distf2(float x1, float y1, float x2, float y2)
254{
255 float x = x2 - x1;
256 float y = y2 - y1;
Jason Sams1bada8c2009-08-09 17:01:55 -0700257 return sqrtf(x * x + y * y);
Romain Guy8839ca52009-07-31 11:20:59 -0700258}
259
260static float SC_distf3(float x1, float y1, float z1, float x2, float y2, float z2)
261{
262 float x = x2 - x1;
263 float y = y2 - y1;
264 float z = z2 - z1;
Jason Sams1bada8c2009-08-09 17:01:55 -0700265 return sqrtf(x * x + y * y + z * z);
Romain Guy8839ca52009-07-31 11:20:59 -0700266}
267
268static float SC_magf2(float a, float b)
269{
270 return sqrtf(a * a + b * b);
271}
272
273static float SC_magf3(float a, float b, float c)
274{
275 return sqrtf(a * a + b * b + c * c);
276}
277
278static float SC_radf(float degrees)
279{
Jason Sams1bada8c2009-08-09 17:01:55 -0700280 return degrees * DEG_TO_RAD;
Romain Guy8839ca52009-07-31 11:20:59 -0700281}
282
283static float SC_degf(float radians)
284{
Jason Sams1bada8c2009-08-09 17:01:55 -0700285 return radians * RAD_TO_DEG;
Romain Guy8839ca52009-07-31 11:20:59 -0700286}
287
288static float SC_lerpf(float start, float stop, float amount)
289{
290 return start + (stop - start) * amount;
291}
292
293static float SC_normf(float start, float stop, float value)
294{
295 return (value - start) / (stop - start);
296}
297
298static float SC_mapf(float minStart, float minStop, float maxStart, float maxStop, float value)
299{
300 return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart));
301}
Jason Samsc97bb882009-07-20 14:31:06 -0700302
Romain Guy584a3752009-07-30 18:45:01 -0700303//////////////////////////////////////////////////////////////////////////////
304// Time routines
305//////////////////////////////////////////////////////////////////////////////
Jason Samsc97bb882009-07-20 14:31:06 -0700306
Joe Onorato3370ec92009-08-09 11:39:02 -0700307static int32_t SC_second()
Romain Guy584a3752009-07-30 18:45:01 -0700308{
309 GET_TLS();
310
311 time_t rawtime;
312 time(&rawtime);
313
314 if (sc->mEnviroment.mTimeZone) {
315 struct tm timeinfo;
316 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
317 return timeinfo.tm_sec;
318 } else {
319 struct tm *timeinfo;
320 timeinfo = localtime(&rawtime);
321 return timeinfo->tm_sec;
322 }
323}
324
Joe Onorato3370ec92009-08-09 11:39:02 -0700325static int32_t SC_minute()
Romain Guy584a3752009-07-30 18:45:01 -0700326{
327 GET_TLS();
Jason Sams1bada8c2009-08-09 17:01:55 -0700328
Romain Guy584a3752009-07-30 18:45:01 -0700329 time_t rawtime;
330 time(&rawtime);
Jason Sams1bada8c2009-08-09 17:01:55 -0700331
Romain Guy584a3752009-07-30 18:45:01 -0700332 if (sc->mEnviroment.mTimeZone) {
333 struct tm timeinfo;
334 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
335 return timeinfo.tm_min;
336 } else {
337 struct tm *timeinfo;
338 timeinfo = localtime(&rawtime);
339 return timeinfo->tm_min;
340 }
Jason Sams1bada8c2009-08-09 17:01:55 -0700341}
Romain Guy584a3752009-07-30 18:45:01 -0700342
Joe Onorato3370ec92009-08-09 11:39:02 -0700343static int32_t SC_hour()
Romain Guy584a3752009-07-30 18:45:01 -0700344{
345 GET_TLS();
Jason Sams1bada8c2009-08-09 17:01:55 -0700346
Romain Guy584a3752009-07-30 18:45:01 -0700347 time_t rawtime;
348 time(&rawtime);
Jason Sams1bada8c2009-08-09 17:01:55 -0700349
Romain Guy584a3752009-07-30 18:45:01 -0700350 if (sc->mEnviroment.mTimeZone) {
351 struct tm timeinfo;
352 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
353 return timeinfo.tm_hour;
354 } else {
355 struct tm *timeinfo;
356 timeinfo = localtime(&rawtime);
357 return timeinfo->tm_hour;
358 }
Romain Guy8839ca52009-07-31 11:20:59 -0700359}
360
Joe Onorato3370ec92009-08-09 11:39:02 -0700361static int32_t SC_day()
Romain Guy8839ca52009-07-31 11:20:59 -0700362{
363 GET_TLS();
Jason Sams1bada8c2009-08-09 17:01:55 -0700364
Romain Guy8839ca52009-07-31 11:20:59 -0700365 time_t rawtime;
366 time(&rawtime);
Jason Sams1bada8c2009-08-09 17:01:55 -0700367
Romain Guy8839ca52009-07-31 11:20:59 -0700368 if (sc->mEnviroment.mTimeZone) {
369 struct tm timeinfo;
370 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
371 return timeinfo.tm_mday;
372 } else {
373 struct tm *timeinfo;
374 timeinfo = localtime(&rawtime);
375 return timeinfo->tm_mday;
376 }
Jason Sams1bada8c2009-08-09 17:01:55 -0700377}
Jason Samsc97bb882009-07-20 14:31:06 -0700378
Joe Onorato3370ec92009-08-09 11:39:02 -0700379static int32_t SC_month()
Romain Guy8839ca52009-07-31 11:20:59 -0700380{
381 GET_TLS();
Jason Sams1bada8c2009-08-09 17:01:55 -0700382
Romain Guy8839ca52009-07-31 11:20:59 -0700383 time_t rawtime;
384 time(&rawtime);
Jason Sams1bada8c2009-08-09 17:01:55 -0700385
Romain Guy8839ca52009-07-31 11:20:59 -0700386 if (sc->mEnviroment.mTimeZone) {
387 struct tm timeinfo;
388 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
389 return timeinfo.tm_mon;
390 } else {
391 struct tm *timeinfo;
392 timeinfo = localtime(&rawtime);
393 return timeinfo->tm_mon;
394 }
Jason Sams1bada8c2009-08-09 17:01:55 -0700395}
Romain Guy8839ca52009-07-31 11:20:59 -0700396
Joe Onorato3370ec92009-08-09 11:39:02 -0700397static int32_t SC_year()
Romain Guy8839ca52009-07-31 11:20:59 -0700398{
399 GET_TLS();
Jason Sams1bada8c2009-08-09 17:01:55 -0700400
Romain Guy8839ca52009-07-31 11:20:59 -0700401 time_t rawtime;
402 time(&rawtime);
Jason Sams1bada8c2009-08-09 17:01:55 -0700403
Romain Guy8839ca52009-07-31 11:20:59 -0700404 if (sc->mEnviroment.mTimeZone) {
405 struct tm timeinfo;
406 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
407 return timeinfo.tm_year;
408 } else {
409 struct tm *timeinfo;
410 timeinfo = localtime(&rawtime);
411 return timeinfo->tm_year;
412 }
413}
414
Joe Onorato3370ec92009-08-09 11:39:02 -0700415static int32_t SC_uptimeMillis()
416{
417 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
418}
419
420static int32_t SC_startTimeMillis()
421{
422 GET_TLS();
423 return sc->mEnviroment.mStartTimeMillis;
424}
425
426static int32_t SC_elapsedTimeMillis()
427{
428 GET_TLS();
429 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC))
430 - sc->mEnviroment.mStartTimeMillis;
431}
432
Jason Samsc97bb882009-07-20 14:31:06 -0700433//////////////////////////////////////////////////////////////////////////////
434// Matrix routines
435//////////////////////////////////////////////////////////////////////////////
436
437
438static void SC_matrixLoadIdentity(rsc_Matrix *mat)
439{
440 Matrix *m = reinterpret_cast<Matrix *>(mat);
441 m->loadIdentity();
442}
443
444static void SC_matrixLoadFloat(rsc_Matrix *mat, const float *f)
445{
446 Matrix *m = reinterpret_cast<Matrix *>(mat);
447 m->load(f);
448}
449
450static void SC_matrixLoadMat(rsc_Matrix *mat, const rsc_Matrix *newmat)
451{
452 Matrix *m = reinterpret_cast<Matrix *>(mat);
453 m->load(reinterpret_cast<const Matrix *>(newmat));
454}
455
456static void SC_matrixLoadRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
457{
458 Matrix *m = reinterpret_cast<Matrix *>(mat);
459 m->loadRotate(rot, x, y, z);
460}
461
462static void SC_matrixLoadScale(rsc_Matrix *mat, float x, float y, float z)
463{
464 Matrix *m = reinterpret_cast<Matrix *>(mat);
465 m->loadScale(x, y, z);
466}
467
468static void SC_matrixLoadTranslate(rsc_Matrix *mat, float x, float y, float z)
469{
470 Matrix *m = reinterpret_cast<Matrix *>(mat);
471 m->loadTranslate(x, y, z);
472}
473
474static void SC_matrixLoadMultiply(rsc_Matrix *mat, const rsc_Matrix *lhs, const rsc_Matrix *rhs)
475{
476 Matrix *m = reinterpret_cast<Matrix *>(mat);
477 m->loadMultiply(reinterpret_cast<const Matrix *>(lhs),
478 reinterpret_cast<const Matrix *>(rhs));
479}
480
481static void SC_matrixMultiply(rsc_Matrix *mat, const rsc_Matrix *rhs)
482{
483 Matrix *m = reinterpret_cast<Matrix *>(mat);
484 m->multiply(reinterpret_cast<const Matrix *>(rhs));
485}
486
487static void SC_matrixRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
488{
489 Matrix *m = reinterpret_cast<Matrix *>(mat);
490 m->rotate(rot, x, y, z);
491}
492
493static void SC_matrixScale(rsc_Matrix *mat, float x, float y, float z)
494{
495 Matrix *m = reinterpret_cast<Matrix *>(mat);
496 m->scale(x, y, z);
497}
498
499static void SC_matrixTranslate(rsc_Matrix *mat, float x, float y, float z)
500{
501 Matrix *m = reinterpret_cast<Matrix *>(mat);
502 m->translate(x, y, z);
503}
504
505
Jason Sams334ea0c2009-08-17 13:56:09 -0700506static void SC_vec2Rand(float *vec, float maxLen)
507{
508 float angle = SC_randf(PI * 2);
509 float len = SC_randf(maxLen);
510 vec[0] = len * sinf(angle);
511 vec[1] = len * cosf(angle);
512}
513
Jason Samsc97bb882009-07-20 14:31:06 -0700514
515
516//////////////////////////////////////////////////////////////////////////////
517// Context
518//////////////////////////////////////////////////////////////////////////////
519
520static void SC_bindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va)
521{
522 GET_TLS();
523 rsi_ProgramFragmentBindTexture(rsc,
524 static_cast<ProgramFragment *>(vpf),
525 slot,
526 static_cast<Allocation *>(va));
527
528}
529
530static void SC_bindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs)
531{
532 GET_TLS();
533 rsi_ProgramFragmentBindSampler(rsc,
534 static_cast<ProgramFragment *>(vpf),
535 slot,
536 static_cast<Sampler *>(vs));
537
538}
539
540static void SC_bindProgramFragmentStore(RsProgramFragmentStore pfs)
541{
542 GET_TLS();
543 rsi_ContextBindProgramFragmentStore(rsc, pfs);
544
545}
546
547static void SC_bindProgramFragment(RsProgramFragment pf)
548{
549 GET_TLS();
550 rsi_ContextBindProgramFragment(rsc, pf);
551
552}
553
Jason Samsee411122009-07-21 12:20:54 -0700554static void SC_bindProgramVertex(RsProgramVertex pv)
555{
556 GET_TLS();
557 rsi_ContextBindProgramVertex(rsc, pv);
558
559}
Jason Samsc97bb882009-07-20 14:31:06 -0700560
561//////////////////////////////////////////////////////////////////////////////
Jason Samsb0ec1b42009-07-28 12:02:16 -0700562// VP
563//////////////////////////////////////////////////////////////////////////////
564
565static void SC_vpLoadModelMatrix(const rsc_Matrix *m)
566{
567 GET_TLS();
568 rsc->getVertex()->setModelviewMatrix(m);
569}
570
571static void SC_vpLoadTextureMatrix(const rsc_Matrix *m)
572{
573 GET_TLS();
574 rsc->getVertex()->setTextureMatrix(m);
575}
576
577
578
579//////////////////////////////////////////////////////////////////////////////
Jason Samsc97bb882009-07-20 14:31:06 -0700580// Drawing
581//////////////////////////////////////////////////////////////////////////////
582
583static void SC_drawTriangleMesh(RsTriangleMesh mesh)
584{
585 GET_TLS();
586 rsi_TriangleMeshRender(rsc, mesh);
587}
588
589static void SC_drawTriangleMeshRange(RsTriangleMesh mesh, uint32_t start, uint32_t count)
590{
591 GET_TLS();
592 rsi_TriangleMeshRenderRange(rsc, mesh, start, count);
593}
594
Romain Guy6c0cc6d2009-08-07 15:40:32 -0700595static void SC_drawLine(float x1, float y1, float z1,
596 float x2, float y2, float z2)
597{
598 GET_TLS();
599 rsc->setupCheck();
600
601 float vtx[] = { x1, y1, z1, x2, y2, z2 };
602
603 glBindBuffer(GL_ARRAY_BUFFER, 0);
604 glEnableClientState(GL_VERTEX_ARRAY);
605 glVertexPointer(3, GL_FLOAT, 0, vtx);
606
607 glDisableClientState(GL_NORMAL_ARRAY);
608 glDisableClientState(GL_COLOR_ARRAY);
609
610 glDrawArrays(GL_LINES, 0, 2);
611}
612
Romain Guy8f5c94b2009-08-08 18:30:19 -0700613static void SC_drawQuadTexCoords(float x1, float y1, float z1,
614 float u1, float v1,
615 float x2, float y2, float z2,
616 float u2, float v2,
617 float x3, float y3, float z3,
618 float u3, float v3,
619 float x4, float y4, float z4,
620 float u4, float v4)
Jason Samsc97bb882009-07-20 14:31:06 -0700621{
622 GET_TLS();
Jason Sams40a29e82009-08-10 14:55:26 -0700623
Jason Samsc97bb882009-07-20 14:31:06 -0700624 //LOGE("Quad");
625 //LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1);
626 //LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2);
627 //LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3);
628 //LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4);
Jason Sams40a29e82009-08-10 14:55:26 -0700629
Jason Samsc97bb882009-07-20 14:31:06 -0700630 float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4};
Romain Guy8f5c94b2009-08-08 18:30:19 -0700631 const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4};
Jason Samsc97bb882009-07-20 14:31:06 -0700632
633 rsc->setupCheck();
634
635 glBindBuffer(GL_ARRAY_BUFFER, 0);
636 //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]);
637
638 glEnableClientState(GL_VERTEX_ARRAY);
639 glVertexPointer(3, GL_FLOAT, 0, vtx);
640
641 glClientActiveTexture(GL_TEXTURE0);
642 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
643 glTexCoordPointer(2, GL_FLOAT, 0, tex);
644 glClientActiveTexture(GL_TEXTURE1);
645 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
646 glTexCoordPointer(2, GL_FLOAT, 0, tex);
647 glClientActiveTexture(GL_TEXTURE0);
648
649 glDisableClientState(GL_NORMAL_ARRAY);
650 glDisableClientState(GL_COLOR_ARRAY);
651
652 //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr);
653
654 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
655}
656
Romain Guy8f5c94b2009-08-08 18:30:19 -0700657static void SC_drawQuad(float x1, float y1, float z1,
658 float x2, float y2, float z2,
659 float x3, float y3, float z3,
660 float x4, float y4, float z4)
661{
662 SC_drawQuadTexCoords(x1, y1, z1, 0, 1,
663 x2, y2, z2, 1, 1,
664 x3, y3, z3, 1, 0,
665 x4, y4, z4, 0, 0);
666}
667
Jason Sams6f5c61c2009-07-28 17:20:11 -0700668static void SC_drawRect(float x1, float y1,
669 float x2, float y2, float z)
670{
671 SC_drawQuad(x1, y2, z,
672 x2, y2, z,
673 x2, y1, z,
674 x1, y1, z);
675}
676
Jason Sams1bada8c2009-08-09 17:01:55 -0700677static void SC_drawSimpleMesh(RsSimpleMesh vsm)
678{
679 GET_TLS();
680 SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
681 rsc->setupCheck();
682 sm->render();
683}
684
685static void SC_drawSimpleMeshRange(RsSimpleMesh vsm, uint32_t start, uint32_t len)
686{
687 GET_TLS();
688 SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
689 rsc->setupCheck();
690 sm->renderRange(start, len);
691}
692
693
Jason Samsc97bb882009-07-20 14:31:06 -0700694//////////////////////////////////////////////////////////////////////////////
695//
696//////////////////////////////////////////////////////////////////////////////
697
Jason Samsc97bb882009-07-20 14:31:06 -0700698static void SC_color(float r, float g, float b, float a)
699{
700 glColor4f(r, g, b, a);
701}
702
Romain Guyb62627e2009-08-06 22:52:13 -0700703static void SC_ambient(float r, float g, float b, float a)
704{
705 GLfloat params[] = { r, g, b, a };
706 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, params);
707}
708
709static void SC_diffuse(float r, float g, float b, float a)
710{
711 GLfloat params[] = { r, g, b, a };
712 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, params);
713}
714
715static void SC_specular(float r, float g, float b, float a)
716{
717 GLfloat params[] = { r, g, b, a };
718 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, params);
719}
720
721static void SC_emission(float r, float g, float b, float a)
722{
723 GLfloat params[] = { r, g, b, a };
724 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, params);
725}
726
Romain Guy6c0cc6d2009-08-07 15:40:32 -0700727static void SC_shininess(float s)
Romain Guyb62627e2009-08-06 22:52:13 -0700728{
Romain Guy6c0cc6d2009-08-07 15:40:32 -0700729 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, s);
Romain Guyb62627e2009-08-06 22:52:13 -0700730}
731
Romain Guya32d1002009-07-31 15:33:59 -0700732static void SC_hsb(float h, float s, float b, float a)
733{
734 float red = 0.0f;
735 float green = 0.0f;
736 float blue = 0.0f;
Jason Sams1bada8c2009-08-09 17:01:55 -0700737
Romain Guya32d1002009-07-31 15:33:59 -0700738 float x = h;
739 float y = s;
740 float z = b;
Jason Sams1bada8c2009-08-09 17:01:55 -0700741
Romain Guya32d1002009-07-31 15:33:59 -0700742 float hf = (x - (int) x) * 6.0f;
743 int ihf = (int) hf;
744 float f = hf - ihf;
745 float pv = z * (1.0f - y);
746 float qv = z * (1.0f - y * f);
747 float tv = z * (1.0f - y * (1.0f - f));
Jason Sams1bada8c2009-08-09 17:01:55 -0700748
Romain Guya32d1002009-07-31 15:33:59 -0700749 switch (ihf) {
750 case 0: // Red is the dominant color
751 red = z;
752 green = tv;
753 blue = pv;
754 break;
755 case 1: // Green is the dominant color
756 red = qv;
757 green = z;
758 blue = pv;
759 break;
760 case 2:
761 red = pv;
762 green = z;
763 blue = tv;
764 break;
765 case 3: // Blue is the dominant color
766 red = pv;
767 green = qv;
768 blue = z;
769 break;
770 case 4:
771 red = tv;
772 green = pv;
773 blue = z;
774 break;
775 case 5: // Red is the dominant color
776 red = z;
777 green = pv;
778 blue = qv;
779 break;
780 }
Jason Sams1bada8c2009-08-09 17:01:55 -0700781
Romain Guya32d1002009-07-31 15:33:59 -0700782 glColor4f(red, green, blue, a);
783}
784
Jason Samsb0ec1b42009-07-28 12:02:16 -0700785static void SC_uploadToTexture(RsAllocation va, uint32_t baseMipLevel)
Jason Samsc97bb882009-07-20 14:31:06 -0700786{
787 GET_TLS();
788 rsi_AllocationUploadToTexture(rsc, va, baseMipLevel);
789}
790
Jason Sams1bada8c2009-08-09 17:01:55 -0700791static void SC_uploadToBufferObject(RsAllocation va)
792{
793 GET_TLS();
794 rsi_AllocationUploadToBufferObject(rsc, va);
795}
796
Jason Samsc97bb882009-07-20 14:31:06 -0700797static void SC_ClearColor(float r, float g, float b, float a)
798{
799 //LOGE("c %f %f %f %f", r, g, b, a);
800 GET_TLS();
801 sc->mEnviroment.mClearColor[0] = r;
802 sc->mEnviroment.mClearColor[1] = g;
803 sc->mEnviroment.mClearColor[2] = b;
804 sc->mEnviroment.mClearColor[3] = a;
805}
806
Jason Samsb0ec1b42009-07-28 12:02:16 -0700807static void SC_debugF(const char *s, float f)
808{
809 LOGE("%s %f", s, f);
810}
811
812static void SC_debugI32(const char *s, int32_t i)
813{
814 LOGE("%s %i", s, i);
815}
816
Jason Sams40a29e82009-08-10 14:55:26 -0700817static uint32_t SC_getWidth()
818{
819 GET_TLS();
820 return rsc->getWidth();
821}
Jason Samsc97bb882009-07-20 14:31:06 -0700822
Jason Sams40a29e82009-08-10 14:55:26 -0700823static uint32_t SC_getHeight()
824{
825 GET_TLS();
826 return rsc->getHeight();
827}
Jason Samsc97bb882009-07-20 14:31:06 -0700828
Jason Sams334ea0c2009-08-17 13:56:09 -0700829static uint32_t SC_colorFloatRGBAtoUNorm8(float r, float g, float b, float a)
830{
831 uint32_t c = 0;
832 c |= (uint32_t)(r * 255.f + 0.5f);
833 c |= ((uint32_t)(g * 255.f + 0.5f)) << 8;
834 c |= ((uint32_t)(b * 255.f + 0.5f)) << 16;
835 c |= ((uint32_t)(a * 255.f + 0.5f)) << 24;
836 return c;
837}
838
839static uint32_t SC_colorFloatRGBAto565(float r, float g, float b)
840{
841 uint32_t ir = (uint32_t)(r * 255.f + 0.5f);
842 uint32_t ig = (uint32_t)(g * 255.f + 0.5f);
843 uint32_t ib = (uint32_t)(b * 255.f + 0.5f);
844 return rs888to565(ir, ig, ib);
845}
846
Jason Samsc97bb882009-07-20 14:31:06 -0700847//////////////////////////////////////////////////////////////////////////////
848// Class implementation
849//////////////////////////////////////////////////////////////////////////////
850
851ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
852 // IO
853 { "loadI32", (void *)&SC_loadI32,
854 "int", "(int, int)" },
855 //{ "loadU32", (void *)&SC_loadU32, "unsigned int", "(int, int)" },
856 { "loadF", (void *)&SC_loadF,
857 "float", "(int, int)" },
Romain Guya2136d62009-08-04 17:19:48 -0700858 { "loadArrayF", (void *)&SC_loadArrayF,
Romain Guyf8e136d2009-08-06 12:40:41 -0700859 "float*", "(int, int)" },
Romain Guya2136d62009-08-04 17:19:48 -0700860 { "loadArrayI32", (void *)&SC_loadArrayI32,
Romain Guyf8e136d2009-08-06 12:40:41 -0700861 "int*", "(int, int)" },
Jason Samsc97bb882009-07-20 14:31:06 -0700862 { "loadVec4", (void *)&SC_loadVec4,
863 "void", "(int, int, float *)" },
864 { "loadMatrix", (void *)&SC_loadMatrix,
865 "void", "(int, int, float *)" },
866 { "storeI32", (void *)&SC_storeI32,
867 "void", "(int, int, int)" },
868 //{ "storeU32", (void *)&SC_storeU32, "void", "(int, int, unsigned int)" },
869 { "storeF", (void *)&SC_storeF,
870 "void", "(int, int, float)" },
871 { "storeVec4", (void *)&SC_storeVec4,
872 "void", "(int, int, float *)" },
873 { "storeMatrix", (void *)&SC_storeMatrix,
874 "void", "(int, int, float *)" },
Romain Guyb62627e2009-08-06 22:52:13 -0700875 { "loadTriangleMeshVerticesF", (void *)&SC_loadTriangleMeshVerticesF,
876 "float*", "(int)" },
877 { "updateTriangleMesh", (void *)&SC_updateTriangleMesh,
878 "void", "(int)" },
Jason Samsc97bb882009-07-20 14:31:06 -0700879
880 // math
Romain Guya9d2d5e2009-08-09 17:04:54 -0700881 { "modf", (void *)&fmod,
882 "float", "(float, float)" },
Romain Guy8f5c94b2009-08-08 18:30:19 -0700883 { "abs", (void *)&abs,
884 "int", "(int)" },
885 { "absf", (void *)&fabs,
886 "float", "(float)" },
Romain Guycac80a62009-08-18 11:39:17 -0700887 { "sinf_fast", (void *)&SC_sinf_fast,
888 "float", "(float)" },
889 { "cosf_fast", (void *)&SC_cosf_fast,
890 "float", "(float)" },
Jason Samsc97bb882009-07-20 14:31:06 -0700891 { "sinf", (void *)&sinf,
892 "float", "(float)" },
893 { "cosf", (void *)&cosf,
894 "float", "(float)" },
Romain Guy8839ca52009-07-31 11:20:59 -0700895 { "asinf", (void *)&asinf,
896 "float", "(float)" },
897 { "acosf", (void *)&acosf,
898 "float", "(float)" },
899 { "atanf", (void *)&atanf,
900 "float", "(float)" },
901 { "atan2f", (void *)&atan2f,
Romain Guya32d1002009-07-31 15:33:59 -0700902 "float", "(float, float)" },
Jason Sams6f5c61c2009-07-28 17:20:11 -0700903 { "fabsf", (void *)&fabsf,
Jason Samsc97bb882009-07-20 14:31:06 -0700904 "float", "(float)" },
905 { "randf", (void *)&SC_randf,
906 "float", "(float)" },
Romain Guy8839ca52009-07-31 11:20:59 -0700907 { "randf2", (void *)&SC_randf2,
908 "float", "(float, float)" },
Jason Samsb0ec1b42009-07-28 12:02:16 -0700909 { "floorf", (void *)&floorf,
910 "float", "(float)" },
911 { "ceilf", (void *)&ceilf,
912 "float", "(float)" },
Romain Guy8839ca52009-07-31 11:20:59 -0700913 { "expf", (void *)&expf,
914 "float", "(float)" },
915 { "logf", (void *)&logf,
916 "float", "(float)" },
917 { "powf", (void *)&powf,
918 "float", "(float, float)" },
919 { "maxf", (void *)&SC_maxf,
920 "float", "(float, float)" },
921 { "minf", (void *)&SC_minf,
922 "float", "(float, float)" },
Romain Guy8f5c94b2009-08-08 18:30:19 -0700923 { "sqrt", (void *)&sqrt,
924 "int", "(int)" },
Romain Guy8839ca52009-07-31 11:20:59 -0700925 { "sqrtf", (void *)&sqrtf,
926 "float", "(float)" },
Romain Guy8f5c94b2009-08-08 18:30:19 -0700927 { "sqr", (void *)&SC_sqr,
928 "int", "(int)" },
Romain Guy8839ca52009-07-31 11:20:59 -0700929 { "sqrf", (void *)&SC_sqrf,
930 "float", "(float)" },
Romain Guya9d2d5e2009-08-09 17:04:54 -0700931 { "clamp", (void *)&SC_clamp,
932 "int", "(int, int, int)" },
Romain Guy8839ca52009-07-31 11:20:59 -0700933 { "clampf", (void *)&SC_clampf,
934 "float", "(float, float, float)" },
935 { "distf2", (void *)&SC_distf2,
936 "float", "(float, float, float, float)" },
937 { "distf3", (void *)&SC_distf3,
938 "float", "(float, float, float, float, float, float)" },
939 { "magf2", (void *)&SC_magf2,
940 "float", "(float, float)" },
941 { "magf3", (void *)&SC_magf3,
942 "float", "(float, float, float)" },
943 { "radf", (void *)&SC_radf,
944 "float", "(float)" },
945 { "degf", (void *)&SC_degf,
946 "float", "(float)" },
947 { "lerpf", (void *)&SC_lerpf,
948 "float", "(float, float, float)" },
949 { "normf", (void *)&SC_normf,
950 "float", "(float, float, float)" },
951 { "mapf", (void *)&SC_mapf,
952 "float", "(float, float, float, float, float)" },
Romain Guyecc7ca032009-08-03 21:12:51 -0700953 { "noisef", (void *)&SC_noisef,
954 "float", "(float)" },
955 { "noisef2", (void *)&SC_noisef2,
956 "float", "(float, float)" },
957 { "noisef3", (void *)&SC_noisef3,
958 "float", "(float, float, float)" },
959 { "turbulencef2", (void *)&SC_turbulencef2,
960 "float", "(float, float, float)" },
961 { "turbulencef3", (void *)&SC_turbulencef3,
962 "float", "(float, float, float, float)" },
Jason Samsc97bb882009-07-20 14:31:06 -0700963
Romain Guy584a3752009-07-30 18:45:01 -0700964 // time
965 { "second", (void *)&SC_second,
966 "int", "()" },
967 { "minute", (void *)&SC_minute,
968 "int", "()" },
969 { "hour", (void *)&SC_hour,
970 "int", "()" },
Romain Guy8839ca52009-07-31 11:20:59 -0700971 { "day", (void *)&SC_day,
972 "int", "()" },
973 { "month", (void *)&SC_month,
974 "int", "()" },
975 { "year", (void *)&SC_year,
976 "int", "()" },
Joe Onorato3370ec92009-08-09 11:39:02 -0700977 { "uptimeMillis", (void*)&SC_uptimeMillis,
978 "int", "()" }, // TODO: use long instead
979 { "startTimeMillis", (void*)&SC_startTimeMillis,
980 "int", "()" }, // TODO: use long instead
981 { "elapsedTimeMillis", (void*)&SC_elapsedTimeMillis,
982 "int", "()" }, // TODO: use long instead
Romain Guy584a3752009-07-30 18:45:01 -0700983
Jason Samsc97bb882009-07-20 14:31:06 -0700984 // matrix
985 { "matrixLoadIdentity", (void *)&SC_matrixLoadIdentity,
986 "void", "(float *mat)" },
987 { "matrixLoadFloat", (void *)&SC_matrixLoadFloat,
988 "void", "(float *mat, float *f)" },
989 { "matrixLoadMat", (void *)&SC_matrixLoadMat,
990 "void", "(float *mat, float *newmat)" },
991 { "matrixLoadRotate", (void *)&SC_matrixLoadRotate,
992 "void", "(float *mat, float rot, float x, float y, float z)" },
993 { "matrixLoadScale", (void *)&SC_matrixLoadScale,
994 "void", "(float *mat, float x, float y, float z)" },
995 { "matrixLoadTranslate", (void *)&SC_matrixLoadTranslate,
996 "void", "(float *mat, float x, float y, float z)" },
997 { "matrixLoadMultiply", (void *)&SC_matrixLoadMultiply,
998 "void", "(float *mat, float *lhs, float *rhs)" },
999 { "matrixMultiply", (void *)&SC_matrixMultiply,
1000 "void", "(float *mat, float *rhs)" },
1001 { "matrixRotate", (void *)&SC_matrixRotate,
1002 "void", "(float *mat, float rot, float x, float y, float z)" },
1003 { "matrixScale", (void *)&SC_matrixScale,
1004 "void", "(float *mat, float x, float y, float z)" },
1005 { "matrixTranslate", (void *)&SC_matrixTranslate,
1006 "void", "(float *mat, float x, float y, float z)" },
1007
Jason Sams334ea0c2009-08-17 13:56:09 -07001008 // vector
1009 { "vec2Rand", (void *)&SC_vec2Rand,
1010 "void", "(float *vec, float maxLen)" },
1011
Jason Samsc97bb882009-07-20 14:31:06 -07001012 // context
1013 { "bindProgramFragment", (void *)&SC_bindProgramFragment,
1014 "void", "(int)" },
1015 { "bindProgramFragmentStore", (void *)&SC_bindProgramFragmentStore,
1016 "void", "(int)" },
Jason Samsee411122009-07-21 12:20:54 -07001017 { "bindProgramVertex", (void *)&SC_bindProgramVertex,
1018 "void", "(int)" },
Jason Samsc97bb882009-07-20 14:31:06 -07001019 { "bindSampler", (void *)&SC_bindSampler,
1020 "void", "(int, int, int)" },
1021 { "bindTexture", (void *)&SC_bindTexture,
1022 "void", "(int, int, int)" },
1023
Jason Samsb0ec1b42009-07-28 12:02:16 -07001024 // vp
Jason Samsfaf15202009-07-29 20:55:44 -07001025 { "vpLoadModelMatrix", (void *)&SC_vpLoadModelMatrix,
Jason Samsb0ec1b42009-07-28 12:02:16 -07001026 "void", "(void *)" },
Jason Samsfaf15202009-07-29 20:55:44 -07001027 { "vpLoadTextureMatrix", (void *)&SC_vpLoadTextureMatrix,
Jason Samsb0ec1b42009-07-28 12:02:16 -07001028 "void", "(void *)" },
1029
1030
1031
Jason Samsc97bb882009-07-20 14:31:06 -07001032 // drawing
Jason Sams6f5c61c2009-07-28 17:20:11 -07001033 { "drawRect", (void *)&SC_drawRect,
1034 "void", "(float x1, float y1, float x2, float y2, float z)" },
Jason Samsc97bb882009-07-20 14:31:06 -07001035 { "drawQuad", (void *)&SC_drawQuad,
1036 "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 -07001037 { "drawQuadTexCoords", (void *)&SC_drawQuadTexCoords,
1038 "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 -07001039 { "drawTriangleMesh", (void *)&SC_drawTriangleMesh,
1040 "void", "(int mesh)" },
1041 { "drawTriangleMeshRange", (void *)&SC_drawTriangleMeshRange,
1042 "void", "(int mesh, int start, int count)" },
Romain Guy6c0cc6d2009-08-07 15:40:32 -07001043 { "drawLine", (void *)&SC_drawLine,
1044 "void", "(float x1, float y1, float z1, float x2, float y2, float z2)" },
Jason Sams1bada8c2009-08-09 17:01:55 -07001045 { "drawSimpleMesh", (void *)&SC_drawSimpleMesh,
1046 "void", "(int ism)" },
1047 { "drawSimpleMeshRange", (void *)&SC_drawSimpleMeshRange,
1048 "void", "(int ism, int start, int len)" },
Jason Samsc97bb882009-07-20 14:31:06 -07001049
1050
1051 // misc
1052 { "pfClearColor", (void *)&SC_ClearColor,
1053 "void", "(float, float, float, float)" },
Jason Samsc97bb882009-07-20 14:31:06 -07001054 { "color", (void *)&SC_color,
1055 "void", "(float, float, float, float)" },
Romain Guya32d1002009-07-31 15:33:59 -07001056 { "hsb", (void *)&SC_hsb,
1057 "void", "(float, float, float, float)" },
Romain Guyb62627e2009-08-06 22:52:13 -07001058 { "ambient", (void *)&SC_ambient,
1059 "void", "(float, float, float, float)" },
1060 { "diffuse", (void *)&SC_diffuse,
1061 "void", "(float, float, float, float)" },
1062 { "specular", (void *)&SC_specular,
1063 "void", "(float, float, float, float)" },
1064 { "emission", (void *)&SC_emission,
1065 "void", "(float, float, float, float)" },
1066 { "shininess", (void *)&SC_shininess,
Romain Guy6c0cc6d2009-08-07 15:40:32 -07001067 "void", "(float)" },
Jason Samsc97bb882009-07-20 14:31:06 -07001068
Jason Samsb0ec1b42009-07-28 12:02:16 -07001069 { "uploadToTexture", (void *)&SC_uploadToTexture,
1070 "void", "(int, int)" },
Jason Sams1bada8c2009-08-09 17:01:55 -07001071 { "uploadToBufferObject", (void *)&SC_uploadToBufferObject,
1072 "void", "(int)" },
Jason Samsb0ec1b42009-07-28 12:02:16 -07001073
Jason Sams334ea0c2009-08-17 13:56:09 -07001074 { "colorFloatRGBAtoUNorm8", (void *)&SC_colorFloatRGBAtoUNorm8,
1075 "int", "(float, float, float, float)" },
1076 { "colorFloatRGBto565", (void *)&SC_colorFloatRGBAto565,
1077 "int", "(float, float, float)" },
1078
1079
Jason Sams40a29e82009-08-10 14:55:26 -07001080 { "getWidth", (void *)&SC_getWidth,
1081 "int", "()" },
1082 { "getHeight", (void *)&SC_getHeight,
1083 "int", "()" },
1084
1085
Jason Samsb0ec1b42009-07-28 12:02:16 -07001086
1087 { "debugF", (void *)&SC_debugF,
1088 "void", "(void *, float)" },
1089 { "debugI32", (void *)&SC_debugI32,
1090 "void", "(void *, int)" },
1091
1092
Jason Samsc97bb882009-07-20 14:31:06 -07001093 { NULL, NULL, NULL, NULL }
1094};
1095
1096const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym)
1097{
1098 ScriptCState::SymbolTable_t *syms = gSyms;
1099
1100 while (syms->mPtr) {
1101 if (!strcmp(syms->mName, sym)) {
1102 return syms;
1103 }
1104 syms++;
1105 }
1106 return NULL;
1107}
1108
1109void ScriptCState::appendDecls(String8 *str)
1110{
1111 ScriptCState::SymbolTable_t *syms = gSyms;
1112 while (syms->mPtr) {
1113 str->append(syms->mRet);
1114 str->append(" ");
1115 str->append(syms->mName);
1116 str->append(syms->mParam);
1117 str->append(";\n");
1118 syms++;
1119 }
1120}
1121
1122