blob: 4bb527b5f347bc3e21da990464cb408d22f71421 [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/**
Tim Murraya9084222013-04-05 22:06:43 +000024 * @hide
Jason Samsd4ca9912012-05-08 19:02:07 -070025 * @deprecated in API 16
Tim Murrayc11e25c2013-04-09 11:01:01 -070026 * <p>The RenderScript fragment program, also known as fragment shader is responsible
Robert Ly11518ac2011-02-09 13:57:06 -080027 * for manipulating pixel data in a user defined way. It's constructed from a GLSL
28 * shader string containing the program body, textures inputs, and a Type object
29 * that describes the constants used by the program. Similar to the vertex programs,
30 * when an allocation with constant input values is bound to the shader, its values
31 * are sent to the graphics program automatically.</p>
32 * <p> The values inside the allocation are not explicitly tracked. If they change between two draw
33 * calls using the same program object, the runtime needs to be notified of that
34 * change by calling rsgAllocationSyncAll so it could send the new values to hardware.
35 * Communication between the vertex and fragment programs is handled internally in the
36 * GLSL code. For example, if the fragment program is expecting a varying input called
37 * varTex0, the GLSL code inside the program vertex must provide it.
38 * </p>
Jason Sams22534172009-08-04 16:58:20 -070039 *
40 **/
Jason Sams7e5ab3b2009-12-15 13:27:04 -080041public class ProgramFragment extends Program {
Tim Murray7a629fa2013-11-19 12:45:54 -080042 ProgramFragment(long id, RenderScript rs) {
Jason Sams7e5ab3b2009-12-15 13:27:04 -080043 super(id, rs);
Jason Sams22534172009-08-04 16:58:20 -070044 }
45
Jason Samsd4ca9912012-05-08 19:02:07 -070046 /**
47 * @deprecated in API 16
48 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080049 public static class Builder extends BaseProgramBuilder {
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070050 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070051 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -080052 * Create a builder object.
53 *
Alex Sakhartchoukf5c876e2011-01-13 14:53:43 -080054 * @param rs Context to which the program will belong.
Alex Sakhartchoukdf272022011-01-09 11:34:03 -080055 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080056 public Builder(RenderScript rs) {
Jason Sams7e5ab3b2009-12-15 13:27:04 -080057 super(rs);
58 }
59
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070060 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070061 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -080062 * Creates ProgramFragment from the current state of the builder
63 *
64 * @return ProgramFragment
65 */
Jason Sams7e5ab3b2009-12-15 13:27:04 -080066 public ProgramFragment create() {
67 mRS.validate();
Ashok Bhat98071552014-02-12 09:54:43 +000068 long[] tmp = new long[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2];
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080069 String[] texNames = new String[mTextureCount];
Jason Sams7e5ab3b2009-12-15 13:27:04 -080070 int idx = 0;
71
72 for (int i=0; i < mInputCount; i++) {
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -080073 tmp[idx++] = ProgramParam.INPUT.mID;
Ashok Bhat98071552014-02-12 09:54:43 +000074 tmp[idx++] = mInputs[i].getID(mRS);
Jason Sams7e5ab3b2009-12-15 13:27:04 -080075 }
76 for (int i=0; i < mOutputCount; i++) {
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -080077 tmp[idx++] = ProgramParam.OUTPUT.mID;
Ashok Bhat98071552014-02-12 09:54:43 +000078 tmp[idx++] = mOutputs[i].getID(mRS);
Jason Sams7e5ab3b2009-12-15 13:27:04 -080079 }
80 for (int i=0; i < mConstantCount; i++) {
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -080081 tmp[idx++] = ProgramParam.CONSTANT.mID;
Ashok Bhat98071552014-02-12 09:54:43 +000082 tmp[idx++] = mConstants[i].getID(mRS);
Jason Sams7e5ab3b2009-12-15 13:27:04 -080083 }
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -080084 for (int i=0; i < mTextureCount; i++) {
85 tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID;
Ashok Bhat98071552014-02-12 09:54:43 +000086 tmp[idx++] = mTextureTypes[i].mID;
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080087 texNames[i] = mTextureNames[i];
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -080088 }
Jason Sams7e5ab3b2009-12-15 13:27:04 -080089
Tim Murray7a629fa2013-11-19 12:45:54 -080090 long id = mRS.nProgramFragmentCreate(mShader, texNames, tmp);
Jason Sams7e5ab3b2009-12-15 13:27:04 -080091 ProgramFragment pf = new ProgramFragment(id, mRS);
92 initProgram(pf);
93 return pf;
94 }
95 }
Jason Sams22534172009-08-04 16:58:20 -070096}
97
98
99