| 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 | |
| 20 | import android.util.Config; |
| 21 | import android.util.Log; |
| 22 | |
| 23 | |
| 24 | /** |
| Alex Sakhartchouk | df27202 | 2011-01-09 11:34:03 -0800 | [diff] [blame] | 25 | * ProgramFragment, also know as a fragment shader, describes a |
| 26 | * stage in the graphics pipeline responsible for manipulating |
| 27 | * pixel data in a user-defined way. |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 28 | * |
| 29 | **/ |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 30 | public class ProgramFragment extends Program { |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 31 | ProgramFragment(int id, RenderScript rs) { |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 32 | super(id, rs); |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 35 | public static class Builder extends BaseProgramBuilder { |
| Alex Sakhartchouk | df27202 | 2011-01-09 11:34:03 -0800 | [diff] [blame] | 36 | /** |
| 37 | * Create a builder object. |
| 38 | * |
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 39 | * @param rs Context to which the program will belong. |
| Alex Sakhartchouk | df27202 | 2011-01-09 11:34:03 -0800 | [diff] [blame] | 40 | */ |
| Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 41 | public Builder(RenderScript rs) { |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 42 | super(rs); |
| 43 | } |
| 44 | |
| Alex Sakhartchouk | df27202 | 2011-01-09 11:34:03 -0800 | [diff] [blame] | 45 | /** |
| 46 | * Creates ProgramFragment from the current state of the builder |
| 47 | * |
| 48 | * @return ProgramFragment |
| 49 | */ |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 50 | public ProgramFragment create() { |
| 51 | mRS.validate(); |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 52 | int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2]; |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 53 | int idx = 0; |
| 54 | |
| 55 | for (int i=0; i < mInputCount; i++) { |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 56 | tmp[idx++] = ProgramParam.INPUT.mID; |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 57 | tmp[idx++] = mInputs[i].getID(); |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 58 | } |
| 59 | for (int i=0; i < mOutputCount; i++) { |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 60 | tmp[idx++] = ProgramParam.OUTPUT.mID; |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 61 | tmp[idx++] = mOutputs[i].getID(); |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 62 | } |
| 63 | for (int i=0; i < mConstantCount; i++) { |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 64 | tmp[idx++] = ProgramParam.CONSTANT.mID; |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 65 | tmp[idx++] = mConstants[i].getID(); |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 66 | } |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 67 | for (int i=0; i < mTextureCount; i++) { |
| 68 | tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID; |
| 69 | tmp[idx++] = mTextureTypes[i].mID; |
| 70 | } |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 71 | |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 72 | int id = mRS.nProgramFragmentCreate(mShader, tmp); |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 73 | ProgramFragment pf = new ProgramFragment(id, mRS); |
| 74 | initProgram(pf); |
| 75 | return pf; |
| 76 | } |
| 77 | } |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | |
| 81 | |