Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8df16d63 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change I7f047786 into eclair

* changes:
  Update the SimpleMesh API to support new attribute types.  Also spilt add/set commands to avoid permutation explosion.
parents 82e863d8 7f047786
Loading
Loading
Loading
Loading
+79 −51
Original line number Diff line number Diff line
@@ -181,19 +181,31 @@ public class SimpleMesh extends BaseObj {
        RenderScript mRS;
        Element mElement;

        float mNX = 0;
        float mNY = 0;
        float mNZ = -1;
        float mS0 = 0;
        float mT0 = 0;
        float mR = 1;
        float mG = 1;
        float mB = 1;
        float mA = 1;

        int mVtxSize;
        boolean mNorm;
        boolean mTex;
        int mFlags;

        public static final int COLOR = 0x0001;
        public static final int NORMAL = 0x0002;
        public static final int TEXTURE_0 = 0x0100;

        public TriangleMeshBuilder(RenderScript rs, int vtxSize, boolean norm, boolean tex) {
        public TriangleMeshBuilder(RenderScript rs, int vtxSize, int flags) {
            mRS = rs;
            mVtxCount = 0;
            mIndexCount = 0;
            mVtxData = new float[128];
            mIndexData = new short[128];
            mVtxSize = vtxSize;
            mNorm = norm;
            mTex = tex;
            mFlags = flags;

            if (vtxSize < 2 || vtxSize > 3) {
                throw new IllegalArgumentException("Vertex size out of range.");
@@ -208,61 +220,73 @@ public class SimpleMesh extends BaseObj {
            }
        }

        public void add_XY(float x, float y) {
            if((mVtxSize != 2) || mNorm || mTex) {
                throw new IllegalStateException("add mistmatch with declaired components.");
        private void latch() {
            if ((mFlags & COLOR) != 0) {
                makeSpace(4);
                mVtxData[mVtxCount++] = mR;
                mVtxData[mVtxCount++] = mG;
                mVtxData[mVtxCount++] = mB;
                mVtxData[mVtxCount++] = mA;
            }
            if ((mFlags & NORMAL) != 0) {
                makeSpace(3);
                mVtxData[mVtxCount++] = mNX;
                mVtxData[mVtxCount++] = mNY;
                mVtxData[mVtxCount++] = mNZ;
            }
            if ((mFlags & TEXTURE_0) != 0) {
                makeSpace(2);
                mVtxData[mVtxCount++] = mS0;
                mVtxData[mVtxCount++] = mT0;
            }
        }

        public void addVertex(float x, float y) {
            if (mVtxSize != 2) {
                throw new IllegalStateException("add mistmatch with declared components.");
            }
            makeSpace(2);
            mVtxData[mVtxCount++] = x;
            mVtxData[mVtxCount++] = y;
            latch();
        }

        public void add_XYZ(float x, float y, float z) {
            if((mVtxSize != 3) || mNorm || mTex) {
                throw new IllegalStateException("add mistmatch with declaired components.");
        public void addVertex(float x, float y, float z) {
            if (mVtxSize != 3) {
                throw new IllegalStateException("add mistmatch with declared components.");
            }
            makeSpace(3);
            mVtxData[mVtxCount++] = x;
            mVtxData[mVtxCount++] = y;
            mVtxData[mVtxCount++] = z;
            latch();
        }

        public void add_XY_ST(float x, float y, float s, float t) {
            if((mVtxSize != 2) || mNorm || !mTex) {
                throw new IllegalStateException("add mistmatch with declaired components.");
        public void setTexture(float s, float t) {
            if ((mFlags & TEXTURE_0) == 0) {
                throw new IllegalStateException("add mistmatch with declared components.");
            }
            makeSpace(4);
            mVtxData[mVtxCount++] = x;
            mVtxData[mVtxCount++] = y;
            mVtxData[mVtxCount++] = s;
            mVtxData[mVtxCount++] = t;
            mS0 = s;
            mT0 = t;
        }

        public void add_XYZ_ST(float x, float y, float z, float s, float t) {
            if((mVtxSize != 3) || mNorm || !mTex) {
                throw new IllegalStateException("add mistmatch with declaired components.");
        public void setNormal(float x, float y, float z) {
            if ((mFlags & NORMAL) == 0) {
                throw new IllegalStateException("add mistmatch with declared components.");
            }
            makeSpace(5);
            mVtxData[mVtxCount++] = x;
            mVtxData[mVtxCount++] = y;
            mVtxData[mVtxCount++] = z;
            mVtxData[mVtxCount++] = s;
            mVtxData[mVtxCount++] = t;
            mNX = x;
            mNY = y;
            mNZ = z;
        }

        public void add_XYZ_ST_NORM(float x, float y, float z, float s, float t, float nx, float ny, float nz) {
            if((mVtxSize != 3) || !mNorm || !mTex) {
                throw new IllegalStateException("add mistmatch with declaired components.");
        public void setColor(float r, float g, float b, float a) {
            if ((mFlags & COLOR) == 0) {
                throw new IllegalStateException("add mistmatch with declared components.");
            }
            makeSpace(8);
            mVtxData[mVtxCount++] = x;
            mVtxData[mVtxCount++] = y;
            mVtxData[mVtxCount++] = z;
            mVtxData[mVtxCount++] = s;
            mVtxData[mVtxCount++] = t;
            mVtxData[mVtxCount++] = nx;
            mVtxData[mVtxCount++] = ny;
            mVtxData[mVtxCount++] = nz;
            mR = r;
            mG = g;
            mB = b;
            mA = a;
        }

        public void addTriangle(int idx1, int idx2, int idx3) {
@@ -284,11 +308,15 @@ public class SimpleMesh extends BaseObj {
            } else {
                b.addFloatXYZ();
            }
            if(mTex) {
            if ((mFlags & COLOR) != 0) {
                floatCount += 4;
                b.addFloatRGBA();
            }
            if ((mFlags & TEXTURE_0) != 0) {
                floatCount += 2;
                b.addFloatST();
            }
            if(mNorm) {
            if ((mFlags & NORMAL) != 0) {
                floatCount += 3;
                b.addFloatNorm();
            }
+8 −3
Original line number Diff line number Diff line
@@ -212,7 +212,9 @@ class FilmStripMesh {
        t.nxyz(1, 0, 0);
        int count = vtx.length / 2;

        SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(rs, 3, true, true);
        SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(
            rs, 3,
            SimpleMesh.TriangleMeshBuilder.NORMAL | SimpleMesh.TriangleMeshBuilder.TEXTURE_0);

        float runningS = 0;
        for (int ct=0; ct < (count-1); ct++) {
@@ -227,11 +229,14 @@ class FilmStripMesh {
            t.ny /= len;
            t.y = -0.5f;
            t.t = 0;
            tm.add_XYZ_ST_NORM(t.x, t.y, t.z, t.s, t.t, t.nx, t.ny, t.nz);
            tm.setNormal(t.nx, t.ny, t.nz);
            tm.setTexture(t.s, t.t);
            tm.addVertex(t.x, t.y, t.z);
            //android.util.Log.e("rs", "vtx x="+t.x+" y="+t.y+" z="+t.z+" s="+t.s+" t="+t.t);
            t.y = .5f;
            t.t = 1;
            tm.add_XYZ_ST_NORM(t.x, t.y, t.z, t.s, t.t, t.nx, t.ny, t.nz);
            tm.setTexture(t.s, t.t);
            tm.addVertex(t.x, t.y, t.z);
            //android.util.Log.e("rs", "vtx x="+t.x+" y="+t.y+" z="+t.z+" s="+t.s+" t="+t.t);

            if((runningS*2) > mTriangleOffsetsCount) {