Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compressing integer accessors #121

Merged
merged 10 commits into from
Jul 15, 2016
Prev Previous commit
Next Next commit
jsHint
  • Loading branch information
lasalvavida committed Jul 13, 2016
commit f8d4dab08530e6e84111f3e036f4c2142d8e315e
1 change: 0 additions & 1 deletion lib/AccessorReader.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
var Cesium = require('cesium');
var defaultValue = Cesium.defaultValue;
var defined = Cesium.defined;

var byteLengthForComponentType = require('./byteLengthForComponentType');
var getAccessorByteStride = require('./getAccessorByteStride');
Expand Down
207 changes: 204 additions & 3 deletions specs/lib/compressIntegerAccessorsSpec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,204 @@
/**
* Created by rtaglang on 7/13/2016.
*/
'use strict';
var Cesium = require('cesium');
var clone = require('clone');

var WebGLConstants = Cesium.WebGLConstants;

var compressIntegerAccessors = require('../../lib/compressIntegerAccessors');

var cantCompressByte = new Buffer([-1, 0, 1]);
var cantCompressUByte = new Buffer([0, 1, 2]);
var cantCompressIndices = new Buffer(new Uint16Array([1, 2, 3]).buffer);
var cantCompressBigShort = new Buffer(new Uint16Array([0, 1, 65535]).buffer);
var floatToShort = new Buffer(new Float32Array([32767.0, -1.0, 0.0]).buffer);
var floatToByte = new Buffer(new Float32Array([255.0, -1.0, 0.0]).buffer);
var shortToByte = new Buffer(new Uint16Array([-2, 0, 2]).buffer);
var testGltf = {
accessors : {
cantCompressByte : {
bufferView : 'cantCompressByteBufferView',
byteOffset : 0,
byteStride : 0,
componentType : WebGLConstants.BYTE,
count : 3,
type : "SCALAR"
},
cantCompressUByte : {
bufferView : 'cantCompressUByteBufferView',
byteOffset : 0,
byteStride : 0,
componentType : WebGLConstants.UNSIGNED_BYTE,
count : 3,
type : "SCALAR"
},
cantCompressIndices : {
bufferView : 'cantCompressIndicesBufferView',
byteOffset : 0,
byteStride : 0,
componentType : WebGLConstants.UNSIGNED_SHORT,
count : 3,
type : "SCALAR"
},
cantCompressBigShort : {
bufferView : 'cantCompressBigShortBufferView',
byteOffset : 0,
byteStride : 0,
componentType : WebGLConstants.UNSIGNED_SHORT,
count : 3,
type : "SCALAR"
},
floatToShort : {
bufferView : 'floatToShortBufferView',
byteOffset : 0,
byteStride : 0,
componentType : WebGLConstants.FLOAT,
count : 3,
type : "SCALAR"
},
floatToByte : {
bufferView : 'floatToByteBufferView',
byteOffset : 0,
byteStride : 0,
componentType : WebGLConstants.FLOAT,
count : 3,
type : "SCALAR"
},
shortToByte : {
bufferView : 'shortToByteBufferView',
byteOffset : 0,
byteStride : 0,
componentType : WebGLConstants.SHORT,
count : 3,
type : "SCALAR"
}
},
bufferViews : {
cantCompressByteBufferView : {
buffer : 'cantCompressByteBuffer',
byteOffset : 0,
byteLength : cantCompressByte.length,
target : WebGLConstants.ARRAY_BUFFER
},
cantCompressUByteBufferView : {
buffer : 'cantCompressUByteBuffer',
byteOffset : 0,
byteLength : cantCompressUByte.length,
target : WebGLConstants.ARRAY_BUFFER
},
cantCompressIndicesBufferView : {
buffer : 'cantCompressIndicesBuffer',
byteOffset : 0,
byteLength : cantCompressIndices.length,
target : WebGLConstants.ELEMENT_ARRAY_BUFFER
},
cantCompressBigShortBufferView : {
buffer : 'cantCompressBigShortBuffer',
byteOffset : 0,
byteLength : cantCompressBigShort.length,
target : WebGLConstants.ARRAY_BUFFER
},
floatToShortBufferView : {
buffer : 'floatToShortBuffer',
byteOffset : 0,
byteLength : floatToShort.length,
target : WebGLConstants.ARRAY_BUFFER
},
floatToByteBufferView : {
buffer : 'floatToByteBuffer',
byteOffset : 0,
byteLength : floatToByte.length,
target : WebGLConstants.ARRAY_BUFFER
},
shortToByteBufferView : {
buffer : 'shortToByteBuffer',
byteOffset : 0,
byteLength : shortToByte.length,
target : WebGLConstants.ARRAY_BUFFER
}
},
buffers : {
cantCompressByteBuffer : {
byteLength : cantCompressByte.length,
extras : {
_pipeline : {
source : cantCompressByte
}
},
type : "arraybuffer"
},
cantCompressUByteBuffer : {
byteLength : cantCompressUByte.length,
extras : {
_pipeline : {
source : cantCompressUByte
}
},
type : "arraybuffer"
},
cantCompressIndicesBuffer : {
byteLength : cantCompressIndices.length,
extras : {
_pipeline : {
source : cantCompressIndices
}
},
type : "arraybuffer"
},
cantCompressBigShortBuffer : {
byteLength : cantCompressBigShort.length,
extras : {
_pipeline : {
source : cantCompressBigShort
}
},
type : "arraybuffer"
},
floatToShortBuffer : {
byteLength : floatToShort.length,
extras : {
_pipeline : {
source : floatToShort
}
},
type : "arraybuffer"
},
floatToByteBuffer : {
byteLength : floatToByte.length,
extras : {
_pipeline : {
source : floatToByte
}
},
type : "arraybuffer"
},
shortToByteBuffer : {
byteLength : shortToByte.length,
extras : {
_pipeline : {
source : shortToByte
}
},
type : "arraybuffer"
}
}
};

describe('compressIntegerAccessors', function() {
it('compresses integer accessors and leaves uncompressible accessors alone', function() {
var gltf = testGltf;
compressIntegerAccessors(gltf);
expect(gltf.accessors.cantCompressByte.componentType === WebGLConstants.BYTE);
expect(gltf.accessors.cantCompressUByte.componentType === WebGLConstants.UNSIGNED_BYTE);
expect(gltf.accessors.cantCompressIndices.componentType === WebGLConstants.UNSIGNED_SHORT);
expect(gltf.accessors.cantCompressBigShort.componentType === WebGLConstants.UNSIGNED_SHORT);

expect(gltf.accessors.floatToShort.componentType === WebGLConstants.UNSIGNED_SHORT);
expect(gltf.buffers.floatToShortBuffer.extras._pipeline.source.length === 3 * 2);

expect(gltf.accessors.floatToByte.componentType === WebGLConstants.BYTE);
expect(gltf.buffers.floatToByteBuffer.extras._pipeline.source.length === 3);

expect(gltf.accessors.shortToByte.componentType === WebGLConstants.BYTE);
expect(gltf.buffers.floatToByteBuffer.extras._pipeline.source.length === 3);
});
});