From d1a38d55c0d70693cb52383b7bb893ba32e72279 Mon Sep 17 00:00:00 2001 From: Ben Richards Date: Tue, 28 May 2024 19:36:03 +1200 Subject: [PATCH] Remove renderer from RenderNode parameters. It's easy to access via the manager parameter. --- .../webgl/renderNodes/BatchHandler.js | 10 ++++----- src/renderer/webgl/renderNodes/Camera.js | 5 ++--- src/renderer/webgl/renderNodes/FillCamera.js | 5 ++--- src/renderer/webgl/renderNodes/FillRect.js | 7 +++---- .../webgl/renderNodes/GameObjectBatcher.js | 5 ++--- .../webgl/renderNodes/ListCompositor.js | 8 +++---- .../webgl/renderNodes/QuadBatchHandler.js | 21 ++++++++++--------- src/renderer/webgl/renderNodes/RenderNode.js | 13 ++---------- .../webgl/renderNodes/RenderNodeManager.js | 2 +- 9 files changed, 32 insertions(+), 44 deletions(-) diff --git a/src/renderer/webgl/renderNodes/BatchHandler.js b/src/renderer/webgl/renderNodes/BatchHandler.js index c90ec4b04..1cfaba2c4 100644 --- a/src/renderer/webgl/renderNodes/BatchHandler.js +++ b/src/renderer/webgl/renderNodes/BatchHandler.js @@ -27,15 +27,15 @@ var RenderNode = require('./RenderNode'); * @since 3.90.0 * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. - * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - The renderer that owns this RenderNode. * @param {Phaser.Renderer.WebGL.RenderNodes.BatchHandlerConfig} [config] - The configuration object for this RenderNode. * @param {Phaser.Renderer.WebGL.RenderNodes.BatchHandlerConfig} defaultConfig - The default configuration object for this RenderNode. This is used to ensure all required properties are present, so it must be complete. */ var BatchHandler = new Class({ Extends: RenderNode, - initialize: function BatchHandler (manager, renderer, config, defaultConfig) + initialize: function BatchHandler (manager, config, defaultConfig) { + var renderer = manager.renderer; var gl = renderer.gl; config = this._copyAndCompleteConfig(config || {}, defaultConfig); @@ -46,7 +46,7 @@ var BatchHandler = new Class({ throw new Error('BatchHandler must have a name'); } - RenderNode.call(this, name, manager, renderer); + RenderNode.call(this, name, manager); /** * The number of instances per batch, used to determine the size of the @@ -79,7 +79,7 @@ var BatchHandler = new Class({ // Calculate the final number of instances per batch. var indexLimit = 65536; // 2^16 var maxInstances = Math.floor(indexLimit / this.verticesPerInstance); - var targetInstances = config.instancesPerBatch || this.renderer.config.batchSize || maxInstances; + var targetInstances = config.instancesPerBatch || renderer.config.batchSize || maxInstances; this.instancesPerBatch = Math.min(targetInstances, maxInstances); /** @@ -247,7 +247,7 @@ var BatchHandler = new Class({ // Set the dimension-related uniforms and listen for resize events. this.resize(renderer.width, renderer.height); - this.renderer.on(Phaser.Renderer.Events.RESIZE, this.resize, this); + renderer.on(Phaser.Renderer.Events.RESIZE, this.resize, this); }, /** diff --git a/src/renderer/webgl/renderNodes/Camera.js b/src/renderer/webgl/renderNodes/Camera.js index a089a16cf..128f487f8 100644 --- a/src/renderer/webgl/renderNodes/Camera.js +++ b/src/renderer/webgl/renderNodes/Camera.js @@ -16,14 +16,13 @@ var RenderNode = require('./RenderNode'); * @since 3.90.0 * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. - * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - The renderer that owns this RenderNode. */ var Camera = new Class({ Extends: RenderNode, - initialize: function Camera (manager, renderer) + initialize: function Camera (manager) { - RenderNode.call(this, 'Camera', manager, renderer); + RenderNode.call(this, 'Camera', manager); /** * The RenderNode that handles filling the camera with a diff --git a/src/renderer/webgl/renderNodes/FillCamera.js b/src/renderer/webgl/renderNodes/FillCamera.js index fc7e6cabb..08fb117a7 100644 --- a/src/renderer/webgl/renderNodes/FillCamera.js +++ b/src/renderer/webgl/renderNodes/FillCamera.js @@ -17,14 +17,13 @@ var RenderNode = require('./RenderNode'); * @since 3.90.0 * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. - * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - The renderer that owns this RenderNode. */ var FillCamera = new Class({ Extends: RenderNode, - initialize: function FillCamera (manager, renderer) + initialize: function FillCamera (manager) { - RenderNode.call(this, 'FillCamera', manager, renderer); + RenderNode.call(this, 'FillCamera', manager); /** * The RenderNode that draws a filled rectangle. diff --git a/src/renderer/webgl/renderNodes/FillRect.js b/src/renderer/webgl/renderNodes/FillRect.js index 63900209a..75724407e 100644 --- a/src/renderer/webgl/renderNodes/FillRect.js +++ b/src/renderer/webgl/renderNodes/FillRect.js @@ -22,14 +22,13 @@ var RenderNode = require('./RenderNode'); * @since 3.90.0 * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. - * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - The renderer that owns this RenderNode. */ var FillRect = new Class({ Extends: RenderNode, - initialize: function FillRect (manager, renderer) + initialize: function FillRect (manager) { - RenderNode.call(this, 'FillRect', manager, renderer); + RenderNode.call(this, 'FillRect', manager); /** * The QuadBatchHandler that handles the rendering of quads. @@ -95,7 +94,7 @@ var FillRect = new Class({ this.quadBatchHandlerNode.batch( drawingContext, - this.renderer.whiteTexture, + this.manager.renderer.whiteTexture, // Quad vertices in TRIANGLE_STRIP order: quad[0], quad[1], diff --git a/src/renderer/webgl/renderNodes/GameObjectBatcher.js b/src/renderer/webgl/renderNodes/GameObjectBatcher.js index 99ed58662..d82878335 100644 --- a/src/renderer/webgl/renderNodes/GameObjectBatcher.js +++ b/src/renderer/webgl/renderNodes/GameObjectBatcher.js @@ -44,19 +44,18 @@ var getTint = Utils.getTintAppendFloatAlpha; * @since 3.90.0 * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. - * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - The renderer that owns this RenderNode. * @param {Phaser.Renderer.WebGL.RenderNodes.GameObjectBatcherConfig} [config] - The configuration object for this RenderNode. */ var GameObjectBatcher = new Class({ Extends: RenderNode, - initialize: function GameObjectBatcher (manager, renderer, config) + initialize: function GameObjectBatcher (manager, config) { if (config === undefined) { config = {}; } var name = config.name || 'GameObjectBatcher'; - RenderNode.call(this, name, manager, renderer); + RenderNode.call(this, name, manager); var batchHandler = 'QuadBatchHandler'; if (config.batchHandler) diff --git a/src/renderer/webgl/renderNodes/ListCompositor.js b/src/renderer/webgl/renderNodes/ListCompositor.js index a3e903dee..45323891e 100644 --- a/src/renderer/webgl/renderNodes/ListCompositor.js +++ b/src/renderer/webgl/renderNodes/ListCompositor.js @@ -16,14 +16,13 @@ var RenderNode = require('./RenderNode'); * @since 3.90.0 * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. - * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - The renderer that owns this RenderNode. */ var ListCompositor = new Class({ Extends: RenderNode, - initialize: function ListCompositor (manager, renderer) + initialize: function ListCompositor (manager) { - RenderNode.call(this, 'ListCompositor', manager, renderer); + RenderNode.call(this, 'ListCompositor', manager); }, /** @@ -43,6 +42,7 @@ var ListCompositor = new Class({ var currentContext = displayContext; var baseBlendMode = displayContext.blendMode; var currentBlendMode = baseBlendMode; + var renderer = this.manager.renderer; // Render each child in the display list for (var i = 0; i < children.length; i++) @@ -73,7 +73,7 @@ var ListCompositor = new Class({ } } - child.renderWebGL(this.renderer, child, currentContext, parentTransformMatrix); + child.renderWebGL(renderer, child, currentContext, parentTransformMatrix); } // Release any remaining context. diff --git a/src/renderer/webgl/renderNodes/QuadBatchHandler.js b/src/renderer/webgl/renderNodes/QuadBatchHandler.js index c1d1e33cb..4ed7ccc51 100644 --- a/src/renderer/webgl/renderNodes/QuadBatchHandler.js +++ b/src/renderer/webgl/renderNodes/QuadBatchHandler.js @@ -20,19 +20,18 @@ var BatchHandler = require('./BatchHandler'); * @constructor * @since 3.90.0 * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. - * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - The renderer that owns this RenderNode. * @param {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} [config] - The configuration object for this handler. */ var QuadBatchHandler = new Class({ Extends: BatchHandler, - initialize: function QuadBatchHandler (manager, renderer, config) + initialize: function QuadBatchHandler (manager, config) { - BatchHandler.call(this, manager, renderer, config, this.defaultConfig); + BatchHandler.call(this, manager, config, this.defaultConfig); // Main sampler will never change after initialization, // because it addresses texture units, not textures. - this.program.setUniform('uMainSampler[0]', this.renderer.textureUnitIndices); + this.program.setUniform('uMainSampler[0]', this.manager.renderer.textureUnitIndices); }, defaultConfig: { @@ -112,7 +111,7 @@ var QuadBatchHandler = new Class({ resize: function (width, height) { this.program.setUniform('uResolution', [ width, height ]); - this.program.setUniform('uProjectionMatrix', this.renderer.projectionMatrix.val); + this.program.setUniform('uProjectionMatrix', this.manager.renderer.projectionMatrix.val); }, /** @@ -136,12 +135,14 @@ var QuadBatchHandler = new Class({ */ updateTextureCount: function (count) { + var renderer = this.manager.renderer; + if (count === undefined) { - count = this.renderer.maxTextures; + count = renderer.maxTextures; } - var newCount = Math.max(1, Math.min(count, this.renderer.maxTextures)); + var newCount = Math.max(1, Math.min(count, renderer.maxTextures)); if (newCount === this.texturesPerBatch) { return; @@ -168,9 +169,9 @@ var QuadBatchHandler = new Class({ this.program.setUniform( 'uMainSampler[0]', - this.renderer.textureUnitIndices + renderer.textureUnitIndices ); - this.resize(this.renderer.width, this.renderer.height); + this.resize(renderer.width, renderer.height); }, /** @@ -191,7 +192,7 @@ var QuadBatchHandler = new Class({ var indicesPerInstance = this.indicesPerInstance; var program = this.program; var vao = this.vao; - var renderer = this.renderer; + var renderer = this.manager.renderer; var vertexBuffer = this.vertexBufferLayout.buffer; // Finalize the current batch entry. diff --git a/src/renderer/webgl/renderNodes/RenderNode.js b/src/renderer/webgl/renderNodes/RenderNode.js index 96819e037..8b0dd800c 100644 --- a/src/renderer/webgl/renderNodes/RenderNode.js +++ b/src/renderer/webgl/renderNodes/RenderNode.js @@ -16,13 +16,13 @@ var Class = require('../../../utils/Class'); * @constructor * @since 3.90.0 * @param {string} name - The name of the RenderNode. - * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - The renderer that owns this RenderNode. + * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ var RenderNode = new Class({ initialize: - function RenderNode (name, manager, renderer) + function RenderNode (name, manager) { /** * The name of the RenderNode. @@ -42,15 +42,6 @@ var RenderNode = new Class({ */ this.manager = manager; - /** - * The renderer that owns this RenderNode. - * - * @name Phaser.Renderer.WebGL.RenderNodes.RenderNode#renderer - * @type {Phaser.Renderer.WebGL.WebGLRenderer} - * @since 3.90.0 - */ - this.renderer = renderer; - /** * Reference to the original `run` method of this node. * Used when `setDebug` is enabled. diff --git a/src/renderer/webgl/renderNodes/RenderNodeManager.js b/src/renderer/webgl/renderNodes/RenderNodeManager.js index c4d63ce66..1f7a8a5d1 100644 --- a/src/renderer/webgl/renderNodes/RenderNodeManager.js +++ b/src/renderer/webgl/renderNodes/RenderNodeManager.js @@ -238,7 +238,7 @@ var RenderNodeManager = new Class({ } if (this._nodeConstructors[name]) { - var node = new this._nodeConstructors[name](this, this.renderer); + var node = new this._nodeConstructors[name](this); this.addNode(name, node); return node; }