Skip to content

Class ShaderLibrary

Namespace: Apogee.Rendering.Shaders
Assembly: Apogee.Rendering.dll

Where renderers get their shaders. takes the compiled artifact of a shader module when its project was imported (), which is how a shipped game and a mod that ships its shaders work: the Slang compiler is never loaded. A module without an artifact is compiled, as in development, if the compiler is there, and the error says what to do when it is not. The engine's own shaders are mounted as shaders:// (); a mod's are at mod://id/…, with their artifacts in mod://id/imported. The library remembers which files each module it loaded was made from, so that when files change (, from HotReloader.ShadersChanged or a ) it can say which modules are out of date (): rebuilds on that. It is thread safe.

public sealed class ShaderLibrary

Inheritance

object ← ShaderLibrary

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Constructors

ShaderLibrary(VirtualFileSystem, ShaderCompilerOptions?, Func<ShaderCompilerOptions, ShaderCompiler>?, bool?)

public ShaderLibrary(VirtualFileSystem files, ShaderCompilerOptions? options = null, Func<ShaderCompilerOptions, ShaderCompiler>? createCompiler = null, bool? canCompile = null)

Parameters

files VirtualFileSystem

The file system the shaders are read from.

options ShaderCompilerOptions?

The compiler's options, for shaders that have to be compiled.

createCompiler Func<ShaderCompilerOptions, ShaderCompiler>?

Makes the compiler (tests replace it); the default is .

canCompile bool?

Says whether shaders without an artifact can be compiled; by default whether the compiler library loads.

Properties

CanCompile

True when shaders without an artifact can be compiled: the compiler library is there.

public bool CanCompile { get; }

Property Value

bool

Errors

The compile errors of the shaders that are being rebuilt and could not be, one message per group of pipelines; empty when everything is as the files say. The dev overlay shows them.

public IReadOnlyList<string> Errors { get; }

Property Value

IReadOnlyList<string>

Files

public VirtualFileSystem Files { get; }

Property Value

VirtualFileSystem

Methods

Load(string, IReadOnlyDictionary<string, string>?, ShaderBackend)

The module at path (shaders://forward.slang), in the variant that defines names, with the code for backend (a device's ShaderBackend).

public CompiledShader Load(string path, IReadOnlyDictionary<string, string>? defines = null, ShaderBackend backend = ShaderBackend.Spirv)

Parameters

path string

defines IReadOnlyDictionary<string, string>?

backend ShaderBackend

Returns

CompiledShader

Exceptions

ShaderCompileException

It has no artifact and cannot be compiled, or it does not compile.

MountEngineShaders(VirtualFileSystem, IEnumerable<string>?, bool)

Mounts the engine's shaders as shaders://. With directories null that is the Shaders folder next to the program, or, with sources, the folders of the shaders' own sources when the program runs from the repository, so that editing them is what the running program sees.

public static void MountEngineShaders(VirtualFileSystem files, IEnumerable<string>? directories = null, bool sources = false)

Parameters

files VirtualFileSystem

directories IEnumerable<string>?

sources bool

NotifyChanged(IEnumerable<string>)

Says that these files changed (virtual paths, as HotReloader.ShadersChanged reports them): the artifact indexes are read again, and is raised with the loaded modules that are one of the files or were made from one.

public void NotifyChanged(IEnumerable<string> paths)

Parameters

paths IEnumerable<string>

Refresh()

Reads the artifact indexes again (after an import).

public void Refresh()

Standard(string?, string?)

The engine's shaders: the Shaders folder next to the program, as shaders://.

public static ShaderLibrary Standard(string? cacheDirectory = null, string? shaderDirectory = null)

Parameters

cacheDirectory string?

shaderDirectory string?

Returns

ShaderLibrary

ModulesChanged

Raised, on the thread that called , with the modules that were loaded and depend on a file that changed.

public event Action<IReadOnlyCollection<string>>? ModulesChanged

Event Type

Action<IReadOnlyCollection<string>>?