API cleanup for renderscript. This will be a multiproject commit.

Change-Id: Ida62d3a155285a20725be9daa62217faef1c3734
diff --git a/graphics/java/android/renderscript/FieldPacker.java b/graphics/java/android/renderscript/FieldPacker.java
index ed16451..2a585fd 100644
--- a/graphics/java/android/renderscript/FieldPacker.java
+++ b/graphics/java/android/renderscript/FieldPacker.java
@@ -248,27 +248,6 @@
         addU32(v.w);
     }
 
-    // to be removed on cleanup
-    public void addObj(Matrix4f v) {
-        for (int i=0; i < v.mMat.length; i++) {
-            addF32(v.mMat[i]);
-        }
-    }
-
-    // to be removed on cleanup
-    public void addObj(Matrix3f v) {
-        for (int i=0; i < v.mMat.length; i++) {
-            addF32(v.mMat[i]);
-        }
-    }
-
-    // to be removed on cleanup
-    public void addObj(Matrix2f v) {
-        for (int i=0; i < v.mMat.length; i++) {
-            addF32(v.mMat[i]);
-        }
-    }
-
     public void addMatrix(Matrix4f v) {
         for (int i=0; i < v.mMat.length; i++) {
             addF32(v.mMat[i]);
diff --git a/graphics/java/android/renderscript/Matrix2f.java b/graphics/java/android/renderscript/Matrix2f.java
index 4654c48..6ce8379 100644
--- a/graphics/java/android/renderscript/Matrix2f.java
+++ b/graphics/java/android/renderscript/Matrix2f.java
@@ -57,7 +57,7 @@
     }
 
     public void load(Matrix2f src) {
-        System.arraycopy(mMat, 0, src, 0, 4);
+        System.arraycopy(mMat, 0, src.getArray(), 0, 4);
     }
 
     public void loadRotate(float rot) {
diff --git a/graphics/java/android/renderscript/Matrix3f.java b/graphics/java/android/renderscript/Matrix3f.java
index 15e5ce6..b44d8fa 100644
--- a/graphics/java/android/renderscript/Matrix3f.java
+++ b/graphics/java/android/renderscript/Matrix3f.java
@@ -63,7 +63,7 @@
     }
 
     public void load(Matrix3f src) {
-        System.arraycopy(mMat, 0, src, 0, 9);
+        System.arraycopy(mMat, 0, src.getArray(), 0, 9);
     }
 
     public void loadRotate(float rot, float x, float y, float z) {
diff --git a/graphics/java/android/renderscript/Matrix4f.java b/graphics/java/android/renderscript/Matrix4f.java
index ea97509..219d93b 100644
--- a/graphics/java/android/renderscript/Matrix4f.java
+++ b/graphics/java/android/renderscript/Matrix4f.java
@@ -71,7 +71,7 @@
     }
 
     public void load(Matrix4f src) {
-        System.arraycopy(mMat, 0, src, 0, 16);
+        System.arraycopy(mMat, 0, src.getArray(), 0, 16);
     }
 
     public void loadRotate(float rot, float x, float y, float z) {
@@ -180,6 +180,32 @@
         loadFrustum(left, right, bottom, top, near, far);
     }
 
+    public void loadProjectionNormalized(int w, int h) {
+        // range -1,1 in the narrow axis at z = 0.
+        Matrix4f m1 = new Matrix4f();
+        Matrix4f m2 = new Matrix4f();
+
+        if(w > h) {
+            float aspect = ((float)w) / h;
+            m1.loadFrustum(-aspect,aspect,  -1,1,  1,100);
+        } else {
+            float aspect = ((float)h) / w;
+            m1.loadFrustum(-1,1, -aspect,aspect, 1,100);
+        }
+
+        m2.loadRotate(180, 0, 1, 0);
+        m1.loadMultiply(m1, m2);
+
+        m2.loadScale(-2, 2, 1);
+        m1.loadMultiply(m1, m2);
+
+        m2.loadTranslate(0, 0, 2);
+        m1.loadMultiply(m1, m2);
+
+        load(m1);
+    }
+
+
     public void multiply(Matrix4f rhs) {
         Matrix4f tmp = new Matrix4f();
         tmp.loadMultiply(this, rhs);
diff --git a/graphics/java/android/renderscript/Mesh.java b/graphics/java/android/renderscript/Mesh.java
index 950a91a..59e3dd9 100644
--- a/graphics/java/android/renderscript/Mesh.java
+++ b/graphics/java/android/renderscript/Mesh.java
@@ -27,6 +27,20 @@
  **/
 public class Mesh extends BaseObj {
 
+    public enum Primitive {
+        POINT (0),
+        LINE (1),
+        LINE_STRIP (2),
+        TRIANGLE (3),
+        TRIANGLE_STRIP (4),
+        TRIANGLE_FAN (5);
+
+        int mID;
+        Primitive(int id) {
+            mID = id;
+        }
+    }
+
     Allocation[] mVertexBuffers;
     Allocation[] mIndexBuffers;
     Primitive[] mPrimitives;
@@ -51,7 +65,7 @@
         }
         return mIndexBuffers.length;
     }
-    public Allocation getIndexAllocation(int slot) {
+    public Allocation getIndexSetAllocation(int slot) {
         return mIndexBuffers[slot];
     }
     public Primitive getPrimitive(int slot) {
@@ -115,64 +129,67 @@
             mIndexTypes = new Vector();
         }
 
-        public int addVertexType(Type t) throws IllegalStateException {
+        public int getCurrentVertexTypeIndex() {
+            return mVertexTypeCount - 1;
+        }
+
+        public int getCurrentIndexSetIndex() {
+            return mIndexTypes.size() - 1;
+        }
+
+        public Builder addVertexType(Type t) throws IllegalStateException {
             if (mVertexTypeCount >= mVertexTypes.length) {
                 throw new IllegalStateException("Max vertex types exceeded.");
             }
 
-            int addedIndex = mVertexTypeCount;
             mVertexTypes[mVertexTypeCount] = new Entry();
             mVertexTypes[mVertexTypeCount].t = t;
             mVertexTypes[mVertexTypeCount].e = null;
             mVertexTypeCount++;
-            return addedIndex;
+            return this;
         }
 
-        public int addVertexType(Element e, int size) throws IllegalStateException {
+        public Builder addVertexType(Element e, int size) throws IllegalStateException {
             if (mVertexTypeCount >= mVertexTypes.length) {
                 throw new IllegalStateException("Max vertex types exceeded.");
             }
 
-            int addedIndex = mVertexTypeCount;
             mVertexTypes[mVertexTypeCount] = new Entry();
             mVertexTypes[mVertexTypeCount].t = null;
             mVertexTypes[mVertexTypeCount].e = e;
             mVertexTypes[mVertexTypeCount].size = size;
             mVertexTypeCount++;
-            return addedIndex;
+            return this;
         }
 
-        public int addIndexType(Type t, Primitive p) {
-            int addedIndex  = mIndexTypes.size();
+        public Builder addIndexSetType(Type t, Primitive p) {
             Entry indexType = new Entry();
             indexType.t = t;
             indexType.e = null;
             indexType.size = 0;
             indexType.prim = p;
             mIndexTypes.addElement(indexType);
-            return addedIndex;
+            return this;
         }
 
-        public int addIndexType(Primitive p) {
-            int addedIndex  = mIndexTypes.size();
+        public Builder addIndexSetType(Primitive p) {
             Entry indexType = new Entry();
             indexType.t = null;
             indexType.e = null;
             indexType.size = 0;
             indexType.prim = p;
             mIndexTypes.addElement(indexType);
-            return addedIndex;
+            return this;
         }
 
-        public int addIndexType(Element e, int size, Primitive p) {
-            int addedIndex  = mIndexTypes.size();
+        public Builder addIndexSetType(Element e, int size, Primitive p) {
             Entry indexType = new Entry();
             indexType.t = null;
             indexType.e = e;
             indexType.size = size;
             indexType.prim = p;
             mIndexTypes.addElement(indexType);
-            return addedIndex;
+            return this;
         }
 
         Type newType(Element e, int size) {
@@ -247,34 +264,39 @@
             mIndexTypes = new Vector();
         }
 
-        public int addVertexAllocation(Allocation a) throws IllegalStateException {
+        public int getCurrentVertexTypeIndex() {
+            return mVertexTypeCount - 1;
+        }
+
+        public int getCurrentIndexSetIndex() {
+            return mIndexTypes.size() - 1;
+        }
+
+        public AllocationBuilder addVertexAllocation(Allocation a) throws IllegalStateException {
             if (mVertexTypeCount >= mVertexTypes.length) {
                 throw new IllegalStateException("Max vertex types exceeded.");
             }
 
-            int addedIndex = mVertexTypeCount;
             mVertexTypes[mVertexTypeCount] = new Entry();
             mVertexTypes[mVertexTypeCount].a = a;
             mVertexTypeCount++;
-            return addedIndex;
+            return this;
         }
 
-        public int addIndexAllocation(Allocation a, Primitive p) {
-            int addedIndex  = mIndexTypes.size();
+        public AllocationBuilder addIndexSetAllocation(Allocation a, Primitive p) {
             Entry indexType = new Entry();
             indexType.a = a;
             indexType.prim = p;
             mIndexTypes.addElement(indexType);
-            return addedIndex;
+            return this;
         }
 
-        public int addIndexType(Primitive p) {
-            int addedIndex  = mIndexTypes.size();
+        public AllocationBuilder addIndexSetType(Primitive p) {
             Entry indexType = new Entry();
             indexType.a = null;
             indexType.prim = p;
             mIndexTypes.addElement(indexType);
-            return addedIndex;
+            return this;
         }
 
         static synchronized Mesh internalCreate(RenderScript rs, AllocationBuilder b) {
@@ -379,7 +401,7 @@
             }
         }
 
-        public void addVertex(float x, float y) {
+        public TriangleMeshBuilder addVertex(float x, float y) {
             if (mVtxSize != 2) {
                 throw new IllegalStateException("add mistmatch with declared components.");
             }
@@ -387,9 +409,10 @@
             mVtxData[mVtxCount++] = x;
             mVtxData[mVtxCount++] = y;
             latch();
+            return this;
         }
 
-        public void addVertex(float x, float y, float z) {
+        public TriangleMeshBuilder addVertex(float x, float y, float z) {
             if (mVtxSize != 3) {
                 throw new IllegalStateException("add mistmatch with declared components.");
             }
@@ -398,26 +421,29 @@
             mVtxData[mVtxCount++] = y;
             mVtxData[mVtxCount++] = z;
             latch();
+            return this;
         }
 
-        public void setTexture(float s, float t) {
+        public TriangleMeshBuilder setTexture(float s, float t) {
             if ((mFlags & TEXTURE_0) == 0) {
                 throw new IllegalStateException("add mistmatch with declared components.");
             }
             mS0 = s;
             mT0 = t;
+            return this;
         }
 
-        public void setNormal(float x, float y, float z) {
+        public TriangleMeshBuilder setNormal(float x, float y, float z) {
             if ((mFlags & NORMAL) == 0) {
                 throw new IllegalStateException("add mistmatch with declared components.");
             }
             mNX = x;
             mNY = y;
             mNZ = z;
+            return this;
         }
 
-        public void setColor(float r, float g, float b, float a) {
+        public TriangleMeshBuilder setColor(float r, float g, float b, float a) {
             if ((mFlags & COLOR) == 0) {
                 throw new IllegalStateException("add mistmatch with declared components.");
             }
@@ -425,9 +451,10 @@
             mG = g;
             mB = b;
             mA = a;
+            return this;
         }
 
-        public void addTriangle(int idx1, int idx2, int idx3) {
+        public TriangleMeshBuilder addTriangle(int idx1, int idx2, int idx3) {
             if((idx1 >= mVtxCount) || (idx1 < 0) ||
                (idx2 >= mVtxCount) || (idx2 < 0) ||
                (idx3 >= mVtxCount) || (idx3 < 0)) {
@@ -441,6 +468,7 @@
             mIndexData[mIndexCount++] = (short)idx1;
             mIndexData[mIndexCount++] = (short)idx2;
             mIndexData[mIndexCount++] = (short)idx3;
+            return this;
         }
 
         public Mesh create(boolean uploadToBufferObject) {
@@ -470,7 +498,7 @@
 
             Builder smb = new Builder(mRS, usage);
             smb.addVertexType(mElement, mVtxCount / floatCount);
-            smb.addIndexType(Element.U16(mRS), mIndexCount, Primitive.TRIANGLE);
+            smb.addIndexSetType(Element.U16(mRS), mIndexCount, Primitive.TRIANGLE);
 
             Mesh sm = smb.create();
 
@@ -481,9 +509,9 @@
                 }
             }
 
-            sm.getIndexAllocation(0).copyFrom(mIndexData);
+            sm.getIndexSetAllocation(0).copyFrom(mIndexData);
             if (uploadToBufferObject) {
-                sm.getIndexAllocation(0).syncAll(Allocation.USAGE_SCRIPT);
+                sm.getIndexSetAllocation(0).syncAll(Allocation.USAGE_SCRIPT);
             }
 
             return sm;
diff --git a/graphics/java/android/renderscript/Primitive.java b/graphics/java/android/renderscript/Primitive.java
deleted file mode 100644
index 7925cac..0000000
--- a/graphics/java/android/renderscript/Primitive.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.renderscript;
-
-/**
- * @hide
- **/
-public enum Primitive {
-    POINT (0),
-    LINE (1),
-    LINE_STRIP (2),
-    TRIANGLE (3),
-    TRIANGLE_STRIP (4),
-    TRIANGLE_FAN (5);
-
-    int mID;
-    Primitive(int id) {
-        mID = id;
-    }
-}
-
-
-
diff --git a/graphics/java/android/renderscript/Program.java b/graphics/java/android/renderscript/Program.java
index c3536c3..a9eaec3 100644
--- a/graphics/java/android/renderscript/Program.java
+++ b/graphics/java/android/renderscript/Program.java
@@ -177,36 +177,15 @@
             return this;
         }
 
-        public void addInput(Element e) throws IllegalStateException {
-            // Should check for consistant and non-conflicting names...
-            if(mInputCount >= MAX_INPUT) {
-                throw new RSIllegalArgumentException("Max input count exceeded.");
-            }
-            if (e.isComplex()) {
-                throw new RSIllegalArgumentException("Complex elements not allowed.");
-            }
-            mInputs[mInputCount++] = e;
+        public int getCurrentConstantIndex() {
+            return mConstantCount - 1;
         }
 
-        public void addOutput(Element e) throws IllegalStateException {
-            // Should check for consistant and non-conflicting names...
-            if(mOutputCount >= MAX_OUTPUT) {
-                throw new RSIllegalArgumentException("Max output count exceeded.");
-            }
-            if (e.isComplex()) {
-                throw new RSIllegalArgumentException("Complex elements not allowed.");
-            }
-            mOutputs[mOutputCount++] = e;
+        public int getCurrentTextureIndex() {
+            return mTextureCount - 1;
         }
 
-        void resetConstant() {
-            mConstantCount = 0;
-            for(int i = 0; i < MAX_CONSTANT; i ++) {
-                mConstants[i] = null;
-            }
-        }
-
-        public int addConstant(Type t) throws IllegalStateException {
+        public BaseProgramBuilder addConstant(Type t) throws IllegalStateException {
             // Should check for consistant and non-conflicting names...
             if(mConstantCount >= MAX_CONSTANT) {
                 throw new RSIllegalArgumentException("Max input count exceeded.");
@@ -215,18 +194,7 @@
                 throw new RSIllegalArgumentException("Complex elements not allowed.");
             }
             mConstants[mConstantCount] = t;
-            return mConstantCount++;
-        }
-
-        public BaseProgramBuilder setTextureCount(int count) throws IllegalArgumentException {
-            // Should check for consistant and non-conflicting names...
-            if(count >= MAX_TEXTURE) {
-                throw new IllegalArgumentException("Max texture count exceeded.");
-            }
-            mTextureCount = count;
-            for (int i = 0; i < mTextureCount; i ++) {
-                mTextureTypes[i] = TextureType.TEXTURE_2D;
-            }
+            mConstantCount++;
             return this;
         }
 
diff --git a/graphics/java/android/renderscript/ProgramFragment.java b/graphics/java/android/renderscript/ProgramFragment.java
index 074c393..59d4967 100644
--- a/graphics/java/android/renderscript/ProgramFragment.java
+++ b/graphics/java/android/renderscript/ProgramFragment.java
@@ -30,8 +30,8 @@
         super(id, rs);
     }
 
-    public static class ShaderBuilder extends BaseProgramBuilder {
-        public ShaderBuilder(RenderScript rs) {
+    public static class Builder extends BaseProgramBuilder {
+        public Builder(RenderScript rs) {
             super(rs);
         }
 
@@ -63,169 +63,6 @@
             return pf;
         }
     }
-
-    public static class Builder extends ShaderBuilder {
-        public static final int MAX_TEXTURE = 2;
-        int mNumTextures;
-        boolean mPointSpriteEnable;
-        boolean mVaryingColorEnable;
-
-        public enum EnvMode {
-            REPLACE (1),
-            MODULATE (2),
-            DECAL (3);
-
-            int mID;
-            EnvMode(int id) {
-                mID = id;
-            }
-        }
-
-        public enum Format {
-            ALPHA (1),
-            LUMINANCE_ALPHA (2),
-            RGB (3),
-            RGBA (4);
-
-            int mID;
-            Format(int id) {
-                mID = id;
-            }
-        }
-
-        private class Slot {
-            EnvMode env;
-            Format format;
-            Slot(EnvMode _env, Format _fmt) {
-                env = _env;
-                format = _fmt;
-            }
-        }
-        Slot[] mSlots;
-
-        private void buildShaderString() {
-            mShader  = "//rs_shader_internal\n";
-            mShader += "varying lowp vec4 varColor;\n";
-            mShader += "varying vec2 varTex0;\n";
-
-            mShader += "void main() {\n";
-            if (mVaryingColorEnable) {
-                mShader += "  lowp vec4 col = varColor;\n";
-            } else {
-                mShader += "  lowp vec4 col = UNI_Color;\n";
-            }
-
-            if (mNumTextures != 0) {
-                if (mPointSpriteEnable) {
-                    mShader += "  vec2 t0 = gl_PointCoord;\n";
-                } else {
-                    mShader += "  vec2 t0 = varTex0.xy;\n";
-                }
-            }
-
-            for(int i = 0; i < mNumTextures; i ++) {
-                switch(mSlots[i].env) {
-                case REPLACE:
-                    switch (mSlots[i].format) {
-                    case ALPHA:
-                        mShader += "  col.a = texture2D(UNI_Tex0, t0).a;\n";
-                        break;
-                    case LUMINANCE_ALPHA:
-                        mShader += "  col.rgba = texture2D(UNI_Tex0, t0).rgba;\n";
-                        break;
-                    case RGB:
-                        mShader += "  col.rgb = texture2D(UNI_Tex0, t0).rgb;\n";
-                        break;
-                    case RGBA:
-                        mShader += "  col.rgba = texture2D(UNI_Tex0, t0).rgba;\n";
-                        break;
-                    }
-                    break;
-                case MODULATE:
-                    switch (mSlots[i].format) {
-                    case ALPHA:
-                        mShader += "  col.a *= texture2D(UNI_Tex0, t0).a;\n";
-                        break;
-                    case LUMINANCE_ALPHA:
-                        mShader += "  col.rgba *= texture2D(UNI_Tex0, t0).rgba;\n";
-                        break;
-                    case RGB:
-                        mShader += "  col.rgb *= texture2D(UNI_Tex0, t0).rgb;\n";
-                        break;
-                    case RGBA:
-                        mShader += "  col.rgba *= texture2D(UNI_Tex0, t0).rgba;\n";
-                        break;
-                    }
-                    break;
-                case DECAL:
-                    mShader += "  col = texture2D(UNI_Tex0, t0);\n";
-                    break;
-                }
-            }
-
-            mShader += "  gl_FragColor = col;\n";
-            mShader += "}\n";
-        }
-
-        public Builder(RenderScript rs) {
-            super(rs);
-            mRS = rs;
-            mSlots = new Slot[MAX_TEXTURE];
-            mPointSpriteEnable = false;
-        }
-
-        public Builder setTexture(EnvMode env, Format fmt, int slot)
-            throws IllegalArgumentException {
-            if((slot < 0) || (slot >= MAX_TEXTURE)) {
-                throw new IllegalArgumentException("MAX_TEXTURE exceeded.");
-            }
-            mSlots[slot] = new Slot(env, fmt);
-            return this;
-        }
-
-        public Builder setPointSpriteTexCoordinateReplacement(boolean enable) {
-            mPointSpriteEnable = enable;
-            return this;
-        }
-
-        public Builder setVaryingColor(boolean enable) {
-            mVaryingColorEnable = enable;
-            return this;
-        }
-
-        @Override
-        public ProgramFragment create() {
-            mNumTextures = 0;
-            for(int i = 0; i < MAX_TEXTURE; i ++) {
-                if(mSlots[i] != null) {
-                    mNumTextures ++;
-                }
-            }
-            resetConstant();
-            buildShaderString();
-            Type constType = null;
-            if (!mVaryingColorEnable) {
-                Element.Builder b = new Element.Builder(mRS);
-                b.add(Element.F32_4(mRS), "Color");
-                Type.Builder typeBuilder = new Type.Builder(mRS, b.create());
-                typeBuilder.setX(1);
-                constType = typeBuilder.create();
-                addConstant(constType);
-            }
-            setTextureCount(mNumTextures);
-
-            ProgramFragment pf = super.create();
-            pf.mTextureCount = MAX_TEXTURE;
-            if (!mVaryingColorEnable) {
-                Allocation constantData = Allocation.createTyped(mRS,constType);
-                float[] data = new float[4];
-                data[0] = data[1] = data[2] = data[3] = 1.0f;
-                constantData.copyFrom(data);
-                pf.bindConstants(constantData, 0);
-            }
-            return pf;
-        }
-    }
 }
 
 
diff --git a/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java b/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java
new file mode 100644
index 0000000..d011219
--- /dev/null
+++ b/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java
@@ -0,0 +1,237 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript;
+
+
+import android.util.Config;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class ProgramFragmentFixedFunction extends ProgramFragment {
+    ProgramFragmentFixedFunction(int id, RenderScript rs) {
+        super(id, rs);
+    }
+
+    static class InternalBuilder extends BaseProgramBuilder {
+        public InternalBuilder(RenderScript rs) {
+            super(rs);
+        }
+
+        public ProgramFragmentFixedFunction create() {
+            mRS.validate();
+            int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2];
+            int idx = 0;
+
+            for (int i=0; i < mInputCount; i++) {
+                tmp[idx++] = ProgramParam.INPUT.mID;
+                tmp[idx++] = mInputs[i].getID();
+            }
+            for (int i=0; i < mOutputCount; i++) {
+                tmp[idx++] = ProgramParam.OUTPUT.mID;
+                tmp[idx++] = mOutputs[i].getID();
+            }
+            for (int i=0; i < mConstantCount; i++) {
+                tmp[idx++] = ProgramParam.CONSTANT.mID;
+                tmp[idx++] = mConstants[i].getID();
+            }
+            for (int i=0; i < mTextureCount; i++) {
+                tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID;
+                tmp[idx++] = mTextureTypes[i].mID;
+            }
+
+            int id = mRS.nProgramFragmentCreate(mShader, tmp);
+            ProgramFragmentFixedFunction pf = new ProgramFragmentFixedFunction(id, mRS);
+            initProgram(pf);
+            return pf;
+        }
+    }
+
+    public static class Builder {
+        public static final int MAX_TEXTURE = 2;
+        int mNumTextures;
+        boolean mPointSpriteEnable;
+        boolean mVaryingColorEnable;
+        String mShader;
+        RenderScript mRS;
+
+        public enum EnvMode {
+            REPLACE (1),
+            MODULATE (2),
+            DECAL (3);
+
+            int mID;
+            EnvMode(int id) {
+                mID = id;
+            }
+        }
+
+        public enum Format {
+            ALPHA (1),
+            LUMINANCE_ALPHA (2),
+            RGB (3),
+            RGBA (4);
+
+            int mID;
+            Format(int id) {
+                mID = id;
+            }
+        }
+
+        private class Slot {
+            EnvMode env;
+            Format format;
+            Slot(EnvMode _env, Format _fmt) {
+                env = _env;
+                format = _fmt;
+            }
+        }
+        Slot[] mSlots;
+
+        private void buildShaderString() {
+            mShader  = "//rs_shader_internal\n";
+            mShader += "varying lowp vec4 varColor;\n";
+            mShader += "varying vec2 varTex0;\n";
+
+            mShader += "void main() {\n";
+            if (mVaryingColorEnable) {
+                mShader += "  lowp vec4 col = varColor;\n";
+            } else {
+                mShader += "  lowp vec4 col = UNI_Color;\n";
+            }
+
+            if (mNumTextures != 0) {
+                if (mPointSpriteEnable) {
+                    mShader += "  vec2 t0 = gl_PointCoord;\n";
+                } else {
+                    mShader += "  vec2 t0 = varTex0.xy;\n";
+                }
+            }
+
+            for(int i = 0; i < mNumTextures; i ++) {
+                switch(mSlots[i].env) {
+                case REPLACE:
+                    switch (mSlots[i].format) {
+                    case ALPHA:
+                        mShader += "  col.a = texture2D(UNI_Tex0, t0).a;\n";
+                        break;
+                    case LUMINANCE_ALPHA:
+                        mShader += "  col.rgba = texture2D(UNI_Tex0, t0).rgba;\n";
+                        break;
+                    case RGB:
+                        mShader += "  col.rgb = texture2D(UNI_Tex0, t0).rgb;\n";
+                        break;
+                    case RGBA:
+                        mShader += "  col.rgba = texture2D(UNI_Tex0, t0).rgba;\n";
+                        break;
+                    }
+                    break;
+                case MODULATE:
+                    switch (mSlots[i].format) {
+                    case ALPHA:
+                        mShader += "  col.a *= texture2D(UNI_Tex0, t0).a;\n";
+                        break;
+                    case LUMINANCE_ALPHA:
+                        mShader += "  col.rgba *= texture2D(UNI_Tex0, t0).rgba;\n";
+                        break;
+                    case RGB:
+                        mShader += "  col.rgb *= texture2D(UNI_Tex0, t0).rgb;\n";
+                        break;
+                    case RGBA:
+                        mShader += "  col.rgba *= texture2D(UNI_Tex0, t0).rgba;\n";
+                        break;
+                    }
+                    break;
+                case DECAL:
+                    mShader += "  col = texture2D(UNI_Tex0, t0);\n";
+                    break;
+                }
+            }
+
+            mShader += "  gl_FragColor = col;\n";
+            mShader += "}\n";
+        }
+
+        public Builder(RenderScript rs) {
+            mRS = rs;
+            mSlots = new Slot[MAX_TEXTURE];
+            mPointSpriteEnable = false;
+        }
+
+        public Builder setTexture(EnvMode env, Format fmt, int slot)
+            throws IllegalArgumentException {
+            if((slot < 0) || (slot >= MAX_TEXTURE)) {
+                throw new IllegalArgumentException("MAX_TEXTURE exceeded.");
+            }
+            mSlots[slot] = new Slot(env, fmt);
+            return this;
+        }
+
+        public Builder setPointSpriteTexCoordinateReplacement(boolean enable) {
+            mPointSpriteEnable = enable;
+            return this;
+        }
+
+        public Builder setVaryingColor(boolean enable) {
+            mVaryingColorEnable = enable;
+            return this;
+        }
+
+        public ProgramFragmentFixedFunction create() {
+            InternalBuilder sb = new InternalBuilder(mRS);
+            mNumTextures = 0;
+            for(int i = 0; i < MAX_TEXTURE; i ++) {
+                if(mSlots[i] != null) {
+                    mNumTextures ++;
+                }
+            }
+            buildShaderString();
+            sb.setShader(mShader);
+
+            Type constType = null;
+            if (!mVaryingColorEnable) {
+                Element.Builder b = new Element.Builder(mRS);
+                b.add(Element.F32_4(mRS), "Color");
+                Type.Builder typeBuilder = new Type.Builder(mRS, b.create());
+                typeBuilder.setX(1);
+                constType = typeBuilder.create();
+                sb.addConstant(constType);
+            }
+            for (int i = 0; i < mNumTextures; i ++) {
+                sb.addTexture(TextureType.TEXTURE_2D);
+            }
+
+            ProgramFragmentFixedFunction pf = sb.create();
+            pf.mTextureCount = MAX_TEXTURE;
+            if (!mVaryingColorEnable) {
+                Allocation constantData = Allocation.createTyped(mRS,constType);
+                float[] data = new float[4];
+                data[0] = data[1] = data[2] = data[3] = 1.0f;
+                constantData.copyFrom(data);
+                pf.bindConstants(constantData, 0);
+            }
+            return pf;
+        }
+    }
+}
+
+
+
+
diff --git a/graphics/java/android/renderscript/ProgramRaster.java b/graphics/java/android/renderscript/ProgramRaster.java
index 5b55015..3bdd71d 100644
--- a/graphics/java/android/renderscript/ProgramRaster.java
+++ b/graphics/java/android/renderscript/ProgramRaster.java
@@ -109,21 +109,11 @@
             mCullMode = CullMode.BACK;
         }
 
-        public Builder setPointSpriteEnable(boolean enable) {
+        public Builder setPointSpriteEnabled(boolean enable) {
             mPointSprite = enable;
             return this;
         }
 
-        public Builder setPointSmoothEnable(boolean enable) {
-            mPointSmooth = enable;
-            return this;
-        }
-
-        public Builder setLineSmoothEnable(boolean enable) {
-            mLineSmooth = enable;
-            return this;
-        }
-
         public Builder setCullMode(CullMode m) {
             mCullMode = m;
             return this;
diff --git a/graphics/java/android/renderscript/ProgramStore.java b/graphics/java/android/renderscript/ProgramStore.java
index d191b06..2d2b162 100644
--- a/graphics/java/android/renderscript/ProgramStore.java
+++ b/graphics/java/android/renderscript/ProgramStore.java
@@ -26,14 +26,14 @@
  *
  **/
 public class ProgramStore extends BaseObj {
-        public enum DepthFunc {
+    public enum DepthFunc {
         ALWAYS (0),
         LESS (1),
-        LEQUAL (2),
+        LESS_OR_EQUAL (2),
         GREATER (3),
-        GEQUAL (4),
+        GREATER_OR_EQUAL (4),
         EQUAL (5),
-        NOTEQUAL (6);
+        NOT_EQUAL (6);
 
         int mID;
         DepthFunc(int id) {
@@ -84,140 +84,49 @@
             ProgramStore.Builder builder = new ProgramStore.Builder(rs);
             builder.setDepthFunc(ProgramStore.DepthFunc.LESS);
             builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
-            builder.setDitherEnable(false);
-            builder.setDepthMask(true);
+            builder.setDitherEnabled(false);
+            builder.setDepthMaskEnabled(true);
             rs.mProgramStore_BLEND_NONE_DEPTH_TEST = builder.create();
         }
         return rs.mProgramStore_BLEND_NONE_DEPTH_TEST;
     }
-    public static ProgramStore BLEND_NONE_DEPTH_NO_DEPTH(RenderScript rs) {
+    public static ProgramStore BLEND_NONE_DEPTH_NONE(RenderScript rs) {
         if(rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH == null) {
             ProgramStore.Builder builder = new ProgramStore.Builder(rs);
             builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
             builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
-            builder.setDitherEnable(false);
-            builder.setDepthMask(false);
+            builder.setDitherEnabled(false);
+            builder.setDepthMaskEnabled(false);
             rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH = builder.create();
         }
         return rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
     }
-    public static ProgramStore BLEND_NONE_DEPTH_NO_TEST(RenderScript rs) {
-        if(rs.mProgramStore_BLEND_NONE_DEPTH_NO_TEST == null) {
-            ProgramStore.Builder builder = new ProgramStore.Builder(rs);
-            builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
-            builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
-            builder.setDitherEnable(false);
-            builder.setDepthMask(true);
-            rs.mProgramStore_BLEND_NONE_DEPTH_NO_TEST = builder.create();
-        }
-        return rs.mProgramStore_BLEND_NONE_DEPTH_NO_TEST;
-    }
-    public static ProgramStore BLEND_NONE_DEPTH_NO_WRITE(RenderScript rs) {
-        if(rs.mProgramStore_BLEND_NONE_DEPTH_NO_WRITE == null) {
-            ProgramStore.Builder builder = new ProgramStore.Builder(rs);
-            builder.setDepthFunc(ProgramStore.DepthFunc.LESS);
-            builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
-            builder.setDitherEnable(false);
-            builder.setDepthMask(false);
-            rs.mProgramStore_BLEND_NONE_DEPTH_NO_WRITE = builder.create();
-        }
-        return rs.mProgramStore_BLEND_NONE_DEPTH_NO_WRITE;
-    }
 
     public static ProgramStore BLEND_ALPHA_DEPTH_TEST(RenderScript rs) {
         if(rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST == null) {
             ProgramStore.Builder builder = new ProgramStore.Builder(rs);
             builder.setDepthFunc(ProgramStore.DepthFunc.LESS);
             builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
-            builder.setDitherEnable(false);
-            builder.setDepthMask(true);
+            builder.setDitherEnabled(false);
+            builder.setDepthMaskEnabled(true);
             rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST = builder.create();
         }
         return rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST;
     }
-    public static ProgramStore BLEND_ALPHA_DEPTH_NO_DEPTH(RenderScript rs) {
+    public static ProgramStore BLEND_ALPHA_DEPTH_NONE(RenderScript rs) {
         if(rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH == null) {
             ProgramStore.Builder builder = new ProgramStore.Builder(rs);
             builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
             builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
-            builder.setDitherEnable(false);
-            builder.setDepthMask(false);
+            builder.setDitherEnabled(false);
+            builder.setDepthMaskEnabled(false);
             rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH = builder.create();
         }
         return rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
     }
-    public static ProgramStore BLEND_ALPHA_DEPTH_NO_TEST(RenderScript rs) {
-        if(rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_TEST == null) {
-            ProgramStore.Builder builder = new ProgramStore.Builder(rs);
-            builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
-            builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
-            builder.setDitherEnable(false);
-            builder.setDepthMask(true);
-            rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_TEST = builder.create();
-        }
-        return rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_TEST;
-    }
-    public static ProgramStore BLEND_ALPHA_DEPTH_NO_WRITE(RenderScript rs) {
-        if(rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_WRITE == null) {
-            ProgramStore.Builder builder = new ProgramStore.Builder(rs);
-            builder.setDepthFunc(ProgramStore.DepthFunc.LESS);
-            builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
-            builder.setDitherEnable(false);
-            builder.setDepthMask(false);
-            rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_WRITE = builder.create();
-        }
-        return rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_WRITE;
-    }
-
-    public static ProgramStore BLEND_ADD_DEPTH_TEST(RenderScript rs) {
-        if(rs.mProgramStore_BLEND_ADD_DEPTH_TEST == null) {
-            ProgramStore.Builder builder = new ProgramStore.Builder(rs);
-            builder.setDepthFunc(ProgramStore.DepthFunc.LESS);
-            builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE);
-            builder.setDitherEnable(false);
-            builder.setDepthMask(true);
-            rs.mProgramStore_BLEND_ADD_DEPTH_TEST = builder.create();
-        }
-        return rs.mProgramStore_BLEND_ADD_DEPTH_TEST;
-    }
-    public static ProgramStore BLEND_ADD_DEPTH_NO_DEPTH(RenderScript rs) {
-        if(rs.mProgramStore_BLEND_ADD_DEPTH_NO_DEPTH == null) {
-            ProgramStore.Builder builder = new ProgramStore.Builder(rs);
-            builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
-            builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE);
-            builder.setDitherEnable(false);
-            builder.setDepthMask(false);
-            rs.mProgramStore_BLEND_ADD_DEPTH_NO_DEPTH = builder.create();
-        }
-        return rs.mProgramStore_BLEND_ADD_DEPTH_NO_DEPTH;
-    }
-    public static ProgramStore BLEND_ADD_DEPTH_NO_TEST(RenderScript rs) {
-        if(rs.mProgramStore_BLEND_ADD_DEPTH_NO_TEST == null) {
-            ProgramStore.Builder builder = new ProgramStore.Builder(rs);
-            builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
-            builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE);
-            builder.setDitherEnable(false);
-            builder.setDepthMask(true);
-            rs.mProgramStore_BLEND_ADD_DEPTH_NO_DEPTH = builder.create();
-        }
-        return rs.mProgramStore_BLEND_ADD_DEPTH_NO_TEST;
-    }
-    public static ProgramStore BLEND_ADD_DEPTH_NO_WRITE(RenderScript rs) {
-        if(rs.mProgramStore_BLEND_ADD_DEPTH_NO_WRITE == null) {
-            ProgramStore.Builder builder = new ProgramStore.Builder(rs);
-            builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
-            builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE);
-            builder.setDitherEnable(false);
-            builder.setDepthMask(false);
-            rs.mProgramStore_BLEND_ADD_DEPTH_NO_WRITE = builder.create();
-        }
-        return rs.mProgramStore_BLEND_ADD_DEPTH_NO_WRITE;
-    }
 
     public static class Builder {
         RenderScript mRS;
-        Element mIn;
-        Element mOut;
         DepthFunc mDepthFunc;
         boolean mDepthMask;
         boolean mColorMaskR;
@@ -228,26 +137,8 @@
         BlendDstFunc mBlendDst;
         boolean mDither;
 
-
-
-        public Builder(RenderScript rs, Element in, Element out) {
-            mRS = rs;
-            mIn = in;
-            mOut = out;
-            mDepthFunc = DepthFunc.ALWAYS;
-            mDepthMask = false;
-            mColorMaskR = true;
-            mColorMaskG = true;
-            mColorMaskB = true;
-            mColorMaskA = true;
-            mBlendSrc = BlendSrcFunc.ONE;
-            mBlendDst = BlendDstFunc.ZERO;
-        }
-
         public Builder(RenderScript rs) {
             mRS = rs;
-            mIn = null;
-            mOut = null;
             mDepthFunc = DepthFunc.ALWAYS;
             mDepthMask = false;
             mColorMaskR = true;
@@ -263,12 +154,12 @@
             return this;
         }
 
-        public Builder setDepthMask(boolean enable) {
+        public Builder setDepthMaskEnabled(boolean enable) {
             mDepthMask = enable;
             return this;
         }
 
-        public Builder setColorMask(boolean r, boolean g, boolean b, boolean a) {
+        public Builder setColorMaskEnabled(boolean r, boolean g, boolean b, boolean a) {
             mColorMaskR = r;
             mColorMaskG = g;
             mColorMaskB = b;
@@ -282,7 +173,7 @@
             return this;
         }
 
-        public Builder setDitherEnable(boolean enable) {
+        public Builder setDitherEnabled(boolean enable) {
             mDither = enable;
             return this;
         }
diff --git a/graphics/java/android/renderscript/ProgramVertex.java b/graphics/java/android/renderscript/ProgramVertex.java
index 5d41f63..954ac9a 100644
--- a/graphics/java/android/renderscript/ProgramVertex.java
+++ b/graphics/java/android/renderscript/ProgramVertex.java
@@ -27,23 +27,28 @@
  *
  **/
 public class ProgramVertex extends Program {
-    public static final int MAX_LIGHT = 8;
-
 
     ProgramVertex(int id, RenderScript rs) {
         super(id, rs);
     }
 
-    public void bindAllocation(MatrixAllocation va) {
-        mRS.validate();
-        bindConstants(va.mAlloc, 0);
-    }
-
-    public static class ShaderBuilder extends BaseProgramBuilder {
-        public ShaderBuilder(RenderScript rs) {
+    public static class Builder extends BaseProgramBuilder {
+        public Builder(RenderScript rs) {
             super(rs);
         }
 
+        public Builder addInput(Element e) throws IllegalStateException {
+            // Should check for consistant and non-conflicting names...
+            if(mInputCount >= MAX_INPUT) {
+                throw new RSIllegalArgumentException("Max input count exceeded.");
+            }
+            if (e.isComplex()) {
+                throw new RSIllegalArgumentException("Complex elements not allowed.");
+            }
+            mInputs[mInputCount++] = e;
+            return this;
+        }
+
         public ProgramVertex create() {
             mRS.validate();
             int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2];
@@ -73,165 +78,4 @@
         }
     }
 
-    public static class Builder extends ShaderBuilder {
-        boolean mTextureMatrixEnable;
-
-        public Builder(RenderScript rs, Element in, Element out) {
-            super(rs);
-        }
-        public Builder(RenderScript rs) {
-            super(rs);
-        }
-
-        public Builder setTextureMatrixEnable(boolean enable) {
-            mTextureMatrixEnable = enable;
-            return this;
-        }
-        static Type getConstantInputType(RenderScript rs) {
-            Element.Builder b = new Element.Builder(rs);
-            b.add(Element.MATRIX4X4(rs), "MV");
-            b.add(Element.MATRIX4X4(rs), "P");
-            b.add(Element.MATRIX4X4(rs), "TexMatrix");
-            b.add(Element.MATRIX4X4(rs), "MVP");
-
-            Type.Builder typeBuilder = new Type.Builder(rs, b.create());
-            typeBuilder.setX(1);
-            return typeBuilder.create();
-        }
-
-        private void buildShaderString() {
-
-            mShader  = "//rs_shader_internal\n";
-            mShader += "varying vec4 varColor;\n";
-            mShader += "varying vec2 varTex0;\n";
-
-            mShader += "void main() {\n";
-            mShader += "  gl_Position = UNI_MVP * ATTRIB_position;\n";
-            mShader += "  gl_PointSize = 1.0;\n";
-
-            mShader += "  varColor = ATTRIB_color;\n";
-            if (mTextureMatrixEnable) {
-                mShader += "  varTex0 = (UNI_TexMatrix * vec4(ATTRIB_texture0, 0.0, 1.0)).xy;\n";
-            } else {
-                mShader += "  varTex0 = ATTRIB_texture0;\n";
-            }
-            mShader += "}\n";
-        }
-
-        @Override
-        public ProgramVertex create() {
-            buildShaderString();
-
-            addConstant(getConstantInputType(mRS));
-
-            Element.Builder b = new Element.Builder(mRS);
-            b.add(Element.F32_4(mRS), "position");
-            b.add(Element.F32_4(mRS), "color");
-            b.add(Element.F32_3(mRS), "normal");
-            b.add(Element.F32_2(mRS), "texture0");
-            addInput(b.create());
-
-            return super.create();
-        }
-    }
-
-
-
-    public static class MatrixAllocation {
-        static final int MODELVIEW_OFFSET = 0;
-        static final int PROJECTION_OFFSET = 16;
-        static final int TEXTURE_OFFSET = 32;
-
-        Matrix4f mModel;
-        Matrix4f mProjection;
-        Matrix4f mTexture;
-
-        public Allocation mAlloc;
-        private FieldPacker mIOBuffer;
-
-        public MatrixAllocation(RenderScript rs) {
-            Type constInputType = ProgramVertex.Builder.getConstantInputType(rs);
-            mAlloc = Allocation.createTyped(rs, constInputType);
-            int bufferSize = constInputType.getElement().getSizeBytes()*
-                             constInputType.getCount();
-            mIOBuffer = new FieldPacker(bufferSize);
-            loadModelview(new Matrix4f());
-            loadProjection(new Matrix4f());
-            loadTexture(new Matrix4f());
-        }
-
-        public void destroy() {
-            mAlloc.destroy();
-            mAlloc = null;
-        }
-
-        private void addToBuffer(int offset, Matrix4f m) {
-            mIOBuffer.reset(offset);
-            for(int i = 0; i < 16; i ++) {
-                mIOBuffer.addF32(m.mMat[i]);
-            }
-            mAlloc.copyFrom(mIOBuffer.getData());
-        }
-
-        public void loadModelview(Matrix4f m) {
-            mModel = m;
-            addToBuffer(MODELVIEW_OFFSET*4, m);
-        }
-
-        public void loadProjection(Matrix4f m) {
-            mProjection = m;
-            addToBuffer(PROJECTION_OFFSET*4, m);
-        }
-
-        public void loadTexture(Matrix4f m) {
-            mTexture = m;
-            addToBuffer(TEXTURE_OFFSET*4, m);
-        }
-
-        public void setupOrthoWindow(int w, int h) {
-            mProjection.loadOrtho(0,w, h,0, -1,1);
-            addToBuffer(PROJECTION_OFFSET*4, mProjection);
-        }
-
-        public void setupOrthoNormalized(int w, int h) {
-            // range -1,1 in the narrow axis.
-            if(w > h) {
-                float aspect = ((float)w) / h;
-                mProjection.loadOrtho(-aspect,aspect,  -1,1,  -1,1);
-            } else {
-                float aspect = ((float)h) / w;
-                mProjection.loadOrtho(-1,1, -aspect,aspect,  -1,1);
-            }
-            addToBuffer(PROJECTION_OFFSET*4, mProjection);
-        }
-
-        public void setupProjectionNormalized(int w, int h) {
-            // range -1,1 in the narrow axis at z = 0.
-            Matrix4f m1 = new Matrix4f();
-            Matrix4f m2 = new Matrix4f();
-
-            if(w > h) {
-                float aspect = ((float)w) / h;
-                m1.loadFrustum(-aspect,aspect,  -1,1,  1,100);
-            } else {
-                float aspect = ((float)h) / w;
-                m1.loadFrustum(-1,1, -aspect,aspect, 1,100);
-            }
-
-            m2.loadRotate(180, 0, 1, 0);
-            m1.loadMultiply(m1, m2);
-
-            m2.loadScale(-2, 2, 1);
-            m1.loadMultiply(m1, m2);
-
-            m2.loadTranslate(0, 0, 2);
-            m1.loadMultiply(m1, m2);
-
-            mProjection = m1;
-            addToBuffer(PROJECTION_OFFSET*4, mProjection);
-        }
-
-    }
-
 }
-
diff --git a/graphics/java/android/renderscript/ProgramVertexFixedFunction.java b/graphics/java/android/renderscript/ProgramVertexFixedFunction.java
new file mode 100644
index 0000000..2240dd7
--- /dev/null
+++ b/graphics/java/android/renderscript/ProgramVertexFixedFunction.java
@@ -0,0 +1,205 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript;
+
+
+import android.graphics.Matrix;
+import android.util.Config;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class ProgramVertexFixedFunction extends ProgramVertex {
+
+    ProgramVertexFixedFunction(int id, RenderScript rs) {
+        super(id, rs);
+    }
+
+    public void bindConstants(Constants va) {
+        mRS.validate();
+        bindConstants(va.getAllocation(), 0);
+    }
+
+    static class InternalBuilder extends BaseProgramBuilder {
+        public InternalBuilder(RenderScript rs) {
+            super(rs);
+        }
+
+        public InternalBuilder addInput(Element e) throws IllegalStateException {
+            // Should check for consistant and non-conflicting names...
+            if(mInputCount >= MAX_INPUT) {
+                throw new RSIllegalArgumentException("Max input count exceeded.");
+            }
+            if (e.isComplex()) {
+                throw new RSIllegalArgumentException("Complex elements not allowed.");
+            }
+            mInputs[mInputCount++] = e;
+            return this;
+        }
+
+        public ProgramVertexFixedFunction create() {
+            mRS.validate();
+            int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2];
+            int idx = 0;
+
+            for (int i=0; i < mInputCount; i++) {
+                tmp[idx++] = ProgramParam.INPUT.mID;
+                tmp[idx++] = mInputs[i].getID();
+            }
+            for (int i=0; i < mOutputCount; i++) {
+                tmp[idx++] = ProgramParam.OUTPUT.mID;
+                tmp[idx++] = mOutputs[i].getID();
+            }
+            for (int i=0; i < mConstantCount; i++) {
+                tmp[idx++] = ProgramParam.CONSTANT.mID;
+                tmp[idx++] = mConstants[i].getID();
+            }
+            for (int i=0; i < mTextureCount; i++) {
+                tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID;
+                tmp[idx++] = mTextureTypes[i].mID;
+            }
+
+            int id = mRS.nProgramVertexCreate(mShader, tmp);
+            ProgramVertexFixedFunction pv = new ProgramVertexFixedFunction(id, mRS);
+            initProgram(pv);
+            return pv;
+        }
+    }
+
+    public static class Builder {
+        boolean mTextureMatrixEnable;
+        String mShader;
+        RenderScript mRS;
+
+        public Builder(RenderScript rs) {
+            mRS = rs;
+        }
+
+        public Builder setTextureMatrixEnable(boolean enable) {
+            mTextureMatrixEnable = enable;
+            return this;
+        }
+        static Type getConstantInputType(RenderScript rs) {
+            Element.Builder b = new Element.Builder(rs);
+            b.add(Element.MATRIX4X4(rs), "MV");
+            b.add(Element.MATRIX4X4(rs), "P");
+            b.add(Element.MATRIX4X4(rs), "TexMatrix");
+            b.add(Element.MATRIX4X4(rs), "MVP");
+
+            Type.Builder typeBuilder = new Type.Builder(rs, b.create());
+            typeBuilder.setX(1);
+            return typeBuilder.create();
+        }
+
+        private void buildShaderString() {
+
+            mShader  = "//rs_shader_internal\n";
+            mShader += "varying vec4 varColor;\n";
+            mShader += "varying vec2 varTex0;\n";
+
+            mShader += "void main() {\n";
+            mShader += "  gl_Position = UNI_MVP * ATTRIB_position;\n";
+            mShader += "  gl_PointSize = 1.0;\n";
+
+            mShader += "  varColor = ATTRIB_color;\n";
+            if (mTextureMatrixEnable) {
+                mShader += "  varTex0 = (UNI_TexMatrix * vec4(ATTRIB_texture0, 0.0, 1.0)).xy;\n";
+            } else {
+                mShader += "  varTex0 = ATTRIB_texture0;\n";
+            }
+            mShader += "}\n";
+        }
+
+        public ProgramVertexFixedFunction create() {
+            buildShaderString();
+
+            InternalBuilder sb = new InternalBuilder(mRS);
+            sb.setShader(mShader);
+            sb.addConstant(getConstantInputType(mRS));
+
+            Element.Builder b = new Element.Builder(mRS);
+            b.add(Element.F32_4(mRS), "position");
+            b.add(Element.F32_4(mRS), "color");
+            b.add(Element.F32_3(mRS), "normal");
+            b.add(Element.F32_2(mRS), "texture0");
+            sb.addInput(b.create());
+
+            return sb.create();
+        }
+    }
+
+    public static class Constants {
+        static final int MODELVIEW_OFFSET = 0;
+        static final int PROJECTION_OFFSET = 16;
+        static final int TEXTURE_OFFSET = 32;
+
+        Matrix4f mModel;
+        Matrix4f mProjection;
+        Matrix4f mTexture;
+
+        Allocation mAlloc;
+        Allocation getAllocation() {
+            return mAlloc;
+        }
+        private FieldPacker mIOBuffer;
+
+        public Constants(RenderScript rs) {
+            Type constInputType = ProgramVertexFixedFunction.Builder.getConstantInputType(rs);
+            mAlloc = Allocation.createTyped(rs, constInputType);
+            int bufferSize = constInputType.getElement().getSizeBytes()*
+                             constInputType.getCount();
+            mIOBuffer = new FieldPacker(bufferSize);
+            mModel = new Matrix4f();
+            mProjection = new Matrix4f();
+            mTexture = new Matrix4f();
+            setModelview(new Matrix4f());
+            setProjection(new Matrix4f());
+            setTexture(new Matrix4f());
+        }
+
+        public void destroy() {
+            mAlloc.destroy();
+            mAlloc = null;
+        }
+
+        private void addToBuffer(int offset, Matrix4f m) {
+            mIOBuffer.reset(offset);
+            for(int i = 0; i < 16; i ++) {
+                mIOBuffer.addF32(m.mMat[i]);
+            }
+            mAlloc.copyFrom(mIOBuffer.getData());
+        }
+
+        public void setModelview(Matrix4f m) {
+            mModel.load(m);
+            addToBuffer(MODELVIEW_OFFSET*4, m);
+        }
+
+        public void setProjection(Matrix4f m) {
+            mProjection.load(m);
+            addToBuffer(PROJECTION_OFFSET*4, m);
+        }
+
+        public void setTexture(Matrix4f m) {
+            mTexture.load(m);
+            addToBuffer(TEXTURE_OFFSET*4, m);
+        }
+    }
+}
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 16ad55a..2d16e32 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -589,16 +589,8 @@
 
     ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST;
     ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
-    ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_TEST;
-    ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_WRITE;
     ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_TEST;
     ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
-    ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_TEST;
-    ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_WRITE;
-    ProgramStore mProgramStore_BLEND_ADD_DEPTH_TEST;
-    ProgramStore mProgramStore_BLEND_ADD_DEPTH_NO_DEPTH;
-    ProgramStore mProgramStore_BLEND_ADD_DEPTH_NO_TEST;
-    ProgramStore mProgramStore_BLEND_ADD_DEPTH_NO_WRITE;
 
     ProgramRaster mProgramRaster_CULL_BACK;
     ProgramRaster mProgramRaster_CULL_FRONT;
diff --git a/graphics/java/android/renderscript/Sampler.java b/graphics/java/android/renderscript/Sampler.java
index 45a3949..6faa206 100644
--- a/graphics/java/android/renderscript/Sampler.java
+++ b/graphics/java/android/renderscript/Sampler.java
@@ -65,8 +65,8 @@
     public static Sampler CLAMP_NEAREST(RenderScript rs) {
         if(rs.mSampler_CLAMP_NEAREST == null) {
             Builder b = new Builder(rs);
-            b.setMin(Value.NEAREST);
-            b.setMag(Value.NEAREST);
+            b.setMinification(Value.NEAREST);
+            b.setMagnification(Value.NEAREST);
             b.setWrapS(Value.CLAMP);
             b.setWrapT(Value.CLAMP);
             rs.mSampler_CLAMP_NEAREST = b.create();
@@ -85,8 +85,8 @@
     public static Sampler CLAMP_LINEAR(RenderScript rs) {
         if(rs.mSampler_CLAMP_LINEAR == null) {
             Builder b = new Builder(rs);
-            b.setMin(Value.LINEAR);
-            b.setMag(Value.LINEAR);
+            b.setMinification(Value.LINEAR);
+            b.setMagnification(Value.LINEAR);
             b.setWrapS(Value.CLAMP);
             b.setWrapT(Value.CLAMP);
             rs.mSampler_CLAMP_LINEAR = b.create();
@@ -105,8 +105,8 @@
     public static Sampler CLAMP_LINEAR_MIP_LINEAR(RenderScript rs) {
         if(rs.mSampler_CLAMP_LINEAR_MIP_LINEAR == null) {
             Builder b = new Builder(rs);
-            b.setMin(Value.LINEAR_MIP_LINEAR);
-            b.setMag(Value.LINEAR);
+            b.setMinification(Value.LINEAR_MIP_LINEAR);
+            b.setMagnification(Value.LINEAR);
             b.setWrapS(Value.CLAMP);
             b.setWrapT(Value.CLAMP);
             rs.mSampler_CLAMP_LINEAR_MIP_LINEAR = b.create();
@@ -125,8 +125,8 @@
     public static Sampler WRAP_NEAREST(RenderScript rs) {
         if(rs.mSampler_WRAP_NEAREST == null) {
             Builder b = new Builder(rs);
-            b.setMin(Value.NEAREST);
-            b.setMag(Value.NEAREST);
+            b.setMinification(Value.NEAREST);
+            b.setMagnification(Value.NEAREST);
             b.setWrapS(Value.WRAP);
             b.setWrapT(Value.WRAP);
             rs.mSampler_WRAP_NEAREST = b.create();
@@ -145,8 +145,8 @@
     public static Sampler WRAP_LINEAR(RenderScript rs) {
         if(rs.mSampler_WRAP_LINEAR == null) {
             Builder b = new Builder(rs);
-            b.setMin(Value.LINEAR);
-            b.setMag(Value.LINEAR);
+            b.setMinification(Value.LINEAR);
+            b.setMagnification(Value.LINEAR);
             b.setWrapS(Value.WRAP);
             b.setWrapT(Value.WRAP);
             rs.mSampler_WRAP_LINEAR = b.create();
@@ -165,8 +165,8 @@
     public static Sampler WRAP_LINEAR_MIP_LINEAR(RenderScript rs) {
         if(rs.mSampler_WRAP_LINEAR_MIP_LINEAR == null) {
             Builder b = new Builder(rs);
-            b.setMin(Value.LINEAR_MIP_LINEAR);
-            b.setMag(Value.LINEAR);
+            b.setMinification(Value.LINEAR_MIP_LINEAR);
+            b.setMagnification(Value.LINEAR);
             b.setWrapS(Value.WRAP);
             b.setWrapT(Value.WRAP);
             rs.mSampler_WRAP_LINEAR_MIP_LINEAR = b.create();
@@ -199,7 +199,7 @@
             mAniso = 1.0f;
         }
 
-        public void setMin(Value v) {
+        public void setMinification(Value v) {
             if (v == Value.NEAREST ||
                 v == Value.LINEAR ||
                 v == Value.LINEAR_MIP_LINEAR ||
@@ -210,7 +210,7 @@
             }
         }
 
-        public void setMag(Value v) {
+        public void setMagnification(Value v) {
             if (v == Value.NEAREST || v == Value.LINEAR) {
                 mMag = v;
             } else {
@@ -234,14 +234,6 @@
             }
         }
 
-        public void setWrapR(Value v) {
-            if (v == Value.WRAP || v == Value.CLAMP) {
-                mWrapR = v;
-            } else {
-                throw new IllegalArgumentException("Invalid value");
-            }
-        }
-
         public void setAnisotropy(float v) {
             if(v >= 0.0f) {
                 mAniso = v;