Skip to content

Commit 0003d27

Browse files
committed
Updated to use new external MVP functions
1 parent 06c1336 commit 0003d27

5 files changed

Lines changed: 181 additions & 172 deletions

File tree

src/gameobjects/rendertexture/RenderTexture.js

Lines changed: 69 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@ var CONST = require('../../const');
1313
var Frame = require('../../textures/Frame');
1414
var GameObject = require('../GameObject');
1515
var NOOP = require('../../utils/NOOP');
16+
var ProjectOrtho = require('../../renderer/webgl/mvp/ProjectOrtho');
1617
var Render = require('./RenderTextureRender');
1718
var Utils = require('../../renderer/webgl/Utils');
1819
var UUID = require('../../utils/string/UUID');
1920

2021
/**
2122
* @classdesc
2223
* A Render Texture.
23-
*
24+
*
2425
* A Render Texture is a special texture that allows any number of Game Objects to be drawn to it. You can take many complex objects and
2526
* draw them all to this one texture, which can they be used as the texture for other Game Object's. It's a way to generate dynamic
2627
* textures at run-time that are WebGL friendly and don't invoke expensive GPU uploads.
27-
*
28+
*
2829
* Note that under WebGL a FrameBuffer, which is what the Render Texture uses internally, cannot be anti-aliased. This means
2930
* that when drawing objects such as Shapes to a Render Texture they will appear to be drawn with no aliasing, however this
3031
* is a technical limitation of WebGL. To get around it, create your shape as a texture in an art package, then draw that
@@ -202,14 +203,14 @@ var RenderTexture = new Class({
202203

203204
// Create a new Texture for this Text object
204205
this.texture = scene.sys.textures.addCanvas(UUID(), this.canvas);
205-
206+
206207
// Get the frame
207208
this.frame = this.texture.get();
208209
}
209210
else
210211
{
211212
this.texture = scene.sys.textures.get(key);
212-
213+
213214
// Get the frame
214215
this.frame = this.texture.get(frame);
215216

@@ -308,13 +309,13 @@ var RenderTexture = new Class({
308309

309310
/**
310311
* Sets the size of this Game Object.
311-
*
312+
*
312313
* @method Phaser.GameObjects.RenderTexture#setSize
313314
* @since 3.0.0
314315
*
315316
* @param {number} width - The width of this Game Object.
316317
* @param {number} height - The height of this Game Object.
317-
*
318+
*
318319
* @return {this} This Game Object instance.
319320
*/
320321
setSize: function (width, height)
@@ -324,7 +325,7 @@ var RenderTexture = new Class({
324325

325326
/**
326327
* Resizes the Render Texture to the new dimensions given.
327-
*
328+
*
328329
* If Render Texture was created from specific frame, only the size of the frame will be changed. The size of the source
329330
* texture will not change.
330331
*
@@ -355,10 +356,10 @@ var RenderTexture = new Class({
355356

356357
this.canvas.width = width;
357358
this.canvas.height = height;
358-
359+
359360
this.texture.width = width;
360361
this.texture.height = height;
361-
362+
362363
if (this.gl)
363364
{
364365
var gl = this.gl;
@@ -455,24 +456,24 @@ var RenderTexture = new Class({
455456

456457
/**
457458
* Stores a copy of this Render Texture in the Texture Manager using the given key.
458-
*
459+
*
459460
* After doing this, any texture based Game Object, such as a Sprite, can use the contents of this
460461
* Render Texture by using the texture key:
461-
*
462+
*
462463
* ```javascript
463464
* var rt = this.add.renderTexture(0, 0, 128, 128);
464-
*
465+
*
465466
* // Draw something to the Render Texture
466-
*
467+
*
467468
* rt.saveTexture('doodle');
468-
*
469+
*
469470
* this.add.image(400, 300, 'doodle');
470471
* ```
471-
*
472+
*
472473
* Updating the contents of this Render Texture will automatically update _any_ Game Object
473474
* that is using it as a texture. Calling `saveTexture` again will not save another copy
474475
* of the same texture, it will just rename the key of the existing copy.
475-
*
476+
*
476477
* By default it will create a single base texture. You can add frames to the texture
477478
* by using the `Texture.add` method. After doing this, you can then allow Game Objects
478479
* to use a specific frame from a Render Texture.
@@ -487,7 +488,7 @@ var RenderTexture = new Class({
487488
saveTexture: function (key)
488489
{
489490
this.textureManager.renameTexture(this.texture.key, key);
490-
491+
491492
this._saved = true;
492493

493494
return this.texture;
@@ -537,8 +538,8 @@ var RenderTexture = new Class({
537538
this.renderer.pushScissor(cx, cy, cw, ch, ch);
538539

539540
var pipeline = this.pipeline;
540-
541-
pipeline.projOrtho(0, this.texture.width, 0, this.texture.height, -1000.0, 1000.0);
541+
542+
ProjectOrtho(pipeline, 0, this.texture.width, 0, this.texture.height, -1000.0, 1000.0);
542543

543544
pipeline.drawFillRect(
544545
x, y, width, height,
@@ -550,7 +551,7 @@ var RenderTexture = new Class({
550551

551552
this.renderer.popScissor();
552553

553-
pipeline.projOrtho(0, pipeline.width, pipeline.height, 0, -1000.0, 1000.0);
554+
ProjectOrtho(pipeline, 0, pipeline.width, pipeline.height, 0, -1000.0, 1000.0);
554555
}
555556
else
556557
{
@@ -586,7 +587,7 @@ var RenderTexture = new Class({
586587
var renderer = this.renderer;
587588

588589
renderer.setFramebuffer(this.framebuffer, true);
589-
590+
590591
if (this.frame.cutWidth !== this.canvas.width || this.frame.cutHeight !== this.canvas.height)
591592
{
592593
gl.scissor(this.frame.cutX, this.frame.cutY, this.frame.cutWidth, this.frame.cutHeight);
@@ -616,9 +617,9 @@ var RenderTexture = new Class({
616617
/**
617618
* Draws the given object, or an array of objects, to this Render Texture using a blend mode of ERASE.
618619
* This has the effect of erasing any filled pixels in the objects from this Render Texture.
619-
*
620+
*
620621
* It can accept any of the following:
621-
*
622+
*
622623
* * Any renderable Game Object, such as a Sprite, Text, Graphics or TileSprite.
623624
* * Dynamic and Static Tilemap Layers.
624625
* * A Group. The contents of which will be iterated and drawn in turn.
@@ -627,24 +628,24 @@ var RenderTexture = new Class({
627628
* * Another Render Texture.
628629
* * A Texture Frame instance.
629630
* * A string. This is used to look-up a texture from the Texture Manager.
630-
*
631+
*
631632
* Note: You cannot erase a Render Texture from itself.
632-
*
633+
*
633634
* If passing in a Group or Container it will only draw children that return `true`
634635
* when their `willRender()` method is called. I.e. a Container with 10 children,
635636
* 5 of which have `visible=false` will only draw the 5 visible ones.
636-
*
637+
*
637638
* If passing in an array of Game Objects it will draw them all, regardless if
638639
* they pass a `willRender` check or not.
639-
*
640+
*
640641
* You can pass in a string in which case it will look for a texture in the Texture
641642
* Manager matching that string, and draw the base frame.
642-
*
643+
*
643644
* You can pass in the `x` and `y` coordinates to draw the objects at. The use of
644645
* the coordinates differ based on what objects are being drawn. If the object is
645646
* a Group, Container or Display List, the coordinates are _added_ to the positions
646647
* of the children. For all other types of object, the coordinates are exact.
647-
*
648+
*
648649
* Calling this method causes the WebGL batch to flush, so it can write the texture
649650
* data to the framebuffer being used internally. The batch is flushed at the end,
650651
* after the entries have been iterated. So if you've a bunch of objects to draw,
@@ -679,9 +680,9 @@ var RenderTexture = new Class({
679680

680681
/**
681682
* Draws the given object, or an array of objects, to this Render Texture.
682-
*
683+
*
683684
* It can accept any of the following:
684-
*
685+
*
685686
* * Any renderable Game Object, such as a Sprite, Text, Graphics or TileSprite.
686687
* * Dynamic and Static Tilemap Layers.
687688
* * A Group. The contents of which will be iterated and drawn in turn.
@@ -690,28 +691,28 @@ var RenderTexture = new Class({
690691
* * Another Render Texture.
691692
* * A Texture Frame instance.
692693
* * A string. This is used to look-up a texture from the Texture Manager.
693-
*
694+
*
694695
* Note: You cannot draw a Render Texture to itself.
695-
*
696+
*
696697
* If passing in a Group or Container it will only draw children that return `true`
697698
* when their `willRender()` method is called. I.e. a Container with 10 children,
698699
* 5 of which have `visible=false` will only draw the 5 visible ones.
699-
*
700+
*
700701
* If passing in an array of Game Objects it will draw them all, regardless if
701702
* they pass a `willRender` check or not.
702-
*
703+
*
703704
* You can pass in a string in which case it will look for a texture in the Texture
704705
* Manager matching that string, and draw the base frame. If you need to specify
705706
* exactly which frame to draw then use the method `drawFrame` instead.
706-
*
707+
*
707708
* You can pass in the `x` and `y` coordinates to draw the objects at. The use of
708709
* the coordinates differ based on what objects are being drawn. If the object is
709710
* a Group, Container or Display List, the coordinates are _added_ to the positions
710711
* of the children. For all other types of object, the coordinates are exact.
711-
*
712+
*
712713
* The `alpha` and `tint` values are only used by Texture Frames.
713714
* Game Objects use their own alpha and tint values when being drawn.
714-
*
715+
*
715716
* Calling this method causes the WebGL batch to flush, so it can write the texture
716717
* data to the framebuffer being used internally. The batch is flushed at the end,
717718
* after the entries have been iterated. So if you've a bunch of objects to draw,
@@ -763,8 +764,8 @@ var RenderTexture = new Class({
763764
this.renderer.pushScissor(cx, cy, cw, ch, ch);
764765

765766
var pipeline = this.pipeline;
766-
767-
pipeline.projOrtho(0, this.texture.width, 0, this.texture.height, -1000.0, 1000.0);
767+
768+
ProjectOrtho(pipeline, 0, this.texture.width, 0, this.texture.height, -1000.0, 1000.0);
768769

769770
this.batchList(entries, x, y, alpha, tint);
770771

@@ -774,7 +775,7 @@ var RenderTexture = new Class({
774775

775776
this.renderer.popScissor();
776777

777-
pipeline.projOrtho(0, pipeline.width, pipeline.height, 0, -1000.0, 1000.0);
778+
ProjectOrtho(pipeline, 0, pipeline.width, pipeline.height, 0, -1000.0, 1000.0);
778779
}
779780
else
780781
{
@@ -792,20 +793,20 @@ var RenderTexture = new Class({
792793

793794
/**
794795
* Draws the Texture Frame to the Render Texture at the given position.
795-
*
796+
*
796797
* Textures are referenced by their string-based keys, as stored in the Texture Manager.
797-
*
798+
*
798799
* ```javascript
799800
* var rt = this.add.renderTexture(0, 0, 800, 600);
800801
* rt.drawFrame(key, frame);
801802
* ```
802-
*
803+
*
803804
* You can optionally provide a position, alpha and tint value to apply to the frame
804805
* before it is drawn.
805-
*
806+
*
806807
* Calling this method will cause a batch flush, so if you've got a stack of things to draw
807808
* in a tight loop, try using the `draw` method instead.
808-
*
809+
*
809810
* If you need to draw a Sprite to this Render Texture, use the `draw` method instead.
810811
*
811812
* @method Phaser.GameObjects.RenderTexture#drawFrame
@@ -848,24 +849,24 @@ var RenderTexture = new Class({
848849
var cy = this.camera._cy;
849850
var cw = this.camera._cw;
850851
var ch = this.camera._ch;
851-
852+
852853
this.renderer.setFramebuffer(this.framebuffer, false);
853-
854+
854855
this.renderer.pushScissor(cx, cy, cw, ch, ch);
855-
856+
856857
var pipeline = this.pipeline;
857-
858-
pipeline.projOrtho(0, this.texture.width, 0, this.texture.height, -1000.0, 1000.0);
859-
858+
859+
ProjectOrtho(pipeline, 0, this.texture.width, 0, this.texture.height, -1000.0, 1000.0);
860+
860861
pipeline.batchTextureFrame(textureFrame, x + this.frame.cutX, y + this.frame.cutY, tint, alpha, this.camera.matrix, null);
861-
862+
862863
pipeline.flush();
863-
864+
864865
this.renderer.setFramebuffer(null, false);
865866

866867
this.renderer.popScissor();
867-
868-
pipeline.projOrtho(0, pipeline.width, pipeline.height, 0, -1000.0, 1000.0);
868+
869+
ProjectOrtho(pipeline, 0, pipeline.width, pipeline.height, 0, -1000.0, 1000.0);
869870
}
870871
else
871872
{
@@ -988,7 +989,7 @@ var RenderTexture = new Class({
988989
}
989990

990991
gameObject.setPosition(x + this.frame.cutX, y + this.frame.cutY);
991-
992+
992993
gameObject.renderWebGL(this.renderer, gameObject, 0, this.camera, null);
993994

994995
gameObject.setPosition(prevX, prevY);
@@ -1085,9 +1086,9 @@ var RenderTexture = new Class({
10851086
var ctx = this.context;
10861087
var cd = textureFrame.canvasData;
10871088
var source = textureFrame.source.image;
1088-
1089+
10891090
var matrix = this.camera.matrix;
1090-
1091+
10911092
ctx.globalAlpha = this.globalAlpha;
10921093

10931094
ctx.setTransform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
@@ -1098,11 +1099,11 @@ var RenderTexture = new Class({
10981099

10991100
/**
11001101
* Takes a snapshot of the given area of this Render Texture.
1101-
*
1102+
*
11021103
* The snapshot is taken immediately.
1103-
*
1104+
*
11041105
* To capture the whole Render Texture see the `snapshot` method. To capture a specific pixel, see `snapshotPixel`.
1105-
*
1106+
*
11061107
* Snapshots work by using the WebGL `readPixels` feature to grab every pixel from the frame buffer into an ArrayBufferView.
11071108
* It then parses this, copying the contents to a temporary Canvas and finally creating an Image object from it,
11081109
* which is the image returned to the callback provided. All in all, this is a computationally expensive and blocking process,
@@ -1137,11 +1138,11 @@ var RenderTexture = new Class({
11371138

11381139
/**
11391140
* Takes a snapshot of the whole of this Render Texture.
1140-
*
1141+
*
11411142
* The snapshot is taken immediately.
1142-
*
1143+
*
11431144
* To capture just a portion of the Render Texture see the `snapshotArea` method. To capture a specific pixel, see `snapshotPixel`.
1144-
*
1145+
*
11451146
* Snapshots work by using the WebGL `readPixels` feature to grab every pixel from the frame buffer into an ArrayBufferView.
11461147
* It then parses this, copying the contents to a temporary Canvas and finally creating an Image object from it,
11471148
* which is the image returned to the callback provided. All in all, this is a computationally expensive and blocking process,
@@ -1172,11 +1173,11 @@ var RenderTexture = new Class({
11721173

11731174
/**
11741175
* Takes a snapshot of the given pixel from this Render Texture.
1175-
*
1176+
*
11761177
* The snapshot is taken immediately.
1177-
*
1178+
*
11781179
* To capture the whole Render Texture see the `snapshot` method. To capture a specific portion, see `snapshotArea`.
1179-
*
1180+
*
11801181
* Unlike the other two snapshot methods, this one will send your callback a `Color` object containing the color data for
11811182
* the requested pixel. It doesn't need to create an internal Canvas or Image object, so is a lot faster to execute,
11821183
* using less memory, than the other snapshot methods.

0 commit comments

Comments
 (0)