Holidays 12.10. -> 25.10.2020

~ Moved code around in files.

SM.Base:
+ PostProcessing-system
+ OnInitialization() for Scenes.
+ Shader-Extensions
+ Added option to not react while unfocused to the window.
+ Added Screenshots to the window.
+ Connected the log system to the SM.OGL-action system.

~ Replaced IShader with abstract MaterialShader.
~ When a log compression folder doesn't exist, it will create one.

SM.OGL:
+ Added support for UniformArrays
+ Added ShaderPreProcessing
+ Added Shader Extensions.
+ Added Debug actions.
+ SM.OGL settings

~ Framebuffer Size is automaticly changed, when the window and scale is set.

SM2D:
+ Added easy shader drawing.
This commit is contained in:
Michel Fedde 2020-10-24 15:10:36 +02:00
parent 2c00dbd31a
commit 03b3942732
102 changed files with 2683 additions and 1398 deletions

View file

@ -1,41 +1,52 @@
using OpenTK;
#region usings
using OpenTK;
#endregion
namespace SM.Base.Scene
{
/// <summary>
/// Controller for a camera
/// Controller for a camera
/// </summary>
public abstract class GenericCamera
{
/// <summary>
/// The matrix for the orthographic world.
/// The matrix for the orthographic world.
/// </summary>
public static Matrix4 OrthographicWorld { get; protected set; }
/// <summary>
/// The matrix for the perspective world.
/// The matrix for the perspective world.
/// </summary>
public static Matrix4 PerspectiveWorld { get; protected set; }
/// <summary>
/// This defines what is up. (Normalized)
/// <para>Default: <see cref="Vector3.UnitY"/></para>
/// This defines what is up. (Normalized)
/// <para>Default: <see cref="Vector3.UnitY" /></para>
/// </summary>
public static Vector3 UpVector { get; set; } = Vector3.UnitY;
/// <summary>
/// Contains the view matrix of this camera.
/// <para>Default: <see cref="Matrix4.Identity"/></para>
/// Contains the view matrix of this camera.
/// <para>Default: <see cref="Matrix4.Identity" /></para>
/// </summary>
public Matrix4 ViewMatrix { get; protected set; } = Matrix4.Identity;
/// <summary>
/// Returns the world matrix that is connected to this camera.
/// Returns the world matrix that is connected to this camera.
/// </summary>
public Matrix4 World => Orthographic ? OrthographicWorld : PerspectiveWorld;
/// <summary>
/// Calculates the view matrix.
/// Represents if the camera is orthographic.
/// </summary>
/// <returns>The calculated view matrix. Same as <see cref="ViewMatrix"/></returns>
public abstract bool Orthographic { get; }
/// <summary>
/// Calculates the view matrix.
/// </summary>
/// <returns>The calculated view matrix. Same as <see cref="ViewMatrix" /></returns>
internal Matrix4 CalculateViewMatrix()
{
ViewMatrix = ViewCalculation();
@ -43,18 +54,17 @@ namespace SM.Base.Scene
}
/// <summary>
/// This calculates the view matrix.
/// This calculates the view matrix.
/// </summary>
/// <returns>The new view matrix. This is the returns for <see cref="CalculateViewMatrix"/> and the next value for <see cref="ViewMatrix"/>. </returns>
/// <returns>
/// The new view matrix. This is the returns for <see cref="CalculateViewMatrix" /> and the next value for
/// <see cref="ViewMatrix" />.
/// </returns>
protected abstract Matrix4 ViewCalculation();
/// <summary>
/// Represents if the camera is orthographic.
/// </summary>
public abstract bool Orthographic { get; }
/// <summary>
/// This will calculate the world.
/// <para>This is called on <see cref="GenericWindow{TScene,TCamera}.ViewportCamera"/> to calculate the world.</para>
/// This will calculate the world.
/// <para>This is called on <see cref="GenericWindow{TScene,TCamera}.ViewportCamera" /> to calculate the world.</para>
/// </summary>
/// <param name="world">The world scale</param>
/// <param name="aspect">The aspect ratio from the window.</param>

View file

@ -1,10 +1,14 @@
using System.Collections.Generic;
#region usings
using System.Collections.Generic;
using SM.Base.Contexts;
#endregion
namespace SM.Base.Scene
{
/// <summary>
/// Contains a list of show items.
/// Contains a list of show items.
/// </summary>
/// <typeparam name="TItem">The type of show items.</typeparam>
public abstract class GenericItemCollection<TItem> : List<TItem>, IShowItem, IShowCollection<TItem>
@ -22,8 +26,32 @@ namespace SM.Base.Scene
/// <inheritdoc />
public ICollection<string> Flags { get; set; } = new[] {"collection"};
/// <inheritdoc />
public virtual void Update(UpdateContext context)
{
for (var i = 0; i < Objects.Count; i++)
this[i].Update(context);
}
/// <inheritdoc cref="IShowCollection{TItem}.Draw" />
public virtual void Draw(DrawContext context)
{
for (var i = 0; i < Objects.Count; i++)
this[i].Draw(context);
}
/// <inheritdoc />
public virtual void OnAdded(object sender)
{
}
/// <inheritdoc />
public virtual void OnRemoved(object sender)
{
}
/// <summary>
/// Adds a item.
/// Adds a item.
/// </summary>
public new void Add(TItem item)
{
@ -33,7 +61,7 @@ namespace SM.Base.Scene
}
/// <summary>
/// Removes a item.
/// Removes a item.
/// </summary>
/// <param name="item"></param>
public new void Remove(TItem item)
@ -43,72 +71,46 @@ namespace SM.Base.Scene
item.OnRemoved(this);
}
/// <inheritdoc />
public virtual void Update(UpdateContext context)
{
for(int i = 0; i < Objects.Count; i++)
this[i].Update(context);
}
/// <inheritdoc cref="IShowCollection{TItem}.Draw" />
public virtual void Draw(DrawContext context)
{
for (int i = 0; i < Objects.Count; i++)
this[i].Draw(context);
}
/// <inheritdoc />
public virtual void OnAdded(object sender)
{
}
/// <inheritdoc />
public virtual void OnRemoved(object sender)
{ }
/// <summary>
/// Returns a object with this name or the default, if not available.
/// <para>Not reclusive.</para>
/// Returns a object with this name or the default, if not available.
/// <para>Not reclusive.</para>
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public TItem GetItemByName(string name)
{
TItem obj = default;
for (var i = 0; i < this.Count; i++)
{
for (var i = 0; i < Count; i++)
if (this[i].Name == name)
{
obj = this[i];
break;
}
}
return obj;
}
/// <summary>
/// Returns a object with this name or the default if not available.
/// <para>Not reclusive.</para>
/// Returns a object with this name or the default if not available.
/// <para>Not reclusive.</para>
/// </summary>
/// <typeparam name="TGetItem">Type of return</typeparam>
public TGetItem GetItemByName<TGetItem>(string name)
where TGetItem : TItem
{
return (TGetItem)GetItemByName(name);
return (TGetItem) GetItemByName(name);
}
/// <summary>
/// Returns all object that have this flag.
/// <para>Only in this list.</para>
/// Returns all object that have this flag.
/// <para>Only in this list.</para>
/// </summary>
public ICollection<TItem> GetItemsWithFlag(string flag)
{
List<TItem> list = new List<TItem>();
for (var i = 0; i < this.Count; i++)
var list = new List<TItem>();
for (var i = 0; i < Count; i++)
{
TItem obj = this[i];
var obj = this[i];
if (obj.Flags.Contains(flag)) list.Add(obj);
}
@ -117,7 +119,7 @@ namespace SM.Base.Scene
}
/// <summary>
/// Contains a list of show items with transformation.
/// Contains a list of show items with transformation.
/// </summary>
/// <typeparam name="TItem">The type of show items.</typeparam>
/// <typeparam name="TTransformation">The type of transformation.</typeparam>
@ -126,7 +128,7 @@ namespace SM.Base.Scene
where TTransformation : GenericTransformation, new()
{
/// <summary>
/// Transformation of the collection
/// Transformation of the collection
/// </summary>
public TTransformation Transform = new TTransformation();
@ -134,7 +136,7 @@ namespace SM.Base.Scene
public override void Draw(DrawContext context)
{
context.ModelMaster = Transform.GetMatrix() * context.ModelMaster;
base.Draw(context);
}
}

View file

@ -1,19 +1,22 @@
using System;
#region usings
using System.Collections.Generic;
using OpenTK;
using System.Dynamic;
using SM.Base.Contexts;
#endregion
namespace SM.Base.Scene
{
/// <summary>
/// A generic scene, that imports functions for scene control.
/// A generic scene, that imports functions for scene control.
/// </summary>
public abstract class GenericScene
{
private IBackgroundItem _background;
/// <summary>
/// This contains the background.
/// This contains the background.
/// </summary>
protected IBackgroundItem _Background
{
@ -24,41 +27,53 @@ namespace SM.Base.Scene
_background = value;
}
}
public bool IsInitialized { get; private set; }
/// <summary>
/// Updates this scene.
/// Updates this scene.
/// </summary>
/// <param name="context"></param>
public virtual void Update(UpdateContext context)
{
}
/// <summary>
/// Draws this scene.
/// Draws this scene.
/// </summary>
public virtual void Draw(DrawContext context)
{
}
/// <summary>
/// Called, when the user activates the scene.
/// Called, when the user activates the scene.
/// </summary>
internal void Activate()
{
if (!IsInitialized)
{
OnInitialization();
IsInitialized = true;
}
OnActivating();
}
/// <summary>
/// Called, when the user activates the scene.
/// Called, when the user activates the scene for the first time.
/// </summary>
protected virtual void OnInitialization()
{ }
/// <summary>
/// Called, when the user activates the scene.
/// </summary>
protected virtual void OnActivating()
{ }
{
}
}
/// <summary>
/// A generic scene that imports different functions.
/// A generic scene that imports different functions.
/// </summary>
/// <typeparam name="TCamera">The type of cameras.</typeparam>
/// <typeparam name="TItem">The type of show items.</typeparam>
@ -68,25 +83,32 @@ namespace SM.Base.Scene
where TCollection : GenericItemCollection<TItem>, new()
where TItem : IShowItem
{
private TCollection _objectCollection = new TCollection();
private TCollection _hud = new TCollection();
private TCollection _objectCollection = new TCollection();
/// <summary>
/// The active camera, that is used if the context doesn't force the viewport camera.
/// <para>If none set, it automaticly uses the viewport camera.</para>
/// A collection for cameras to switch easier to different cameras.
/// </summary>
public Dictionary<string, TCamera> Cameras = new Dictionary<string, TCamera>();
/// <summary>
/// The active camera, that is used if the context doesn't force the viewport camera.
/// <para>If none set, it automaticly uses the viewport camera.</para>
/// </summary>
public TCamera Camera { get; set; }
/// <summary>
/// A camera to control the background.
/// A camera to control the background.
/// </summary>
public TCamera BackgroundCamera { get; set; } = new TCamera();
/// <summary>
/// A camera to control the HUD.
/// A camera to control the HUD.
/// </summary>
public TCamera HUDCamera { get; set; } = new TCamera();
/// <summary>
/// Objects inside the scene.
/// Objects inside the scene.
/// </summary>
public TCollection Objects
{
@ -99,7 +121,7 @@ namespace SM.Base.Scene
}
/// <summary>
/// This defines the HUD objects.
/// This defines the HUD objects.
/// </summary>
public TCollection HUD
{
@ -110,10 +132,6 @@ namespace SM.Base.Scene
_hud = value;
}
}
/// <summary>
/// A collection for cameras to switch easier to different cameras.
/// </summary>
public Dictionary<string, TCamera> Cameras = new Dictionary<string, TCamera>();
/// <inheritdoc />
@ -127,14 +145,28 @@ namespace SM.Base.Scene
/// <inheritdoc />
public override void Draw(DrawContext context)
{
if (!context.ForceViewport && Camera != null) context.View = Camera.CalculateViewMatrix();
DrawBackground(context);
DrawContext backgroundDrawContext = context;
DrawMainObjects(context);
DrawHUD(context);
}
public void DrawBackground(DrawContext context)
{
var backgroundDrawContext = context;
backgroundDrawContext.View = BackgroundCamera.CalculateViewMatrix();
_Background?.Draw(backgroundDrawContext);
}
public void DrawMainObjects(DrawContext context)
{
if (!context.ForceViewport && Camera != null) context.View = Camera.CalculateViewMatrix();
_objectCollection.Draw(context);
}
public void DrawHUD(DrawContext context)
{
context.View = HUDCamera.CalculateViewMatrix();
_hud.Draw(context);
}

View file

@ -1,10 +1,9 @@
namespace SM.Base.Scene
{
/// <summary>
/// A iteration of <see cref="IShowItem"/> to reduce clutter.
/// A iteration of <see cref="IShowItem" /> to reduce clutter.
/// </summary>
public interface IBackgroundItem : IShowItem
{
}
}

View file

@ -1,21 +1,25 @@
using System.Collections.Generic;
#region usings
using System.Collections.Generic;
using SM.Base.Contexts;
#endregion
namespace SM.Base.Scene
{
/// <summary>
/// Adds functions, that is required for a collection.
/// Adds functions, that is required for a collection.
/// </summary>
/// <typeparam name="TItem">The type of show item.</typeparam>
public interface IShowCollection<TItem> where TItem : IShowItem
{
/// <summary>
/// The object collection.
/// The object collection.
/// </summary>
List<TItem> Objects { get; }
/// <summary>
/// This draws the objects in the <see cref="Objects"/> list.
/// This draws the objects in the <see cref="Objects" /> list.
/// </summary>
/// <param name="context">The context how the objects need to be drawn.</param>
void Draw(DrawContext context);

View file

@ -1,45 +1,51 @@
using System.Collections.Generic;
#region usings
using System.Collections.Generic;
using SM.Base.Contexts;
#endregion
namespace SM.Base.Scene
{
/// <summary>
/// Adds requirements to object, to be properly used as a update and/or draw item.
/// Adds requirements to object, to be properly used as a update and/or draw item.
/// </summary>
public interface IShowItem
{
/// <summary>
/// Parent of the object.
/// Parent of the object.
/// </summary>
object Parent { get; set; }
/// <summary>
/// Contains the name for the object.
/// Contains the name for the object.
/// </summary>
string Name { get; set; }
/// <summary>
/// Contains specific flags for the object.
/// Contains specific flags for the object.
/// </summary>
ICollection<string> Flags { get; set; }
/// <summary>
/// Tells the object to update own systems.
/// Tells the object to update own systems.
/// </summary>
/// <param name="context">The update context</param>
void Update(UpdateContext context);
/// <summary>
/// Tells the object to draw its object.
/// Tells the object to draw its object.
/// </summary>
/// <param name="context"></param>
void Draw(DrawContext context);
/// <summary>
/// Action, that is called, when the object was added to a GenericItemCollection.
/// Action, that is called, when the object was added to a GenericItemCollection.
/// </summary>
void OnAdded(object sender);
/// <summary>
/// Action, that is called, when the object was removed from a GenericItemCollection.
/// Action, that is called, when the object was removed from a GenericItemCollection.
/// </summary>
void OnRemoved(object sender);
}