@awayjs/renderer
Version:
Renderer for AwayJS
108 lines (107 loc) • 4.52 kB
JavaScript
import { __extends } from "tslib";
import { PassEvent } from '../events/PassEvent';
import { _Render_MaterialBase } from './_Render_MaterialBase';
/**
* _Render_MaterialPassBase provides an abstract base class for material shader passes. A material pass constitutes at least
* a render call per required renderable.
*/
var _Render_MaterialPassBase = /** @class */ (function (_super) {
__extends(_Render_MaterialPassBase, _super);
function _Render_MaterialPassBase() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(_Render_MaterialPassBase.prototype, "shader", {
get: function () {
return this._shader;
},
enumerable: false,
configurable: true
});
Object.defineProperty(_Render_MaterialPassBase.prototype, "numUsedStreams", {
get: function () {
return this._shader.numUsedStreams;
},
enumerable: false,
configurable: true
});
Object.defineProperty(_Render_MaterialPassBase.prototype, "numUsedTextures", {
get: function () {
return this._shader.numUsedTextures;
},
enumerable: false,
configurable: true
});
_Render_MaterialPassBase.prototype._includeDependencies = function (shader) {
shader.alphaThreshold = this._asset.alphaThreshold;
shader.useImageRect = this._asset.imageRect;
shader.usesCurves = this._asset.curves;
shader.useBothSides = this._asset.bothSides;
shader.usesUVTransform = this._asset.animateUVs;
shader.usesColorTransform = this._asset.useColorTransform;
};
/**
* Marks the shader program as invalid, so it will be recompiled before the next render.
*/
_Render_MaterialPassBase.prototype.invalidate = function () {
this._shader.invalidateProgram();
this.dispatchEvent(new PassEvent(PassEvent.INVALIDATE, this));
};
_Render_MaterialPassBase.prototype.dispose = function () {
if (this._shader) {
this._shader.dispose();
this._shader = null;
}
};
/**
* Renders the current pass. Before calling pass, activatePass needs to be called with the same index.
* @param pass The pass used to render the renderable.
* @param renderable The IRenderable object to draw.
* @param stage The Stage object used for rendering.
* @param entityCollector The EntityCollector object that contains the visible scene data.
* @param viewProjection The view-projection matrix used to project to the screen. This is not the same as
* camera.viewProjection as it includes the scaling factors when rendering to textures.
*
* @internal
*/
_Render_MaterialPassBase.prototype._setRenderState = function (renderState) {
this._shader._setRenderState(renderState);
};
/**
* Sets the render state for the pass that is independent of the rendered object. This needs to be called before
* calling pass. Before activating a pass, the previously used pass needs to be deactivated.
* @param stage The Stage object which is currently used for rendering.
* @param camera The camera from which the scene is viewed.
* @private
*/
_Render_MaterialPassBase.prototype._activate = function () {
this._shader._activate();
};
/**
* Clears the render state for the pass. This needs to be called before activating another pass.
* @param stage The Stage used for rendering
*
* @private
*/
_Render_MaterialPassBase.prototype._deactivate = function () {
this._shader._deactivate();
};
_Render_MaterialPassBase.prototype._initConstantData = function () {
};
_Render_MaterialPassBase.prototype._getVertexCode = function (registerCache, sharedRegisters) {
return '';
};
_Render_MaterialPassBase.prototype._getFragmentCode = function (registerCache, sharedRegisters) {
return '';
};
_Render_MaterialPassBase.prototype._getPostAnimationFragmentCode = function (registerCache, sharedRegisters) {
return '';
};
_Render_MaterialPassBase.prototype._getNormalVertexCode = function (registerCache, sharedRegisters) {
return '';
};
_Render_MaterialPassBase.prototype._getNormalFragmentCode = function (registerCache, sharedRegisters) {
return '';
};
return _Render_MaterialPassBase;
}(_Render_MaterialBase));
export { _Render_MaterialPassBase };