#region usings
using System.Collections.Generic;
using System.Threading;
using SM.Base.Drawing;
using SM.Base.Shaders;
using SM.Base.Utility;
using SM.OGL.Framebuffer;
using SM.OGL.Texture;
#endregion
namespace SM.Base.Window
{
///
/// This represents a render pipeline.
///
public abstract class RenderPipeline : IInitializable
{
///
/// This contains the windows its connected to.
///
public IGenericWindow ConnectedWindow { get; internal set; }
///
/// This should contains the framebuffer, when any back buffer effects are used.
///
public Framebuffer MainFramebuffer { get; protected set; }
///
/// This list contains all framebuffers that are required to update.
///
public List Framebuffers { get; } = new List();
///
/// This contains the default shader.
/// Default:
///
public virtual MaterialShader DefaultShader { get; protected set; }
///
/// Here you can set a default material.
///
public virtual Material DefaultMaterial { get; protected set; }
///
public bool IsInitialized { get; set; }
///
public virtual void Activate()
{
}
///
public virtual void Initialization()
{
if (MainFramebuffer != null) {
Framebuffers.Add(MainFramebuffer);
MainFramebuffer.Name = GetType().Name + ".MainFramebuffer";
}
DefaultShader ??= SMRenderer.DefaultMaterialShader;
}
internal void Render(ref DrawContext context)
{
RenderProcess(ref context);
}
///
/// The process of rendering.
///
protected abstract void RenderProcess(ref DrawContext context);
///
/// The event when resizing.
///
public virtual void Resize()
{
if (Framebuffers == null) return;
foreach (var framebuffer in Framebuffers)
framebuffer.Dispose();
Thread.Sleep(50);
foreach (var framebuffer in Framebuffers)
framebuffer.Compile();
}
///
/// This creates a finished setup for a framebuffer.
///
///
///
public Framebuffer CreateWindowFramebuffer(int multisamples = 0)
{
Framebuffer framebuffer = new Framebuffer(ConnectedWindow);
framebuffer.Append("color", new ColorAttachment(0, PixelInformation.RGBA_LDR, multisamples));
RenderbufferAttachment depthAttach = RenderbufferAttachment.Depth;
depthAttach.Multisample = multisamples;
framebuffer.AppendRenderbuffer(depthAttach);
return framebuffer;
}
}
}