mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 15:12:18 +00:00
RenderTarget added to renderable game objects
This commit is contained in:
parent
5cdf2f0e96
commit
581fdb50ee
11 changed files with 242 additions and 1 deletions
|
@ -12,6 +12,7 @@ var DynamicBitmapText = new Class({
|
||||||
Components.Alpha,
|
Components.Alpha,
|
||||||
Components.BlendMode,
|
Components.BlendMode,
|
||||||
Components.Origin,
|
Components.Origin,
|
||||||
|
Components.RenderTarget,
|
||||||
Components.Size,
|
Components.Size,
|
||||||
Components.Texture,
|
Components.Texture,
|
||||||
Components.Transform,
|
Components.Transform,
|
||||||
|
|
|
@ -12,6 +12,7 @@ var BitmapText = new Class({
|
||||||
Components.Alpha,
|
Components.Alpha,
|
||||||
Components.BlendMode,
|
Components.BlendMode,
|
||||||
Components.Origin,
|
Components.Origin,
|
||||||
|
Components.RenderTarget,
|
||||||
Components.Size,
|
Components.Size,
|
||||||
Components.Texture,
|
Components.Texture,
|
||||||
Components.Transform,
|
Components.Transform,
|
||||||
|
|
|
@ -30,6 +30,7 @@ var Blitter = new Class({
|
||||||
Mixins: [
|
Mixins: [
|
||||||
Components.Alpha,
|
Components.Alpha,
|
||||||
Components.BlendMode,
|
Components.BlendMode,
|
||||||
|
Components.RenderTarget,
|
||||||
Components.ScaleMode,
|
Components.ScaleMode,
|
||||||
Components.Size,
|
Components.Size,
|
||||||
Components.Texture,
|
Components.Texture,
|
||||||
|
|
|
@ -14,6 +14,7 @@ var Graphics = new Class({
|
||||||
Components.Alpha,
|
Components.Alpha,
|
||||||
Components.BlendMode,
|
Components.BlendMode,
|
||||||
Components.Transform,
|
Components.Transform,
|
||||||
|
Components.RenderTarget,
|
||||||
Components.Visible,
|
Components.Visible,
|
||||||
Render
|
Render
|
||||||
],
|
],
|
||||||
|
|
196
v3/src/gameobjects/renderpass/RenderPass.js
Normal file
196
v3/src/gameobjects/renderpass/RenderPass.js
Normal file
|
@ -0,0 +1,196 @@
|
||||||
|
var Class = require('../../utils/Class');
|
||||||
|
var GameObject = require('../GameObject');
|
||||||
|
var Components = require('../../components');
|
||||||
|
var Render = require('./RenderPassRender');
|
||||||
|
|
||||||
|
var RenderPass = new Class({
|
||||||
|
|
||||||
|
Extends: GameObject,
|
||||||
|
|
||||||
|
Mixins: [
|
||||||
|
Components.Alpha,
|
||||||
|
Components.BlendMode,
|
||||||
|
Components.Flip,
|
||||||
|
Components.GetBounds,
|
||||||
|
Components.Origin,
|
||||||
|
Components.RenderTarget,
|
||||||
|
Components.ScaleMode,
|
||||||
|
Components.Size,
|
||||||
|
Components.Transform,
|
||||||
|
Components.Visible,
|
||||||
|
Render
|
||||||
|
],
|
||||||
|
|
||||||
|
initialize:
|
||||||
|
|
||||||
|
function RenderPass(state, x, y, width, height, shaderName, fragmentShader)
|
||||||
|
{
|
||||||
|
GameObject.call(this, state);
|
||||||
|
|
||||||
|
var resourceManager = state.game.renderer.resourceManager;
|
||||||
|
var gl;
|
||||||
|
|
||||||
|
this.dstRenderTarget = null
|
||||||
|
this.dstRenderTexture = null;
|
||||||
|
this.dstShader = null;
|
||||||
|
this.uniforms = {};
|
||||||
|
|
||||||
|
if (resourceManager !== undefined)
|
||||||
|
{
|
||||||
|
/*gl = state.game.renderer.gl;
|
||||||
|
this.dstShader = resourceManager.createShader(shaderName, {
|
||||||
|
vert: TexturedAndNormalizedTintedShader.vert,
|
||||||
|
frag: fragmentShader
|
||||||
|
});
|
||||||
|
this.dstRenderTexture = resourceManager.createTexture(
|
||||||
|
0,
|
||||||
|
gl.LINEAR, gl.LINEAR,
|
||||||
|
gl.CLAMP_TO_EDGE, gl.CLAMP_TO_EDGE,
|
||||||
|
gl.RGBA,
|
||||||
|
null, width, height
|
||||||
|
);
|
||||||
|
this.dstRenderTarget = resourceManager.createRenderTarget(width, height, this.dstRenderTexture, null); */
|
||||||
|
state.game.renderer.currentTexture = null; // force rebinding of prev texture
|
||||||
|
}
|
||||||
|
this.flipY = true;
|
||||||
|
this.setPosition(x, y);
|
||||||
|
this.setSize(width, height);
|
||||||
|
this.setOrigin(0, 0);
|
||||||
|
},
|
||||||
|
|
||||||
|
render: function (gameObject)
|
||||||
|
{
|
||||||
|
},
|
||||||
|
|
||||||
|
getUniformLocation: function (uniformName)
|
||||||
|
{
|
||||||
|
var dstShader = this.dstShader;
|
||||||
|
var uniforms = this.uniforms;
|
||||||
|
var location;
|
||||||
|
|
||||||
|
if (uniformName in uniforms)
|
||||||
|
{
|
||||||
|
location = uniforms[uniformName];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
location = dstShader.getUniformLocation(uniformName);
|
||||||
|
uniforms[uniformName] = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
return location;
|
||||||
|
},
|
||||||
|
|
||||||
|
setFloat: function (uniformName, x)
|
||||||
|
{
|
||||||
|
var dstShader = this.dstShader;
|
||||||
|
|
||||||
|
if (dstShader === null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dstShader.setConstantFloat1(this.getUniformLocation(uniformName), x);
|
||||||
|
},
|
||||||
|
|
||||||
|
setFloat2: function (uniformName, x, y)
|
||||||
|
{
|
||||||
|
var dstShader = this.dstShader;
|
||||||
|
|
||||||
|
if (dstShader === null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dstShader.setConstantFloat2(this.getUniformLocation(uniformName), x, y);
|
||||||
|
},
|
||||||
|
|
||||||
|
setFloat3: function (uniformName, x, y, z)
|
||||||
|
{
|
||||||
|
var dstShader = this.dstShader;
|
||||||
|
|
||||||
|
if (dstShader === null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dstShader.setConstantFloat3(this.getUniformLocation(uniformName), x, y, z);
|
||||||
|
},
|
||||||
|
|
||||||
|
setFloat4: function (uniformName, x, y, z, w)
|
||||||
|
{
|
||||||
|
var dstShader = this.dstShader;
|
||||||
|
|
||||||
|
if (dstShader === null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dstShader.setConstantFloat4(this.getUniformLocation(uniformName), x, y, z, w);
|
||||||
|
},
|
||||||
|
|
||||||
|
setInt: function (uniformName, x)
|
||||||
|
{
|
||||||
|
var dstShader = this.dstShader;
|
||||||
|
|
||||||
|
if (dstShader === null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dstShader.setConstantInt1(this.getUniformLocation(uniformName), x);
|
||||||
|
},
|
||||||
|
|
||||||
|
setInt2: function (uniformName, x, y)
|
||||||
|
{
|
||||||
|
var dstShader = this.dstShader;
|
||||||
|
|
||||||
|
if (dstShader === null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dstShader.setConstantInt2(this.getUniformLocation(uniformName), x, y);
|
||||||
|
},
|
||||||
|
|
||||||
|
setInt3: function (uniformName, x, y, z)
|
||||||
|
{
|
||||||
|
var dstShader = this.dstShader;
|
||||||
|
|
||||||
|
if (dstShader === null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dstShader.setConstantInt3(this.getUniformLocation(uniformName), x, y, z);
|
||||||
|
},
|
||||||
|
|
||||||
|
setInt4: function (uniformName, x, y, z, w)
|
||||||
|
{
|
||||||
|
var dstShader = this.dstShader;
|
||||||
|
|
||||||
|
if (dstShader === null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dstShader.setConstantInt4(this.getUniformLocation(uniformName), x, y, z, w);
|
||||||
|
},
|
||||||
|
|
||||||
|
setMatrix2x2: function (uniformName, matrix)
|
||||||
|
{
|
||||||
|
var dstShader = this.dstShader;
|
||||||
|
|
||||||
|
if (dstShader === null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dstShader.setConstantMatrix2x2(this.getUniformLocation(uniformName), matrix);
|
||||||
|
},
|
||||||
|
|
||||||
|
setMatrix3x3: function (uniformName, matrix)
|
||||||
|
{
|
||||||
|
var dstShader = this.dstShader;
|
||||||
|
|
||||||
|
if (dstShader === null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dstShader.setConstantMatrix3x3(this.getUniformLocation(uniformName), matrix);
|
||||||
|
},
|
||||||
|
|
||||||
|
setMatrix4x4: function (uniformName, matrix)
|
||||||
|
{
|
||||||
|
var dstShader = this.dstShader;
|
||||||
|
|
||||||
|
if (dstShader === null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dstShader.setConstantMatrix4x4(this.getUniformLocation(uniformName), matrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = RenderPass;
|
|
@ -0,0 +1,7 @@
|
||||||
|
var RenderPassCanvasRenderer = function (renderer, src, interpolationPercentage, camera)
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = RenderPassCanvasRenderer;
|
||||||
|
|
20
v3/src/gameobjects/renderpass/RenderPassFactory.js
Normal file
20
v3/src/gameobjects/renderpass/RenderPassFactory.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
var RenderPass = require('./RenderPass');
|
||||||
|
var FactoryContainer = require('../../gameobjects/FactoryContainer');
|
||||||
|
|
||||||
|
var RenderPassFactory = {
|
||||||
|
|
||||||
|
KEY: 'renderPass',
|
||||||
|
|
||||||
|
add: function (x, y, width, height, shaderName, fragmentShader)
|
||||||
|
{
|
||||||
|
return this.children.add(new RenderPass(this.state, x, y, width, height, shaderName, fragmentShader));
|
||||||
|
},
|
||||||
|
|
||||||
|
make: function (x, y, width, height, shaderName, fragmentShader)
|
||||||
|
{
|
||||||
|
return new RenderPass(this.state, x, y, width, height, shaderName, fragmentShader);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = FactoryContainer.register(RenderPassFactory);
|
6
v3/src/gameobjects/renderpass/RenderPassRender.js
Normal file
6
v3/src/gameobjects/renderpass/RenderPassRender.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
module.exports = {
|
||||||
|
|
||||||
|
renderCanvas: require('./RenderPassCanvasRenderer'),
|
||||||
|
renderWebGL: require('./RenderPassWebGLRenderer')
|
||||||
|
|
||||||
|
};
|
7
v3/src/gameobjects/renderpass/RenderPassWebGLRenderer.js
Normal file
7
v3/src/gameobjects/renderpass/RenderPassWebGLRenderer.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
var RenderPassWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = RenderPassWebGLRenderer;
|
||||||
|
|
|
@ -16,6 +16,7 @@ var Text = new Class({
|
||||||
Components.BlendMode,
|
Components.BlendMode,
|
||||||
Components.GetBounds,
|
Components.GetBounds,
|
||||||
Components.Origin,
|
Components.Origin,
|
||||||
|
Components.RenderTarget,
|
||||||
Components.ScaleMode,
|
Components.ScaleMode,
|
||||||
Components.Transform,
|
Components.Transform,
|
||||||
Components.Visible,
|
Components.Visible,
|
||||||
|
|
|
@ -446,7 +446,7 @@ WebGLRenderer.prototype = {
|
||||||
dstTexture.height = srcCanvas.height;
|
dstTexture.height = srcCanvas.height;
|
||||||
|
|
||||||
/* we must rebind old texture */
|
/* we must rebind old texture */
|
||||||
gl.bindTexture(gl.TEXTURE_2D, this.currentTexture.texture);
|
this.currentTexture = null;
|
||||||
|
|
||||||
return dstTexture;
|
return dstTexture;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue