All files / engine/Source/Renderer ComputeCommand.js

100% Statements 14/14
75% Branches 3/4
100% Functions 2/2
100% Lines 14/14

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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120                    66x               66x               66x               66x                 66x               66x                 66x                 66x               66x                 66x               66x                         66x               1x 60x      
import Frozen from "../Core/Frozen.js";
import Pass from "./Pass.js";
 
/**
 * Represents a command to the renderer for GPU Compute (using old-school GPGPU).
 *
 * @private
 * @constructor
 */
function ComputeCommand(options) {
  options = options ?? Frozen.EMPTY_OBJECT;
 
  /**
   * The vertex array. If none is provided, a viewport quad will be used.
   *
   * @type {VertexArray}
   * @default undefined
   */
  this.vertexArray = options.vertexArray;
 
  /**
   * The fragment shader source. The default vertex shader is ViewportQuadVS.
   *
   * @type {ShaderSource}
   * @default undefined
   */
  this.fragmentShaderSource = options.fragmentShaderSource;
 
  /**
   * The shader program to apply.
   *
   * @type {ShaderProgram}
   * @default undefined
   */
  this.shaderProgram = options.shaderProgram;
 
  /**
   * An object with functions whose names match the uniforms in the shader program
   * and return values to set those uniforms.
   *
   * @type {object}
   * @default undefined
   */
  this.uniformMap = options.uniformMap;
 
  /**
   * Texture to use for offscreen rendering.
   *
   * @type {Texture}
   * @default undefined
   */
  this.outputTexture = options.outputTexture;
 
  /**
   * Function that is called immediately before the ComputeCommand is executed. Used to
   * update any renderer resources. Takes the ComputeCommand as its single argument.
   *
   * @type {Function}
   * @default undefined
   */
  this.preExecute = options.preExecute;
 
  /**
   * Function that is called after the ComputeCommand is executed. Takes the output
   * texture as its single argument.
   *
   * @type {Function}
   * @default undefined
   */
  this.postExecute = options.postExecute;
 
  /**
   * Function that is called when the command is canceled
   *
   * @type {Function}
   * @default undefined
   */
  this.canceled = options.canceled;
 
  /**
   * Whether the renderer resources will persist beyond this call. If not, they
   * will be destroyed after completion.
   *
   * @type {boolean}
   * @default false
   */
  this.persists = options.persists ?? false;
 
  /**
   * The pass when to render. Always compute pass.
   *
   * @type {Pass}
   * @default Pass.COMPUTE;
   */
  this.pass = Pass.COMPUTE;
 
  /**
   * The object who created this command.  This is useful for debugging command
   * execution; it allows us to see who created a command when we 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;
}
 
/**
 * Executes the compute command.
 *
 * @param {ComputeEngine} computeEngine The context that processes the compute command.
 */
ComputeCommand.prototype.execute = function (computeEngine) {
  computeEngine.execute(this);
};
export default ComputeCommand;