Merge change I7f047786 into eclair

* changes:
  Update the SimpleMesh API to support new attribute types.  Also spilt add/set commands to avoid permutation explosion.
This commit is contained in:
Android (Google) Code Review
2009-10-02 21:40:07 -04:00
2 changed files with 88 additions and 55 deletions

View File

@@ -181,19 +181,31 @@ public class SimpleMesh extends BaseObj {
RenderScript mRS; RenderScript mRS;
Element mElement; Element mElement;
int mVtxSize; float mNX = 0;
boolean mNorm; float mNY = 0;
boolean mTex; float mNZ = -1;
float mS0 = 0;
float mT0 = 0;
float mR = 1;
float mG = 1;
float mB = 1;
float mA = 1;
public TriangleMeshBuilder(RenderScript rs, int vtxSize, boolean norm, boolean tex) { int mVtxSize;
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, int flags) {
mRS = rs; mRS = rs;
mVtxCount = 0; mVtxCount = 0;
mIndexCount = 0; mIndexCount = 0;
mVtxData = new float[128]; mVtxData = new float[128];
mIndexData = new short[128]; mIndexData = new short[128];
mVtxSize = vtxSize; mVtxSize = vtxSize;
mNorm = norm; mFlags = flags;
mTex = tex;
if (vtxSize < 2 || vtxSize > 3) { if (vtxSize < 2 || vtxSize > 3) {
throw new IllegalArgumentException("Vertex size out of range."); 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) { private void latch() {
if((mVtxSize != 2) || mNorm || mTex) { if ((mFlags & COLOR) != 0) {
throw new IllegalStateException("add mistmatch with declaired components."); 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); makeSpace(2);
mVtxData[mVtxCount++] = x; mVtxData[mVtxCount++] = x;
mVtxData[mVtxCount++] = y; mVtxData[mVtxCount++] = y;
latch();
} }
public void add_XYZ(float x, float y, float z) { public void addVertex(float x, float y, float z) {
if((mVtxSize != 3) || mNorm || mTex) { if (mVtxSize != 3) {
throw new IllegalStateException("add mistmatch with declaired components."); throw new IllegalStateException("add mistmatch with declared components.");
} }
makeSpace(3); makeSpace(3);
mVtxData[mVtxCount++] = x; mVtxData[mVtxCount++] = x;
mVtxData[mVtxCount++] = y; mVtxData[mVtxCount++] = y;
mVtxData[mVtxCount++] = z; mVtxData[mVtxCount++] = z;
latch();
} }
public void add_XY_ST(float x, float y, float s, float t) { public void setTexture(float s, float t) {
if((mVtxSize != 2) || mNorm || !mTex) { if ((mFlags & TEXTURE_0) == 0) {
throw new IllegalStateException("add mistmatch with declaired components."); throw new IllegalStateException("add mistmatch with declared components.");
} }
makeSpace(4); mS0 = s;
mVtxData[mVtxCount++] = x; mT0 = t;
mVtxData[mVtxCount++] = y;
mVtxData[mVtxCount++] = s;
mVtxData[mVtxCount++] = t;
} }
public void add_XYZ_ST(float x, float y, float z, float s, float t) { public void setNormal(float x, float y, float z) {
if((mVtxSize != 3) || mNorm || !mTex) { if ((mFlags & NORMAL) == 0) {
throw new IllegalStateException("add mistmatch with declaired components."); throw new IllegalStateException("add mistmatch with declared components.");
} }
makeSpace(5); mNX = x;
mVtxData[mVtxCount++] = x; mNY = y;
mVtxData[mVtxCount++] = y; mNZ = z;
mVtxData[mVtxCount++] = z;
mVtxData[mVtxCount++] = s;
mVtxData[mVtxCount++] = t;
} }
public void add_XYZ_ST_NORM(float x, float y, float z, float s, float t, float nx, float ny, float nz) { public void setColor(float r, float g, float b, float a) {
if((mVtxSize != 3) || !mNorm || !mTex) { if ((mFlags & COLOR) == 0) {
throw new IllegalStateException("add mistmatch with declaired components."); throw new IllegalStateException("add mistmatch with declared components.");
} }
makeSpace(8); mR = r;
mVtxData[mVtxCount++] = x; mG = g;
mVtxData[mVtxCount++] = y; mB = b;
mVtxData[mVtxCount++] = z; mA = a;
mVtxData[mVtxCount++] = s;
mVtxData[mVtxCount++] = t;
mVtxData[mVtxCount++] = nx;
mVtxData[mVtxCount++] = ny;
mVtxData[mVtxCount++] = nz;
} }
public void addTriangle(int idx1, int idx2, int idx3) { public void addTriangle(int idx1, int idx2, int idx3) {
@@ -284,11 +308,15 @@ public class SimpleMesh extends BaseObj {
} else { } else {
b.addFloatXYZ(); b.addFloatXYZ();
} }
if(mTex) { if ((mFlags & COLOR) != 0) {
floatCount += 4;
b.addFloatRGBA();
}
if ((mFlags & TEXTURE_0) != 0) {
floatCount += 2; floatCount += 2;
b.addFloatST(); b.addFloatST();
} }
if(mNorm) { if ((mFlags & NORMAL) != 0) {
floatCount += 3; floatCount += 3;
b.addFloatNorm(); b.addFloatNorm();
} }

View File

@@ -212,7 +212,9 @@ class FilmStripMesh {
t.nxyz(1, 0, 0); t.nxyz(1, 0, 0);
int count = vtx.length / 2; 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; float runningS = 0;
for (int ct=0; ct < (count-1); ct++) { for (int ct=0; ct < (count-1); ct++) {
@@ -227,11 +229,14 @@ class FilmStripMesh {
t.ny /= len; t.ny /= len;
t.y = -0.5f; t.y = -0.5f;
t.t = 0; 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); //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.y = .5f;
t.t = 1; 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); //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) { if((runningS*2) > mTriangleOffsetsCount) {