Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 1 | /* |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 2 | * Copyright (C) 2011 The Android Open Source Project |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 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" |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 19 | #include "rsMatrix4x4.h" |
| 20 | #include "rsMatrix3x3.h" |
| 21 | #include "rsMatrix2x2.h" |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 22 | |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 23 | #include "utils/Timers.h" |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 24 | #include "driver/rsdVertexArray.h" |
| 25 | #include "driver/rsdShaderCache.h" |
| 26 | #include "driver/rsdCore.h" |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 27 | |
| 28 | #define GL_GLEXT_PROTOTYPES |
| 29 | |
| 30 | #include <GLES/gl.h> |
| 31 | #include <GLES/glext.h> |
| 32 | #include <GLES2/gl2.h> |
| 33 | #include <GLES2/gl2ext.h> |
| 34 | |
| 35 | #include <time.h> |
| 36 | |
| 37 | using namespace android; |
| 38 | using namespace android::renderscript; |
| 39 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 40 | namespace android { |
| 41 | namespace renderscript { |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 42 | |
| 43 | ////////////////////////////////////////////////////////////////////////////// |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 44 | // Context |
| 45 | ////////////////////////////////////////////////////////////////////////////// |
| 46 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 47 | void rsrBindTexture(Context *rsc, Script *sc, ProgramFragment *pf, uint32_t slot, Allocation *a) { |
| 48 | CHECK_OBJ_OR_NULL(a); |
| 49 | CHECK_OBJ(pf); |
| 50 | pf->bindTexture(rsc, slot, a); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 53 | void rsrBindSampler(Context *rsc, Script *sc, ProgramFragment *pf, uint32_t slot, Sampler *s) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 54 | CHECK_OBJ_OR_NULL(vs); |
| 55 | CHECK_OBJ(vpf); |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 56 | pf->bindSampler(rsc, slot, s); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 59 | void rsrBindProgramStore(Context *rsc, Script *sc, ProgramStore *ps) { |
| 60 | CHECK_OBJ_OR_NULL(ps); |
| 61 | rsc->setProgramStore(ps); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 64 | void rsrBindProgramFragment(Context *rsc, Script *sc, ProgramFragment *pf) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 65 | CHECK_OBJ_OR_NULL(pf); |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 66 | rsc->setProgramFragment(pf); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 69 | void rsrBindProgramVertex(Context *rsc, Script *sc, ProgramVertex *pv) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 70 | CHECK_OBJ_OR_NULL(pv); |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 71 | rsc->setProgramVertex(pv); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 74 | void rsrBindProgramRaster(Context *rsc, Script *sc, ProgramRaster *pr) { |
| 75 | CHECK_OBJ_OR_NULL(pr); |
| 76 | rsc->setProgramRaster(pr); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 79 | void rsrBindFrameBufferObjectColorTarget(Context *rsc, Script *sc, Allocation *a, uint32_t slot) { |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 80 | CHECK_OBJ(va); |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 81 | rsc->mFBOCache.bindColorTarget(rsc, a, slot); |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 84 | void rsrBindFrameBufferObjectDepthTarget(Context *rsc, Script *sc, Allocation *a) { |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 85 | CHECK_OBJ(va); |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 86 | rsc->mFBOCache.bindDepthTarget(rsc, a); |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 89 | void rsrClearFrameBufferObjectColorTarget(Context *rsc, Script *sc, uint32_t slot) { |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 90 | rsc->mFBOCache.bindColorTarget(rsc, NULL, slot); |
| 91 | } |
| 92 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 93 | void rsrClearFrameBufferObjectDepthTarget(Context *rsc, Script *sc) { |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 94 | rsc->mFBOCache.bindDepthTarget(rsc, NULL); |
| 95 | } |
| 96 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 97 | void rsrClearFrameBufferObjectTargets(Context *rsc, Script *sc) { |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 98 | rsc->mFBOCache.resetAll(rsc); |
| 99 | } |
| 100 | |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 101 | ////////////////////////////////////////////////////////////////////////////// |
| 102 | // VP |
| 103 | ////////////////////////////////////////////////////////////////////////////// |
| 104 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 105 | void rsrVpLoadProjectionMatrix(Context *rsc, Script *sc, const rsc_Matrix *m) { |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 106 | rsc->getProgramVertex()->setProjectionMatrix(rsc, m); |
Jim Miller | d8e7620 | 2010-07-28 14:46:22 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 109 | void rsrVpLoadModelMatrix(Context *rsc, Script *sc, const rsc_Matrix *m) { |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 110 | rsc->getProgramVertex()->setModelviewMatrix(rsc, m); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 113 | void rsrVpLoadTextureMatrix(Context *rsc, Script *sc, const rsc_Matrix *m) { |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 114 | rsc->getProgramVertex()->setTextureMatrix(rsc, m); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 117 | void rsrPfConstantColor(Context *rsc, Script *sc, ProgramFragment *pf, |
| 118 | float r, float g, float b, float a) { |
| 119 | CHECK_OBJ(pf); |
Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 120 | pf->setConstantColor(rsc, r, g, b, a); |
Jason Sams | 442a647 | 2010-08-04 17:50:20 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 123 | void rsrVpGetProjectionMatrix(Context *rsc, Script *sc, rsc_Matrix *m) { |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 124 | rsc->getProgramVertex()->getProjectionMatrix(rsc, m); |
Alex Sakhartchouk | cbed752 | 2010-08-16 17:40:10 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 127 | ////////////////////////////////////////////////////////////////////////////// |
| 128 | // Drawing |
| 129 | ////////////////////////////////////////////////////////////////////////////// |
| 130 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 131 | void rsrDrawQuadTexCoords(Context *rsc, Script *sc, |
| 132 | float x1, float y1, float z1, float u1, float v1, |
| 133 | float x2, float y2, float z2, float u2, float v2, |
| 134 | float x3, float y3, float z3, float u3, float v3, |
| 135 | float x4, float y4, float z4, float u4, float v4) { |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 136 | if (!rsc->setupCheck()) { |
| 137 | return; |
| 138 | } |
| 139 | |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 140 | RsdHal *dc = (RsdHal *)rsc->mHal.drv; |
| 141 | if (!dc->gl.shaderCache->setup(rsc)) { |
| 142 | return; |
| 143 | } |
| 144 | |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 145 | //LOGE("Quad"); |
| 146 | //LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1); |
| 147 | //LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2); |
| 148 | //LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3); |
| 149 | //LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4); |
| 150 | |
| 151 | float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4}; |
| 152 | const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4}; |
| 153 | |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 154 | RsdVertexArray::Attrib attribs[2]; |
Alex Sakhartchouk | 9d71e21 | 2010-11-08 15:10:52 -0800 | [diff] [blame] | 155 | attribs[0].set(GL_FLOAT, 3, 12, false, (uint32_t)vtx, "ATTRIB_position"); |
| 156 | attribs[1].set(GL_FLOAT, 2, 8, false, (uint32_t)tex, "ATTRIB_texture0"); |
| 157 | |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 158 | RsdVertexArray va(attribs, 2); |
Alex Sakhartchouk | 407cae9 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 159 | va.setup(rsc); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 160 | |
Jason Sams | 5316b9e | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 161 | RSD_CALL_GL(glDrawArrays, GL_TRIANGLE_FAN, 0, 4); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 164 | void rsrDrawQuad(Context *rsc, Script *sc, |
| 165 | float x1, float y1, float z1, |
| 166 | float x2, float y2, float z2, |
| 167 | float x3, float y3, float z3, |
| 168 | float x4, float y4, float z4) { |
| 169 | rsrDrawQuadTexCoords(rsc, sc, x1, y1, z1, 0, 1, |
| 170 | x2, y2, z2, 1, 1, |
| 171 | x3, y3, z3, 1, 0, |
| 172 | x4, y4, z4, 0, 0); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 175 | void rsrDrawSpriteScreenspace(Context *rsc, Script *sc, |
| 176 | float x, float y, float z, float w, float h) { |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 177 | ObjectBaseRef<const ProgramVertex> tmp(rsc->getProgramVertex()); |
| 178 | rsc->setProgramVertex(rsc->getDefaultProgramVertex()); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 179 | //rsc->setupCheck(); |
| 180 | |
| 181 | //GLint crop[4] = {0, h, w, -h}; |
| 182 | |
| 183 | float sh = rsc->getHeight(); |
| 184 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 185 | rsrDrawQuad(rsc, sc, |
| 186 | x, sh - y, z, |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 187 | x+w, sh - y, z, |
| 188 | x+w, sh - (y+h), z, |
| 189 | x, sh - (y+h), z); |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 190 | rsc->setProgramVertex((ProgramVertex *)tmp.get()); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 191 | } |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 192 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 193 | void rsrDrawRect(Context *rsc, Script *sc, float x1, float y1, float x2, float y2, float z) { |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 194 | //LOGE("SC_drawRect %f,%f %f,%f %f", x1, y1, x2, y2, z); |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 195 | rsrDrawQuad(rsc, sc, x1, y2, z, x2, y2, z, x2, y1, z, x1, y1, z); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 198 | void rsrDrawMesh(Context *rsc, Script *sc, Mesh *sm) { |
| 199 | CHECK_OBJ(sm); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 200 | if (!rsc->setupCheck()) { |
| 201 | return; |
| 202 | } |
| 203 | sm->render(rsc); |
| 204 | } |
| 205 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 206 | void rsrDrawMeshPrimitive(Context *rsc, Script *sc, Mesh *sm, uint32_t primIndex) { |
| 207 | CHECK_OBJ(sm); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 208 | if (!rsc->setupCheck()) { |
| 209 | return; |
| 210 | } |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 211 | sm->renderPrimitive(rsc, primIndex); |
| 212 | } |
| 213 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 214 | void rsrDrawMeshPrimitiveRange(Context *rsc, Script *sc, Mesh *sm, uint32_t primIndex, |
| 215 | uint32_t start, uint32_t len) { |
| 216 | CHECK_OBJ(sm); |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 217 | if (!rsc->setupCheck()) { |
| 218 | return; |
| 219 | } |
| 220 | sm->renderPrimitiveRange(rsc, primIndex, start, len); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 223 | void rsrMeshComputeBoundingBox(Context *rsc, Script *sc, Mesh *sm, |
| 224 | float *minX, float *minY, float *minZ, |
| 225 | float *maxX, float *maxY, float *maxZ) { |
| 226 | CHECK_OBJ(sm); |
Alex Sakhartchouk | a80145d | 2010-08-13 14:32:23 -0700 | [diff] [blame] | 227 | sm->computeBBox(); |
| 228 | *minX = sm->mBBoxMin[0]; |
| 229 | *minY = sm->mBBoxMin[1]; |
| 230 | *minZ = sm->mBBoxMin[2]; |
| 231 | *maxX = sm->mBBoxMax[0]; |
| 232 | *maxY = sm->mBBoxMax[1]; |
| 233 | *maxZ = sm->mBBoxMax[2]; |
| 234 | } |
| 235 | |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 236 | |
| 237 | ////////////////////////////////////////////////////////////////////////////// |
| 238 | // |
| 239 | ////////////////////////////////////////////////////////////////////////////// |
| 240 | |
| 241 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 242 | void rsrColor(Context *rsc, Script *sc, float r, float g, float b, float a) { |
| 243 | ProgramFragment *pf = rsc->getProgramFragment(); |
Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 244 | pf->setConstantColor(rsc, r, g, b, a); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 247 | void rsrFinish(Context *rsc, Script *sc) { |
Jason Sams | 5316b9e | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 248 | RSD_CALL_GL(glFinish); |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 251 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 252 | void rsrClearColor(Context *rsc, Script *sc, float r, float g, float b, float a) { |
Alex Sakhartchouk | 407cae9 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 253 | rsc->mFBOCache.setup(rsc); |
Alex Sakhartchouk | feede2a | 2010-10-01 10:54:06 -0700 | [diff] [blame] | 254 | rsc->setupProgramStore(); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 255 | |
Jason Sams | 5316b9e | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 256 | RSD_CALL_GL(glClearColor, r, g, b, a); |
| 257 | RSD_CALL_GL(glClear, GL_COLOR_BUFFER_BIT); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 260 | void rsrClearDepth(Context *rsc, Script *sc, float v) { |
Alex Sakhartchouk | 407cae9 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 261 | rsc->mFBOCache.setup(rsc); |
Alex Sakhartchouk | feede2a | 2010-10-01 10:54:06 -0700 | [diff] [blame] | 262 | rsc->setupProgramStore(); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 263 | |
Jason Sams | 5316b9e | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 264 | RSD_CALL_GL(glClearDepthf, v); |
| 265 | RSD_CALL_GL(glClear, GL_DEPTH_BUFFER_BIT); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 268 | uint32_t rsrGetWidth(Context *rsc, Script *sc) { |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 269 | return rsc->getWidth(); |
| 270 | } |
| 271 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 272 | uint32_t rsrGetHeight(Context *rsc, Script *sc) { |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 273 | return rsc->getHeight(); |
| 274 | } |
| 275 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 276 | void rsrDrawTextAlloc(Context *rsc, Script *sc, Allocation *a, int x, int y) { |
| 277 | const char *text = (const char *)a->getPtr(); |
| 278 | size_t allocSize = a->getType()->getSizeBytes(); |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 279 | rsc->mStateFont.renderText(text, allocSize, x, y); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 282 | void rsrDrawText(Context *rsc, Script *sc, const char *text, int x, int y) { |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 283 | size_t textLen = strlen(text); |
| 284 | rsc->mStateFont.renderText(text, textLen, x, y); |
| 285 | } |
| 286 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 287 | static void SetMetrics(Font::Rect *metrics, |
| 288 | int32_t *left, int32_t *right, int32_t *top, int32_t *bottom) { |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 289 | if (left) { |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 290 | *left = metrics->left; |
| 291 | } |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 292 | if (right) { |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 293 | *right = metrics->right; |
| 294 | } |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 295 | if (top) { |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 296 | *top = metrics->top; |
| 297 | } |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 298 | if (bottom) { |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 299 | *bottom = metrics->bottom; |
| 300 | } |
| 301 | } |
| 302 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 303 | void rsrMeasureTextAlloc(Context *rsc, Script *sc, Allocation *a, |
| 304 | int32_t *left, int32_t *right, int32_t *top, int32_t *bottom) { |
| 305 | CHECK_OBJ(a); |
| 306 | const char *text = (const char *)a->getPtr(); |
| 307 | size_t textLen = a->getType()->getSizeBytes(); |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 308 | Font::Rect metrics; |
| 309 | rsc->mStateFont.measureText(text, textLen, &metrics); |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 310 | SetMetrics(&metrics, left, right, top, bottom); |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 313 | void rsrMeasureText(Context *rsc, Script *sc, const char *text, |
| 314 | int32_t *left, int32_t *right, int32_t *top, int32_t *bottom) { |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 315 | size_t textLen = strlen(text); |
| 316 | Font::Rect metrics; |
| 317 | rsc->mStateFont.measureText(text, textLen, &metrics); |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 318 | SetMetrics(&metrics, left, right, top, bottom); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 321 | void rsrBindFont(Context *rsc, Script *sc, Font *font) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 322 | CHECK_OBJ(font); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 323 | rsi_ContextBindFont(rsc, font); |
| 324 | } |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 325 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 326 | void rsrFontColor(Context *rsc, Script *sc, float r, float g, float b, float a) { |
Alex Sakhartchouk | fb10c16 | 2010-08-04 14:45:48 -0700 | [diff] [blame] | 327 | rsc->mStateFont.setFontColor(r, g, b, a); |
| 328 | } |
| 329 | |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 330 | } |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 331 | } |