Gondwana Game Engine Development (master) - 2.7.0
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
RenderSurfaceHost.Resolution.cs
1using System.Drawing;
3
4namespace Gondwana.Rendering;
5
6public sealed partial class RenderSurfaceHost<TBackbuffer>
7 where TBackbuffer : BackbufferBase
8{
9 private bool _resolutionEstablished;
10 private int _logicalWidth, _logicalHeight;
11 private float _deferredRenderScale = float.NaN;
12
13 private void OnRenderSurfaceAdapterResized(RenderSurfaceAdapterResizedEventArgs args)
14 {
15 Interlocked.Exchange(ref _presentationInvalidated, 1);
16
17 if (float.IsFinite(_deferredRenderScale) && args.NewWidth > 0 && args.NewHeight > 0)
18 RequestRenderScale(_deferredRenderScale);
19
20 if (!_resolutionEstablished && args.NewWidth > 0 && args.NewHeight > 0)
21 {
22 _resolutionEstablished = true;
23 RequestRenderScale(Engine.Instance.Configuration.RenderScale);
24 }
25 }
26
41 public void RequestLogicalResolution(int width, int height)
42 {
43 ArgumentOutOfRangeException.ThrowIfNegativeOrZero(width);
44 ArgumentOutOfRangeException.ThrowIfNegativeOrZero(height);
45 ObjectDisposedException.ThrowIf(_disposed, this);
46
47 // Keep the normal adapter-resize policy unchanged: only callers invoking
48 // this API opt in to a new resolution. The backbuffer coalesces pending
49 // requests and applies them on its own rendering thread.
50 _deferredRenderScale = float.NaN;
51 Backbuffer.RequestResize(width, height);
52 }
53
54 internal override void RequestRenderScale(float scale)
55 {
56 if (!_resolutionEstablished || _disposed)
57 return;
58
59 var adapter = RenderSurfaceAdapter;
60
61 // Zero-size requests are deferred until a valid presentation size exists.
62 if (adapter.Width <= 0 || adapter.Height <= 0)
63 {
64 _deferredRenderScale = scale;
65 return;
66 }
67
68 _deferredRenderScale = float.NaN;
69
70 Backbuffer.RequestResize(
71 PresentationTransform.ScaleDimension(adapter.Width, scale),
72 PresentationTransform.ScaleDimension(adapter.Height, scale));
73 }
74
75 private void OnBackbufferSizeChanged(int width, int height)
76 {
77 float scaleX = (float)width / _logicalWidth;
78 float scaleY = (float)height / _logicalHeight;
79 _logicalWidth = width;
80 _logicalHeight = height;
81 RenderSurfaceAdapter.SetBackbufferSize(width, height);
82
83 foreach (var view in ViewManager.Views)
84 {
85 var old = view.Viewport.TargetRectPx;
86
87 view.Viewport.TargetRectPx = Rectangle.FromLTRB(
88 (int)Math.Round(old.Left * scaleX),
89 (int)Math.Round(old.Top * scaleY),
90 (int)Math.Round(old.Right * scaleX),
91 (int)Math.Round(old.Bottom * scaleY));
92 }
93
94 Scene.FullRefreshNeeded = true;
95 Interlocked.Exchange(ref _presentationInvalidated, 1);
96 }
97}
int NewWidth
Gets the new width of the render surface adapter after the resize.
int NewHeight
Gets the new height of the render surface adapter after the resize.
void RequestLogicalResolution(int width, int height)
Explicitly requests a new logical backbuffer resolution without changing the global Gondwana....
override BackbufferBase Backbuffer
Gets the backbuffer used for off-screen rendering before presentation to the adapter.
readonly record struct PresentationTransform(float Scale, SKRect DestinationRect)
Aspect-preserving mapping between logical Backbuffer ScreenPx and adapter pixels.