diff options
author | Alex Sakhartchouk <alexst@google.com> | 2010-12-21 14:42:26 -0800 |
---|---|---|
committer | Alex Sakhartchouk <alexst@google.com> | 2010-12-21 14:57:04 -0800 |
commit | b4d7bb6872f523b4318144202e119766ed9054ed (patch) | |
tree | 2e7e18e9864c7c9398bbce8f0bc227f147b648f4 | |
parent | 1528d8f47cc6f0e0d5c9f905f82d15a35ce1bafb (diff) | |
download | frameworks_base-b4d7bb6872f523b4318144202e119766ed9054ed.zip frameworks_base-b4d7bb6872f523b4318144202e119766ed9054ed.tar.gz frameworks_base-b4d7bb6872f523b4318144202e119766ed9054ed.tar.bz2 |
API cleanup for renderscript. This will be a multiproject commit.
Change-Id: Ida62d3a155285a20725be9daa62217faef1c3734
21 files changed, 710 insertions, 719 deletions
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 @@ public class FieldPacker { 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 class Matrix2f { } 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 class Matrix3f { } 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 class Matrix4f { } 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 @@ public class Matrix4f { 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 @@ import android.util.Log; **/ 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 @@ public class Mesh extends BaseObj { } 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 @@ public class Mesh extends BaseObj { 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 @@ public class Mesh extends BaseObj { 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 class Mesh extends BaseObj { } } - 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 @@ public class Mesh extends BaseObj { 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 @@ public class Mesh extends BaseObj { 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 @@ public class Mesh extends BaseObj { 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 @@ public class Mesh extends BaseObj { mIndexData[mIndexCount++] = (short)idx1; mIndexData[mIndexCount++] = (short)idx2; mIndexData[mIndexCount++] = (short)idx3; + return this; } public Mesh create(boolean uploadToBufferObject) { @@ -470,7 +498,7 @@ public class Mesh extends BaseObj { 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 @@ public class Mesh extends BaseObj { } } - 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 @@ public class Program extends BaseObj { 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 @@ public class Program extends BaseObj { 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 @@ public class ProgramFragment extends Program { 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 @@ public class ProgramFragment extends Program { 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 @@ public class ProgramRaster extends BaseObj { 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 @@ import android.util.Log; * **/ 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 @@ public class ProgramStore extends BaseObj { 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 @@ public class ProgramStore extends BaseObj { 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 @@ public class ProgramStore extends BaseObj { 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 @@ public class ProgramStore extends BaseObj { 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 @@ import android.util.Log; * **/ 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 class ProgramVertex extends Program { } } - 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 @@ public class RenderScript { 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 class Sampler extends BaseObj { 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 class Sampler extends BaseObj { 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 class Sampler extends BaseObj { 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 class Sampler extends BaseObj { 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 class Sampler extends BaseObj { 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 class Sampler extends BaseObj { 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 @@ public class Sampler extends BaseObj { 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 class Sampler extends BaseObj { } } - 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 class Sampler extends BaseObj { } } - 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; diff --git a/libs/rs/java/Balls/src/com/android/balls/BallsRS.java b/libs/rs/java/Balls/src/com/android/balls/BallsRS.java index 0a06394..50ee921 100644 --- a/libs/rs/java/Balls/src/com/android/balls/BallsRS.java +++ b/libs/rs/java/Balls/src/com/android/balls/BallsRS.java @@ -50,7 +50,7 @@ public class BallsRS { private void createProgramVertex() { updateProjectionMatrices(); - ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(mRS); + ProgramVertex.Builder sb = new ProgramVertex.Builder(mRS); String t = "varying vec4 varColor;\n" + "void main() {\n" + " vec4 pos = vec4(0.0, 0.0, 0.0, 1.0);\n" + @@ -75,18 +75,27 @@ public class BallsRS { return allocation; } + ProgramStore BLEND_ADD_DEPTH_NONE(RenderScript rs) { + ProgramStore.Builder builder = new ProgramStore.Builder(rs); + builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); + builder.setBlendFunc(ProgramStore.BlendSrcFunc.ONE, ProgramStore.BlendDstFunc.ONE); + builder.setDitherEnabled(false); + builder.setDepthMaskEnabled(false); + return builder.create(); + } + public void init(RenderScriptGL rs, Resources res, int width, int height) { mRS = rs; mRes = res; - ProgramFragment.Builder pfb = new ProgramFragment.Builder(rs); + ProgramFragmentFixedFunction.Builder pfb = new ProgramFragmentFixedFunction.Builder(rs); pfb.setPointSpriteTexCoordinateReplacement(true); - pfb.setTexture(ProgramFragment.Builder.EnvMode.MODULATE, - ProgramFragment.Builder.Format.RGBA, 0); + pfb.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE, + ProgramFragmentFixedFunction.Builder.Format.RGBA, 0); pfb.setVaryingColor(true); mPFPoints = pfb.create(); - pfb = new ProgramFragment.Builder(rs); + pfb = new ProgramFragmentFixedFunction.Builder(rs); pfb.setVaryingColor(true); mPFLines = pfb.create(); @@ -97,7 +106,7 @@ public class BallsRS { Mesh.AllocationBuilder smb = new Mesh.AllocationBuilder(mRS); smb.addVertexAllocation(mPoints.getAllocation()); - smb.addIndexType(Primitive.POINT); + smb.addIndexSetType(Mesh.Primitive.POINT); Mesh smP = smb.create(); mPhysicsScript = new ScriptC_ball_physics(mRS, mRes, R.raw.ball_physics); @@ -113,7 +122,7 @@ public class BallsRS { mScript.set_gPFPoints(mPFPoints); createProgramVertex(); - mRS.bindProgramStore(ProgramStore.BLEND_ADD_DEPTH_NO_DEPTH(mRS)); + mRS.bindProgramStore(BLEND_ADD_DEPTH_NONE(mRS)); mPhysicsScript.set_gMinPos(new Float2(5, 5)); mPhysicsScript.set_gMaxPos(new Float2(width - 5, height - 5)); diff --git a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java index a5d06e9..be2f9ca 100644 --- a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java +++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java @@ -34,7 +34,7 @@ public class FountainRS { mRS = rs; mRes = res; - ProgramFragment.Builder pfb = new ProgramFragment.Builder(rs); + ProgramFragmentFixedFunction.Builder pfb = new ProgramFragmentFixedFunction.Builder(rs); pfb.setVaryingColor(true); rs.bindProgramFragment(pfb.create()); @@ -43,7 +43,7 @@ public class FountainRS { Mesh.AllocationBuilder smb = new Mesh.AllocationBuilder(mRS); smb.addVertexAllocation(points.getAllocation()); - smb.addIndexType(Primitive.POINT); + smb.addIndexSetType(Mesh.Primitive.POINT); Mesh sm = smb.create(); mScript = new ScriptC_fountain(mRS, mRes, R.raw.fountain); diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java index 7d99686..f91f31e 100644 --- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java +++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java @@ -54,7 +54,7 @@ public class SceneGraphRS { private ProgramStore mPSBackground; private ProgramFragment mPFBackground; private ProgramVertex mPVBackground; - private ProgramVertex.MatrixAllocation mPVA; + private ProgramVertexFixedFunction.Constants mPVA; private Allocation mGridImage; private Allocation mAllocPV; @@ -94,8 +94,8 @@ public class SceneGraphRS { ProgramStore.Builder b = new ProgramStore.Builder(mRS); b.setDepthFunc(ProgramStore.DepthFunc.LESS); - b.setDitherEnable(false); - b.setDepthMask(true); + b.setDitherEnabled(false); + b.setDepthMaskEnabled(true); mPSBackground = b.create(); mScript.set_gPFSBackground(mPSBackground); @@ -103,15 +103,15 @@ public class SceneGraphRS { private void initPF() { Sampler.Builder bs = new Sampler.Builder(mRS); - bs.setMin(Sampler.Value.LINEAR); - bs.setMag(Sampler.Value.LINEAR); + bs.setMinification(Sampler.Value.LINEAR); + bs.setMagnification(Sampler.Value.LINEAR); bs.setWrapS(Sampler.Value.CLAMP); bs.setWrapT(Sampler.Value.CLAMP); mSampler = bs.create(); - ProgramFragment.Builder b = new ProgramFragment.Builder(mRS); - b.setTexture(ProgramFragment.Builder.EnvMode.REPLACE, - ProgramFragment.Builder.Format.RGBA, 0); + ProgramFragmentFixedFunction.Builder b = new ProgramFragmentFixedFunction.Builder(mRS); + b.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE, + ProgramFragmentFixedFunction.Builder.Format.RGBA, 0); mPFBackground = b.create(); mPFBackground.bindSampler(mSampler, 0); @@ -119,11 +119,11 @@ public class SceneGraphRS { } private void initPV() { - ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS); + ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS); mPVBackground = pvb.create(); - mPVA = new ProgramVertex.MatrixAllocation(mRS); - mPVBackground.bindAllocation(mPVA); + mPVA = new ProgramVertexFixedFunction.Constants(mRS); + ((ProgramVertexFixedFunction)mPVBackground).bindConstants(mPVA); mScript.set_gPVBackground(mPVBackground); } diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java index 5451ca1..b18a327 100644 --- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java +++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java @@ -50,7 +50,7 @@ public class SimpleModelRS { private ProgramStore mPSBackground; private ProgramFragment mPFBackground; private ProgramVertex mPVBackground; - private ProgramVertex.MatrixAllocation mPVA; + private ProgramVertexFixedFunction.Constants mPVA; private Allocation mGridImage; private Allocation mAllocPV; @@ -89,8 +89,8 @@ public class SimpleModelRS { ProgramStore.Builder b = new ProgramStore.Builder(mRS); b.setDepthFunc(ProgramStore.DepthFunc.LESS); - b.setDitherEnable(false); - b.setDepthMask(true); + b.setDitherEnabled(false); + b.setDepthMaskEnabled(true); mPSBackground = b.create(); mScript.set_gPFSBackground(mPSBackground); @@ -98,15 +98,15 @@ public class SimpleModelRS { private void initPF() { Sampler.Builder bs = new Sampler.Builder(mRS); - bs.setMin(Sampler.Value.LINEAR); - bs.setMag(Sampler.Value.LINEAR); + bs.setMinification(Sampler.Value.LINEAR); + bs.setMagnification(Sampler.Value.LINEAR); bs.setWrapS(Sampler.Value.CLAMP); bs.setWrapT(Sampler.Value.CLAMP); mSampler = bs.create(); - ProgramFragment.Builder b = new ProgramFragment.Builder(mRS); - b.setTexture(ProgramFragment.Builder.EnvMode.REPLACE, - ProgramFragment.Builder.Format.RGBA, 0); + ProgramFragmentFixedFunction.Builder b = new ProgramFragmentFixedFunction.Builder(mRS); + b.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE, + ProgramFragmentFixedFunction.Builder.Format.RGBA, 0); mPFBackground = b.create(); mPFBackground.bindSampler(mSampler, 0); @@ -114,11 +114,11 @@ public class SimpleModelRS { } private void initPV() { - ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS); + ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS); mPVBackground = pvb.create(); - mPVA = new ProgramVertex.MatrixAllocation(mRS); - mPVBackground.bindAllocation(mPVA); + mPVA = new ProgramVertexFixedFunction.Constants(mRS); + ((ProgramVertexFixedFunction)mPVBackground).bindConstants(mPVA); mScript.set_gPVBackground(mPVBackground); } diff --git a/libs/rs/java/Samples/src/com/android/samples/RsBenchRS.java b/libs/rs/java/Samples/src/com/android/samples/RsBenchRS.java index b3e8026..5430a13 100644 --- a/libs/rs/java/Samples/src/com/android/samples/RsBenchRS.java +++ b/libs/rs/java/Samples/src/com/android/samples/RsBenchRS.java @@ -26,6 +26,8 @@ import android.renderscript.Allocation.CubemapLayout; import android.renderscript.Allocation.MipmapControl; import android.renderscript.Program.TextureType; import android.renderscript.ProgramStore.DepthFunc; +import android.renderscript.ProgramStore.BlendSrcFunc; +import android.renderscript.ProgramStore.BlendDstFunc; import android.renderscript.Sampler.Value; import android.util.Log; @@ -69,7 +71,7 @@ public class RsBenchRS { private ProgramFragment mProgFragmentColor; private ProgramVertex mProgVertex; - private ProgramVertex.MatrixAllocation mPVA; + private ProgramVertexFixedFunction.Constants mPVA; // Custom shaders private ProgramVertex mProgVertexCustom; @@ -122,6 +124,15 @@ public class RsBenchRS { mScript.set_gDisplayMode(mMode); } + ProgramStore BLEND_ADD_DEPTH_NONE(RenderScript rs) { + ProgramStore.Builder builder = new ProgramStore.Builder(rs); + builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); + builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE); + builder.setDitherEnabled(false); + builder.setDepthMaskEnabled(false); + return builder.create(); + } + private Mesh getMbyNMesh(float width, float height, int wResolution, int hResolution) { Mesh.TriangleMeshBuilder tmb = new Mesh.TriangleMeshBuilder(mRS, @@ -155,18 +166,18 @@ public class RsBenchRS { private void initProgramStore() { // Use stock the stock program store object mProgStoreBlendNoneDepth = ProgramStore.BLEND_NONE_DEPTH_TEST(mRS); - mProgStoreBlendNone = ProgramStore.BLEND_NONE_DEPTH_NO_DEPTH(mRS); + mProgStoreBlendNone = ProgramStore.BLEND_NONE_DEPTH_NONE(mRS); // Create a custom program store ProgramStore.Builder builder = new ProgramStore.Builder(mRS); builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); builder.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA); - builder.setDitherEnable(false); - builder.setDepthMask(false); + builder.setDitherEnabled(false); + builder.setDepthMaskEnabled(false); mProgStoreBlendAlpha = builder.create(); - mProgStoreBlendAdd = ProgramStore.BLEND_ADD_DEPTH_NO_DEPTH(mRS); + mProgStoreBlendAdd = BLEND_ADD_DEPTH_NONE(mRS); mScript.set_gProgStoreBlendNoneDepth(mProgStoreBlendNoneDepth); mScript.set_gProgStoreBlendNone(mProgStoreBlendNone); @@ -176,13 +187,13 @@ public class RsBenchRS { private void initProgramFragment() { - ProgramFragment.Builder texBuilder = new ProgramFragment.Builder(mRS); - texBuilder.setTexture(ProgramFragment.Builder.EnvMode.REPLACE, - ProgramFragment.Builder.Format.RGBA, 0); + ProgramFragmentFixedFunction.Builder texBuilder = new ProgramFragmentFixedFunction.Builder(mRS); + texBuilder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE, + ProgramFragmentFixedFunction.Builder.Format.RGBA, 0); mProgFragmentTexture = texBuilder.create(); mProgFragmentTexture.bindSampler(mLinearClamp, 0); - ProgramFragment.Builder colBuilder = new ProgramFragment.Builder(mRS); + ProgramFragmentFixedFunction.Builder colBuilder = new ProgramFragmentFixedFunction.Builder(mRS); colBuilder.setVaryingColor(false); mProgFragmentColor = colBuilder.create(); @@ -191,12 +202,14 @@ public class RsBenchRS { } private void initProgramVertex() { - ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS); + ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS); mProgVertex = pvb.create(); - mPVA = new ProgramVertex.MatrixAllocation(mRS); - mProgVertex.bindAllocation(mPVA); - mPVA.setupOrthoWindow(mWidth, mHeight); + mPVA = new ProgramVertexFixedFunction.Constants(mRS); + ((ProgramVertexFixedFunction)mProgVertex).bindConstants(mPVA); + Matrix4f proj = new Matrix4f(); + proj.loadOrthoWindow(mWidth, mHeight); + mPVA.setProjection(proj); mScript.set_gProgVertex(mProgVertex); } @@ -213,7 +226,7 @@ public class RsBenchRS { mScript.bind_gFSConstPixel(mFSConstPixel); // Initialize the shader builder - ProgramVertex.ShaderBuilder pvbCustom = new ProgramVertex.ShaderBuilder(mRS); + ProgramVertex.Builder pvbCustom = new ProgramVertex.Builder(mRS); // Specify the resource that contains the shader string pvbCustom.setShader(mRes, R.raw.shaderv); // Use a script field to specify the input layout @@ -224,7 +237,7 @@ public class RsBenchRS { // Bind the source of constant data mProgVertexCustom.bindConstants(mVSConst.getAllocation(), 0); - ProgramFragment.ShaderBuilder pfbCustom = new ProgramFragment.ShaderBuilder(mRS); + ProgramFragment.Builder pfbCustom = new ProgramFragment.Builder(mRS); // Specify the resource that contains the shader string pfbCustom.setShader(mRes, R.raw.shaderf); // Tell the builder how many textures we have @@ -236,42 +249,44 @@ public class RsBenchRS { mProgFragmentCustom.bindConstants(mFSConst.getAllocation(), 0); // Cubemap test shaders - pvbCustom = new ProgramVertex.ShaderBuilder(mRS); + pvbCustom = new ProgramVertex.Builder(mRS); pvbCustom.setShader(mRes, R.raw.shadercubev); pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS)); pvbCustom.addConstant(mVSConst.getAllocation().getType()); mProgVertexCube = pvbCustom.create(); mProgVertexCube.bindConstants(mVSConst.getAllocation(), 0); - pfbCustom = new ProgramFragment.ShaderBuilder(mRS); + pfbCustom = new ProgramFragment.Builder(mRS); pfbCustom.setShader(mRes, R.raw.shadercubef); pfbCustom.addTexture(Program.TextureType.TEXTURE_CUBE); mProgFragmentCube = pfbCustom.create(); - pvbCustom = new ProgramVertex.ShaderBuilder(mRS); + pvbCustom = new ProgramVertex.Builder(mRS); pvbCustom.setShader(mRes, R.raw.shader2v); pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS)); pvbCustom.addConstant(mVSConstPixel.getAllocation().getType()); mProgVertexPixelLight = pvbCustom.create(); mProgVertexPixelLight.bindConstants(mVSConstPixel.getAllocation(), 0); - pvbCustom = new ProgramVertex.ShaderBuilder(mRS); + pvbCustom = new ProgramVertex.Builder(mRS); pvbCustom.setShader(mRes, R.raw.shader2movev); pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS)); pvbCustom.addConstant(mVSConstPixel.getAllocation().getType()); mProgVertexPixelLightMove = pvbCustom.create(); mProgVertexPixelLightMove.bindConstants(mVSConstPixel.getAllocation(), 0); - pfbCustom = new ProgramFragment.ShaderBuilder(mRS); + pfbCustom = new ProgramFragment.Builder(mRS); pfbCustom.setShader(mRes, R.raw.shader2f); pfbCustom.addTexture(Program.TextureType.TEXTURE_2D); pfbCustom.addConstant(mFSConstPixel.getAllocation().getType()); mProgFragmentPixelLight = pfbCustom.create(); mProgFragmentPixelLight.bindConstants(mFSConstPixel.getAllocation(), 0); - pfbCustom = new ProgramFragment.ShaderBuilder(mRS); + pfbCustom = new ProgramFragment.Builder(mRS); pfbCustom.setShader(mRes, R.raw.multitexf); - pfbCustom.setTextureCount(3); + for (int texCount = 0; texCount < 3; texCount ++) { + pfbCustom.addTexture(Program.TextureType.TEXTURE_2D); + } mProgFragmentMultitex = pfbCustom.create(); mScript.set_gProgVertexCustom(mProgVertexCustom); @@ -354,8 +369,8 @@ public class RsBenchRS { private void initSamplers() { Sampler.Builder bs = new Sampler.Builder(mRS); - bs.setMin(Sampler.Value.LINEAR); - bs.setMag(Sampler.Value.LINEAR); + bs.setMinification(Sampler.Value.LINEAR); + bs.setMagnification(Sampler.Value.LINEAR); bs.setWrapS(Sampler.Value.WRAP); bs.setWrapT(Sampler.Value.WRAP); mLinearWrap = bs.create(); @@ -365,8 +380,8 @@ public class RsBenchRS { mMipLinearWrap = Sampler.WRAP_LINEAR_MIP_LINEAR(mRS); bs = new Sampler.Builder(mRS); - bs.setMin(Sampler.Value.LINEAR_MIP_LINEAR); - bs.setMag(Sampler.Value.LINEAR); + bs.setMinification(Sampler.Value.LINEAR_MIP_LINEAR); + bs.setMagnification(Sampler.Value.LINEAR); bs.setWrapS(Sampler.Value.WRAP); bs.setWrapT(Sampler.Value.WRAP); bs.setAnisotropy(8.0f); diff --git a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java index 636a486..cac105a 100644 --- a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java +++ b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java @@ -26,6 +26,8 @@ import android.renderscript.Allocation.CubemapLayout; import android.renderscript.Font.Style; import android.renderscript.Program.TextureType; import android.renderscript.ProgramStore.DepthFunc; +import android.renderscript.ProgramStore.BlendSrcFunc; +import android.renderscript.ProgramStore.BlendDstFunc; import android.renderscript.Sampler.Value; import android.util.Log; @@ -69,7 +71,7 @@ public class RsRenderStatesRS { private ProgramFragment mProgFragmentColor; private ProgramVertex mProgVertex; - private ProgramVertex.MatrixAllocation mPVA; + private ProgramVertexFixedFunction.Constants mPVA; // Custom shaders private ProgramVertex mProgVertexCustom; @@ -120,6 +122,15 @@ public class RsRenderStatesRS { mScript.set_gDisplayMode(mMode); } + ProgramStore BLEND_ADD_DEPTH_NONE(RenderScript rs) { + ProgramStore.Builder builder = new ProgramStore.Builder(rs); + builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); + builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE); + builder.setDitherEnabled(false); + builder.setDepthMaskEnabled(false); + return builder.create(); + } + private Mesh getMbyNMesh(float width, float height, int wResolution, int hResolution) { Mesh.TriangleMeshBuilder tmb = new Mesh.TriangleMeshBuilder(mRS, @@ -153,18 +164,18 @@ public class RsRenderStatesRS { private void initProgramStore() { // Use stock the stock program store object mProgStoreBlendNoneDepth = ProgramStore.BLEND_NONE_DEPTH_TEST(mRS); - mProgStoreBlendNone = ProgramStore.BLEND_NONE_DEPTH_NO_DEPTH(mRS); + mProgStoreBlendNone = ProgramStore.BLEND_NONE_DEPTH_NONE(mRS); // Create a custom program store ProgramStore.Builder builder = new ProgramStore.Builder(mRS); builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); builder.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA); - builder.setDitherEnable(false); - builder.setDepthMask(false); + builder.setDitherEnabled(false); + builder.setDepthMaskEnabled(false); mProgStoreBlendAlpha = builder.create(); - mProgStoreBlendAdd = ProgramStore.BLEND_ADD_DEPTH_NO_DEPTH(mRS); + mProgStoreBlendAdd = BLEND_ADD_DEPTH_NONE(mRS); mScript.set_gProgStoreBlendNoneDepth(mProgStoreBlendNoneDepth); mScript.set_gProgStoreBlendNone(mProgStoreBlendNone); @@ -174,13 +185,13 @@ public class RsRenderStatesRS { private void initProgramFragment() { - ProgramFragment.Builder texBuilder = new ProgramFragment.Builder(mRS); - texBuilder.setTexture(ProgramFragment.Builder.EnvMode.REPLACE, - ProgramFragment.Builder.Format.RGBA, 0); + ProgramFragmentFixedFunction.Builder texBuilder = new ProgramFragmentFixedFunction.Builder(mRS); + texBuilder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE, + ProgramFragmentFixedFunction.Builder.Format.RGBA, 0); mProgFragmentTexture = texBuilder.create(); mProgFragmentTexture.bindSampler(mLinearClamp, 0); - ProgramFragment.Builder colBuilder = new ProgramFragment.Builder(mRS); + ProgramFragmentFixedFunction.Builder colBuilder = new ProgramFragmentFixedFunction.Builder(mRS); colBuilder.setVaryingColor(false); mProgFragmentColor = colBuilder.create(); @@ -189,12 +200,14 @@ public class RsRenderStatesRS { } private void initProgramVertex() { - ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS); + ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS); mProgVertex = pvb.create(); - mPVA = new ProgramVertex.MatrixAllocation(mRS); - mProgVertex.bindAllocation(mPVA); - mPVA.setupOrthoWindow(mWidth, mHeight); + mPVA = new ProgramVertexFixedFunction.Constants(mRS); + ((ProgramVertexFixedFunction)mProgVertex).bindConstants(mPVA); + Matrix4f proj = new Matrix4f(); + proj.loadOrthoWindow(mWidth, mHeight); + mPVA.setProjection(proj); mScript.set_gProgVertex(mProgVertex); } @@ -211,7 +224,7 @@ public class RsRenderStatesRS { mScript.bind_gFSConstants2(mFSConst2); // Initialize the shader builder - ProgramVertex.ShaderBuilder pvbCustom = new ProgramVertex.ShaderBuilder(mRS); + ProgramVertex.Builder pvbCustom = new ProgramVertex.Builder(mRS); // Specify the resource that contains the shader string pvbCustom.setShader(mRes, R.raw.shaderv); // Use a script field to spcify the input layout @@ -222,47 +235,49 @@ public class RsRenderStatesRS { // Bind the source of constant data mProgVertexCustom.bindConstants(mVSConst.getAllocation(), 0); - ProgramFragment.ShaderBuilder pfbCustom = new ProgramFragment.ShaderBuilder(mRS); + ProgramFragment.Builder pfbCustom = new ProgramFragment.Builder(mRS); // Specify the resource that contains the shader string pfbCustom.setShader(mRes, R.raw.shaderf); //Tell the builder how many textures we have - pfbCustom.setTextureCount(1); + pfbCustom.addTexture(Program.TextureType.TEXTURE_2D); // Define the constant input layout pfbCustom.addConstant(mFSConst.getAllocation().getType()); mProgFragmentCustom = pfbCustom.create(); // Bind the source of constant data mProgFragmentCustom.bindConstants(mFSConst.getAllocation(), 0); - pvbCustom = new ProgramVertex.ShaderBuilder(mRS); + pvbCustom = new ProgramVertex.Builder(mRS); pvbCustom.setShader(mRes, R.raw.shaderarrayv); pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS)); pvbCustom.addConstant(mVSConst2.getAllocation().getType()); mProgVertexCustom2 = pvbCustom.create(); mProgVertexCustom2.bindConstants(mVSConst2.getAllocation(), 0); - pfbCustom = new ProgramFragment.ShaderBuilder(mRS); + pfbCustom = new ProgramFragment.Builder(mRS); pfbCustom.setShader(mRes, R.raw.shaderarrayf); - pfbCustom.setTextureCount(1); + pfbCustom.addTexture(Program.TextureType.TEXTURE_2D); pfbCustom.addConstant(mFSConst2.getAllocation().getType()); mProgFragmentCustom2 = pfbCustom.create(); mProgFragmentCustom2.bindConstants(mFSConst2.getAllocation(), 0); // Cubemap test shaders - pvbCustom = new ProgramVertex.ShaderBuilder(mRS); + pvbCustom = new ProgramVertex.Builder(mRS); pvbCustom.setShader(mRes, R.raw.shadercubev); pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS)); pvbCustom.addConstant(mVSConst.getAllocation().getType()); mProgVertexCube = pvbCustom.create(); mProgVertexCube.bindConstants(mVSConst.getAllocation(), 0); - pfbCustom = new ProgramFragment.ShaderBuilder(mRS); + pfbCustom = new ProgramFragment.Builder(mRS); pfbCustom.setShader(mRes, R.raw.shadercubef); pfbCustom.addTexture(Program.TextureType.TEXTURE_CUBE); mProgFragmentCube = pfbCustom.create(); - pfbCustom = new ProgramFragment.ShaderBuilder(mRS); + pfbCustom = new ProgramFragment.Builder(mRS); pfbCustom.setShader(mRes, R.raw.multitexf); - pfbCustom.setTextureCount(3); + for (int texCount = 0; texCount < 3; texCount ++) { + pfbCustom.addTexture(Program.TextureType.TEXTURE_2D); + } mProgFragmentMultitex = pfbCustom.create(); mScript.set_gProgVertexCustom(mProgVertexCustom); @@ -340,8 +355,8 @@ public class RsRenderStatesRS { private void initSamplers() { Sampler.Builder bs = new Sampler.Builder(mRS); - bs.setMin(Sampler.Value.LINEAR); - bs.setMag(Sampler.Value.LINEAR); + bs.setMinification(Sampler.Value.LINEAR); + bs.setMagnification(Sampler.Value.LINEAR); bs.setWrapS(Sampler.Value.WRAP); bs.setWrapT(Sampler.Value.WRAP); mLinearWrap = bs.create(); @@ -351,8 +366,8 @@ public class RsRenderStatesRS { mMipLinearWrap = Sampler.WRAP_LINEAR_MIP_LINEAR(mRS); bs = new Sampler.Builder(mRS); - bs.setMin(Sampler.Value.LINEAR_MIP_LINEAR); - bs.setMag(Sampler.Value.LINEAR); + bs.setMinification(Sampler.Value.LINEAR_MIP_LINEAR); + bs.setMagnification(Sampler.Value.LINEAR); bs.setWrapS(Sampler.Value.WRAP); bs.setWrapT(Sampler.Value.WRAP); bs.setAnisotropy(8.0f); |