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