ClearCommand.js 2.3 KB

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