blob: 561cde6ca880bc7e17a5c45f58d4a8b2239f6723 [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"
23#include "utils/String8.h"
24
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
62static uint32_t SC_loadU32(uint32_t bank, uint32_t offset)
63{
64 GET_TLS();
65 const void *vp = sc->mSlots[bank]->getPtr();
66 const uint32_t *i = static_cast<const uint32_t *>(vp);
67 return i[offset];
68}
69
70static void SC_loadVec4(uint32_t bank, uint32_t offset, rsc_Vector4 *v)
71{
72 GET_TLS();
73 const void *vp = sc->mSlots[bank]->getPtr();
74 const float *f = static_cast<const float *>(vp);
75 memcpy(v, &f[offset], sizeof(rsc_Vector4));
76}
77
78static void SC_loadMatrix(uint32_t bank, uint32_t offset, rsc_Matrix *m)
79{
80 GET_TLS();
81 const void *vp = sc->mSlots[bank]->getPtr();
82 const float *f = static_cast<const float *>(vp);
83 memcpy(m, &f[offset], sizeof(rsc_Matrix));
84}
85
86
87static void SC_storeF(uint32_t bank, uint32_t offset, float v)
88{
89 //LOGE("storeF %i %i %f", bank, offset, v);
90 GET_TLS();
91 void *vp = sc->mSlots[bank]->getPtr();
92 float *f = static_cast<float *>(vp);
93 f[offset] = v;
94}
95
96static void SC_storeI32(uint32_t bank, uint32_t offset, int32_t v)
97{
98 GET_TLS();
99 void *vp = sc->mSlots[bank]->getPtr();
100 int32_t *f = static_cast<int32_t *>(vp);
101 static_cast<int32_t *>(sc->mSlots[bank]->getPtr())[offset] = v;
102}
103
104static void SC_storeU32(uint32_t bank, uint32_t offset, uint32_t v)
105{
106 GET_TLS();
107 void *vp = sc->mSlots[bank]->getPtr();
108 uint32_t *f = static_cast<uint32_t *>(vp);
109 static_cast<uint32_t *>(sc->mSlots[bank]->getPtr())[offset] = v;
110}
111
112static void SC_storeVec4(uint32_t bank, uint32_t offset, const rsc_Vector4 *v)
113{
114 GET_TLS();
115 void *vp = sc->mSlots[bank]->getPtr();
116 float *f = static_cast<float *>(vp);
117 memcpy(&f[offset], v, sizeof(rsc_Vector4));
118}
119
120static void SC_storeMatrix(uint32_t bank, uint32_t offset, const rsc_Matrix *m)
121{
122 GET_TLS();
123 void *vp = sc->mSlots[bank]->getPtr();
124 float *f = static_cast<float *>(vp);
125 memcpy(&f[offset], m, sizeof(rsc_Matrix));
126}
127
128
129//////////////////////////////////////////////////////////////////////////////
130// Math routines
131//////////////////////////////////////////////////////////////////////////////
132
Romain Guy8839ca52009-07-31 11:20:59 -0700133#define PI 3.1415926f
134#define DEG_TO_RAD PI / 180.0f
135#define RAD_TO_DEG 180.0f / PI
136
Jason Samsc97bb882009-07-20 14:31:06 -0700137static float SC_randf(float max)
138{
139 float r = (float)rand();
140 return r / RAND_MAX * max;
141}
142
Romain Guy8839ca52009-07-31 11:20:59 -0700143static float SC_randf2(float min, float max)
144{
145 float r = (float)rand();
146 return r / RAND_MAX * (max - min) + min;
147}
148
149static float SC_clampf(float amount, float low, float high)
150{
151 return amount < low ? low : (amount > high ? high : amount);
152}
153
154static float SC_maxf(float a, float b)
155{
156 return a > b ? a : b;
157}
158
159static float SC_minf(float a, float b)
160{
161 return a < b ? a : b;
162}
163
164static float SC_sqrf(float v)
165{
166 return v * v;
167}
168
169static float SC_distf2(float x1, float y1, float x2, float y2)
170{
171 float x = x2 - x1;
172 float y = y2 - y1;
173 return sqrtf(x * x + y * y);
174}
175
176static float SC_distf3(float x1, float y1, float z1, float x2, float y2, float z2)
177{
178 float x = x2 - x1;
179 float y = y2 - y1;
180 float z = z2 - z1;
181 return sqrtf(x * x + y * y + z * z);
182}
183
184static float SC_magf2(float a, float b)
185{
186 return sqrtf(a * a + b * b);
187}
188
189static float SC_magf3(float a, float b, float c)
190{
191 return sqrtf(a * a + b * b + c * c);
192}
193
194static float SC_radf(float degrees)
195{
196 return degrees * DEG_TO_RAD;
197}
198
199static float SC_degf(float radians)
200{
201 return radians * RAD_TO_DEG;
202}
203
204static float SC_lerpf(float start, float stop, float amount)
205{
206 return start + (stop - start) * amount;
207}
208
209static float SC_normf(float start, float stop, float value)
210{
211 return (value - start) / (stop - start);
212}
213
214static float SC_mapf(float minStart, float minStop, float maxStart, float maxStop, float value)
215{
216 return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart));
217}
Jason Samsc97bb882009-07-20 14:31:06 -0700218
Romain Guy584a3752009-07-30 18:45:01 -0700219//////////////////////////////////////////////////////////////////////////////
220// Time routines
221//////////////////////////////////////////////////////////////////////////////
Jason Samsc97bb882009-07-20 14:31:06 -0700222
Romain Guy584a3752009-07-30 18:45:01 -0700223static uint32_t SC_second()
224{
225 GET_TLS();
226
227 time_t rawtime;
228 time(&rawtime);
229
230 if (sc->mEnviroment.mTimeZone) {
231 struct tm timeinfo;
232 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
233 return timeinfo.tm_sec;
234 } else {
235 struct tm *timeinfo;
236 timeinfo = localtime(&rawtime);
237 return timeinfo->tm_sec;
238 }
239}
240
241static uint32_t SC_minute()
242{
243 GET_TLS();
244
245 time_t rawtime;
246 time(&rawtime);
247
248 if (sc->mEnviroment.mTimeZone) {
249 struct tm timeinfo;
250 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
251 return timeinfo.tm_min;
252 } else {
253 struct tm *timeinfo;
254 timeinfo = localtime(&rawtime);
255 return timeinfo->tm_min;
256 }
257}
258
Romain Guy8839ca52009-07-31 11:20:59 -0700259static uint32_t SC_hour()
Romain Guy584a3752009-07-30 18:45:01 -0700260{
261 GET_TLS();
262
263 time_t rawtime;
264 time(&rawtime);
265
266 if (sc->mEnviroment.mTimeZone) {
267 struct tm timeinfo;
268 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
269 return timeinfo.tm_hour;
270 } else {
271 struct tm *timeinfo;
272 timeinfo = localtime(&rawtime);
273 return timeinfo->tm_hour;
274 }
Romain Guy8839ca52009-07-31 11:20:59 -0700275}
276
277static uint32_t SC_day()
278{
279 GET_TLS();
280
281 time_t rawtime;
282 time(&rawtime);
283
284 if (sc->mEnviroment.mTimeZone) {
285 struct tm timeinfo;
286 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
287 return timeinfo.tm_mday;
288 } else {
289 struct tm *timeinfo;
290 timeinfo = localtime(&rawtime);
291 return timeinfo->tm_mday;
292 }
Romain Guy584a3752009-07-30 18:45:01 -0700293}
Jason Samsc97bb882009-07-20 14:31:06 -0700294
Romain Guy8839ca52009-07-31 11:20:59 -0700295static uint32_t SC_month()
296{
297 GET_TLS();
298
299 time_t rawtime;
300 time(&rawtime);
301
302 if (sc->mEnviroment.mTimeZone) {
303 struct tm timeinfo;
304 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
305 return timeinfo.tm_mon;
306 } else {
307 struct tm *timeinfo;
308 timeinfo = localtime(&rawtime);
309 return timeinfo->tm_mon;
310 }
311}
312
313static uint32_t SC_year()
314{
315 GET_TLS();
316
317 time_t rawtime;
318 time(&rawtime);
319
320 if (sc->mEnviroment.mTimeZone) {
321 struct tm timeinfo;
322 localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone);
323 return timeinfo.tm_year;
324 } else {
325 struct tm *timeinfo;
326 timeinfo = localtime(&rawtime);
327 return timeinfo->tm_year;
328 }
329}
330
Jason Samsc97bb882009-07-20 14:31:06 -0700331//////////////////////////////////////////////////////////////////////////////
332// Matrix routines
333//////////////////////////////////////////////////////////////////////////////
334
335
336static void SC_matrixLoadIdentity(rsc_Matrix *mat)
337{
338 Matrix *m = reinterpret_cast<Matrix *>(mat);
339 m->loadIdentity();
340}
341
342static void SC_matrixLoadFloat(rsc_Matrix *mat, const float *f)
343{
344 Matrix *m = reinterpret_cast<Matrix *>(mat);
345 m->load(f);
346}
347
348static void SC_matrixLoadMat(rsc_Matrix *mat, const rsc_Matrix *newmat)
349{
350 Matrix *m = reinterpret_cast<Matrix *>(mat);
351 m->load(reinterpret_cast<const Matrix *>(newmat));
352}
353
354static void SC_matrixLoadRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
355{
356 Matrix *m = reinterpret_cast<Matrix *>(mat);
357 m->loadRotate(rot, x, y, z);
358}
359
360static void SC_matrixLoadScale(rsc_Matrix *mat, float x, float y, float z)
361{
362 Matrix *m = reinterpret_cast<Matrix *>(mat);
363 m->loadScale(x, y, z);
364}
365
366static void SC_matrixLoadTranslate(rsc_Matrix *mat, float x, float y, float z)
367{
368 Matrix *m = reinterpret_cast<Matrix *>(mat);
369 m->loadTranslate(x, y, z);
370}
371
372static void SC_matrixLoadMultiply(rsc_Matrix *mat, const rsc_Matrix *lhs, const rsc_Matrix *rhs)
373{
374 Matrix *m = reinterpret_cast<Matrix *>(mat);
375 m->loadMultiply(reinterpret_cast<const Matrix *>(lhs),
376 reinterpret_cast<const Matrix *>(rhs));
377}
378
379static void SC_matrixMultiply(rsc_Matrix *mat, const rsc_Matrix *rhs)
380{
381 Matrix *m = reinterpret_cast<Matrix *>(mat);
382 m->multiply(reinterpret_cast<const Matrix *>(rhs));
383}
384
385static void SC_matrixRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
386{
387 Matrix *m = reinterpret_cast<Matrix *>(mat);
388 m->rotate(rot, x, y, z);
389}
390
391static void SC_matrixScale(rsc_Matrix *mat, float x, float y, float z)
392{
393 Matrix *m = reinterpret_cast<Matrix *>(mat);
394 m->scale(x, y, z);
395}
396
397static void SC_matrixTranslate(rsc_Matrix *mat, float x, float y, float z)
398{
399 Matrix *m = reinterpret_cast<Matrix *>(mat);
400 m->translate(x, y, z);
401}
402
403
404
405
406//////////////////////////////////////////////////////////////////////////////
407// Context
408//////////////////////////////////////////////////////////////////////////////
409
410static void SC_bindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va)
411{
412 GET_TLS();
413 rsi_ProgramFragmentBindTexture(rsc,
414 static_cast<ProgramFragment *>(vpf),
415 slot,
416 static_cast<Allocation *>(va));
417
418}
419
420static void SC_bindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs)
421{
422 GET_TLS();
423 rsi_ProgramFragmentBindSampler(rsc,
424 static_cast<ProgramFragment *>(vpf),
425 slot,
426 static_cast<Sampler *>(vs));
427
428}
429
430static void SC_bindProgramFragmentStore(RsProgramFragmentStore pfs)
431{
432 GET_TLS();
433 rsi_ContextBindProgramFragmentStore(rsc, pfs);
434
435}
436
437static void SC_bindProgramFragment(RsProgramFragment pf)
438{
439 GET_TLS();
440 rsi_ContextBindProgramFragment(rsc, pf);
441
442}
443
Jason Samsee411122009-07-21 12:20:54 -0700444static void SC_bindProgramVertex(RsProgramVertex pv)
445{
446 GET_TLS();
447 rsi_ContextBindProgramVertex(rsc, pv);
448
449}
Jason Samsc97bb882009-07-20 14:31:06 -0700450
451//////////////////////////////////////////////////////////////////////////////
Jason Samsb0ec1b42009-07-28 12:02:16 -0700452// VP
453//////////////////////////////////////////////////////////////////////////////
454
455static void SC_vpLoadModelMatrix(const rsc_Matrix *m)
456{
457 GET_TLS();
458 rsc->getVertex()->setModelviewMatrix(m);
459}
460
461static void SC_vpLoadTextureMatrix(const rsc_Matrix *m)
462{
463 GET_TLS();
464 rsc->getVertex()->setTextureMatrix(m);
465}
466
467
468
469//////////////////////////////////////////////////////////////////////////////
Jason Samsc97bb882009-07-20 14:31:06 -0700470// Drawing
471//////////////////////////////////////////////////////////////////////////////
472
473static void SC_drawTriangleMesh(RsTriangleMesh mesh)
474{
475 GET_TLS();
476 rsi_TriangleMeshRender(rsc, mesh);
477}
478
479static void SC_drawTriangleMeshRange(RsTriangleMesh mesh, uint32_t start, uint32_t count)
480{
481 GET_TLS();
482 rsi_TriangleMeshRenderRange(rsc, mesh, start, count);
483}
484
485// Assumes (GL_FIXED) x,y,z (GL_UNSIGNED_BYTE)r,g,b,a
486static void SC_drawTriangleArray(int ialloc, uint32_t count)
487{
488 GET_TLS();
489 RsAllocation alloc = (RsAllocation)ialloc;
490
491 const Allocation *a = (const Allocation *)alloc;
492 const uint32_t *ptr = (const uint32_t *)a->getPtr();
493
494 rsc->setupCheck();
495
496 glBindBuffer(GL_ARRAY_BUFFER, 0);
497 //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]);
498
499 glEnableClientState(GL_VERTEX_ARRAY);
500 glDisableClientState(GL_NORMAL_ARRAY);
501 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
502 glEnableClientState(GL_COLOR_ARRAY);
503
504 glVertexPointer(2, GL_FIXED, 12, ptr + 1);
505 //glTexCoordPointer(2, GL_FIXED, 24, ptr + 1);
506 glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr);
507
508 glDrawArrays(GL_TRIANGLES, 0, count * 3);
509}
510
511static void SC_drawQuad(float x1, float y1, float z1,
512 float x2, float y2, float z2,
513 float x3, float y3, float z3,
514 float x4, float y4, float z4)
515{
516 GET_TLS();
517
518 //LOGE("Quad");
519 //LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1);
520 //LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2);
521 //LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3);
522 //LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4);
523
524 float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4};
525 static const float tex[] = {0,1, 1,1, 1,0, 0,0};
526
527
528 rsc->setupCheck();
529
530 glBindBuffer(GL_ARRAY_BUFFER, 0);
531 //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]);
532
533 glEnableClientState(GL_VERTEX_ARRAY);
534 glVertexPointer(3, GL_FLOAT, 0, vtx);
535
536 glClientActiveTexture(GL_TEXTURE0);
537 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
538 glTexCoordPointer(2, GL_FLOAT, 0, tex);
539 glClientActiveTexture(GL_TEXTURE1);
540 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
541 glTexCoordPointer(2, GL_FLOAT, 0, tex);
542 glClientActiveTexture(GL_TEXTURE0);
543
544 glDisableClientState(GL_NORMAL_ARRAY);
545 glDisableClientState(GL_COLOR_ARRAY);
546
547 //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr);
548
549 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
550}
551
Jason Sams6f5c61c2009-07-28 17:20:11 -0700552static void SC_drawRect(float x1, float y1,
553 float x2, float y2, float z)
554{
555 SC_drawQuad(x1, y2, z,
556 x2, y2, z,
557 x2, y1, z,
558 x1, y1, z);
559}
560
Jason Samsc97bb882009-07-20 14:31:06 -0700561//////////////////////////////////////////////////////////////////////////////
562//
563//////////////////////////////////////////////////////////////////////////////
564
Jason Samsc97bb882009-07-20 14:31:06 -0700565static void SC_color(float r, float g, float b, float a)
566{
567 glColor4f(r, g, b, a);
568}
569
Romain Guya32d1002009-07-31 15:33:59 -0700570static void SC_hsb(float h, float s, float b, float a)
571{
572 float red = 0.0f;
573 float green = 0.0f;
574 float blue = 0.0f;
575
576 float x = h;
577 float y = s;
578 float z = b;
579
580 float hf = (x - (int) x) * 6.0f;
581 int ihf = (int) hf;
582 float f = hf - ihf;
583 float pv = z * (1.0f - y);
584 float qv = z * (1.0f - y * f);
585 float tv = z * (1.0f - y * (1.0f - f));
586
587 switch (ihf) {
588 case 0: // Red is the dominant color
589 red = z;
590 green = tv;
591 blue = pv;
592 break;
593 case 1: // Green is the dominant color
594 red = qv;
595 green = z;
596 blue = pv;
597 break;
598 case 2:
599 red = pv;
600 green = z;
601 blue = tv;
602 break;
603 case 3: // Blue is the dominant color
604 red = pv;
605 green = qv;
606 blue = z;
607 break;
608 case 4:
609 red = tv;
610 green = pv;
611 blue = z;
612 break;
613 case 5: // Red is the dominant color
614 red = z;
615 green = pv;
616 blue = qv;
617 break;
618 }
619
620 glColor4f(red, green, blue, a);
621}
622
Jason Samsb0ec1b42009-07-28 12:02:16 -0700623/*
Jason Samsc97bb882009-07-20 14:31:06 -0700624extern "C" void materialDiffuse(float r, float g, float b, float a)
625{
626 float v[] = {r, g, b, a};
627 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, v);
628}
629
630extern "C" void materialSpecular(float r, float g, float b, float a)
631{
632 float v[] = {r, g, b, a};
633 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, v);
634}
635
Jason Samsc97bb882009-07-20 14:31:06 -0700636extern "C" void materialShininess(float s)
637{
638 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &s);
639}
Jason Samsb0ec1b42009-07-28 12:02:16 -0700640*/
Jason Samsc97bb882009-07-20 14:31:06 -0700641
Jason Samsb0ec1b42009-07-28 12:02:16 -0700642static void SC_uploadToTexture(RsAllocation va, uint32_t baseMipLevel)
Jason Samsc97bb882009-07-20 14:31:06 -0700643{
644 GET_TLS();
645 rsi_AllocationUploadToTexture(rsc, va, baseMipLevel);
646}
647
Jason Samsc97bb882009-07-20 14:31:06 -0700648static void SC_ClearColor(float r, float g, float b, float a)
649{
650 //LOGE("c %f %f %f %f", r, g, b, a);
651 GET_TLS();
652 sc->mEnviroment.mClearColor[0] = r;
653 sc->mEnviroment.mClearColor[1] = g;
654 sc->mEnviroment.mClearColor[2] = b;
655 sc->mEnviroment.mClearColor[3] = a;
656}
657
Jason Samsb0ec1b42009-07-28 12:02:16 -0700658static void SC_debugF(const char *s, float f)
659{
660 LOGE("%s %f", s, f);
661}
662
663static void SC_debugI32(const char *s, int32_t i)
664{
665 LOGE("%s %i", s, i);
666}
667
Jason Samsc97bb882009-07-20 14:31:06 -0700668
669
670//////////////////////////////////////////////////////////////////////////////
671// Class implementation
672//////////////////////////////////////////////////////////////////////////////
673
674ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
675 // IO
676 { "loadI32", (void *)&SC_loadI32,
677 "int", "(int, int)" },
678 //{ "loadU32", (void *)&SC_loadU32, "unsigned int", "(int, int)" },
679 { "loadF", (void *)&SC_loadF,
680 "float", "(int, int)" },
681 { "loadVec4", (void *)&SC_loadVec4,
682 "void", "(int, int, float *)" },
683 { "loadMatrix", (void *)&SC_loadMatrix,
684 "void", "(int, int, float *)" },
685 { "storeI32", (void *)&SC_storeI32,
686 "void", "(int, int, int)" },
687 //{ "storeU32", (void *)&SC_storeU32, "void", "(int, int, unsigned int)" },
688 { "storeF", (void *)&SC_storeF,
689 "void", "(int, int, float)" },
690 { "storeVec4", (void *)&SC_storeVec4,
691 "void", "(int, int, float *)" },
692 { "storeMatrix", (void *)&SC_storeMatrix,
693 "void", "(int, int, float *)" },
694
695 // math
696 { "sinf", (void *)&sinf,
697 "float", "(float)" },
698 { "cosf", (void *)&cosf,
699 "float", "(float)" },
Romain Guy8839ca52009-07-31 11:20:59 -0700700 { "asinf", (void *)&asinf,
701 "float", "(float)" },
702 { "acosf", (void *)&acosf,
703 "float", "(float)" },
704 { "atanf", (void *)&atanf,
705 "float", "(float)" },
706 { "atan2f", (void *)&atan2f,
Romain Guya32d1002009-07-31 15:33:59 -0700707 "float", "(float, float)" },
Jason Sams6f5c61c2009-07-28 17:20:11 -0700708 { "fabsf", (void *)&fabsf,
Jason Samsc97bb882009-07-20 14:31:06 -0700709 "float", "(float)" },
710 { "randf", (void *)&SC_randf,
711 "float", "(float)" },
Romain Guy8839ca52009-07-31 11:20:59 -0700712 { "randf2", (void *)&SC_randf2,
713 "float", "(float, float)" },
Jason Samsb0ec1b42009-07-28 12:02:16 -0700714 { "floorf", (void *)&floorf,
715 "float", "(float)" },
716 { "ceilf", (void *)&ceilf,
717 "float", "(float)" },
Romain Guy8839ca52009-07-31 11:20:59 -0700718 { "expf", (void *)&expf,
719 "float", "(float)" },
720 { "logf", (void *)&logf,
721 "float", "(float)" },
722 { "powf", (void *)&powf,
723 "float", "(float, float)" },
724 { "maxf", (void *)&SC_maxf,
725 "float", "(float, float)" },
726 { "minf", (void *)&SC_minf,
727 "float", "(float, float)" },
728 { "sqrtf", (void *)&sqrtf,
729 "float", "(float)" },
730 { "sqrf", (void *)&SC_sqrf,
731 "float", "(float)" },
732 { "clampf", (void *)&SC_clampf,
733 "float", "(float, float, float)" },
734 { "distf2", (void *)&SC_distf2,
735 "float", "(float, float, float, float)" },
736 { "distf3", (void *)&SC_distf3,
737 "float", "(float, float, float, float, float, float)" },
738 { "magf2", (void *)&SC_magf2,
739 "float", "(float, float)" },
740 { "magf3", (void *)&SC_magf3,
741 "float", "(float, float, float)" },
742 { "radf", (void *)&SC_radf,
743 "float", "(float)" },
744 { "degf", (void *)&SC_degf,
745 "float", "(float)" },
746 { "lerpf", (void *)&SC_lerpf,
747 "float", "(float, float, float)" },
748 { "normf", (void *)&SC_normf,
749 "float", "(float, float, float)" },
750 { "mapf", (void *)&SC_mapf,
751 "float", "(float, float, float, float, float)" },
Romain Guyecc7ca032009-08-03 21:12:51 -0700752 { "noisef", (void *)&SC_noisef,
753 "float", "(float)" },
754 { "noisef2", (void *)&SC_noisef2,
755 "float", "(float, float)" },
756 { "noisef3", (void *)&SC_noisef3,
757 "float", "(float, float, float)" },
758 { "turbulencef2", (void *)&SC_turbulencef2,
759 "float", "(float, float, float)" },
760 { "turbulencef3", (void *)&SC_turbulencef3,
761 "float", "(float, float, float, float)" },
Jason Samsc97bb882009-07-20 14:31:06 -0700762
Romain Guy584a3752009-07-30 18:45:01 -0700763 // time
764 { "second", (void *)&SC_second,
765 "int", "()" },
766 { "minute", (void *)&SC_minute,
767 "int", "()" },
768 { "hour", (void *)&SC_hour,
769 "int", "()" },
Romain Guy8839ca52009-07-31 11:20:59 -0700770 { "day", (void *)&SC_day,
771 "int", "()" },
772 { "month", (void *)&SC_month,
773 "int", "()" },
774 { "year", (void *)&SC_year,
775 "int", "()" },
Romain Guy584a3752009-07-30 18:45:01 -0700776
Jason Samsc97bb882009-07-20 14:31:06 -0700777 // matrix
778 { "matrixLoadIdentity", (void *)&SC_matrixLoadIdentity,
779 "void", "(float *mat)" },
780 { "matrixLoadFloat", (void *)&SC_matrixLoadFloat,
781 "void", "(float *mat, float *f)" },
782 { "matrixLoadMat", (void *)&SC_matrixLoadMat,
783 "void", "(float *mat, float *newmat)" },
784 { "matrixLoadRotate", (void *)&SC_matrixLoadRotate,
785 "void", "(float *mat, float rot, float x, float y, float z)" },
786 { "matrixLoadScale", (void *)&SC_matrixLoadScale,
787 "void", "(float *mat, float x, float y, float z)" },
788 { "matrixLoadTranslate", (void *)&SC_matrixLoadTranslate,
789 "void", "(float *mat, float x, float y, float z)" },
790 { "matrixLoadMultiply", (void *)&SC_matrixLoadMultiply,
791 "void", "(float *mat, float *lhs, float *rhs)" },
792 { "matrixMultiply", (void *)&SC_matrixMultiply,
793 "void", "(float *mat, float *rhs)" },
794 { "matrixRotate", (void *)&SC_matrixRotate,
795 "void", "(float *mat, float rot, float x, float y, float z)" },
796 { "matrixScale", (void *)&SC_matrixScale,
797 "void", "(float *mat, float x, float y, float z)" },
798 { "matrixTranslate", (void *)&SC_matrixTranslate,
799 "void", "(float *mat, float x, float y, float z)" },
800
801 // context
802 { "bindProgramFragment", (void *)&SC_bindProgramFragment,
803 "void", "(int)" },
804 { "bindProgramFragmentStore", (void *)&SC_bindProgramFragmentStore,
805 "void", "(int)" },
Jason Samsee411122009-07-21 12:20:54 -0700806 { "bindProgramVertex", (void *)&SC_bindProgramVertex,
807 "void", "(int)" },
Jason Samsc97bb882009-07-20 14:31:06 -0700808 { "bindSampler", (void *)&SC_bindSampler,
809 "void", "(int, int, int)" },
810 { "bindTexture", (void *)&SC_bindTexture,
811 "void", "(int, int, int)" },
812
Jason Samsb0ec1b42009-07-28 12:02:16 -0700813 // vp
Jason Samsfaf15202009-07-29 20:55:44 -0700814 { "vpLoadModelMatrix", (void *)&SC_vpLoadModelMatrix,
Jason Samsb0ec1b42009-07-28 12:02:16 -0700815 "void", "(void *)" },
Jason Samsfaf15202009-07-29 20:55:44 -0700816 { "vpLoadTextureMatrix", (void *)&SC_vpLoadTextureMatrix,
Jason Samsb0ec1b42009-07-28 12:02:16 -0700817 "void", "(void *)" },
818
819
820
Jason Samsc97bb882009-07-20 14:31:06 -0700821 // drawing
Jason Sams6f5c61c2009-07-28 17:20:11 -0700822 { "drawRect", (void *)&SC_drawRect,
823 "void", "(float x1, float y1, float x2, float y2, float z)" },
Jason Samsc97bb882009-07-20 14:31:06 -0700824 { "drawQuad", (void *)&SC_drawQuad,
825 "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)" },
826 { "drawTriangleArray", (void *)&SC_drawTriangleArray,
827 "void", "(int ialloc, int count)" },
828 { "drawTriangleMesh", (void *)&SC_drawTriangleMesh,
829 "void", "(int mesh)" },
830 { "drawTriangleMeshRange", (void *)&SC_drawTriangleMeshRange,
831 "void", "(int mesh, int start, int count)" },
832
833
834 // misc
835 { "pfClearColor", (void *)&SC_ClearColor,
836 "void", "(float, float, float, float)" },
Jason Samsc97bb882009-07-20 14:31:06 -0700837 { "color", (void *)&SC_color,
838 "void", "(float, float, float, float)" },
Romain Guya32d1002009-07-31 15:33:59 -0700839 { "hsb", (void *)&SC_hsb,
840 "void", "(float, float, float, float)" },
Jason Samsc97bb882009-07-20 14:31:06 -0700841
Jason Samsb0ec1b42009-07-28 12:02:16 -0700842 { "uploadToTexture", (void *)&SC_uploadToTexture,
843 "void", "(int, int)" },
844
845
846 { "debugF", (void *)&SC_debugF,
847 "void", "(void *, float)" },
848 { "debugI32", (void *)&SC_debugI32,
849 "void", "(void *, int)" },
850
851
Jason Samsc97bb882009-07-20 14:31:06 -0700852 { NULL, NULL, NULL, NULL }
853};
854
855const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym)
856{
857 ScriptCState::SymbolTable_t *syms = gSyms;
858
859 while (syms->mPtr) {
860 if (!strcmp(syms->mName, sym)) {
861 return syms;
862 }
863 syms++;
864 }
865 return NULL;
866}
867
868void ScriptCState::appendDecls(String8 *str)
869{
870 ScriptCState::SymbolTable_t *syms = gSyms;
871 while (syms->mPtr) {
872 str->append(syms->mRet);
873 str->append(" ");
874 str->append(syms->mName);
875 str->append(syms->mParam);
876 str->append(";\n");
877 syms++;
878 }
879}
880
881