From abace1664619807fbae60b6054cedf15b9094b18 Mon Sep 17 00:00:00 2001 From: Ben Richards Date: Thu, 11 Jul 2024 15:47:53 +1200 Subject: [PATCH] Allow GameObjects to set their own BatchHandler render nodes. --- .../renderNodes/BatchHandlerQuadLightShadow.js | 4 ++-- .../defaults/DefaultBitmapTextNodes.js | 4 +++- .../renderNodes/defaults/DefaultBlitterNodes.js | 4 +++- .../renderNodes/defaults/DefaultImageNodes.js | 2 ++ .../defaults/DefaultParticleEmitterNodes.js | 4 +++- .../defaults/DefaultTilemapLayerNodes.js | 2 ++ .../webgl/renderNodes/submitter/SubmitterQuad.js | 15 +++++++++------ .../renderNodes/submitter/SubmitterQuadLight.js | 9 ++++++--- 8 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/renderer/webgl/renderNodes/BatchHandlerQuadLightShadow.js b/src/renderer/webgl/renderNodes/BatchHandlerQuadLightShadow.js index c6fbe68ad..2e06c4f17 100644 --- a/src/renderer/webgl/renderNodes/BatchHandlerQuadLightShadow.js +++ b/src/renderer/webgl/renderNodes/BatchHandlerQuadLightShadow.js @@ -35,8 +35,8 @@ var BatchHandlerQuadLight = require('./BatchHandlerQuadLight'); * @memberof Phaser.Renderer.WebGL.RenderNodes * @constructor * @since 3.90.0 - * @param {Phaser.Renderer.WebGL.WebGLRenderer} manager - The WebGLRenderer instance that owns this handler. - * @param {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} config - The configuration object for this handler. + * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. + * @param {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} [config] - The configuration object for this handler. */ var BatchHandlerQuadLightShadow = new Class({ Extends: BatchHandlerQuadLight, diff --git a/src/renderer/webgl/renderNodes/defaults/DefaultBitmapTextNodes.js b/src/renderer/webgl/renderNodes/defaults/DefaultBitmapTextNodes.js index 2aedbeba0..ee4929115 100644 --- a/src/renderer/webgl/renderNodes/defaults/DefaultBitmapTextNodes.js +++ b/src/renderer/webgl/renderNodes/defaults/DefaultBitmapTextNodes.js @@ -8,7 +8,9 @@ var Map = require('../../../../structs/Map'); var DefaultBitmapTextNodes = new Map([ [ 'Submitter', 'SubmitterQuad' ], - [ 'SubmitterLight', 'SubmitterQuadLight' ] + [ 'SubmitterLight', 'SubmitterQuadLight' ], + [ 'BatchHandler', 'BatchHandlerQuad' ], + [ 'BatchHandlerLight', 'BatchHandlerQuadLight' ] ]); module.exports = DefaultBitmapTextNodes; diff --git a/src/renderer/webgl/renderNodes/defaults/DefaultBlitterNodes.js b/src/renderer/webgl/renderNodes/defaults/DefaultBlitterNodes.js index dbdecbd4f..9758b657b 100644 --- a/src/renderer/webgl/renderNodes/defaults/DefaultBlitterNodes.js +++ b/src/renderer/webgl/renderNodes/defaults/DefaultBlitterNodes.js @@ -8,7 +8,9 @@ var Map = require('../../../../structs/Map'); var DefaultBlitterNodes = new Map([ [ 'Submitter', 'SubmitterQuad' ], - [ 'SubmitterLight', 'SubmitterQuadLight' ] + [ 'SubmitterLight', 'SubmitterQuadLight' ], + [ 'BatchHandler', 'BatchHandlerQuad' ], + [ 'BatchHandlerLight', 'BatchHandlerQuadLight' ] ]); module.exports = DefaultBlitterNodes; diff --git a/src/renderer/webgl/renderNodes/defaults/DefaultImageNodes.js b/src/renderer/webgl/renderNodes/defaults/DefaultImageNodes.js index 872cf0462..6d29f8935 100644 --- a/src/renderer/webgl/renderNodes/defaults/DefaultImageNodes.js +++ b/src/renderer/webgl/renderNodes/defaults/DefaultImageNodes.js @@ -9,6 +9,8 @@ var Map = require('../../../../structs/Map'); var DefaultImageNodes = new Map([ [ 'Submitter', 'SubmitterQuad' ], [ 'SubmitterLight', 'SubmitterQuadLight' ], + [ 'BatchHandler', 'BatchHandlerQuad' ], + [ 'BatchHandlerLight', 'BatchHandlerQuadLight' ], [ 'Transformer', 'TransformerImage' ], [ 'Texturer', 'TexturerImage' ] ]); diff --git a/src/renderer/webgl/renderNodes/defaults/DefaultParticleEmitterNodes.js b/src/renderer/webgl/renderNodes/defaults/DefaultParticleEmitterNodes.js index f137e9b07..4e12003f3 100644 --- a/src/renderer/webgl/renderNodes/defaults/DefaultParticleEmitterNodes.js +++ b/src/renderer/webgl/renderNodes/defaults/DefaultParticleEmitterNodes.js @@ -8,7 +8,9 @@ var Map = require('../../../../structs/Map'); var DefaultParticleEmitterNodes = new Map([ [ 'Submitter', 'SubmitterQuad' ], - [ 'SubmitterLight', 'SubmitterQuadLight' ] + [ 'SubmitterLight', 'SubmitterQuadLight' ], + [ 'BatchHandler', 'BatchHandlerQuad' ], + [ 'BatchHandlerLight', 'BatchHandlerQuadLight' ] ]); module.exports = DefaultParticleEmitterNodes; diff --git a/src/renderer/webgl/renderNodes/defaults/DefaultTilemapLayerNodes.js b/src/renderer/webgl/renderNodes/defaults/DefaultTilemapLayerNodes.js index a4f30245b..efcee67cf 100644 --- a/src/renderer/webgl/renderNodes/defaults/DefaultTilemapLayerNodes.js +++ b/src/renderer/webgl/renderNodes/defaults/DefaultTilemapLayerNodes.js @@ -9,6 +9,8 @@ var Map = require('../../../../structs/Map'); var DefaultTilemapLayerNodes = new Map([ [ 'Submitter', 'SubmitterQuad' ], [ 'SubmitterLight', 'SubmitterQuadLight' ], + [ 'BatchHandler', 'BatchHandlerQuad' ], + [ 'BatchHandlerLight', 'BatchHandlerQuadLight' ], [ 'Transformer', 'TransformerTile' ] ]); diff --git a/src/renderer/webgl/renderNodes/submitter/SubmitterQuad.js b/src/renderer/webgl/renderNodes/submitter/SubmitterQuad.js index 166076ee7..1cee74605 100644 --- a/src/renderer/webgl/renderNodes/submitter/SubmitterQuad.js +++ b/src/renderer/webgl/renderNodes/submitter/SubmitterQuad.js @@ -32,7 +32,7 @@ var getTint = Utils.getTintAppendFloatAlpha; * @param {object} [config] - The configuration object for this RenderNode. * @param {string} [config.name='SubmitterQuad'] - The name of this RenderNode. * @param {string} [config.role='Submitter'] - The expected role of this RenderNode. - * @param {string} [config.batchHandler='BatchHandlerQuad'] - The key of the default batch handler node to use for this RenderNode. This should correspond to a node which extends `BatchHandlerQuad`. + * @param {string} [config.batchHandler='BatchHandler'] - The key of the default batch handler node to use for this RenderNode. This should correspond to a node which extends `BatchHandlerQuad`. It will be derived from the game object whenever the node runs. */ var SubmitterQuad = new Class({ Extends: RenderNode, @@ -44,13 +44,13 @@ var SubmitterQuad = new Class({ RenderNode.call(this, config.name, manager); /** - * The RenderNode used to render data. + * The key of the RenderNode used to render data. * * @name Phaser.Renderer.WebGL.RenderNodes.SubmitterQuad#batchHandler - * @type {Phaser.Renderer.WebGL.RenderNodes.BatchHandler} + * @type {string} * @since 3.90.0 */ - this.batchHandler = manager.getNode(config.batchHandler); + this.batchHandler = config.batchHandler; }, /** @@ -62,7 +62,7 @@ var SubmitterQuad = new Class({ defaultConfig: { name: 'SubmitterQuad', role: 'Submitter', - batchHandler: 'BatchHandlerQuad' + batchHandler: 'BatchHandler' }, /** @@ -129,7 +129,10 @@ var SubmitterQuad = new Class({ var u1 = uvSource.u1; var v1 = uvSource.v1; - this.batchHandler.batch( + ( + gameObject.customRenderNodes[this.batchHandler] || + gameObject.defaultRenderNodes[this.batchHandler] + ).batch( drawingContext, // Use `frame.source.glTexture` instead of `frame.glTexture` diff --git a/src/renderer/webgl/renderNodes/submitter/SubmitterQuadLight.js b/src/renderer/webgl/renderNodes/submitter/SubmitterQuadLight.js index 867865966..331ff868f 100644 --- a/src/renderer/webgl/renderNodes/submitter/SubmitterQuadLight.js +++ b/src/renderer/webgl/renderNodes/submitter/SubmitterQuadLight.js @@ -27,7 +27,7 @@ var getTint = Utils.getTintAppendFloatAlpha; * @param {object} [config] - The configuration object for this RenderNode. * @param {string} [config.name='SubmitterQuadLight'] - The name of this RenderNode. * @param {string} [config.role='Submitter'] - The expected role of this RenderNode. - * @param {string} [config.batchHandler='BatchHandlerQuadLight'] - The key of the default batch handler node to use for this RenderNode. This should correspond to a node which extends `BatchHandlerQuadLight`. + * @param {string} [config.batchHandler='BatchHandlerLight'] - The key of the default batch handler node to use for this RenderNode. This should correspond to a node which extends `BatchHandlerQuadLight`. It will be derived from the game object whenever the node runs. */ var SubmitterQuadLight = new Class({ Extends: SubmitterQuad, @@ -42,7 +42,7 @@ var SubmitterQuadLight = new Class({ defaultConfig: { name: 'SubmitterQuadLight', role: 'Submitter', - batchHandler: 'BatchHandlerQuadLight' + batchHandler: 'BatchHandlerLight' }, /** @@ -164,7 +164,10 @@ var SubmitterQuadLight = new Class({ } // Batch the quad. - this.batchHandler.batch( + ( + gameObject.customRenderNodes[this.batchHandler] || + gameObject.defaultRenderNodes[this.batchHandler] + ).batch( drawingContext, // Use `frame.source.glTexture` instead of `frame.glTexture`