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.Composition.cs
1using System.Drawing;
8using SkiaSharp;
9
10namespace Gondwana.Rendering;
11
12public sealed partial class RenderSurfaceHost<TBackbuffer>
13 where TBackbuffer : BackbufferBase
14{
15 private void BeginViewportClip(View view, Rectangle viewport, BackbufferBase target)
16 {
17 target.Canvas.Save();
18 target.Canvas.ResetMatrix();
19 target.Canvas.ClipRect(viewport.ToSKRect(), SKClipOperation.Intersect, antialias: false);
20
21 foreach (var blocker in ViewManager.GetViewsAbove(view))
22 {
23 if (!blocker.BlocksViewsBelow)
24 continue;
25
26 var overlap = Rectangle.Intersect(viewport, blocker.GetRenderViewportTargetRectPx());
27
28 if (!overlap.IsEmpty)
29 target.Canvas.ClipRect(overlap.ToSKRect(), SKClipOperation.Difference, antialias: false);
30 }
31 }
32
33 private int BeginPresentation(
34 RectangleF bounds,
35 float opacity,
36 float reveal,
37 EffectDirection direction,
38 BackbufferBase? destination = null)
39 {
40 var target = destination ?? Backbuffer;
41 opacity = Math.Clamp(opacity, 0f, 1f);
42 reveal = Math.Clamp(reveal, 0f, 1f);
43
44 if (opacity <= 0.0001f || reveal <= 0.0001f || bounds.IsEmpty)
45 return 0;
46
47 int saveCount = 1;
48 target.Canvas.Save();
49
50 if (reveal < 0.9999f)
51 {
52 RectangleF revealRect = EffectGeometry.GetRevealRect(bounds, direction, reveal);
53
54 target.Canvas.ClipRect(
55 revealRect.ToSKRect(),
56 SKClipOperation.Intersect,
57 antialias: false);
58 }
59
60 if (opacity < 0.9999f)
61 {
62 using var paint = new SKPaint
63 {
64 Color = new SKColor(
65 255,
66 255,
67 255,
68 (byte)Math.Round(opacity * 255f))
69 };
70
71 target.Canvas.SaveLayer(bounds.ToSKRect(), paint);
72 saveCount++;
73 }
74
75 return saveCount;
76 }
77
78 private void EndPresentation(int saveCount, BackbufferBase? destination = null)
79 {
80 var target = destination ?? Backbuffer;
81
82 while (saveCount-- > 0)
83 target.Canvas.Restore();
84 }
85
86 private static RectangleF GetLayerPresentationBounds(View view, SceneLayer layer)
87 {
88 RectangleF viewport = view.GetRenderViewportTargetRectPx();
89 PointF offset = view.GetEffectOffsetPx(layer);
90
91 return new RectangleF(
92 viewport.Left + offset.X,
93 viewport.Top + offset.Y,
94 viewport.Width,
95 viewport.Height);
96 }
97
98 private void InvokePostSceneCanvasHooks(BackbufferBase? destination = null)
99 {
100 var target = destination ?? Backbuffer;
101 var hasSurfaceHandlers = RenderBackbufferPostScene is not null;
102 var hasPlugins = EnginePluginRegistry.All.Count > 0;
103
104 if (!hasSurfaceHandlers && !hasPlugins)
105 return;
106
107 if (!target.IsGlThreadRendered)
108 target.AddToBackbufferDirtyRectangle(
109 new Rectangle(
110 0,
111 0,
112 target.Width,
113 target.Height));
114
115 if (hasSurfaceHandlers)
116 RenderBackbufferPostScene?.Invoke(target.Canvas);
117
118 if (hasPlugins)
119 EnginePluginRegistry.InvokePostRenderCanvas(Engine.Instance, this, target.Canvas);
120 }
121}
SKCanvas Canvas
Gets the SkiaSharp canvas used for drawing operations on this backbuffer.
@ Rectangle
Particles are spawned uniformly within a rectangular area. This is the default distribution.
EffectDirection
Specifies the direction in which a directional display effect travels.
@ Backbuffer
Displays logical backbuffer dimensions.