Loads and loads of small improvements I added while developing on my game
This commit is contained in:
parent
41421b1df9
commit
a7c71e7ea1
107 changed files with 2278 additions and 1023 deletions
62
SMCode/SM.Base/Shaders/MaterialShader.cs
Normal file
62
SMCode/SM.Base/Shaders/MaterialShader.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#region usings
|
||||
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.Base;
|
||||
using SM.Base.Windows;
|
||||
using SM.OGL.Mesh;
|
||||
using SM.OGL.Shaders;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Drawing
|
||||
{
|
||||
/// <summary>
|
||||
/// A general class to work with material shaders properly.
|
||||
/// </summary>
|
||||
public abstract class MaterialShader : GenericShader
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected MaterialShader(string combinedData) : base(combinedData)
|
||||
{}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected MaterialShader(string vertex, string fragment) : base(vertex, fragment)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected MaterialShader(ShaderFileCollection shaderFileFiles) : base(shaderFileFiles)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prepares the context for the drawing.
|
||||
/// </summary>
|
||||
/// <param name="context">The context</param>
|
||||
public virtual void Draw(DrawContext context)
|
||||
{
|
||||
context.Shader.Activate();
|
||||
|
||||
context.Mesh.Activate();
|
||||
|
||||
if (context.Mesh is ILineMesh lineMesh)
|
||||
GL.LineWidth(context.Material.ShaderArguments.Get("LineWidth", lineMesh.LineWidth));
|
||||
|
||||
if (context.Material.Blending)
|
||||
{
|
||||
GL.Enable(EnableCap.Blend);
|
||||
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
|
||||
} else GL.Disable(EnableCap.Blend);
|
||||
|
||||
DrawProcess(context);
|
||||
|
||||
CleanUp();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws the context.
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected abstract void DrawProcess(DrawContext context);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue