Moved SnapShot feature into the renderer folder and updated paths.

This commit is contained in:
photonstorm 2017-07-04 13:10:26 +01:00
parent c86c2bae81
commit 5d1393b9dc
6 changed files with 28 additions and 16 deletions

View file

@ -3,7 +3,7 @@ var DrawImage = require('./utils/DrawImage');
var BlitImage = require('./utils/BlitImage'); var BlitImage = require('./utils/BlitImage');
var GetBlendModes = require('./utils/GetBlendModes'); var GetBlendModes = require('./utils/GetBlendModes');
var GetContext = require('../../canvas/GetContext'); var GetContext = require('../../canvas/GetContext');
var Snapshot = require('../../snapshot/Snapshot'); var CanvasSnapshot = require('../snapshot/CanvasSnapshot');
var Smoothing = require('../../dom/Smoothing'); var Smoothing = require('../../dom/Smoothing');
var ScaleModes = require('../ScaleModes'); var ScaleModes = require('../ScaleModes');
@ -257,7 +257,7 @@ CanvasRenderer.prototype = {
if (this.snapshotCallback) if (this.snapshotCallback)
{ {
this.snapshotCallback(Snapshot.CanvasSnapshot(this.gameCanvas)); this.snapshotCallback(CanvasSnapshot(this.gameCanvas));
this.snapshotCallback = null; this.snapshotCallback = null;
} }

View file

@ -1,8 +1,11 @@
var CanvasSnapshot = function (canvas) var CanvasSnapshot = function (canvas)
{ {
var src = canvas.toDataURL(); var src = canvas.toDataURL();
var image = new Image(); var image = new Image();
image.src = src; image.src = src;
return image; return image;
}; };

View file

@ -0,0 +1,8 @@
// Phaser.Renderer.Snapshot
module.exports = {
Canvas: require('./CanvasSnapshot'),
WebGL: require('./WebGLSnapshot')
};

View file

@ -1,17 +1,21 @@
var WebGLSnapshot = function (canvas) var WebGLSnapshot = function (sourceCanvas)
{ {
var gl = canvas.getContext('experimental-webgl'); var gl = sourceCanvas.getContext('experimental-webgl');
var pixels = new Uint8Array(gl.drawingBufferWidth * gl.drawingBufferHeight * 4); var pixels = new Uint8Array(gl.drawingBufferWidth * gl.drawingBufferHeight * 4);
gl.readPixels(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight, gl.RGBA, gl.UNSIGNED_BYTE, pixels); gl.readPixels(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
// CanvasPool?
var canvas = document.createElement('canvas'); var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d'); var ctx = canvas.getContext('2d');
var imageData; var imageData;
canvas.width = gl.drawingBufferWidth; canvas.width = gl.drawingBufferWidth;
canvas.height = gl.drawingBufferHeight; canvas.height = gl.drawingBufferHeight;
imageData = ctx.getImageData(0, 0, canvas.width, canvas.height); imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
var data = imageData.data; var data = imageData.data;
for (var y = 0; y < canvas.height; y += 1) for (var y = 0; y < canvas.height; y += 1)
{ {
for (var x = 0; x < canvas.width; x += 1) for (var x = 0; x < canvas.width; x += 1)
@ -24,10 +28,12 @@ var WebGLSnapshot = function (canvas)
data[di + 3] = pixels[si + 3]; data[di + 3] = pixels[si + 3];
} }
} }
ctx.putImageData(imageData, 0, 0); ctx.putImageData(imageData, 0, 0);
var src = canvas.toDataURL(); var src = canvas.toDataURL();
var image = new Image(); var image = new Image();
image.src = src; image.src = src;
return image; return image;

View file

@ -17,7 +17,7 @@ var BlendModes = require('../BlendModes');
var ScaleModes = require('../ScaleModes'); var ScaleModes = require('../ScaleModes');
var ResourceManager = require('./ResourceManager'); var ResourceManager = require('./ResourceManager');
var Resources = require('./resources'); var Resources = require('./resources');
var Snapshot = require('../../snapshot/Snapshot'); var WebGLSnapshot = require('../snapshot/WebGLSnapshot');
var WebGLRenderer = function (game) var WebGLRenderer = function (game)
{ {
@ -414,7 +414,7 @@ WebGLRenderer.prototype = {
if (this.snapshotCallback) if (this.snapshotCallback)
{ {
this.snapshotCallback(Snapshot.WebGLSnapshot(this.view)); this.snapshotCallback(WebGLSnapshot(this.view));
this.snapshotCallback = null; this.snapshotCallback = null;
} }
@ -428,7 +428,6 @@ WebGLRenderer.prototype = {
this.snapshotCallback = callback; this.snapshotCallback = callback;
}, },
destroy: function () destroy: function ()
{ {
this.gl = null; this.gl = null;

View file

@ -1,4 +0,0 @@
module.exports = {
CanvasSnapshot: require('./CanvasSnapshot'),
WebGLSnapshot: require('./WebGLSnapshot')
};