Webgl buffer / add utility getSize function
Saves checking whether the buffer was initialized with an array already
This commit is contained in:
@@ -344,7 +344,7 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
|
||||
* @inheritDoc
|
||||
*/
|
||||
renderFrame(frameState) {
|
||||
const renderCount = this.indicesBuffer_.getArray() ? this.indicesBuffer_.getArray().length : 0;
|
||||
const renderCount = this.indicesBuffer_.getSize();
|
||||
this.helper.drawElements(0, renderCount);
|
||||
this.helper.finalizeDraw(frameState);
|
||||
const canvas = this.helper.getCanvas();
|
||||
@@ -561,7 +561,7 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
|
||||
this.helper.enableAttributeArray(DefaultAttrib.ROTATE_WITH_VIEW, 1, FLOAT, bytesPerFloat * stride, bytesPerFloat * 7);
|
||||
this.helper.enableAttributeArray(DefaultAttrib.COLOR, 4, FLOAT, bytesPerFloat * stride, bytesPerFloat * 8);
|
||||
|
||||
const renderCount = this.indicesBuffer_.getArray() ? this.indicesBuffer_.getArray().length : 0;
|
||||
const renderCount = this.indicesBuffer_.getSize();
|
||||
this.helper.drawElements(0, renderCount);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ class WebGLArrayBuffer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Will return null if the buffer was not initialized
|
||||
* @return {Float32Array|Uint32Array} Array.
|
||||
*/
|
||||
getArray() {
|
||||
@@ -107,6 +108,14 @@ class WebGLArrayBuffer {
|
||||
getUsage() {
|
||||
return this.usage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will return 0 if the buffer is not initialized
|
||||
* @return {number} Array size
|
||||
*/
|
||||
getSize() {
|
||||
return this.array ? this.array.length : 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -75,4 +75,21 @@ describe('ol.webgl.Buffer', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#getSize', function() {
|
||||
let b;
|
||||
beforeEach(function() {
|
||||
b = new WebGLArrayBuffer(ARRAY_BUFFER);
|
||||
});
|
||||
|
||||
it('returns 0 when the buffer array is not initialized', function() {
|
||||
expect(b.getSize()).to.be(0);
|
||||
});
|
||||
|
||||
it('returns the size of the array otherwise', function() {
|
||||
b.ofSize(12);
|
||||
expect(b.getSize()).to.be(12);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user