blob: 1ed0f31b45d9e3abc2a565b8bc9ff3587858e1c1 [file] [log] [blame]
Jason Sams536923d2010-05-18 13:35:45 -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"
Jason Sams536923d2010-05-18 13:35:45 -070020
Jason Sams536923d2010-05-18 13:35:45 -070021#include "utils/Timers.h"
22
23#define GL_GLEXT_PROTOTYPES
24
25#include <GLES/gl.h>
26#include <GLES/glext.h>
27#include <GLES2/gl2.h>
28#include <GLES2/gl2ext.h>
29
30#include <time.h>
31
32using namespace android;
33using namespace android::renderscript;
34
Jason Sams55d2a252011-03-17 16:12:47 -070035#define GET_TLS() ScriptTLSStruct * tls = \
36 (ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \
Jason Sams536923d2010-05-18 13:35:45 -070037 Context * rsc = tls->mContext; \
38 ScriptC * sc = (ScriptC *) tls->mScript
39
40
41//////////////////////////////////////////////////////////////////////////////
Jason Sams536923d2010-05-18 13:35:45 -070042// Context
43//////////////////////////////////////////////////////////////////////////////
44
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080045static void SC_bindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va) {
Jason Samsf166d9b2010-09-30 18:15:52 -070046 CHECK_OBJ_OR_NULL(va);
47 CHECK_OBJ(vpf);
Jason Sams536923d2010-05-18 13:35:45 -070048 GET_TLS();
49 rsi_ProgramBindTexture(rsc,
50 static_cast<ProgramFragment *>(vpf),
51 slot,
52 static_cast<Allocation *>(va));
Jason Sams536923d2010-05-18 13:35:45 -070053}
54
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080055static void SC_bindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs) {
Jason Samsf166d9b2010-09-30 18:15:52 -070056 CHECK_OBJ_OR_NULL(vs);
57 CHECK_OBJ(vpf);
Jason Sams536923d2010-05-18 13:35:45 -070058 GET_TLS();
59 rsi_ProgramBindSampler(rsc,
60 static_cast<ProgramFragment *>(vpf),
61 slot,
62 static_cast<Sampler *>(vs));
Jason Sams536923d2010-05-18 13:35:45 -070063}
64
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080065static void SC_bindProgramStore(RsProgramStore pfs) {
Jason Samsf166d9b2010-09-30 18:15:52 -070066 CHECK_OBJ_OR_NULL(pfs);
Jason Sams536923d2010-05-18 13:35:45 -070067 GET_TLS();
68 rsi_ContextBindProgramStore(rsc, pfs);
69}
70
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080071static void SC_bindProgramFragment(RsProgramFragment pf) {
Jason Samsf166d9b2010-09-30 18:15:52 -070072 CHECK_OBJ_OR_NULL(pf);
Jason Sams536923d2010-05-18 13:35:45 -070073 GET_TLS();
74 rsi_ContextBindProgramFragment(rsc, pf);
75}
76
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080077static void SC_bindProgramVertex(RsProgramVertex pv) {
Jason Samsf166d9b2010-09-30 18:15:52 -070078 CHECK_OBJ_OR_NULL(pv);
Jason Sams536923d2010-05-18 13:35:45 -070079 GET_TLS();
80 rsi_ContextBindProgramVertex(rsc, pv);
81}
82
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080083static void SC_bindProgramRaster(RsProgramRaster pv) {
Jason Samsf166d9b2010-09-30 18:15:52 -070084 CHECK_OBJ_OR_NULL(pv);
Jason Sams536923d2010-05-18 13:35:45 -070085 GET_TLS();
86 rsi_ContextBindProgramRaster(rsc, pv);
87}
88
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -070089static void SC_bindFrameBufferObjectColorTarget(RsAllocation va, uint32_t slot) {
90 CHECK_OBJ(va);
91 GET_TLS();
92 rsc->mFBOCache.bindColorTarget(rsc, static_cast<Allocation *>(va), slot);
93}
94
95static void SC_bindFrameBufferObjectDepthTarget(RsAllocation va) {
96 CHECK_OBJ(va);
97 GET_TLS();
98 rsc->mFBOCache.bindDepthTarget(rsc, static_cast<Allocation *>(va));
99}
100
101static void SC_clearFrameBufferObjectColorTarget(uint32_t slot) {
102 GET_TLS();
103 rsc->mFBOCache.bindColorTarget(rsc, NULL, slot);
104}
105
106static void SC_clearFrameBufferObjectDepthTarget() {
107 GET_TLS();
108 rsc->mFBOCache.bindDepthTarget(rsc, NULL);
109}
110
111static void SC_clearFrameBufferObjectTargets() {
112 GET_TLS();
113 rsc->mFBOCache.resetAll(rsc);
114}
115
Jason Sams536923d2010-05-18 13:35:45 -0700116//////////////////////////////////////////////////////////////////////////////
117// VP
118//////////////////////////////////////////////////////////////////////////////
119
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800120static void SC_vpLoadProjectionMatrix(const rsc_Matrix *m) {
Jim Millerd8e76202010-07-28 14:46:22 -0700121 GET_TLS();
Jason Samsa17af042010-11-17 15:29:32 -0800122 rsc->getProgramVertex()->setProjectionMatrix(rsc, m);
Jim Millerd8e76202010-07-28 14:46:22 -0700123}
124
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800125static void SC_vpLoadModelMatrix(const rsc_Matrix *m) {
Jason Sams536923d2010-05-18 13:35:45 -0700126 GET_TLS();
Jason Samsa17af042010-11-17 15:29:32 -0800127 rsc->getProgramVertex()->setModelviewMatrix(rsc, m);
Jason Sams536923d2010-05-18 13:35:45 -0700128}
129
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800130static void SC_vpLoadTextureMatrix(const rsc_Matrix *m) {
Jason Sams536923d2010-05-18 13:35:45 -0700131 GET_TLS();
Jason Samsa17af042010-11-17 15:29:32 -0800132 rsc->getProgramVertex()->setTextureMatrix(rsc, m);
Jason Sams536923d2010-05-18 13:35:45 -0700133}
134
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800135static void SC_pfConstantColor(RsProgramFragment vpf, float r, float g, float b, float a) {
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -0700136 GET_TLS();
Jason Samsf166d9b2010-09-30 18:15:52 -0700137 CHECK_OBJ(vpf);
Jason Sams442a6472010-08-04 17:50:20 -0700138 ProgramFragment *pf = static_cast<ProgramFragment *>(vpf);
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -0700139 pf->setConstantColor(rsc, r, g, b, a);
Jason Sams442a6472010-08-04 17:50:20 -0700140}
141
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800142static void SC_vpGetProjectionMatrix(rsc_Matrix *m) {
Alex Sakhartchoukcbed7522010-08-16 17:40:10 -0700143 GET_TLS();
Jason Samsa17af042010-11-17 15:29:32 -0800144 rsc->getProgramVertex()->getProjectionMatrix(rsc, m);
Alex Sakhartchoukcbed7522010-08-16 17:40:10 -0700145}
146
Jason Sams536923d2010-05-18 13:35:45 -0700147//////////////////////////////////////////////////////////////////////////////
148// Drawing
149//////////////////////////////////////////////////////////////////////////////
150
Jason Sams536923d2010-05-18 13:35:45 -0700151static void SC_drawQuadTexCoords(float x1, float y1, float z1,
152 float u1, float v1,
153 float x2, float y2, float z2,
154 float u2, float v2,
155 float x3, float y3, float z3,
156 float u3, float v3,
157 float x4, float y4, float z4,
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800158 float u4, float v4) {
Jason Sams536923d2010-05-18 13:35:45 -0700159 GET_TLS();
160 if (!rsc->setupCheck()) {
161 return;
162 }
163
164 //LOGE("Quad");
165 //LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1);
166 //LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2);
167 //LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3);
168 //LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4);
169
170 float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4};
171 const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4};
172
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -0800173 VertexArray::Attrib attribs[2];
174 attribs[0].set(GL_FLOAT, 3, 12, false, (uint32_t)vtx, "ATTRIB_position");
175 attribs[1].set(GL_FLOAT, 2, 8, false, (uint32_t)tex, "ATTRIB_texture0");
176
177 VertexArray va(attribs, 2);
Jason Sams8cb39de2010-06-01 15:47:01 -0700178 va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
Jason Sams536923d2010-05-18 13:35:45 -0700179
180 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
181}
182
183static void SC_drawQuad(float x1, float y1, float z1,
184 float x2, float y2, float z2,
185 float x3, float y3, float z3,
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800186 float x4, float y4, float z4) {
Jason Sams536923d2010-05-18 13:35:45 -0700187 SC_drawQuadTexCoords(x1, y1, z1, 0, 1,
188 x2, y2, z2, 1, 1,
189 x3, y3, z3, 1, 0,
190 x4, y4, z4, 0, 0);
191}
192
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800193static void SC_drawSpriteScreenspace(float x, float y, float z, float w, float h) {
Jason Sams536923d2010-05-18 13:35:45 -0700194 GET_TLS();
Jason Samsa17af042010-11-17 15:29:32 -0800195 ObjectBaseRef<const ProgramVertex> tmp(rsc->getProgramVertex());
196 rsc->setProgramVertex(rsc->getDefaultProgramVertex());
Jason Sams536923d2010-05-18 13:35:45 -0700197 //rsc->setupCheck();
198
199 //GLint crop[4] = {0, h, w, -h};
200
201 float sh = rsc->getHeight();
202
203 SC_drawQuad(x, sh - y, z,
204 x+w, sh - y, z,
205 x+w, sh - (y+h), z,
206 x, sh - (y+h), z);
Jason Samsa17af042010-11-17 15:29:32 -0800207 rsc->setProgramVertex((ProgramVertex *)tmp.get());
Jason Sams536923d2010-05-18 13:35:45 -0700208}
Jason Sams6d1cf412010-06-17 18:05:38 -0700209/*
Jason Sams536923d2010-05-18 13:35:45 -0700210static void SC_drawSprite(float x, float y, float z, float w, float h)
211{
212 GET_TLS();
213 float vin[3] = {x, y, z};
214 float vout[4];
215
216 //LOGE("ds in %f %f %f", x, y, z);
217 rsc->getVertex()->transformToScreen(rsc, vout, vin);
218 //LOGE("ds out %f %f %f %f", vout[0], vout[1], vout[2], vout[3]);
219 vout[0] /= vout[3];
220 vout[1] /= vout[3];
221 vout[2] /= vout[3];
222
223 vout[0] *= rsc->getWidth() / 2;
224 vout[1] *= rsc->getHeight() / 2;
225 vout[0] += rsc->getWidth() / 2;
226 vout[1] += rsc->getHeight() / 2;
227
228 vout[0] -= w/2;
229 vout[1] -= h/2;
230
231 //LOGE("ds out2 %f %f %f", vout[0], vout[1], vout[2]);
232
233 // U, V, W, H
234 SC_drawSpriteScreenspace(vout[0], vout[1], z, h, w);
235 //rsc->setupCheck();
236}
Jason Sams6d1cf412010-06-17 18:05:38 -0700237*/
Jason Sams536923d2010-05-18 13:35:45 -0700238
239static void SC_drawRect(float x1, float y1,
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800240 float x2, float y2, float z) {
Jason Sams536923d2010-05-18 13:35:45 -0700241 //LOGE("SC_drawRect %f,%f %f,%f %f", x1, y1, x2, y2, z);
242 SC_drawQuad(x1, y2, z,
243 x2, y2, z,
244 x2, y1, z,
245 x1, y1, z);
246}
247
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800248static void SC_drawMesh(RsMesh vsm) {
Jason Samsf166d9b2010-09-30 18:15:52 -0700249 CHECK_OBJ(vsm);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700250 GET_TLS();
251 Mesh *sm = static_cast<Mesh *>(vsm);
Jason Sams536923d2010-05-18 13:35:45 -0700252 if (!rsc->setupCheck()) {
253 return;
254 }
255 sm->render(rsc);
256}
257
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800258static void SC_drawMeshPrimitive(RsMesh vsm, uint32_t primIndex) {
Jason Samsf166d9b2010-09-30 18:15:52 -0700259 CHECK_OBJ(vsm);
Jason Sams536923d2010-05-18 13:35:45 -0700260 GET_TLS();
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700261 Mesh *sm = static_cast<Mesh *>(vsm);
Jason Sams536923d2010-05-18 13:35:45 -0700262 if (!rsc->setupCheck()) {
263 return;
264 }
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700265 sm->renderPrimitive(rsc, primIndex);
266}
267
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800268static void SC_drawMeshPrimitiveRange(RsMesh vsm, uint32_t primIndex, uint32_t start, uint32_t len) {
Jason Samsf166d9b2010-09-30 18:15:52 -0700269 CHECK_OBJ(vsm);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700270 GET_TLS();
271 Mesh *sm = static_cast<Mesh *>(vsm);
272 if (!rsc->setupCheck()) {
273 return;
274 }
275 sm->renderPrimitiveRange(rsc, primIndex, start, len);
Jason Sams536923d2010-05-18 13:35:45 -0700276}
277
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800278static void SC_meshComputeBoundingBox(RsMesh vsm,
279 float *minX, float *minY, float *minZ,
280 float *maxX, float *maxY, float *maxZ) {
Jason Samsf166d9b2010-09-30 18:15:52 -0700281 CHECK_OBJ(vsm);
Alex Sakhartchouka80145d2010-08-13 14:32:23 -0700282 GET_TLS();
283 Mesh *sm = static_cast<Mesh *>(vsm);
284 sm->computeBBox();
285 *minX = sm->mBBoxMin[0];
286 *minY = sm->mBBoxMin[1];
287 *minZ = sm->mBBoxMin[2];
288 *maxX = sm->mBBoxMax[0];
289 *maxY = sm->mBBoxMax[1];
290 *maxZ = sm->mBBoxMax[2];
291}
292
Jason Sams536923d2010-05-18 13:35:45 -0700293
294//////////////////////////////////////////////////////////////////////////////
295//
296//////////////////////////////////////////////////////////////////////////////
297
298
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800299static void SC_color(float r, float g, float b, float a) {
Jason Sams536923d2010-05-18 13:35:45 -0700300 GET_TLS();
Jason Samsa17af042010-11-17 15:29:32 -0800301 ProgramFragment *pf = (ProgramFragment *)rsc->getProgramFragment();
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -0700302 pf->setConstantColor(rsc, r, g, b, a);
Jason Sams536923d2010-05-18 13:35:45 -0700303}
304
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -0700305static void SC_finish() {
306 glFinish();
307}
308
Jason Sams6d8eb262010-12-15 01:41:00 -0800309static void SC_allocationSyncAll(RsAllocation va) {
310 CHECK_OBJ(va);
311 GET_TLS();
312 static_cast<Allocation *>(va)->syncAll(rsc, RS_ALLOCATION_USAGE_SCRIPT);
313}
314
Stephen Hines60f9a622011-03-01 17:34:59 -0800315#if 0
Jason Sams6d8eb262010-12-15 01:41:00 -0800316static void SC_allocationSyncAll2(RsAllocation va, RsAllocationUsageType source) {
317 CHECK_OBJ(va);
318 GET_TLS();
319 static_cast<Allocation *>(va)->syncAll(rsc, source);
320}
Stephen Hines60f9a622011-03-01 17:34:59 -0800321#endif
Jason Sams6d8eb262010-12-15 01:41:00 -0800322
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800323static void SC_ClearColor(float r, float g, float b, float a) {
Jason Sams536923d2010-05-18 13:35:45 -0700324 GET_TLS();
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -0700325 rsc->mFBOCache.setupGL2(rsc);
Alex Sakhartchoukfeede2a2010-10-01 10:54:06 -0700326 rsc->setupProgramStore();
Jason Samsd79b2e92010-05-19 17:22:57 -0700327
328 glClearColor(r, g, b, a);
329 glClear(GL_COLOR_BUFFER_BIT);
330}
331
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800332static void SC_ClearDepth(float v) {
Jason Samsd79b2e92010-05-19 17:22:57 -0700333 GET_TLS();
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -0700334 rsc->mFBOCache.setupGL2(rsc);
Alex Sakhartchoukfeede2a2010-10-01 10:54:06 -0700335 rsc->setupProgramStore();
Jason Samsd79b2e92010-05-19 17:22:57 -0700336
337 glClearDepthf(v);
338 glClear(GL_DEPTH_BUFFER_BIT);
Jason Sams536923d2010-05-18 13:35:45 -0700339}
340
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800341static uint32_t SC_getWidth() {
Jason Sams536923d2010-05-18 13:35:45 -0700342 GET_TLS();
343 return rsc->getWidth();
344}
345
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800346static uint32_t SC_getHeight() {
Jason Sams536923d2010-05-18 13:35:45 -0700347 GET_TLS();
348 return rsc->getHeight();
349}
350
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800351static void SC_DrawTextAlloc(RsAllocation va, int x, int y) {
Jason Samsf166d9b2010-09-30 18:15:52 -0700352 CHECK_OBJ(va);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700353 GET_TLS();
354 Allocation *alloc = static_cast<Allocation *>(va);
Alex Sakhartchouk10825a02010-10-05 11:33:27 -0700355 const char *text = (const char *)alloc->getPtr();
356 size_t allocSize = alloc->getType()->getSizeBytes();
357 rsc->mStateFont.renderText(text, allocSize, x, y);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700358}
359
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800360static void SC_DrawText(const char *text, int x, int y) {
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700361 GET_TLS();
Alex Sakhartchouk10825a02010-10-05 11:33:27 -0700362 size_t textLen = strlen(text);
363 rsc->mStateFont.renderText(text, textLen, x, y);
364}
365
366static void SC_setMetrics(Font::Rect *metrics,
367 int32_t *left, int32_t *right,
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800368 int32_t *top, int32_t *bottom) {
369 if (left) {
Alex Sakhartchouk10825a02010-10-05 11:33:27 -0700370 *left = metrics->left;
371 }
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800372 if (right) {
Alex Sakhartchouk10825a02010-10-05 11:33:27 -0700373 *right = metrics->right;
374 }
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800375 if (top) {
Alex Sakhartchouk10825a02010-10-05 11:33:27 -0700376 *top = metrics->top;
377 }
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800378 if (bottom) {
Alex Sakhartchouk10825a02010-10-05 11:33:27 -0700379 *bottom = metrics->bottom;
380 }
381}
382
383static void SC_MeasureTextAlloc(RsAllocation va,
384 int32_t *left, int32_t *right,
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800385 int32_t *top, int32_t *bottom) {
Alex Sakhartchouk10825a02010-10-05 11:33:27 -0700386 CHECK_OBJ(va);
387 GET_TLS();
388 Allocation *alloc = static_cast<Allocation *>(va);
389 const char *text = (const char *)alloc->getPtr();
390 size_t textLen = alloc->getType()->getSizeBytes();
391 Font::Rect metrics;
392 rsc->mStateFont.measureText(text, textLen, &metrics);
393 SC_setMetrics(&metrics, left, right, top, bottom);
394}
395
396static void SC_MeasureText(const char *text,
397 int32_t *left, int32_t *right,
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800398 int32_t *top, int32_t *bottom) {
Alex Sakhartchouk10825a02010-10-05 11:33:27 -0700399 GET_TLS();
400 size_t textLen = strlen(text);
401 Font::Rect metrics;
402 rsc->mStateFont.measureText(text, textLen, &metrics);
403 SC_setMetrics(&metrics, left, right, top, bottom);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700404}
405
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800406static void SC_BindFont(RsFont font) {
Jason Samsf166d9b2010-09-30 18:15:52 -0700407 CHECK_OBJ(font);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700408 GET_TLS();
409 rsi_ContextBindFont(rsc, font);
410}
Jason Sams536923d2010-05-18 13:35:45 -0700411
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800412static void SC_FontColor(float r, float g, float b, float a) {
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700413 GET_TLS();
414 rsc->mStateFont.setFontColor(r, g, b, a);
415}
416
Jason Sams536923d2010-05-18 13:35:45 -0700417//////////////////////////////////////////////////////////////////////////////
418// Class implementation
419//////////////////////////////////////////////////////////////////////////////
420
421// llvm name mangling ref
422// <builtin-type> ::= v # void
423// ::= b # bool
424// ::= c # char
425// ::= a # signed char
426// ::= h # unsigned char
427// ::= s # short
428// ::= t # unsigned short
429// ::= i # int
430// ::= j # unsigned int
431// ::= l # long
432// ::= m # unsigned long
433// ::= x # long long, __int64
434// ::= y # unsigned long long, __int64
435// ::= f # float
436// ::= d # double
437
438static ScriptCState::SymbolTable_t gSyms[] = {
Jason Sams8f0adba2010-11-01 14:26:30 -0700439 { "_Z22rsgBindProgramFragment19rs_program_fragment", (void *)&SC_bindProgramFragment, false },
440 { "_Z19rsgBindProgramStore16rs_program_store", (void *)&SC_bindProgramStore, false },
441 { "_Z20rsgBindProgramVertex17rs_program_vertex", (void *)&SC_bindProgramVertex, false },
442 { "_Z20rsgBindProgramRaster17rs_program_raster", (void *)&SC_bindProgramRaster, false },
443 { "_Z14rsgBindSampler19rs_program_fragmentj10rs_sampler", (void *)&SC_bindSampler, false },
444 { "_Z14rsgBindTexture19rs_program_fragmentj13rs_allocation", (void *)&SC_bindTexture, false },
Jason Samsd79b2e92010-05-19 17:22:57 -0700445
Jason Sams8f0adba2010-11-01 14:26:30 -0700446 { "_Z36rsgProgramVertexLoadProjectionMatrixPK12rs_matrix4x4", (void *)&SC_vpLoadProjectionMatrix, false },
447 { "_Z31rsgProgramVertexLoadModelMatrixPK12rs_matrix4x4", (void *)&SC_vpLoadModelMatrix, false },
448 { "_Z33rsgProgramVertexLoadTextureMatrixPK12rs_matrix4x4", (void *)&SC_vpLoadTextureMatrix, false },
Jason Samsd79b2e92010-05-19 17:22:57 -0700449
Jason Sams8f0adba2010-11-01 14:26:30 -0700450 { "_Z35rsgProgramVertexGetProjectionMatrixP12rs_matrix4x4", (void *)&SC_vpGetProjectionMatrix, false },
Alex Sakhartchoukcbed7522010-08-16 17:40:10 -0700451
Jason Sams8f0adba2010-11-01 14:26:30 -0700452 { "_Z31rsgProgramFragmentConstantColor19rs_program_fragmentffff", (void *)&SC_pfConstantColor, false },
Jason Sams442a6472010-08-04 17:50:20 -0700453
Jason Sams8f0adba2010-11-01 14:26:30 -0700454 { "_Z11rsgGetWidthv", (void *)&SC_getWidth, false },
455 { "_Z12rsgGetHeightv", (void *)&SC_getHeight, false },
Jason Samsd79b2e92010-05-19 17:22:57 -0700456
Jason Sams6d8eb262010-12-15 01:41:00 -0800457 { "_Z20rsgAllocationSyncAll13rs_allocation", (void *)&SC_allocationSyncAll, false },
458
Jason Sams8f0adba2010-11-01 14:26:30 -0700459 { "_Z11rsgDrawRectfffff", (void *)&SC_drawRect, false },
460 { "_Z11rsgDrawQuadffffffffffff", (void *)&SC_drawQuad, false },
461 { "_Z20rsgDrawQuadTexCoordsffffffffffffffffffff", (void *)&SC_drawQuadTexCoords, false },
462 { "_Z24rsgDrawSpriteScreenspacefffff", (void *)&SC_drawSpriteScreenspace, false },
Jason Samsd79b2e92010-05-19 17:22:57 -0700463
Jason Sams8f0adba2010-11-01 14:26:30 -0700464 { "_Z11rsgDrawMesh7rs_mesh", (void *)&SC_drawMesh, false },
465 { "_Z11rsgDrawMesh7rs_meshj", (void *)&SC_drawMeshPrimitive, false },
466 { "_Z11rsgDrawMesh7rs_meshjjj", (void *)&SC_drawMeshPrimitiveRange, false },
467 { "_Z25rsgMeshComputeBoundingBox7rs_meshPfS0_S0_S0_S0_S0_", (void *)&SC_meshComputeBoundingBox, false },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700468
Jason Sams8f0adba2010-11-01 14:26:30 -0700469 { "_Z13rsgClearColorffff", (void *)&SC_ClearColor, false },
470 { "_Z13rsgClearDepthf", (void *)&SC_ClearDepth, false },
Jason Samsd79b2e92010-05-19 17:22:57 -0700471
Jason Sams8f0adba2010-11-01 14:26:30 -0700472 { "_Z11rsgDrawTextPKcii", (void *)&SC_DrawText, false },
473 { "_Z11rsgDrawText13rs_allocationii", (void *)&SC_DrawTextAlloc, false },
474 { "_Z14rsgMeasureTextPKcPiS1_S1_S1_", (void *)&SC_MeasureText, false },
475 { "_Z14rsgMeasureText13rs_allocationPiS0_S0_S0_", (void *)&SC_MeasureTextAlloc, false },
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700476
Jason Sams8f0adba2010-11-01 14:26:30 -0700477 { "_Z11rsgBindFont7rs_font", (void *)&SC_BindFont, false },
478 { "_Z12rsgFontColorffff", (void *)&SC_FontColor, false },
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700479
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -0700480 { "_Z18rsgBindColorTarget13rs_allocationj", (void *)&SC_bindFrameBufferObjectColorTarget, false },
481 { "_Z18rsgBindDepthTarget13rs_allocation", (void *)&SC_bindFrameBufferObjectDepthTarget, false },
482 { "_Z19rsgClearColorTargetj", (void *)&SC_clearFrameBufferObjectColorTarget, false },
483 { "_Z19rsgClearDepthTargetv", (void *)&SC_clearFrameBufferObjectDepthTarget, false },
484 { "_Z24rsgClearAllRenderTargetsv", (void *)&SC_clearFrameBufferObjectTargets, false },
485
Jason Sams536923d2010-05-18 13:35:45 -0700486 // misc
Jason Sams8f0adba2010-11-01 14:26:30 -0700487 { "_Z5colorffff", (void *)&SC_color, false },
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -0700488 { "_Z9rsgFinishv", (void *)&SC_finish, false },
Jason Sams536923d2010-05-18 13:35:45 -0700489
Jason Sams8f0adba2010-11-01 14:26:30 -0700490 { NULL, NULL, false }
Jason Sams536923d2010-05-18 13:35:45 -0700491};
492
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800493const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbolGL(const char *sym) {
Jason Sams536923d2010-05-18 13:35:45 -0700494 ScriptCState::SymbolTable_t *syms = gSyms;
495
496 while (syms->mPtr) {
497 if (!strcmp(syms->mName, sym)) {
498 return syms;
499 }
500 syms++;
501 }
502 return NULL;
503}
504