2017-01-10 17:04:30 +01:00
|
|
|
/**
|
|
|
|
* Renders a scene with a camera
|
2017-12-02 11:49:27 +01:00
|
|
|
* @param graphics GameLib.GraphicsRuntime
|
2017-01-10 17:04:30 +01:00
|
|
|
* @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,
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a Render Target instance
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
2017-06-28 17:09:06 +02:00
|
|
|
GameLib.D3.RenderTarget.prototype.createInstance = function() {
|
2017-01-10 17:04:30 +01:00
|
|
|
|
2017-10-23 14:52:35 +02:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(this.texture)) {
|
|
|
|
throw new Error('no texture');
|
|
|
|
}
|
2017-01-10 17:04:30 +01:00
|
|
|
|
2017-10-23 14:52:35 +02:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(this.texture.instance)) {
|
|
|
|
throw new Error('no texture instance');
|
2017-01-10 17:04:30 +01:00
|
|
|
}
|
|
|
|
|
2017-10-23 14:52:35 +02:00
|
|
|
this.instance = new THREE.WebGLRenderTarget(
|
|
|
|
this.width,
|
|
|
|
this.height,
|
|
|
|
{
|
|
|
|
stencilBuffer : this.stencilBuffer
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.instance.texture = this.texture.instance;
|
2017-10-09 10:18:59 +02:00
|
|
|
|
2017-10-23 14:52:35 +02:00
|
|
|
GameLib.Component.prototype.createInstance.call(this);
|
2017-01-10 17:04:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* updates instance
|
|
|
|
*/
|
|
|
|
GameLib.D3.RenderTarget.prototype.updateInstance = function() {
|
2017-10-09 10:18:59 +02:00
|
|
|
|
|
|
|
if (this.instance) {
|
|
|
|
this.instance.setSize(this.width, this.height);
|
|
|
|
this.instance.stencilBuffer = this.stencilBuffer;
|
2017-10-27 11:03:21 +02:00
|
|
|
if (this.texture && this.texture.instance) {
|
2017-10-09 10:18:59 +02:00
|
|
|
this.instance.texture = this.texture.instance;
|
|
|
|
this.instance.texture.needsUpdate = true;
|
|
|
|
} else {
|
|
|
|
this.instance.texture = null;
|
|
|
|
}
|
|
|
|
} else {
|
2017-10-23 14:52:35 +02:00
|
|
|
try {
|
|
|
|
this.createInstance();
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
2017-10-09 10:18:59 +02:00
|
|
|
}
|
|
|
|
}
|
2017-01-10 17:04:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.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
|
|
|
|
);
|
|
|
|
};
|