| Jason Sams | 110195f | 2009-08-04 18:47:46 -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 | |
| Alex Sakhartchouk | c984dd7 | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 20 | import android.graphics.Matrix; |
| Jason Sams | 110195f | 2009-08-04 18:47:46 -0700 | [diff] [blame] | 21 | import android.util.Config; |
| 22 | import android.util.Log; |
| 23 | |
| 24 | |
| 25 | /** |
| 26 | * @hide |
| 27 | * |
| 28 | **/ |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 29 | public class ProgramVertex extends Program { |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 30 | |
| Jason Sams | 110195f | 2009-08-04 18:47:46 -0700 | [diff] [blame] | 31 | ProgramVertex(int id, RenderScript rs) { |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 32 | super(id, rs); |
| Jason Sams | 110195f | 2009-08-04 18:47:46 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame^] | 35 | public static class Builder extends BaseProgramBuilder { |
| 36 | public Builder(RenderScript rs) { |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 37 | super(rs); |
| Jason Sams | 110195f | 2009-08-04 18:47:46 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame^] | 40 | public Builder addInput(Element e) throws IllegalStateException { |
| 41 | // Should check for consistant and non-conflicting names... |
| 42 | if(mInputCount >= MAX_INPUT) { |
| 43 | throw new RSIllegalArgumentException("Max input count exceeded."); |
| 44 | } |
| 45 | if (e.isComplex()) { |
| 46 | throw new RSIllegalArgumentException("Complex elements not allowed."); |
| 47 | } |
| 48 | mInputs[mInputCount++] = e; |
| 49 | return this; |
| 50 | } |
| 51 | |
| Jason Sams | 110195f | 2009-08-04 18:47:46 -0700 | [diff] [blame] | 52 | public ProgramVertex create() { |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 53 | mRS.validate(); |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 54 | int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2]; |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 55 | int idx = 0; |
| 56 | |
| 57 | for (int i=0; i < mInputCount; i++) { |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 58 | tmp[idx++] = ProgramParam.INPUT.mID; |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 59 | tmp[idx++] = mInputs[i].getID(); |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 60 | } |
| 61 | for (int i=0; i < mOutputCount; i++) { |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 62 | tmp[idx++] = ProgramParam.OUTPUT.mID; |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 63 | tmp[idx++] = mOutputs[i].getID(); |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 64 | } |
| 65 | for (int i=0; i < mConstantCount; i++) { |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 66 | tmp[idx++] = ProgramParam.CONSTANT.mID; |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 67 | tmp[idx++] = mConstants[i].getID(); |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 68 | } |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 69 | for (int i=0; i < mTextureCount; i++) { |
| 70 | tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID; |
| 71 | tmp[idx++] = mTextureTypes[i].mID; |
| 72 | } |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 73 | |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 74 | int id = mRS.nProgramVertexCreate(mShader, tmp); |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 75 | ProgramVertex pv = new ProgramVertex(id, mRS); |
| 76 | initProgram(pv); |
| 77 | return pv; |
| Jason Sams | 110195f | 2009-08-04 18:47:46 -0700 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
| Jason Sams | 110195f | 2009-08-04 18:47:46 -0700 | [diff] [blame] | 81 | } |