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
12 changes: 12 additions & 0 deletions .ai/memory/architecture/activex.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ while a changed scene for one layer invalidates only that entry. The coordinator
prunes removed IDs before every backend choice, and explicit layer or scene
invalidation releases the retained CPU mesh storage.

The screen OpenGL renderer also caches context-local vertex and index buffers
for immutable layer geometry when OpenGL 1.5 or
`GL_ARB_vertex_buffer_object` is available. Stored vertices are localized to
one origin for the layer, so pan and zoom change a model-view transform without
reuploading coordinates. Scene changes and explicit invalidation release the
affected buffers; the client-array path remains the fallback. Temporary
renderers share CPU fill meshes but own separate GPU buffers because buffer
names belong to their OpenGL contexts. A framebuffer readback remains required
for GDI presentation, but the bottom-up BGRA buffer can be passed to a
bottom-up DIB without a CPU row reversal. See
`OpenGlVectorLayerRenderer.cpp`.

Core objects are not thread-safe by default. The control serializes their use.
ActiveX-specific implementation units are also compiled into
`MapWinGIS.ActiveX.Impl.lib`, allowing native tests to exercise them without
Expand Down
8 changes: 6 additions & 2 deletions .github/plans/Vector-Rendering-Performance-Improvement.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ Copilot: Update this checklist as each phase is implemented. Only mark a phase c
- OpenGL lazy fill meshes are cached per stable layer ID and immutable scene identity, surviving viewport changes, layer reordering, temporary draws, visibility changes, and backend selection.
- Scene replacement, explicit per-layer invalidation, removed-layer pruning, and clear-all invalidation release only the affected generated mesh storage; retained mesh bytes are tracked for tests.
- Limitation: no cache-size limit or eviction policy was added because measurements did not establish that the additional complexity is justified.
- [ ] **Phase 5 – Introduce viewport-aware geometry processing** (PR 5)
- [ ] **Phase 6 – Optimize OpenGL rendering and data transfer** (PR 6)
- [x] **Phase 5 – Introduce viewport-aware geometry processing** (PR 5)
- [x] **Phase 6 – Optimize OpenGL rendering and data transfer** (PR 6)
- The screen OpenGL renderer caches immutable fill and outline geometry in vertex and index buffers per stable layer and scene, retaining a client-array fallback for systems without buffer objects.
- Viewport navigation reuses uploaded coordinates through a matrix transform; direct bottom-up DIB presentation removes the CPU row reversal, while the required `glReadPixels` transfer remains.
- On the generated 2,459-feature Release grid, steady, pan, and zoom frames measured 2.5 / 2.3 / 2.3 ms versus 2.7 / 2.6 / 2.6 ms before; eight readbacks measured 13.5 ms versus 18.3 ms. First-frame buffer and context setup remains noise-sensitive and did not improve.
- Limitation: the FBO-to-CPU readback remains required by the GDI presentation path, and temporary renderers own separate GPU buffers because OpenGL buffer names are context-local.
- [ ] **Phase 7 – Testing and regression prevention** (PR 7)

**Target branch:** `development`
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ datasets or triangulating polygons again. OpenGL generates missing fill
meshes on the first fill draw and caches them per stable map layer. Viewport
changes, backend selection, layer reordering, and temporary draws reuse valid
entries; changed or removed layers release or replace only their own meshes.
The screen OpenGL renderer uploads immutable fill and outline geometry to
reusable GPU buffers, then changes only its viewport transform on pan and zoom.
Systems without buffer-object support keep the client-array fallback.

## Build and test

Expand Down
31 changes: 21 additions & 10 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,19 +351,26 @@ 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
buffer before copying them to the host device context.
OpenGL uses a context created on a hidden, never-presented window. When OpenGL
buffer objects are available (OpenGL 1.5 or `GL_ARB_vertex_buffer_object`), it
uploads each layer's immutable, scene-localized fill and outline coordinates
once to a reusable vertex buffer and indices to an element buffer. Pan and zoom
change the fixed-function model-view transform without rebuilding the source
coordinates. The client-side transformed-array path remains as a compatibility
fallback. Drawing uses a framebuffer object (OpenGL 3.0 or
`GL_EXT_framebuffer_object`) and reads pixels back in bottom-up BGRA order into
a CPU buffer before copying them to the host device context.
BGRA stores blue, green, red, and alpha bytes in that order.
The screen renderer retains its staging allocation and GPU framebuffer.
Alternate-size draws use a temporary OpenGL renderer that releases both after
the draw and shares the screen renderer's lazy fill meshes, leaving the screen
resources unchanged.
A separate vertex buffer is reused across polygons within each layer.
This avoids a fresh allocation for every polygon's transformed triangle vertices.
CPU, framebuffer, and geometry-buffer resources unchanged. Temporary renderers
use their own context-local GPU geometry buffers because OpenGL buffer names are
not portable between contexts.
Rendering into a framebuffer object avoids undefined pixels from window
pixel-ownership rules. Presentation still copies pixels through GDI.
pixel-ownership rules. `SetDIBitsToDevice` consumes the bottom-up OpenGL scanlines
without a second CPU row-swap pass, so presentation still requires one readback
but not an additional full-frame copy.
Interior rings and concave boundaries draw identically in both backends
because both consume the same scene. A failed lazy triangulation, an unusable
explicitly prepared mesh, missing framebuffer-object support, initialization
Expand Down Expand Up @@ -498,7 +505,10 @@ OpenGL's lazily generated fill meshes have a second, backend-owned cache keyed
by stable `LayerId` and the immutable scene identity. Reordering, hiding,
redrawing, viewport changes, and backend selection retain valid entries.
Replacing one layer scene invalidates only that layer's entry; removed layers
and explicit invalidation release their generated mesh storage.
and explicit invalidation release their generated mesh storage. A parallel
context-owned GPU buffer cache uses the same layer and scene identity. Scene
replacement, context recreation, and coordinator invalidation release or queue
the affected vertex and index buffers; viewport changes do not.
When a driver cannot provide a fast extent, scene preparation computes bounds
during the geometry traversal. It caches those bounds on the vector layer,
so a later map fit does not scan the layer again.
Expand All @@ -524,7 +534,8 @@ 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
polygons. OpenGL fills every polygon from a supplied or lazily generated
triangle mesh and copies each frame through CPU memory. Its reusable CPU
triangle mesh and copies each frame through CPU memory because the ActiveX
offscreen-DIB composition contract still presents through GDI. Its reusable CPU
staging buffer is limited to 64 MiB per frame; target dimensions are also
limited by the detected framebuffer and viewport capabilities. GDI is the supported
Windows CPU fallback; Core has no independent platform-neutral renderer.
Expand Down
29 changes: 25 additions & 4 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ They cover whole-pixel cached pan draws, fractional and oversized offsets,
failed-resize cache invalidation and redraw notifications, and screen-buffer
preservation across scaled draws.
Renderer tests cover BGRA color and row order, temporary staging buffers,
and context-initialization retry delays and resize-triggered retries.
reused GPU geometry buffers across pan, zoom, and render-mode changes, and
context-initialization retry delays and resize-triggered retries.
Diagnostic conversion tests verify that malformed UTF-8 and embedded NULs
are replaced instead of rejecting a completed operation's result.
Its registered-control host test also sends a wheel zoom and captured drag to
Expand Down Expand Up @@ -218,9 +219,10 @@ opening, layer metadata, OGR feature reads, internal geometry conversion,
scene construction, GEOS validation, triangulation, OpenGL geometry
submission, complete backend rendering, and `glReadPixels`. It also records
feature/geometry counts, triangles, invalid and failed triangulations,
viewport skips, and scene-cache hits and misses. OpenGL currently submits
client-side transformed arrays with `glDrawElements`; there is no persistent
GPU buffer-upload stage to measure yet.
viewport skips, and scene-cache hits and misses. OpenGL records GPU-buffer
preparation and draw submission in the geometry-submission scope. On systems
with OpenGL 1.5 or the ARB buffer-object extension, unchanged source geometry
is uploaded once; other systems retain the client-array fallback.

`RenderingBaseline.MeasuresComplexPolygonCosts` generates a second dataset —
concave L-shaped polygons, holed rectangles where every feature is a
Expand Down Expand Up @@ -309,6 +311,25 @@ The pre-triangulation measurements are retained for comparison:
| OpenGL frame (median) | 10.0 ms | 82.3 ms | 80.5 ms |
| Private memory, total | 91.7 MiB | 167.4 MiB | 167.2 MiB |

Phase 6 was measured again on the same developer workstation against the
`development` commit immediately before this phase, using a Release build and
the generated 2,459-feature grid:

| OpenGL measurement | Before | Phase 6 |
|---|---:|---:|
| First frame (context + draw) | 158.8 ms | 161.3 ms |
| Steady frame (median) | 2.7 ms | 2.5 ms |
| Pan | 2.6 ms | 2.3 ms |
| Zoom | 2.6 ms | 2.3 ms |
| Eight framebuffer readbacks | 18.3 ms | 13.5 ms |

The first-frame timings are noise-sensitive and include one-time context and
buffer setup. The Phase 6 geometry-submission scope covers the initial GPU
upload plus eight draws, so it is not directly comparable with the old
per-frame transformed client-array submission total. The frame still requires
`glReadPixels` because the control presents through GDI; this phase removes the
extra CPU scanline reversal, not the required GPU-to-CPU transfer.

Scene preparation reads geometries sequentially through OGR and copies
their coordinates directly, avoiding indexed lookups, WKT serialization, and
reparsing. The 100k-feature measurement dropped from 15,225 ms to 91.5 ms on
Expand Down
Loading