Expand RS vector3 types to vector4.
BUG=5609007
The underlying LLVM implementation for vector3 types does this implicitly. If
RS does not adjust its implementation, we will always be misaligned for any
subsequent data after a vector3 type. We previously inserted padding into the
reflected layers from llvm-rs-cc (hence the skip padding part of this change).
We can safely ignore the padding now that the Java/native code is updated to
use the expanded size. The compiler will also need modification to ensure that
we don't mistakenly skip over any end-of-struct padding.
Fixing the 3 component vector padding problem.
Change-Id: If68af42287deb8f4b28addcd19a9fa314656be44
diff --git a/graphics/java/android/renderscript/Mesh.java b/graphics/java/android/renderscript/Mesh.java
index 7b3b73f..b6ca58c3 100644
--- a/graphics/java/android/renderscript/Mesh.java
+++ b/graphics/java/android/renderscript/Mesh.java
@@ -514,6 +514,7 @@
public static class TriangleMeshBuilder {
float mVtxData[];
int mVtxCount;
+ int mMaxIndex;
short mIndexData[];
int mIndexCount;
RenderScript mRS;
@@ -548,6 +549,7 @@
public TriangleMeshBuilder(RenderScript rs, int vtxSize, int flags) {
mRS = rs;
mVtxCount = 0;
+ mMaxIndex = 0;
mIndexCount = 0;
mVtxData = new float[128];
mIndexData = new short[128];
@@ -581,11 +583,13 @@
mVtxData[mVtxCount++] = mT0;
}
if ((mFlags & NORMAL) != 0) {
- makeSpace(3);
+ makeSpace(4);
mVtxData[mVtxCount++] = mNX;
mVtxData[mVtxCount++] = mNY;
mVtxData[mVtxCount++] = mNZ;
+ mVtxData[mVtxCount++] = 0.0f;
}
+ mMaxIndex ++;
}
/**
@@ -622,10 +626,11 @@
if (mVtxSize != 3) {
throw new IllegalStateException("add mistmatch with declared components.");
}
- makeSpace(3);
+ makeSpace(4);
mVtxData[mVtxCount++] = x;
mVtxData[mVtxCount++] = y;
mVtxData[mVtxCount++] = z;
+ mVtxData[mVtxCount++] = 1.0f;
latch();
return this;
}
@@ -697,9 +702,9 @@
* @return this
**/
public TriangleMeshBuilder addTriangle(int idx1, int idx2, int idx3) {
- if((idx1 >= mVtxCount) || (idx1 < 0) ||
- (idx2 >= mVtxCount) || (idx2 < 0) ||
- (idx3 >= mVtxCount) || (idx3 < 0)) {
+ if((idx1 >= mMaxIndex) || (idx1 < 0) ||
+ (idx2 >= mMaxIndex) || (idx2 < 0) ||
+ (idx3 >= mMaxIndex) || (idx3 < 0)) {
throw new IllegalStateException("Index provided greater than vertex count.");
}
if ((mIndexCount + 3) >= mIndexData.length) {
@@ -729,20 +734,16 @@
**/
public Mesh create(boolean uploadToBufferObject) {
Element.Builder b = new Element.Builder(mRS);
- int floatCount = mVtxSize;
b.add(Element.createVector(mRS,
Element.DataType.FLOAT_32,
mVtxSize), "position");
if ((mFlags & COLOR) != 0) {
- floatCount += 4;
b.add(Element.F32_4(mRS), "color");
}
if ((mFlags & TEXTURE_0) != 0) {
- floatCount += 2;
b.add(Element.F32_2(mRS), "texture0");
}
if ((mFlags & NORMAL) != 0) {
- floatCount += 3;
b.add(Element.F32_3(mRS), "normal");
}
mElement = b.create();
@@ -753,12 +754,12 @@
}
Builder smb = new Builder(mRS, usage);
- smb.addVertexType(mElement, mVtxCount / floatCount);
+ smb.addVertexType(mElement, mMaxIndex);
smb.addIndexSetType(Element.U16(mRS), mIndexCount, Primitive.TRIANGLE);
Mesh sm = smb.create();
- sm.getVertexAllocation(0).copy1DRangeFromUnchecked(0, mVtxCount / floatCount, mVtxData);
+ sm.getVertexAllocation(0).copy1DRangeFromUnchecked(0, mMaxIndex, mVtxData);
if(uploadToBufferObject) {
if (uploadToBufferObject) {
sm.getVertexAllocation(0).syncAll(Allocation.USAGE_SCRIPT);