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