Skip to content

quads chunk 2: GPU upload n-gon triangulation - #328

Closed
fernandotonon wants to merge 2 commits into
feat/quads-1-foundationfrom
feat/quads-2-gpu-upload
Closed

quads chunk 2: GPU upload n-gon triangulation#328
fernandotonon wants to merge 2 commits into
feat/quads-1-foundationfrom
feat/quads-2-gpu-upload

Conversation

@fernandotonon

Copy link
Copy Markdown
Owner

Summary

Chunk 2 of the quad migration (#326). Builds on chunk 1 (#327). Wires the EditableSubMesh::faces field through the GPU upload path so quad-bearing meshes render correctly via fan-triangulation. No behavior change for triangle-only meshes — same paths, byte-identical output.

Changes

  • buildSubMeshBuffers (the GPU upload used by resizeEntityBuffers + createNewMesh) defensively re-triangulates faces into triangles when faces is non-empty, so the GPU buffer is always consistent with the live face data.
  • recalculateNormals / recalculateNormalsFlat re-sync triangles from faces before accumulating, so vertex normals reflect current polygon geometry.
  • New EditableMesh::syncTriangulation() for callers that mutate faces directly.
  • New EditableMesh::totalFaceCount() reporting n-gon count when present, triangle count for legacy submeshes.

Tests (+5 standalone)

  • syncTriangulation fan-triangulates a quad → 2 tris.
  • syncTriangulation is a no-op on triangle-only submeshes.
  • totalFaceCount semantics for legacy and n-gon submeshes.
  • recalculateNormals re-syncs from faces and produces correct +Z normals on a planar quad.

Test plan

  • 191 standalone tests green (was 173 + 18 = wait, was 173 → now 191; +5 from chunk 2 + the +13 from chunk 1).
  • App builds clean.
  • CI on Linux/macOS/Windows.

Targeting feat/quads-1-foundation

Stacked on chunk 1 (#327). When chunk 1 merges into feat/quads, this PR's base will auto-update to feat/quads.

Towards #326.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c792a618-7d1c-4ade-99e7-c2c8fe6c26d1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/quads-2-gpu-upload

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

fernandotonon added a commit that referenced this pull request Apr 28, 2026
Chunk 2 (#328) targets feat/quads-1-foundation (chunk 1) so the diff
shows just chunk 2's own work rather than stacking onto the previous
chunk's noise. That bypasses the workflow's branch trigger because the
previous list only allowed `master` and `feat/quads`. Add the
`feat/quads-*` glob to cover stacked chunk PRs.

Towards #326.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@fernandotonon
fernandotonon force-pushed the feat/quads-1-foundation branch from ff5cc8f to ba49a76 Compare April 28, 2026 06:48
Wires the EditableSubMesh::faces (n-gon canonical) field through the
GPU upload path so quad-bearing meshes render correctly via fan-
triangulation. Triangle-only meshes are byte-identical before/after.

Changes:
  - buildSubMeshBuffers (the GPU upload entry point used by
    resizeEntityBuffers and createNewMesh) re-triangulates faces into
    triangles defensively when faces is non-empty, so the index buffer
    always matches the live face data even if the caller forgot to
    sync. Triangle-only submeshes pay zero overhead — no copy, no
    extra work.
  - recalculateNormals / recalculateNormalsFlat call triangulateFaces
    first when faces is canonical, so vertex normals always reflect
    the current polygon geometry.
  - New EditableMesh::syncTriangulation() helper for callers that
    mutate faces directly and want to publish the change to triangles.
  - New EditableMesh::totalFaceCount() for the n-gon-aware caller —
    reports faces.size() when n-gons are present, falls back to
    triangles.size() for legacy submeshes.

Tests (+5):
  - syncTriangulation fan-triangulates a quad face into 2 triangles.
  - syncTriangulation is a no-op on triangle-only submeshes.
  - totalFaceCount falls back to triangle count for legacy submeshes
    and reports n-gon count when faces is canonical.
  - recalculateNormals re-syncs triangles from faces and produces
    correct vertex normals on a quad-only mesh.

No behavior change for triangle-only meshes — chunk 1 + chunk 2 keep
the existing path byte-identical. Quad meshes can now render correctly
end-to-end (limited by importers, which still triangulate at load —
that's chunk 3).

Towards #326.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@fernandotonon
fernandotonon force-pushed the feat/quads-2-gpu-upload branch from 7c6a063 to e28245d Compare April 28, 2026 06:48
- src/EditableMesh.cpp:355,433: explicit `static_cast<uint32_t>` for
  `size_t` → Ogre's `vertexCount` / `indexCount` (uint32). The
  conversion was implicit pre-existing, but Sonar treats my edits to
  those lines as new and flags the precision-loss warning.
- src/EditableMesh.h: convert the new `totalFaceCount()` and
  `syncTriangulation()` from member methods to free functions taking
  `std::vector<EditableSubMesh>&`. The class hit Sonar's 35-method
  ceiling; free functions are the natural pattern here anyway since
  they mirror the existing `triangulateFaces(EditableSubMesh&)` and
  `promoteTrianglesToFaces(EditableSubMesh&)` helpers.
- Tests updated to call the free-function versions.

No behavior change; same 191 tests still pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant