![]() |
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.
|
Provides a fully GPU-rendered backbuffer implementation using SkiaSharp and OpenGL. More...
Public Member Functions | |
| GpuBackbuffer (int width, int height) | |
| Initializes a new instance of the GpuBackbuffer class with the specified dimensions. | |
| void | Initialize (GRContext grContext, int width, int height) |
| Creates (or recreates) the GPU render-target surface for this backbuffer. | |
| bool | EnsureInitialized (GRContext context) |
| Initializes on the owning GL thread, or applies an explicit logical resolution request. Adapter dimensions are deliberately absent: window resize never reallocates this surface. Returns true when a new surface needs its first complete frame. | |
| void | RecordFrame () |
Records that one frame has been rendered. Called by the platform adapter on every PaintSurface callback so the engine can compute the actual rendered FPS. | |
| override void | Dispose () |
| Releases all resources used by this GpuBackbuffer. | |
| Public Member Functions inherited from Gondwana.Rendering.Backbuffers.BackbufferBase | |
| virtual byte[] | ToByteArray (SKEncodedImageFormat format=SKEncodedImageFormat.Png, int quality=100) |
| Converts the current image to a byte array in the specified format and quality. | |
Properties | |
| int | TargetFps [get, set] |
| Gets or sets the target frame rate associated with this GPU backbuffer. | |
| bool | VSync = true [get, set] |
| Gets or sets a value indicating whether vertical synchronisation (vsync) is enabled. | |
| int | MsaaSampleCount [get, set] |
| Gets or sets the number of MSAA (multisample anti-aliasing) samples used when creating the GPU render-target surface. | |
| int | ActualMsaaSampleCount [get] |
| Gets the sample count used by the currently active GPU render-target surface. | |
| int | MaxSupportedMsaaSampleCount [get] |
| Gets the maximum MSAA sample count reported by the active GPU context for SKColorType.Rgba8888 render-target surfaces. | |
| override bool | IsGlThreadRendered [get] |
| override SKCanvas | Canvas [get] |
| Gets the SkiaSharp canvas for drawing operations. | |
| Properties inherited from Gondwana.Rendering.Backbuffers.BackbufferBase | |
| SKCanvas | Canvas [get] |
| Gets the SkiaSharp canvas used for drawing operations on this backbuffer. | |
| SKPaint | FogPaint [get, set] |
| Gets or sets the paint object used to render fog effects. | |
| SKPaint | GridLinePaint [get, set] |
| Gets or sets the paint settings used to render grid lines. | |
| SKPaint | CollisionBoxPaint [get, set] |
| Gets or sets the paint settings used to render collision boxes. | |
| int | Width [get] |
| Gets the current Backbuffer width in a thread-safe manner. | |
| int | Height [get] |
| Gets the current Backbuffer height in a thread-safe manner. | |
| SKColor | ClearColor [get, set] |
| Gets or sets the color used to clear the drawing surface. | |
| virtual bool | IsGlThreadRendered [get] |
| Gets a value indicating whether this backbuffer is rendered on the GL thread rather than the engine's background render thread. | |
Additional Inherited Members | |
| Protected Member Functions inherited from Gondwana.Rendering.Backbuffers.BackbufferBase | |
| BackbufferBase (int width, int height) | |
| Initializes a new instance of the BackbufferBase class with the specified dimensions. | |
| void | UpdateSize (int width, int height) |
| Updates the stored backbuffer dimensions and raises the SizeChanged event. | |
| Protected Attributes inherited from Gondwana.Rendering.Backbuffers.BackbufferBase | |
| readonly SKPaint | _fillPaint |
| Paint used to fill cleared regions of the backbuffer with the current ClearColor. | |
Provides a fully GPU-rendered backbuffer implementation using SkiaSharp and OpenGL.
Architecture (GL-thread rendering): All rendering operations (tile drawing, canvas operations) and presentation happen on the GL thread, driven by WinFormGpuRenderSurfaceAdapter from within SKGLControl.PaintSurface. The engine's background loop skips this surface entirely (see IsGlThreadRendered). No CPU↔GPU data transfer occurs for the backbuffer contents; tiles are rasterised directly into an off-screen GPU render target and then blitted to the window surface in a single GPU draw call.
Before the first Initialize call the backbuffer uses a temporary CPU raster surface (identical to BitmapBackbuffer) so that the host can always be in a valid state. Once a GRContext becomes available on the GL thread, Initialize replaces that with a proper GPU surface.
Thread safety: After Initialize has been called, all methods and properties that access or mutate GL state must be invoked from the GL thread (the thread on which the GRContext is current). The engine loop guarantees this by checking IsGlThreadRendered before touching the backbuffer. Configuration properties such as VSync, MsaaSampleCount, and TargetFps may be updated from other threads because they modify managed configuration state only. In particular, changing MsaaSampleCount records a new configuration revision; any required GPU surface recreation is deferred until the next owning GL-thread EnsureInitialized call.
Definition at line 39 of file GpuBackbuffer.cs.
| Gondwana.Rendering.Backbuffers.GpuBackbuffer.GpuBackbuffer | ( | int | width, |
| int | height ) |
Initializes a new instance of the GpuBackbuffer class with the specified dimensions.
| width | The initial width of the backbuffer in pixels. |
| height | The initial height of the backbuffer in pixels. |
Definition at line 184 of file GpuBackbuffer.cs.
|
virtual |
Releases all resources used by this GpuBackbuffer.
Reimplemented from Gondwana.Rendering.Backbuffers.BackbufferBase.
Definition at line 420 of file GpuBackbuffer.cs.
| bool Gondwana.Rendering.Backbuffers.GpuBackbuffer.EnsureInitialized | ( | GRContext | context | ) |
Initializes on the owning GL thread, or applies an explicit logical resolution request. Adapter dimensions are deliberately absent: window resize never reallocates this surface. Returns true when a new surface needs its first complete frame.
| context | The context. |
true if initialization succeeded; otherwise, false.Definition at line 255 of file GpuBackbuffer.cs.
| void Gondwana.Rendering.Backbuffers.GpuBackbuffer.Initialize | ( | GRContext | grContext, |
| int | width, | ||
| int | height ) |
Creates (or recreates) the GPU render-target surface for this backbuffer.
Called from the owning GL thread for initial setup, an explicit logical resolution change, or an MSAA configuration change. Replaces the current surface with a hardware-accelerated off-screen render target backed by grContext .
| grContext | The active Skia GPU context. Must not be null. |
| width | The new surface width in pixels. |
| height | The new surface height in pixels. |
Definition at line 215 of file GpuBackbuffer.cs.
| void Gondwana.Rendering.Backbuffers.GpuBackbuffer.RecordFrame | ( | ) |
Records that one frame has been rendered. Called by the platform adapter on every PaintSurface callback so the engine can compute the actual rendered FPS.
|
get |
Gets the sample count used by the currently active GPU render-target surface.
Before the first GPU initialization this reports 1 for the temporary CPU surface. If the requested MsaaSampleCount is unsupported and surface creation falls back to non-MSAA rendering, this property reports 1 while MsaaSampleCount continues to report the requested value.
Definition at line 160 of file GpuBackbuffer.cs.
|
get |
Gets the SkiaSharp canvas for drawing operations.
Definition at line 277 of file GpuBackbuffer.cs.
|
get |
Always returns true. The engine loop will skip this surface; the platform adapter drives rendering from SKGLControl.PaintSurface.
Definition at line 202 of file GpuBackbuffer.cs.
|
get |
Gets the maximum MSAA sample count reported by the active GPU context for SKColorType.Rgba8888 render-target surfaces.
Before the first GPU initialization this reports 1. A value of 1 means the active context reports no multisample support for Gondwana's GPU render-target color type.
Definition at line 170 of file GpuBackbuffer.cs.
|
getset |
Gets or sets the number of MSAA (multisample anti-aliasing) samples used when creating the GPU render-target surface.
This property only applies to GpuBackbuffer; other backbuffer types ignore it.
This value is kept in sync with Gondwana.Configuration.EngineConfiguration.MsaaSampleCount (which propagates its value to all registered GPU backbuffers). A value of 1 disables MSAA. Common values are 2, 4, or 8, subject to hardware support.
Changing this property on an already-initialized backbuffer schedules the GPU render-target surface for recreation. The new sample count is applied by the next owning GL-thread EnsureInitialized call; callers do not need to resize the backbuffer.
If the requested sample count is not supported by the hardware or driver, Initialize will automatically fall back to a sample count of 1 (no MSAA) so the surface is always valid.
The MSAA sample count. Values less than 1 are clamped to 1. The default is 1.
Definition at line 129 of file GpuBackbuffer.cs.
|
getset |
Gets or sets the target frame rate associated with this GPU backbuffer.
This value is kept in sync with Gondwana.Configuration.EngineConfiguration.TargetFPS (which propagates its value to all registered GPU backbuffers). The engine's own foreground cycle — not the backbuffer — is responsible for throttling the frame rate; see Gondwana.Configuration.EngineConfiguration.TargetFPS for details.
The desired frames per second. Negative values are clamped to zero. The default is 60.
Definition at line 73 of file GpuBackbuffer.cs.
|
getset |
Gets or sets a value indicating whether vertical synchronisation (vsync) is enabled.
This property only applies to GpuBackbuffer; other backbuffer types ignore it.
This value is kept in sync with Gondwana.Configuration.EngineConfiguration.VSync (which propagates its value to all registered GPU backbuffers). The value is read by the platform adapter (e.g. WinFormGpuRenderSurfaceAdapter) at the start of each PaintSurface call and applied to the underlying GLControl.VSync property when it changes. Enabling vsync prevents screen tearing but caps the frame rate to the monitor refresh rate. Disabling vsync allows higher frame rates at the cost of potential tearing.
true to synchronise presentation with the monitor refresh; otherwise false. The default is true.
Definition at line 99 of file GpuBackbuffer.cs.