ClearCommand.js 2.8 KB

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