ComputeCommand.js 3.2 KB

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