Added missing summeries #1
This commit is contained in:
parent
03d99ea28e
commit
8665b5b709
104 changed files with 1165 additions and 821 deletions
|
|
@ -1,18 +1,24 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Forms;
|
||||
using OpenTK.Input;
|
||||
using SharpDX.Win32;
|
||||
|
||||
#endregion
|
||||
|
||||
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 List<Key> _lastPressedKeys = new List<Key>();
|
||||
|
||||
/// <summary>
|
||||
/// True, when ANY key pressed.
|
||||
/// </summary>
|
||||
public static bool IsAnyKeyPressed => _keyboardState?.IsAnyKeyDown == true;
|
||||
|
||||
|
||||
|
|
@ -23,18 +29,53 @@ namespace SM.Base.Controls
|
|||
_lastPressedKeys = new List<Key>();
|
||||
|
||||
foreach (object o in Enum.GetValues(typeof(Key)))
|
||||
{
|
||||
if (_keyboardState.Value[(Key)o]) _lastPressedKeys.Add((Key)o);
|
||||
}
|
||||
if (_keyboardState.Value[(Key) o])
|
||||
_lastPressedKeys.Add((Key) o);
|
||||
}
|
||||
|
||||
_keyboardState = OpenTK.Input.Keyboard.GetState();
|
||||
}
|
||||
|
||||
public static bool IsDown(Key key, bool once = false) => _keyboardState?[key] == true && !(once && _lastPressedKeys.Contains(key));
|
||||
public static bool WasDown(Key key) => _keyboardState?[key] == false && _lastPressedKeys.Contains(key);
|
||||
public static bool IsUp(Key key, bool once = false) => _keyboardState?[key] == false && !(once && !_lastPressedKeys.Contains(key));
|
||||
/// <summary>
|
||||
/// Checks if a key is down.
|
||||
/// </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)
|
||||
{
|
||||
if (startIndex > endIndex)
|
||||
|
|
@ -51,19 +92,42 @@ namespace SM.Base.Controls
|
|||
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)
|
||||
{
|
||||
foreach (Key key in keys)
|
||||
{
|
||||
if (IsDown(key, once)) return true;
|
||||
}
|
||||
if (IsDown(key, once))
|
||||
return true;
|
||||
|
||||
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)
|
||||
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++)
|
||||
{
|
||||
int actualIndex = i + startIndex;
|
||||
Key key = (Key)actualIndex;
|
||||
Key key = (Key) actualIndex;
|
||||
if (IsDown(key, once))
|
||||
{
|
||||
keys.Add(key);
|
||||
success = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pressedKeys = keys.ToArray();
|
||||
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)
|
||||
{
|
||||
List<Key> pressedKey = new List<Key>();
|
||||
bool success = false;
|
||||
|
||||
foreach (Key key in keys)
|
||||
{
|
||||
if (IsDown(key, once))
|
||||
{
|
||||
pressedKey.Add(key);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
pressedKeys = pressedKey.ToArray();
|
||||
return success;
|
||||
|
|
|
|||
|
|
@ -2,10 +2,9 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Documents;
|
||||
using OpenTK;
|
||||
using OpenTK.Input;
|
||||
using SM.Base.Windows;
|
||||
using SM.Base.Window;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -14,7 +13,6 @@ namespace SM.Base.Controls
|
|||
/// <summary>
|
||||
/// Mouse controller
|
||||
/// </summary>
|
||||
/// <typeparam name="TWindow">The type of window this controller is connected to.</typeparam>
|
||||
public class Mouse
|
||||
{
|
||||
internal static MouseState? _mouseState;
|
||||
|
|
@ -37,7 +35,7 @@ namespace SM.Base.Controls
|
|||
internal static void MouseMoveEvent(MouseMoveEventArgs mmea, IGenericWindow window)
|
||||
{
|
||||
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()
|
||||
|
|
@ -47,19 +45,21 @@ namespace SM.Base.Controls
|
|||
_lastButtonsPressed = new List<MouseButton>();
|
||||
|
||||
foreach (object o in Enum.GetValues(typeof(MouseButton)))
|
||||
{
|
||||
if (_mouseState.Value[(MouseButton)o]) _lastButtonsPressed.Add((MouseButton)o);
|
||||
}
|
||||
if (_mouseState.Value[(MouseButton) o])
|
||||
_lastButtonsPressed.Add((MouseButton) o);
|
||||
}
|
||||
|
||||
_mouseState = OpenTK.Input.Mouse.GetState();
|
||||
|
||||
}
|
||||
|
||||
public static bool IsDown(MouseButton button, bool once = false) => _mouseState?[button] == true && !(once && _lastButtonsPressed.Contains(button));
|
||||
|
||||
public static bool IsUp(MouseButton button, bool once = false) =>
|
||||
_mouseState?[button] == false && !(once && !_lastButtonsPressed.Contains(button));
|
||||
public static bool IsDown(MouseButton button, bool once = false)
|
||||
{
|
||||
return _mouseState?[button] == true && !(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
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenTK.Graphics.ES11;
|
||||
using SM.Base;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.Windows;
|
||||
using SM.Base.Window;
|
||||
using SM.OGL.Mesh;
|
||||
using PrimitiveType = OpenTK.Graphics.OpenGL4.PrimitiveType;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -22,15 +20,27 @@ namespace SM.Base.Drawing
|
|||
/// </summary>
|
||||
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>
|
||||
/// The mesh it should use.
|
||||
/// </summary>
|
||||
public GenericMesh Mesh { get; set; } = SMRenderer.DefaultMesh;
|
||||
|
||||
public ShaderArguments ShaderArguments => Material.ShaderArguments;
|
||||
public TextureTransformation TextureTransform = new TextureTransformation();
|
||||
|
||||
/// <inheritdoc />
|
||||
public object Parent { get; set; }
|
||||
|
||||
|
|
@ -40,12 +50,11 @@ namespace SM.Base.Drawing
|
|||
/// <inheritdoc />
|
||||
public ICollection<string> Flags { get; set; }
|
||||
|
||||
public PrimitiveType? ForcedMeshType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// This value determents if the object should draw something.
|
||||
/// </summary>
|
||||
public bool Active { get; set; } = true;
|
||||
|
||||
public bool RenderActive { get; set; } = true;
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
|||
|
|
@ -12,12 +12,18 @@ namespace SM.Base.Drawing
|
|||
public abstract class GenericTransformation
|
||||
{
|
||||
/// <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>
|
||||
public bool Ignore = false;
|
||||
|
||||
/// <summary>
|
||||
/// The last matrix that was used to calculate the real world matrix.
|
||||
/// </summary>
|
||||
public Matrix4 LastMaster { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// The transformation in world space.
|
||||
/// </summary>
|
||||
public Matrix4 InWorldSpace => MergeMatrix(LastMaster);
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ namespace SM.Base.Drawing
|
|||
/// </summary>
|
||||
public Matrix4 ModelMatrix = Matrix4.Identity;
|
||||
|
||||
/// <summary>
|
||||
/// The Texture matrix
|
||||
/// </summary>
|
||||
public Matrix3 TextureMatrix = Matrix3.Identity;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#region usings
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenTK.Graphics;
|
||||
using SM.Base.Shaders;
|
||||
using SM.OGL.Texture;
|
||||
|
||||
#endregion
|
||||
|
|
@ -13,6 +13,8 @@ namespace SM.Base.Drawing
|
|||
/// </summary>
|
||||
public class Material
|
||||
{
|
||||
public bool Blending = false;
|
||||
|
||||
/// <summary>
|
||||
/// A custom shader, that is used to draw this material.
|
||||
/// </summary>
|
||||
|
|
@ -28,8 +30,9 @@ namespace SM.Base.Drawing
|
|||
/// </summary>
|
||||
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 bool Blending = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,8 @@
|
|||
using SM.Base.Time;
|
||||
#region usings
|
||||
|
||||
using SM.Base.Time;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Drawing.Particles
|
||||
{
|
||||
|
|
@ -8,11 +12,12 @@ namespace SM.Base.Drawing.Particles
|
|||
public struct ParticleContext
|
||||
{
|
||||
/// <summary>
|
||||
/// The Timer of the particles
|
||||
/// The Timer of the particles
|
||||
/// </summary>
|
||||
public Timer Timer;
|
||||
|
||||
/// <summary>
|
||||
/// The current speed of the particles.
|
||||
/// The current speed of the particles.
|
||||
/// </summary>
|
||||
public float Speed;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,42 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenTK;
|
||||
using SM.Base;
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.Time;
|
||||
using SM.Base.Types;
|
||||
using SM.Base.Windows;
|
||||
using SM.OGL.Shaders;
|
||||
using SM.Base.Window;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Drawing.Particles
|
||||
{
|
||||
/// <summary>
|
||||
/// The (drawing) basis for particles
|
||||
/// The (drawing) basis for particles
|
||||
/// </summary>
|
||||
public abstract class ParticleDrawingBasis<TTransform, TDirection> : DrawingBasis<TTransform>, IScriptable
|
||||
where TTransform : GenericTransformation, new()
|
||||
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>
|
||||
/// This contains all important information for each particle.
|
||||
/// </summary>
|
||||
protected ParticleStruct<TDirection>[] particleStructs;
|
||||
/// <summary>
|
||||
/// This contains the different instances for the particles.
|
||||
/// </summary>
|
||||
protected List<Instance> instances;
|
||||
|
||||
/// <summary>
|
||||
/// The stopwatch of the particles.
|
||||
|
|
@ -33,13 +44,13 @@ namespace SM.Base.Drawing.Particles
|
|||
protected Timer timer;
|
||||
|
||||
/// <summary>
|
||||
/// The amount of particles
|
||||
/// Sets up the timer.
|
||||
/// </summary>
|
||||
public int Amount = 32;
|
||||
/// <summary>
|
||||
/// The maximum speed of the particles
|
||||
/// </summary>
|
||||
public float MaxSpeed = 1;
|
||||
/// <param name="duration">Duration how long the particles should live</param>
|
||||
protected ParticleDrawingBasis(TimeSpan duration)
|
||||
{
|
||||
timer = new Timer(duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/Sets the state of pausing.
|
||||
|
|
@ -55,13 +66,25 @@ namespace SM.Base.Drawing.Particles
|
|||
/// </summary>
|
||||
public abstract Func<TDirection, ParticleContext, TDirection> MovementCalculation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets up the timer.
|
||||
/// </summary>
|
||||
/// <param name="duration">Duration how long the particles should live</param>
|
||||
protected ParticleDrawingBasis(TimeSpan duration)
|
||||
/// <inheritdoc />
|
||||
public bool UpdateActive { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
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>
|
||||
|
|
@ -74,30 +97,11 @@ namespace SM.Base.Drawing.Particles
|
|||
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 />
|
||||
protected override void DrawContext(ref DrawContext context)
|
||||
{
|
||||
if (!timer.Active) return;
|
||||
|
||||
|
||||
base.DrawContext(ref context);
|
||||
|
||||
context.Instances = instances;
|
||||
|
|
@ -124,7 +128,7 @@ namespace SM.Base.Drawing.Particles
|
|||
/// Creates a particle.
|
||||
/// </summary>
|
||||
protected abstract ParticleStruct<TDirection> CreateObject(int index);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Generates the desired matrix for drawing.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
using OpenTK;
|
||||
#region usings
|
||||
|
||||
using OpenTK;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Drawing.Particles
|
||||
{
|
||||
|
|
@ -10,10 +14,17 @@ namespace SM.Base.Drawing.Particles
|
|||
/// <summary>
|
||||
/// Default movement for 2D.
|
||||
/// </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>
|
||||
/// Default movement for 3D.
|
||||
/// </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;
|
||||
using SM.Base.Types;
|
||||
#region usings
|
||||
|
||||
using OpenTK;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Drawing.Particles
|
||||
{
|
||||
|
|
@ -13,10 +16,12 @@ namespace SM.Base.Drawing.Particles
|
|||
/// A direction, that the particle should travel.
|
||||
/// </summary>
|
||||
public TDirection Direction;
|
||||
|
||||
/// <summary>
|
||||
/// A matrix to store rotation and scale.
|
||||
/// </summary>
|
||||
public Matrix4 Matrix;
|
||||
|
||||
/// <summary>
|
||||
/// Speeeeeeeeeed
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -1,13 +1,26 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Drawing
|
||||
{
|
||||
/// <summary>
|
||||
/// A custom dictionary, with a few useful methods.
|
||||
/// </summary>
|
||||
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)
|
||||
{
|
||||
return ContainsKey(name) ? (TType)this[name] : defaultValue;
|
||||
return ContainsKey(name) ? (TType) this[name] : defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,8 +32,6 @@ namespace SM.Base.Drawing.Text
|
|||
/// </summary>
|
||||
public float FontSize = 12;
|
||||
|
||||
public float Spacing = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The font style.
|
||||
/// <para>Default: <see cref="System.Drawing.FontStyle.Regular" /></para>
|
||||
|
|
@ -45,6 +43,11 @@ namespace SM.Base.Drawing.Text
|
|||
/// </summary>
|
||||
public Dictionary<char, CharParameter> Positions = new Dictionary<char, CharParameter>();
|
||||
|
||||
/// <summary>
|
||||
/// Allows a font wide spacing option.
|
||||
/// </summary>
|
||||
public float Spacing = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Generates a font from a font family from the specified path.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@
|
|||
using System;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using SM.Base;
|
||||
using SM.Base.Windows;
|
||||
using SM.Base.Window;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -27,33 +26,34 @@ namespace SM.Base.Drawing.Text
|
|||
/// </summary>
|
||||
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>
|
||||
/// The spacing between numbers.
|
||||
/// <para>Default: 1</para>
|
||||
/// </summary>
|
||||
public float Spacing = 1;
|
||||
|
||||
public float ActualSpacing => Spacing * Font.Spacing;
|
||||
|
||||
public float Width;
|
||||
public float Height;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a text object with a font.
|
||||
/// Calculates the actual spacing for the object.
|
||||
/// </summary>
|
||||
/// <param name="font">The font.</param>
|
||||
protected TextDrawingBasis(Font font)
|
||||
{
|
||||
Material.Texture = font;
|
||||
Material.Blending = true;
|
||||
}
|
||||
public float ActualSpacing => Spacing * Font.Spacing;
|
||||
|
||||
/// <summary>
|
||||
/// The font.
|
||||
/// </summary>
|
||||
public Font Font
|
||||
{
|
||||
get => (Font) Material.Texture;
|
||||
get => (Font)Material.Texture;
|
||||
set
|
||||
{
|
||||
Material.Texture = value;
|
||||
|
|
@ -83,6 +83,16 @@ namespace SM.Base.Drawing.Text
|
|||
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 />
|
||||
protected override void DrawContext(ref DrawContext context)
|
||||
|
|
@ -137,7 +147,8 @@ namespace SM.Base.Drawing.Text
|
|||
_instances[i] = new Instance
|
||||
{
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -1,20 +1,46 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
using OpenTK;
|
||||
using SM.Base.Types;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Drawing
|
||||
{
|
||||
/// <summary>
|
||||
/// Stores transformations for the textures.
|
||||
/// </summary>
|
||||
public class TextureTransformation
|
||||
{
|
||||
/// <summary>
|
||||
/// The offset from the origin.
|
||||
/// </summary>
|
||||
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);
|
||||
/// <summary>
|
||||
/// The scale of the texture.
|
||||
/// </summary>
|
||||
public CVector2 Scale = new CVector2(1);
|
||||
|
||||
/// <summary>
|
||||
/// Get the texture matrix.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Matrix3 GetMatrix()
|
||||
{
|
||||
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)
|
||||
{
|
||||
float radians = MathHelper.DegreesToRadians(rotation);
|
||||
|
|
|
|||
|
|
@ -1,17 +1,22 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.OGL.Mesh;
|
||||
|
||||
#endregion
|
||||
|
||||
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)
|
||||
{
|
||||
Attributes["vertex"] = Vertex = new VBO();
|
||||
|
||||
foreach (string attribute in enabledAttibute)
|
||||
{
|
||||
switch (attribute)
|
||||
{
|
||||
case "uv":
|
||||
|
|
@ -24,9 +29,6 @@ namespace SM.Base.Objects
|
|||
Attributes["color"] = Color = new VBO(pointerSize: 4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float LineWidth { get; set; } = 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -7,16 +7,13 @@ using SM.OGL.Mesh;
|
|||
|
||||
namespace SM.Base.Objects
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <inheritdoc cref="GenericMesh" />
|
||||
public class Mesh : GenericMesh, ILineMesh
|
||||
{
|
||||
|
||||
public float LineWidth { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// While initializing, it will add the <see cref="Color" /> to the data index.
|
||||
/// </summary>
|
||||
public Mesh(PrimitiveType type) : base()
|
||||
public Mesh(PrimitiveType type)
|
||||
{
|
||||
PrimitiveType = type;
|
||||
Attributes.Add(3, "color", Color);
|
||||
|
|
@ -27,5 +24,7 @@ namespace SM.Base.Objects
|
|||
/// </summary>
|
||||
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 SM.OGL.Mesh;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Objects.Static
|
||||
{
|
||||
/// <summary>
|
||||
/// An AxisHelper-Model
|
||||
/// <para>White: -X, -Y, -Z</para>
|
||||
/// <para>Red: +X </para>
|
||||
/// <para>Green: +Y </para>
|
||||
/// <para>Blue: +Z </para>
|
||||
/// <para>White: -X, -Y, -Z</para>
|
||||
/// <para>Red: +X </para>
|
||||
/// <para>Green: +Y </para>
|
||||
/// <para>Blue: +Z </para>
|
||||
/// </summary>
|
||||
public class AxisHelper : Mesh
|
||||
{
|
||||
|
|
@ -18,28 +22,30 @@ namespace SM.Base.Objects.Static
|
|||
/// </summary>
|
||||
public static AxisHelper Object = new AxisHelper();
|
||||
|
||||
private AxisHelper() : base(PrimitiveType.Lines) {}
|
||||
private AxisHelper() : base(PrimitiveType.Lines)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override VBO Vertex { get; protected set; } = new VBO()
|
||||
public override VBO Vertex { get; protected set; } = new VBO
|
||||
{
|
||||
{0, 0, 0},
|
||||
{.5f, 0, 0},
|
||||
{0, 0, 0},
|
||||
{0, .5f, 0},
|
||||
{0, 0, -.5f},
|
||||
{0, 0, .5f},
|
||||
{0, 0, .5f}
|
||||
};
|
||||
|
||||
/// <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.Red},
|
||||
{Color4.White},
|
||||
{Color4.Green},
|
||||
{Color4.White},
|
||||
{Color4.DarkBlue},
|
||||
Color4.White,
|
||||
Color4.Red,
|
||||
Color4.White,
|
||||
Color4.Green,
|
||||
Color4.White,
|
||||
Color4.DarkBlue
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +1,58 @@
|
|||
using System.ComponentModel;
|
||||
#region usings
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.Base;
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.PostProcess;
|
||||
using SM.Base.Windows;
|
||||
using SM.Base.Utility;
|
||||
using SM.Base.Window;
|
||||
using SM.OGL.Framebuffer;
|
||||
using SM.OGL.Texture;
|
||||
using SM.Utility;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.PostEffects
|
||||
{
|
||||
public class BloomEffect : PostProcessEffect
|
||||
{
|
||||
private static BezierCurve _defaultCurve = new BezierCurve(Vector2.UnitY, new Vector2(0.32f, 1), new Vector2(0.432f, 0), new Vector2(1,0));
|
||||
|
||||
private const float _defaultTextureScale = .75f;
|
||||
|
||||
private float _textureScale = .75f;
|
||||
private static readonly BezierCurve _defaultCurve = new BezierCurve(Vector2.UnitY, new Vector2(0.32f, 1),
|
||||
new Vector2(0.432f, 0), new Vector2(1, 0));
|
||||
|
||||
private Framebuffer _bloomBuffer1;
|
||||
private Framebuffer _bloomBuffer2;
|
||||
|
||||
private ColorAttachment _xBuffer;
|
||||
private ColorAttachment _yBuffer;
|
||||
private readonly bool _hdr;
|
||||
|
||||
private PostProcessShader _shader = new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath+".bloom_blur.glsl"));
|
||||
private PostProcessShader _mergeShader = new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath+".bloom_merge_vert.glsl"), AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath+".bloom_merge.glsl"));
|
||||
private readonly PostProcessShader _mergeShader = new PostProcessShader(
|
||||
AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom_merge_vert.glsl"),
|
||||
AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom_merge.glsl"));
|
||||
|
||||
private readonly PostProcessShader _shader =
|
||||
new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom_blur.glsl"));
|
||||
|
||||
private bool _hdr;
|
||||
private Framebuffer _source;
|
||||
|
||||
private BezierCurve _weightCurve ;
|
||||
private readonly float _textureScale = .75f;
|
||||
|
||||
private BezierCurve _weightCurve;
|
||||
private float[] _weights;
|
||||
|
||||
public int Iterations = 1;
|
||||
public float Threshold = .8f;
|
||||
public float Power = 1;
|
||||
|
||||
public bool Enable = true;
|
||||
|
||||
public float MinAmount = 0;
|
||||
public float MaxAmount = 1;
|
||||
private ColorAttachment _xBuffer;
|
||||
private ColorAttachment _yBuffer;
|
||||
public TextureBase AmountMap;
|
||||
public TextureTransformation AmountTransform = new TextureTransformation();
|
||||
|
||||
public BezierCurve WeightCurve
|
||||
{
|
||||
get => _weightCurve;
|
||||
set
|
||||
{
|
||||
_weightCurve = value;
|
||||
UpdateWeights();
|
||||
}
|
||||
}
|
||||
|
||||
public bool Enable = true;
|
||||
|
||||
public int Iterations = 1;
|
||||
public float MaxAmount = 1;
|
||||
|
||||
public float MinAmount = 0;
|
||||
public float Power = 1;
|
||||
public float Threshold = .8f;
|
||||
|
||||
public int WeightCurvePickAmount = 4;
|
||||
|
||||
|
||||
|
|
@ -67,18 +65,25 @@ namespace SM.Base.PostEffects
|
|||
WeightCurve = _defaultCurve;
|
||||
}
|
||||
|
||||
public BezierCurve WeightCurve
|
||||
{
|
||||
get => _weightCurve;
|
||||
set
|
||||
{
|
||||
_weightCurve = value;
|
||||
UpdateWeights();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void UpdateWeights()
|
||||
{
|
||||
_weights = new float[WeightCurvePickAmount];
|
||||
|
||||
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()
|
||||
{
|
||||
|
|
@ -86,10 +91,16 @@ namespace SM.Base.PostEffects
|
|||
|
||||
_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.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.Compile();
|
||||
|
||||
|
|
@ -101,34 +112,36 @@ namespace SM.Base.PostEffects
|
|||
{
|
||||
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();
|
||||
bool first = true, hoz = true;
|
||||
int iter = Iterations * 2;
|
||||
for (int i = 0; i < iter; i++)
|
||||
{
|
||||
(hoz ? _bloomBuffer1 : _bloomBuffer2).Activate();
|
||||
|
||||
|
||||
_shader.Draw(collection =>
|
||||
{
|
||||
collection["renderedTexture"].SetTexture(first ? _source.ColorAttachments["color"] : (hoz ? _yBuffer : _xBuffer));
|
||||
collection["renderedTexture"]
|
||||
.SetTexture(first ? _source.ColorAttachments["color"] : hoz ? _yBuffer : _xBuffer);
|
||||
collection["RenderScale"].SetUniform1(_textureScale);
|
||||
|
||||
collection["First"].SetUniform1(first);
|
||||
collection["Threshold"].SetUniform1(Threshold);
|
||||
|
||||
|
||||
collection["Horizontal"].SetUniform1(hoz);
|
||||
|
||||
|
||||
collection["Weights"].SetUniform1(_weights);
|
||||
collection["WeightCount"].SetUniform1(WeightCurvePickAmount);
|
||||
collection["Power"].SetUniform1(Power);
|
||||
});
|
||||
|
||||
|
||||
hoz = !hoz;
|
||||
if (first) first = false;
|
||||
}
|
||||
|
||||
|
||||
GL.Viewport(Pipeline.ConnectedWindow.ClientRectangle);
|
||||
target.Activate();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,54 @@
|
|||
using System.Windows.Controls;
|
||||
#region usings
|
||||
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.Base.PostProcess;
|
||||
using SM.Base.Windows;
|
||||
using SM.Base.Utility;
|
||||
using SM.OGL.Framebuffer;
|
||||
using SM.Utility;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.PostEffects
|
||||
{
|
||||
public class PostProcessFinals
|
||||
/// <summary>
|
||||
/// This class has some utility for render pipelines
|
||||
/// </summary>
|
||||
public static 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"));
|
||||
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, BlitFramebufferFilter.Nearest);
|
||||
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);
|
||||
|
|
@ -34,6 +57,10 @@ namespace SM.Base.PostEffects
|
|||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This applys gamma
|
||||
/// </summary>
|
||||
/// <param name="attachment"></param>
|
||||
public static void FinalizeGamma(ColorAttachment attachment)
|
||||
{
|
||||
_gammaShader.Draw(u =>
|
||||
|
|
|
|||
|
|
@ -1,19 +1,15 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#region usings
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.Base;
|
||||
using SM.Base.Objects.Static;
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.Windows;
|
||||
using SM.OGL.Framebuffer;
|
||||
using SM.OGL.Shaders;
|
||||
using SM.Base.Window;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.PostProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// Basis for a post process effect
|
||||
/// Basis for a post process effect
|
||||
/// </summary>
|
||||
public abstract class PostProcessEffect
|
||||
{
|
||||
|
|
@ -22,7 +18,7 @@ namespace SM.Base.PostProcess
|
|||
protected RenderPipeline Pipeline;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the effect.
|
||||
/// Initialize the effect.
|
||||
/// </summary>
|
||||
/// <param name="pipeline"></param>
|
||||
public void Initilize(RenderPipeline pipeline)
|
||||
|
|
@ -30,24 +26,25 @@ namespace SM.Base.PostProcess
|
|||
Pipeline = pipeline;
|
||||
InitProcess();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method, to initialize the shader.
|
||||
/// </summary>
|
||||
protected virtual void InitProcess() {}
|
||||
|
||||
|
||||
/// <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>
|
||||
public abstract void Draw(DrawContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Event, when the scene changed.
|
||||
/// Event, when the scene changed.
|
||||
/// </summary>
|
||||
public virtual void SceneChanged(GenericScene scene)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,13 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.Base.Objects.Static;
|
||||
using SM.OGL.Framebuffer;
|
||||
using SM.Base.Utility;
|
||||
using SM.OGL.Shaders;
|
||||
using SM.Utility;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.PostProcess
|
||||
{
|
||||
|
|
@ -13,8 +16,12 @@ namespace SM.Base.PostProcess
|
|||
/// </summary>
|
||||
public class PostProcessShader : GenericShader
|
||||
{
|
||||
private static readonly ShaderFile _fragExtensions = 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 ShaderFile _fragExtensions =
|
||||
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 =
|
||||
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.
|
||||
/// </summary>
|
||||
public PostProcessShader(string fragment) : this(_normalVertex,
|
||||
new ShaderFile(fragment))
|
||||
{ }
|
||||
new ShaderFile(fragment))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the shader with an vertex extension and custom fragment.
|
||||
|
|
@ -32,9 +40,10 @@ namespace SM.Base.PostProcess
|
|||
/// <param name="fragment"></param>
|
||||
public PostProcessShader(string vertexExt, string fragment) : this(new ShaderFile(_normalVertexWithExt)
|
||||
{
|
||||
GLSLExtensions = new List<ShaderFile>() { new ShaderFile(vertexExt) }
|
||||
}, new ShaderFile(fragment))
|
||||
{ }
|
||||
GLSLExtensions = new List<ShaderFile> {new ShaderFile(vertexExt)}
|
||||
}, new ShaderFile(fragment))
|
||||
{
|
||||
}
|
||||
|
||||
private PostProcessShader(ShaderFile vertex, ShaderFile fragment) : base(
|
||||
new ShaderFileCollection(vertex, fragment))
|
||||
|
|
@ -43,7 +52,7 @@ namespace SM.Base.PostProcess
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws the shader with special uniforms.
|
||||
/// Draws the shader with special uniforms.
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <param name="setUniformAction"></param>
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@
|
|||
<HintPath>..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<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>
|
||||
</Reference>
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
#region usings
|
||||
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.Drawing.Text;
|
||||
using SM.Base.Objects.Static;
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.Windows;
|
||||
using SM.Base.Shaders;
|
||||
using SM.Base.Utility;
|
||||
using SM.Base.Window;
|
||||
using SM.OGL.Mesh;
|
||||
using SM.OGL.Shaders;
|
||||
using SM.Utility;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#region usings
|
||||
|
||||
using OpenTK;
|
||||
using SM.Base.Windows;
|
||||
using SM.Base.Window;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -12,6 +12,11 @@ namespace SM.Base.Scene
|
|||
/// </summary>
|
||||
public abstract class GenericCamera
|
||||
{
|
||||
/// <summary>
|
||||
/// Exposure defines the exposure to the Scene.
|
||||
/// </summary>
|
||||
public float Exposure = 1;
|
||||
|
||||
/// <summary>
|
||||
/// This defines what is up. (Normalized)
|
||||
/// <para>Default: <see cref="Vector3.UnitY" /></para>
|
||||
|
|
@ -34,11 +39,6 @@ namespace SM.Base.Scene
|
|||
/// </summary>
|
||||
public abstract bool Orthographic { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Exposure defines the exposure to the Scene.
|
||||
/// </summary>
|
||||
public float Exposure = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the view matrix.
|
||||
/// </summary>
|
||||
|
|
@ -46,10 +46,7 @@ namespace SM.Base.Scene
|
|||
internal void CalculateViewMatrix(IGenericWindow window)
|
||||
{
|
||||
View = ViewCalculation(window);
|
||||
if (WorldCalculation(window, out Matrix4 world))
|
||||
{
|
||||
World = world;
|
||||
}
|
||||
if (WorldCalculation(window, out Matrix4 world)) World = world;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -61,6 +58,12 @@ namespace SM.Base.Scene
|
|||
/// </returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,10 +2,8 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using OpenTK;
|
||||
using SM.Base;
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.Windows;
|
||||
using SM.Base.Window;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -16,12 +14,17 @@ namespace SM.Base.Scene
|
|||
/// </summary>
|
||||
public abstract class GenericItemCollection : List<IShowItem>, IShowItem, IShowCollection, IScriptable
|
||||
{
|
||||
private List<IScriptable> _scriptableObjects = new List<IScriptable>();
|
||||
private readonly List<IScriptable> _scriptableObjects = new List<IScriptable>();
|
||||
|
||||
/// <summary>
|
||||
/// Currently active script objects.
|
||||
/// </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 />
|
||||
public List<IShowItem> Objects => this;
|
||||
|
||||
|
|
@ -32,23 +35,13 @@ namespace SM.Base.Scene
|
|||
public string Name { get; set; } = "Unnamed Item Collection";
|
||||
|
||||
/// <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 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++)
|
||||
{
|
||||
if (!_scriptableObjects[i].Active || !_scriptableObjects[i].UpdateActive) continue;
|
||||
_scriptableObjects[i].Update(context);
|
||||
}
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public bool RenderActive { get; set; } = true;
|
||||
|
||||
/// <inheritdoc cref="IShowCollection.Draw" />
|
||||
public virtual void Draw(DrawContext context)
|
||||
|
|
@ -62,6 +55,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 />
|
||||
public virtual void OnAdded(object sender)
|
||||
{
|
||||
|
|
@ -75,7 +80,7 @@ namespace SM.Base.Scene
|
|||
/// <summary>
|
||||
/// Adds a item to the draw and the script collection, when applicable.
|
||||
/// </summary>
|
||||
public new void Add(params IShowItem[] items)
|
||||
public void Add(params IShowItem[] items)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
|
|
@ -87,7 +92,7 @@ namespace SM.Base.Scene
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the object to the collection.
|
||||
/// Adds the object to the collection.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public void AddObject(IShowItem item)
|
||||
|
|
@ -96,8 +101,9 @@ namespace SM.Base.Scene
|
|||
item.Parent = this;
|
||||
item.OnAdded(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the script to the collection.
|
||||
/// Adds the script to the collection.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public void AddScript(IScriptable item)
|
||||
|
|
@ -105,7 +111,7 @@ namespace SM.Base.Scene
|
|||
_scriptableObjects.Add(item);
|
||||
}
|
||||
|
||||
public new void Remove(params IShowItem[] items)
|
||||
public void Remove(params IShowItem[] items)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
|
|
@ -117,7 +123,7 @@ namespace SM.Base.Scene
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the object from the draw collection.
|
||||
/// Remove the object from the draw collection.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public void RemoveObject(IShowItem item)
|
||||
|
|
@ -128,7 +134,7 @@ namespace SM.Base.Scene
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the object from the script collection.
|
||||
/// Remove the object from the script collection.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public void RemoveScript(IScriptable item)
|
||||
|
|
@ -139,7 +145,7 @@ namespace SM.Base.Scene
|
|||
public ICollection<IShowItem> GetAllItems(bool includeCollections = false)
|
||||
{
|
||||
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;
|
||||
items.Add(this[i]);
|
||||
|
|
@ -201,7 +207,8 @@ namespace SM.Base.Scene
|
|||
/// </summary>
|
||||
/// <typeparam name="TItem">The type of show items.</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()
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -2,12 +2,8 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Windows.Controls;
|
||||
using SM.Base;
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.Windows;
|
||||
using SM.Utility;
|
||||
using SM.Base.Utility;
|
||||
using SM.Base.Window;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -18,12 +14,17 @@ namespace SM.Base.Scene
|
|||
/// </summary>
|
||||
public abstract class GenericScene : IInitializable
|
||||
{
|
||||
private IBackgroundItem _background;
|
||||
private readonly Dictionary<Type, object> _extensions = new Dictionary<Type, object>();
|
||||
|
||||
private GenericItemCollection _hud;
|
||||
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>
|
||||
/// This contains the background.
|
||||
/// </summary>
|
||||
|
|
@ -63,16 +64,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>
|
||||
/// If true, shows a axis helper at (0,0,0)
|
||||
|
|
@ -95,6 +86,20 @@ namespace SM.Base.Scene
|
|||
/// </summary>
|
||||
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>
|
||||
/// Updates this scene.
|
||||
/// </summary>
|
||||
|
|
@ -155,7 +160,6 @@ namespace SM.Base.Scene
|
|||
/// <param name="context"></param>
|
||||
public virtual void DrawDebug(DrawContext context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -178,25 +182,20 @@ namespace SM.Base.Scene
|
|||
object ext = _extensions[typeof(T)];
|
||||
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 (T)ext;
|
||||
return (T) ext;
|
||||
}
|
||||
|
||||
|
||||
public virtual void Activate()
|
||||
/// <summary>
|
||||
/// This is triggered when the scene gets deactivated.
|
||||
/// </summary>
|
||||
public virtual void Deactivate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void Initialization()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void Deactivate() {}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -242,6 +241,5 @@ namespace SM.Base.Scene
|
|||
get => (TCamera) base.BackgroundCamera;
|
||||
set => base.BackgroundCamera = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,24 @@
|
|||
using SM.Base;
|
||||
using SM.Base.Windows;
|
||||
#region usings
|
||||
|
||||
using SM.Base.Window;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a object as script.
|
||||
/// Defines a object as script.
|
||||
/// </summary>
|
||||
public interface IScriptable
|
||||
{
|
||||
/// <summary>
|
||||
/// If not active, ItemCollections will ignore them.
|
||||
/// </summary>
|
||||
bool Active { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If not active, ItemCollections will ignore them.
|
||||
/// </summary>
|
||||
bool UpdateActive { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
#region usings
|
||||
|
||||
using System.Collections.Generic;
|
||||
using SM.Base;
|
||||
using SM.Base.Windows;
|
||||
using SM.Base.Window;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -11,7 +10,6 @@ namespace SM.Base.Scene
|
|||
/// <summary>
|
||||
/// Adds functions, that is required for a collection.
|
||||
/// </summary>
|
||||
/// <typeparam name="TItem">The type of show item.</typeparam>
|
||||
public interface IShowCollection
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
#region usings
|
||||
|
||||
using System.Collections.Generic;
|
||||
using SM.Base;
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.Windows;
|
||||
using SM.Base.Window;
|
||||
using SM.OGL.Mesh;
|
||||
|
||||
#endregion
|
||||
|
|
@ -50,7 +49,7 @@ namespace SM.Base.Scene
|
|||
void OnRemoved(object sender);
|
||||
}
|
||||
|
||||
public interface ITransformItem<TTransform>
|
||||
public interface ITransformItem<TTransform>
|
||||
where TTransform : GenericTransformation
|
||||
{
|
||||
TTransform Transform { get; set; }
|
||||
|
|
@ -58,7 +57,8 @@ namespace SM.Base.Scene
|
|||
|
||||
public interface IShowTransformItem<TTransform> : IShowItem, ITransformItem<TTransform>
|
||||
where TTransform : GenericTransformation
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
public interface IModelItem
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using SM.OGL.Shaders;
|
|||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.ShaderExtension
|
||||
namespace SM.Base.Shaders.Extensions
|
||||
{
|
||||
internal class ExtensionManager
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
#region usings
|
||||
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.Base;
|
||||
using SM.Base.Windows;
|
||||
using SM.Base.Window;
|
||||
using SM.OGL.Mesh;
|
||||
using SM.OGL.Shaders;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Drawing
|
||||
namespace SM.Base.Shaders
|
||||
{
|
||||
/// <summary>
|
||||
/// A general class to work with material shaders properly.
|
||||
|
|
@ -17,7 +16,8 @@ namespace SM.Base.Drawing
|
|||
{
|
||||
/// <inheritdoc />
|
||||
protected MaterialShader(string combinedData) : base(combinedData)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected MaterialShader(string vertex, string fragment) : base(vertex, fragment)
|
||||
|
|
@ -39,16 +39,20 @@ namespace SM.Base.Drawing
|
|||
|
||||
context.Mesh.Activate();
|
||||
|
||||
if (context.Mesh is ILineMesh lineMesh)
|
||||
GL.LineWidth(context.Material.ShaderArguments.Get("LineWidth", lineMesh.LineWidth));
|
||||
if (context.Mesh is ILineMesh lineMesh)
|
||||
GL.LineWidth(context.Material.ShaderArguments.Get("LineWidth", lineMesh.LineWidth));
|
||||
else if (context.Material.ShaderArguments.ContainsKey("LineWidth"))
|
||||
GL.LineWidth((float)context.Material.ShaderArguments["LineWidth"]);
|
||||
GL.LineWidth((float) context.Material.ShaderArguments["LineWidth"]);
|
||||
|
||||
if (context.Material.Blending)
|
||||
{
|
||||
GL.Enable(EnableCap.Blend);
|
||||
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
|
||||
} else GL.Disable(EnableCap.Blend);
|
||||
}
|
||||
else
|
||||
{
|
||||
GL.Disable(EnableCap.Blend);
|
||||
}
|
||||
|
||||
DrawProcess(context);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,30 +1,46 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using SM.Base.Windows;
|
||||
using SM.OGL.Shaders;
|
||||
using SM.Utility;
|
||||
#region usings
|
||||
|
||||
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
|
||||
{
|
||||
/// <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 =
|
||||
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()
|
||||
{
|
||||
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"}
|
||||
},
|
||||
BasicSetUniforms
|
||||
));
|
||||
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"}
|
||||
},
|
||||
|
|
@ -35,7 +51,7 @@ namespace SM.Base.Drawing
|
|||
new ShaderFile(
|
||||
AssemblyUtility.ReadAssemblyFile("SM.Base.Shaders.SimpleShaderPresets.instanced_vertex.glsl"))
|
||||
{
|
||||
StringOverrides = { ["instanceMax"] = SMRenderer.MaxInstances.ToString(), ["extension"] = "0" }
|
||||
StringOverrides = {["instanceMax"] = SMRenderer.MaxInstances.ToString(), ["extension"] = "0"}
|
||||
},
|
||||
InstancedSetUniforms
|
||||
));
|
||||
|
|
@ -43,16 +59,46 @@ namespace SM.Base.Drawing
|
|||
new ShaderFile(
|
||||
AssemblyUtility.ReadAssemblyFile("SM.Base.Shaders.SimpleShaderPresets.instanced_vertex.glsl"))
|
||||
{
|
||||
StringOverrides = { ["instanceMax"] = SMRenderer.MaxInstances.ToString(), ["extension"] = "0" }
|
||||
StringOverrides = {["instanceMax"] = SMRenderer.MaxInstances.ToString(), ["extension"] = "0"}
|
||||
},
|
||||
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
|
||||
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["HasVColor"]
|
||||
.SetUniform1(context.Mesh.Attributes.Has("color"));
|
||||
|
|
@ -60,7 +106,7 @@ namespace SM.Base.Drawing
|
|||
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["MasterTextureMatrix"].SetMatrix3(context.TextureMatrix);
|
||||
|
|
@ -86,28 +132,11 @@ namespace SM.Base.Drawing
|
|||
|
||||
shaderInstanceI++;
|
||||
}
|
||||
|
||||
DrawObject(context.ForcedType.GetValueOrDefault(context.Mesh.PrimitiveType), context.Mesh, shaderInstanceI);
|
||||
}
|
||||
|
||||
private string _vertexPreset;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void DrawProcess(DrawContext context)
|
||||
{
|
||||
SetUniform?.Invoke(Uniforms, context);
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ namespace SM.Base.Textures
|
|||
/// </summary>
|
||||
public class Texture : TextureBase
|
||||
{
|
||||
private int? _width;
|
||||
private int? _height;
|
||||
private int? _width;
|
||||
|
||||
/// <summary>
|
||||
/// Decides if the bitmap will automatically dispose itself.
|
||||
|
|
@ -28,24 +28,6 @@ namespace SM.Base.Textures
|
|||
/// </summary>
|
||||
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>
|
||||
/// Empty constructor
|
||||
/// </summary>
|
||||
|
|
@ -72,12 +54,31 @@ namespace SM.Base.Textures
|
|||
{
|
||||
Map = map;
|
||||
|
||||
Aspect = (float)map.Width / map.Height;
|
||||
Aspect = (float) map.Width / map.Height;
|
||||
|
||||
Filter = filter;
|
||||
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 />
|
||||
public override void Compile()
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
#region usings
|
||||
|
||||
using System;
|
||||
using SM.Base;
|
||||
using SM.Base.Windows;
|
||||
using SM.Base.Window;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SM.Base;
|
||||
using SM.Base.Windows;
|
||||
using SM.Base.Window;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -14,17 +13,17 @@ namespace SM.Base.Time
|
|||
/// </summary>
|
||||
public class Stopwatch
|
||||
{
|
||||
private static List<Stopwatch> _activeStopwatches = new List<Stopwatch>();
|
||||
private bool _paused = false;
|
||||
private static readonly List<Stopwatch> _activeStopwatches = new List<Stopwatch>();
|
||||
private bool _paused;
|
||||
|
||||
/// <summary>
|
||||
/// If true, the stopwatch was started.
|
||||
/// <para>This doesn't changed when paused.</para>
|
||||
/// If true, the stopwatch was started.
|
||||
/// <para>This doesn't changed when paused.</para>
|
||||
/// </summary>
|
||||
public bool Active { get; private set; } = false;
|
||||
public bool Active { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets if the stopwatch is paused.
|
||||
/// Gets/Sets if the stopwatch is paused.
|
||||
/// </summary>
|
||||
public bool Paused
|
||||
{
|
||||
|
|
@ -39,7 +38,7 @@ namespace SM.Base.Time
|
|||
}
|
||||
|
||||
/// <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>
|
||||
public bool Running => Active && !Paused;
|
||||
|
||||
|
|
@ -53,6 +52,9 @@ namespace SM.Base.Time
|
|||
/// </summary>
|
||||
public TimeSpan ElapsedSpan { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// This event gets triggered every tick.
|
||||
/// </summary>
|
||||
public event Action<Stopwatch, UpdateContext> Tick;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -66,7 +68,6 @@ namespace SM.Base.Time
|
|||
Active = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Performs a tick.
|
||||
|
|
@ -81,15 +82,15 @@ namespace SM.Base.Time
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resumes the timer.
|
||||
/// Resumes the timer.
|
||||
/// </summary>
|
||||
protected virtual void Resume()
|
||||
{
|
||||
_paused = false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Pauses the timer.
|
||||
/// Pauses the timer.
|
||||
/// </summary>
|
||||
protected virtual void Pause()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
#region usings
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.Eventing.Reader;
|
||||
using SM.Base;
|
||||
using SM.Base.Windows;
|
||||
using SM.Base.Window;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -35,7 +33,7 @@ namespace SM.Base.Time
|
|||
/// <summary>
|
||||
/// The target time in seconds.
|
||||
/// </summary>
|
||||
public float Target { get; private set; }
|
||||
public float Target { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The already elapsed time but normalized to the target.
|
||||
|
|
|
|||
|
|
@ -1,39 +1,18 @@
|
|||
using System;
|
||||
using OpenTK;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Types
|
||||
{
|
||||
/// <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>
|
||||
public class CVector1
|
||||
{
|
||||
/// <summary>
|
||||
/// X - Component
|
||||
/// </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
|
||||
/// Creates a class vector
|
||||
/// </summary>
|
||||
/// <param name="x">X-Component</param>
|
||||
public CVector1(float x)
|
||||
|
|
@ -41,10 +20,33 @@ namespace SM.Base.Types
|
|||
X = x;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// X - Component
|
||||
/// </summary>
|
||||
public float X { get; set; }
|
||||
|
||||
/// <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>
|
||||
/// <param name="squared">If true, it will return the squared product.</param>
|
||||
/// <returns></returns>
|
||||
|
|
@ -57,7 +59,7 @@ namespace SM.Base.Types
|
|||
|
||||
|
||||
/// <summary>
|
||||
/// Normalizes the vector.
|
||||
/// Normalizes the vector.
|
||||
/// </summary>
|
||||
public void Normalize()
|
||||
{
|
||||
|
|
@ -66,7 +68,7 @@ namespace SM.Base.Types
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the X-Component.
|
||||
/// Sets the X-Component.
|
||||
/// </summary>
|
||||
/// <param name="x">X-Component</param>
|
||||
public virtual void Set(float uniform, bool triggerChanged = true)
|
||||
|
|
@ -75,6 +77,11 @@ namespace SM.Base.Types
|
|||
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)
|
||||
{
|
||||
X += uniform;
|
||||
|
|
@ -82,20 +89,24 @@ namespace SM.Base.Types
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Conversion into <see cref="float"/>
|
||||
/// Conversion into <see cref="float" />
|
||||
/// </summary>
|
||||
public static implicit operator float(CVector1 vector1) => vector1.X;
|
||||
public static implicit operator float(CVector1 vector1)
|
||||
{
|
||||
return vector1.X;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Conversion from <see cref="float"/> to One-dimensional Vector.
|
||||
/// Conversion from <see cref="float" /> to One-dimensional Vector.
|
||||
/// </summary>
|
||||
/// <param name="f"></param>
|
||||
/// <returns></returns>
|
||||
//public static implicit operator CVector1(float f) => new CVector1(f);
|
||||
|
||||
protected virtual float GetLengthProcess()
|
||||
{
|
||||
return X * X;
|
||||
}
|
||||
|
||||
protected virtual void NormalizationProcess(float length)
|
||||
{
|
||||
X *= length;
|
||||
|
|
|
|||
|
|
@ -1,19 +1,18 @@
|
|||
using OpenTK;
|
||||
#region usings
|
||||
|
||||
using OpenTK;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// A two-dimensional vector.
|
||||
/// A two-dimensional vector.
|
||||
/// </summary>
|
||||
public class CVector2 : CVector1
|
||||
{
|
||||
/// <summary>
|
||||
/// Y-component
|
||||
/// </summary>
|
||||
public float Y { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a vector, where each component is the same value.
|
||||
/// Creates a vector, where each component is the same value.
|
||||
/// </summary>
|
||||
/// <param name="uniform">The Value</param>
|
||||
public CVector2(float uniform) : base(uniform)
|
||||
|
|
@ -22,18 +21,25 @@ namespace SM.Base.Types
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a vector
|
||||
/// Creates a vector
|
||||
/// </summary>
|
||||
public CVector2(float x, float y) : base(x)
|
||||
{
|
||||
Y = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Y-component
|
||||
/// </summary>
|
||||
public float Y { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override float GetLengthProcess()
|
||||
{
|
||||
return base.GetLengthProcess() + Y * Y;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void NormalizationProcess(float length)
|
||||
{
|
||||
base.NormalizationProcess(length);
|
||||
|
|
@ -41,7 +47,7 @@ namespace SM.Base.Types
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets each component to the same value
|
||||
/// Sets each component to the same value
|
||||
/// </summary>
|
||||
/// <param name="uniform"></param>
|
||||
public override void Set(float uniform, bool triggerChanged = true)
|
||||
|
|
@ -51,7 +57,7 @@ namespace SM.Base.Types
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets each component to the <see cref="Vector2"/> counter-part.
|
||||
/// Sets each component to the <see cref="Vector2" /> counter-part.
|
||||
/// </summary>
|
||||
/// <param name="vector"></param>
|
||||
public void Set(Vector2 vector, bool triggerChanged = true)
|
||||
|
|
@ -60,7 +66,7 @@ namespace SM.Base.Types
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the a own value to each component.
|
||||
/// Sets the a own value to each component.
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
|
|
@ -70,17 +76,29 @@ namespace SM.Base.Types
|
|||
base.Set(x, triggerChanged);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Add(float uniform, bool triggerChanged = true)
|
||||
{
|
||||
Y += uniform;
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
Y += y;
|
||||
|
|
@ -88,12 +106,19 @@ namespace SM.Base.Types
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts to <see cref="Vector2"/>
|
||||
/// Converts to <see cref="Vector2" />
|
||||
/// </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>
|
||||
/// Converts from <see cref="Vector2"/> to <see cref="CVector2"/>.
|
||||
/// Converts from <see cref="Vector2" /> to <see cref="CVector2" />.
|
||||
/// </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
|
||||
{
|
||||
/// <summary>
|
||||
/// A three-dimensional vector.
|
||||
/// A three-dimensional vector.
|
||||
/// </summary>
|
||||
public class CVector3 : CVector2
|
||||
{
|
||||
/// <summary>
|
||||
/// Z-component
|
||||
/// </summary>
|
||||
public float Z { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a vector, where each component is the same value.
|
||||
/// Creates a vector, where each component is the same value.
|
||||
/// </summary>
|
||||
/// <param name="uniform">The Value</param>
|
||||
public CVector3(float uniform) : base(uniform)
|
||||
{
|
||||
Z = uniform;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a vector
|
||||
/// Creates a vector
|
||||
/// </summary>
|
||||
public CVector3(float x, float y, float z) : base(x, y)
|
||||
{
|
||||
Z = z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Z-component
|
||||
/// </summary>
|
||||
public float Z { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override float GetLengthProcess()
|
||||
{
|
||||
return base.GetLengthProcess() + Z * Z;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void NormalizationProcess(float length)
|
||||
{
|
||||
base.NormalizationProcess(length);
|
||||
|
|
@ -47,15 +54,16 @@ namespace SM.Base.Types
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the a own value to each component.
|
||||
/// Sets the a own value to each component.
|
||||
/// </summary>
|
||||
public void Set(float x, float y, float z, bool triggerChanged = true)
|
||||
{
|
||||
Z = z;
|
||||
base.Set(x,y, triggerChanged);
|
||||
base.Set(x, y, triggerChanged);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets each component to the <see cref="Vector3"/> counter-part.
|
||||
/// Sets each component to the <see cref="Vector3" /> counter-part.
|
||||
/// </summary>
|
||||
/// <param name="vector"></param>
|
||||
public void Set(Vector3 vector, bool triggerChanged = true)
|
||||
|
|
@ -63,30 +71,50 @@ namespace SM.Base.Types
|
|||
Set(vector.X, vector.Y, vector.Z, triggerChanged);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Add(float uniform, bool triggerChanged = true)
|
||||
{
|
||||
Z += uniform;
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
Z += z;
|
||||
base.Add(x,y, triggerChanged);
|
||||
base.Add(x, y, triggerChanged);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts to <see cref="Vector3"/>
|
||||
/// Converts to <see cref="Vector3" />
|
||||
/// </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>
|
||||
/// Converts from <see cref="Vector3"/> to <see cref="CVector3"/>.
|
||||
/// Converts from <see cref="Vector3" /> to <see cref="CVector3" />.
|
||||
/// </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
|
||||
|
||||
namespace SM.Utility
|
||||
namespace SM.Base.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains utility functions for handling with assemblies.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
namespace SM.Utility
|
||||
namespace SM.Base.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// A assistant to control the delta time.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
namespace SM.Utility
|
||||
namespace SM.Base.Utility
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public interface IInitializable
|
||||
{
|
||||
bool IsInitialized { get; set; }
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
#region usings
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Utility
|
||||
namespace SM.Base.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// A global helper class for randomization.
|
||||
|
|
@ -85,7 +83,7 @@ namespace SM.Utility
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a random item from the provided list.
|
||||
/// Gets a random item from the provided list.
|
||||
/// </summary>
|
||||
public static TSource GetRandomItem<TSource>(this IList<TSource> list)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
using System;
|
||||
using System.Windows;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
using OpenTK;
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.Scene;
|
||||
using SM.OGL.Mesh;
|
||||
|
||||
namespace SM.Utility
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Utility
|
||||
{
|
||||
public struct Ray
|
||||
{
|
||||
|
|
@ -23,9 +24,9 @@ namespace SM.Utility
|
|||
distance = 0.0f;
|
||||
float tMin = 0.0f;
|
||||
float tMax = 100000.0f;
|
||||
|
||||
|
||||
Vector3 delta = modelMatrix.Row3.Xyz - Position;
|
||||
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
float t1 = (e + box.Min[i]) / f;
|
||||
float t2 = (e + box.Max[i]) / f;
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ namespace SM.Utility
|
|||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using OpenTK;
|
|||
|
||||
#endregion
|
||||
|
||||
namespace SM.Utility
|
||||
namespace SM.Base.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Utilitys for rotations
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
namespace SM.Utility
|
||||
namespace SM.Base.Utility
|
||||
{
|
||||
public class ShaderUtility
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,10 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
namespace SM.Utility
|
||||
using System;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Utility
|
||||
{
|
||||
public class Util
|
||||
{
|
||||
|
|
@ -11,6 +15,7 @@ namespace SM.Utility
|
|||
obj.Initialization();
|
||||
obj.IsInitialized = true;
|
||||
}
|
||||
|
||||
obj.Activate();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
using System.Collections.Generic;
|
||||
#region usings
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.Shaders;
|
||||
using SM.OGL.Mesh;
|
||||
|
||||
namespace SM.Base.Windows
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Window
|
||||
{
|
||||
public struct DrawContext
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
using OpenTK.Input;
|
||||
#region usings
|
||||
|
||||
using SM.Base.Scene;
|
||||
|
||||
namespace SM.Base.Windows
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Window
|
||||
{
|
||||
public struct UpdateContext
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,20 +1,39 @@
|
|||
using System;
|
||||
using System.Windows;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Input;
|
||||
using SM.Base.Controls;
|
||||
using SM.Base.Scene;
|
||||
using SM.OGL;
|
||||
using Mouse = SM.Base.Controls.Mouse;
|
||||
|
||||
namespace SM.Base.Windows
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Window
|
||||
{
|
||||
public class GLWindow : GameWindow, IGenericWindow
|
||||
{
|
||||
private Vector2 _flagWindowSize;
|
||||
|
||||
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 float AspectRatio { get; set; }
|
||||
|
||||
|
|
@ -29,78 +48,12 @@ namespace SM.Base.Windows
|
|||
public ISetup AppliedSetup { get; private set; }
|
||||
public event Action<IGenericWindow> Resize;
|
||||
public event Action<IGenericWindow> Load;
|
||||
public event Action<IGenericWindow> Loaded;
|
||||
|
||||
public GenericScene CurrentScene { get; private set; }
|
||||
public RenderPipeline CurrentRenderPipeline { get; private set; }
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
WindowCode.Load(this);
|
||||
SMRenderer.CurrentWindow = this;
|
||||
|
||||
base.OnLoad(e);
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
|
||||
WindowCode.Resize(this);
|
||||
|
||||
if (WindowFlags == WindowFlags.Window) _flagWindowSize = WindowSize;
|
||||
|
||||
if (Loading)
|
||||
{
|
||||
Loading = false;
|
||||
Loaded?.Invoke(this);
|
||||
AppliedSetup?.Loaded(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnUpdateFrame(FrameEventArgs e)
|
||||
{
|
||||
if (!Focused && !UpdateWhileUnfocused) return;
|
||||
|
||||
base.OnUpdateFrame(e);
|
||||
|
||||
WindowCode.Update(this, (float)e.Time);
|
||||
}
|
||||
|
||||
|
||||
protected override void OnRenderFrame(FrameEventArgs e)
|
||||
{
|
||||
base.OnRenderFrame(e);
|
||||
|
||||
WindowCode.Render(this, (float)e.Time);
|
||||
|
||||
SwapBuffers();
|
||||
|
||||
GLDebugging.CheckGLErrors();
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseMoveEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
Mouse.MouseMoveEvent(e, this);
|
||||
}
|
||||
|
||||
public void Update(UpdateContext context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void ApplySetup(ISetup setup)
|
||||
|
|
@ -133,9 +86,68 @@ namespace SM.Base.Windows
|
|||
CurrentRenderPipeline = renderPipeline;
|
||||
}
|
||||
|
||||
public void TriggerLoad() => Load?.Invoke(this);
|
||||
public void TriggerLoad()
|
||||
{
|
||||
Load?.Invoke(this);
|
||||
}
|
||||
|
||||
public void TriggerResize() => Resize?.Invoke(this);
|
||||
public void TriggerResize()
|
||||
{
|
||||
Resize?.Invoke(this);
|
||||
}
|
||||
|
||||
public event Action<IGenericWindow> Loaded;
|
||||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
WindowCode.Load(this);
|
||||
SMRenderer.CurrentWindow = this;
|
||||
|
||||
base.OnLoad(e);
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
|
||||
WindowCode.Resize(this);
|
||||
|
||||
if (WindowFlags == WindowFlags.Window) _flagWindowSize = WindowSize;
|
||||
|
||||
if (Loading)
|
||||
{
|
||||
Loading = false;
|
||||
Loaded?.Invoke(this);
|
||||
AppliedSetup?.Loaded(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnUpdateFrame(FrameEventArgs e)
|
||||
{
|
||||
if (!Focused && !UpdateWhileUnfocused) return;
|
||||
|
||||
base.OnUpdateFrame(e);
|
||||
|
||||
WindowCode.Update(this, (float) e.Time);
|
||||
}
|
||||
|
||||
|
||||
protected override void OnRenderFrame(FrameEventArgs e)
|
||||
{
|
||||
base.OnRenderFrame(e);
|
||||
|
||||
WindowCode.Render(this, (float) e.Time);
|
||||
|
||||
SwapBuffers();
|
||||
|
||||
GLDebugging.CheckGLErrors();
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseMoveEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
Mouse.MouseMoveEvent(e, this);
|
||||
}
|
||||
|
||||
public void ChangeWindowFlag(WindowFlags newFlag)
|
||||
{
|
||||
|
|
@ -144,14 +156,14 @@ namespace SM.Base.Windows
|
|||
switch (newFlag)
|
||||
{
|
||||
case WindowFlags.Window:
|
||||
Width = (int)_flagWindowSize.X;
|
||||
Height = (int)_flagWindowSize.Y;
|
||||
Width = (int) _flagWindowSize.X;
|
||||
Height = (int) _flagWindowSize.Y;
|
||||
|
||||
WindowBorder = WindowBorder.Resizable;
|
||||
break;
|
||||
case WindowFlags.BorderlessWindow:
|
||||
WindowBorder = WindowBorder.Hidden;
|
||||
|
||||
|
||||
X = Screen.PrimaryScreen.Bounds.Left;
|
||||
Y = Screen.PrimaryScreen.Bounds.Top;
|
||||
Width = Screen.PrimaryScreen.Bounds.Width;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenTK;
|
||||
using SM.Base.Controls;
|
||||
using SM.Base.Scene;
|
||||
using SM.OGL.Framebuffer;
|
||||
|
||||
namespace SM.Base.Windows
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Window
|
||||
{
|
||||
public interface IGenericWindow : IFramebufferWindow
|
||||
{
|
||||
|
|
@ -26,12 +29,12 @@ namespace SM.Base.Windows
|
|||
|
||||
ISetup AppliedSetup { get; }
|
||||
|
||||
event Action<IGenericWindow> Resize;
|
||||
event Action<IGenericWindow> Load;
|
||||
|
||||
GenericScene CurrentScene { get; }
|
||||
RenderPipeline CurrentRenderPipeline { get; }
|
||||
|
||||
event Action<IGenericWindow> Resize;
|
||||
event Action<IGenericWindow> Load;
|
||||
|
||||
void Update(UpdateContext context);
|
||||
|
||||
void ApplySetup(ISetup setup);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
namespace SM.Base.Windows
|
||||
namespace SM.Base.Window
|
||||
{
|
||||
public interface ISetup
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
using System.Collections.Generic;
|
||||
#region usings
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.Shaders;
|
||||
using SM.Base.Utility;
|
||||
using SM.OGL.Framebuffer;
|
||||
using SM.OGL.Texture;
|
||||
using SM.Utility;
|
||||
|
||||
namespace SM.Base.Windows
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Window
|
||||
{
|
||||
public abstract class RenderPipeline : IInitializable
|
||||
{
|
||||
|
|
@ -20,25 +25,8 @@ namespace SM.Base.Windows
|
|||
|
||||
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 Initialization()
|
||||
|
|
@ -47,13 +35,34 @@ namespace SM.Base.Windows
|
|||
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)
|
||||
{
|
||||
Framebuffer framebuffer = new Framebuffer(window: ConnectedWindow);
|
||||
Framebuffer framebuffer = new Framebuffer(ConnectedWindow);
|
||||
framebuffer.Append("color", new ColorAttachment(0, PixelInformation.RGBA_LDR, multisamples));
|
||||
|
||||
RenderbufferAttachment depthAttach = RenderbufferAttachment.Depth;
|
||||
depthAttach.Multisample = multisamples;
|
||||
framebuffer.AppendRenderbuffer(depthAttach);
|
||||
|
||||
return framebuffer;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using OpenTK.Input;
|
||||
|
|
@ -9,13 +9,16 @@ using SM.Base.Drawing;
|
|||
using SM.Base.Objects.Static;
|
||||
using SM.Base.PostProcess;
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.ShaderExtension;
|
||||
using SM.Base.Shaders.Extensions;
|
||||
using SM.Base.Time;
|
||||
using SM.Base.Utility;
|
||||
using SM.OGL;
|
||||
using SM.Utility;
|
||||
using Keyboard = SM.Base.Controls.Keyboard;
|
||||
using Mouse = SM.Base.Controls.Mouse;
|
||||
|
||||
namespace SM.Base.Windows
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Window
|
||||
{
|
||||
internal class WindowCode
|
||||
{
|
||||
|
|
@ -69,19 +72,16 @@ namespace SM.Base.Windows
|
|||
internal static void Update(IGenericWindow window, float deltatime)
|
||||
{
|
||||
Deltatime.UpdateDelta = deltatime;
|
||||
SM.Base.Controls.Mouse.SetState();
|
||||
Controls.Keyboard.SetStage();
|
||||
var context = new UpdateContext()
|
||||
Mouse.SetState();
|
||||
Keyboard.SetStage();
|
||||
var context = new UpdateContext
|
||||
{
|
||||
Window = window,
|
||||
|
||||
Scene = window.CurrentScene
|
||||
};
|
||||
|
||||
if (Keyboard.IsDown(Key.AltLeft) && Keyboard.IsDown(Key.F4))
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
if (Keyboard.IsDown(Key.AltLeft) && Keyboard.IsDown(Key.F4)) window.Close();
|
||||
|
||||
Stopwatch.PerformTicks(context);
|
||||
window.CurrentScene?.Update(context);
|
||||
|
|
@ -97,7 +97,7 @@ namespace SM.Base.Windows
|
|||
GLObject.DisposeMarkedObjects();
|
||||
|
||||
Deltatime.RenderDelta = deltatime;
|
||||
var drawContext = new DrawContext()
|
||||
var drawContext = new DrawContext
|
||||
{
|
||||
Window = window,
|
||||
Scene = window.CurrentScene,
|
||||
|
|
@ -110,7 +110,7 @@ namespace SM.Base.Windows
|
|||
TextureMatrix = Matrix3.Identity,
|
||||
Instances = new Instance[1]
|
||||
{
|
||||
new Instance() {ModelMatrix = Matrix4.Identity, TextureMatrix = Matrix3.Identity}
|
||||
new Instance {ModelMatrix = Matrix4.Identity, TextureMatrix = Matrix3.Identity}
|
||||
}
|
||||
};
|
||||
drawContext.SetCamera(window.ViewportCamera);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
namespace SM.Base.Windows
|
||||
namespace SM.Base.Window
|
||||
{
|
||||
public enum WindowFlags
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<packages>
|
||||
<package id="OpenTK" version="3.3.1" targetFramework="net452" />
|
||||
<package id="OpenTK.GLWpfControl" version="3.2.3" targetFramework="net452" />
|
||||
<package id="SharpDX" version="4.2.0" targetFramework="net452" />
|
||||
<package id="SharpDX.XInput" version="4.2.0" targetFramework="net452" />
|
||||
<package id="OpenTK" version="3.3.1" targetFramework="net452" />
|
||||
<package id="OpenTK.GLWpfControl" version="3.2.3" targetFramework="net452" />
|
||||
<package id="SharpDX" version="4.2.0" targetFramework="net452" />
|
||||
<package id="SharpDX.XInput" version="4.2.0" targetFramework="net452" />
|
||||
</packages>
|
||||
Loading…
Add table
Add a link
Reference in a new issue