04.10.2020

+ render pipeline system for more control about the renderering.
+ Log system
+ Framebuffer system

~ Default shader was moved to pipelines.
This commit is contained in:
Michel Fedde 2020-10-04 16:31:48 +02:00
parent 97e638d9d9
commit 820d6ce700
34 changed files with 660 additions and 106 deletions

View file

@ -38,9 +38,20 @@ namespace SM.Base.Contexts
/// </summary>
public Material Material;
/// <summary>
/// Contains the currently used render pipeline.
/// </summary>
public RenderPipeline ActivePipeline;
/// <summary>
/// The current world scale.
/// </summary>
public Vector2 WorldScale;
/// <summary>
/// Returns the appropriate shader.
/// <para>Returns the material shader, if available, otherwise it will take the default shader from the render pipeline.</para>
/// </summary>
public IShader Shader => Material.CustomShader ?? ActivePipeline._defaultShader;
}
}

View file

@ -41,14 +41,14 @@ namespace SM.Base
{
GLSystem.INIT_SYSTEM();
Console.Write("----------------------\n" +
"--- OpenGL Loading ---\n" +
"----------------------------------\n" +
$"--- {"DeviceVersion",14}: {GLSystem.DeviceVersion,-10} ---\n" +
$"--- {"ForcedVersion",14}: {GLSystem.ForcedVersion,-10} ---\n" +
$"--- {"ShadingVersion",14}: {GLSystem.ShadingVersion,-10} ---\n" +
$"--- {"Debugging",14}: {GLSystem.Debugging,-10} ---\n" +
$"----------------------------------\n");
Log.Write("#", ConsoleColor.Cyan, "----------------------",
"--- OpenGL Loading ---",
"----------------------------------",
$"--- {"DeviceVersion",14}: {GLSystem.DeviceVersion,-10} ---",
$"--- {"ForcedVersion",14}: {GLSystem.ForcedVersion,-10} ---",
$"--- {"ShadingVersion",14}: {GLSystem.ShadingVersion,-10} ---",
$"--- {"Debugging",14}: {GLSystem.Debugging,-10} ---",
$"----------------------------------");
base.OnLoad(e);
_loading = true;
@ -123,11 +123,9 @@ namespace SM.Base
/// The base window.
/// </summary>
/// <typeparam name="TScene">The scene type</typeparam>
/// <typeparam name="TItem">The base item type</typeparam>
/// <typeparam name="TCamera">The camera type</typeparam>
public abstract class GenericWindow<TScene, TItem, TCamera> : GenericWindow
where TScene : GenericScene<TCamera, TItem>, new()
where TItem : IShowItem
public abstract class GenericWindow<TScene, TCamera> : GenericWindow
where TScene : GenericScene, new()
where TCamera : GenericCamera, new()
{
/// <summary>
@ -144,6 +142,11 @@ namespace SM.Base
/// </summary>
public TScene CurrentScene { get; private set; }
/// <summary>
/// Controls how a scene is rendered.
/// </summary>
public RenderPipeline<TScene> RenderPipeline { get; private set; }
/// <inheritdoc />
protected GenericWindow()
{
@ -153,6 +156,7 @@ namespace SM.Base
/// <inheritdoc />
protected override void OnRenderFrame(FrameEventArgs e)
{
Deltatime.RenderDelta = (float)e.Time;
DrawContext drawContext = new DrawContext()
{
World = ViewportCamera.World,
@ -165,11 +169,11 @@ namespace SM.Base
base.OnRenderFrame(e);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
CurrentScene.Draw(drawContext);
RenderPipeline.Render(ref drawContext, CurrentScene);
SwapBuffers();
GLDebugging.CheckGLErrors();
}
/// <inheritdoc />
@ -178,6 +182,7 @@ namespace SM.Base
base.OnResize(e);
ViewportCamera.RecalculateWorld(_worldScale, Aspect);
RenderPipeline.Resize();
}
/// <summary>
@ -189,5 +194,15 @@ namespace SM.Base
CurrentScene = scene;
scene.Activate();
}
/// <summary>
/// Defines the render pipeline.
/// </summary>
/// <param name="pipeline"></param>
public void SetRenderPipeline(RenderPipeline<TScene> pipeline)
{
RenderPipeline = pipeline;
pipeline.Activate(this);
}
}
}

View file

@ -0,0 +1,74 @@
using System.Collections.Generic;
using SM.Base.Contexts;
using SM.Base.Scene;
using SM.OGL.Framebuffer;
namespace SM.Base
{
/// <summary>
/// Definition of specific render options.
/// </summary>
public abstract class RenderPipeline
{
/// <summary>
/// The framebuffers, that are used in this Pipeline.
/// </summary>
protected virtual List<Framebuffer> _framebuffers { get; }
/// <summary>
/// The default shader for the pipeline.
/// </summary>
protected internal virtual IShader _defaultShader { get; }
/// <summary>
/// Occurs, when the window is loading.
/// </summary>
protected internal virtual void Load()
{
foreach (Framebuffer framebuffer in _framebuffers)
framebuffer.Compile();
}
/// <summary>
/// Occurs, when the window is resizing.
/// </summary>
protected internal virtual void Resize()
{ }
/// <summary>
/// Occurs, when the pipeline was connected to a window.
/// </summary>
protected internal virtual void Activate(GenericWindow window)
{
}
/// <summary>
/// Occurs, when the window is unloading.
/// </summary>
protected internal virtual void Unload()
{
foreach (Framebuffer framebuffer in _framebuffers)
{
framebuffer.Dispose();
}
}
}
/// <summary>
/// Represents a render pipeline.
/// </summary>
/// <typeparam name="TScene">The scene type</typeparam>
public abstract class RenderPipeline<TScene> : RenderPipeline
where TScene : GenericScene
{
/// <summary>
/// The system to render stuff.
/// </summary>
protected internal virtual void Render(ref DrawContext context, TScene scene)
{
context.ActivePipeline = this;
}
}
}