2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2018-04-05 08:02:36 +00:00
|
|
|
* @author Felipe Alfonso <@bitnenfer>
|
2020-01-15 12:07:09 +00:00
|
|
|
* @copyright 2020 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2018-01-10 20:03:01 +00:00
|
|
|
var Class = require('../../utils/Class');
|
2020-08-21 15:03:07 +00:00
|
|
|
var GetFastValue = require('../../utils/object/GetFastValue');
|
2020-10-26 14:05:39 +00:00
|
|
|
var Matrix4 = require('../../math/Matrix4');
|
2018-01-22 22:51:15 +00:00
|
|
|
var Utils = require('./Utils');
|
2020-10-21 17:15:02 +00:00
|
|
|
var WebGLShader = require('./WebGLShader');
|
2018-01-09 01:34:45 +00:00
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
2020-08-21 15:03:07 +00:00
|
|
|
* The `WebGLPipeline` is a base class used by all of the core Phaser pipelines.
|
2018-09-10 01:05:29 +00:00
|
|
|
*
|
2020-08-21 15:03:07 +00:00
|
|
|
* It describes the way elements will be rendered in WebGL. Internally, it handles
|
2020-10-21 10:19:12 +00:00
|
|
|
* compiling the shaders, creating vertex buffers, assigning primitive topology and
|
2020-08-21 15:03:07 +00:00
|
|
|
* binding vertex attributes, all based on the given configuration data.
|
|
|
|
*
|
|
|
|
* The pipeline is configured by passing in a `WebGLPipelineConfig` object. Please
|
|
|
|
* see the documentation for this type to fully understand the configuration options
|
|
|
|
* available to you.
|
|
|
|
*
|
|
|
|
* Usually, you would not extend from this class directly, but would instead extend
|
2020-10-21 17:15:02 +00:00
|
|
|
* from one of the core pipelines, such as the Multi Pipeline.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @class WebGLPipeline
|
2018-10-10 09:49:13 +00:00
|
|
|
* @memberof Phaser.Renderer.WebGL
|
2018-02-09 19:19:21 +00:00
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-08-21 15:03:07 +00:00
|
|
|
* @param {Phaser.Types.Renderer.WebGL.WebGLPipelineConfig} config - The configuration object for this WebGL Pipeline.
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
var WebGLPipeline = new Class({
|
2018-01-09 01:34:45 +00:00
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
initialize:
|
2018-01-10 20:03:01 +00:00
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
function WebGLPipeline (config)
|
2018-01-10 20:03:01 +00:00
|
|
|
{
|
2020-08-21 15:03:07 +00:00
|
|
|
var game = config.game;
|
|
|
|
var renderer = game.renderer;
|
|
|
|
var gl = renderer.gl;
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2020-10-21 17:15:02 +00:00
|
|
|
* Name of the pipeline. Used for identification and setting from Game Objects.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#name
|
|
|
|
* @type {string}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2020-08-21 15:03:07 +00:00
|
|
|
this.name = GetFastValue(config, 'name', 'WebGLPipeline');
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-21 15:03:07 +00:00
|
|
|
* The Phaser Game instance to which this pipeline is bound.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#game
|
|
|
|
* @type {Phaser.Game}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2020-08-21 15:03:07 +00:00
|
|
|
this.game = game;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The WebGL Renderer instance to which this pipeline is bound.
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#renderer
|
|
|
|
* @type {Phaser.Renderer.WebGL.WebGLRenderer}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.renderer = renderer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The WebGL context this WebGL Pipeline uses.
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#gl
|
|
|
|
* @type {WebGLRenderingContext}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.gl = gl;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-10-22 11:12:31 +00:00
|
|
|
* The canvas which this WebGL Pipeline renders to.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#view
|
|
|
|
* @type {HTMLCanvasElement}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2020-08-21 15:03:07 +00:00
|
|
|
this.view = game.canvas;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-21 15:03:07 +00:00
|
|
|
* Width of the current viewport.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#width
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2019-01-11 16:44:08 +00:00
|
|
|
this.width = 0;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-21 15:03:07 +00:00
|
|
|
* Height of the current viewport.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#height
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2019-01-11 16:44:08 +00:00
|
|
|
this.height = 0;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-21 15:03:07 +00:00
|
|
|
* The current number of vertices that have been added to the pipeline batch.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#vertexCount
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-10 20:03:01 +00:00
|
|
|
this.vertexCount = 0;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-21 15:03:07 +00:00
|
|
|
* The total number of vertices that the pipeline batch can hold before it will flush.
|
|
|
|
* This defaults to `batchSize * 6`, where `batchSize` is defined in the Renderer Config.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#vertexCapacity
|
|
|
|
* @type {integer}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2020-08-21 15:03:07 +00:00
|
|
|
this.vertexCapacity = GetFastValue(config, 'vertexCapacity', renderer.config.batchSize * 6);
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2020-09-18 15:38:26 +00:00
|
|
|
* The size, in bytes, of a single vertex.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2020-09-18 15:38:26 +00:00
|
|
|
* This is derived by adding together all of the vertex attributes.
|
2020-08-21 15:03:07 +00:00
|
|
|
*
|
2020-09-18 15:38:26 +00:00
|
|
|
* For example, the Multi Pipeline has the following attributes:
|
|
|
|
*
|
|
|
|
* inPosition - (size 2 x gl.FLOAT) = 8
|
|
|
|
* inTexCoord - (size 2 x gl.FLOAT) = 8
|
|
|
|
* inTexId - (size 1 x gl.FLOAT) = 4
|
|
|
|
* inTintEffect - (size 1 x gl.FLOAT) = 4
|
|
|
|
* inTint - (size 4 x gl.UNSIGNED_BYTE) = 4
|
|
|
|
*
|
|
|
|
* The total is 8 + 8 + 4 + 4 + 4 = 28, which is the default for this property.
|
2020-08-21 15:03:07 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* Other pipelines may require different totals. Use the config property to set it, as it can't be changed post-creation.
|
|
|
|
*
|
2020-08-21 15:03:07 +00:00
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#vertexSize
|
|
|
|
* @type {integer}
|
2020-10-21 17:15:02 +00:00
|
|
|
* @readonly
|
2018-02-09 19:19:21 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2020-08-21 15:03:07 +00:00
|
|
|
this.vertexSize = GetFastValue(config, 'vertexSize', 28);
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-25 22:52:20 +00:00
|
|
|
* Raw byte buffer of vertices.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* Either set via the config object, or generates a new Array Buffer of size `vertexCapacity * vertexSize`.
|
|
|
|
*
|
2018-02-09 19:19:21 +00:00
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#vertexData
|
2018-02-13 00:12:17 +00:00
|
|
|
* @type {ArrayBuffer}
|
2020-10-21 17:15:02 +00:00
|
|
|
* @readonly
|
2018-02-09 19:19:21 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2020-08-21 15:03:07 +00:00
|
|
|
this.vertexData = GetFastValue(config, 'vertices', new ArrayBuffer(this.vertexCapacity * this.vertexSize));
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-21 15:03:07 +00:00
|
|
|
* The WebGLBuffer that holds the vertex data.
|
2020-10-21 10:30:49 +00:00
|
|
|
*
|
2020-08-21 15:03:07 +00:00
|
|
|
* Created from the `vertices` config ArrayBuffer that was passed in, or set by default, by the pipeline.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#vertexBuffer
|
2018-02-13 00:12:17 +00:00
|
|
|
* @type {WebGLBuffer}
|
2020-10-21 17:15:02 +00:00
|
|
|
* @readonly
|
2018-02-09 19:19:21 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2020-09-07 15:03:36 +00:00
|
|
|
if (GetFastValue(config, 'vertices', null))
|
|
|
|
{
|
|
|
|
this.vertexBuffer = this.renderer.createVertexBuffer(this.vertexData, this.gl.STREAM_DRAW);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.vertexBuffer = this.renderer.createVertexBuffer(this.vertexData.byteLength, this.gl.STREAM_DRAW);
|
|
|
|
}
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2020-07-16 02:12:53 +00:00
|
|
|
* The primitive topology which the pipeline will use to submit draw calls.
|
2020-10-21 17:15:02 +00:00
|
|
|
*
|
|
|
|
* Defaults to GL_TRIANGLES if not otherwise set in the config.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#topology
|
2020-08-21 15:03:07 +00:00
|
|
|
* @type {GLenum}
|
2018-02-09 19:19:21 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2020-08-21 15:03:07 +00:00
|
|
|
this.topology = GetFastValue(config, 'topology', gl.TRIANGLES);
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-21 17:15:02 +00:00
|
|
|
* Uint8 view to the `vertexData` ArrayBuffer. Used for uploading vertex buffer resources to the GPU.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#bytes
|
|
|
|
* @type {Uint8Array}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-22 21:21:47 +00:00
|
|
|
this.bytes = new Uint8Array(this.vertexData);
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-21 17:15:02 +00:00
|
|
|
* Indicates if the current pipeline is active, or not, for this frame only.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* Reset to `true` in the `onRender` method.
|
2018-05-31 15:57:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#active
|
|
|
|
* @type {boolean}
|
|
|
|
* @since 3.10.0
|
|
|
|
*/
|
|
|
|
this.active = false;
|
2020-07-16 14:16:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Holds the most recently assigned texture unit.
|
2020-10-21 17:15:02 +00:00
|
|
|
|
2020-07-16 14:16:17 +00:00
|
|
|
* Treat this value as read-only.
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.Pipelines.WebGLPipeline#currentUnit
|
|
|
|
* @type {number}
|
2020-07-31 12:41:29 +00:00
|
|
|
* @since 3.50.0
|
2020-07-16 14:16:17 +00:00
|
|
|
*/
|
|
|
|
this.currentUnit = 0;
|
2020-07-17 12:55:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Some pipelines require the forced use of texture zero (like the light pipeline).
|
2020-10-21 17:15:02 +00:00
|
|
|
*
|
|
|
|
* This property should be set when that is the case.
|
2020-07-17 12:55:39 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#forceZero
|
|
|
|
* @type {boolean}
|
2020-07-31 12:41:29 +00:00
|
|
|
* @since 3.50.0
|
2020-07-17 12:55:39 +00:00
|
|
|
*/
|
|
|
|
this.forceZero = false;
|
2020-08-20 09:47:21 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-21 17:15:02 +00:00
|
|
|
* Indicates if this pipeline has booted or not.
|
|
|
|
*
|
|
|
|
* A pipeline boots only when the Game instance itself, and all associated systems, is
|
|
|
|
* fully ready.
|
2020-08-20 09:47:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#hasBooted
|
|
|
|
* @type {boolean}
|
|
|
|
* @readonly
|
|
|
|
* @since 3.50.0
|
|
|
|
*/
|
|
|
|
this.hasBooted = false;
|
2020-09-21 13:05:30 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
/**
|
|
|
|
* Array of objects that describe the vertex attributes.
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#attributes
|
|
|
|
* @type {Phaser.Types.Renderer.WebGL.WebGLPipelineAttributesConfig}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.attributes = config.attributes;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The amount of vertex attribute components of 32 bit length.
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#vertexComponentCount
|
|
|
|
* @type {integer}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.vertexComponentCount = Utils.getComponentCount(this.attributes, this.gl);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An array of all the WebGLShader instances that belong to this pipeline.
|
|
|
|
*
|
|
|
|
* All shaders must use the same attributes, as set by this pipeline, but can manage their own
|
|
|
|
* uniforms.
|
|
|
|
*
|
|
|
|
* These are set in a call to the `setShadersFromConfig` method, which happens automatically,
|
|
|
|
* but can also be called at any point in your game. See the method documentation for details.
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#shaders
|
|
|
|
* @type {Phaser.Renderer.WebGL.WebGLShader[]}
|
|
|
|
* @since 3.50.0
|
|
|
|
*/
|
2020-10-26 14:05:39 +00:00
|
|
|
this.shaders = [];
|
2020-10-21 17:15:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A reference to the currently bound WebGLShader instance from the `WebGLPipeline.shaders` array.
|
|
|
|
*
|
|
|
|
* For lots of pipelines, this is the only shader, so it is a quick way to reference it without
|
|
|
|
* an array look-up.
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#currentShader
|
|
|
|
* @type {Phaser.Renderer.WebGL.WebGLShader}
|
|
|
|
* @since 3.50.0
|
|
|
|
*/
|
|
|
|
this.currentShader;
|
|
|
|
|
2020-10-26 14:05:39 +00:00
|
|
|
/**
|
|
|
|
* The Model matrix, used by shaders as 'uModelMatrix' uniform.
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#modelMatrix
|
|
|
|
* @type {Phaser.Math.Matrix4}
|
|
|
|
* @since 3.50.0
|
|
|
|
*/
|
|
|
|
this.modelMatrix = new Matrix4().identity();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The View matrix, used by shaders as 'uViewMatrix' uniform.
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#viewMatrix
|
|
|
|
* @type {Phaser.Math.Matrix4}
|
|
|
|
* @since 3.50.0
|
|
|
|
*/
|
|
|
|
this.viewMatrix = new Matrix4().identity();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Projection matrix, used by shaders as 'uProjectionMatrix' uniform.
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#projectionMatrix
|
|
|
|
* @type {Phaser.Math.Matrix4}
|
|
|
|
* @since 3.50.0
|
|
|
|
*/
|
|
|
|
this.projectionMatrix = new Matrix4().identity();
|
|
|
|
|
2020-10-26 15:00:17 +00:00
|
|
|
/**
|
|
|
|
* A flag indicating if the MVP matrices are dirty, or not.
|
|
|
|
*
|
|
|
|
* Used by WebGLShader when binding the uniforms.
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#mvpDirty
|
|
|
|
* @type {boolean}
|
|
|
|
* @since 3.50.0
|
|
|
|
*/
|
2020-10-26 14:05:39 +00:00
|
|
|
this.mvpDirty = true;
|
|
|
|
|
2020-10-26 15:00:17 +00:00
|
|
|
/**
|
|
|
|
* The configuration object that was used to create this pipeline.
|
|
|
|
*
|
|
|
|
* Treat this object as 'read only', because changing it post-creation will not
|
|
|
|
* impact this pipeline in any way. However, it is used internally for cloning
|
|
|
|
* and post-boot set-up.
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLPipeline#config
|
|
|
|
* @type {Phaser.Types.Renderer.WebGL.WebGLPipelineConfig}
|
|
|
|
* @since 3.50.0
|
|
|
|
*/
|
|
|
|
this.config = config;
|
2018-01-10 20:03:01 +00:00
|
|
|
},
|
|
|
|
|
2018-07-13 10:13:46 +00:00
|
|
|
/**
|
|
|
|
* Called when the Game has fully booted and the Renderer has finished setting up.
|
2018-09-10 01:05:29 +00:00
|
|
|
*
|
2020-10-21 10:30:49 +00:00
|
|
|
* By this stage all Game level systems are now in place. You can perform any final tasks that the
|
|
|
|
* pipeline may need, that relies on game systems such as the Texture Manager being ready.
|
2018-07-13 10:13:46 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLPipeline#boot
|
|
|
|
* @since 3.11.0
|
2020-10-26 14:05:39 +00:00
|
|
|
*/
|
2018-07-13 10:13:46 +00:00
|
|
|
boot: function ()
|
|
|
|
{
|
2020-10-26 15:00:17 +00:00
|
|
|
this.setShadersFromConfig(this.config);
|
2020-07-16 02:12:53 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
this.renderer.setVertexBuffer(this.vertexBuffer);
|
2020-07-16 02:12:53 +00:00
|
|
|
|
2020-08-25 12:24:56 +00:00
|
|
|
this.setAttribPointers(true);
|
2020-07-16 02:12:53 +00:00
|
|
|
|
2020-08-20 09:47:21 +00:00
|
|
|
this.hasBooted = true;
|
|
|
|
|
2020-07-16 02:12:53 +00:00
|
|
|
return this;
|
2018-07-13 10:13:46 +00:00
|
|
|
},
|
2020-10-26 14:05:39 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-26 15:00:17 +00:00
|
|
|
* Resets the model, projection and view matrices to identity matrices.
|
2020-10-26 14:05:39 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLPipeline#mvpInit
|
|
|
|
* @since 3.50.0
|
2020-07-16 14:16:17 +00:00
|
|
|
*/
|
2020-10-26 14:05:39 +00:00
|
|
|
mvpInit: function ()
|
|
|
|
{
|
|
|
|
this.modelMatrix.identity();
|
|
|
|
this.projectionMatrix.identity();
|
|
|
|
this.viewMatrix.identity();
|
|
|
|
},
|
2020-07-16 14:16:17 +00:00
|
|
|
|
2020-10-26 15:00:17 +00:00
|
|
|
/**
|
|
|
|
* Creates a brand new WebGLPipeline instance based on the configuration object that
|
|
|
|
* was used to create this one.
|
|
|
|
*
|
|
|
|
* The new instance is returned by this method. Note that the new instance is _not_
|
|
|
|
* added to the Pipeline Manager. You will need to add it yourself should you require so.
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLPipeline#mvpInit
|
|
|
|
* @since 3.50.0
|
|
|
|
*
|
|
|
|
* @param {string} name - The new name to give the cloned pipeline.
|
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLPipeline} A clone of this WebGLPipeline instance.
|
|
|
|
*/
|
|
|
|
clone: function (name)
|
|
|
|
{
|
|
|
|
var clone = new WebGLPipeline(this.config);
|
|
|
|
|
|
|
|
clone.name = name;
|
|
|
|
|
|
|
|
return clone;
|
|
|
|
},
|
|
|
|
|
2018-03-05 15:28:59 +00:00
|
|
|
/**
|
2020-10-21 17:15:02 +00:00
|
|
|
* Sets the currently active shader within this pipeline.
|
2018-03-05 15:28:59 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.WebGLPipeline#setShader
|
|
|
|
* @since 3.50.0
|
2018-03-05 15:28:59 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @param {number} index - The index of the shader to set.
|
2018-03-05 15:28:59 +00:00
|
|
|
*
|
2018-09-12 14:34:48 +00:00
|
|
|
* @return {this} This WebGLPipeline instance.
|
2018-03-05 15:28:59 +00:00
|
|
|
*/
|
2020-10-21 17:15:02 +00:00
|
|
|
setShader: function (index)
|
2018-03-05 14:29:48 +00:00
|
|
|
{
|
2020-10-21 17:15:02 +00:00
|
|
|
var shader = this.shaders[index];
|
2018-03-05 14:29:48 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
if (shader)
|
|
|
|
{
|
|
|
|
shader.bind();
|
|
|
|
|
|
|
|
this.currentShader = shader;
|
|
|
|
}
|
2020-09-21 13:05:30 +00:00
|
|
|
|
2018-03-05 14:29:48 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2020-10-21 17:15:02 +00:00
|
|
|
* Searches all shaders in this pipeline for one matching the given name, then returns it.
|
2020-09-15 10:54:12 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.WebGLPipeline#getShaderByName
|
|
|
|
* @since 3.50.0
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @param {string} name - The index of the shader to set.
|
2020-09-15 10:54:12 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLShader} The WebGLShader instance, if found.
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2020-10-21 17:15:02 +00:00
|
|
|
getShaderByName: function (name)
|
2018-01-10 20:03:01 +00:00
|
|
|
{
|
2020-10-21 17:15:02 +00:00
|
|
|
var shaders = this.shaders;
|
2020-09-15 10:54:12 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
for (var i = 0; i < shaders.length; i++)
|
|
|
|
{
|
|
|
|
if (shaders[i].name === name)
|
|
|
|
{
|
|
|
|
return shaders[i];
|
|
|
|
}
|
|
|
|
}
|
2018-01-10 20:03:01 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2020-10-21 17:15:02 +00:00
|
|
|
* Destroys all shaders currently set in the `WebGLPipeline.shaders` array and then parses the given
|
|
|
|
* `config` object, extracting the shaders from it, creating `WebGLShader` instances and finally
|
|
|
|
* setting them into the `shaders` array of this pipeline.
|
2020-10-21 10:30:49 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* This is a destructive process. Be very careful when you call it, should you need to.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.WebGLPipeline#setShadersFromConfig
|
|
|
|
* @since 3.50.0
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @param {Phaser.Types.Renderer.WebGL.WebGLPipelineConfig} config - The configuration object for this WebGL Pipeline.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-09-12 14:34:48 +00:00
|
|
|
* @return {this} This WebGLPipeline instance.
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2020-10-21 17:15:02 +00:00
|
|
|
setShadersFromConfig: function (config)
|
2018-01-10 20:03:01 +00:00
|
|
|
{
|
2020-10-21 17:15:02 +00:00
|
|
|
var i;
|
|
|
|
var shaders = this.shaders;
|
2018-09-12 14:34:48 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
for (i = 0; i < shaders.length; i++)
|
|
|
|
{
|
|
|
|
shaders[i].destroy();
|
|
|
|
}
|
2018-01-10 20:03:01 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
var defaultVertShader = GetFastValue(config, 'vertShader', null);
|
|
|
|
var defaultFragShader = GetFastValue(config, 'fragShader', null);
|
|
|
|
var defaultUniforms = GetFastValue(config, 'uniforms', null);
|
|
|
|
|
|
|
|
var configShaders = GetFastValue(config, 'shaders', []);
|
2020-08-25 12:24:56 +00:00
|
|
|
|
2020-10-26 14:05:39 +00:00
|
|
|
var len = configShaders.length;
|
|
|
|
|
|
|
|
if (len === 0)
|
|
|
|
{
|
|
|
|
this.shaders = [ new WebGLShader(this, 'default', defaultVertShader, defaultFragShader, defaultUniforms) ];
|
|
|
|
}
|
|
|
|
else
|
2020-10-21 17:15:02 +00:00
|
|
|
{
|
2020-10-26 14:05:39 +00:00
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
var shaderEntry = configShaders[i];
|
|
|
|
|
|
|
|
var name = GetFastValue(shaderEntry, 'name', 'default');
|
2018-01-10 20:03:01 +00:00
|
|
|
|
2020-10-26 14:05:39 +00:00
|
|
|
var vertShader = GetFastValue(shaderEntry, 'vertShader', defaultVertShader);
|
|
|
|
var fragShader = GetFastValue(shaderEntry, 'fragShader', defaultFragShader);
|
|
|
|
var uniforms = GetFastValue(shaderEntry, 'uniforms', defaultUniforms);
|
2018-01-20 04:05:56 +00:00
|
|
|
|
2020-10-26 14:05:39 +00:00
|
|
|
configShaders.push(new WebGLShader(this, name, vertShader, fragShader, uniforms));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.shaders = configShaders;
|
2020-10-21 17:15:02 +00:00
|
|
|
}
|
|
|
|
|
2020-10-26 14:05:39 +00:00
|
|
|
this.currentShader = this.shaders[0];
|
2020-07-17 12:55:39 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2020-09-21 13:05:30 +00:00
|
|
|
/**
|
2020-10-21 17:15:02 +00:00
|
|
|
* Adds a description of vertex attribute to the pipeline.
|
2020-09-21 13:05:30 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.WebGLPipeline#addAttribute
|
|
|
|
* @since 3.2.0
|
2020-09-21 13:05:30 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @param {string} name - Name of the vertex attribute
|
|
|
|
* @param {integer} size - Vertex component size
|
|
|
|
* @param {integer} type - Type of the attribute
|
|
|
|
* @param {boolean} normalized - Is the value normalized to a range
|
|
|
|
* @param {integer} offset - Byte offset to the beginning of the first element in the vertex
|
2020-09-21 13:05:30 +00:00
|
|
|
*
|
|
|
|
* @return {this} This WebGLPipeline instance.
|
|
|
|
*/
|
2020-10-21 17:15:02 +00:00
|
|
|
addAttribute: function (name, size, type, normalized, offset)
|
2020-09-21 13:05:30 +00:00
|
|
|
{
|
2020-10-21 17:15:02 +00:00
|
|
|
this.attributes.push({
|
|
|
|
name: name,
|
|
|
|
size: size,
|
|
|
|
type: this.renderer.glFormats[type],
|
|
|
|
normalized: normalized,
|
|
|
|
offset: offset,
|
|
|
|
enabled: false,
|
|
|
|
location: -1
|
|
|
|
});
|
2020-09-21 13:05:30 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
this.vertexComponentCount = Utils.getComponentCount(this.attributes, this.gl);
|
2020-09-21 13:05:30 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2020-07-17 12:55:39 +00:00
|
|
|
/**
|
|
|
|
* Sets the vertex attribute pointers.
|
2020-10-21 10:30:49 +00:00
|
|
|
*
|
2020-07-17 12:55:39 +00:00
|
|
|
* This should only be called after the vertex buffer has been bound.
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLPipeline#setAttribPointers
|
2020-07-31 12:41:29 +00:00
|
|
|
* @since 3.50.0
|
2020-07-17 12:55:39 +00:00
|
|
|
*
|
2020-08-25 12:24:56 +00:00
|
|
|
* @param {boolean} [reset=false] - Reset the vertex attribute locations?
|
|
|
|
*
|
2020-07-17 12:55:39 +00:00
|
|
|
* @return {this} This WebGLPipeline instance.
|
|
|
|
*/
|
2020-08-25 12:24:56 +00:00
|
|
|
setAttribPointers: function (reset)
|
2020-07-17 12:55:39 +00:00
|
|
|
{
|
2020-08-25 12:24:56 +00:00
|
|
|
if (reset === undefined) { reset = false; }
|
|
|
|
|
2020-07-17 12:55:39 +00:00
|
|
|
var gl = this.gl;
|
|
|
|
var attributes = this.attributes;
|
|
|
|
var vertexSize = this.vertexSize;
|
2020-10-21 17:15:02 +00:00
|
|
|
var program = this.currentShader.program;
|
2020-07-17 12:55:39 +00:00
|
|
|
|
2020-07-16 02:12:53 +00:00
|
|
|
for (var i = 0; i < attributes.length; i++)
|
2018-01-20 04:05:56 +00:00
|
|
|
{
|
2020-07-16 02:12:53 +00:00
|
|
|
var element = attributes[i];
|
2018-01-20 04:05:56 +00:00
|
|
|
|
2020-08-25 12:24:56 +00:00
|
|
|
if (reset)
|
|
|
|
{
|
|
|
|
var location = gl.getAttribLocation(program, element.name);
|
|
|
|
|
|
|
|
if (location >= 0)
|
|
|
|
{
|
|
|
|
gl.enableVertexAttribArray(location);
|
|
|
|
gl.vertexAttribPointer(location, element.size, element.type, element.normalized, vertexSize, element.offset);
|
|
|
|
element.enabled = true;
|
|
|
|
element.location = location;
|
|
|
|
}
|
|
|
|
else if (location !== -1)
|
|
|
|
{
|
|
|
|
gl.disableVertexAttribArray(location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (element.enabled)
|
2018-01-20 04:05:56 +00:00
|
|
|
{
|
2020-07-16 02:12:53 +00:00
|
|
|
gl.vertexAttribPointer(element.location, element.size, element.type, element.normalized, vertexSize, element.offset);
|
2018-01-20 04:05:56 +00:00
|
|
|
}
|
2020-07-16 02:12:53 +00:00
|
|
|
else if (!element.enabled && element.location > -1)
|
2018-01-20 04:05:56 +00:00
|
|
|
{
|
2020-07-16 02:12:53 +00:00
|
|
|
gl.disableVertexAttribArray(element.location);
|
|
|
|
element.location = -1;
|
2018-01-20 04:05:56 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-10 20:03:01 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2020-10-21 17:15:02 +00:00
|
|
|
* Custom pipelines can use this method in order to perform any required pre-batch tasks
|
|
|
|
* for the given Game Object. It must return the texture unit the Game Object was assigned.
|
2020-09-21 13:05:30 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.Pipelines.WebGLPipeline#setGameObject
|
2020-09-21 13:05:30 +00:00
|
|
|
* @since 3.50.0
|
2018-03-05 15:28:59 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object being rendered or added to the batch.
|
|
|
|
* @param {Phaser.Textures.Frame} [frame] - Optional frame to use. Can override that of the Game Object.
|
2018-03-05 15:28:59 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @return {number} The texture unit the Game Object has been assigned.
|
2018-03-05 15:28:59 +00:00
|
|
|
*/
|
2020-10-21 17:15:02 +00:00
|
|
|
setGameObject: function (gameObject, frame)
|
2018-03-05 14:29:48 +00:00
|
|
|
{
|
2020-10-21 17:15:02 +00:00
|
|
|
if (frame === undefined) { frame = gameObject.frame; }
|
2018-03-05 14:29:48 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
this.currentUnit = this.renderer.setTextureSource(frame.source);
|
2018-08-07 15:26:22 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
return this.currentUnit;
|
2018-03-05 14:29:48 +00:00
|
|
|
},
|
|
|
|
|
2018-09-10 01:05:29 +00:00
|
|
|
/**
|
2020-10-21 17:15:02 +00:00
|
|
|
* Check if the current batch of vertices is full.
|
2018-09-10 01:05:29 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* You can optionally provide an `amount` parameter. If given, it will check if the batch
|
|
|
|
* needs to flush _if_ the `amount` is added to it. This allows you to test if you should
|
|
|
|
* flush before populating the batch.
|
2018-09-10 01:05:29 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.WebGLPipeline#shouldFlush
|
|
|
|
* @since 3.0.0
|
2020-09-21 13:05:30 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @param {integer} [amount=0] - Will the batch need to flush if this many vertices are added to it?
|
2018-09-10 01:05:29 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @return {boolean} `true` if the current batch should be flushed, otherwise `false`.
|
2018-09-10 01:05:29 +00:00
|
|
|
*/
|
2020-10-21 17:15:02 +00:00
|
|
|
shouldFlush: function (amount)
|
2018-09-10 01:05:29 +00:00
|
|
|
{
|
2020-10-21 17:15:02 +00:00
|
|
|
if (amount === undefined) { amount = 0; }
|
2018-09-10 01:05:29 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
return (this.vertexCount + amount >= this.vertexCapacity);
|
2018-09-10 01:05:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2020-10-21 17:15:02 +00:00
|
|
|
* Resizes the properties used to describe the viewport.
|
2018-09-10 01:05:29 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* This method is called automatically by the renderer during its resize handler.
|
2020-09-21 13:05:30 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.WebGLPipeline#resize
|
|
|
|
* @since 3.0.0
|
2018-09-10 01:05:29 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @param {number} width - The new width of this WebGL Pipeline.
|
|
|
|
* @param {number} height - The new height of this WebGL Pipeline.
|
2018-09-10 01:05:29 +00:00
|
|
|
*
|
2018-09-12 14:34:48 +00:00
|
|
|
* @return {this} This WebGLPipeline instance.
|
2018-09-10 01:05:29 +00:00
|
|
|
*/
|
2020-10-21 17:15:02 +00:00
|
|
|
resize: function (width, height)
|
2018-09-10 01:05:29 +00:00
|
|
|
{
|
2020-10-21 17:15:02 +00:00
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
2018-09-10 01:05:29 +00:00
|
|
|
|
2020-10-26 14:05:39 +00:00
|
|
|
this.projectionMatrix.ortho(0, width, height, 0, -1000, 1000);
|
|
|
|
|
|
|
|
this.mvpDirty = true;
|
|
|
|
|
2018-09-10 01:05:29 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2020-10-21 17:15:02 +00:00
|
|
|
* Binds the pipeline resources, including the give shader, vertex buffer and attribute pointers.
|
2018-09-10 01:05:29 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* This method is called every time this pipeline is made the current active pipeline.
|
2018-09-10 01:05:29 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.WebGLPipeline#bind
|
|
|
|
* @since 3.0.0
|
2020-09-21 13:05:30 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @param {boolean} [reset=false] - Should the pipeline be fully re-bound after a renderer pipeline clear?
|
|
|
|
* @param {number} [shader=0] - If this is a multi-shader pipeline, which shader should be bound?
|
2018-09-10 01:05:29 +00:00
|
|
|
*
|
2018-09-12 14:34:48 +00:00
|
|
|
* @return {this} This WebGLPipeline instance.
|
2018-09-10 01:05:29 +00:00
|
|
|
*/
|
2020-10-21 17:15:02 +00:00
|
|
|
bind: function (reset, shader)
|
2018-09-10 01:05:29 +00:00
|
|
|
{
|
2020-10-21 17:15:02 +00:00
|
|
|
if (reset === undefined) { reset = false; }
|
2018-09-10 01:05:29 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
if (shader !== undefined)
|
|
|
|
{
|
|
|
|
this.setShader(shader);
|
|
|
|
}
|
2018-09-10 01:05:29 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
this.currentShader.bind();
|
2018-09-10 01:05:29 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
this.renderer.setVertexBuffer(this.vertexBuffer);
|
2018-09-10 01:05:29 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
this.setAttribPointers(reset);
|
2020-09-21 13:05:30 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2020-10-21 17:15:02 +00:00
|
|
|
* This method is called every time a **Game Object** asks the Pipeline Manager to use this pipeline.
|
2020-09-21 13:05:30 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* Unlike the `bind` method, which is only called once per frame, this is called for every object
|
|
|
|
* that requests use of this pipeline, allowing you to perform per-object set-up, such as loading
|
|
|
|
* shader uniform data.
|
2020-09-21 13:05:30 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.WebGLPipeline#onBind
|
|
|
|
* @since 3.0.0
|
2020-09-21 13:05:30 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @param {Phaser.GameObjects.GameObject} [gameObject] - The Game Object that invoked this pipeline, if any.
|
2020-09-21 13:05:30 +00:00
|
|
|
*
|
|
|
|
* @return {this} This WebGLPipeline instance.
|
|
|
|
*/
|
2020-10-21 17:15:02 +00:00
|
|
|
onBind: function ()
|
2020-09-21 13:05:30 +00:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2020-10-21 17:15:02 +00:00
|
|
|
* This method is called once per frame, right before anything has been rendered, but after the canvas
|
|
|
|
* has been cleared.
|
2020-09-21 13:05:30 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.WebGLPipeline#onPreRender
|
|
|
|
* @since 3.0.0
|
2020-09-21 13:05:30 +00:00
|
|
|
*
|
|
|
|
* @return {this} This WebGLPipeline instance.
|
|
|
|
*/
|
2020-10-21 17:15:02 +00:00
|
|
|
onPreRender: function ()
|
2020-09-21 13:05:30 +00:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2020-10-21 17:15:02 +00:00
|
|
|
* This method is called once per frame, for every Camera in a Scene that wants to render.
|
2020-09-21 13:05:30 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.WebGLPipeline#onRender
|
|
|
|
* @since 3.0.0
|
2018-03-05 15:28:59 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @param {Phaser.Scene} scene - The Scene being rendered.
|
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Scene Camera being rendered with.
|
2020-09-21 13:05:30 +00:00
|
|
|
*
|
|
|
|
* @return {this} This WebGLPipeline instance.
|
|
|
|
*/
|
2020-10-21 17:15:02 +00:00
|
|
|
onRender: function ()
|
2020-09-21 13:05:30 +00:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2020-10-21 17:15:02 +00:00
|
|
|
* This method is called once per frame, after all rendering has happened and snapshots have been taken.
|
2020-09-21 13:05:30 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.WebGLPipeline#onPostRender
|
|
|
|
* @since 3.0.0
|
2018-03-05 15:28:59 +00:00
|
|
|
*
|
2018-09-12 14:34:48 +00:00
|
|
|
* @return {this} This WebGLPipeline instance.
|
2018-03-05 15:28:59 +00:00
|
|
|
*/
|
2020-10-21 17:15:02 +00:00
|
|
|
onPostRender: function ()
|
2018-03-05 14:29:48 +00:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-03-05 15:28:59 +00:00
|
|
|
/**
|
2020-10-21 17:15:02 +00:00
|
|
|
* Uploads the vertex data and emits a draw call for the current batch of vertices.
|
2018-03-05 15:28:59 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.WebGLPipeline#flush
|
|
|
|
* @since 3.0.0
|
2018-03-05 15:28:59 +00:00
|
|
|
*
|
2018-09-12 14:34:48 +00:00
|
|
|
* @return {this} This WebGLPipeline instance.
|
2018-03-05 15:28:59 +00:00
|
|
|
*/
|
2020-10-21 17:15:02 +00:00
|
|
|
flush: function ()
|
2018-03-05 14:29:48 +00:00
|
|
|
{
|
2020-10-21 17:15:02 +00:00
|
|
|
var gl = this.gl;
|
|
|
|
var vertexCount = this.vertexCount;
|
|
|
|
var topology = this.topology;
|
|
|
|
var vertexSize = this.vertexSize;
|
2018-03-05 14:29:48 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
if (vertexCount === 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-08-07 15:26:22 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.bytes.subarray(0, vertexCount * vertexSize));
|
|
|
|
gl.drawArrays(topology, 0, vertexCount);
|
2018-03-05 14:29:48 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
this.vertexCount = 0;
|
2018-08-07 15:26:22 +00:00
|
|
|
|
2018-03-05 14:29:48 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-03-05 15:28:59 +00:00
|
|
|
/**
|
2020-10-21 17:15:02 +00:00
|
|
|
* Destroys all shader instances, removes all object references and nulls all external references.
|
2018-03-05 15:28:59 +00:00
|
|
|
*
|
2020-10-21 17:15:02 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.WebGLPipeline#destroy
|
|
|
|
* @since 3.0.0
|
2018-03-05 15:28:59 +00:00
|
|
|
*
|
2018-09-12 14:34:48 +00:00
|
|
|
* @return {this} This WebGLPipeline instance.
|
2018-03-05 15:28:59 +00:00
|
|
|
*/
|
2020-10-21 17:15:02 +00:00
|
|
|
destroy: function ()
|
2018-03-05 14:29:48 +00:00
|
|
|
{
|
2020-10-21 17:15:02 +00:00
|
|
|
var shaders = this.shaders;
|
2018-03-05 14:29:48 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
for (var i = 0; i < shaders.length; i++)
|
|
|
|
{
|
|
|
|
shaders[i].destroy();
|
|
|
|
}
|
2018-08-07 15:26:22 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
this.gl.deleteBuffer(this.vertexBuffer);
|
2018-03-05 14:29:48 +00:00
|
|
|
|
2020-10-21 17:15:02 +00:00
|
|
|
this.game = null;
|
|
|
|
this.renderer = null;
|
|
|
|
this.gl = null;
|
|
|
|
this.view = null;
|
|
|
|
this.shaders = null;
|
|
|
|
this.vertexData = null;
|
|
|
|
this.vertexBuffer = null;
|
2018-08-07 15:26:22 +00:00
|
|
|
|
2018-01-10 20:03:01 +00:00
|
|
|
return this;
|
|
|
|
}
|
2018-01-09 01:34:45 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
module.exports = WebGLPipeline;
|