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>
|
2018-02-12 16:01:20 +00:00
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2017-07-04 13:48:18 +00:00
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
var CONST = require('../../const');
|
2018-01-20 04:05:56 +00:00
|
|
|
var IsSizePowerOfTwo = require('../../math/pow2/IsSizePowerOfTwo');
|
2018-04-23 16:30:09 +00:00
|
|
|
var SpliceOne = require('../../utils/array/SpliceOne');
|
2018-01-24 03:57:33 +00:00
|
|
|
var Utils = require('./Utils');
|
2018-02-09 19:19:21 +00:00
|
|
|
var WebGLSnapshot = require('../snapshot/WebGLSnapshot');
|
2018-01-17 21:25:43 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
// Default Pipelines
|
2018-01-25 18:43:19 +00:00
|
|
|
var BitmapMaskPipeline = require('./pipelines/BitmapMaskPipeline');
|
2018-02-09 19:19:21 +00:00
|
|
|
var FlatTintPipeline = require('./pipelines/FlatTintPipeline');
|
2018-01-29 21:46:48 +00:00
|
|
|
var ForwardDiffuseLightPipeline = require('./pipelines/ForwardDiffuseLightPipeline');
|
2018-02-09 19:19:21 +00:00
|
|
|
var TextureTintPipeline = require('./pipelines/TextureTintPipeline');
|
2018-01-22 21:21:47 +00:00
|
|
|
|
2018-03-19 20:41:24 +00:00
|
|
|
/**
|
|
|
|
* @callback WebGLContextCallback
|
|
|
|
*
|
|
|
|
* @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - [description]
|
|
|
|
*/
|
|
|
|
|
2018-03-21 13:41:17 +00:00
|
|
|
/**
|
|
|
|
* @typedef {object} SnapshotState
|
|
|
|
*
|
|
|
|
* @property {SnapshotCallback} callback - [description]
|
|
|
|
* @property {string} type - [description]
|
2018-06-26 22:19:14 +00:00
|
|
|
* @property {number} encoder - [description]
|
2018-03-21 13:41:17 +00:00
|
|
|
*/
|
|
|
|
|
2018-01-31 13:54:44 +00:00
|
|
|
/**
|
2018-02-09 19:19:21 +00:00
|
|
|
* @classdesc
|
2018-04-25 23:30:41 +00:00
|
|
|
* WebGLRenderer is a class that contains the needed functionality to keep the
|
|
|
|
* WebGLRenderingContext state clean. The main idea of the WebGLRenderer is to keep track of
|
|
|
|
* any context change that happens for WebGL rendering inside of Phaser. This means
|
|
|
|
* if raw webgl functions are called outside the WebGLRenderer of the Phaser WebGL
|
|
|
|
* rendering ecosystem they might pollute the current WebGLRenderingContext state producing
|
2018-07-02 11:33:46 +00:00
|
|
|
* unexpected behavior. It's recommended that WebGL interaction is done through
|
2018-04-25 23:30:41 +00:00
|
|
|
* WebGLRenderer and/or WebGLPipeline.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @class WebGLRenderer
|
|
|
|
* @memberOf Phaser.Renderer.WebGL
|
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Game} game - [description]
|
2018-01-31 13:54:44 +00:00
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
var WebGLRenderer = new Class({
|
2016-12-07 02:28:22 +00:00
|
|
|
|
2017-07-04 13:48:18 +00:00
|
|
|
initialize:
|
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
function WebGLRenderer (game)
|
2016-12-07 02:28:22 +00:00
|
|
|
{
|
2018-02-16 18:44:07 +00:00
|
|
|
// eslint-disable-next-line consistent-this
|
2018-01-17 21:25:43 +00:00
|
|
|
var renderer = this;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
2018-03-16 13:22:52 +00:00
|
|
|
var gameConfig = game.config;
|
|
|
|
|
2018-02-05 22:06:02 +00:00
|
|
|
var contextCreationConfig = {
|
2018-03-16 13:22:52 +00:00
|
|
|
alpha: gameConfig.transparent,
|
2018-02-05 22:06:02 +00:00
|
|
|
depth: false, // enable when 3D is added in the future
|
2018-03-16 13:22:52 +00:00
|
|
|
antialias: gameConfig.antialias,
|
|
|
|
premultipliedAlpha: gameConfig.premultipliedAlpha,
|
2018-02-05 22:06:02 +00:00
|
|
|
stencil: true,
|
2018-03-16 13:22:52 +00:00
|
|
|
preserveDrawingBuffer: gameConfig.preserveDrawingBuffer,
|
|
|
|
failIfMajorPerformanceCaveat: gameConfig.failIfMajorPerformanceCaveat,
|
|
|
|
powerPreference: gameConfig.powerPreference
|
2018-01-17 21:25:43 +00:00
|
|
|
};
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#config
|
2018-03-21 13:41:17 +00:00
|
|
|
* @type {RendererConfig}
|
2018-02-09 19:19:21 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-02-06 20:37:13 +00:00
|
|
|
this.config = {
|
2018-03-16 13:22:52 +00:00
|
|
|
clearBeforeRender: gameConfig.clearBeforeRender,
|
2018-06-27 14:15:00 +00:00
|
|
|
antialias: gameConfig.antialias,
|
2018-03-16 13:22:52 +00:00
|
|
|
backgroundColor: gameConfig.backgroundColor,
|
2018-02-06 21:47:42 +00:00
|
|
|
contextCreation: contextCreationConfig,
|
2018-03-16 13:22:52 +00:00
|
|
|
resolution: gameConfig.resolution,
|
|
|
|
autoResize: gameConfig.autoResize,
|
2018-05-09 11:12:16 +00:00
|
|
|
roundPixels: gameConfig.roundPixels,
|
|
|
|
maxTextures: gameConfig.maxTextures,
|
2018-07-02 11:33:46 +00:00
|
|
|
maxTextureSize: gameConfig.maxTextureSize,
|
|
|
|
batchSize: gameConfig.batchSize
|
2018-02-06 20:37:13 +00:00
|
|
|
};
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#game
|
|
|
|
* @type {Phaser.Game}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 13:48:18 +00:00
|
|
|
this.game = game;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#type
|
|
|
|
* @type {integer}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 13:48:18 +00:00
|
|
|
this.type = CONST.WEBGL;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#width
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-02-09 18:45:22 +00:00
|
|
|
this.width = game.config.width;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#height
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-02-09 18:45:22 +00:00
|
|
|
this.height = game.config.height;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#canvas
|
|
|
|
* @type {HTMLCanvasElement}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
this.canvas = game.canvas;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#lostContextCallbacks
|
2018-03-19 20:41:24 +00:00
|
|
|
* @type {WebGLContextCallback[]}
|
2018-02-09 19:19:21 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-24 00:40:20 +00:00
|
|
|
this.lostContextCallbacks = [];
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#restoredContextCallbacks
|
2018-03-19 20:41:24 +00:00
|
|
|
* @type {WebGLContextCallback[]}
|
2018-02-09 19:19:21 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-24 00:40:20 +00:00
|
|
|
this.restoredContextCallbacks = [];
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#blendModes
|
|
|
|
* @type {array}
|
|
|
|
* @default []
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
this.blendModes = [];
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Keeps track of any WebGLTexture created with the current WebGLRenderingContext
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#nativeTextures
|
|
|
|
* @type {array}
|
|
|
|
* @default []
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-31 17:36:00 +00:00
|
|
|
this.nativeTextures = [];
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#contextLost
|
|
|
|
* @type {boolean}
|
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
this.contextLost = false;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* This object will store all pipelines created through addPipeline
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#pipelines
|
2018-02-13 00:12:17 +00:00
|
|
|
* @type {object}
|
2018-02-09 19:19:21 +00:00
|
|
|
* @default null
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
this.pipelines = null;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#snapshotState
|
2018-03-21 13:41:17 +00:00
|
|
|
* @type {SnapshotState}
|
2018-02-09 19:19:21 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-20 04:05:56 +00:00
|
|
|
this.snapshotState = {
|
|
|
|
callback: null,
|
|
|
|
type: null,
|
|
|
|
encoder: null
|
|
|
|
};
|
2017-09-13 19:11:40 +00:00
|
|
|
|
2018-02-16 18:07:49 +00:00
|
|
|
// Internal Renderer State (Textures, Framebuffers, Pipelines, Buffers, etc)
|
2018-02-09 19:19:21 +00:00
|
|
|
|
2018-02-14 19:45:22 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Cached value for the last texture unit that was used
|
2018-02-14 19:45:22 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentActiveTextureUnit
|
2018-02-16 18:07:49 +00:00
|
|
|
* @type {integer}
|
2018-02-15 14:31:15 +00:00
|
|
|
* @since 3.1.0
|
2018-02-14 19:45:22 +00:00
|
|
|
*/
|
|
|
|
this.currentActiveTextureUnit = 0;
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* An array of the last texture handles that were bound to the WebGLRenderingContext
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentTextures
|
2018-02-13 00:12:17 +00:00
|
|
|
* @type {array}
|
2018-02-09 19:19:21 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
this.currentTextures = new Array(16);
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Current framebuffer in use
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentFramebuffer
|
2018-02-13 00:12:17 +00:00
|
|
|
* @type {WebGLFramebuffer}
|
2018-02-09 19:19:21 +00:00
|
|
|
* @default null
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
this.currentFramebuffer = null;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Current WebGLPipeline in use
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentPipeline
|
2018-02-13 00:12:17 +00:00
|
|
|
* @type {Phaser.Renderer.WebGL.WebGLPipeline}
|
2018-02-09 19:19:21 +00:00
|
|
|
* @default null
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
this.currentPipeline = null;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Current WebGLProgram in use
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentProgram
|
2018-02-13 00:12:17 +00:00
|
|
|
* @type {WebGLProgram}
|
2018-02-09 19:19:21 +00:00
|
|
|
* @default null
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-22 21:21:47 +00:00
|
|
|
this.currentProgram = null;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Current WebGLBuffer (Vertex buffer) in use
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentVertexBuffer
|
2018-02-13 00:12:17 +00:00
|
|
|
* @type {WebGLBuffer}
|
2018-02-09 19:19:21 +00:00
|
|
|
* @default null
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
this.currentVertexBuffer = null;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Current WebGLBuffer (Index buffer) in use
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentIndexBuffer
|
2018-02-13 00:12:17 +00:00
|
|
|
* @type {WebGLBuffer}
|
2018-02-09 19:19:21 +00:00
|
|
|
* @default null
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
this.currentIndexBuffer = null;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Current blend mode in use
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentBlendMode
|
2018-02-16 18:07:49 +00:00
|
|
|
* @type {integer}
|
2018-02-09 19:19:21 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-22 21:21:47 +00:00
|
|
|
this.currentBlendMode = Infinity;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Indicates if the the scissor state is enabled in WebGLRenderingContext
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentScissorEnabled
|
|
|
|
* @type {boolean}
|
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-24 18:55:23 +00:00
|
|
|
this.currentScissorEnabled = false;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Stores the current scissor data
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentScissor
|
|
|
|
* @type {Uint32Array}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-02-16 18:17:51 +00:00
|
|
|
this.currentScissor = new Uint32Array([ 0, 0, this.width, this.height ]);
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Index to the scissor stack top
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentScissorIdx
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-24 18:55:23 +00:00
|
|
|
this.currentScissorIdx = 0;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Stack of scissor data
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#scissorStack
|
|
|
|
* @type {Uint32Array}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-02-16 18:17:51 +00:00
|
|
|
this.scissorStack = new Uint32Array(4 * 1000);
|
2018-01-17 21:25:43 +00:00
|
|
|
|
|
|
|
// Setup context lost and restore event listeners
|
2018-02-09 19:19:21 +00:00
|
|
|
|
2018-02-16 18:17:51 +00:00
|
|
|
this.canvas.addEventListener('webglcontextlost', function (event)
|
|
|
|
{
|
2018-01-17 21:25:43 +00:00
|
|
|
renderer.contextLost = true;
|
|
|
|
event.preventDefault();
|
2018-01-31 17:36:00 +00:00
|
|
|
|
2018-01-24 00:40:20 +00:00
|
|
|
for (var index = 0; index < renderer.lostContextCallbacks.length; ++index)
|
|
|
|
{
|
|
|
|
var callback = renderer.lostContextCallbacks[index];
|
|
|
|
callback[0].call(callback[1], renderer);
|
|
|
|
}
|
2018-01-17 21:25:43 +00:00
|
|
|
}, false);
|
2017-07-04 13:48:18 +00:00
|
|
|
|
2018-02-16 18:44:07 +00:00
|
|
|
this.canvas.addEventListener('webglcontextrestored', function ()
|
2018-02-16 18:17:51 +00:00
|
|
|
{
|
2018-01-17 21:25:43 +00:00
|
|
|
renderer.contextLost = false;
|
2018-02-06 20:37:13 +00:00
|
|
|
renderer.init(renderer.config);
|
2018-01-24 00:40:20 +00:00
|
|
|
for (var index = 0; index < renderer.restoredContextCallbacks.length; ++index)
|
|
|
|
{
|
|
|
|
var callback = renderer.restoredContextCallbacks[index];
|
|
|
|
callback[0].call(callback[1], renderer);
|
|
|
|
}
|
2018-01-17 21:25:43 +00:00
|
|
|
}, false);
|
|
|
|
|
2018-04-24 14:32:08 +00:00
|
|
|
// These are initialized post context creation
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#gl
|
2018-02-13 00:12:17 +00:00
|
|
|
* @type {WebGLRenderingContext}
|
2018-02-09 19:19:21 +00:00
|
|
|
* @default null
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 13:48:18 +00:00
|
|
|
this.gl = null;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Array of strings that indicate which WebGL extensions are supported by the browser
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#supportedExtensions
|
2018-02-13 00:12:17 +00:00
|
|
|
* @type {object}
|
2018-02-09 19:19:21 +00:00
|
|
|
* @default null
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
this.supportedExtensions = null;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Extensions loaded into the current context
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#extensions
|
|
|
|
* @type {object}
|
|
|
|
* @default {}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
this.extensions = {};
|
2017-07-04 13:48:18 +00:00
|
|
|
|
2018-03-05 15:28:59 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Stores the current WebGL component formats for further use
|
2018-03-05 15:28:59 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#glFormats
|
|
|
|
* @type {array}
|
|
|
|
* @default []
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
2018-03-05 14:29:48 +00:00
|
|
|
this.glFormats = [];
|
|
|
|
|
2018-05-09 12:46:19 +00:00
|
|
|
/**
|
|
|
|
* Stores the supported WebGL texture compression formats.
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#compression
|
|
|
|
* @type {array}
|
|
|
|
* @since 3.8.0
|
|
|
|
*/
|
|
|
|
this.compression = {
|
|
|
|
ETC1: false,
|
|
|
|
PVRTC: false,
|
|
|
|
S3TC: false
|
|
|
|
};
|
|
|
|
|
2018-07-10 15:32:28 +00:00
|
|
|
/**
|
|
|
|
* Cached drawing buffer height to reduce gl calls.
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#drawingBufferHeight
|
|
|
|
* @type {number}
|
|
|
|
* @readOnly
|
|
|
|
* @since 3.11.0
|
|
|
|
*/
|
|
|
|
this.drawingBufferHeight = 0;
|
|
|
|
|
2018-02-06 20:37:13 +00:00
|
|
|
this.init(this.config);
|
2017-07-04 13:48:18 +00:00
|
|
|
},
|
2017-01-25 12:02:18 +00:00
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Creates a new WebGLRenderingContext and initializes all internal
|
|
|
|
* state.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#init
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {object} config - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-02-06 20:37:13 +00:00
|
|
|
init: function (config)
|
2017-07-04 13:48:18 +00:00
|
|
|
{
|
2018-05-10 11:25:33 +00:00
|
|
|
var gl;
|
2018-01-17 21:25:43 +00:00
|
|
|
var canvas = this.canvas;
|
|
|
|
var clearColor = config.backgroundColor;
|
2018-05-10 11:25:33 +00:00
|
|
|
|
|
|
|
// Did they provide their own context?
|
|
|
|
if (this.game.config.context)
|
|
|
|
{
|
|
|
|
gl = this.game.config.context;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gl = canvas.getContext('webgl', config.contextCreation) || canvas.getContext('experimental-webgl', config.contextCreation);
|
|
|
|
}
|
2018-03-19 20:41:24 +00:00
|
|
|
|
2018-04-16 18:16:23 +00:00
|
|
|
if (!gl || gl.isContextLost())
|
2016-12-07 02:28:22 +00:00
|
|
|
{
|
|
|
|
this.contextLost = true;
|
2018-05-10 11:25:33 +00:00
|
|
|
|
2018-01-10 20:03:01 +00:00
|
|
|
throw new Error('This browser does not support WebGL. Try using the Canvas pipeline.');
|
2016-12-07 02:28:22 +00:00
|
|
|
}
|
2017-09-13 19:11:40 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
this.gl = gl;
|
|
|
|
|
2018-07-02 11:33:46 +00:00
|
|
|
// Set it back into the Game, so developers can access it from there too
|
2018-05-10 11:25:33 +00:00
|
|
|
this.game.context = gl;
|
|
|
|
|
2018-02-19 20:49:17 +00:00
|
|
|
for (var i = 0; i <= 16; i++)
|
|
|
|
{
|
|
|
|
this.blendModes.push({ func: [ gl.ONE, gl.ONE_MINUS_SRC_ALPHA ], equation: gl.FUNC_ADD });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.blendModes[1].func = [ gl.ONE, gl.DST_ALPHA ];
|
|
|
|
this.blendModes[2].func = [ gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA ];
|
|
|
|
this.blendModes[3].func = [ gl.ONE, gl.ONE_MINUS_SRC_COLOR ];
|
|
|
|
|
2018-03-05 14:29:48 +00:00
|
|
|
this.glFormats[0] = gl.BYTE;
|
|
|
|
this.glFormats[1] = gl.SHORT;
|
|
|
|
this.glFormats[2] = gl.UNSIGNED_BYTE;
|
|
|
|
this.glFormats[3] = gl.UNSIGNED_SHORT;
|
|
|
|
this.glFormats[4] = gl.FLOAT;
|
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
// Load supported extensions
|
2018-05-09 12:46:19 +00:00
|
|
|
var exts = gl.getSupportedExtensions();
|
2017-09-13 19:11:40 +00:00
|
|
|
|
2018-05-09 11:12:16 +00:00
|
|
|
if (!config.maxTextures)
|
|
|
|
{
|
|
|
|
config.maxTextures = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!config.maxTextureSize)
|
|
|
|
{
|
|
|
|
config.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
|
|
|
|
}
|
|
|
|
|
2018-05-09 13:32:32 +00:00
|
|
|
var extString = 'WEBGL_compressed_texture_';
|
2018-05-09 12:46:19 +00:00
|
|
|
var wkExtString = 'WEBKIT_' + extString;
|
|
|
|
|
|
|
|
this.compression.ETC1 = gl.getExtension(extString + 'etc1') || gl.getExtension(wkExtString + 'etc1');
|
|
|
|
this.compression.PVRTC = gl.getExtension(extString + 'pvrtc') || gl.getExtension(wkExtString + 'pvrtc');
|
|
|
|
this.compression.S3TC = gl.getExtension(extString + 's3tc') || gl.getExtension(wkExtString + 's3tc');
|
|
|
|
|
|
|
|
this.supportedExtensions = exts;
|
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
// Setup initial WebGL state
|
2016-12-07 02:28:22 +00:00
|
|
|
gl.disable(gl.DEPTH_TEST);
|
|
|
|
gl.disable(gl.CULL_FACE);
|
2018-07-10 15:32:28 +00:00
|
|
|
|
|
|
|
// gl.disable(gl.SCISSOR_TEST);
|
|
|
|
|
2016-12-07 02:28:22 +00:00
|
|
|
gl.enable(gl.BLEND);
|
2018-01-17 21:25:43 +00:00
|
|
|
gl.clearColor(clearColor.redGL, clearColor.greenGL, clearColor.blueGL, 1.0);
|
2017-08-03 01:09:59 +00:00
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
// Initialize all textures to null
|
|
|
|
for (var index = 0; index < this.currentTextures.length; ++index)
|
2017-08-03 01:09:59 +00:00
|
|
|
{
|
2018-01-17 21:25:43 +00:00
|
|
|
this.currentTextures[index] = null;
|
2017-08-03 01:09:59 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
// Clear previous pipelines and reload default ones
|
|
|
|
this.pipelines = {};
|
2017-08-03 01:09:59 +00:00
|
|
|
|
2018-03-05 14:29:48 +00:00
|
|
|
this.addPipeline('TextureTintPipeline', new TextureTintPipeline({ game: this.game, renderer: this }));
|
|
|
|
this.addPipeline('FlatTintPipeline', new FlatTintPipeline({ game: this.game, renderer: this }));
|
|
|
|
this.addPipeline('BitmapMaskPipeline', new BitmapMaskPipeline({ game: this.game, renderer: this }));
|
|
|
|
this.addPipeline('Light2D', new ForwardDiffuseLightPipeline({ game: this.game, renderer: this }));
|
2018-03-19 20:41:24 +00:00
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
this.setBlendMode(CONST.BlendModes.NORMAL);
|
2018-02-09 18:45:22 +00:00
|
|
|
this.resize(this.width, this.height);
|
2018-03-19 20:41:24 +00:00
|
|
|
|
2018-07-13 10:13:46 +00:00
|
|
|
this.game.events.once('ready', this.boot, this);
|
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
return this;
|
2017-08-03 01:09:59 +00:00
|
|
|
},
|
|
|
|
|
2018-07-13 10:13:46 +00:00
|
|
|
/**
|
|
|
|
* Internal boot handler. Calls 'boot' on each pipeline.
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#boot
|
|
|
|
* @private
|
|
|
|
* @since 3.11.0
|
|
|
|
*/
|
|
|
|
boot: function ()
|
|
|
|
{
|
|
|
|
for (var pipelineName in this.pipelines)
|
|
|
|
{
|
|
|
|
this.pipelines[pipelineName].boot();
|
|
|
|
}
|
2018-07-26 14:04:46 +00:00
|
|
|
|
|
|
|
var blank = this.game.textures.getFrame('__DEFAULT');
|
|
|
|
|
|
|
|
this.pipelines.FlatTintPipeline.currentFrame = blank;
|
|
|
|
|
|
|
|
this.blankTexture = blank;
|
2018-07-13 10:13:46 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#resize
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} width - [description]
|
|
|
|
* @param {number} height - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-02-09 18:45:22 +00:00
|
|
|
resize: function (width, height)
|
2017-08-03 01:09:59 +00:00
|
|
|
{
|
2018-01-17 21:25:43 +00:00
|
|
|
var gl = this.gl;
|
2018-01-22 21:21:47 +00:00
|
|
|
var pipelines = this.pipelines;
|
2018-02-09 18:45:22 +00:00
|
|
|
var resolution = this.config.resolution;
|
2017-08-03 01:09:59 +00:00
|
|
|
|
2018-03-15 21:15:39 +00:00
|
|
|
this.width = Math.floor(width * resolution);
|
|
|
|
this.height = Math.floor(height * resolution);
|
2018-03-19 20:41:24 +00:00
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
this.canvas.width = this.width;
|
|
|
|
this.canvas.height = this.height;
|
2017-08-03 01:09:59 +00:00
|
|
|
|
2018-02-12 19:03:13 +00:00
|
|
|
if (this.config.autoResize)
|
2017-08-03 01:09:59 +00:00
|
|
|
{
|
2018-01-17 21:25:43 +00:00
|
|
|
this.canvas.style.width = (this.width / resolution) + 'px';
|
|
|
|
this.canvas.style.height = (this.height / resolution) + 'px';
|
2017-08-03 01:09:59 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
gl.viewport(0, 0, this.width, this.height);
|
2017-08-03 01:09:59 +00:00
|
|
|
|
2018-07-13 10:13:46 +00:00
|
|
|
// Update all registered pipelines
|
2018-01-20 04:05:56 +00:00
|
|
|
for (var pipelineName in pipelines)
|
|
|
|
{
|
2018-01-22 21:21:47 +00:00
|
|
|
pipelines[pipelineName].resize(width, height, resolution);
|
2018-01-20 04:05:56 +00:00
|
|
|
}
|
2018-03-21 02:38:00 +00:00
|
|
|
|
|
|
|
this.currentScissor.set([ 0, 0, this.width, this.height ]);
|
2018-07-10 15:32:28 +00:00
|
|
|
|
|
|
|
this.drawingBufferHeight = gl.drawingBufferHeight;
|
2017-08-10 04:17:58 +00:00
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
return this;
|
2017-09-13 19:43:34 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#onContextRestored
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-03-19 20:41:24 +00:00
|
|
|
* @param {WebGLContextCallback} callback - [description]
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {object} target - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-24 00:40:20 +00:00
|
|
|
onContextRestored: function (callback, target)
|
|
|
|
{
|
2018-02-16 18:17:51 +00:00
|
|
|
this.restoredContextCallbacks.push([ callback, target ]);
|
2018-03-12 13:37:13 +00:00
|
|
|
|
2018-01-24 00:40:20 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#onContextLost
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-03-19 20:41:24 +00:00
|
|
|
* @param {WebGLContextCallback} callback - [description]
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {object} target - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-24 00:40:20 +00:00
|
|
|
onContextLost: function (callback, target)
|
|
|
|
{
|
2018-02-16 18:17:51 +00:00
|
|
|
this.lostContextCallbacks.push([ callback, target ]);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-24 00:40:20 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Checks if a WebGL extension is supported
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#hasExtension
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @param {string} extensionName - Name of the WebGL extension
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {boolean} [description]
|
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
hasExtension: function (extensionName)
|
2017-09-13 19:43:34 +00:00
|
|
|
{
|
2018-01-17 21:25:43 +00:00
|
|
|
return this.supportedExtensions ? this.supportedExtensions.indexOf(extensionName) : false;
|
2017-09-13 19:43:34 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Loads a WebGL extension
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#getExtension
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {string} extensionName - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @return {object} WebGL extension if the extension is supported
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
getExtension: function (extensionName)
|
2017-01-19 23:20:36 +00:00
|
|
|
{
|
2018-02-16 18:17:51 +00:00
|
|
|
if (!this.hasExtension(extensionName)) { return null; }
|
2017-07-04 13:48:18 +00:00
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
if (!(extensionName in this.extensions))
|
2017-01-19 23:20:36 +00:00
|
|
|
{
|
2018-01-17 21:25:43 +00:00
|
|
|
this.extensions[extensionName] = this.gl.getExtension(extensionName);
|
2017-01-19 23:20:36 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
return this.extensions[extensionName];
|
2017-01-19 23:20:36 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Flushes the current pipeline if the pipeline is bound
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#flush
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-20 04:05:56 +00:00
|
|
|
flush: function ()
|
|
|
|
{
|
|
|
|
if (this.currentPipeline)
|
|
|
|
{
|
|
|
|
this.currentPipeline.flush();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
/* Renderer State Manipulation Functions */
|
2017-01-19 17:53:20 +00:00
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Checks if a pipeline is present in the current WebGLRenderer
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#hasPipeline
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @param {string} pipelineName - Name of the pipeline
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {boolean} [description]
|
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
hasPipeline: function (pipelineName)
|
2017-01-19 22:43:41 +00:00
|
|
|
{
|
2018-01-17 21:25:43 +00:00
|
|
|
return (pipelineName in this.pipelines);
|
2017-04-07 01:49:15 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Returns the pipeline by name if the pipeline exists
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#getPipeline
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {string} pipelineName - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
getPipeline: function (pipelineName)
|
2017-04-07 01:49:15 +00:00
|
|
|
{
|
2018-02-09 19:19:21 +00:00
|
|
|
return (this.hasPipeline(pipelineName)) ? this.pipelines[pipelineName] : null;
|
2017-01-19 22:43:41 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Removes a pipeline by name
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#removePipeline
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {string} pipelineName - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
removePipeline: function (pipelineName)
|
2016-12-07 02:28:22 +00:00
|
|
|
{
|
2018-01-17 21:25:43 +00:00
|
|
|
delete this.pipelines[pipelineName];
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
return this;
|
2016-12-07 02:28:22 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Adds a pipeline instance into the collection of pipelines
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#addPipeline
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {string} pipelineName - [description]
|
2018-04-25 23:30:41 +00:00
|
|
|
* @param {Phaser.Renderer.WebGL.WebGLPipeline} pipelineInstance - Pipeline instance must extend WebGLPipeline
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLPipeline} The instance that was passed.
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
addPipeline: function (pipelineName, pipelineInstance)
|
2016-12-07 02:28:22 +00:00
|
|
|
{
|
2018-03-15 21:15:39 +00:00
|
|
|
if (!this.hasPipeline(pipelineName))
|
|
|
|
{
|
|
|
|
this.pipelines[pipelineName] = pipelineInstance;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Pipeline', pipelineName, ' already exists.');
|
|
|
|
}
|
2017-06-08 16:15:02 +00:00
|
|
|
|
2018-01-30 22:46:43 +00:00
|
|
|
pipelineInstance.name = pipelineName;
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-02-06 20:37:13 +00:00
|
|
|
this.pipelines[pipelineName].resize(this.width, this.height, this.config.resolution);
|
2016-12-07 02:28:22 +00:00
|
|
|
|
2018-03-05 14:29:48 +00:00
|
|
|
return pipelineInstance;
|
2017-01-25 17:10:19 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Sets the current scissor state
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setScissor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-16 18:07:49 +00:00
|
|
|
* @param {integer} x - [description]
|
|
|
|
* @param {integer} y - [description]
|
|
|
|
* @param {integer} w - [description]
|
|
|
|
* @param {integer} h - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-24 18:55:23 +00:00
|
|
|
setScissor: function (x, y, w, h)
|
2018-01-23 23:36:49 +00:00
|
|
|
{
|
|
|
|
var gl = this.gl;
|
2018-01-24 18:55:23 +00:00
|
|
|
var currentScissor = this.currentScissor;
|
2018-07-10 15:32:28 +00:00
|
|
|
var enabled = (x === 0 && y === 0 && w === this.width && h === this.height && w >= 0 && h >= 0);
|
|
|
|
|
|
|
|
// TODO: If new scissor is same as old scissor, skip setting it again
|
|
|
|
// TODO: If scissor is viewport size, skip setting altogether
|
2018-01-24 18:55:23 +00:00
|
|
|
|
2018-02-16 18:17:51 +00:00
|
|
|
if (currentScissor[0] !== x ||
|
|
|
|
currentScissor[1] !== y ||
|
|
|
|
currentScissor[2] !== w ||
|
2018-01-24 18:55:23 +00:00
|
|
|
currentScissor[3] !== h)
|
2018-01-23 23:36:49 +00:00
|
|
|
{
|
2018-01-24 03:57:33 +00:00
|
|
|
this.flush();
|
2018-01-23 23:36:49 +00:00
|
|
|
}
|
|
|
|
|
2018-01-24 18:55:23 +00:00
|
|
|
currentScissor[0] = x;
|
|
|
|
currentScissor[1] = y;
|
|
|
|
currentScissor[2] = w;
|
|
|
|
currentScissor[3] = h;
|
2018-01-23 23:36:49 +00:00
|
|
|
|
2018-01-24 18:55:23 +00:00
|
|
|
this.currentScissorEnabled = enabled;
|
2018-01-23 23:36:49 +00:00
|
|
|
|
2018-01-24 18:55:23 +00:00
|
|
|
if (enabled)
|
2018-01-23 23:36:49 +00:00
|
|
|
{
|
|
|
|
gl.disable(gl.SCISSOR_TEST);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
|
|
|
return this;
|
2018-01-23 23:36:49 +00:00
|
|
|
}
|
2018-01-24 18:55:23 +00:00
|
|
|
|
|
|
|
gl.enable(gl.SCISSOR_TEST);
|
2018-07-10 15:32:28 +00:00
|
|
|
gl.scissor(x, (this.drawingBufferHeight - y - h), w, h);
|
2018-01-24 18:55:23 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Pushes a new scissor state. This is used to set nested scissor states.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#pushScissor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-16 18:07:49 +00:00
|
|
|
* @param {integer} x - [description]
|
|
|
|
* @param {integer} y - [description]
|
|
|
|
* @param {integer} w - [description]
|
|
|
|
* @param {integer} h - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-24 18:55:23 +00:00
|
|
|
pushScissor: function (x, y, w, h)
|
|
|
|
{
|
|
|
|
var scissorStack = this.scissorStack;
|
|
|
|
var stackIndex = this.currentScissorIdx;
|
|
|
|
var currentScissor = this.currentScissor;
|
|
|
|
|
|
|
|
scissorStack[stackIndex + 0] = currentScissor[0];
|
|
|
|
scissorStack[stackIndex + 1] = currentScissor[1];
|
|
|
|
scissorStack[stackIndex + 2] = currentScissor[2];
|
|
|
|
scissorStack[stackIndex + 3] = currentScissor[3];
|
2018-03-19 20:41:24 +00:00
|
|
|
|
2018-01-24 18:55:23 +00:00
|
|
|
this.currentScissorIdx += 4;
|
|
|
|
this.setScissor(x, y, w, h);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Pops the last scissor state and sets it.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#popScissor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-24 18:55:23 +00:00
|
|
|
popScissor: function ()
|
|
|
|
{
|
|
|
|
var scissorStack = this.scissorStack;
|
|
|
|
var stackIndex = this.currentScissorIdx - 4;
|
2018-03-19 20:41:24 +00:00
|
|
|
|
2018-01-24 18:55:23 +00:00
|
|
|
var x = scissorStack[stackIndex + 0];
|
|
|
|
var y = scissorStack[stackIndex + 1];
|
|
|
|
var w = scissorStack[stackIndex + 2];
|
|
|
|
var h = scissorStack[stackIndex + 3];
|
|
|
|
|
|
|
|
this.currentScissorIdx = stackIndex;
|
2018-02-16 18:17:51 +00:00
|
|
|
this.setScissor(x, y, w, h);
|
2018-03-19 20:41:24 +00:00
|
|
|
|
2018-01-24 18:55:23 +00:00
|
|
|
return this;
|
2018-01-23 23:36:49 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Binds a WebGLPipeline and sets it as the current pipeline to be used.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setPipeline
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-07-11 15:24:20 +00:00
|
|
|
* @param {Phaser.Renderer.WebGL.WebGLPipeline} pipelineInstance - The pipeline instance to be activated.
|
|
|
|
* @param {Phaser.GameObjects.GameObject} [gameObject] - The Game Object that invoked this pipeline, if any.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-07-11 15:24:20 +00:00
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLPipeline} The pipeline that was activated.
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-07-11 15:24:20 +00:00
|
|
|
setPipeline: function (pipelineInstance, gameObject)
|
2018-01-20 04:05:56 +00:00
|
|
|
{
|
2018-01-25 05:26:14 +00:00
|
|
|
if (this.currentPipeline !== pipelineInstance ||
|
2018-01-30 03:38:31 +00:00
|
|
|
this.currentPipeline.vertexBuffer !== this.currentVertexBuffer ||
|
|
|
|
this.currentPipeline.program !== this.currentProgram)
|
2018-01-20 04:05:56 +00:00
|
|
|
{
|
2018-01-24 03:08:14 +00:00
|
|
|
this.flush();
|
2018-01-23 16:38:58 +00:00
|
|
|
this.currentPipeline = pipelineInstance;
|
2018-01-30 03:38:31 +00:00
|
|
|
this.currentPipeline.bind();
|
2018-01-20 04:05:56 +00:00
|
|
|
}
|
|
|
|
|
2018-07-11 15:24:20 +00:00
|
|
|
this.currentPipeline.onBind(gameObject);
|
2018-01-25 05:26:14 +00:00
|
|
|
|
2018-01-23 19:29:47 +00:00
|
|
|
return this.currentPipeline;
|
2018-01-20 04:05:56 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-07-23 00:39:32 +00:00
|
|
|
* Sets the blend mode to the value given.
|
|
|
|
*
|
|
|
|
* If the current blend mode is different from the one given, the pipeline is flushed and the new
|
|
|
|
* blend mode is enabled.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setBlendMode
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-07-23 00:39:32 +00:00
|
|
|
* @param {integer} blendModeId - The blend mode to be set. Can be a `BlendModes` const or an integer value.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-07-23 00:39:32 +00:00
|
|
|
* @return {boolean} `true` if the blend mode was changed as a result of this call, forcing a flush, otherwise `false`.
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
setBlendMode: function (blendModeId)
|
2017-01-25 17:10:19 +00:00
|
|
|
{
|
2017-01-31 23:06:13 +00:00
|
|
|
var gl = this.gl;
|
2018-01-17 21:25:43 +00:00
|
|
|
var blendMode = this.blendModes[blendModeId];
|
2017-02-07 16:12:20 +00:00
|
|
|
|
2018-07-23 00:39:32 +00:00
|
|
|
if (blendModeId !== CONST.BlendModes.SKIP_CHECK && this.currentBlendMode !== blendModeId)
|
2017-01-19 17:53:20 +00:00
|
|
|
{
|
2018-01-20 04:05:56 +00:00
|
|
|
this.flush();
|
2017-12-15 04:07:16 +00:00
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
gl.enable(gl.BLEND);
|
|
|
|
gl.blendEquation(blendMode.equation);
|
2017-06-08 16:15:02 +00:00
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
if (blendMode.func.length > 2)
|
2017-11-06 22:12:19 +00:00
|
|
|
{
|
2018-01-17 21:25:43 +00:00
|
|
|
gl.blendFuncSeparate(blendMode.func[0], blendMode.func[1], blendMode.func[2], blendMode.func[3]);
|
2017-11-06 22:12:19 +00:00
|
|
|
}
|
2018-01-17 21:25:43 +00:00
|
|
|
else
|
2017-11-06 22:12:19 +00:00
|
|
|
{
|
2018-01-17 21:25:43 +00:00
|
|
|
gl.blendFunc(blendMode.func[0], blendMode.func[1]);
|
2017-11-06 22:12:19 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
this.currentBlendMode = blendModeId;
|
2018-07-23 00:39:32 +00:00
|
|
|
|
|
|
|
return true;
|
2017-02-10 00:48:32 +00:00
|
|
|
}
|
2017-06-08 16:15:02 +00:00
|
|
|
|
2018-07-23 00:39:32 +00:00
|
|
|
return false;
|
2018-02-14 16:20:56 +00:00
|
|
|
},
|
|
|
|
|
2018-03-15 21:15:39 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#addBlendMode
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {function} func - [description]
|
|
|
|
* @param {function} equation - [description]
|
|
|
|
*
|
|
|
|
* @return {integer} [description]
|
|
|
|
*/
|
2018-02-14 16:20:56 +00:00
|
|
|
addBlendMode: function (func, equation)
|
|
|
|
{
|
|
|
|
var index = this.blendModes.push({ func: func, equation: equation });
|
|
|
|
|
|
|
|
return index - 1;
|
|
|
|
},
|
|
|
|
|
2018-03-15 21:15:39 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#updateBlendMode
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {integer} index - [description]
|
|
|
|
* @param {function} func - [description]
|
|
|
|
* @param {function} equation - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer.
|
|
|
|
*/
|
2018-02-14 16:20:56 +00:00
|
|
|
updateBlendMode: function (index, func, equation)
|
|
|
|
{
|
|
|
|
if (this.blendModes[index])
|
|
|
|
{
|
|
|
|
this.blendModes[index].func = func;
|
|
|
|
|
|
|
|
if (equation)
|
|
|
|
{
|
|
|
|
this.blendModes[index].equation = equation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-03-15 21:15:39 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#removeBlendMode
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {integer} index - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer.
|
|
|
|
*/
|
2018-02-14 16:20:56 +00:00
|
|
|
removeBlendMode: function (index)
|
|
|
|
{
|
|
|
|
if (index > 16 && this.blendModes[index])
|
|
|
|
{
|
|
|
|
this.blendModes.splice(index, 1);
|
|
|
|
}
|
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
return this;
|
2017-02-07 19:30:50 +00:00
|
|
|
},
|
2016-12-07 02:28:22 +00:00
|
|
|
|
2018-07-26 14:04:46 +00:00
|
|
|
/**
|
|
|
|
* Sets the current active texture for texture unit zero to be a blank texture.
|
|
|
|
* This only happens if there isn't a texture already in use by texture unit zero.
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setBlankTexture
|
|
|
|
* @private
|
|
|
|
* @since 3.12.0
|
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer.
|
|
|
|
*/
|
|
|
|
setBlankTexture: function ()
|
|
|
|
{
|
|
|
|
if (this.currentActiveTextureUnit !== 0 || !this.currentTextures[0])
|
|
|
|
{
|
|
|
|
this.setTexture2D(this.blankTexture.glTexture, 0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Binds a texture at a texture unit. If a texture is already
|
|
|
|
* bound to that unit it will force a flush on the current pipeline.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setTexture2D
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @param {WebGLTexture} texture - The WebGL texture that needs to be bound
|
|
|
|
* @param {integer} textureUnit - The texture unit to which the texture will be bound
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-03-15 21:15:39 +00:00
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer.
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
setTexture2D: function (texture, textureUnit)
|
2017-02-07 19:30:50 +00:00
|
|
|
{
|
2018-01-17 21:25:43 +00:00
|
|
|
var gl = this.gl;
|
2017-05-16 19:15:01 +00:00
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
if (texture !== this.currentTextures[textureUnit])
|
2017-05-16 19:15:01 +00:00
|
|
|
{
|
2018-01-23 19:29:47 +00:00
|
|
|
this.flush();
|
|
|
|
|
2018-02-14 19:45:22 +00:00
|
|
|
if (this.currentActiveTextureUnit !== textureUnit)
|
|
|
|
{
|
|
|
|
gl.activeTexture(gl.TEXTURE0 + textureUnit);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-02-14 19:45:22 +00:00
|
|
|
this.currentActiveTextureUnit = textureUnit;
|
|
|
|
}
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
2017-05-16 19:15:01 +00:00
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
this.currentTextures[textureUnit] = texture;
|
|
|
|
}
|
2016-12-07 02:28:22 +00:00
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
return this;
|
2017-05-16 19:15:01 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Binds a framebuffer. If there was another framebuffer already bound
|
|
|
|
* it will force a pipeline flush.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setFramebuffer
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @param {WebGLFramebuffer} framebuffer - The framebuffer that needs to be bound
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-03-15 21:15:39 +00:00
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer.
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
setFramebuffer: function (framebuffer)
|
2017-01-23 21:42:47 +00:00
|
|
|
{
|
2017-12-01 21:55:27 +00:00
|
|
|
var gl = this.gl;
|
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
if (framebuffer !== this.currentFramebuffer)
|
2017-10-17 03:17:28 +00:00
|
|
|
{
|
2018-01-23 19:29:47 +00:00
|
|
|
this.flush();
|
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-25 05:26:14 +00:00
|
|
|
this.currentFramebuffer = framebuffer;
|
2017-10-17 03:17:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
return this;
|
2017-02-13 15:27:32 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Binds a program. If there was another program already bound
|
|
|
|
* it will force a pipeline flush
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setProgram
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @param {WebGLProgram} program - The program that needs to be bound
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-03-15 21:15:39 +00:00
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer.
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-22 21:21:47 +00:00
|
|
|
setProgram: function (program)
|
|
|
|
{
|
|
|
|
var gl = this.gl;
|
|
|
|
|
|
|
|
if (program !== this.currentProgram)
|
|
|
|
{
|
2018-01-23 19:29:47 +00:00
|
|
|
this.flush();
|
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
gl.useProgram(program);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-25 05:26:14 +00:00
|
|
|
this.currentProgram = program;
|
2018-01-22 21:21:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Bounds a vertex buffer. If there is a vertex buffer already bound
|
|
|
|
* it'll force a pipeline flush.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setVertexBuffer
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @param {WebGLBuffer} vertexBuffer - The buffer that needs to be bound
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-03-15 21:15:39 +00:00
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer.
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
setVertexBuffer: function (vertexBuffer)
|
2017-02-13 15:27:32 +00:00
|
|
|
{
|
2018-01-17 21:25:43 +00:00
|
|
|
var gl = this.gl;
|
2017-06-08 16:15:02 +00:00
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
if (vertexBuffer !== this.currentVertexBuffer)
|
2017-02-13 15:27:32 +00:00
|
|
|
{
|
2018-01-23 19:29:47 +00:00
|
|
|
this.flush();
|
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-25 05:26:14 +00:00
|
|
|
this.currentVertexBuffer = vertexBuffer;
|
2017-02-13 15:27:32 +00:00
|
|
|
}
|
2017-06-08 16:15:02 +00:00
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
return this;
|
2017-03-21 20:45:57 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Bounds a index buffer. If there is a index buffer already bound
|
|
|
|
* it'll force a pipeline flush.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setIndexBuffer
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @param {WebGLBuffer} indexBuffer - The buffer the needs to be bound
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-03-15 21:15:39 +00:00
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer.
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-17 21:25:43 +00:00
|
|
|
setIndexBuffer: function (indexBuffer)
|
2017-05-20 01:16:45 +00:00
|
|
|
{
|
|
|
|
var gl = this.gl;
|
2017-06-08 16:15:02 +00:00
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
if (indexBuffer !== this.currentIndexBuffer)
|
2017-06-08 16:15:02 +00:00
|
|
|
{
|
2018-01-23 19:29:47 +00:00
|
|
|
this.flush();
|
2018-03-19 20:41:24 +00:00
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-25 05:26:14 +00:00
|
|
|
this.currentIndexBuffer = indexBuffer;
|
2017-06-08 16:15:02 +00:00
|
|
|
}
|
2017-05-20 01:16:45 +00:00
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
return this;
|
2017-05-20 01:16:45 +00:00
|
|
|
},
|
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
/* Renderer Resource Creation Functions */
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Creates a texture from an image source. If the source is not valid
|
|
|
|
* it creates an empty texture
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#createTextureFromSource
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {object} source - [description]
|
2018-02-16 18:07:49 +00:00
|
|
|
* @param {integer} width - [description]
|
|
|
|
* @param {integer} height - [description]
|
|
|
|
* @param {integer} scaleMode - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @return {WebGLTexture} [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-24 00:40:20 +00:00
|
|
|
createTextureFromSource: function (source, width, height, scaleMode)
|
2018-02-16 18:17:51 +00:00
|
|
|
{
|
2018-01-20 04:05:56 +00:00
|
|
|
var gl = this.gl;
|
|
|
|
var filter = gl.NEAREST;
|
|
|
|
var wrap = gl.CLAMP_TO_EDGE;
|
2018-01-24 00:40:20 +00:00
|
|
|
var texture = null;
|
2018-01-20 04:05:56 +00:00
|
|
|
|
|
|
|
width = source ? source.width : width;
|
|
|
|
height = source ? source.height : height;
|
|
|
|
|
|
|
|
if (IsSizePowerOfTwo(width, height))
|
|
|
|
{
|
|
|
|
wrap = gl.REPEAT;
|
|
|
|
}
|
|
|
|
|
2018-06-28 11:59:27 +00:00
|
|
|
if (scaleMode === CONST.ScaleModes.LINEAR && this.config.antialias)
|
2018-01-20 04:05:56 +00:00
|
|
|
{
|
2018-01-24 00:40:20 +00:00
|
|
|
filter = gl.LINEAR;
|
|
|
|
}
|
2018-01-20 04:05:56 +00:00
|
|
|
|
2018-01-24 00:40:20 +00:00
|
|
|
if (!source && typeof width === 'number' && typeof height === 'number')
|
|
|
|
{
|
|
|
|
texture = this.createTexture2D(0, filter, filter, wrap, wrap, gl.RGBA, null, width, height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
texture = this.createTexture2D(0, filter, filter, wrap, wrap, gl.RGBA, source);
|
2018-01-20 04:05:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-24 00:40:20 +00:00
|
|
|
return texture;
|
2018-01-20 04:05:56 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* A wrapper for creating a WebGLTexture. If not pixel data is passed
|
|
|
|
* it will create an empty texture.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#createTexture2D
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @param {integer} mipLevel - Mip level of the texture
|
|
|
|
* @param {integer} minFilter - Filtering of the texture
|
|
|
|
* @param {integer} magFilter - Filtering of the texture
|
|
|
|
* @param {integer} wrapT - Wrapping mode of the texture
|
|
|
|
* @param {integer} wrapS - Wrapping mode of the texture
|
|
|
|
* @param {integer} format - Which format does the texture use
|
|
|
|
* @param {object} pixels - pixel data
|
|
|
|
* @param {integer} width - Width of the texture in pixels
|
|
|
|
* @param {integer} height - Height of the texture in pixels
|
2018-06-28 11:59:27 +00:00
|
|
|
* @param {boolean} pma - Does the texture have premultiplied alpha?
|
2018-04-25 23:30:41 +00:00
|
|
|
*
|
|
|
|
* @return {WebGLTexture} Raw WebGLTexture
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-20 00:37:52 +00:00
|
|
|
createTexture2D: function (mipLevel, minFilter, magFilter, wrapT, wrapS, format, pixels, width, height, pma)
|
2018-01-17 21:25:43 +00:00
|
|
|
{
|
2018-01-20 00:37:52 +00:00
|
|
|
var gl = this.gl;
|
|
|
|
var texture = gl.createTexture();
|
|
|
|
|
2018-02-16 18:17:51 +00:00
|
|
|
pma = (pma === undefined || pma === null) ? true : pma;
|
2018-01-20 00:37:52 +00:00
|
|
|
|
|
|
|
this.setTexture2D(texture, 0);
|
2018-03-19 20:41:24 +00:00
|
|
|
|
2018-01-20 00:37:52 +00:00
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);
|
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);
|
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapS);
|
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapT);
|
|
|
|
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, pma);
|
|
|
|
|
|
|
|
if (pixels === null || pixels === undefined)
|
|
|
|
{
|
|
|
|
gl.texImage2D(gl.TEXTURE_2D, mipLevel, format, width, height, 0, format, gl.UNSIGNED_BYTE, null);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gl.texImage2D(gl.TEXTURE_2D, mipLevel, format, format, gl.UNSIGNED_BYTE, pixels);
|
|
|
|
width = pixels.width;
|
|
|
|
height = pixels.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setTexture2D(null, 0);
|
|
|
|
|
|
|
|
texture.isAlphaPremultiplied = pma;
|
|
|
|
texture.isRenderTexture = false;
|
|
|
|
texture.width = width;
|
|
|
|
texture.height = height;
|
|
|
|
|
2018-01-31 17:36:00 +00:00
|
|
|
this.nativeTextures.push(texture);
|
|
|
|
|
2018-01-20 00:37:52 +00:00
|
|
|
return texture;
|
2018-01-17 21:25:43 +00:00
|
|
|
},
|
2017-07-04 13:48:18 +00:00
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Wrapper for creating WebGLFramebuffer.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#createFramebuffer
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @param {integer} width - Width in pixels of the framebuffer
|
|
|
|
* @param {integer} height - Height in pixels of the framebuffer
|
|
|
|
* @param {WebGLTexture} renderTexture - The color texture to where the color pixels are written
|
|
|
|
* @param {boolean} addDepthStencilBuffer - Indicates if the current framebuffer support depth and stencil buffers
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @return {WebGLFramebuffer} Raw WebGLFramebuffer
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-20 00:37:52 +00:00
|
|
|
createFramebuffer: function (width, height, renderTexture, addDepthStencilBuffer)
|
2018-01-17 21:25:43 +00:00
|
|
|
{
|
2018-01-20 00:37:52 +00:00
|
|
|
var gl = this.gl;
|
|
|
|
var framebuffer = gl.createFramebuffer();
|
|
|
|
var complete = 0;
|
|
|
|
|
|
|
|
this.setFramebuffer(framebuffer);
|
|
|
|
|
|
|
|
if (addDepthStencilBuffer)
|
|
|
|
{
|
|
|
|
var depthStencilBuffer = gl.createRenderbuffer();
|
|
|
|
gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencilBuffer);
|
|
|
|
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height);
|
|
|
|
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, depthStencilBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderTexture.isRenderTexture = true;
|
|
|
|
renderTexture.isAlphaPremultiplied = false;
|
|
|
|
|
|
|
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, renderTexture, 0);
|
|
|
|
|
|
|
|
complete = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
|
|
|
|
|
|
|
|
if (complete !== gl.FRAMEBUFFER_COMPLETE)
|
|
|
|
{
|
|
|
|
var errors = {
|
|
|
|
36054: 'Incomplete Attachment',
|
|
|
|
36055: 'Missing Attachment',
|
|
|
|
36057: 'Incomplete Dimensions',
|
|
|
|
36061: 'Framebuffer Unsupported'
|
|
|
|
};
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-20 00:37:52 +00:00
|
|
|
throw new Error('Framebuffer incomplete. Framebuffer status: ' + errors[complete]);
|
|
|
|
}
|
|
|
|
|
|
|
|
framebuffer.renderTexture = renderTexture;
|
2017-07-04 13:48:18 +00:00
|
|
|
|
2018-01-20 00:37:52 +00:00
|
|
|
this.setFramebuffer(null);
|
|
|
|
|
|
|
|
return framebuffer;
|
2018-01-17 21:25:43 +00:00
|
|
|
},
|
2017-07-12 20:55:57 +00:00
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Wrapper for creating a WebGLProgram
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#createProgram
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @param {string} vertexShader - Source to the vertex shader
|
|
|
|
* @param {string} fragmentShader - Source to the fragment shader
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @return {WebGLProgram} Raw WebGLProgram
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-20 00:37:52 +00:00
|
|
|
createProgram: function (vertexShader, fragmentShader)
|
2018-01-17 21:25:43 +00:00
|
|
|
{
|
2018-01-20 00:37:52 +00:00
|
|
|
var gl = this.gl;
|
|
|
|
var program = gl.createProgram();
|
|
|
|
var vs = gl.createShader(gl.VERTEX_SHADER);
|
|
|
|
var fs = gl.createShader(gl.FRAGMENT_SHADER);
|
|
|
|
|
|
|
|
gl.shaderSource(vs, vertexShader);
|
|
|
|
gl.shaderSource(fs, fragmentShader);
|
|
|
|
gl.compileShader(vs);
|
|
|
|
gl.compileShader(fs);
|
|
|
|
|
|
|
|
if (!gl.getShaderParameter(vs, gl.COMPILE_STATUS))
|
|
|
|
{
|
2018-01-25 18:43:19 +00:00
|
|
|
throw new Error('Failed to compile Vertex Shader:\n' + gl.getShaderInfoLog(vs));
|
2018-01-20 00:37:52 +00:00
|
|
|
}
|
|
|
|
if (!gl.getShaderParameter(fs, gl.COMPILE_STATUS))
|
|
|
|
{
|
2018-01-25 18:43:19 +00:00
|
|
|
throw new Error('Failed to compile Fragment Shader:\n' + gl.getShaderInfoLog(fs));
|
2018-01-20 00:37:52 +00:00
|
|
|
}
|
2017-08-03 20:02:57 +00:00
|
|
|
|
2018-01-20 00:37:52 +00:00
|
|
|
gl.attachShader(program, vs);
|
|
|
|
gl.attachShader(program, fs);
|
|
|
|
gl.linkProgram(program);
|
|
|
|
|
|
|
|
if (!gl.getProgramParameter(program, gl.LINK_STATUS))
|
|
|
|
{
|
2018-01-25 18:43:19 +00:00
|
|
|
throw new Error('Failed to link program:\n' + gl.getProgramInfoLog(program));
|
2018-01-20 00:37:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return program;
|
2018-01-17 21:25:43 +00:00
|
|
|
},
|
2017-03-21 20:45:57 +00:00
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Wrapper for creating a vertex buffer.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#createVertexBuffer
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @param {ArrayBuffer} initialDataOrSize - It's either ArrayBuffer or an integer indicating the size of the vbo
|
|
|
|
* @param {integer} bufferUsage - How the buffer is used. gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @return {WebGLBuffer} Raw vertex buffer
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-20 00:37:52 +00:00
|
|
|
createVertexBuffer: function (initialDataOrSize, bufferUsage)
|
2018-01-17 21:25:43 +00:00
|
|
|
{
|
2018-01-20 00:37:52 +00:00
|
|
|
var gl = this.gl;
|
|
|
|
var vertexBuffer = gl.createBuffer();
|
2017-03-21 20:45:57 +00:00
|
|
|
|
2018-01-20 00:37:52 +00:00
|
|
|
this.setVertexBuffer(vertexBuffer);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-20 00:37:52 +00:00
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, initialDataOrSize, bufferUsage);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-20 00:37:52 +00:00
|
|
|
this.setVertexBuffer(null);
|
|
|
|
|
|
|
|
return vertexBuffer;
|
2017-07-04 13:48:18 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Wrapper for creating a vertex buffer.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#createIndexBuffer
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @param {ArrayBuffer} initialDataOrSize - It's either ArrayBuffer or an integer indicating the size of the vbo
|
|
|
|
* @param {integer} bufferUsage - How the buffer is used. gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @return {WebGLBuffer} Raw index buffer
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-25 00:15:51 +00:00
|
|
|
createIndexBuffer: function (initialDataOrSize, bufferUsage)
|
2017-07-04 13:48:18 +00:00
|
|
|
{
|
2018-01-20 00:37:52 +00:00
|
|
|
var gl = this.gl;
|
|
|
|
var indexBuffer = gl.createBuffer();
|
|
|
|
|
|
|
|
this.setIndexBuffer(indexBuffer);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-20 00:37:52 +00:00
|
|
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, initialDataOrSize, bufferUsage);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-20 00:37:52 +00:00
|
|
|
this.setIndexBuffer(null);
|
|
|
|
|
|
|
|
return indexBuffer;
|
2018-01-20 04:05:56 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#deleteTexture
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {WebGLTexture} texture - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-03-15 21:15:39 +00:00
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer.
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-02-23 03:44:22 +00:00
|
|
|
deleteTexture: function (texture)
|
2018-01-25 00:15:51 +00:00
|
|
|
{
|
2018-04-23 16:30:09 +00:00
|
|
|
var index = this.nativeTextures.indexOf(texture);
|
|
|
|
|
|
|
|
if (index !== -1)
|
|
|
|
{
|
|
|
|
SpliceOne(this.nativeTextures, index);
|
|
|
|
}
|
|
|
|
|
2018-02-23 03:44:22 +00:00
|
|
|
this.gl.deleteTexture(texture);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-25 00:15:51 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Wrapper for deleting a raw WebGLFramebuffer
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#deleteFramebuffer
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {WebGLFramebuffer} framebuffer - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-03-15 21:15:39 +00:00
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer.
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-02-23 03:44:22 +00:00
|
|
|
deleteFramebuffer: function (framebuffer)
|
2018-01-25 00:15:51 +00:00
|
|
|
{
|
2018-02-23 03:44:22 +00:00
|
|
|
this.gl.deleteFramebuffer(framebuffer);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-25 00:15:51 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#deleteProgram
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {WebGLProgram} program - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-03-15 21:15:39 +00:00
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer.
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-02-23 03:44:22 +00:00
|
|
|
deleteProgram: function (program)
|
2018-01-25 00:15:51 +00:00
|
|
|
{
|
2018-02-23 03:44:22 +00:00
|
|
|
this.gl.deleteProgram(program);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-25 00:15:51 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Wrapper for deleting a vertex or index buffer
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#deleteBuffer
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {WebGLBuffer} vertexBuffer - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-03-15 21:15:39 +00:00
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer.
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-02-23 03:44:22 +00:00
|
|
|
deleteBuffer: function (buffer)
|
2018-01-25 00:15:51 +00:00
|
|
|
{
|
2018-02-23 03:44:22 +00:00
|
|
|
this.gl.deleteBuffer(buffer);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-25 00:15:51 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-01-20 04:05:56 +00:00
|
|
|
/* Rendering Functions */
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Handles any clipping needed by the camera and renders the background
|
|
|
|
* color if a color is visible.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#preRenderCamera
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
|
|
|
|
*/
|
2018-01-24 03:57:33 +00:00
|
|
|
preRenderCamera: function (camera)
|
|
|
|
{
|
2018-07-18 13:32:06 +00:00
|
|
|
var cx = camera._cx;
|
|
|
|
var cy = camera._cy;
|
|
|
|
var cw = camera._cw;
|
|
|
|
var ch = camera._ch;
|
2018-03-15 21:15:39 +00:00
|
|
|
|
|
|
|
this.pushScissor(cx, cy, cw, ch);
|
2018-03-19 20:41:24 +00:00
|
|
|
|
2018-01-24 03:57:33 +00:00
|
|
|
if (camera.backgroundColor.alphaGL > 0)
|
|
|
|
{
|
|
|
|
var color = camera.backgroundColor;
|
|
|
|
var FlatTintPipeline = this.pipelines.FlatTintPipeline;
|
|
|
|
|
|
|
|
FlatTintPipeline.batchFillRect(
|
2018-02-16 18:17:51 +00:00
|
|
|
0, 0, 1, 1, 0,
|
2018-07-17 22:26:30 +00:00
|
|
|
cx, cy, cw, ch,
|
2018-01-24 03:57:33 +00:00
|
|
|
Utils.getTintFromFloats(color.redGL, color.greenGL, color.blueGL, 1.0),
|
|
|
|
color.alphaGL,
|
|
|
|
1, 0, 0, 1, 0, 0,
|
2018-02-16 18:17:51 +00:00
|
|
|
[ 1, 0, 0, 1, 0, 0 ]
|
2018-01-24 03:57:33 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
FlatTintPipeline.flush();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Renders the foreground camera effects like flash and fading.
|
|
|
|
* It resets the current scissor state.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#postRenderCamera
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
|
|
|
|
*/
|
2018-01-24 03:57:33 +00:00
|
|
|
postRenderCamera: function (camera)
|
|
|
|
{
|
2018-04-14 16:38:48 +00:00
|
|
|
var FlatTintPipeline = this.pipelines.FlatTintPipeline;
|
2018-01-24 03:57:33 +00:00
|
|
|
|
2018-04-15 04:05:03 +00:00
|
|
|
var isFlashing = camera.flashEffect.postRenderWebGL(FlatTintPipeline, Utils.getTintFromFloats);
|
|
|
|
var isFading = camera.fadeEffect.postRenderWebGL(FlatTintPipeline, Utils.getTintFromFloats);
|
2018-01-24 03:57:33 +00:00
|
|
|
|
2018-04-14 16:38:48 +00:00
|
|
|
if (isFading || isFlashing)
|
|
|
|
{
|
2018-01-24 03:57:33 +00:00
|
|
|
FlatTintPipeline.flush();
|
|
|
|
}
|
|
|
|
|
2018-07-12 00:13:34 +00:00
|
|
|
camera.dirty = false;
|
|
|
|
|
2018-01-24 18:55:23 +00:00
|
|
|
this.popScissor();
|
2018-01-24 03:57:33 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Clears the current vertex buffer and updates pipelines.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#preRender
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-20 04:05:56 +00:00
|
|
|
preRender: function ()
|
|
|
|
{
|
2018-02-16 18:17:51 +00:00
|
|
|
if (this.contextLost) { return; }
|
2018-01-20 04:05:56 +00:00
|
|
|
|
2018-01-22 22:51:15 +00:00
|
|
|
var gl = this.gl;
|
2018-02-06 20:37:13 +00:00
|
|
|
var color = this.config.backgroundColor;
|
2018-01-26 23:17:11 +00:00
|
|
|
var pipelines = this.pipelines;
|
2018-01-22 22:51:15 +00:00
|
|
|
|
|
|
|
// Bind custom framebuffer here
|
|
|
|
gl.clearColor(color.redGL, color.greenGL, color.blueGL, color.alphaGL);
|
2018-02-05 22:06:02 +00:00
|
|
|
|
2018-02-06 20:37:13 +00:00
|
|
|
if (this.config.clearBeforeRender)
|
2018-03-15 21:15:39 +00:00
|
|
|
{
|
|
|
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
|
|
|
|
}
|
2018-01-26 23:17:11 +00:00
|
|
|
|
|
|
|
for (var key in pipelines)
|
|
|
|
{
|
|
|
|
pipelines[key].onPreRender();
|
|
|
|
}
|
2018-01-20 04:05:56 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#render
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Scene} scene - [description]
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {Phaser.GameObjects.GameObject} children - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
* @param {number} interpolationPercentage - [description]
|
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
|
|
|
|
*/
|
2018-01-20 04:05:56 +00:00
|
|
|
render: function (scene, children, interpolationPercentage, camera)
|
|
|
|
{
|
2018-02-16 18:17:51 +00:00
|
|
|
if (this.contextLost) { return; }
|
2018-01-20 04:05:56 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
var list = children.list;
|
|
|
|
var childCount = list.length;
|
2018-01-29 21:46:48 +00:00
|
|
|
var pipelines = this.pipelines;
|
|
|
|
|
|
|
|
for (var key in pipelines)
|
|
|
|
{
|
|
|
|
pipelines[key].onRender(scene, camera);
|
|
|
|
}
|
2018-01-22 21:37:47 +00:00
|
|
|
|
2018-07-10 12:59:49 +00:00
|
|
|
// Apply scissor for cam region + render background color, if not transparent
|
2018-01-24 03:57:33 +00:00
|
|
|
this.preRenderCamera(camera);
|
2018-01-22 21:37:47 +00:00
|
|
|
|
2018-07-19 12:19:02 +00:00
|
|
|
for (var i = 0; i < childCount; i++)
|
2018-01-22 21:21:47 +00:00
|
|
|
{
|
2018-07-19 12:19:02 +00:00
|
|
|
var child = list[i];
|
2018-01-22 21:21:47 +00:00
|
|
|
|
2018-07-19 12:19:02 +00:00
|
|
|
if (!child.willRender(camera))
|
2018-01-22 21:21:47 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-01-22 21:37:47 +00:00
|
|
|
if (child.blendMode !== this.currentBlendMode)
|
|
|
|
{
|
|
|
|
this.setBlendMode(child.blendMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child.mask)
|
|
|
|
{
|
|
|
|
child.mask.preRenderWebGL(this, child, camera);
|
|
|
|
}
|
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
child.renderWebGL(this, child, interpolationPercentage, camera);
|
|
|
|
|
2018-01-22 21:37:47 +00:00
|
|
|
if (child.mask)
|
|
|
|
{
|
|
|
|
child.mask.postRenderWebGL(this, child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-23 23:36:49 +00:00
|
|
|
this.flush();
|
2018-01-24 03:57:33 +00:00
|
|
|
this.setBlendMode(CONST.BlendModes.NORMAL);
|
2018-07-10 12:59:49 +00:00
|
|
|
|
|
|
|
// Applies camera effects and pops the scissor, if set
|
2018-01-24 03:57:33 +00:00
|
|
|
this.postRenderCamera(camera);
|
2018-01-20 04:05:56 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#postRender
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-20 04:05:56 +00:00
|
|
|
postRender: function ()
|
|
|
|
{
|
2018-02-16 18:17:51 +00:00
|
|
|
if (this.contextLost) { return; }
|
2018-01-20 04:05:56 +00:00
|
|
|
|
2018-01-22 22:51:15 +00:00
|
|
|
// Unbind custom framebuffer here
|
|
|
|
|
2018-01-20 04:05:56 +00:00
|
|
|
if (this.snapshotState.callback)
|
|
|
|
{
|
|
|
|
this.snapshotState.callback(WebGLSnapshot(this.canvas, this.snapshotState.type, this.snapshotState.encoder));
|
|
|
|
this.snapshotState.callback = null;
|
|
|
|
}
|
2018-01-26 23:17:11 +00:00
|
|
|
|
|
|
|
var pipelines = this.pipelines;
|
|
|
|
|
|
|
|
for (var key in pipelines)
|
|
|
|
{
|
|
|
|
pipelines[key].onPostRender();
|
|
|
|
}
|
2018-01-20 04:05:56 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#snapshot
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-03-19 20:41:24 +00:00
|
|
|
* @param {SnapshotCallback} callback - [description]
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {string} type - [description]
|
2018-06-26 22:19:14 +00:00
|
|
|
* @param {number} encoderOptions - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-20 04:05:56 +00:00
|
|
|
snapshot: function (callback, type, encoderOptions)
|
|
|
|
{
|
|
|
|
this.snapshotState.callback = callback;
|
|
|
|
this.snapshotState.type = type;
|
|
|
|
this.snapshotState.encoder = encoderOptions;
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-20 04:05:56 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#canvasToTexture
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {HTMLCanvasElement} srcCanvas - [description]
|
2018-04-23 16:30:09 +00:00
|
|
|
* @param {WebGLTexture} [dstTexture] - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @return {WebGLTexture} [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-03-05 01:45:28 +00:00
|
|
|
canvasToTexture: function (srcCanvas, dstTexture)
|
2018-01-20 04:05:56 +00:00
|
|
|
{
|
|
|
|
var gl = this.gl;
|
|
|
|
|
|
|
|
if (!dstTexture)
|
|
|
|
{
|
2018-02-06 15:46:05 +00:00
|
|
|
var wrapping = gl.CLAMP_TO_EDGE;
|
|
|
|
|
|
|
|
if (IsSizePowerOfTwo(srcCanvas.width, srcCanvas.height))
|
|
|
|
{
|
|
|
|
wrapping = gl.REPEAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
dstTexture = this.createTexture2D(0, gl.NEAREST, gl.NEAREST, wrapping, wrapping, gl.RGBA, srcCanvas, srcCanvas.width, srcCanvas.height, true);
|
2018-01-20 04:05:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-24 03:03:43 +00:00
|
|
|
this.setTexture2D(dstTexture, 0);
|
2018-01-20 04:05:56 +00:00
|
|
|
|
2018-04-23 16:30:09 +00:00
|
|
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, srcCanvas);
|
|
|
|
|
|
|
|
dstTexture.width = srcCanvas.width;
|
|
|
|
dstTexture.height = srcCanvas.height;
|
2018-01-20 04:05:56 +00:00
|
|
|
|
2018-01-24 03:03:43 +00:00
|
|
|
this.setTexture2D(null, 0);
|
2018-01-20 04:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return dstTexture;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setTextureFilter
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-16 18:07:49 +00:00
|
|
|
* @param {integer} texture - [description]
|
|
|
|
* @param {integer} filter - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-20 04:05:56 +00:00
|
|
|
setTextureFilter: function (texture, filter)
|
|
|
|
{
|
|
|
|
var gl = this.gl;
|
|
|
|
var glFilter = [ gl.LINEAR, gl.NEAREST ][filter];
|
|
|
|
|
|
|
|
this.setTexture2D(texture, 0);
|
|
|
|
|
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, glFilter);
|
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, glFilter);
|
|
|
|
|
|
|
|
this.setTexture2D(null, 0);
|
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setFloat1
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {WebGLProgram} program - [description]
|
|
|
|
* @param {string} name - [description]
|
2018-06-26 22:19:14 +00:00
|
|
|
* @param {number} x - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-22 21:21:47 +00:00
|
|
|
setFloat1: function (program, name, x)
|
|
|
|
{
|
|
|
|
this.setProgram(program);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
this.gl.uniform1f(this.gl.getUniformLocation(program, name), x);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setFloat2
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {WebGLProgram} program - [description]
|
|
|
|
* @param {string} name - [description]
|
2018-06-26 22:19:14 +00:00
|
|
|
* @param {number} x - [description]
|
|
|
|
* @param {number} y - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-22 21:21:47 +00:00
|
|
|
setFloat2: function (program, name, x, y)
|
|
|
|
{
|
|
|
|
this.setProgram(program);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
this.gl.uniform2f(this.gl.getUniformLocation(program, name), x, y);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setFloat3
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {WebGLProgram} program - [description]
|
|
|
|
* @param {string} name - [description]
|
2018-06-26 22:19:14 +00:00
|
|
|
* @param {number} x - [description]
|
|
|
|
* @param {number} y - [description]
|
|
|
|
* @param {number} z - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-22 21:21:47 +00:00
|
|
|
setFloat3: function (program, name, x, y, z)
|
|
|
|
{
|
|
|
|
this.setProgram(program);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
this.gl.uniform3f(this.gl.getUniformLocation(program, name), x, y, z);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Sets uniform of a WebGLProgram
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setFloat4
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @param {WebGLProgram} program - Target program
|
|
|
|
* @param {string} name - Name of the uniform
|
2018-06-26 22:19:14 +00:00
|
|
|
* @param {number} x - X component
|
|
|
|
* @param {number} y - Y component
|
|
|
|
* @param {number} z - Z component
|
|
|
|
* @param {number} w - W component
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-22 21:21:47 +00:00
|
|
|
setFloat4: function (program, name, x, y, z, w)
|
|
|
|
{
|
|
|
|
this.setProgram(program);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
this.gl.uniform4f(this.gl.getUniformLocation(program, name), x, y, z, w);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setInt1
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {WebGLProgram} program - [description]
|
|
|
|
* @param {string} name - [description]
|
2018-02-16 18:07:49 +00:00
|
|
|
* @param {integer} x - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-22 21:21:47 +00:00
|
|
|
setInt1: function (program, name, x)
|
|
|
|
{
|
|
|
|
this.setProgram(program);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
this.gl.uniform1i(this.gl.getUniformLocation(program, name), x);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setInt2
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {WebGLProgram} program - [description]
|
|
|
|
* @param {string} name - [description]
|
2018-02-16 18:07:49 +00:00
|
|
|
* @param {integer} x - [description]
|
|
|
|
* @param {integer} y - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-22 21:21:47 +00:00
|
|
|
setInt2: function (program, name, x, y)
|
|
|
|
{
|
|
|
|
this.setProgram(program);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
this.gl.uniform2i(this.gl.getUniformLocation(program, name), x, y);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setInt3
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {WebGLProgram} program - [description]
|
|
|
|
* @param {string} name - [description]
|
2018-02-16 18:07:49 +00:00
|
|
|
* @param {integer} x - [description]
|
|
|
|
* @param {integer} y - [description]
|
|
|
|
* @param {integer} z - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-22 21:21:47 +00:00
|
|
|
setInt3: function (program, name, x, y, z)
|
|
|
|
{
|
|
|
|
this.setProgram(program);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
this.gl.uniform3i(this.gl.getUniformLocation(program, name), x, y, z);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Sets uniform of a WebGLProgram
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setInt4
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @param {WebGLProgram} program - Target Program
|
|
|
|
* @param {string} name - Name of the uniform
|
|
|
|
* @param {integer} x - X component
|
|
|
|
* @param {integer} y - Y component
|
|
|
|
* @param {integer} z - Z component
|
|
|
|
* @param {integer} w - W component
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-22 21:21:47 +00:00
|
|
|
setInt4: function (program, name, x, y, z, w)
|
|
|
|
{
|
|
|
|
this.setProgram(program);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
this.gl.uniform4i(this.gl.getUniformLocation(program, name), x, y, z, w);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setMatrix2
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {WebGLProgram} program - [description]
|
|
|
|
* @param {string} name - [description]
|
|
|
|
* @param {boolean} transpose - [description]
|
|
|
|
* @param {Float32Array} matrix - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-22 21:21:47 +00:00
|
|
|
setMatrix2: function (program, name, transpose, matrix)
|
|
|
|
{
|
|
|
|
this.setProgram(program);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
this.gl.uniformMatrix2fv(this.gl.getUniformLocation(program, name), transpose, matrix);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setMatrix3
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-13 00:12:17 +00:00
|
|
|
* @param {WebGLProgram} program - [description]
|
|
|
|
* @param {string} name - [description]
|
|
|
|
* @param {boolean} transpose - [description]
|
|
|
|
* @param {Float32Array} matrix - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-22 21:21:47 +00:00
|
|
|
setMatrix3: function (program, name, transpose, matrix)
|
|
|
|
{
|
|
|
|
this.setProgram(program);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
this.gl.uniformMatrix3fv(this.gl.getUniformLocation(program, name), transpose, matrix);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 23:30:41 +00:00
|
|
|
* Sets uniform of a WebGLProgram
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#setMatrix4
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-25 23:30:41 +00:00
|
|
|
* @param {WebGLProgram} program - Target program
|
|
|
|
* @param {string} name - Name of the uniform
|
|
|
|
* @param {boolean} transpose - Is the matrix transposed
|
|
|
|
* @param {Float32Array} matrix - Matrix data
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
|
|
|
*/
|
2018-01-22 21:21:47 +00:00
|
|
|
setMatrix4: function (program, name, transpose, matrix)
|
|
|
|
{
|
|
|
|
this.setProgram(program);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
this.gl.uniformMatrix4fv(this.gl.getUniformLocation(program, name), transpose, matrix);
|
2018-03-15 21:15:39 +00:00
|
|
|
|
2018-01-20 04:05:56 +00:00
|
|
|
return this;
|
2018-01-31 03:38:10 +00:00
|
|
|
},
|
|
|
|
|
2018-05-09 11:12:16 +00:00
|
|
|
/**
|
|
|
|
* Returns the maximum number of texture units that can be used in a fragment shader.
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#getMaxTextures
|
|
|
|
* @since 3.8.0
|
|
|
|
*
|
|
|
|
* @return {integer} The maximum number of textures WebGL supports.
|
|
|
|
*/
|
|
|
|
getMaxTextures: function ()
|
|
|
|
{
|
|
|
|
return this.config.maxTextures;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the largest texture size (either width or height) that can be created.
|
|
|
|
* Note that VRAM may not allow a texture of any given size, it just expresses
|
|
|
|
* hardware / driver support for a given size.
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#getMaxTextureSize
|
|
|
|
* @since 3.8.0
|
|
|
|
*
|
|
|
|
* @return {integer} ...
|
|
|
|
*/
|
|
|
|
getMaxTextureSize: function ()
|
|
|
|
{
|
|
|
|
return this.config.maxTextureSize;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.WebGLRenderer#destroy
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-31 03:38:10 +00:00
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
// Clear-up anything that should be cleared :)
|
2018-01-31 17:36:00 +00:00
|
|
|
for (var key in this.pipelines)
|
|
|
|
{
|
|
|
|
this.pipelines[key].destroy();
|
2018-04-23 18:11:16 +00:00
|
|
|
|
2018-01-31 17:36:00 +00:00
|
|
|
delete this.pipelines[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var index = 0; index < this.nativeTextures.length; ++index)
|
|
|
|
{
|
|
|
|
this.deleteTexture(this.nativeTextures[index]);
|
2018-04-23 18:11:16 +00:00
|
|
|
|
2018-02-16 18:17:51 +00:00
|
|
|
delete this.nativeTextures[index];
|
2018-01-31 17:36:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete this.gl;
|
|
|
|
delete this.game;
|
2018-01-31 03:38:10 +00:00
|
|
|
|
2018-01-31 17:36:00 +00:00
|
|
|
this.contextLost = true;
|
|
|
|
this.extensions = {};
|
|
|
|
this.nativeTextures.length = 0;
|
2017-01-23 21:42:47 +00:00
|
|
|
}
|
2017-07-04 13:48:18 +00:00
|
|
|
|
|
|
|
});
|
2016-12-07 02:28:22 +00:00
|
|
|
|
2018-01-17 21:25:43 +00:00
|
|
|
module.exports = WebGLRenderer;
|