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:
parent
a7c71e7ea1
commit
c6bf5c75bc
16 changed files with 114 additions and 26 deletions
|
|
@ -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>
|
||||
|
|
|
|||
35
SMCode/SM.OGL/Framebuffer/RenderbufferAttachment.cs
Normal file
35
SMCode/SM.OGL/Framebuffer/RenderbufferAttachment.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -44,6 +44,7 @@
|
|||
<Compile Include="Framebuffer\ColorAttachment.cs" />
|
||||
<Compile Include="Framebuffer\Framebuffer.cs" />
|
||||
<Compile Include="Framebuffer\IFramebufferWindow.cs" />
|
||||
<Compile Include="Framebuffer\RenderbufferAttachment.cs" />
|
||||
<Compile Include="GLCustomActions.cs" />
|
||||
<Compile Include="GLDebugging.cs" />
|
||||
<Compile Include="GLObject.cs" />
|
||||
|
|
|
|||
|
|
@ -132,7 +132,19 @@ namespace SM.OGL.Shaders
|
|||
if (mesh.Indices != null)
|
||||
GL.DrawElementsInstanced(mesh.PrimitiveType, 0, DrawElementsType.UnsignedInt, mesh.Indices, amount);
|
||||
else
|
||||
GL.DrawArraysInstanced(mesh.PrimitiveType, 0, mesh.Vertex.Count, amount);
|
||||
GL.DrawArraysInstanced(mesh.PrimitiveType, 0, mesh.Vertex.Count / mesh.Vertex.PointerSize, amount);
|
||||
}
|
||||
/// <summary>
|
||||
/// Draws the mesh while forcing a primitive type instead of using the mesh type.
|
||||
/// </summary>
|
||||
/// <param name="mesh">The mesh.</param>
|
||||
/// <param name="amount">The amounts for instancing.</param>
|
||||
public static void DrawObject(PrimitiveType forcedType, GenericMesh mesh, int amount = 1)
|
||||
{
|
||||
if (mesh.Indices != null)
|
||||
GL.DrawElementsInstanced(forcedType, 0, DrawElementsType.UnsignedInt, mesh.Indices, amount);
|
||||
else
|
||||
GL.DrawArraysInstanced(forcedType, 0, mesh.Vertex.Count / mesh.Vertex.PointerSize, amount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue