geometryBufferRendererSceneComponent.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { Scene } from "../scene.js";
  2. import { SceneComponentConstants } from "../sceneComponent.js";
  3. import { GeometryBufferRenderer } from "./geometryBufferRenderer.js";
  4. Object.defineProperty(Scene.prototype, "geometryBufferRenderer", {
  5. get: function () {
  6. return this._geometryBufferRenderer;
  7. },
  8. set: function (value) {
  9. if (value && value.isSupported) {
  10. this._geometryBufferRenderer = value;
  11. }
  12. },
  13. enumerable: true,
  14. configurable: true,
  15. });
  16. Scene.prototype.enableGeometryBufferRenderer = function (ratio = 1, depthFormat = 15, textureTypesAndFormats) {
  17. if (this._geometryBufferRenderer) {
  18. return this._geometryBufferRenderer;
  19. }
  20. this._geometryBufferRenderer = new GeometryBufferRenderer(this, ratio, depthFormat, textureTypesAndFormats);
  21. if (!this._geometryBufferRenderer.isSupported) {
  22. this._geometryBufferRenderer = null;
  23. }
  24. return this._geometryBufferRenderer;
  25. };
  26. Scene.prototype.disableGeometryBufferRenderer = function () {
  27. if (!this._geometryBufferRenderer) {
  28. return;
  29. }
  30. this._geometryBufferRenderer.dispose();
  31. this._geometryBufferRenderer = null;
  32. };
  33. /**
  34. * Defines the Geometry Buffer scene component responsible to manage a G-Buffer useful
  35. * in several rendering techniques.
  36. */
  37. export class GeometryBufferRendererSceneComponent {
  38. /**
  39. * Creates a new instance of the component for the given scene
  40. * @param scene Defines the scene to register the component in
  41. */
  42. constructor(scene) {
  43. /**
  44. * The component name helpful to identify the component in the list of scene components.
  45. */
  46. this.name = SceneComponentConstants.NAME_GEOMETRYBUFFERRENDERER;
  47. this.scene = scene;
  48. }
  49. /**
  50. * Registers the component in a given scene
  51. */
  52. register() {
  53. this.scene._gatherRenderTargetsStage.registerStep(SceneComponentConstants.STEP_GATHERRENDERTARGETS_GEOMETRYBUFFERRENDERER, this, this._gatherRenderTargets);
  54. }
  55. /**
  56. * Rebuilds the elements related to this component in case of
  57. * context lost for instance.
  58. */
  59. rebuild() {
  60. // Nothing to do for this component
  61. }
  62. /**
  63. * Disposes the component and the associated resources
  64. */
  65. dispose() {
  66. // Nothing to do for this component
  67. }
  68. _gatherRenderTargets(renderTargets) {
  69. if (this.scene._geometryBufferRenderer) {
  70. renderTargets.push(this.scene._geometryBufferRenderer.getGBuffer());
  71. }
  72. }
  73. }
  74. GeometryBufferRenderer._SceneComponentInitialization = (scene) => {
  75. // Register the G Buffer component to the scene.
  76. let component = scene._getComponent(SceneComponentConstants.NAME_GEOMETRYBUFFERRENDERER);
  77. if (!component) {
  78. component = new GeometryBufferRendererSceneComponent(scene);
  79. scene._addComponent(component);
  80. }
  81. };
  82. //# sourceMappingURL=geometryBufferRendererSceneComponent.js.map