r3-legacy/src/game-lib-d3-render-target.js

118 lines
2.8 KiB
JavaScript
Raw Normal View History

2017-01-10 17:04:30 +01:00
/**
* Renders a scene with a camera
* @param graphics GameLib.D3.Graphics
* @param apiRenderTarget GameLib.D3.API.RenderTarget
* @constructor
*/
GameLib.D3.RenderTarget = function (
graphics,
apiRenderTarget
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
GameLib.D3.API.RenderTarget.call(
this,
apiRenderTarget.id,
apiRenderTarget.name,
apiRenderTarget.width,
apiRenderTarget.height,
apiRenderTarget.minFilter,
apiRenderTarget.magFilter,
apiRenderTarget.format,
apiRenderTarget.stencilBuffer
);
this.instance = this.createInstance();
};
GameLib.D3.RenderTarget.prototype = Object.create(GameLib.D3.API.RenderTarget.prototype);
GameLib.D3.RenderTarget.prototype.constructor = GameLib.D3.RenderTarget;
/**
* Some constants (based on THREE.js constants - update if needed)
* @type {number}
*/
GameLib.D3.RenderTarget.LINEAR_FILTER = 1006;
GameLib.D3.RenderTarget.RGB_FORMAT = 1022;
GameLib.D3.RenderTarget.RGBA_FORMAT = 1023;
/**
* Creates a Render Target instance
* @param update
* @returns {*}
*/
GameLib.D3.RenderTarget.prototype.createInstance = function(update) {
var instance = null;
if (update) {
instance = this.instance;
instance.width = this.width;
instance.height = this.height;
instance.minFilter = this.minFilter;
instance.magFilter = this.magFilter;
instance.format = this.format;
instance.stencilBuffer = this.stencilBuffer;
} else {
instance = new THREE.WebGLRenderTarget(
this.width,
this.height,
{
minFilter : this.minFilter,
magFilter : this.magFilter,
format : this.format,
stencilBuffer : this.stencilBuffer
}
);
}
return instance;
};
/**
* updates instance
*/
GameLib.D3.RenderTarget.prototype.updateInstance = function() {
this.instance = this.createInstance(true);
};
/**
* Render Target to API Render Target
* @returns {GameLib.D3.API.RenderTarget}
*/
GameLib.D3.RenderTarget.prototype.toApiComponent = function() {
var apiRenderTarget = new GameLib.D3.API.RenderTarget(
this.id,
this.name,
this.width,
this.height,
this.minFilter,
this.magFilter,
this.format,
this.stencilBuffer,
GameLib.Utils.IdOrNull(this.parentEntity)
);
return apiRenderTarget;
};
/**
*
* @param graphics
* @param objectComponent
* @returns {GameLib.D3.RenderTarget}
* @constructor
*/
GameLib.D3.RenderTarget.FromObjectComponent = function(graphics, objectComponent) {
var apiRenderTarget = GameLib.D3.API.RenderTarget.FromObjectComponent(objectComponent);
return new GameLib.D3.RenderTarget(
graphics,
apiRenderTarget
);
};