From 324eb76930f49b0c03a0d66ade47e72e90fa004e Mon Sep 17 00:00:00 2001 From: Michel Fedde Date: Mon, 22 Mar 2021 13:18:52 +0100 Subject: [PATCH] Missing commit --- SMCode/SM.Base/Window/WindowCode.cs | 2 ++ SMCode/SM.OGL/Framebuffer/Framebuffer.cs | 18 +++++++++++++++--- SM_TEST/TestRenderPipeline.cs | 7 +++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/SMCode/SM.Base/Window/WindowCode.cs b/SMCode/SM.Base/Window/WindowCode.cs index 0389b09..209994b 100644 --- a/SMCode/SM.Base/Window/WindowCode.cs +++ b/SMCode/SM.Base/Window/WindowCode.cs @@ -13,6 +13,7 @@ using SM.Base.Shaders.Extensions; using SM.Base.Time; using SM.Base.Utility; using SM.OGL; +using SM.OGL.Framebuffer; using Keyboard = SM.Base.Controls.Keyboard; using Mouse = SM.Base.Controls.Mouse; @@ -26,6 +27,7 @@ namespace SM.Base.Window { GLSystem.INIT_SYSTEM(); GLSettings.ShaderPreProcessing = true; + Framebuffer.ScreenWindow = window; var args = Environment.GetCommandLineArgs(); if (args.Contains("--advDebugging")) diff --git a/SMCode/SM.OGL/Framebuffer/Framebuffer.cs b/SMCode/SM.OGL/Framebuffer/Framebuffer.cs index cbf5eae..5eefede 100644 --- a/SMCode/SM.OGL/Framebuffer/Framebuffer.cs +++ b/SMCode/SM.OGL/Framebuffer/Framebuffer.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Linq; using OpenTK; using OpenTK.Graphics.OpenGL4; @@ -16,6 +17,8 @@ namespace SM.OGL.Framebuffer { protected override bool AutoCompile { get; set; } = true; + public static IFramebufferWindow ScreenWindow; + /// /// Represents the screen buffer. /// @@ -23,6 +26,8 @@ namespace SM.OGL.Framebuffer { _id = 0, CanCompile = false, + _window = ScreenWindow, + _windowScale = 1, }; private IFramebufferWindow _window; @@ -42,7 +47,7 @@ namespace SM.OGL.Framebuffer public Dictionary ColorAttachments { get; private set; } = new Dictionary(); - public List RenderbufferAttachments { get; } = new List(); + public Dictionary RenderbufferAttachments { get; } = new Dictionary(); /// /// Creates a buffer without any options. @@ -75,6 +80,7 @@ namespace SM.OGL.Framebuffer /// public override void Compile() { + if (_id == 0) _window = ScreenWindow; if (_window != null) Size = new Vector2(_window.Width * _windowScale, _window.Height * _windowScale); base.Compile(); @@ -95,10 +101,11 @@ namespace SM.OGL.Framebuffer GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, pair.Value.FramebufferAttachment, pair.Value.Target, pair.Value.ID, 0); - foreach (RenderbufferAttachment attachment in RenderbufferAttachments) + foreach (RenderbufferAttachment attachment in RenderbufferAttachments.Keys.ToArray()) { int att = attachment.Generate(this); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, attachment.FramebufferAttachment, RenderbufferTarget.Renderbuffer, att); + RenderbufferAttachments[attachment] = att; } var err = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); @@ -114,6 +121,11 @@ namespace SM.OGL.Framebuffer { foreach (var attachment in ColorAttachments.Values) attachment.Dispose(); + foreach (KeyValuePair pair in RenderbufferAttachments.ToArray()) + { + GL.DeleteRenderbuffer(pair.Value); + RenderbufferAttachments[pair.Key] = -1; + } GL.DeleteFramebuffer(this); base.Dispose(); @@ -133,7 +145,7 @@ namespace SM.OGL.Framebuffer public void AppendRenderbuffer(RenderbufferAttachment attachment) { - RenderbufferAttachments.Add(attachment); + RenderbufferAttachments.Add(attachment, -1); } /// diff --git a/SM_TEST/TestRenderPipeline.cs b/SM_TEST/TestRenderPipeline.cs index fe53e1c..0a5c20c 100644 --- a/SM_TEST/TestRenderPipeline.cs +++ b/SM_TEST/TestRenderPipeline.cs @@ -2,6 +2,7 @@ using SM.Base.PostEffects; using SM.Base.Window; using SM.OGL.Framebuffer; +using SM.OGL.Texture; namespace SM_TEST { @@ -13,9 +14,9 @@ namespace SM_TEST public override void Initialization() { - MainFramebuffer = CreateWindowFramebuffer(16); + MainFramebuffer = CreateWindowFramebuffer(0, true, PixelInformation.RGBA_HDR); - _postBuffer = CreateWindowFramebuffer(); + _postBuffer = CreateWindowFramebuffer(0, false, PixelInformation.RGBA_HDR); Framebuffers.Add(_postBuffer); _bloom = new BloomEffect(MainFramebuffer, hdr: true, .5f) { @@ -33,8 +34,10 @@ namespace SM_TEST context.Scene.DrawBackground(context); context.Scene.DrawMainObjects(context); context.Scene.DrawHUD(context); + Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); + _bloom.Draw(context); context.Scene.DrawDebug(context);