mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 20:53:39 +00:00
Added camera gameobject filtering
This commit is contained in:
parent
8fd14688b6
commit
9856200fdf
25 changed files with 128 additions and 60 deletions
|
@ -61,6 +61,8 @@ var Camera = new Class({
|
|||
|
||||
// Follow
|
||||
this._follow = null;
|
||||
|
||||
this._id = 0;
|
||||
},
|
||||
|
||||
cameraToScreen: require('./components/CameraToScreen'),
|
||||
|
@ -71,6 +73,7 @@ var Camera = new Class({
|
|||
destroy: require('./components/Destroy'),
|
||||
fade: require('./components/Fade'),
|
||||
flash: require('./components/Flash'),
|
||||
ignore: require('./components/Ignore'),
|
||||
preRender: require('./components/PreRender'),
|
||||
removeBounds: require('./components/RemoveBounds'),
|
||||
setBackgroundColor: require('./components/SetBackgroundColor'),
|
||||
|
|
16
v3/src/camera/components/Ignore.js
Normal file
16
v3/src/camera/components/Ignore.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
var Ignore = function (gameObjectOrArray)
|
||||
{
|
||||
if (gameObjectOrArray instanceof Array)
|
||||
{
|
||||
for (var index = 0; index < gameObjectOrArray.length; ++index)
|
||||
{
|
||||
gameObjectOrArray[index].cameraFilter |= this._id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gameObjectOrArray.cameraFilter |= this._id;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Ignore;
|
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: '37876e10-8162-11e7-b191-e9a855a11647'
|
||||
build: '3bd13fc0-81f1-11e7-b26f-e58093bce12c'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -23,6 +23,7 @@ var GameObject = new Class({
|
|||
// Will Render bitmask flags for the components Visible, Alpha, Transform and Texture respectively
|
||||
this.renderMask = 15;
|
||||
this.renderFlags = 15;
|
||||
this.cameraFilter = 0;
|
||||
|
||||
this.input = null;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ var tempMatrixChar = new TransformMatrix();
|
|||
|
||||
var DynamicBitmapTextWebGLRenderer = function (renderer, gameObject, interpolationPercentage, camera)
|
||||
{
|
||||
if (this.renderMask !== this.renderFlags)
|
||||
if (this.renderMask !== this.renderFlags || (gameObject.cameraFilter > 0 && (gameObject.cameraFilter & camera._id)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ var tempMatrix = new TransformMatrix();
|
|||
|
||||
var BitmapTextWebGLRenderer = function (renderer, gameObject, interpolationPercentage, camera)
|
||||
{
|
||||
if (this.renderMask !== this.renderFlags)
|
||||
if (this.renderMask !== this.renderFlags || (gameObject.cameraFilter > 0 && (gameObject.cameraFilter & camera._id)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var BlitterWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
|
||||
{
|
||||
if (this.renderMask !== this.renderFlags)
|
||||
if (this.renderMask !== this.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var EffectLayerWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
|
||||
{
|
||||
if (this.renderMask !== this.renderFlags)
|
||||
if (this.renderMask !== this.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ var Path = function (x, y, width, rgb, alpha)
|
|||
|
||||
var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercentage, camera, forceRenderTarget)
|
||||
{
|
||||
if (this.renderMask !== this.renderFlags)
|
||||
if (this.renderMask !== this.renderFlags || (gameObject.cameraFilter > 0 && (gameObject.cameraFilter & camera._id)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var ImageWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
|
||||
{
|
||||
if (this.renderMask !== this.renderFlags)
|
||||
if (this.renderMask !== this.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
var VertexBuffer = require('../../renderer/webgl/resources/VertexBuffer');
|
||||
|
||||
var DeferredRenderer = function (renderer, lightLayer, interpolationPercentage, camera)
|
||||
{
|
||||
var spriteList = lightLayer.sprites;
|
||||
|
@ -5,7 +7,7 @@ var DeferredRenderer = function (renderer, lightLayer, interpolationPercentage,
|
|||
var batch = renderer.spriteBatch;
|
||||
var gl = renderer.gl;
|
||||
|
||||
if (this.renderMask !== this.renderFlags)
|
||||
if (this.renderMask !== this.renderFlags || length === 0 || (lightLayer.cameraFilter > 0 && (lightLayer.cameraFilter & camera._id)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -149,12 +151,12 @@ var DeferredRenderer = function (renderer, lightLayer, interpolationPercentage,
|
|||
renderer.setTexture({texture: lightLayer.gBufferNormalTex}, 1);
|
||||
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
gl.useProgram(lightLayer.lightPassShader.program);
|
||||
lightLayer.lightPassShader.bind();
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, lightLayer.lightPassVBO);
|
||||
gl.enableVertexAttribArray(0);
|
||||
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT, 0);
|
||||
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
||||
|
||||
VertexBuffer.SetDirty();
|
||||
batch.bind();
|
||||
};
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ var ForwardRenderer = function (renderer, lightLayer, interpolationPercentage, c
|
|||
var length = spriteList.length;
|
||||
var batch = renderer.spriteBatch;
|
||||
|
||||
if (this.renderMask !== this.renderFlags || length === 0)
|
||||
if (this.renderMask !== this.renderFlags || length === 0 || (lightLayer.cameraFilter > 0 && (lightLayer.cameraFilter & camera._id)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ var TexturedAndNormalizedTintedShader = require('../../renderer/webgl/shaders/Te
|
|||
var Const = require('./Const');
|
||||
var Matrix = require('../components/TransformMatrix');
|
||||
var TempMatrix = new Matrix();
|
||||
var VertexBuffer = require('../../renderer/webgl/resources/VertexBuffer');
|
||||
|
||||
// http://cpetry.github.io/NormalMap-Online/
|
||||
|
||||
|
@ -267,6 +268,7 @@ var LightLayer = new Class({
|
|||
}
|
||||
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
VertexBuffer.SetDirty();
|
||||
}
|
||||
|
||||
this.setOrigin(0, 0);
|
||||
|
@ -392,18 +394,22 @@ var LightLayer = new Class({
|
|||
var point = {x: 0, y: 0};
|
||||
var height = renderer.height;
|
||||
var cameraMatrix = camera.matrix;
|
||||
shader.setConstantFloat4(this.uCameraLoc, camera.x, camera.y, camera.rotation, camera.zoom);
|
||||
shader.setConstantFloat2(this.uResolutionLoc, renderer.width, renderer.height);
|
||||
shader.setConstantFloat3(this.ambientLightColorLoc, this.ambientLightColorR, this.ambientLightColorG, this.ambientLightColorB);
|
||||
var gl = this.gl;
|
||||
|
||||
shader.bind();
|
||||
|
||||
gl.uniform2f(this.uResolutionLoc, renderer.width, renderer.height);
|
||||
gl.uniform3f(this.ambientLightColorLoc, this.ambientLightColorR, this.ambientLightColorG, this.ambientLightColorB);
|
||||
gl.uniform4f(this.uCameraLoc, camera.x, camera.y, camera.rotation, camera.zoom);
|
||||
|
||||
for (var index = 0; index < length; ++index)
|
||||
{
|
||||
var light = lights[index];
|
||||
cameraMatrix.transformPoint(light.x, light.y, point);
|
||||
shader.setConstantFloat3(locations[index].position, point.x - (camera.scrollX * light.scrollFactorX * camera.zoom), height - (point.y - (camera.scrollY * light.scrollFactorY) * camera.zoom), light.z);
|
||||
shader.setConstantFloat3(locations[index].color, light.r, light.g, light.b);
|
||||
shader.setConstantFloat1(locations[index].attenuation, light.attenuation);
|
||||
shader.setConstantFloat1(locations[index].radius, light.radius);
|
||||
gl.uniform1f(locations[index].attenuation, light.attenuation);
|
||||
gl.uniform1f(locations[index].radius, light.radius);
|
||||
gl.uniform3f(locations[index].position, point.x - (camera.scrollX * light.scrollFactorX * camera.zoom), height - (point.y - (camera.scrollY * light.scrollFactorY) * camera.zoom), light.z);
|
||||
gl.uniform3f(locations[index].color, light.r, light.g, light.b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var MeshWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
|
||||
{
|
||||
if (this.renderMask !== this.renderFlags)
|
||||
if (this.renderMask !== this.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var RenderPassWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
|
||||
{
|
||||
if (this.renderMask !== this.renderFlags)
|
||||
if (this.renderMask !== this.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var SpriteWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
|
||||
{
|
||||
if (this.renderMask !== this.renderFlags)
|
||||
if (this.renderMask !== this.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var TextWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
|
||||
{
|
||||
if (this.renderMask !== this.renderFlags)
|
||||
if (this.renderMask !== this.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var TilemapWebGLRenderer = function (renderer, gameObject, interpolationPercentage, camera)
|
||||
{
|
||||
if (this.renderMask !== this.renderFlags)
|
||||
if (this.renderMask !== this.renderFlags || (gameObject.cameraFilter > 0 && (gameObject.cameraFilter & camera._id)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var StaticTilemapWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
|
||||
{
|
||||
if (this.renderMask !== this.renderFlags)
|
||||
if (this.renderMask !== this.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var TileSpriteWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
|
||||
{
|
||||
if (this.renderMask !== this.renderFlags)
|
||||
if (this.renderMask !== this.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ var CameraManager = new Class({
|
|||
function CameraManager (scene)
|
||||
{
|
||||
// The Scene that owns this plugin
|
||||
this.currentCameraId = 1;
|
||||
this.scene = scene;
|
||||
|
||||
this.cameras = [];
|
||||
|
@ -30,6 +31,7 @@ var CameraManager = new Class({
|
|||
|
||||
// Set the default camera
|
||||
this.main = this.cameras[0];
|
||||
|
||||
},
|
||||
|
||||
/*
|
||||
|
@ -144,6 +146,9 @@ var CameraManager = new Class({
|
|||
this.main = camera;
|
||||
}
|
||||
|
||||
camera._id = this.currentCameraId;
|
||||
this.currentCameraId = this.currentCameraId << 1;
|
||||
|
||||
return camera;
|
||||
},
|
||||
|
||||
|
|
|
@ -130,6 +130,7 @@ var WebGLRenderer = new Class({
|
|||
this.tileBatch = this.addRenderer(new TileBatch(this.game, gl, this));
|
||||
this.tilemapRenderer = this.addRenderer(new TilemapRenderer(this.game, gl, this));
|
||||
this.currentRenderer = this.spriteBatch;
|
||||
this.currentVertexBuffer = null;
|
||||
this.setBlendMode(0);
|
||||
this.resize(this.width, this.height);
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
var Class = require('../../../utils/Class');
|
||||
|
||||
var CurrentIndexBuffer = null;
|
||||
var IndexBuffer = new Class({
|
||||
|
||||
initialize:
|
||||
|
@ -14,8 +14,11 @@ var IndexBuffer = new Class({
|
|||
bind: function ()
|
||||
{
|
||||
var gl = this.gl;
|
||||
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.bufferObject);
|
||||
if (CurrentIndexBuffer !== this)
|
||||
{
|
||||
CurrentIndexBuffer = this;
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.bufferObject);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
@ -24,7 +27,11 @@ var IndexBuffer = new Class({
|
|||
{
|
||||
var gl = this.gl;
|
||||
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.bufferObject);
|
||||
if (CurrentIndexBuffer !== this)
|
||||
{
|
||||
CurrentIndexBuffer = this;
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.bufferObject);
|
||||
}
|
||||
gl.bufferSubData(gl.ELEMENT_ARRAY_BUFFER, offset, bufferData);
|
||||
|
||||
return this;
|
||||
|
@ -32,4 +39,9 @@ var IndexBuffer = new Class({
|
|||
|
||||
});
|
||||
|
||||
IndexBuffer.SetDirty = function ()
|
||||
{
|
||||
CurrentIndexBuffer = null;
|
||||
};
|
||||
|
||||
module.exports = IndexBuffer;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
var Class = require('../../../utils/Class');
|
||||
|
||||
var CurrentShader = null;
|
||||
var Shader = new Class({
|
||||
|
||||
initialize:
|
||||
|
@ -31,7 +31,7 @@ var Shader = new Class({
|
|||
|
||||
setConstantFloat1: function (location, x)
|
||||
{
|
||||
this.gl.useProgram(this.program);
|
||||
this.bind();
|
||||
this.gl.uniform1f(location, x);
|
||||
|
||||
return this;
|
||||
|
@ -39,7 +39,7 @@ var Shader = new Class({
|
|||
|
||||
setConstantFloat2: function (location, x, y)
|
||||
{
|
||||
this.gl.useProgram(this.program);
|
||||
this.bind();
|
||||
this.gl.uniform2f(location, x, y);
|
||||
|
||||
return this;
|
||||
|
@ -47,7 +47,7 @@ var Shader = new Class({
|
|||
|
||||
setConstantFloat3: function (location, x, y, z)
|
||||
{
|
||||
this.gl.useProgram(this.program);
|
||||
this.bind();
|
||||
this.gl.uniform3f(location, x, y, z);
|
||||
|
||||
return this;
|
||||
|
@ -55,7 +55,7 @@ var Shader = new Class({
|
|||
|
||||
setConstantFloat4: function (location, x, y, z, w)
|
||||
{
|
||||
this.gl.useProgram(this.program);
|
||||
this.bind();
|
||||
this.gl.uniform4f(location, x, y, z, w);
|
||||
|
||||
return this;
|
||||
|
@ -63,7 +63,7 @@ var Shader = new Class({
|
|||
|
||||
setConstantInt1: function (location, x)
|
||||
{
|
||||
this.gl.useProgram(this.program);
|
||||
this.bind();
|
||||
this.gl.uniform1i(location, x);
|
||||
|
||||
return this;
|
||||
|
@ -71,7 +71,7 @@ var Shader = new Class({
|
|||
|
||||
setConstantInt2: function (location, x, y)
|
||||
{
|
||||
this.gl.useProgram(this.program);
|
||||
this.bind();
|
||||
this.gl.uniform2i(location, x, y);
|
||||
|
||||
return this;
|
||||
|
@ -79,7 +79,7 @@ var Shader = new Class({
|
|||
|
||||
setConstantInt3: function (location, x, y, z)
|
||||
{
|
||||
this.gl.useProgram(this.program);
|
||||
this.bind();
|
||||
this.gl.uniform3i(location, x, y, z);
|
||||
|
||||
return this;
|
||||
|
@ -87,7 +87,7 @@ var Shader = new Class({
|
|||
|
||||
setConstantInt4: function (location, x, y, z, w)
|
||||
{
|
||||
this.gl.useProgram(this.program);
|
||||
this.bind();
|
||||
this.gl.uniform4i(location, x, y, z, w);
|
||||
|
||||
return this;
|
||||
|
@ -95,7 +95,7 @@ var Shader = new Class({
|
|||
|
||||
setConstantMatrix2x2: function (location, floatArray)
|
||||
{
|
||||
this.gl.useProgram(this.program);
|
||||
this.bind();
|
||||
this.gl.uniformMatrix2fv(location, false, floatArray);
|
||||
|
||||
return this;
|
||||
|
@ -103,7 +103,7 @@ var Shader = new Class({
|
|||
|
||||
setConstantMatrix3x3: function (location, floatArray)
|
||||
{
|
||||
this.gl.useProgram(this.program);
|
||||
this.bind();
|
||||
this.gl.uniformMatrix3fv(location, false, floatArray);
|
||||
|
||||
return this;
|
||||
|
@ -111,7 +111,7 @@ var Shader = new Class({
|
|||
|
||||
setConstantMatrix4x4: function (location, floatArray)
|
||||
{
|
||||
this.gl.useProgram(this.program);
|
||||
this.bind();
|
||||
this.gl.uniformMatrix4fv(location, false, floatArray);
|
||||
|
||||
return this;
|
||||
|
@ -119,11 +119,20 @@ var Shader = new Class({
|
|||
|
||||
bind: function ()
|
||||
{
|
||||
this.gl.useProgram(this.program);
|
||||
if (CurrentShader !== this)
|
||||
{
|
||||
CurrentShader = this;
|
||||
this.gl.useProgram(this.program);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Shader.SetDirty = function ()
|
||||
{
|
||||
CurrentShader = null;
|
||||
};
|
||||
|
||||
module.exports = Shader;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
var Class = require('../../../utils/Class');
|
||||
|
||||
var CurrentVertexBuffer = null;
|
||||
var VertexBuffer = new Class({
|
||||
|
||||
initialize:
|
||||
|
@ -30,7 +30,11 @@ var VertexBuffer = new Class({
|
|||
{
|
||||
var gl = this.gl;
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.bufferObject);
|
||||
if (CurrentVertexBuffer !== this)
|
||||
{
|
||||
CurrentVertexBuffer = this;
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.bufferObject);
|
||||
}
|
||||
gl.bufferSubData(gl.ARRAY_BUFFER, offset, bufferData);
|
||||
|
||||
return this;
|
||||
|
@ -43,29 +47,38 @@ var VertexBuffer = new Class({
|
|||
var attributes = this.attributes;
|
||||
var attributesLength = attributes.length;
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, bufferObject);
|
||||
|
||||
for (var index = 0; index < attributesLength; ++index)
|
||||
if (CurrentVertexBuffer !== this)
|
||||
{
|
||||
var element = attributes[index];
|
||||
|
||||
if (element !== undefined && element !== null)
|
||||
CurrentVertexBuffer = this;
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, bufferObject);
|
||||
|
||||
for (var index = 0; index < attributesLength; ++index)
|
||||
{
|
||||
gl.enableVertexAttribArray(element.index);
|
||||
gl.vertexAttribPointer(
|
||||
element.index,
|
||||
element.size,
|
||||
element.type,
|
||||
element.normalized,
|
||||
element.stride,
|
||||
element.offset
|
||||
);
|
||||
var element = attributes[index];
|
||||
|
||||
if (element !== undefined && element !== null)
|
||||
{
|
||||
gl.enableVertexAttribArray(element.index);
|
||||
gl.vertexAttribPointer(
|
||||
element.index,
|
||||
element.size,
|
||||
element.type,
|
||||
element.normalized,
|
||||
element.stride,
|
||||
element.offset
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
VertexBuffer.SetDirty = function ()
|
||||
{
|
||||
CurrentVertexBuffer = null;
|
||||
};
|
||||
|
||||
module.exports = VertexBuffer;
|
||||
|
|
Loading…
Reference in a new issue