Table of Contents

Class ShaderManager

Namespace
BSGameLib.Game
Assembly
BSGameLib.Game.dll

Holds the shader programs and the materials that use them. Disposing it disposes every shader it holds.

public class ShaderManager : IDisposable
Inheritance
ShaderManager
Implements
Inherited Members

Constructors

ShaderManager(IShaderProgramFactory)

Created by dependency injection.

public ShaderManager(IShaderProgramFactory shaderFactory)

Parameters

shaderFactory IShaderProgramFactory

Methods

Dispose()

Disposes every shader this manager holds, and forgets them.

public void Dispose()

EnsureMaterial(Material, Action<MaterialBuilder>)

Registers material with configure unless it already has a definition, and returns the definition either way.

public MaterialDefinition EnsureMaterial(Material material, Action<MaterialBuilder> configure)

Parameters

material Material
configure Action<MaterialBuilder>

Returns

MaterialDefinition

GetMaterialDefinition(Material)

Returns the definition of material. Throws when it has not been registered.

public MaterialDefinition GetMaterialDefinition(Material material)

Parameters

material Material

Returns

MaterialDefinition

GetMaterialShader(Material)

Returns the shader for material, made from its definition the first time. Throws when the material is not registered.

public IShaderProgram GetMaterialShader(Material material)

Parameters

material Material

Returns

IShaderProgram

GetMaterialShader(Material, Func<IShaderProgram>)

Returns the shader for material. When the material is not registered yet, registers it to use factory for its shader.

public IShaderProgram GetMaterialShader(Material material, Func<IShaderProgram> factory)

Parameters

material Material
factory Func<IShaderProgram>

Returns

IShaderProgram

Remarks

factory is used only by that first registration; later calls ignore it.

GetOrAdd(string, Func<IShaderProgram>)

Returns the shader stored under name. When there is none, calls factory, stores its result and returns it.

public IShaderProgram GetOrAdd(string name, Func<IShaderProgram> factory)

Parameters

name string
factory Func<IShaderProgram>

Returns

IShaderProgram

GetShader(string)

Returns the shader stored under name.

public IShaderProgram GetShader(string name)

Parameters

name string

Returns

IShaderProgram

LoadEmbedded(string, Assembly, string, string)

Returns the shader stored under name. The first call reads the two embedded resources in assembly, compiles them and stores the result; later calls return that.

public IShaderProgram LoadEmbedded(string name, Assembly assembly, string vertexResource, string fragmentResource)

Parameters

name string
assembly Assembly
vertexResource string
fragmentResource string

Returns

IShaderProgram

LoadShader(string, string, string)

Compiles a shader from source and stores it under name.

public void LoadShader(string name, string vertexSource, string fragmentSource)

Parameters

name string
vertexSource string
fragmentSource string

RegisterMaterial(Material, Action<MaterialBuilder>)

Builds the definition of material with configure and stores it, replacing any definition already registered. The next GetMaterialShader(Material) makes the shader from the new definition; one already handed out stays usable until this manager is disposed.

public MaterialDefinition RegisterMaterial(Material material, Action<MaterialBuilder> configure)

Parameters

material Material
configure Action<MaterialBuilder>

Returns

MaterialDefinition

TryGetMaterialDefinition(Material, out MaterialDefinition)

Whether material has a definition, and the definition when it does.

public bool TryGetMaterialDefinition(Material material, out MaterialDefinition definition)

Parameters

material Material
definition MaterialDefinition

Returns

bool