ComputeCommand.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import defaultValue from "../Core/defaultValue.js";
  2. import Pass from "./Pass.js";
  3. /**
  4. * Represents a command to the renderer for GPU Compute (using old-school GPGPU).
  5. *
  6. * @private
  7. * @constructor
  8. */
  9. function ComputeCommand(options) {
  10. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  11. /**
  12. * The vertex array. If none is provided, a viewport quad will be used.
  13. *
  14. * @type {VertexArray}
  15. * @default undefined
  16. */
  17. this.vertexArray = options.vertexArray;
  18. /**
  19. * The fragment shader source. The default vertex shader is ViewportQuadVS.
  20. *
  21. * @type {ShaderSource}
  22. * @default undefined
  23. */
  24. this.fragmentShaderSource = options.fragmentShaderSource;
  25. /**
  26. * The shader program to apply.
  27. *
  28. * @type {ShaderProgram}
  29. * @default undefined
  30. */
  31. this.shaderProgram = options.shaderProgram;
  32. /**
  33. * An object with functions whose names match the uniforms in the shader program
  34. * and return values to set those uniforms.
  35. *
  36. * @type {Object}
  37. * @default undefined
  38. */
  39. this.uniformMap = options.uniformMap;
  40. /**
  41. * Texture to use for offscreen rendering.
  42. *
  43. * @type {Texture}
  44. * @default undefined
  45. */
  46. this.outputTexture = options.outputTexture;
  47. /**
  48. * Function that is called immediately before the ComputeCommand is executed. Used to
  49. * update any renderer resources. Takes the ComputeCommand as its single argument.
  50. *
  51. * @type {Function}
  52. * @default undefined
  53. */
  54. this.preExecute = options.preExecute;
  55. /**
  56. * Function that is called after the ComputeCommand is executed. Takes the output
  57. * texture as its single argument.
  58. *
  59. * @type {Function}
  60. * @default undefined
  61. */
  62. this.postExecute = options.postExecute;
  63. /**
  64. * Function that is called when the command is canceled
  65. *
  66. * @type {Function}
  67. * @default undefined
  68. */
  69. this.canceled = options.canceled;
  70. /**
  71. * Whether the renderer resources will persist beyond this call. If not, they
  72. * will be destroyed after completion.
  73. *
  74. * @type {Boolean}
  75. * @default false
  76. */
  77. this.persists = defaultValue(options.persists, false);
  78. /**
  79. * The pass when to render. Always compute pass.
  80. *
  81. * @type {Pass}
  82. * @default Pass.COMPUTE;
  83. */
  84. this.pass = Pass.COMPUTE;
  85. /**
  86. * The object who created this command. This is useful for debugging command
  87. * execution; it allows us to see who created a command when we only have a
  88. * reference to the command, and can be used to selectively execute commands
  89. * with {@link Scene#debugCommandFilter}.
  90. *
  91. * @type {Object}
  92. * @default undefined
  93. *
  94. * @see Scene#debugCommandFilter
  95. */
  96. this.owner = options.owner;
  97. }
  98. /**
  99. * Executes the compute command.
  100. *
  101. * @param {ComputeEngine} computeEngine The context that processes the compute command.
  102. */
  103. ComputeCommand.prototype.execute = function (computeEngine) {
  104. computeEngine.execute(this);
  105. };
  106. export default ComputeCommand;