diff --git a/.gitignore b/.gitignore
index 4ce6fdd..731df43 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,6 +26,7 @@ bld/
[Bb]in/
[Oo]bj/
[Ll]og/
+build/*
# Visual Studio 2015/2017 cache/options directory
.vs/
diff --git a/SMCode/SM.Base/Controls/Mouse.cs b/SMCode/SM.Base/Controls/Mouse.cs
index 19e5061..e3cfece 100644
--- a/SMCode/SM.Base/Controls/Mouse.cs
+++ b/SMCode/SM.Base/Controls/Mouse.cs
@@ -28,6 +28,18 @@ namespace SM.Base.Controls
///
public static Vector2 InScreenNormalized { get; private set; }
+ ///
+ /// This returns true, if the left mouse button was pressed.
+ /// Its pretty much: IsDown(MouseButton.Left, true)
+ ///
+ public static bool LeftClick => IsDown(MouseButton.Left, true);
+
+ ///
+ /// This returns true, if the right mouse button was pressed.
+ /// Its pretty much: IsDown(MouseButton.Right, true)
+ ///
+ public static bool RightClick => IsDown(MouseButton.Right, true);
+
///
/// The event to update the values.
///
@@ -53,11 +65,21 @@ namespace SM.Base.Controls
_mouseState = OpenTK.Input.Mouse.GetState();
}
+ ///
+ /// Checks if the mouse is pressed.
+ ///
+ ///
+ /// If true, it will not get called, when it was pressed in the last update.
public static bool IsDown(MouseButton button, bool once = false)
{
return _mouseState?[button] == true && !(once && _lastButtonsPressed.Contains(button));
}
+ ///
+ /// Checks if the mouse is not pressed.
+ ///
+ ///
+ /// If true, it will not get called, when it was not pressed in the last update.
public static bool IsUp(MouseButton button, bool once = false)
{
return _mouseState?[button] == false && !(once && !_lastButtonsPressed.Contains(button));
diff --git a/SMCode/SM.Base/Drawing/DrawingBasis.cs b/SMCode/SM.Base/Drawing/DrawingBasis.cs
index e7716b0..1cd76ce 100644
--- a/SMCode/SM.Base/Drawing/DrawingBasis.cs
+++ b/SMCode/SM.Base/Drawing/DrawingBasis.cs
@@ -55,6 +55,7 @@ namespace SM.Base.Drawing
///
public bool Active { get; set; } = true;
+ ///
public bool RenderActive { get; set; } = true;
///
diff --git a/SMCode/SM.Base/SM.Base.csproj b/SMCode/SM.Base/SM.Base.csproj
index f5f1d37..ee29747 100644
--- a/SMCode/SM.Base/SM.Base.csproj
+++ b/SMCode/SM.Base/SM.Base.csproj
@@ -34,19 +34,10 @@
latest
-
- ..\..\packages\OpenTK.GLWpfControl.3.2.3\lib\net452\GLWpfControl.dll
-
..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll
-
- ..\..\packages\SharpDX.4.2.0\lib\net45\SharpDX.dll
-
-
- ..\..\packages\SharpDX.XInput.4.2.0\lib\net45\SharpDX.XInput.dll
-
diff --git a/SMCode/SM.Base/Scene/GenericItemCollection.cs b/SMCode/SM.Base/Scene/GenericItemCollection.cs
index c3a3076..ead3352 100644
--- a/SMCode/SM.Base/Scene/GenericItemCollection.cs
+++ b/SMCode/SM.Base/Scene/GenericItemCollection.cs
@@ -15,8 +15,8 @@ namespace SM.Base.Scene
///
public abstract class GenericItemCollection : List, IShowItem, IShowCollection, IScriptable, IFixedScriptable
{
- private List _scriptableObjects = new List();
- private List _fixedScriptables = new List();
+ private readonly List _scriptableObjects = new List();
+ private readonly List _fixedScriptables = new List();
///
/// Currently active script objects.
@@ -45,6 +45,7 @@ namespace SM.Base.Scene
///
public bool RenderActive { get; set; } = true;
+ ///
public virtual void FixedUpdate(FixedUpdateContext context)
{
if (!Active || !UpdateActive) return;
@@ -126,6 +127,11 @@ namespace SM.Base.Scene
if (item is IFixedScriptable fs) _fixedScriptables.Add(fs);
}
+ ///
+ /// Removes an object from the drawing list.
+ /// If the object is a scriptable object, it will remove the object from that list as well.
+ ///
+ ///
public void Remove(params IShowItem[] items)
{
foreach (var item in items)
@@ -161,6 +167,12 @@ namespace SM.Base.Scene
if (item is IFixedScriptable fs) _fixedScriptables.Remove(fs);
}
+ ///
+ /// Returns all objects in the drawing list.
+ /// Not reclusive.
+ ///
+ /// If true, it will add collections as well.
+ ///
public ICollection GetAllItems(bool includeCollections = false)
{
List items = new List();
@@ -224,7 +236,6 @@ namespace SM.Base.Scene
///
/// Contains a list of show items with transformation.
///
- /// The type of show items.
/// The type of transformation.
public abstract class GenericItemCollection : GenericItemCollection,
IShowTransformItem
diff --git a/SMCode/SM.Base/Scene/GenericScene.cs b/SMCode/SM.Base/Scene/GenericScene.cs
index bda2ee8..5bd3c1e 100644
--- a/SMCode/SM.Base/Scene/GenericScene.cs
+++ b/SMCode/SM.Base/Scene/GenericScene.cs
@@ -213,18 +213,24 @@ namespace SM.Base.Scene
/// A generic scene that imports different functions.
///
/// The type of cameras.
- /// The type of show items.
/// The type for collections
public abstract class GenericScene : GenericScene
where TCamera : GenericCamera, new()
where TCollection : GenericItemCollection, new()
{
+ ///
+ /// Objects inside the scene, but as the collection type.
+ ///
public new TCollection Objects
{
get => (TCollection) base.Objects;
set => base.Objects = value;
}
+
+ ///
+ /// HUD-Objects inside the scene, but as the collection type.
+ ///
public new TCollection HUD
{
get
@@ -235,18 +241,28 @@ namespace SM.Base.Scene
set => base.HUD = value;
}
+ ///
+ /// The active camera, that is used if the context doesn't force the viewport camera.
+ /// If none set, it automaticly uses the viewport camera.
+ ///
public new TCamera Camera
{
get => (TCamera) base.Camera;
set => base.Camera = value;
}
+ ///
+ /// A camera to control the HUD.
+ ///
public new TCamera HUDCamera
{
get => (TCamera) base.HUDCamera;
set => base.HUDCamera = value;
}
+ ///
+ /// A camera to control the background.
+ ///
public new TCamera BackgroundCamera
{
get => (TCamera) base.BackgroundCamera;
diff --git a/SMCode/SM.Base/Scene/IShowItem.cs b/SMCode/SM.Base/Scene/IShowItem.cs
index 899f9e6..2878da3 100644
--- a/SMCode/SM.Base/Scene/IShowItem.cs
+++ b/SMCode/SM.Base/Scene/IShowItem.cs
@@ -55,19 +55,36 @@ namespace SM.Base.Scene
void OnRemoved(object sender);
}
+ ///
+ /// Interface to implement transformation.
+ ///
+ ///
public interface ITransformItem
where TTransform : GenericTransformation
{
+ ///
+ /// Controls the transformation of the object.
+ ///
TTransform Transform { get; set; }
}
+ ///
+ /// Merges and .
+ ///
+ ///
public interface IShowTransformItem : IShowItem, ITransformItem
where TTransform : GenericTransformation
{
}
+ ///
+ /// Interface to implement models in the object.
+ ///
public interface IModelItem
{
+ ///
+ /// The mesh the rendering should use.
+ ///
GenericMesh Mesh { get; set; }
}
}
\ No newline at end of file
diff --git a/SMCode/SM.Base/Types/CVector1.cs b/SMCode/SM.Base/Types/CVector1.cs
index a4c3b42..2125112 100644
--- a/SMCode/SM.Base/Types/CVector1.cs
+++ b/SMCode/SM.Base/Types/CVector1.cs
@@ -96,7 +96,6 @@ namespace SM.Base.Types
///
/// Conversion from to One-dimensional Vector.
///
- ///
///
//public static implicit operator CVector1(float f) => new CVector1(f);
protected virtual float GetLengthProcess()
@@ -104,14 +103,27 @@ namespace SM.Base.Types
return X * X;
}
+ ///
+ /// Normalizes the vector.
+ ///
+ ///
protected virtual void NormalizationProcess(float length)
{
X *= length;
}
+ ///
+ /// This triggers the event.
+ ///
protected void TriggerChanged()
{
Changed?.Invoke();
}
+
+ ///
+ public override string ToString()
+ {
+ return X.ToString();
+ }
}
}
\ No newline at end of file
diff --git a/SMCode/SM.Base/Types/CVector2.cs b/SMCode/SM.Base/Types/CVector2.cs
index 270d810..6d1a8b1 100644
--- a/SMCode/SM.Base/Types/CVector2.cs
+++ b/SMCode/SM.Base/Types/CVector2.cs
@@ -46,6 +46,12 @@ namespace SM.Base.Types
Y *= length;
}
+ ///
+ public override string ToString()
+ {
+ return "{"+X+"; "+Y+"}";
+ }
+
///
/// Sets each component to the same value
///
@@ -58,7 +64,6 @@ namespace SM.Base.Types
///
/// Sets each component to the counter-part.
///
- ///
public void Set(Vector2 vector, bool triggerChanged = true)
{
Set(vector.X, vector.Y, triggerChanged);
@@ -67,8 +72,6 @@ namespace SM.Base.Types
///
/// Sets the a own value to each component.
///
- ///
- ///
public void Set(float x, float y, bool triggerChanged = true)
{
Y = y;
diff --git a/SMCode/SM.Base/Types/CVector3.cs b/SMCode/SM.Base/Types/CVector3.cs
index 9e43c02..58b881e 100644
--- a/SMCode/SM.Base/Types/CVector3.cs
+++ b/SMCode/SM.Base/Types/CVector3.cs
@@ -46,6 +46,12 @@ namespace SM.Base.Types
Z *= length;
}
+ ///
+ public override string ToString()
+ {
+ return "{" + X + "; " + Y + "}";
+ }
+
///
public override void Set(float uniform, bool triggerChanged = true)
{
diff --git a/SMCode/SM.Base/Window/Contexts/UpdateContext.cs b/SMCode/SM.Base/Window/Contexts/UpdateContext.cs
index 39d9084..c56d4a8 100644
--- a/SMCode/SM.Base/Window/Contexts/UpdateContext.cs
+++ b/SMCode/SM.Base/Window/Contexts/UpdateContext.cs
@@ -6,12 +6,24 @@ using SM.Base.Scene;
namespace SM.Base.Window
{
+ ///
+ /// A context that gets send when a window want to update the scene.
+ ///
public struct UpdateContext
{
+ ///
+ /// The window what triggered the updated.
+ ///
public IGenericWindow Window;
+ ///
+ /// A current update delta time. Equivalent to .
+ ///
public float Deltatime => SMRenderer.DefaultDeltatime.DeltaTime;
+ ///
+ /// The scene that gets updated.
+ ///
public GenericScene Scene;
}
}
\ No newline at end of file
diff --git a/SMCode/SM.Base/Window/GLWindow.cs b/SMCode/SM.Base/Window/GLWindow.cs
index 7123993..6e75aa2 100644
--- a/SMCode/SM.Base/Window/GLWindow.cs
+++ b/SMCode/SM.Base/Window/GLWindow.cs
@@ -18,17 +18,80 @@ using Mouse = SM.Base.Controls.Mouse;
namespace SM.Base.Window
{
+ ///
+ /// This provides the main entry, by executing the window.
+ ///
public class GLWindow : GameWindow, IGenericWindow
{
private Vector2 _flagWindowSize;
private Thread _fixedUpdateThread;
+ private WindowFlags _windowFlags;
- public WindowFlags WindowFlags;
+
+ ///
+ public bool Loading { get; private set; } = true;
+
+ ///
+ public float AspectRatio { get; set; }
+
+ ///
+ public GenericCamera ViewportCamera { get; set; }
+
+ ///
+ public bool ForceViewportCamera { get; set; }
+
+ ///
+ public bool DrawWhileUnfocused { get; set; } = true;
+ ///
+ public bool UpdateWhileUnfocused { get; set; } = false;
+ ///
+ public Vector2 WindowSize { get; set; }
+ ///
+ public ISetup AppliedSetup { get; private set; }
+
+ ///
+ public new event Action Resize;
+ ///
+ public new event Action Load;
+
+ ///
+ public GenericScene CurrentScene { get; private set; }
+ ///
+ public RenderPipeline CurrentRenderPipeline { get; private set; }
+
+ ///
+ /// Gets/Sets the current window flag.
+ ///
+ public WindowFlags WindowFlags
+ {
+ get => _windowFlags;
+ set
+ {
+ if (_windowFlags != value)
+ {
+ _windowFlags = value;
+ ChangeWindowFlag(value);
+ }
+ }
+ }
+
+ ///
+ /// Loads the window with default values.
+ /// Width: 1280px; Height: 720px; Title: Generic OpenGL Title; WindowFlag: Window
+ ///
public GLWindow() : this(1280, 720, "Generic OpenGL Title", WindowFlags.Window)
{
}
+ ///
+ /// Loads the window with custom values.
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
public GLWindow(int width, int height, string title, WindowFlags flags, VSyncMode vSync = VSyncMode.On) :
base(width, height, default, title, (GameWindowFlags) flags, DisplayDevice.Default,
GLSettings.ForcedVersion.MajorVersion, GLSettings.ForcedVersion.MinorVersion,
@@ -37,39 +100,16 @@ namespace SM.Base.Window
VSync = vSync;
_flagWindowSize = new Vector2(width, height);
- ChangeWindowFlag(flags);
+ WindowFlags = flags;
}
- public bool Loading { get; private set; } = true;
- public float AspectRatio { get; set; }
-
- public GenericCamera ViewportCamera { get; set; }
- public bool ForceViewportCamera { get; set; }
-
- public bool DrawWhileUnfocused { get; set; } = true;
- public bool UpdateWhileUnfocused { get; set; } = false;
-
- public Vector2 WindowSize { get; set; }
-
- public ISetup AppliedSetup { get; private set; }
- public new event Action Resize;
- public new event Action Load;
-
- public GenericScene CurrentScene { get; private set; }
- public RenderPipeline CurrentRenderPipeline { get; private set; }
-
- public void TriggerLoad()
- {
- Load?.Invoke(this);
- }
-
- public void TriggerResize()
- {
- Resize?.Invoke(this);
- }
+ ///
+ /// A event that gets executed when the window is done loading.
+ ///
public event Action Loaded;
+ ///
protected override void OnLoad(EventArgs e)
{
WindowCode.Load(this);
@@ -78,6 +118,7 @@ namespace SM.Base.Window
base.OnLoad(e);
}
+ ///
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
@@ -94,6 +135,7 @@ namespace SM.Base.Window
}
}
+ ///
protected override void OnUpdateFrame(FrameEventArgs e)
{
if (!Focused && !UpdateWhileUnfocused) return;
@@ -104,6 +146,7 @@ namespace SM.Base.Window
}
+ ///
protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);
@@ -115,23 +158,40 @@ namespace SM.Base.Window
GLDebugging.CheckGLErrors();
}
+ ///
protected override void OnMouseMove(MouseMoveEventArgs e)
{
base.OnMouseMove(e);
Mouse.MouseMoveEvent(e, this);
}
+
+ ///
+ public void TriggerLoad()
+ {
+ Load?.Invoke(this);
+ }
+
+ ///
+ public void TriggerResize()
+ {
+ Resize?.Invoke(this);
+ }
+
+ ///
public void Update(UpdateContext context)
{
}
+ ///
public void ApplySetup(ISetup setup)
{
AppliedSetup = setup;
setup.Applied(this);
}
+ ///
public void SetScene(GenericScene scene)
{
if (Loading)
@@ -144,6 +204,7 @@ namespace SM.Base.Window
CurrentScene = scene;
}
+ ///
public void SetRenderPipeline(RenderPipeline renderPipeline)
{
if (Loading)
@@ -156,34 +217,12 @@ namespace SM.Base.Window
CurrentRenderPipeline = renderPipeline;
}
- public void ChangeWindowFlag(WindowFlags newFlag)
- {
- WindowFlags = newFlag;
-
- switch (newFlag)
- {
- case WindowFlags.Window:
- Width = (int) _flagWindowSize.X;
- Height = (int) _flagWindowSize.Y;
-
- WindowBorder = WindowBorder.Resizable;
- break;
- case WindowFlags.BorderlessWindow:
- WindowBorder = WindowBorder.Hidden;
-
- X = Screen.PrimaryScreen.Bounds.Left;
- Y = Screen.PrimaryScreen.Bounds.Top;
- Width = Screen.PrimaryScreen.Bounds.Width;
- Height = Screen.PrimaryScreen.Bounds.Height;
-
- break;
- case WindowFlags.ExclusiveFullscreen:
- break;
- default:
- throw new ArgumentOutOfRangeException(nameof(newFlag), newFlag, null);
- }
- }
+ ///
+ /// Starts the fixed update loop.
+ /// Need to get executed before can be used.
+ ///
+ ///
public void RunFixedUpdate(float updatesPerSecond)
{
Deltatime.FixedUpdateDelta = 1 / (float)updatesPerSecond;
@@ -208,5 +247,31 @@ namespace SM.Base.Window
Thread.Sleep(waitTime);
}
}
+
+ private void ChangeWindowFlag(WindowFlags newFlag)
+ {
+ switch (newFlag)
+ {
+ case WindowFlags.Window:
+ Width = (int)_flagWindowSize.X;
+ Height = (int)_flagWindowSize.Y;
+
+ WindowBorder = WindowBorder.Resizable;
+ break;
+ case WindowFlags.BorderlessWindow:
+ WindowBorder = WindowBorder.Hidden;
+
+ X = Screen.PrimaryScreen.Bounds.Left;
+ Y = Screen.PrimaryScreen.Bounds.Top;
+ Width = Screen.PrimaryScreen.Bounds.Width;
+ Height = Screen.PrimaryScreen.Bounds.Height;
+
+ break;
+ case WindowFlags.ExclusiveFullscreen:
+ break;
+ default:
+ throw new ArgumentOutOfRangeException(nameof(newFlag), newFlag, null);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/SMCode/SM.Base/Window/IGenericWindow.cs b/SMCode/SM.Base/Window/IGenericWindow.cs
index e96c28a..504cb80 100644
--- a/SMCode/SM.Base/Window/IGenericWindow.cs
+++ b/SMCode/SM.Base/Window/IGenericWindow.cs
@@ -10,39 +10,106 @@ using SM.OGL.Framebuffer;
namespace SM.Base.Window
{
+ ///
+ /// This interface sets ground functions for windows.
+ ///
public interface IGenericWindow : IFramebufferWindow
{
+ ///
+ /// If true, the window is currently loading.
+ ///
bool Loading { get; }
+ ///
+ /// Holds the aspect ratio of the window.
+ ///
float AspectRatio { get; set; }
+ ///
+ /// The viewport camera is used, when no camera is found in the scene.
+ ///
GenericCamera ViewportCamera { get; set; }
+ ///
+ /// Turning this to true, will force the window to render in the viewport camera.
+ ///
bool ForceViewportCamera { get; set; }
+ ///
+ /// Turning this to false will not allow drawing while the window is not in focus.
+ ///
bool DrawWhileUnfocused { get; set; }
+ ///
+ /// Turning this to false will not allow updating while the window is not in focus.
+ ///
bool UpdateWhileUnfocused { get; set; }
+ ///
+ /// Contains the window size.
+ ///
Vector2 WindowSize { get; set; }
+ ///
+ /// The rectangle the window is using.
+ ///
Rectangle ClientRectangle { get; }
+ ///
+ /// The setup that was applied to the window.
+ ///
ISetup AppliedSetup { get; }
+ ///
+ /// The scene that is currently used.
+ ///
GenericScene CurrentScene { get; }
+ ///
+ /// The render pipeline that is currently used.
+ ///
RenderPipeline CurrentRenderPipeline { get; }
+ ///
+ /// An event, when the window resizes.
+ ///
event Action Resize;
+ ///
+ /// An event, when the window is loading.
+ ///
event Action Load;
+ ///
+ /// This gets executed, when the window should update something.
+ ///
+ /// The context of the update.
void Update(UpdateContext context);
+ ///
+ /// This applies a setup to the window.
+ ///
+ ///
void ApplySetup(ISetup setup);
+ ///
+ /// This sets a scene for the window to use.
+ ///
+ ///
void SetScene(GenericScene scene);
+ ///
+ /// This sets a render pipeline, from where the scene gets rendered.
+ ///
+ ///
void SetRenderPipeline(RenderPipeline renderPipeline);
+ ///
+ /// This triggeres the event.
+ ///
void TriggerLoad();
+ ///
+ /// This triggeres the event.
+ ///
void TriggerResize();
+ ///
+ /// This closes the window.
+ ///
void Close();
}
}
\ No newline at end of file
diff --git a/SMCode/SM.Base/packages.config b/SMCode/SM.Base/packages.config
index bf47353..82cdaeb 100644
--- a/SMCode/SM.Base/packages.config
+++ b/SMCode/SM.Base/packages.config
@@ -1,8 +1,4 @@
-
-
-
-
-
+
\ No newline at end of file
diff --git a/SMCode/SM.OGL/Framebuffer/ColorAttachment.cs b/SMCode/SM.OGL/Framebuffer/ColorAttachment.cs
index 0d8d749..cf3678a 100644
--- a/SMCode/SM.OGL/Framebuffer/ColorAttachment.cs
+++ b/SMCode/SM.OGL/Framebuffer/ColorAttachment.cs
@@ -14,7 +14,7 @@ namespace SM.OGL.Framebuffer
///
public class ColorAttachment : TextureBase
{
- private int _multisamples;
+ private readonly int _multisamples;
///
/// The ID the attachment was given.
@@ -50,6 +50,12 @@ namespace SM.OGL.Framebuffer
public ColorAttachment(int attachmentId) : this(attachmentId, PixelInformation.RGBA_LDR)
{ }
+ ///
+ /// Creates a color attachment with a specific id, specific pixel informations and multisamples.
+ ///
+ ///
+ ///
+ ///
public ColorAttachment(int attachmentID, PixelInformation pixelInformation, int multisamples = 0)
{
AttachmentID = attachmentID;
diff --git a/SMCode/SM.OGL/Framebuffer/Framebuffer.cs b/SMCode/SM.OGL/Framebuffer/Framebuffer.cs
index cbf5eae..b92718b 100644
--- a/SMCode/SM.OGL/Framebuffer/Framebuffer.cs
+++ b/SMCode/SM.OGL/Framebuffer/Framebuffer.cs
@@ -14,6 +14,7 @@ namespace SM.OGL.Framebuffer
///
public class Framebuffer : GLObject
{
+ ///
protected override bool AutoCompile { get; set; } = true;
///
@@ -25,8 +26,8 @@ namespace SM.OGL.Framebuffer
CanCompile = false,
};
- private IFramebufferWindow _window;
- private float _windowScale;
+ private readonly IFramebufferWindow _window;
+ private readonly float _windowScale;
///
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Framebuffer;
@@ -42,6 +43,9 @@ namespace SM.OGL.Framebuffer
public Dictionary ColorAttachments { get; private set; } =
new Dictionary();
+ ///
+ /// Contains the current renderbuffer attachments of the framebuffer.
+ ///
public List RenderbufferAttachments { get; } = new List();
///
@@ -131,6 +135,10 @@ namespace SM.OGL.Framebuffer
ColorAttachments.Add(key, value);
}
+ ///
+ /// Appends a renderbuffer attachment to the framebuffer.
+ ///
+ ///
public void AppendRenderbuffer(RenderbufferAttachment attachment)
{
RenderbufferAttachments.Add(attachment);
@@ -173,6 +181,11 @@ namespace SM.OGL.Framebuffer
GL.Clear(clear);
}
+ ///
+ /// Returns a handle of the current framebuffer.
+ ///
+ ///
+ ///
public static Framebuffer GetCurrentlyActive(FramebufferTarget target = FramebufferTarget.Framebuffer)
{
Framebuffer buffer = new Framebuffer()
diff --git a/SMCode/SM.OGL/Framebuffer/IFramebufferWindow.cs b/SMCode/SM.OGL/Framebuffer/IFramebufferWindow.cs
index a6278b5..c15a456 100644
--- a/SMCode/SM.OGL/Framebuffer/IFramebufferWindow.cs
+++ b/SMCode/SM.OGL/Framebuffer/IFramebufferWindow.cs
@@ -5,7 +5,13 @@
///
public interface IFramebufferWindow
{
+ ///
+ /// The width of the window.
+ ///
int Width { get; }
+ ///
+ /// The height of the window.
+ ///
int Height { get; }
}
}
\ No newline at end of file
diff --git a/SMCode/SM.OGL/GLObject.cs b/SMCode/SM.OGL/GLObject.cs
index a2a7096..5458abe 100644
--- a/SMCode/SM.OGL/GLObject.cs
+++ b/SMCode/SM.OGL/GLObject.cs
@@ -14,20 +14,30 @@ namespace SM.OGL
///
public abstract class GLObject
{
- private static List _disposableObjects = new List();
+ private static readonly List _disposableObjects = new List();
private string _name = "";
- protected bool ReportAsNotCompiled;
///
/// Contains the OpenGL ID
///
protected int _id = -1;
+ ///
+ /// This can mark the object to never report as compiled, even when it was.
+ /// You can still figure out, if it was compiled by checking . If not -1, its compiled.
+ /// Default: false
+ ///
+ protected bool ReportAsNotCompiled;
+ ///
+ /// This can prevent the object to compile.
+ /// Default: true
+ ///
protected bool CanCompile = true;
///
/// If true, the system will call "Compile()", when "ID" is tried to get, but the id is still -1.
+ /// Default: false
///
protected virtual bool AutoCompile { get; set; } = false;
@@ -36,6 +46,10 @@ namespace SM.OGL
///
public bool WasCompiled => _id > 0 && !ReportAsNotCompiled;
+ ///
+ /// Names the object
+ /// If is true, then it will also name the object in the system.
+ ///
public string Name
{
get => _name;
@@ -111,11 +125,15 @@ namespace SM.OGL
Compile();
}
+ ///
public override string ToString()
{
return $"{GetType().Name} {(string.IsNullOrEmpty(_name) ? "" : $"\"{_name}\" ")}[{_id}]";
}
+ ///
+ /// This disposes the current objects, that where marked by the garbage collector.
+ ///
public static void DisposeMarkedObjects()
{
foreach (GLObject o in _disposableObjects)
@@ -134,6 +152,9 @@ namespace SM.OGL
return glo.ID;
}
+ ///
+ /// If the garbage collector is trying to remove this object, it will add the object to a list, what get removed when is called.
+ ///
~GLObject()
{
if (WasCompiled) _disposableObjects.Add(this);
diff --git a/SMCode/SM.OGL/Mesh/BoundingBox.cs b/SMCode/SM.OGL/Mesh/BoundingBox.cs
index dec59c7..8db9137 100644
--- a/SMCode/SM.OGL/Mesh/BoundingBox.cs
+++ b/SMCode/SM.OGL/Mesh/BoundingBox.cs
@@ -49,21 +49,59 @@ namespace SM.OGL.Mesh
///
public Vector3 this[bool x, bool y, bool z] => Get(x,y,z);
+ ///
+ /// Equivalent to .
+ /// Returns specific configurations of corners
+ ///
+ /// If true, it takes the X-value of maximum, otherwise the minimum.
+ /// If true, it takes the Y-value of maximum, otherwise the minimum.
+ /// If true, it takes the Z-value of maximum, otherwise the minimum.
+ ///
public Vector3 Get(bool x, bool y, bool z)
{
return new Vector3(x ? Max.X : Min.X, y ? Max.Y : Min.Y, z ? Max.Z : Min.Z);
}
+ ///
+ /// Returns the configuration of the two furthest away corners.
+ ///
+ /// If true, it will take the maximum, otherwise the minimum.
+ ///
public Vector3 Get(bool xyz) => Get(xyz, xyz, xyz);
+ ///
+ /// Returns the configuration of one corner and applies a transformation to it.
+ /// If the transformation causes the points to shift to no being in the right location is NOT checked!
+ /// For that use
+ ///
+ /// The transformation
+ /// If true, it takes the X-value of maximum, otherwise the minimum.
+ /// If true, it takes the Y-value of maximum, otherwise the minimum.
+ /// If true, it takes the Z-value of maximum, otherwise the minimum.
+ ///
public Vector3 Get(Matrix4 transformation, bool x, bool y, bool z)
{
Vector3 get = Get(x, y, z);
return (new Vector4(get, 1) * transformation).Xyz;
}
+ ///
+ /// Returns the configuration of the two furthest away corners.
+ /// If the transformation causes the points to shift to no being in the right location is NOT checked!
+ /// For that use
+ ///
+ /// The transformation
+ /// If true, it will take the maximum, otherwise the minimum.
+ ///
public Vector3 Get(Matrix4 transformation, bool xyz) => Get(transformation, xyz, xyz, xyz);
+ ///
+ /// Returns the bounds of the bounding box while applying a transformation.
+ /// This takes care of min and max locations.
+ ///
+ ///
+ ///
+ ///
public void GetBounds(Matrix4 transformation, out Vector3 min, out Vector3 max)
{
min = Get(transformation, false);
@@ -79,6 +117,10 @@ namespace SM.OGL.Mesh
}
}
+ ///
+ /// Updates the bounding box to the mesh provided.
+ ///
+ ///
public void Update(GenericMesh mesh)
{
int pos = 0;
diff --git a/SMCode/SM.OGL/Mesh/GenericMesh.cs b/SMCode/SM.OGL/Mesh/GenericMesh.cs
index d8f552a..cadd423 100644
--- a/SMCode/SM.OGL/Mesh/GenericMesh.cs
+++ b/SMCode/SM.OGL/Mesh/GenericMesh.cs
@@ -13,9 +13,7 @@ namespace SM.OGL.Mesh
public abstract class GenericMesh : GLObject
{
private bool _boundingBoxUpdated = false;
-
- public static int LastID { get; internal set; } = -1;
-
+
///
protected override bool AutoCompile { get; set; } = true;
@@ -71,12 +69,18 @@ namespace SM.OGL.Mesh
};
}
+ ///
+ /// Updates the object bounding box.
+ ///
public void UpdateBoundingBox()
{
BoundingBox.Update(this);
_boundingBoxUpdated = true;
}
+ ///
+ /// Activates the object to be rendered.
+ ///
public void Activate()
{
GL.BindVertexArray(ID);
@@ -99,6 +103,7 @@ namespace SM.OGL.Mesh
GL.BindVertexArray(0);
}
+ ///
public override void Dispose()
{
GL.DeleteVertexArray(_id);
diff --git a/SMCode/SM.OGL/Mesh/MeshAttribute.cs b/SMCode/SM.OGL/Mesh/MeshAttribute.cs
index 4777e95..472e463 100644
--- a/SMCode/SM.OGL/Mesh/MeshAttribute.cs
+++ b/SMCode/SM.OGL/Mesh/MeshAttribute.cs
@@ -18,6 +18,12 @@
///
public VBO ConnectedVBO;
+ ///
+ /// Creates a attribute for a mesh.
+ ///
+ ///
+ ///
+ ///
public MeshAttribute(int index, string name, VBO buffer)
{
Index = index;
diff --git a/SMCode/SM.OGL/Mesh/MeshAttributeList.cs b/SMCode/SM.OGL/Mesh/MeshAttributeList.cs
index 5cbeb66..e01e17a 100644
--- a/SMCode/SM.OGL/Mesh/MeshAttributeList.cs
+++ b/SMCode/SM.OGL/Mesh/MeshAttributeList.cs
@@ -49,6 +49,11 @@ namespace SM.OGL.Mesh
Add(new MeshAttribute(id, name, vbo));
}
+ ///
+ /// Checks if the attribute list has the attribute name.
+ ///
+ ///
+ ///
public bool Has(string name)
{
VBO attribute = this[name];
diff --git a/SMCode/SM.OGL/Mesh/VBO.cs b/SMCode/SM.OGL/Mesh/VBO.cs
index 0bd3ac1..738bb60 100644
--- a/SMCode/SM.OGL/Mesh/VBO.cs
+++ b/SMCode/SM.OGL/Mesh/VBO.cs
@@ -139,6 +139,10 @@ namespace SM.OGL.Mesh
Add(vector.X, vector.Y, z, w);
}
+ ///
+ /// Adds a array of vector2s.
+ ///
+ ///
public void Add(params Vector2[] vectors)
{
foreach (Vector2 vector in vectors)
@@ -163,6 +167,10 @@ namespace SM.OGL.Mesh
Add(vector.X, vector.Y, vector.Z, w);
}
+ ///
+ /// Adds a array of Vector3s.
+ ///
+ ///
public void Add(params Vector3[] vectors)
{
foreach (Vector3 vector in vectors)
diff --git a/SMCode/SM.OGL/Shaders/GenericShader.cs b/SMCode/SM.OGL/Shaders/GenericShader.cs
index 5ec6067..ddb32a1 100644
--- a/SMCode/SM.OGL/Shaders/GenericShader.cs
+++ b/SMCode/SM.OGL/Shaders/GenericShader.cs
@@ -70,6 +70,11 @@ namespace SM.OGL.Shaders
ShaderFileFiles = new ShaderFileCollection(vertex,fragment, geometry);
}
+ ///
+ /// Creates a shader out of a vertex and an fragment shader.
+ ///
+ ///
+ ///
protected GenericShader(string vertex, string fragment) : this(new ShaderFileCollection(vertex, fragment)){}
///
@@ -81,6 +86,10 @@ namespace SM.OGL.Shaders
///
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Program;
+ ///
+ /// Updates the shader files and recompiles the shader.
+ ///
+ ///
public void Update(ShaderFileCollection newShaderFiles)
{
ShaderFileFiles = newShaderFiles;
@@ -104,6 +113,9 @@ namespace SM.OGL.Shaders
GLDebugging.CheckGLErrors($"A error occured at shader creation for '{GetType()}': %code%");
}
+ ///
+ /// Activates the shader
+ ///
public void Activate()
{
GL.UseProgram(ID);
@@ -115,6 +127,7 @@ namespace SM.OGL.Shaders
Load();
}
+ ///
public override void Dispose()
{
GL.DeleteProgram(this);
@@ -136,14 +149,15 @@ namespace SM.OGL.Shaders
///
/// Draws the mesh while forcing a primitive type instead of using the mesh type.
///
+ /// The type, as what the object should be rendered.
/// The mesh.
/// The amounts for instancing.
- public static void DrawObject(PrimitiveType forcedType, GenericMesh mesh, int amount = 1)
+ public static void DrawObject(PrimitiveType modelType, GenericMesh mesh, int amount = 1)
{
if (mesh.Indices != null)
- GL.DrawElementsInstanced(forcedType, 0, DrawElementsType.UnsignedInt, mesh.Indices, amount);
+ GL.DrawElementsInstanced(modelType, 0, DrawElementsType.UnsignedInt, mesh.Indices, amount);
else
- GL.DrawArraysInstanced(forcedType, 0, mesh.Vertex.Count / mesh.Vertex.PointerSize, amount);
+ GL.DrawArraysInstanced(modelType, 0, mesh.Vertex.Count / mesh.Vertex.PointerSize, amount);
}
///
diff --git a/SMCode/SM.OGL/Shaders/UniformArray.cs b/SMCode/SM.OGL/Shaders/UniformArray.cs
index 2689851..5b36532 100644
--- a/SMCode/SM.OGL/Shaders/UniformArray.cs
+++ b/SMCode/SM.OGL/Shaders/UniformArray.cs
@@ -2,28 +2,51 @@
namespace SM.OGL.Shaders
{
+ ///
+ /// This class controls uniform array structures.
+ ///
public class UniformArray : IUniform
{
- private Dictionary> storedUniforms = new Dictionary>();
- internal List uniformNames = new List();
+ private readonly Dictionary> storedUniforms = new Dictionary>();
+ internal List UniformNames = new List();
+ ///
public int Location { get; internal set; }
+ ///
+ /// The name of the uniform.
+ ///
public string Name { get; internal set; }
+ ///
+ /// The uniform collection the uniform is from.
+ ///
public UniformCollection Parent { get; internal set; }
+ ///
+ /// The shader the uniform is from.
+ ///
public GenericShader ParentShader { get; internal set; }
+ ///
+ /// The length of the array.
+ ///
public int Length => storedUniforms.Count;
+ ///
+ /// Returns a dictionary to control the current index inside the array.
+ ///
public Dictionary this[int index] => Get(index);
+ ///
+ /// Equivalent to
+ /// Returns a dictionary to control the current index inside the array.
+ ///
public Dictionary Get(int index)
{
if (!storedUniforms.ContainsKey(index))
{
Dictionary dic = storedUniforms[index] = new Dictionary();
- for (int i = 0; i < uniformNames.Count; i++)
+ for (int i = 0; i < UniformNames.Count; i++)
{
- dic.Add(uniformNames[i], new Uniform(Name + $"[{index}]." + uniformNames[i], ParentShader, Parent));
+ dic.Add(UniformNames[i], new Uniform(Name + $"[{index}]." + UniformNames[i], ParentShader, Parent));
}
}
diff --git a/SMCode/SM.OGL/Shaders/UniformCollection.cs b/SMCode/SM.OGL/Shaders/UniformCollection.cs
index a4ab939..e575b3f 100644
--- a/SMCode/SM.OGL/Shaders/UniformCollection.cs
+++ b/SMCode/SM.OGL/Shaders/UniformCollection.cs
@@ -8,14 +8,34 @@ using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Shaders
{
+ ///
+ /// Collects and provied the uniforms of a shader.
+ ///
public class UniformCollection : Dictionary
{
- public int NextTexture = 0;
internal string KeyString = "";
+ ///
+ /// The next uniform-position for textures.
+ ///
+ public int NextTexture = 0;
+ ///
+ /// The shader this collections is connected to.
+ ///
public GenericShader ParentShader { get; internal set; }
+ ///
+ ///
+ ///
+ ///
public new Uniform this[string key] => Get(key);
+ ///
+ /// Equivalent to
+ /// Gets the uniform with the provied key.
+ /// If it can't find it, it will create a warning and a uniform with the location of -1.
+ ///
+ ///
+ ///
public Uniform Get(string key)
{
try
@@ -31,18 +51,22 @@ namespace SM.OGL.Shaders
}
}
+ ///
+ /// Gets a array.
+ ///
+ ///
+ ///
+ /// If the key wasn't found, it will throw a exception
public UniformArray GetArray(string key)
{
- try
- {
+ if (ContainsKey(key))
return (UniformArray) base[key];
- }
- catch (KeyNotFoundException)
- {
- throw new Exception("UniformArray '"+key+"' wasn't found");
- }
+ else throw new KeyNotFoundException("UniformArray '"+key+"' wasn't found");
}
+ ///
+ /// Adds a uniform to the collection.
+ ///
public void Add(string key, int location)
{
base.Add(key, new Uniform(location, this));
@@ -101,7 +125,7 @@ namespace SM.OGL.Shaders
}
if (keySplits[1] == "0")
- array.uniformNames.Add(keySplits[2].Substring(1));
+ array.UniformNames.Add(keySplits[2].Substring(1));
}
else
{
diff --git a/SMCode/SM2D/Controls/Mouse2D.cs b/SMCode/SM2D/Controls/Mouse2D.cs
index 8bf2c10..2690cef 100644
--- a/SMCode/SM2D/Controls/Mouse2D.cs
+++ b/SMCode/SM2D/Controls/Mouse2D.cs
@@ -8,8 +8,14 @@ using SM2D.Types;
namespace SM2D.Controls
{
+ ///
+ /// Contains special methods for the mouse.
+ ///
public class Mouse2D
{
+ ///
+ /// Returns the current position of the mouse inside the world.
+ ///
public static Vector2 InWorld(Vector2 worldScale)
{
var res = worldScale;
@@ -17,28 +23,63 @@ namespace SM2D.Controls
return Mouse.InScreenNormalized * res - res / 2;
}
+ ///
+ /// Returns the current position of the mouse inside the world.
+ ///
public static Vector2 InWorld(Camera cam)
{
return InWorld(cam.WorldScale) + cam.Position;
}
+ ///
+ /// Returns the current position of the mouse inside the world.
+ ///
public static Vector2 InWorld(Vector2 worldScale, Vector2 position)
{
return InWorld(worldScale) + position;
}
+ ///
+ /// Checks if the mouse is over an object.
+ ///
+ /// The position in the world. See
+ ///
+ ///
public static bool MouseOver(Vector2 mousePos, params TObject[] checkingObjects)
where TObject : IModelItem, ITransformItem
=> MouseOver(mousePos, out _, checkingObjects);
+ ///
+ /// Checks if the mouse is over an object.
+ ///
+ /// The position in the world. See
+ ///
+ ///
+ ///
public static bool MouseOver(Vector2 mousePos, ICollection checkingObjects)
where TObject : IModelItem, ITransformItem
=> MouseOver(mousePos, out _, checkingObjects);
+ ///
+ /// Checks if the mouse is over an object and returns the object that was clicked on.
+ ///
+ /// The position in the world. See
+ ///
+ ///
+ ///
+ ///
public static bool MouseOver(Vector2 mousePos, out TObject clicked, params TObject[] checkingObjects)
where TObject : IModelItem, ITransformItem
=> MouseOver(mousePos, out clicked, (ICollection)checkingObjects);
+ ///
+ /// Checks if the mouse is over an object and returns the object that was clicked on.
+ ///
+ /// The position in the world. See
+ ///
+ ///
+ ///
+ ///
public static bool MouseOver(Vector2 mousePos, out TObject clickedObj, ICollection checkingObjects)
where TObject : IModelItem, ITransformItem
{
@@ -70,6 +111,13 @@ namespace SM2D.Controls
return success;
}
+ ///
+ /// Checks if the mouse is over an object and returns the object that was clicked on.
+ ///
+ /// The position in the world. See
+ ///
+ ///
+ ///
public static bool MouseOver(Vector2 mousePos, BoundingBox boundingBox, Transformation transform)
{
Matrix4 worldPos = transform.InWorldSpace;
diff --git a/SMCode/SM2D/Drawing/DrawBackground.cs b/SMCode/SM2D/Drawing/DrawBackground.cs
index 280381d..7808855 100644
--- a/SMCode/SM2D/Drawing/DrawBackground.cs
+++ b/SMCode/SM2D/Drawing/DrawBackground.cs
@@ -14,14 +14,23 @@ using SM2D.Scene;
namespace SM2D.Drawing
{
+ ///
+ /// Allows easy access to draw something on the background.
+ ///
public class DrawBackground : DrawingBasis, IBackgroundItem
{
+ ///
+ /// Sets the color or tint (in case a texture is set).
+ ///
public Color4 Color
{
get => Material.Tint;
set => Material.Tint = value;
}
+ ///
+ /// Sets the texture of the background.
+ ///
public TextureBase Texture
{
get => Material.Texture;
@@ -32,18 +41,34 @@ namespace SM2D.Drawing
}
}
+ ///
+ /// Creates a black background.
+ ///
public DrawBackground() : this(Color4.Black) {}
+ ///
+ /// Creates a background with a color.
+ ///
+ ///
public DrawBackground(Color4 color)
{
Color = color;
}
+ ///
+ /// Creates a background with a texture.
+ ///
+ ///
public DrawBackground(Bitmap texture)
{
Texture = (Texture) texture;
}
+ ///
+ /// Creates a background with a texture and a tint.
+ ///
+ ///
+ ///
public DrawBackground(Bitmap texture, Color4 tint)
{
Color = tint;
@@ -51,6 +76,7 @@ namespace SM2D.Drawing
}
+ ///
protected override void DrawContext(ref DrawContext context)
{
base.DrawContext(ref context);
diff --git a/SMCode/SM2D/Drawing/DrawObject2D.cs b/SMCode/SM2D/Drawing/DrawObject2D.cs
index 81b4158..e9176e6 100644
--- a/SMCode/SM2D/Drawing/DrawObject2D.cs
+++ b/SMCode/SM2D/Drawing/DrawObject2D.cs
@@ -10,46 +10,72 @@ using SM2D.Types;
namespace SM2D.Drawing
{
+ ///
public class DrawObject2D : DrawingBasis
{
+ ///
+ /// The texture the object should use.
+ ///
public Texture Texture
{
get => (Texture) Material.Texture;
set => Material.Texture = value;
}
+ ///
+ /// The color or tint the object should use.
+ ///
public Color4 Color
{
get => Material.Tint;
set => Material.Tint = value;
}
+ ///
protected override void DrawContext(ref DrawContext context)
{
base.DrawContext(ref context);
context.Shader.Draw(context);
}
-
- public void SetShader(MaterialShader shader) => Material.CustomShader = shader;
- public Polygon ApplyPolygon(ICollection vertices, bool centerUVs = false)
+ ///
+ /// Applies a polygon to the object.
+ ///
+ ///
+ ///
+ public Polygon ApplyPolygon(ICollection vertices)
{
Polygon polygon = new Polygon(vertices);
Mesh = polygon;
return polygon;
}
- public Polygon ApplyPolygon(ICollection vertices, bool centerUVs = false)
+
+ ///
+ /// Applies a polygon to the object.
+ ///
+ ///
+ ///
+ public Polygon ApplyPolygon(ICollection vertices)
{
Polygon polygon = new Polygon(vertices);
Mesh = polygon;
return polygon;
}
+
+ ///
+ /// Applies a polygon to the object.
+ ///
public void ApplyPolygon(Polygon polygon)
{
Mesh = polygon;
}
- public Polygon ApplyCircle(int segments = 32, bool centerUVs = false)
+ ///
+ /// This applies a circle.
+ ///
+ ///
+ ///
+ public Polygon ApplyCircle(int segments = 32)
{
Polygon pol = Polygon.GenerateCircle(segments);
Mesh = pol;
diff --git a/SMCode/SM2D/Drawing/DrawParticles.cs b/SMCode/SM2D/Drawing/DrawParticles.cs
index c2e814e..4adb988 100644
--- a/SMCode/SM2D/Drawing/DrawParticles.cs
+++ b/SMCode/SM2D/Drawing/DrawParticles.cs
@@ -6,14 +6,20 @@ using SM2D.Types;
namespace SM2D.Drawing
{
+ ///
+ /// Creates particles.
+ ///
public class DrawParticles : ParticleDrawingBasis
{
+ ///
public override Func MovementCalculation { get; set; } = ParticleMovement.Default2D;
+ ///
public DrawParticles(TimeSpan duration) : base(duration)
{
}
+ ///
protected override ParticleStruct CreateObject(int index)
{
return new ParticleStruct()
@@ -24,6 +30,7 @@ namespace SM2D.Drawing
};
}
+ ///
protected override Matrix4 CreateMatrix(ParticleStruct Struct, Vector2 direction)
{
return Struct.Matrix * Matrix4.CreateTranslation(direction.X, direction.Y, 0);
diff --git a/SMCode/SM2D/Drawing/DrawText.cs b/SMCode/SM2D/Drawing/DrawText.cs
index eba649c..0441603 100644
--- a/SMCode/SM2D/Drawing/DrawText.cs
+++ b/SMCode/SM2D/Drawing/DrawText.cs
@@ -9,14 +9,21 @@ using SM2D.Types;
namespace SM2D.Drawing
{
+ ///
+ /// Draws a text to the world.
+ ///
public class DrawText : TextDrawingBasis
{
+ ///
+ /// Creates a text object.
+ ///
public DrawText(Font font, string text) : base(font)
{
_text = text;
Transform.Size = new CVector2(1);
}
+ ///
protected override void DrawContext(ref DrawContext context)
{
base.DrawContext(ref context);
diff --git a/SMCode/SM2D/Object/PolyLine.cs b/SMCode/SM2D/Object/PolyLine.cs
index 0a723ee..997f1a3 100644
--- a/SMCode/SM2D/Object/PolyLine.cs
+++ b/SMCode/SM2D/Object/PolyLine.cs
@@ -5,15 +5,36 @@ using SM.OGL.Mesh;
namespace SM2D.Object
{
+ ///
+ /// Allows different type of lines.
+ ///
public enum PolyLineType
{
+ ///
+ /// Those lines are not connected to each other.
+ /// Every two points starts a new line.
+ ///
NotConnected = 1,
+ ///
+ /// Those lines are connected with each other, but don't connect the start and the end.
+ ///
Connected = 3,
+ ///
+ /// Those lines are connected and they connect start and end.
+ ///
ConnectedLoop = 2
}
+ ///
+ /// Creates new poly line.
+ ///
public class PolyLine : Polygon, ILineMesh
{
+ ///
+ /// Creates a new polyline by using .
+ ///
+ ///
+ ///
public PolyLine(ICollection vertices, PolyLineType lineType = PolyLineType.NotConnected) : base(vertices)
{
UVs.Active = false;
@@ -21,6 +42,11 @@ namespace SM2D.Object
PrimitiveType = (PrimitiveType)lineType;
}
+ ///
+ /// Creates a new polyline by using .
+ ///
+ ///
+ ///
public PolyLine(ICollection vertices, PolyLineType lineType = PolyLineType.NotConnected) : base(vertices)
{
UVs.Active = false;
diff --git a/SMCode/SM2D/Object/Polygon.cs b/SMCode/SM2D/Object/Polygon.cs
index 85cee64..b1ef988 100644
--- a/SMCode/SM2D/Object/Polygon.cs
+++ b/SMCode/SM2D/Object/Polygon.cs
@@ -11,8 +11,27 @@ using SM.OGL.Mesh;
namespace SM2D.Object
{
+ ///
+ /// Creates a polygon.
+ ///
public class Polygon : Mesh
{
+ ///
+ public override VBO Vertex { get; protected set; } = new VBO();
+
+ ///
+ public override VBO UVs { get; protected set; } = new VBO(pointerSize: 2);
+
+ ///
+ public override VBO Color { get; protected set; } = new VBO(pointerSize: 4);
+
+ ///
+ public override PrimitiveType PrimitiveType { get; protected set; } = PrimitiveType.TriangleFan;
+
+ ///
+ /// Creates a polygon with s.
+ ///
+ ///
public Polygon(ICollection vertices) : base(PrimitiveType.TriangleFan)
{
Color.Active = false;
@@ -27,25 +46,23 @@ namespace SM2D.Object
if (UVs.Active) foreach (var vertex in vertices) AddUV(vertex);
}
+ ///
+ /// Creates a polygon with , what allows colors hard coded.
+ ///
+ ///
public Polygon(ICollection vertices) : base(PrimitiveType.TriangleFan)
{
foreach (var polygonVertex in vertices)
{
Color.Add(polygonVertex.Color);
- Vertex.Add(polygonVertex.Vertex, 0);
+ Vertex.Add(polygonVertex.Position, 0);
}
UpdateBoundingBox();
- if (UVs.Active) foreach (var vertex in vertices) AddUV(vertex.Vertex);
+ if (UVs.Active) foreach (var vertex in vertices) AddUV(vertex.Position);
}
- public override VBO Vertex { get; protected set; } = new VBO();
- public override VBO UVs { get; protected set; } = new VBO(pointerSize: 2);
- public override VBO Color { get; protected set; } = new VBO(pointerSize: 4);
-
- public override PrimitiveType PrimitiveType { get; protected set; } = PrimitiveType.TriangleFan;
-
private void AddUV(Vector2 vertex)
{
var uv = Vector2.Divide(vertex - BoundingBox.Min.Xy, BoundingBox.Max.Xy - BoundingBox.Min.Xy);
@@ -53,6 +70,11 @@ namespace SM2D.Object
UVs.Add(uv);
}
+ ///
+ /// Creates a circle.
+ ///
+ ///
+ ///
public static Polygon GenerateCircle(int secments = 32)
{
var vertices = new List {Vector2.Zero};
diff --git a/SMCode/SM2D/Object/PolygonVertex.cs b/SMCode/SM2D/Object/PolygonVertex.cs
index a288e05..02026b3 100644
--- a/SMCode/SM2D/Object/PolygonVertex.cs
+++ b/SMCode/SM2D/Object/PolygonVertex.cs
@@ -7,17 +7,36 @@ using OpenTK.Graphics;
namespace SM2D.Object
{
+ ///
+ /// Allows storing more information inside a vertex.
+ ///
public struct PolygonVertex
{
- public Vector2 Vertex;
+ ///
+ /// The position in the polygon.
+ ///
+ public Vector2 Position;
+ ///
+ /// The color of the vertex.
+ ///
public Color4 Color;
- public PolygonVertex(Vector2 vertex = default, Color4 color = default)
+ ///
+ /// Creates a polygon vertex.
+ ///
+ ///
+ ///
+ public PolygonVertex(Vector2 position = default, Color4 color = default)
{
- Vertex = vertex;
+ Position = position;
Color = color;
}
+ ///
+ /// Automaticly translates Vector2s to PolygonVertex
+ ///
+ ///
+ ///
public static implicit operator PolygonVertex(Vector2 vec) => new PolygonVertex(vec, Color4.White);
}
}
\ No newline at end of file
diff --git a/SMCode/SM2D/Pipelines/Basic2DPipeline.cs b/SMCode/SM2D/Pipelines/Basic2DPipeline.cs
index d3573e5..2945fe0 100644
--- a/SMCode/SM2D/Pipelines/Basic2DPipeline.cs
+++ b/SMCode/SM2D/Pipelines/Basic2DPipeline.cs
@@ -4,13 +4,22 @@ using SM2D.Shader;
namespace SM2D.Pipelines
{
+ ///
+ /// This implements the most basic render pipeline.
+ ///
public class Basic2DPipeline : RenderPipeline
{
+ ///
+ /// The access to the pipeline.
+ ///
public static Basic2DPipeline Pipeline = new Basic2DPipeline();
+ ///
public override MaterialShader DefaultShader { get; protected set; } = ShaderCollection.Instanced;
+ private Basic2DPipeline() {}
+ ///
protected override void RenderProcess(ref DrawContext context)
{
context.Scene?.Draw(context);
diff --git a/SMCode/SM2D/SM2D.csproj b/SMCode/SM2D/SM2D.csproj
index 96f1749..6463877 100644
--- a/SMCode/SM2D/SM2D.csproj
+++ b/SMCode/SM2D/SM2D.csproj
@@ -8,7 +8,7 @@
Library
Properties
SM2D
- SM2D
+ SMRenderer2D
v4.5.2
512
true
@@ -21,6 +21,7 @@
DEBUG;TRACE
prompt
4
+ bin\Debug\SMRenderer2D.xml
pdbonly
@@ -47,13 +48,11 @@
-
-
@@ -69,9 +68,6 @@
3.3.1
-
- 3.2.3
-
diff --git a/SMCode/SM2D/Scene/Camera.cs b/SMCode/SM2D/Scene/Camera.cs
index 916fd2e..ca39f81 100644
--- a/SMCode/SM2D/Scene/Camera.cs
+++ b/SMCode/SM2D/Scene/Camera.cs
@@ -10,6 +10,7 @@ using SM.Base.Window;
namespace SM2D.Scene
{
+ ///
public class Camera : GenericCamera
{
internal static int ResizeCounter = 0;
@@ -19,6 +20,14 @@ namespace SM2D.Scene
private bool _updateWorldScale = false;
private Vector2? _requestedWorldScale = null;
+ ///
+ /// This vector allows to request a world scale.
+ /// Following cases are possible. ("not set" means 0)
+ /// None is set: It takes the window size.
+ /// X is set: Y get calculated by the aspect ratio of the window.
+ /// Y is set: X get calculated by the aspect ratio of the window.
+ /// Both are set: Now the system try to keep a (invisible) rectangle in view, by increasing the width or height of the view, if needed.
+ ///
public Vector2? RequestedWorldScale
{
get => _requestedWorldScale;
@@ -29,18 +38,32 @@ namespace SM2D.Scene
}
}
+ ///
+ /// The world scale that got calculated.
+ ///
public Vector2 WorldScale { get; private set; } = Vector2.Zero;
+ ///
+ /// A event that gets triggered, when the world scale changed.
+ /// Possible causes: Window resizes, changed
+ ///
public event Action WorldScaleChanged;
+ ///
+ /// The position of the camera.
+ ///
public CVector2 Position = new CVector2(0);
+
+ ///
public override bool Orthographic { get; } = true;
+ ///
protected override Matrix4 ViewCalculation(IGenericWindow window)
{
return Matrix4.LookAt(Position.X, Position.Y, Distance, Position.X, Position.Y, 0f, 0, 1, 0);
}
+ ///
protected override bool WorldCalculation(IGenericWindow window, out Matrix4 world)
{
world = Matrix4.Identity;
@@ -57,6 +80,11 @@ namespace SM2D.Scene
return false;
}
+ ///
+ /// This calculates the world scale.
+ /// Usually gets called, by the camera itself, but if you need the world scale for additional calculations, you can execute it by yourself.
+ ///
+ ///
public void CalculateWorldScale(IGenericWindow window)
{
if (RequestedWorldScale.HasValue)
diff --git a/SMCode/SM2D/Scene/I2DShowItem.cs b/SMCode/SM2D/Scene/I2DShowItem.cs
deleted file mode 100644
index 7e8a95c..0000000
--- a/SMCode/SM2D/Scene/I2DShowItem.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-#region usings
-
-using SM.Base.Scene;
-
-#endregion
-
-namespace SM2D.Scene
-{
- public interface I2DShowItem : IShowItem
- {
- int ZIndex { get; set; }
- }
-}
\ No newline at end of file
diff --git a/SMCode/SM2D/Scene/ItemCollection.cs b/SMCode/SM2D/Scene/ItemCollection.cs
index bbe47eb..51f7f0d 100644
--- a/SMCode/SM2D/Scene/ItemCollection.cs
+++ b/SMCode/SM2D/Scene/ItemCollection.cs
@@ -2,23 +2,19 @@
using SM.Base.Scene;
using SM.Base.Types;
-using SM.Base.Window;
using SM2D.Types;
#endregion
namespace SM2D.Scene
{
+ ///
public class ItemCollection : GenericItemCollection
{
+ ///
public ItemCollection()
{
Transform.Size = new CVector2(1);
}
-
- public override void Draw(DrawContext context)
- {
- base.Draw(context);
- }
}
}
\ No newline at end of file
diff --git a/SMCode/SM2D/Scene/Scene.cs b/SMCode/SM2D/Scene/Scene.cs
index 2fd4663..e6f2641 100644
--- a/SMCode/SM2D/Scene/Scene.cs
+++ b/SMCode/SM2D/Scene/Scene.cs
@@ -11,17 +11,25 @@ using SM2D.Drawing;
namespace SM2D.Scene
{
+ ///
+ /// The scene allows connecting different objects to render together.
+ ///
public class Scene : GenericScene
{
- private static DrawObject2D _axisHelper;
+ private static readonly DrawObject2D _axisHelper;
+ ///
+ /// This determent how large the axishelper should be.
+ ///
public float AxisHelperSize = 100;
static Scene()
{
- _axisHelper = new DrawObject2D();
- _axisHelper.Mesh = AxisHelper.Object;
+ _axisHelper = new DrawObject2D {Mesh = AxisHelper.Object};
}
+ ///
+ /// This creates a new scene.
+ ///
public Scene()
{
_Background = new DrawBackground(Color4.Black);
@@ -32,12 +40,16 @@ namespace SM2D.Scene
}
+ ///
+ /// Gets/Sets the background.
+ ///
public DrawBackground Background
{
get => (DrawBackground) _Background;
set => _Background = value;
}
+ ///
public override void DrawHUD(DrawContext context)
{
context.ModelMatrix *= Matrix4.CreateTranslation(0,0,1);
@@ -45,6 +57,7 @@ namespace SM2D.Scene
base.DrawHUD(context);
}
+ ///
public override void DrawDebug(DrawContext context)
{
if (ShowAxisHelper)
diff --git a/SMCode/SM2D/Shader/ShaderCollection.cs b/SMCode/SM2D/Shader/ShaderCollection.cs
index a6837ba..e7dacf8 100644
--- a/SMCode/SM2D/Shader/ShaderCollection.cs
+++ b/SMCode/SM2D/Shader/ShaderCollection.cs
@@ -5,9 +5,15 @@ using SM.OGL.Shaders;
namespace SM2D.Shader
{
- public class ShaderCollection
+ class ShaderCollection
{
+ ///
+ /// The most basic shader, that renders only one thing and only allows colors and one texture.
+ ///
public static SimpleShader Basic = new SimpleShader("basic", AssemblyUtility.ReadAssemblyFile("SM2D.Shader.ShaderFiles.basic.glsl"), SetUniforms);
+ ///
+ /// The same fragment shader as , but allows to be instanced and used in (f.E.) text.
+ ///
public static SimpleShader Instanced = new SimpleShader("instanced", AssemblyUtility.ReadAssemblyFile("SM2D.Shader.ShaderFiles.basic.glsl"), SetUniforms);
static void SetUniforms(UniformCollection uniforms, DrawContext context)
diff --git a/SMCode/SM2D/Shader/ShaderFiles/basic.glsl b/SMCode/SM2D/Shader/ShaderFiles/basic.glsl
index 075b00f..95d50a5 100644
--- a/SMCode/SM2D/Shader/ShaderFiles/basic.glsl
+++ b/SMCode/SM2D/Shader/ShaderFiles/basic.glsl
@@ -11,5 +11,4 @@ layout(location = 0) out vec4 color;
void main() {
color = v_Color * Tint;
if (UseTexture) color *= texture(Texture, v_TexCoords);
- color *= 1.2;
}
\ No newline at end of file
diff --git a/SMCode/SM2D/Types/Transformation.cs b/SMCode/SM2D/Types/Transformation.cs
index 7fb80ee..31fa815 100644
--- a/SMCode/SM2D/Types/Transformation.cs
+++ b/SMCode/SM2D/Types/Transformation.cs
@@ -10,22 +10,46 @@ using SM.Base.Utility;
namespace SM2D.Types
{
+ ///
public class Transformation : GenericTransformation
{
- public static int ZIndexPercision = 300;
+ ///
+ /// The precision of the Z-Index.
+ /// High values can result into "z-fighting" and cliping.
+ ///
+ public static int ZIndexPercision = 100;
+ ///
+ /// The transformations translation.
+ ///
public CVector2 Position { get; set; } = new CVector2(0);
+ ///
+ /// The scaling.
+ ///
public CVector2 Size { get; set; } = new CVector2(50);
+ ///
+ /// The rotation.
+ ///
public CVector1 Rotation { get; set; } = new CVector1(0);
+ ///
+ /// If true, the object get rotated on the X-Axis by 180°.
+ ///
public bool HorizontalFlip { get; set; } = false;
+ ///
+ /// If true, the object get rotated on the Y-Axis by 180°.
+ ///
public bool VerticalFlip { get; set; } = false;
+ ///
+ /// The ZIndex.
+ ///
public CVector1 ZIndex { get; set; } = new CVector1(0);
+ ///
protected override Matrix4 RequestMatrix()
{
float z = 1 / (float) ZIndexPercision * ZIndex;
@@ -37,11 +61,18 @@ namespace SM2D.Types
Matrix4.CreateTranslation(Position.X, Position.Y, z);
}
- public void TurnTo(Vector2 v)
+ ///
+ /// Rotates the object, so it SHOULD turn toward the position.
+ ///
+ public void TurnTo(Vector2 turnposition)
{
- Rotation.Set(RotationUtility.TurnTowards(Position, v));
+ Rotation.Set(RotationUtility.TurnTowards(Position, turnposition));
}
+ ///
+ /// Returns the vector the object is looking.
+ ///
+ ///
public Vector2 LookAtVector()
{
if (_modelMatrix.Determinant < 0.0001) return new Vector2(0);
@@ -51,11 +82,20 @@ namespace SM2D.Types
return vec.Xy;
}
+ ///
+ /// The object scale gets set to the same as the resolution of the texture.
+ ///
+ ///
public void ApplyTextureSize(Texture texture)
{
Size.Set(texture.Width, texture.Height);
}
+ ///
+ /// The object scale gets set to the same aspect ratio as the texture and then it will set the width..
+ ///
+ ///
+ ///
public void ApplyTextureSize(Texture texture, float width)
{
Size.Set(width, width / texture.Aspect);
diff --git a/SMCode/SM2D/Window/I2DSetup.cs b/SMCode/SM2D/Window/I2DSetup.cs
deleted file mode 100644
index 64bdf04..0000000
--- a/SMCode/SM2D/Window/I2DSetup.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using OpenTK;
-using SM.Base.Window;
-
-namespace SM2D
-{
- public interface I2DSetup : ISetup
- {
- Vector2? WorldScale { get; set; }
- }
-}
\ No newline at end of file
diff --git a/SMCode/SM2D/Window/Window2DSetup.cs b/SMCode/SM2D/Window/Window2DSetup.cs
index 9bb5360..9b340e1 100644
--- a/SMCode/SM2D/Window/Window2DSetup.cs
+++ b/SMCode/SM2D/Window/Window2DSetup.cs
@@ -7,10 +7,12 @@ using SM2D.Shader;
namespace SM2D
{
- public struct Window2DSetup : I2DSetup
+ ///
+ /// Sets up a 2D window.
+ ///
+ public struct Window2DSetup : ISetup
{
- public Vector2? WorldScale { get; set; }
-
+ ///
public void Applied(IGenericWindow window)
{
window.ViewportCamera = new Camera();
@@ -18,16 +20,18 @@ namespace SM2D
SMRenderer.DefaultMaterialShader = ShaderCollection.Instanced;
}
+ ///
public void Load(IGenericWindow window)
{
- (window.ViewportCamera as Camera).RequestedWorldScale = WorldScale;
GL.Enable(EnableCap.DepthTest);
}
+ ///
public void Loaded(IGenericWindow window)
{
}
+ ///
public void Resize(IGenericWindow window)
{
Camera.ResizeCounter++;
diff --git a/SM_TEST/Program.cs b/SM_TEST/Program.cs
index 892c992..bed67ca 100644
--- a/SM_TEST/Program.cs
+++ b/SM_TEST/Program.cs
@@ -21,13 +21,13 @@ namespace SM_TEST
{
font = new Font(@"C:\Windows\Fonts\Arial.ttf")
{
- FontSize = 32
+ FontSize = 16
};
- Log.SetLogFile(compressionFolder:"logs");
+ //Log.SetLogFile(compressionFolder:"logs");
window = new GLWindow {VSync = VSyncMode.Off};
- window.ApplySetup(new Window2DSetup() {WorldScale = new Vector2(0,1000)});
+ window.ApplySetup(new Window2DSetup());
window.SetRenderPipeline(new TestRenderPipeline());
window.SetScene(scene = new Scene());
window.RunFixedUpdate(60);
@@ -36,15 +36,8 @@ namespace SM_TEST
window.Run();
}
- private static DrawParticles particles;
private static void WindowOnUpdateFrame(object sender, FrameEventArgs e)
{
- if (Keyboard.GetState()[Key.R])
- particles.Trigger();
- //particles.Paused = Keyboard.GetState()[Key.P];
-
- GameControllerState s1 = new GameController(0).GetState();
- GameControllerState s2 = new GameController(1).GetState();
}
private static void WindowOnLoad(IGenericWindow window)
diff --git a/SM_TEST/TestRenderPipeline.cs b/SM_TEST/TestRenderPipeline.cs
index fe53e1c..652abd6 100644
--- a/SM_TEST/TestRenderPipeline.cs
+++ b/SM_TEST/TestRenderPipeline.cs
@@ -13,11 +13,11 @@ namespace SM_TEST
public override void Initialization()
{
- MainFramebuffer = CreateWindowFramebuffer(16);
+ MainFramebuffer = CreateWindowFramebuffer(0);
_postBuffer = CreateWindowFramebuffer();
Framebuffers.Add(_postBuffer);
- _bloom = new BloomEffect(MainFramebuffer, hdr: true, .5f)
+ _bloom = new BloomEffect(MainFramebuffer, hdr: true, .75f)
{
Threshold = .5f,
};