blob: 69968ac043880c9374f3b9e629b4ea9e60cf8ff3 [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
Jason Sams22534172009-08-04 16:58:20 -070020import android.util.Log;
21
22
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070023/**
Jason Samsd4ca9912012-05-08 19:02:07 -070024 * @deprecated in API 16
Robert Ly11518ac2011-02-09 13:57:06 -080025 * <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>
Jason Sams22534172009-08-04 16:58:20 -070038 *
39 **/
Jason Sams7e5ab3b2009-12-15 13:27:04 -080040public class ProgramFragment extends Program {
Jason Sams22534172009-08-04 16:58:20 -070041 ProgramFragment(int id, RenderScript rs) {
Jason Sams7e5ab3b2009-12-15 13:27:04 -080042 super(id, rs);
Jason Sams22534172009-08-04 16:58:20 -070043 }
44
Jason Samsd4ca9912012-05-08 19:02:07 -070045 /**
46 * @deprecated in API 16
47 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080048 public static class Builder extends BaseProgramBuilder {
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070049 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070050 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -080051 * Create a builder object.
52 *
Alex Sakhartchoukf5c876e2011-01-13 14:53:43 -080053 * @param rs Context to which the program will belong.
Alex Sakhartchoukdf272022011-01-09 11:34:03 -080054 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080055 public Builder(RenderScript rs) {
Jason Sams7e5ab3b2009-12-15 13:27:04 -080056 super(rs);
57 }
58
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070059 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070060 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -080061 * Creates ProgramFragment from the current state of the builder
62 *
63 * @return ProgramFragment
64 */
Jason Sams7e5ab3b2009-12-15 13:27:04 -080065 public ProgramFragment create() {
66 mRS.validate();
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -080067 int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2];
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080068 String[] texNames = new String[mTextureCount];
Jason Sams7e5ab3b2009-12-15 13:27:04 -080069 int idx = 0;
70
71 for (int i=0; i < mInputCount; i++) {
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -080072 tmp[idx++] = ProgramParam.INPUT.mID;
Jason Samse07694b2012-04-03 15:36:36 -070073 tmp[idx++] = mInputs[i].getID(mRS);
Jason Sams7e5ab3b2009-12-15 13:27:04 -080074 }
75 for (int i=0; i < mOutputCount; i++) {
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -080076 tmp[idx++] = ProgramParam.OUTPUT.mID;
Jason Samse07694b2012-04-03 15:36:36 -070077 tmp[idx++] = mOutputs[i].getID(mRS);
Jason Sams7e5ab3b2009-12-15 13:27:04 -080078 }
79 for (int i=0; i < mConstantCount; i++) {
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -080080 tmp[idx++] = ProgramParam.CONSTANT.mID;
Jason Samse07694b2012-04-03 15:36:36 -070081 tmp[idx++] = mConstants[i].getID(mRS);
Jason Sams7e5ab3b2009-12-15 13:27:04 -080082 }
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -080083 for (int i=0; i < mTextureCount; i++) {
84 tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID;
85 tmp[idx++] = mTextureTypes[i].mID;
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080086 texNames[i] = mTextureNames[i];
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -080087 }
Jason Sams7e5ab3b2009-12-15 13:27:04 -080088
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080089 int id = mRS.nProgramFragmentCreate(mShader, texNames, tmp);
Jason Sams7e5ab3b2009-12-15 13:27:04 -080090 ProgramFragment pf = new ProgramFragment(id, mRS);
91 initProgram(pf);
92 return pf;
93 }
94 }
Jason Sams22534172009-08-04 16:58:20 -070095}
96
97
98