Skip to content

[Refactor] Shared per-mesh vertex-stream binding helpers - #1130

Merged
untoldengine merged 2 commits into
untoldengine:developfrom
miolabs:feature/vertex_stream_binding
Aug 6, 2026
Merged

[Refactor] Shared per-mesh vertex-stream binding helpers#1130
untoldengine merged 2 commits into
untoldengine:developfrom
miolabs:feature/vertex_stream_binding

Conversation

@miogds

@miogds miogds commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

What

  • Adds bindModelVertexStreams / bindShadowVertexStreams encoder helpers (Renderer/RenderVertexStreamBinding.swift) and replaces the nine open-coded per-mesh vertex-buffer bind sites across the model, shadow (CSM/spot/point), transparency, and wireframe passes plus RenderExtensionModelSurface. Batched-geometry sites keep their raw batch-buffer binds.
  • Adds testUnknownCoreChunkTypeIsIgnored to NativeFormatTests: a core-range chunk type unknown to the runtime must not prevent the rest of a .untold asset from loading, locking in forward compatibility for future format chunks.

Why

Every pass that draws meshes repeats the same six setVertexBuffer calls plus the hasArmature/joint-matrix pair; the copies have already drifted stylistically and are easy to miss when the mesh streams evolve. Consolidating them into one helper makes future vertex-stream changes (e.g. GPU vertex deformation ahead of the shadow pass) a single-point edit. Zero behavior change intended.

Notes for reviewers

  • The shadow-pass sites index the source metalKitMesh.vertexBuffers array with modelPass* enums while binding to shadowPass* slots — that was correct (the array is laid out in model-descriptor order); the helper now encodes the source-vs-destination distinction explicitly.
  • hasArmature uses getEntityComponent (exists-guarded) instead of raw scene.get; equivalent on all current call paths.

Verification

  • swift build and the unit test target pass locally.
  • The animation keyframe render test's five skinned-pose images were compared pixel-by-pixel against a clean develop baseline run: bit-identical.
  • SwiftFormat 0.60.1 lint clean on changed files.

Replace the nine open-coded per-mesh vertex buffer bind sites in the
model-family and shadow-family passes with bindModelVertexStreams /
bindShadowVertexStreams encoder helpers. Batched-geometry sites keep
their raw batch-buffer binds.

Also add a reader regression test covering unknown core-range chunk
types so future format chunks cannot brick older runtimes.

Groundwork for the deformation compute pass: the helpers are the single
point where deformed position/normal buffers will replace the base
streams.
@miogds
miogds requested a review from untoldengine as a code owner August 4, 2026 15:41
//
// Shared per-mesh vertex-stream binding for the model-family and shadow-family
// render passes.
//

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit picking here.
Can you add the proper license header:

//
// RenderVertexStreamBinding.swift
// UntoldEngine
//
// Copyright (C) Untold Engine Studios
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of course!

@untoldengine
untoldengine merged commit b3149b1 into untoldengine:develop Aug 6, 2026
6 of 7 checks passed
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.

2 participants