blob: 7f12661ba22d9a99b25eec18934d9576abb26396 [file] [log] [blame]
Jason Sams22534172009-08-04 16:58:20 -07001/*
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/**
Jason Sams22534172009-08-04 16:58:20 -070025 *
26 **/
Jason Sams7e5ab3b2009-12-15 13:27:04 -080027public class ProgramFragment extends Program {
Jason Sams22534172009-08-04 16:58:20 -070028 ProgramFragment(int id, RenderScript rs) {
Jason Sams7e5ab3b2009-12-15 13:27:04 -080029 super(id, rs);
Jason Sams22534172009-08-04 16:58:20 -070030 }
31
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080032 public static class Builder extends BaseProgramBuilder {
33 public Builder(RenderScript rs) {
Jason Sams7e5ab3b2009-12-15 13:27:04 -080034 super(rs);
35 }
36
37 public ProgramFragment create() {
38 mRS.validate();
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -080039 int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2];
Jason Sams7e5ab3b2009-12-15 13:27:04 -080040 int idx = 0;
41
42 for (int i=0; i < mInputCount; i++) {
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -080043 tmp[idx++] = ProgramParam.INPUT.mID;
Jason Sams06d69de2010-11-09 17:11:40 -080044 tmp[idx++] = mInputs[i].getID();
Jason Sams7e5ab3b2009-12-15 13:27:04 -080045 }
46 for (int i=0; i < mOutputCount; i++) {
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -080047 tmp[idx++] = ProgramParam.OUTPUT.mID;
Jason Sams06d69de2010-11-09 17:11:40 -080048 tmp[idx++] = mOutputs[i].getID();
Jason Sams7e5ab3b2009-12-15 13:27:04 -080049 }
50 for (int i=0; i < mConstantCount; i++) {
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -080051 tmp[idx++] = ProgramParam.CONSTANT.mID;
Jason Sams06d69de2010-11-09 17:11:40 -080052 tmp[idx++] = mConstants[i].getID();
Jason Sams7e5ab3b2009-12-15 13:27:04 -080053 }
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -080054 for (int i=0; i < mTextureCount; i++) {
55 tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID;
56 tmp[idx++] = mTextureTypes[i].mID;
57 }
Jason Sams7e5ab3b2009-12-15 13:27:04 -080058
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -070059 int id = mRS.nProgramFragmentCreate(mShader, tmp);
Jason Sams7e5ab3b2009-12-15 13:27:04 -080060 ProgramFragment pf = new ProgramFragment(id, mRS);
61 initProgram(pf);
62 return pf;
63 }
64 }
Jason Sams22534172009-08-04 16:58:20 -070065}
66
67
68