Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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 | |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 21 | #include "acc/acc.h" |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 22 | #include "utils/String8.h" |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 23 | |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 24 | #include <GLES/gl.h> |
| 25 | #include <GLES/glext.h> |
| 26 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 27 | using namespace android; |
| 28 | using namespace android::renderscript; |
| 29 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 30 | #define GET_TLS() Context::ScriptTLSStruct * tls = \ |
| 31 | (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \ |
| 32 | Context * rsc = tls->mContext; \ |
| 33 | ScriptC * sc = (ScriptC *) tls->mScript |
| 34 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 35 | |
| 36 | ScriptC::ScriptC() |
| 37 | { |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 38 | mAccScript = NULL; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 39 | memset(&mProgram, 0, sizeof(mProgram)); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | ScriptC::~ScriptC() |
| 43 | { |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 44 | if (mAccScript) { |
| 45 | accDeleteScript(mAccScript); |
| 46 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Jason Sams | af49c74 | 2009-06-19 18:33:44 -0700 | [diff] [blame] | 49 | extern "C" float fixedToFloat(int32_t f) |
| 50 | { |
| 51 | return ((float)f) / 0x10000; |
| 52 | } |
| 53 | |
| 54 | extern "C" float intToFloat(int32_t f) |
| 55 | { |
| 56 | return (float)f; |
| 57 | } |
| 58 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 59 | extern "C" void matrixLoadIdentity(rsc_Matrix *mat) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 60 | { |
| 61 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 62 | m->loadIdentity(); |
| 63 | } |
| 64 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 65 | extern "C" void matrixLoadFloat(rsc_Matrix *mat, const float *f) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 66 | { |
| 67 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 68 | m->load(f); |
| 69 | } |
| 70 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 71 | extern "C" void matrixLoadMat(rsc_Matrix *mat, const rsc_Matrix *newmat) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 72 | { |
| 73 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 74 | m->load(reinterpret_cast<const Matrix *>(newmat)); |
| 75 | } |
| 76 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 77 | extern "C" void matrixLoadRotate(rsc_Matrix *mat, float rot, float x, float y, float z) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 78 | { |
| 79 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 80 | m->loadRotate(rot, x, y, z); |
| 81 | } |
| 82 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 83 | extern "C" void matrixLoadScale(rsc_Matrix *mat, float x, float y, float z) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 84 | { |
| 85 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 86 | m->loadScale(x, y, z); |
| 87 | } |
| 88 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 89 | extern "C" void matrixLoadTranslate(rsc_Matrix *mat, float x, float y, float z) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 90 | { |
| 91 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 92 | m->loadTranslate(x, y, z); |
| 93 | } |
| 94 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 95 | extern "C" void matrixLoadMultiply(rsc_Matrix *mat, const rsc_Matrix *lhs, const rsc_Matrix *rhs) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 96 | { |
| 97 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 98 | m->loadMultiply(reinterpret_cast<const Matrix *>(lhs), |
| 99 | reinterpret_cast<const Matrix *>(rhs)); |
| 100 | } |
| 101 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 102 | extern "C" void matrixMultiply(rsc_Matrix *mat, const rsc_Matrix *rhs) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 103 | { |
| 104 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 105 | m->multiply(reinterpret_cast<const Matrix *>(rhs)); |
| 106 | } |
| 107 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 108 | extern "C" void matrixRotate(rsc_Matrix *mat, float rot, float x, float y, float z) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 109 | { |
| 110 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 111 | m->rotate(rot, x, y, z); |
| 112 | } |
| 113 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 114 | extern "C" void matrixScale(rsc_Matrix *mat, float x, float y, float z) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 115 | { |
| 116 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 117 | m->scale(x, y, z); |
| 118 | } |
| 119 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 120 | extern "C" void matrixTranslate(rsc_Matrix *mat, float x, float y, float z) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 121 | { |
| 122 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 123 | m->translate(x, y, z); |
| 124 | } |
| 125 | |
| 126 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 127 | extern "C" const void * loadVp(uint32_t bank, uint32_t offset) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 128 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 129 | GET_TLS(); |
| 130 | return &static_cast<const uint8_t *>(sc->mSlots[bank]->getPtr())[offset]; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 133 | extern "C" float loadF(uint32_t bank, uint32_t offset) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 134 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 135 | GET_TLS(); |
| 136 | return static_cast<const float *>(sc->mSlots[bank]->getPtr())[offset]; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 139 | extern "C" int32_t loadI32(uint32_t bank, uint32_t offset) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 140 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 141 | GET_TLS(); |
| 142 | return static_cast<const int32_t *>(sc->mSlots[bank]->getPtr())[offset]; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 145 | extern "C" uint32_t loadU32(uint32_t bank, uint32_t offset) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 146 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 147 | GET_TLS(); |
| 148 | return static_cast<const uint32_t *>(sc->mSlots[bank]->getPtr())[offset]; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 151 | extern "C" void loadEnvVec4(uint32_t bank, uint32_t offset, rsc_Vector4 *v) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 152 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 153 | GET_TLS(); |
| 154 | memcpy(v, &static_cast<const float *>(sc->mSlots[bank]->getPtr())[offset], sizeof(rsc_Vector4)); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 157 | extern "C" void loadEnvMatrix(uint32_t bank, uint32_t offset, rsc_Matrix *m) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 158 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 159 | GET_TLS(); |
| 160 | memcpy(m, &static_cast<const float *>(sc->mSlots[bank]->getPtr())[offset], sizeof(rsc_Matrix)); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 164 | extern "C" void storeF(uint32_t bank, uint32_t offset, float v) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 165 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 166 | GET_TLS(); |
| 167 | static_cast<float *>(sc->mSlots[bank]->getPtr())[offset] = v; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 170 | extern "C" void storeI32(uint32_t bank, uint32_t offset, int32_t v) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 171 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 172 | GET_TLS(); |
| 173 | static_cast<int32_t *>(sc->mSlots[bank]->getPtr())[offset] = v; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 176 | extern "C" void storeU32(uint32_t bank, uint32_t offset, uint32_t v) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 177 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 178 | GET_TLS(); |
| 179 | static_cast<uint32_t *>(sc->mSlots[bank]->getPtr())[offset] = v; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 182 | extern "C" void storeEnvVec4(uint32_t bank, uint32_t offset, const rsc_Vector4 *v) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 183 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 184 | GET_TLS(); |
| 185 | memcpy(&static_cast<float *>(sc->mSlots[bank]->getPtr())[offset], v, sizeof(rsc_Vector4)); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 188 | extern "C" void storeEnvMatrix(uint32_t bank, uint32_t offset, const rsc_Matrix *m) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 189 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 190 | GET_TLS(); |
| 191 | memcpy(&static_cast<float *>(sc->mSlots[bank]->getPtr())[offset], m, sizeof(rsc_Matrix)); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 195 | extern "C" void color(float r, float g, float b, float a) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 196 | { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 197 | glColor4f(r, g, b, a); |
| 198 | } |
| 199 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 200 | extern "C" void renderTriangleMesh(RsTriangleMesh mesh) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 201 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 202 | GET_TLS(); |
| 203 | rsi_TriangleMeshRender(rsc, mesh); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 206 | extern "C" void renderTriangleMeshRange(RsTriangleMesh mesh, uint32_t start, uint32_t count) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 207 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 208 | GET_TLS(); |
| 209 | rsi_TriangleMeshRenderRange(rsc, mesh, start, count); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 212 | extern "C" void materialDiffuse(float r, float g, float b, float a) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 213 | { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 214 | float v[] = {r, g, b, a}; |
| 215 | glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, v); |
| 216 | } |
| 217 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 218 | extern "C" void materialSpecular(float r, float g, float b, float a) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 219 | { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 220 | float v[] = {r, g, b, a}; |
| 221 | glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, v); |
| 222 | } |
| 223 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 224 | extern "C" void lightPosition(float x, float y, float z, float w) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 225 | { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 226 | float v[] = {x, y, z, w}; |
| 227 | glLightfv(GL_LIGHT0, GL_POSITION, v); |
| 228 | } |
| 229 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 230 | extern "C" void materialShininess(float s) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 231 | { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 232 | glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &s); |
| 233 | } |
| 234 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 235 | extern "C" void uploadToTexture(RsAllocation va, uint32_t baseMipLevel) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 236 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 237 | GET_TLS(); |
| 238 | rsi_AllocationUploadToTexture(rsc, va, baseMipLevel); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 241 | extern "C" void enable(uint32_t p) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 242 | { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 243 | glEnable(p); |
| 244 | } |
| 245 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 246 | extern "C" void disable(uint32_t p) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 247 | { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 248 | glDisable(p); |
| 249 | } |
| 250 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 251 | extern "C" uint32_t scriptRand(uint32_t max) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 252 | { |
| 253 | return (uint32_t)(((float)rand()) * max / RAND_MAX); |
| 254 | } |
| 255 | |
| 256 | // Assumes (GL_FIXED) x,y,z (GL_UNSIGNED_BYTE)r,g,b,a |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 257 | extern "C" void drawTriangleArray(RsAllocation alloc, uint32_t count) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 258 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 259 | GET_TLS(); |
| 260 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 261 | const Allocation *a = (const Allocation *)alloc; |
| 262 | const uint32_t *ptr = (const uint32_t *)a->getPtr(); |
| 263 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 264 | rsc->setupCheck(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 265 | |
| 266 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 267 | //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); |
| 268 | |
| 269 | glEnableClientState(GL_VERTEX_ARRAY); |
| 270 | glDisableClientState(GL_NORMAL_ARRAY); |
| 271 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
| 272 | glEnableClientState(GL_COLOR_ARRAY); |
| 273 | |
| 274 | glVertexPointer(2, GL_FIXED, 12, ptr + 1); |
| 275 | //glTexCoordPointer(2, GL_FIXED, 24, ptr + 1); |
| 276 | glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr); |
| 277 | |
| 278 | glDrawArrays(GL_TRIANGLES, 0, count * 3); |
| 279 | } |
| 280 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 281 | extern "C" void drawRect(int32_t x1, int32_t x2, int32_t y1, int32_t y2) |
Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 282 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 283 | GET_TLS(); |
Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 284 | x1 = (x1 << 16); |
| 285 | x2 = (x2 << 16); |
| 286 | y1 = (y1 << 16); |
| 287 | y2 = (y2 << 16); |
| 288 | |
| 289 | int32_t vtx[] = {x1,y1, x1,y2, x2,y1, x2,y2}; |
| 290 | static const int32_t tex[] = {0,0, 0,0x10000, 0x10000,0, 0x10000,0x10000}; |
| 291 | |
| 292 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 293 | rsc->setupCheck(); |
Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 294 | |
| 295 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 296 | //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); |
| 297 | |
| 298 | glEnableClientState(GL_VERTEX_ARRAY); |
| 299 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 300 | glDisableClientState(GL_NORMAL_ARRAY); |
| 301 | glDisableClientState(GL_COLOR_ARRAY); |
| 302 | |
| 303 | glVertexPointer(2, GL_FIXED, 8, vtx); |
| 304 | glTexCoordPointer(2, GL_FIXED, 8, tex); |
| 305 | //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr); |
| 306 | |
| 307 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
| 308 | } |
| 309 | |
Jason Sams | fdcc14e | 2009-07-01 16:41:34 -0700 | [diff] [blame] | 310 | extern "C" void drawQuad(int32_t x1, int32_t y1, int32_t z1, |
| 311 | int32_t x2, int32_t y2, int32_t z2, |
| 312 | int32_t x3, int32_t y3, int32_t z3, |
| 313 | int32_t x4, int32_t y4, int32_t z4) |
| 314 | { |
| 315 | GET_TLS(); |
| 316 | //x1 = (x1 << 16); |
| 317 | //x2 = (x2 << 16); |
| 318 | //y1 = (y1 << 16); |
| 319 | //y2 = (y2 << 16); |
| 320 | |
| 321 | //LOGE("Quad"); |
| 322 | //LOGE("0x%08x, 0x%08x, 0x%08x", x1, y1, z1); |
| 323 | //LOGE("0x%08x, 0x%08x, 0x%08x", x2, y2, z2); |
| 324 | //LOGE("0x%08x, 0x%08x, 0x%08x", x3, y3, z3); |
| 325 | //LOGE("0x%08x, 0x%08x, 0x%08x", x4, y4, z4); |
| 326 | |
Jason Sams | aabd009 | 2009-07-01 20:17:07 -0700 | [diff] [blame] | 327 | int32_t vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4}; |
| 328 | static const int32_t tex[] = {0,0, 0,0x10000, 0x10000,0x10000, 0x10000,0}; |
Jason Sams | fdcc14e | 2009-07-01 16:41:34 -0700 | [diff] [blame] | 329 | |
| 330 | |
| 331 | rsc->setupCheck(); |
| 332 | |
| 333 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 334 | //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); |
| 335 | |
| 336 | glEnableClientState(GL_VERTEX_ARRAY); |
Jason Sams | 4244afa | 2009-07-02 15:09:27 -0700 | [diff] [blame] | 337 | glVertexPointer(3, GL_FIXED, 0, vtx); |
| 338 | |
| 339 | glClientActiveTexture(GL_TEXTURE0); |
Jason Sams | fdcc14e | 2009-07-01 16:41:34 -0700 | [diff] [blame] | 340 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
Jason Sams | 4244afa | 2009-07-02 15:09:27 -0700 | [diff] [blame] | 341 | glTexCoordPointer(2, GL_FIXED, 0, tex); |
| 342 | glClientActiveTexture(GL_TEXTURE1); |
| 343 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 344 | glTexCoordPointer(2, GL_FIXED, 0, tex); |
| 345 | glClientActiveTexture(GL_TEXTURE0); |
| 346 | |
Jason Sams | fdcc14e | 2009-07-01 16:41:34 -0700 | [diff] [blame] | 347 | glDisableClientState(GL_NORMAL_ARRAY); |
| 348 | glDisableClientState(GL_COLOR_ARRAY); |
| 349 | |
Jason Sams | fdcc14e | 2009-07-01 16:41:34 -0700 | [diff] [blame] | 350 | //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr); |
| 351 | |
| 352 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 353 | } |
| 354 | |
| 355 | extern "C" int32_t sinx(int32_t angle) |
| 356 | { |
| 357 | float a = ((float)angle) / 0x10000; |
| 358 | a *= 3.14f / 180.f; |
| 359 | float s = (float)sin(a); |
| 360 | return int32_t(s * 0x10000); |
| 361 | } |
| 362 | |
| 363 | extern "C" int32_t cosx(int32_t angle) |
| 364 | { |
| 365 | float a = ((float)angle) / 0x10000; |
| 366 | a *= 3.14f / 180.f; |
| 367 | float s = (float)cos(a); |
| 368 | return int32_t(s * 0x10000); |
| 369 | } |
| 370 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 371 | extern "C" void pfBindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 372 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 373 | GET_TLS(); |
| 374 | rsi_ProgramFragmentBindTexture(rsc, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 375 | static_cast<ProgramFragment *>(vpf), |
| 376 | slot, |
| 377 | static_cast<Allocation *>(va)); |
| 378 | |
| 379 | } |
| 380 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 381 | extern "C" void pfBindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 382 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 383 | GET_TLS(); |
| 384 | rsi_ProgramFragmentBindSampler(rsc, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 385 | static_cast<ProgramFragment *>(vpf), |
| 386 | slot, |
| 387 | static_cast<Sampler *>(vs)); |
| 388 | |
| 389 | } |
| 390 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 391 | extern "C" void contextBindProgramFragmentStore(RsProgramFragmentStore pfs) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 392 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 393 | GET_TLS(); |
| 394 | rsi_ContextBindProgramFragmentStore(rsc, pfs); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 395 | |
| 396 | } |
| 397 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 398 | extern "C" void contextBindProgramFragment(RsProgramFragment pf) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 399 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 400 | GET_TLS(); |
| 401 | rsi_ContextBindProgramFragment(rsc, pf); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 402 | |
| 403 | } |
| 404 | |
| 405 | |
| 406 | static rsc_FunctionTable scriptCPtrTable = { |
| 407 | loadVp, |
| 408 | loadF, |
| 409 | loadI32, |
| 410 | loadU32, |
| 411 | loadEnvVec4, |
| 412 | loadEnvMatrix, |
| 413 | |
| 414 | storeF, |
| 415 | storeI32, |
| 416 | storeU32, |
| 417 | storeEnvVec4, |
| 418 | storeEnvMatrix, |
| 419 | |
| 420 | matrixLoadIdentity, |
| 421 | matrixLoadFloat, |
| 422 | matrixLoadMat, |
| 423 | matrixLoadRotate, |
| 424 | matrixLoadScale, |
| 425 | matrixLoadTranslate, |
| 426 | matrixLoadMultiply, |
| 427 | matrixMultiply, |
| 428 | matrixRotate, |
| 429 | matrixScale, |
| 430 | matrixTranslate, |
| 431 | |
| 432 | color, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 433 | |
| 434 | pfBindTexture, |
| 435 | pfBindSampler, |
| 436 | |
| 437 | materialDiffuse, |
| 438 | materialSpecular, |
| 439 | lightPosition, |
| 440 | materialShininess, |
| 441 | uploadToTexture, |
| 442 | enable, |
| 443 | disable, |
| 444 | |
| 445 | scriptRand, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 446 | contextBindProgramFragment, |
Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 447 | contextBindProgramFragmentStore, |
| 448 | |
| 449 | |
| 450 | renderTriangleMesh, |
| 451 | renderTriangleMeshRange, |
| 452 | |
| 453 | drawTriangleArray, |
| 454 | drawRect |
| 455 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 456 | }; |
| 457 | |
| 458 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 459 | bool ScriptC::run(Context *rsc, uint32_t launchIndex) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 460 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 461 | Context::ScriptTLSStruct * tls = |
| 462 | (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 463 | |
| 464 | if (mEnviroment.mFragmentStore.get()) { |
| 465 | rsc->setFragmentStore(mEnviroment.mFragmentStore.get()); |
| 466 | } |
| 467 | if (mEnviroment.mFragment.get()) { |
| 468 | rsc->setFragment(mEnviroment.mFragment.get()); |
| 469 | } |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 470 | if (mEnviroment.mVertex.get()) { |
| 471 | rsc->setVertex(mEnviroment.mVertex.get()); |
| 472 | } |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 473 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 474 | tls->mScript = this; |
| 475 | return mProgram.mScript(launchIndex, &scriptCPtrTable) != 0; |
| 476 | tls->mScript = NULL; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | ScriptCState::ScriptCState() |
| 480 | { |
| 481 | clear(); |
| 482 | } |
| 483 | |
| 484 | ScriptCState::~ScriptCState() |
| 485 | { |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 486 | if (mAccScript) { |
| 487 | accDeleteScript(mAccScript); |
| 488 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | void ScriptCState::clear() |
| 492 | { |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 493 | memset(&mProgram, 0, sizeof(mProgram)); |
| 494 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 495 | mConstantBufferTypes.clear(); |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 496 | |
| 497 | memset(&mEnviroment, 0, sizeof(mEnviroment)); |
| 498 | mEnviroment.mClearColor[0] = 0; |
| 499 | mEnviroment.mClearColor[1] = 0; |
| 500 | mEnviroment.mClearColor[2] = 0; |
| 501 | mEnviroment.mClearColor[3] = 1; |
| 502 | mEnviroment.mClearDepth = 1; |
| 503 | mEnviroment.mClearStencil = 0; |
| 504 | mEnviroment.mIsRoot = false; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 505 | |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 506 | mAccScript = NULL; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 507 | |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 510 | |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 511 | void ScriptCState::runCompiler(Context *rsc) |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 512 | { |
| 513 | mAccScript = accCreateScript(); |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 514 | String8 tmp; |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 515 | |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 516 | rsc->appendNameDefines(&tmp); |
| 517 | |
| 518 | const char* scriptSource[] = {tmp.string(), mProgram.mScriptText}; |
| 519 | int scriptLength[] = {tmp.length(), mProgram.mScriptTextLength} ; |
| 520 | accScriptSource(mAccScript, sizeof(scriptLength) / sizeof(int), scriptSource, scriptLength); |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 521 | accCompileScript(mAccScript); |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 522 | accGetScriptLabel(mAccScript, "main", (ACCvoid**) &mProgram.mScript); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 523 | rsAssert(mProgram.mScript); |
| 524 | |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 525 | mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); |
| 526 | mEnviroment.mVertex.set(rsc->getDefaultProgramVertex()); |
| 527 | mEnviroment.mFragmentStore.set(rsc->getDefaultProgramFragmentStore()); |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 528 | |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 529 | if (mProgram.mScript) { |
| 530 | const static int pragmaMax = 16; |
| 531 | ACCsizei pragmaCount; |
| 532 | ACCchar * str[pragmaMax]; |
| 533 | accGetPragmas(mAccScript, &pragmaCount, pragmaMax, &str[0]); |
| 534 | |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 535 | for (int ct=0; ct < pragmaCount; ct+=2) { |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 536 | if (!strcmp(str[ct], "version")) { |
| 537 | continue; |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 540 | if (!strcmp(str[ct], "stateVertex")) { |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 541 | if (!strcmp(str[ct+1], "default")) { |
| 542 | continue; |
| 543 | } |
| 544 | if (!strcmp(str[ct+1], "parent")) { |
| 545 | mEnviroment.mVertex.clear(); |
| 546 | continue; |
| 547 | } |
| 548 | ProgramVertex * pv = (ProgramVertex *)rsc->lookupName(str[ct+1]); |
| 549 | if (pv != NULL) { |
| 550 | mEnviroment.mVertex.set(pv); |
| 551 | continue; |
| 552 | } |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 553 | LOGE("Unreconized value %s passed to stateVertex", str[ct+1]); |
| 554 | } |
| 555 | |
| 556 | if (!strcmp(str[ct], "stateRaster")) { |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 557 | LOGE("Unreconized value %s passed to stateRaster", str[ct+1]); |
| 558 | } |
| 559 | |
| 560 | if (!strcmp(str[ct], "stateFragment")) { |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 561 | if (!strcmp(str[ct+1], "default")) { |
| 562 | continue; |
| 563 | } |
| 564 | if (!strcmp(str[ct+1], "parent")) { |
| 565 | mEnviroment.mFragment.clear(); |
| 566 | continue; |
| 567 | } |
| 568 | ProgramFragment * pf = (ProgramFragment *)rsc->lookupName(str[ct+1]); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 569 | if (pf != NULL) { |
| 570 | mEnviroment.mFragment.set(pf); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 571 | continue; |
| 572 | } |
| 573 | LOGE("Unreconized value %s passed to stateFragment", str[ct+1]); |
| 574 | } |
| 575 | |
| 576 | if (!strcmp(str[ct], "stateFragmentStore")) { |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 577 | if (!strcmp(str[ct+1], "default")) { |
| 578 | continue; |
| 579 | } |
| 580 | if (!strcmp(str[ct+1], "parent")) { |
| 581 | mEnviroment.mFragmentStore.clear(); |
| 582 | continue; |
| 583 | } |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 584 | ProgramFragmentStore * pfs = |
| 585 | (ProgramFragmentStore *)rsc->lookupName(str[ct+1]); |
| 586 | if (pfs != NULL) { |
| 587 | mEnviroment.mFragmentStore.set(pfs); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 588 | continue; |
| 589 | } |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 590 | LOGE("Unreconized value %s passed to stateFragmentStore", str[ct+1]); |
| 591 | } |
| 592 | |
| 593 | } |
| 594 | |
| 595 | |
| 596 | } else { |
| 597 | // Deal with an error. |
| 598 | } |
| 599 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | namespace android { |
| 603 | namespace renderscript { |
| 604 | |
| 605 | void rsi_ScriptCBegin(Context * rsc) |
| 606 | { |
| 607 | ScriptCState *ss = &rsc->mScriptC; |
| 608 | ss->clear(); |
| 609 | } |
| 610 | |
| 611 | void rsi_ScriptCSetClearColor(Context * rsc, float r, float g, float b, float a) |
| 612 | { |
| 613 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 614 | ss->mEnviroment.mClearColor[0] = r; |
| 615 | ss->mEnviroment.mClearColor[1] = g; |
| 616 | ss->mEnviroment.mClearColor[2] = b; |
| 617 | ss->mEnviroment.mClearColor[3] = a; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | void rsi_ScriptCSetClearDepth(Context * rsc, float v) |
| 621 | { |
| 622 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 623 | ss->mEnviroment.mClearDepth = v; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | void rsi_ScriptCSetClearStencil(Context * rsc, uint32_t v) |
| 627 | { |
| 628 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 629 | ss->mEnviroment.mClearStencil = v; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | void rsi_ScriptCAddType(Context * rsc, RsType vt) |
| 633 | { |
| 634 | ScriptCState *ss = &rsc->mScriptC; |
| 635 | ss->mConstantBufferTypes.add(static_cast<const Type *>(vt)); |
| 636 | } |
| 637 | |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 638 | void rsi_ScriptCSetScript(Context * rsc, void *vp) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 639 | { |
| 640 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 641 | ss->mProgram.mScript = reinterpret_cast<rsc_RunScript>(vp); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | void rsi_ScriptCSetRoot(Context * rsc, bool isRoot) |
| 645 | { |
| 646 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 647 | ss->mEnviroment.mIsRoot = isRoot; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 648 | } |
| 649 | |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 650 | void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len) |
| 651 | { |
| 652 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 653 | ss->mProgram.mScriptText = text; |
| 654 | ss->mProgram.mScriptTextLength = len; |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 658 | RsScript rsi_ScriptCCreate(Context * rsc) |
| 659 | { |
| 660 | ScriptCState *ss = &rsc->mScriptC; |
| 661 | |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 662 | ss->runCompiler(rsc); |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 663 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 664 | ScriptC *s = new ScriptC(); |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 665 | s->incRef(); |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 666 | s->mAccScript = ss->mAccScript; |
| 667 | ss->mAccScript = NULL; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 668 | s->mEnviroment = ss->mEnviroment; |
| 669 | s->mProgram = ss->mProgram; |
| 670 | ss->clear(); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 671 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 672 | return s; |
| 673 | } |
| 674 | |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | |