123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- import BoundingRectangle from "../Core/BoundingRectangle.js";
- import Color from "../Core/Color.js";
- import defined from "../Core/defined.js";
- import destroyObject from "../Core/destroyObject.js";
- import DeveloperError from "../Core/DeveloperError.js";
- import Pass from "../Renderer/Pass.js";
- import RenderState from "../Renderer/RenderState.js";
- import ShaderSource from "../Renderer/ShaderSource.js";
- import ViewportQuadFS from "../Shaders/ViewportQuadFS.js";
- import BlendingState from "./BlendingState.js";
- import Material from "./Material.js";
- function ViewportQuad(rectangle, material) {
-
- this.show = true;
- if (!defined(rectangle)) {
- rectangle = new BoundingRectangle();
- }
-
- this.rectangle = BoundingRectangle.clone(rectangle);
- if (!defined(material)) {
- material = Material.fromType(Material.ColorType, {
- color: new Color(1.0, 1.0, 1.0, 1.0),
- });
- }
-
- this.material = material;
- this._material = undefined;
- this._overlayCommand = undefined;
- this._rs = undefined;
- }
- ViewportQuad.prototype.update = function (frameState) {
- if (!this.show) {
- return;
- }
-
- if (!defined(this.material)) {
- throw new DeveloperError("this.material must be defined.");
- }
- if (!defined(this.rectangle)) {
- throw new DeveloperError("this.rectangle must be defined.");
- }
-
- var rs = this._rs;
- if (!defined(rs) || !BoundingRectangle.equals(rs.viewport, this.rectangle)) {
- this._rs = RenderState.fromCache({
- blending: BlendingState.ALPHA_BLEND,
- viewport: this.rectangle,
- });
- }
- var pass = frameState.passes;
- if (pass.render) {
- var context = frameState.context;
- if (this._material !== this.material || !defined(this._overlayCommand)) {
-
- this._material = this.material;
- if (defined(this._overlayCommand)) {
- this._overlayCommand.shaderProgram.destroy();
- }
- var fs = new ShaderSource({
- sources: [this._material.shaderSource, ViewportQuadFS],
- });
- this._overlayCommand = context.createViewportQuadCommand(fs, {
- renderState: this._rs,
- uniformMap: this._material._uniforms,
- owner: this,
- });
- this._overlayCommand.pass = Pass.OVERLAY;
- }
- this._material.update(context);
- this._overlayCommand.uniformMap = this._material._uniforms;
- frameState.commandList.push(this._overlayCommand);
- }
- };
- ViewportQuad.prototype.isDestroyed = function () {
- return false;
- };
- ViewportQuad.prototype.destroy = function () {
- if (defined(this._overlayCommand)) {
- this._overlayCommand.shaderProgram =
- this._overlayCommand.shaderProgram &&
- this._overlayCommand.shaderProgram.destroy();
- }
- return destroyObject(this);
- };
- export default ViewportQuad;
|