Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .ai/memory/architecture/activex.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ The control exposes a deliberately small v6 automation API. It does not expose
the broad MapWinGIS 5 map, layer, shape, event, or editing surface. The current
render scene is built in source coordinates, without reprojection; backend
support differs: GDI draws the original rings with an alternate fill rule,
while OpenGL fills the Core-prepared triangulated meshes and declines scenes
whose polygons lack a usable mesh so the coordinator falls back to GDI.
while OpenGL fill draws require explicitly prepared meshes. Normal Core scene
creation is mesh-free; fill operations without usable meshes fall back to
GDI, which fills the original rings. The OpenGL renderer also has an
outline mode that draws those rings without triangulation.
Consult the current implementation and architecture documentation before
assuming a capability or compatibility guarantee.

Expand Down
5 changes: 4 additions & 1 deletion .github/plans/Vector-Rendering-Performance-Improvement.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ Copilot: Update this checklist as each phase is implemented. Only mark a phase c
- Measured the supplied 10.3 MB, 2,459-feature shapefile with all A-D configurations; results are recorded in the Phase 1 benchmark section below.
- Limitation: the measured shapefile is not stored in the repository; `MWG_RENDERING_BASELINE_DATASET` can rerun it when available.
- Limitation: configuration C records the current OpenGL rejection because outline-only OpenGL rendering is a Phase 2 change.
- [ ] **Phase 2 – Separate geometry loading from rendering preparation** (PR 2)
- [x] **Phase 2 – Separate geometry loading from rendering preparation** (PR 2)
- Normal scene construction now preserves source rings and bounds without triangulating polygons; fill meshes remain available through explicit preparation.
- GDI fills directly from source rings, and OpenGL can draw mesh-free polygon outlines while fill requests retain the existing mesh requirement and GDI fallback.
- Limitation: OpenGL fill meshes are prepared explicitly rather than generated lazily; lazy triangulation and cache reuse remain Phase 3 and Phase 4 work.
- [ ] **Phase 3 – Implement lazy polygon triangulation** (PR 3)
- [ ] **Phase 4 – Add intelligent caching and invalidation** (PR 4)
- [ ] **Phase 5 – Introduce viewport-aware geometry processing** (PR 5)
Expand Down
33 changes: 17 additions & 16 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,19 +323,20 @@ Rendering consumes backend-neutral input prepared from core data; neither the
coordinator nor a backend loads datasets or implements GIS rules. For each
visible map layer, Core sequentially reads Polygon, MultiPolygon,
CurvePolygon, and MultiSurface features into an owned vector scene,
linearizing curved geometries. Scene creation also triangulates every polygon
into an indexed, backend-neutral triangle mesh with the constrained Delaunay
triangulation of GDAL/OGR and GEOS, retained per polygon so a backend never
triangulates per frame; a polygon that cannot be triangulated keeps its rings
and has no mesh. `ViewTransform` captures the `Viewport` once
linearizing curved geometries. Scene creation preserves source rings and
rendering metadata without triangulating polygons. A caller can explicitly
request fill-mesh preparation when a fill operation needs indexed,
backend-neutral triangles; a polygon that cannot be triangulated keeps its
rings and has no mesh. `ViewTransform` captures the `Viewport` once
per frame so both backends transform every vertex of every layer with the
same arithmetic as `Viewport::MapToScreen`; GDI draws a screen position in
the pixel that contains it (`ToPixel`). One backend draws the whole frame.
The coordinator tries the OpenGL backend when every polygon of every layer
has a triangulated fill mesh. GDI checks each layer before drawing it; a
layer with non-finite or out-of-range device coordinates is skipped and
reported (`GetFailedLayers`, `RenderingStatus`) while the other layers are
still drawn.
has a triangulated fill mesh for a fill draw. OpenGL outline mode draws the
source rings without requiring fill meshes. GDI checks each layer before
drawing it; a layer with non-finite or out-of-range device coordinates is
skipped and reported (`GetFailedLayers`, `RenderingStatus`) while the other
layers are still drawn.
OpenGL uses a context created on a hidden, never-presented window, draws with
fixed-function calls into a framebuffer object (OpenGL 3.0 or
`GL_EXT_framebuffer_object`), and reads pixels back in BGRA order into a CPU
Expand All @@ -349,10 +350,10 @@ This avoids a fresh allocation for every polygon's transformed triangle vertices
Rendering into a framebuffer object avoids undefined pixels from window
pixel-ownership rules. Presentation still copies pixels through GDI.
Interior rings and concave boundaries draw identically in both backends
because both consume the same scene; a polygon without a fill mesh (for
example a self-intersecting ring that GEOS cannot triangulate), missing
framebuffer-object support, initialization failures, and drawing failures use
the GDI backend, which draws the original rings.
because both consume the same scene. A fill request without a usable mesh,
missing framebuffer-object support, initialization failures, and drawing
failures use the GDI backend. GDI fills and outlines the original rings, so
a self-intersecting ring that GEOS cannot triangulate can still be displayed.
The GDI backend draws the original rings of the whole supported polygon scene,
including its interior rings and concave boundaries. Both backends draw source coordinates without reprojection,
and scene preparation currently supports Polygon, MultiPolygon, CurvePolygon,
Expand Down Expand Up @@ -486,9 +487,9 @@ and `Ring` types remain available for caller-created triangulation input.
There is no tiling, paging, or clipping to the visible extent. GDI skips a
layer whose device coordinates exceed its range. It clips drawing to the
requested target rectangle and the host's existing clip region, then restores
the device context. Triangulation runs once per polygon when the scene is
prepared; view changes (resize, zoom, pan) and redraws reuse the retained
meshes. The opt-in
the device context. Fill triangulation runs only when scene preparation
explicitly requests it; view changes (resize, zoom, pan) and redraws reuse
the retained meshes. The opt-in
rendering baseline (see [TESTING.md](TESTING.md#rendering-performance-baseline))
tracks scene preparation, mesh storage, and backend frame costs on both a
convex grid and a complex mix of concave, holed multipart, and many-vertex
Expand Down
22 changes: 11 additions & 11 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,11 @@ The `RenderingBaseline` tests are opt-in. They use either a generated
GeoPackage grid of convex 32-vertex polygons or the dataset named by
`MWG_RENDERING_BASELINE_DATASET`. `MeasuresTriangulationDisabledCosts` builds a
mesh-free scene (configuration A for GDI, which still fills the original rings,
and configuration C for OpenGL, which rejects it).
`MeasuresCoreSceneAndBackendCosts` uses the default fill-mesh preparation
and configuration C for OpenGL outline-only rendering).
`MeasuresCoreSceneAndBackendCosts` explicitly requests fill-mesh preparation
(configurations B and D). Successful backends report first and steady frame
times, plus pan and zoom frames, for a 1280x720 off-screen target.
times, plus pan and zoom frames, for a 1280x720 off-screen target. Normal scene
creation does not perform triangulation.

Performance diagnostics are disabled by default and aggregate process-wide
timings with `std::chrono::steady_clock`. The collector records dataset
Expand All @@ -223,8 +224,8 @@ GPU buffer-upload stage to measure yet.
concave L-shaped polygons, holed rectangles where every feature is a
two-component multipolygon, and concave 32-vertex star polygons across three
layers — and additionally reports the number of triangulated polygons and the
mesh storage (vertices plus indices). Scene preparation in both tests
includes the one-time constrained Delaunay triangulation of every polygon.
mesh storage (vertices plus indices). Its scene preparation explicitly
requests the one-time constrained Delaunay triangulation of every polygon.
Results are recorded as GoogleTest properties; the tests fail only when a
stage fails. Use a Release build for meaningful numbers:

Expand Down Expand Up @@ -263,12 +264,11 @@ submission took 5.3 ms. These measurements show scene triangulation is the
dominant opening cost on the generated grid, without assuming it is the only
cost for other datasets.

Configuration C is intentionally reported as a rejection rather than a
successful outline render: the current OpenGL backend requires a triangle
mesh for every polygon. Measuring successful triangulation-free OpenGL
outlines is a Phase 2 deliverable. Viewport culling and its skipped-feature
counter remain zero because scene construction currently processes all
features.
Configuration C records the Phase 1 rejection because that baseline predates
the mesh-free OpenGL outline mode. The baseline test now exercises that
outline mode directly when OpenGL is available. Viewport culling and its
skipped-feature counter remain zero because scene construction currently
processes all features.

Previous measurements on one developer workstation, with triangulation
included in scene preparation, remain useful as history:
Expand Down
13 changes: 9 additions & 4 deletions src/MapWinGIS.ActiveX/GdiVectorLayerRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ namespace mwg::activex
const RECT& bounds,
const rendering::MapRenderScene& scene,
const Viewport& viewport,
const bool) noexcept
const bool,
const VectorRenderMode renderMode) noexcept
{
const diagnostics::PerformanceScope scope(
diagnostics::PerformanceOperation::FrameRender);
Expand Down Expand Up @@ -252,14 +253,18 @@ namespace mwg::activex
return S_OK;
}

const ScopedGdiObject brush(CreateSolidBrush(kFillColor));
const ScopedGdiObject fillBrush(
renderMode == VectorRenderMode::Fill ? CreateSolidBrush(kFillColor) : nullptr);
const HGDIOBJ brush = renderMode == VectorRenderMode::Fill
? fillBrush.Get()
: GetStockObject(NULL_BRUSH);
const ScopedGdiObject pen(CreatePen(PS_SOLID, 1, kOutlineColor));
if (brush.Get() == nullptr || pen.Get() == nullptr)
if (brush == nullptr || pen.Get() == nullptr)
{
return E_OUTOFMEMORY;
}

const ScopedSelection selectedBrush(deviceContext, brush.Get());
const ScopedSelection selectedBrush(deviceContext, brush);
const ScopedSelection selectedPen(deviceContext, pen.Get());
if (!selectedBrush.IsValid() || !selectedPen.IsValid() ||
SetPolyFillMode(deviceContext, ALTERNATE) == 0)
Expand Down
3 changes: 2 additions & 1 deletion src/MapWinGIS.ActiveX/GdiVectorLayerRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ namespace mwg::activex
const RECT& bounds,
const rendering::MapRenderScene& scene,
const Viewport& viewport,
bool retainStagingBuffer = true) noexcept override;
bool retainStagingBuffer = true,
VectorRenderMode renderMode = VectorRenderMode::Fill) noexcept override;

/// Layers skipped by the last Draw call, in drawing order.
[[nodiscard]] const std::vector<LayerId>& GetFailedLayers() const noexcept
Expand Down
Loading