smrendererv3/SMCode/SM.Base/Shaders/MaterialShader.cs
Michel Fedde c6bf5c75bc 2021-04-03
+ Added Field to DrawingBasis to enfore PrimitiveTypes
+ LastObject to context for Debugging
+ AppendRenderbuffer to Framebuffer

~ Added a depthbuffer to RenderPipeline.CreateWindowFramebuffer
~ Proper ZIndices over Z-Translation and DepthBuffer
~ Made "ShaderArguments["LineWidth"]" set the LineWidth even if the object isn't maked as LineMesh
~ Made that the SM2D.PolygonVertex can translate OpenTK.Vector2 by itself.
~ Made the SM2D.Transformation.ZIndex a CVector1 instead a float
2021-03-04 22:17:03 +01:00

64 lines
No EOL
1.8 KiB
C#

#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));
else if (context.Material.ShaderArguments.ContainsKey("LineWidth"))
GL.LineWidth((float)context.Material.ShaderArguments["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);
}
}