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