DrawCommand.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*global define*/
  2. define([
  3. '../Core/defaultValue',
  4. '../Core/PrimitiveType'
  5. ], function(
  6. defaultValue,
  7. PrimitiveType) {
  8. "use strict";
  9. /**
  10. * Represents a command to the renderer for drawing.
  11. *
  12. * @private
  13. */
  14. var DrawCommand = function(options) {
  15. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  16. /**
  17. * The bounding volume of the geometry in world space. This is used for culling and frustum selection.
  18. * <p>
  19. * For best rendering performance, use the tightest possible bounding volume. Although
  20. * <code>undefined</code> is allowed, always try to provide a bounding volume to
  21. * allow the tightest possible near and far planes to be computed for the scene, and
  22. * minimize the number of frustums needed.
  23. * </p>
  24. *
  25. * @type {Object}
  26. * @default undefined
  27. *
  28. * @see DrawCommand#debugShowBoundingVolume
  29. */
  30. this.boundingVolume = options.boundingVolume;
  31. /**
  32. * When <code>true</code>, the renderer frustum and horizon culls the command based on its {@link DrawCommand#boundingVolume}.
  33. * If the command was already culled, set this to <code>false</code> for a performance improvement.
  34. *
  35. * @type {Boolean}
  36. * @default true
  37. */
  38. this.cull = defaultValue(options.cull, true);
  39. /**
  40. * The transformation from the geometry in model space to world space.
  41. * <p>
  42. * When <code>undefined</code>, the geometry is assumed to be defined in world space.
  43. * </p>
  44. *
  45. * @type {Matrix4}
  46. * @default undefined
  47. */
  48. this.modelMatrix = options.modelMatrix;
  49. /**
  50. * The type of geometry in the vertex array.
  51. *
  52. * @type {PrimitiveType}
  53. * @default PrimitiveType.TRIANGLES
  54. */
  55. this.primitiveType = defaultValue(options.primitiveType, PrimitiveType.TRIANGLES);
  56. /**
  57. * The vertex array.
  58. *
  59. * @type {VertexArray}
  60. * @default undefined
  61. */
  62. this.vertexArray = options.vertexArray;
  63. /**
  64. * The number of vertices to draw in the vertex array.
  65. *
  66. * @type {Number}
  67. * @default undefined
  68. */
  69. this.count = options.count;
  70. /**
  71. * The offset to start drawing in the vertex array.
  72. *
  73. * @type {Number}
  74. * @default 0
  75. */
  76. this.offset = defaultValue(options.offset, 0);
  77. /**
  78. * The shader program to apply.
  79. *
  80. * @type {ShaderProgram}
  81. * @default undefined
  82. */
  83. this.shaderProgram = options.shaderProgram;
  84. /**
  85. * An object with functions whose names match the uniforms in the shader program
  86. * and return values to set those uniforms.
  87. *
  88. * @type {Object}
  89. * @default undefined
  90. */
  91. this.uniformMap = options.uniformMap;
  92. /**
  93. * The render state.
  94. *
  95. * @type {RenderState}
  96. * @default undefined
  97. *
  98. * @see Context#createRenderState
  99. */
  100. this.renderState = options.renderState;
  101. /**
  102. * The framebuffer to draw to.
  103. *
  104. * @type {Framebuffer}
  105. * @default undefined
  106. */
  107. this.framebuffer = options.framebuffer;
  108. /**
  109. * The pass when to render.
  110. *
  111. * @type {Pass}
  112. * @default undefined
  113. */
  114. this.pass = options.pass;
  115. /**
  116. * Specifies if this command is only to be executed in the frustum closest
  117. * to the eye containing the bounding volume. Defaults to <code>false</code>.
  118. *
  119. * @type {Boolean}
  120. * @default false
  121. */
  122. this.executeInClosestFrustum = defaultValue(options.executeInClosestFrustum, false);
  123. /**
  124. * The object who created this command. This is useful for debugging command
  125. * execution; it allows us to see who created a command when we only have a
  126. * reference to the command, and can be used to selectively execute commands
  127. * with {@link Scene#debugCommandFilter}.
  128. *
  129. * @type {Object}
  130. * @default undefined
  131. *
  132. * @see Scene#debugCommandFilter
  133. */
  134. this.owner = options.owner;
  135. /**
  136. * This property is for debugging only; it is not for production use nor is it optimized.
  137. * <p>
  138. * Draws the {@link DrawCommand#boundingVolume} for this command, assuming it is a sphere, when the command executes.
  139. * </p>
  140. *
  141. * @type {Boolean}
  142. * @default false
  143. *
  144. * @see DrawCommand#boundingVolume
  145. */
  146. this.debugShowBoundingVolume = defaultValue(options.debugShowBoundingVolume, false);
  147. /**
  148. * Used to implement Scene.debugShowFrustums.
  149. * @private
  150. */
  151. this.debugOverlappingFrustums = 0;
  152. /**
  153. * @private
  154. */
  155. this.oit = undefined;
  156. };
  157. /**
  158. * Executes the draw command.
  159. *
  160. * @param {Context} context The renderer context in which to draw.
  161. * @param {PassState} [passState] The state for the current render pass.
  162. * @param {RenderState} [renderState] The render state that will override the render state of the command.
  163. * @param {ShaderProgram} [shaderProgram] The shader program that will override the shader program of the command.
  164. */
  165. DrawCommand.prototype.execute = function(context, passState, renderState, shaderProgram) {
  166. context.draw(this, passState, renderState, shaderProgram);
  167. };
  168. return DrawCommand;
  169. });