|
@@ -1,4 +1,62 @@
|
|
|
module BABYLON {
|
|
|
+ export interface Scene {
|
|
|
+ /** @hidden (Backing field) */
|
|
|
+ _geometryBufferRenderer: Nullable<GeometryBufferRenderer>;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Gets or Sets the current geometry buffer associated to the scene.
|
|
|
+ */
|
|
|
+ geometryBufferRenderer: Nullable<GeometryBufferRenderer>;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Enables a GeometryBufferRender and associates it with the scene
|
|
|
+ * @param ratio defines the scaling ratio to apply to the renderer (1 by default which means same resolution)
|
|
|
+ * @returns the GeometryBufferRenderer
|
|
|
+ */
|
|
|
+ enableGeometryBufferRenderer(ratio?: number): Nullable<GeometryBufferRenderer>;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Disables the GeometryBufferRender associated with the scene
|
|
|
+ */
|
|
|
+ disableGeometryBufferRenderer(): void;
|
|
|
+ }
|
|
|
+
|
|
|
+ Object.defineProperty(Scene.prototype, "geometryBufferRenderer", {
|
|
|
+ get: function (this:Scene) {
|
|
|
+ this._geometryBufferRenderer;
|
|
|
+ },
|
|
|
+ set: function (this:Scene, value: Nullable<GeometryBufferRenderer>) {
|
|
|
+ if (value && value.isSupported) {
|
|
|
+ this._geometryBufferRenderer = value;
|
|
|
+ };
|
|
|
+ },
|
|
|
+ enumerable: true,
|
|
|
+ configurable: true
|
|
|
+ });
|
|
|
+
|
|
|
+ Scene.prototype.enableGeometryBufferRenderer = function(ratio: number = 1): Nullable<GeometryBufferRenderer> {
|
|
|
+ if (this._geometryBufferRenderer) {
|
|
|
+ return this._geometryBufferRenderer;
|
|
|
+ }
|
|
|
+
|
|
|
+ this._geometryBufferRenderer = new GeometryBufferRenderer(this, ratio);
|
|
|
+ if (!this._geometryBufferRenderer.isSupported) {
|
|
|
+ this._geometryBufferRenderer = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return this._geometryBufferRenderer;
|
|
|
+ }
|
|
|
+
|
|
|
+ Scene.prototype.disableGeometryBufferRenderer = function(): void {
|
|
|
+ if (!this._geometryBufferRenderer) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ this._geometryBufferRenderer.dispose();
|
|
|
+ this._geometryBufferRenderer = null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* This renderer is helpfull to fill one of the render target with a geometry buffer.
|
|
|
*/
|
|
@@ -67,6 +125,13 @@ module BABYLON {
|
|
|
this._scene = scene;
|
|
|
this._ratio = ratio;
|
|
|
|
|
|
+ // Register the G Buffer component to the scene.
|
|
|
+ let component = scene._getComponent(SceneComponentConstants.NAME_GEOMETRYBUFFER) as GeometryBufferSceneComponent;
|
|
|
+ if (!component) {
|
|
|
+ component = new GeometryBufferSceneComponent(scene);
|
|
|
+ scene._addComponent(component);
|
|
|
+ }
|
|
|
+
|
|
|
// Render target
|
|
|
this._createRenderTargets();
|
|
|
}
|
|
@@ -269,4 +334,56 @@ module BABYLON {
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Defines the Geometry Buffer scene component responsible to manage a G-Buffer usefull
|
|
|
+ * in several rendering techniques.
|
|
|
+ */
|
|
|
+ export class GeometryBufferSceneComponent implements ISceneComponent {
|
|
|
+ /**
|
|
|
+ * The component name helpfull to identify the component in the list of scene components.
|
|
|
+ */
|
|
|
+ public readonly name = SceneComponentConstants.NAME_GEOMETRYBUFFER;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The scene the component belongs to.
|
|
|
+ */
|
|
|
+ public scene: Scene;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creates a new instance of the component for the given scene
|
|
|
+ * @param scene Defines the scene to register the component in
|
|
|
+ */
|
|
|
+ constructor(scene: Scene) {
|
|
|
+ this.scene = scene;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Registers the component in a given scene
|
|
|
+ */
|
|
|
+ public register(): void {
|
|
|
+ this.scene._gatherRenderTargetsStage.registerStep(SceneComponentConstants.STEP_GATHERRENDERTARGETS_GEOMETRYBUFFER, this, this._gatherRenderTargets);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Rebuilds the elements related to this component in case of
|
|
|
+ * context lost for instance.
|
|
|
+ */
|
|
|
+ public rebuild(): void {
|
|
|
+ // Nothing to do for this component
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Disposes the component and the associated ressources
|
|
|
+ */
|
|
|
+ public dispose(): void {
|
|
|
+ // Nothing to do for this component
|
|
|
+ }
|
|
|
+
|
|
|
+ private _gatherRenderTargets(renderTargets: SmartArrayNoDuplicate<RenderTargetTexture>): void {
|
|
|
+ if (this.scene._geometryBufferRenderer) {
|
|
|
+ renderTargets.push(this.scene._geometryBufferRenderer.getGBuffer());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|