mirror of
https://github.com/photonstorm/phaser
synced 2024-11-25 22:20:44 +00:00
Fix buffer initialization issues.
Support dynamic index buffer creation. Fix config handling.
This commit is contained in:
parent
19f47ff10c
commit
ff4980d85d
4 changed files with 34 additions and 8 deletions
|
@ -168,7 +168,7 @@ var BatchHandler = new Class({
|
|||
*/
|
||||
this.indexBuffer = renderer.createIndexBuffer(
|
||||
this._generateElementIndices(this.instancesPerBatch),
|
||||
gl.STATIC_DRAW
|
||||
config.indexBufferDynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW
|
||||
);
|
||||
|
||||
// Prepare the vertex buffer layout.
|
||||
|
@ -287,6 +287,7 @@ var BatchHandler = new Class({
|
|||
newConfig.indicesPerInstance = config.indicesPerInstance || defaultConfig.indicesPerInstance;
|
||||
newConfig.vertexSource = config.vertexSource || defaultConfig.vertexSource;
|
||||
newConfig.fragmentSource = config.fragmentSource || defaultConfig.fragmentSource;
|
||||
newConfig.indexBufferDynamic = config.indexBufferDynamic || defaultConfig.indexBufferDynamic;
|
||||
|
||||
// These may be left undefined to auto-calculate instance count.
|
||||
newConfig.instancesPerBatch = config.instancesPerBatch;
|
||||
|
|
|
@ -119,7 +119,7 @@ var BatchHandlerQuadLight = new Class({
|
|||
|
||||
_copyAndCompleteConfig: function (manager, config, defaultConfig)
|
||||
{
|
||||
var newConfig = BatchHandlerQuad.prototype._copyAndCompleteConfig.call(this, config, defaultConfig);
|
||||
var newConfig = BatchHandlerQuad.prototype._copyAndCompleteConfig.call(this, manager, config, defaultConfig);
|
||||
|
||||
newConfig.fragmentSource = newConfig.fragmentSource.replace(
|
||||
'%LIGHT_COUNT%',
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* @property {number} [verticesPerInstance=4] - The number of unique vertices per instance. This is usually 4 for a quad.
|
||||
* @property {number} [indicesPerInstance=6] - The number of indices per instance. This is used to populate and advance the element buffer. Default quads use 6 indices in the TRIANGLE_STRIP pattern [0, 0, 1, 2, 3, 3] to connect independent quads with degenerate topology. The minimum number is 3.
|
||||
* @property {number} [maxTexturesPerBatch] - The maximum number of textures per batch entry. This defaults to the maximum number of textures supported by the renderer. It is used to compile the shader program. At runtime, the manager may suggest a different number, which is interpreted by the node's `updateTextureCount` method.
|
||||
* @property {boolean} [indexBufferDynamic=false] - Whether the index buffer should be created as a dynamic buffer. This is useful for handlers that need to change the index data frequently.
|
||||
* @property {string} [vertexSource] - The vertex shader source code. If not provided, a default quad shader will be used.
|
||||
* @property {string} [fragmentSource] - The fragment shader source code. If not provided, a default quad shader will be used. The fragment shader will be compiled
|
||||
* @property {Partial<Phaser.Types.Renderer.WebGL.WebGLAttributeBufferLayout>} [vertexBufferLayout] - The vertex buffer layout for the batch handler. If not provided, a default quad layout will be used. The `count` property will be determined by the `instancesPerBatch` and `verticesPerInstance` properties. The `location` and `bytes` properties of each attribute will be determined automatically during initialization.
|
||||
|
|
|
@ -68,11 +68,19 @@ var WebGLBufferWrapper = new Class({
|
|||
/**
|
||||
* A Float32Array view of the dataBuffer.
|
||||
*
|
||||
* This will be `null` if the byte length of the dataBuffer
|
||||
* is not divisible by Float32Array.BYTES_PER_ELEMENT (4).
|
||||
* Such a buffer is only suited for use with 16-bit indices.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.Wrappers.WebGLBufferWrapper#viewF32
|
||||
* @type {Float32Array}
|
||||
* @type {Float32Array | null}
|
||||
* @since 3.90.0
|
||||
*/
|
||||
this.viewF32 = null;
|
||||
if (dataBuffer.byteLength % Float32Array.BYTES_PER_ELEMENT === 0)
|
||||
{
|
||||
this.viewF32 = new Float32Array(dataBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Uint8Array view of the dataBuffer.
|
||||
|
@ -86,20 +94,36 @@ var WebGLBufferWrapper = new Class({
|
|||
/**
|
||||
* A Uint16Array view of the dataBuffer.
|
||||
*
|
||||
* This will be `null` if the byte length of the dataBuffer
|
||||
* is not divisible by Uint16Array.BYTES_PER_ELEMENT (2).
|
||||
* Such a buffer is only suited for use with byte data.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.Wrappers.WebGLBufferWrapper#viewU16
|
||||
* @type {Uint16Array}
|
||||
* @type {Uint16Array | null}
|
||||
* @since 3.90.0
|
||||
*/
|
||||
this.viewU16 = null;
|
||||
if (dataBuffer.byteLength % Uint16Array.BYTES_PER_ELEMENT === 0)
|
||||
{
|
||||
this.viewU16 = new Uint16Array(dataBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Uint32Array view of the dataBuffer.
|
||||
*
|
||||
* This will be `null` if the byte length of the dataBuffer
|
||||
* is not divisible by Uint32Array.BYTES_PER_ELEMENT (4).
|
||||
* Such a buffer is only suited for use with 16-bit indices.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.Wrappers.WebGLBufferWrapper#viewU32
|
||||
* @type {Uint32Array}
|
||||
* @type {Uint32Array | null}
|
||||
* @since 3.90.0
|
||||
*/
|
||||
this.viewU32 = null;
|
||||
if (dataBuffer.byteLength % Uint32Array.BYTES_PER_ELEMENT === 0)
|
||||
{
|
||||
this.viewU32 = new Uint32Array(dataBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of the buffer.
|
||||
|
|
Loading…
Reference in a new issue