blob: 84a39aa304ab3abbe38d54c0f51ab61335059351 [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
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 Guy06f7c932009-08-06 12:40:41 -070062static float* SC_loadArrayF(uint32_t bank, uint32_t offset)
Romain Guy36401002009-08-04 17:19:48 -070063{
64 GET_TLS();
65 void *vp = sc->mSlots[bank]->getPtr();
66 float *f = static_cast<float *>(vp);
Romain Guy06f7c932009-08-06 12:40:41 -070067 return f + offset;
Romain Guy36401002009-08-04 17:19:48 -070068}
69
Romain Guy06f7c932009-08-06 12:40:41 -070070static int32_t* SC_loadArrayI32(uint32_t bank, uint32_t offset)
Romain Guy36401002009-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 Guy06f7c932009-08-06 12:40:41 -070075 return i + offset;
Romain Guy36401002009-08-04 17:19:48 -070076}
77
Romain Guy48b7edc2009-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 Samse5ffb872009-08-09 17:01:55 -070092
Romain Guy48b7edc2009-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 Samse5ffb872009-08-09 17:01:55 -070095 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
Romain Guy48b7edc2009-08-06 22:52:13 -070096}
Romain Guy06f7c932009-08-06 12:40:41 -070097
Jason Samse45ac6e2009-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 Guy39dbc802009-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 Guy2275d632009-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 Samse45ac6e2009-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 Guy39dbc802009-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 Guy27162ab2009-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 Guy39dbc802009-07-31 11:20:59 -0700233static float SC_maxf(float a, float b)
234{
Jason Samse5ffb872009-08-09 17:01:55 -0700235 return a > b ? a : b;
Romain Guy39dbc802009-07-31 11:20:59 -0700236}
237
238static float SC_minf(float a, float b)
239{
Jason Samse5ffb872009-08-09 17:01:55 -0700240 return a < b ? a : b;
Romain Guy39dbc802009-07-31 11:20:59 -0700241}
242
243static float SC_sqrf(float v)
244{
Jason Samse5ffb872009-08-09 17:01:55 -0700245 return v * v;
Romain Guy39dbc802009-07-31 11:20:59 -0700246}
247
Romain Guyfcc1c2b2009-08-08 18:30:19 -0700248static int SC_sqr(int v)
249{
250 return v * v;
251}
252
Romain Guy39dbc802009-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 Samse5ffb872009-08-09 17:01:55 -0700257 return sqrtf(x * x + y * y);
Romain Guy39dbc802009-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 Samse5ffb872009-08-09 17:01:55 -0700265 return sqrtf(x * x + y * y + z * z);
Romain Guy39dbc802009-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 Samse5ffb872009-08-09 17:01:55 -0700280 return degrees * DEG_TO_RAD;
Romain Guy39dbc802009-07-31 11:20:59 -0700281}
282
283static float SC_degf(float radians)
284{
Jason Samse5ffb872009-08-09 17:01:55 -0700285 return radians * RAD_TO_DEG;
Romain Guy39dbc802009-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 Samse45ac6e2009-07-20 14:31:06 -0700302
Romain Guy98e10fd2009-07-30 18:45:01 -0700303//////////////////////////////////////////////////////////////////////////////
304// Time routines
305//////////////////////////////////////////////////////////////////////////////
Jason Samse45ac6e2009-07-20 14:31:06 -0700306
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700307static int32_t SC_second()
Romain Guy98e10fd2009-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 Onorato9c4e4ca2009-08-09 11:39:02 -0700325static int32_t SC_minute()
Romain Guy98e10fd2009-07-30 18:45:01 -0700326{
327 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700328
Romain Guy98e10fd2009-07-30 18:45:01 -0700329 time_t rawtime;
330 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700331
Romain Guy98e10fd2009-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 Samse5ffb872009-08-09 17:01:55 -0700341}
Romain Guy98e10fd2009-07-30 18:45:01 -0700342
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700343static int32_t SC_hour()
Romain Guy98e10fd2009-07-30 18:45:01 -0700344{
345 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700346
Romain Guy98e10fd2009-07-30 18:45:01 -0700347 time_t rawtime;
348 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700349
Romain Guy98e10fd2009-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 Guy39dbc802009-07-31 11:20:59 -0700359}
360
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700361static int32_t SC_day()
Romain Guy39dbc802009-07-31 11:20:59 -0700362{
363 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700364
Romain Guy39dbc802009-07-31 11:20:59 -0700365 time_t rawtime;
366 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700367
Romain Guy39dbc802009-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 Samse5ffb872009-08-09 17:01:55 -0700377}
Jason Samse45ac6e2009-07-20 14:31:06 -0700378
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700379static int32_t SC_month()
Romain Guy39dbc802009-07-31 11:20:59 -0700380{
381 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700382
Romain Guy39dbc802009-07-31 11:20:59 -0700383 time_t rawtime;
384 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700385
Romain Guy39dbc802009-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 Samse5ffb872009-08-09 17:01:55 -0700395}
Romain Guy39dbc802009-07-31 11:20:59 -0700396
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700397static int32_t SC_year()
Romain Guy39dbc802009-07-31 11:20:59 -0700398{
399 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700400
Romain Guy39dbc802009-07-31 11:20:59 -0700401 time_t rawtime;
402 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700403
Romain Guy39dbc802009-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 Onorato9c4e4ca2009-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 Samse45ac6e2009-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 Sams90b36a82009-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 Samse45ac6e2009-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 Samsb5909ce2009-07-21 12:20:54 -0700554static void SC_bindProgramVertex(RsProgramVertex pv)
555{
556 GET_TLS();
557 rsi_ContextBindProgramVertex(rsc, pv);
558
559}
Jason Samse45ac6e2009-07-20 14:31:06 -0700560
561//////////////////////////////////////////////////////////////////////////////
Jason Samsc9d43db2009-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 Samse45ac6e2009-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 Guyd369e272009-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 Guyfcc1c2b2009-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 Samse45ac6e2009-07-20 14:31:06 -0700621{
622 GET_TLS();
Jason Samse579df42009-08-10 14:55:26 -0700623
Jason Samse45ac6e2009-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 Samse579df42009-08-10 14:55:26 -0700629
Jason Samse45ac6e2009-07-20 14:31:06 -0700630 float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4};
Romain Guyfcc1c2b2009-08-08 18:30:19 -0700631 const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4};
Jason Samse45ac6e2009-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 Guyfcc1c2b2009-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 Samse9f5c532009-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 Samse5ffb872009-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 Samse45ac6e2009-07-20 14:31:06 -0700694//////////////////////////////////////////////////////////////////////////////
695//
696//////////////////////////////////////////////////////////////////////////////
697
Jason Samse45ac6e2009-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 Guy48b7edc2009-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 Guyd369e272009-08-07 15:40:32 -0700727static void SC_shininess(float s)
Romain Guy48b7edc2009-08-06 22:52:13 -0700728{
Romain Guyd369e272009-08-07 15:40:32 -0700729 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, s);
Romain Guy48b7edc2009-08-06 22:52:13 -0700730}
731
Romain Guy370ed152009-08-20 17:08:33 -0700732static void SC_hsbToRgb(float h, float s, float b, float* rgb)
Romain Guy9c59d022009-07-31 15:33:59 -0700733{
734 float red = 0.0f;
735 float green = 0.0f;
736 float blue = 0.0f;
Jason Samse5ffb872009-08-09 17:01:55 -0700737
Romain Guy9c59d022009-07-31 15:33:59 -0700738 float x = h;
739 float y = s;
740 float z = b;
Jason Samse5ffb872009-08-09 17:01:55 -0700741
Romain Guy9c59d022009-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 Samse5ffb872009-08-09 17:01:55 -0700748
Romain Guy9c59d022009-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 Samse5ffb872009-08-09 17:01:55 -0700781
Romain Guy370ed152009-08-20 17:08:33 -0700782 rgb[0] = red;
783 rgb[1] = green;
784 rgb[2] = blue;
785}
786
787static int SC_hsbToAbgr(float h, float s, float b, float a)
788{
789 float rgb[3];
790 SC_hsbToRgb(h, s, b, rgb);
791 return int(a * 255.0f) << 24 |
792 int(rgb[2] * 255.0f) << 16 |
793 int(rgb[1] * 255.0f) << 8 |
794 int(rgb[0] * 255.0f);
795}
796
797static void SC_hsb(float h, float s, float b, float a)
798{
799 float rgb[3];
800 SC_hsbToRgb(h, s, b, rgb);
801 glColor4f(rgb[0], rgb[1], rgb[2], a);
Romain Guy9c59d022009-07-31 15:33:59 -0700802}
803
Jason Samsc9d43db2009-07-28 12:02:16 -0700804static void SC_uploadToTexture(RsAllocation va, uint32_t baseMipLevel)
Jason Samse45ac6e2009-07-20 14:31:06 -0700805{
806 GET_TLS();
807 rsi_AllocationUploadToTexture(rsc, va, baseMipLevel);
808}
809
Jason Samse5ffb872009-08-09 17:01:55 -0700810static void SC_uploadToBufferObject(RsAllocation va)
811{
812 GET_TLS();
813 rsi_AllocationUploadToBufferObject(rsc, va);
814}
815
Jason Samse45ac6e2009-07-20 14:31:06 -0700816static void SC_ClearColor(float r, float g, float b, float a)
817{
818 //LOGE("c %f %f %f %f", r, g, b, a);
819 GET_TLS();
820 sc->mEnviroment.mClearColor[0] = r;
821 sc->mEnviroment.mClearColor[1] = g;
822 sc->mEnviroment.mClearColor[2] = b;
823 sc->mEnviroment.mClearColor[3] = a;
824}
825
Jason Samsc9d43db2009-07-28 12:02:16 -0700826static void SC_debugF(const char *s, float f)
827{
828 LOGE("%s %f", s, f);
829}
830
Romain Guy370ed152009-08-20 17:08:33 -0700831static void SC_debugHexF(const char *s, float f)
832{
833 LOGE("%s 0x%x", s, *((int *) (&f)));
834}
835
Jason Samsc9d43db2009-07-28 12:02:16 -0700836static void SC_debugI32(const char *s, int32_t i)
837{
838 LOGE("%s %i", s, i);
839}
840
Romain Guy370ed152009-08-20 17:08:33 -0700841static void SC_debugHexI32(const char *s, int32_t i)
842{
843 LOGE("%s 0x%x", s, i);
844}
845
Jason Samse579df42009-08-10 14:55:26 -0700846static uint32_t SC_getWidth()
847{
848 GET_TLS();
849 return rsc->getWidth();
850}
Jason Samse45ac6e2009-07-20 14:31:06 -0700851
Jason Samse579df42009-08-10 14:55:26 -0700852static uint32_t SC_getHeight()
853{
854 GET_TLS();
855 return rsc->getHeight();
856}
Jason Samse45ac6e2009-07-20 14:31:06 -0700857
Jason Sams90b36a82009-08-17 13:56:09 -0700858static uint32_t SC_colorFloatRGBAtoUNorm8(float r, float g, float b, float a)
859{
860 uint32_t c = 0;
861 c |= (uint32_t)(r * 255.f + 0.5f);
862 c |= ((uint32_t)(g * 255.f + 0.5f)) << 8;
863 c |= ((uint32_t)(b * 255.f + 0.5f)) << 16;
864 c |= ((uint32_t)(a * 255.f + 0.5f)) << 24;
865 return c;
866}
867
868static uint32_t SC_colorFloatRGBAto565(float r, float g, float b)
869{
870 uint32_t ir = (uint32_t)(r * 255.f + 0.5f);
871 uint32_t ig = (uint32_t)(g * 255.f + 0.5f);
872 uint32_t ib = (uint32_t)(b * 255.f + 0.5f);
873 return rs888to565(ir, ig, ib);
874}
875
Jason Samse45ac6e2009-07-20 14:31:06 -0700876//////////////////////////////////////////////////////////////////////////////
877// Class implementation
878//////////////////////////////////////////////////////////////////////////////
879
880ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
881 // IO
882 { "loadI32", (void *)&SC_loadI32,
883 "int", "(int, int)" },
884 //{ "loadU32", (void *)&SC_loadU32, "unsigned int", "(int, int)" },
885 { "loadF", (void *)&SC_loadF,
886 "float", "(int, int)" },
Romain Guy36401002009-08-04 17:19:48 -0700887 { "loadArrayF", (void *)&SC_loadArrayF,
Romain Guy06f7c932009-08-06 12:40:41 -0700888 "float*", "(int, int)" },
Romain Guy36401002009-08-04 17:19:48 -0700889 { "loadArrayI32", (void *)&SC_loadArrayI32,
Romain Guy06f7c932009-08-06 12:40:41 -0700890 "int*", "(int, int)" },
Jason Samse45ac6e2009-07-20 14:31:06 -0700891 { "loadVec4", (void *)&SC_loadVec4,
892 "void", "(int, int, float *)" },
893 { "loadMatrix", (void *)&SC_loadMatrix,
894 "void", "(int, int, float *)" },
895 { "storeI32", (void *)&SC_storeI32,
896 "void", "(int, int, int)" },
897 //{ "storeU32", (void *)&SC_storeU32, "void", "(int, int, unsigned int)" },
898 { "storeF", (void *)&SC_storeF,
899 "void", "(int, int, float)" },
900 { "storeVec4", (void *)&SC_storeVec4,
901 "void", "(int, int, float *)" },
902 { "storeMatrix", (void *)&SC_storeMatrix,
903 "void", "(int, int, float *)" },
Romain Guy48b7edc2009-08-06 22:52:13 -0700904 { "loadTriangleMeshVerticesF", (void *)&SC_loadTriangleMeshVerticesF,
905 "float*", "(int)" },
906 { "updateTriangleMesh", (void *)&SC_updateTriangleMesh,
907 "void", "(int)" },
Jason Samse45ac6e2009-07-20 14:31:06 -0700908
909 // math
Romain Guy27162ab2009-08-09 17:04:54 -0700910 { "modf", (void *)&fmod,
911 "float", "(float, float)" },
Romain Guyfcc1c2b2009-08-08 18:30:19 -0700912 { "abs", (void *)&abs,
913 "int", "(int)" },
914 { "absf", (void *)&fabs,
915 "float", "(float)" },
Romain Guy2275d632009-08-18 11:39:17 -0700916 { "sinf_fast", (void *)&SC_sinf_fast,
917 "float", "(float)" },
918 { "cosf_fast", (void *)&SC_cosf_fast,
919 "float", "(float)" },
Jason Samse45ac6e2009-07-20 14:31:06 -0700920 { "sinf", (void *)&sinf,
921 "float", "(float)" },
922 { "cosf", (void *)&cosf,
923 "float", "(float)" },
Romain Guy39dbc802009-07-31 11:20:59 -0700924 { "asinf", (void *)&asinf,
925 "float", "(float)" },
926 { "acosf", (void *)&acosf,
927 "float", "(float)" },
928 { "atanf", (void *)&atanf,
929 "float", "(float)" },
930 { "atan2f", (void *)&atan2f,
Romain Guy9c59d022009-07-31 15:33:59 -0700931 "float", "(float, float)" },
Jason Samse9f5c532009-07-28 17:20:11 -0700932 { "fabsf", (void *)&fabsf,
Jason Samse45ac6e2009-07-20 14:31:06 -0700933 "float", "(float)" },
934 { "randf", (void *)&SC_randf,
935 "float", "(float)" },
Romain Guy39dbc802009-07-31 11:20:59 -0700936 { "randf2", (void *)&SC_randf2,
937 "float", "(float, float)" },
Jason Samsc9d43db2009-07-28 12:02:16 -0700938 { "floorf", (void *)&floorf,
939 "float", "(float)" },
940 { "ceilf", (void *)&ceilf,
941 "float", "(float)" },
Romain Guy39dbc802009-07-31 11:20:59 -0700942 { "expf", (void *)&expf,
943 "float", "(float)" },
944 { "logf", (void *)&logf,
945 "float", "(float)" },
946 { "powf", (void *)&powf,
947 "float", "(float, float)" },
948 { "maxf", (void *)&SC_maxf,
949 "float", "(float, float)" },
950 { "minf", (void *)&SC_minf,
951 "float", "(float, float)" },
Romain Guyfcc1c2b2009-08-08 18:30:19 -0700952 { "sqrt", (void *)&sqrt,
953 "int", "(int)" },
Romain Guy39dbc802009-07-31 11:20:59 -0700954 { "sqrtf", (void *)&sqrtf,
955 "float", "(float)" },
Romain Guyfcc1c2b2009-08-08 18:30:19 -0700956 { "sqr", (void *)&SC_sqr,
957 "int", "(int)" },
Romain Guy39dbc802009-07-31 11:20:59 -0700958 { "sqrf", (void *)&SC_sqrf,
959 "float", "(float)" },
Romain Guy27162ab2009-08-09 17:04:54 -0700960 { "clamp", (void *)&SC_clamp,
961 "int", "(int, int, int)" },
Romain Guy39dbc802009-07-31 11:20:59 -0700962 { "clampf", (void *)&SC_clampf,
963 "float", "(float, float, float)" },
964 { "distf2", (void *)&SC_distf2,
965 "float", "(float, float, float, float)" },
966 { "distf3", (void *)&SC_distf3,
967 "float", "(float, float, float, float, float, float)" },
968 { "magf2", (void *)&SC_magf2,
969 "float", "(float, float)" },
970 { "magf3", (void *)&SC_magf3,
971 "float", "(float, float, float)" },
972 { "radf", (void *)&SC_radf,
973 "float", "(float)" },
974 { "degf", (void *)&SC_degf,
975 "float", "(float)" },
976 { "lerpf", (void *)&SC_lerpf,
977 "float", "(float, float, float)" },
978 { "normf", (void *)&SC_normf,
979 "float", "(float, float, float)" },
980 { "mapf", (void *)&SC_mapf,
981 "float", "(float, float, float, float, float)" },
Romain Guyb7f1a6d2009-08-03 21:12:51 -0700982 { "noisef", (void *)&SC_noisef,
983 "float", "(float)" },
984 { "noisef2", (void *)&SC_noisef2,
985 "float", "(float, float)" },
986 { "noisef3", (void *)&SC_noisef3,
987 "float", "(float, float, float)" },
988 { "turbulencef2", (void *)&SC_turbulencef2,
989 "float", "(float, float, float)" },
990 { "turbulencef3", (void *)&SC_turbulencef3,
991 "float", "(float, float, float, float)" },
Jason Samse45ac6e2009-07-20 14:31:06 -0700992
Romain Guy98e10fd2009-07-30 18:45:01 -0700993 // time
994 { "second", (void *)&SC_second,
995 "int", "()" },
996 { "minute", (void *)&SC_minute,
997 "int", "()" },
998 { "hour", (void *)&SC_hour,
999 "int", "()" },
Romain Guy39dbc802009-07-31 11:20:59 -07001000 { "day", (void *)&SC_day,
1001 "int", "()" },
1002 { "month", (void *)&SC_month,
1003 "int", "()" },
1004 { "year", (void *)&SC_year,
1005 "int", "()" },
Joe Onorato9c4e4ca2009-08-09 11:39:02 -07001006 { "uptimeMillis", (void*)&SC_uptimeMillis,
1007 "int", "()" }, // TODO: use long instead
1008 { "startTimeMillis", (void*)&SC_startTimeMillis,
1009 "int", "()" }, // TODO: use long instead
1010 { "elapsedTimeMillis", (void*)&SC_elapsedTimeMillis,
1011 "int", "()" }, // TODO: use long instead
Romain Guy98e10fd2009-07-30 18:45:01 -07001012
Jason Samse45ac6e2009-07-20 14:31:06 -07001013 // matrix
1014 { "matrixLoadIdentity", (void *)&SC_matrixLoadIdentity,
1015 "void", "(float *mat)" },
1016 { "matrixLoadFloat", (void *)&SC_matrixLoadFloat,
1017 "void", "(float *mat, float *f)" },
1018 { "matrixLoadMat", (void *)&SC_matrixLoadMat,
1019 "void", "(float *mat, float *newmat)" },
1020 { "matrixLoadRotate", (void *)&SC_matrixLoadRotate,
1021 "void", "(float *mat, float rot, float x, float y, float z)" },
1022 { "matrixLoadScale", (void *)&SC_matrixLoadScale,
1023 "void", "(float *mat, float x, float y, float z)" },
1024 { "matrixLoadTranslate", (void *)&SC_matrixLoadTranslate,
1025 "void", "(float *mat, float x, float y, float z)" },
1026 { "matrixLoadMultiply", (void *)&SC_matrixLoadMultiply,
1027 "void", "(float *mat, float *lhs, float *rhs)" },
1028 { "matrixMultiply", (void *)&SC_matrixMultiply,
1029 "void", "(float *mat, float *rhs)" },
1030 { "matrixRotate", (void *)&SC_matrixRotate,
1031 "void", "(float *mat, float rot, float x, float y, float z)" },
1032 { "matrixScale", (void *)&SC_matrixScale,
1033 "void", "(float *mat, float x, float y, float z)" },
1034 { "matrixTranslate", (void *)&SC_matrixTranslate,
1035 "void", "(float *mat, float x, float y, float z)" },
1036
Jason Sams90b36a82009-08-17 13:56:09 -07001037 // vector
1038 { "vec2Rand", (void *)&SC_vec2Rand,
1039 "void", "(float *vec, float maxLen)" },
1040
Jason Samse45ac6e2009-07-20 14:31:06 -07001041 // context
1042 { "bindProgramFragment", (void *)&SC_bindProgramFragment,
1043 "void", "(int)" },
1044 { "bindProgramFragmentStore", (void *)&SC_bindProgramFragmentStore,
1045 "void", "(int)" },
Jason Samsb5909ce2009-07-21 12:20:54 -07001046 { "bindProgramVertex", (void *)&SC_bindProgramVertex,
1047 "void", "(int)" },
Jason Samse45ac6e2009-07-20 14:31:06 -07001048 { "bindSampler", (void *)&SC_bindSampler,
1049 "void", "(int, int, int)" },
1050 { "bindTexture", (void *)&SC_bindTexture,
1051 "void", "(int, int, int)" },
1052
Jason Samsc9d43db2009-07-28 12:02:16 -07001053 // vp
Jason Sams50253db2009-07-29 20:55:44 -07001054 { "vpLoadModelMatrix", (void *)&SC_vpLoadModelMatrix,
Jason Samsc9d43db2009-07-28 12:02:16 -07001055 "void", "(void *)" },
Jason Sams50253db2009-07-29 20:55:44 -07001056 { "vpLoadTextureMatrix", (void *)&SC_vpLoadTextureMatrix,
Jason Samsc9d43db2009-07-28 12:02:16 -07001057 "void", "(void *)" },
1058
1059
1060
Jason Samse45ac6e2009-07-20 14:31:06 -07001061 // drawing
Jason Samse9f5c532009-07-28 17:20:11 -07001062 { "drawRect", (void *)&SC_drawRect,
1063 "void", "(float x1, float y1, float x2, float y2, float z)" },
Jason Samse45ac6e2009-07-20 14:31:06 -07001064 { "drawQuad", (void *)&SC_drawQuad,
1065 "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 -07001066 { "drawQuadTexCoords", (void *)&SC_drawQuadTexCoords,
1067 "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 -07001068 { "drawTriangleMesh", (void *)&SC_drawTriangleMesh,
1069 "void", "(int mesh)" },
1070 { "drawTriangleMeshRange", (void *)&SC_drawTriangleMeshRange,
1071 "void", "(int mesh, int start, int count)" },
Romain Guyd369e272009-08-07 15:40:32 -07001072 { "drawLine", (void *)&SC_drawLine,
1073 "void", "(float x1, float y1, float z1, float x2, float y2, float z2)" },
Jason Samse5ffb872009-08-09 17:01:55 -07001074 { "drawSimpleMesh", (void *)&SC_drawSimpleMesh,
1075 "void", "(int ism)" },
1076 { "drawSimpleMeshRange", (void *)&SC_drawSimpleMeshRange,
1077 "void", "(int ism, int start, int len)" },
Jason Samse45ac6e2009-07-20 14:31:06 -07001078
1079
1080 // misc
1081 { "pfClearColor", (void *)&SC_ClearColor,
1082 "void", "(float, float, float, float)" },
Jason Samse45ac6e2009-07-20 14:31:06 -07001083 { "color", (void *)&SC_color,
1084 "void", "(float, float, float, float)" },
Romain Guy9c59d022009-07-31 15:33:59 -07001085 { "hsb", (void *)&SC_hsb,
1086 "void", "(float, float, float, float)" },
Romain Guy370ed152009-08-20 17:08:33 -07001087 { "hsbToRgb", (void *)&SC_hsbToRgb,
1088 "void", "(float, float, float, float*)" },
1089 { "hsbToAbgr", (void *)&SC_hsbToAbgr,
1090 "int", "(float, float, float, float)" },
Romain Guy48b7edc2009-08-06 22:52:13 -07001091 { "ambient", (void *)&SC_ambient,
1092 "void", "(float, float, float, float)" },
1093 { "diffuse", (void *)&SC_diffuse,
1094 "void", "(float, float, float, float)" },
1095 { "specular", (void *)&SC_specular,
1096 "void", "(float, float, float, float)" },
1097 { "emission", (void *)&SC_emission,
1098 "void", "(float, float, float, float)" },
1099 { "shininess", (void *)&SC_shininess,
Romain Guyd369e272009-08-07 15:40:32 -07001100 "void", "(float)" },
Jason Samse45ac6e2009-07-20 14:31:06 -07001101
Jason Samsc9d43db2009-07-28 12:02:16 -07001102 { "uploadToTexture", (void *)&SC_uploadToTexture,
1103 "void", "(int, int)" },
Jason Samse5ffb872009-08-09 17:01:55 -07001104 { "uploadToBufferObject", (void *)&SC_uploadToBufferObject,
1105 "void", "(int)" },
Jason Samsc9d43db2009-07-28 12:02:16 -07001106
Jason Sams90b36a82009-08-17 13:56:09 -07001107 { "colorFloatRGBAtoUNorm8", (void *)&SC_colorFloatRGBAtoUNorm8,
1108 "int", "(float, float, float, float)" },
1109 { "colorFloatRGBto565", (void *)&SC_colorFloatRGBAto565,
1110 "int", "(float, float, float)" },
1111
1112
Jason Samse579df42009-08-10 14:55:26 -07001113 { "getWidth", (void *)&SC_getWidth,
1114 "int", "()" },
1115 { "getHeight", (void *)&SC_getHeight,
1116 "int", "()" },
1117
1118
Jason Samsc9d43db2009-07-28 12:02:16 -07001119
1120 { "debugF", (void *)&SC_debugF,
1121 "void", "(void *, float)" },
1122 { "debugI32", (void *)&SC_debugI32,
1123 "void", "(void *, int)" },
Romain Guy370ed152009-08-20 17:08:33 -07001124 { "debugHexF", (void *)&SC_debugHexF,
1125 "void", "(void *, float)" },
1126 { "debugHexI32", (void *)&SC_debugHexI32,
1127 "void", "(void *, int)" },
Jason Samsc9d43db2009-07-28 12:02:16 -07001128
1129
Jason Samse45ac6e2009-07-20 14:31:06 -07001130 { NULL, NULL, NULL, NULL }
1131};
1132
1133const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym)
1134{
1135 ScriptCState::SymbolTable_t *syms = gSyms;
1136
1137 while (syms->mPtr) {
1138 if (!strcmp(syms->mName, sym)) {
1139 return syms;
1140 }
1141 syms++;
1142 }
1143 return NULL;
1144}
1145
1146void ScriptCState::appendDecls(String8 *str)
1147{
1148 ScriptCState::SymbolTable_t *syms = gSyms;
1149 while (syms->mPtr) {
1150 str->append(syms->mRet);
1151 str->append(" ");
1152 str->append(syms->mName);
1153 str->append(syms->mParam);
1154 str->append(";\n");
1155 syms++;
1156 }
1157}
1158
1159