Improved PostProcessing System

This commit is contained in:
Michel Fedde 2020-12-13 16:13:00 +01:00
parent 0ab7f29b06
commit e4e7db8dc0
10 changed files with 181 additions and 6 deletions

View file

@ -1,6 +1,7 @@
#region usings
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenTK;
@ -27,7 +28,8 @@ namespace SM.Base
/// </summary>
public abstract class GenericWindow : GameWindow
{
private bool _loading;
internal bool _loading = true;
internal List<Action> _actionsAfterLoading = new List<Action>();
/// <summary>
/// This tells you the current world scale.
@ -95,7 +97,6 @@ namespace SM.Base
ExtensionManager.InitExtensions();
base.OnLoad(e);
_loading = true;
}
/// <inheritdoc />
@ -111,6 +112,10 @@ namespace SM.Base
if (_loading)
{
_loading = false;
_actionsAfterLoading.ForEach(a => a());
_actionsAfterLoading = null;
OnLoaded();
}
}
@ -284,7 +289,8 @@ namespace SM.Base
ViewportCamera.RecalculateWorld(_worldScale, Aspect);
RenderPipeline.Resize();
PostProcessEffect.Mvp = Matrix4.CreateScale(_worldScale.X, -_worldScale.Y, 1) *
PostProcessEffect.Model = Matrix4.CreateScale(_worldScale.X, -_worldScale.Y, 1);
PostProcessEffect.Mvp = PostProcessEffect.Model *
Matrix4.LookAt(0, 0, 1, 0, 0, 0, 0, 1, 0) *
GenericCamera.OrthographicWorld;
}
@ -295,8 +301,15 @@ namespace SM.Base
/// <param name="scene"></param>
public virtual void SetScene(TScene scene)
{
if (_loading)
{
_actionsAfterLoading.Add(() => SetScene(scene));
return;
}
CurrentScene = scene;
scene.Activate();
RenderPipeline.SceneChanged(scene);
}
/// <summary>
@ -305,6 +318,12 @@ namespace SM.Base
/// <param name="pipeline"></param>
public void SetRenderPipeline(RenderPipeline<TScene> pipeline)
{
if (_loading)
{
_actionsAfterLoading.Add(() => SetRenderPipeline(pipeline));
return;
}
RenderPipeline = pipeline;
pipeline.Activate(this);
}

View file

@ -16,6 +16,10 @@ namespace SM.Base
/// </summary>
public abstract class RenderPipeline
{
public bool IsInitialized { get; private set; } = false;
protected GenericWindow _window { get; private set; }
/// <summary>
/// The framebuffers, that are used in this Pipeline.
/// </summary>
@ -51,19 +55,46 @@ namespace SM.Base
}
}
internal void Activate(GenericWindow window)
{
_window = window;
if (!IsInitialized)
{
Initialization(window);
IsInitialized = true;
}
Activation(window);
}
/// <summary>
/// Occurs, when the pipeline was connected to a window.
/// </summary>
protected internal virtual void Activate(GenericWindow window)
protected internal virtual void Activation(GenericWindow window)
{
}
protected internal virtual void Initialization(GenericWindow window)
{
}
/// <summary>
/// Occurs, when the window is unloading.
/// </summary>
protected internal virtual void Unload()
{
}
protected Framebuffer CreateWindowFramebuffer()
{
Framebuffer framebuffer = new Framebuffer(window: _window);
framebuffer.Append("color", 0);
framebuffer.Compile();
return framebuffer;
}
}
/// <summary>
@ -80,5 +111,10 @@ namespace SM.Base
{
context.ActivePipeline = this;
}
protected internal virtual void SceneChanged(TScene scene)
{
}
}
}