Table of Contents

Class Light2DManager

Namespace
LibGFX.Graphics.Lights
Assembly
LibGFX.dll

Manages 2D lights in the scene.

public class Light2DManager : ILightManager, ISerialization, IGraphicsResource
Inheritance
Light2DManager
Implements
Inherited Members

Constructors

Light2DManager()

Initializes a new instance of the Light2DManager class.

public Light2DManager()

Properties

ChunkSize

Gets or sets the size, in characters, of each chunk used during processing.

public float ChunkSize { get; set; }

Property Value

float

Remarks

Adjust this value to control the maximum number of characters included in a single chunk. Larger chunk sizes may improve performance but can increase memory usage.

Chunks

The dictionary of light chunks, where the key is a tuple of chunk coordinates (x, y).

public Dictionary<(int, int), Light2DChunk> Chunks { get; set; }

Property Value

Dictionary<(int, int), Light2DChunk>

DirectionalLight

The directional light in the scene.

public DirectionalLight2D DirectionalLight { get; set; }

Property Value

DirectionalLight2D

IsInitialized

Gets a value indicating whether the object has been initialized.

public bool IsInitialized { get; }

Property Value

bool

LightSSBO

The shader storage buffer object (SSBO) for the lights.

public int LightSSBO { get; set; }

Property Value

int

Methods

AddPointLight(PointLight2D)

Adds a directional light to the scene.

public void AddPointLight(PointLight2D light)

Parameters

light PointLight2D

BindLights(Viewport, IRenderDevice, Camera)

Binds the lights to the shader program for rendering.

public void BindLights(Viewport viewport, IRenderDevice renderer, Camera camera)

Parameters

viewport Viewport
renderer IRenderDevice
camera Camera

ClearLights()

Removes all lights from the scene, including the directional light and any additional light sources.

public void ClearLights()

Remarks

After calling this method, the scene will contain no active lights. Use this method to reset the lighting configuration before adding new lights or reconfiguring the scene's illumination.

ContainsLight(Light)

Determines whether the specified light is contained within this collection.

public bool ContainsLight(Light light)

Parameters

light Light

The light to locate in the collection. Can be a directional or point light.

Returns

bool

true if the specified light is present in the collection; otherwise, false.

Remarks

This method checks for both directional and point lights. For directional lights, it compares with the collection's directional light. For point lights, it searches all chunks in the collection.

CullChunkLights(Camera, float)

Gets the lights in the nearby chunks based on the given coordinates and chunk size.

public IEnumerable<Point2DLightData> CullChunkLights(Camera camera, float chunkSize)

Parameters

camera Camera
chunkSize float

Returns

IEnumerable<Point2DLightData>

CullLights(Viewport, IRenderDevice, Camera)

Culls the lights based on the camera's view and the viewport.

public void CullLights(Viewport viewport, IRenderDevice renderer, Camera camera)

Parameters

viewport Viewport
renderer IRenderDevice
camera Camera

Deserialize(JObject, SerializationContext, Func<JObject, bool>)

Populates the current object with values from the specified JSON object.

public void Deserialize(JObject obj, SerializationContext serializationContext, Func<JObject, bool> callback = null)

Parameters

obj JObject
serializationContext SerializationContext
callback Func<JObject, bool>

Dispose(IRenderDevice)

Disposes of the light manager and releases any resources.

public void Dispose(IRenderDevice renderDevice)

Parameters

renderDevice IRenderDevice

DisposeLights(IRenderDevice)

Releases all light resources associated with the current instance using the specified render device.

public void DisposeLights(IRenderDevice renderDevice)

Parameters

renderDevice IRenderDevice

The render device to use when disposing of light resources. Cannot be null.

Remarks

Call this method to ensure that all light resources are properly released before disposing of the parent object or when lights are no longer needed. After calling this method, the collection of lights will be cleared.

FindNearbyChunks(float, float, float)

Finds nearby chunks based on the given coordinates and chunk size.

public IEnumerable<(int, int)> FindNearbyChunks(float x, float y, float chunkSize)

Parameters

x float
y float
chunkSize float

Returns

IEnumerable<(int, int)>

ForEachLight(Action<Light>)

Performs an action on each light in the scene, regardless of type.

public void ForEachLight(Action<Light> action)

Parameters

action Action<Light>

ForEachLight<T>(Action<T>)

Performs an action on each light of the specified type in the scene.

public void ForEachLight<T>(Action<T> action) where T : Light

Parameters

action Action<T>

Type Parameters

T

Exceptions

InvalidOperationException

FreeCPUResources()

Frees any CPU resources used by the light manager.

public void FreeCPUResources()

GetChunk(float, float, float)

Gets the chunk coordinates based on the given x and y coordinates and chunk size.

public (int, int) GetChunk(float x, float y, float chunkSize)

Parameters

x float
y float
chunkSize float

Returns

(int srcFactor, int dstFactor)

GetLightCount<T>()

Gets the light count of the specified type.

public int GetLightCount<T>() where T : Light

Returns

int

Type Parameters

T

Exceptions

ArgumentException

GetLight<T>()

Gets the total light count across all types.

public T GetLight<T>() where T : Light

Returns

T

Type Parameters

T

Exceptions

InvalidOperationException

Init(IRenderDevice)

Initializes the light manager with the given render device.

public void Init(IRenderDevice renderDevice)

Parameters

renderDevice IRenderDevice

RemovePointLight(PointLight2D)

Removes a point light from the scene.

public void RemovePointLight(PointLight2D light)

Parameters

light PointLight2D

Serialize(JsonWriter, SerializationContext, Action<JsonWriter>)

Serializes the current object to a new JSON object representation.

public void Serialize(JsonWriter writer, SerializationContext serializationContext, Action<JsonWriter> callback = null)

Parameters

writer JsonWriter
serializationContext SerializationContext
callback Action<JsonWriter>

SetLightSpaceMatrix(Matrix4)

Sets the light view matrix for the light manager, which is used to transform the light's perspective in the scene. Note: This method is not implemented for 2D lights as they do not have a light space matrix like 3D lights.

public void SetLightSpaceMatrix(Matrix4 lightViewMatrix)

Parameters

lightViewMatrix Matrix4

Exceptions

NotImplementedException