Skip to content

render: extract object creation into ruis::render::factory (issue #190) - #192

Merged
igagis merged 11 commits into
mainfrom
ren_factory
Nov 19, 2026
Merged

igagis merged 11 commits into
mainfrom
ren_factory

Conversation

@igagis

@igagis igagis commented Nov 19, 2026

Copy link
Copy Markdown
Member

Summary

Implements issue #190 (render context redesign).

Splits object creation out of ruis::render::context into a new ruis::render::factory class. The factory is the shared (headless) render context and owns the make_* object-creation functions. Every per-window context holds an injected shared_ref<const factory> and no longer creates shareable objects.

Why

Previously make_texture_2d(), make_vertex_array(), etc. lived on the per-window context, and the objects they returned retained a shared_ref<const context>. Nothing stopped a user from creating a shared object through a window's context and then using it in another window — the object would be pinned to the first window (the root cause of the multi-window freeze/ghost bug). The correct approach was to create shared objects via the shared context, but that was only a convention.

Now the shareable-object make_* functions exist only on the factory, and the resulting objects are bound to the shared context (not any single window). The rule is enforced by the type system: a per-window context no longer exposes those make_* at all.

Changes

  • New ruis::render::factory (abstract): owns the shareable-object make_* + the moved shaders struct and texture_2d_parameters.
  • ruis::render::context: removed the shareable make_* and the nested shaders; added an injected factory member. make_framebuffer stays on the context (a frame buffer is inherently per-window).
  • The 7 GPU object classes + 4 shader base classes store a shared_ref<const factory> instead of a shared_ref<const context>.
  • resource_loader and renderer::objects take the factory; the ~42 core make_* call sites are routed through it.

Depends on

This is the ruis core change. It must be merged before/with the matching renderer and ruisapp PRs (ruis-render-{null,opengl,opengles,vulkan}, ruisapp, carcockpit, cod, ruis-sdl-example).

Implement issue #190 (render context redesign).

Object creation (make_shaders, make_texture_*, make_vertex_buffer,
make_index_buffer, make_vertex_array) is split out of
ruis::render::context into a new ruis::render::factory class. The
factory is the shared (headless) render context and owns the make_*
functions; every per-window context holds an injected
shared_ref<const factory> and no longer creates shareable objects.

Every GPU object (texture_2d, texture_depth, texture_stencil,
texture_cube, vertex_buffer, index_buffer, vertex_array and the four
shader base classes) now stores a shared_ref<const factory> instead of
a shared_ref<const context>, so an object created for one window is
safely usable in any other window (it is bound to the shared context,
not a single window).

make_framebuffer stays on the context: a frame buffer is inherently
per-window.

The resource_loader and renderer::objects now take the factory, and
the ~42 make_* call sites in the ruis core are routed through it.

This makes the 'create shared objects via the shared context' rule
enforced by the type system: a per-window context no longer exposes the
shareable make_* at all.
@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 38.23529% with 63 lines in your changes missing coverage. Please review.
✅ Project coverage is 28.54%. Comparing base (4ab8e90) to head (f0a2fec).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/ruis/widget/widget.cpp 32.00% 16 Missing and 1 partial ⚠️
src/ruis/paint/path_vao.cpp 0.00% 14 Missing ⚠️
src/ruis/render/renderer.cpp 61.11% 0 Missing and 7 partials ⚠️
src/ruis/res/gradient.cpp 0.00% 5 Missing ⚠️
src/ruis/res/image.cpp 0.00% 4 Missing ⚠️
src/ruis/res/nine_patch.cpp 0.00% 3 Missing ⚠️
src/ruis/res/texture_2d.cpp 0.00% 2 Missing ⚠️
src/ruis/resource_loader.hpp 33.33% 2 Missing ⚠️
src/ruis/font/texture_font.cpp 66.66% 1 Missing ⚠️
src/ruis/paint/ellipse_vao.cpp 50.00% 1 Missing ⚠️
... and 7 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #192      +/-   ##
==========================================
+ Coverage   28.50%   28.54%   +0.03%     
==========================================
  Files         238      239       +1     
  Lines        8934     8941       +7     
  Branches     2785     2785              
==========================================
+ Hits         2547     2552       +5     
- Misses       6053     6055       +2     
  Partials      334      334              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

- Make the factory destructor public virtual (matching context) to satisfy
  the cppcoreguidelines-virtual-class-destructor clang-tidy check.
- Bump the tests/harness/modules submodules (ruisapp, ruis-render-opengl,
  ruis-render-opengles, ruis-render-null) to their ren_factory commits so the
  CI builds a consistent set (new ruis core + matching ruisapp/renderers).
Comment thread src/ruis/font/texture_font.hxx Resolved
Comment thread src/ruis/font/texture_font.hxx Resolved
Comment thread src/ruis/font/texture_font_face.cpp Resolved
Comment thread src/ruis/font/texture_font_face.hxx Resolved
Comment thread src/ruis/font/texture_font_face.hxx Resolved
Comment thread src/ruis/paint/ellipse_vao.hpp Resolved
Comment thread src/ruis/paint/ellipse_vao.hpp Resolved
Comment thread src/ruis/paint/path_vao.cpp Resolved
The myci-actions/checkout default is 'remote_recursive', which runs
'git submodule update --remote --recursive' and resets the tests/harness
submodules (ruisapp + renderers) to their 'branch = main' tips, ignoring the
pinned gitlink commits. That broke the harness build for the factory change
(new ruis core vs old main ruisapp/renderers).

Set 'submodules: recursive' on the harness/library jobs so the submodules are
checked out at the recorded gitlink commits (pinned to the ren_factory commits
for now; to be bumped to main once the dependent PRs land).
…th_vao

- texture_font / texture_font_face: rename rendering_context member/param to factory
- ellipse_vao / rectangle_vao: drop stale 'resource-loader'/'outlive' doc comments
- path_vao: retain only the shared factory; take renderer as a render() parameter;
  ctor takes (factory, objects)
- update tests (paint, wire_area) accordingly
Comment thread .github/workflows/ci.yml Resolved
Comment thread .github/workflows/ci.yml Resolved
Comment thread src/ruis/render/context.hpp Resolved
@igagis igagis self-assigned this Nov 19, 2026
…ing_context members to factory

- Convert the public context::factory member to a private factory_ref
  member plus a public fac() accessor (avoids the name clash with the
  ruis::render::factory type and the public-member design smell).
- Rename the rendering_context members/params to factory in the shareable
  object and shader base classes and res/* helpers.
- Update all callers to use context.fac().
- CI: use 'submodules: true' (no nested submodules) for the checkout.
The render factory stays a public member of the context (as before). fac()
is just a shorthand that returns a const reference to it, for the common
context.fac().make_*() call sites.
Comment thread src/ruis/paint/rectangle_vao.cpp Resolved
Comment thread src/ruis/render/context.hpp Resolved
Comment thread src/ruis/render/factory.hpp Resolved
Comment thread src/ruis/res/texture_cube.cpp Resolved
Comment thread src/ruis/widget/widget.cpp Resolved
Comment thread tests/app1/src/cube_widget.cpp Resolved
Comment thread tests/app1/src/cube_widget.cpp Resolved
- rectangle_vao: rename the factory-typed 'ctx' params/vars to 'factory'
- context::fac(): drop the explicit .get() (shared_ref auto-casts to ref)
- resource_loader: add a fac() shorthand; use it in the res/* loaders
- widget/gradient/texture_font: use the renderer's ctx() instead of
  poking at the rendering_context member directly
Replace the verbose context.get().renderer.get().ctx().fac() chains with
the this->ctx().ren().ctx().fac() shortcut, and shorten other long chains
in widget.cpp to r.ctx()/this->ctx().ren().ctx().
factory.hpp is a header-only class with no corresponding source file. Add a
dummy factory.cpp that just includes the header so the header is compiled and
linted during the lint preset build (per the add-new-source-file convention).
@igagis
igagis merged commit c176516 into main Nov 19, 2026
22 of 52 checks passed
@igagis
igagis deleted the ren_factory branch November 19, 2026 15: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