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