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 #include "rsNoise.h"
21
22 #include "acc/acc.h"
23 #include "utils/Timers.h"
24
25 #define GL_GLEXT_PROTOTYPES
26
27 #include <GLES/gl.h>
28 #include <GLES/glext.h>
29
30 #include <time.h>
31
32 using namespace android;
33 using namespace android::renderscript;
34
35 #define GET_TLS() Context::ScriptTLSStruct * tls = \
36 (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \
37 Context * rsc = tls->mContext; \
38 ScriptC * sc = (ScriptC *) tls->mScript
39
40 typedef struct {
41 float x;
42 float y;
43 float z;
44 } vec3_t;
45
46 typedef struct {
47 float x;
48 float y;
49 float z;
50 float w;
51 } vec4_t;
52
53 typedef struct {
54 float x;
55 float y;
56 } vec2_t;
57
58 //////////////////////////////////////////////////////////////////////////////
59 // IO routines
60 //////////////////////////////////////////////////////////////////////////////
61
SC_loadF(uint32_t bank,uint32_t offset)62 static float SC_loadF(uint32_t bank, uint32_t offset)
63 {
64 GET_TLS();
65 const void *vp = sc->mSlots[bank]->getPtr();
66 const float *f = static_cast<const float *>(vp);
67 //LOGE("loadF %i %i = %f %x", bank, offset, f, ((int *)&f)[0]);
68 return f[offset];
69 }
70
SC_loadI32(uint32_t bank,uint32_t offset)71 static int32_t SC_loadI32(uint32_t bank, uint32_t offset)
72 {
73 GET_TLS();
74 const void *vp = sc->mSlots[bank]->getPtr();
75 const int32_t *i = static_cast<const int32_t *>(vp);
76 //LOGE("loadI32 %i %i = %i", bank, offset, t);
77 return i[offset];
78 }
79
SC_loadArrayF(uint32_t bank,uint32_t offset)80 static float* SC_loadArrayF(uint32_t bank, uint32_t offset)
81 {
82 GET_TLS();
83 void *vp = sc->mSlots[bank]->getPtr();
84 float *f = static_cast<float *>(vp);
85 return f + offset;
86 }
87
SC_loadArrayI32(uint32_t bank,uint32_t offset)88 static int32_t* SC_loadArrayI32(uint32_t bank, uint32_t offset)
89 {
90 GET_TLS();
91 void *vp = sc->mSlots[bank]->getPtr();
92 int32_t *i = static_cast<int32_t *>(vp);
93 return i + offset;
94 }
95
SC_loadSimpleMeshVerticesF(RsSimpleMesh mesh,uint32_t idx)96 static float* SC_loadSimpleMeshVerticesF(RsSimpleMesh mesh, uint32_t idx)
97 {
98 SimpleMesh *tm = static_cast<SimpleMesh *>(mesh);
99 void *vp = tm->mVertexBuffers[idx]->getPtr();;
100 return static_cast<float *>(vp);
101 }
102
SC_updateSimpleMesh(RsSimpleMesh mesh)103 static void SC_updateSimpleMesh(RsSimpleMesh mesh)
104 {
105 SimpleMesh *sm = static_cast<SimpleMesh *>(mesh);
106 sm->uploadAll();
107 }
108
SC_loadU32(uint32_t bank,uint32_t offset)109 static uint32_t SC_loadU32(uint32_t bank, uint32_t offset)
110 {
111 GET_TLS();
112 const void *vp = sc->mSlots[bank]->getPtr();
113 const uint32_t *i = static_cast<const uint32_t *>(vp);
114 return i[offset];
115 }
116
SC_loadVec4(uint32_t bank,uint32_t offset,rsc_Vector4 * v)117 static void SC_loadVec4(uint32_t bank, uint32_t offset, rsc_Vector4 *v)
118 {
119 GET_TLS();
120 const void *vp = sc->mSlots[bank]->getPtr();
121 const float *f = static_cast<const float *>(vp);
122 memcpy(v, &f[offset], sizeof(rsc_Vector4));
123 }
124
SC_loadMatrix(uint32_t bank,uint32_t offset,rsc_Matrix * m)125 static void SC_loadMatrix(uint32_t bank, uint32_t offset, rsc_Matrix *m)
126 {
127 GET_TLS();
128 const void *vp = sc->mSlots[bank]->getPtr();
129 const float *f = static_cast<const float *>(vp);
130 memcpy(m, &f[offset], sizeof(rsc_Matrix));
131 }
132
133
SC_storeF(uint32_t bank,uint32_t offset,float v)134 static void SC_storeF(uint32_t bank, uint32_t offset, float v)
135 {
136 //LOGE("storeF %i %i %f", bank, offset, v);
137 GET_TLS();
138 void *vp = sc->mSlots[bank]->getPtr();
139 float *f = static_cast<float *>(vp);
140 f[offset] = v;
141 }
142
SC_storeI32(uint32_t bank,uint32_t offset,int32_t v)143 static void SC_storeI32(uint32_t bank, uint32_t offset, int32_t v)
144 {
145 GET_TLS();
146 void *vp = sc->mSlots[bank]->getPtr();
147 int32_t *f = static_cast<int32_t *>(vp);
148 static_cast<int32_t *>(sc->mSlots[bank]->getPtr())[offset] = v;
149 }
150
SC_storeU32(uint32_t bank,uint32_t offset,uint32_t v)151 static void SC_storeU32(uint32_t bank, uint32_t offset, uint32_t v)
152 {
153 GET_TLS();
154 void *vp = sc->mSlots[bank]->getPtr();
155 uint32_t *f = static_cast<uint32_t *>(vp);
156 static_cast<uint32_t *>(sc->mSlots[bank]->getPtr())[offset] = v;
157 }
158
SC_storeVec4(uint32_t bank,uint32_t offset,const rsc_Vector4 * v)159 static void SC_storeVec4(uint32_t bank, uint32_t offset, const rsc_Vector4 *v)
160 {
161 GET_TLS();
162 void *vp = sc->mSlots[bank]->getPtr();
163 float *f = static_cast<float *>(vp);
164 memcpy(&f[offset], v, sizeof(rsc_Vector4));
165 }
166
SC_storeMatrix(uint32_t bank,uint32_t offset,const rsc_Matrix * m)167 static void SC_storeMatrix(uint32_t bank, uint32_t offset, const rsc_Matrix *m)
168 {
169 GET_TLS();
170 void *vp = sc->mSlots[bank]->getPtr();
171 float *f = static_cast<float *>(vp);
172 memcpy(&f[offset], m, sizeof(rsc_Matrix));
173 }
174
175 //////////////////////////////////////////////////////////////////////////////
176 // Vec3 routines
177 //////////////////////////////////////////////////////////////////////////////
178
SC_vec3Norm(vec3_t * v)179 static void SC_vec3Norm(vec3_t *v)
180 {
181 float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
182 len = 1 / len;
183 v->x *= len;
184 v->y *= len;
185 v->z *= len;
186 }
187
SC_vec3Length(const vec3_t * v)188 static float SC_vec3Length(const vec3_t *v)
189 {
190 return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
191 }
192
SC_vec3Add(vec3_t * dest,const vec3_t * lhs,const vec3_t * rhs)193 static void SC_vec3Add(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
194 {
195 dest->x = lhs->x + rhs->x;
196 dest->y = lhs->y + rhs->y;
197 dest->z = lhs->z + rhs->z;
198 }
199
SC_vec3Sub(vec3_t * dest,const vec3_t * lhs,const vec3_t * rhs)200 static void SC_vec3Sub(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
201 {
202 dest->x = lhs->x - rhs->x;
203 dest->y = lhs->y - rhs->y;
204 dest->z = lhs->z - rhs->z;
205 }
206
SC_vec3Cross(vec3_t * dest,const vec3_t * lhs,const vec3_t * rhs)207 static void SC_vec3Cross(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
208 {
209 float x = lhs->y * rhs->z - lhs->z * rhs->y;
210 float y = lhs->z * rhs->x - lhs->x * rhs->z;
211 float z = lhs->x * rhs->y - lhs->y * rhs->x;
212 dest->x = x;
213 dest->y = y;
214 dest->z = z;
215 }
216
SC_vec3Dot(const vec3_t * lhs,const vec3_t * rhs)217 static float SC_vec3Dot(const vec3_t *lhs, const vec3_t *rhs)
218 {
219 return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z;
220 }
221
SC_vec3Scale(vec3_t * lhs,float scale)222 static void SC_vec3Scale(vec3_t *lhs, float scale)
223 {
224 lhs->x *= scale;
225 lhs->y *= scale;
226 lhs->z *= scale;
227 }
228
229 //////////////////////////////////////////////////////////////////////////////
230 // Vec4 routines
231 //////////////////////////////////////////////////////////////////////////////
232
SC_vec4Norm(vec4_t * v)233 static void SC_vec4Norm(vec4_t *v)
234 {
235 float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w);
236 len = 1 / len;
237 v->x *= len;
238 v->y *= len;
239 v->z *= len;
240 v->w *= len;
241 }
242
SC_vec4Length(const vec4_t * v)243 static float SC_vec4Length(const vec4_t *v)
244 {
245 return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w);
246 }
247
SC_vec4Add(vec4_t * dest,const vec4_t * lhs,const vec4_t * rhs)248 static void SC_vec4Add(vec4_t *dest, const vec4_t *lhs, const vec4_t *rhs)
249 {
250 dest->x = lhs->x + rhs->x;
251 dest->y = lhs->y + rhs->y;
252 dest->z = lhs->z + rhs->z;
253 dest->w = lhs->w + rhs->w;
254 }
255
SC_vec4Sub(vec4_t * dest,const vec4_t * lhs,const vec4_t * rhs)256 static void SC_vec4Sub(vec4_t *dest, const vec4_t *lhs, const vec4_t *rhs)
257 {
258 dest->x = lhs->x - rhs->x;
259 dest->y = lhs->y - rhs->y;
260 dest->z = lhs->z - rhs->z;
261 dest->w = lhs->w - rhs->w;
262 }
263
SC_vec4Dot(const vec4_t * lhs,const vec4_t * rhs)264 static float SC_vec4Dot(const vec4_t *lhs, const vec4_t *rhs)
265 {
266 return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z + lhs->w * rhs->w;
267 }
268
SC_vec4Scale(vec4_t * lhs,float scale)269 static void SC_vec4Scale(vec4_t *lhs, float scale)
270 {
271 lhs->x *= scale;
272 lhs->y *= scale;
273 lhs->z *= scale;
274 lhs->w *= scale;
275 }
276
277 //////////////////////////////////////////////////////////////////////////////
278 // Math routines
279 //////////////////////////////////////////////////////////////////////////////
280
281 #define PI 3.1415926f
282 #define DEG_TO_RAD PI / 180.0f
283 #define RAD_TO_DEG 180.0f / PI
284
SC_sinf_fast(float x)285 static float SC_sinf_fast(float x)
286 {
287 const float A = 1.0f / (2.0f * M_PI);
288 const float B = -16.0f;
289 const float C = 8.0f;
290
291 // scale angle for easy argument reduction
292 x *= A;
293
294 if (fabsf(x) >= 0.5f) {
295 // argument reduction
296 x = x - ceilf(x + 0.5f) + 1.0f;
297 }
298
299 const float y = B * x * fabsf(x) + C * x;
300 return 0.2215f * (y * fabsf(y) - y) + y;
301 }
302
SC_cosf_fast(float x)303 static float SC_cosf_fast(float x)
304 {
305 x += float(M_PI / 2);
306
307 const float A = 1.0f / (2.0f * M_PI);
308 const float B = -16.0f;
309 const float C = 8.0f;
310
311 // scale angle for easy argument reduction
312 x *= A;
313
314 if (fabsf(x) >= 0.5f) {
315 // argument reduction
316 x = x - ceilf(x + 0.5f) + 1.0f;
317 }
318
319 const float y = B * x * fabsf(x) + C * x;
320 return 0.2215f * (y * fabsf(y) - y) + y;
321 }
322
SC_randf(float max)323 static float SC_randf(float max)
324 {
325 float r = (float)rand();
326 return r / RAND_MAX * max;
327 }
328
SC_randf2(float min,float max)329 static float SC_randf2(float min, float max)
330 {
331 float r = (float)rand();
332 return r / RAND_MAX * (max - min) + min;
333 }
334
SC_sign(int value)335 static int SC_sign(int value)
336 {
337 return (value > 0) - (value < 0);
338 }
339
SC_signf(float value)340 static float SC_signf(float value)
341 {
342 return (value > 0) - (value < 0);
343 }
344
SC_clampf(float amount,float low,float high)345 static float SC_clampf(float amount, float low, float high)
346 {
347 return amount < low ? low : (amount > high ? high : amount);
348 }
349
SC_clamp(int amount,int low,int high)350 static int SC_clamp(int amount, int low, int high)
351 {
352 return amount < low ? low : (amount > high ? high : amount);
353 }
354
SC_maxf(float a,float b)355 static float SC_maxf(float a, float b)
356 {
357 return a > b ? a : b;
358 }
359
SC_minf(float a,float b)360 static float SC_minf(float a, float b)
361 {
362 return a < b ? a : b;
363 }
364
SC_sqrf(float v)365 static float SC_sqrf(float v)
366 {
367 return v * v;
368 }
369
SC_sqr(int v)370 static int SC_sqr(int v)
371 {
372 return v * v;
373 }
374
SC_fracf(float v)375 static float SC_fracf(float v)
376 {
377 return v - floorf(v);
378 }
379
SC_roundf(float v)380 static float SC_roundf(float v)
381 {
382 return floorf(v + 0.4999999999);
383 }
384
SC_distf2(float x1,float y1,float x2,float y2)385 static float SC_distf2(float x1, float y1, float x2, float y2)
386 {
387 float x = x2 - x1;
388 float y = y2 - y1;
389 return sqrtf(x * x + y * y);
390 }
391
SC_distf3(float x1,float y1,float z1,float x2,float y2,float z2)392 static float SC_distf3(float x1, float y1, float z1, float x2, float y2, float z2)
393 {
394 float x = x2 - x1;
395 float y = y2 - y1;
396 float z = z2 - z1;
397 return sqrtf(x * x + y * y + z * z);
398 }
399
SC_magf2(float a,float b)400 static float SC_magf2(float a, float b)
401 {
402 return sqrtf(a * a + b * b);
403 }
404
SC_magf3(float a,float b,float c)405 static float SC_magf3(float a, float b, float c)
406 {
407 return sqrtf(a * a + b * b + c * c);
408 }
409
SC_radf(float degrees)410 static float SC_radf(float degrees)
411 {
412 return degrees * DEG_TO_RAD;
413 }
414
SC_degf(float radians)415 static float SC_degf(float radians)
416 {
417 return radians * RAD_TO_DEG;
418 }
419
SC_lerpf(float start,float stop,float amount)420 static float SC_lerpf(float start, float stop, float amount)
421 {
422 return start + (stop - start) * amount;
423 }
424
SC_normf(float start,float stop,float value)425 static float SC_normf(float start, float stop, float value)
426 {
427 return (value - start) / (stop - start);
428 }
429
SC_mapf(float minStart,float minStop,float maxStart,float maxStop,float value)430 static float SC_mapf(float minStart, float minStop, float maxStart, float maxStop, float value)
431 {
432 return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart));
433 }
434
435 //////////////////////////////////////////////////////////////////////////////
436 // Time routines
437 //////////////////////////////////////////////////////////////////////////////
438
SC_second()439 static int32_t SC_second()
440 {
441 GET_TLS();
442
443 time_t rawtime;
444 time(&rawtime);
445
446 struct tm *timeinfo;
447 timeinfo = localtime(&rawtime);
448 return timeinfo->tm_sec;
449 }
450
SC_minute()451 static int32_t SC_minute()
452 {
453 GET_TLS();
454
455 time_t rawtime;
456 time(&rawtime);
457
458 struct tm *timeinfo;
459 timeinfo = localtime(&rawtime);
460 return timeinfo->tm_min;
461 }
462
SC_hour()463 static int32_t SC_hour()
464 {
465 GET_TLS();
466
467 time_t rawtime;
468 time(&rawtime);
469
470 struct tm *timeinfo;
471 timeinfo = localtime(&rawtime);
472 return timeinfo->tm_hour;
473 }
474
SC_day()475 static int32_t SC_day()
476 {
477 GET_TLS();
478
479 time_t rawtime;
480 time(&rawtime);
481
482 struct tm *timeinfo;
483 timeinfo = localtime(&rawtime);
484 return timeinfo->tm_mday;
485 }
486
SC_month()487 static int32_t SC_month()
488 {
489 GET_TLS();
490
491 time_t rawtime;
492 time(&rawtime);
493
494 struct tm *timeinfo;
495 timeinfo = localtime(&rawtime);
496 return timeinfo->tm_mon;
497 }
498
SC_year()499 static int32_t SC_year()
500 {
501 GET_TLS();
502
503 time_t rawtime;
504 time(&rawtime);
505
506 struct tm *timeinfo;
507 timeinfo = localtime(&rawtime);
508 return timeinfo->tm_year;
509 }
510
SC_uptimeMillis()511 static int32_t SC_uptimeMillis()
512 {
513 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
514 }
515
SC_startTimeMillis()516 static int32_t SC_startTimeMillis()
517 {
518 GET_TLS();
519 return sc->mEnviroment.mStartTimeMillis;
520 }
521
SC_elapsedTimeMillis()522 static int32_t SC_elapsedTimeMillis()
523 {
524 GET_TLS();
525 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC))
526 - sc->mEnviroment.mStartTimeMillis;
527 }
528
529 //////////////////////////////////////////////////////////////////////////////
530 // Matrix routines
531 //////////////////////////////////////////////////////////////////////////////
532
533
SC_matrixLoadIdentity(rsc_Matrix * mat)534 static void SC_matrixLoadIdentity(rsc_Matrix *mat)
535 {
536 Matrix *m = reinterpret_cast<Matrix *>(mat);
537 m->loadIdentity();
538 }
539
SC_matrixLoadFloat(rsc_Matrix * mat,const float * f)540 static void SC_matrixLoadFloat(rsc_Matrix *mat, const float *f)
541 {
542 Matrix *m = reinterpret_cast<Matrix *>(mat);
543 m->load(f);
544 }
545
SC_matrixLoadMat(rsc_Matrix * mat,const rsc_Matrix * newmat)546 static void SC_matrixLoadMat(rsc_Matrix *mat, const rsc_Matrix *newmat)
547 {
548 Matrix *m = reinterpret_cast<Matrix *>(mat);
549 m->load(reinterpret_cast<const Matrix *>(newmat));
550 }
551
SC_matrixLoadRotate(rsc_Matrix * mat,float rot,float x,float y,float z)552 static void SC_matrixLoadRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
553 {
554 Matrix *m = reinterpret_cast<Matrix *>(mat);
555 m->loadRotate(rot, x, y, z);
556 }
557
SC_matrixLoadScale(rsc_Matrix * mat,float x,float y,float z)558 static void SC_matrixLoadScale(rsc_Matrix *mat, float x, float y, float z)
559 {
560 Matrix *m = reinterpret_cast<Matrix *>(mat);
561 m->loadScale(x, y, z);
562 }
563
SC_matrixLoadTranslate(rsc_Matrix * mat,float x,float y,float z)564 static void SC_matrixLoadTranslate(rsc_Matrix *mat, float x, float y, float z)
565 {
566 Matrix *m = reinterpret_cast<Matrix *>(mat);
567 m->loadTranslate(x, y, z);
568 }
569
SC_matrixLoadMultiply(rsc_Matrix * mat,const rsc_Matrix * lhs,const rsc_Matrix * rhs)570 static void SC_matrixLoadMultiply(rsc_Matrix *mat, const rsc_Matrix *lhs, const rsc_Matrix *rhs)
571 {
572 Matrix *m = reinterpret_cast<Matrix *>(mat);
573 m->loadMultiply(reinterpret_cast<const Matrix *>(lhs),
574 reinterpret_cast<const Matrix *>(rhs));
575 }
576
SC_matrixMultiply(rsc_Matrix * mat,const rsc_Matrix * rhs)577 static void SC_matrixMultiply(rsc_Matrix *mat, const rsc_Matrix *rhs)
578 {
579 Matrix *m = reinterpret_cast<Matrix *>(mat);
580 m->multiply(reinterpret_cast<const Matrix *>(rhs));
581 }
582
SC_matrixRotate(rsc_Matrix * mat,float rot,float x,float y,float z)583 static void SC_matrixRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
584 {
585 Matrix *m = reinterpret_cast<Matrix *>(mat);
586 m->rotate(rot, x, y, z);
587 }
588
SC_matrixScale(rsc_Matrix * mat,float x,float y,float z)589 static void SC_matrixScale(rsc_Matrix *mat, float x, float y, float z)
590 {
591 Matrix *m = reinterpret_cast<Matrix *>(mat);
592 m->scale(x, y, z);
593 }
594
SC_matrixTranslate(rsc_Matrix * mat,float x,float y,float z)595 static void SC_matrixTranslate(rsc_Matrix *mat, float x, float y, float z)
596 {
597 Matrix *m = reinterpret_cast<Matrix *>(mat);
598 m->translate(x, y, z);
599 }
600
601
SC_vec2Rand(float * vec,float maxLen)602 static void SC_vec2Rand(float *vec, float maxLen)
603 {
604 float angle = SC_randf(PI * 2);
605 float len = SC_randf(maxLen);
606 vec[0] = len * sinf(angle);
607 vec[1] = len * cosf(angle);
608 }
609
610
611
612 //////////////////////////////////////////////////////////////////////////////
613 // Context
614 //////////////////////////////////////////////////////////////////////////////
615
SC_bindTexture(RsProgramFragment vpf,uint32_t slot,RsAllocation va)616 static void SC_bindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va)
617 {
618 GET_TLS();
619 rsi_ProgramFragmentBindTexture(rsc,
620 static_cast<ProgramFragment *>(vpf),
621 slot,
622 static_cast<Allocation *>(va));
623
624 }
625
SC_bindSampler(RsProgramFragment vpf,uint32_t slot,RsSampler vs)626 static void SC_bindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs)
627 {
628 GET_TLS();
629 rsi_ProgramFragmentBindSampler(rsc,
630 static_cast<ProgramFragment *>(vpf),
631 slot,
632 static_cast<Sampler *>(vs));
633
634 }
635
SC_bindProgramFragmentStore(RsProgramFragmentStore pfs)636 static void SC_bindProgramFragmentStore(RsProgramFragmentStore pfs)
637 {
638 GET_TLS();
639 rsi_ContextBindProgramFragmentStore(rsc, pfs);
640
641 }
642
SC_bindProgramFragment(RsProgramFragment pf)643 static void SC_bindProgramFragment(RsProgramFragment pf)
644 {
645 GET_TLS();
646 rsi_ContextBindProgramFragment(rsc, pf);
647
648 }
649
SC_bindProgramVertex(RsProgramVertex pv)650 static void SC_bindProgramVertex(RsProgramVertex pv)
651 {
652 GET_TLS();
653 rsi_ContextBindProgramVertex(rsc, pv);
654
655 }
656
657 //////////////////////////////////////////////////////////////////////////////
658 // VP
659 //////////////////////////////////////////////////////////////////////////////
660
SC_vpLoadModelMatrix(const rsc_Matrix * m)661 static void SC_vpLoadModelMatrix(const rsc_Matrix *m)
662 {
663 GET_TLS();
664 rsc->getVertex()->setModelviewMatrix(m);
665 }
666
SC_vpLoadTextureMatrix(const rsc_Matrix * m)667 static void SC_vpLoadTextureMatrix(const rsc_Matrix *m)
668 {
669 GET_TLS();
670 rsc->getVertex()->setTextureMatrix(m);
671 }
672
673
674
675 //////////////////////////////////////////////////////////////////////////////
676 // Drawing
677 //////////////////////////////////////////////////////////////////////////////
678
SC_drawLine(float x1,float y1,float z1,float x2,float y2,float z2)679 static void SC_drawLine(float x1, float y1, float z1,
680 float x2, float y2, float z2)
681 {
682 GET_TLS();
683 rsc->setupCheck();
684
685 float vtx[] = { x1, y1, z1, x2, y2, z2 };
686
687 glBindBuffer(GL_ARRAY_BUFFER, 0);
688 glEnableClientState(GL_VERTEX_ARRAY);
689 glVertexPointer(3, GL_FLOAT, 0, vtx);
690
691 glDisableClientState(GL_NORMAL_ARRAY);
692 glDisableClientState(GL_COLOR_ARRAY);
693
694 glDrawArrays(GL_LINES, 0, 2);
695 }
696
SC_drawPoint(float x,float y,float z)697 static void SC_drawPoint(float x, float y, float z)
698 {
699 GET_TLS();
700 rsc->setupCheck();
701
702 float vtx[] = { x, y, z };
703
704 glBindBuffer(GL_ARRAY_BUFFER, 0);
705 glEnableClientState(GL_VERTEX_ARRAY);
706 glVertexPointer(3, GL_FLOAT, 0, vtx);
707
708 glDisableClientState(GL_NORMAL_ARRAY);
709 glDisableClientState(GL_COLOR_ARRAY);
710
711 glDrawArrays(GL_POINTS, 0, 1);
712 }
713
SC_drawQuadTexCoords(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)714 static void SC_drawQuadTexCoords(float x1, float y1, float z1,
715 float u1, float v1,
716 float x2, float y2, float z2,
717 float u2, float v2,
718 float x3, float y3, float z3,
719 float u3, float v3,
720 float x4, float y4, float z4,
721 float u4, float v4)
722 {
723 GET_TLS();
724
725 //LOGE("Quad");
726 //LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1);
727 //LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2);
728 //LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3);
729 //LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4);
730
731 float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4};
732 const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4};
733
734 rsc->setupCheck();
735
736 glBindBuffer(GL_ARRAY_BUFFER, 0);
737 //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]);
738
739 glEnableClientState(GL_VERTEX_ARRAY);
740 glVertexPointer(3, GL_FLOAT, 0, vtx);
741
742 glClientActiveTexture(GL_TEXTURE0);
743 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
744 glTexCoordPointer(2, GL_FLOAT, 0, tex);
745 glClientActiveTexture(GL_TEXTURE1);
746 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
747 glTexCoordPointer(2, GL_FLOAT, 0, tex);
748 glClientActiveTexture(GL_TEXTURE0);
749
750 glDisableClientState(GL_NORMAL_ARRAY);
751 glDisableClientState(GL_COLOR_ARRAY);
752
753 //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr);
754
755 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
756 }
757
SC_drawQuad(float x1,float y1,float z1,float x2,float y2,float z2,float x3,float y3,float z3,float x4,float y4,float z4)758 static void SC_drawQuad(float x1, float y1, float z1,
759 float x2, float y2, float z2,
760 float x3, float y3, float z3,
761 float x4, float y4, float z4)
762 {
763 SC_drawQuadTexCoords(x1, y1, z1, 0, 1,
764 x2, y2, z2, 1, 1,
765 x3, y3, z3, 1, 0,
766 x4, y4, z4, 0, 0);
767 }
768
SC_drawSpriteScreenspace(float x,float y,float z,float w,float h)769 static void SC_drawSpriteScreenspace(float x, float y, float z, float w, float h)
770 {
771 GET_TLS();
772 rsc->setupCheck();
773
774 GLint crop[4] = {0, h, w, -h};
775 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
776 glDrawTexfOES(x, y, z, w, h);
777 }
778
SC_drawSprite(float x,float y,float z,float w,float h)779 static void SC_drawSprite(float x, float y, float z, float w, float h)
780 {
781 GET_TLS();
782 rsc->setupCheck();
783
784 float vin[3] = {x, y, z};
785 float vout[4];
786
787 //LOGE("ds in %f %f %f", x, y, z);
788 rsc->getVertex()->transformToScreen(rsc, vout, vin);
789 //LOGE("ds out %f %f %f %f", vout[0], vout[1], vout[2], vout[3]);
790 vout[0] /= vout[3];
791 vout[1] /= vout[3];
792 vout[2] /= vout[3];
793
794 vout[0] *= rsc->getWidth() / 2;
795 vout[1] *= rsc->getHeight() / 2;
796 vout[0] += rsc->getWidth() / 2;
797 vout[1] += rsc->getHeight() / 2;
798
799 vout[0] -= w/2;
800 vout[1] -= h/2;
801
802 //LOGE("ds out2 %f %f %f", vout[0], vout[1], vout[2]);
803
804 // U, V, W, H
805 GLint crop[4] = {0, h, w, -h};
806 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
807 glDrawTexiOES(vout[0], vout[1], 0/*vout[2]*/, w, h);
808 }
809
810
SC_drawRect(float x1,float y1,float x2,float y2,float z)811 static void SC_drawRect(float x1, float y1,
812 float x2, float y2, float z)
813 {
814 SC_drawQuad(x1, y2, z,
815 x2, y2, z,
816 x2, y1, z,
817 x1, y1, z);
818 }
819
SC_drawSimpleMesh(RsSimpleMesh vsm)820 static void SC_drawSimpleMesh(RsSimpleMesh vsm)
821 {
822 GET_TLS();
823 SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
824 rsc->setupCheck();
825 sm->render();
826 }
827
SC_drawSimpleMeshRange(RsSimpleMesh vsm,uint32_t start,uint32_t len)828 static void SC_drawSimpleMeshRange(RsSimpleMesh vsm, uint32_t start, uint32_t len)
829 {
830 GET_TLS();
831 SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
832 rsc->setupCheck();
833 sm->renderRange(start, len);
834 }
835
836
837 //////////////////////////////////////////////////////////////////////////////
838 //
839 //////////////////////////////////////////////////////////////////////////////
840
SC_color(float r,float g,float b,float a)841 static void SC_color(float r, float g, float b, float a)
842 {
843 glColor4f(r, g, b, a);
844 }
845
SC_ambient(float r,float g,float b,float a)846 static void SC_ambient(float r, float g, float b, float a)
847 {
848 GLfloat params[] = { r, g, b, a };
849 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, params);
850 }
851
SC_diffuse(float r,float g,float b,float a)852 static void SC_diffuse(float r, float g, float b, float a)
853 {
854 GLfloat params[] = { r, g, b, a };
855 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, params);
856 }
857
SC_specular(float r,float g,float b,float a)858 static void SC_specular(float r, float g, float b, float a)
859 {
860 GLfloat params[] = { r, g, b, a };
861 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, params);
862 }
863
SC_emission(float r,float g,float b,float a)864 static void SC_emission(float r, float g, float b, float a)
865 {
866 GLfloat params[] = { r, g, b, a };
867 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, params);
868 }
869
SC_shininess(float s)870 static void SC_shininess(float s)
871 {
872 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, s);
873 }
874
SC_pointAttenuation(float a,float b,float c)875 static void SC_pointAttenuation(float a, float b, float c)
876 {
877 GLfloat params[] = { a, b, c };
878 glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, params);
879 }
880
SC_hsbToRgb(float h,float s,float b,float * rgb)881 static void SC_hsbToRgb(float h, float s, float b, float* rgb)
882 {
883 float red = 0.0f;
884 float green = 0.0f;
885 float blue = 0.0f;
886
887 float x = h;
888 float y = s;
889 float z = b;
890
891 float hf = (x - (int) x) * 6.0f;
892 int ihf = (int) hf;
893 float f = hf - ihf;
894 float pv = z * (1.0f - y);
895 float qv = z * (1.0f - y * f);
896 float tv = z * (1.0f - y * (1.0f - f));
897
898 switch (ihf) {
899 case 0: // Red is the dominant color
900 red = z;
901 green = tv;
902 blue = pv;
903 break;
904 case 1: // Green is the dominant color
905 red = qv;
906 green = z;
907 blue = pv;
908 break;
909 case 2:
910 red = pv;
911 green = z;
912 blue = tv;
913 break;
914 case 3: // Blue is the dominant color
915 red = pv;
916 green = qv;
917 blue = z;
918 break;
919 case 4:
920 red = tv;
921 green = pv;
922 blue = z;
923 break;
924 case 5: // Red is the dominant color
925 red = z;
926 green = pv;
927 blue = qv;
928 break;
929 }
930
931 rgb[0] = red;
932 rgb[1] = green;
933 rgb[2] = blue;
934 }
935
SC_hsbToAbgr(float h,float s,float b,float a)936 static int SC_hsbToAbgr(float h, float s, float b, float a)
937 {
938 float rgb[3];
939 SC_hsbToRgb(h, s, b, rgb);
940 return int(a * 255.0f) << 24 |
941 int(rgb[2] * 255.0f) << 16 |
942 int(rgb[1] * 255.0f) << 8 |
943 int(rgb[0] * 255.0f);
944 }
945
SC_hsb(float h,float s,float b,float a)946 static void SC_hsb(float h, float s, float b, float a)
947 {
948 float rgb[3];
949 SC_hsbToRgb(h, s, b, rgb);
950 glColor4f(rgb[0], rgb[1], rgb[2], a);
951 }
952
SC_uploadToTexture(RsAllocation va,uint32_t baseMipLevel)953 static void SC_uploadToTexture(RsAllocation va, uint32_t baseMipLevel)
954 {
955 GET_TLS();
956 rsi_AllocationUploadToTexture(rsc, va, baseMipLevel);
957 }
958
SC_uploadToBufferObject(RsAllocation va)959 static void SC_uploadToBufferObject(RsAllocation va)
960 {
961 GET_TLS();
962 rsi_AllocationUploadToBufferObject(rsc, va);
963 }
964
SC_ClearColor(float r,float g,float b,float a)965 static void SC_ClearColor(float r, float g, float b, float a)
966 {
967 //LOGE("c %f %f %f %f", r, g, b, a);
968 GET_TLS();
969 sc->mEnviroment.mClearColor[0] = r;
970 sc->mEnviroment.mClearColor[1] = g;
971 sc->mEnviroment.mClearColor[2] = b;
972 sc->mEnviroment.mClearColor[3] = a;
973 }
974
SC_debugF(const char * s,float f)975 static void SC_debugF(const char *s, float f)
976 {
977 LOGE("%s %f", s, f);
978 }
979
SC_debugHexF(const char * s,float f)980 static void SC_debugHexF(const char *s, float f)
981 {
982 LOGE("%s 0x%x", s, *((int *) (&f)));
983 }
984
SC_debugI32(const char * s,int32_t i)985 static void SC_debugI32(const char *s, int32_t i)
986 {
987 LOGE("%s %i", s, i);
988 }
989
SC_debugHexI32(const char * s,int32_t i)990 static void SC_debugHexI32(const char *s, int32_t i)
991 {
992 LOGE("%s 0x%x", s, i);
993 }
994
SC_getWidth()995 static uint32_t SC_getWidth()
996 {
997 GET_TLS();
998 return rsc->getWidth();
999 }
1000
SC_getHeight()1001 static uint32_t SC_getHeight()
1002 {
1003 GET_TLS();
1004 return rsc->getHeight();
1005 }
1006
SC_colorFloatRGBAtoUNorm8(float r,float g,float b,float a)1007 static uint32_t SC_colorFloatRGBAtoUNorm8(float r, float g, float b, float a)
1008 {
1009 uint32_t c = 0;
1010 c |= (uint32_t)(r * 255.f + 0.5f);
1011 c |= ((uint32_t)(g * 255.f + 0.5f)) << 8;
1012 c |= ((uint32_t)(b * 255.f + 0.5f)) << 16;
1013 c |= ((uint32_t)(a * 255.f + 0.5f)) << 24;
1014 return c;
1015 }
1016
SC_colorFloatRGBAto565(float r,float g,float b)1017 static uint32_t SC_colorFloatRGBAto565(float r, float g, float b)
1018 {
1019 uint32_t ir = (uint32_t)(r * 255.f + 0.5f);
1020 uint32_t ig = (uint32_t)(g * 255.f + 0.5f);
1021 uint32_t ib = (uint32_t)(b * 255.f + 0.5f);
1022 return rs888to565(ir, ig, ib);
1023 }
1024
SC_toClient(void * data,int cmdID,int len,int waitForSpace)1025 static uint32_t SC_toClient(void *data, int cmdID, int len, int waitForSpace)
1026 {
1027 GET_TLS();
1028 return rsc->sendMessageToClient(data, cmdID, len, waitForSpace != 0);
1029 }
1030
SC_scriptCall(int scriptID)1031 static void SC_scriptCall(int scriptID)
1032 {
1033 GET_TLS();
1034 rsc->runScript((Script *)scriptID, 0);
1035 }
1036
1037
1038 //////////////////////////////////////////////////////////////////////////////
1039 // Class implementation
1040 //////////////////////////////////////////////////////////////////////////////
1041
1042 ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
1043 // IO
1044 { "loadI32", (void *)&SC_loadI32,
1045 "int", "(int, int)" },
1046 //{ "loadU32", (void *)&SC_loadU32, "unsigned int", "(int, int)" },
1047 { "loadF", (void *)&SC_loadF,
1048 "float", "(int, int)" },
1049 { "loadArrayF", (void *)&SC_loadArrayF,
1050 "float*", "(int, int)" },
1051 { "loadArrayI32", (void *)&SC_loadArrayI32,
1052 "int*", "(int, int)" },
1053 { "loadVec4", (void *)&SC_loadVec4,
1054 "void", "(int, int, float *)" },
1055 { "loadMatrix", (void *)&SC_loadMatrix,
1056 "void", "(int, int, float *)" },
1057 { "storeI32", (void *)&SC_storeI32,
1058 "void", "(int, int, int)" },
1059 //{ "storeU32", (void *)&SC_storeU32, "void", "(int, int, unsigned int)" },
1060 { "storeF", (void *)&SC_storeF,
1061 "void", "(int, int, float)" },
1062 { "storeVec4", (void *)&SC_storeVec4,
1063 "void", "(int, int, float *)" },
1064 { "storeMatrix", (void *)&SC_storeMatrix,
1065 "void", "(int, int, float *)" },
1066 { "loadSimpleMeshVerticesF", (void *)&SC_loadSimpleMeshVerticesF,
1067 "float*", "(int, int)" },
1068 { "updateSimpleMesh", (void *)&SC_updateSimpleMesh,
1069 "void", "(int)" },
1070
1071 // math
1072 { "modf", (void *)&fmod,
1073 "float", "(float, float)" },
1074 { "abs", (void *)&abs,
1075 "int", "(int)" },
1076 { "absf", (void *)&fabsf,
1077 "float", "(float)" },
1078 { "sinf_fast", (void *)&SC_sinf_fast,
1079 "float", "(float)" },
1080 { "cosf_fast", (void *)&SC_cosf_fast,
1081 "float", "(float)" },
1082 { "sinf", (void *)&sinf,
1083 "float", "(float)" },
1084 { "cosf", (void *)&cosf,
1085 "float", "(float)" },
1086 { "asinf", (void *)&asinf,
1087 "float", "(float)" },
1088 { "acosf", (void *)&acosf,
1089 "float", "(float)" },
1090 { "atanf", (void *)&atanf,
1091 "float", "(float)" },
1092 { "atan2f", (void *)&atan2f,
1093 "float", "(float, float)" },
1094 { "fabsf", (void *)&fabsf,
1095 "float", "(float)" },
1096 { "randf", (void *)&SC_randf,
1097 "float", "(float)" },
1098 { "randf2", (void *)&SC_randf2,
1099 "float", "(float, float)" },
1100 { "floorf", (void *)&floorf,
1101 "float", "(float)" },
1102 { "fracf", (void *)&SC_fracf,
1103 "float", "(float)" },
1104 { "ceilf", (void *)&ceilf,
1105 "float", "(float)" },
1106 { "roundf", (void *)&SC_roundf,
1107 "float", "(float)" },
1108 { "expf", (void *)&expf,
1109 "float", "(float)" },
1110 { "logf", (void *)&logf,
1111 "float", "(float)" },
1112 { "powf", (void *)&powf,
1113 "float", "(float, float)" },
1114 { "maxf", (void *)&SC_maxf,
1115 "float", "(float, float)" },
1116 { "minf", (void *)&SC_minf,
1117 "float", "(float, float)" },
1118 { "sqrt", (void *)&sqrt,
1119 "int", "(int)" },
1120 { "sqrtf", (void *)&sqrtf,
1121 "float", "(float)" },
1122 { "sqr", (void *)&SC_sqr,
1123 "int", "(int)" },
1124 { "sqrf", (void *)&SC_sqrf,
1125 "float", "(float)" },
1126 { "sign", (void *)&SC_sign,
1127 "int", "(int)" },
1128 { "signf", (void *)&SC_signf,
1129 "float", "(float)" },
1130 { "clamp", (void *)&SC_clamp,
1131 "int", "(int, int, int)" },
1132 { "clampf", (void *)&SC_clampf,
1133 "float", "(float, float, float)" },
1134 { "distf2", (void *)&SC_distf2,
1135 "float", "(float, float, float, float)" },
1136 { "distf3", (void *)&SC_distf3,
1137 "float", "(float, float, float, float, float, float)" },
1138 { "magf2", (void *)&SC_magf2,
1139 "float", "(float, float)" },
1140 { "magf3", (void *)&SC_magf3,
1141 "float", "(float, float, float)" },
1142 { "radf", (void *)&SC_radf,
1143 "float", "(float)" },
1144 { "degf", (void *)&SC_degf,
1145 "float", "(float)" },
1146 { "lerpf", (void *)&SC_lerpf,
1147 "float", "(float, float, float)" },
1148 { "normf", (void *)&SC_normf,
1149 "float", "(float, float, float)" },
1150 { "mapf", (void *)&SC_mapf,
1151 "float", "(float, float, float, float, float)" },
1152 { "noisef", (void *)&SC_noisef,
1153 "float", "(float)" },
1154 { "noisef2", (void *)&SC_noisef2,
1155 "float", "(float, float)" },
1156 { "noisef3", (void *)&SC_noisef3,
1157 "float", "(float, float, float)" },
1158 { "turbulencef2", (void *)&SC_turbulencef2,
1159 "float", "(float, float, float)" },
1160 { "turbulencef3", (void *)&SC_turbulencef3,
1161 "float", "(float, float, float, float)" },
1162
1163 // time
1164 { "second", (void *)&SC_second,
1165 "int", "()" },
1166 { "minute", (void *)&SC_minute,
1167 "int", "()" },
1168 { "hour", (void *)&SC_hour,
1169 "int", "()" },
1170 { "day", (void *)&SC_day,
1171 "int", "()" },
1172 { "month", (void *)&SC_month,
1173 "int", "()" },
1174 { "year", (void *)&SC_year,
1175 "int", "()" },
1176 { "uptimeMillis", (void*)&SC_uptimeMillis,
1177 "int", "()" }, // TODO: use long instead
1178 { "startTimeMillis", (void*)&SC_startTimeMillis,
1179 "int", "()" }, // TODO: use long instead
1180 { "elapsedTimeMillis", (void*)&SC_elapsedTimeMillis,
1181 "int", "()" }, // TODO: use long instead
1182
1183 // matrix
1184 { "matrixLoadIdentity", (void *)&SC_matrixLoadIdentity,
1185 "void", "(float *mat)" },
1186 { "matrixLoadFloat", (void *)&SC_matrixLoadFloat,
1187 "void", "(float *mat, float *f)" },
1188 { "matrixLoadMat", (void *)&SC_matrixLoadMat,
1189 "void", "(float *mat, float *newmat)" },
1190 { "matrixLoadRotate", (void *)&SC_matrixLoadRotate,
1191 "void", "(float *mat, float rot, float x, float y, float z)" },
1192 { "matrixLoadScale", (void *)&SC_matrixLoadScale,
1193 "void", "(float *mat, float x, float y, float z)" },
1194 { "matrixLoadTranslate", (void *)&SC_matrixLoadTranslate,
1195 "void", "(float *mat, float x, float y, float z)" },
1196 { "matrixLoadMultiply", (void *)&SC_matrixLoadMultiply,
1197 "void", "(float *mat, float *lhs, float *rhs)" },
1198 { "matrixMultiply", (void *)&SC_matrixMultiply,
1199 "void", "(float *mat, float *rhs)" },
1200 { "matrixRotate", (void *)&SC_matrixRotate,
1201 "void", "(float *mat, float rot, float x, float y, float z)" },
1202 { "matrixScale", (void *)&SC_matrixScale,
1203 "void", "(float *mat, float x, float y, float z)" },
1204 { "matrixTranslate", (void *)&SC_matrixTranslate,
1205 "void", "(float *mat, float x, float y, float z)" },
1206
1207 // vector
1208 { "vec2Rand", (void *)&SC_vec2Rand,
1209 "void", "(float *vec, float maxLen)" },
1210
1211 // vec3
1212 { "vec3Norm", (void *)&SC_vec3Norm,
1213 "void", "(struct vec3_s *)" },
1214 { "vec3Length", (void *)&SC_vec3Length,
1215 "float", "(struct vec3_s *)" },
1216 { "vec3Add", (void *)&SC_vec3Add,
1217 "void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" },
1218 { "vec3Sub", (void *)&SC_vec3Sub,
1219 "void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" },
1220 { "vec3Cross", (void *)&SC_vec3Cross,
1221 "void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" },
1222 { "vec3Dot", (void *)&SC_vec3Dot,
1223 "float", "(struct vec3_s *lhs, struct vec3_s *rhs)" },
1224 { "vec3Scale", (void *)&SC_vec3Scale,
1225 "void", "(struct vec3_s *lhs, float scale)" },
1226
1227 // vec4
1228 { "vec4Norm", (void *)&SC_vec4Norm,
1229 "void", "(struct vec4_s *)" },
1230 { "vec4Length", (void *)&SC_vec4Length,
1231 "float", "(struct vec4_s *)" },
1232 { "vec4Add", (void *)&SC_vec4Add,
1233 "void", "(struct vec4_s *dest, struct vec4_s *lhs, struct vec4_s *rhs)" },
1234 { "vec4Sub", (void *)&SC_vec4Sub,
1235 "void", "(struct vec4_s *dest, struct vec4_s *lhs, struct vec4_s *rhs)" },
1236 { "vec4Dot", (void *)&SC_vec4Dot,
1237 "float", "(struct vec4_s *lhs, struct vec4_s *rhs)" },
1238 { "vec4Scale", (void *)&SC_vec4Scale,
1239 "void", "(struct vec4_s *lhs, float scale)" },
1240
1241 // context
1242 { "bindProgramFragment", (void *)&SC_bindProgramFragment,
1243 "void", "(int)" },
1244 { "bindProgramFragmentStore", (void *)&SC_bindProgramFragmentStore,
1245 "void", "(int)" },
1246 { "bindProgramStore", (void *)&SC_bindProgramFragmentStore,
1247 "void", "(int)" },
1248 { "bindProgramVertex", (void *)&SC_bindProgramVertex,
1249 "void", "(int)" },
1250 { "bindSampler", (void *)&SC_bindSampler,
1251 "void", "(int, int, int)" },
1252 { "bindTexture", (void *)&SC_bindTexture,
1253 "void", "(int, int, int)" },
1254
1255 // vp
1256 { "vpLoadModelMatrix", (void *)&SC_vpLoadModelMatrix,
1257 "void", "(void *)" },
1258 { "vpLoadTextureMatrix", (void *)&SC_vpLoadTextureMatrix,
1259 "void", "(void *)" },
1260
1261
1262
1263 // drawing
1264 { "drawRect", (void *)&SC_drawRect,
1265 "void", "(float x1, float y1, float x2, float y2, float z)" },
1266 { "drawQuad", (void *)&SC_drawQuad,
1267 "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)" },
1268 { "drawQuadTexCoords", (void *)&SC_drawQuadTexCoords,
1269 "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)" },
1270 { "drawSprite", (void *)&SC_drawSprite,
1271 "void", "(float x, float y, float z, float w, float h)" },
1272 { "drawSpriteScreenspace", (void *)&SC_drawSpriteScreenspace,
1273 "void", "(float x, float y, float z, float w, float h)" },
1274 { "drawLine", (void *)&SC_drawLine,
1275 "void", "(float x1, float y1, float z1, float x2, float y2, float z2)" },
1276 { "drawPoint", (void *)&SC_drawPoint,
1277 "void", "(float x1, float y1, float z1)" },
1278 { "drawSimpleMesh", (void *)&SC_drawSimpleMesh,
1279 "void", "(int ism)" },
1280 { "drawSimpleMeshRange", (void *)&SC_drawSimpleMeshRange,
1281 "void", "(int ism, int start, int len)" },
1282
1283
1284 // misc
1285 { "pfClearColor", (void *)&SC_ClearColor,
1286 "void", "(float, float, float, float)" },
1287 { "color", (void *)&SC_color,
1288 "void", "(float, float, float, float)" },
1289 { "hsb", (void *)&SC_hsb,
1290 "void", "(float, float, float, float)" },
1291 { "hsbToRgb", (void *)&SC_hsbToRgb,
1292 "void", "(float, float, float, float*)" },
1293 { "hsbToAbgr", (void *)&SC_hsbToAbgr,
1294 "int", "(float, float, float, float)" },
1295 { "ambient", (void *)&SC_ambient,
1296 "void", "(float, float, float, float)" },
1297 { "diffuse", (void *)&SC_diffuse,
1298 "void", "(float, float, float, float)" },
1299 { "specular", (void *)&SC_specular,
1300 "void", "(float, float, float, float)" },
1301 { "emission", (void *)&SC_emission,
1302 "void", "(float, float, float, float)" },
1303 { "shininess", (void *)&SC_shininess,
1304 "void", "(float)" },
1305 { "pointAttenuation", (void *)&SC_pointAttenuation,
1306 "void", "(float, float, float)" },
1307
1308 { "uploadToTexture", (void *)&SC_uploadToTexture,
1309 "void", "(int, int)" },
1310 { "uploadToBufferObject", (void *)&SC_uploadToBufferObject,
1311 "void", "(int)" },
1312
1313 { "colorFloatRGBAtoUNorm8", (void *)&SC_colorFloatRGBAtoUNorm8,
1314 "int", "(float, float, float, float)" },
1315 { "colorFloatRGBto565", (void *)&SC_colorFloatRGBAto565,
1316 "int", "(float, float, float)" },
1317
1318
1319 { "getWidth", (void *)&SC_getWidth,
1320 "int", "()" },
1321 { "getHeight", (void *)&SC_getHeight,
1322 "int", "()" },
1323
1324 { "sendToClient", (void *)&SC_toClient,
1325 "int", "(void *data, int cmdID, int len, int waitForSpace)" },
1326
1327
1328 { "debugF", (void *)&SC_debugF,
1329 "void", "(void *, float)" },
1330 { "debugI32", (void *)&SC_debugI32,
1331 "void", "(void *, int)" },
1332 { "debugHexF", (void *)&SC_debugHexF,
1333 "void", "(void *, float)" },
1334 { "debugHexI32", (void *)&SC_debugHexI32,
1335 "void", "(void *, int)" },
1336
1337 { "scriptCall", (void *)&SC_scriptCall,
1338 "void", "(int)" },
1339
1340
1341 { NULL, NULL, NULL, NULL }
1342 };
1343
lookupSymbol(const char * sym)1344 const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym)
1345 {
1346 ScriptCState::SymbolTable_t *syms = gSyms;
1347
1348 while (syms->mPtr) {
1349 if (!strcmp(syms->mName, sym)) {
1350 return syms;
1351 }
1352 syms++;
1353 }
1354 return NULL;
1355 }
1356
appendDecls(String8 * str)1357 void ScriptCState::appendDecls(String8 *str)
1358 {
1359 ScriptCState::SymbolTable_t *syms = gSyms;
1360 while (syms->mPtr) {
1361 str->append(syms->mRet);
1362 str->append(" ");
1363 str->append(syms->mName);
1364 str->append(syms->mParam);
1365 str->append(";\n");
1366 syms++;
1367 }
1368 }
1369
1370
1371