UNPKG

@awayjs/renderer

Version:
132 lines (131 loc) 5 kB
import { __extends } from "tslib"; import { BitmapImage2D } from '@awayjs/stage'; import { PickGroup } from '@awayjs/view'; import { RenderGroup } from './RenderGroup'; import { DepthRenderer } from './DepthRenderer'; import { DistanceRenderer } from './DistanceRenderer'; import { RendererBase } from './RendererBase'; import { CacheRenderer } from './CacheRenderer'; /** * The DefaultRenderer class provides the default rendering method. It renders the scene graph objects using the * materials assigned to them. * * @class away.render.DefaultRenderer */ var DefaultRenderer = /** @class */ (function (_super) { __extends(DefaultRenderer, _super); /** * Creates a new DefaultRenderer object. */ function DefaultRenderer() { var _this = _super.call(this) || this; _this._traverserGroup = RenderGroup.getInstance(CacheRenderer); _this._maskGroup = RenderGroup.getInstance(DefaultRenderer); return _this; } Object.defineProperty(DefaultRenderer.prototype, "antiAlias", { get: function () { return this.stage.antiAlias; }, set: function (value) { this.stage.antiAlias = value; }, enumerable: false, configurable: true }); Object.defineProperty(DefaultRenderer.prototype, "depthPrepass", { /** * */ get: function () { return this._depthPrepass; }, set: function (value) { this._depthPrepass = value; }, enumerable: false, configurable: true }); DefaultRenderer.prototype.init = function (node, pool) { _super.prototype.init.call(this, node, pool); this._depthRenderer = RenderGroup .getInstance(DepthRenderer) .getRenderer(node); this._distanceRenderer = RenderGroup .getInstance(DistanceRenderer) .getRenderer(node); }; /** * */ DefaultRenderer.prototype.enterNode = function (node) { var enter = _super.prototype.enterNode.call(this, node); if (enter && node.boundsVisible) this.applyEntity(node.getBoundsPrimitive(PickGroup.getInstance())); return enter; }; DefaultRenderer.prototype.render = function (enableDepthAndStencil, surfaceSelector, mipmapSelector, maskConfig) { if (enableDepthAndStencil === void 0) { enableDepthAndStencil = true; } if (surfaceSelector === void 0) { surfaceSelector = 0; } if (mipmapSelector === void 0) { mipmapSelector = 0; } if (maskConfig === void 0) { maskConfig = 0; } if (!this.stage.recoverFromDisposal()) { //if context has Disposed by the OS,don't render at this frame return; } if (this._requireDepthRender) this._renderSceneDepthToTexture(); if (this._depthPrepass) this._renderDepthPrepass(); //this._view.target = null; _super.prototype.render.call(this, enableDepthAndStencil, surfaceSelector, mipmapSelector, maskConfig); if (!maskConfig) this.view.present(); }; DefaultRenderer.prototype.onClear = function (event) { _super.prototype.onClear.call(this, event); if (this._pRttBufferManager) { this._pRttBufferManager.dispose(); this._pRttBufferManager = null; } this._depthRenderer.onClear(event); this._distanceRenderer.onClear(event); this._depthRenderer = null; this._distanceRenderer = null; this._depthRender = null; }; /** * */ DefaultRenderer.prototype._renderDepthPrepass = function () { this._depthRenderer.disableColor = true; this._depthRenderer.view.projection = this.view.projection; this._depthRenderer.view.target = null; this._depthRenderer.render(); this._depthRenderer.disableColor = false; }; /** * */ DefaultRenderer.prototype._renderSceneDepthToTexture = function () { if (this._depthTextureDirty || !this._depthRender) this.initDepthTexture(this.stage.context); this._depthRenderer.render(); }; /** * */ DefaultRenderer.prototype.initDepthTexture = function (context) { this._depthTextureDirty = false; if (this._depthRender) this._depthRender.dispose(); this._depthRender = new BitmapImage2D(this._pRttBufferManager.textureWidth, this._pRttBufferManager.textureHeight); this._depthRenderer.view.target = this._depthRender; this._depthRenderer.view.projection = this.view.projection; }; DefaultRenderer.registerMaterial = function (renderMaterialClass, materialClass) { RenderGroup.getInstance(DefaultRenderer).registerMaterial(renderMaterialClass, materialClass); }; DefaultRenderer.assetType = '[renderer DefaultRenderer]'; return DefaultRenderer; }(RendererBase)); export { DefaultRenderer };