Files
cgal/Basic_viewer
Sebastien Loriot d58db8de40 Basic_viewer: fix wrong edge width and vertex size in line-width shader (#9335)
Fix three bugs in the line-width rendering path that caused edges to
appear at incorrect widths and made the `size_edges()` /
`size_vertices()` API behave incorrectly or have no effect in certain
modes.

---

### Bug 1 — Quadratic dependence on `u_PointSize` in
`GEOMETRY_SOURCE_LINE_WIDTH`

The perpendicular offset vector was computed as:
```glsl
vec2 n0 = vec2(-v0.y, v0.x) * u_PointSize * 0.5;
```
and then scaled by `gs_in[i].pointSize = u_PointSize /
effectiveDistance`, making the actual half-width proportional to
`u_PointSize²`. For scenes with large bounding-box diagonals this
produced edges far wider than intended, and `size_edges()` had a
super-linear effect.

**Fix:** remove `u_PointSize` from `n0` so the half-width is linear:
`u_PointSize / (2 * effectiveDistance)`.

---

### Bug 2 — Orthographic mode always produced width 1.0

In `VERTEX_SOURCE_LINE_WIDTH`, the orthographic branch set `distance =
u_PointSize`, so `pointSize = u_PointSize / u_PointSize = 1.0`. The
user-specified size was silently ignored in every 2D viewer.

**Fix:** use `distance = 1.0` so `pointSize = u_PointSize` passes
through directly as a screen-pixel width.

---

### Bug 3 — Baked-in viewport dimensions

The `u_Viewport` uniform was always uploaded as the initial window size
`{500, 450}`:
```cpp
QVector2D viewport = { CGAL_BASIC_VIEWER_INIT_SIZE_X, CGAL_BASIC_VIEWER_INIT_SIZE_Y };
```
After any window resize the NDC↔pixel conversions inside the geometry
shader used stale dimensions, producing incorrect edge geometry.

**Fix:** use `this->width()` / `this->height()` on every frame.

---

### Files changed
- `Basic_viewer/include/CGAL/Basic_shaders.h` —
`VERTEX_SOURCE_LINE_WIDTH`, `GEOMETRY_SOURCE_LINE_WIDTH`
- `Basic_viewer/include/CGAL/Qt/Basic_viewer.h` — viewport uniform in
the edge-drawing renderer

Fixes #9327
2026-06-04 18:21:39 +02:00
..