#region usings using System.Collections.Generic; using System.Threading; using SM.Base.Contexts; using SM.Base.Drawing; using SM.Base.Scene; using SM.OGL.Framebuffer; #endregion namespace SM.Base { /// /// Definition of specific render options. /// public abstract class RenderPipeline { /// /// If true, this pipeline was already once activated. /// public bool IsInitialized { get; private set; } = false; /// /// The window the pipeline is connected to. /// protected IGenericWindow _window { get; private set; } /// /// The framebuffers, that are used in this Pipeline. /// public virtual List Framebuffers { get; private set; } /// /// The default shader for the pipeline. /// protected internal virtual MaterialShader _defaultShader { get; set; } public virtual Framebuffer MainFramebuffer { get; protected set; }= Framebuffer.Screen; /// /// Occurs, when the window is loading. /// protected internal virtual void Load() { } /// /// Occurs, when the window is resizing. /// protected internal virtual void Resize() { if (Framebuffers == null) return; foreach (var framebuffer in Framebuffers) framebuffer.Dispose(); Thread.Sleep(50); foreach (Framebuffer framebuffer in Framebuffers) { framebuffer.Compile(); } } internal void Activate(IGenericWindow window) { _window = window; if (!IsInitialized) { if (_defaultShader == null) _defaultShader = SMRenderer.DefaultMaterialShader; Framebuffers = new List(); Initialization(window); Framebuffers.Add(MainFramebuffer); IsInitialized = true; } Activation(window); } /// /// Occurs, when the pipeline was connected to a window. /// protected internal virtual void Activation(IGenericWindow window) { } /// /// Occurs, when the pipeline was connected to a window the first time. /// /// protected internal virtual void Initialization(IGenericWindow window) { } /// /// Occurs, when the window is unloading. /// protected internal virtual void Unload() { } /// /// Creates a framebuffer, that has specific (often) required settings already applied. /// /// public static Framebuffer CreateWindowFramebuffer() { Framebuffer framebuffer = new Framebuffer(window: SMRenderer.CurrentWindow); framebuffer.Append("color", 0); return framebuffer; } } /// /// Represents a render pipeline. /// /// The scene type public abstract class RenderPipeline : RenderPipeline where TScene : GenericScene { /// /// The system to render stuff. /// internal void Render(ref DrawContext context) { context.ActivePipeline = this; if (context.ActiveScene == null) return; RenderProcess(ref context, (TScene)context.ActiveScene); } protected abstract void RenderProcess(ref DrawContext context, TScene scene); /// /// Event, that triggers, when the scene in the current window changes. /// /// protected internal virtual void SceneChanged(TScene scene) { } } }