nuget server logo nuget api documents
↑

API Docs / Microsoft.VisualBasic.Drawing.DirectX / DxPolygonBatch

DxPolygonBatch

Full name Microsoft.VisualBasic.Drawing.DirectX.DxPolygonBatch Assembly Microsoft.VisualBasic.Drawing.DirectX Members 9

The polygon batch submitter.

00 Remarks

Submitting one draw call per polygon primitive is the main bottleneck of a large polygon scene: every FillGeometry / DrawGeometry call goes through a com interop boundary and forces direct2d to build a new geometry object.

This batch submitter appends every polygon of the same brush as an independent figure of one single ID2D1PathGeometry object, and then all of the accumulated polygons are rasterized by the gpu device through just one draw call, so the per primitive overhead is reduced from O(n) to O(n / batch_size).

The vertex buffer of the figure is written into a pinned scratch buffer that is owned by this submitter, so that no managed array has to be allocated and marshalled for each polygon primitive.

The fill mode of the batch geometry is D2D1_FILL_MODE_WINDING, so that the overlapped area of two polygons is still filled, which keeps the same visual result as drawing the polygons one by one.

01 Syntax

Microsoft.VisualBasic.Drawing.DirectX.DxPolygonBatch

02 Methods

NameOverloadsSummary
AddPolygon 1 append a closed polygon primitive into the current batch
Flush 1 submit all of the accumulated polygon primitives to the gpu device
Discard 1 drop the accumulated polygon primitives without submitting them

03 Properties

NameOverloadsSummary
PendingFigures 1 the amount of the polygon primitives that are accumulated in the current batch
CurrentKey 1 the brush key of the current pending batch, -1 means nothing pending
CurrentIsStroke 1 is the pending batch a stroke batch?

04 Fields

NameOverloadsSummary
MAX_FIGURES 1 flush the geometry after this amount of figures so that the memory cost of a single batch is bounded.
MAX_SCRATCH_POINTS 1 the vertex capacity of the pinned scratch buffer
scratch 1 a pinned managed vertex buffer, it is reused by every polygon so that no per primitive allocation is required

05 Members

method AddPolygon #
AddPolygon(PointF(), Boolean, Int32, ID2D1Brush, Single, ID2D1StrokeStyle)

append a closed polygon primitive into the current batch

Parameters
NameTypeDescription
pointsPointF()

the vertex buffer of the polygon

strokeBoolean

true for a stroke (outline) drawing and false for a fill drawing

keyInt32

the brush cache key, a new batch is required when the key is changed

method Flush #
Flush

submit all of the accumulated polygon primitives to the gpu device

method Discard #
Discard

drop the accumulated polygon primitives without submitting them

Remarks

This is required when the render target that owns the pending geometry is not usable any more (a removed gpu device for example): the pending figures can not be rasterized any more, so they are released directly instead of being drawn.

property PendingFigures #
PendingFigures

the amount of the polygon primitives that are accumulated in the current batch

property CurrentKey #
CurrentKey

the brush key of the current pending batch, -1 means nothing pending

property CurrentIsStroke #
CurrentIsStroke

is the pending batch a stroke batch?

field MAX_FIGURES #
MAX_FIGURES

flush the geometry after this amount of figures so that the memory cost of a single batch is bounded.

field MAX_SCRATCH_POINTS #
MAX_SCRATCH_POINTS

the vertex capacity of the pinned scratch buffer

field scratch #
scratch

a pinned managed vertex buffer, it is reused by every polygon so that no per primitive allocation is required