Skip to content

Commit c29d7b1

Browse files
committed
Removed everything to do with Camera's rendering to textures or managing their own framebuffers.
Now uses pipeline component instead.
1 parent 92eca8d commit c29d7b1

1 file changed

Lines changed: 3 additions & 266 deletions

File tree

src/cameras/2d/Camera.js

Lines changed: 3 additions & 266 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
var BaseCamera = require('./BaseCamera');
8-
var CanvasPool = require('../../display/canvas/CanvasPool');
98
var CenterOn = require('../../geom/rectangle/CenterOn');
109
var Clamp = require('../../math/Clamp');
1110
var Class = require('../../utils/Class');
@@ -47,6 +46,7 @@ var Vector2 = require('../../math/Vector2');
4746
* @extends Phaser.Cameras.Scene2D.BaseCamera
4847
* @extends Phaser.GameObjects.Components.Flip
4948
* @extends Phaser.GameObjects.Components.Tint
49+
* @extends Phaser.GameObjects.Components.Pipeline
5050
*
5151
* @param {number} x - The x position of the Camera, relative to the top-left of the game canvas.
5252
* @param {number} y - The y position of the Camera, relative to the top-left of the game canvas.
@@ -59,7 +59,8 @@ var Camera = new Class({
5959

6060
Mixins: [
6161
Components.Flip,
62-
Components.Tint
62+
Components.Tint,
63+
Components.Pipeline
6364
],
6465

6566
initialize:
@@ -202,268 +203,6 @@ var Camera = new Class({
202203
* @since 3.0.0
203204
*/
204205
this._follow = null;
205-
206-
/**
207-
* Is this Camera rendering directly to the canvas or to a texture?
208-
*
209-
* Enable rendering to texture with the method `setRenderToTexture` (just enabling this boolean won't be enough)
210-
*
211-
* Once enabled you can toggle it by switching this property.
212-
*
213-
* To properly remove a render texture you should call the `clearRenderToTexture()` method.
214-
*
215-
* @name Phaser.Cameras.Scene2D.Camera#renderToTexture
216-
* @type {boolean}
217-
* @default false
218-
* @since 3.13.0
219-
*/
220-
this.renderToTexture = false;
221-
222-
/**
223-
* If this Camera is rendering to a texture (via `setRenderToTexture`) then you
224-
* have the option to control if it should also render to the Game canvas as well.
225-
*
226-
* By default, a Camera will render both to its texture and to the Game canvas.
227-
*
228-
* However, if you set ths property to `false` it will only render to the texture
229-
* and skip rendering to the Game canvas.
230-
*
231-
* Setting this property if the Camera isn't rendering to a texture has no effect.
232-
*
233-
* @name Phaser.Cameras.Scene2D.Camera#renderToGame
234-
* @type {boolean}
235-
* @default true
236-
* @since 3.23.0
237-
*/
238-
this.renderToGame = true;
239-
240-
/**
241-
* If this Camera has been set to render to a texture then this holds a reference
242-
* to the HTML Canvas Element that the Camera is drawing to.
243-
*
244-
* Enable texture rendering using the method `setRenderToTexture`.
245-
*
246-
* This is only populated if Phaser is running with the Canvas Renderer.
247-
*
248-
* @name Phaser.Cameras.Scene2D.Camera#canvas
249-
* @type {HTMLCanvasElement}
250-
* @since 3.13.0
251-
*/
252-
this.canvas = null;
253-
254-
/**
255-
* If this Camera has been set to render to a texture then this holds a reference
256-
* to the Rendering Context belonging to the Canvas element the Camera is drawing to.
257-
*
258-
* Enable texture rendering using the method `setRenderToTexture`.
259-
*
260-
* This is only populated if Phaser is running with the Canvas Renderer.
261-
*
262-
* @name Phaser.Cameras.Scene2D.Camera#context
263-
* @type {CanvasRenderingContext2D}
264-
* @since 3.13.0
265-
*/
266-
this.context = null;
267-
268-
/**
269-
* If this Camera has been set to render to a texture then this holds a reference
270-
* to the GL Texture belonging the Camera is drawing to.
271-
*
272-
* Enable texture rendering using the method `setRenderToTexture`.
273-
*
274-
* This is only set if Phaser is running with the WebGL Renderer.
275-
*
276-
* @name Phaser.Cameras.Scene2D.Camera#glTexture
277-
* @type {?WebGLTexture}
278-
* @since 3.13.0
279-
*/
280-
this.glTexture = null;
281-
282-
/**
283-
* If this Camera has been set to render to a texture then this holds a reference
284-
* to the GL Frame Buffer belonging the Camera is drawing to.
285-
*
286-
* Enable texture rendering using the method `setRenderToTexture`.
287-
*
288-
* This is only set if Phaser is running with the WebGL Renderer.
289-
*
290-
* @name Phaser.Cameras.Scene2D.Camera#framebuffer
291-
* @type {?WebGLFramebuffer}
292-
* @since 3.13.0
293-
*/
294-
this.framebuffer = null;
295-
296-
/**
297-
* If this Camera has been set to render to a texture and to use a custom pipeline,
298-
* then this holds a reference to the pipeline the Camera is drawing with.
299-
*
300-
* Enable texture rendering using the method `setRenderToTexture`.
301-
*
302-
* This is only set if Phaser is running with the WebGL Renderer.
303-
*
304-
* @name Phaser.Cameras.Scene2D.Camera#pipeline
305-
* @type {?Phaser.Renderer.WebGL.WebGLPipeline}
306-
* @since 3.13.0
307-
*/
308-
this.pipeline = null;
309-
},
310-
311-
/**
312-
* Sets the Camera to render to a texture instead of to the main canvas.
313-
*
314-
* The Camera will redirect all Game Objects it's asked to render to this texture.
315-
*
316-
* During the render sequence, the texture itself will then be rendered to the main canvas.
317-
*
318-
* Doing this gives you the ability to modify the texture before this happens,
319-
* allowing for special effects such as Camera specific shaders, or post-processing
320-
* on the texture. You can also then 'tint' the Camera.
321-
*
322-
* If running under Canvas the Camera will render to its `canvas` property.
323-
*
324-
* If running under WebGL the Camera will create a frame buffer, which is stored in its `framebuffer` and `glTexture` properties.
325-
*
326-
* If you set a camera to render to a texture then it will emit 2 events during the render loop:
327-
*
328-
* First, it will emit the event `prerender`. This happens right before any Game Object's are drawn to the Camera texture.
329-
*
330-
* Then, it will emit the event `postrender`. This happens after all Game Object's have been drawn, but right before the
331-
* Camera texture is rendered to the main game canvas. It's the final point at which you can manipulate the texture before
332-
* it appears in-game.
333-
*
334-
* You should not enable this unless you plan on actually using the texture it creates
335-
* somehow, otherwise you're just doubling the work required to render your game.
336-
*
337-
* If you only require the Camera to render to a texture, and not also to the Game,
338-
* them set the `renderToGame` parameter to `false`.
339-
*
340-
* To temporarily disable rendering to a texture, toggle the `renderToTexture` boolean.
341-
*
342-
* If you no longer require the Camera to render to a texture, call the `clearRenderToTexture` method,
343-
* which will delete the respective textures and free-up resources.
344-
*
345-
* @method Phaser.Cameras.Scene2D.Camera#setRenderToTexture
346-
* @since 3.13.0
347-
*
348-
* @param {(string|Phaser.Renderer.WebGL.WebGLPipeline)} [pipeline] - An optional WebGL Pipeline to render with, can be either a string which is the name of the pipeline, or a pipeline reference.
349-
* @param {boolean} [renderToGame=true] - If you do not need the Camera to still render to the Game, set this parameter to `false`.
350-
*
351-
* @return {this} This Camera instance.
352-
*/
353-
setRenderToTexture: function (pipeline, renderToGame)
354-
{
355-
if (renderToGame === undefined) { renderToGame = true; }
356-
357-
var renderer = this.scene.sys.renderer;
358-
359-
if (renderer.gl)
360-
{
361-
this.glTexture = renderer.createTextureFromSource(null, this.width, this.height, 0);
362-
this.framebuffer = renderer.createFramebuffer(this.width, this.height, this.glTexture, false);
363-
}
364-
else
365-
{
366-
this.canvas = CanvasPool.create2D(this, this.width, this.height);
367-
this.context = this.canvas.getContext('2d');
368-
}
369-
370-
this.renderToTexture = true;
371-
this.renderToGame = renderToGame;
372-
373-
if (pipeline)
374-
{
375-
this.setPipeline(pipeline);
376-
}
377-
378-
return this;
379-
},
380-
381-
/**
382-
* Sets the WebGL pipeline this Camera is using when rendering to a texture.
383-
*
384-
* You can pass either the string-based name of the pipeline, or a reference to the pipeline itself.
385-
*
386-
* Call this method with no arguments to clear any previously set pipeline.
387-
*
388-
* @method Phaser.Cameras.Scene2D.Camera#setPipeline
389-
* @since 3.13.0
390-
*
391-
* @param {(string|Phaser.Renderer.WebGL.WebGLPipeline)} [pipeline] - The WebGL Pipeline to render with, can be either a string which is the name of the pipeline, or a pipeline reference. Or if left empty it will clear the pipeline.
392-
*
393-
* @return {this} This Camera instance.
394-
*/
395-
setPipeline: function (pipeline)
396-
{
397-
if (typeof pipeline === 'string')
398-
{
399-
var renderer = this.scene.sys.renderer;
400-
401-
if (renderer.gl && renderer.pipelines.has(pipeline))
402-
{
403-
this.pipeline = renderer.pipelines.get(pipeline);
404-
}
405-
}
406-
else
407-
{
408-
this.pipeline = pipeline;
409-
}
410-
411-
return this;
412-
},
413-
414-
/**
415-
* If this Camera was set to render to a texture, this will clear the resources it was using and
416-
* redirect it to render back to the primary Canvas again.
417-
*
418-
* If you only wish to temporarily disable rendering to a texture then you can toggle the
419-
* property `renderToTexture` instead.
420-
*
421-
* @method Phaser.Cameras.Scene2D.Camera#clearRenderToTexture
422-
* @since 3.13.0
423-
*
424-
* @return {this} This Camera instance.
425-
*/
426-
clearRenderToTexture: function ()
427-
{
428-
if (!this.scene)
429-
{
430-
return;
431-
}
432-
433-
var renderer = this.scene.sys.renderer;
434-
435-
if (!renderer)
436-
{
437-
return;
438-
}
439-
440-
if (renderer.gl)
441-
{
442-
if (this.framebuffer)
443-
{
444-
renderer.deleteFramebuffer(this.framebuffer);
445-
}
446-
447-
if (this.glTexture)
448-
{
449-
renderer.deleteTexture(this.glTexture);
450-
}
451-
452-
this.framebuffer = null;
453-
this.glTexture = null;
454-
this.pipeline = null;
455-
}
456-
else
457-
{
458-
CanvasPool.remove(this);
459-
460-
this.canvas = null;
461-
this.context = null;
462-
}
463-
464-
this.renderToTexture = false;
465-
466-
return this;
467206
},
468207

469208
/**
@@ -1047,8 +786,6 @@ var Camera = new Class({
1047786
*/
1048787
destroy: function ()
1049788
{
1050-
this.clearRenderToTexture();
1051-
1052789
this.resetFX();
1053790

1054791
BaseCamera.prototype.destroy.call(this);

0 commit comments

Comments
 (0)