| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [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 | /** |
| 25 | * @hide |
| 26 | * |
| 27 | **/ |
| 28 | public class Program extends BaseObj { |
| 29 | public static final int MAX_INPUT = 8; |
| 30 | public static final int MAX_OUTPUT = 8; |
| 31 | public static final int MAX_CONSTANT = 8; |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame^] | 32 | public static final int MAX_TEXTURE = 8; |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 33 | |
| 34 | Element mInputs[]; |
| 35 | Element mOutputs[]; |
| 36 | Type mConstants[]; |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame^] | 37 | int mTextureCount; |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 38 | String mShader; |
| 39 | |
| 40 | Program(int id, RenderScript rs) { |
| 41 | super(rs); |
| 42 | mID = id; |
| 43 | } |
| 44 | |
| 45 | public void bindConstants(Allocation a, int slot) { |
| 46 | mRS.nProgramBindConstants(mID, slot, a.mID); |
| 47 | } |
| 48 | |
| 49 | public static class BaseProgramBuilder { |
| 50 | RenderScript mRS; |
| 51 | Element mInputs[]; |
| 52 | Element mOutputs[]; |
| 53 | Type mConstants[]; |
| 54 | Type mTextures[]; |
| 55 | int mInputCount; |
| 56 | int mOutputCount; |
| 57 | int mConstantCount; |
| 58 | int mTextureCount; |
| 59 | String mShader; |
| 60 | |
| 61 | |
| 62 | protected BaseProgramBuilder(RenderScript rs) { |
| 63 | mRS = rs; |
| 64 | mInputs = new Element[MAX_INPUT]; |
| 65 | mOutputs = new Element[MAX_OUTPUT]; |
| 66 | mConstants = new Type[MAX_CONSTANT]; |
| 67 | mInputCount = 0; |
| 68 | mOutputCount = 0; |
| 69 | mConstantCount = 0; |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame^] | 70 | mTextureCount = 0; |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | public void setShader(String s) { |
| 74 | mShader = s; |
| 75 | } |
| 76 | |
| 77 | public void addInput(Element e) throws IllegalStateException { |
| 78 | // Should check for consistant and non-conflicting names... |
| 79 | if(mInputCount >= MAX_INPUT) { |
| 80 | throw new IllegalArgumentException("Max input count exceeded."); |
| 81 | } |
| 82 | mInputs[mInputCount++] = e; |
| 83 | } |
| 84 | |
| 85 | public void addOutput(Element e) throws IllegalStateException { |
| 86 | // Should check for consistant and non-conflicting names... |
| 87 | if(mOutputCount >= MAX_OUTPUT) { |
| 88 | throw new IllegalArgumentException("Max output count exceeded."); |
| 89 | } |
| 90 | mOutputs[mOutputCount++] = e; |
| 91 | } |
| 92 | |
| 93 | public void addConstant(Type t) throws IllegalStateException { |
| 94 | // Should check for consistant and non-conflicting names... |
| 95 | if(mConstantCount >= MAX_CONSTANT) { |
| 96 | throw new IllegalArgumentException("Max input count exceeded."); |
| 97 | } |
| 98 | mConstants[mConstantCount++] = t; |
| 99 | } |
| 100 | |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame^] | 101 | public void setTextureCount(int count) throws IllegalArgumentException { |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 102 | // Should check for consistant and non-conflicting names... |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame^] | 103 | if(count >= MAX_CONSTANT) { |
| 104 | throw new IllegalArgumentException("Max texture count exceeded."); |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 105 | } |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame^] | 106 | mTextureCount = count; |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | protected void initProgram(Program p) { |
| 110 | p.mInputs = new Element[mInputCount]; |
| 111 | System.arraycopy(mInputs, 0, p.mInputs, 0, mInputCount); |
| 112 | p.mOutputs = new Element[mOutputCount]; |
| 113 | System.arraycopy(mOutputs, 0, p.mOutputs, 0, mOutputCount); |
| 114 | p.mConstants = new Type[mConstantCount]; |
| 115 | System.arraycopy(mConstants, 0, p.mConstants, 0, mConstantCount); |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame^] | 116 | p.mTextureCount = mTextureCount; |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
| 120 | } |
| 121 | |
| 122 | |