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