@@ -130,18 +130,22 @@ this.createjs = this.createjs||{};
130130 * for more information on texture purging.
131131 * @param {String|int } [options.clearColor=undefined] Automatically calls {{#crossLink "StageGL/setClearColor"}}{{/crossLink}}
132132 * after init is complete, can be overridden and changed manually later.
133+ * @param {String|int } [options.batchSize=DEFAULT_MAX_BATCH_SIZE] The size of the buffer used to retain a batch.
134+ * Making it smaller reduces GPU load, but making it too small adds extra GPU calls. Figure out your maximum batch
135+ * count and set it to a small buffer above that per-project. Check src/utils/WebGLInspector to track.
133136 */
134137 function StageGL ( canvas , options ) {
135138 this . Stage_constructor ( canvas ) ;
136139
137- var transparent , antialias , preserveBuffer , autoPurge , directDraw ;
140+ var transparent , antialias , preserveBuffer , autoPurge , directDraw , batchSize ;
138141 if ( options !== undefined ) {
139142 if ( typeof options !== "object" ) { throw ( "Invalid options object" ) ; }
140143 transparent = options . transparent ;
141144 antialias = options . antialias ;
142145 preserveBuffer = options . preserveBuffer ;
143146 autoPurge = options . autoPurge ;
144147 directDraw = options . directDraw ;
148+ batchSize = options . batchSize ;
145149 }
146150
147151// public properties:
@@ -269,14 +273,18 @@ this.createjs = this.createjs||{};
269273 this . _clearColor = { r : 0.50 , g : 0.50 , b : 0.50 , a : 0.00 } ;
270274
271275 /**
272- * The maximum number of cards (aka a single sprite) that can be drawn in one draw call. Use getter/setters to
273- * modify otherwise internal buffers may be incorrect sizes.
276+ * The maximum number of verticies (6 make a single sprite) that can be drawn in one draw call. Use constructor props
277+ * to modify otherwise internal buffers may be invalid sizes.
274278 * @property _maxBatchVertexCount
275279 * @protected
276280 * @type {Number }
277281 * @default StageGL.DEFAULT_MAX_BATCH_SIZE * StageGL.INDICIES_PER_CARD
278282 */
279- this . _maxBatchVertexCount = StageGL . DEFAULT_MAX_BATCH_SIZE * StageGL . INDICIES_PER_CARD ;
283+ this . _maxBatchVertexCount = Math . max (
284+ Math . min (
285+ Number ( batchSize ) || StageGL . DEFAULT_MAX_BATCH_SIZE ,
286+ StageGL . DEFAULT_MAX_BATCH_SIZE )
287+ , StageGL . DEFAULT_MIN_BATCH_SIZE ) * StageGL . INDICIES_PER_CARD ;
280288
281289 /**
282290 * The shader program used to draw the current batch.
@@ -705,15 +713,28 @@ this.createjs = this.createjs||{};
705713 /**
706714 * The default value for the maximum number of cards we want to process in a batch. See
707715 * {{#crossLink "StageGL/WEBGL_MAX_INDEX_NUM:property"}}{{/crossLink}} for a hard limit.
716+ * this value comes is designed to sneak under that limit.
708717 * @property DEFAULT_MAX_BATCH_SIZE
709718 * @static
710719 * @final
711720 * @type {Number }
712- * @default 10000
721+ * @default 10920
713722 * @readonly
714723 */
715724 StageGL . DEFAULT_MAX_BATCH_SIZE = 10920 ;
716725
726+ /**
727+ * The default value for the minimum number of cards we want to process in a batch. Less
728+ * max cards can mean better performance, but anything below this is probably not worth it.
729+ * @property DEFAULT_MIN_BATCH_SIZE
730+ * @static
731+ * @final
732+ * @type {Number }
733+ * @default 170
734+ * @readonly
735+ */
736+ StageGL . DEFAULT_MIN_BATCH_SIZE = 170 ;
737+
717738 /**
718739 * The maximum size WebGL allows for element index numbers. Uses a 16 bit unsigned integer. It takes 6 indices to
719740 * make a unique card.
0 commit comments