Gondwana Game Engine
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, mobile, and web platforms using SkiaSharp for graphics and NAudio for sound.
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

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.

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 operations, 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.

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.

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.

◆ 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.

◆ 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.

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,
}

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.

◆ ClearColor

SKColor Gondwana.Rendering.Backbuffers.BackbufferBase.ClearColor
getset

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

◆ 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.

◆ 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.

◆ 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.

◆ Height

int Gondwana.Rendering.Backbuffers.BackbufferBase.Height
get

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

◆ Width

int Gondwana.Rendering.Backbuffers.BackbufferBase.Width
get

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