Added missing summeries #1

This commit is contained in:
Michel Fedde 2021-03-17 17:09:59 +01:00
parent 03d99ea28e
commit 8665b5b709
104 changed files with 1165 additions and 821 deletions

View file

@ -38,6 +38,9 @@ namespace SM.OGL.Framebuffer
/// </summary>
public DrawBuffersEnum DrawBuffersEnum => DrawBuffersEnum.ColorAttachment0 + AttachmentID;
/// <summary>
/// Returns true, if multisamples are above 0.
/// </summary>
public bool IsMultisampled => _multisamples > 0;
/// <summary>

View file

@ -14,7 +14,7 @@ namespace SM.OGL.Framebuffer
/// </summary>
public class Framebuffer : GLObject
{
protected override bool AutoCompile { get; } = true;
protected override bool AutoCompile { get; set; } = true;
/// <summary>
/// Represents the screen buffer.
@ -22,11 +22,9 @@ namespace SM.OGL.Framebuffer
public static readonly Framebuffer Screen = new Framebuffer
{
_id = 0,
_canBeCompiled = false
CanCompile = false,
};
private bool _canBeCompiled = true;
private IFramebufferWindow _window;
private float _windowScale;
@ -77,8 +75,6 @@ namespace SM.OGL.Framebuffer
/// <inheritdoc />
public override void Compile()
{
if (!_canBeCompiled) return;
if (_window != null) Size = new Vector2(_window.Width * _windowScale, _window.Height * _windowScale);
base.Compile();
@ -181,7 +177,7 @@ namespace SM.OGL.Framebuffer
{
Framebuffer buffer = new Framebuffer()
{
_canBeCompiled = false,
CanCompile = false,
ReportAsNotCompiled = true
};
switch (target)

View file

@ -1,5 +1,8 @@
namespace SM.OGL.Framebuffer
{
/// <summary>
/// A interface, so the framebuffer system can react to changes of windows.
/// </summary>
public interface IFramebufferWindow
{
int Width { get; }

View file

@ -2,15 +2,33 @@
namespace SM.OGL.Framebuffer
{
/// <summary>
/// Describes a renderbuffer attachment.
/// </summary>
public struct RenderbufferAttachment
{
/// <summary>
/// Preset for the depthbuffer attachment.
/// </summary>
public static readonly RenderbufferAttachment Depth = new RenderbufferAttachment(RenderbufferStorage.Depth24Stencil8, FramebufferAttachment.DepthStencilAttachment);
/// <summary>
/// Storage describes the internal format for the renderbuffer.
/// </summary>
public RenderbufferStorage Storage;
/// <summary>
/// FramebufferAttachment describes the attachment for the framebuffer.
/// </summary>
public FramebufferAttachment FramebufferAttachment;
/// <summary>
/// This contains the amount of multisampling for the attachment.
/// </summary>
public int Multisample;
/// <summary>
/// Constructor
/// </summary>
public RenderbufferAttachment(RenderbufferStorage storage, FramebufferAttachment framebufferAttachment, int multisample = 0)
{
Storage = storage;
@ -18,18 +36,23 @@ namespace SM.OGL.Framebuffer
Multisample = multisample;
}
/// <summary>
/// This generates the renderbuffer for the framebuffer to add.
/// </summary>
/// <param name="f">The framebuffer</param>
/// <returns>The ID of the renderbuffer.</returns>
public int Generate(Framebuffer f)
{
int rbo = GL.GenRenderbuffer();
int rb = GL.GenRenderbuffer();
GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, rbo);
GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, rb);
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;
return rb;
}
}
}

View file

@ -1,9 +1,8 @@
#region usings
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using OpenTK.Audio;
using OpenTK.Graphics.OpenGL4;
#endregion
@ -16,6 +15,7 @@ namespace SM.OGL
public abstract class GLObject
{
private static List<GLObject> _disposableObjects = new List<GLObject>();
private string _name = "";
protected bool ReportAsNotCompiled;
@ -23,17 +23,29 @@ namespace SM.OGL
/// Contains the OpenGL ID
/// </summary>
protected int _id = -1;
protected bool CanCompile = true;
/// <summary>
/// If true, the system will call "Compile()", when "ID" is tried to get, but the id is still -1.
/// </summary>
protected virtual bool AutoCompile { get; } = false;
protected virtual bool AutoCompile { get; set; } = false;
/// <summary>
/// Checks if the object was compiled.
/// </summary>
public bool WasCompiled => _id > 0 && !ReportAsNotCompiled;
public string Name
{
get => _name;
set
{
_name = value;
if (GLSystem.Debugging && WasCompiled) GL.ObjectLabel(TypeIdentifier, _id, _name.Length, _name);
}
}
/// <summary>
/// Returns the id for this object.
/// <para>It will auto compile, if needed and allowed.</para>
@ -55,7 +67,21 @@ namespace SM.OGL
[DebuggerStepThrough]
private void PerformCompile()
{
if (!CanCompile) return;
Compile();
if (GLSystem.Debugging && string.IsNullOrEmpty(_name))
{
try
{
GL.ObjectLabel(TypeIdentifier, _id, _name.Length, _name);
}
catch
{
// ignore
}
}
}
/// <summary>
@ -85,13 +111,9 @@ namespace SM.OGL
Compile();
}
/// <summary>
/// Names the object for debugging.
/// </summary>
/// <param name="name"></param>
public void Name(string name)
public override string ToString()
{
if (GLSystem.Debugging) GL.ObjectLabel(TypeIdentifier, _id, name.Length, name);
return $"{GetType().Name} {(string.IsNullOrEmpty(_name) ? "" : $"\"{_name}\" ")}[{_id}]";
}
public static void DisposeMarkedObjects()

View file

@ -2,7 +2,6 @@
using System;
using OpenTK;
using OpenTK.Graphics.OpenGL;
#endregion

View file

@ -1,7 +1,6 @@
#region usings
using System;
using System.Collections.Generic;
using OpenTK.Graphics.OpenGL4;
#endregion
@ -17,21 +16,8 @@ namespace SM.OGL.Mesh
public static int LastID { get; internal set; } = -1;
/// <summary>
/// Generates the AttribDataIndex
/// </summary>
protected GenericMesh()
{
Attributes = new MeshAttributeList()
{
{0, "vertex", Vertex},
{1, "uv", UVs},
{2, "normal", Normals}
};
}
/// <inheritdoc />
protected override bool AutoCompile { get; } = true;
protected override bool AutoCompile { get; set; } = true;
/// <inheritdoc />
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.VertexArray;
@ -72,6 +58,19 @@ namespace SM.OGL.Mesh
/// </summary>
public virtual int[] Indices { get; set; }
/// <summary>
/// Generates the AttribDataIndex
/// </summary>
protected GenericMesh()
{
Attributes = new MeshAttributeList()
{
{0, "vertex", Vertex},
{1, "uv", UVs},
{2, "normal", Normals}
};
}
public void UpdateBoundingBox()
{
BoundingBox.Update(this);

View file

@ -1,7 +1,13 @@
namespace SM.OGL.Mesh
{
/// <summary>
/// Represents a mesh that can be a line object.
/// </summary>
public interface ILineMesh
{
/// <summary>
/// The width of a line.
/// </summary>
float LineWidth { get; set; }
}
}

View file

@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using OpenTK.Graphics.OpenGL;
using System.Collections.Generic;
namespace SM.OGL.Mesh
{

View file

@ -40,6 +40,10 @@ namespace SM.OGL.Mesh
/// </summary>
public int PointerStride;
/// <summary>
/// The VBO gets ignored when true.
/// <para>Default: true</para>
/// </summary>
public bool Active = true;
/// <summary>

View file

@ -1,7 +1,6 @@
#region usings
using System;
using System.Linq;
using OpenTK.Graphics.OpenGL4;
using SM.OGL.Mesh;
@ -15,7 +14,7 @@ namespace SM.OGL.Shaders
public abstract class GenericShader : GLObject
{
/// <inheritdoc />
protected override bool AutoCompile { get; } = true;
protected override bool AutoCompile { get; set; } = true;
/// <summary>
/// Contains the different files for the shader.
@ -97,7 +96,6 @@ namespace SM.OGL.Shaders
ShaderFileFiles.Append(this);
GL.LinkProgram(_id);
Name(GetType().Name);
ShaderFileFiles.Detach(this);
Uniforms = new UniformCollection {ParentShader = this};

View file

@ -80,6 +80,7 @@ namespace SM.OGL.Shaders
for (var i = 0; i < GLSLExtensions.Count; i++) GLSLExtensions[i].Compile(shader, type);
}
/// <inheritdoc />
public override void Dispose()
{
GL.DeleteShader(this);

View file

@ -51,6 +51,12 @@ namespace SM.OGL.Shaders
Fragment = new []{fragment};
}
/// <summary>
/// Creates a collection with arrays of shader files.
/// </summary>
/// <param name="vertex"></param>
/// <param name="fragment"></param>
/// <param name="geometry"></param>
public ShaderFileCollection(ShaderFile[] vertex, ShaderFile[] fragment, ShaderFile[] geometry = default)
{
Vertex = vertex;

View file

@ -1,5 +1,4 @@
using System.Collections.Generic;
using OpenTK.Graphics.OpenGL;
namespace SM.OGL.Shaders
{

View file

@ -2,17 +2,47 @@
namespace SM.OGL.Texture
{
/// <summary>
/// Stores information how pixels are stored in textures.
/// </summary>
public struct PixelInformation
{
/// <summary>
/// RGB without Alpha channel, Low Dynamic Range (0 - 1)
/// </summary>
public static PixelInformation RGB_LDR = new PixelInformation(PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.UnsignedByte);
/// <summary>
/// RGB without Alpha channel, High Dynamic Range (0 - n)
/// </summary>
public static PixelInformation RGB_HDR = new PixelInformation(PixelInternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.Float);
/// <summary>
/// RGB with Alpha channel, Low Dynamic Range (0 - 1)
/// </summary>
public static PixelInformation RGBA_LDR = new PixelInformation(PixelInternalFormat.Rgba, PixelFormat.Rgba, PixelType.UnsignedByte);
/// <summary>
/// RGB with Alpha channel, High Dynamic Range (0 - n)
/// </summary>
public static PixelInformation RGBA_HDR = new PixelInformation(PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.Float);
/// <summary>
/// The internal format of the pixels.
/// </summary>
public PixelInternalFormat InternalFormat { get; }
/// <summary>
/// The format of the pixels.
/// </summary>
public PixelFormat Format { get; }
/// <summary>
/// The data type of the pixels,
/// </summary>
public PixelType DataType { get; }
/// <summary>
/// The constructor
/// </summary>
/// <param name="internalFormat"></param>
/// <param name="format"></param>
/// <param name="dataType"></param>
public PixelInformation(PixelInternalFormat internalFormat, PixelFormat format, PixelType dataType)
{
InternalFormat = internalFormat;

View file

@ -12,14 +12,20 @@ namespace SM.OGL.Texture
public abstract class TextureBase : GLObject
{
/// <inheritdoc />
protected override bool AutoCompile { get; } = true;
protected override bool AutoCompile { get; set; } = true;
/// <inheritdoc />
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Texture;
/// <summary>
/// Contains the specific information of each pixel.
/// </summary>
public PixelInformation PixelInformation;
/// <summary>
/// The target of the texture.
/// </summary>
public TextureTarget Target { get; set; } = TextureTarget.Texture2D;
/// <summary>
@ -44,6 +50,7 @@ namespace SM.OGL.Texture
/// </summary>
public virtual int Height { get; protected set; }
/// <inheritdoc />
public override void Dispose()
{
GL.DeleteTexture(_id);