ProgramVertex.java revision f5c876e82d7cc647ba94d29eb914e64b7977c303
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.graphics.Matrix; 21import android.util.Config; 22import android.util.Log; 23 24 25/** 26 * ProgramVertex, also know as a vertex shader, describes a 27 * stage in the graphics pipeline responsible for manipulating 28 * geometric data in a user-defined way. 29 * 30 **/ 31public class ProgramVertex extends Program { 32 33 ProgramVertex(int id, RenderScript rs) { 34 super(id, rs); 35 } 36 37 /** 38 * Builder class for creating ProgramVertex objects. 39 * The builder starts empty and the user must minimally provide 40 * the GLSL shader code, and the varying inputs. Constant, or 41 * uniform parameters to the shader may optionally be provided as 42 * well. 43 * 44 **/ 45 public static class Builder extends BaseProgramBuilder { 46 /** 47 * Create a builder object. 48 * 49 * @param rs Context to which the program will belong. 50 */ 51 public Builder(RenderScript rs) { 52 super(rs); 53 } 54 55 /** 56 * Add varying inputs to the program 57 * 58 * @param e element describing the layout of the varying input 59 * structure 60 * @return self 61 */ 62 public Builder addInput(Element e) throws IllegalStateException { 63 // Should check for consistant and non-conflicting names... 64 if(mInputCount >= MAX_INPUT) { 65 throw new RSIllegalArgumentException("Max input count exceeded."); 66 } 67 if (e.isComplex()) { 68 throw new RSIllegalArgumentException("Complex elements not allowed."); 69 } 70 mInputs[mInputCount++] = e; 71 return this; 72 } 73 74 /** 75 * Creates ProgramVertex from the current state of the builder 76 * 77 * @return ProgramVertex 78 */ 79 public ProgramVertex create() { 80 mRS.validate(); 81 int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2]; 82 int idx = 0; 83 84 for (int i=0; i < mInputCount; i++) { 85 tmp[idx++] = ProgramParam.INPUT.mID; 86 tmp[idx++] = mInputs[i].getID(); 87 } 88 for (int i=0; i < mOutputCount; i++) { 89 tmp[idx++] = ProgramParam.OUTPUT.mID; 90 tmp[idx++] = mOutputs[i].getID(); 91 } 92 for (int i=0; i < mConstantCount; i++) { 93 tmp[idx++] = ProgramParam.CONSTANT.mID; 94 tmp[idx++] = mConstants[i].getID(); 95 } 96 for (int i=0; i < mTextureCount; i++) { 97 tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID; 98 tmp[idx++] = mTextureTypes[i].mID; 99 } 100 101 int id = mRS.nProgramVertexCreate(mShader, tmp); 102 ProgramVertex pv = new ProgramVertex(id, mRS); 103 initProgram(pv); 104 return pv; 105 } 106 } 107 108} 109