mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Moved SnapShot feature into the renderer folder and updated paths.
This commit is contained in:
parent
c86c2bae81
commit
5d1393b9dc
6 changed files with 28 additions and 16 deletions
|
@ -3,7 +3,7 @@ var DrawImage = require('./utils/DrawImage');
|
|||
var BlitImage = require('./utils/BlitImage');
|
||||
var GetBlendModes = require('./utils/GetBlendModes');
|
||||
var GetContext = require('../../canvas/GetContext');
|
||||
var Snapshot = require('../../snapshot/Snapshot');
|
||||
var CanvasSnapshot = require('../snapshot/CanvasSnapshot');
|
||||
var Smoothing = require('../../dom/Smoothing');
|
||||
var ScaleModes = require('../ScaleModes');
|
||||
|
||||
|
@ -257,7 +257,7 @@ CanvasRenderer.prototype = {
|
|||
|
||||
if (this.snapshotCallback)
|
||||
{
|
||||
this.snapshotCallback(Snapshot.CanvasSnapshot(this.gameCanvas));
|
||||
this.snapshotCallback(CanvasSnapshot(this.gameCanvas));
|
||||
this.snapshotCallback = null;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
var CanvasSnapshot = function (canvas)
|
||||
{
|
||||
var src = canvas.toDataURL();
|
||||
|
||||
var image = new Image();
|
||||
|
||||
image.src = src;
|
||||
|
||||
return image;
|
||||
};
|
||||
|
8
v3/src/renderer/snapshot/Snapshot.js
Normal file
8
v3/src/renderer/snapshot/Snapshot.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
// Phaser.Renderer.Snapshot
|
||||
|
||||
module.exports = {
|
||||
|
||||
Canvas: require('./CanvasSnapshot'),
|
||||
WebGL: require('./WebGLSnapshot')
|
||||
|
||||
};
|
|
@ -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);
|
||||
gl.readPixels(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
|
||||
|
||||
// CanvasPool?
|
||||
var canvas = document.createElement('canvas');
|
||||
var ctx = canvas.getContext('2d');
|
||||
var imageData;
|
||||
|
||||
canvas.width = gl.drawingBufferWidth;
|
||||
canvas.height = gl.drawingBufferHeight;
|
||||
|
||||
imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||
|
||||
var data = imageData.data;
|
||||
|
||||
for (var y = 0; y < canvas.height; y += 1)
|
||||
{
|
||||
for (var x = 0; x < canvas.width; x += 1)
|
||||
|
@ -24,10 +28,12 @@ var WebGLSnapshot = function (canvas)
|
|||
data[di + 3] = pixels[si + 3];
|
||||
}
|
||||
}
|
||||
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
|
||||
var src = canvas.toDataURL();
|
||||
var image = new Image();
|
||||
|
||||
image.src = src;
|
||||
|
||||
return image;
|
|
@ -17,7 +17,7 @@ var BlendModes = require('../BlendModes');
|
|||
var ScaleModes = require('../ScaleModes');
|
||||
var ResourceManager = require('./ResourceManager');
|
||||
var Resources = require('./resources');
|
||||
var Snapshot = require('../../snapshot/Snapshot');
|
||||
var WebGLSnapshot = require('../snapshot/WebGLSnapshot');
|
||||
|
||||
var WebGLRenderer = function (game)
|
||||
{
|
||||
|
@ -414,7 +414,7 @@ WebGLRenderer.prototype = {
|
|||
|
||||
if (this.snapshotCallback)
|
||||
{
|
||||
this.snapshotCallback(Snapshot.WebGLSnapshot(this.view));
|
||||
this.snapshotCallback(WebGLSnapshot(this.view));
|
||||
this.snapshotCallback = null;
|
||||
}
|
||||
|
||||
|
@ -428,7 +428,6 @@ WebGLRenderer.prototype = {
|
|||
this.snapshotCallback = callback;
|
||||
},
|
||||
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
this.gl = null;
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
module.exports = {
|
||||
CanvasSnapshot: require('./CanvasSnapshot'),
|
||||
WebGLSnapshot: require('./WebGLSnapshot')
|
||||
};
|
Loading…
Reference in a new issue