Merge "Add error checks to the copyFrom functions." into honeycomb
This commit is contained in:
@@ -121,6 +121,58 @@ public class Allocation extends BaseObj {
|
|||||||
mType = t;
|
mType = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validateIsInt32() {
|
||||||
|
if ((mType.mElement.mType == Element.DataType.SIGNED_32) ||
|
||||||
|
(mType.mElement.mType == Element.DataType.UNSIGNED_32)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new RSIllegalArgumentException(
|
||||||
|
"32 bit integer source does not match allocation type " + mType.mElement.mType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateIsInt16() {
|
||||||
|
if ((mType.mElement.mType == Element.DataType.SIGNED_16) ||
|
||||||
|
(mType.mElement.mType == Element.DataType.UNSIGNED_16)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new RSIllegalArgumentException(
|
||||||
|
"16 bit integer source does not match allocation type " + mType.mElement.mType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateIsInt8() {
|
||||||
|
if ((mType.mElement.mType == Element.DataType.SIGNED_8) ||
|
||||||
|
(mType.mElement.mType == Element.DataType.UNSIGNED_8)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new RSIllegalArgumentException(
|
||||||
|
"8 bit integer source does not match allocation type " + mType.mElement.mType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateIsFloat32() {
|
||||||
|
if (mType.mElement.mType == Element.DataType.FLOAT_32) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new RSIllegalArgumentException(
|
||||||
|
"32 bit float source does not match allocation type " + mType.mElement.mType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateIsObject() {
|
||||||
|
if ((mType.mElement.mType == Element.DataType.RS_ELEMENT) ||
|
||||||
|
(mType.mElement.mType == Element.DataType.RS_TYPE) ||
|
||||||
|
(mType.mElement.mType == Element.DataType.RS_ALLOCATION) ||
|
||||||
|
(mType.mElement.mType == Element.DataType.RS_SAMPLER) ||
|
||||||
|
(mType.mElement.mType == Element.DataType.RS_SCRIPT) ||
|
||||||
|
(mType.mElement.mType == Element.DataType.RS_MESH) ||
|
||||||
|
(mType.mElement.mType == Element.DataType.RS_PROGRAM_FRAGMENT) ||
|
||||||
|
(mType.mElement.mType == Element.DataType.RS_PROGRAM_VERTEX) ||
|
||||||
|
(mType.mElement.mType == Element.DataType.RS_PROGRAM_RASTER) ||
|
||||||
|
(mType.mElement.mType == Element.DataType.RS_PROGRAM_STORE)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new RSIllegalArgumentException(
|
||||||
|
"Object source does not match allocation type " + mType.mElement.mType);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void updateFromNative() {
|
void updateFromNative() {
|
||||||
super.updateFromNative();
|
super.updateFromNative();
|
||||||
@@ -151,6 +203,7 @@ public class Allocation extends BaseObj {
|
|||||||
|
|
||||||
public void copyFrom(BaseObj[] d) {
|
public void copyFrom(BaseObj[] d) {
|
||||||
mRS.validate();
|
mRS.validate();
|
||||||
|
validateIsObject();
|
||||||
if (d.length != mType.getCount()) {
|
if (d.length != mType.getCount()) {
|
||||||
throw new RSIllegalArgumentException("Array size mismatch, allocation sizeX = " +
|
throw new RSIllegalArgumentException("Array size mismatch, allocation sizeX = " +
|
||||||
mType.getCount() + ", array length = " + d.length);
|
mType.getCount() + ", array length = " + d.length);
|
||||||
@@ -258,7 +311,6 @@ public class Allocation extends BaseObj {
|
|||||||
mRS.nAllocationData1D(getID(), xoff, 0, count, data, data.length);
|
mRS.nAllocationData1D(getID(), xoff, 0, count, data, data.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is only intended to be used by auto-generate code reflected from the
|
* This is only intended to be used by auto-generate code reflected from the
|
||||||
* renderscript script files.
|
* renderscript script files.
|
||||||
@@ -317,27 +369,44 @@ public class Allocation extends BaseObj {
|
|||||||
mRS.nAllocationGenerateMipmaps(getID());
|
mRS.nAllocationGenerateMipmaps(getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copy1DRangeFrom(int off, int count, int[] d) {
|
void copy1DRangeFromUnchecked(int off, int count, int[] d) {
|
||||||
int dataSize = mType.mElement.getSizeBytes() * count;
|
int dataSize = mType.mElement.getSizeBytes() * count;
|
||||||
data1DChecks(off, count, d.length * 4, dataSize);
|
data1DChecks(off, count, d.length * 4, dataSize);
|
||||||
mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize);
|
mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize);
|
||||||
}
|
}
|
||||||
public void copy1DRangeFrom(int off, int count, short[] d) {
|
void copy1DRangeFromUnchecked(int off, int count, short[] d) {
|
||||||
int dataSize = mType.mElement.getSizeBytes() * count;
|
int dataSize = mType.mElement.getSizeBytes() * count;
|
||||||
data1DChecks(off, count, d.length * 2, dataSize);
|
data1DChecks(off, count, d.length * 2, dataSize);
|
||||||
mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize);
|
mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize);
|
||||||
}
|
}
|
||||||
public void copy1DRangeFrom(int off, int count, byte[] d) {
|
void copy1DRangeFromUnchecked(int off, int count, byte[] d) {
|
||||||
int dataSize = mType.mElement.getSizeBytes() * count;
|
int dataSize = mType.mElement.getSizeBytes() * count;
|
||||||
data1DChecks(off, count, d.length, dataSize);
|
data1DChecks(off, count, d.length, dataSize);
|
||||||
mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize);
|
mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize);
|
||||||
}
|
}
|
||||||
public void copy1DRangeFrom(int off, int count, float[] d) {
|
void copy1DRangeFromUnchecked(int off, int count, float[] d) {
|
||||||
int dataSize = mType.mElement.getSizeBytes() * count;
|
int dataSize = mType.mElement.getSizeBytes() * count;
|
||||||
data1DChecks(off, count, d.length * 4, dataSize);
|
data1DChecks(off, count, d.length * 4, dataSize);
|
||||||
mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize);
|
mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void copy1DRangeFrom(int off, int count, int[] d) {
|
||||||
|
validateIsInt32();
|
||||||
|
copy1DRangeFromUnchecked(off, count, d);
|
||||||
|
}
|
||||||
|
public void copy1DRangeFrom(int off, int count, short[] d) {
|
||||||
|
validateIsInt16();
|
||||||
|
copy1DRangeFromUnchecked(off, count, d);
|
||||||
|
}
|
||||||
|
public void copy1DRangeFrom(int off, int count, byte[] d) {
|
||||||
|
validateIsInt8();
|
||||||
|
copy1DRangeFromUnchecked(off, count, d);
|
||||||
|
}
|
||||||
|
public void copy1DRangeFrom(int off, int count, float[] d) {
|
||||||
|
validateIsFloat32();
|
||||||
|
copy1DRangeFromUnchecked(off, count, d);
|
||||||
|
}
|
||||||
|
|
||||||
private void validate2DRange(int xoff, int yoff, int w, int h) {
|
private void validate2DRange(int xoff, int yoff, int w, int h) {
|
||||||
if (xoff < 0 || yoff < 0) {
|
if (xoff < 0 || yoff < 0) {
|
||||||
throw new RSIllegalArgumentException("Offset cannot be negative.");
|
throw new RSIllegalArgumentException("Offset cannot be negative.");
|
||||||
@@ -411,21 +480,25 @@ public class Allocation extends BaseObj {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void copyTo(byte[] d) {
|
public void copyTo(byte[] d) {
|
||||||
|
validateIsInt8();
|
||||||
mRS.validate();
|
mRS.validate();
|
||||||
mRS.nAllocationRead(getID(), d);
|
mRS.nAllocationRead(getID(), d);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copyTo(short[] d) {
|
public void copyTo(short[] d) {
|
||||||
|
validateIsInt16();
|
||||||
mRS.validate();
|
mRS.validate();
|
||||||
mRS.nAllocationRead(getID(), d);
|
mRS.nAllocationRead(getID(), d);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copyTo(int[] d) {
|
public void copyTo(int[] d) {
|
||||||
|
validateIsInt32();
|
||||||
mRS.validate();
|
mRS.validate();
|
||||||
mRS.nAllocationRead(getID(), d);
|
mRS.nAllocationRead(getID(), d);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copyTo(float[] d) {
|
public void copyTo(float[] d) {
|
||||||
|
validateIsFloat32();
|
||||||
mRS.validate();
|
mRS.validate();
|
||||||
mRS.nAllocationRead(getID(), d);
|
mRS.nAllocationRead(getID(), d);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -733,14 +733,14 @@ public class Mesh extends BaseObj {
|
|||||||
|
|
||||||
Mesh sm = smb.create();
|
Mesh sm = smb.create();
|
||||||
|
|
||||||
sm.getVertexAllocation(0).copyFrom(mVtxData);
|
sm.getVertexAllocation(0).copy1DRangeFromUnchecked(0, mVtxCount / floatCount, mVtxData);
|
||||||
if(uploadToBufferObject) {
|
if(uploadToBufferObject) {
|
||||||
if (uploadToBufferObject) {
|
if (uploadToBufferObject) {
|
||||||
sm.getVertexAllocation(0).syncAll(Allocation.USAGE_SCRIPT);
|
sm.getVertexAllocation(0).syncAll(Allocation.USAGE_SCRIPT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sm.getIndexSetAllocation(0).copyFrom(mIndexData);
|
sm.getIndexSetAllocation(0).copy1DRangeFromUnchecked(0, mIndexCount, mIndexData);
|
||||||
if (uploadToBufferObject) {
|
if (uploadToBufferObject) {
|
||||||
sm.getIndexSetAllocation(0).syncAll(Allocation.USAGE_SCRIPT);
|
sm.getIndexSetAllocation(0).syncAll(Allocation.USAGE_SCRIPT);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -280,9 +280,10 @@ public class ProgramFragmentFixedFunction extends ProgramFragment {
|
|||||||
pf.mTextureCount = MAX_TEXTURE;
|
pf.mTextureCount = MAX_TEXTURE;
|
||||||
if (!mVaryingColorEnable) {
|
if (!mVaryingColorEnable) {
|
||||||
Allocation constantData = Allocation.createTyped(mRS,constType);
|
Allocation constantData = Allocation.createTyped(mRS,constType);
|
||||||
float[] data = new float[4];
|
FieldPacker fp = new FieldPacker(16);
|
||||||
data[0] = data[1] = data[2] = data[3] = 1.0f;
|
Float4 f4 = new Float4(1.f, 1.f, 1.f, 1.f);
|
||||||
constantData.copyFrom(data);
|
fp.addF32(f4);
|
||||||
|
constantData.setFromFieldPacker(0, fp);
|
||||||
pf.bindConstants(constantData, 0);
|
pf.bindConstants(constantData, 0);
|
||||||
}
|
}
|
||||||
return pf;
|
return pf;
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ public class ProgramVertexFixedFunction extends ProgramVertex {
|
|||||||
for(int i = 0; i < 16; i ++) {
|
for(int i = 0; i < 16; i ++) {
|
||||||
mIOBuffer.addF32(m.mMat[i]);
|
mIOBuffer.addF32(m.mMat[i]);
|
||||||
}
|
}
|
||||||
mAlloc.copyFrom(mIOBuffer.getData());
|
mAlloc.setFromFieldPacker(0, mIOBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user