Fixes to get the renderer working.

This commit is contained in:
Richard Davey 2016-12-07 03:42:41 +00:00
parent 14ee4c2d1b
commit cee7498180
8 changed files with 38 additions and 26 deletions

View file

@ -15,6 +15,7 @@ var StateManager = require('../state/StateManager');
var FactoryContainer = require('../gameobjects/FactoryContainer');
var GameObjects = require('../gameobjects/');
var TextureManager = require ('../textures/TextureManager');
var AddToDOM = require('../dom/AddToDOM');
var Game = function (config)
{
@ -98,6 +99,8 @@ Game.prototype = {
CreateRenderer(this);
AddToDOM(this.canvas, this.config.parent);
this.state.boot();
this.isRunning = true;

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: '66ef5980-bc26-11e6-b62b-c7bd5e19f5c7'
build: '18d69660-bc2f-11e6-9837-952b15df5558'
};
module.exports = CHECKSUM;

View file

@ -34,7 +34,7 @@ var ImageFactory = {
console.log('ImageFactory.add', key, x, y, frame, group);
console.log('into State', this.state);
// return group.children.add(new Image(this.state, x, y, key, frame));
return group.children.add(new Image(this.state, x, y, key, frame));
},
make: function (x, y, key, frame)

View file

@ -32,11 +32,13 @@ ImageFile.prototype.onProcess = function (callback)
this.data = new Image();
this.data.crossOrigin = this.crossOrigin;
var _this = this;
this.data.onload = function ()
{
window.URL.revokeObjectURL(_this.data.src);
URL.revokeObjectURL(_this.data.src);
_this.onComplete();
@ -45,14 +47,14 @@ ImageFile.prototype.onProcess = function (callback)
this.data.onerror = function ()
{
window.URL.revokeObjectURL(_this.data.src);
URL.revokeObjectURL(_this.data.src);
_this.state = CONST.FILE_ERRORED;
callback(_this);
};
this.data.src = window.URL.createObjectURL(this.xhrLoader.response);
this.data.src = URL.createObjectURL(this.xhrLoader.response);
};
module.exports = ImageFile;

View file

@ -5,6 +5,7 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var CONST = require('../../const');
var CreateEmptyTexture = require('./utils/CreateEmptyTexture');
var QuadFBO = require('./utils/QuadFBO');
var BatchManager = require('./BatchManager');
@ -24,7 +25,7 @@ var WebGLRenderer = function (game)
*/
this.game = game;
this.type = Phaser.WEBGL;
this.type = CONST.WEBGL;
// Read all the following from game config
this.clearBeforeRender = true;
@ -35,11 +36,11 @@ var WebGLRenderer = function (game)
this.preserveDrawingBuffer = false;
this.width = game.width * game.resolution;
this.width = game.config.width * game.config.resolution;
this.height = game.height * game.resolution;
this.height = game.config.height * game.config.resolution;
this.resolution = game.resolution;
this.resolution = game.config.resolution;
this.clipUnitX = 2 / this.width;
@ -148,10 +149,10 @@ WebGLRenderer.prototype = {
gl.enable(gl.BLEND);
// Transparent
gl.clearColor(0, 0, 0, 0);
// gl.clearColor(0, 0, 0, 0);
// Black
// gl.clearColor(0, 0, 0, 1);
gl.clearColor(1, 0, 0, 1);
this.shaderManager.init();
this.batch.init();
@ -247,16 +248,18 @@ WebGLRenderer.prototype = {
resize: function (width, height)
{
this.width = width * this.game.resolution;
this.height = height * this.game.resolution;
var res = this.game.config.resolution;
this.width = width * res;
this.height = height * res;
this.view.width = this.width;
this.view.height = this.height;
if (this.autoResize)
{
this.view.style.width = (this.width / this.game.resolution) + 'px';
this.view.style.height = (this.height / this.game.resolution) + 'px';
this.view.style.width = (this.width / res) + 'px';
this.view.style.height = (this.height / res) + 'px';
}
this.gl.viewport(0, 0, this.width, this.height);
@ -264,8 +267,8 @@ WebGLRenderer.prototype = {
this.clipUnitX = 2 / this.width;
this.clipUnitY = 2 / this.height;
this.projection.x = (this.width / 2) / this.game.resolution;
this.projection.y = -(this.height / 2) / this.game.resolution;
this.projection.x = (this.width / 2) / res;
this.projection.y = -(this.height / 2) / res;
},
/**
@ -279,14 +282,14 @@ WebGLRenderer.prototype = {
*/
render: function (state, interpolationPercentage)
{
// console.log('%c render start ', 'color: #ffffff; background: #00ff00;');
// No point rendering if our context has been blown up!
if (this.contextLost)
{
return;
}
console.log('%c render start ', 'color: #ffffff; background: #00ff00;');
// Add Pre-render hook
this.startTime = Date.now();
@ -300,7 +303,7 @@ WebGLRenderer.prototype = {
// clear is needed for the FBO, otherwise corruption ...
gl.clear(gl.COLOR_BUFFER_BIT);
this.setBlendMode(Phaser.blendModes.NORMAL);
this.setBlendMode(CONST.blendModes.NORMAL);
this.drawCount = 0;
@ -413,16 +416,16 @@ WebGLRenderer.prototype = {
// @see https://github.com/mrdoob/three.js/issues/9109
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source.image);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, source.scaleMode === Phaser.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, source.scaleMode === CONST.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST);
if (source.mipmap && source.isPowerOf2)
{
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, source.scaleMode === Phaser.scaleModes.LINEAR ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, source.scaleMode === CONST.scaleModes.LINEAR ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST);
gl.generateMipmap(gl.TEXTURE_2D);
}
else
{
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, source.scaleMode === Phaser.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, source.scaleMode === CONST.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST);
}
if (source.isPowerOf2)
@ -441,6 +444,7 @@ WebGLRenderer.prototype = {
return true;
},
/*
updateCompressedTexture: function (texture)
{
if (!texture.hasLoaded)
@ -497,6 +501,7 @@ WebGLRenderer.prototype = {
return true;
},
*/
// Blend Mode Manager

View file

@ -4,6 +4,8 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var CreateEmptyTexture = require('./CreateEmptyTexture');
/**
* Frame Buffer Object with drawing quad + shader
*
@ -100,7 +102,7 @@ QuadFBO.prototype = {
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0, 0, 1, 0, 0, 1, 1, 1 ]), gl.STATIC_DRAW);
// Create a texture for our color buffer
this.texture = this.renderer.createEmptyTexture(width, height, 0, 0);
this.texture = CreateEmptyTexture(gl, width, height, 0, 0);
// The FBO's depth buffer
this.renderBuffer = gl.createRenderbuffer();

View file

@ -279,7 +279,7 @@ StateManager.prototype = {
var width = newState.settings.width;
var height = newState.settings.height;
// newState.sys.fbo = this.game.renderer.createFBO(newState, x, y, width, height);
newState.sys.fbo = this.game.renderer.createFBO(newState, x, y, width, height);
},
getState: function (key)

View file

@ -192,7 +192,7 @@ MainLoop.prototype = {
this.state.sys.updates.start();
if (this.state.settings.visible && this.state.sys.color.alpha !== 0 && this.state.sys.children.list.length > 0)
if (this.state.settings.visible && this.state.sys.color.alpha !== 0)
{
this.game.renderer.render(this.state, this.frameDelta / this.timestep);
}