#MERGE
This commit is contained in:
commit
31777faa11
107 changed files with 1146 additions and 803 deletions
|
|
@ -1,18 +1,24 @@
|
||||||
using System;
|
#region usings
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.InteropServices.WindowsRuntime;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
using SharpDX.Win32;
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
namespace SM.Base.Controls
|
namespace SM.Base.Controls
|
||||||
{
|
{
|
||||||
public class Keyboard
|
/// <summary>
|
||||||
|
/// A static class to get keyboard inputs.
|
||||||
|
/// </summary>
|
||||||
|
public static class Keyboard
|
||||||
{
|
{
|
||||||
internal static KeyboardState? _keyboardState;
|
internal static KeyboardState? _keyboardState;
|
||||||
internal static List<Key> _lastPressedKeys = new List<Key>();
|
internal static List<Key> _lastPressedKeys = new List<Key>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// True, when ANY key pressed.
|
||||||
|
/// </summary>
|
||||||
public static bool IsAnyKeyPressed => _keyboardState?.IsAnyKeyDown == true;
|
public static bool IsAnyKeyPressed => _keyboardState?.IsAnyKeyDown == true;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -23,18 +29,53 @@ namespace SM.Base.Controls
|
||||||
_lastPressedKeys = new List<Key>();
|
_lastPressedKeys = new List<Key>();
|
||||||
|
|
||||||
foreach (object o in Enum.GetValues(typeof(Key)))
|
foreach (object o in Enum.GetValues(typeof(Key)))
|
||||||
{
|
if (_keyboardState.Value[(Key) o])
|
||||||
if (_keyboardState.Value[(Key)o]) _lastPressedKeys.Add((Key)o);
|
_lastPressedKeys.Add((Key) o);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_keyboardState = OpenTK.Input.Keyboard.GetState();
|
_keyboardState = OpenTK.Input.Keyboard.GetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsDown(Key key, bool once = false) => _keyboardState?[key] == true && !(once && _lastPressedKeys.Contains(key));
|
/// <summary>
|
||||||
public static bool WasDown(Key key) => _keyboardState?[key] == false && _lastPressedKeys.Contains(key);
|
/// Checks if a key is down.
|
||||||
public static bool IsUp(Key key, bool once = false) => _keyboardState?[key] == false && !(once && !_lastPressedKeys.Contains(key));
|
/// </summary>
|
||||||
|
/// <param name="key">The key</param>
|
||||||
|
/// <param name="once">If true, the method doesn't return true, when it was pressed one stage before.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool IsDown(Key key, bool once = false)
|
||||||
|
{
|
||||||
|
return _keyboardState?[key] == true && !(once && _lastPressedKeys.Contains(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if a key was down but not anymore.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool WasDown(Key key)
|
||||||
|
{
|
||||||
|
return _keyboardState?[key] == false && _lastPressedKeys.Contains(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if a is up.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="once">If true, the method doesn't return true, when it was up one stage before.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool IsUp(Key key, bool once = false)
|
||||||
|
{
|
||||||
|
return _keyboardState?[key] == false && !(once && !_lastPressedKeys.Contains(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if specific keys are down.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="startIndex">Startindex</param>
|
||||||
|
/// <param name="endIndex">Endindex</param>
|
||||||
|
/// <param name="once">If true, it ignores keys that were down a state before.</param>
|
||||||
|
/// <returns>True if any of the specific keys where found down.</returns>
|
||||||
|
/// <exception cref="ArgumentException">The start index can't be greater then the end index.</exception>
|
||||||
public static bool AreSpecificKeysPressed(int startIndex, int endIndex, bool once = false)
|
public static bool AreSpecificKeysPressed(int startIndex, int endIndex, bool once = false)
|
||||||
{
|
{
|
||||||
if (startIndex > endIndex)
|
if (startIndex > endIndex)
|
||||||
|
|
@ -51,19 +92,42 @@ namespace SM.Base.Controls
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool AreSpecificKeysPressed(params Key[] keys) => AreSpecificKeysPressed(false, keys);
|
/// <summary>
|
||||||
|
/// Checks if any of the specific keys are pressed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="keys"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool AreSpecificKeysPressed(params Key[] keys)
|
||||||
|
{
|
||||||
|
return AreSpecificKeysPressed(false, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if any of the specific keys are pressed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="once">If true, it ignores keys that were down a state before.</param>
|
||||||
|
/// <param name="keys"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static bool AreSpecificKeysPressed(bool once, params Key[] keys)
|
public static bool AreSpecificKeysPressed(bool once, params Key[] keys)
|
||||||
{
|
{
|
||||||
foreach (Key key in keys)
|
foreach (Key key in keys)
|
||||||
{
|
if (IsDown(key, once))
|
||||||
if (IsDown(key, once)) return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool AreSpecificKeysPressed(int startIndex, int endIndex, out Key[] pressedKeys, bool once = false)
|
/// <summary>
|
||||||
|
/// Checks if specific keys are down and returns the pressed keys.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="startIndex">Startindex</param>
|
||||||
|
/// <param name="endIndex">Endindex</param>
|
||||||
|
/// <param name="pressedKeys"></param>
|
||||||
|
/// <param name="once">If true, it ignores keys that were down a state before.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="ArgumentException"></exception>
|
||||||
|
public static bool AreSpecificKeysPressed(int startIndex, int endIndex, out Key[] pressedKeys,
|
||||||
|
bool once = false)
|
||||||
{
|
{
|
||||||
if (startIndex > endIndex)
|
if (startIndex > endIndex)
|
||||||
throw new ArgumentException("The startIndex is greater than the endIndex.", nameof(startIndex));
|
throw new ArgumentException("The startIndex is greater than the endIndex.", nameof(startIndex));
|
||||||
|
|
@ -75,34 +139,47 @@ namespace SM.Base.Controls
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
int actualIndex = i + startIndex;
|
int actualIndex = i + startIndex;
|
||||||
Key key = (Key)actualIndex;
|
Key key = (Key) actualIndex;
|
||||||
if (IsDown(key, once))
|
if (IsDown(key, once))
|
||||||
{
|
{
|
||||||
keys.Add(key);
|
keys.Add(key);
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pressedKeys = keys.ToArray();
|
pressedKeys = keys.ToArray();
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool AreSpecificKeysPressed(out Key[] pressedKey, params Key[] keys) => AreSpecificKeysPressed(false, out pressedKey, keys);
|
/// <summary>
|
||||||
|
/// Checks if any of the specific keys are pressed and returns them.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pressedKey"></param>
|
||||||
|
/// <param name="keys"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool AreSpecificKeysPressed(out Key[] pressedKey, params Key[] keys)
|
||||||
|
{
|
||||||
|
return AreSpecificKeysPressed(false, out pressedKey, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if any of the specific keys are pressed and returns them.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="once">If true, it ignores keys that were down a state before.</param>
|
||||||
|
/// <param name="pressedKeys"></param>
|
||||||
|
/// <param name="keys"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static bool AreSpecificKeysPressed(bool once, out Key[] pressedKeys, params Key[] keys)
|
public static bool AreSpecificKeysPressed(bool once, out Key[] pressedKeys, params Key[] keys)
|
||||||
{
|
{
|
||||||
List<Key> pressedKey = new List<Key>();
|
List<Key> pressedKey = new List<Key>();
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
foreach (Key key in keys)
|
foreach (Key key in keys)
|
||||||
{
|
|
||||||
if (IsDown(key, once))
|
if (IsDown(key, once))
|
||||||
{
|
{
|
||||||
pressedKey.Add(key);
|
pressedKey.Add(key);
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pressedKeys = pressedKey.ToArray();
|
pressedKeys = pressedKey.ToArray();
|
||||||
return success;
|
return success;
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,9 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Windows.Documents;
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
using SM.Base.Windows;
|
using SM.Base.Window;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
@ -14,7 +13,6 @@ namespace SM.Base.Controls
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Mouse controller
|
/// Mouse controller
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TWindow">The type of window this controller is connected to.</typeparam>
|
|
||||||
public class Mouse
|
public class Mouse
|
||||||
{
|
{
|
||||||
internal static MouseState? _mouseState;
|
internal static MouseState? _mouseState;
|
||||||
|
|
@ -37,7 +35,7 @@ namespace SM.Base.Controls
|
||||||
internal static void MouseMoveEvent(MouseMoveEventArgs mmea, IGenericWindow window)
|
internal static void MouseMoveEvent(MouseMoveEventArgs mmea, IGenericWindow window)
|
||||||
{
|
{
|
||||||
InScreen = new Vector2(mmea.X, mmea.Y);
|
InScreen = new Vector2(mmea.X, mmea.Y);
|
||||||
InScreenNormalized = new Vector2(mmea.X / (float)window.Width, mmea.Y / (float)window.Height);
|
InScreenNormalized = new Vector2(mmea.X / (float) window.Width, mmea.Y / (float) window.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void SetState()
|
internal static void SetState()
|
||||||
|
|
@ -47,19 +45,21 @@ namespace SM.Base.Controls
|
||||||
_lastButtonsPressed = new List<MouseButton>();
|
_lastButtonsPressed = new List<MouseButton>();
|
||||||
|
|
||||||
foreach (object o in Enum.GetValues(typeof(MouseButton)))
|
foreach (object o in Enum.GetValues(typeof(MouseButton)))
|
||||||
{
|
if (_mouseState.Value[(MouseButton) o])
|
||||||
if (_mouseState.Value[(MouseButton)o]) _lastButtonsPressed.Add((MouseButton)o);
|
_lastButtonsPressed.Add((MouseButton) o);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_mouseState = OpenTK.Input.Mouse.GetState();
|
_mouseState = OpenTK.Input.Mouse.GetState();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsDown(MouseButton button, bool once = false) => _mouseState?[button] == true && !(once && _lastButtonsPressed.Contains(button));
|
public static bool IsDown(MouseButton button, bool once = false)
|
||||||
|
{
|
||||||
public static bool IsUp(MouseButton button, bool once = false) =>
|
return _mouseState?[button] == true && !(once && _lastButtonsPressed.Contains(button));
|
||||||
_mouseState?[button] == false && !(once && !_lastButtonsPressed.Contains(button));
|
}
|
||||||
|
|
||||||
|
public static bool IsUp(MouseButton button, bool once = false)
|
||||||
|
{
|
||||||
|
return _mouseState?[button] == false && !(once && !_lastButtonsPressed.Contains(button));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenTK.Graphics.ES11;
|
using OpenTK.Graphics.OpenGL4;
|
||||||
using SM.Base;
|
|
||||||
using SM.Base.Scene;
|
using SM.Base.Scene;
|
||||||
using SM.Base.Windows;
|
using SM.Base.Window;
|
||||||
using SM.OGL.Mesh;
|
using SM.OGL.Mesh;
|
||||||
using PrimitiveType = OpenTK.Graphics.OpenGL4.PrimitiveType;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
@ -22,15 +20,27 @@ namespace SM.Base.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Material Material = new Material();
|
public Material Material = new Material();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Transformation for the textures.
|
||||||
|
/// </summary>
|
||||||
|
public TextureTransformation TextureTransform = new TextureTransformation();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This allows custom shaders to add own arguments.
|
||||||
|
/// </summary>
|
||||||
|
public ShaderArguments ShaderArguments => Material.ShaderArguments;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This can force a shader to render the object with the specified mesh type.
|
||||||
|
/// </summary>
|
||||||
|
public PrimitiveType? ForcedMeshType { get; set; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The mesh it should use.
|
/// The mesh it should use.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public GenericMesh Mesh { get; set; } = SMRenderer.DefaultMesh;
|
public GenericMesh Mesh { get; set; } = SMRenderer.DefaultMesh;
|
||||||
|
|
||||||
public ShaderArguments ShaderArguments => Material.ShaderArguments;
|
|
||||||
public TextureTransformation TextureTransform = new TextureTransformation();
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public object Parent { get; set; }
|
public object Parent { get; set; }
|
||||||
|
|
||||||
|
|
@ -40,12 +50,11 @@ namespace SM.Base.Drawing
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public ICollection<string> Flags { get; set; }
|
public ICollection<string> Flags { get; set; }
|
||||||
|
|
||||||
public PrimitiveType? ForcedMeshType { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This value determents if the object should draw something.
|
/// This value determents if the object should draw something.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Active { get; set; } = true;
|
public bool Active { get; set; } = true;
|
||||||
|
|
||||||
public bool RenderActive { get; set; } = true;
|
public bool RenderActive { get; set; } = true;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,18 @@ namespace SM.Base.Drawing
|
||||||
public abstract class GenericTransformation
|
public abstract class GenericTransformation
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If true, ignores the transformation and sends <see cref="Matrix4.Identity"/>, when requested.
|
/// If true, ignores the transformation and sends <see cref="Matrix4.Identity" />, when requested.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Ignore = false;
|
public bool Ignore = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The last matrix that was used to calculate the real world matrix.
|
||||||
|
/// </summary>
|
||||||
public Matrix4 LastMaster { get; internal set; }
|
public Matrix4 LastMaster { get; internal set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The transformation in world space.
|
||||||
|
/// </summary>
|
||||||
public Matrix4 InWorldSpace => MergeMatrix(LastMaster);
|
public Matrix4 InWorldSpace => MergeMatrix(LastMaster);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@ namespace SM.Base.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Matrix4 ModelMatrix = Matrix4.Identity;
|
public Matrix4 ModelMatrix = Matrix4.Identity;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Texture matrix
|
||||||
|
/// </summary>
|
||||||
public Matrix3 TextureMatrix = Matrix3.Identity;
|
public Matrix3 TextureMatrix = Matrix3.Identity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
|
using SM.Base.Shaders;
|
||||||
using SM.OGL.Texture;
|
using SM.OGL.Texture;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -13,6 +13,8 @@ namespace SM.Base.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Material
|
public class Material
|
||||||
{
|
{
|
||||||
|
public bool Blending = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A custom shader, that is used to draw this material.
|
/// A custom shader, that is used to draw this material.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -28,8 +30,9 @@ namespace SM.Base.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color4 Tint = Color4.White;
|
public Color4 Tint = Color4.White;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This allows custom shaders to use own shader arguments.
|
||||||
|
/// </summary>
|
||||||
public ShaderArguments ShaderArguments { get; internal set; } = new ShaderArguments();
|
public ShaderArguments ShaderArguments { get; internal set; } = new ShaderArguments();
|
||||||
|
|
||||||
public bool Blending = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
using SM.Base.Time;
|
#region usings
|
||||||
|
|
||||||
|
using SM.Base.Time;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
namespace SM.Base.Drawing.Particles
|
namespace SM.Base.Drawing.Particles
|
||||||
{
|
{
|
||||||
|
|
@ -8,11 +12,12 @@ namespace SM.Base.Drawing.Particles
|
||||||
public struct ParticleContext
|
public struct ParticleContext
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Timer of the particles
|
/// The Timer of the particles
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Timer Timer;
|
public Timer Timer;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current speed of the particles.
|
/// The current speed of the particles.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float Speed;
|
public float Speed;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,42 @@
|
||||||
using System;
|
#region usings
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using SM.Base;
|
|
||||||
using SM.Base.Scene;
|
using SM.Base.Scene;
|
||||||
using SM.Base.Time;
|
using SM.Base.Time;
|
||||||
using SM.Base.Types;
|
using SM.Base.Window;
|
||||||
using SM.Base.Windows;
|
|
||||||
using SM.OGL.Shaders;
|
#endregion
|
||||||
|
|
||||||
namespace SM.Base.Drawing.Particles
|
namespace SM.Base.Drawing.Particles
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The (drawing) basis for particles
|
/// The (drawing) basis for particles
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class ParticleDrawingBasis<TTransform, TDirection> : DrawingBasis<TTransform>, IScriptable
|
public abstract class ParticleDrawingBasis<TTransform, TDirection> : DrawingBasis<TTransform>, IScriptable
|
||||||
where TTransform : GenericTransformation, new()
|
where TTransform : GenericTransformation, new()
|
||||||
where TDirection : struct
|
where TDirection : struct
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The amount of particles
|
||||||
|
/// </summary>
|
||||||
|
public int Amount = 32;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This contains the different instances for the particles.
|
||||||
|
/// </summary>
|
||||||
|
protected List<Instance> instances;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The maximum speed of the particles
|
||||||
|
/// </summary>
|
||||||
|
public float MaxSpeed = 1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This contains all important information for each particle.
|
/// This contains all important information for each particle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected ParticleStruct<TDirection>[] particleStructs;
|
protected ParticleStruct<TDirection>[] particleStructs;
|
||||||
/// <summary>
|
|
||||||
/// This contains the different instances for the particles.
|
|
||||||
/// </summary>
|
|
||||||
protected List<Instance> instances;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The stopwatch of the particles.
|
/// The stopwatch of the particles.
|
||||||
|
|
@ -33,13 +44,13 @@ namespace SM.Base.Drawing.Particles
|
||||||
protected Timer timer;
|
protected Timer timer;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The amount of particles
|
/// Sets up the timer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Amount = 32;
|
/// <param name="duration">Duration how long the particles should live</param>
|
||||||
/// <summary>
|
protected ParticleDrawingBasis(TimeSpan duration)
|
||||||
/// The maximum speed of the particles
|
{
|
||||||
/// </summary>
|
timer = new Timer(duration);
|
||||||
public float MaxSpeed = 1;
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get/Sets the state of pausing.
|
/// Get/Sets the state of pausing.
|
||||||
|
|
@ -55,13 +66,25 @@ namespace SM.Base.Drawing.Particles
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract Func<TDirection, ParticleContext, TDirection> MovementCalculation { get; set; }
|
public abstract Func<TDirection, ParticleContext, TDirection> MovementCalculation { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc />
|
||||||
/// Sets up the timer.
|
public bool UpdateActive { get; set; }
|
||||||
/// </summary>
|
|
||||||
/// <param name="duration">Duration how long the particles should live</param>
|
/// <inheritdoc />
|
||||||
protected ParticleDrawingBasis(TimeSpan duration)
|
public void Update(UpdateContext context)
|
||||||
{
|
{
|
||||||
timer = new Timer(duration);
|
if (!timer.Running) return;
|
||||||
|
|
||||||
|
ParticleContext particleContext = new ParticleContext
|
||||||
|
{
|
||||||
|
Timer = timer
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < Amount; i++)
|
||||||
|
{
|
||||||
|
particleContext.Speed = particleStructs[i].Speed;
|
||||||
|
instances[i].ModelMatrix = CreateMatrix(particleStructs[i],
|
||||||
|
MovementCalculation(particleStructs[i].Direction, particleContext));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -74,30 +97,11 @@ namespace SM.Base.Drawing.Particles
|
||||||
CreateParticles();
|
CreateParticles();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool UpdateActive { get; set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public void Update(UpdateContext context)
|
|
||||||
{
|
|
||||||
if (!timer.Running) return;
|
|
||||||
|
|
||||||
ParticleContext particleContext = new ParticleContext()
|
|
||||||
{
|
|
||||||
Timer = timer,
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int i = 0; i < Amount; i++)
|
|
||||||
{
|
|
||||||
particleContext.Speed = particleStructs[i].Speed;
|
|
||||||
instances[i].ModelMatrix = CreateMatrix(particleStructs[i], MovementCalculation(particleStructs[i].Direction, particleContext));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void DrawContext(ref DrawContext context)
|
protected override void DrawContext(ref DrawContext context)
|
||||||
{
|
{
|
||||||
if (!timer.Active) return;
|
if (!timer.Active) return;
|
||||||
|
|
||||||
base.DrawContext(ref context);
|
base.DrawContext(ref context);
|
||||||
|
|
||||||
context.Instances = instances;
|
context.Instances = instances;
|
||||||
|
|
@ -124,7 +128,7 @@ namespace SM.Base.Drawing.Particles
|
||||||
/// Creates a particle.
|
/// Creates a particle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected abstract ParticleStruct<TDirection> CreateObject(int index);
|
protected abstract ParticleStruct<TDirection> CreateObject(int index);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generates the desired matrix for drawing.
|
/// Generates the desired matrix for drawing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
using OpenTK;
|
#region usings
|
||||||
|
|
||||||
|
using OpenTK;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
namespace SM.Base.Drawing.Particles
|
namespace SM.Base.Drawing.Particles
|
||||||
{
|
{
|
||||||
|
|
@ -10,10 +14,17 @@ namespace SM.Base.Drawing.Particles
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default movement for 2D.
|
/// Default movement for 2D.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Vector2 Default2D(Vector2 direction, ParticleContext context) => direction * (context.Timer.Elapsed * context.Speed);
|
public static Vector2 Default2D(Vector2 direction, ParticleContext context)
|
||||||
|
{
|
||||||
|
return direction * (context.Timer.Elapsed * context.Speed);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default movement for 3D.
|
/// Default movement for 3D.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Vector3 Default3D(Vector3 direction, ParticleContext context) => direction * (context.Timer.Elapsed * context.Speed);
|
public static Vector3 Default3D(Vector3 direction, ParticleContext context)
|
||||||
|
{
|
||||||
|
return direction * (context.Timer.Elapsed * context.Speed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
using OpenTK;
|
#region usings
|
||||||
using SM.Base.Types;
|
|
||||||
|
using OpenTK;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
namespace SM.Base.Drawing.Particles
|
namespace SM.Base.Drawing.Particles
|
||||||
{
|
{
|
||||||
|
|
@ -13,10 +16,12 @@ namespace SM.Base.Drawing.Particles
|
||||||
/// A direction, that the particle should travel.
|
/// A direction, that the particle should travel.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TDirection Direction;
|
public TDirection Direction;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A matrix to store rotation and scale.
|
/// A matrix to store rotation and scale.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Matrix4 Matrix;
|
public Matrix4 Matrix;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Speeeeeeeeeed
|
/// Speeeeeeeeeed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,26 @@
|
||||||
using System;
|
#region usings
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
namespace SM.Base.Drawing
|
namespace SM.Base.Drawing
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A custom dictionary, with a few useful methods.
|
||||||
|
/// </summary>
|
||||||
public class ShaderArguments : Dictionary<string, object>
|
public class ShaderArguments : Dictionary<string, object>
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the stored value or the default value if the name doesn't exist.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <param name="defaultValue"></param>
|
||||||
|
/// <typeparam name="TType"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
public TType Get<TType>(string name, TType defaultValue = default)
|
public TType Get<TType>(string name, TType defaultValue = default)
|
||||||
{
|
{
|
||||||
return ContainsKey(name) ? (TType)this[name] : defaultValue;
|
return ContainsKey(name) ? (TType) this[name] : defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -32,8 +32,6 @@ namespace SM.Base.Drawing.Text
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float FontSize = 12;
|
public float FontSize = 12;
|
||||||
|
|
||||||
public float Spacing = 1;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The font style.
|
/// The font style.
|
||||||
/// <para>Default: <see cref="System.Drawing.FontStyle.Regular" /></para>
|
/// <para>Default: <see cref="System.Drawing.FontStyle.Regular" /></para>
|
||||||
|
|
@ -45,6 +43,11 @@ namespace SM.Base.Drawing.Text
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Dictionary<char, CharParameter> Positions = new Dictionary<char, CharParameter>();
|
public Dictionary<char, CharParameter> Positions = new Dictionary<char, CharParameter>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allows a font wide spacing option.
|
||||||
|
/// </summary>
|
||||||
|
public float Spacing = 1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generates a font from a font family from the specified path.
|
/// Generates a font from a font family from the specified path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,7 @@
|
||||||
using System;
|
using System;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using SM.Base;
|
using SM.Base.Window;
|
||||||
using SM.Base.Windows;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
@ -27,33 +26,34 @@ namespace SM.Base.Drawing.Text
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected string _text;
|
protected string _text;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The width of the text object.
|
||||||
|
/// </summary>
|
||||||
|
public float Width;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The height of the text object.
|
||||||
|
/// </summary>
|
||||||
|
public float Height;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The spacing between numbers.
|
/// The spacing between numbers.
|
||||||
/// <para>Default: 1</para>
|
/// <para>Default: 1</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float Spacing = 1;
|
public float Spacing = 1;
|
||||||
|
|
||||||
public float ActualSpacing => Spacing * Font.Spacing;
|
|
||||||
|
|
||||||
public float Width;
|
|
||||||
public float Height;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a text object with a font.
|
/// Calculates the actual spacing for the object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="font">The font.</param>
|
public float ActualSpacing => Spacing * Font.Spacing;
|
||||||
protected TextDrawingBasis(Font font)
|
|
||||||
{
|
|
||||||
Material.Texture = font;
|
|
||||||
Material.Blending = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The font.
|
/// The font.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Font Font
|
public Font Font
|
||||||
{
|
{
|
||||||
get => (Font) Material.Texture;
|
get => (Font)Material.Texture;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
Material.Texture = value;
|
Material.Texture = value;
|
||||||
|
|
@ -83,6 +83,16 @@ namespace SM.Base.Drawing.Text
|
||||||
set => Material.Tint = value;
|
set => Material.Tint = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a text object with a font.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="font">The font.</param>
|
||||||
|
protected TextDrawingBasis(Font font)
|
||||||
|
{
|
||||||
|
Material.Texture = font;
|
||||||
|
Material.Blending = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void DrawContext(ref DrawContext context)
|
protected override void DrawContext(ref DrawContext context)
|
||||||
|
|
@ -137,7 +147,8 @@ namespace SM.Base.Drawing.Text
|
||||||
_instances[i] = new Instance
|
_instances[i] = new Instance
|
||||||
{
|
{
|
||||||
ModelMatrix = matrix,
|
ModelMatrix = matrix,
|
||||||
TextureMatrix = TextureTransformation.CalculateMatrix(new Vector2(parameter.NormalizedX, 0), new Vector2(parameter.NormalizedWidth, 1), 0),
|
TextureMatrix = TextureTransformation.CalculateMatrix(new Vector2(parameter.NormalizedX, 0),
|
||||||
|
new Vector2(parameter.NormalizedWidth, 1), 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
x += parameter.Width * ActualSpacing;
|
x += parameter.Width * ActualSpacing;
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,46 @@
|
||||||
using System;
|
#region usings
|
||||||
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using SM.Base.Types;
|
using SM.Base.Types;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
namespace SM.Base.Drawing
|
namespace SM.Base.Drawing
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Stores transformations for the textures.
|
||||||
|
/// </summary>
|
||||||
public class TextureTransformation
|
public class TextureTransformation
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The offset from the origin.
|
||||||
|
/// </summary>
|
||||||
public CVector2 Offset = new CVector2(0);
|
public CVector2 Offset = new CVector2(0);
|
||||||
public CVector2 Scale = new CVector2(1);
|
/// <summary>
|
||||||
|
/// The rotation of the texture.
|
||||||
|
/// </summary>
|
||||||
public CVector1 Rotation = new CVector1(0);
|
public CVector1 Rotation = new CVector1(0);
|
||||||
|
/// <summary>
|
||||||
|
/// The scale of the texture.
|
||||||
|
/// </summary>
|
||||||
|
public CVector2 Scale = new CVector2(1);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the texture matrix.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
public Matrix3 GetMatrix()
|
public Matrix3 GetMatrix()
|
||||||
{
|
{
|
||||||
return CalculateMatrix(Offset, Scale, Rotation);
|
return CalculateMatrix(Offset, Scale, Rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates a texture matrix.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="offset"></param>
|
||||||
|
/// <param name="scale"></param>
|
||||||
|
/// <param name="rotation"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static Matrix3 CalculateMatrix(Vector2 offset, Vector2 scale, float rotation)
|
public static Matrix3 CalculateMatrix(Vector2 offset, Vector2 scale, float rotation)
|
||||||
{
|
{
|
||||||
float radians = MathHelper.DegreesToRadians(rotation);
|
float radians = MathHelper.DegreesToRadians(rotation);
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,22 @@
|
||||||
using System;
|
#region usings
|
||||||
|
|
||||||
using OpenTK.Graphics.OpenGL4;
|
using OpenTK.Graphics.OpenGL4;
|
||||||
using SM.OGL.Mesh;
|
using SM.OGL.Mesh;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
namespace SM.Base.Objects
|
namespace SM.Base.Objects
|
||||||
{
|
{
|
||||||
public class InstancedMesh : Mesh, ILineMesh
|
/// <summary>
|
||||||
|
/// This class allows for fast mesh creation.
|
||||||
|
/// </summary>
|
||||||
|
public class InstancedMesh : Mesh
|
||||||
{
|
{
|
||||||
public InstancedMesh(PrimitiveType type, string[] enabledAttibute) : base(type)
|
public InstancedMesh(PrimitiveType type, string[] enabledAttibute) : base(type)
|
||||||
{
|
{
|
||||||
Attributes["vertex"] = Vertex = new VBO();
|
Attributes["vertex"] = Vertex = new VBO();
|
||||||
|
|
||||||
foreach (string attribute in enabledAttibute)
|
foreach (string attribute in enabledAttibute)
|
||||||
{
|
|
||||||
switch (attribute)
|
switch (attribute)
|
||||||
{
|
{
|
||||||
case "uv":
|
case "uv":
|
||||||
|
|
@ -24,9 +29,6 @@ namespace SM.Base.Objects
|
||||||
Attributes["color"] = Color = new VBO(pointerSize: 4);
|
Attributes["color"] = Color = new VBO(pointerSize: 4);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public float LineWidth { get; set; } = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -7,16 +7,13 @@ using SM.OGL.Mesh;
|
||||||
|
|
||||||
namespace SM.Base.Objects
|
namespace SM.Base.Objects
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc cref="GenericMesh" />
|
||||||
public class Mesh : GenericMesh, ILineMesh
|
public class Mesh : GenericMesh, ILineMesh
|
||||||
{
|
{
|
||||||
|
|
||||||
public float LineWidth { get; set; } = 1;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// While initializing, it will add the <see cref="Color" /> to the data index.
|
/// While initializing, it will add the <see cref="Color" /> to the data index.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Mesh(PrimitiveType type) : base()
|
public Mesh(PrimitiveType type)
|
||||||
{
|
{
|
||||||
PrimitiveType = type;
|
PrimitiveType = type;
|
||||||
Attributes.Add(3, "color", Color);
|
Attributes.Add(3, "color", Color);
|
||||||
|
|
@ -27,5 +24,7 @@ namespace SM.Base.Objects
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual VBO Color { get; protected set; }
|
public virtual VBO Color { get; protected set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public float LineWidth { get; set; } = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,15 +1,19 @@
|
||||||
using OpenTK.Graphics;
|
#region usings
|
||||||
|
|
||||||
|
using OpenTK.Graphics;
|
||||||
using OpenTK.Graphics.OpenGL4;
|
using OpenTK.Graphics.OpenGL4;
|
||||||
using SM.OGL.Mesh;
|
using SM.OGL.Mesh;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
namespace SM.Base.Objects.Static
|
namespace SM.Base.Objects.Static
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An AxisHelper-Model
|
/// An AxisHelper-Model
|
||||||
/// <para>White: -X, -Y, -Z</para>
|
/// <para>White: -X, -Y, -Z</para>
|
||||||
/// <para>Red: +X </para>
|
/// <para>Red: +X </para>
|
||||||
/// <para>Green: +Y </para>
|
/// <para>Green: +Y </para>
|
||||||
/// <para>Blue: +Z </para>
|
/// <para>Blue: +Z </para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AxisHelper : Mesh
|
public class AxisHelper : Mesh
|
||||||
{
|
{
|
||||||
|
|
@ -18,28 +22,30 @@ namespace SM.Base.Objects.Static
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static AxisHelper Object = new AxisHelper();
|
public static AxisHelper Object = new AxisHelper();
|
||||||
|
|
||||||
private AxisHelper() : base(PrimitiveType.Lines) {}
|
private AxisHelper() : base(PrimitiveType.Lines)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override VBO Vertex { get; protected set; } = new VBO()
|
public override VBO Vertex { get; protected set; } = new VBO
|
||||||
{
|
{
|
||||||
{0, 0, 0},
|
{0, 0, 0},
|
||||||
{.5f, 0, 0},
|
{.5f, 0, 0},
|
||||||
{0, 0, 0},
|
{0, 0, 0},
|
||||||
{0, .5f, 0},
|
{0, .5f, 0},
|
||||||
{0, 0, -.5f},
|
{0, 0, -.5f},
|
||||||
{0, 0, .5f},
|
{0, 0, .5f}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override VBO Color { get; protected set; } = new VBO(pointerSize:4)
|
public override VBO Color { get; protected set; } = new VBO(pointerSize: 4)
|
||||||
{
|
{
|
||||||
{Color4.White},
|
Color4.White,
|
||||||
{Color4.Red},
|
Color4.Red,
|
||||||
{Color4.White},
|
Color4.White,
|
||||||
{Color4.Green},
|
Color4.Green,
|
||||||
{Color4.White},
|
Color4.White,
|
||||||
{Color4.DarkBlue},
|
Color4.DarkBlue
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,38 +1,46 @@
|
||||||
using System.ComponentModel;
|
#region usings
|
||||||
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics.OpenGL4;
|
using OpenTK.Graphics.OpenGL4;
|
||||||
using SM.Base;
|
|
||||||
using SM.Base.Drawing;
|
using SM.Base.Drawing;
|
||||||
using SM.Base.PostProcess;
|
using SM.Base.PostProcess;
|
||||||
using SM.Base.Windows;
|
using SM.Base.Utility;
|
||||||
|
using SM.Base.Window;
|
||||||
using SM.OGL.Framebuffer;
|
using SM.OGL.Framebuffer;
|
||||||
using SM.OGL.Texture;
|
using SM.OGL.Texture;
|
||||||
using SM.Utility;
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
namespace SM.Base.PostEffects
|
namespace SM.Base.PostEffects
|
||||||
{
|
{
|
||||||
public class BloomEffect : PostProcessEffect
|
public class BloomEffect : PostProcessEffect
|
||||||
{
|
{
|
||||||
private static BezierCurve _defaultCurve = new BezierCurve(Vector2.UnitY, Vector2.Zero, new Vector2(0.2f, 0f), new Vector2(1,0));
|
private static BezierCurve _defaultCurve = new BezierCurve(Vector2.UnitY, Vector2.Zero, new Vector2(0.4f, 0), new Vector2(.5f,0));
|
||||||
|
private static readonly PostProcessShader _mergeShader = new PostProcessShader(
|
||||||
|
AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom_merge_vert.glsl"),
|
||||||
|
AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom_merge.glsl"));
|
||||||
|
|
||||||
|
private static readonly PostProcessShader _shader =
|
||||||
|
new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom_blur.glsl"));
|
||||||
private const float _defaultTextureScale = .75f;
|
private const float _defaultTextureScale = .75f;
|
||||||
|
|
||||||
private float _textureScale = .75f;
|
private Framebuffer _source;
|
||||||
|
|
||||||
private Framebuffer _bloomBuffer1;
|
private Framebuffer _bloomBuffer1;
|
||||||
private Framebuffer _bloomBuffer2;
|
private Framebuffer _bloomBuffer2;
|
||||||
|
|
||||||
|
private readonly bool _hdr;
|
||||||
|
|
||||||
|
private readonly float _textureScale = .75f;
|
||||||
|
|
||||||
|
private BezierCurve _weightCurve;
|
||||||
|
private float[] _weights;
|
||||||
|
|
||||||
private ColorAttachment _xBuffer;
|
private ColorAttachment _xBuffer;
|
||||||
private ColorAttachment _yBuffer;
|
private ColorAttachment _yBuffer;
|
||||||
|
|
||||||
private PostProcessShader _shader = new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath+".bloom_blur.glsl"));
|
public TextureBase AmountMap;
|
||||||
private PostProcessShader _mergeShader = new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath+".bloom_merge_vert.glsl"), AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath+".bloom_merge.glsl"));
|
public TextureTransformation AmountTransform = new TextureTransformation();
|
||||||
|
|
||||||
private bool _hdr;
|
|
||||||
private Framebuffer _source;
|
|
||||||
|
|
||||||
private BezierCurve _weightCurve ;
|
|
||||||
private float[] _weights;
|
|
||||||
|
|
||||||
public int Iterations = 8;
|
public int Iterations = 8;
|
||||||
public float Threshold = .8f;
|
public float Threshold = .8f;
|
||||||
|
|
@ -40,21 +48,10 @@ namespace SM.Base.PostEffects
|
||||||
|
|
||||||
public bool Enable = true;
|
public bool Enable = true;
|
||||||
|
|
||||||
public float MinAmount = 0;
|
|
||||||
public float MaxAmount = 1;
|
public float MaxAmount = 1;
|
||||||
public TextureBase AmountMap;
|
|
||||||
public TextureTransformation AmountTransform = new TextureTransformation();
|
|
||||||
|
|
||||||
public BezierCurve WeightCurve
|
public float MinAmount = 0;
|
||||||
{
|
|
||||||
get => _weightCurve;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_weightCurve = value;
|
|
||||||
UpdateWeights();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int WeightCurvePickAmount = 4;
|
public int WeightCurvePickAmount = 4;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -67,18 +64,25 @@ namespace SM.Base.PostEffects
|
||||||
WeightCurve = _defaultCurve;
|
WeightCurve = _defaultCurve;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BezierCurve WeightCurve
|
||||||
|
{
|
||||||
|
get => _weightCurve;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_weightCurve = value;
|
||||||
|
UpdateWeights();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void UpdateWeights()
|
private void UpdateWeights()
|
||||||
{
|
{
|
||||||
_weights = new float[WeightCurvePickAmount];
|
_weights = new float[WeightCurvePickAmount];
|
||||||
|
|
||||||
for (int i = 0; i < WeightCurvePickAmount; i++)
|
for (int i = 0; i < WeightCurvePickAmount; i++)
|
||||||
{
|
_weights[i] = _weightCurve.CalculatePoint((float) (i + 1) / (WeightCurvePickAmount + 1)).Y;
|
||||||
_weights[i] = _weightCurve.CalculatePoint((float)(i + 1) / (WeightCurvePickAmount + 1)).Y;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected override void InitProcess()
|
protected override void InitProcess()
|
||||||
{
|
{
|
||||||
|
|
@ -86,10 +90,16 @@ namespace SM.Base.PostEffects
|
||||||
|
|
||||||
_source.ColorAttachments["color"].PixelInformation = PixelInformation.RGBA_HDR;
|
_source.ColorAttachments["color"].PixelInformation = PixelInformation.RGBA_HDR;
|
||||||
|
|
||||||
_bloomBuffer1 = new Framebuffer(Pipeline.ConnectedWindow, _textureScale);
|
_bloomBuffer1 = new Framebuffer(Pipeline.ConnectedWindow, _textureScale)
|
||||||
|
{
|
||||||
|
Name = "BloomX"
|
||||||
|
};
|
||||||
_bloomBuffer1.Append("xBuffer", _xBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR));
|
_bloomBuffer1.Append("xBuffer", _xBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR));
|
||||||
_bloomBuffer1.Compile();
|
_bloomBuffer1.Compile();
|
||||||
_bloomBuffer2 = new Framebuffer(Pipeline.ConnectedWindow, _textureScale);
|
_bloomBuffer2 = new Framebuffer(Pipeline.ConnectedWindow, _textureScale)
|
||||||
|
{
|
||||||
|
Name = "BloomY"
|
||||||
|
};
|
||||||
_bloomBuffer2.Append("yBuffer", _yBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR));
|
_bloomBuffer2.Append("yBuffer", _yBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR));
|
||||||
_bloomBuffer2.Compile();
|
_bloomBuffer2.Compile();
|
||||||
|
|
||||||
|
|
@ -101,33 +111,34 @@ namespace SM.Base.PostEffects
|
||||||
{
|
{
|
||||||
if (Enable)
|
if (Enable)
|
||||||
{
|
{
|
||||||
GL.Viewport(0,0, (int)(Pipeline.ConnectedWindow.Width * _textureScale), (int)(Pipeline.ConnectedWindow.Height * _textureScale));
|
GL.Viewport(0, 0, (int) (Pipeline.ConnectedWindow.Width * _textureScale),
|
||||||
|
(int) (Pipeline.ConnectedWindow.Height * _textureScale));
|
||||||
|
|
||||||
Framebuffer target = Framebuffer.GetCurrentlyActive();
|
Framebuffer target = Framebuffer.GetCurrentlyActive();
|
||||||
bool first = true, hoz = true;
|
bool first = true, hoz = true;
|
||||||
int iter = Iterations * 2;
|
int iter = Iterations * 2;
|
||||||
for (int i = 0; i < iter; i++)
|
for (int i = 0; i < iter; i++)
|
||||||
{
|
{
|
||||||
(hoz ? _bloomBuffer1 : _bloomBuffer2).Activate();
|
(hoz ? _bloomBuffer1 : _bloomBuffer2).Activate();
|
||||||
|
|
||||||
_shader.Draw(collection =>
|
_shader.Draw(collection =>
|
||||||
{
|
{
|
||||||
collection["renderedTexture"].SetTexture(first ? _source.ColorAttachments["color"] : (hoz ? _yBuffer : _xBuffer));
|
collection["renderedTexture"].SetTexture(first ? _source.ColorAttachments["color"] : (hoz ? _yBuffer : _xBuffer));
|
||||||
|
|
||||||
collection["First"].SetUniform1(first);
|
collection["First"].SetUniform1(first);
|
||||||
collection["Threshold"].SetUniform1(Threshold);
|
collection["Threshold"].SetUniform1(Threshold);
|
||||||
|
|
||||||
collection["Horizontal"].SetUniform1(hoz);
|
collection["Horizontal"].SetUniform1(hoz);
|
||||||
|
|
||||||
collection["Weights"].SetUniform1(_weights);
|
collection["Weights"].SetUniform1(_weights);
|
||||||
collection["WeightCount"].SetUniform1(WeightCurvePickAmount);
|
collection["WeightCount"].SetUniform1(WeightCurvePickAmount);
|
||||||
collection["Power"].SetUniform1(Power);
|
collection["Power"].SetUniform1(Power);
|
||||||
});
|
});
|
||||||
|
|
||||||
hoz = !hoz;
|
hoz = !hoz;
|
||||||
if (first) first = false;
|
if (first) first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GL.Viewport(Pipeline.ConnectedWindow.ClientRectangle);
|
GL.Viewport(Pipeline.ConnectedWindow.ClientRectangle);
|
||||||
target.Activate();
|
target.Activate();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
using System.Windows.Controls;
|
|
||||||
using OpenTK.Graphics.OpenGL4;
|
|
||||||
using SM.Base.PostProcess;
|
|
||||||
using SM.Base.Windows;
|
|
||||||
using SM.OGL.Framebuffer;
|
|
||||||
using SM.Utility;
|
|
||||||
|
|
||||||
namespace SM.Base.PostEffects
|
|
||||||
{
|
|
||||||
public class PostProcessFinals
|
|
||||||
{
|
|
||||||
static PostProcessShader _hdrExposureShader = new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath+".finalize_hdr.glsl"));
|
|
||||||
static PostProcessShader _gammaShader = new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".finalize_gamma.glsl"));
|
|
||||||
|
|
||||||
public static float Gamma = 2.2f;
|
|
||||||
|
|
||||||
public static void ResolveMultisampledBuffers(Framebuffer multisampledBuffers, Framebuffer target)
|
|
||||||
{
|
|
||||||
multisampledBuffers.Activate(FramebufferTarget.ReadFramebuffer);
|
|
||||||
target.Activate(FramebufferTarget.DrawFramebuffer);
|
|
||||||
GL.BlitFramebuffer(0, 0, (int)multisampledBuffers.Size.X, (int)multisampledBuffers.Size.Y, 0, 0, (int)target.Size.X, (int)target.Size.Y, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Nearest);
|
|
||||||
|
|
||||||
target.Activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void FinalizeHDR(ColorAttachment attachment, float exposure)
|
|
||||||
{
|
|
||||||
|
|
||||||
_hdrExposureShader.Draw(u =>
|
|
||||||
{
|
|
||||||
u["Gamma"].SetUniform1(Gamma);
|
|
||||||
u["Exposure"].SetUniform1(exposure);
|
|
||||||
u["Scene"].SetTexture(attachment);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void FinalizeGamma(ColorAttachment attachment)
|
|
||||||
{
|
|
||||||
_gammaShader.Draw(u =>
|
|
||||||
{
|
|
||||||
u["Gamma"].SetUniform1(Gamma);
|
|
||||||
u["Scene"].SetTexture(attachment);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
73
SMCode/SM.Base/PostEffects/PostProcessUtility.cs
Normal file
73
SMCode/SM.Base/PostEffects/PostProcessUtility.cs
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
#region usings
|
||||||
|
|
||||||
|
using OpenTK.Graphics.OpenGL4;
|
||||||
|
using SM.Base.PostProcess;
|
||||||
|
using SM.Base.Utility;
|
||||||
|
using SM.OGL.Framebuffer;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace SM.Base.PostEffects
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This class has some utility for render pipelines
|
||||||
|
/// </summary>
|
||||||
|
public static class PostProcessUtility
|
||||||
|
{
|
||||||
|
private static readonly PostProcessShader _hdrExposureShader =
|
||||||
|
new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".finalize_hdr.glsl"));
|
||||||
|
|
||||||
|
private static readonly PostProcessShader _gammaShader =
|
||||||
|
new PostProcessShader(
|
||||||
|
AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".finalize_gamma.glsl"));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The gamma that is used for <see cref="FinalizeGamma"/> and <see cref="FinalizeHDR"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static float Gamma = 2.2f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This resolves a multisampled framebuffer to a non-multisampled renderbuffer.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="multisampledBuffers"></param>
|
||||||
|
/// <param name="target"></param>
|
||||||
|
public static void ResolveMultisampledBuffers(Framebuffer multisampledBuffers, Framebuffer target)
|
||||||
|
{
|
||||||
|
multisampledBuffers.Activate(FramebufferTarget.ReadFramebuffer);
|
||||||
|
target.Activate(FramebufferTarget.DrawFramebuffer);
|
||||||
|
GL.BlitFramebuffer(0, 0, (int) multisampledBuffers.Size.X, (int) multisampledBuffers.Size.Y, 0, 0,
|
||||||
|
(int) target.Size.X, (int) target.Size.Y, ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit,
|
||||||
|
BlitFramebufferFilter.Nearest);
|
||||||
|
|
||||||
|
target.Activate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This converts HDR to LDR and applys gamma.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="attachment"></param>
|
||||||
|
/// <param name="exposure"></param>
|
||||||
|
public static void FinalizeHDR(ColorAttachment attachment, float exposure)
|
||||||
|
{
|
||||||
|
_hdrExposureShader.Draw(u =>
|
||||||
|
{
|
||||||
|
u["Gamma"].SetUniform1(Gamma);
|
||||||
|
u["Exposure"].SetUniform1(exposure);
|
||||||
|
u["Scene"].SetTexture(attachment);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This applys gamma
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="attachment"></param>
|
||||||
|
public static void FinalizeGamma(ColorAttachment attachment)
|
||||||
|
{
|
||||||
|
_gammaShader.Draw(u =>
|
||||||
|
{
|
||||||
|
u["Gamma"].SetUniform1(Gamma);
|
||||||
|
u["Scene"].SetTexture(attachment);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,19 +1,15 @@
|
||||||
using System.Collections;
|
#region usings
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics.OpenGL4;
|
|
||||||
using SM.Base;
|
|
||||||
using SM.Base.Objects.Static;
|
|
||||||
using SM.Base.Scene;
|
using SM.Base.Scene;
|
||||||
using SM.Base.Windows;
|
using SM.Base.Window;
|
||||||
using SM.OGL.Framebuffer;
|
|
||||||
using SM.OGL.Shaders;
|
#endregion
|
||||||
|
|
||||||
namespace SM.Base.PostProcess
|
namespace SM.Base.PostProcess
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Basis for a post process effect
|
/// Basis for a post process effect
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class PostProcessEffect
|
public abstract class PostProcessEffect
|
||||||
{
|
{
|
||||||
|
|
@ -22,7 +18,7 @@ namespace SM.Base.PostProcess
|
||||||
protected RenderPipeline Pipeline;
|
protected RenderPipeline Pipeline;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize the effect.
|
/// Initialize the effect.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pipeline"></param>
|
/// <param name="pipeline"></param>
|
||||||
public void Initilize(RenderPipeline pipeline)
|
public void Initilize(RenderPipeline pipeline)
|
||||||
|
|
@ -30,24 +26,25 @@ namespace SM.Base.PostProcess
|
||||||
Pipeline = pipeline;
|
Pipeline = pipeline;
|
||||||
InitProcess();
|
InitProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Method, to initialize the shader.
|
|
||||||
/// </summary>
|
|
||||||
protected virtual void InitProcess() {}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Method to draw the actual effect.
|
/// Method, to initialize the shader.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void InitProcess()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Method to draw the actual effect.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract void Draw(DrawContext context);
|
public abstract void Draw(DrawContext context);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Event, when the scene changed.
|
/// Event, when the scene changed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void SceneChanged(GenericScene scene)
|
public virtual void SceneChanged(GenericScene scene)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
using System;
|
#region usings
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenTK.Graphics.OpenGL4;
|
using OpenTK.Graphics.OpenGL4;
|
||||||
using SM.Base.Objects.Static;
|
using SM.Base.Objects.Static;
|
||||||
using SM.OGL.Framebuffer;
|
using SM.Base.Utility;
|
||||||
using SM.OGL.Shaders;
|
using SM.OGL.Shaders;
|
||||||
using SM.Utility;
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
namespace SM.Base.PostProcess
|
namespace SM.Base.PostProcess
|
||||||
{
|
{
|
||||||
|
|
@ -13,8 +16,12 @@ namespace SM.Base.PostProcess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PostProcessShader : GenericShader
|
public class PostProcessShader : GenericShader
|
||||||
{
|
{
|
||||||
private static readonly ShaderFile _fragExtensions = new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.extensions.frag"));
|
private static readonly ShaderFile _fragExtensions =
|
||||||
private static readonly ShaderFile _normalVertex = new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.vertexFile.vert"));
|
new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.extensions.frag"));
|
||||||
|
|
||||||
|
private static readonly ShaderFile _normalVertex =
|
||||||
|
new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.vertexFile.vert"));
|
||||||
|
|
||||||
private static readonly string _normalVertexWithExt =
|
private static readonly string _normalVertexWithExt =
|
||||||
AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.vertexWithExt.vert");
|
AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.vertexWithExt.vert");
|
||||||
|
|
||||||
|
|
@ -22,8 +29,9 @@ namespace SM.Base.PostProcess
|
||||||
/// Creates the shader with the default vertex shader and custom fragment.
|
/// Creates the shader with the default vertex shader and custom fragment.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PostProcessShader(string fragment) : this(_normalVertex,
|
public PostProcessShader(string fragment) : this(_normalVertex,
|
||||||
new ShaderFile(fragment))
|
new ShaderFile(fragment))
|
||||||
{ }
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the shader with an vertex extension and custom fragment.
|
/// Creates the shader with an vertex extension and custom fragment.
|
||||||
|
|
@ -32,9 +40,10 @@ namespace SM.Base.PostProcess
|
||||||
/// <param name="fragment"></param>
|
/// <param name="fragment"></param>
|
||||||
public PostProcessShader(string vertexExt, string fragment) : this(new ShaderFile(_normalVertexWithExt)
|
public PostProcessShader(string vertexExt, string fragment) : this(new ShaderFile(_normalVertexWithExt)
|
||||||
{
|
{
|
||||||
GLSLExtensions = new List<ShaderFile>() { new ShaderFile(vertexExt) }
|
GLSLExtensions = new List<ShaderFile> {new ShaderFile(vertexExt)}
|
||||||
}, new ShaderFile(fragment))
|
}, new ShaderFile(fragment))
|
||||||
{ }
|
{
|
||||||
|
}
|
||||||
|
|
||||||
private PostProcessShader(ShaderFile vertex, ShaderFile fragment) : base(
|
private PostProcessShader(ShaderFile vertex, ShaderFile fragment) : base(
|
||||||
new ShaderFileCollection(vertex, fragment))
|
new ShaderFileCollection(vertex, fragment))
|
||||||
|
|
@ -43,7 +52,7 @@ namespace SM.Base.PostProcess
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Draws the shader with special uniforms.
|
/// Draws the shader with special uniforms.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color"></param>
|
/// <param name="color"></param>
|
||||||
/// <param name="setUniformAction"></param>
|
/// <param name="setUniformAction"></param>
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,6 @@
|
||||||
<HintPath>..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll</HintPath>
|
<HintPath>..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="PresentationCore" />
|
<Reference Include="PresentationCore" />
|
||||||
<Reference Include="PresentationFramework" />
|
|
||||||
<Reference Include="SharpDX, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
|
<Reference Include="SharpDX, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\SharpDX.4.2.0\lib\net45\SharpDX.dll</HintPath>
|
<HintPath>..\..\packages\SharpDX.4.2.0\lib\net45\SharpDX.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|
@ -65,7 +64,7 @@
|
||||||
<Compile Include="Drawing\Instance.cs" />
|
<Compile Include="Drawing\Instance.cs" />
|
||||||
<Compile Include="Drawing\ShaderArguments.cs" />
|
<Compile Include="Drawing\ShaderArguments.cs" />
|
||||||
<Compile Include="Drawing\TextureTransformation.cs" />
|
<Compile Include="Drawing\TextureTransformation.cs" />
|
||||||
<Compile Include="PostEffects\PostProcessFinals.cs" />
|
<Compile Include="PostEffects\PostProcessUtility.cs" />
|
||||||
<Compile Include="Scene\IFixedScriptable.cs" />
|
<Compile Include="Scene\IFixedScriptable.cs" />
|
||||||
<Compile Include="Shaders\MaterialShader.cs" />
|
<Compile Include="Shaders\MaterialShader.cs" />
|
||||||
<Compile Include="Drawing\Particles\ParticleContext.cs" />
|
<Compile Include="Drawing\Particles\ParticleContext.cs" />
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,11 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using SM.Base.Drawing;
|
|
||||||
using SM.Base.Drawing.Text;
|
using SM.Base.Drawing.Text;
|
||||||
using SM.Base.Objects.Static;
|
using SM.Base.Objects.Static;
|
||||||
using SM.Base.Scene;
|
using SM.Base.Shaders;
|
||||||
using SM.Base.Windows;
|
using SM.Base.Utility;
|
||||||
|
using SM.Base.Window;
|
||||||
using SM.OGL.Mesh;
|
using SM.OGL.Mesh;
|
||||||
using SM.OGL.Shaders;
|
|
||||||
using SM.Utility;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using SM.Base.Windows;
|
using SM.Base.Window;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
@ -12,6 +12,11 @@ namespace SM.Base.Scene
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class GenericCamera
|
public abstract class GenericCamera
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Exposure defines the exposure to the Scene.
|
||||||
|
/// </summary>
|
||||||
|
public float Exposure = 1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This defines what is up. (Normalized)
|
/// This defines what is up. (Normalized)
|
||||||
/// <para>Default: <see cref="Vector3.UnitY" /></para>
|
/// <para>Default: <see cref="Vector3.UnitY" /></para>
|
||||||
|
|
@ -34,11 +39,6 @@ namespace SM.Base.Scene
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract bool Orthographic { get; }
|
public abstract bool Orthographic { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Exposure defines the exposure to the Scene.
|
|
||||||
/// </summary>
|
|
||||||
public float Exposure = 1;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calculates the view matrix.
|
/// Calculates the view matrix.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -46,10 +46,7 @@ namespace SM.Base.Scene
|
||||||
internal void CalculateViewMatrix(IGenericWindow window)
|
internal void CalculateViewMatrix(IGenericWindow window)
|
||||||
{
|
{
|
||||||
View = ViewCalculation(window);
|
View = ViewCalculation(window);
|
||||||
if (WorldCalculation(window, out Matrix4 world))
|
if (WorldCalculation(window, out Matrix4 world)) World = world;
|
||||||
{
|
|
||||||
World = world;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -61,6 +58,12 @@ namespace SM.Base.Scene
|
||||||
/// </returns>
|
/// </returns>
|
||||||
protected abstract Matrix4 ViewCalculation(IGenericWindow window);
|
protected abstract Matrix4 ViewCalculation(IGenericWindow window);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This calculates the world.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="window"></param>
|
||||||
|
/// <param name="world"></param>
|
||||||
|
/// <returns></returns>
|
||||||
protected abstract bool WorldCalculation(IGenericWindow window, out Matrix4 world);
|
protected abstract bool WorldCalculation(IGenericWindow window, out Matrix4 world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,11 +2,9 @@
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using OpenTK;
|
|
||||||
using SM.Base;
|
|
||||||
using SM.Base.Drawing;
|
using SM.Base.Drawing;
|
||||||
|
using SM.Base.Window;
|
||||||
using SM.Base.Window.Contexts;
|
using SM.Base.Window.Contexts;
|
||||||
using SM.Base.Windows;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
@ -23,7 +21,12 @@ namespace SM.Base.Scene
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Currently active script objects.
|
/// Currently active script objects.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ReadOnlyCollection<IScriptable> ScriptableObjects => new ReadOnlyCollection<IScriptable>(_scriptableObjects);
|
public ReadOnlyCollection<IScriptable> ScriptableObjects =>
|
||||||
|
new ReadOnlyCollection<IScriptable>(_scriptableObjects);
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool UpdateActive { get; set; } = true;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public List<IShowItem> Objects => this;
|
public List<IShowItem> Objects => this;
|
||||||
|
|
||||||
|
|
@ -34,23 +37,13 @@ namespace SM.Base.Scene
|
||||||
public string Name { get; set; } = "Unnamed Item Collection";
|
public string Name { get; set; } = "Unnamed Item Collection";
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public ICollection<string> Flags { get; set; } = new List<string>() {"collection"};
|
public ICollection<string> Flags { get; set; } = new List<string> {"collection"};
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IShowItem" />
|
||||||
public bool Active { get; set; } = true;
|
public bool Active { get; set; } = true;
|
||||||
public bool UpdateActive { get; set; } = true;
|
|
||||||
public bool RenderActive { get; set; } = true;
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public virtual void Update(UpdateContext context)
|
|
||||||
{
|
|
||||||
if (!Active || !UpdateActive) return;
|
|
||||||
|
|
||||||
for (var i = 0; i < _scriptableObjects.Count; i++)
|
/// <inheritdoc />
|
||||||
{
|
public bool RenderActive { get; set; } = true;
|
||||||
if (!_scriptableObjects[i].Active || !_scriptableObjects[i].UpdateActive) continue;
|
|
||||||
_scriptableObjects[i].Update(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void FixedUpdate(FixedUpdateContext context)
|
public virtual void FixedUpdate(FixedUpdateContext context)
|
||||||
{
|
{
|
||||||
|
|
@ -74,6 +67,18 @@ namespace SM.Base.Scene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public virtual void Update(UpdateContext context)
|
||||||
|
{
|
||||||
|
if (!Active || !UpdateActive) return;
|
||||||
|
|
||||||
|
for (var i = 0; i < _scriptableObjects.Count; i++)
|
||||||
|
{
|
||||||
|
if (!_scriptableObjects[i].Active || !_scriptableObjects[i].UpdateActive) continue;
|
||||||
|
_scriptableObjects[i].Update(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual void OnAdded(object sender)
|
public virtual void OnAdded(object sender)
|
||||||
{
|
{
|
||||||
|
|
@ -87,7 +92,7 @@ namespace SM.Base.Scene
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a item to the draw and the script collection, when applicable.
|
/// Adds a item to the draw and the script collection, when applicable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public new void Add(params IShowItem[] items)
|
public void Add(params IShowItem[] items)
|
||||||
{
|
{
|
||||||
foreach (var item in items)
|
foreach (var item in items)
|
||||||
{
|
{
|
||||||
|
|
@ -101,7 +106,7 @@ namespace SM.Base.Scene
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the object to the collection.
|
/// Adds the object to the collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
public void AddObject(IShowItem item)
|
public void AddObject(IShowItem item)
|
||||||
|
|
@ -110,8 +115,9 @@ namespace SM.Base.Scene
|
||||||
item.Parent = this;
|
item.Parent = this;
|
||||||
item.OnAdded(this);
|
item.OnAdded(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the script to the collection.
|
/// Adds the script to the collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
public void AddScript(IScriptable item)
|
public void AddScript(IScriptable item)
|
||||||
|
|
@ -120,7 +126,7 @@ namespace SM.Base.Scene
|
||||||
if (item is IFixedScriptable fs) _fixedScriptables.Add(fs);
|
if (item is IFixedScriptable fs) _fixedScriptables.Add(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public new void Remove(params IShowItem[] items)
|
public void Remove(params IShowItem[] items)
|
||||||
{
|
{
|
||||||
foreach (var item in items)
|
foreach (var item in items)
|
||||||
{
|
{
|
||||||
|
|
@ -135,7 +141,7 @@ namespace SM.Base.Scene
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Remove the object from the draw collection.
|
/// Remove the object from the draw collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
public void RemoveObject(IShowItem item)
|
public void RemoveObject(IShowItem item)
|
||||||
|
|
@ -146,7 +152,7 @@ namespace SM.Base.Scene
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Remove the object from the script collection.
|
/// Remove the object from the script collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
public void RemoveScript(IScriptable item)
|
public void RemoveScript(IScriptable item)
|
||||||
|
|
@ -158,7 +164,7 @@ namespace SM.Base.Scene
|
||||||
public ICollection<IShowItem> GetAllItems(bool includeCollections = false)
|
public ICollection<IShowItem> GetAllItems(bool includeCollections = false)
|
||||||
{
|
{
|
||||||
List<IShowItem> items = new List<IShowItem>();
|
List<IShowItem> items = new List<IShowItem>();
|
||||||
for (var i = 0; i < this.Count; i++)
|
for (var i = 0; i < Count; i++)
|
||||||
{
|
{
|
||||||
if (!includeCollections && this[i] is IShowCollection) continue;
|
if (!includeCollections && this[i] is IShowCollection) continue;
|
||||||
items.Add(this[i]);
|
items.Add(this[i]);
|
||||||
|
|
@ -220,7 +226,8 @@ namespace SM.Base.Scene
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TItem">The type of show items.</typeparam>
|
/// <typeparam name="TItem">The type of show items.</typeparam>
|
||||||
/// <typeparam name="TTransformation">The type of transformation.</typeparam>
|
/// <typeparam name="TTransformation">The type of transformation.</typeparam>
|
||||||
public abstract class GenericItemCollection<TTransformation> : GenericItemCollection, IShowTransformItem<TTransformation>
|
public abstract class GenericItemCollection<TTransformation> : GenericItemCollection,
|
||||||
|
IShowTransformItem<TTransformation>
|
||||||
where TTransformation : GenericTransformation, new()
|
where TTransformation : GenericTransformation, new()
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,9 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Dynamic;
|
using SM.Base.Utility;
|
||||||
using System.Windows.Controls;
|
using SM.Base.Window;
|
||||||
using SM.Base;
|
|
||||||
using SM.Base.Drawing;
|
|
||||||
using SM.Base.Window.Contexts;
|
using SM.Base.Window.Contexts;
|
||||||
using SM.Base.Windows;
|
|
||||||
using SM.Utility;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
@ -19,12 +15,17 @@ namespace SM.Base.Scene
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class GenericScene : IInitializable
|
public abstract class GenericScene : IInitializable
|
||||||
{
|
{
|
||||||
|
private IBackgroundItem _background;
|
||||||
|
private readonly Dictionary<Type, object> _extensions = new Dictionary<Type, object>();
|
||||||
|
|
||||||
private GenericItemCollection _hud;
|
private GenericItemCollection _hud;
|
||||||
private GenericItemCollection _objectCollection;
|
private GenericItemCollection _objectCollection;
|
||||||
private IBackgroundItem _background;
|
|
||||||
private Dictionary<Type, object> _extensions = new Dictionary<Type, object>();
|
/// <summary>
|
||||||
|
/// A collection for cameras to switch easier to different cameras.
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<string, GenericCamera> Cameras = new Dictionary<string, GenericCamera>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This contains the background.
|
/// This contains the background.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -64,16 +65,6 @@ namespace SM.Base.Scene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A collection for cameras to switch easier to different cameras.
|
|
||||||
/// </summary>
|
|
||||||
public Dictionary<string, GenericCamera> Cameras = new Dictionary<string, GenericCamera>();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// If true, the scene was already initialized.
|
|
||||||
/// </summary>
|
|
||||||
public bool IsInitialized { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If true, shows a axis helper at (0,0,0)
|
/// If true, shows a axis helper at (0,0,0)
|
||||||
|
|
@ -96,6 +87,20 @@ namespace SM.Base.Scene
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public GenericCamera HUDCamera { get; set; }
|
public GenericCamera HUDCamera { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If true, the scene was already initialized.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsInitialized { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public virtual void Activate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Initialization()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates this scene.
|
/// Updates this scene.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -162,7 +167,6 @@ namespace SM.Base.Scene
|
||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
public virtual void DrawDebug(DrawContext context)
|
public virtual void DrawDebug(DrawContext context)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -185,25 +189,20 @@ namespace SM.Base.Scene
|
||||||
object ext = _extensions[typeof(T)];
|
object ext = _extensions[typeof(T)];
|
||||||
if (ext == null)
|
if (ext == null)
|
||||||
{
|
{
|
||||||
Log.Write(LogType.Warning, $"Tried to get the extension '{typeof(T).Name}', that doesn't exist in the scene.");
|
Log.Write(LogType.Warning,
|
||||||
|
$"Tried to get the extension '{typeof(T).Name}', that doesn't exist in the scene.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (T)ext;
|
return (T) ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
public virtual void Activate()
|
/// This is triggered when the scene gets deactivated.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void Deactivate()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Initialization()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void Deactivate() {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -249,6 +248,5 @@ namespace SM.Base.Scene
|
||||||
get => (TCamera) base.BackgroundCamera;
|
get => (TCamera) base.BackgroundCamera;
|
||||||
set => base.BackgroundCamera = value;
|
set => base.BackgroundCamera = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,14 +1,24 @@
|
||||||
using SM.Base;
|
#region usings
|
||||||
using SM.Base.Windows;
|
|
||||||
|
using SM.Base.Window;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
namespace SM.Base.Scene
|
namespace SM.Base.Scene
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines a object as script.
|
/// Defines a object as script.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IScriptable
|
public interface IScriptable
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// If not active, ItemCollections will ignore them.
|
||||||
|
/// </summary>
|
||||||
bool Active { get; set; }
|
bool Active { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If not active, ItemCollections will ignore them.
|
||||||
|
/// </summary>
|
||||||
bool UpdateActive { get; set; }
|
bool UpdateActive { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using SM.Base;
|
using SM.Base.Window;
|
||||||
using SM.Base.Windows;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
@ -11,7 +10,6 @@ namespace SM.Base.Scene
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds functions, that is required for a collection.
|
/// Adds functions, that is required for a collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TItem">The type of show item.</typeparam>
|
|
||||||
public interface IShowCollection
|
public interface IShowCollection
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using SM.Base;
|
|
||||||
using SM.Base.Drawing;
|
using SM.Base.Drawing;
|
||||||
using SM.Base.Windows;
|
using SM.Base.Window;
|
||||||
using SM.OGL.Mesh;
|
using SM.OGL.Mesh;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -50,7 +49,7 @@ namespace SM.Base.Scene
|
||||||
void OnRemoved(object sender);
|
void OnRemoved(object sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ITransformItem<TTransform>
|
public interface ITransformItem<TTransform>
|
||||||
where TTransform : GenericTransformation
|
where TTransform : GenericTransformation
|
||||||
{
|
{
|
||||||
TTransform Transform { get; set; }
|
TTransform Transform { get; set; }
|
||||||
|
|
@ -58,7 +57,8 @@ namespace SM.Base.Scene
|
||||||
|
|
||||||
public interface IShowTransformItem<TTransform> : IShowItem, ITransformItem<TTransform>
|
public interface IShowTransformItem<TTransform> : IShowItem, ITransformItem<TTransform>
|
||||||
where TTransform : GenericTransformation
|
where TTransform : GenericTransformation
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public interface IModelItem
|
public interface IModelItem
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ using SM.OGL.Shaders;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace SM.Base.ShaderExtension
|
namespace SM.Base.Shaders.Extensions
|
||||||
{
|
{
|
||||||
internal class ExtensionManager
|
internal class ExtensionManager
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,13 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using OpenTK.Graphics.OpenGL4;
|
using OpenTK.Graphics.OpenGL4;
|
||||||
using SM.Base;
|
using SM.Base.Window;
|
||||||
using SM.Base.Windows;
|
|
||||||
using SM.OGL.Mesh;
|
using SM.OGL.Mesh;
|
||||||
using SM.OGL.Shaders;
|
using SM.OGL.Shaders;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace SM.Base.Drawing
|
namespace SM.Base.Shaders
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A general class to work with material shaders properly.
|
/// A general class to work with material shaders properly.
|
||||||
|
|
@ -19,7 +18,8 @@ namespace SM.Base.Drawing
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected MaterialShader(string combinedData) : base(combinedData)
|
protected MaterialShader(string combinedData) : base(combinedData)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected MaterialShader(string vertex, string fragment) : base(vertex, fragment)
|
protected MaterialShader(string vertex, string fragment) : base(vertex, fragment)
|
||||||
|
|
@ -60,7 +60,11 @@ namespace SM.Base.Drawing
|
||||||
{
|
{
|
||||||
GL.Enable(EnableCap.Blend);
|
GL.Enable(EnableCap.Blend);
|
||||||
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
|
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
|
||||||
} else GL.Disable(EnableCap.Blend);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GL.Disable(EnableCap.Blend);
|
||||||
|
}
|
||||||
|
|
||||||
DrawProcess(context);
|
DrawProcess(context);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,46 @@
|
||||||
using System;
|
#region usings
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Dynamic;
|
|
||||||
using SM.Base.Windows;
|
|
||||||
using SM.OGL.Shaders;
|
|
||||||
using SM.Utility;
|
|
||||||
|
|
||||||
namespace SM.Base.Drawing
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using SM.Base.Utility;
|
||||||
|
using SM.Base.Window;
|
||||||
|
using SM.OGL.Shaders;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace SM.Base.Shaders
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Allows for simple creation of shaders.
|
||||||
|
/// </summary>
|
||||||
public class SimpleShader : MaterialShader
|
public class SimpleShader : MaterialShader
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Vertex files that are stored in this dictionary can be used as vertex presets.
|
||||||
|
/// </summary>
|
||||||
public static Dictionary<string, Tuple<ShaderFile, Action<UniformCollection, DrawContext>>> VertexFiles =
|
public static Dictionary<string, Tuple<ShaderFile, Action<UniformCollection, DrawContext>>> VertexFiles =
|
||||||
new Dictionary<string, Tuple<ShaderFile, Action<UniformCollection, DrawContext>>>();
|
new Dictionary<string, Tuple<ShaderFile, Action<UniformCollection, DrawContext>>>();
|
||||||
|
|
||||||
|
private readonly string _vertexPreset;
|
||||||
|
|
||||||
static ShaderFile _extensionDefineFile = new ShaderFile("#define SM_SIMPLE_EXTENSION");
|
/// <summary>
|
||||||
|
/// Stores the function that sets the uniforms.
|
||||||
|
/// </summary>
|
||||||
|
public Action<UniformCollection, DrawContext> SetUniform;
|
||||||
|
|
||||||
static SimpleShader()
|
static SimpleShader()
|
||||||
{
|
{
|
||||||
VertexFiles.Add("basic", new Tuple<ShaderFile, Action<UniformCollection, DrawContext>>(
|
VertexFiles.Add("basic", new Tuple<ShaderFile, Action<UniformCollection, DrawContext>>(
|
||||||
new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.Shaders.SimpleShaderPresets.basic_vertex.glsl"))
|
new ShaderFile(
|
||||||
|
AssemblyUtility.ReadAssemblyFile("SM.Base.Shaders.SimpleShaderPresets.basic_vertex.glsl"))
|
||||||
{
|
{
|
||||||
StringOverrides = {["extension"] = "0"}
|
StringOverrides = {["extension"] = "0"}
|
||||||
},
|
},
|
||||||
BasicSetUniforms
|
BasicSetUniforms
|
||||||
));
|
));
|
||||||
VertexFiles.Add("E_basic", new Tuple<ShaderFile, Action<UniformCollection, DrawContext>>(
|
VertexFiles.Add("E_basic", new Tuple<ShaderFile, Action<UniformCollection, DrawContext>>(
|
||||||
new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.Shaders.SimpleShaderPresets.basic_vertex.glsl"))
|
new ShaderFile(
|
||||||
|
AssemblyUtility.ReadAssemblyFile("SM.Base.Shaders.SimpleShaderPresets.basic_vertex.glsl"))
|
||||||
{
|
{
|
||||||
StringOverrides = {["extension"] = "1"}
|
StringOverrides = {["extension"] = "1"}
|
||||||
},
|
},
|
||||||
|
|
@ -35,7 +51,7 @@ namespace SM.Base.Drawing
|
||||||
new ShaderFile(
|
new ShaderFile(
|
||||||
AssemblyUtility.ReadAssemblyFile("SM.Base.Shaders.SimpleShaderPresets.instanced_vertex.glsl"))
|
AssemblyUtility.ReadAssemblyFile("SM.Base.Shaders.SimpleShaderPresets.instanced_vertex.glsl"))
|
||||||
{
|
{
|
||||||
StringOverrides = { ["instanceMax"] = SMRenderer.MaxInstances.ToString(), ["extension"] = "0" }
|
StringOverrides = {["instanceMax"] = SMRenderer.MaxInstances.ToString(), ["extension"] = "0"}
|
||||||
},
|
},
|
||||||
InstancedSetUniforms
|
InstancedSetUniforms
|
||||||
));
|
));
|
||||||
|
|
@ -43,16 +59,46 @@ namespace SM.Base.Drawing
|
||||||
new ShaderFile(
|
new ShaderFile(
|
||||||
AssemblyUtility.ReadAssemblyFile("SM.Base.Shaders.SimpleShaderPresets.instanced_vertex.glsl"))
|
AssemblyUtility.ReadAssemblyFile("SM.Base.Shaders.SimpleShaderPresets.instanced_vertex.glsl"))
|
||||||
{
|
{
|
||||||
StringOverrides = { ["instanceMax"] = SMRenderer.MaxInstances.ToString(), ["extension"] = "0" }
|
StringOverrides = {["instanceMax"] = SMRenderer.MaxInstances.ToString(), ["extension"] = "0"}
|
||||||
},
|
},
|
||||||
InstancedSetUniforms
|
InstancedSetUniforms
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void BasicSetUniforms(UniformCollection uniforms, DrawContext context)
|
/// <summary>
|
||||||
|
/// Creates a simple shader.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vertexPreset">The vertex preset.</param>
|
||||||
|
/// <param name="fragment">The fragment shader</param>
|
||||||
|
/// <param name="setUniform">The uniform function.</param>
|
||||||
|
public SimpleShader(string vertexPreset, string fragment, Action<UniformCollection, DrawContext> setUniform) :
|
||||||
|
base(new ShaderFileCollection(VertexFiles[vertexPreset].Item1, new ShaderFile(fragment)))
|
||||||
|
{
|
||||||
|
_vertexPreset = vertexPreset;
|
||||||
|
SetUniform = setUniform;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a simple shader with a extension.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vertexPreset">The vertex preset.</param>
|
||||||
|
/// <param name="vertexExtension">The vertex extension shader</param>
|
||||||
|
/// <param name="fragment">The fragment shader</param>
|
||||||
|
/// <param name="setUniform">The uniform function.</param>
|
||||||
|
public SimpleShader(string vertexPreset, string vertexExtension, string fragment,
|
||||||
|
Action<UniformCollection, DrawContext> setUniform) : base(new ShaderFileCollection(
|
||||||
|
new[] {VertexFiles["E_" + vertexPreset].Item1, new ShaderFile(vertexExtension)},
|
||||||
|
new[] {new ShaderFile(fragment)}))
|
||||||
|
{
|
||||||
|
_vertexPreset = vertexPreset;
|
||||||
|
SetUniform = setUniform;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void BasicSetUniforms(UniformCollection uniforms, DrawContext context)
|
||||||
{
|
{
|
||||||
// Vertex Uniforms
|
// Vertex Uniforms
|
||||||
uniforms["MVP"].SetMatrix4(context.Instances[0].ModelMatrix * context.ModelMatrix * context.View * context.World);
|
uniforms["MVP"]
|
||||||
|
.SetMatrix4(context.Instances[0].ModelMatrix * context.ModelMatrix * context.View * context.World);
|
||||||
uniforms["MasterTextureMatrix"].SetMatrix3(context.Instances[0].TextureMatrix * context.TextureMatrix);
|
uniforms["MasterTextureMatrix"].SetMatrix3(context.Instances[0].TextureMatrix * context.TextureMatrix);
|
||||||
uniforms["HasVColor"]
|
uniforms["HasVColor"]
|
||||||
.SetUniform1(context.Mesh.Attributes.Has("color"));
|
.SetUniform1(context.Mesh.Attributes.Has("color"));
|
||||||
|
|
@ -60,7 +106,7 @@ namespace SM.Base.Drawing
|
||||||
DrawObject(context.ForcedType.GetValueOrDefault(context.Mesh.PrimitiveType), context.Mesh);
|
DrawObject(context.ForcedType.GetValueOrDefault(context.Mesh.PrimitiveType), context.Mesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InstancedSetUniforms(UniformCollection uniforms, DrawContext context)
|
private static void InstancedSetUniforms(UniformCollection uniforms, DrawContext context)
|
||||||
{
|
{
|
||||||
uniforms["MVP"].SetMatrix4(context.ModelMatrix * context.View * context.World);
|
uniforms["MVP"].SetMatrix4(context.ModelMatrix * context.View * context.World);
|
||||||
uniforms["MasterTextureMatrix"].SetMatrix3(context.TextureMatrix);
|
uniforms["MasterTextureMatrix"].SetMatrix3(context.TextureMatrix);
|
||||||
|
|
@ -86,28 +132,11 @@ namespace SM.Base.Drawing
|
||||||
|
|
||||||
shaderInstanceI++;
|
shaderInstanceI++;
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawObject(context.ForcedType.GetValueOrDefault(context.Mesh.PrimitiveType), context.Mesh, shaderInstanceI);
|
DrawObject(context.ForcedType.GetValueOrDefault(context.Mesh.PrimitiveType), context.Mesh, shaderInstanceI);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string _vertexPreset;
|
/// <inheritdoc />
|
||||||
|
|
||||||
public Action<UniformCollection, DrawContext> SetUniform;
|
|
||||||
|
|
||||||
public SimpleShader(string vertexPreset, string fragment, Action<UniformCollection, DrawContext> setUniform) : base(new ShaderFileCollection(VertexFiles[vertexPreset].Item1, new ShaderFile(fragment)))
|
|
||||||
{
|
|
||||||
_vertexPreset = vertexPreset;
|
|
||||||
SetUniform = setUniform;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SimpleShader(string vertexPreset, string vertexExtension, string fragment,
|
|
||||||
Action<UniformCollection, DrawContext> setUniform) : base(new ShaderFileCollection(
|
|
||||||
new[] {VertexFiles["E_"+vertexPreset].Item1, new ShaderFile(vertexExtension)},
|
|
||||||
new[] {new ShaderFile(fragment),}))
|
|
||||||
{
|
|
||||||
_vertexPreset = vertexPreset;
|
|
||||||
SetUniform = setUniform;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void DrawProcess(DrawContext context)
|
protected override void DrawProcess(DrawContext context)
|
||||||
{
|
{
|
||||||
SetUniform?.Invoke(Uniforms, context);
|
SetUniform?.Invoke(Uniforms, context);
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ namespace SM.Base.Textures
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Texture : TextureBase
|
public class Texture : TextureBase
|
||||||
{
|
{
|
||||||
private int? _width;
|
|
||||||
private int? _height;
|
private int? _height;
|
||||||
|
private int? _width;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Decides if the bitmap will automatically dispose itself.
|
/// Decides if the bitmap will automatically dispose itself.
|
||||||
|
|
@ -28,24 +28,6 @@ namespace SM.Base.Textures
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Bitmap Map;
|
public Bitmap Map;
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override int Width
|
|
||||||
{
|
|
||||||
get => _width ?? Map.Width;
|
|
||||||
protected set => _width = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override int Height
|
|
||||||
{
|
|
||||||
get => _height ?? Map.Height;
|
|
||||||
protected set => _height = value;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Aspect ratio of Width and Height of the texture
|
|
||||||
/// </summary>
|
|
||||||
public float Aspect { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Empty constructor
|
/// Empty constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -72,12 +54,31 @@ namespace SM.Base.Textures
|
||||||
{
|
{
|
||||||
Map = map;
|
Map = map;
|
||||||
|
|
||||||
Aspect = (float)map.Width / map.Height;
|
Aspect = (float) map.Width / map.Height;
|
||||||
|
|
||||||
Filter = filter;
|
Filter = filter;
|
||||||
WrapMode = wrapMode;
|
WrapMode = wrapMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override int Width
|
||||||
|
{
|
||||||
|
get => _width ?? Map.Width;
|
||||||
|
protected set => _width = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override int Height
|
||||||
|
{
|
||||||
|
get => _height ?? Map.Height;
|
||||||
|
protected set => _height = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Aspect ratio of Width and Height of the texture
|
||||||
|
/// </summary>
|
||||||
|
public float Aspect { get; }
|
||||||
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Compile()
|
public override void Compile()
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using SM.Base;
|
using SM.Base.Window;
|
||||||
using SM.Base.Windows;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using SM.Base;
|
using SM.Base.Window;
|
||||||
using SM.Base.Windows;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
@ -14,17 +13,17 @@ namespace SM.Base.Time
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Stopwatch
|
public class Stopwatch
|
||||||
{
|
{
|
||||||
private static List<Stopwatch> _activeStopwatches = new List<Stopwatch>();
|
private static readonly List<Stopwatch> _activeStopwatches = new List<Stopwatch>();
|
||||||
private bool _paused = false;
|
private bool _paused;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If true, the stopwatch was started.
|
/// If true, the stopwatch was started.
|
||||||
/// <para>This doesn't changed when paused.</para>
|
/// <para>This doesn't changed when paused.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Active { get; private set; } = false;
|
public bool Active { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets/Sets if the stopwatch is paused.
|
/// Gets/Sets if the stopwatch is paused.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Paused
|
public bool Paused
|
||||||
{
|
{
|
||||||
|
|
@ -39,7 +38,7 @@ namespace SM.Base.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If true, the stopwatch is active and not paused... (who would have guessed...)
|
/// If true, the stopwatch is active and not paused... (who would have guessed...)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Running => Active && !Paused;
|
public bool Running => Active && !Paused;
|
||||||
|
|
||||||
|
|
@ -53,6 +52,9 @@ namespace SM.Base.Time
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TimeSpan ElapsedSpan { get; protected set; }
|
public TimeSpan ElapsedSpan { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This event gets triggered every tick.
|
||||||
|
/// </summary>
|
||||||
public event Action<Stopwatch, UpdateContext> Tick;
|
public event Action<Stopwatch, UpdateContext> Tick;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -66,7 +68,6 @@ namespace SM.Base.Time
|
||||||
Active = true;
|
Active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Performs a tick.
|
/// Performs a tick.
|
||||||
|
|
@ -81,15 +82,15 @@ namespace SM.Base.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resumes the timer.
|
/// Resumes the timer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual void Resume()
|
protected virtual void Resume()
|
||||||
{
|
{
|
||||||
_paused = false;
|
_paused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Pauses the timer.
|
/// Pauses the timer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual void Pause()
|
protected virtual void Pause()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.Eventing.Reader;
|
using SM.Base.Window;
|
||||||
using SM.Base;
|
|
||||||
using SM.Base.Windows;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
@ -35,7 +33,7 @@ namespace SM.Base.Time
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The target time in seconds.
|
/// The target time in seconds.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float Target { get; private set; }
|
public float Target { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The already elapsed time but normalized to the target.
|
/// The already elapsed time but normalized to the target.
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,18 @@
|
||||||
using System;
|
#region usings
|
||||||
using OpenTK;
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
namespace SM.Base.Types
|
namespace SM.Base.Types
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A One-dimensional Vector (also known as <see cref="float"/>), in a class.
|
/// A One-dimensional Vector (also known as <see cref="float" />), in a class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CVector1
|
public class CVector1
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// X - Component
|
/// Creates a class vector
|
||||||
/// </summary>
|
|
||||||
public float X
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The length/magnitute of the vector.
|
|
||||||
/// </summary>
|
|
||||||
public float Length => GetLength();
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the square of the vector length (magnitude).
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// This property avoids the costly square root operation required by the Length property. This makes it more suitable
|
|
||||||
/// for comparisons.
|
|
||||||
/// </remarks>
|
|
||||||
public float LengthSquared => GetLength(true);
|
|
||||||
|
|
||||||
public event Action Changed;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a class vector
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="x">X-Component</param>
|
/// <param name="x">X-Component</param>
|
||||||
public CVector1(float x)
|
public CVector1(float x)
|
||||||
|
|
@ -41,10 +20,33 @@ namespace SM.Base.Types
|
||||||
X = x;
|
X = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// X - Component
|
||||||
|
/// </summary>
|
||||||
|
public float X { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the length of the vector.
|
/// The length/magnitute of the vector.
|
||||||
|
/// </summary>
|
||||||
|
public float Length => GetLength();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the square of the vector length (magnitude).
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This property avoids the costly square root operation required by the Length property. This makes it more suitable
|
||||||
|
/// for comparisons.
|
||||||
|
/// </remarks>
|
||||||
|
public float LengthSquared => GetLength(true);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This event triggers when a component changed.
|
||||||
|
/// </summary>
|
||||||
|
public event Action Changed;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the length of the vector.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="squared">If true, it will return the squared product.</param>
|
/// <param name="squared">If true, it will return the squared product.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
|
@ -57,7 +59,7 @@ namespace SM.Base.Types
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Normalizes the vector.
|
/// Normalizes the vector.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Normalize()
|
public void Normalize()
|
||||||
{
|
{
|
||||||
|
|
@ -66,7 +68,7 @@ namespace SM.Base.Types
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the X-Component.
|
/// Sets the X-Component.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="x">X-Component</param>
|
/// <param name="x">X-Component</param>
|
||||||
public virtual void Set(float uniform, bool triggerChanged = true)
|
public virtual void Set(float uniform, bool triggerChanged = true)
|
||||||
|
|
@ -75,6 +77,11 @@ namespace SM.Base.Types
|
||||||
if (triggerChanged) TriggerChanged();
|
if (triggerChanged) TriggerChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds the value to the components.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="uniform"></param>
|
||||||
|
/// <param name="triggerChanged"></param>
|
||||||
public virtual void Add(float uniform, bool triggerChanged = true)
|
public virtual void Add(float uniform, bool triggerChanged = true)
|
||||||
{
|
{
|
||||||
X += uniform;
|
X += uniform;
|
||||||
|
|
@ -82,20 +89,24 @@ namespace SM.Base.Types
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Conversion into <see cref="float"/>
|
/// Conversion into <see cref="float" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static implicit operator float(CVector1 vector1) => vector1.X;
|
public static implicit operator float(CVector1 vector1)
|
||||||
|
{
|
||||||
|
return vector1.X;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Conversion from <see cref="float"/> to One-dimensional Vector.
|
/// Conversion from <see cref="float" /> to One-dimensional Vector.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="f"></param>
|
/// <param name="f"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
//public static implicit operator CVector1(float f) => new CVector1(f);
|
//public static implicit operator CVector1(float f) => new CVector1(f);
|
||||||
|
|
||||||
protected virtual float GetLengthProcess()
|
protected virtual float GetLengthProcess()
|
||||||
{
|
{
|
||||||
return X * X;
|
return X * X;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void NormalizationProcess(float length)
|
protected virtual void NormalizationProcess(float length)
|
||||||
{
|
{
|
||||||
X *= length;
|
X *= length;
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,18 @@
|
||||||
using OpenTK;
|
#region usings
|
||||||
|
|
||||||
|
using OpenTK;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
namespace SM.Base.Types
|
namespace SM.Base.Types
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A two-dimensional vector.
|
/// A two-dimensional vector.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CVector2 : CVector1
|
public class CVector2 : CVector1
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Y-component
|
/// Creates a vector, where each component is the same value.
|
||||||
/// </summary>
|
|
||||||
public float Y { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a vector, where each component is the same value.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="uniform">The Value</param>
|
/// <param name="uniform">The Value</param>
|
||||||
public CVector2(float uniform) : base(uniform)
|
public CVector2(float uniform) : base(uniform)
|
||||||
|
|
@ -22,18 +21,25 @@ namespace SM.Base.Types
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a vector
|
/// Creates a vector
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public CVector2(float x, float y) : base(x)
|
public CVector2(float x, float y) : base(x)
|
||||||
{
|
{
|
||||||
Y = y;
|
Y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Y-component
|
||||||
|
/// </summary>
|
||||||
|
public float Y { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
protected override float GetLengthProcess()
|
protected override float GetLengthProcess()
|
||||||
{
|
{
|
||||||
return base.GetLengthProcess() + Y * Y;
|
return base.GetLengthProcess() + Y * Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
protected override void NormalizationProcess(float length)
|
protected override void NormalizationProcess(float length)
|
||||||
{
|
{
|
||||||
base.NormalizationProcess(length);
|
base.NormalizationProcess(length);
|
||||||
|
|
@ -41,7 +47,7 @@ namespace SM.Base.Types
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets each component to the same value
|
/// Sets each component to the same value
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="uniform"></param>
|
/// <param name="uniform"></param>
|
||||||
public override void Set(float uniform, bool triggerChanged = true)
|
public override void Set(float uniform, bool triggerChanged = true)
|
||||||
|
|
@ -51,7 +57,7 @@ namespace SM.Base.Types
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets each component to the <see cref="Vector2"/> counter-part.
|
/// Sets each component to the <see cref="Vector2" /> counter-part.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="vector"></param>
|
/// <param name="vector"></param>
|
||||||
public void Set(Vector2 vector, bool triggerChanged = true)
|
public void Set(Vector2 vector, bool triggerChanged = true)
|
||||||
|
|
@ -60,7 +66,7 @@ namespace SM.Base.Types
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the a own value to each component.
|
/// Sets the a own value to each component.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="x"></param>
|
/// <param name="x"></param>
|
||||||
/// <param name="y"></param>
|
/// <param name="y"></param>
|
||||||
|
|
@ -70,17 +76,29 @@ namespace SM.Base.Types
|
||||||
base.Set(x, triggerChanged);
|
base.Set(x, triggerChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public override void Add(float uniform, bool triggerChanged = true)
|
public override void Add(float uniform, bool triggerChanged = true)
|
||||||
{
|
{
|
||||||
Y += uniform;
|
Y += uniform;
|
||||||
base.Add(uniform, triggerChanged);
|
base.Add(uniform, triggerChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds <see cref="Vector2"/> to the CVector.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector"></param>
|
||||||
|
/// <param name="triggerChanged">If false, the event Changed doesn't gets triggered </param>
|
||||||
public void Add(Vector2 vector, bool triggerChanged = true)
|
public void Add(Vector2 vector, bool triggerChanged = true)
|
||||||
{
|
{
|
||||||
Add(vector.X, vector.Y, triggerChanged);
|
Add(vector.X, vector.Y, triggerChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds the values to the CVector.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x"></param>
|
||||||
|
/// <param name="y"></param>
|
||||||
|
/// <param name="triggerChanged">If false, the event Changed doesn't gets triggered </param>
|
||||||
public void Add(float x, float y, bool triggerChanged = true)
|
public void Add(float x, float y, bool triggerChanged = true)
|
||||||
{
|
{
|
||||||
Y += y;
|
Y += y;
|
||||||
|
|
@ -88,12 +106,19 @@ namespace SM.Base.Types
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts to <see cref="Vector2"/>
|
/// Converts to <see cref="Vector2" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static implicit operator Vector2(CVector2 vector2) => new Vector2(vector2.X, vector2.Y);
|
public static implicit operator Vector2(CVector2 vector2)
|
||||||
|
{
|
||||||
|
return new Vector2(vector2.X, vector2.Y);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts from <see cref="Vector2"/> to <see cref="CVector2"/>.
|
/// Converts from <see cref="Vector2" /> to <see cref="CVector2" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static implicit operator CVector2(Vector2 vector2) => new CVector2(vector2.X, vector2.Y);
|
public static implicit operator CVector2(Vector2 vector2)
|
||||||
|
{
|
||||||
|
return new CVector2(vector2.X, vector2.Y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,38 +1,45 @@
|
||||||
using OpenTK;
|
#region usings
|
||||||
|
|
||||||
|
using OpenTK;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
namespace SM.Base.Types
|
namespace SM.Base.Types
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A three-dimensional vector.
|
/// A three-dimensional vector.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CVector3 : CVector2
|
public class CVector3 : CVector2
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Z-component
|
/// Creates a vector, where each component is the same value.
|
||||||
/// </summary>
|
|
||||||
public float Z { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a vector, where each component is the same value.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="uniform">The Value</param>
|
/// <param name="uniform">The Value</param>
|
||||||
public CVector3(float uniform) : base(uniform)
|
public CVector3(float uniform) : base(uniform)
|
||||||
{
|
{
|
||||||
Z = uniform;
|
Z = uniform;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a vector
|
/// Creates a vector
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public CVector3(float x, float y, float z) : base(x, y)
|
public CVector3(float x, float y, float z) : base(x, y)
|
||||||
{
|
{
|
||||||
Z = z;
|
Z = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Z-component
|
||||||
|
/// </summary>
|
||||||
|
public float Z { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
protected override float GetLengthProcess()
|
protected override float GetLengthProcess()
|
||||||
{
|
{
|
||||||
return base.GetLengthProcess() + Z * Z;
|
return base.GetLengthProcess() + Z * Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
protected override void NormalizationProcess(float length)
|
protected override void NormalizationProcess(float length)
|
||||||
{
|
{
|
||||||
base.NormalizationProcess(length);
|
base.NormalizationProcess(length);
|
||||||
|
|
@ -47,15 +54,16 @@ namespace SM.Base.Types
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the a own value to each component.
|
/// Sets the a own value to each component.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Set(float x, float y, float z, bool triggerChanged = true)
|
public void Set(float x, float y, float z, bool triggerChanged = true)
|
||||||
{
|
{
|
||||||
Z = z;
|
Z = z;
|
||||||
base.Set(x,y, triggerChanged);
|
base.Set(x, y, triggerChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets each component to the <see cref="Vector3"/> counter-part.
|
/// Sets each component to the <see cref="Vector3" /> counter-part.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="vector"></param>
|
/// <param name="vector"></param>
|
||||||
public void Set(Vector3 vector, bool triggerChanged = true)
|
public void Set(Vector3 vector, bool triggerChanged = true)
|
||||||
|
|
@ -63,30 +71,50 @@ namespace SM.Base.Types
|
||||||
Set(vector.X, vector.Y, vector.Z, triggerChanged);
|
Set(vector.X, vector.Y, vector.Z, triggerChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public override void Add(float uniform, bool triggerChanged = true)
|
public override void Add(float uniform, bool triggerChanged = true)
|
||||||
{
|
{
|
||||||
Z += uniform;
|
Z += uniform;
|
||||||
base.Add(uniform, triggerChanged);
|
base.Add(uniform, triggerChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a <see cref="Vector3"/> to the CVector.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector"></param>
|
||||||
|
/// <param name="triggerChanged">If false, the event Changed doesn't gets triggered </param>
|
||||||
public void Add(Vector3 vector, bool triggerChanged = true)
|
public void Add(Vector3 vector, bool triggerChanged = true)
|
||||||
{
|
{
|
||||||
Add(vector.X, vector.Y, vector.Z, triggerChanged);
|
Add(vector.X, vector.Y, vector.Z, triggerChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds the values to the CVector.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x"></param>
|
||||||
|
/// <param name="y"></param>
|
||||||
|
/// <param name="z"></param>
|
||||||
|
/// <param name="triggerChanged">If false, the event Changed doesn't gets triggered </param>
|
||||||
public void Add(float x, float y, float z, bool triggerChanged = true)
|
public void Add(float x, float y, float z, bool triggerChanged = true)
|
||||||
{
|
{
|
||||||
Z += z;
|
Z += z;
|
||||||
base.Add(x,y, triggerChanged);
|
base.Add(x, y, triggerChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts to <see cref="Vector3"/>
|
/// Converts to <see cref="Vector3" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static implicit operator Vector3(CVector3 vector) => new Vector3(vector.X, vector.Y, vector.Z);
|
public static implicit operator Vector3(CVector3 vector)
|
||||||
|
{
|
||||||
|
return new Vector3(vector.X, vector.Y, vector.Z);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts from <see cref="Vector3"/> to <see cref="CVector3"/>.
|
/// Converts from <see cref="Vector3" /> to <see cref="CVector3" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static implicit operator CVector3(Vector3 vector) => new CVector3(vector.X, vector.Y, vector.Z);
|
public static implicit operator CVector3(Vector3 vector)
|
||||||
|
{
|
||||||
|
return new CVector3(vector.X, vector.Y, vector.Z);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,7 +6,7 @@ using System.Reflection;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace SM.Utility
|
namespace SM.Base.Utility
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains utility functions for handling with assemblies.
|
/// Contains utility functions for handling with assemblies.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace SM.Utility
|
namespace SM.Base.Utility
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A assistant to control the delta time.
|
/// A assistant to control the delta time.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
namespace SM.Utility
|
namespace SM.Base.Utility
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
public interface IInitializable
|
public interface IInitializable
|
||||||
{
|
{
|
||||||
bool IsInitialized { get; set; }
|
bool IsInitialized { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,11 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace SM.Utility
|
namespace SM.Base.Utility
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A global helper class for randomization.
|
/// A global helper class for randomization.
|
||||||
|
|
@ -85,7 +83,7 @@ namespace SM.Utility
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a random item from the provided list.
|
/// Gets a random item from the provided list.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static TSource GetRandomItem<TSource>(this IList<TSource> list)
|
public static TSource GetRandomItem<TSource>(this IList<TSource> list)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
using System;
|
#region usings
|
||||||
using System.Windows;
|
|
||||||
|
using System;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using SM.Base.Drawing;
|
|
||||||
using SM.Base.Scene;
|
|
||||||
using SM.OGL.Mesh;
|
using SM.OGL.Mesh;
|
||||||
|
|
||||||
namespace SM.Utility
|
#endregion
|
||||||
|
|
||||||
|
namespace SM.Base.Utility
|
||||||
{
|
{
|
||||||
public struct Ray
|
public struct Ray
|
||||||
{
|
{
|
||||||
|
|
@ -23,9 +24,9 @@ namespace SM.Utility
|
||||||
distance = 0.0f;
|
distance = 0.0f;
|
||||||
float tMin = 0.0f;
|
float tMin = 0.0f;
|
||||||
float tMax = 100000.0f;
|
float tMax = 100000.0f;
|
||||||
|
|
||||||
Vector3 delta = modelMatrix.Row3.Xyz - Position;
|
Vector3 delta = modelMatrix.Row3.Xyz - Position;
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
Vector3 axis = new Vector3(modelMatrix[i, 0], modelMatrix[i, 1], modelMatrix[i, 2]);
|
Vector3 axis = new Vector3(modelMatrix[i, 0], modelMatrix[i, 1], modelMatrix[i, 2]);
|
||||||
|
|
@ -35,7 +36,6 @@ namespace SM.Utility
|
||||||
|
|
||||||
if (Math.Abs(f) > 0.001f)
|
if (Math.Abs(f) > 0.001f)
|
||||||
{
|
{
|
||||||
|
|
||||||
float t1 = (e + box.Min[i]) / f;
|
float t1 = (e + box.Min[i]) / f;
|
||||||
float t2 = (e + box.Max[i]) / f;
|
float t2 = (e + box.Max[i]) / f;
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@ namespace SM.Utility
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (-e + box.Min[i] > 0.0f || -e + box.Max[i] < 0.0f)
|
if (-e + box.Min[i] > 0.0f || -e + box.Max[i] < 0.0f)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ using OpenTK;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace SM.Utility
|
namespace SM.Base.Utility
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Utilitys for rotations
|
/// Utilitys for rotations
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
namespace SM.Utility
|
namespace SM.Base.Utility
|
||||||
{
|
{
|
||||||
public class ShaderUtility
|
public class ShaderUtility
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
using System;
|
#region usings
|
||||||
|
|
||||||
namespace SM.Utility
|
using System;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace SM.Base.Utility
|
||||||
{
|
{
|
||||||
public class Util
|
public class Util
|
||||||
{
|
{
|
||||||
|
|
@ -11,6 +15,7 @@ namespace SM.Utility
|
||||||
obj.Initialization();
|
obj.Initialization();
|
||||||
obj.IsInitialized = true;
|
obj.IsInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.Activate();
|
obj.Activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,16 @@
|
||||||
using System.Collections.Generic;
|
#region usings
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics.OpenGL4;
|
using OpenTK.Graphics.OpenGL4;
|
||||||
using SM.Base.Drawing;
|
using SM.Base.Drawing;
|
||||||
using SM.Base.Scene;
|
using SM.Base.Scene;
|
||||||
|
using SM.Base.Shaders;
|
||||||
using SM.OGL.Mesh;
|
using SM.OGL.Mesh;
|
||||||
|
|
||||||
namespace SM.Base.Windows
|
#endregion
|
||||||
|
|
||||||
|
namespace SM.Base.Window
|
||||||
{
|
{
|
||||||
public struct DrawContext
|
public struct DrawContext
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
using OpenTK.Input;
|
#region usings
|
||||||
|
|
||||||
using SM.Base.Scene;
|
using SM.Base.Scene;
|
||||||
|
|
||||||
namespace SM.Base.Windows
|
#endregion
|
||||||
|
|
||||||
|
namespace SM.Base.Window
|
||||||
{
|
{
|
||||||
public struct UpdateContext
|
public struct UpdateContext
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,45 @@
|
||||||
using System;
|
#region usings
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
using SM.Base.Controls;
|
|
||||||
using SM.Base.Scene;
|
using SM.Base.Scene;
|
||||||
|
using SM.Base.Utility;
|
||||||
using SM.Base.Window.Contexts;
|
using SM.Base.Window.Contexts;
|
||||||
using SM.OGL;
|
using SM.OGL;
|
||||||
using SM.Utility;
|
|
||||||
using Mouse = SM.Base.Controls.Mouse;
|
using Mouse = SM.Base.Controls.Mouse;
|
||||||
|
|
||||||
namespace SM.Base.Windows
|
#endregion
|
||||||
|
|
||||||
|
namespace SM.Base.Window
|
||||||
{
|
{
|
||||||
public class GLWindow : GameWindow, IGenericWindow
|
public class GLWindow : GameWindow, IGenericWindow
|
||||||
{
|
{
|
||||||
private Vector2 _flagWindowSize;
|
private Vector2 _flagWindowSize;
|
||||||
private Thread _fixedUpdateThread;
|
private Thread _fixedUpdateThread;
|
||||||
|
|
||||||
|
public WindowFlags WindowFlags;
|
||||||
|
|
||||||
|
public GLWindow() : this(1280, 720, "Generic OpenGL Title", WindowFlags.Window)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
GraphicsContextFlags.Default)
|
||||||
|
{
|
||||||
|
VSync = vSync;
|
||||||
|
_flagWindowSize = new Vector2(width, height);
|
||||||
|
|
||||||
|
ChangeWindowFlag(flags);
|
||||||
|
}
|
||||||
|
|
||||||
public bool Loading { get; private set; } = true;
|
public bool Loading { get; private set; } = true;
|
||||||
public float AspectRatio { get; set; }
|
public float AspectRatio { get; set; }
|
||||||
|
|
||||||
|
|
@ -35,24 +54,22 @@ namespace SM.Base.Windows
|
||||||
public ISetup AppliedSetup { get; private set; }
|
public ISetup AppliedSetup { get; private set; }
|
||||||
public event Action<IGenericWindow> Resize;
|
public event Action<IGenericWindow> Resize;
|
||||||
public event Action<IGenericWindow> Load;
|
public event Action<IGenericWindow> Load;
|
||||||
public event Action<IGenericWindow> Loaded;
|
|
||||||
|
|
||||||
public GenericScene CurrentScene { get; private set; }
|
public GenericScene CurrentScene { get; private set; }
|
||||||
public RenderPipeline CurrentRenderPipeline { get; private set; }
|
public RenderPipeline CurrentRenderPipeline { get; private set; }
|
||||||
|
|
||||||
public WindowFlags WindowFlags;
|
|
||||||
|
|
||||||
public GLWindow() : this(1280, 720, "Generic OpenGL Title", WindowFlags.Window) {}
|
public void TriggerLoad()
|
||||||
|
|
||||||
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, GraphicsContextFlags.Default)
|
|
||||||
{
|
{
|
||||||
VSync = vSync;
|
Load?.Invoke(this);
|
||||||
_flagWindowSize = new Vector2(width, height);
|
|
||||||
|
|
||||||
ChangeWindowFlag(flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void TriggerResize()
|
||||||
|
{
|
||||||
|
Resize?.Invoke(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public event Action<IGenericWindow> Loaded;
|
||||||
|
|
||||||
protected override void OnLoad(EventArgs e)
|
protected override void OnLoad(EventArgs e)
|
||||||
{
|
{
|
||||||
WindowCode.Load(this);
|
WindowCode.Load(this);
|
||||||
|
|
@ -83,7 +100,7 @@ namespace SM.Base.Windows
|
||||||
|
|
||||||
base.OnUpdateFrame(e);
|
base.OnUpdateFrame(e);
|
||||||
|
|
||||||
WindowCode.Update(this, (float)e.Time);
|
WindowCode.Update(this, (float) e.Time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -91,7 +108,7 @@ namespace SM.Base.Windows
|
||||||
{
|
{
|
||||||
base.OnRenderFrame(e);
|
base.OnRenderFrame(e);
|
||||||
|
|
||||||
WindowCode.Render(this, (float)e.Time);
|
WindowCode.Render(this, (float) e.Time);
|
||||||
|
|
||||||
SwapBuffers();
|
SwapBuffers();
|
||||||
|
|
||||||
|
|
@ -145,10 +162,6 @@ namespace SM.Base.Windows
|
||||||
CurrentRenderPipeline = renderPipeline;
|
CurrentRenderPipeline = renderPipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TriggerLoad() => Load?.Invoke(this);
|
|
||||||
|
|
||||||
public void TriggerResize() => Resize?.Invoke(this);
|
|
||||||
|
|
||||||
public void ChangeWindowFlag(WindowFlags newFlag)
|
public void ChangeWindowFlag(WindowFlags newFlag)
|
||||||
{
|
{
|
||||||
WindowFlags = newFlag;
|
WindowFlags = newFlag;
|
||||||
|
|
@ -156,14 +169,14 @@ namespace SM.Base.Windows
|
||||||
switch (newFlag)
|
switch (newFlag)
|
||||||
{
|
{
|
||||||
case WindowFlags.Window:
|
case WindowFlags.Window:
|
||||||
Width = (int)_flagWindowSize.X;
|
Width = (int) _flagWindowSize.X;
|
||||||
Height = (int)_flagWindowSize.Y;
|
Height = (int) _flagWindowSize.Y;
|
||||||
|
|
||||||
WindowBorder = WindowBorder.Resizable;
|
WindowBorder = WindowBorder.Resizable;
|
||||||
break;
|
break;
|
||||||
case WindowFlags.BorderlessWindow:
|
case WindowFlags.BorderlessWindow:
|
||||||
WindowBorder = WindowBorder.Hidden;
|
WindowBorder = WindowBorder.Hidden;
|
||||||
|
|
||||||
X = Screen.PrimaryScreen.Bounds.Left;
|
X = Screen.PrimaryScreen.Bounds.Left;
|
||||||
Y = Screen.PrimaryScreen.Bounds.Top;
|
Y = Screen.PrimaryScreen.Bounds.Top;
|
||||||
Width = Screen.PrimaryScreen.Bounds.Width;
|
Width = Screen.PrimaryScreen.Bounds.Width;
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
using System;
|
#region usings
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using SM.Base.Controls;
|
|
||||||
using SM.Base.Scene;
|
using SM.Base.Scene;
|
||||||
using SM.OGL.Framebuffer;
|
using SM.OGL.Framebuffer;
|
||||||
|
|
||||||
namespace SM.Base.Windows
|
#endregion
|
||||||
|
|
||||||
|
namespace SM.Base.Window
|
||||||
{
|
{
|
||||||
public interface IGenericWindow : IFramebufferWindow
|
public interface IGenericWindow : IFramebufferWindow
|
||||||
{
|
{
|
||||||
|
|
@ -26,12 +29,12 @@ namespace SM.Base.Windows
|
||||||
|
|
||||||
ISetup AppliedSetup { get; }
|
ISetup AppliedSetup { get; }
|
||||||
|
|
||||||
event Action<IGenericWindow> Resize;
|
|
||||||
event Action<IGenericWindow> Load;
|
|
||||||
|
|
||||||
GenericScene CurrentScene { get; }
|
GenericScene CurrentScene { get; }
|
||||||
RenderPipeline CurrentRenderPipeline { get; }
|
RenderPipeline CurrentRenderPipeline { get; }
|
||||||
|
|
||||||
|
event Action<IGenericWindow> Resize;
|
||||||
|
event Action<IGenericWindow> Load;
|
||||||
|
|
||||||
void Update(UpdateContext context);
|
void Update(UpdateContext context);
|
||||||
|
|
||||||
void ApplySetup(ISetup setup);
|
void ApplySetup(ISetup setup);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace SM.Base.Windows
|
namespace SM.Base.Window
|
||||||
{
|
{
|
||||||
public interface ISetup
|
public interface ISetup
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,16 @@
|
||||||
using System.Collections.Generic;
|
#region usings
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using SM.Base.Drawing;
|
using SM.Base.Drawing;
|
||||||
|
using SM.Base.Shaders;
|
||||||
|
using SM.Base.Utility;
|
||||||
using SM.OGL.Framebuffer;
|
using SM.OGL.Framebuffer;
|
||||||
using SM.OGL.Texture;
|
using SM.OGL.Texture;
|
||||||
using SM.Utility;
|
|
||||||
|
|
||||||
namespace SM.Base.Windows
|
#endregion
|
||||||
|
|
||||||
|
namespace SM.Base.Window
|
||||||
{
|
{
|
||||||
public abstract class RenderPipeline : IInitializable
|
public abstract class RenderPipeline : IInitializable
|
||||||
{
|
{
|
||||||
|
|
@ -20,25 +25,8 @@ namespace SM.Base.Windows
|
||||||
|
|
||||||
public bool IsInitialized { get; set; }
|
public bool IsInitialized { get; set; }
|
||||||
|
|
||||||
internal void Render(ref DrawContext context) => RenderProcess(ref context);
|
|
||||||
|
|
||||||
protected abstract void RenderProcess(ref DrawContext context);
|
|
||||||
|
|
||||||
public virtual void Resize()
|
|
||||||
{
|
|
||||||
if (Framebuffers == null) return;
|
|
||||||
foreach(var framebuffer in Framebuffers)
|
|
||||||
framebuffer.Dispose();
|
|
||||||
|
|
||||||
Thread.Sleep(50);
|
|
||||||
|
|
||||||
foreach(var framebuffer in Framebuffers)
|
|
||||||
framebuffer.Compile();
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void Activate()
|
public virtual void Activate()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Initialization()
|
public virtual void Initialization()
|
||||||
|
|
@ -47,13 +35,34 @@ namespace SM.Base.Windows
|
||||||
DefaultShader ??= SMRenderer.DefaultMaterialShader;
|
DefaultShader ??= SMRenderer.DefaultMaterialShader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void Render(ref DrawContext context)
|
||||||
|
{
|
||||||
|
RenderProcess(ref context);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void RenderProcess(ref DrawContext context);
|
||||||
|
|
||||||
|
public virtual void Resize()
|
||||||
|
{
|
||||||
|
if (Framebuffers == null) return;
|
||||||
|
foreach (var framebuffer in Framebuffers)
|
||||||
|
framebuffer.Dispose();
|
||||||
|
|
||||||
|
Thread.Sleep(50);
|
||||||
|
|
||||||
|
foreach (var framebuffer in Framebuffers)
|
||||||
|
framebuffer.Compile();
|
||||||
|
}
|
||||||
|
|
||||||
public Framebuffer CreateWindowFramebuffer(int multisamples = 0)
|
public Framebuffer CreateWindowFramebuffer(int multisamples = 0)
|
||||||
{
|
{
|
||||||
Framebuffer framebuffer = new Framebuffer(window: ConnectedWindow);
|
Framebuffer framebuffer = new Framebuffer(ConnectedWindow);
|
||||||
framebuffer.Append("color", new ColorAttachment(0, PixelInformation.RGBA_LDR, multisamples));
|
framebuffer.Append("color", new ColorAttachment(0, PixelInformation.RGBA_LDR, multisamples));
|
||||||
|
|
||||||
RenderbufferAttachment depthAttach = RenderbufferAttachment.Depth;
|
RenderbufferAttachment depthAttach = RenderbufferAttachment.Depth;
|
||||||
depthAttach.Multisample = multisamples;
|
depthAttach.Multisample = multisamples;
|
||||||
framebuffer.AppendRenderbuffer(depthAttach);
|
framebuffer.AppendRenderbuffer(depthAttach);
|
||||||
|
|
||||||
return framebuffer;
|
return framebuffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
#region usings
|
||||||
using System.Collections.Generic;
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics.OpenGL4;
|
using OpenTK.Graphics.OpenGL4;
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
|
|
@ -9,13 +9,16 @@ using SM.Base.Drawing;
|
||||||
using SM.Base.Objects.Static;
|
using SM.Base.Objects.Static;
|
||||||
using SM.Base.PostProcess;
|
using SM.Base.PostProcess;
|
||||||
using SM.Base.Scene;
|
using SM.Base.Scene;
|
||||||
using SM.Base.ShaderExtension;
|
using SM.Base.Shaders.Extensions;
|
||||||
using SM.Base.Time;
|
using SM.Base.Time;
|
||||||
|
using SM.Base.Utility;
|
||||||
using SM.OGL;
|
using SM.OGL;
|
||||||
using SM.Utility;
|
|
||||||
using Keyboard = SM.Base.Controls.Keyboard;
|
using Keyboard = SM.Base.Controls.Keyboard;
|
||||||
|
using Mouse = SM.Base.Controls.Mouse;
|
||||||
|
|
||||||
namespace SM.Base.Windows
|
#endregion
|
||||||
|
|
||||||
|
namespace SM.Base.Window
|
||||||
{
|
{
|
||||||
internal class WindowCode
|
internal class WindowCode
|
||||||
{
|
{
|
||||||
|
|
@ -69,19 +72,16 @@ namespace SM.Base.Windows
|
||||||
internal static void Update(IGenericWindow window, float deltatime)
|
internal static void Update(IGenericWindow window, float deltatime)
|
||||||
{
|
{
|
||||||
Deltatime.UpdateDelta = deltatime;
|
Deltatime.UpdateDelta = deltatime;
|
||||||
SM.Base.Controls.Mouse.SetState();
|
Mouse.SetState();
|
||||||
Controls.Keyboard.SetStage();
|
Keyboard.SetStage();
|
||||||
var context = new UpdateContext()
|
var context = new UpdateContext
|
||||||
{
|
{
|
||||||
Window = window,
|
Window = window,
|
||||||
|
|
||||||
Scene = window.CurrentScene
|
Scene = window.CurrentScene
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Keyboard.IsDown(Key.AltLeft) && Keyboard.IsDown(Key.F4))
|
if (Keyboard.IsDown(Key.AltLeft) && Keyboard.IsDown(Key.F4)) window.Close();
|
||||||
{
|
|
||||||
window.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
Stopwatch.PerformTicks(context);
|
Stopwatch.PerformTicks(context);
|
||||||
window.CurrentScene?.Update(context);
|
window.CurrentScene?.Update(context);
|
||||||
|
|
@ -97,7 +97,7 @@ namespace SM.Base.Windows
|
||||||
GLObject.DisposeMarkedObjects();
|
GLObject.DisposeMarkedObjects();
|
||||||
|
|
||||||
Deltatime.RenderDelta = deltatime;
|
Deltatime.RenderDelta = deltatime;
|
||||||
var drawContext = new DrawContext()
|
var drawContext = new DrawContext
|
||||||
{
|
{
|
||||||
Window = window,
|
Window = window,
|
||||||
Scene = window.CurrentScene,
|
Scene = window.CurrentScene,
|
||||||
|
|
@ -110,7 +110,7 @@ namespace SM.Base.Windows
|
||||||
TextureMatrix = Matrix3.Identity,
|
TextureMatrix = Matrix3.Identity,
|
||||||
Instances = new Instance[1]
|
Instances = new Instance[1]
|
||||||
{
|
{
|
||||||
new Instance() {ModelMatrix = Matrix4.Identity, TextureMatrix = Matrix3.Identity}
|
new Instance {ModelMatrix = Matrix4.Identity, TextureMatrix = Matrix3.Identity}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
drawContext.SetCamera(window.ViewportCamera);
|
drawContext.SetCamera(window.ViewportCamera);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace SM.Base.Windows
|
namespace SM.Base.Window
|
||||||
{
|
{
|
||||||
public enum WindowFlags
|
public enum WindowFlags
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<packages>
|
<packages>
|
||||||
<package id="OpenTK" version="3.3.1" targetFramework="net452" />
|
<package id="OpenTK" version="3.3.1" targetFramework="net452" />
|
||||||
<package id="OpenTK.GLWpfControl" version="3.2.3" targetFramework="net452" />
|
<package id="OpenTK.GLWpfControl" version="3.2.3" targetFramework="net452" />
|
||||||
<package id="SharpDX" version="4.2.0" targetFramework="net452" />
|
<package id="SharpDX" version="4.2.0" targetFramework="net452" />
|
||||||
<package id="SharpDX.XInput" version="4.2.0" targetFramework="net452" />
|
<package id="SharpDX.XInput" version="4.2.0" targetFramework="net452" />
|
||||||
</packages>
|
</packages>
|
||||||
|
|
@ -38,6 +38,9 @@ namespace SM.OGL.Framebuffer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DrawBuffersEnum DrawBuffersEnum => DrawBuffersEnum.ColorAttachment0 + AttachmentID;
|
public DrawBuffersEnum DrawBuffersEnum => DrawBuffersEnum.ColorAttachment0 + AttachmentID;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true, if multisamples are above 0.
|
||||||
|
/// </summary>
|
||||||
public bool IsMultisampled => _multisamples > 0;
|
public bool IsMultisampled => _multisamples > 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ namespace SM.OGL.Framebuffer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Framebuffer : GLObject
|
public class Framebuffer : GLObject
|
||||||
{
|
{
|
||||||
protected override bool AutoCompile { get; } = true;
|
protected override bool AutoCompile { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents the screen buffer.
|
/// Represents the screen buffer.
|
||||||
|
|
@ -22,11 +22,9 @@ namespace SM.OGL.Framebuffer
|
||||||
public static readonly Framebuffer Screen = new Framebuffer
|
public static readonly Framebuffer Screen = new Framebuffer
|
||||||
{
|
{
|
||||||
_id = 0,
|
_id = 0,
|
||||||
_canBeCompiled = false
|
CanCompile = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
private bool _canBeCompiled = true;
|
|
||||||
|
|
||||||
private IFramebufferWindow _window;
|
private IFramebufferWindow _window;
|
||||||
private float _windowScale;
|
private float _windowScale;
|
||||||
|
|
||||||
|
|
@ -77,8 +75,6 @@ namespace SM.OGL.Framebuffer
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Compile()
|
public override void Compile()
|
||||||
{
|
{
|
||||||
if (!_canBeCompiled) return;
|
|
||||||
|
|
||||||
if (_window != null) Size = new Vector2(_window.Width * _windowScale, _window.Height * _windowScale);
|
if (_window != null) Size = new Vector2(_window.Width * _windowScale, _window.Height * _windowScale);
|
||||||
|
|
||||||
base.Compile();
|
base.Compile();
|
||||||
|
|
@ -181,7 +177,7 @@ namespace SM.OGL.Framebuffer
|
||||||
{
|
{
|
||||||
Framebuffer buffer = new Framebuffer()
|
Framebuffer buffer = new Framebuffer()
|
||||||
{
|
{
|
||||||
_canBeCompiled = false,
|
CanCompile = false,
|
||||||
ReportAsNotCompiled = true
|
ReportAsNotCompiled = true
|
||||||
};
|
};
|
||||||
switch (target)
|
switch (target)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
namespace SM.OGL.Framebuffer
|
namespace SM.OGL.Framebuffer
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A interface, so the framebuffer system can react to changes of windows.
|
||||||
|
/// </summary>
|
||||||
public interface IFramebufferWindow
|
public interface IFramebufferWindow
|
||||||
{
|
{
|
||||||
int Width { get; }
|
int Width { get; }
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,33 @@
|
||||||
|
|
||||||
namespace SM.OGL.Framebuffer
|
namespace SM.OGL.Framebuffer
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Describes a renderbuffer attachment.
|
||||||
|
/// </summary>
|
||||||
public struct RenderbufferAttachment
|
public struct RenderbufferAttachment
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Preset for the depthbuffer attachment.
|
||||||
|
/// </summary>
|
||||||
public static readonly RenderbufferAttachment Depth = new RenderbufferAttachment(RenderbufferStorage.Depth24Stencil8, FramebufferAttachment.DepthStencilAttachment);
|
public static readonly RenderbufferAttachment Depth = new RenderbufferAttachment(RenderbufferStorage.Depth24Stencil8, FramebufferAttachment.DepthStencilAttachment);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Storage describes the internal format for the renderbuffer.
|
||||||
|
/// </summary>
|
||||||
public RenderbufferStorage Storage;
|
public RenderbufferStorage Storage;
|
||||||
|
/// <summary>
|
||||||
|
/// FramebufferAttachment describes the attachment for the framebuffer.
|
||||||
|
/// </summary>
|
||||||
public FramebufferAttachment FramebufferAttachment;
|
public FramebufferAttachment FramebufferAttachment;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This contains the amount of multisampling for the attachment.
|
||||||
|
/// </summary>
|
||||||
public int Multisample;
|
public int Multisample;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
public RenderbufferAttachment(RenderbufferStorage storage, FramebufferAttachment framebufferAttachment, int multisample = 0)
|
public RenderbufferAttachment(RenderbufferStorage storage, FramebufferAttachment framebufferAttachment, int multisample = 0)
|
||||||
{
|
{
|
||||||
Storage = storage;
|
Storage = storage;
|
||||||
|
|
@ -18,18 +36,23 @@ namespace SM.OGL.Framebuffer
|
||||||
Multisample = multisample;
|
Multisample = multisample;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This generates the renderbuffer for the framebuffer to add.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="f">The framebuffer</param>
|
||||||
|
/// <returns>The ID of the renderbuffer.</returns>
|
||||||
public int Generate(Framebuffer f)
|
public int Generate(Framebuffer f)
|
||||||
{
|
{
|
||||||
int rbo = GL.GenRenderbuffer();
|
int rb = GL.GenRenderbuffer();
|
||||||
|
|
||||||
GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, rbo);
|
GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, rb);
|
||||||
if (Multisample != 0)
|
if (Multisample != 0)
|
||||||
GL.RenderbufferStorageMultisample(RenderbufferTarget.Renderbuffer, Multisample, Storage, (int)f.Size.X, (int)f.Size.Y);
|
GL.RenderbufferStorageMultisample(RenderbufferTarget.Renderbuffer, Multisample, Storage, (int)f.Size.X, (int)f.Size.Y);
|
||||||
else
|
else
|
||||||
GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, Storage, (int)f.Size.X, (int)f.Size.Y);
|
GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, Storage, (int)f.Size.X, (int)f.Size.Y);
|
||||||
GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0);
|
GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0);
|
||||||
|
|
||||||
return rbo;
|
return rb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Runtime.InteropServices;
|
using OpenTK.Audio;
|
||||||
using OpenTK.Graphics.OpenGL4;
|
using OpenTK.Graphics.OpenGL4;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -16,6 +15,7 @@ namespace SM.OGL
|
||||||
public abstract class GLObject
|
public abstract class GLObject
|
||||||
{
|
{
|
||||||
private static List<GLObject> _disposableObjects = new List<GLObject>();
|
private static List<GLObject> _disposableObjects = new List<GLObject>();
|
||||||
|
private string _name = "";
|
||||||
|
|
||||||
protected bool ReportAsNotCompiled;
|
protected bool ReportAsNotCompiled;
|
||||||
|
|
||||||
|
|
@ -23,17 +23,29 @@ namespace SM.OGL
|
||||||
/// Contains the OpenGL ID
|
/// Contains the OpenGL ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected int _id = -1;
|
protected int _id = -1;
|
||||||
|
|
||||||
|
protected bool CanCompile = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If true, the system will call "Compile()", when "ID" is tried to get, but the id is still -1.
|
/// If true, the system will call "Compile()", when "ID" is tried to get, but the id is still -1.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual bool AutoCompile { get; } = false;
|
protected virtual bool AutoCompile { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if the object was compiled.
|
/// Checks if the object was compiled.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool WasCompiled => _id > 0 && !ReportAsNotCompiled;
|
public bool WasCompiled => _id > 0 && !ReportAsNotCompiled;
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get => _name;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_name = value;
|
||||||
|
if (GLSystem.Debugging && WasCompiled) GL.ObjectLabel(TypeIdentifier, _id, _name.Length, _name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the id for this object.
|
/// Returns the id for this object.
|
||||||
/// <para>It will auto compile, if needed and allowed.</para>
|
/// <para>It will auto compile, if needed and allowed.</para>
|
||||||
|
|
@ -55,7 +67,21 @@ namespace SM.OGL
|
||||||
[DebuggerStepThrough]
|
[DebuggerStepThrough]
|
||||||
private void PerformCompile()
|
private void PerformCompile()
|
||||||
{
|
{
|
||||||
|
if (!CanCompile) return;
|
||||||
|
|
||||||
Compile();
|
Compile();
|
||||||
|
|
||||||
|
if (GLSystem.Debugging && string.IsNullOrEmpty(_name))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
GL.ObjectLabel(TypeIdentifier, _id, _name.Length, _name);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -85,13 +111,9 @@ namespace SM.OGL
|
||||||
Compile();
|
Compile();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public override string ToString()
|
||||||
/// Names the object for debugging.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name"></param>
|
|
||||||
public void Name(string name)
|
|
||||||
{
|
{
|
||||||
if (GLSystem.Debugging) GL.ObjectLabel(TypeIdentifier, _id, name.Length, name);
|
return $"{GetType().Name} {(string.IsNullOrEmpty(_name) ? "" : $"\"{_name}\" ")}[{_id}]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DisposeMarkedObjects()
|
public static void DisposeMarkedObjects()
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics.OpenGL;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using OpenTK.Graphics.OpenGL4;
|
using OpenTK.Graphics.OpenGL4;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -17,21 +16,8 @@ namespace SM.OGL.Mesh
|
||||||
|
|
||||||
public static int LastID { get; internal set; } = -1;
|
public static int LastID { get; internal set; } = -1;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generates the AttribDataIndex
|
|
||||||
/// </summary>
|
|
||||||
protected GenericMesh()
|
|
||||||
{
|
|
||||||
Attributes = new MeshAttributeList()
|
|
||||||
{
|
|
||||||
{0, "vertex", Vertex},
|
|
||||||
{1, "uv", UVs},
|
|
||||||
{2, "normal", Normals}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override bool AutoCompile { get; } = true;
|
protected override bool AutoCompile { get; set; } = true;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.VertexArray;
|
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.VertexArray;
|
||||||
|
|
@ -72,6 +58,19 @@ namespace SM.OGL.Mesh
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual int[] Indices { get; set; }
|
public virtual int[] Indices { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates the AttribDataIndex
|
||||||
|
/// </summary>
|
||||||
|
protected GenericMesh()
|
||||||
|
{
|
||||||
|
Attributes = new MeshAttributeList()
|
||||||
|
{
|
||||||
|
{0, "vertex", Vertex},
|
||||||
|
{1, "uv", UVs},
|
||||||
|
{2, "normal", Normals}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public void UpdateBoundingBox()
|
public void UpdateBoundingBox()
|
||||||
{
|
{
|
||||||
BoundingBox.Update(this);
|
BoundingBox.Update(this);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,13 @@
|
||||||
namespace SM.OGL.Mesh
|
namespace SM.OGL.Mesh
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a mesh that can be a line object.
|
||||||
|
/// </summary>
|
||||||
public interface ILineMesh
|
public interface ILineMesh
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The width of a line.
|
||||||
|
/// </summary>
|
||||||
float LineWidth { get; set; }
|
float LineWidth { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using OpenTK.Graphics.OpenGL;
|
|
||||||
|
|
||||||
namespace SM.OGL.Mesh
|
namespace SM.OGL.Mesh
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,10 @@ namespace SM.OGL.Mesh
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int PointerStride;
|
public int PointerStride;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The VBO gets ignored when true.
|
||||||
|
/// <para>Default: true</para>
|
||||||
|
/// </summary>
|
||||||
public bool Active = true;
|
public bool Active = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using OpenTK.Graphics.OpenGL4;
|
using OpenTK.Graphics.OpenGL4;
|
||||||
using SM.OGL.Mesh;
|
using SM.OGL.Mesh;
|
||||||
|
|
||||||
|
|
@ -15,7 +14,7 @@ namespace SM.OGL.Shaders
|
||||||
public abstract class GenericShader : GLObject
|
public abstract class GenericShader : GLObject
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override bool AutoCompile { get; } = true;
|
protected override bool AutoCompile { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains the different files for the shader.
|
/// Contains the different files for the shader.
|
||||||
|
|
@ -97,7 +96,6 @@ namespace SM.OGL.Shaders
|
||||||
|
|
||||||
ShaderFileFiles.Append(this);
|
ShaderFileFiles.Append(this);
|
||||||
GL.LinkProgram(_id);
|
GL.LinkProgram(_id);
|
||||||
Name(GetType().Name);
|
|
||||||
ShaderFileFiles.Detach(this);
|
ShaderFileFiles.Detach(this);
|
||||||
|
|
||||||
Uniforms = new UniformCollection {ParentShader = this};
|
Uniforms = new UniformCollection {ParentShader = this};
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ namespace SM.OGL.Shaders
|
||||||
for (var i = 0; i < GLSLExtensions.Count; i++) GLSLExtensions[i].Compile(shader, type);
|
for (var i = 0; i < GLSLExtensions.Count; i++) GLSLExtensions[i].Compile(shader, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
GL.DeleteShader(this);
|
GL.DeleteShader(this);
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,12 @@ namespace SM.OGL.Shaders
|
||||||
Fragment = new []{fragment};
|
Fragment = new []{fragment};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a collection with arrays of shader files.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vertex"></param>
|
||||||
|
/// <param name="fragment"></param>
|
||||||
|
/// <param name="geometry"></param>
|
||||||
public ShaderFileCollection(ShaderFile[] vertex, ShaderFile[] fragment, ShaderFile[] geometry = default)
|
public ShaderFileCollection(ShaderFile[] vertex, ShaderFile[] fragment, ShaderFile[] geometry = default)
|
||||||
{
|
{
|
||||||
Vertex = vertex;
|
Vertex = vertex;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenTK.Graphics.OpenGL;
|
|
||||||
|
|
||||||
namespace SM.OGL.Shaders
|
namespace SM.OGL.Shaders
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace SM.OGL.Shaders
|
||||||
}
|
}
|
||||||
catch (KeyNotFoundException)
|
catch (KeyNotFoundException)
|
||||||
{
|
{
|
||||||
GLCustomActions.AtWarning?.Invoke("Uniform '" + KeyString + key + "' at '" + ParentShader.GetType().Name + "' was not found. Tried to recreate it.");
|
GLCustomActions.AtWarning?.Invoke("Uniform '" + KeyString + key + "' at '" + ParentShader.ToString() + "' was not found. Tried to recreate it.");
|
||||||
var u = new Uniform(GL.GetUniformLocation(ParentShader, KeyString + key), this);
|
var u = new Uniform(GL.GetUniformLocation(ParentShader, KeyString + key), this);
|
||||||
Add(key, u);
|
Add(key, u);
|
||||||
return u;
|
return u;
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,47 @@
|
||||||
|
|
||||||
namespace SM.OGL.Texture
|
namespace SM.OGL.Texture
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Stores information how pixels are stored in textures.
|
||||||
|
/// </summary>
|
||||||
public struct PixelInformation
|
public struct PixelInformation
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// RGB without Alpha channel, Low Dynamic Range (0 - 1)
|
||||||
|
/// </summary>
|
||||||
public static PixelInformation RGB_LDR = new PixelInformation(PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.UnsignedByte);
|
public static PixelInformation RGB_LDR = new PixelInformation(PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.UnsignedByte);
|
||||||
|
/// <summary>
|
||||||
|
/// RGB without Alpha channel, High Dynamic Range (0 - n)
|
||||||
|
/// </summary>
|
||||||
public static PixelInformation RGB_HDR = new PixelInformation(PixelInternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.Float);
|
public static PixelInformation RGB_HDR = new PixelInformation(PixelInternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.Float);
|
||||||
|
/// <summary>
|
||||||
|
/// RGB with Alpha channel, Low Dynamic Range (0 - 1)
|
||||||
|
/// </summary>
|
||||||
public static PixelInformation RGBA_LDR = new PixelInformation(PixelInternalFormat.Rgba, PixelFormat.Rgba, PixelType.UnsignedByte);
|
public static PixelInformation RGBA_LDR = new PixelInformation(PixelInternalFormat.Rgba, PixelFormat.Rgba, PixelType.UnsignedByte);
|
||||||
|
/// <summary>
|
||||||
|
/// RGB with Alpha channel, High Dynamic Range (0 - n)
|
||||||
|
/// </summary>
|
||||||
public static PixelInformation RGBA_HDR = new PixelInformation(PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.Float);
|
public static PixelInformation RGBA_HDR = new PixelInformation(PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.Float);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The internal format of the pixels.
|
||||||
|
/// </summary>
|
||||||
public PixelInternalFormat InternalFormat { get; }
|
public PixelInternalFormat InternalFormat { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// The format of the pixels.
|
||||||
|
/// </summary>
|
||||||
public PixelFormat Format { get; }
|
public PixelFormat Format { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// The data type of the pixels,
|
||||||
|
/// </summary>
|
||||||
public PixelType DataType { get; }
|
public PixelType DataType { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="internalFormat"></param>
|
||||||
|
/// <param name="format"></param>
|
||||||
|
/// <param name="dataType"></param>
|
||||||
public PixelInformation(PixelInternalFormat internalFormat, PixelFormat format, PixelType dataType)
|
public PixelInformation(PixelInternalFormat internalFormat, PixelFormat format, PixelType dataType)
|
||||||
{
|
{
|
||||||
InternalFormat = internalFormat;
|
InternalFormat = internalFormat;
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,20 @@ namespace SM.OGL.Texture
|
||||||
public abstract class TextureBase : GLObject
|
public abstract class TextureBase : GLObject
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override bool AutoCompile { get; } = true;
|
protected override bool AutoCompile { get; set; } = true;
|
||||||
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Texture;
|
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Texture;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Contains the specific information of each pixel.
|
||||||
|
/// </summary>
|
||||||
public PixelInformation PixelInformation;
|
public PixelInformation PixelInformation;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The target of the texture.
|
||||||
|
/// </summary>
|
||||||
public TextureTarget Target { get; set; } = TextureTarget.Texture2D;
|
public TextureTarget Target { get; set; } = TextureTarget.Texture2D;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -44,6 +50,7 @@ namespace SM.OGL.Texture
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual int Height { get; protected set; }
|
public virtual int Height { get; protected set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
GL.DeleteTexture(_id);
|
GL.DeleteTexture(_id);
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Windows.Controls;
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using SM.Base.Controls;
|
using SM.Base.Controls;
|
||||||
using SM.Base.Drawing;
|
|
||||||
using SM.Base.Scene;
|
using SM.Base.Scene;
|
||||||
using SM.Utility;
|
|
||||||
using SM2D.Scene;
|
using SM2D.Scene;
|
||||||
using SM2D.Types;
|
using SM2D.Types;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,12 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using SM.Base;
|
|
||||||
using SM.Base.Drawing;
|
using SM.Base.Drawing;
|
||||||
using SM.Base.Objects.Static;
|
|
||||||
using SM.Base.Scene;
|
using SM.Base.Scene;
|
||||||
using SM.Base.Textures;
|
using SM.Base.Textures;
|
||||||
using SM.Base.Windows;
|
using SM.Base.Window;
|
||||||
using SM.OGL.Texture;
|
using SM.OGL.Texture;
|
||||||
using SM2D.Scene;
|
using SM2D.Scene;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,11 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using SM.Base;
|
|
||||||
using SM.Base.Drawing;
|
using SM.Base.Drawing;
|
||||||
using SM.Base.Objects;
|
using SM.Base.Shaders;
|
||||||
using SM.Base.Textures;
|
using SM.Base.Textures;
|
||||||
using SM.Base.Windows;
|
using SM.Base.Window;
|
||||||
using SM.OGL.Mesh;
|
|
||||||
using SM2D.Object;
|
using SM2D.Object;
|
||||||
using SM2D.Scene;
|
|
||||||
using SM2D.Types;
|
using SM2D.Types;
|
||||||
|
|
||||||
namespace SM2D.Drawing
|
namespace SM2D.Drawing
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using SM.Base.Drawing.Particles;
|
using SM.Base.Drawing.Particles;
|
||||||
using SM.Utility;
|
using SM.Base.Utility;
|
||||||
using SM2D.Scene;
|
|
||||||
using SM2D.Types;
|
using SM2D.Types;
|
||||||
|
|
||||||
namespace SM2D.Drawing
|
namespace SM2D.Drawing
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using SM.Base;
|
|
||||||
using SM.Base.Drawing.Text;
|
using SM.Base.Drawing.Text;
|
||||||
using SM.Base.Types;
|
using SM.Base.Types;
|
||||||
using SM.Base.Windows;
|
using SM.Base.Window;
|
||||||
using SM2D.Scene;
|
|
||||||
using SM2D.Types;
|
using SM2D.Types;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
|
||||||
using OpenTK.Graphics.OpenGL4;
|
using OpenTK.Graphics.OpenGL4;
|
||||||
using SM.Base.Objects;
|
|
||||||
using SM.OGL.Mesh;
|
using SM.OGL.Mesh;
|
||||||
|
|
||||||
namespace SM2D.Object
|
namespace SM2D.Object
|
||||||
|
|
@ -16,8 +14,6 @@ namespace SM2D.Object
|
||||||
|
|
||||||
public class PolyLine : Polygon, ILineMesh
|
public class PolyLine : Polygon, ILineMesh
|
||||||
{
|
{
|
||||||
public float LineWidth { get; set; } = 1;
|
|
||||||
|
|
||||||
public PolyLine(ICollection<Vector2> vertices, PolyLineType lineType = PolyLineType.NotConnected) : base(vertices)
|
public PolyLine(ICollection<Vector2> vertices, PolyLineType lineType = PolyLineType.NotConnected) : base(vertices)
|
||||||
{
|
{
|
||||||
UVs.Active = false;
|
UVs.Active = false;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
|
||||||
using OpenTK.Graphics.OpenGL4;
|
using OpenTK.Graphics.OpenGL4;
|
||||||
using SM.Base.Objects;
|
using SM.Base.Objects;
|
||||||
using SM.OGL.Mesh;
|
using SM.OGL.Mesh;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,5 @@
|
||||||
using System;
|
using SM.Base.Shaders;
|
||||||
using OpenTK.Graphics.OpenGL4;
|
using SM.Base.Window;
|
||||||
using SM.Base;
|
|
||||||
using SM.Base.Drawing;
|
|
||||||
using SM.Base.Windows;
|
|
||||||
using SM.OGL.Framebuffer;
|
|
||||||
using SM2D.Shader;
|
using SM2D.Shader;
|
||||||
|
|
||||||
namespace SM2D.Pipelines
|
namespace SM2D.Pipelines
|
||||||
|
|
|
||||||
|
|
@ -31,13 +31,9 @@
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="PresentationCore" />
|
|
||||||
<Reference Include="PresentationFramework" />
|
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Xaml" />
|
|
||||||
<Reference Include="WindowsBase" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Controls\Mouse2D.cs" />
|
<Compile Include="Controls\Mouse2D.cs" />
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.Serialization.Formatters;
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using SM.Base;
|
|
||||||
using SM.Base.Scene;
|
using SM.Base.Scene;
|
||||||
using SM.Base.Types;
|
using SM.Base.Types;
|
||||||
using SM.Base.Windows;
|
using SM.Base.Window;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using SM.Base;
|
|
||||||
using SM.Base.Scene;
|
using SM.Base.Scene;
|
||||||
using SM.Base.Types;
|
using SM.Base.Types;
|
||||||
using SM.Base.Windows;
|
using SM.Base.Window;
|
||||||
using SM2D.Types;
|
using SM2D.Types;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using System.Drawing.Drawing2D;
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using SM.Base;
|
|
||||||
using SM.Base.Objects.Static;
|
using SM.Base.Objects.Static;
|
||||||
using SM.Base.Scene;
|
using SM.Base.Scene;
|
||||||
using SM.Base.Windows;
|
using SM.Base.Window;
|
||||||
using SM2D.Drawing;
|
using SM2D.Drawing;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
using SM.Base.Drawing;
|
using SM.Base.Shaders;
|
||||||
using SM.Base.Windows;
|
using SM.Base.Utility;
|
||||||
|
using SM.Base.Window;
|
||||||
using SM.OGL.Shaders;
|
using SM.OGL.Shaders;
|
||||||
using SM.Utility;
|
|
||||||
|
|
||||||
namespace SM2D.Shader
|
namespace SM2D.Shader
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -11,4 +11,5 @@ layout(location = 0) out vec4 color;
|
||||||
void main() {
|
void main() {
|
||||||
color = v_Color * Tint;
|
color = v_Color * Tint;
|
||||||
if (UseTexture) color *= texture(Texture, v_TexCoords);
|
if (UseTexture) color *= texture(Texture, v_TexCoords);
|
||||||
|
color *= 1.2;
|
||||||
}
|
}
|
||||||
|
|
@ -1,13 +1,10 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Drawing.Drawing2D;
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using SM.Base.Drawing;
|
using SM.Base.Drawing;
|
||||||
using SM.Base.Scene;
|
|
||||||
using SM.Base.Textures;
|
using SM.Base.Textures;
|
||||||
using SM.Base.Types;
|
using SM.Base.Types;
|
||||||
using SM.Utility;
|
using SM.Base.Utility;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using SM.Base.Windows;
|
using SM.Base.Window;
|
||||||
|
|
||||||
namespace SM2D
|
namespace SM2D
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
using System.Drawing.Drawing2D;
|
using OpenTK;
|
||||||
using OpenTK;
|
|
||||||
using OpenTK.Graphics.OpenGL4;
|
using OpenTK.Graphics.OpenGL4;
|
||||||
using SM.Base;
|
using SM.Base;
|
||||||
using SM.Base.PostProcess;
|
using SM.Base.Window;
|
||||||
using SM.Base.Windows;
|
|
||||||
using SM2D.Scene;
|
using SM2D.Scene;
|
||||||
using SM2D.Shader;
|
using SM2D.Shader;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using OpenTK.Input;
|
|
||||||
|
|
||||||
namespace SM.Game.Controls
|
namespace SM.Game.Controls
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
using System;
|
using OpenTK.Input;
|
||||||
using System.Collections.Generic;
|
|
||||||
using OpenTK.Input;
|
|
||||||
|
|
||||||
namespace SM.Game.Controls
|
namespace SM.Game.Controls
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenTK.Input;
|
|
||||||
|
|
||||||
namespace SM.Game.Controls
|
namespace SM.Game.Controls
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
|
||||||
using OpenTK.Input;
|
|
||||||
|
|
||||||
namespace SM.Game.Controls
|
namespace SM.Game.Controls
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
// General Information about an assembly is controlled through the following
|
||||||
|
|
|
||||||
|
|
@ -42,12 +42,6 @@
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
|
||||||
<Reference Include="Microsoft.CSharp" />
|
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Net.Http" />
|
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Controls\GameController.cs" />
|
<Compile Include="Controls\GameController.cs" />
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
using System;
|
using OpenTK;
|
||||||
using OpenTK;
|
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
using SM.Base;
|
using SM.Base;
|
||||||
using SM.Base.Windows;
|
using SM.Base.Window;
|
||||||
using SM.Game.Controls;
|
using SM.Game.Controls;
|
||||||
using SM2D;
|
using SM2D;
|
||||||
using SM2D.Drawing;
|
using SM2D.Drawing;
|
||||||
|
|
@ -58,7 +57,7 @@ namespace SM_TEST
|
||||||
DrawText text = new DrawText(font, "Test Text");
|
DrawText text = new DrawText(font, "Test Text");
|
||||||
text.Transform.Position.Set(50, 0);
|
text.Transform.Position.Set(50, 0);
|
||||||
text.Transform.Size.Set(2);
|
text.Transform.Size.Set(2);
|
||||||
scene.Objects.Add(text);
|
scene.HUD.Add(text);
|
||||||
|
|
||||||
//particles.Trigger();
|
//particles.Trigger();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
// General Information about an assembly is controlled through the following
|
||||||
|
|
|
||||||
|
|
@ -45,12 +45,6 @@
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
|
||||||
<Reference Include="Microsoft.CSharp" />
|
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Net.Http" />
|
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue