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.Log;
21
22
23/**
24 * @deprecated in API 16
25 * <p>The Renderscript fragment program, also known as fragment shader is responsible
26 * for manipulating pixel data in a user defined way. It's constructed from a GLSL
27 * shader string containing the program body, textures inputs, and a Type object
28 * that describes the constants used by the program. Similar to the vertex programs,
29 * when an allocation with constant input values is bound to the shader, its values
30 * are sent to the graphics program automatically.</p>
31 * <p> The values inside the allocation are not explicitly tracked. If they change between two draw
32 * calls using the same program object, the runtime needs to be notified of that
33 * change by calling rsgAllocationSyncAll so it could send the new values to hardware.
34 * Communication between the vertex and fragment programs is handled internally in the
35 * GLSL code. For example, if the fragment program is expecting a varying input called
36 * varTex0, the GLSL code inside the program vertex must provide it.
37 * </p>
38 *
39 **/
40public class ProgramFragment extends Program {
41    ProgramFragment(int id, RenderScript rs) {
42        super(id, rs);
43    }
44
45    /**
46     * @deprecated in API 16
47     */
48    public static class Builder extends BaseProgramBuilder {
49        /**
50         * @deprecated in API 16
51         * Create a builder object.
52         *
53         * @param rs Context to which the program will belong.
54         */
55        public Builder(RenderScript rs) {
56            super(rs);
57        }
58
59        /**
60         * @deprecated in API 16
61         * Creates ProgramFragment from the current state of the builder
62         *
63         * @return  ProgramFragment
64         */
65        public ProgramFragment create() {
66            mRS.validate();
67            int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2];
68            String[] texNames = new String[mTextureCount];
69            int idx = 0;
70
71            for (int i=0; i < mInputCount; i++) {
72                tmp[idx++] = ProgramParam.INPUT.mID;
73                tmp[idx++] = mInputs[i].getID(mRS);
74            }
75            for (int i=0; i < mOutputCount; i++) {
76                tmp[idx++] = ProgramParam.OUTPUT.mID;
77                tmp[idx++] = mOutputs[i].getID(mRS);
78            }
79            for (int i=0; i < mConstantCount; i++) {
80                tmp[idx++] = ProgramParam.CONSTANT.mID;
81                tmp[idx++] = mConstants[i].getID(mRS);
82            }
83            for (int i=0; i < mTextureCount; i++) {
84                tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID;
85                tmp[idx++] = mTextureTypes[i].mID;
86                texNames[i] = mTextureNames[i];
87            }
88
89            int id = mRS.nProgramFragmentCreate(mShader, texNames, tmp);
90            ProgramFragment pf = new ProgramFragment(id, mRS);
91            initProgram(pf);
92            return pf;
93        }
94    }
95}
96
97
98
99