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
Gondwana.Rendering.Backbuffers.BackbufferBase Class Referenceabstract

Represents a base class for managing a graphical backbuffer, and is the in-memory surface where rendering operations are performed before being presented to the display. More...

Inheritance diagram for Gondwana.Rendering.Backbuffers.BackbufferBase:
Gondwana.Rendering.Backbuffers.BitmapBackbuffer Gondwana.Rendering.Backbuffers.GpuBackbuffer

Public Member Functions

virtual byte[] ToByteArray (SKEncodedImageFormat format=SKEncodedImageFormat.Png, int quality=100)
 Converts the current image to a byte array in the specified format and quality.
virtual void Dispose ()
 Releases all resources used by the BackbufferBase instance.

Protected Member Functions

 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

readonly SKPaint _fillPaint
 Paint used to fill cleared regions of the backbuffer with the current ClearColor.

Properties

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.

Detailed Description

Represents a base class for managing a graphical backbuffer, and is the in-memory surface where rendering operations are performed before being presented to the display.

This abstract class serves as the foundation for backbuffer implementations, offering methods and properties to facilitate rendering, manage graphical state, and interact with graphical elements such as tiles. Derived classes must implement the Canvas, DrawTileFrame(Tile, RectangleF), and Snapshot members to define specific rendering behavior.

Definition at line 19 of file BackbufferBase.cs.

Constructor & Destructor Documentation

◆ BackbufferBase()

Gondwana.Rendering.Backbuffers.BackbufferBase.BackbufferBase ( int width,
int height )
protected

Initializes a new instance of the BackbufferBase class with the specified dimensions.

Parameters
widthThe width of the backbuffer in pixels.
heightThe height of the backbuffer in pixels.

This constructor establishes the initial size of the backbuffer. Derived classes can override RequestResize to implement dynamic resizing behavior if needed.

Definition at line 36 of file BackbufferBase.cs.

Member Function Documentation

◆ Dispose()

virtual void Gondwana.Rendering.Backbuffers.BackbufferBase.Dispose ( )
virtual

Releases all resources used by the BackbufferBase instance.

This method disposes of managed resources including paint objects used for fog effects, grid lines, collision boxes, and fill operations. Derived classes can override this method to dispose of additional resources but should call the base implementation to ensure proper cleanup of base class resources.

After disposal, the backbuffer should not be used for further rendering operations.

Reimplemented in Gondwana.Rendering.Backbuffers.BitmapBackbuffer, and Gondwana.Rendering.Backbuffers.GpuBackbuffer.

Definition at line 529 of file BackbufferBase.cs.

◆ ToByteArray()

virtual byte[] Gondwana.Rendering.Backbuffers.BackbufferBase.ToByteArray ( SKEncodedImageFormat format = SKEncodedImageFormat::Png,
int quality = 100 )
virtual

Converts the current image to a byte array in the specified format and quality.

This method creates a snapshot of the current image and encodes it into the specified format. The resulting byte array can be used for saving the image to a file, transmitting it over a network, or other purposes requiring a binary representation of the image.

Parameters
formatThe format to encode the image in. The default is SKEncodedImageFormat.Png.
qualityThe quality of the encoded image, ranging from 0 (lowest quality) to 100 (highest quality). This parameter is ignored for formats that do not support quality settings. The default is 100.
Returns
A byte array containing the encoded image data.

Definition at line 496 of file BackbufferBase.cs.

◆ UpdateSize()

void Gondwana.Rendering.Backbuffers.BackbufferBase.UpdateSize ( int width,
int height )
protected

Updates the stored backbuffer dimensions and raises the SizeChanged event.

Parameters
widthThe new width in pixels.
heightThe new height in pixels.

This method should be called by derived classes after successfully resizing the backbuffer to ensure that the Width and Height properties are updated in a thread-safe manner and subscribers are notified of the size change.

The method uses volatile writes to ensure visibility across threads and raises the SizeChanged event with the new dimensions.

Definition at line 252 of file BackbufferBase.cs.

Member Data Documentation

◆ _fillPaint

readonly SKPaint Gondwana.Rendering.Backbuffers.BackbufferBase._fillPaint
protected
Initial value:
= new()
{
IsAntialias = false,
BlendMode = SKBlendMode.Src,
Style = SKPaintStyle.Fill,
FilterQuality = SKFilterQuality.None,
}

Paint used to fill cleared regions of the backbuffer with the current ClearColor.

Definition at line 271 of file BackbufferBase.cs.

Property Documentation

◆ Canvas

SKCanvas Gondwana.Rendering.Backbuffers.BackbufferBase.Canvas
getabstract

Gets the SkiaSharp canvas used for drawing operations on this backbuffer.

An SKCanvas instance that provides the drawing surface for rendering operations.

Derived classes must implement this property to provide access to the underlying drawing canvas. All rendering operations, including tiles, sprites, and direct drawing instances, are performed on this canvas.

The canvas should be configured with appropriate coordinate transformations, clipping regions, and rendering states before drawing operations begin.

Definition at line 60 of file BackbufferBase.cs.

◆ ClearColor

SKColor Gondwana.Rendering.Backbuffers.BackbufferBase.ClearColor
getset

Gets or sets the color used to clear the drawing surface.

Definition at line 282 of file BackbufferBase.cs.

◆ CollisionBoxPaint

SKPaint Gondwana.Rendering.Backbuffers.BackbufferBase.CollisionBoxPaint
getset
Initial value:
= new()
{
Color = SKColors.Green,
IsStroke = true,
StrokeWidth = 1
}

Gets or sets the paint settings used to render collision boxes.

Definition at line 175 of file BackbufferBase.cs.

◆ FogPaint

SKPaint Gondwana.Rendering.Backbuffers.BackbufferBase.FogPaint
getset
Initial value:
= new()
{
Color = new SKColor(0, 0, 0, 128),
IsAntialias = true
}

Gets or sets the paint object used to render fog effects.

Definition at line 156 of file BackbufferBase.cs.

◆ GridLinePaint

SKPaint Gondwana.Rendering.Backbuffers.BackbufferBase.GridLinePaint
getset
Initial value:
= new()
{
Color = SKColors.White,
IsStroke = true,
StrokeWidth = 1
}

Gets or sets the paint settings used to render grid lines.

Definition at line 165 of file BackbufferBase.cs.

◆ Height

int Gondwana.Rendering.Backbuffers.BackbufferBase.Height
get

Gets the current Backbuffer height in a thread-safe manner.

Definition at line 190 of file BackbufferBase.cs.

◆ IsGlThreadRendered

virtual bool Gondwana.Rendering.Backbuffers.BackbufferBase.IsGlThreadRendered
get

Gets a value indicating whether this backbuffer is rendered on the GL thread rather than the engine's background render thread.

When true, bitmap dirty-region rendering is skipped. Desktop GPU hosts record immutable snapshots during foreground work; the platform GL callback replays and presents them via RenderSurfaceHostBase.GlRenderAndSnapshot. Browser GPU hosts retain synchronous full-viewport rendering.

Definition at line 513 of file BackbufferBase.cs.

◆ Width

int Gondwana.Rendering.Backbuffers.BackbufferBase.Width
get

Gets the current Backbuffer width in a thread-safe manner.

Definition at line 185 of file BackbufferBase.cs.