#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 GenericWindow _window { get; private set; } /// /// The framebuffers, that are used in this Pipeline. /// protected virtual List _framebuffers { get; } /// /// The default shader for the pipeline. /// protected internal virtual MaterialShader _defaultShader { get; } = SMRenderer.DefaultMaterialShader; /// /// 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(GenericWindow window) { _window = window; if (!IsInitialized) { Initialization(window); IsInitialized = true; } Activation(window); } /// /// Occurs, when the pipeline was connected to a window. /// protected internal virtual void Activation(GenericWindow window) { } /// /// Occurs, when the pipeline was connected to a window the first time. /// /// protected internal virtual void Initialization(GenericWindow 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); framebuffer.Compile(); return framebuffer; } } /// /// Represents a render pipeline. /// /// The scene type public abstract class RenderPipeline : RenderPipeline where TScene : GenericScene { /// /// The system to render stuff. /// protected internal virtual void Render(ref DrawContext context, TScene scene) { context.ActivePipeline = this; } /// /// Event, that triggers, when the scene in the current window changes. /// /// protected internal virtual void SceneChanged(TScene scene) { } } }