@@ -302,22 +302,26 @@ base class RenderPass extends NativeFieldWrapperClass1 {
302302 /// pipeline's `VertexLayout` . The default of 0 matches the default
303303 /// layout declared by a shader bundle, which is what every single-buffer
304304 /// call site expects. To bind multiple structure-of-arrays vertex
305- /// buffers, call this method once per slot.
306- ///
307- /// The number of vertices to draw is passed separately, to [draw] .
305+ /// buffers, call this method once per slot. The [vertexCount] takes
306+ /// effect only when no index buffer is bound, and is read from the
307+ /// binding at slot 0, so values supplied at higher slots are ignored .
308308 ///
309309 /// Sparse bindings are not supported. Every slot in `[0, highestBound]`
310- /// must have been bound before [draw] or [drawIndexed] is called,
311- /// otherwise they throw a [StateError] naming the unbound slots. Slots
312- /// can be bound in any order.
310+ /// must have been bound before [draw] is called, otherwise [draw] throws
311+ /// a [StateError] naming the unbound slots. Slots can be bound in any
312+ /// order.
313313 ///
314314 /// [slot] must be in `[0, 16)` (Impeller's HAL caps vertex buffer
315315 /// bindings at 16). On the OpenGL ES backend, the per-pipeline limit on
316316 /// the *total attribute count* across all bound buffers is whatever the
317317 /// device reports for `GL_MAX_VERTEX_ATTRIBS` (minimum 8 on GL ES 2.0,
318318 /// minimum 16 on GL ES 3.0+), and is enforced by the driver rather than
319319 /// by this method.
320- void bindVertexBuffer (BufferView bufferView, {int slot = 0 }) {
320+ void bindVertexBuffer (
321+ BufferView bufferView,
322+ int vertexCount, {
323+ int slot = 0 ,
324+ }) {
321325 if (slot < 0 || slot >= _kMaxVertexBufferSlots) {
322326 throw RangeError .range (
323327 slot,
@@ -335,20 +339,22 @@ base class RenderPass extends NativeFieldWrapperClass1 {
335339 this ,
336340 bufferView.offsetInBytes,
337341 bufferView.lengthInBytes,
342+ vertexCount,
338343 slot,
339344 );
340345 }
341346
342- /// Binds [bufferView] as the index buffer.
343- ///
344- /// [indexType] is the width of each index. The number of indices to draw
345- /// is passed separately, to [drawIndexed] .
346- void bindIndexBuffer ( BufferView bufferView, IndexType indexType ) {
347+ void bindIndexBuffer (
348+ BufferView bufferView,
349+ IndexType indexType,
350+ int indexCount,
351+ ) {
347352 bufferView.buffer._bindAsIndexBuffer (
348353 this ,
349354 bufferView.offsetInBytes,
350355 bufferView.lengthInBytes,
351356 indexType,
357+ indexCount,
352358 );
353359 }
354360
@@ -499,29 +505,7 @@ base class RenderPass extends NativeFieldWrapperClass1 {
499505 _setWindingOrder (windingOrder.index);
500506 }
501507
502- /// Appends a non-indexed draw of [vertexCount] vertices, read from the
503- /// bound vertex buffers.
504- void draw (int vertexCount) {
505- RangeError .checkNotNegative (vertexCount, 'vertexCount' );
506- _validateVertexBindings ();
507- if (! _draw (vertexCount)) {
508- throw Exception ("Failed to append draw" );
509- }
510- }
511-
512- /// Appends an indexed draw of [indexCount] indices, read from the index
513- /// buffer bound with [bindIndexBuffer] .
514- void drawIndexed (int indexCount) {
515- RangeError .checkNotNegative (indexCount, 'indexCount' );
516- _validateVertexBindings ();
517- if (! _drawIndexed (indexCount)) {
518- throw Exception ("Failed to append drawIndexed" );
519- }
520- }
521-
522- /// Throws a [StateError] when the bound vertex buffer slots are sparse,
523- /// naming the slots in `[0, highestBound]` that were left unbound.
524- void _validateVertexBindings () {
508+ void draw () {
525509 if (_maxBoundVertexSlot >= 0 ) {
526510 final int expectedMask = (1 << (_maxBoundVertexSlot + 1 )) - 1 ;
527511 if (_boundVertexSlotsMask != expectedMask) {
@@ -530,12 +514,15 @@ base class RenderPass extends NativeFieldWrapperClass1 {
530514 if ((_boundVertexSlotsMask & (1 << i)) == 0 ) i,
531515 ];
532516 throw StateError (
533- 'draw called with sparse vertex buffer bindings: slot(s) '
517+ 'draw() called with sparse vertex buffer bindings: slot(s) '
534518 '${missing .join (', ' )} were not bound but slot $_maxBoundVertexSlot '
535519 'was. Bind every slot in [0, $_maxBoundVertexSlot ] before drawing.' ,
536520 );
537521 }
538522 }
523+ if (! _draw ()) {
524+ throw Exception ("Failed to append draw" );
525+ }
539526 }
540527
541528 /// Wrap with native counterpart.
@@ -604,24 +591,26 @@ base class RenderPass extends NativeFieldWrapperClass1 {
604591 )
605592 external void _bindPipeline (RenderPipeline pipeline);
606593
607- @Native < Void Function (Pointer <Void >, Pointer <Void >, Int , Int , Int )> (
594+ @Native < Void Function (Pointer <Void >, Pointer <Void >, Int , Int , Int , Int )> (
608595 symbol: 'InternalFlutterGpu_RenderPass_BindVertexBufferDevice' ,
609596 )
610597 external void _bindVertexBufferDevice (
611598 DeviceBuffer buffer,
612599 int offsetInBytes,
613600 int lengthInBytes,
601+ int vertexCount,
614602 int slot,
615603 );
616604
617- @Native < Void Function (Pointer <Void >, Pointer <Void >, Int , Int , Int )> (
605+ @Native < Void Function (Pointer <Void >, Pointer <Void >, Int , Int , Int , Int )> (
618606 symbol: 'InternalFlutterGpu_RenderPass_BindIndexBufferDevice' ,
619607 )
620608 external void _bindIndexBufferDevice (
621609 DeviceBuffer buffer,
622610 int offsetInBytes,
623611 int lengthInBytes,
624612 int indexType,
613+ int indexCount,
625614 );
626615
627616 @Native <
@@ -747,13 +736,8 @@ base class RenderPass extends NativeFieldWrapperClass1 {
747736 )
748737 external void _setPolygonMode (int polygonMode);
749738
750- @Native < Bool Function (Pointer <Void >, Int )> (
739+ @Native < Bool Function (Pointer <Void >)> (
751740 symbol: 'InternalFlutterGpu_RenderPass_Draw' ,
752741 )
753- external bool _draw (int vertexCount);
754-
755- @Native < Bool Function (Pointer <Void >, Int )> (
756- symbol: 'InternalFlutterGpu_RenderPass_DrawIndexed' ,
757- )
758- external bool _drawIndexed (int indexCount);
742+ external bool _draw ();
759743}
0 commit comments