2021-04-03

+ Added Field to DrawingBasis to enfore PrimitiveTypes
+ LastObject to context for Debugging
+ AppendRenderbuffer to Framebuffer

~ Added a depthbuffer to RenderPipeline.CreateWindowFramebuffer
~ Proper ZIndices over Z-Translation and DepthBuffer
~ Made "ShaderArguments["LineWidth"]" set the LineWidth even if the object isn't maked as LineMesh
~ Made that the SM2D.PolygonVertex can translate OpenTK.Vector2 by itself.
~ Made the SM2D.Transformation.ZIndex a CVector1 instead a float
This commit is contained in:
Michel Fedde 2021-03-04 22:17:03 +01:00
parent a7c71e7ea1
commit c6bf5c75bc
16 changed files with 114 additions and 26 deletions

View file

@ -30,6 +30,22 @@ namespace SM.OGL.Framebuffer
private IFramebufferWindow _window;
private float _windowScale;
/// <inheritdoc />
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Framebuffer;
/// <summary>
/// Contains the size of the framebuffer.
/// </summary>
public Vector2 Size { get; private set; }
/// <summary>
/// Contains all color attachments.
/// </summary>
public Dictionary<string, ColorAttachment> ColorAttachments { get; private set; } =
new Dictionary<string, ColorAttachment>();
public List<RenderbufferAttachment> RenderbufferAttachments { get; } = new List<RenderbufferAttachment>();
/// <summary>
/// Creates a buffer without any options.
/// </summary>
@ -58,20 +74,6 @@ namespace SM.OGL.Framebuffer
Size = size;
}
/// <inheritdoc />
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Framebuffer;
/// <summary>
/// Contains the size of the framebuffer.
/// </summary>
public Vector2 Size { get; private set; }
/// <summary>
/// Contains all color attachments.
/// </summary>
public Dictionary<string, ColorAttachment> ColorAttachments { get; private set; } =
new Dictionary<string, ColorAttachment>();
/// <inheritdoc />
public override void Compile()
{
@ -97,6 +99,12 @@ namespace SM.OGL.Framebuffer
GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, pair.Value.FramebufferAttachment, pair.Value.Target, pair.Value.ID,
0);
foreach (RenderbufferAttachment attachment in RenderbufferAttachments)
{
int att = attachment.Generate(this);
GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, attachment.FramebufferAttachment, RenderbufferTarget.Renderbuffer, att);
}
var err = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
if (err != FramebufferErrorCode.FramebufferComplete)
throw new Exception("Failed loading framebuffer.\nProblem: " + err);
@ -125,6 +133,11 @@ namespace SM.OGL.Framebuffer
ColorAttachments.Add(key, value);
}
public void AppendRenderbuffer(RenderbufferAttachment attachment)
{
RenderbufferAttachments.Add(attachment);
}
/// <summary>
/// Activates the framebuffer without clearing the buffer.
/// </summary>

View file

@ -0,0 +1,35 @@
using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Framebuffer
{
public struct RenderbufferAttachment
{
public static readonly RenderbufferAttachment Depth = new RenderbufferAttachment(RenderbufferStorage.Depth24Stencil8, FramebufferAttachment.DepthStencilAttachment);
public RenderbufferStorage Storage;
public FramebufferAttachment FramebufferAttachment;
public int Multisample;
public RenderbufferAttachment(RenderbufferStorage storage, FramebufferAttachment framebufferAttachment, int multisample = 0)
{
Storage = storage;
FramebufferAttachment = framebufferAttachment;
Multisample = multisample;
}
public int Generate(Framebuffer f)
{
int rbo = GL.GenRenderbuffer();
GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, rbo);
if (Multisample != 0)
GL.RenderbufferStorageMultisample(RenderbufferTarget.Renderbuffer, Multisample, Storage, (int)f.Size.X, (int)f.Size.Y);
else
GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, Storage, (int)f.Size.X, (int)f.Size.Y);
GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0);
return rbo;
}
}
}