mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +00:00
Index and vertex buffer allocators
This commit is contained in:
parent
a03d1a571c
commit
0df61f3057
2 changed files with 90 additions and 0 deletions
42
v3/src/renderer/webgl/utils/IndexBuffer.js
Normal file
42
v3/src/renderer/webgl/utils/IndexBuffer.js
Normal file
|
@ -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;
|
48
v3/src/renderer/webgl/utils/VertexBuffer.js
Normal file
48
v3/src/renderer/webgl/utils/VertexBuffer.js
Normal file
|
@ -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;
|
Loading…
Reference in a new issue