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