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
shaderFactoryIShaderProgramFactory
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
materialMaterialconfigureAction<MaterialBuilder>
Returns
GetMaterialDefinition(Material)
Returns the definition of material. Throws when it has not been
registered.
public MaterialDefinition GetMaterialDefinition(Material material)
Parameters
materialMaterial
Returns
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
materialMaterial
Returns
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
materialMaterialfactoryFunc<IShaderProgram>
Returns
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
namestringfactoryFunc<IShaderProgram>
Returns
GetShader(string)
Returns the shader stored under name.
public IShaderProgram GetShader(string name)
Parameters
namestring
Returns
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
Returns
LoadShader(string, string, string)
Compiles a shader from source and stores it under name.
public void LoadShader(string name, string vertexSource, string fragmentSource)
Parameters
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
materialMaterialconfigureAction<MaterialBuilder>
Returns
TryGetMaterialDefinition(Material, out MaterialDefinition)
Whether material has a definition, and the definition when it does.
public bool TryGetMaterialDefinition(Material material, out MaterialDefinition definition)
Parameters
materialMaterialdefinitionMaterialDefinition