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}; |
| 329 | static const float tex[] = {0,0, 0,1, 1,1, 1,0}; |
| 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" float sinf(float angle) |
| 357 | { |
| 358 | float s = (float)sin(angle); |
| 359 | return s; |
| 360 | } |
| 361 | |
| 362 | extern "C" float cosf(float angle) |
| 363 | { |
| 364 | float s = (float)cos(angle); |
| 365 | return s; |
| 366 | } |
| 367 | |
| 368 | extern "C" void pfClearColor(float r, float g, float b, float a) |
| 369 | { |
| 370 | //LOGE("c %f %f %f %f", r, g, b, a); |
| 371 | GET_TLS(); |
| 372 | sc->mEnviroment.mClearColor[0] = r; |
| 373 | sc->mEnviroment.mClearColor[1] = g; |
| 374 | sc->mEnviroment.mClearColor[2] = b; |
| 375 | sc->mEnviroment.mClearColor[3] = a; |
| 376 | } |
| 377 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 378 | extern "C" void pfBindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 379 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 380 | GET_TLS(); |
| 381 | rsi_ProgramFragmentBindTexture(rsc, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 382 | static_cast<ProgramFragment *>(vpf), |
| 383 | slot, |
| 384 | static_cast<Allocation *>(va)); |
| 385 | |
| 386 | } |
| 387 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 388 | extern "C" void pfBindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 389 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 390 | GET_TLS(); |
| 391 | rsi_ProgramFragmentBindSampler(rsc, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 392 | static_cast<ProgramFragment *>(vpf), |
| 393 | slot, |
| 394 | static_cast<Sampler *>(vs)); |
| 395 | |
| 396 | } |
| 397 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 398 | extern "C" void contextBindProgramFragmentStore(RsProgramFragmentStore pfs) |
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_ContextBindProgramFragmentStore(rsc, pfs); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 402 | |
| 403 | } |
| 404 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 405 | extern "C" void contextBindProgramFragment(RsProgramFragment pf) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 406 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 407 | GET_TLS(); |
| 408 | rsi_ContextBindProgramFragment(rsc, pf); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 409 | |
| 410 | } |
| 411 | |
| 412 | |
| 413 | static rsc_FunctionTable scriptCPtrTable = { |
| 414 | loadVp, |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 415 | SC_loadF, |
| 416 | SC_loadI32, |
| 417 | SC_loadU32, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 418 | loadEnvVec4, |
| 419 | loadEnvMatrix, |
| 420 | |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 421 | SC_storeF, |
| 422 | SC_storeI32, |
| 423 | SC_storeU32, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 424 | storeEnvVec4, |
| 425 | storeEnvMatrix, |
| 426 | |
| 427 | matrixLoadIdentity, |
| 428 | matrixLoadFloat, |
| 429 | matrixLoadMat, |
| 430 | matrixLoadRotate, |
| 431 | matrixLoadScale, |
| 432 | matrixLoadTranslate, |
| 433 | matrixLoadMultiply, |
| 434 | matrixMultiply, |
| 435 | matrixRotate, |
| 436 | matrixScale, |
| 437 | matrixTranslate, |
| 438 | |
| 439 | color, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 440 | |
| 441 | pfBindTexture, |
| 442 | pfBindSampler, |
| 443 | |
| 444 | materialDiffuse, |
| 445 | materialSpecular, |
| 446 | lightPosition, |
| 447 | materialShininess, |
| 448 | uploadToTexture, |
| 449 | enable, |
| 450 | disable, |
| 451 | |
| 452 | scriptRand, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 453 | contextBindProgramFragment, |
Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 454 | contextBindProgramFragmentStore, |
| 455 | |
| 456 | |
| 457 | renderTriangleMesh, |
| 458 | renderTriangleMeshRange, |
| 459 | |
| 460 | drawTriangleArray, |
| 461 | drawRect |
| 462 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 463 | }; |
| 464 | |
| 465 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 466 | bool ScriptC::run(Context *rsc, uint32_t launchIndex) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 467 | { |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 468 | Context::ScriptTLSStruct * tls = |
| 469 | (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 470 | |
| 471 | if (mEnviroment.mFragmentStore.get()) { |
| 472 | rsc->setFragmentStore(mEnviroment.mFragmentStore.get()); |
| 473 | } |
| 474 | if (mEnviroment.mFragment.get()) { |
| 475 | rsc->setFragment(mEnviroment.mFragment.get()); |
| 476 | } |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 477 | if (mEnviroment.mVertex.get()) { |
| 478 | rsc->setVertex(mEnviroment.mVertex.get()); |
| 479 | } |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 480 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 481 | tls->mScript = this; |
| 482 | return mProgram.mScript(launchIndex, &scriptCPtrTable) != 0; |
| 483 | tls->mScript = NULL; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | ScriptCState::ScriptCState() |
| 487 | { |
| 488 | clear(); |
| 489 | } |
| 490 | |
| 491 | ScriptCState::~ScriptCState() |
| 492 | { |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 493 | if (mAccScript) { |
| 494 | accDeleteScript(mAccScript); |
| 495 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | void ScriptCState::clear() |
| 499 | { |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 500 | memset(&mProgram, 0, sizeof(mProgram)); |
| 501 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 502 | mConstantBufferTypes.clear(); |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 503 | |
| 504 | memset(&mEnviroment, 0, sizeof(mEnviroment)); |
| 505 | mEnviroment.mClearColor[0] = 0; |
| 506 | mEnviroment.mClearColor[1] = 0; |
| 507 | mEnviroment.mClearColor[2] = 0; |
| 508 | mEnviroment.mClearColor[3] = 1; |
| 509 | mEnviroment.mClearDepth = 1; |
| 510 | mEnviroment.mClearStencil = 0; |
| 511 | mEnviroment.mIsRoot = false; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 512 | |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 513 | mAccScript = NULL; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 514 | |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 517 | ScriptCState::SymbolTable_t ScriptCState::gSyms[] = { |
| 518 | { "loadI32", (void *)&SC_loadI32, "int loadI32(int, int)" }, |
| 519 | { "loadF", (void *)&SC_loadF, "float loadF(int, int)" }, |
| 520 | { "storeI32", (void *)&SC_storeI32, "void storeI32(int, int, int)" }, |
| 521 | { "storeF", (void *)&SC_storeF, "void storeF(int, int, float)" }, |
Jason Sams | 764205c | 2009-07-16 17:47:40 -0700 | [diff] [blame^] | 522 | { "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] | 523 | { "sinf", (void *)&sinf, "float sinf(float)" }, |
| 524 | { "cosf", (void *)&cosf, "float cosf(float)" }, |
Jason Sams | 764205c | 2009-07-16 17:47:40 -0700 | [diff] [blame^] | 525 | { "contextBindProgramFragmentStore", (void *)&contextBindProgramFragmentStore, "void contextBindProgramFragmentStore(int)" }, |
| 526 | { "pfClearColor", (void *)&pfClearColor, "void pfClearColor(float, float, float, float)" }, |
| 527 | { "pfBindTexture", (void *)&pfBindTexture, "void pfBindTexture(int, int, int)" }, |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 528 | |
| 529 | |
| 530 | { NULL, NULL, NULL } |
| 531 | }; |
| 532 | |
| 533 | const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym) |
| 534 | { |
| 535 | ScriptCState::SymbolTable_t *syms = gSyms; |
| 536 | |
| 537 | while (syms->mPtr) { |
| 538 | if (!strcmp(syms->mName, sym)) { |
| 539 | return syms; |
| 540 | } |
| 541 | syms++; |
| 542 | } |
| 543 | return NULL; |
| 544 | } |
| 545 | |
| 546 | static ACCvoid* symbolLookup(ACCvoid* pContext, const ACCchar* name) |
| 547 | { |
| 548 | const ScriptCState::SymbolTable_t *sym = ScriptCState::lookupSymbol(name); |
| 549 | |
| 550 | if (sym) { |
| 551 | return sym->mPtr; |
| 552 | } |
| 553 | |
| 554 | LOGE("ScriptC sym lookup failed for %s", name); |
| 555 | |
| 556 | // Default to calling dlsym to allow any global symbol: |
| 557 | return NULL; |
| 558 | } |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 559 | |
Jason Sams | 764205c | 2009-07-16 17:47:40 -0700 | [diff] [blame^] | 560 | void ScriptCState::appendDecls(String8 *str) |
| 561 | { |
| 562 | ScriptCState::SymbolTable_t *syms = gSyms; |
| 563 | while (syms->mPtr) { |
| 564 | str->append(syms->mDecl); |
| 565 | str->append(";\n"); |
| 566 | syms++; |
| 567 | } |
| 568 | } |
| 569 | |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 570 | void ScriptCState::runCompiler(Context *rsc) |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 571 | { |
| 572 | mAccScript = accCreateScript(); |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 573 | String8 tmp; |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 574 | |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 575 | rsc->appendNameDefines(&tmp); |
Jason Sams | 764205c | 2009-07-16 17:47:40 -0700 | [diff] [blame^] | 576 | appendDecls(&tmp); |
| 577 | //tmp.append("#line 1\n"); |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 578 | |
| 579 | const char* scriptSource[] = {tmp.string(), mProgram.mScriptText}; |
| 580 | int scriptLength[] = {tmp.length(), mProgram.mScriptTextLength} ; |
| 581 | accScriptSource(mAccScript, sizeof(scriptLength) / sizeof(int), scriptSource, scriptLength); |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 582 | accRegisterSymbolCallback(mAccScript, symbolLookup, NULL); |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 583 | accCompileScript(mAccScript); |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 584 | accGetScriptLabel(mAccScript, "main", (ACCvoid**) &mProgram.mScript); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 585 | rsAssert(mProgram.mScript); |
| 586 | |
Jason Sams | 764205c | 2009-07-16 17:47:40 -0700 | [diff] [blame^] | 587 | if (!mProgram.mScript) { |
| 588 | ACCchar buf[4096]; |
| 589 | ACCsizei len; |
| 590 | accGetScriptInfoLog(mAccScript, sizeof(buf), &len, buf); |
| 591 | LOGE(buf); |
| 592 | |
| 593 | } |
| 594 | |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 595 | mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); |
| 596 | mEnviroment.mVertex.set(rsc->getDefaultProgramVertex()); |
| 597 | mEnviroment.mFragmentStore.set(rsc->getDefaultProgramFragmentStore()); |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 598 | |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 599 | if (mProgram.mScript) { |
| 600 | const static int pragmaMax = 16; |
| 601 | ACCsizei pragmaCount; |
| 602 | ACCchar * str[pragmaMax]; |
| 603 | accGetPragmas(mAccScript, &pragmaCount, pragmaMax, &str[0]); |
| 604 | |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 605 | for (int ct=0; ct < pragmaCount; ct+=2) { |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 606 | if (!strcmp(str[ct], "version")) { |
| 607 | continue; |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 610 | if (!strcmp(str[ct], "stateVertex")) { |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 611 | if (!strcmp(str[ct+1], "default")) { |
| 612 | continue; |
| 613 | } |
| 614 | if (!strcmp(str[ct+1], "parent")) { |
| 615 | mEnviroment.mVertex.clear(); |
| 616 | continue; |
| 617 | } |
| 618 | ProgramVertex * pv = (ProgramVertex *)rsc->lookupName(str[ct+1]); |
| 619 | if (pv != NULL) { |
| 620 | mEnviroment.mVertex.set(pv); |
| 621 | continue; |
| 622 | } |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 623 | LOGE("Unreconized value %s passed to stateVertex", str[ct+1]); |
| 624 | } |
| 625 | |
| 626 | if (!strcmp(str[ct], "stateRaster")) { |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 627 | LOGE("Unreconized value %s passed to stateRaster", str[ct+1]); |
| 628 | } |
| 629 | |
| 630 | if (!strcmp(str[ct], "stateFragment")) { |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 631 | if (!strcmp(str[ct+1], "default")) { |
| 632 | continue; |
| 633 | } |
| 634 | if (!strcmp(str[ct+1], "parent")) { |
| 635 | mEnviroment.mFragment.clear(); |
| 636 | continue; |
| 637 | } |
| 638 | ProgramFragment * pf = (ProgramFragment *)rsc->lookupName(str[ct+1]); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 639 | if (pf != NULL) { |
| 640 | mEnviroment.mFragment.set(pf); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 641 | continue; |
| 642 | } |
| 643 | LOGE("Unreconized value %s passed to stateFragment", str[ct+1]); |
| 644 | } |
| 645 | |
| 646 | if (!strcmp(str[ct], "stateFragmentStore")) { |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 647 | if (!strcmp(str[ct+1], "default")) { |
| 648 | continue; |
| 649 | } |
| 650 | if (!strcmp(str[ct+1], "parent")) { |
| 651 | mEnviroment.mFragmentStore.clear(); |
| 652 | continue; |
| 653 | } |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 654 | ProgramFragmentStore * pfs = |
| 655 | (ProgramFragmentStore *)rsc->lookupName(str[ct+1]); |
| 656 | if (pfs != NULL) { |
| 657 | mEnviroment.mFragmentStore.set(pfs); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 658 | continue; |
| 659 | } |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 660 | LOGE("Unreconized value %s passed to stateFragmentStore", str[ct+1]); |
| 661 | } |
| 662 | |
| 663 | } |
| 664 | |
| 665 | |
| 666 | } else { |
| 667 | // Deal with an error. |
| 668 | } |
| 669 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | namespace android { |
| 673 | namespace renderscript { |
| 674 | |
| 675 | void rsi_ScriptCBegin(Context * rsc) |
| 676 | { |
| 677 | ScriptCState *ss = &rsc->mScriptC; |
| 678 | ss->clear(); |
| 679 | } |
| 680 | |
| 681 | void rsi_ScriptCSetClearColor(Context * rsc, float r, float g, float b, float a) |
| 682 | { |
| 683 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 684 | ss->mEnviroment.mClearColor[0] = r; |
| 685 | ss->mEnviroment.mClearColor[1] = g; |
| 686 | ss->mEnviroment.mClearColor[2] = b; |
| 687 | ss->mEnviroment.mClearColor[3] = a; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | void rsi_ScriptCSetClearDepth(Context * rsc, float v) |
| 691 | { |
| 692 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 693 | ss->mEnviroment.mClearDepth = v; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | void rsi_ScriptCSetClearStencil(Context * rsc, uint32_t v) |
| 697 | { |
| 698 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 699 | ss->mEnviroment.mClearStencil = v; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | void rsi_ScriptCAddType(Context * rsc, RsType vt) |
| 703 | { |
| 704 | ScriptCState *ss = &rsc->mScriptC; |
| 705 | ss->mConstantBufferTypes.add(static_cast<const Type *>(vt)); |
| 706 | } |
| 707 | |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 708 | void rsi_ScriptCSetScript(Context * rsc, void *vp) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 709 | { |
| 710 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 711 | ss->mProgram.mScript = reinterpret_cast<rsc_RunScript>(vp); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | void rsi_ScriptCSetRoot(Context * rsc, bool isRoot) |
| 715 | { |
| 716 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 717 | ss->mEnviroment.mIsRoot = isRoot; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 720 | void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len) |
| 721 | { |
| 722 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 723 | ss->mProgram.mScriptText = text; |
| 724 | ss->mProgram.mScriptTextLength = len; |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 728 | RsScript rsi_ScriptCCreate(Context * rsc) |
| 729 | { |
| 730 | ScriptCState *ss = &rsc->mScriptC; |
| 731 | |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 732 | ss->runCompiler(rsc); |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 733 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 734 | ScriptC *s = new ScriptC(); |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 735 | s->incRef(); |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 736 | s->mAccScript = ss->mAccScript; |
| 737 | ss->mAccScript = NULL; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 738 | s->mEnviroment = ss->mEnviroment; |
| 739 | s->mProgram = ss->mProgram; |
| 740 | ss->clear(); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 741 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 742 | return s; |
| 743 | } |
| 744 | |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | |