Jason Sams | 536923d | 2010-05-18 13:35:45 -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" |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 20 | |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 21 | #include "utils/Timers.h" |
| 22 | |
| 23 | #define GL_GLEXT_PROTOTYPES |
| 24 | |
| 25 | #include <GLES/gl.h> |
| 26 | #include <GLES/glext.h> |
| 27 | #include <GLES2/gl2.h> |
| 28 | #include <GLES2/gl2ext.h> |
| 29 | |
| 30 | #include <time.h> |
| 31 | |
| 32 | using namespace android; |
| 33 | using namespace android::renderscript; |
| 34 | |
Jason Sams | 55d2a25 | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 35 | #define GET_TLS() ScriptTLSStruct * tls = \ |
| 36 | (ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \ |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 37 | Context * rsc = tls->mContext; \ |
| 38 | ScriptC * sc = (ScriptC *) tls->mScript |
| 39 | |
| 40 | |
| 41 | ////////////////////////////////////////////////////////////////////////////// |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 42 | // Context |
| 43 | ////////////////////////////////////////////////////////////////////////////// |
| 44 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 45 | static void SC_bindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 46 | CHECK_OBJ_OR_NULL(va); |
| 47 | CHECK_OBJ(vpf); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 48 | GET_TLS(); |
| 49 | rsi_ProgramBindTexture(rsc, |
| 50 | static_cast<ProgramFragment *>(vpf), |
| 51 | slot, |
| 52 | static_cast<Allocation *>(va)); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 55 | static void SC_bindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 56 | CHECK_OBJ_OR_NULL(vs); |
| 57 | CHECK_OBJ(vpf); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 58 | GET_TLS(); |
| 59 | rsi_ProgramBindSampler(rsc, |
| 60 | static_cast<ProgramFragment *>(vpf), |
| 61 | slot, |
| 62 | static_cast<Sampler *>(vs)); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 65 | static void SC_bindProgramStore(RsProgramStore pfs) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 66 | CHECK_OBJ_OR_NULL(pfs); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 67 | GET_TLS(); |
| 68 | rsi_ContextBindProgramStore(rsc, pfs); |
| 69 | } |
| 70 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 71 | static void SC_bindProgramFragment(RsProgramFragment pf) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 72 | CHECK_OBJ_OR_NULL(pf); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 73 | GET_TLS(); |
| 74 | rsi_ContextBindProgramFragment(rsc, pf); |
| 75 | } |
| 76 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 77 | static void SC_bindProgramVertex(RsProgramVertex pv) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 78 | CHECK_OBJ_OR_NULL(pv); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 79 | GET_TLS(); |
| 80 | rsi_ContextBindProgramVertex(rsc, pv); |
| 81 | } |
| 82 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 83 | static void SC_bindProgramRaster(RsProgramRaster pv) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 84 | CHECK_OBJ_OR_NULL(pv); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 85 | GET_TLS(); |
| 86 | rsi_ContextBindProgramRaster(rsc, pv); |
| 87 | } |
| 88 | |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 89 | static void SC_bindFrameBufferObjectColorTarget(RsAllocation va, uint32_t slot) { |
| 90 | CHECK_OBJ(va); |
| 91 | GET_TLS(); |
| 92 | rsc->mFBOCache.bindColorTarget(rsc, static_cast<Allocation *>(va), slot); |
| 93 | } |
| 94 | |
| 95 | static void SC_bindFrameBufferObjectDepthTarget(RsAllocation va) { |
| 96 | CHECK_OBJ(va); |
| 97 | GET_TLS(); |
| 98 | rsc->mFBOCache.bindDepthTarget(rsc, static_cast<Allocation *>(va)); |
| 99 | } |
| 100 | |
| 101 | static void SC_clearFrameBufferObjectColorTarget(uint32_t slot) { |
| 102 | GET_TLS(); |
| 103 | rsc->mFBOCache.bindColorTarget(rsc, NULL, slot); |
| 104 | } |
| 105 | |
| 106 | static void SC_clearFrameBufferObjectDepthTarget() { |
| 107 | GET_TLS(); |
| 108 | rsc->mFBOCache.bindDepthTarget(rsc, NULL); |
| 109 | } |
| 110 | |
| 111 | static void SC_clearFrameBufferObjectTargets() { |
| 112 | GET_TLS(); |
| 113 | rsc->mFBOCache.resetAll(rsc); |
| 114 | } |
| 115 | |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 116 | ////////////////////////////////////////////////////////////////////////////// |
| 117 | // VP |
| 118 | ////////////////////////////////////////////////////////////////////////////// |
| 119 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 120 | static void SC_vpLoadProjectionMatrix(const rsc_Matrix *m) { |
Jim Miller | d8e7620 | 2010-07-28 14:46:22 -0700 | [diff] [blame] | 121 | GET_TLS(); |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 122 | rsc->getProgramVertex()->setProjectionMatrix(rsc, m); |
Jim Miller | d8e7620 | 2010-07-28 14:46:22 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 125 | static void SC_vpLoadModelMatrix(const rsc_Matrix *m) { |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 126 | GET_TLS(); |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 127 | rsc->getProgramVertex()->setModelviewMatrix(rsc, m); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 130 | static void SC_vpLoadTextureMatrix(const rsc_Matrix *m) { |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 131 | GET_TLS(); |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 132 | rsc->getProgramVertex()->setTextureMatrix(rsc, m); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 135 | static void SC_pfConstantColor(RsProgramFragment vpf, float r, float g, float b, float a) { |
Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 136 | GET_TLS(); |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 137 | CHECK_OBJ(vpf); |
Jason Sams | 442a647 | 2010-08-04 17:50:20 -0700 | [diff] [blame] | 138 | ProgramFragment *pf = static_cast<ProgramFragment *>(vpf); |
Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 139 | pf->setConstantColor(rsc, r, g, b, a); |
Jason Sams | 442a647 | 2010-08-04 17:50:20 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 142 | static void SC_vpGetProjectionMatrix(rsc_Matrix *m) { |
Alex Sakhartchouk | cbed752 | 2010-08-16 17:40:10 -0700 | [diff] [blame] | 143 | GET_TLS(); |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 144 | rsc->getProgramVertex()->getProjectionMatrix(rsc, m); |
Alex Sakhartchouk | cbed752 | 2010-08-16 17:40:10 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 147 | ////////////////////////////////////////////////////////////////////////////// |
| 148 | // Drawing |
| 149 | ////////////////////////////////////////////////////////////////////////////// |
| 150 | |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 151 | static void SC_drawQuadTexCoords(float x1, float y1, float z1, |
| 152 | float u1, float v1, |
| 153 | float x2, float y2, float z2, |
| 154 | float u2, float v2, |
| 155 | float x3, float y3, float z3, |
| 156 | float u3, float v3, |
| 157 | float x4, float y4, float z4, |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 158 | float u4, float v4) { |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 159 | GET_TLS(); |
| 160 | if (!rsc->setupCheck()) { |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | //LOGE("Quad"); |
| 165 | //LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1); |
| 166 | //LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2); |
| 167 | //LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3); |
| 168 | //LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4); |
| 169 | |
| 170 | float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4}; |
| 171 | const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4}; |
| 172 | |
Alex Sakhartchouk | 9d71e21 | 2010-11-08 15:10:52 -0800 | [diff] [blame] | 173 | VertexArray::Attrib attribs[2]; |
| 174 | attribs[0].set(GL_FLOAT, 3, 12, false, (uint32_t)vtx, "ATTRIB_position"); |
| 175 | attribs[1].set(GL_FLOAT, 2, 8, false, (uint32_t)tex, "ATTRIB_texture0"); |
| 176 | |
| 177 | VertexArray va(attribs, 2); |
Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 178 | va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 179 | |
| 180 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 181 | } |
| 182 | |
| 183 | static void SC_drawQuad(float x1, float y1, float z1, |
| 184 | float x2, float y2, float z2, |
| 185 | float x3, float y3, float z3, |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 186 | float x4, float y4, float z4) { |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 187 | SC_drawQuadTexCoords(x1, y1, z1, 0, 1, |
| 188 | x2, y2, z2, 1, 1, |
| 189 | x3, y3, z3, 1, 0, |
| 190 | x4, y4, z4, 0, 0); |
| 191 | } |
| 192 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 193 | static void SC_drawSpriteScreenspace(float x, float y, float z, float w, float h) { |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 194 | GET_TLS(); |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 195 | ObjectBaseRef<const ProgramVertex> tmp(rsc->getProgramVertex()); |
| 196 | rsc->setProgramVertex(rsc->getDefaultProgramVertex()); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 197 | //rsc->setupCheck(); |
| 198 | |
| 199 | //GLint crop[4] = {0, h, w, -h}; |
| 200 | |
| 201 | float sh = rsc->getHeight(); |
| 202 | |
| 203 | SC_drawQuad(x, sh - y, z, |
| 204 | x+w, sh - y, z, |
| 205 | x+w, sh - (y+h), z, |
| 206 | x, sh - (y+h), z); |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 207 | rsc->setProgramVertex((ProgramVertex *)tmp.get()); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 208 | } |
Jason Sams | 6d1cf41 | 2010-06-17 18:05:38 -0700 | [diff] [blame] | 209 | /* |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 210 | static void SC_drawSprite(float x, float y, float z, float w, float h) |
| 211 | { |
| 212 | GET_TLS(); |
| 213 | float vin[3] = {x, y, z}; |
| 214 | float vout[4]; |
| 215 | |
| 216 | //LOGE("ds in %f %f %f", x, y, z); |
| 217 | rsc->getVertex()->transformToScreen(rsc, vout, vin); |
| 218 | //LOGE("ds out %f %f %f %f", vout[0], vout[1], vout[2], vout[3]); |
| 219 | vout[0] /= vout[3]; |
| 220 | vout[1] /= vout[3]; |
| 221 | vout[2] /= vout[3]; |
| 222 | |
| 223 | vout[0] *= rsc->getWidth() / 2; |
| 224 | vout[1] *= rsc->getHeight() / 2; |
| 225 | vout[0] += rsc->getWidth() / 2; |
| 226 | vout[1] += rsc->getHeight() / 2; |
| 227 | |
| 228 | vout[0] -= w/2; |
| 229 | vout[1] -= h/2; |
| 230 | |
| 231 | //LOGE("ds out2 %f %f %f", vout[0], vout[1], vout[2]); |
| 232 | |
| 233 | // U, V, W, H |
| 234 | SC_drawSpriteScreenspace(vout[0], vout[1], z, h, w); |
| 235 | //rsc->setupCheck(); |
| 236 | } |
Jason Sams | 6d1cf41 | 2010-06-17 18:05:38 -0700 | [diff] [blame] | 237 | */ |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 238 | |
| 239 | static void SC_drawRect(float x1, float y1, |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 240 | float x2, float y2, float z) { |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 241 | //LOGE("SC_drawRect %f,%f %f,%f %f", x1, y1, x2, y2, z); |
| 242 | SC_drawQuad(x1, y2, z, |
| 243 | x2, y2, z, |
| 244 | x2, y1, z, |
| 245 | x1, y1, z); |
| 246 | } |
| 247 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 248 | static void SC_drawMesh(RsMesh vsm) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 249 | CHECK_OBJ(vsm); |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 250 | GET_TLS(); |
| 251 | Mesh *sm = static_cast<Mesh *>(vsm); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 252 | if (!rsc->setupCheck()) { |
| 253 | return; |
| 254 | } |
| 255 | sm->render(rsc); |
| 256 | } |
| 257 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 258 | static void SC_drawMeshPrimitive(RsMesh vsm, uint32_t primIndex) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 259 | CHECK_OBJ(vsm); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 260 | GET_TLS(); |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 261 | Mesh *sm = static_cast<Mesh *>(vsm); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 262 | if (!rsc->setupCheck()) { |
| 263 | return; |
| 264 | } |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 265 | sm->renderPrimitive(rsc, primIndex); |
| 266 | } |
| 267 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 268 | static void SC_drawMeshPrimitiveRange(RsMesh vsm, uint32_t primIndex, uint32_t start, uint32_t len) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 269 | CHECK_OBJ(vsm); |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 270 | GET_TLS(); |
| 271 | Mesh *sm = static_cast<Mesh *>(vsm); |
| 272 | if (!rsc->setupCheck()) { |
| 273 | return; |
| 274 | } |
| 275 | sm->renderPrimitiveRange(rsc, primIndex, start, len); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 278 | static void SC_meshComputeBoundingBox(RsMesh vsm, |
| 279 | float *minX, float *minY, float *minZ, |
| 280 | float *maxX, float *maxY, float *maxZ) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 281 | CHECK_OBJ(vsm); |
Alex Sakhartchouk | a80145d | 2010-08-13 14:32:23 -0700 | [diff] [blame] | 282 | GET_TLS(); |
| 283 | Mesh *sm = static_cast<Mesh *>(vsm); |
| 284 | sm->computeBBox(); |
| 285 | *minX = sm->mBBoxMin[0]; |
| 286 | *minY = sm->mBBoxMin[1]; |
| 287 | *minZ = sm->mBBoxMin[2]; |
| 288 | *maxX = sm->mBBoxMax[0]; |
| 289 | *maxY = sm->mBBoxMax[1]; |
| 290 | *maxZ = sm->mBBoxMax[2]; |
| 291 | } |
| 292 | |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 293 | |
| 294 | ////////////////////////////////////////////////////////////////////////////// |
| 295 | // |
| 296 | ////////////////////////////////////////////////////////////////////////////// |
| 297 | |
| 298 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 299 | static void SC_color(float r, float g, float b, float a) { |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 300 | GET_TLS(); |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 301 | ProgramFragment *pf = (ProgramFragment *)rsc->getProgramFragment(); |
Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 302 | pf->setConstantColor(rsc, r, g, b, a); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 305 | static void SC_finish() { |
| 306 | glFinish(); |
| 307 | } |
| 308 | |
Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 309 | static void SC_allocationSyncAll(RsAllocation va) { |
| 310 | CHECK_OBJ(va); |
| 311 | GET_TLS(); |
| 312 | static_cast<Allocation *>(va)->syncAll(rsc, RS_ALLOCATION_USAGE_SCRIPT); |
| 313 | } |
| 314 | |
Stephen Hines | 60f9a62 | 2011-03-01 17:34:59 -0800 | [diff] [blame] | 315 | #if 0 |
Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 316 | static void SC_allocationSyncAll2(RsAllocation va, RsAllocationUsageType source) { |
| 317 | CHECK_OBJ(va); |
| 318 | GET_TLS(); |
| 319 | static_cast<Allocation *>(va)->syncAll(rsc, source); |
| 320 | } |
Stephen Hines | 60f9a62 | 2011-03-01 17:34:59 -0800 | [diff] [blame] | 321 | #endif |
Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 322 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 323 | static void SC_ClearColor(float r, float g, float b, float a) { |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 324 | GET_TLS(); |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 325 | rsc->mFBOCache.setupGL2(rsc); |
Alex Sakhartchouk | feede2a | 2010-10-01 10:54:06 -0700 | [diff] [blame] | 326 | rsc->setupProgramStore(); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 327 | |
| 328 | glClearColor(r, g, b, a); |
| 329 | glClear(GL_COLOR_BUFFER_BIT); |
| 330 | } |
| 331 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 332 | static void SC_ClearDepth(float v) { |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 333 | GET_TLS(); |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 334 | rsc->mFBOCache.setupGL2(rsc); |
Alex Sakhartchouk | feede2a | 2010-10-01 10:54:06 -0700 | [diff] [blame] | 335 | rsc->setupProgramStore(); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 336 | |
| 337 | glClearDepthf(v); |
| 338 | glClear(GL_DEPTH_BUFFER_BIT); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 341 | static uint32_t SC_getWidth() { |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 342 | GET_TLS(); |
| 343 | return rsc->getWidth(); |
| 344 | } |
| 345 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 346 | static uint32_t SC_getHeight() { |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 347 | GET_TLS(); |
| 348 | return rsc->getHeight(); |
| 349 | } |
| 350 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 351 | static void SC_DrawTextAlloc(RsAllocation va, int x, int y) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 352 | CHECK_OBJ(va); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 353 | GET_TLS(); |
| 354 | Allocation *alloc = static_cast<Allocation *>(va); |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 355 | const char *text = (const char *)alloc->getPtr(); |
| 356 | size_t allocSize = alloc->getType()->getSizeBytes(); |
| 357 | rsc->mStateFont.renderText(text, allocSize, x, y); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 360 | static void SC_DrawText(const char *text, int x, int y) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 361 | GET_TLS(); |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 362 | size_t textLen = strlen(text); |
| 363 | rsc->mStateFont.renderText(text, textLen, x, y); |
| 364 | } |
| 365 | |
| 366 | static void SC_setMetrics(Font::Rect *metrics, |
| 367 | int32_t *left, int32_t *right, |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 368 | int32_t *top, int32_t *bottom) { |
| 369 | if (left) { |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 370 | *left = metrics->left; |
| 371 | } |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 372 | if (right) { |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 373 | *right = metrics->right; |
| 374 | } |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 375 | if (top) { |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 376 | *top = metrics->top; |
| 377 | } |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 378 | if (bottom) { |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 379 | *bottom = metrics->bottom; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | static void SC_MeasureTextAlloc(RsAllocation va, |
| 384 | int32_t *left, int32_t *right, |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 385 | int32_t *top, int32_t *bottom) { |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 386 | CHECK_OBJ(va); |
| 387 | GET_TLS(); |
| 388 | Allocation *alloc = static_cast<Allocation *>(va); |
| 389 | const char *text = (const char *)alloc->getPtr(); |
| 390 | size_t textLen = alloc->getType()->getSizeBytes(); |
| 391 | Font::Rect metrics; |
| 392 | rsc->mStateFont.measureText(text, textLen, &metrics); |
| 393 | SC_setMetrics(&metrics, left, right, top, bottom); |
| 394 | } |
| 395 | |
| 396 | static void SC_MeasureText(const char *text, |
| 397 | int32_t *left, int32_t *right, |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 398 | int32_t *top, int32_t *bottom) { |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 399 | GET_TLS(); |
| 400 | size_t textLen = strlen(text); |
| 401 | Font::Rect metrics; |
| 402 | rsc->mStateFont.measureText(text, textLen, &metrics); |
| 403 | SC_setMetrics(&metrics, left, right, top, bottom); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 406 | static void SC_BindFont(RsFont font) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 407 | CHECK_OBJ(font); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 408 | GET_TLS(); |
| 409 | rsi_ContextBindFont(rsc, font); |
| 410 | } |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 411 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 412 | static void SC_FontColor(float r, float g, float b, float a) { |
Alex Sakhartchouk | fb10c16 | 2010-08-04 14:45:48 -0700 | [diff] [blame] | 413 | GET_TLS(); |
| 414 | rsc->mStateFont.setFontColor(r, g, b, a); |
| 415 | } |
| 416 | |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 417 | ////////////////////////////////////////////////////////////////////////////// |
| 418 | // Class implementation |
| 419 | ////////////////////////////////////////////////////////////////////////////// |
| 420 | |
| 421 | // llvm name mangling ref |
| 422 | // <builtin-type> ::= v # void |
| 423 | // ::= b # bool |
| 424 | // ::= c # char |
| 425 | // ::= a # signed char |
| 426 | // ::= h # unsigned char |
| 427 | // ::= s # short |
| 428 | // ::= t # unsigned short |
| 429 | // ::= i # int |
| 430 | // ::= j # unsigned int |
| 431 | // ::= l # long |
| 432 | // ::= m # unsigned long |
| 433 | // ::= x # long long, __int64 |
| 434 | // ::= y # unsigned long long, __int64 |
| 435 | // ::= f # float |
| 436 | // ::= d # double |
| 437 | |
| 438 | static ScriptCState::SymbolTable_t gSyms[] = { |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 439 | { "_Z22rsgBindProgramFragment19rs_program_fragment", (void *)&SC_bindProgramFragment, false }, |
| 440 | { "_Z19rsgBindProgramStore16rs_program_store", (void *)&SC_bindProgramStore, false }, |
| 441 | { "_Z20rsgBindProgramVertex17rs_program_vertex", (void *)&SC_bindProgramVertex, false }, |
| 442 | { "_Z20rsgBindProgramRaster17rs_program_raster", (void *)&SC_bindProgramRaster, false }, |
| 443 | { "_Z14rsgBindSampler19rs_program_fragmentj10rs_sampler", (void *)&SC_bindSampler, false }, |
| 444 | { "_Z14rsgBindTexture19rs_program_fragmentj13rs_allocation", (void *)&SC_bindTexture, false }, |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 445 | |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 446 | { "_Z36rsgProgramVertexLoadProjectionMatrixPK12rs_matrix4x4", (void *)&SC_vpLoadProjectionMatrix, false }, |
| 447 | { "_Z31rsgProgramVertexLoadModelMatrixPK12rs_matrix4x4", (void *)&SC_vpLoadModelMatrix, false }, |
| 448 | { "_Z33rsgProgramVertexLoadTextureMatrixPK12rs_matrix4x4", (void *)&SC_vpLoadTextureMatrix, false }, |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 449 | |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 450 | { "_Z35rsgProgramVertexGetProjectionMatrixP12rs_matrix4x4", (void *)&SC_vpGetProjectionMatrix, false }, |
Alex Sakhartchouk | cbed752 | 2010-08-16 17:40:10 -0700 | [diff] [blame] | 451 | |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 452 | { "_Z31rsgProgramFragmentConstantColor19rs_program_fragmentffff", (void *)&SC_pfConstantColor, false }, |
Jason Sams | 442a647 | 2010-08-04 17:50:20 -0700 | [diff] [blame] | 453 | |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 454 | { "_Z11rsgGetWidthv", (void *)&SC_getWidth, false }, |
| 455 | { "_Z12rsgGetHeightv", (void *)&SC_getHeight, false }, |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 456 | |
Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 457 | { "_Z20rsgAllocationSyncAll13rs_allocation", (void *)&SC_allocationSyncAll, false }, |
| 458 | |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 459 | { "_Z11rsgDrawRectfffff", (void *)&SC_drawRect, false }, |
| 460 | { "_Z11rsgDrawQuadffffffffffff", (void *)&SC_drawQuad, false }, |
| 461 | { "_Z20rsgDrawQuadTexCoordsffffffffffffffffffff", (void *)&SC_drawQuadTexCoords, false }, |
| 462 | { "_Z24rsgDrawSpriteScreenspacefffff", (void *)&SC_drawSpriteScreenspace, false }, |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 463 | |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 464 | { "_Z11rsgDrawMesh7rs_mesh", (void *)&SC_drawMesh, false }, |
| 465 | { "_Z11rsgDrawMesh7rs_meshj", (void *)&SC_drawMeshPrimitive, false }, |
| 466 | { "_Z11rsgDrawMesh7rs_meshjjj", (void *)&SC_drawMeshPrimitiveRange, false }, |
| 467 | { "_Z25rsgMeshComputeBoundingBox7rs_meshPfS0_S0_S0_S0_S0_", (void *)&SC_meshComputeBoundingBox, false }, |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 468 | |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 469 | { "_Z13rsgClearColorffff", (void *)&SC_ClearColor, false }, |
| 470 | { "_Z13rsgClearDepthf", (void *)&SC_ClearDepth, false }, |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 471 | |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 472 | { "_Z11rsgDrawTextPKcii", (void *)&SC_DrawText, false }, |
| 473 | { "_Z11rsgDrawText13rs_allocationii", (void *)&SC_DrawTextAlloc, false }, |
| 474 | { "_Z14rsgMeasureTextPKcPiS1_S1_S1_", (void *)&SC_MeasureText, false }, |
| 475 | { "_Z14rsgMeasureText13rs_allocationPiS0_S0_S0_", (void *)&SC_MeasureTextAlloc, false }, |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 476 | |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 477 | { "_Z11rsgBindFont7rs_font", (void *)&SC_BindFont, false }, |
| 478 | { "_Z12rsgFontColorffff", (void *)&SC_FontColor, false }, |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 479 | |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 480 | { "_Z18rsgBindColorTarget13rs_allocationj", (void *)&SC_bindFrameBufferObjectColorTarget, false }, |
| 481 | { "_Z18rsgBindDepthTarget13rs_allocation", (void *)&SC_bindFrameBufferObjectDepthTarget, false }, |
| 482 | { "_Z19rsgClearColorTargetj", (void *)&SC_clearFrameBufferObjectColorTarget, false }, |
| 483 | { "_Z19rsgClearDepthTargetv", (void *)&SC_clearFrameBufferObjectDepthTarget, false }, |
| 484 | { "_Z24rsgClearAllRenderTargetsv", (void *)&SC_clearFrameBufferObjectTargets, false }, |
| 485 | |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 486 | // misc |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 487 | { "_Z5colorffff", (void *)&SC_color, false }, |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 488 | { "_Z9rsgFinishv", (void *)&SC_finish, false }, |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 489 | |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 490 | { NULL, NULL, false } |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 491 | }; |
| 492 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 493 | const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbolGL(const char *sym) { |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 494 | ScriptCState::SymbolTable_t *syms = gSyms; |
| 495 | |
| 496 | while (syms->mPtr) { |
| 497 | if (!strcmp(syms->mName, sym)) { |
| 498 | return syms; |
| 499 | } |
| 500 | syms++; |
| 501 | } |
| 502 | return NULL; |
| 503 | } |
| 504 | |