Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "rsContext.h" |
| 18 | #include "rsProgramFragment.h" |
| 19 | |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 20 | #include <GLES/gl.h> |
| 21 | #include <GLES/glext.h> |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 22 | #include <GLES2/gl2.h> |
| 23 | #include <GLES2/gl2ext.h> |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 24 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 25 | using namespace android; |
| 26 | using namespace android::renderscript; |
| 27 | |
| 28 | |
Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 29 | ProgramFragment::ProgramFragment(Context *rsc, const uint32_t * params, |
| 30 | uint32_t paramLength) : |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 31 | Program(rsc) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 32 | { |
Jason Sams | 61f08d6 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 33 | mAllocFile = __FILE__; |
| 34 | mAllocLine = __LINE__; |
Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 35 | rsAssert(paramLength = 5); |
| 36 | |
| 37 | mEnvModes[0] = (RsTexEnvMode)params[0]; |
| 38 | mTextureFormats[0] = params[1]; |
| 39 | mEnvModes[1] = (RsTexEnvMode)params[2]; |
| 40 | mTextureFormats[1] = params[3]; |
| 41 | mPointSpriteEnable = params[4] != 0; |
| 42 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 43 | mTextureEnableMask = 0; |
Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 44 | if (mEnvModes[0]) { |
| 45 | mTextureEnableMask |= 1; |
| 46 | } |
| 47 | if (mEnvModes[1]) { |
| 48 | mTextureEnableMask |= 2; |
| 49 | } |
| 50 | init(rsc); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 53 | ProgramFragment::ProgramFragment(Context *rsc, const char * shaderText, |
| 54 | uint32_t shaderLength, const uint32_t * params, |
| 55 | uint32_t paramLength) : |
| 56 | Program(rsc, shaderText, shaderLength, params, paramLength) |
| 57 | { |
| 58 | mAllocFile = __FILE__; |
| 59 | mAllocLine = __LINE__; |
| 60 | |
| 61 | init(rsc); |
| 62 | mTextureEnableMask = (1 << mTextureCount) -1; |
| 63 | } |
| 64 | |
| 65 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 66 | ProgramFragment::~ProgramFragment() |
| 67 | { |
| 68 | } |
| 69 | |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 70 | void ProgramFragment::setupGL(const Context *rsc, ProgramFragmentState *state) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 71 | { |
Jason Sams | 9bee51c | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 72 | if ((state->mLast.get() == this) && !mDirty) { |
| 73 | return; |
| 74 | } |
| 75 | state->mLast.set(this); |
| 76 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 77 | for (uint32_t ct=0; ct < MAX_TEXTURE; ct++) { |
| 78 | glActiveTexture(GL_TEXTURE0 + ct); |
Jason Sams | 4244afa | 2009-07-02 15:09:27 -0700 | [diff] [blame] | 79 | if (!(mTextureEnableMask & (1 << ct)) || !mTextures[ct].get()) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 80 | glDisable(GL_TEXTURE_2D); |
| 81 | continue; |
| 82 | } |
| 83 | |
| 84 | glEnable(GL_TEXTURE_2D); |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 85 | if (rsc->checkVersion1_1()) { |
Romain Guy | 2d496bf | 2009-09-04 17:55:41 -0700 | [diff] [blame] | 86 | if (mPointSpriteEnable) { |
| 87 | glEnable(GL_POINT_SPRITE_OES); |
| 88 | } else { |
| 89 | glDisable(GL_POINT_SPRITE_OES); |
| 90 | } |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 91 | glTexEnvi(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, mPointSpriteEnable); |
| 92 | } |
Jason Sams | 3b7d39b | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 93 | mTextures[ct]->uploadCheck(rsc); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 94 | glBindTexture(GL_TEXTURE_2D, mTextures[ct]->getTextureID()); |
| 95 | |
| 96 | switch(mEnvModes[ct]) { |
Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 97 | case RS_TEX_ENV_MODE_NONE: |
| 98 | rsAssert(0); |
| 99 | break; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 100 | case RS_TEX_ENV_MODE_REPLACE: |
Jason Sams | 4244afa | 2009-07-02 15:09:27 -0700 | [diff] [blame] | 101 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 102 | break; |
| 103 | case RS_TEX_ENV_MODE_MODULATE: |
Jason Sams | 4244afa | 2009-07-02 15:09:27 -0700 | [diff] [blame] | 104 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 105 | break; |
| 106 | case RS_TEX_ENV_MODE_DECAL: |
Jason Sams | 4244afa | 2009-07-02 15:09:27 -0700 | [diff] [blame] | 107 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 108 | break; |
| 109 | } |
| 110 | |
Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 111 | if (mSamplers[ct].get()) { |
Jason Sams | 2978bfc | 2010-02-22 15:37:51 -0800 | [diff] [blame] | 112 | mSamplers[ct]->setupGL(rsc, mTextures[ct]->getType()->getIsNp2()); |
Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 113 | } else { |
Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 114 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 115 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
Jason Sams | 4244afa | 2009-07-02 15:09:27 -0700 | [diff] [blame] | 116 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 117 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 118 | } |
Jason Sams | 4244afa | 2009-07-02 15:09:27 -0700 | [diff] [blame] | 119 | |
| 120 | // Gross hack. |
| 121 | if (ct == 2) { |
| 122 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); |
| 123 | |
| 124 | glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD); |
| 125 | glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS); |
| 126 | glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE); |
| 127 | glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); |
| 128 | glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); |
| 129 | |
| 130 | glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_ADD); |
| 131 | glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS); |
| 132 | glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_TEXTURE); |
| 133 | glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); |
| 134 | glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA); |
| 135 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 136 | } |
| 137 | glActiveTexture(GL_TEXTURE0); |
Jason Sams | 9bee51c | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 138 | mDirty = false; |
Jason Sams | a09a6e1 | 2010-01-06 11:57:52 -0800 | [diff] [blame] | 139 | rsc->checkError("ProgramFragment::setupGL"); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 142 | void ProgramFragment::setupGL2(const Context *rsc, ProgramFragmentState *state, ShaderCache *sc) |
| 143 | { |
Jason Sams | 5dbfe93 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 144 | |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 145 | //LOGE("sgl2 frag1 %x", glGetError()); |
| 146 | if ((state->mLast.get() == this) && !mDirty) { |
| 147 | //return; |
| 148 | } |
| 149 | state->mLast.set(this); |
| 150 | |
Jason Sams | 5dbfe93 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 151 | rsc->checkError("ProgramFragment::setupGL2 start"); |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 152 | for (uint32_t ct=0; ct < MAX_TEXTURE; ct++) { |
| 153 | glActiveTexture(GL_TEXTURE0 + ct); |
| 154 | if (!(mTextureEnableMask & (1 << ct)) || !mTextures[ct].get()) { |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 155 | continue; |
| 156 | } |
| 157 | |
Jason Sams | 3b7d39b | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 158 | mTextures[ct]->uploadCheck(rsc); |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 159 | glBindTexture(GL_TEXTURE_2D, mTextures[ct]->getTextureID()); |
Jason Sams | 5dbfe93 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 160 | rsc->checkError("ProgramFragment::setupGL2 tex bind"); |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 161 | if (mSamplers[ct].get()) { |
Jason Sams | 2978bfc | 2010-02-22 15:37:51 -0800 | [diff] [blame] | 162 | mSamplers[ct]->setupGL(rsc, mTextures[ct]->getType()->getIsNp2()); |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 163 | } else { |
| 164 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 165 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 166 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 167 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
Jason Sams | 5dbfe93 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 168 | rsc->checkError("ProgramFragment::setupGL2 tex env"); |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 171 | glUniform1i(sc->fragUniformSlot(ct), ct); |
Jason Sams | 5dbfe93 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 172 | rsc->checkError("ProgramFragment::setupGL2 uniforms"); |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | glActiveTexture(GL_TEXTURE0); |
| 176 | mDirty = false; |
Jason Sams | a09a6e1 | 2010-01-06 11:57:52 -0800 | [diff] [blame] | 177 | rsc->checkError("ProgramFragment::setupGL2"); |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 178 | } |
| 179 | |
Jason Sams | 5dad8b4 | 2009-12-15 19:10:11 -0800 | [diff] [blame] | 180 | void ProgramFragment::loadShader(Context *rsc) { |
| 181 | Program::loadShader(rsc, GL_FRAGMENT_SHADER); |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | void ProgramFragment::createShader() |
| 185 | { |
| 186 | mShader.setTo("precision mediump float;\n"); |
| 187 | mShader.append("varying vec4 varColor;\n"); |
| 188 | mShader.append("varying vec4 varTex0;\n"); |
| 189 | |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 190 | if (mUserShader.length() > 1) { |
| 191 | for (uint32_t ct=0; ct < mTextureCount; ct++) { |
| 192 | char buf[256]; |
| 193 | sprintf(buf, "uniform sampler2D uni_Tex%i;\n", ct); |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 194 | mShader.append(buf); |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 195 | } |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 196 | |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 197 | mShader.append(mUserShader); |
| 198 | } else { |
| 199 | uint32_t mask = mTextureEnableMask; |
| 200 | uint32_t texNum = 0; |
| 201 | while (mask) { |
| 202 | if (mask & 1) { |
| 203 | char buf[64]; |
| 204 | mShader.append("uniform sampler2D uni_Tex"); |
| 205 | sprintf(buf, "%i", texNum); |
| 206 | mShader.append(buf); |
| 207 | mShader.append(";\n"); |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 208 | } |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 209 | mask >>= 1; |
| 210 | texNum++; |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 211 | } |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 212 | |
| 213 | |
| 214 | mShader.append("void main() {\n"); |
| 215 | mShader.append(" vec4 col = varColor;\n"); |
| 216 | |
| 217 | if (mTextureEnableMask) { |
| 218 | if (mPointSpriteEnable) { |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 219 | mShader.append(" vec2 t0 = gl_PointCoord;\n"); |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 220 | } else { |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 221 | mShader.append(" vec2 t0 = varTex0.xy;\n"); |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
| 225 | mask = mTextureEnableMask; |
| 226 | texNum = 0; |
| 227 | while (mask) { |
| 228 | if (mask & 1) { |
| 229 | switch(mEnvModes[texNum]) { |
Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 230 | case RS_TEX_ENV_MODE_NONE: |
| 231 | rsAssert(0); |
| 232 | break; |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 233 | case RS_TEX_ENV_MODE_REPLACE: |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 234 | switch(mTextureFormats[texNum]) { |
| 235 | case 1: |
| 236 | mShader.append(" col.a = texture2D(uni_Tex0, t0).a;\n"); |
| 237 | break; |
| 238 | case 2: |
| 239 | mShader.append(" col.rgba = texture2D(uni_Tex0, t0).rgba;\n"); |
| 240 | break; |
| 241 | case 3: |
| 242 | mShader.append(" col.rgb = texture2D(uni_Tex0, t0).rgb;\n"); |
| 243 | break; |
| 244 | case 4: |
| 245 | mShader.append(" col.rgba = texture2D(uni_Tex0, t0).rgba;\n"); |
| 246 | break; |
| 247 | } |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 248 | break; |
| 249 | case RS_TEX_ENV_MODE_MODULATE: |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 250 | switch(mTextureFormats[texNum]) { |
| 251 | case 1: |
| 252 | mShader.append(" col.a *= texture2D(uni_Tex0, t0).a;\n"); |
| 253 | break; |
| 254 | case 2: |
| 255 | mShader.append(" col.rgba *= texture2D(uni_Tex0, t0).rgba;\n"); |
| 256 | break; |
| 257 | case 3: |
| 258 | mShader.append(" col.rgb *= texture2D(uni_Tex0, t0).rgb;\n"); |
| 259 | break; |
| 260 | case 4: |
| 261 | mShader.append(" col.rgba *= texture2D(uni_Tex0, t0).rgba;\n"); |
| 262 | break; |
| 263 | } |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 264 | break; |
| 265 | case RS_TEX_ENV_MODE_DECAL: |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 266 | mShader.append(" col = texture2D(uni_Tex0, t0);\n"); |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 267 | break; |
| 268 | } |
| 269 | |
| 270 | } |
| 271 | mask >>= 1; |
| 272 | texNum++; |
| 273 | } |
| 274 | |
| 275 | //mShader.append(" col.a = 1.0;\n"); |
| 276 | //mShader.append(" col.r = 0.5;\n"); |
| 277 | |
| 278 | mShader.append(" gl_FragColor = col;\n"); |
| 279 | mShader.append("}\n"); |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 280 | } |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 281 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 282 | |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 283 | void ProgramFragment::init(Context *rsc) |
| 284 | { |
| 285 | mUniformCount = 2; |
| 286 | mUniformNames[0].setTo("uni_Tex0"); |
| 287 | mUniformNames[1].setTo("uni_Tex1"); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 288 | |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 289 | createShader(); |
| 290 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 291 | |
| 292 | ProgramFragmentState::ProgramFragmentState() |
| 293 | { |
| 294 | mPF = NULL; |
| 295 | } |
| 296 | |
| 297 | ProgramFragmentState::~ProgramFragmentState() |
| 298 | { |
| 299 | delete mPF; |
| 300 | |
| 301 | } |
| 302 | |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 303 | void ProgramFragmentState::init(Context *rsc, int32_t w, int32_t h) |
| 304 | { |
Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 305 | uint32_t tmp[5] = { |
| 306 | RS_TEX_ENV_MODE_NONE, 0, |
| 307 | RS_TEX_ENV_MODE_NONE, 0, |
| 308 | 0 |
| 309 | }; |
| 310 | ProgramFragment *pf = new ProgramFragment(rsc, tmp, 5); |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 311 | mDefault.set(pf); |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 312 | pf->init(rsc); |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 313 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 314 | |
Jason Sams | 61f08d6 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 315 | void ProgramFragmentState::deinit(Context *rsc) |
| 316 | { |
| 317 | mDefault.clear(); |
| 318 | mLast.clear(); |
| 319 | } |
| 320 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 321 | |
| 322 | namespace android { |
| 323 | namespace renderscript { |
| 324 | |
Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 325 | RsProgramFragment rsi_ProgramFragmentCreate(Context *rsc, |
| 326 | const uint32_t * params, |
| 327 | uint32_t paramLength) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 328 | { |
Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 329 | ProgramFragment *pf = new ProgramFragment(rsc, params, paramLength); |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 330 | pf->incUserRef(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 331 | return pf; |
| 332 | } |
| 333 | |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 334 | RsProgramFragment rsi_ProgramFragmentCreate2(Context *rsc, const char * shaderText, |
| 335 | uint32_t shaderLength, const uint32_t * params, |
| 336 | uint32_t paramLength) |
| 337 | { |
| 338 | ProgramFragment *pf = new ProgramFragment(rsc, shaderText, shaderLength, params, paramLength); |
| 339 | pf->incUserRef(); |
| 340 | return pf; |
| 341 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 342 | |
| 343 | } |
| 344 | } |
| 345 | |