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();
|
|
|
|
|
2017-01-17 13:24:45 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(apiRenderTarget)) {
|
|
|
|
apiRenderTarget = {};
|
|
|
|
}
|
|
|
|
|
2017-05-11 04:48:02 +02:00
|
|
|
if (apiRenderTarget instanceof GameLib.D3.RenderTarget) {
|
|
|
|
return apiRenderTarget;
|
|
|
|
}
|
|
|
|
|
2017-01-10 17:04:30 +01:00
|
|
|
GameLib.D3.API.RenderTarget.call(
|
|
|
|
this,
|
|
|
|
apiRenderTarget.id,
|
|
|
|
apiRenderTarget.name,
|
|
|
|
apiRenderTarget.width,
|
|
|
|
apiRenderTarget.height,
|
|
|
|
apiRenderTarget.minFilter,
|
|
|
|
apiRenderTarget.magFilter,
|
|
|
|
apiRenderTarget.format,
|
2017-01-12 17:40:17 +01:00
|
|
|
apiRenderTarget.stencilBuffer,
|
|
|
|
apiRenderTarget.texture
|
2017-01-10 17:04:30 +01:00
|
|
|
);
|
|
|
|
|
2017-06-16 15:49:53 +02:00
|
|
|
GameLib.Component.call(
|
|
|
|
this,
|
|
|
|
GameLib.Component.COMPONENT_RENDER_TARGET,
|
|
|
|
{
|
|
|
|
'texture' : GameLib.D3.Texture
|
|
|
|
}
|
|
|
|
);
|
2017-01-10 17:04:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
2017-01-12 17:40:17 +01:00
|
|
|
instance.texture = this.texture.instance;
|
|
|
|
instance.texture.needsUpdate = true;
|
2017-01-10 17:04:30 +01:00
|
|
|
} else {
|
|
|
|
instance = new THREE.WebGLRenderTarget(
|
|
|
|
this.width,
|
|
|
|
this.height,
|
|
|
|
{
|
|
|
|
minFilter : this.minFilter,
|
|
|
|
magFilter : this.magFilter,
|
|
|
|
format : this.format,
|
|
|
|
stencilBuffer : this.stencilBuffer
|
|
|
|
}
|
|
|
|
);
|
2017-01-12 17:40:17 +01:00
|
|
|
|
|
|
|
if (this.texture instanceof GameLib.D3.Texture && this.texture.instance) {
|
|
|
|
instance.texture = this.texture.instance;
|
|
|
|
}
|
2017-01-10 17:04:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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}
|
|
|
|
*/
|
2017-05-16 14:51:57 +02:00
|
|
|
GameLib.D3.RenderTarget.prototype.toApiObject = function() {
|
2017-01-10 17:04:30 +01:00
|
|
|
|
|
|
|
var apiRenderTarget = new GameLib.D3.API.RenderTarget(
|
|
|
|
this.id,
|
|
|
|
this.name,
|
|
|
|
this.width,
|
|
|
|
this.height,
|
|
|
|
this.minFilter,
|
|
|
|
this.magFilter,
|
|
|
|
this.format,
|
|
|
|
this.stencilBuffer,
|
2017-01-12 17:40:17 +01:00
|
|
|
GameLib.Utils.IdOrNull(this.texture),
|
2017-01-10 17:04:30 +01:00
|
|
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
|
|
|
);
|
|
|
|
|
|
|
|
return apiRenderTarget;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param graphics
|
|
|
|
* @param objectComponent
|
|
|
|
* @returns {GameLib.D3.RenderTarget}
|
|
|
|
* @constructor
|
|
|
|
*/
|
2017-06-14 14:21:57 +02:00
|
|
|
GameLib.D3.RenderTarget.FromObject = function(graphics, objectComponent) {
|
2017-01-10 17:04:30 +01:00
|
|
|
|
2017-06-14 14:21:57 +02:00
|
|
|
var apiRenderTarget = GameLib.D3.API.RenderTarget.FromObject(objectComponent);
|
2017-01-10 17:04:30 +01:00
|
|
|
|
|
|
|
return new GameLib.D3.RenderTarget(
|
|
|
|
graphics,
|
|
|
|
apiRenderTarget
|
|
|
|
);
|
|
|
|
};
|