05.01.2021

+ Bloom effect
+ PixelInformation
+ Many Summaries
+ Add-methods for CVectors
+ Exposure-Field in GenericCamera for HDR.

~ ColorAttachments now can have PixelInformation
~ Transformed MeshAttributes to a own class
~ Fixed the non-applying of transformations at texts
~ Added more information to the context
~ Improved Pipeline-Process.
~ Changed how Uniform takes arrays

- Light system
This commit is contained in:
Michel Fedde 2021-01-06 17:04:15 +01:00
parent 9b917ac181
commit 4c18127c88
52 changed files with 697 additions and 373 deletions

View file

@ -8,31 +8,64 @@ using SM.OGL.Texture;
namespace SM.OGL.Framebuffer
{
/// <summary>
/// Represents a Framebuffer-Color Attachment.
/// <para>Can be use like a texture.</para>
/// </summary>
public class ColorAttachment : TextureBase
{
public ColorAttachment(int attachmentId)
/// <summary>
/// Creates a attachment with a specific id.
/// </summary>
/// <param name="attachmentId"></param>
public ColorAttachment(int attachmentId) : this(attachmentId, PixelInformation.RGBA_LDR)
{ }
public ColorAttachment(int attachmentID, PixelInformation pixelInformation)
{
AttachmentID = attachmentId;
AttachmentID = attachmentID;
PixelInformation = pixelInformation;
}
/// <summary>
/// The ID the attachment was given.
/// </summary>
public int AttachmentID { get; }
/// <summary>
/// Returns the <see cref="OpenTK.Graphics.OpenGL4.FramebufferAttachment"/> of this ColorAttachment.
/// </summary>
public FramebufferAttachment FramebufferAttachment => FramebufferAttachment.ColorAttachment0 + AttachmentID;
/// <summary>
/// Returns the <see cref="OpenTK.Graphics.OpenGL4.DrawBufferMode"/> of this ColorAttachment.
/// </summary>
public DrawBufferMode DrawBufferMode => DrawBufferMode.ColorAttachment0 + AttachmentID;
/// <summary>
/// Returns the <see cref="OpenTK.Graphics.OpenGL4.ReadBufferMode"/> of this ColorAttachment.
/// </summary>
public ReadBufferMode ReadBufferMode => ReadBufferMode.ColorAttachment0 + AttachmentID;
/// <summary>
/// Returns the <see cref="OpenTK.Graphics.OpenGL4.DrawBuffersEnum"/> of this ColorAttachment.
/// </summary>
public DrawBuffersEnum DrawBuffersEnum => DrawBuffersEnum.ColorAttachment0 + AttachmentID;
/// <summary>
/// Generates the attachment.
/// </summary>
/// <param name="f"></param>
public void Generate(Framebuffer f)
{
_id = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, _id);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8,
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInformation.InternalFormat,
(int) f.Size.X, (int) f.Size.Y,
0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero);
0, PixelInformation.Format, PixelInformation.DataType, IntPtr.Zero);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
(int) TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter,
(int) TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS,
(int) TextureParameterName.ClampToEdge);

View file

@ -9,9 +9,14 @@ using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Framebuffer
{
// TODO: Write summeries for framebuffer-system.
/// <summary>
/// Represents a OpenGL Framebuffer.
/// </summary>
public class Framebuffer : GLObject
{
/// <summary>
/// Represents the screen buffer.
/// </summary>
public static readonly Framebuffer Screen = new Framebuffer
{
_id = 0,
@ -23,10 +28,18 @@ namespace SM.OGL.Framebuffer
private INativeWindow _window;
private float _windowScale;
/// <summary>
/// Creates a buffer without any options.
/// </summary>
public Framebuffer()
{
}
/// <summary>
/// Creates a buffer, while always respecting the screen.
/// </summary>
/// <param name="window"></param>
/// <param name="scale"></param>
public Framebuffer(INativeWindow window, float scale = 1) : this(new Vector2(window.Width * scale,
window.Height * scale))
{
@ -34,18 +47,30 @@ namespace SM.OGL.Framebuffer
_windowScale = scale;
}
/// <summary>
/// Creates a buffer, with a specified size.
/// </summary>
/// <param name="size"></param>
public Framebuffer(Vector2 size)
{
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()
{
if (!_canBeCompiled) return;
@ -78,6 +103,7 @@ namespace SM.OGL.Framebuffer
GL.BindTexture(TextureTarget.Texture2D, 0);
}
/// <inheritdoc />
public override void Dispose()
{
base.Dispose();
@ -85,32 +111,76 @@ namespace SM.OGL.Framebuffer
GL.DeleteFramebuffer(this);
}
/// <summary>
/// Appends a color attachment.
/// </summary>
public void Append(string key, int pos) => Append(key, new ColorAttachment(pos));
/// <summary>
/// Appends a color attachment.
/// </summary>
public void Append(string key, ColorAttachment value)
{
ColorAttachments.Add(key, value);
}
/// <summary>
/// Activates the framebuffer without clearing the buffer.
/// </summary>
public void Activate()
{
Activate(FramebufferTarget.Framebuffer, ClearBufferMask.None);
}
/// <summary>
/// Activates the framebuffer for the specific target framebuffer and without clearing.
/// </summary>
/// <param name="target"></param>
public void Activate(FramebufferTarget target)
{
Activate(target, ClearBufferMask.None);
}
/// <summary>
/// Activates the framebuffer while clearing the specified buffer.
/// </summary>
/// <param name="clearMask"></param>
public void Activate(ClearBufferMask clearMask)
{
Activate(FramebufferTarget.Framebuffer, clearMask);
}
/// <summary>
/// Activates the framebuffer for the specific target and with clearing.
/// </summary>
/// <param name="target"></param>
/// <param name="clear"></param>
public void Activate(FramebufferTarget target, ClearBufferMask clear)
{
GL.BindFramebuffer(target, this);
GL.Clear(clear);
}
public static Framebuffer GetCurrentlyActive(FramebufferTarget target = FramebufferTarget.Framebuffer)
{
Framebuffer buffer = new Framebuffer()
{
_canBeCompiled = false,
};
switch (target)
{
case FramebufferTarget.ReadFramebuffer:
GL.GetInteger(GetPName.ReadFramebufferBinding, out buffer._id);
break;
case FramebufferTarget.DrawFramebuffer:
GL.GetInteger(GetPName.DrawFramebufferBinding, out buffer._id);
break;
case FramebufferTarget.Framebuffer:
GL.GetInteger(GetPName.FramebufferBinding, out buffer._id);
break;
}
return buffer;
}
}
}