am 8df16d63: Merge change I7f047786 into eclair
Merge commit '8df16d63d4e1c70cf75a9acc4f24e4e1abca5abc' into eclair-mr2 * commit '8df16d63d4e1c70cf75a9acc4f24e4e1abca5abc': Update the SimpleMesh API to support new attribute types. Also spilt add/set commands to avoid permutation explosion.
This commit is contained in:
@@ -82,7 +82,7 @@ public class SimpleMesh extends BaseObj {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int addVertexType(Type t) throws IllegalStateException {
|
public int addVertexType(Type t) throws IllegalStateException {
|
||||||
if(mVertexTypeCount >= mVertexTypes.length) {
|
if (mVertexTypeCount >= mVertexTypes.length) {
|
||||||
throw new IllegalStateException("Max vertex types exceeded.");
|
throw new IllegalStateException("Max vertex types exceeded.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ public class SimpleMesh extends BaseObj {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int addVertexType(Element e, int size) throws IllegalStateException {
|
public int addVertexType(Element e, int size) throws IllegalStateException {
|
||||||
if(mVertexTypeCount >= mVertexTypes.length) {
|
if (mVertexTypeCount >= mVertexTypes.length) {
|
||||||
throw new IllegalStateException("Max vertex types exceeded.");
|
throw new IllegalStateException("Max vertex types exceeded.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,9 +134,9 @@ public class SimpleMesh extends BaseObj {
|
|||||||
int toDestroyCount = 0;
|
int toDestroyCount = 0;
|
||||||
|
|
||||||
int indexID = 0;
|
int indexID = 0;
|
||||||
if(b.mIndexType.t != null) {
|
if (b.mIndexType.t != null) {
|
||||||
indexID = b.mIndexType.t.mID;
|
indexID = b.mIndexType.t.mID;
|
||||||
} else if(b.mIndexType.size != 0) {
|
} else if (b.mIndexType.size != 0) {
|
||||||
b.mIndexType.t = b.newType(b.mIndexType.e, b.mIndexType.size);
|
b.mIndexType.t = b.newType(b.mIndexType.e, b.mIndexType.size);
|
||||||
indexID = b.mIndexType.t.mID;
|
indexID = b.mIndexType.t.mID;
|
||||||
toDestroy[toDestroyCount++] = b.mIndexType.t;
|
toDestroy[toDestroyCount++] = b.mIndexType.t;
|
||||||
@@ -144,7 +144,7 @@ public class SimpleMesh extends BaseObj {
|
|||||||
|
|
||||||
int[] IDs = new int[b.mVertexTypeCount];
|
int[] IDs = new int[b.mVertexTypeCount];
|
||||||
for(int ct=0; ct < b.mVertexTypeCount; ct++) {
|
for(int ct=0; ct < b.mVertexTypeCount; ct++) {
|
||||||
if(b.mVertexTypes[ct].t != null) {
|
if (b.mVertexTypes[ct].t != null) {
|
||||||
IDs[ct] = b.mVertexTypes[ct].t.mID;
|
IDs[ct] = b.mVertexTypes[ct].t.mID;
|
||||||
} else {
|
} else {
|
||||||
b.mVertexTypes[ct].t = b.newType(b.mVertexTypes[ct].e, b.mVertexTypes[ct].size);
|
b.mVertexTypes[ct].t = b.newType(b.mVertexTypes[ct].e, b.mVertexTypes[ct].size);
|
||||||
@@ -181,92 +181,116 @@ 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.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeSpace(int count) {
|
private void makeSpace(int count) {
|
||||||
if((mVtxCount + count) >= mVtxData.length) {
|
if ((mVtxCount + count) >= mVtxData.length) {
|
||||||
float t[] = new float[mVtxData.length * 2];
|
float t[] = new float[mVtxData.length * 2];
|
||||||
System.arraycopy(mVtxData, 0, t, 0, mVtxData.length);
|
System.arraycopy(mVtxData, 0, t, 0, mVtxData.length);
|
||||||
mVtxData = t;
|
mVtxData = t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
if((mIndexCount + 3) >= mIndexData.length) {
|
if ((mIndexCount + 3) >= mIndexData.length) {
|
||||||
short t[] = new short[mIndexData.length * 2];
|
short t[] = new short[mIndexData.length * 2];
|
||||||
System.arraycopy(mIndexData, 0, t, 0, mIndexData.length);
|
System.arraycopy(mIndexData, 0, t, 0, mIndexData.length);
|
||||||
mIndexData = t;
|
mIndexData = t;
|
||||||
@@ -279,16 +303,20 @@ public class SimpleMesh extends BaseObj {
|
|||||||
public SimpleMesh create() {
|
public SimpleMesh create() {
|
||||||
Element.Builder b = new Element.Builder(mRS);
|
Element.Builder b = new Element.Builder(mRS);
|
||||||
int floatCount = mVtxSize;
|
int floatCount = mVtxSize;
|
||||||
if(mVtxSize == 2) {
|
if (mVtxSize == 2) {
|
||||||
b.addFloatXY();
|
b.addFloatXY();
|
||||||
} 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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user