Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | package android.renderscript; |
| 18 | |
| 19 | |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 20 | import android.util.Log; |
| 21 | |
| 22 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 23 | /** |
Tim Murray | a908422 | 2013-04-05 22:06:43 +0000 | [diff] [blame] | 24 | * @hide |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 25 | * @deprecated in API 16 |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 26 | * <p>The RenderScript fragment program, also known as fragment shader is responsible |
Robert Ly | 11518ac | 2011-02-09 13:57:06 -0800 | [diff] [blame] | 27 | * for manipulating pixel data in a user defined way. It's constructed from a GLSL |
| 28 | * shader string containing the program body, textures inputs, and a Type object |
| 29 | * that describes the constants used by the program. Similar to the vertex programs, |
| 30 | * when an allocation with constant input values is bound to the shader, its values |
| 31 | * are sent to the graphics program automatically.</p> |
| 32 | * <p> The values inside the allocation are not explicitly tracked. If they change between two draw |
| 33 | * calls using the same program object, the runtime needs to be notified of that |
| 34 | * change by calling rsgAllocationSyncAll so it could send the new values to hardware. |
| 35 | * Communication between the vertex and fragment programs is handled internally in the |
| 36 | * GLSL code. For example, if the fragment program is expecting a varying input called |
| 37 | * varTex0, the GLSL code inside the program vertex must provide it. |
| 38 | * </p> |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 39 | * |
| 40 | **/ |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 41 | public class ProgramFragment extends Program { |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 42 | ProgramFragment(long id, RenderScript rs) { |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 43 | super(id, rs); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 46 | /** |
| 47 | * @deprecated in API 16 |
| 48 | */ |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 49 | public static class Builder extends BaseProgramBuilder { |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 50 | /** |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 51 | * @deprecated in API 16 |
Alex Sakhartchouk | df27202 | 2011-01-09 11:34:03 -0800 | [diff] [blame] | 52 | * Create a builder object. |
| 53 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 54 | * @param rs Context to which the program will belong. |
Alex Sakhartchouk | df27202 | 2011-01-09 11:34:03 -0800 | [diff] [blame] | 55 | */ |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 56 | public Builder(RenderScript rs) { |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 57 | super(rs); |
| 58 | } |
| 59 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 60 | /** |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 61 | * @deprecated in API 16 |
Alex Sakhartchouk | df27202 | 2011-01-09 11:34:03 -0800 | [diff] [blame] | 62 | * Creates ProgramFragment from the current state of the builder |
| 63 | * |
| 64 | * @return ProgramFragment |
| 65 | */ |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 66 | public ProgramFragment create() { |
| 67 | mRS.validate(); |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 68 | int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2]; |
Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 69 | String[] texNames = new String[mTextureCount]; |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 70 | int idx = 0; |
| 71 | |
| 72 | for (int i=0; i < mInputCount; i++) { |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 73 | tmp[idx++] = ProgramParam.INPUT.mID; |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 74 | tmp[idx++] = (int)mInputs[i].getID(mRS); |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 75 | } |
| 76 | for (int i=0; i < mOutputCount; i++) { |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 77 | tmp[idx++] = ProgramParam.OUTPUT.mID; |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 78 | tmp[idx++] = (int)mOutputs[i].getID(mRS); |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 79 | } |
| 80 | for (int i=0; i < mConstantCount; i++) { |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 81 | tmp[idx++] = ProgramParam.CONSTANT.mID; |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 82 | tmp[idx++] = (int)mConstants[i].getID(mRS); |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 83 | } |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 84 | for (int i=0; i < mTextureCount; i++) { |
| 85 | tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID; |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 86 | tmp[idx++] = (int)mTextureTypes[i].mID; |
Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 87 | texNames[i] = mTextureNames[i]; |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 88 | } |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 89 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 90 | long id = mRS.nProgramFragmentCreate(mShader, texNames, tmp); |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 91 | ProgramFragment pf = new ProgramFragment(id, mRS); |
| 92 | initProgram(pf); |
| 93 | return pf; |
| 94 | } |
| 95 | } |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
| 99 | |