mirror of
https://github.com/photonstorm/phaser
synced 2024-11-30 00:21:04 +00:00
Starting core renderer
This commit is contained in:
parent
a30675d1fd
commit
b05d7f5481
4 changed files with 204 additions and 11 deletions
|
@ -124,12 +124,6 @@ var Layer3DScene = new Class({
|
|||
renderList.add(object, camera);
|
||||
}
|
||||
|
||||
// if (object.type === OBJECT_TYPE.CANVAS2D)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Handle children by recursion
|
||||
var children = object.children;
|
||||
|
||||
for (var i = 0; i < children.length; i++)
|
||||
|
@ -150,11 +144,6 @@ var Layer3DScene = new Class({
|
|||
this.lights.add(object);
|
||||
}
|
||||
|
||||
// if (object.type === OBJECT_TYPE.CANVAS2D)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
var children = object.children;
|
||||
|
||||
for (var i = 0; i < children.length; i++)
|
||||
|
|
39
src/layer3d/render/RenderTargetBack.js
Normal file
39
src/layer3d/render/RenderTargetBack.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2020 Photon Storm Ltd.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
var Class = require('../../utils/Class');
|
||||
var RenderTargetBase = require('./RenderTargetBase');
|
||||
|
||||
var RenderTargetBack = new Class({
|
||||
|
||||
Extends: RenderTargetBase,
|
||||
|
||||
initialize:
|
||||
|
||||
function RenderTargetBack (view)
|
||||
{
|
||||
RenderTargetBase.call(this, view.width, view.height);
|
||||
|
||||
this.view = view;
|
||||
},
|
||||
|
||||
resize: function (width, height)
|
||||
{
|
||||
this.view.width = width;
|
||||
this.view.height = height;
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
},
|
||||
|
||||
dispose: function ()
|
||||
{
|
||||
// TODO - Event?
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = RenderTargetBack;
|
43
src/layer3d/render/RenderTargetBase.js
Normal file
43
src/layer3d/render/RenderTargetBase.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2020 Photon Storm Ltd.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
var Class = require('../../utils/Class');
|
||||
|
||||
var RenderTargetBase = new Class({
|
||||
|
||||
initialize:
|
||||
|
||||
function RenderTargetBase (width, height)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
this.isRenderTarget = true;
|
||||
},
|
||||
|
||||
resize: function (width, height)
|
||||
{
|
||||
if (this.width !== width || this.height !== height)
|
||||
{
|
||||
this.dispose();
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
dispose: function ()
|
||||
{
|
||||
// TODO - Event?
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = RenderTargetBase;
|
122
src/layer3d/render/Renderer.js
Normal file
122
src/layer3d/render/Renderer.js
Normal file
|
@ -0,0 +1,122 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2020 Photon Storm Ltd.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
var Class = require('../../utils/Class');
|
||||
var RenderTargetBack = require('./RenderTargetBack');
|
||||
|
||||
var Renderer = new Class({
|
||||
|
||||
initialize:
|
||||
|
||||
function Renderer (scene)
|
||||
{
|
||||
this.scene = scene;
|
||||
|
||||
this.gl = scene.sys.renderer.gl;
|
||||
|
||||
this.backRenderTarget = new RenderTargetBack(scene.sys.renderer.canvas);
|
||||
|
||||
this.shadowMapPass;
|
||||
|
||||
this.shadowAutoUpdate = false;
|
||||
this.shadowNeedsUpdate = false;
|
||||
|
||||
this.matrixAutoUpdate = true;
|
||||
this.lightsAutoUpdate = true;
|
||||
this.autoClear = true;
|
||||
|
||||
/*
|
||||
var properties = new WebGLProperties();
|
||||
|
||||
this.properties = properties;
|
||||
|
||||
var capabilities = new WebGLCapabilities(gl);
|
||||
|
||||
this.capabilities = capabilities;
|
||||
|
||||
var state = new WebGLState(gl, capabilities);
|
||||
|
||||
this.state = state;
|
||||
|
||||
var vertexArrayBindings = new WebGLVertexArrayBindings(gl, properties, capabilities);
|
||||
|
||||
this.vertexArrayBindings = vertexArrayBindings;
|
||||
|
||||
var texture = new WebGLTexture(gl, state, properties, capabilities);
|
||||
|
||||
this.texture = texture;
|
||||
|
||||
var renderBuffer = new WebGLRenderBuffer(gl, properties, capabilities);
|
||||
|
||||
this.renderTarget = new WebGLRenderTarget(gl, state, texture, renderBuffer, properties, capabilities);
|
||||
|
||||
this.geometry = new WebGLGeometry(gl, state, vertexArrayBindings, properties, capabilities);
|
||||
|
||||
this.programs = new WebGLPrograms(gl, state, capabilities);
|
||||
|
||||
this._usedTextureUnits = 0;
|
||||
*/
|
||||
},
|
||||
|
||||
render: function (scene, camera, renderTarget, forceClear)
|
||||
{
|
||||
if (renderTarget === undefined) { renderTarget = this.backRenderTarget; }
|
||||
|
||||
if (this.matrixAutoUpdate)
|
||||
{
|
||||
scene.updateMatrix();
|
||||
}
|
||||
|
||||
if (this.lightsAutoUpdate)
|
||||
{
|
||||
scene.updateLights();
|
||||
}
|
||||
|
||||
/*
|
||||
if (this.shadowAutoUpdate || this.shadowNeedsUpdate)
|
||||
{
|
||||
this.shadowMapPass.render(this.glCore, scene);
|
||||
|
||||
this.shadowNeedsUpdate = false;
|
||||
}
|
||||
*/
|
||||
|
||||
// this.renderTarget.setRenderTarget(renderTarget);
|
||||
|
||||
if (this.autoClear || forceClear)
|
||||
{
|
||||
this.clear(true, true, true);
|
||||
}
|
||||
|
||||
var renderList = scene.updateRenderList(camera);
|
||||
|
||||
// TODO - Avoid object creation each frame:
|
||||
this.renderPass(renderList.opaque, camera, {
|
||||
scene: scene,
|
||||
getMaterial: function (renderable)
|
||||
{
|
||||
return scene.overrideMaterial || renderable.material;
|
||||
}
|
||||
});
|
||||
|
||||
// TODO - Avoid object creation each frame:
|
||||
this.renderPass(renderList.transparent, camera, {
|
||||
scene: scene,
|
||||
getMaterial: function (renderable)
|
||||
{
|
||||
return scene.overrideMaterial || renderable.material;
|
||||
}
|
||||
});
|
||||
|
||||
if (renderTarget.texture)
|
||||
{
|
||||
renderTarget.updateRenderTargetMipmap(renderTarget);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = Renderer;
|
Loading…
Reference in a new issue