UNPKG

phaser

Version:

A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers from the team at Phaser Studio Inc.

476 lines (390 loc) 164 kB
# Phaser 3 Change Log ## Version 3.50.0 - Subaru - 16th December 2020 Due to the massive amount of changes in 3.50 this Change Log is, by its nature, very long. It's important to scan through it, especially if you're porting a game from an earlier version of Phaser to 3.50. However, if you're after more top-level descriptions of what's new, with example code, then please see the posts we will be making to the Phaser site and Phaser Patreon in the coming months after release. We have also updated the Phaser 3 Examples site, so that every single example up there has been rewritten for 3.50, so you don't have to struggle working through old or deprecated syntax. Virtually all new features are covered in new examples, as well. With that said, we've tried to organize the Change Log into commonly themed sections to make it more digestible, but we appreciate there is a lot here. Please don't feel overwhelmed! If you need clarification about something, join us on the Phaser Discord and feel free to ask. ### WebGL Pipelines and Post Processing WebGL Pipelines are responsible for the rendering of all Game Objects in Phaser and they have had a complete rewrite in 3.50. This was to allow for the introduction of post processing pipelines, now readily available to be created from the new Post FX Pipeline class. The changes in this area have been extensive, so if you use custom WebGL Pipelines in your game already, you must update your code to use Phaser 3.50. #### Pipeline Manager The `WebGL.PipelineManager` is a new class that is responsible for managing all of the WebGL Pipelines in Phaser. An instance of the Pipeline Manager is created by the WebGL Renderer and is available under the `pipelines` property. This means that the WebGL Renderer no longer handles pipelines directly, causing the following API changes: * `WebGLRenderer.pipelines` is no longer a plain object containing pipeline instances. It's now an instance of the `PipelineManager` class. This instance is created during the init and boot phase of the renderer. * The `WebGLRenderer.currentPipeline` property no longer exists, instead use `PipelineManager.current`. * The `WebGLRenderer.previousPipeline` property no longer exists, instead use `PipelineManager.previous`. * The `WebGLRenderer.hasPipeline` method no longer exists, instead use `PipelineManager.has`. * The `WebGLRenderer.getPipeline` method no longer exists, instead use `PipelineManager.get`. * The `WebGLRenderer.removePipeline` method no longer exists, instead use `PipelineManager.remove`. * The `WebGLRenderer.addPipeline` method no longer exists, instead use `PipelineManager.add`. * The `WebGLRenderer.setPipeline` method no longer exists, instead use `PipelineManager.set`. * The `WebGLRenderer.rebindPipeline` method no longer exists, instead use `PipelineManager.rebind`. * The `WebGLRenderer.clearPipeline` method no longer exists, instead use `PipelineManager.clear`. The Pipeline Manager also offers the following new features: * The `PipelineManager.resize` method automatically handles resize events across all pipelines. * The `PipelineManager.preRender` method calls the pre-render method of all pipelines. * The `PipelineManager.render` method calls the render method of all pipelines. * The `PipelineManager.postRender` method calls the post-render method of all pipelines. * The `PipelineManager.setMulti` method automatically binds the Multi Texture Pipeline, Phasers default. * The `PipelineManager.clear` method will clear the pipeline, store it in `previous` and free the renderer. * The `PipelineManager.rebind` method will reset the rendering context and restore the `previous` pipeline, if set. * The `PipelineManager.copyFrame` method will copy a `source` Render Target to the `target` Render Target, optionally setting the brightness of the copy. * The `PipelineManager.blitFrame` method will copy a `source` Render Target to the `target` Render Target. Unlike `copyFrame` no resizing takes place and you can optionally set the brightness and erase mode of the copy. * The `PipelineManager.copyFrameRect` method binds the `source` Render Target and then copies a section of it to the `target` using `gl.copyTexSubImage2D` rather than a shader, making it much faster if you don't need blending or preserving alpha details. * The `PipelineManager.copyToGame` method pops the framebuffer from the renderers FBO stack and sets that as the active target, then draws the `source` Render Target to it. Use when you need to render the _final_ result to the game canvas. * The `PipelineManager.drawFrame` method will copy a `source` Render Target, optionally to a `target` Render Target, using the given ColorMatrix, allowing for full control over the luminance values used during the copy. * The `PipelineManager.blendFrames` method draws the `source1` and `source2` Render Targets to the `target` Render Target using a linear blend effect, which is controlled by the `strength` parameter. * The `PipelineManager.blendFramesAdditive` method draws the `source1` and `source2` Render Targets to the `target` Render Target using an additive blend effect, which is controlled by the `strength` parameter. * The `PipelineManager.clearFrame` method clears the given Render Target. New constants have been created to help you reference a pipeline without needing to use strings: * `Phaser.Renderer.WebGL.Pipelines.BITMAPMASK_PIPELINE` for the Bitmap Mask Pipeline. * `Phaser.Renderer.WebGL.Pipelines.LIGHT_PIPELINE` for the Light 2D Pipeline. * `Phaser.Renderer.WebGL.Pipelines.SINGLE_PIPELINE` for the Single Pipeline. * `Phaser.Renderer.WebGL.Pipelines.MULTI_PIPELINE` for the Multi Pipeline. * `Phaser.Renderer.WebGL.Pipelines.ROPE_PIPELINE` for the Rope Pipeline. * `Phaser.Renderer.WebGL.Pipelines.POINTLIGHT_PIPELINE` for the Point Light Pipeline. * `Phaser.Renderer.WebGL.Pipelines.POSTFX_PIPELINE` for the Post FX Pipeline. * `Phaser.Renderer.WebGL.Pipelines.UTILITY_PIPELINE` for the Utility Pipeline. All Game Objects have been updated to use the new constants and Pipeline Manager. #### Post FX Pipeline The Post FX Pipeline is a brand new and special kind of pipeline specifically for handling post processing effects in Phaser 3.50. Where-as a standard Pipeline allows you to control the process of rendering Game Objects by configuring the shaders and attributes used to draw them, a Post FX Pipeline is designed to allow you to apply processing _after_ the Game Object/s have been rendered. Typical examples of post processing effects are bloom filters, blurs, light effects and color manipulation. The pipeline works by creating a tiny vertex buffer with just one single hard-coded quad in it. Game Objects can have a Post Pipeline set on them, which becomes their own unique pipeline instance. Those objects are then rendered using their standard pipeline, but are redirected to the Render Targets owned by the post pipeline, which can then apply their own shaders and effects, before passing them back to the main renderer. The following properties and methods are available in the new `PostFXPipeline` class: * The `PostFXPipeline.gameObject` property is a reference to the Game Object that owns the Post Pipeline, if any. * The `PostFXPipeline.colorMatrix` property is a Color Matrix instance used by the draw shader. * The `PostFXPipeline.fullFrame1` property is a reference to the `fullFrame1` Render Target that belongs to the Utility Pipeline, as it's commonly used in post processing. * The `PostFXPipeline.fullFrame2` property is a reference to the `fullFrame2` Render Target that belongs to the Utility Pipeline, as it's commonly used in post processing. * The `PostFXPipeline.halfFrame1` property is a reference to the `halfFrame1` Render Target that belongs to the Utility Pipeline, as it's commonly used in post processing. * The `PostFXPipeline.halfFrame2` property is a reference to the `halfFrame2` Render Target that belongs to the Utility Pipeline, as it's commonly used in post processing. * The `PostFXPipeline.copyFrame` method will copy a `source` Render Target to the `target` Render Target, optionally setting the brightness of the copy. * The `PostFXPipeline.blitFrame` method will copy a `source` Render Target to the `target` Render Target. Unlike `copyFrame` no resizing takes place and you can optionally set the brightness and erase mode of the copy. * The `PostFXPipeline.copyFrameRect` method binds the `source` Render Target and then copies a section of it to the `target` using `gl.copyTexSubImage2D` rather than a shader, making it much faster if you don't need blending or preserving alpha details. * The `PostFXPipeline.copyToGame` method pops the framebuffer from the renderers FBO stack and sets that as the active target, then draws the `source` Render Target to it. Use when you need to render the _final_ result to the game canvas. * The `PostFXPipeline.drawFrame` method will copy a `source` Render Target, optionally to a `target` Render Target, using the given ColorMatrix, allowing for full control over the luminance values used during the copy. * The `PostFXPipeline.blendFrames` method draws the `source1` and `source2` Render Targets to the `target` Render Target using a linear blend effect, which is controlled by the `strength` parameter. * The `PostFXPipeline.blendFramesAdditive` method draws the `source1` and `source2` Render Targets to the `target` Render Target using an additive blend effect, which is controlled by the `strength` parameter. * The `PostFXPipeline.clearFrame` method clears the given Render Target. * The `PostFXPipeline.bindAndDraw` method binds this pipeline and draws the `source` Render Target to the `target` Render Target. This is typically the final step taken in when post processing. #### Renamed WebGL Pipelines Due to the huge amount of work that has taken place in this area, all of the pipelines have been renamed. If you extend any of these pipelines or use them in your game code (referenced by name), then please update accordingly. The name changes are: * `TextureTintPipeline` is now called the `MultiPipeline`. * `TextureTintStripPipeline` is now called the `RopePipeline`. * `ForwardDiffuseLightPipeline` is now called the `LightPipeline`. There is also the new `GraphicsPipeline`. Previously, the `TextureTintPipeline` was responsible for rendering all Sprites, Graphics, and Shape objects. Now, it only renders Sprites. All Graphics and Shapes are handled by the new `GraphicsPipeline`, which uses its own shaders. See below for details about this change. To match the new pipeline names, the shader source code has also been renamed. * `ForwardDiffuse.frag` is now called `Light.frag`. * `TextureTint.frag` is now called `Multi.frag`. * `TextureTint.vert` is now called `Multi.vert`. #### WebGL Pipelines Updates Further pipeline changes are as follows: * None of the shaders or pipelines use the `uViewMatrix` and `uModelMatrix` uniforms any longer. These were always just plain identity matrices, so there is no point spending CPU and GPU time to set them as uniforms or use them in the shaders. Should you need these uniforms, you can add them to your own custom pipelines. * `Types.Renderer.WebGL.WebGLPipelineConfig` is a new TypeDef that helps you easily configure your own Custom Pipeline when using TypeScript and also provides better JSDocs. * `Types.Renderer.WebGL.WebGLPipelineAttributesConfig` is a new TypeDef that helps you easily configure the attributes for your own Custom Pipelines when using TypeScript and also provides better JSDocs. * All pipelines will now work out the `renderer` property automatically, so it's no longer required in the config. * All pipelines will now work out the `gl` property automatically, so it's no longer required in the config. * All pipelines will now extract the `name` property from the config, allowing you to set it externally. * All pipelines will now extract the `vertexCapacity` property from the config, allowing you to set it externally. * All pipelines will now extract the `vertexSize` property from the config, allowing you to set it externally. * All pipelines will now extract the `vertexData` property from the config, allowing you to set it externally. * All pipelines will now extract the `attributes` property from the config, allowing you to set it externally. * All pipelines will now extract the `topology` property from the config, allowing you to set it externally. * The `WebGLPipeline.shouldFlush` method now accepts an optional parameter `amount`. If given, it will return `true` if the amount to be added to the vertex count exceeds the vertex capacity. The Multi Pipeline has been updated to now use this method instead of performing the comparison multiple times itself. * The `RopePipeline` now extends `MultiPipeline` and just changes the topology, vastly reducing the file size. * The `WebGLPipeline.flushLocked` property has been removed. A pipeline can never flush in the middle of a flush anyway, so it was just wasting CPU cycles being set. * `WebGLPipeline.manager` is a new property that is a reference to the WebGL Pipeline Manager. * `WebGLPipeline.currentUnit` is a new property that holds the most recently assigned texture unit. Treat as read-only. * `WebGLPipeline.forceZero` is a new boolean property that sets if the pipeline should force the use of texture zero. * `WebGLPipeline.hasBooted` is a new boolean property that is set once the pipeline has finished setting itself up and has booted. * `WebGLPipeline.isPostFX` is a new boolean property that is only set by Post FX Pipelines to help identify them. * `WebGLPipeline.renderTargets` is a new property that holds an array of WebGL Render Targets belonging to the pipeline. * `WebGLPipeline.currentRenderTarget` is a new property that holds a reference to the currently bound Render Target. * `WebGLPipeline.shaders` is a new property that holds an array of all WebGLShader instances that belong to the pipeline. * `WebGLPipeline.currentShader` is a new property that holds a reference to the currently active shader within the pipeline. * `WebGLPipeline.config` is a new property that holds the pipeline configuration object used to create it. * `WebGLPipeline.projectionMatrix` is a new property that holds a Matrix4 used as the projection matrix for the pipeline. * `WebGLPipeline.setProjectionMatrix` is a new method that allows you to set the ortho projection matrix of the pipeline. * `WebGLPipeline.boot` will now check all of the attributes and store the pointer location within the attribute entry. * `WebGLPipeline.bind` no longer looks-up and enables every attribute, every frame. Instead, it uses the cached pointer location stored in the attribute entry, cutting down on redundant WebGL operations. * `WebGLPipeline.setAttribPointers` is a new method that will set the vertex attribute pointers for the pipeline. * `WebGLPipeline.setShader` is a new method that allows you to set the currently active shader within the pipeline. * `WebGLPipeline.getShaderByName` is a new method that allows you to get a shader from the pipeline based on its name. * `WebGLPipeline.setShadersFromConfig` is a new method that destroys all current shaders and creates brand new ones parsed from the given config object. This is part of the pipeline boot process, but also exposed should you need to call it directly. * `WebGLPipeline.setGameObject` is a new method that custom pipelines can use in order to perform pre-batch tasks for the given Game Object. * `WebGLPipeline.setVertexBuffer` is a new method that checks if the pipelines vertex buffer is active, or not, and if not, binds it as the active buffer. This used to be performed by the WebGL Renderer, but pipelines now manage this directly. * `WebGLPipeline.preBatch` is a new method that is called when a new quad is about to be added to the batch. This is used by Post FX Pipelines to set frame buffers. * `WebGLPipeline.postBatch` is a new method that is called after a quad has been added to the batch. This is used by Post FX Pipelines to apply post processing. * `WebGLPipeline.unbind` is a new method that unbinds the current Render Target, if one is set. * `WebGLPipeline.batchVert` is a new method that adds a single vertex to the vertex buffer and increments the count by 1. * `WebGLPipeline.batchQuad` is a new method that adds a single quad (6 vertices) to the vertex buffer and increments the count, flushing first if adding the quad would exceed the batch limit. * `WebGLPipeline.batchTri` is a new method that adds a single tri (3 vertices) to the vertex buffer and increments the count, flushing first if adding the tri would exceed the batch limit. * `WebGLPipeline.drawFillRect` is a new method that pushes a filled rectangle into the vertex batch. * `WebGLPipeline.setTexture2D` is a new method that sets the texture to be bound to the next available texture unit. * `WebGLPipeline.bindTexture` is a new method that immediately activates the given WebGL Texture and binds it to the requested slot. * `WebGLPipeline.bindRenderTarget` is a new method that binds the given Render Target to a given texture slot. * `WebGLPipeline.setTime` is a new method that gets the current game loop duration to the given shader uniform. #### Pipeline Hooks The `WebGLPipeline` class has lots of new hooks you can use. These are all empty by default so you can safely override them in your own classes to take advantage of them: * `WebGLPipeline.onBoot` is a new hook you can override in your own pipelines that is called when the pipeline has booted. * `WebGLPipeline.onResize` is a new hook you can override in your own pipelines that is called when the pipeline is resized. * `WebGLPipeline.onDraw` is a new hook you can override in your own pipelines that is called by Post FX Pipelines every time `postBatch` is invoked. * `WebGLPipeline.onActive` is a new hook you can override in your own pipelines that is called every time the Pipeline Manager makes the pipeline the active pipeline. * `WebGLPipeline.onBind` is a new hook you can override in your own pipelines that is called every time a Game Object asks the Pipeline Manager to use this pipeline, even if it's already active. * `WebGLPipeline.onRebind` is a new hook you can override in your own pipelines that is called every time the Pipeline Manager needs to reset and rebind the current pipeline. * `WebGLPipeline.onBatch` is a new hook you can override in your own pipelines that is called _after_ a new quad (or tri) has been added to the batch. * `WebGLPipeline.onPreBatch` is a new hook you can override in your own pipelines that is called _before_ a new Game Object is about to process itself through the batch. * `WebGLPipeline.onPostBatch` is a new hook you can override in your own pipelines that is called _after_ a new Game Object has added itself to the batch. * `WebGLPipeline.onPreRender` is a new hook you can override in your own pipelines that is called once, per frame, right before anything has been rendered. * `WebGLPipeline.onRender` is a new hook you can override in your own pipelines that is called once, per frame, by every Camera in the Scene that wants to render, at the start of the render process. * `WebGLPipeline.onPostRender` is a new hook you can override in your own pipelines that is called once, per frame, after all rendering has happened and snapshots have been taken. * `WebGLPipeline.onBeforeFlush` is a new hook you can override in your own pipelines that is called immediately before the `gl.bufferData` and `gl.drawArrays` calls are made, so you can perform any final pre-render modifications. * `WebGLPipeline.onAfterFlush` is a new hook you can override in your own pipelines that is called after `gl.drawArrays`, so you can perform additional post-render effects. #### Pipeline Events The `WebGLPipeline` class now extends the Event Emitter and emits the following new events: * The `WebGL.Pipelines.Events.AFTER_FLUSH` event is dispatched by a WebGL Pipeline right after it has issued a `drawArrays` command. * The `WebGL.Pipelines.Events.BEFORE_FLUSH` event is dispatched by a WebGL Pipeline right before it is about to flush. * The `WebGL.Pipelines.Events.BIND` event is dispatched by a WebGL Pipeline when it is bound by the Pipeline Manager. * The `WebGL.Pipelines.Events.BOOT` event is dispatched by a WebGL Pipeline when it has finished booting. * The `WebGL.Pipelines.Events.DESTROY` event is dispatched by a WebGL Pipeline when it begins its destruction process. * The `WebGL.Pipelines.Events.REBIND` event is dispatched by a WebGL Pipeline when the Pipeline Manager resets and rebinds it. * The `WebGL.Pipelines.Events.RESIZE` event is dispatched by a WebGL Pipeline when it is resized, usually as a result of the Renderer. #### Pipeline Uniform Changes WebGLShaders have a `uniforms` object that is automatically populated when the shader is created. It scans all of the active uniforms from the compiled shader and then builds an object containing their `WebGLUniformLocation` and a value cache. This saves redundant gl operations for both looking-up uniform locations and setting their values if they're already the currently set values by using the local cache instead. The `WebGLPipeline` classes offer a means to set uniform values on the shader (or shaders) belonging to the pipeline. Previously, calling a method such as `setFloat3` on a pipeline would pass that call over to `WebGLRenderer`. The renderer would first check to see if the pipeline program was current, and if not, make it so, before then looking up the uniform location and finally setting it. This is a lot of steps to take for pipelines that potentially need to change uniforms for every Game Object they render. Under the new methods, and using the new pre-cached uniform locations and values, these extra steps are skipped. The uniform value is set directly, no shader binding takes place and no location look-up happens. This dramatically reduces the number of WebGL ops being issued per frame. To clearly differentiate these pipeline methods, we have renamed them. The new method names are as follows: * `WebGLPipeline.set1f` will set a 1f uniform based on the given name. * `WebGLPipeline.set2f` will set a 2f uniform based on the given name. * `WebGLPipeline.set3f` will set a 3f uniform based on the given name. * `WebGLPipeline.set4f` will set a 4f uniform based on the given name. * `WebGLPipeline.set1fv` will set a 1fv uniform based on the given name. * `WebGLPipeline.set2fv` will set a 2fv uniform based on the given name. * `WebGLPipeline.set3fv` will set a 3fv uniform based on the given name. * `WebGLPipeline.set4fv` will set a 4fv uniform based on the given name. * `WebGLPipeline.set1iv` will set a 1iv uniform based on the given name. * `WebGLPipeline.set2iv` will set a 2iv uniform based on the given name. * `WebGLPipeline.set3iv` will set a 3iv uniform based on the given name. * `WebGLPipeline.set4iv` will set a 4iv uniform based on the given name. * `WebGLPipeline.set1i` will set a 1i uniform based on the given name. * `WebGLPipeline.set2i` will set a 2i uniform based on the given name. * `WebGLPipeline.set3i` will set a 3i uniform based on the given name. * `WebGLPipeline.set4i` will set a 4i uniform based on the given name. * `WebGLPipeline.setMatrix2fv` will set a matrix 2fv uniform based on the given name. * `WebGLPipeline.setMatrix3fv` will set a matrix 3fv uniform based on the given name. * `WebGLPipeline.setMatrix4fv` will set a matrix 4fv uniform based on the given name. If your code uses any of the old method names, please update them using the list below: * `WebGLPipeline.setFloat1` has been removed. Please use `set1f` instead. * `WebGLPipeline.setFloat2` has been removed. Please use `set2f` instead. * `WebGLPipeline.setFloat3` has been removed. Please use `set3f` instead. * `WebGLPipeline.setFloat4` has been removed. Please use `set4f` instead. * `WebGLPipeline.setFloat1v` has been removed. Please use `set1fv` instead. * `WebGLPipeline.setFloat2v` has been removed. Please use `set2fv` instead. * `WebGLPipeline.setFloat3v` has been removed. Please use `set3fv` instead. * `WebGLPipeline.setFloat4v` has been removed. Please use `set4fv` instead. * `WebGLPipeline.setInt1` has been removed. Please use `set1i` instead. * `WebGLPipeline.setInt2` has been removed. Please use `set2i` instead. * `WebGLPipeline.setInt3` has been removed. Please use `set3i` instead. * `WebGLPipeline.setInt4` has been removed. Please use `set4i` instead. * `WebGLPipeline.setMatrix1` has been removed. Please use `setMatrix2fv` instead. * `WebGLPipeline.setMatrix2` has been removed. Please use `setMatrix3fv` instead. * `WebGLPipeline.setMatrix3` has been removed. Please use `setMatrix4fv` instead. #### Game Object Pipeline Component Updates To support the new Post Pipelines in 3.50, the Pipeline Component which most Game Objects inherit has been updated. That means the following new properties and methods are available on all Game Objects that have this component, such as Sprite, Layer, Rope, etc. * `hasPostPipeline` is a new boolean property that indicates if the Game Object has one, or more post pipelines set. * `postPipelines` is a new property that contains an array of Post Pipelines owned by the Game Object. * `pipelineData` is a new object object to store pipeline specific data in. * The `setPipeline` method has been updated with 2 new parameters: `pipelineData` and `copyData`. These allow you to populate the pipeline data object during setting. * You can now pass a pipeline instance to the `setPipeline` method, as well as a string. * `setPostPipeline` is a new method that allows you to set one, or more, Post FX Pipelines on the Game Object. And optionally set the pipeline data with them. * `setPipelineData` is a new method that allows you to set a key/value pair into the pipeline data object in a chainable way. * `getPostPipeline` is a new method that will return a Post Pipeline instance from the Game Object based on the given string, function or instance. * The `resetPipeline` method has two new parameters `resetPostPipeline` and `resetData`, both false by default, that will reset the Post Pipelines and pipeline data accordingly. * `resetPostPipeline` is a new method that will specifically reset just the Post Pipelines, and optionally the pipeline data. * `removePostPipeline` is a new method that will destroy and remove the given Post Pipeline from the Game Object. #### Utility Pipeline The Utility Pipeline is a brand new default special-use WebGL Pipeline that is created by and belongs to the Pipeline Manager. It provides 4 shaders and handy associated methods: 1) Copy Shader. A fast texture to texture copy shader with optional brightness setting. 2) Additive Blend Mode Shader. Blends two textures using an additive blend mode. 3) Linear Blend Mode Shader. Blends two textures using a linear blend mode. 4) Color Matrix Copy Shader. Draws a texture to a target using a Color Matrix. You do not extend this pipeline, but instead get a reference to it from the Pipeline Manager via the `setUtility` method. You can also access its methods, such as `copyFrame`, directly from both the Pipeline Manager and from Post FX Pipelines, where its features are most useful. This pipeline provides methods for manipulating framebuffer backed textures, such as copying or blending one texture to another, copying a portion of a texture, additively blending two textures, flipping textures and more. All essential and common operations for post processing. The following properties and methods are available in the new `UtilityPipeline` class: * The `UtilityPipeline.colorMatrix` property is an instance of a ColorMatrix class, used by the draw shader. * The `UtilityPipeline.copyShader` property is a reference to the Copy Shader. * The `UtilityPipeline.addShader` property is a reference to the additive blend shader. * The `UtilityPipeline.linearShader` property is a reference to the linear blend shader. * The `UtilityPipeline.colorMatrixShader` property is a reference to the color matrix (draw) shader. * The `UtilityPipeline.fullFrame1` property is a full sized Render Target that can be used as a temporary buffer during post processing calls. * The `UtilityPipeline.fullFrame2` property is a full sized Render Target that can be used as a temporary buffer during post processing calls. * The `UtilityPipeline.halfFrame1` property is a half sized Render Target that can be used as a temporary buffer during post processing calls, where a small texture is required for more intensive operations. * The `UtilityPipeline.halfFrame2` property is a half sized Render Target that can be used as a temporary buffer during post processing calls, where a small texture is required for more intensive operations. * The `UtilityPipeline.copyFrame` method will copy a `source` Render Target to the `target` Render Target, optionally setting the brightness of the copy. * The `UtilityPipeline.blitFrame` method will copy a `source` Render Target to the `target` Render Target. Unlike `copyFrame` no resizing takes place and you can optionally set the brightness and erase mode of the copy. * The `UtilityPipeline.copyFrameRect` method binds the `source` Render Target and then copies a section of it to the `target` using `gl.copyTexSubImage2D` rather than a shader, making it much faster if you don't need blending or preserving alpha details. * The `UtilityPipeline.copyToGame` method pops the framebuffer from the renderers FBO stack and sets that as the active target, then draws the `source` Render Target to it. Use when you need to render the _final_ result to the game canvas. * The `UtilityPipeline.drawFrame` method will copy a `source` Render Target, optionally to a `target` Render Target, using the given ColorMatrix, allowing for full control over the luminance values used during the copy. * The `UtilityPipeline.blendFrames` method draws the `source1` and `source2` Render Targets to the `target` Render Target using a linear blend effect, which is controlled by the `strength` parameter. * The `UtilityPipeline.blendFramesAdditive` method draws the `source1` and `source2` Render Targets to the `target` Render Target using an additive blend effect, which is controlled by the `strength` parameter. * The `UtilityPipeline.clearFrame` method clears the given Render Target. * The `UtilityPipeline.setUVs` method allows you to set the UV values for the 6 vertices that make-up the quad belonging to the Utility Pipeline. * The `UtilityPipeline.setTargetUVs` method sets the vertex UV coordinates of the quad used by the shaders so that they correctly adjust the texture coordinates for a blit frame effect. * The `UtilityPipeline.flipX` method horizontally flips the UV coordinates of the quad used by the shaders. * The `UtilityPipeline.flipY` method vertically flips the UV coordinates of the quad used by the shaders. * The `UtilityPipeline.resetUVs` method resets the quad vertice UV values to their default settings. #### Light Pipeline Update The Light Pipeline (previously called the Forward Diffuse Light Pipeline), which is responsible for rendering lights under WebGL, has been rewritten to work with the new Multi Pipeline features. Lots of redundant code has been removed and the following changes and improvements took place: * The pipeline now works with Game Objects that do not have a normal map. They will be rendered using the new default normal map, which allows for a flat light effect to pass over them and merge with their diffuse map colors. * Fixed a bug in the way lights were handled that caused Tilemaps to render one tile at a time, causing massive slow down. They're now batched properly, making a combination of lights and tilemaps possible again. * The Bitmap Text (Static and Dynamic) Game Objects now support rendering with normal maps. * The TileSprite Game Objects now support rendering with normal maps. * Mesh Game Objects now support rendering with normal maps. * Particle Emitter Game Object now supports rendering in Light2d. * The Text Game Object now supports rendering in Light2d, no matter which font, stroke or style it is using. * Tilemap Layer Game Objects now support the Light2d pipeline, with or without normal maps. * The pipeline will no longer look-up and set all of the light uniforms unless the `Light` is dirty. * The pipeline will no longer reset all of the lights unless the quantity of lights has changed. * The `ForwardDiffuseLightPipeline.defaultNormalMap` property has changed, it's now an object with a `glTexture` property that maps to the pipelines default normal map. * The `ForwardDiffuseLightPipeline.boot` method has been changed to now generate a default normal map. * The `ForwardDiffuseLightPipeline.onBind` method has been removed as it's no longer required. * The `ForwardDiffuseLightPipeline.setNormalMap` method has been removed as it's no longer required. * `ForwardDiffuseLightPipeline.bind` is a new method that handles setting-up the shader uniforms. * The `ForwardDiffuseLightPipeline.batchTexture` method has been rewritten to use the Texture Tint Pipeline function instead. * The `ForwardDiffuseLightPipeline.batchSprite` method has been rewritten to use the Texture Tint Pipeline function instead. * `ForwardDiffuseLightPipeline.lightCount` is a new property that stores the previous number of lights rendered. * `ForwardDiffuseLightPipeline.getNormalMap` is a new method that will look-up and return a normal map for the given object. #### Point Lights Pipeline The Point Light Pipeline is a brand new pipeline in 3.50 that was creates specifically for rendering the new Point Light Game Objects in WebGL. It extends the WebGLPipeline and sets the required shader attributes and uniforms for Point Light rendering. You typically don't access or set the pipeline directly, but rather create instances of the Point Light Game Object instead. However, it does have the following unique methods: * The `PointLightPipeline.batchPointLight` method is a special-case method that is called directly by the Point Light Game Object during rendering and allows it to add itself into the rendering batch. * The `PointLightPipeline.batchLightVert` method is a special internal method, used by `batchPointLight` that adds a single Point Light vert into the batch. #### Graphics Pipeline and Graphics Game Object Changes The Graphics Pipeline is a new pipeline added in 3.50 that is responsible for rendering Graphics Game Objects and all of the Shape Game Objects, such as Arc, Rectangle, Star, etc. Due to the new pipeline some changes have been made: * The Graphics Pipeline now uses much simpler vertex and fragment shaders with just two attributes (`inPosition` and `inColor`), making the vertex size and memory-use 57% smaller. * The private `_tempMatrix1`, 2, 3 and 4 properties have all been removed from the pipeline. * A new public `calcMatrix` property has been added, which Shape Game Objects use to maintain transform state during rendering. * The Graphics Pipeline no longer makes use of `tintEffect` or any textures. * Because Graphics and Shapes now render with their own pipeline, you are able to exclude the pipeline and those Game Objects entirely from custom builds, further reducing the final bundle size. As a result of these changes the following features are no longer available: * `Graphics.setTexture` has been removed. You can no longer use a texture as a 'fill' for a Graphic. It never worked with any shape other than a Rectangle, anyway, due to UV mapping issues, so is much better handled via the new Mesh Game Object. * `Graphics._tempMatrix1`, 2 and 3 have been removed. They're not required internally any longer. * `Graphics.renderWebGL` now uses the standard `GetCalcMatrix` function, cutting down on duplicate code significantly. #### Single Pipeline Update There is a new pipeline called `SinglePipeline`, created to emulate the old `TextureTintPipeline`. This special pipeline uses just a single texture and makes things a lot easier if you wish to create a custom pipeline, but not have to recode your shaders to work with multiple textures. Instead, just extend `SinglePipeline`, where-as before you extended the `TextureTintPipeline` and you won't have to change any of your shader code. However, if you can, you should update it to make it perform faster, but that choice is left up to you. ### WebGLShader `WebGLShader` is a new class that is created and belongs to WebGL Pipeline classes. When the pipeline is created it will create a `WebGLShader` instance for each one of its shaders, as defined in the pipeline configuration. This class encapsulates everything needed to manage a shader in a pipeline, including the shader attributes and uniforms, as well as lots of handy methods such as `set2f`, for setting uniform values on this shader. Uniform values are automatically cached to avoid unnecessary gl operations. Typically, you do not create an instance of this class directly, as it works in unison with the pipeline to which it belongs. You can gain access to this class via a pipeline's `shaders` array, post-creation. The following properties and methods are available in the new `WebGLShader` class: * The `WebGLShader.pipeline` property is a reference to the WebGL Pipeline that owns the WebGLShader instance. * The `WebGLShader.name` property is the name of the shader. * The `WebGLShader.renderer` property is a reference to the WebGL Renderer. * The `WebGLShader.gl` property is a reference to the WebGL Rendering Context. * The `WebGLShader.program` property is the WebGL Program created from the vertex and fragment shaders. * The `WebGLShader.attributes` property is an array of objects that describe the vertex attributes of the shader. * The `WebGLShader.vertexComponentCount` property is the total amount of vertex attribute components of 32-bit length. * The `WebGLShader.vertexSize` property is the size, in bytes, of a single vertex. * The `WebGLShader.uniforms` property is an object that is automatically populated with all active uniforms in the shader. * The `WebGLShader.createAttributes` method takes the vertex attributes config and parses it, creating the shader attributes. This is called automatically. * The `WebGLShader.bind` method sets the program the shader uses as being active. Called automatically when the parent pipeline needs this shader. * The `WebGLShader.rebind` method sets the program the shader uses as being active and resets all of the vertex attribute pointers. * The `WebGLShader.setAttribPointers` method sets the vertex attribute pointers. Called automatically during `bind`. * The `WebGLShader.createUniforms` method populates the `uniforms` object with details about all active uniforms. * The `WebGLShader.hasUniform` method returns a boolean if the given uniform exists. * The `WebGLShader.resetUniform` method resets the cached value for the given uniform. * The `WebGLShader.setUniform1` method is an internal method used for setting a single value uniform on the shader. * The `WebGLShader.setUniform2` method is an internal method used for setting a double value uniform on the shader. * The `WebGLShader.setUniform3` method is an internal method used for setting a triple value uniform on the shader. * The `WebGLShader.setUniform4` method is an internal method used for setting a quadruple value uniform on the shader. * The `WebGLShader.set1f` method sets a 1f uniform based on the given name. * The `WebGLShader.set2f` method sets a 2f uniform based on the given name. * The `WebGLShader.set3f` method sets a 3f uniform based on the given name. * The `WebGLShader.set4f` method sets a 4f uniform based on the given name. * The `WebGLShader.set1fv` method sets a 1fv uniform based on the given name. * The `WebGLShader.set2fv` method sets a 2fv uniform based on the given name. * The `WebGLShader.set3fv` method sets a 3fv uniform based on the given name. * The `WebGLShader.set4fv` method sets a 4fv uniform based on the given name. * The `WebGLShader.set1iv` method sets a 1iv uniform based on the given name. * The `WebGLShader.set2iv` method sets a 2iv uniform based on the given name. * The `WebGLShader.set3iv` method sets a 3iv uniform based on the given name. * The `WebGLShader.set4iv` method sets a 4iv uniform based on the given name. * The `WebGLShader.set1i` method sets a 1i uniform based on the given name. * The `WebGLShader.set2i` method sets a 2i uniform based on the given name. * The `WebGLShader.set3i` method sets a 3i uniform based on the given name. * The `WebGLShader.set4i` method sets a 4i uniform based on the given name. * The `WebGLShader.setMatrix2fv` method sets a matrix 2fv uniform based on the given name. * The `WebGLShader.setMatrix3fv` method sets a matrix 3fv uniform based on the given name. * The `WebGLShader.setMatrix4fv` method sets a matrix 4fv uniform based on the given name. * The `WebGLShader.destroy` method removes all external references and deletes the program and attributes. ### Render Target `RenderTarget` is a brand new class that encapsulates a WebGL framebuffer and the WebGL Texture that displays it. Instances of this class are typically created by, and belong to WebGL Pipelines, however other Game Objects and classes can take advantage of Render Targets as well. The following properties and methods are available in the new `RenderTarget` class: * The `RenderTarget.renderer` property is a reference to the WebGL Renderer. * The `RenderTarget.framebuffer` property is the WebGLFramebuffer belonging to the Render Target. * The `RenderTarget.texture` property is a WebGLTexture belonging to the Render Target and bound to the framebuffer. * The `RenderTarget.width` property is the width of the Render Target. * The `RenderTarget.height` property is the height of the Render Target. * The `RenderTarget.scale` property is the scale of the Render Target, applied to the dimensions during resize. * The `RenderTarget.minFilter` property is the min filter of the texture. * The `RenderTarget.autoClear` property is a boolean that controls if the Render Target is automatically cleared when bound. * The `RenderTarget.autoResize` property is a boolean that controls if the Render Target is automatically resized if the WebGLRenderer resizes. * The `RenderTarget.setAutoResize` method lets you set the auto resize of the Render Target. * The `RenderTarget.resize` method lets you resize the Render Target. * The `RenderTarget.bind` method sets the Render Target as being the active fbo in the renderer and optionally clears and adjusts the viewport. * The `RenderTarget.adjustViewport` method sets the viewport to match the Render Target dimensions. * The `RenderTarget.clear` method disables the scissors, clears the Render Target and resets the scissors again. * The `RenderTarget.unbind` method flushes the renderer and pops the Render Target framebuffer from the stack. * The `RenderTarget.destroy` method removes all external references and deletes the framebuffer and texture. ### WebGL Renderer #### New WebGL Multi-Texture Support The Multi Pipeline (previously called the Texture Tint Pipeline) has had its core flow rewritten to eliminate the need for constantly creating `batch` objects. Instead, it now supports the new multi-texture shader, vastly increasing rendering performance, especially on draw-call bound systems. All of the internal functions, such as `batchQuad` and `batchSprite` have been updated to use the new method of texture setting. The method signatures all remain the same unless indicated below. * `Config.render.maxTextures` is a new game config setting that allows you to control how many texture units will be used in WebGL. * `WebGL.Utils.checkShaderMax` is a new function, used internally by the renderer, to determine the maximum number of texture units the GPU + browser supports. * The property `WebGLRenderer.currentActiveTextureUnit` has been renamed to `currentActiveTexture`. * `WebGLRenderer.startActiveTexture` is a new read-only property contains the current starting active texture unit. * `WebGLRenderer.maxTextures` is a new read-only property that contains the maximum number of texture units WebGL can use. * `WebGLRenderer.textureIndexes` is a new read-only array that contains all of the available WebGL texture units. * `WebGLRenderer.tempTextures` is a new read-only array that contains temporary WebGL textures. * The `WebGLRenderer.currentTextures` property has been removed, as it's no longer used. * `TextureSource.glIndex` is a new property that holds the currently assigned texture unit for the Texture Source. * `TextureSource.glIndexCounter` is a new property that holds the time the index was assigned to the Texture Source. * `WebGLRenderer.currentTextures` has been removed, as it's no longer used internally. * `WebGLRenderer.setBlankTexture` no longer has a `force` parameter, as it's set by default. * The Mesh Game Object WebGL Renderer function has been updated to support multi-texture units. * The Blitter Game Object WebGL Renderer function has been updated to support multi-texture units. * The Bitmap Text Game Object WebGL Renderer function has been updated to support multi-texture units. * The Dynamic Bitmap Text Game Object WebGL Renderer function has been updated to support multi-texture units. * The Particle Emitter Game Object WebGL Renderer function has been updated to support multi-texture units. * The Texture Tint vertex and fragment shaders have been updated to support the `inTexId` float attribute and dynamic generation. * The Texture Tint Pipeline has a new attribute, `inTexId` which is a `gl.FLOAT`. * `TextureTintPipeline.bind` is a new method that sets the `uMainSampler` uniform. * The `TextureTintPipeline.requireTextureBatch` method has been removed, as it's no longer required. * The `TextureTintPipeline.pushBatch` method has been removed, as it's no longer required. * The `TextureTintPipeline.maxQuads` property has been removed, as it's no longer required. * The `TextureTintPipeline.batches` property has been removed, as it's no longer required. * `TextureTintPipeline.flush` has been rewritten to support multi-textures. * `TextureTintPipeline.flush` no longer creates a sub-array if the batch is full, but instead uses `bufferData` for speed. * `WebGLRenderer.setTextureSource` is a new method, used by pipelines and Game Objects, that will assign a texture unit to the given Texture Source. * The `WebGLRenderer.setTexture2D` method has been updated to use the new texture unit assignment. It no longer takes the `textureUnit` or `flush` parameters and these have been removed from its method signature. * `WebGLRenderer.setTextureZero` is a new method that activates texture zero and binds the given texture to it. Useful for fbo backed game objects. * `WebGLRenderer.clearTextureZero` is a new method that clears the texture that was bound to unit zero. * `WebGLRenderer.textureZero` is a new property that holds the currently bound unit zero texture. * `WebGLRenderer.normalTexture` is a new property that holds the currently bound normal map (texture unit one). * `WebGLRenderer.setNormalMap` is a new method that sets the current normal map texture. * `WebGLRenderer.clearNormalMap` is a new method that clears the current normal map texture. * `WebGLRenderer.resetTextures` is a new method that flushes the pipeline, resets all textures back to the temporary ones, and resets the active texture counter. * `WebGLRenderer.isNewNormalMap` is a new method that returns a boolean if the given parameters are not currently used. * `WebGLRenderer.unbindTextures` is a new method that will activate and then null bind all WebGL textures. * `Renderer.WebGL.Utils.parseFragmentShaderMaxTextures` is a new function that will take fragment shader source and search it for `%count%` and `%forloop%` declarations, replacing them with the required GLSL for multi-texture support, returning the modified source. * The `WebGL.Utils.getComponentCount` function has been removed as this is no longer required internally. #### WebGLRenderer New Features, Updates and API Changes * `WebGLRenderer.instancedArraysExtension` is a new property that holds the WebGL Extension for instanced array drawing, if supported by the browser. * `WebGLRenderer.vaoExtension` is a new property that holds a reference to the Vertex Array Object WebGL Extension, if supported by the browser. * `WebGLRenderer.resetProgram` is a new method that will rebind the current program, without flushing or changing any properties. * `WebGLRenderer.textureFlush` is a new property that keeps track of the total texture flushes per frame. * `WebGLRenderer.finalType` is a new boolean property that signifies if the current Game Object being rendered is the final one in the list. * The `WebGLRenderer.updateCanvasTexture` method will now set `gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL` to true, which should stop issues where you update a Text Game Object, having added a Render Texture or Spine Game Object to the Scene after it, which switches the PMA setting. Fix #5064 #5155 (thanks @hugoruscitti @immangrove-supertree) * `WebGLRenderer.previousPipeline` is a new property that is set during a call to `clearPipeline` and used during calls to `rebindPipeline`, allowing the renderer to rebind any previous pipeline, not just the Multi Pipeline. * The `WebGLRenderer.rebindPipeline` method has been changed slightly. Previously, you had to specify the `pipelineInstance`, but this is now optional. If you don't, it will use the new `previousPipeline` property instead. If not set, or none given, it will now return without throwing gl errors as well. * `WebGLRenderer.defaultScissor` is a new property that holds the default scissor dimensions for the renderer. This is modified during `resize` and avoids continuous array generation in the `preRender` loop. * The `WebGLRenderer.nativeTextures` array has been removed and an