Skip to content

Refactor librenderer2 to modular rendering pipeline and state management#1275

Draft
adfriz wants to merge 13 commits into
leezer3:masterfrom
adfriz:librender2-refactor
Draft

Refactor librenderer2 to modular rendering pipeline and state management#1275
adfriz wants to merge 13 commits into
leezer3:masterfrom
adfriz:librender2-refactor

Conversation

@adfriz

@adfriz adfriz commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Overhauled LibRender2 to use a multipass pipeline architecture.

  • Split rendering logic into specialized passes (Geometry, Sky, Shadow, Overlay).
  • Added SceneManager to decouple visibility logic from the renderer.
  • Implemented GraphicsDevice for centralized OpenGL state caching.
  • Introduced GpuResourceManager for managed resource lifecycles.
  • Unified the rendering loop across all application modules.

Although it works locally, it have some bugs like shadow not working, some weird halo effect around texture, ingame gui looks odd, 2d cab looks too bright.

WIP, not tested in macos and linux.

currently only synced to commit d37ec8e from upstream master.

adfriz added 2 commits April 24, 2026 20:00
Overhauled LibRender2 to use a structured pipeline architecture.

- Split rendering logic into specialized passes (Geometry, Sky, Shadow, Overlay).
- Added SceneManager to decouple visibility logic from the renderer.
- Implemented GraphicsDevice for centralized OpenGL state caching.
- Introduced GpuResourceManager for managed resource lifecycles.
- Unified the rendering loop across all application modules.
@adfriz

adfriz commented Apr 24, 2026

Copy link
Copy Markdown
Contributor Author
image

some preview

@adfriz

adfriz commented Apr 24, 2026

Copy link
Copy Markdown
Contributor Author

good, the ci build without error.

synced with latest master, the bright bug now gone but, halo effect still persist and now the ingame gui clipped with trains and other close object.... it seems something wrong with the depth test
image

@leezer3

leezer3 commented Apr 24, 2026

Copy link
Copy Markdown
Owner

Without digging too far into what you've done, I'd suggest that you probably want to convert the rest of the SetBlend calls from the base renderer.
(The loading screen, text, and some face parts)

Looks like the blending mode is off to cause the halo.

adfriz added 6 commits April 24, 2026 20:57
- Replace direct OpenGL calls (GL.DepthMask, GL.Enable, GL.BlendFunc, etc.) with GraphicsDevice cached state methods across LibRender2 and OpenBVE renderer.
- Add null-safety checks to Transformation constructors and Vector3 transformation operations to prevent NullReferenceExceptions.
- Ensure proper renderer de-initialization in GameWindow during application shutdown.
- Update Transformation constructors to use default vectors (Right, Down, Forward) when the input transformation is null.
This reverts commit 03dd64b.
- Implement a blend state stack (PushBlendFunc/PopBlendFunc) in BaseRenderer to allow safe temporary blending changes.
- Convert direct OpenGL blending calls in OpenGlString and Background to use BaseRenderer helper methods.
- Fix "halo" visual bug by ensuring proper restoration of blending state in text rendering.
- Restore null-safety checks in Transformation constructors and Vector3 operations to prevent crashes.
- Fix compilation error in NewRenderer by adding missing using directive.
- Implemented Opaque Face Batching to significantly reduce draw calls.
- Optimized VisibleObjectLibrary with O(1) insertion and deferred VAO sorting.
- Replaced expensive parallel distance sorting with camera-forward dot product (20x faster).
- Fixed race conditions in ObjectLibrary by using thread-safe cloning for alpha faces.
- Resolved Z-fighting and flickering artifacts using DepthFunction.Lequal.
- Added defensive null checks for VAOs and animation matrices to prevent crashes.
- Implemented AABB and Bounding Sphere generation for future culling optimizations.
- Optimized state management for night textures to minimize redundant GL calls.
- Updated default fragment shader for better lighting/transparency handling.
- Refactored OverlayPass, SkyPass and main Renderer entry points for consistency.
- Updated ShaderLayout and FaceState to support recent performance optimizations.
@leezer3

leezer3 commented Apr 27, 2026

Copy link
Copy Markdown
Owner

The cab overlay faces aren't right at the minute- I'm seeing a lot of stuff in 2D (BVE4 / BVE2 era cabs) being glitchy.

adfriz added 2 commits April 27, 2026 16:22
- Implement RenderFace in BaseRenderer to unify drawing across passes
- Optimize matrix and VAO updates by tracking current ObjectState
- Refactor ShadowPass to use centralized RenderFace logic
- Improve OverlayPass handling for new renderer path
- Fix light direction sign in ShadowPass
- Ensure proper shader state reset when switching programs
@adfriz

adfriz commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

Mostly sorted out, still need to check other stuff like bve5 route parser.

image

@adfriz

adfriz commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

@leezer3

on master, shadow currently not affected if using night time texture or its emissive material. do you think i should give player 2 new checkbox in the shadow settings to allow player to choose if shadow cast on faces with night time texture and emissive material?

it should say like:

[x] Cast on Night time texture
[x] Cast on emissive material 

because some trains content like the fujikyu 6000 above wont cast shadow on the interior because it use night time texture.

@leezer3

leezer3 commented Apr 27, 2026

Copy link
Copy Markdown
Owner

Less options is better really.
probably cast on nighttime, but not emissive.

I will note the following which you may or may not have seen:
https://github.com/leezer3/OpenBVE/wiki/Errata#lighting-behaviour-with-a-defined-daytime-and-nighttime-texture

See also the linked issue.
Basically, whatever you do, it'll break something.

@adfriz
adfriz marked this pull request as draft May 8, 2026 15:41
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