From 8296d9b8a907104347af6a84dbec1df4bd2524c3 Mon Sep 17 00:00:00 2001 From: Michel Fedde Date: Fri, 19 Mar 2021 20:59:02 +0100 Subject: [PATCH 1/5] Added Summeries --- .gitignore | 1 + SMCode/SM.Base/Controls/Mouse.cs | 22 +++ SMCode/SM.Base/Drawing/DrawingBasis.cs | 1 + SMCode/SM.Base/SM.Base.csproj | 9 - SMCode/SM.Base/Scene/GenericItemCollection.cs | 17 +- SMCode/SM.Base/Scene/GenericScene.cs | 18 +- SMCode/SM.Base/Scene/IShowItem.cs | 17 ++ SMCode/SM.Base/Types/CVector1.cs | 14 +- SMCode/SM.Base/Types/CVector2.cs | 9 +- SMCode/SM.Base/Types/CVector3.cs | 6 + .../SM.Base/Window/Contexts/UpdateContext.cs | 12 ++ SMCode/SM.Base/Window/GLWindow.cs | 177 ++++++++++++------ SMCode/SM.Base/Window/IGenericWindow.cs | 67 +++++++ SMCode/SM.Base/packages.config | 6 +- SMCode/SM.OGL/Framebuffer/ColorAttachment.cs | 8 +- SMCode/SM.OGL/Framebuffer/Framebuffer.cs | 17 +- .../SM.OGL/Framebuffer/IFramebufferWindow.cs | 6 + SMCode/SM.OGL/GLObject.cs | 25 ++- SMCode/SM.OGL/Mesh/BoundingBox.cs | 42 +++++ SMCode/SM.OGL/Mesh/GenericMesh.cs | 11 +- SMCode/SM.OGL/Mesh/MeshAttribute.cs | 6 + SMCode/SM.OGL/Mesh/MeshAttributeList.cs | 5 + SMCode/SM.OGL/Mesh/VBO.cs | 8 + SMCode/SM.OGL/Shaders/GenericShader.cs | 20 +- SMCode/SM.OGL/Shaders/UniformArray.cs | 31 ++- SMCode/SM.OGL/Shaders/UniformCollection.cs | 42 ++++- SMCode/SM2D/Controls/Mouse2D.cs | 48 +++++ SMCode/SM2D/Drawing/DrawBackground.cs | 26 +++ SMCode/SM2D/Drawing/DrawObject2D.cs | 36 +++- SMCode/SM2D/Drawing/DrawParticles.cs | 7 + SMCode/SM2D/Drawing/DrawText.cs | 7 + SMCode/SM2D/Object/PolyLine.cs | 26 +++ SMCode/SM2D/Object/Polygon.cs | 38 +++- SMCode/SM2D/Object/PolygonVertex.cs | 25 ++- SMCode/SM2D/Pipelines/Basic2DPipeline.cs | 9 + SMCode/SM2D/SM2D.csproj | 8 +- SMCode/SM2D/Scene/Camera.cs | 28 +++ SMCode/SM2D/Scene/I2DShowItem.cs | 13 -- SMCode/SM2D/Scene/ItemCollection.cs | 8 +- SMCode/SM2D/Scene/Scene.cs | 19 +- SMCode/SM2D/Shader/ShaderCollection.cs | 8 +- SMCode/SM2D/Shader/ShaderFiles/basic.glsl | 1 - SMCode/SM2D/Types/Transformation.cs | 46 ++++- SMCode/SM2D/Window/I2DSetup.cs | 10 - SMCode/SM2D/Window/Window2DSetup.cs | 12 +- SM_TEST/Program.cs | 13 +- SM_TEST/TestRenderPipeline.cs | 4 +- 47 files changed, 812 insertions(+), 177 deletions(-) delete mode 100644 SMCode/SM2D/Scene/I2DShowItem.cs delete mode 100644 SMCode/SM2D/Window/I2DSetup.cs 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, }; From e24f7ebfb930c210975bddd06d6596a8e0332924 Mon Sep 17 00:00:00 2001 From: Michel Fedde Date: Fri, 19 Mar 2021 22:09:36 +0100 Subject: [PATCH 2/5] Made SM2D Nuget ready --- .gitignore | 4 ++++ SMCode/SM2D/SM2D.csproj | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 731df43..5d68136 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,10 @@ *.userosscache *.sln.docstates +# Dev-Added files +*.nuspec +*/*/nuget.exe + # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/SMCode/SM2D/SM2D.csproj b/SMCode/SM2D/SM2D.csproj index 6463877..f4b25f5 100644 --- a/SMCode/SM2D/SM2D.csproj +++ b/SMCode/SM2D/SM2D.csproj @@ -1,6 +1,5 @@  - Debug AnyCPU From a9c53a1e52b01cc6f31afd3ebd91e45f19b71087 Mon Sep 17 00:00:00 2001 From: Michel Fedde Date: Fri, 19 Mar 2021 22:57:10 +0100 Subject: [PATCH 3/5] Fixed few problems with render pipeline. --- SMCode/SM.Base/Window/RenderPipeline.cs | 7 +++--- SMCode/SM2D/Pipelines/Basic2DPipeline.cs | 9 +++++-- SMCode/SM2D/Properties/AssemblyInfo.cs | 3 +-- SM_TEST/Program.cs | 32 +++--------------------- SM_TEST/SM_TEST.csproj | 13 +++------- 5 files changed, 19 insertions(+), 45 deletions(-) diff --git a/SMCode/SM.Base/Window/RenderPipeline.cs b/SMCode/SM.Base/Window/RenderPipeline.cs index 7365cb5..649d11a 100644 --- a/SMCode/SM.Base/Window/RenderPipeline.cs +++ b/SMCode/SM.Base/Window/RenderPipeline.cs @@ -53,9 +53,10 @@ namespace SM.Base.Window /// public virtual void Initialization() { - MainFramebuffer.Name = GetType().Name + ".MainFramebuffer"; - - if (MainFramebuffer != null) Framebuffers.Add(MainFramebuffer); + if (MainFramebuffer != null) { + Framebuffers.Add(MainFramebuffer); + MainFramebuffer.Name = GetType().Name + ".MainFramebuffer"; + } DefaultShader ??= SMRenderer.DefaultMaterialShader; } diff --git a/SMCode/SM2D/Pipelines/Basic2DPipeline.cs b/SMCode/SM2D/Pipelines/Basic2DPipeline.cs index 2945fe0..0b1b0e8 100644 --- a/SMCode/SM2D/Pipelines/Basic2DPipeline.cs +++ b/SMCode/SM2D/Pipelines/Basic2DPipeline.cs @@ -1,5 +1,7 @@ -using SM.Base.Shaders; +using OpenTK.Graphics.OpenGL4; +using SM.Base.Shaders; using SM.Base.Window; +using SM.OGL.Framebuffer; using SM2D.Shader; namespace SM2D.Pipelines @@ -12,7 +14,8 @@ namespace SM2D.Pipelines /// /// The access to the pipeline. /// - public static Basic2DPipeline Pipeline = new Basic2DPipeline(); + public static Basic2DPipeline Pipeline = + new Basic2DPipeline(); /// public override MaterialShader DefaultShader { get; protected set; } = ShaderCollection.Instanced; @@ -22,6 +25,8 @@ namespace SM2D.Pipelines /// protected override void RenderProcess(ref DrawContext context) { + Framebuffer.Screen.Activate(FramebufferTarget.Framebuffer, ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); + context.Scene?.Draw(context); } } diff --git a/SMCode/SM2D/Properties/AssemblyInfo.cs b/SMCode/SM2D/Properties/AssemblyInfo.cs index 634ede6..d73b59d 100644 --- a/SMCode/SM2D/Properties/AssemblyInfo.cs +++ b/SMCode/SM2D/Properties/AssemblyInfo.cs @@ -35,5 +35,4 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file +[assembly: AssemblyVersion("1.0.1.1")] \ No newline at end of file diff --git a/SM_TEST/Program.cs b/SM_TEST/Program.cs index bed67ca..bc5c4f6 100644 --- a/SM_TEST/Program.cs +++ b/SM_TEST/Program.cs @@ -3,9 +3,8 @@ using OpenTK.Graphics; using OpenTK.Input; using SM.Base; using SM.Base.Window; -using SM.Game.Controls; using SM2D; -using SM2D.Drawing; +using SM2D.Pipelines; using SM2D.Scene; using Font = SM.Base.Drawing.Text.Font; using Vector2 = OpenTK.Vector2; @@ -19,20 +18,10 @@ namespace SM_TEST private static GLWindow window; static void Main(string[] args) { - font = new Font(@"C:\Windows\Fonts\Arial.ttf") - { - FontSize = 16 - }; - - //Log.SetLogFile(compressionFolder:"logs"); - - window = new GLWindow {VSync = VSyncMode.Off}; + window = new GLWindow(); window.ApplySetup(new Window2DSetup()); - window.SetRenderPipeline(new TestRenderPipeline()); + window.SetRenderPipeline(Basic2DPipeline.Pipeline); window.SetScene(scene = new Scene()); - window.RunFixedUpdate(60); - window.Load += WindowOnLoad; - window.RenderFrame += WindowOnUpdateFrame; window.Run(); } @@ -41,19 +30,6 @@ namespace SM_TEST } private static void WindowOnLoad(IGenericWindow window) - { - scene.ShowAxisHelper = true; - //scene.Background.Color = Color4.White; - - DrawObject2D box = new DrawObject2D(); - scene.Objects.Add(box); - - DrawText text = new DrawText(font, "Test Text"); - text.Transform.Position.Set(50, 0); - text.Transform.Size.Set(2); - scene.HUD.Add(text); - - //particles.Trigger(); - } + { } } } \ No newline at end of file diff --git a/SM_TEST/SM_TEST.csproj b/SM_TEST/SM_TEST.csproj index 8658e18..b84ebe5 100644 --- a/SM_TEST/SM_TEST.csproj +++ b/SM_TEST/SM_TEST.csproj @@ -36,12 +36,6 @@ ..\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 - @@ -56,6 +50,9 @@ + + + {8e733844-4204-43e7-b3dc-3913cddabb0d} @@ -69,10 +66,6 @@ {a4565538-625a-42c6-a330-dd4f1abb3986} SM2D - - {079bab31-3dc4-40da-90c7-efaa8517c647} - SM.Game - \ No newline at end of file From 261a3be02d8baa335ea49193c3e7b11990b5d57b Mon Sep 17 00:00:00 2001 From: Michel Fedde Date: Sat, 20 Mar 2021 10:22:30 +0100 Subject: [PATCH 4/5] Updated gitignore; Removed MigrationBackup and Legacy --- .gitignore | 1 + Legacy/Window/Contexts/DrawContext.cs | 103 ------ Legacy/Window/Contexts/UpdateContext.cs | 32 -- Legacy/Window/GLWPFWindow2D.cs | 48 --- Legacy/Window/GLWindow2D.cs | 65 ---- Legacy/Window/GenericWPFWindow.cs | 106 ------- Legacy/Window/GenericWindow.cs | 296 ------------------ Legacy/Window/GenericWindowCode.cs | 107 ------- Legacy/Window/IGLWindow2D.cs | 14 - Legacy/Window/IGenericWindow.cs | 37 --- Legacy/Window/RenderPipeline.cs | 150 --------- .../SMRenderer/SM2D/NuGetUpgradeLog.html | 162 ---------- .../d4ed0f1f/SMRenderer/SM2D/SM2D.csproj | 82 ----- .../d4ed0f1f/SMRenderer/SM2D/packages.config | 4 - 14 files changed, 1 insertion(+), 1206 deletions(-) delete mode 100644 Legacy/Window/Contexts/DrawContext.cs delete mode 100644 Legacy/Window/Contexts/UpdateContext.cs delete mode 100644 Legacy/Window/GLWPFWindow2D.cs delete mode 100644 Legacy/Window/GLWindow2D.cs delete mode 100644 Legacy/Window/GenericWPFWindow.cs delete mode 100644 Legacy/Window/GenericWindow.cs delete mode 100644 Legacy/Window/GenericWindowCode.cs delete mode 100644 Legacy/Window/IGLWindow2D.cs delete mode 100644 Legacy/Window/IGenericWindow.cs delete mode 100644 Legacy/Window/RenderPipeline.cs delete mode 100644 MigrationBackup/d4ed0f1f/SMRenderer/SM2D/NuGetUpgradeLog.html delete mode 100644 MigrationBackup/d4ed0f1f/SMRenderer/SM2D/SM2D.csproj delete mode 100644 MigrationBackup/d4ed0f1f/SMRenderer/SM2D/packages.config diff --git a/.gitignore b/.gitignore index 5d68136..76f1e51 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ # Dev-Added files *.nuspec */*/nuget.exe +**/apireference/** # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/Legacy/Window/Contexts/DrawContext.cs b/Legacy/Window/Contexts/DrawContext.cs deleted file mode 100644 index cb449f5..0000000 --- a/Legacy/Window/Contexts/DrawContext.cs +++ /dev/null @@ -1,103 +0,0 @@ -#region usings - -using System.Collections.Generic; -using System.Dynamic; -using OpenTK; -using SM.Base.Drawing; -using SM.Base.Scene; -using SM.OGL.Mesh; - -#endregion - -namespace SM.Base.Contexts -{ - /// - /// Contains important information for drawing. - /// - public struct DrawContext - { - /// - /// This says if it was forced to use the viewport camera. - /// - public bool ForceViewport; - - /// - /// Contains the currently used render pipeline. - /// - public RenderPipeline ActivePipeline; - - public GenericScene ActiveScene; - public IGenericWindow Window; - - - public GenericCamera UsedCamera => - ForceViewport || ActiveScene._camera == null ? Window.ViewportCamera : ActiveScene._camera; - - - - /// - /// The mesh. - /// - public GenericMesh Mesh; - - /// - /// The material. - /// - public Material Material; - - /// - /// The drawing instances. - /// If there is only one, it's index 0 - /// - public IList Instances; - - - - /// - /// The current world scale. - /// - public Vector2 WorldScale; - - /// - /// The last collection the context was passed though. - /// - public object LastPassthough; - - - - /// - /// Returns the appropriate shader. - /// - /// Returns the material shader, if available, otherwise it will take the default shader from the render - /// pipeline. - /// - /// - public MaterialShader Shader => Material.CustomShader ?? ActivePipeline._defaultShader; - /// - /// Arguments for shaders - /// - public IDictionary ShaderArguments; - - - - /// - /// The current world matrix. - /// - public Matrix4 World; - - /// - /// The current view matrix. - /// - public Matrix4 View; - - /// - /// The current WorldView matrix. - /// - public Matrix4 WorldView; - - /// - /// The master model matrix. - /// - public Matrix4 ModelMaster; - } -} \ No newline at end of file diff --git a/Legacy/Window/Contexts/UpdateContext.cs b/Legacy/Window/Contexts/UpdateContext.cs deleted file mode 100644 index 63eb913..0000000 --- a/Legacy/Window/Contexts/UpdateContext.cs +++ /dev/null @@ -1,32 +0,0 @@ -#region usings - -using OpenTK.Input; -using SM.Base.Scene; - -#endregion - -namespace SM.Base.Contexts -{ - /// - /// The update context. - /// - public struct UpdateContext - { - /// - /// The delta time. - /// - public float Deltatime => SMRenderer.DefaultDeltatime.DeltaTime; - - /// - /// The current keyboard state. - /// - public KeyboardState KeyboardState; - - /// - /// The current mouse state. - /// - public MouseState MouseState; - - public GenericScene CurrentScene; - } -} \ No newline at end of file diff --git a/Legacy/Window/GLWPFWindow2D.cs b/Legacy/Window/GLWPFWindow2D.cs deleted file mode 100644 index f334bac..0000000 --- a/Legacy/Window/GLWPFWindow2D.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Windows.Media; -using OpenTK; -using OpenTK.Graphics.ES11; -using SM.Base; -using SM2D.Controls; -using SM2D.Pipelines; -using SM2D.Scene; -using SM2D.Shader; - -namespace SM2D -{ - public class GLWPFWindow2D : GenericWPFWindow, IGLWindow2D - { - public GLWPFWindow2D() - { - Mouse = new Mouse2D(this); - } - - public Vector2? Scaling { get; set; } - public Mouse2D Mouse { get; } - - protected override void Init() - { - base.Init(); - - SMRenderer.DefaultMaterialShader = Default2DShader.MaterialShader; - - //SetRenderPipeline(Default2DPipeline.Pipeline); - } - - protected override void Rendering(TimeSpan delta) - { - GL.Disable(EnableCap.DepthTest); - base.Rendering(delta); - } - - public override void SetWorldScale() - { - if (Scaling.HasValue) - { - if (Scaling.Value.X > 0 && Scaling.Value.Y > 0) WorldScale = Scaling.Value; - else if (Scaling.Value.X > 0) WorldScale = new Vector2(Scaling.Value.X, Scaling.Value.X / Aspect); - else if (Scaling.Value.Y > 0) WorldScale = new Vector2(Aspect * Scaling.Value.Y, Scaling.Value.Y); - } - } - } -} \ No newline at end of file diff --git a/Legacy/Window/GLWindow2D.cs b/Legacy/Window/GLWindow2D.cs deleted file mode 100644 index dc3924d..0000000 --- a/Legacy/Window/GLWindow2D.cs +++ /dev/null @@ -1,65 +0,0 @@ -#region usings - -using System; -using OpenTK; -using OpenTK.Graphics.OpenGL4; -using OpenTK.Input; -using SM.Base; -using SM2D.Controls; -using SM2D.Pipelines; -using SM2D.Scene; -using SM2D.Shader; - -#endregion - -namespace SM2D -{ - public class GLWindow2D : GenericWindow, IGLWindow2D - { - public GLWindow2D() - { - Mouse = new Mouse2D(this); - } - - public Vector2? Scaling { get; set; } - - public Mouse2D Mouse { get; } - - protected override void OnLoad(EventArgs e) - { - base.OnLoad(e); - GL.Enable(EnableCap.Blend); - GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); - } - - protected override void OnLoaded() - { - base.OnLoaded(); - SMRenderer.DefaultMaterialShader = Default2DShader.MaterialShader; - - SetRenderPipeline(Default2DPipeline.Pipeline); - } - - protected override void OnRenderFrame(FrameEventArgs e) - { - GL.Disable(EnableCap.DepthTest); - base.OnRenderFrame(e); - } - - public override void SetWorldScale() - { - if (Scaling.HasValue) - { - if (Scaling.Value.X > 0 && Scaling.Value.Y > 0) WorldScale = Scaling.Value; - else if (Scaling.Value.X > 0) WorldScale = new Vector2(Scaling.Value.X, Scaling.Value.X / Aspect); - else if (Scaling.Value.Y > 0) WorldScale = new Vector2(Aspect * Scaling.Value.Y, Scaling.Value.Y); - } - } - - protected override void OnMouseMove(MouseMoveEventArgs e) - { - base.OnMouseMove(e); - Mouse.MouseMoveEvent(e); - } - } -} \ No newline at end of file diff --git a/Legacy/Window/GenericWPFWindow.cs b/Legacy/Window/GenericWPFWindow.cs deleted file mode 100644 index f36ff3b..0000000 --- a/Legacy/Window/GenericWPFWindow.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System; -using System.Drawing; -using System.Windows; -using System.Windows.Media; -using OpenTK; -using OpenTK.Wpf; -using SM.Base.Scene; -using SM.OGL; - -namespace SM.Base -{ - public class GenericWPFWindow : OpenTK.Wpf.GLWpfControl, IGenericWindow - { - protected GenericCamera _viewportCamera; - - public bool Loading => !base.IsInitialized; - public float Aspect { get; set; } - public GenericCamera ViewportCamera => _viewportCamera; - public bool ForceViewportCamera { get; set; } - public int Width => (int) base.ActualWidth; - public int Height => (int) base.ActualHeight; - public Rectangle ClientRectangle => new Rectangle((int)base.RenderTransformOrigin.X, (int)RenderTransformOrigin.Y, Width, Height); - public Vector2 WorldScale { get; set; } - - public GenericWPFWindow() - { - - Ready += Init; - Render += Rendering; - } - - protected virtual void Init() - { - GenericWindowCode.Load(this); - } - - protected virtual void Rendering(TimeSpan delta) - { - - } - - protected override void OnRenderSizeChanged(SizeChangedInfo info) - { - base.OnRenderSizeChanged(info); - - GenericWindowCode.Resize(this); - } - - public void Start(bool renderContinuesly = false) - { - GLWpfControlSettings settings = new GLWpfControlSettings() - { - MajorVersion = GLSettings.ForcedVersion.MajorVersion, - MinorVersion = GLSettings.ForcedVersion.MinorVersion, - RenderContinuously = renderContinuesly - }; - base.Start(settings); - } - - public virtual void SetWorldScale() - { } - } - - public class GenericWPFWindow : GenericWPFWindow, IGenericWindow - where TScene : GenericScene, new() - where TCamera : GenericCamera, new() - { - private TScene _scene; - private RenderPipeline _renderPipeline; - - public TScene CurrentScene => _scene; - public RenderPipeline RenderPipeline => _renderPipeline; - - public GenericWPFWindow() : base() - { - _viewportCamera = new TCamera(); - } - - protected override void Rendering(TimeSpan delta) - { - base.Rendering(delta); - - GenericWindowCode.Render(this, (float)delta.TotalSeconds); - } - - protected override void OnRenderSizeChanged(SizeChangedInfo info) - { - base.OnRenderSizeChanged(info); - - GenericWindowCode.Resize(this); - } - - public void SetScene(TScene scene) - { - _scene = scene; - scene.Activate(); - RenderPipeline?.SceneChanged(scene); - } - - public void SetRenderPipeline(RenderPipeline renderPipeline) - { - _renderPipeline = renderPipeline; - renderPipeline.Activate(this); - } - } -} \ No newline at end of file diff --git a/Legacy/Window/GenericWindow.cs b/Legacy/Window/GenericWindow.cs deleted file mode 100644 index cb6a887..0000000 --- a/Legacy/Window/GenericWindow.cs +++ /dev/null @@ -1,296 +0,0 @@ -#region usings - -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using OpenTK; -using OpenTK.Graphics; -using OpenTK.Graphics.OpenGL4; -using OpenTK.Input; -using SM.Base.Contexts; -using SM.Base.Drawing; -using SM.Base.Objects.Static; -using SM.Base.PostProcess; -using SM.Base.Scene; -using SM.Base.ShaderExtension; -using SM.Base.Time; -using SM.OGL; -using SM.OGL.Framebuffer; -using SM.Utility; - -#endregion - -namespace SM.Base -{ - /// - /// The base window. - /// - public abstract class GenericWindow : GameWindow, IGenericWindow - { - protected GenericCamera _viewportCamera; - - internal bool _loading = true; - internal List _actionsAfterLoading = new List(); - - public bool Loading => _loading; - - /// - /// This tells you the current world scale. - /// - public Vector2 WorldScale { get; set; } = Vector2.Zero; - - /// - /// This tells you the current aspect ratio of this window. - /// - public float Aspect { get; set; } - - /// - /// If false, the window will not react on updates and will not render something. - /// - /// Default: false - /// - /// - public bool ReactWhileUnfocused = false; - - public GenericCamera ViewportCamera => _viewportCamera; - public bool ForceViewportCamera { get; set; } - - /// - protected GenericWindow() : this(1280, 720, "Generic OGL Title", GameWindowFlags.Default) - { - } - - /// - /// Creates a window... - /// - protected GenericWindow(int width, int height, string title, GameWindowFlags flags, bool vSync = true) : base(width, height, - GraphicsMode.Default, title, flags, DisplayDevice.Default, GLSettings.ForcedVersion.MajorVersion, - GLSettings.ForcedVersion.MinorVersion, GraphicsContextFlags.Default) - { - VSync = vSync ? VSyncMode.On : VSyncMode.Off; - } - - - /// - protected override void OnLoad(EventArgs e) - { - GenericWindowCode.Load(this); - - base.OnLoad(e); - } - - /// - protected override void OnResize(EventArgs e) - { - base.OnResize(e); - - GenericWindowCode.Resize(this); - - if (_loading) - { - _loading = false; - - OnLoaded(); - - _actionsAfterLoading.ForEach(a => a()); - _actionsAfterLoading = null; - } - } - - /// - /// This is triggered after all the window-loading has been done. - /// - protected virtual void OnLoaded() - { - } - - /// - /// Sets the world scale. - /// - public virtual void SetWorldScale() - { - } - - /// - protected override void OnUpdateFrame(FrameEventArgs e) - { - if (!ReactWhileUnfocused && !Focused) return; - - base.OnUpdateFrame(e); - - Deltatime.UpdateDelta = (float) e.Time; - var context = new UpdateContext - { - KeyboardState = Keyboard.GetState(), - MouseState = Mouse.GetState() - }; - - if (context.KeyboardState[Key.AltLeft] && context.KeyboardState[Key.F4]) Close(); - - Update(e, ref context); - } - - /// - /// Updates the system. - /// - /// - /// - protected virtual void Update(FrameEventArgs e, ref UpdateContext context) - { - Stopwatch.PerformTicks(context); - } - - /// - /// Grabs the cursor and make sure it doesn't leave the window. - /// - /// If true, it makes the cursor invisible. - public void GrabCursor(bool makeItInvisible = true) - { - CursorGrabbed = true; - CursorVisible = !makeItInvisible; - } - - /// - /// Ungrabs the cursor. - /// - public void UngrabCursor() - { - CursorGrabbed = false; - if (!CursorVisible) CursorVisible = true; - } - - /// - /// Create a bitmap from the framebuffer. - /// - public Bitmap TakeScreenshot(Framebuffer framebuffer, ReadBufferMode readBuffer, int x, int y, int width, int height) - { - GL.GetInteger(GetPName.FramebufferBinding, out int prevFBId); - GL.GetInteger(GetPName.DrawFramebufferBinding, out int prevFBDrawId); - GL.GetInteger(GetPName.ReadFramebufferBinding, out int prevFBReadId); - - Bitmap b = new Bitmap(width, height); - System.Drawing.Imaging.BitmapData bits = b.LockBits(new Rectangle(0, 0, width, height), - System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); - - GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, framebuffer); - GL.ReadBuffer(readBuffer); - GL.ReadPixels(x, y, width, height, OpenTK.Graphics.OpenGL4.PixelFormat.Bgra, PixelType.UnsignedByte, - bits.Scan0); - - b.UnlockBits(bits); - b.RotateFlip(RotateFlipType.RotateNoneFlipY); - - GL.BindFramebuffer(FramebufferTarget.Framebuffer, prevFBId); - GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, prevFBDrawId); - GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, prevFBReadId); - - return b; - } - } - - /// - /// The base window. - /// - /// The scene type - /// The camera type - public abstract class GenericWindow : GenericWindow, IGenericWindow - where TScene : GenericScene, new() - where TCamera : GenericCamera, new() - { - private RenderPipeline _renderPipeline; - private TScene _scene; - - /// - protected GenericWindow() - { - _viewportCamera = new TCamera(); - } - - /// - /// The viewport camera. - /// - public TCamera ViewportCamera { - get => (TCamera)_viewportCamera; - set => _viewportCamera = value; - } - - /// - /// This forces the render to use the viewport camera. - /// - public bool ForceViewportCamera { get; set; } = false; - - /// - /// The current scene. - /// - public TScene CurrentScene => _scene; - - /// - /// Controls how a scene is rendered. - /// - public RenderPipeline RenderPipeline => _renderPipeline; - - /// - protected override void Update(FrameEventArgs e, ref UpdateContext context) - { - base.Update(e, ref context); - context.CurrentScene = CurrentScene; - CurrentScene?.Update(context); - } - - /// - protected override void OnRenderFrame(FrameEventArgs e) - { - if (!ReactWhileUnfocused && !Focused) return; - - base.OnRenderFrame(e); - - GenericWindowCode.Render(this, (float)e.Time); - - SwapBuffers(); - - GLDebugging.CheckGLErrors(); - } - - /// - protected override void OnResize(EventArgs e) - { - base.OnResize(e); - - GenericWindowCode.Resize(this); - } - - /// - /// Sets the scene. - /// - /// - public virtual void SetScene(TScene scene) - { - if (_loading) - { - _actionsAfterLoading.Add(() => SetScene(scene)); - return; - } - - _scene = scene; - scene.Activate(); - RenderPipeline.SceneChanged(scene); - } - - /// - /// Defines the render pipeline. - /// - /// - public void SetRenderPipeline(RenderPipeline pipeline) - { - if (_loading) - { - _actionsAfterLoading.Add(() => SetRenderPipeline(pipeline)); - return; - } - - _renderPipeline = pipeline; - pipeline.Activate(this); - } - } -} \ No newline at end of file diff --git a/Legacy/Window/GenericWindowCode.cs b/Legacy/Window/GenericWindowCode.cs deleted file mode 100644 index 115ef15..0000000 --- a/Legacy/Window/GenericWindowCode.cs +++ /dev/null @@ -1,107 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using OpenTK; -using OpenTK.Graphics.OpenGL4; -using SM.Base.Contexts; -using SM.Base.Drawing; -using SM.Base.Objects.Static; -using SM.Base.PostProcess; -using SM.Base.Scene; -using SM.Base.ShaderExtension; -using SM.OGL; -using SM.Utility; - -namespace SM.Base -{ - public class GenericWindowCode - { - internal static void Load(IGenericWindow window) - { - SMRenderer.CurrentWindow = window; - - GLSystem.INIT_SYSTEM(); - GLSettings.ShaderPreProcessing = true; - - var args = Environment.GetCommandLineArgs(); - if (args.Contains("--advDebugging")) - { - SMRenderer.AdvancedDebugging = true; - GLSettings.InfoEveryUniform = true; - } - - Log.Init(); - - Log.Write("#", ConsoleColor.Cyan, "----------------------", - "--- OpenGL Loading ---", - "----------------------------------", - $"--- {"DeviceVersion",14}: {GLSystem.DeviceVersion,-10} ---", - $"--- {"ForcedVersion",14}: {GLSettings.ForcedVersion,-10} ---", - $"--- {"ShadingVersion",14}: {GLSystem.ShadingVersion,-10} ---", - $"--- {"Debugging",14}: {GLSystem.Debugging,-10} ---", - $"--- {"AdvDebugging",14}: {SMRenderer.AdvancedDebugging,-10} ---", - "----------------------------------"); - - if (SMRenderer.AdvancedDebugging) Log.Write("Extension", ConsoleColor.DarkCyan, GLSystem.Extensions); - - ExtensionManager.InitExtensions(); - } - - internal static void Resize(IGenericWindow window) - { - window.Aspect = (float) window.Width / window.Height; - window.WorldScale = new Vector2(window.Width, window.Height); - window.SetWorldScale(); - GL.Viewport(window.ClientRectangle); - } - - internal static void Resize(IGenericWindow window) - where TScene : GenericScene, new() - where TCamera : GenericCamera, new() - { - window.ViewportCamera.RecalculateWorld(window.WorldScale, window.Aspect); - window.RenderPipeline?.Resize(); - - PostProcessEffect.Model = Matrix4.CreateScale(window.WorldScale.X, -window.WorldScale.Y, 1); - PostProcessEffect.Mvp = PostProcessEffect.Model * - Matrix4.LookAt(0, 0, 1, 0, 0, 0, 0, 1, 0) * - GenericCamera.OrthographicWorld; - } - - internal static void Render(IGenericWindow window, float deltatime) - where TScene : GenericScene, new() - where TCamera : GenericCamera, new() - { - if (window.CurrentScene == null) return; - - SMRenderer.CurrentFrame++; - - Deltatime.RenderDelta = deltatime; - var drawContext = new DrawContext - { - ForceViewport = window.ForceViewportCamera, - ActiveScene = window.CurrentScene, - Window = window, - - Instances = new[] - { - new Instance - {ModelMatrix = Matrix4.Identity, TexturePosition = Vector2.Zero, TextureScale = Vector2.One} - }, - Mesh = Plate.Object, - - WorldScale = window.WorldScale, - LastPassthough = window, - - ShaderArguments = new Dictionary(), - - World = window.ViewportCamera.World, - View = window.ViewportCamera.CalculateViewMatrix(), - ModelMaster = Matrix4.Identity - }; - - - window.RenderPipeline?.Render(ref drawContext); - } - } -} \ No newline at end of file diff --git a/Legacy/Window/IGLWindow2D.cs b/Legacy/Window/IGLWindow2D.cs deleted file mode 100644 index 1d783e3..0000000 --- a/Legacy/Window/IGLWindow2D.cs +++ /dev/null @@ -1,14 +0,0 @@ -using OpenTK; -using SM.Base; -using SM2D.Controls; -using SM2D.Scene; - -namespace SM2D -{ - public interface IGLWindow2D : IGenericWindow - { - Vector2? Scaling { get; set; } - - Mouse2D Mouse { get; } - } -} \ No newline at end of file diff --git a/Legacy/Window/IGenericWindow.cs b/Legacy/Window/IGenericWindow.cs deleted file mode 100644 index bc93341..0000000 --- a/Legacy/Window/IGenericWindow.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Drawing; -using System.Windows; -using OpenTK; -using SM.Base.Scene; -using SM.OGL.Framebuffer; - -namespace SM.Base -{ - public interface IGenericWindow : IFramebufferWindow - { - bool Loading { get; } - float Aspect { get; set; } - - GenericCamera ViewportCamera { get; } - bool ForceViewportCamera { get; set; } - - int Width { get; } - int Height { get; } - - Rectangle ClientRectangle { get; } - Vector2 WorldScale { get; set; } - - void SetWorldScale(); - } - - public interface IGenericWindow : IGenericWindow - where TScene : GenericScene, new() - where TCamera : GenericCamera, new() - { - TScene CurrentScene { get; } - - RenderPipeline RenderPipeline { get; } - - void SetScene(TScene scene); - void SetRenderPipeline(RenderPipeline renderPipeline); - } -} \ No newline at end of file diff --git a/Legacy/Window/RenderPipeline.cs b/Legacy/Window/RenderPipeline.cs deleted file mode 100644 index 689511a..0000000 --- a/Legacy/Window/RenderPipeline.cs +++ /dev/null @@ -1,150 +0,0 @@ -#region usings - -using System.Collections.Generic; -using System.Threading; -using SM.Base.Contexts; -using SM.Base.Drawing; -using SM.Base.Scene; -using SM.OGL.Framebuffer; - -#endregion - -namespace SM.Base -{ - /// - /// Definition of specific render options. - /// - public abstract class RenderPipeline - { - /// - /// If true, this pipeline was already once activated. - /// - public bool IsInitialized { get; private set; } = false; - - /// - /// The window the pipeline is connected to. - /// - protected IGenericWindow _window { get; private set; } - - /// - /// The framebuffers, that are used in this Pipeline. - /// - public virtual List Framebuffers { get; private set; } - - /// - /// The default shader for the pipeline. - /// - protected internal virtual MaterialShader _defaultShader { get; set; } - - public virtual Framebuffer MainFramebuffer { get; protected set; }= Framebuffer.Screen; - - /// - /// Occurs, when the window is loading. - /// - protected internal virtual void Load() - { - } - - /// - /// Occurs, when the window is resizing. - /// - protected internal virtual void Resize() - { - if (Framebuffers == null) return; - - foreach (var framebuffer in Framebuffers) - framebuffer.Dispose(); - - Thread.Sleep(50); - - foreach (Framebuffer framebuffer in Framebuffers) - { - framebuffer.Compile(); - } - } - - internal void Activate(IGenericWindow window) - { - _window = window; - - if (!IsInitialized) - { - if (_defaultShader == null) _defaultShader = SMRenderer.DefaultMaterialShader; - Framebuffers = new List(); - - Initialization(window); - - Framebuffers.Add(MainFramebuffer); - - IsInitialized = true; - } - - Activation(window); - } - - /// - /// Occurs, when the pipeline was connected to a window. - /// - protected internal virtual void Activation(IGenericWindow window) - { - } - - - /// - /// Occurs, when the pipeline was connected to a window the first time. - /// - /// - protected internal virtual void Initialization(IGenericWindow window) - { - - } - - /// - /// Occurs, when the window is unloading. - /// - protected internal virtual void Unload() - { - } - - /// - /// Creates a framebuffer, that has specific (often) required settings already applied. - /// - /// - public static Framebuffer CreateWindowFramebuffer() - { - Framebuffer framebuffer = new Framebuffer(window: SMRenderer.CurrentWindow); - framebuffer.Append("color", 0); - return framebuffer; - } - } - - /// - /// Represents a render pipeline. - /// - /// The scene type - public abstract class RenderPipeline : RenderPipeline - where TScene : GenericScene - { - /// - /// The system to render stuff. - /// - internal void Render(ref DrawContext context) - { - context.ActivePipeline = this; - if (context.ActiveScene == null) return; - - RenderProcess(ref context, (TScene)context.ActiveScene); - } - - protected abstract void RenderProcess(ref DrawContext context, TScene scene); - - /// - /// Event, that triggers, when the scene in the current window changes. - /// - /// - protected internal virtual void SceneChanged(TScene scene) - { - - } - } -} \ No newline at end of file diff --git a/MigrationBackup/d4ed0f1f/SMRenderer/SM2D/NuGetUpgradeLog.html b/MigrationBackup/d4ed0f1f/SMRenderer/SM2D/NuGetUpgradeLog.html deleted file mode 100644 index 20325c2..0000000 --- a/MigrationBackup/d4ed0f1f/SMRenderer/SM2D/NuGetUpgradeLog.html +++ /dev/null @@ -1,162 +0,0 @@ - - - - - NuGetMigrationLog -

- NuGet Migration Report - SMRenderer\SM2D

Overview

Migration to PackageReference was completed successfully. Please build and run your solution to verify that all packages are available.
- If you run into any problems, have feedback, questions, or concerns, please - file an issue on the NuGet GitHub repository.

Packages processed

Top-level dependencies:

Package IdVersion
OpenTK - v3.2.1

Transitive dependencies:

Package IdVersion
- No transitive dependencies found. -

Package compatibility issues

Description
- No issues were found. -
\ No newline at end of file diff --git a/MigrationBackup/d4ed0f1f/SMRenderer/SM2D/SM2D.csproj b/MigrationBackup/d4ed0f1f/SMRenderer/SM2D/SM2D.csproj deleted file mode 100644 index b87112a..0000000 --- a/MigrationBackup/d4ed0f1f/SMRenderer/SM2D/SM2D.csproj +++ /dev/null @@ -1,82 +0,0 @@ - - - - - Debug - AnyCPU - {A4565538-625A-42C6-A330-DD4F1ABB3986} - Library - Properties - SM2D - SM2D - v4.5.2 - 512 - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\..\packages\OpenTK.3.2.1\lib\net20\OpenTK.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {8e733844-4204-43e7-b3dc-3913cddabb0d} - SM.Base - - - {f604d684-bc1d-4819-88b5-8b5d03a17be0} - SM.OGL - - - - - - - - - \ No newline at end of file diff --git a/MigrationBackup/d4ed0f1f/SMRenderer/SM2D/packages.config b/MigrationBackup/d4ed0f1f/SMRenderer/SM2D/packages.config deleted file mode 100644 index 9a4debe..0000000 --- a/MigrationBackup/d4ed0f1f/SMRenderer/SM2D/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file From b58e3f72f8d09718aa67cb636859db4ba92c07f8 Mon Sep 17 00:00:00 2001 From: Michel Fedde Date: Sat, 20 Mar 2021 17:26:52 +0100 Subject: [PATCH 5/5] Fixed Fullscreen mode + added a method to change the resolution. --- SMCode/SM.Base/SMRenderer.cs | 5 ++ SMCode/SM.Base/Window/GLWindow.cs | 76 ++++++++++++++++++++++++++--- SMCode/SM.Base/Window/WindowCode.cs | 1 + SMCode/SM2D/Window/Window2DSetup.cs | 2 + SM_TEST/Program.cs | 18 ++++++- 5 files changed, 93 insertions(+), 9 deletions(-) diff --git a/SMCode/SM.Base/SMRenderer.cs b/SMCode/SM.Base/SMRenderer.cs index 204a508..8e6b524 100644 --- a/SMCode/SM.Base/SMRenderer.cs +++ b/SMCode/SM.Base/SMRenderer.cs @@ -43,6 +43,11 @@ namespace SM.Base ///
public static MaterialShader DefaultMaterialShader; + /// + /// The default render pipeline. + /// + public static RenderPipeline DefaultRenderPipeline; + /// /// Shows more information onto the log system. /// diff --git a/SMCode/SM.Base/Window/GLWindow.cs b/SMCode/SM.Base/Window/GLWindow.cs index 6e75aa2..c4b49ad 100644 --- a/SMCode/SM.Base/Window/GLWindow.cs +++ b/SMCode/SM.Base/Window/GLWindow.cs @@ -3,6 +3,7 @@ using System; using System.ComponentModel; using System.Diagnostics; +using System.Drawing.Text; using System.Threading; using System.Windows.Forms; using OpenTK; @@ -23,10 +24,14 @@ namespace SM.Base.Window /// public class GLWindow : GameWindow, IGenericWindow { + private Vector2 _flagWindowPos; private Vector2 _flagWindowSize; + private Thread _fixedUpdateThread; private WindowFlags _windowFlags; + private DisplayResolution _normalResolution; + private DisplayResolution _fullscreenResolution; /// @@ -45,6 +50,7 @@ namespace SM.Base.Window public bool DrawWhileUnfocused { get; set; } = true; /// public bool UpdateWhileUnfocused { get; set; } = false; + /// public Vector2 WindowSize { get; set; } /// @@ -70,8 +76,9 @@ namespace SM.Base.Window { if (_windowFlags != value) { + WindowFlags oldV = _windowFlags; _windowFlags = value; - ChangeWindowFlag(value); + ChangeWindowFlag(value, oldV); } } } @@ -93,14 +100,15 @@ namespace SM.Base.Window /// /// public GLWindow(int width, int height, string title, WindowFlags flags, VSyncMode vSync = VSyncMode.On) : - base(width, height, default, title, (GameWindowFlags) flags, DisplayDevice.Default, + base(width, height, default, title, GameWindowFlags.Default, DisplayDevice.Default, GLSettings.ForcedVersion.MajorVersion, GLSettings.ForcedVersion.MinorVersion, GraphicsContextFlags.Default) { VSync = vSync; - _flagWindowSize = new Vector2(width, height); - WindowFlags = flags; + + FocusedChanged += GLWindow_FocusedChanged; + _normalResolution = _fullscreenResolution = DisplayDevice.Default.SelectResolution(DisplayDevice.Default.Width, DisplayDevice.Default.Height, DisplayDevice.Default.BitsPerPixel, DisplayDevice.Default.RefreshRate); } @@ -125,8 +133,6 @@ namespace SM.Base.Window WindowCode.Resize(this); - if (WindowFlags == WindowFlags.Window) _flagWindowSize = WindowSize; - if (Loading) { Loading = false; @@ -217,6 +223,17 @@ namespace SM.Base.Window CurrentRenderPipeline = renderPipeline; } + /// + /// Changes the resolution in fullscreen mode. + /// Can be executed before changing to fullscreen, but with no effect until changed. + /// + /// The resolution you get from or + public void ChangeFullscreenResolution(DisplayResolution resolution) + { + _fullscreenResolution = resolution; + + if (_windowFlags == WindowFlags.ExclusiveFullscreen) ApplyFullscreenResolution(); + } /// /// Starts the fixed update loop. @@ -248,17 +265,48 @@ namespace SM.Base.Window } } - private void ChangeWindowFlag(WindowFlags newFlag) + private void GLWindow_FocusedChanged(object sender, EventArgs e) { + if (_windowFlags == WindowFlags.ExclusiveFullscreen) + { + if (!Focused) + { + DisplayDevice.Default.ChangeResolution(_normalResolution); + WindowState = WindowState.Minimized; + } + else + { + ApplyFullscreenResolution(); + } + } + + } + private void ChangeWindowFlag(WindowFlags newFlag, WindowFlags oldFlag) + { + if (oldFlag == WindowFlags.Window) + { + _flagWindowSize = WindowSize; + _flagWindowPos = new Vector2(X, Y); + } + switch (newFlag) { case WindowFlags.Window: + DisplayDevice.Default.ChangeResolution(_normalResolution); + WindowState = WindowState.Normal; Width = (int)_flagWindowSize.X; Height = (int)_flagWindowSize.Y; + X = (int) _flagWindowPos.X; + Y = (int) _flagWindowPos.Y; + WindowBorder = WindowBorder.Resizable; + + break; case WindowFlags.BorderlessWindow: + DisplayDevice.Default.ChangeResolution(_normalResolution); + WindowState = WindowState.Maximized; WindowBorder = WindowBorder.Hidden; X = Screen.PrimaryScreen.Bounds.Left; @@ -268,10 +316,24 @@ namespace SM.Base.Window break; case WindowFlags.ExclusiveFullscreen: + + + WindowState = WindowState.Fullscreen; + ApplyFullscreenResolution(); + break; default: throw new ArgumentOutOfRangeException(nameof(newFlag), newFlag, null); } + + + } + + private void ApplyFullscreenResolution() + { + DisplayDevice.Default.ChangeResolution(_fullscreenResolution); + Width = _fullscreenResolution.Width; + Height = _fullscreenResolution.Height; } } } \ No newline at end of file diff --git a/SMCode/SM.Base/Window/WindowCode.cs b/SMCode/SM.Base/Window/WindowCode.cs index 0389b09..8f35b89 100644 --- a/SMCode/SM.Base/Window/WindowCode.cs +++ b/SMCode/SM.Base/Window/WindowCode.cs @@ -91,6 +91,7 @@ namespace SM.Base.Window internal static void Render(IGenericWindow window, float deltatime) { if (window.CurrentScene == null) return; + if (window.CurrentRenderPipeline == null) window.SetRenderPipeline(SMRenderer.DefaultRenderPipeline); SMRenderer.CurrentFrame++; diff --git a/SMCode/SM2D/Window/Window2DSetup.cs b/SMCode/SM2D/Window/Window2DSetup.cs index 9b340e1..d9c7ae9 100644 --- a/SMCode/SM2D/Window/Window2DSetup.cs +++ b/SMCode/SM2D/Window/Window2DSetup.cs @@ -2,6 +2,7 @@ using OpenTK.Graphics.OpenGL4; using SM.Base; using SM.Base.Window; +using SM2D.Pipelines; using SM2D.Scene; using SM2D.Shader; @@ -18,6 +19,7 @@ namespace SM2D window.ViewportCamera = new Camera(); SMRenderer.DefaultMaterialShader = ShaderCollection.Instanced; + SMRenderer.DefaultRenderPipeline = Basic2DPipeline.Pipeline; } /// diff --git a/SM_TEST/Program.cs b/SM_TEST/Program.cs index bc5c4f6..6fc29b1 100644 --- a/SM_TEST/Program.cs +++ b/SM_TEST/Program.cs @@ -1,9 +1,12 @@ -using OpenTK; +using System; +using System.Diagnostics; +using OpenTK; using OpenTK.Graphics; using OpenTK.Input; using SM.Base; using SM.Base.Window; using SM2D; +using SM2D.Drawing; using SM2D.Pipelines; using SM2D.Scene; using Font = SM.Base.Drawing.Text.Font; @@ -20,13 +23,24 @@ namespace SM_TEST { window = new GLWindow(); window.ApplySetup(new Window2DSetup()); - window.SetRenderPipeline(Basic2DPipeline.Pipeline); window.SetScene(scene = new Scene()); + scene.Objects.Add(new DrawObject2D()); + window.UpdateFrame += WindowOnUpdateFrame; window.Run(); + + Debug.WriteLine("Window Closed"); } private static void WindowOnUpdateFrame(object sender, FrameEventArgs e) { + if (SM.Base.Controls.Keyboard.IsDown(Key.F, true)) + { + window.WindowFlags = WindowFlags.ExclusiveFullscreen; + window.ChangeFullscreenResolution(DisplayDevice.Default.SelectResolution(1280,720, DisplayDevice.Default.BitsPerPixel, DisplayDevice.Default.RefreshRate)); + } + if (SM.Base.Controls.Keyboard.IsDown(Key.W, true)) window.WindowFlags = WindowFlags.Window; + if (SM.Base.Controls.Keyboard.IsDown(Key.B, true)) window.WindowFlags = WindowFlags.BorderlessWindow; + } private static void WindowOnLoad(IGenericWindow window)