r3-legacy/src/game-lib-d3-pass-0.js

114 lines
2.4 KiB
JavaScript

/**
* GameLib.D3.Pass
* @param graphics GameLib.GraphicsRuntime
* @param apiPass GameLib.D3.API.Pass
* @property passType
* @constructor
*/
GameLib.D3.Pass = function (
graphics,
apiPass
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiPass)) {
apiPass = {
passType : GameLib.D3.API.Pass.PASS_TYPE_NONE
}
}
GameLib.D3.API.Pass.call(
this,
apiPass.id,
apiPass.name,
apiPass.passType,
apiPass.parentEntity,
apiPass.renderToScreen
);
var linkedObjects = {};
switch (this.passType) {
case GameLib.D3.API.Pass.PASS_TYPE_RENDER:
case GameLib.D3.API.Pass.PASS_TYPE_SSAO:
linkedObjects.scene = GameLib.D3.Scene;
linkedObjects.camera = GameLib.D3.Camera;
break;
default :
break;
}
GameLib.Component.call(
this,
linkedObjects
);
};
GameLib.D3.Pass.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.Pass.prototype.constructor = GameLib.D3.Pass;
/**
* Create Pass instance
* @returns {*}
*/
GameLib.D3.Pass.prototype.createInstance = function() {
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
console.warn('no instance - call the child createInstance() first');
return;
}
this.instance.renderToScreen = this.renderToScreen;
GameLib.Component.prototype.createInstance.call(this);
};
/**
* Update Pass instance
*/
GameLib.D3.Pass.prototype.updateInstance = function(property) {
if (property === 'passType') {
var componentType = GameLib.D3.API.Pass.GetComponentType(this.passType);
this.replace(componentType);
return;
}
if (property === 'renderToScreen') {
this.instance.renderToScreen = this.renderToScreen;
}
};
/**
* Not all passes have setSize, but this is just a safety function in case someone calls setSize on a pass component
* @param property
*/
GameLib.D3.Pass.prototype.setSize = function(property) {
};
/**
* GameLib.D3.Pass to GameLib.D3.API.Pass
* @returns {GameLib.D3.API.Pass}
*/
GameLib.D3.Pass.prototype.toApiObject = function() {
var apiPass = new GameLib.D3.API.Pass(
this.id,
this.name,
this.passType,
GameLib.Utils.IdOrNull(this.parentEntity),
this.renderToScreen
);
return apiPass;
};