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 | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 133 | static float SC_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(); |
Jason Sams | c75a257 | 2009-07-15 18:35:54 -0700 | [diff] [blame] | 136 | float f = static_cast<const float *>(sc->mSlots[bank]->getPtr())[offset]; |
| 137 | //LOGE("loadF %i %i = %f %x", bank, offset, f, ((int *)&f)[0]); |
| 138 | return f; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 141 | static int32_t SC_loadI32(uint32_t bank, uint32_t offset) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 142 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 143 | GET_TLS(); |
Jason Sams | c75a257 | 2009-07-15 18:35:54 -0700 | [diff] [blame] | 144 | int32_t t = static_cast<const int32_t *>(sc->mSlots[bank]->getPtr())[offset]; |
| 145 | //LOGE("loadI32 %i %i = %i", bank, offset, t); |
| 146 | return t; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 149 | static uint32_t SC_loadU32(uint32_t bank, uint32_t offset) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 150 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 151 | GET_TLS(); |
| 152 | return static_cast<const uint32_t *>(sc->mSlots[bank]->getPtr())[offset]; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 155 | 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] | 156 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 157 | GET_TLS(); |
| 158 | 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] | 159 | } |
| 160 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 161 | 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] | 162 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 163 | GET_TLS(); |
| 164 | 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] | 165 | } |
| 166 | |
| 167 | |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 168 | static void SC_storeF(uint32_t bank, uint32_t offset, float v) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 169 | { |
Jason Sams | c75a257 | 2009-07-15 18:35:54 -0700 | [diff] [blame] | 170 | //LOGE("storeF %i %i %f", bank, offset, v); |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 171 | GET_TLS(); |
| 172 | static_cast<float *>(sc->mSlots[bank]->getPtr())[offset] = v; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 175 | static void SC_storeI32(uint32_t bank, uint32_t offset, int32_t v) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 176 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 177 | GET_TLS(); |
| 178 | static_cast<int32_t *>(sc->mSlots[bank]->getPtr())[offset] = v; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 181 | static void SC_storeU32(uint32_t bank, uint32_t offset, uint32_t v) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 182 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 183 | GET_TLS(); |
| 184 | static_cast<uint32_t *>(sc->mSlots[bank]->getPtr())[offset] = v; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 187 | 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] | 188 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 189 | GET_TLS(); |
| 190 | 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] | 191 | } |
| 192 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 193 | 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] | 194 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 195 | GET_TLS(); |
| 196 | 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] | 197 | } |
| 198 | |
| 199 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 200 | extern "C" void color(float r, float g, float b, float a) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 201 | { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 202 | glColor4f(r, g, b, a); |
| 203 | } |
| 204 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 205 | extern "C" void renderTriangleMesh(RsTriangleMesh mesh) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 206 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 207 | GET_TLS(); |
| 208 | rsi_TriangleMeshRender(rsc, mesh); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 211 | extern "C" void renderTriangleMeshRange(RsTriangleMesh mesh, uint32_t start, uint32_t count) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 212 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 213 | GET_TLS(); |
| 214 | rsi_TriangleMeshRenderRange(rsc, mesh, start, count); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 217 | extern "C" void materialDiffuse(float r, float g, float b, float a) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 218 | { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 219 | float v[] = {r, g, b, a}; |
| 220 | glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, v); |
| 221 | } |
| 222 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 223 | extern "C" void materialSpecular(float r, float g, float b, float a) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 224 | { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 225 | float v[] = {r, g, b, a}; |
| 226 | glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, v); |
| 227 | } |
| 228 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 229 | extern "C" void lightPosition(float x, float y, float z, float w) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 230 | { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 231 | float v[] = {x, y, z, w}; |
| 232 | glLightfv(GL_LIGHT0, GL_POSITION, v); |
| 233 | } |
| 234 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 235 | extern "C" void materialShininess(float s) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 236 | { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 237 | glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &s); |
| 238 | } |
| 239 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 240 | extern "C" void uploadToTexture(RsAllocation va, uint32_t baseMipLevel) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 241 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 242 | GET_TLS(); |
| 243 | rsi_AllocationUploadToTexture(rsc, va, baseMipLevel); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 246 | extern "C" void enable(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 | glEnable(p); |
| 249 | } |
| 250 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 251 | extern "C" void disable(uint32_t p) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 252 | { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 253 | glDisable(p); |
| 254 | } |
| 255 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 256 | extern "C" uint32_t scriptRand(uint32_t max) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 257 | { |
| 258 | return (uint32_t)(((float)rand()) * max / RAND_MAX); |
| 259 | } |
| 260 | |
| 261 | // 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] | 262 | extern "C" void drawTriangleArray(RsAllocation alloc, uint32_t count) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 263 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 264 | GET_TLS(); |
| 265 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 266 | const Allocation *a = (const Allocation *)alloc; |
| 267 | const uint32_t *ptr = (const uint32_t *)a->getPtr(); |
| 268 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 269 | rsc->setupCheck(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 270 | |
| 271 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 272 | //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); |
| 273 | |
| 274 | glEnableClientState(GL_VERTEX_ARRAY); |
| 275 | glDisableClientState(GL_NORMAL_ARRAY); |
| 276 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
| 277 | glEnableClientState(GL_COLOR_ARRAY); |
| 278 | |
| 279 | glVertexPointer(2, GL_FIXED, 12, ptr + 1); |
| 280 | //glTexCoordPointer(2, GL_FIXED, 24, ptr + 1); |
| 281 | glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr); |
| 282 | |
| 283 | glDrawArrays(GL_TRIANGLES, 0, count * 3); |
| 284 | } |
| 285 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 286 | 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] | 287 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 288 | GET_TLS(); |
Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 289 | x1 = (x1 << 16); |
| 290 | x2 = (x2 << 16); |
| 291 | y1 = (y1 << 16); |
| 292 | y2 = (y2 << 16); |
| 293 | |
| 294 | int32_t vtx[] = {x1,y1, x1,y2, x2,y1, x2,y2}; |
| 295 | static const int32_t tex[] = {0,0, 0,0x10000, 0x10000,0, 0x10000,0x10000}; |
| 296 | |
| 297 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 298 | rsc->setupCheck(); |
Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 299 | |
| 300 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 301 | //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); |
| 302 | |
| 303 | glEnableClientState(GL_VERTEX_ARRAY); |
| 304 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 305 | glDisableClientState(GL_NORMAL_ARRAY); |
| 306 | glDisableClientState(GL_COLOR_ARRAY); |
| 307 | |
| 308 | glVertexPointer(2, GL_FIXED, 8, vtx); |
| 309 | glTexCoordPointer(2, GL_FIXED, 8, tex); |
| 310 | //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr); |
| 311 | |
| 312 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
| 313 | } |
| 314 | |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 315 | static void SC_drawQuad(float x1, float y1, float z1, |
| 316 | float x2, float y2, float z2, |
| 317 | float x3, float y3, float z3, |
| 318 | float x4, float y4, float z4) |
Jason Sams | c75a257 | 2009-07-15 18:35:54 -0700 | [diff] [blame] | 319 | { |
| 320 | GET_TLS(); |
| 321 | |
| 322 | //LOGE("Quad"); |
| 323 | //LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1); |
| 324 | //LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2); |
| 325 | //LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3); |
| 326 | //LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4); |
| 327 | |
| 328 | float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4}; |
Jason Sams | c1ea948 | 2009-07-16 19:09:33 -0700 | [diff] [blame] | 329 | static const float tex[] = {0,1, 1,1, 1,0, 0,0}; |
Jason Sams | c75a257 | 2009-07-15 18:35:54 -0700 | [diff] [blame] | 330 | |
| 331 | |
| 332 | rsc->setupCheck(); |
| 333 | |
| 334 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 335 | //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); |
| 336 | |
| 337 | glEnableClientState(GL_VERTEX_ARRAY); |
| 338 | glVertexPointer(3, GL_FLOAT, 0, vtx); |
| 339 | |
| 340 | glClientActiveTexture(GL_TEXTURE0); |
| 341 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 342 | glTexCoordPointer(2, GL_FLOAT, 0, tex); |
| 343 | glClientActiveTexture(GL_TEXTURE1); |
| 344 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 345 | glTexCoordPointer(2, GL_FLOAT, 0, tex); |
| 346 | glClientActiveTexture(GL_TEXTURE0); |
| 347 | |
| 348 | glDisableClientState(GL_NORMAL_ARRAY); |
| 349 | glDisableClientState(GL_COLOR_ARRAY); |
| 350 | |
| 351 | //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr); |
| 352 | |
| 353 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 354 | } |
| 355 | |
Jason Sams | c75a257 | 2009-07-15 18:35:54 -0700 | [diff] [blame] | 356 | extern "C" void pfClearColor(float r, float g, float b, float a) |
| 357 | { |
| 358 | //LOGE("c %f %f %f %f", r, g, b, a); |
| 359 | GET_TLS(); |
| 360 | sc->mEnviroment.mClearColor[0] = r; |
| 361 | sc->mEnviroment.mClearColor[1] = g; |
| 362 | sc->mEnviroment.mClearColor[2] = b; |
| 363 | sc->mEnviroment.mClearColor[3] = a; |
| 364 | } |
| 365 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 366 | extern "C" void pfBindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 367 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 368 | GET_TLS(); |
| 369 | rsi_ProgramFragmentBindTexture(rsc, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 370 | static_cast<ProgramFragment *>(vpf), |
| 371 | slot, |
| 372 | static_cast<Allocation *>(va)); |
| 373 | |
| 374 | } |
| 375 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 376 | extern "C" void pfBindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 377 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 378 | GET_TLS(); |
| 379 | rsi_ProgramFragmentBindSampler(rsc, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 380 | static_cast<ProgramFragment *>(vpf), |
| 381 | slot, |
| 382 | static_cast<Sampler *>(vs)); |
| 383 | |
| 384 | } |
| 385 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 386 | extern "C" void contextBindProgramFragmentStore(RsProgramFragmentStore pfs) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 387 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 388 | GET_TLS(); |
| 389 | rsi_ContextBindProgramFragmentStore(rsc, pfs); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 390 | |
| 391 | } |
| 392 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 393 | extern "C" void contextBindProgramFragment(RsProgramFragment pf) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 394 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 395 | GET_TLS(); |
| 396 | rsi_ContextBindProgramFragment(rsc, pf); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 397 | |
| 398 | } |
| 399 | |
| 400 | |
| 401 | static rsc_FunctionTable scriptCPtrTable = { |
| 402 | loadVp, |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 403 | SC_loadF, |
| 404 | SC_loadI32, |
| 405 | SC_loadU32, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 406 | loadEnvVec4, |
| 407 | loadEnvMatrix, |
| 408 | |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 409 | SC_storeF, |
| 410 | SC_storeI32, |
| 411 | SC_storeU32, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 412 | storeEnvVec4, |
| 413 | storeEnvMatrix, |
| 414 | |
| 415 | matrixLoadIdentity, |
| 416 | matrixLoadFloat, |
| 417 | matrixLoadMat, |
| 418 | matrixLoadRotate, |
| 419 | matrixLoadScale, |
| 420 | matrixLoadTranslate, |
| 421 | matrixLoadMultiply, |
| 422 | matrixMultiply, |
| 423 | matrixRotate, |
| 424 | matrixScale, |
| 425 | matrixTranslate, |
| 426 | |
| 427 | color, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 428 | |
| 429 | pfBindTexture, |
| 430 | pfBindSampler, |
| 431 | |
| 432 | materialDiffuse, |
| 433 | materialSpecular, |
| 434 | lightPosition, |
| 435 | materialShininess, |
| 436 | uploadToTexture, |
| 437 | enable, |
| 438 | disable, |
| 439 | |
| 440 | scriptRand, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 441 | contextBindProgramFragment, |
Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 442 | contextBindProgramFragmentStore, |
| 443 | |
| 444 | |
| 445 | renderTriangleMesh, |
| 446 | renderTriangleMeshRange, |
| 447 | |
| 448 | drawTriangleArray, |
| 449 | drawRect |
| 450 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 451 | }; |
| 452 | |
| 453 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 454 | bool ScriptC::run(Context *rsc, uint32_t launchIndex) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 455 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 456 | Context::ScriptTLSStruct * tls = |
| 457 | (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 458 | |
| 459 | if (mEnviroment.mFragmentStore.get()) { |
| 460 | rsc->setFragmentStore(mEnviroment.mFragmentStore.get()); |
| 461 | } |
| 462 | if (mEnviroment.mFragment.get()) { |
| 463 | rsc->setFragment(mEnviroment.mFragment.get()); |
| 464 | } |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 465 | if (mEnviroment.mVertex.get()) { |
| 466 | rsc->setVertex(mEnviroment.mVertex.get()); |
| 467 | } |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 468 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 469 | tls->mScript = this; |
| 470 | return mProgram.mScript(launchIndex, &scriptCPtrTable) != 0; |
| 471 | tls->mScript = NULL; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | ScriptCState::ScriptCState() |
| 475 | { |
| 476 | clear(); |
| 477 | } |
| 478 | |
| 479 | ScriptCState::~ScriptCState() |
| 480 | { |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 481 | if (mAccScript) { |
| 482 | accDeleteScript(mAccScript); |
| 483 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | void ScriptCState::clear() |
| 487 | { |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 488 | memset(&mProgram, 0, sizeof(mProgram)); |
| 489 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 490 | mConstantBufferTypes.clear(); |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 491 | |
| 492 | memset(&mEnviroment, 0, sizeof(mEnviroment)); |
| 493 | mEnviroment.mClearColor[0] = 0; |
| 494 | mEnviroment.mClearColor[1] = 0; |
| 495 | mEnviroment.mClearColor[2] = 0; |
| 496 | mEnviroment.mClearColor[3] = 1; |
| 497 | mEnviroment.mClearDepth = 1; |
| 498 | mEnviroment.mClearStencil = 0; |
| 499 | mEnviroment.mIsRoot = false; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 500 | |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 501 | mAccScript = NULL; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 502 | |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 505 | ScriptCState::SymbolTable_t ScriptCState::gSyms[] = { |
| 506 | { "loadI32", (void *)&SC_loadI32, "int loadI32(int, int)" }, |
| 507 | { "loadF", (void *)&SC_loadF, "float loadF(int, int)" }, |
| 508 | { "storeI32", (void *)&SC_storeI32, "void storeI32(int, int, int)" }, |
| 509 | { "storeF", (void *)&SC_storeF, "void storeF(int, int, float)" }, |
Jason Sams | 764205c | 2009-07-16 17:47:40 -0700 | [diff] [blame] | 510 | { "drawQuad", (void *)&SC_drawQuad, "void 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)" }, |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 511 | { "sinf", (void *)&sinf, "float sinf(float)" }, |
| 512 | { "cosf", (void *)&cosf, "float cosf(float)" }, |
Jason Sams | c1ea948 | 2009-07-16 19:09:33 -0700 | [diff] [blame] | 513 | { "fabs", (void *)&fabs, "float fabs(float)" }, |
Jason Sams | 764205c | 2009-07-16 17:47:40 -0700 | [diff] [blame] | 514 | { "contextBindProgramFragmentStore", (void *)&contextBindProgramFragmentStore, "void contextBindProgramFragmentStore(int)" }, |
| 515 | { "pfClearColor", (void *)&pfClearColor, "void pfClearColor(float, float, float, float)" }, |
| 516 | { "pfBindTexture", (void *)&pfBindTexture, "void pfBindTexture(int, int, int)" }, |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 517 | |
| 518 | |
| 519 | { NULL, NULL, NULL } |
| 520 | }; |
| 521 | |
| 522 | const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym) |
| 523 | { |
| 524 | ScriptCState::SymbolTable_t *syms = gSyms; |
| 525 | |
| 526 | while (syms->mPtr) { |
| 527 | if (!strcmp(syms->mName, sym)) { |
| 528 | return syms; |
| 529 | } |
| 530 | syms++; |
| 531 | } |
| 532 | return NULL; |
| 533 | } |
| 534 | |
| 535 | static ACCvoid* symbolLookup(ACCvoid* pContext, const ACCchar* name) |
| 536 | { |
| 537 | const ScriptCState::SymbolTable_t *sym = ScriptCState::lookupSymbol(name); |
| 538 | |
| 539 | if (sym) { |
| 540 | return sym->mPtr; |
| 541 | } |
| 542 | |
| 543 | LOGE("ScriptC sym lookup failed for %s", name); |
| 544 | |
| 545 | // Default to calling dlsym to allow any global symbol: |
| 546 | return NULL; |
| 547 | } |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 548 | |
Jason Sams | 764205c | 2009-07-16 17:47:40 -0700 | [diff] [blame] | 549 | void ScriptCState::appendDecls(String8 *str) |
| 550 | { |
| 551 | ScriptCState::SymbolTable_t *syms = gSyms; |
| 552 | while (syms->mPtr) { |
| 553 | str->append(syms->mDecl); |
| 554 | str->append(";\n"); |
| 555 | syms++; |
| 556 | } |
| 557 | } |
| 558 | |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 559 | void ScriptCState::runCompiler(Context *rsc) |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 560 | { |
| 561 | mAccScript = accCreateScript(); |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 562 | String8 tmp; |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 563 | |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 564 | rsc->appendNameDefines(&tmp); |
Jason Sams | 764205c | 2009-07-16 17:47:40 -0700 | [diff] [blame] | 565 | appendDecls(&tmp); |
| 566 | //tmp.append("#line 1\n"); |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 567 | |
| 568 | const char* scriptSource[] = {tmp.string(), mProgram.mScriptText}; |
| 569 | int scriptLength[] = {tmp.length(), mProgram.mScriptTextLength} ; |
| 570 | accScriptSource(mAccScript, sizeof(scriptLength) / sizeof(int), scriptSource, scriptLength); |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 571 | accRegisterSymbolCallback(mAccScript, symbolLookup, NULL); |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 572 | accCompileScript(mAccScript); |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 573 | accGetScriptLabel(mAccScript, "main", (ACCvoid**) &mProgram.mScript); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 574 | rsAssert(mProgram.mScript); |
| 575 | |
Jason Sams | 764205c | 2009-07-16 17:47:40 -0700 | [diff] [blame] | 576 | if (!mProgram.mScript) { |
| 577 | ACCchar buf[4096]; |
| 578 | ACCsizei len; |
| 579 | accGetScriptInfoLog(mAccScript, sizeof(buf), &len, buf); |
| 580 | LOGE(buf); |
| 581 | |
| 582 | } |
| 583 | |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 584 | mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); |
| 585 | mEnviroment.mVertex.set(rsc->getDefaultProgramVertex()); |
| 586 | mEnviroment.mFragmentStore.set(rsc->getDefaultProgramFragmentStore()); |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 587 | |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 588 | if (mProgram.mScript) { |
| 589 | const static int pragmaMax = 16; |
| 590 | ACCsizei pragmaCount; |
| 591 | ACCchar * str[pragmaMax]; |
| 592 | accGetPragmas(mAccScript, &pragmaCount, pragmaMax, &str[0]); |
| 593 | |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 594 | for (int ct=0; ct < pragmaCount; ct+=2) { |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 595 | if (!strcmp(str[ct], "version")) { |
| 596 | continue; |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 597 | } |
| 598 | |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 599 | if (!strcmp(str[ct], "stateVertex")) { |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 600 | if (!strcmp(str[ct+1], "default")) { |
| 601 | continue; |
| 602 | } |
| 603 | if (!strcmp(str[ct+1], "parent")) { |
| 604 | mEnviroment.mVertex.clear(); |
| 605 | continue; |
| 606 | } |
| 607 | ProgramVertex * pv = (ProgramVertex *)rsc->lookupName(str[ct+1]); |
| 608 | if (pv != NULL) { |
| 609 | mEnviroment.mVertex.set(pv); |
| 610 | continue; |
| 611 | } |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 612 | LOGE("Unreconized value %s passed to stateVertex", str[ct+1]); |
| 613 | } |
| 614 | |
| 615 | if (!strcmp(str[ct], "stateRaster")) { |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 616 | LOGE("Unreconized value %s passed to stateRaster", str[ct+1]); |
| 617 | } |
| 618 | |
| 619 | if (!strcmp(str[ct], "stateFragment")) { |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 620 | if (!strcmp(str[ct+1], "default")) { |
| 621 | continue; |
| 622 | } |
| 623 | if (!strcmp(str[ct+1], "parent")) { |
| 624 | mEnviroment.mFragment.clear(); |
| 625 | continue; |
| 626 | } |
| 627 | ProgramFragment * pf = (ProgramFragment *)rsc->lookupName(str[ct+1]); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 628 | if (pf != NULL) { |
| 629 | mEnviroment.mFragment.set(pf); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 630 | continue; |
| 631 | } |
| 632 | LOGE("Unreconized value %s passed to stateFragment", str[ct+1]); |
| 633 | } |
| 634 | |
| 635 | if (!strcmp(str[ct], "stateFragmentStore")) { |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 636 | if (!strcmp(str[ct+1], "default")) { |
| 637 | continue; |
| 638 | } |
| 639 | if (!strcmp(str[ct+1], "parent")) { |
| 640 | mEnviroment.mFragmentStore.clear(); |
| 641 | continue; |
| 642 | } |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 643 | ProgramFragmentStore * pfs = |
| 644 | (ProgramFragmentStore *)rsc->lookupName(str[ct+1]); |
| 645 | if (pfs != NULL) { |
| 646 | mEnviroment.mFragmentStore.set(pfs); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 647 | continue; |
| 648 | } |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 649 | LOGE("Unreconized value %s passed to stateFragmentStore", str[ct+1]); |
| 650 | } |
| 651 | |
| 652 | } |
| 653 | |
| 654 | |
| 655 | } else { |
| 656 | // Deal with an error. |
| 657 | } |
| 658 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | namespace android { |
| 662 | namespace renderscript { |
| 663 | |
| 664 | void rsi_ScriptCBegin(Context * rsc) |
| 665 | { |
| 666 | ScriptCState *ss = &rsc->mScriptC; |
| 667 | ss->clear(); |
| 668 | } |
| 669 | |
| 670 | void rsi_ScriptCSetClearColor(Context * rsc, float r, float g, float b, float a) |
| 671 | { |
| 672 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 673 | ss->mEnviroment.mClearColor[0] = r; |
| 674 | ss->mEnviroment.mClearColor[1] = g; |
| 675 | ss->mEnviroment.mClearColor[2] = b; |
| 676 | ss->mEnviroment.mClearColor[3] = a; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | void rsi_ScriptCSetClearDepth(Context * rsc, float v) |
| 680 | { |
| 681 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 682 | ss->mEnviroment.mClearDepth = v; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | void rsi_ScriptCSetClearStencil(Context * rsc, uint32_t v) |
| 686 | { |
| 687 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 688 | ss->mEnviroment.mClearStencil = v; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | void rsi_ScriptCAddType(Context * rsc, RsType vt) |
| 692 | { |
| 693 | ScriptCState *ss = &rsc->mScriptC; |
| 694 | ss->mConstantBufferTypes.add(static_cast<const Type *>(vt)); |
| 695 | } |
| 696 | |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 697 | void rsi_ScriptCSetScript(Context * rsc, void *vp) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 698 | { |
| 699 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 700 | ss->mProgram.mScript = reinterpret_cast<rsc_RunScript>(vp); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | void rsi_ScriptCSetRoot(Context * rsc, bool isRoot) |
| 704 | { |
| 705 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 706 | ss->mEnviroment.mIsRoot = isRoot; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 709 | void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len) |
| 710 | { |
| 711 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 712 | ss->mProgram.mScriptText = text; |
| 713 | ss->mProgram.mScriptTextLength = len; |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 717 | RsScript rsi_ScriptCCreate(Context * rsc) |
| 718 | { |
| 719 | ScriptCState *ss = &rsc->mScriptC; |
| 720 | |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 721 | ss->runCompiler(rsc); |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 722 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 723 | ScriptC *s = new ScriptC(); |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 724 | s->incRef(); |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 725 | s->mAccScript = ss->mAccScript; |
| 726 | ss->mAccScript = NULL; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 727 | s->mEnviroment = ss->mEnviroment; |
| 728 | s->mProgram = ss->mProgram; |
| 729 | ss->clear(); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 730 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 731 | return s; |
| 732 | } |
| 733 | |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | |