Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 2 | * Copyright (C) 2011 The Android Open Source Project |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -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" |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 18 | #include "rsProgramVertex.h" |
Alex Sakhartchouk | 4edf030 | 2012-03-09 10:47:27 -0800 | [diff] [blame] | 19 | #include "rsMatrix4x4.h" |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 20 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 21 | using namespace android; |
| 22 | using namespace android::renderscript; |
| 23 | |
| 24 | |
Alex Sakhartchouk | 748eb07 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 25 | ProgramVertex::ProgramVertex(Context *rsc, const char * shaderText, size_t shaderLength, |
| 26 | const char** textureNames, size_t textureNamesCount, const size_t *textureNamesLength, |
| 27 | |
Ian Rogers | f8852d0 | 2014-01-29 15:35:17 -0800 | [diff] [blame] | 28 | const uintptr_t * params, size_t paramLength) |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 29 | : Program(rsc, shaderText, shaderLength, params, paramLength) { |
Jason Sams | f313dc3 | 2013-07-09 14:29:39 -0700 | [diff] [blame] | 30 | mRSC->mHal.funcs.vertex.init(mRSC, this, mUserShader, mUserShaderLen, |
Alex Sakhartchouk | 748eb07 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 31 | textureNames, textureNamesCount, textureNamesLength); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 34 | ProgramVertex::~ProgramVertex() { |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 35 | mRSC->mHal.funcs.vertex.destroy(mRSC, this); |
Jason Sams | 56bc1af | 2009-06-16 17:49:58 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Alex Sakhartchouk | c19ff01 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 38 | void ProgramVertex::setup(Context *rsc, ProgramVertexState *state) { |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 39 | if ((state->mLast.get() == this) && !mDirty) { |
Jason Sams | e64c2f1 | 2010-06-22 17:22:13 -0700 | [diff] [blame] | 40 | return; |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 41 | } |
| 42 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 43 | if (!isUserProgram()) { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 44 | if (mHal.state.constants[0] == nullptr) { |
Jason Sams | 87319de | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 45 | rsc->setError(RS_ERROR_FATAL_UNKNOWN, |
| 46 | "Unable to set fixed function emulation matrices because allocation is missing"); |
Alex Sakhartchouk | 0bd3c86 | 2010-09-27 10:29:47 -0700 | [diff] [blame] | 47 | return; |
| 48 | } |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 49 | float *f = static_cast<float *>(rsc->mHal.funcs.allocation.lock1D( |
| 50 | rsc, mHal.state.constants[0])); |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 51 | Matrix4x4 mvp; |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 52 | mvp.load(&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET]); |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 53 | Matrix4x4 t; |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 54 | t.load(&f[RS_PROGRAM_VERTEX_MODELVIEW_OFFSET]); |
| 55 | mvp.multiply(&t); |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 56 | for (uint32_t i = 0; i < 16; i ++) { |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 57 | f[RS_PROGRAM_VERTEX_MVP_OFFSET + i] = mvp.m[i]; |
| 58 | } |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 59 | rsc->mHal.funcs.allocation.unlock1D(rsc, mHal.state.constants[0]); |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | state->mLast.set(this); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 63 | |
| 64 | rsc->mHal.funcs.vertex.setActive(rsc, this); |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 67 | void ProgramVertex::setProjectionMatrix(Context *rsc, const rsc_Matrix *m) const { |
| 68 | if (isUserProgram()) { |
Jason Sams | 87319de | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 69 | rsc->setError(RS_ERROR_FATAL_UNKNOWN, |
| 70 | "Attempting to set fixed function emulation matrix projection on user program"); |
Alex Sakhartchouk | 383e5b1 | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 71 | return; |
| 72 | } |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 73 | if (mHal.state.constants[0] == nullptr) { |
Jason Sams | 87319de | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 74 | rsc->setError(RS_ERROR_FATAL_UNKNOWN, |
| 75 | "Unable to set fixed function emulation matrix projection because allocation is missing"); |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 76 | return; |
| 77 | } |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 78 | float *f = static_cast<float *>(rsc->mHal.funcs.allocation.lock1D( |
| 79 | rsc, mHal.state.constants[0])); |
Jason Sams | c9d43db | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 80 | memcpy(&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET], m, sizeof(rsc_Matrix)); |
Jason Sams | cfb1d11 | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 81 | mDirty = true; |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 82 | rsc->mHal.funcs.allocation.unlock1D(rsc, mHal.state.constants[0]); |
Jason Sams | c9d43db | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 85 | void ProgramVertex::setModelviewMatrix(Context *rsc, const rsc_Matrix *m) const { |
| 86 | if (isUserProgram()) { |
Jason Sams | 87319de | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 87 | rsc->setError(RS_ERROR_FATAL_UNKNOWN, |
| 88 | "Attempting to set fixed function emulation matrix modelview on user program"); |
Alex Sakhartchouk | 383e5b1 | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 89 | return; |
| 90 | } |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 91 | if (mHal.state.constants[0] == nullptr) { |
Jason Sams | 87319de | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 92 | rsc->setError(RS_ERROR_FATAL_UNKNOWN, |
| 93 | "Unable to set fixed function emulation matrix modelview because allocation is missing"); |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 94 | return; |
| 95 | } |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 96 | float *f = static_cast<float *>(rsc->mHal.funcs.allocation.lock1D( |
| 97 | rsc, mHal.state.constants[0])); |
Jason Sams | c9d43db | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 98 | memcpy(&f[RS_PROGRAM_VERTEX_MODELVIEW_OFFSET], m, sizeof(rsc_Matrix)); |
Jason Sams | cfb1d11 | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 99 | mDirty = true; |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 100 | rsc->mHal.funcs.allocation.unlock1D(rsc, mHal.state.constants[0]); |
Jason Sams | c9d43db | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 103 | void ProgramVertex::setTextureMatrix(Context *rsc, const rsc_Matrix *m) const { |
| 104 | if (isUserProgram()) { |
Jason Sams | 87319de | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 105 | rsc->setError(RS_ERROR_FATAL_UNKNOWN, |
| 106 | "Attempting to set fixed function emulation matrix texture on user program"); |
Alex Sakhartchouk | 383e5b1 | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 107 | return; |
| 108 | } |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 109 | if (mHal.state.constants[0] == nullptr) { |
Jason Sams | 87319de | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 110 | rsc->setError(RS_ERROR_FATAL_UNKNOWN, |
| 111 | "Unable to set fixed function emulation matrix texture because allocation is missing"); |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 112 | return; |
| 113 | } |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 114 | float *f = static_cast<float *>(rsc->mHal.funcs.allocation.lock1D( |
| 115 | rsc, mHal.state.constants[0])); |
Jason Sams | c9d43db | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 116 | memcpy(&f[RS_PROGRAM_VERTEX_TEXTURE_OFFSET], m, sizeof(rsc_Matrix)); |
Jason Sams | cfb1d11 | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 117 | mDirty = true; |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 118 | rsc->mHal.funcs.allocation.unlock1D(rsc, mHal.state.constants[0]); |
Jason Sams | c9d43db | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 121 | void ProgramVertex::getProjectionMatrix(Context *rsc, rsc_Matrix *m) const { |
| 122 | if (isUserProgram()) { |
Jason Sams | 87319de | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 123 | rsc->setError(RS_ERROR_FATAL_UNKNOWN, |
| 124 | "Attempting to get fixed function emulation matrix projection on user program"); |
Alex Sakhartchouk | 383e5b1 | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 125 | return; |
| 126 | } |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 127 | if (mHal.state.constants[0] == nullptr) { |
Jason Sams | 87319de | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 128 | rsc->setError(RS_ERROR_FATAL_UNKNOWN, |
| 129 | "Unable to get fixed function emulation matrix projection because allocation is missing"); |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 130 | return; |
| 131 | } |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 132 | float *f = static_cast<float *>( |
| 133 | rsc->mHal.funcs.allocation.lock1D(rsc, mHal.state.constants[0])); |
Alex Sakhartchouk | 95333f9 | 2010-08-16 17:40:10 -0700 | [diff] [blame] | 134 | memcpy(m, &f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET], sizeof(rsc_Matrix)); |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 135 | rsc->mHal.funcs.allocation.unlock1D(rsc, mHal.state.constants[0]); |
Alex Sakhartchouk | 95333f9 | 2010-08-16 17:40:10 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 138 | void ProgramVertex::transformToScreen(Context *rsc, float *v4out, const float *v3in) const { |
| 139 | if (isUserProgram()) { |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 140 | return; |
| 141 | } |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 142 | float *f = static_cast<float *>( |
| 143 | rsc->mHal.funcs.allocation.lock1D(rsc, mHal.state.constants[0])); |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 144 | Matrix4x4 mvp; |
| 145 | mvp.loadMultiply((Matrix4x4 *)&f[RS_PROGRAM_VERTEX_MODELVIEW_OFFSET], |
| 146 | (Matrix4x4 *)&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET]); |
Jason Sams | 3a97c59 | 2009-09-30 17:36:20 -0700 | [diff] [blame] | 147 | mvp.vectorMultiply(v4out, v3in); |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 148 | rsc->mHal.funcs.allocation.unlock1D(rsc, mHal.state.constants[0]); |
Jason Sams | 3a97c59 | 2009-09-30 17:36:20 -0700 | [diff] [blame] | 149 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 150 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 151 | void ProgramVertex::serialize(Context *rsc, OStream *stream) const { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 154 | ProgramVertex *ProgramVertex::createFromStream(Context *rsc, IStream *stream) { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 155 | return nullptr; |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 158 | |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 159 | /////////////////////////////////////////////////////////////////////// |
| 160 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 161 | ProgramVertexState::ProgramVertexState() { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 164 | ProgramVertexState::~ProgramVertexState() { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 167 | void ProgramVertexState::init(Context *rsc) { |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 168 | ObjectBaseRef<const Element> matrixElem = Element::createRef(rsc, RS_TYPE_MATRIX_4X4, |
| 169 | RS_KIND_USER, false, 1); |
| 170 | ObjectBaseRef<const Element> f2Elem = Element::createRef(rsc, RS_TYPE_FLOAT_32, |
| 171 | RS_KIND_USER, false, 2); |
| 172 | ObjectBaseRef<const Element> f3Elem = Element::createRef(rsc, RS_TYPE_FLOAT_32, |
| 173 | RS_KIND_USER, false, 3); |
| 174 | ObjectBaseRef<const Element> f4Elem = Element::createRef(rsc, RS_TYPE_FLOAT_32, |
| 175 | RS_KIND_USER, false, 4); |
Jason Sams | 8287c0c | 2009-09-24 12:33:45 -0700 | [diff] [blame] | 176 | |
Jason Sams | f313dc3 | 2013-07-09 14:29:39 -0700 | [diff] [blame] | 177 | const char *ebn1[] = { "MV", "P", "TexMatrix", "MVP" }; |
| 178 | const Element *ebe1[] = {matrixElem.get(), matrixElem.get(), |
| 179 | matrixElem.get(), matrixElem.get()}; |
| 180 | ObjectBaseRef<const Element> constInput = Element::create(rsc, 4, ebe1, ebn1); |
Jason Sams | 8287c0c | 2009-09-24 12:33:45 -0700 | [diff] [blame] | 181 | |
Jason Sams | f313dc3 | 2013-07-09 14:29:39 -0700 | [diff] [blame] | 182 | const char *ebn2[] = { "position", "color", "normal", "texture0" }; |
| 183 | const Element *ebe2[] = {f4Elem.get(), f4Elem.get(), f3Elem.get(), f2Elem.get()}; |
| 184 | ObjectBaseRef<const Element> attrElem = Element::create(rsc, 4, ebe2, ebn2); |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 185 | |
Jason Sams | c7968a0 | 2014-11-11 16:24:36 -0800 | [diff] [blame] | 186 | ObjectBaseRef<Type> inputType = Type::getTypeRef(rsc, constInput.get(), 1); |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 187 | |
Jason Sams | a7f5e04 | 2013-07-08 16:46:18 -0700 | [diff] [blame] | 188 | const char *shaderString = |
| 189 | RS_SHADER_INTERNAL |
| 190 | "varying vec4 varColor;\n" |
| 191 | "varying vec2 varTex0;\n" |
| 192 | "void main() {\n" |
| 193 | " gl_Position = UNI_MVP * ATTRIB_position;\n" |
| 194 | " gl_PointSize = 1.0;\n" |
| 195 | " varColor = ATTRIB_color;\n" |
| 196 | " varTex0 = ATTRIB_texture0;\n" |
| 197 | "}\n"; |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 198 | |
Ian Rogers | f8852d0 | 2014-01-29 15:35:17 -0800 | [diff] [blame] | 199 | uintptr_t tmp[4]; |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 200 | tmp[0] = RS_PROGRAM_PARAM_CONSTANT; |
Ian Rogers | f8852d0 | 2014-01-29 15:35:17 -0800 | [diff] [blame] | 201 | tmp[1] = (uintptr_t)inputType.get(); |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 202 | tmp[2] = RS_PROGRAM_PARAM_INPUT; |
Ian Rogers | f8852d0 | 2014-01-29 15:35:17 -0800 | [diff] [blame] | 203 | tmp[3] = (uintptr_t)attrElem.get(); |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 204 | |
Jason Sams | a7f5e04 | 2013-07-08 16:46:18 -0700 | [diff] [blame] | 205 | ProgramVertex *pv = new ProgramVertex(rsc, shaderString, strlen(shaderString), |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 206 | nullptr, 0, nullptr, tmp, 4); |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 207 | Allocation *alloc = Allocation::createAllocation(rsc, inputType.get(), |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 208 | RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS); |
Alex Sakhartchouk | 383e5b1 | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 209 | pv->bindAllocation(rsc, alloc, 0); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 210 | |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 211 | mDefaultAlloc.set(alloc); |
| 212 | mDefault.set(pv); |
Jason Sams | cfb1d11 | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 213 | |
Jason Sams | 771565f | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 214 | updateSize(rsc); |
Jason Sams | e18844a | 2009-11-12 16:09:45 -0800 | [diff] [blame] | 215 | } |
| 216 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 217 | void ProgramVertexState::updateSize(Context *rsc) { |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 218 | float *f = static_cast<float *>(rsc->mHal.funcs.allocation.lock1D(rsc, mDefaultAlloc.get())); |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 219 | |
Alex Sakhartchouk | a74a8f6 | 2011-11-16 12:22:10 -0800 | [diff] [blame] | 220 | float surfaceWidth = (float)rsc->getCurrentSurfaceWidth(); |
| 221 | float surfaceHeight = (float)rsc->getCurrentSurfaceHeight(); |
| 222 | |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 223 | Matrix4x4 m; |
Alex Sakhartchouk | a74a8f6 | 2011-11-16 12:22:10 -0800 | [diff] [blame] | 224 | m.loadOrtho(0, surfaceWidth, surfaceHeight, 0, -1, 1); |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 225 | memcpy(&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET], m.m, sizeof(m)); |
| 226 | memcpy(&f[RS_PROGRAM_VERTEX_MVP_OFFSET], m.m, sizeof(m)); |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 227 | |
| 228 | m.loadIdentity(); |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 229 | memcpy(&f[RS_PROGRAM_VERTEX_MODELVIEW_OFFSET], m.m, sizeof(m)); |
| 230 | memcpy(&f[RS_PROGRAM_VERTEX_TEXTURE_OFFSET], m.m, sizeof(m)); |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 231 | rsc->mHal.funcs.allocation.unlock1D(rsc, mDefaultAlloc.get()); |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 232 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 233 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 234 | void ProgramVertexState::deinit(Context *rsc) { |
Jason Sams | f2649a9 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 235 | mDefaultAlloc.clear(); |
| 236 | mDefault.clear(); |
Jason Sams | f2649a9 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 237 | mLast.clear(); |
Jason Sams | f2649a9 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 240 | |
| 241 | namespace android { |
| 242 | namespace renderscript { |
| 243 | |
Alex Sakhartchouk | 748eb07 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 244 | RsProgramVertex rsi_ProgramVertexCreate(Context *rsc, const char * shaderText, size_t shaderLength, |
| 245 | const char** textureNames, size_t textureNamesCount, |
| 246 | const size_t *textureNamesLength, |
Ian Rogers | f8852d0 | 2014-01-29 15:35:17 -0800 | [diff] [blame] | 247 | const uintptr_t * params, size_t paramLength) { |
Alex Sakhartchouk | 748eb07 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 248 | ProgramVertex *pv = new ProgramVertex(rsc, shaderText, shaderLength, |
| 249 | textureNames, textureNamesCount, textureNamesLength, |
| 250 | params, paramLength); |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 251 | pv->incUserRef(); |
| 252 | return pv; |
Jason Sams | b5909ce | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 253 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 254 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 255 | } |
| 256 | } |