All files / engine/Source/Renderer ClearCommand.js

100% Statements 11/11
100% Branches 2/2
100% Functions 2/2
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103                    10476x                 10476x                 10476x                 10476x                     10476x                 10476x                           10476x                 10476x                   1x               1x 38267x      
import Color from "../Core/Color.js";
import Frozen from "../Core/Frozen.js";
 
/**
 * Represents a command to the renderer for clearing a framebuffer.
 *
 * @private
 * @constructor
 */
function ClearCommand(options) {
  options = options ?? Frozen.EMPTY_OBJECT;
 
  /**
   * The value to clear the color buffer to.  When <code>undefined</code>, the color buffer is not cleared.
   *
   * @type {Color}
   *
   * @default undefined
   */
  this.color = options.color;
 
  /**
   * The value to clear the depth buffer to.  When <code>undefined</code>, the depth buffer is not cleared.
   *
   * @type {number}
   *
   * @default undefined
   */
  this.depth = options.depth;
 
  /**
   * The value to clear the stencil buffer to.  When <code>undefined</code>, the stencil buffer is not cleared.
   *
   * @type {number}
   *
   * @default undefined
   */
  this.stencil = options.stencil;
 
  /**
   * The render state to apply when executing the clear command.  The following states affect clearing:
   * scissor test, color mask, depth mask, and stencil mask.  When the render state is
   * <code>undefined</code>, the default render state is used.
   *
   * @type {RenderState}
   *
   * @default undefined
   */
  this.renderState = options.renderState;
 
  /**
   * The framebuffer to clear.
   *
   * @type {Framebuffer}
   *
   * @default undefined
   */
  this.framebuffer = options.framebuffer;
 
  /**
   * The object who created this command.  This is useful for debugging command
   * execution; it allows you to see who created a command when you only have a
   * reference to the command, and can be used to selectively execute commands
   * with {@link Scene#debugCommandFilter}.
   *
   * @type {object}
   *
   * @default undefined
   *
   * @see Scene#debugCommandFilter
   */
  this.owner = options.owner;
 
  /**
   * The pass in which to run this command.
   *
   * @type {Pass}
   *
   * @default undefined
   */
  this.pass = options.pass;
}
 
/**
 * Clears color to (0.0, 0.0, 0.0, 0.0); depth to 1.0; and stencil to 0.
 *
 * @type {ClearCommand}
 *
 * @constant
 */
ClearCommand.ALL = Object.freeze(
  new ClearCommand({
    color: new Color(0.0, 0.0, 0.0, 0.0),
    depth: 1.0,
    stencil: 0.0,
  }),
);
 
ClearCommand.prototype.execute = function (context, passState) {
  context.clear(this, passState);
};
export default ClearCommand;