Skip to content

Render: move the methods to a static vtable, call them through render_* helpers - #33

Merged
resetius merged 2 commits into
masterfrom
objmodel-render
Nov 7, 2026
Merged

resetius merged 2 commits into
masterfrom
objmodel-render

Conversation

@resetius

@resetius resetius commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

PRs 31–32 are merged; review only the last commit.

Part of the object model change from the tracker task: one vtbl pointer per object to a static const method table, like a C++ vptr.

What changed:

  • render/render.h: new struct RenderVtbl with the same 14 methods. struct Render now holds only const struct RenderVtbl* vtbl.
  • Call helpers (one-line macros) with the render_ prefix for every method: render_pipeline, render_buffer_manager, render_draw_begin, render_counter_submit and so on. render_free keeps the NULL check of the old rend_free.
  • The old wrapper functions rend_free, rend_tex_new and rend_char_new became these helpers, so render/render.c is empty and is removed (CMakeLists.txt and Makefile updated).
  • The constructors are renamed to the same prefix: rend_opengl_new → render_opengl_new, rend_vulkan_new → render_vulkan_new.
  • opengl/render.c and vulkan/render.c: one static const struct RenderVtbl render_vtbl before the constructor, with exactly the fields of the old base literal. The constructor sets r->base.vtbl = &render_vtbl.
  • Callers: 61 calls in main.c, font/font.c and the 10 models. No direct ->method( calls of Render are left.

Size of the struct Render part on 64-bit: 112 bytes before, 8 bytes after (one object per run, so this is about the style, not memory).

No behavior change.

Verification (macOS, AppleClang, CMake + Ninja):

  • Clean rebuild: no new warnings (the same 5 as on master: one in contrib/astc-codec, four from glslc).
  • ctest: 3/3 passed.
  • Vulkan demos with VK_LAYER_KHRONOS_validation (layer load confirmed with VK_LOADER_DEBUG=layer), 10 s each: particles3, mandelbrot, stl, 0 validation messages.
  • Local test build of main.c (not in this PR): at frame 30 it sends key presses and releases for LEFT, RIGHT, UP, DOWN, A, Z, TAB and two mouse moves through the normal GLFW callbacks, then leaves the main loop after 8 s, so all free functions run. Vulkan particles3, mandelbrot, stl, gltf, triangle, torus, mandelbulb, particles, particles2 and OpenGL mandelbrot, stl, torus, triangle, mandelbulb, particles2: all exit with code 0. The logs are the same as on master after removing timings, FPS and pointer values (same buffer allocations, same validation output). On master, stl, gltf and triangle already report leaked objects at vkDestroyDevice (one message each); nothing else is reported.

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Test Results

9 tests  ±0   9 ✅ ±0   0s ⏱️ ±0s
3 suites ±0   0 💤 ±0 
3 files   ±0   0 ❌ ±0 

Results for commit 00f27d8. ± Comparison against base commit 4a501de.

♻️ This comment has been updated with latest results.

@resetius

resetius commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Independent review of head 35fc2cb

Verdict: approve. One P3 (naming nit).

  • OpenGL and Vulkan render_vtbl have the same 14 members as the old base initializers (checked line by line: set_view_entity = set_window_ in Vulkan, pipeline = pipeline_builder_*, char_new, buffer_manager, tex_new, counter_*, screenshot, print_compute_stats). In Vulkan the vtbl pointer is now set later than the old struct copy, but after the only exit() path, so nothing observable changes.
  • render/render.c removed in CMakeLists.txt and Makefile; its three wrappers became macros. render_free keeps the old NULL check. All call sites in main.c, font, and all models converted; rend_opengl_new / rend_vulkan_new renamed to render_*_new. Macro args are r, render, t->r, app->r: no side effects.
  • P3: rend_vulkan_char_new (vulkan/char.c:40) and the static rend_char_new_ / rend_free_ in opengl/render.c keep the rend_ prefix. If the intent is "no rend_ left", rename them too; otherwise ignore.

Build: clean CMake+Ninja (Release, -Wall -Wextra) of this head on a fresh SSH clone with submodules: builds, 98 warnings, identical set to master (no new warnings); ctest 3/3 passed.

@resetius

resetius commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Review follow-up: renamed the remaining rend_ identifiers to render_ in 4552fd4

@resetius

resetius commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Restacked onto master eff69ca after PR 29

@resetius

resetius commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Restacked onto master b76fe0a after PR 30.

@resetius

resetius commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Restacked onto master a33ca6c after PR 31.

@resetius

resetius commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Restacked onto master 4a501de after PRs 31–32.

@resetius
resetius merged commit 02aa325 into master Nov 7, 2026
2 checks passed
@resetius
resetius deleted the objmodel-render branch November 7, 2026 16:32
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