diff --git a/v3/src/renderer/webgl/utils/IndexBuffer.js b/v3/src/renderer/webgl/utils/IndexBuffer.js new file mode 100644 index 000000000..95dfce92e --- /dev/null +++ b/v3/src/renderer/webgl/utils/IndexBuffer.js @@ -0,0 +1,42 @@ +var IndexBuffer = function (byteSize) +{ + this.wordLength = 0; + this.wordCapacity = byteSize / 2; + this.buffer = new ArrayBuffer(byteSize); + this.shortView = new Int16Array(this.buffer); + this.wordView = new Uint16Array(this.buffer); +}; + +IndexBuffer.prototype.clear = function () +{ + this.wordLength = 0; +}; + +IndexBuffer.prototype.getByteLength = function () +{ + return this.wordLength * 2; +}; + +IndexBuffer.prototype.getByteCapacity = function () +{ + return this.buffer.byteLength; +}; + +IndexBuffer.prototype.allocate = function (wordSize) +{ + var currentLength = this.wordLength; + this.wordLength += wordSize; + return currentLength; +}; + +IndexBuffer.prototype.getUsedBufferAsShort = function () +{ + return this.shortView.subarray(0, this.dwordLength); +}; + +IndexBuffer.prototype.getUsedBufferAsWord = function () +{ + return this.wordView.subarray(0, this.dwordLength); +}; + +module.exports = IndexBuffer; diff --git a/v3/src/renderer/webgl/utils/VertexBuffer.js b/v3/src/renderer/webgl/utils/VertexBuffer.js new file mode 100644 index 000000000..13bb4c428 --- /dev/null +++ b/v3/src/renderer/webgl/utils/VertexBuffer.js @@ -0,0 +1,48 @@ +var VertexBuffer = function (byteSize) +{ + this.dwordLength = 0; + this.dwordCapacity = byteSize / 4; + this.buffer = new ArrayBuffer(byteSize); + this.floatView = new Float32Array(this.buffer); + this.intView = new Int32Array(this.buffer); + this.uintView = new Uint32Array(this.buffer); +}; + +VertexBuffer.prototype.clear = function () +{ + this.dwordLength = 0; +}; + +VertexBuffer.prototype.getByteLength = function () +{ + return this.dwordLength * 4; +}; + +VertexBuffer.prototype.getByteCapacity = function () +{ + return this.buffer.byteLength; +}; + +VertexBuffer.prototype.allocate = function (dwordSize) +{ + var currentLength = this.dwordLength; + this.dwordLength += dwordSize; + return currentLength; +}; + +VertexBuffer.prototype.getUsedBufferAsFloat = function () +{ + return this.floatView.subarray(0, this.dwordLength); +}; + +VertexBuffer.prototype.getUsedBufferAsInt = function () +{ + return this.intView.subarray(0, this.dwordLength); +}; + +VertexBuffer.prototype.getUsedBufferAsUint = function () +{ + return this.uintView.subarray(0, this.dwordLength); +}; + +module.exports = VertexBuffer;