Gondwana Game Engine Development (master) - 2.6.1
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
RenderContext.cs
2
3namespace Gondwana.Rendering;
4
10internal sealed class RenderContext
11{
12 [ThreadStatic]
13 private static RenderContext? _current;
14 private static long _nextPassId;
15
16 internal static RenderContext? Current => _current;
17
18 private readonly RenderContext? _prior;
19
20 private RenderContext(View view, long tick, RenderContext? prior)
21 {
22 PassId = System.Threading.Interlocked.Increment(ref _nextPassId);
23 View = view;
24 Tick = tick;
25
26 // Capture every value used by the view's world/screen transform. GPU
27 // rendering occurs on the UI/GL thread while the engine thread continues
28 // updating cameras and animated viewports, so reading these values live
29 // while drawing can produce multiple transforms within one frame.
30 CameraPositionPx = view.Camera.PositionPx;
31 ViewportTargetRectPx = view.Viewport.TargetRectPx;
32 ViewportScreenOffsetPx = view.Viewport.ScreenOffsetPx;
33 ViewEffectOffsetFactor = view.EffectOffsetFactor;
34 ViewEffectOffsetPx = view.EffectOffsetPx;
35
36 var z = view.Viewport.Zoom;
37 ViewportZoom = (z > 0f) ? z : 1f;
38
39 _prior = prior;
40 }
41
42 internal long PassId { get; }
43 internal View View { get; }
44 internal long Tick { get; }
45 internal System.Drawing.PointF CameraPositionPx { get; }
46 internal System.Drawing.Rectangle ViewportTargetRectPx { get; }
47 internal System.Drawing.PointF ViewportScreenOffsetPx { get; }
48 internal float ViewportZoom { get; }
49 internal System.Drawing.PointF ViewEffectOffsetFactor { get; }
50 internal System.Drawing.PointF ViewEffectOffsetPx { get; }
51
52 internal static void Push(View view, long tick)
53 {
54 _current = new RenderContext(view, tick, _current);
55 }
56
57 internal static void Pop()
58 {
59 _current = _current?._prior;
60 }
61}
PointF PositionPx
Gets or sets the camera's world-space position in pixels, interpreted as the upper-left corner of the...
Definition Camera.cs:37
Camera Camera
Gets the camera that controls the world-space position and following behavior for this view....
Definition View.cs:34
Viewport Viewport
Gets the viewport that defines the screen-space rectangle, zoom level, and other rendering parameters...
Definition View.cs:44
Rectangle TargetRectPx
Screen-space rectangle (in SCREEN / RenderSurface pixels) where this view is drawn....
Definition Viewport.cs:35
PointF ScreenOffsetPx
Optional per-view HUD/safe-area offset in screen pixels.
Definition Viewport.cs:81
float Zoom
Zoom factor applied to the world when rendering this view. Values greater than 1 zoom in,...
Definition Viewport.cs:67