ProgramFragment.java revision a90842283e322b1210e2bea5850b05177e3d87af
122534176fb5c1257130ef4ee589739ca42766a32Jason Sams/* 222534176fb5c1257130ef4ee589739ca42766a32Jason Sams * Copyright (C) 2008 The Android Open Source Project 322534176fb5c1257130ef4ee589739ca42766a32Jason Sams * 422534176fb5c1257130ef4ee589739ca42766a32Jason Sams * Licensed under the Apache License, Version 2.0 (the "License"); 522534176fb5c1257130ef4ee589739ca42766a32Jason Sams * you may not use this file except in compliance with the License. 622534176fb5c1257130ef4ee589739ca42766a32Jason Sams * You may obtain a copy of the License at 722534176fb5c1257130ef4ee589739ca42766a32Jason Sams * 822534176fb5c1257130ef4ee589739ca42766a32Jason Sams * http://www.apache.org/licenses/LICENSE-2.0 922534176fb5c1257130ef4ee589739ca42766a32Jason Sams * 1022534176fb5c1257130ef4ee589739ca42766a32Jason Sams * Unless required by applicable law or agreed to in writing, software 1122534176fb5c1257130ef4ee589739ca42766a32Jason Sams * distributed under the License is distributed on an "AS IS" BASIS, 1222534176fb5c1257130ef4ee589739ca42766a32Jason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1322534176fb5c1257130ef4ee589739ca42766a32Jason Sams * See the License for the specific language governing permissions and 1422534176fb5c1257130ef4ee589739ca42766a32Jason Sams * limitations under the License. 1522534176fb5c1257130ef4ee589739ca42766a32Jason Sams */ 1622534176fb5c1257130ef4ee589739ca42766a32Jason Sams 1722534176fb5c1257130ef4ee589739ca42766a32Jason Samspackage android.renderscript; 1822534176fb5c1257130ef4ee589739ca42766a32Jason Sams 1922534176fb5c1257130ef4ee589739ca42766a32Jason Sams 2022534176fb5c1257130ef4ee589739ca42766a32Jason Samsimport android.util.Log; 2122534176fb5c1257130ef4ee589739ca42766a32Jason Sams 2222534176fb5c1257130ef4ee589739ca42766a32Jason Sams 239c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines/** 24a90842283e322b1210e2bea5850b05177e3d87afTim Murray * @hide 25d4ca9910982853e50429ea9233f2150ca619b3d8Jason Sams * @deprecated in API 16 2611518acc8c416023d8c2192b441a1767205676d9Robert Ly * <p>The Renderscript fragment program, also known as fragment shader is responsible 2711518acc8c416023d8c2192b441a1767205676d9Robert Ly * for manipulating pixel data in a user defined way. It's constructed from a GLSL 2811518acc8c416023d8c2192b441a1767205676d9Robert Ly * shader string containing the program body, textures inputs, and a Type object 2911518acc8c416023d8c2192b441a1767205676d9Robert Ly * that describes the constants used by the program. Similar to the vertex programs, 3011518acc8c416023d8c2192b441a1767205676d9Robert Ly * when an allocation with constant input values is bound to the shader, its values 3111518acc8c416023d8c2192b441a1767205676d9Robert Ly * are sent to the graphics program automatically.</p> 3211518acc8c416023d8c2192b441a1767205676d9Robert Ly * <p> The values inside the allocation are not explicitly tracked. If they change between two draw 3311518acc8c416023d8c2192b441a1767205676d9Robert Ly * calls using the same program object, the runtime needs to be notified of that 3411518acc8c416023d8c2192b441a1767205676d9Robert Ly * change by calling rsgAllocationSyncAll so it could send the new values to hardware. 3511518acc8c416023d8c2192b441a1767205676d9Robert Ly * Communication between the vertex and fragment programs is handled internally in the 3611518acc8c416023d8c2192b441a1767205676d9Robert Ly * GLSL code. For example, if the fragment program is expecting a varying input called 3711518acc8c416023d8c2192b441a1767205676d9Robert Ly * varTex0, the GLSL code inside the program vertex must provide it. 3811518acc8c416023d8c2192b441a1767205676d9Robert Ly * </p> 3922534176fb5c1257130ef4ee589739ca42766a32Jason Sams * 4022534176fb5c1257130ef4ee589739ca42766a32Jason Sams **/ 417e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Samspublic class ProgramFragment extends Program { 4222534176fb5c1257130ef4ee589739ca42766a32Jason Sams ProgramFragment(int id, RenderScript rs) { 437e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams super(id, rs); 4422534176fb5c1257130ef4ee589739ca42766a32Jason Sams } 4522534176fb5c1257130ef4ee589739ca42766a32Jason Sams 46d4ca9910982853e50429ea9233f2150ca619b3d8Jason Sams /** 47d4ca9910982853e50429ea9233f2150ca619b3d8Jason Sams * @deprecated in API 16 48d4ca9910982853e50429ea9233f2150ca619b3d8Jason Sams */ 49b4d7bb6872f523b4318144202e119766ed9054edAlex Sakhartchouk public static class Builder extends BaseProgramBuilder { 509c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines /** 51d4ca9910982853e50429ea9233f2150ca619b3d8Jason Sams * @deprecated in API 16 52df27202debdc2573b7882405010fba31ee4d46e6Alex Sakhartchouk * Create a builder object. 53df27202debdc2573b7882405010fba31ee4d46e6Alex Sakhartchouk * 54f5c876e82d7cc647ba94d29eb914e64b7977c303Alex Sakhartchouk * @param rs Context to which the program will belong. 55df27202debdc2573b7882405010fba31ee4d46e6Alex Sakhartchouk */ 56b4d7bb6872f523b4318144202e119766ed9054edAlex Sakhartchouk public Builder(RenderScript rs) { 577e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams super(rs); 587e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams } 597e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams 609c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines /** 61d4ca9910982853e50429ea9233f2150ca619b3d8Jason Sams * @deprecated in API 16 62df27202debdc2573b7882405010fba31ee4d46e6Alex Sakhartchouk * Creates ProgramFragment from the current state of the builder 63df27202debdc2573b7882405010fba31ee4d46e6Alex Sakhartchouk * 64df27202debdc2573b7882405010fba31ee4d46e6Alex Sakhartchouk * @return ProgramFragment 65df27202debdc2573b7882405010fba31ee4d46e6Alex Sakhartchouk */ 667e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams public ProgramFragment create() { 677e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams mRS.validate(); 6867f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchouk int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2]; 692123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk String[] texNames = new String[mTextureCount]; 707e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams int idx = 0; 717e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams 727e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams for (int i=0; i < mInputCount; i++) { 7367f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchouk tmp[idx++] = ProgramParam.INPUT.mID; 74e07694b24f7d12d72b084b6651356681ebd0efd6Jason Sams tmp[idx++] = mInputs[i].getID(mRS); 757e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams } 767e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams for (int i=0; i < mOutputCount; i++) { 7767f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchouk tmp[idx++] = ProgramParam.OUTPUT.mID; 78e07694b24f7d12d72b084b6651356681ebd0efd6Jason Sams tmp[idx++] = mOutputs[i].getID(mRS); 797e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams } 807e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams for (int i=0; i < mConstantCount; i++) { 8167f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchouk tmp[idx++] = ProgramParam.CONSTANT.mID; 82e07694b24f7d12d72b084b6651356681ebd0efd6Jason Sams tmp[idx++] = mConstants[i].getID(mRS); 837e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams } 8467f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchouk for (int i=0; i < mTextureCount; i++) { 8567f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchouk tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID; 8667f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchouk tmp[idx++] = mTextureTypes[i].mID; 872123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk texNames[i] = mTextureNames[i]; 8867f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchouk } 897e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams 902123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk int id = mRS.nProgramFragmentCreate(mShader, texNames, tmp); 917e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams ProgramFragment pf = new ProgramFragment(id, mRS); 927e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams initProgram(pf); 937e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams return pf; 947e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams } 957e5ab3b177b10fee304d011b3a4b9ee03e2b18b5Jason Sams } 9622534176fb5c1257130ef4ee589739ca42766a32Jason Sams} 9722534176fb5c1257130ef4ee589739ca42766a32Jason Sams 9822534176fb5c1257130ef4ee589739ca42766a32Jason Sams 9922534176fb5c1257130ef4ee589739ca42766a32Jason Sams 100