UNPKG

@itwin/core-frontend

Version:
70 lines 2.97 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module WebGL */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ViewRectUniforms = void 0; const core_geometry_1 = require("@itwin/core-geometry"); const Matrix_1 = require("./Matrix"); const Sync_1 = require("./Sync"); /** Maintains uniform variable state associated with a Target's ViewRect. * @internal */ class ViewRectUniforms { syncKey = 0; projectionMatrix = core_geometry_1.Matrix4d.createIdentity(); projectionMatrix32 = new Matrix_1.Matrix4(); _dimensions = [0, 0]; _inverseDimensions = [0, 0]; _viewportMatrix = new Matrix_1.Matrix4(); update(width, height) { if (width === this.width && height === this.height) return; (0, Sync_1.desync)(this); this._dimensions[0] = width; this._dimensions[1] = height; Matrix_1.Matrix4.fromOrtho(0.0, width, height, 0.0, -1.0, 1.0, this.projectionMatrix32); this.projectionMatrix32.toMatrix4d(this.projectionMatrix); this._inverseDimensions[0] = 1 / width; this._inverseDimensions[1] = 1 / height; const nearDepthRange = 0.0; const farDepthRange = 1.0; const x = 0; const y = 0; const halfWidth = width * 0.5; const halfHeight = height * 0.5; const halfDepth = (farDepthRange - nearDepthRange) * 0.5; const column0Row0 = halfWidth; const column1Row1 = halfHeight; const column2Row2 = halfDepth; const column3Row0 = x + halfWidth; const column3Row1 = y + halfHeight; const column3Row2 = nearDepthRange + halfDepth; const column3Row3 = 1.0; Matrix_1.Matrix4.fromValues(column0Row0, 0.0, 0.0, column3Row0, 0.0, column1Row1, 0.0, column3Row1, 0.0, 0.0, column2Row2, column3Row2, 0.0, 0.0, 0.0, column3Row3, this._viewportMatrix); } get width() { return this._dimensions[0]; } get height() { return this._dimensions[1]; } bindProjectionMatrix(uniform) { if (!(0, Sync_1.sync)(this, uniform)) uniform.setMatrix4(this.projectionMatrix32); } bindDimensions(uniform) { if (!(0, Sync_1.sync)(this, uniform)) uniform.setUniform2fv(this._dimensions); } bindInverseDimensions(uniform) { if (!(0, Sync_1.sync)(this, uniform)) uniform.setUniform2fv(this._inverseDimensions); } bindViewportMatrix(uniform) { if (!(0, Sync_1.sync)(this, uniform)) uniform.setMatrix4(this._viewportMatrix); } } exports.ViewRectUniforms = ViewRectUniforms; //# sourceMappingURL=ViewRectUniforms.js.map