Added missing summeries #1

This commit is contained in:
Michel Fedde 2021-03-17 17:09:59 +01:00
parent 03d99ea28e
commit 8665b5b709
104 changed files with 1165 additions and 821 deletions

View file

@ -1,18 +1,24 @@
using System; #region usings
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Windows.Documents;
using System.Windows.Forms;
using OpenTK.Input; using OpenTK.Input;
using SharpDX.Win32;
#endregion
namespace SM.Base.Controls namespace SM.Base.Controls
{ {
public class Keyboard /// <summary>
/// A static class to get keyboard inputs.
/// </summary>
public static class Keyboard
{ {
internal static KeyboardState? _keyboardState; internal static KeyboardState? _keyboardState;
internal static List<Key> _lastPressedKeys = new List<Key>(); internal static List<Key> _lastPressedKeys = new List<Key>();
/// <summary>
/// True, when ANY key pressed.
/// </summary>
public static bool IsAnyKeyPressed => _keyboardState?.IsAnyKeyDown == true; public static bool IsAnyKeyPressed => _keyboardState?.IsAnyKeyDown == true;
@ -23,18 +29,53 @@ namespace SM.Base.Controls
_lastPressedKeys = new List<Key>(); _lastPressedKeys = new List<Key>();
foreach (object o in Enum.GetValues(typeof(Key))) foreach (object o in Enum.GetValues(typeof(Key)))
{ if (_keyboardState.Value[(Key) o])
if (_keyboardState.Value[(Key)o]) _lastPressedKeys.Add((Key)o); _lastPressedKeys.Add((Key) o);
}
} }
_keyboardState = OpenTK.Input.Keyboard.GetState(); _keyboardState = OpenTK.Input.Keyboard.GetState();
} }
public static bool IsDown(Key key, bool once = false) => _keyboardState?[key] == true && !(once && _lastPressedKeys.Contains(key)); /// <summary>
public static bool WasDown(Key key) => _keyboardState?[key] == false && _lastPressedKeys.Contains(key); /// Checks if a key is down.
public static bool IsUp(Key key, bool once = false) => _keyboardState?[key] == false && !(once && !_lastPressedKeys.Contains(key)); /// </summary>
/// <param name="key">The key</param>
/// <param name="once">If true, the method doesn't return true, when it was pressed one stage before.</param>
/// <returns></returns>
public static bool IsDown(Key key, bool once = false)
{
return _keyboardState?[key] == true && !(once && _lastPressedKeys.Contains(key));
}
/// <summary>
/// Checks if a key was down but not anymore.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static bool WasDown(Key key)
{
return _keyboardState?[key] == false && _lastPressedKeys.Contains(key);
}
/// <summary>
/// Check if a is up.
/// </summary>
/// <param name="key"></param>
/// <param name="once">If true, the method doesn't return true, when it was up one stage before.</param>
/// <returns></returns>
public static bool IsUp(Key key, bool once = false)
{
return _keyboardState?[key] == false && !(once && !_lastPressedKeys.Contains(key));
}
/// <summary>
/// Checks if specific keys are down.
/// </summary>
/// <param name="startIndex">Startindex</param>
/// <param name="endIndex">Endindex</param>
/// <param name="once">If true, it ignores keys that were down a state before.</param>
/// <returns>True if any of the specific keys where found down.</returns>
/// <exception cref="ArgumentException">The start index can't be greater then the end index.</exception>
public static bool AreSpecificKeysPressed(int startIndex, int endIndex, bool once = false) public static bool AreSpecificKeysPressed(int startIndex, int endIndex, bool once = false)
{ {
if (startIndex > endIndex) if (startIndex > endIndex)
@ -51,19 +92,42 @@ namespace SM.Base.Controls
return false; return false;
} }
public static bool AreSpecificKeysPressed(params Key[] keys) => AreSpecificKeysPressed(false, keys); /// <summary>
/// Checks if any of the specific keys are pressed.
/// </summary>
/// <param name="keys"></param>
/// <returns></returns>
public static bool AreSpecificKeysPressed(params Key[] keys)
{
return AreSpecificKeysPressed(false, keys);
}
/// <summary>
/// Checks if any of the specific keys are pressed.
/// </summary>
/// <param name="once">If true, it ignores keys that were down a state before.</param>
/// <param name="keys"></param>
/// <returns></returns>
public static bool AreSpecificKeysPressed(bool once, params Key[] keys) public static bool AreSpecificKeysPressed(bool once, params Key[] keys)
{ {
foreach (Key key in keys) foreach (Key key in keys)
{ if (IsDown(key, once))
if (IsDown(key, once)) return true; return true;
}
return false; return false;
} }
public static bool AreSpecificKeysPressed(int startIndex, int endIndex, out Key[] pressedKeys, bool once = false) /// <summary>
/// Checks if specific keys are down and returns the pressed keys.
/// </summary>
/// <param name="startIndex">Startindex</param>
/// <param name="endIndex">Endindex</param>
/// <param name="pressedKeys"></param>
/// <param name="once">If true, it ignores keys that were down a state before.</param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
public static bool AreSpecificKeysPressed(int startIndex, int endIndex, out Key[] pressedKeys,
bool once = false)
{ {
if (startIndex > endIndex) if (startIndex > endIndex)
throw new ArgumentException("The startIndex is greater than the endIndex.", nameof(startIndex)); throw new ArgumentException("The startIndex is greater than the endIndex.", nameof(startIndex));
@ -81,28 +145,41 @@ namespace SM.Base.Controls
keys.Add(key); keys.Add(key);
success = true; success = true;
} }
} }
pressedKeys = keys.ToArray(); pressedKeys = keys.ToArray();
return success; return success;
} }
public static bool AreSpecificKeysPressed(out Key[] pressedKey, params Key[] keys) => AreSpecificKeysPressed(false, out pressedKey, keys); /// <summary>
/// Checks if any of the specific keys are pressed and returns them.
/// </summary>
/// <param name="pressedKey"></param>
/// <param name="keys"></param>
/// <returns></returns>
public static bool AreSpecificKeysPressed(out Key[] pressedKey, params Key[] keys)
{
return AreSpecificKeysPressed(false, out pressedKey, keys);
}
/// <summary>
/// Checks if any of the specific keys are pressed and returns them.
/// </summary>
/// <param name="once">If true, it ignores keys that were down a state before.</param>
/// <param name="pressedKeys"></param>
/// <param name="keys"></param>
/// <returns></returns>
public static bool AreSpecificKeysPressed(bool once, out Key[] pressedKeys, params Key[] keys) public static bool AreSpecificKeysPressed(bool once, out Key[] pressedKeys, params Key[] keys)
{ {
List<Key> pressedKey = new List<Key>(); List<Key> pressedKey = new List<Key>();
bool success = false; bool success = false;
foreach (Key key in keys) foreach (Key key in keys)
{
if (IsDown(key, once)) if (IsDown(key, once))
{ {
pressedKey.Add(key); pressedKey.Add(key);
success = true; success = true;
} }
}
pressedKeys = pressedKey.ToArray(); pressedKeys = pressedKey.ToArray();
return success; return success;

View file

@ -2,10 +2,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Documents;
using OpenTK; using OpenTK;
using OpenTK.Input; using OpenTK.Input;
using SM.Base.Windows; using SM.Base.Window;
#endregion #endregion
@ -14,7 +13,6 @@ namespace SM.Base.Controls
/// <summary> /// <summary>
/// Mouse controller /// Mouse controller
/// </summary> /// </summary>
/// <typeparam name="TWindow">The type of window this controller is connected to.</typeparam>
public class Mouse public class Mouse
{ {
internal static MouseState? _mouseState; internal static MouseState? _mouseState;
@ -47,19 +45,21 @@ namespace SM.Base.Controls
_lastButtonsPressed = new List<MouseButton>(); _lastButtonsPressed = new List<MouseButton>();
foreach (object o in Enum.GetValues(typeof(MouseButton))) foreach (object o in Enum.GetValues(typeof(MouseButton)))
{ if (_mouseState.Value[(MouseButton) o])
if (_mouseState.Value[(MouseButton)o]) _lastButtonsPressed.Add((MouseButton)o); _lastButtonsPressed.Add((MouseButton) o);
}
} }
_mouseState = OpenTK.Input.Mouse.GetState(); _mouseState = OpenTK.Input.Mouse.GetState();
} }
public static bool IsDown(MouseButton button, bool once = false) => _mouseState?[button] == true && !(once && _lastButtonsPressed.Contains(button)); public static bool IsDown(MouseButton button, bool once = false)
{
public static bool IsUp(MouseButton button, bool once = false) => return _mouseState?[button] == true && !(once && _lastButtonsPressed.Contains(button));
_mouseState?[button] == false && !(once && !_lastButtonsPressed.Contains(button)); }
public static bool IsUp(MouseButton button, bool once = false)
{
return _mouseState?[button] == false && !(once && !_lastButtonsPressed.Contains(button));
}
} }
} }

View file

@ -1,12 +1,10 @@
#region usings #region usings
using System.Collections.Generic; using System.Collections.Generic;
using OpenTK.Graphics.ES11; using OpenTK.Graphics.OpenGL4;
using SM.Base;
using SM.Base.Scene; using SM.Base.Scene;
using SM.Base.Windows; using SM.Base.Window;
using SM.OGL.Mesh; using SM.OGL.Mesh;
using PrimitiveType = OpenTK.Graphics.OpenGL4.PrimitiveType;
#endregion #endregion
@ -22,15 +20,27 @@ namespace SM.Base.Drawing
/// </summary> /// </summary>
public Material Material = new Material(); public Material Material = new Material();
/// <summary>
/// Transformation for the textures.
/// </summary>
public TextureTransformation TextureTransform = new TextureTransformation();
/// <summary>
/// This allows custom shaders to add own arguments.
/// </summary>
public ShaderArguments ShaderArguments => Material.ShaderArguments;
/// <summary>
/// This can force a shader to render the object with the specified mesh type.
/// </summary>
public PrimitiveType? ForcedMeshType { get; set; }
/// <summary> /// <summary>
/// The mesh it should use. /// The mesh it should use.
/// </summary> /// </summary>
public GenericMesh Mesh { get; set; } = SMRenderer.DefaultMesh; public GenericMesh Mesh { get; set; } = SMRenderer.DefaultMesh;
public ShaderArguments ShaderArguments => Material.ShaderArguments;
public TextureTransformation TextureTransform = new TextureTransformation();
/// <inheritdoc /> /// <inheritdoc />
public object Parent { get; set; } public object Parent { get; set; }
@ -40,12 +50,11 @@ namespace SM.Base.Drawing
/// <inheritdoc /> /// <inheritdoc />
public ICollection<string> Flags { get; set; } public ICollection<string> Flags { get; set; }
public PrimitiveType? ForcedMeshType { get; set; }
/// <summary> /// <summary>
/// This value determents if the object should draw something. /// This value determents if the object should draw something.
/// </summary> /// </summary>
public bool Active { get; set; } = true; public bool Active { get; set; } = true;
public bool RenderActive { get; set; } = true; public bool RenderActive { get; set; } = true;
/// <inheritdoc /> /// <inheritdoc />

View file

@ -16,8 +16,14 @@ namespace SM.Base.Drawing
/// </summary> /// </summary>
public bool Ignore = false; public bool Ignore = false;
/// <summary>
/// The last matrix that was used to calculate the real world matrix.
/// </summary>
public Matrix4 LastMaster { get; internal set; } public Matrix4 LastMaster { get; internal set; }
/// <summary>
/// The transformation in world space.
/// </summary>
public Matrix4 InWorldSpace => MergeMatrix(LastMaster); public Matrix4 InWorldSpace => MergeMatrix(LastMaster);
/// <summary> /// <summary>

View file

@ -16,6 +16,9 @@ namespace SM.Base.Drawing
/// </summary> /// </summary>
public Matrix4 ModelMatrix = Matrix4.Identity; public Matrix4 ModelMatrix = Matrix4.Identity;
/// <summary>
/// The Texture matrix
/// </summary>
public Matrix3 TextureMatrix = Matrix3.Identity; public Matrix3 TextureMatrix = Matrix3.Identity;
} }
} }

View file

@ -1,7 +1,7 @@
#region usings #region usings
using System.Collections.Generic;
using OpenTK.Graphics; using OpenTK.Graphics;
using SM.Base.Shaders;
using SM.OGL.Texture; using SM.OGL.Texture;
#endregion #endregion
@ -13,6 +13,8 @@ namespace SM.Base.Drawing
/// </summary> /// </summary>
public class Material public class Material
{ {
public bool Blending = false;
/// <summary> /// <summary>
/// A custom shader, that is used to draw this material. /// A custom shader, that is used to draw this material.
/// </summary> /// </summary>
@ -28,8 +30,9 @@ namespace SM.Base.Drawing
/// </summary> /// </summary>
public Color4 Tint = Color4.White; public Color4 Tint = Color4.White;
/// <summary>
/// This allows custom shaders to use own shader arguments.
/// </summary>
public ShaderArguments ShaderArguments { get; internal set; } = new ShaderArguments(); public ShaderArguments ShaderArguments { get; internal set; } = new ShaderArguments();
public bool Blending = false;
} }
} }

View file

@ -1,4 +1,8 @@
using SM.Base.Time; #region usings
using SM.Base.Time;
#endregion
namespace SM.Base.Drawing.Particles namespace SM.Base.Drawing.Particles
{ {
@ -11,6 +15,7 @@ namespace SM.Base.Drawing.Particles
/// The Timer of the particles /// The Timer of the particles
/// </summary> /// </summary>
public Timer Timer; public Timer Timer;
/// <summary> /// <summary>
/// The current speed of the particles. /// The current speed of the particles.
/// </summary> /// </summary>

View file

@ -1,12 +1,13 @@
using System; #region usings
using System;
using System.Collections.Generic; using System.Collections.Generic;
using OpenTK; using OpenTK;
using SM.Base;
using SM.Base.Scene; using SM.Base.Scene;
using SM.Base.Time; using SM.Base.Time;
using SM.Base.Types; using SM.Base.Window;
using SM.Base.Windows;
using SM.OGL.Shaders; #endregion
namespace SM.Base.Drawing.Particles namespace SM.Base.Drawing.Particles
{ {
@ -17,15 +18,25 @@ namespace SM.Base.Drawing.Particles
where TTransform : GenericTransformation, new() where TTransform : GenericTransformation, new()
where TDirection : struct where TDirection : struct
{ {
/// <summary>
/// The amount of particles
/// </summary>
public int Amount = 32;
/// <summary>
/// This contains the different instances for the particles.
/// </summary>
protected List<Instance> instances;
/// <summary>
/// The maximum speed of the particles
/// </summary>
public float MaxSpeed = 1;
/// <summary> /// <summary>
/// This contains all important information for each particle. /// This contains all important information for each particle.
/// </summary> /// </summary>
protected ParticleStruct<TDirection>[] particleStructs; protected ParticleStruct<TDirection>[] particleStructs;
/// <summary>
/// This contains the different instances for the particles.
/// </summary>
protected List<Instance> instances;
/// <summary> /// <summary>
/// The stopwatch of the particles. /// The stopwatch of the particles.
@ -33,13 +44,13 @@ namespace SM.Base.Drawing.Particles
protected Timer timer; protected Timer timer;
/// <summary> /// <summary>
/// The amount of particles /// Sets up the timer.
/// </summary> /// </summary>
public int Amount = 32; /// <param name="duration">Duration how long the particles should live</param>
/// <summary> protected ParticleDrawingBasis(TimeSpan duration)
/// The maximum speed of the particles {
/// </summary> timer = new Timer(duration);
public float MaxSpeed = 1; }
/// <summary> /// <summary>
/// Get/Sets the state of pausing. /// Get/Sets the state of pausing.
@ -55,13 +66,25 @@ namespace SM.Base.Drawing.Particles
/// </summary> /// </summary>
public abstract Func<TDirection, ParticleContext, TDirection> MovementCalculation { get; set; } public abstract Func<TDirection, ParticleContext, TDirection> MovementCalculation { get; set; }
/// <summary> /// <inheritdoc />
/// Sets up the timer. public bool UpdateActive { get; set; }
/// </summary>
/// <param name="duration">Duration how long the particles should live</param> /// <inheritdoc />
protected ParticleDrawingBasis(TimeSpan duration) public void Update(UpdateContext context)
{ {
timer = new Timer(duration); if (!timer.Running) return;
ParticleContext particleContext = new ParticleContext
{
Timer = timer
};
for (int i = 0; i < Amount; i++)
{
particleContext.Speed = particleStructs[i].Speed;
instances[i].ModelMatrix = CreateMatrix(particleStructs[i],
MovementCalculation(particleStructs[i].Direction, particleContext));
}
} }
/// <summary> /// <summary>
@ -74,25 +97,6 @@ namespace SM.Base.Drawing.Particles
CreateParticles(); CreateParticles();
} }
public bool UpdateActive { get; set; }
/// <inheritdoc />
public void Update(UpdateContext context)
{
if (!timer.Running) return;
ParticleContext particleContext = new ParticleContext()
{
Timer = timer,
};
for (int i = 0; i < Amount; i++)
{
particleContext.Speed = particleStructs[i].Speed;
instances[i].ModelMatrix = CreateMatrix(particleStructs[i], MovementCalculation(particleStructs[i].Direction, particleContext));
}
}
/// <inheritdoc /> /// <inheritdoc />
protected override void DrawContext(ref DrawContext context) protected override void DrawContext(ref DrawContext context)
{ {

View file

@ -1,4 +1,8 @@
using OpenTK; #region usings
using OpenTK;
#endregion
namespace SM.Base.Drawing.Particles namespace SM.Base.Drawing.Particles
{ {
@ -10,10 +14,17 @@ namespace SM.Base.Drawing.Particles
/// <summary> /// <summary>
/// Default movement for 2D. /// Default movement for 2D.
/// </summary> /// </summary>
public static Vector2 Default2D(Vector2 direction, ParticleContext context) => direction * (context.Timer.Elapsed * context.Speed); public static Vector2 Default2D(Vector2 direction, ParticleContext context)
{
return direction * (context.Timer.Elapsed * context.Speed);
}
/// <summary> /// <summary>
/// Default movement for 3D. /// Default movement for 3D.
/// </summary> /// </summary>
public static Vector3 Default3D(Vector3 direction, ParticleContext context) => direction * (context.Timer.Elapsed * context.Speed); public static Vector3 Default3D(Vector3 direction, ParticleContext context)
{
return direction * (context.Timer.Elapsed * context.Speed);
}
} }
} }

View file

@ -1,5 +1,8 @@
using OpenTK; #region usings
using SM.Base.Types;
using OpenTK;
#endregion
namespace SM.Base.Drawing.Particles namespace SM.Base.Drawing.Particles
{ {
@ -13,10 +16,12 @@ namespace SM.Base.Drawing.Particles
/// A direction, that the particle should travel. /// A direction, that the particle should travel.
/// </summary> /// </summary>
public TDirection Direction; public TDirection Direction;
/// <summary> /// <summary>
/// A matrix to store rotation and scale. /// A matrix to store rotation and scale.
/// </summary> /// </summary>
public Matrix4 Matrix; public Matrix4 Matrix;
/// <summary> /// <summary>
/// Speeeeeeeeeed /// Speeeeeeeeeed
/// </summary> /// </summary>

View file

@ -1,10 +1,23 @@
using System; #region usings
using System.Collections.Generic; using System.Collections.Generic;
#endregion
namespace SM.Base.Drawing namespace SM.Base.Drawing
{ {
/// <summary>
/// A custom dictionary, with a few useful methods.
/// </summary>
public class ShaderArguments : Dictionary<string, object> public class ShaderArguments : Dictionary<string, object>
{ {
/// <summary>
/// Returns the stored value or the default value if the name doesn't exist.
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <typeparam name="TType"></typeparam>
/// <returns></returns>
public TType Get<TType>(string name, TType defaultValue = default) public TType Get<TType>(string name, TType defaultValue = default)
{ {
return ContainsKey(name) ? (TType) this[name] : defaultValue; return ContainsKey(name) ? (TType) this[name] : defaultValue;

View file

@ -32,8 +32,6 @@ namespace SM.Base.Drawing.Text
/// </summary> /// </summary>
public float FontSize = 12; public float FontSize = 12;
public float Spacing = 1;
/// <summary> /// <summary>
/// The font style. /// The font style.
/// <para>Default: <see cref="System.Drawing.FontStyle.Regular" /></para> /// <para>Default: <see cref="System.Drawing.FontStyle.Regular" /></para>
@ -45,6 +43,11 @@ namespace SM.Base.Drawing.Text
/// </summary> /// </summary>
public Dictionary<char, CharParameter> Positions = new Dictionary<char, CharParameter>(); public Dictionary<char, CharParameter> Positions = new Dictionary<char, CharParameter>();
/// <summary>
/// Allows a font wide spacing option.
/// </summary>
public float Spacing = 1;
/// <summary> /// <summary>
/// Generates a font from a font family from the specified path. /// Generates a font from a font family from the specified path.
/// </summary> /// </summary>

View file

@ -3,8 +3,7 @@
using System; using System;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using SM.Base; using SM.Base.Window;
using SM.Base.Windows;
#endregion #endregion
@ -27,26 +26,27 @@ namespace SM.Base.Drawing.Text
/// </summary> /// </summary>
protected string _text; protected string _text;
/// <summary>
/// The width of the text object.
/// </summary>
public float Width;
/// <summary>
/// The height of the text object.
/// </summary>
public float Height;
/// <summary> /// <summary>
/// The spacing between numbers. /// The spacing between numbers.
/// <para>Default: 1</para> /// <para>Default: 1</para>
/// </summary> /// </summary>
public float Spacing = 1; public float Spacing = 1;
public float ActualSpacing => Spacing * Font.Spacing;
public float Width;
public float Height;
/// <summary> /// <summary>
/// Creates a text object with a font. /// Calculates the actual spacing for the object.
/// </summary> /// </summary>
/// <param name="font">The font.</param> public float ActualSpacing => Spacing * Font.Spacing;
protected TextDrawingBasis(Font font)
{
Material.Texture = font;
Material.Blending = true;
}
/// <summary> /// <summary>
/// The font. /// The font.
@ -83,6 +83,16 @@ namespace SM.Base.Drawing.Text
set => Material.Tint = value; set => Material.Tint = value;
} }
/// <summary>
/// Creates a text object with a font.
/// </summary>
/// <param name="font">The font.</param>
protected TextDrawingBasis(Font font)
{
Material.Texture = font;
Material.Blending = true;
}
/// <inheritdoc /> /// <inheritdoc />
protected override void DrawContext(ref DrawContext context) protected override void DrawContext(ref DrawContext context)
@ -137,7 +147,8 @@ namespace SM.Base.Drawing.Text
_instances[i] = new Instance _instances[i] = new Instance
{ {
ModelMatrix = matrix, ModelMatrix = matrix,
TextureMatrix = TextureTransformation.CalculateMatrix(new Vector2(parameter.NormalizedX, 0), new Vector2(parameter.NormalizedWidth, 1), 0), TextureMatrix = TextureTransformation.CalculateMatrix(new Vector2(parameter.NormalizedX, 0),
new Vector2(parameter.NormalizedWidth, 1), 0)
}; };
x += parameter.Width * ActualSpacing; x += parameter.Width * ActualSpacing;

View file

@ -1,20 +1,46 @@
using System; #region usings
using OpenTK; using OpenTK;
using SM.Base.Types; using SM.Base.Types;
#endregion
namespace SM.Base.Drawing namespace SM.Base.Drawing
{ {
/// <summary>
/// Stores transformations for the textures.
/// </summary>
public class TextureTransformation public class TextureTransformation
{ {
/// <summary>
/// The offset from the origin.
/// </summary>
public CVector2 Offset = new CVector2(0); public CVector2 Offset = new CVector2(0);
public CVector2 Scale = new CVector2(1); /// <summary>
/// The rotation of the texture.
/// </summary>
public CVector1 Rotation = new CVector1(0); public CVector1 Rotation = new CVector1(0);
/// <summary>
/// The scale of the texture.
/// </summary>
public CVector2 Scale = new CVector2(1);
/// <summary>
/// Get the texture matrix.
/// </summary>
/// <returns></returns>
public Matrix3 GetMatrix() public Matrix3 GetMatrix()
{ {
return CalculateMatrix(Offset, Scale, Rotation); return CalculateMatrix(Offset, Scale, Rotation);
} }
/// <summary>
/// Calculates a texture matrix.
/// </summary>
/// <param name="offset"></param>
/// <param name="scale"></param>
/// <param name="rotation"></param>
/// <returns></returns>
public static Matrix3 CalculateMatrix(Vector2 offset, Vector2 scale, float rotation) public static Matrix3 CalculateMatrix(Vector2 offset, Vector2 scale, float rotation)
{ {
float radians = MathHelper.DegreesToRadians(rotation); float radians = MathHelper.DegreesToRadians(rotation);

View file

@ -1,17 +1,22 @@
using System; #region usings
using OpenTK.Graphics.OpenGL4; using OpenTK.Graphics.OpenGL4;
using SM.OGL.Mesh; using SM.OGL.Mesh;
#endregion
namespace SM.Base.Objects namespace SM.Base.Objects
{ {
public class InstancedMesh : Mesh, ILineMesh /// <summary>
/// This class allows for fast mesh creation.
/// </summary>
public class InstancedMesh : Mesh
{ {
public InstancedMesh(PrimitiveType type, string[] enabledAttibute) : base(type) public InstancedMesh(PrimitiveType type, string[] enabledAttibute) : base(type)
{ {
Attributes["vertex"] = Vertex = new VBO(); Attributes["vertex"] = Vertex = new VBO();
foreach (string attribute in enabledAttibute) foreach (string attribute in enabledAttibute)
{
switch (attribute) switch (attribute)
{ {
case "uv": case "uv":
@ -26,7 +31,4 @@ namespace SM.Base.Objects
} }
} }
} }
public float LineWidth { get; set; } = 1;
}
} }

View file

@ -7,16 +7,13 @@ using SM.OGL.Mesh;
namespace SM.Base.Objects namespace SM.Base.Objects
{ {
/// <inheritdoc /> /// <inheritdoc cref="GenericMesh" />
public class Mesh : GenericMesh, ILineMesh public class Mesh : GenericMesh, ILineMesh
{ {
public float LineWidth { get; set; } = 1;
/// <summary> /// <summary>
/// While initializing, it will add the <see cref="Color" /> to the data index. /// While initializing, it will add the <see cref="Color" /> to the data index.
/// </summary> /// </summary>
public Mesh(PrimitiveType type) : base() public Mesh(PrimitiveType type)
{ {
PrimitiveType = type; PrimitiveType = type;
Attributes.Add(3, "color", Color); Attributes.Add(3, "color", Color);
@ -27,5 +24,7 @@ namespace SM.Base.Objects
/// </summary> /// </summary>
public virtual VBO Color { get; protected set; } public virtual VBO Color { get; protected set; }
/// <inheritdoc />
public float LineWidth { get; set; } = 1;
} }
} }

View file

@ -1,7 +1,11 @@
using OpenTK.Graphics; #region usings
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL4; using OpenTK.Graphics.OpenGL4;
using SM.OGL.Mesh; using SM.OGL.Mesh;
#endregion
namespace SM.Base.Objects.Static namespace SM.Base.Objects.Static
{ {
/// <summary> /// <summary>
@ -18,28 +22,30 @@ namespace SM.Base.Objects.Static
/// </summary> /// </summary>
public static AxisHelper Object = new AxisHelper(); public static AxisHelper Object = new AxisHelper();
private AxisHelper() : base(PrimitiveType.Lines) {} private AxisHelper() : base(PrimitiveType.Lines)
{
}
/// <inheritdoc /> /// <inheritdoc />
public override VBO Vertex { get; protected set; } = new VBO() public override VBO Vertex { get; protected set; } = new VBO
{ {
{0, 0, 0}, {0, 0, 0},
{.5f, 0, 0}, {.5f, 0, 0},
{0, 0, 0}, {0, 0, 0},
{0, .5f, 0}, {0, .5f, 0},
{0, 0, -.5f}, {0, 0, -.5f},
{0, 0, .5f}, {0, 0, .5f}
}; };
/// <inheritdoc /> /// <inheritdoc />
public override VBO Color { get; protected set; } = new VBO(pointerSize: 4) public override VBO Color { get; protected set; } = new VBO(pointerSize: 4)
{ {
{Color4.White}, Color4.White,
{Color4.Red}, Color4.Red,
{Color4.White}, Color4.White,
{Color4.Green}, Color4.Green,
{Color4.White}, Color4.White,
{Color4.DarkBlue}, Color4.DarkBlue
}; };
} }
} }

View file

@ -1,59 +1,57 @@
using System.ComponentModel; #region usings
using OpenTK; using OpenTK;
using OpenTK.Graphics.OpenGL4; using OpenTK.Graphics.OpenGL4;
using SM.Base;
using SM.Base.Drawing; using SM.Base.Drawing;
using SM.Base.PostProcess; using SM.Base.PostProcess;
using SM.Base.Windows; using SM.Base.Utility;
using SM.Base.Window;
using SM.OGL.Framebuffer; using SM.OGL.Framebuffer;
using SM.OGL.Texture; using SM.OGL.Texture;
using SM.Utility;
#endregion
namespace SM.Base.PostEffects namespace SM.Base.PostEffects
{ {
public class BloomEffect : PostProcessEffect public class BloomEffect : PostProcessEffect
{ {
private static BezierCurve _defaultCurve = new BezierCurve(Vector2.UnitY, new Vector2(0.32f, 1), new Vector2(0.432f, 0), new Vector2(1,0));
private const float _defaultTextureScale = .75f; 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 _bloomBuffer1;
private Framebuffer _bloomBuffer2; private Framebuffer _bloomBuffer2;
private ColorAttachment _xBuffer; private readonly bool _hdr;
private ColorAttachment _yBuffer;
private PostProcessShader _shader = new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath+".bloom_blur.glsl")); private readonly PostProcessShader _mergeShader = new PostProcessShader(
private PostProcessShader _mergeShader = new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath+".bloom_merge_vert.glsl"), AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath+".bloom_merge.glsl")); 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 Framebuffer _source;
private readonly float _textureScale = .75f;
private BezierCurve _weightCurve; private BezierCurve _weightCurve;
private float[] _weights; private float[] _weights;
public int Iterations = 1; private ColorAttachment _xBuffer;
public float Threshold = .8f; private ColorAttachment _yBuffer;
public float Power = 1;
public bool Enable = true;
public float MinAmount = 0;
public float MaxAmount = 1;
public TextureBase AmountMap; public TextureBase AmountMap;
public TextureTransformation AmountTransform = new TextureTransformation(); public TextureTransformation AmountTransform = new TextureTransformation();
public BezierCurve WeightCurve public bool Enable = true;
{
get => _weightCurve; public int Iterations = 1;
set public float MaxAmount = 1;
{
_weightCurve = value; public float MinAmount = 0;
UpdateWeights(); public float Power = 1;
} public float Threshold = .8f;
}
public int WeightCurvePickAmount = 4; public int WeightCurvePickAmount = 4;
@ -67,17 +65,24 @@ namespace SM.Base.PostEffects
WeightCurve = _defaultCurve; WeightCurve = _defaultCurve;
} }
public BezierCurve WeightCurve
{
get => _weightCurve;
set
{
_weightCurve = value;
UpdateWeights();
}
}
private void UpdateWeights() private void UpdateWeights()
{ {
_weights = new float[WeightCurvePickAmount]; _weights = new float[WeightCurvePickAmount];
for (int i = 0; i < WeightCurvePickAmount; i++) for (int i = 0; i < WeightCurvePickAmount; i++)
{
_weights[i] = _weightCurve.CalculatePoint((float) (i + 1) / (WeightCurvePickAmount + 1)).Y; _weights[i] = _weightCurve.CalculatePoint((float) (i + 1) / (WeightCurvePickAmount + 1)).Y;
} }
}
protected override void InitProcess() protected override void InitProcess()
@ -86,10 +91,16 @@ namespace SM.Base.PostEffects
_source.ColorAttachments["color"].PixelInformation = PixelInformation.RGBA_HDR; _source.ColorAttachments["color"].PixelInformation = PixelInformation.RGBA_HDR;
_bloomBuffer1 = new Framebuffer(Pipeline.ConnectedWindow, _textureScale); _bloomBuffer1 = new Framebuffer(Pipeline.ConnectedWindow, _textureScale)
{
Name = "BloomX"
};
_bloomBuffer1.Append("xBuffer", _xBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR)); _bloomBuffer1.Append("xBuffer", _xBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR));
_bloomBuffer1.Compile(); _bloomBuffer1.Compile();
_bloomBuffer2 = new Framebuffer(Pipeline.ConnectedWindow, _textureScale); _bloomBuffer2 = new Framebuffer(Pipeline.ConnectedWindow, _textureScale)
{
Name = "BloomY"
};
_bloomBuffer2.Append("yBuffer", _yBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR)); _bloomBuffer2.Append("yBuffer", _yBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR));
_bloomBuffer2.Compile(); _bloomBuffer2.Compile();
@ -101,7 +112,8 @@ namespace SM.Base.PostEffects
{ {
if (Enable) if (Enable)
{ {
GL.Viewport(0,0, (int)(Pipeline.ConnectedWindow.Width * _textureScale), (int)(Pipeline.ConnectedWindow.Height * _textureScale)); GL.Viewport(0, 0, (int) (Pipeline.ConnectedWindow.Width * _textureScale),
(int) (Pipeline.ConnectedWindow.Height * _textureScale));
Framebuffer target = Framebuffer.GetCurrentlyActive(); Framebuffer target = Framebuffer.GetCurrentlyActive();
bool first = true, hoz = true; bool first = true, hoz = true;
@ -112,7 +124,8 @@ namespace SM.Base.PostEffects
_shader.Draw(collection => _shader.Draw(collection =>
{ {
collection["renderedTexture"].SetTexture(first ? _source.ColorAttachments["color"] : (hoz ? _yBuffer : _xBuffer)); collection["renderedTexture"]
.SetTexture(first ? _source.ColorAttachments["color"] : hoz ? _yBuffer : _xBuffer);
collection["RenderScale"].SetUniform1(_textureScale); collection["RenderScale"].SetUniform1(_textureScale);
collection["First"].SetUniform1(first); collection["First"].SetUniform1(first);

View file

@ -1,31 +1,54 @@
using System.Windows.Controls; #region usings
using OpenTK.Graphics.OpenGL4; using OpenTK.Graphics.OpenGL4;
using SM.Base.PostProcess; using SM.Base.PostProcess;
using SM.Base.Windows; using SM.Base.Utility;
using SM.OGL.Framebuffer; using SM.OGL.Framebuffer;
using SM.Utility;
#endregion
namespace SM.Base.PostEffects 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")); private static readonly PostProcessShader _hdrExposureShader =
static PostProcessShader _gammaShader = new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".finalize_gamma.glsl")); 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; 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) public static void ResolveMultisampledBuffers(Framebuffer multisampledBuffers, Framebuffer target)
{ {
multisampledBuffers.Activate(FramebufferTarget.ReadFramebuffer); multisampledBuffers.Activate(FramebufferTarget.ReadFramebuffer);
target.Activate(FramebufferTarget.DrawFramebuffer); 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(); 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) public static void FinalizeHDR(ColorAttachment attachment, float exposure)
{ {
_hdrExposureShader.Draw(u => _hdrExposureShader.Draw(u =>
{ {
u["Gamma"].SetUniform1(Gamma); 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) public static void FinalizeGamma(ColorAttachment attachment)
{ {
_gammaShader.Draw(u => _gammaShader.Draw(u =>

View file

@ -1,14 +1,10 @@
using System.Collections; #region usings
using System.Collections.Generic;
using System.Diagnostics;
using OpenTK; using OpenTK;
using OpenTK.Graphics.OpenGL4;
using SM.Base;
using SM.Base.Objects.Static;
using SM.Base.Scene; using SM.Base.Scene;
using SM.Base.Windows; using SM.Base.Window;
using SM.OGL.Framebuffer;
using SM.OGL.Shaders; #endregion
namespace SM.Base.PostProcess namespace SM.Base.PostProcess
{ {
@ -34,7 +30,9 @@ namespace SM.Base.PostProcess
/// <summary> /// <summary>
/// Method, to initialize the shader. /// Method, to initialize the shader.
/// </summary> /// </summary>
protected virtual void InitProcess() {} protected virtual void InitProcess()
{
}
/// <summary> /// <summary>
@ -47,7 +45,6 @@ namespace SM.Base.PostProcess
/// </summary> /// </summary>
public virtual void SceneChanged(GenericScene scene) public virtual void SceneChanged(GenericScene scene)
{ {
} }
} }
} }

View file

@ -1,10 +1,13 @@
using System; #region usings
using System;
using System.Collections.Generic; using System.Collections.Generic;
using OpenTK.Graphics.OpenGL4; using OpenTK.Graphics.OpenGL4;
using SM.Base.Objects.Static; using SM.Base.Objects.Static;
using SM.OGL.Framebuffer; using SM.Base.Utility;
using SM.OGL.Shaders; using SM.OGL.Shaders;
using SM.Utility;
#endregion
namespace SM.Base.PostProcess namespace SM.Base.PostProcess
{ {
@ -13,8 +16,12 @@ namespace SM.Base.PostProcess
/// </summary> /// </summary>
public class PostProcessShader : GenericShader public class PostProcessShader : GenericShader
{ {
private static readonly ShaderFile _fragExtensions = new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.extensions.frag")); private static readonly ShaderFile _fragExtensions =
private static readonly ShaderFile _normalVertex = new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.vertexFile.vert")); new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.extensions.frag"));
private static readonly ShaderFile _normalVertex =
new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.vertexFile.vert"));
private static readonly string _normalVertexWithExt = private static readonly string _normalVertexWithExt =
AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.vertexWithExt.vert"); AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.vertexWithExt.vert");
@ -23,7 +30,8 @@ namespace SM.Base.PostProcess
/// </summary> /// </summary>
public PostProcessShader(string fragment) : this(_normalVertex, public PostProcessShader(string fragment) : this(_normalVertex,
new ShaderFile(fragment)) new ShaderFile(fragment))
{ } {
}
/// <summary> /// <summary>
/// Creates the shader with an vertex extension and custom fragment. /// Creates the shader with an vertex extension and custom fragment.
@ -32,9 +40,10 @@ namespace SM.Base.PostProcess
/// <param name="fragment"></param> /// <param name="fragment"></param>
public PostProcessShader(string vertexExt, string fragment) : this(new ShaderFile(_normalVertexWithExt) public PostProcessShader(string vertexExt, string fragment) : this(new ShaderFile(_normalVertexWithExt)
{ {
GLSLExtensions = new List<ShaderFile>() { new ShaderFile(vertexExt) } GLSLExtensions = new List<ShaderFile> {new ShaderFile(vertexExt)}
}, new ShaderFile(fragment)) }, new ShaderFile(fragment))
{ } {
}
private PostProcessShader(ShaderFile vertex, ShaderFile fragment) : base( private PostProcessShader(ShaderFile vertex, ShaderFile fragment) : base(
new ShaderFileCollection(vertex, fragment)) new ShaderFileCollection(vertex, fragment))

View file

@ -41,7 +41,6 @@
<HintPath>..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll</HintPath> <HintPath>..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll</HintPath>
</Reference> </Reference>
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="SharpDX, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL"> <Reference Include="SharpDX, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
<HintPath>..\..\packages\SharpDX.4.2.0\lib\net45\SharpDX.dll</HintPath> <HintPath>..\..\packages\SharpDX.4.2.0\lib\net45\SharpDX.dll</HintPath>
</Reference> </Reference>

View file

@ -1,13 +1,11 @@
#region usings #region usings
using SM.Base.Drawing;
using SM.Base.Drawing.Text; using SM.Base.Drawing.Text;
using SM.Base.Objects.Static; using SM.Base.Objects.Static;
using SM.Base.Scene; using SM.Base.Shaders;
using SM.Base.Windows; using SM.Base.Utility;
using SM.Base.Window;
using SM.OGL.Mesh; using SM.OGL.Mesh;
using SM.OGL.Shaders;
using SM.Utility;
#endregion #endregion

View file

@ -1,7 +1,7 @@
#region usings #region usings
using OpenTK; using OpenTK;
using SM.Base.Windows; using SM.Base.Window;
#endregion #endregion
@ -12,6 +12,11 @@ namespace SM.Base.Scene
/// </summary> /// </summary>
public abstract class GenericCamera public abstract class GenericCamera
{ {
/// <summary>
/// Exposure defines the exposure to the Scene.
/// </summary>
public float Exposure = 1;
/// <summary> /// <summary>
/// This defines what is up. (Normalized) /// This defines what is up. (Normalized)
/// <para>Default: <see cref="Vector3.UnitY" /></para> /// <para>Default: <see cref="Vector3.UnitY" /></para>
@ -34,11 +39,6 @@ namespace SM.Base.Scene
/// </summary> /// </summary>
public abstract bool Orthographic { get; } public abstract bool Orthographic { get; }
/// <summary>
/// Exposure defines the exposure to the Scene.
/// </summary>
public float Exposure = 1;
/// <summary> /// <summary>
/// Calculates the view matrix. /// Calculates the view matrix.
/// </summary> /// </summary>
@ -46,10 +46,7 @@ namespace SM.Base.Scene
internal void CalculateViewMatrix(IGenericWindow window) internal void CalculateViewMatrix(IGenericWindow window)
{ {
View = ViewCalculation(window); View = ViewCalculation(window);
if (WorldCalculation(window, out Matrix4 world)) if (WorldCalculation(window, out Matrix4 world)) World = world;
{
World = world;
}
} }
/// <summary> /// <summary>
@ -61,6 +58,12 @@ namespace SM.Base.Scene
/// </returns> /// </returns>
protected abstract Matrix4 ViewCalculation(IGenericWindow window); protected abstract Matrix4 ViewCalculation(IGenericWindow window);
/// <summary>
/// This calculates the world.
/// </summary>
/// <param name="window"></param>
/// <param name="world"></param>
/// <returns></returns>
protected abstract bool WorldCalculation(IGenericWindow window, out Matrix4 world); protected abstract bool WorldCalculation(IGenericWindow window, out Matrix4 world);
} }
} }

View file

@ -2,10 +2,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using OpenTK;
using SM.Base;
using SM.Base.Drawing; using SM.Base.Drawing;
using SM.Base.Windows; using SM.Base.Window;
#endregion #endregion
@ -16,12 +14,17 @@ namespace SM.Base.Scene
/// </summary> /// </summary>
public abstract class GenericItemCollection : List<IShowItem>, IShowItem, IShowCollection, IScriptable 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> /// <summary>
/// Currently active script objects. /// Currently active script objects.
/// </summary> /// </summary>
public ReadOnlyCollection<IScriptable> ScriptableObjects => new ReadOnlyCollection<IScriptable>(_scriptableObjects); public ReadOnlyCollection<IScriptable> ScriptableObjects =>
new ReadOnlyCollection<IScriptable>(_scriptableObjects);
/// <inheritdoc />
public bool UpdateActive { get; set; } = true;
/// <inheritdoc /> /// <inheritdoc />
public List<IShowItem> Objects => this; public List<IShowItem> Objects => this;
@ -32,23 +35,13 @@ namespace SM.Base.Scene
public string Name { get; set; } = "Unnamed Item Collection"; public string Name { get; set; } = "Unnamed Item Collection";
/// <inheritdoc /> /// <inheritdoc />
public ICollection<string> Flags { get; set; } = new List<string>() {"collection"}; public ICollection<string> Flags { get; set; } = new List<string> {"collection"};
/// <inheritdoc cref="IShowItem" />
public bool Active { get; set; } = true; public bool Active { get; set; } = true;
public bool UpdateActive { get; set; } = true;
public bool RenderActive { get; set; } = true;
/// <inheritdoc /> /// <inheritdoc />
public virtual void Update(UpdateContext context) public bool RenderActive { get; set; } = true;
{
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 cref="IShowCollection.Draw" /> /// <inheritdoc cref="IShowCollection.Draw" />
public virtual void Draw(DrawContext context) 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 /> /// <inheritdoc />
public virtual void OnAdded(object sender) public virtual void OnAdded(object sender)
{ {
@ -75,7 +80,7 @@ namespace SM.Base.Scene
/// <summary> /// <summary>
/// Adds a item to the draw and the script collection, when applicable. /// Adds a item to the draw and the script collection, when applicable.
/// </summary> /// </summary>
public new void Add(params IShowItem[] items) public void Add(params IShowItem[] items)
{ {
foreach (var item in items) foreach (var item in items)
{ {
@ -96,6 +101,7 @@ namespace SM.Base.Scene
item.Parent = this; item.Parent = this;
item.OnAdded(this); item.OnAdded(this);
} }
/// <summary> /// <summary>
/// Adds the script to the collection. /// Adds the script to the collection.
/// </summary> /// </summary>
@ -105,7 +111,7 @@ namespace SM.Base.Scene
_scriptableObjects.Add(item); _scriptableObjects.Add(item);
} }
public new void Remove(params IShowItem[] items) public void Remove(params IShowItem[] items)
{ {
foreach (var item in items) foreach (var item in items)
{ {
@ -139,7 +145,7 @@ namespace SM.Base.Scene
public ICollection<IShowItem> GetAllItems(bool includeCollections = false) public ICollection<IShowItem> GetAllItems(bool includeCollections = false)
{ {
List<IShowItem> items = new List<IShowItem>(); List<IShowItem> items = new List<IShowItem>();
for (var i = 0; i < this.Count; i++) for (var i = 0; i < Count; i++)
{ {
if (!includeCollections && this[i] is IShowCollection) continue; if (!includeCollections && this[i] is IShowCollection) continue;
items.Add(this[i]); items.Add(this[i]);
@ -201,7 +207,8 @@ namespace SM.Base.Scene
/// </summary> /// </summary>
/// <typeparam name="TItem">The type of show items.</typeparam> /// <typeparam name="TItem">The type of show items.</typeparam>
/// <typeparam name="TTransformation">The type of transformation.</typeparam> /// <typeparam name="TTransformation">The type of transformation.</typeparam>
public abstract class GenericItemCollection<TTransformation> : GenericItemCollection, IShowTransformItem<TTransformation> public abstract class GenericItemCollection<TTransformation> : GenericItemCollection,
IShowTransformItem<TTransformation>
where TTransformation : GenericTransformation, new() where TTransformation : GenericTransformation, new()
{ {
/// <summary> /// <summary>

View file

@ -2,12 +2,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Dynamic; using SM.Base.Utility;
using System.Windows.Controls; using SM.Base.Window;
using SM.Base;
using SM.Base.Drawing;
using SM.Base.Windows;
using SM.Utility;
#endregion #endregion
@ -18,11 +14,16 @@ namespace SM.Base.Scene
/// </summary> /// </summary>
public abstract class GenericScene : IInitializable public abstract class GenericScene : IInitializable
{ {
private IBackgroundItem _background;
private readonly Dictionary<Type, object> _extensions = new Dictionary<Type, object>();
private GenericItemCollection _hud; private GenericItemCollection _hud;
private GenericItemCollection _objectCollection; private GenericItemCollection _objectCollection;
private IBackgroundItem _background;
private Dictionary<Type, object> _extensions = new Dictionary<Type, object>(); /// <summary>
/// A collection for cameras to switch easier to different cameras.
/// </summary>
public Dictionary<string, GenericCamera> Cameras = new Dictionary<string, GenericCamera>();
/// <summary> /// <summary>
/// This contains the background. /// This contains the background.
@ -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> /// <summary>
/// If true, shows a axis helper at (0,0,0) /// If true, shows a axis helper at (0,0,0)
@ -95,6 +86,20 @@ namespace SM.Base.Scene
/// </summary> /// </summary>
public GenericCamera HUDCamera { get; set; } public GenericCamera HUDCamera { get; set; }
/// <summary>
/// If true, the scene was already initialized.
/// </summary>
public bool IsInitialized { get; set; }
public virtual void Activate()
{
}
public virtual void Initialization()
{
}
/// <summary> /// <summary>
/// Updates this scene. /// Updates this scene.
/// </summary> /// </summary>
@ -155,7 +160,6 @@ namespace SM.Base.Scene
/// <param name="context"></param> /// <param name="context"></param>
public virtual void DrawDebug(DrawContext context) public virtual void DrawDebug(DrawContext context)
{ {
} }
/// <summary> /// <summary>
@ -178,25 +182,20 @@ namespace SM.Base.Scene
object ext = _extensions[typeof(T)]; object ext = _extensions[typeof(T)];
if (ext == null) if (ext == null)
{ {
Log.Write(LogType.Warning, $"Tried to get the extension '{typeof(T).Name}', that doesn't exist in the scene."); Log.Write(LogType.Warning,
$"Tried to get the extension '{typeof(T).Name}', that doesn't exist in the scene.");
return null; return null;
} }
return (T) ext; return (T) ext;
} }
/// <summary>
public virtual void Activate() /// This is triggered when the scene gets deactivated.
/// </summary>
public virtual void Deactivate()
{ {
} }
public virtual void Initialization()
{
}
public virtual void Deactivate() {}
} }
/// <summary> /// <summary>
@ -242,6 +241,5 @@ namespace SM.Base.Scene
get => (TCamera) base.BackgroundCamera; get => (TCamera) base.BackgroundCamera;
set => base.BackgroundCamera = value; set => base.BackgroundCamera = value;
} }
} }
} }

View file

@ -1,5 +1,8 @@
using SM.Base; #region usings
using SM.Base.Windows;
using SM.Base.Window;
#endregion
namespace SM.Base.Scene namespace SM.Base.Scene
{ {
@ -8,7 +11,14 @@ namespace SM.Base.Scene
/// </summary> /// </summary>
public interface IScriptable public interface IScriptable
{ {
/// <summary>
/// If not active, ItemCollections will ignore them.
/// </summary>
bool Active { get; set; } bool Active { get; set; }
/// <summary>
/// If not active, ItemCollections will ignore them.
/// </summary>
bool UpdateActive { get; set; } bool UpdateActive { get; set; }
/// <summary> /// <summary>

View file

@ -1,8 +1,7 @@
#region usings #region usings
using System.Collections.Generic; using System.Collections.Generic;
using SM.Base; using SM.Base.Window;
using SM.Base.Windows;
#endregion #endregion
@ -11,7 +10,6 @@ namespace SM.Base.Scene
/// <summary> /// <summary>
/// Adds functions, that is required for a collection. /// Adds functions, that is required for a collection.
/// </summary> /// </summary>
/// <typeparam name="TItem">The type of show item.</typeparam>
public interface IShowCollection public interface IShowCollection
{ {
/// <summary> /// <summary>

View file

@ -1,9 +1,8 @@
#region usings #region usings
using System.Collections.Generic; using System.Collections.Generic;
using SM.Base;
using SM.Base.Drawing; using SM.Base.Drawing;
using SM.Base.Windows; using SM.Base.Window;
using SM.OGL.Mesh; using SM.OGL.Mesh;
#endregion #endregion
@ -58,7 +57,8 @@ namespace SM.Base.Scene
public interface IShowTransformItem<TTransform> : IShowItem, ITransformItem<TTransform> public interface IShowTransformItem<TTransform> : IShowItem, ITransformItem<TTransform>
where TTransform : GenericTransformation where TTransform : GenericTransformation
{} {
}
public interface IModelItem public interface IModelItem
{ {

View file

@ -4,7 +4,7 @@ using SM.OGL.Shaders;
#endregion #endregion
namespace SM.Base.ShaderExtension namespace SM.Base.Shaders.Extensions
{ {
internal class ExtensionManager internal class ExtensionManager
{ {

View file

@ -1,14 +1,13 @@
#region usings #region usings
using OpenTK.Graphics.OpenGL4; using OpenTK.Graphics.OpenGL4;
using SM.Base; using SM.Base.Window;
using SM.Base.Windows;
using SM.OGL.Mesh; using SM.OGL.Mesh;
using SM.OGL.Shaders; using SM.OGL.Shaders;
#endregion #endregion
namespace SM.Base.Drawing namespace SM.Base.Shaders
{ {
/// <summary> /// <summary>
/// A general class to work with material shaders properly. /// A general class to work with material shaders properly.
@ -17,7 +16,8 @@ namespace SM.Base.Drawing
{ {
/// <inheritdoc /> /// <inheritdoc />
protected MaterialShader(string combinedData) : base(combinedData) protected MaterialShader(string combinedData) : base(combinedData)
{} {
}
/// <inheritdoc /> /// <inheritdoc />
protected MaterialShader(string vertex, string fragment) : base(vertex, fragment) protected MaterialShader(string vertex, string fragment) : base(vertex, fragment)
@ -48,7 +48,11 @@ namespace SM.Base.Drawing
{ {
GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
} else GL.Disable(EnableCap.Blend); }
else
{
GL.Disable(EnableCap.Blend);
}
DrawProcess(context); DrawProcess(context);

View file

@ -1,30 +1,46 @@
using System; #region usings
using System.Collections.Generic;
using System.Dynamic;
using SM.Base.Windows;
using SM.OGL.Shaders;
using SM.Utility;
namespace SM.Base.Drawing using System;
using System.Collections.Generic;
using SM.Base.Utility;
using SM.Base.Window;
using SM.OGL.Shaders;
#endregion
namespace SM.Base.Shaders
{ {
/// <summary>
/// Allows for simple creation of shaders.
/// </summary>
public class SimpleShader : MaterialShader public class SimpleShader : MaterialShader
{ {
/// <summary>
/// Vertex files that are stored in this dictionary can be used as vertex presets.
/// </summary>
public static Dictionary<string, Tuple<ShaderFile, Action<UniformCollection, DrawContext>>> VertexFiles = public static Dictionary<string, Tuple<ShaderFile, Action<UniformCollection, DrawContext>>> VertexFiles =
new Dictionary<string, Tuple<ShaderFile, Action<UniformCollection, DrawContext>>>(); new Dictionary<string, Tuple<ShaderFile, Action<UniformCollection, DrawContext>>>();
static ShaderFile _extensionDefineFile = new ShaderFile("#define SM_SIMPLE_EXTENSION"); private readonly string _vertexPreset;
/// <summary>
/// Stores the function that sets the uniforms.
/// </summary>
public Action<UniformCollection, DrawContext> SetUniform;
static SimpleShader() static SimpleShader()
{ {
VertexFiles.Add("basic", new Tuple<ShaderFile, Action<UniformCollection, DrawContext>>( VertexFiles.Add("basic", new Tuple<ShaderFile, Action<UniformCollection, DrawContext>>(
new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.Shaders.SimpleShaderPresets.basic_vertex.glsl")) new ShaderFile(
AssemblyUtility.ReadAssemblyFile("SM.Base.Shaders.SimpleShaderPresets.basic_vertex.glsl"))
{ {
StringOverrides = {["extension"] = "0"} StringOverrides = {["extension"] = "0"}
}, },
BasicSetUniforms BasicSetUniforms
)); ));
VertexFiles.Add("E_basic", new Tuple<ShaderFile, Action<UniformCollection, DrawContext>>( VertexFiles.Add("E_basic", new Tuple<ShaderFile, Action<UniformCollection, DrawContext>>(
new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.Shaders.SimpleShaderPresets.basic_vertex.glsl")) new ShaderFile(
AssemblyUtility.ReadAssemblyFile("SM.Base.Shaders.SimpleShaderPresets.basic_vertex.glsl"))
{ {
StringOverrides = {["extension"] = "1"} StringOverrides = {["extension"] = "1"}
}, },
@ -49,10 +65,40 @@ namespace SM.Base.Drawing
)); ));
} }
static void BasicSetUniforms(UniformCollection uniforms, DrawContext context) /// <summary>
/// Creates a simple shader.
/// </summary>
/// <param name="vertexPreset">The vertex preset.</param>
/// <param name="fragment">The fragment shader</param>
/// <param name="setUniform">The uniform function.</param>
public SimpleShader(string vertexPreset, string fragment, Action<UniformCollection, DrawContext> setUniform) :
base(new ShaderFileCollection(VertexFiles[vertexPreset].Item1, new ShaderFile(fragment)))
{
_vertexPreset = vertexPreset;
SetUniform = setUniform;
}
/// <summary>
/// Creates a simple shader with a extension.
/// </summary>
/// <param name="vertexPreset">The vertex preset.</param>
/// <param name="vertexExtension">The vertex extension shader</param>
/// <param name="fragment">The fragment shader</param>
/// <param name="setUniform">The uniform function.</param>
public SimpleShader(string vertexPreset, string vertexExtension, string fragment,
Action<UniformCollection, DrawContext> setUniform) : base(new ShaderFileCollection(
new[] {VertexFiles["E_" + vertexPreset].Item1, new ShaderFile(vertexExtension)},
new[] {new ShaderFile(fragment)}))
{
_vertexPreset = vertexPreset;
SetUniform = setUniform;
}
private static void BasicSetUniforms(UniformCollection uniforms, DrawContext context)
{ {
// Vertex Uniforms // Vertex Uniforms
uniforms["MVP"].SetMatrix4(context.Instances[0].ModelMatrix * context.ModelMatrix * context.View * context.World); uniforms["MVP"]
.SetMatrix4(context.Instances[0].ModelMatrix * context.ModelMatrix * context.View * context.World);
uniforms["MasterTextureMatrix"].SetMatrix3(context.Instances[0].TextureMatrix * context.TextureMatrix); uniforms["MasterTextureMatrix"].SetMatrix3(context.Instances[0].TextureMatrix * context.TextureMatrix);
uniforms["HasVColor"] uniforms["HasVColor"]
.SetUniform1(context.Mesh.Attributes.Has("color")); .SetUniform1(context.Mesh.Attributes.Has("color"));
@ -60,7 +106,7 @@ namespace SM.Base.Drawing
DrawObject(context.ForcedType.GetValueOrDefault(context.Mesh.PrimitiveType), context.Mesh); DrawObject(context.ForcedType.GetValueOrDefault(context.Mesh.PrimitiveType), context.Mesh);
} }
static void InstancedSetUniforms(UniformCollection uniforms, DrawContext context) private static void InstancedSetUniforms(UniformCollection uniforms, DrawContext context)
{ {
uniforms["MVP"].SetMatrix4(context.ModelMatrix * context.View * context.World); uniforms["MVP"].SetMatrix4(context.ModelMatrix * context.View * context.World);
uniforms["MasterTextureMatrix"].SetMatrix3(context.TextureMatrix); uniforms["MasterTextureMatrix"].SetMatrix3(context.TextureMatrix);
@ -86,28 +132,11 @@ namespace SM.Base.Drawing
shaderInstanceI++; shaderInstanceI++;
} }
DrawObject(context.ForcedType.GetValueOrDefault(context.Mesh.PrimitiveType), context.Mesh, shaderInstanceI); DrawObject(context.ForcedType.GetValueOrDefault(context.Mesh.PrimitiveType), context.Mesh, shaderInstanceI);
} }
private string _vertexPreset; /// <inheritdoc />
public Action<UniformCollection, DrawContext> SetUniform;
public SimpleShader(string vertexPreset, string fragment, Action<UniformCollection, DrawContext> setUniform) : base(new ShaderFileCollection(VertexFiles[vertexPreset].Item1, new ShaderFile(fragment)))
{
_vertexPreset = vertexPreset;
SetUniform = setUniform;
}
public SimpleShader(string vertexPreset, string vertexExtension, string fragment,
Action<UniformCollection, DrawContext> setUniform) : base(new ShaderFileCollection(
new[] {VertexFiles["E_"+vertexPreset].Item1, new ShaderFile(vertexExtension)},
new[] {new ShaderFile(fragment),}))
{
_vertexPreset = vertexPreset;
SetUniform = setUniform;
}
protected override void DrawProcess(DrawContext context) protected override void DrawProcess(DrawContext context)
{ {
SetUniform?.Invoke(Uniforms, context); SetUniform?.Invoke(Uniforms, context);

View file

@ -15,8 +15,8 @@ namespace SM.Base.Textures
/// </summary> /// </summary>
public class Texture : TextureBase public class Texture : TextureBase
{ {
private int? _width;
private int? _height; private int? _height;
private int? _width;
/// <summary> /// <summary>
/// Decides if the bitmap will automatically dispose itself. /// Decides if the bitmap will automatically dispose itself.
@ -28,24 +28,6 @@ namespace SM.Base.Textures
/// </summary> /// </summary>
public Bitmap Map; public Bitmap Map;
/// <inheritdoc />
public override int Width
{
get => _width ?? Map.Width;
protected set => _width = value;
}
/// <inheritdoc />
public override int Height
{
get => _height ?? Map.Height;
protected set => _height = value;
}
/// <summary>
/// Aspect ratio of Width and Height of the texture
/// </summary>
public float Aspect { get; private set; }
/// <summary> /// <summary>
/// Empty constructor /// Empty constructor
/// </summary> /// </summary>
@ -78,6 +60,25 @@ namespace SM.Base.Textures
WrapMode = wrapMode; WrapMode = wrapMode;
} }
/// <inheritdoc />
public override int Width
{
get => _width ?? Map.Width;
protected set => _width = value;
}
/// <inheritdoc />
public override int Height
{
get => _height ?? Map.Height;
protected set => _height = value;
}
/// <summary>
/// Aspect ratio of Width and Height of the texture
/// </summary>
public float Aspect { get; }
/// <inheritdoc /> /// <inheritdoc />
public override void Compile() public override void Compile()

View file

@ -1,8 +1,7 @@
#region usings #region usings
using System; using System;
using SM.Base; using SM.Base.Window;
using SM.Base.Windows;
#endregion #endregion

View file

@ -2,8 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using SM.Base; using SM.Base.Window;
using SM.Base.Windows;
#endregion #endregion
@ -14,14 +13,14 @@ namespace SM.Base.Time
/// </summary> /// </summary>
public class Stopwatch public class Stopwatch
{ {
private static List<Stopwatch> _activeStopwatches = new List<Stopwatch>(); private static readonly List<Stopwatch> _activeStopwatches = new List<Stopwatch>();
private bool _paused = false; private bool _paused;
/// <summary> /// <summary>
/// If true, the stopwatch was started. /// If true, the stopwatch was started.
/// <para>This doesn't changed when paused.</para> /// <para>This doesn't changed when paused.</para>
/// </summary> /// </summary>
public bool Active { get; private set; } = false; public bool Active { get; private set; }
/// <summary> /// <summary>
/// Gets/Sets if the stopwatch is paused. /// Gets/Sets if the stopwatch is paused.
@ -53,6 +52,9 @@ namespace SM.Base.Time
/// </summary> /// </summary>
public TimeSpan ElapsedSpan { get; protected set; } public TimeSpan ElapsedSpan { get; protected set; }
/// <summary>
/// This event gets triggered every tick.
/// </summary>
public event Action<Stopwatch, UpdateContext> Tick; public event Action<Stopwatch, UpdateContext> Tick;
/// <summary> /// <summary>
@ -67,7 +69,6 @@ namespace SM.Base.Time
} }
/// <summary> /// <summary>
/// Performs a tick. /// Performs a tick.
/// </summary> /// </summary>

View file

@ -1,9 +1,7 @@
#region usings #region usings
using System; using System;
using System.Diagnostics.Eventing.Reader; using SM.Base.Window;
using SM.Base;
using SM.Base.Windows;
#endregion #endregion
@ -35,7 +33,7 @@ namespace SM.Base.Time
/// <summary> /// <summary>
/// The target time in seconds. /// The target time in seconds.
/// </summary> /// </summary>
public float Target { get; private set; } public float Target { get; }
/// <summary> /// <summary>
/// The already elapsed time but normalized to the target. /// The already elapsed time but normalized to the target.

View file

@ -1,5 +1,8 @@
using System; #region usings
using OpenTK;
using System;
#endregion
namespace SM.Base.Types namespace SM.Base.Types
{ {
@ -8,19 +11,25 @@ namespace SM.Base.Types
/// </summary> /// </summary>
public class CVector1 public class CVector1
{ {
/// <summary>
/// Creates a class vector
/// </summary>
/// <param name="x">X-Component</param>
public CVector1(float x)
{
X = x;
}
/// <summary> /// <summary>
/// X - Component /// X - Component
/// </summary> /// </summary>
public float X public float X { get; set; }
{
get;
set;
}
/// <summary> /// <summary>
/// The length/magnitute of the vector. /// The length/magnitute of the vector.
/// </summary> /// </summary>
public float Length => GetLength(); public float Length => GetLength();
/// <summary> /// <summary>
/// Gets the square of the vector length (magnitude). /// Gets the square of the vector length (magnitude).
/// </summary> /// </summary>
@ -30,17 +39,10 @@ namespace SM.Base.Types
/// </remarks> /// </remarks>
public float LengthSquared => GetLength(true); public float LengthSquared => GetLength(true);
public event Action Changed;
/// <summary> /// <summary>
/// Creates a class vector /// This event triggers when a component changed.
/// </summary> /// </summary>
/// <param name="x">X-Component</param> public event Action Changed;
public CVector1(float x)
{
X = x;
}
/// <summary> /// <summary>
@ -75,6 +77,11 @@ namespace SM.Base.Types
if (triggerChanged) TriggerChanged(); if (triggerChanged) TriggerChanged();
} }
/// <summary>
/// Adds the value to the components.
/// </summary>
/// <param name="uniform"></param>
/// <param name="triggerChanged"></param>
public virtual void Add(float uniform, bool triggerChanged = true) public virtual void Add(float uniform, bool triggerChanged = true)
{ {
X += uniform; X += uniform;
@ -84,18 +91,22 @@ namespace SM.Base.Types
/// <summary> /// <summary>
/// Conversion into <see cref="float" /> /// Conversion into <see cref="float" />
/// </summary> /// </summary>
public static implicit operator float(CVector1 vector1) => vector1.X; public static implicit operator float(CVector1 vector1)
{
return vector1.X;
}
/// <summary> /// <summary>
/// Conversion from <see cref="float" /> to One-dimensional Vector. /// Conversion from <see cref="float" /> to One-dimensional Vector.
/// </summary> /// </summary>
/// <param name="f"></param> /// <param name="f"></param>
/// <returns></returns> /// <returns></returns>
//public static implicit operator CVector1(float f) => new CVector1(f); //public static implicit operator CVector1(float f) => new CVector1(f);
protected virtual float GetLengthProcess() protected virtual float GetLengthProcess()
{ {
return X * X; return X * X;
} }
protected virtual void NormalizationProcess(float length) protected virtual void NormalizationProcess(float length)
{ {
X *= length; X *= length;

View file

@ -1,4 +1,8 @@
using OpenTK; #region usings
using OpenTK;
#endregion
namespace SM.Base.Types namespace SM.Base.Types
{ {
@ -7,11 +11,6 @@ namespace SM.Base.Types
/// </summary> /// </summary>
public class CVector2 : CVector1 public class CVector2 : CVector1
{ {
/// <summary>
/// Y-component
/// </summary>
public float Y { get; set; }
/// <summary> /// <summary>
/// Creates a vector, where each component is the same value. /// Creates a vector, where each component is the same value.
/// </summary> /// </summary>
@ -29,11 +28,18 @@ namespace SM.Base.Types
Y = y; Y = y;
} }
/// <summary>
/// Y-component
/// </summary>
public float Y { get; set; }
/// <inheritdoc />
protected override float GetLengthProcess() protected override float GetLengthProcess()
{ {
return base.GetLengthProcess() + Y * Y; return base.GetLengthProcess() + Y * Y;
} }
/// <inheritdoc />
protected override void NormalizationProcess(float length) protected override void NormalizationProcess(float length)
{ {
base.NormalizationProcess(length); base.NormalizationProcess(length);
@ -70,17 +76,29 @@ namespace SM.Base.Types
base.Set(x, triggerChanged); base.Set(x, triggerChanged);
} }
/// <inheritdoc />
public override void Add(float uniform, bool triggerChanged = true) public override void Add(float uniform, bool triggerChanged = true)
{ {
Y += uniform; Y += uniform;
base.Add(uniform, triggerChanged); base.Add(uniform, triggerChanged);
} }
/// <summary>
/// Adds <see cref="Vector2"/> to the CVector.
/// </summary>
/// <param name="vector"></param>
/// <param name="triggerChanged">If false, the event Changed doesn't gets triggered </param>
public void Add(Vector2 vector, bool triggerChanged = true) public void Add(Vector2 vector, bool triggerChanged = true)
{ {
Add(vector.X, vector.Y, triggerChanged); Add(vector.X, vector.Y, triggerChanged);
} }
/// <summary>
/// Adds the values to the CVector.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="triggerChanged">If false, the event Changed doesn't gets triggered </param>
public void Add(float x, float y, bool triggerChanged = true) public void Add(float x, float y, bool triggerChanged = true)
{ {
Y += y; Y += y;
@ -90,10 +108,17 @@ namespace SM.Base.Types
/// <summary> /// <summary>
/// Converts to <see cref="Vector2" /> /// Converts to <see cref="Vector2" />
/// </summary> /// </summary>
public static implicit operator Vector2(CVector2 vector2) => new Vector2(vector2.X, vector2.Y); public static implicit operator Vector2(CVector2 vector2)
{
return new Vector2(vector2.X, vector2.Y);
}
/// <summary> /// <summary>
/// Converts from <see cref="Vector2" /> to <see cref="CVector2" />. /// Converts from <see cref="Vector2" /> to <see cref="CVector2" />.
/// </summary> /// </summary>
public static implicit operator CVector2(Vector2 vector2) => new CVector2(vector2.X, vector2.Y); public static implicit operator CVector2(Vector2 vector2)
{
return new CVector2(vector2.X, vector2.Y);
}
} }
} }

View file

@ -1,4 +1,8 @@
using OpenTK; #region usings
using OpenTK;
#endregion
namespace SM.Base.Types namespace SM.Base.Types
{ {
@ -7,11 +11,6 @@ namespace SM.Base.Types
/// </summary> /// </summary>
public class CVector3 : CVector2 public class CVector3 : CVector2
{ {
/// <summary>
/// Z-component
/// </summary>
public float Z { get; set; }
/// <summary> /// <summary>
/// Creates a vector, where each component is the same value. /// Creates a vector, where each component is the same value.
/// </summary> /// </summary>
@ -20,6 +19,7 @@ namespace SM.Base.Types
{ {
Z = uniform; Z = uniform;
} }
/// <summary> /// <summary>
/// Creates a vector /// Creates a vector
/// </summary> /// </summary>
@ -28,11 +28,18 @@ namespace SM.Base.Types
Z = z; Z = z;
} }
/// <summary>
/// Z-component
/// </summary>
public float Z { get; set; }
/// <inheritdoc />
protected override float GetLengthProcess() protected override float GetLengthProcess()
{ {
return base.GetLengthProcess() + Z * Z; return base.GetLengthProcess() + Z * Z;
} }
/// <inheritdoc />
protected override void NormalizationProcess(float length) protected override void NormalizationProcess(float length)
{ {
base.NormalizationProcess(length); base.NormalizationProcess(length);
@ -54,6 +61,7 @@ namespace SM.Base.Types
Z = z; Z = z;
base.Set(x, y, triggerChanged); base.Set(x, y, triggerChanged);
} }
/// <summary> /// <summary>
/// Sets each component to the <see cref="Vector3" /> counter-part. /// Sets each component to the <see cref="Vector3" /> counter-part.
/// </summary> /// </summary>
@ -63,17 +71,30 @@ namespace SM.Base.Types
Set(vector.X, vector.Y, vector.Z, triggerChanged); Set(vector.X, vector.Y, vector.Z, triggerChanged);
} }
/// <inheritdoc />
public override void Add(float uniform, bool triggerChanged = true) public override void Add(float uniform, bool triggerChanged = true)
{ {
Z += uniform; Z += uniform;
base.Add(uniform, triggerChanged); base.Add(uniform, triggerChanged);
} }
/// <summary>
/// Adds a <see cref="Vector3"/> to the CVector.
/// </summary>
/// <param name="vector"></param>
/// <param name="triggerChanged">If false, the event Changed doesn't gets triggered </param>
public void Add(Vector3 vector, bool triggerChanged = true) public void Add(Vector3 vector, bool triggerChanged = true)
{ {
Add(vector.X, vector.Y, vector.Z, triggerChanged); Add(vector.X, vector.Y, vector.Z, triggerChanged);
} }
/// <summary>
/// Adds the values to the CVector.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <param name="triggerChanged">If false, the event Changed doesn't gets triggered </param>
public void Add(float x, float y, float z, bool triggerChanged = true) public void Add(float x, float y, float z, bool triggerChanged = true)
{ {
Z += z; Z += z;
@ -83,10 +104,17 @@ namespace SM.Base.Types
/// <summary> /// <summary>
/// Converts to <see cref="Vector3" /> /// Converts to <see cref="Vector3" />
/// </summary> /// </summary>
public static implicit operator Vector3(CVector3 vector) => new Vector3(vector.X, vector.Y, vector.Z); public static implicit operator Vector3(CVector3 vector)
{
return new Vector3(vector.X, vector.Y, vector.Z);
}
/// <summary> /// <summary>
/// Converts from <see cref="Vector3" /> to <see cref="CVector3" />. /// Converts from <see cref="Vector3" /> to <see cref="CVector3" />.
/// </summary> /// </summary>
public static implicit operator CVector3(Vector3 vector) => new CVector3(vector.X, vector.Y, vector.Z); public static implicit operator CVector3(Vector3 vector)
{
return new CVector3(vector.X, vector.Y, vector.Z);
}
} }
} }

View file

@ -6,7 +6,7 @@ using System.Reflection;
#endregion #endregion
namespace SM.Utility namespace SM.Base.Utility
{ {
/// <summary> /// <summary>
/// Contains utility functions for handling with assemblies. /// Contains utility functions for handling with assemblies.

View file

@ -1,4 +1,4 @@
namespace SM.Utility namespace SM.Base.Utility
{ {
/// <summary> /// <summary>
/// A assistant to control the delta time. /// A assistant to control the delta time.

View file

@ -1,5 +1,8 @@
namespace SM.Utility namespace SM.Base.Utility
{ {
/// <summary>
///
/// </summary>
public interface IInitializable public interface IInitializable
{ {
bool IsInitialized { get; set; } bool IsInitialized { get; set; }

View file

@ -1,13 +1,11 @@
#region usings #region usings
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
#endregion #endregion
namespace SM.Utility namespace SM.Base.Utility
{ {
/// <summary> /// <summary>
/// A global helper class for randomization. /// A global helper class for randomization.

View file

@ -1,11 +1,12 @@
using System; #region usings
using System.Windows;
using System;
using OpenTK; using OpenTK;
using SM.Base.Drawing;
using SM.Base.Scene;
using SM.OGL.Mesh; using SM.OGL.Mesh;
namespace SM.Utility #endregion
namespace SM.Base.Utility
{ {
public struct Ray public struct Ray
{ {
@ -35,7 +36,6 @@ namespace SM.Utility
if (Math.Abs(f) > 0.001f) if (Math.Abs(f) > 0.001f)
{ {
float t1 = (e + box.Min[i]) / f; float t1 = (e + box.Min[i]) / f;
float t2 = (e + box.Max[i]) / f; float t2 = (e + box.Max[i]) / f;

View file

@ -5,7 +5,7 @@ using OpenTK;
#endregion #endregion
namespace SM.Utility namespace SM.Base.Utility
{ {
/// <summary> /// <summary>
/// Utilitys for rotations /// Utilitys for rotations

View file

@ -1,7 +1,6 @@
namespace SM.Utility namespace SM.Base.Utility
{ {
public class ShaderUtility public class ShaderUtility
{ {
} }
} }

View file

@ -1,6 +1,10 @@
using System; #region usings
namespace SM.Utility using System;
#endregion
namespace SM.Base.Utility
{ {
public class Util public class Util
{ {
@ -11,6 +15,7 @@ namespace SM.Utility
obj.Initialization(); obj.Initialization();
obj.IsInitialized = true; obj.IsInitialized = true;
} }
obj.Activate(); obj.Activate();
} }

View file

@ -1,11 +1,16 @@
using System.Collections.Generic; #region usings
using System.Collections.Generic;
using OpenTK; using OpenTK;
using OpenTK.Graphics.OpenGL4; using OpenTK.Graphics.OpenGL4;
using SM.Base.Drawing; using SM.Base.Drawing;
using SM.Base.Scene; using SM.Base.Scene;
using SM.Base.Shaders;
using SM.OGL.Mesh; using SM.OGL.Mesh;
namespace SM.Base.Windows #endregion
namespace SM.Base.Window
{ {
public struct DrawContext public struct DrawContext
{ {

View file

@ -1,7 +1,10 @@
using OpenTK.Input; #region usings
using SM.Base.Scene; using SM.Base.Scene;
namespace SM.Base.Windows #endregion
namespace SM.Base.Window
{ {
public struct UpdateContext public struct UpdateContext
{ {

View file

@ -1,20 +1,39 @@
using System; #region usings
using System.Windows;
using System;
using System.Windows.Forms; using System.Windows.Forms;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using OpenTK.Input; using OpenTK.Input;
using SM.Base.Controls;
using SM.Base.Scene; using SM.Base.Scene;
using SM.OGL; using SM.OGL;
using Mouse = SM.Base.Controls.Mouse; using Mouse = SM.Base.Controls.Mouse;
namespace SM.Base.Windows #endregion
namespace SM.Base.Window
{ {
public class GLWindow : GameWindow, IGenericWindow public class GLWindow : GameWindow, IGenericWindow
{ {
private Vector2 _flagWindowSize; private Vector2 _flagWindowSize;
public WindowFlags WindowFlags;
public GLWindow() : this(1280, 720, "Generic OpenGL Title", WindowFlags.Window)
{
}
public GLWindow(int width, int height, string title, WindowFlags flags, VSyncMode vSync = VSyncMode.On) :
base(width, height, default, title, (GameWindowFlags) flags, DisplayDevice.Default,
GLSettings.ForcedVersion.MajorVersion, GLSettings.ForcedVersion.MinorVersion,
GraphicsContextFlags.Default)
{
VSync = vSync;
_flagWindowSize = new Vector2(width, height);
ChangeWindowFlag(flags);
}
public bool Loading { get; private set; } = true; public bool Loading { get; private set; } = true;
public float AspectRatio { get; set; } public float AspectRatio { get; set; }
@ -29,24 +48,56 @@ namespace SM.Base.Windows
public ISetup AppliedSetup { get; private set; } public ISetup AppliedSetup { get; private set; }
public event Action<IGenericWindow> Resize; public event Action<IGenericWindow> Resize;
public event Action<IGenericWindow> Load; public event Action<IGenericWindow> Load;
public event Action<IGenericWindow> Loaded;
public GenericScene CurrentScene { get; private set; } public GenericScene CurrentScene { get; private set; }
public RenderPipeline CurrentRenderPipeline { get; private set; } public RenderPipeline CurrentRenderPipeline { get; private set; }
public WindowFlags WindowFlags; public void Update(UpdateContext context)
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 void ApplySetup(ISetup setup)
{
AppliedSetup = setup;
setup.Applied(this);
}
public void SetScene(GenericScene scene)
{
if (Loading)
{
Loaded += window => SetScene(scene);
return;
}
WindowCode.PrepareScene(this, scene);
CurrentScene = scene;
}
public void SetRenderPipeline(RenderPipeline renderPipeline)
{
if (Loading)
{
Loaded += window => SetRenderPipeline(renderPipeline);
return;
}
WindowCode.PreparePipeline(this, renderPipeline);
CurrentRenderPipeline = renderPipeline;
}
public void TriggerLoad()
{
Load?.Invoke(this);
}
public void TriggerResize()
{
Resize?.Invoke(this);
}
public event Action<IGenericWindow> Loaded;
protected override void OnLoad(EventArgs e) protected override void OnLoad(EventArgs e)
{ {
WindowCode.Load(this); WindowCode.Load(this);
@ -98,45 +149,6 @@ namespace SM.Base.Windows
Mouse.MouseMoveEvent(e, this); Mouse.MouseMoveEvent(e, this);
} }
public void Update(UpdateContext context)
{
}
public void ApplySetup(ISetup setup)
{
AppliedSetup = setup;
setup.Applied(this);
}
public void SetScene(GenericScene scene)
{
if (Loading)
{
Loaded += window => SetScene(scene);
return;
}
WindowCode.PrepareScene(this, scene);
CurrentScene = scene;
}
public void SetRenderPipeline(RenderPipeline renderPipeline)
{
if (Loading)
{
Loaded += window => SetRenderPipeline(renderPipeline);
return;
}
WindowCode.PreparePipeline(this, renderPipeline);
CurrentRenderPipeline = renderPipeline;
}
public void TriggerLoad() => Load?.Invoke(this);
public void TriggerResize() => Resize?.Invoke(this);
public void ChangeWindowFlag(WindowFlags newFlag) public void ChangeWindowFlag(WindowFlags newFlag)
{ {
WindowFlags = newFlag; WindowFlags = newFlag;

View file

@ -1,11 +1,14 @@
using System; #region usings
using System;
using System.Drawing; using System.Drawing;
using OpenTK; using OpenTK;
using SM.Base.Controls;
using SM.Base.Scene; using SM.Base.Scene;
using SM.OGL.Framebuffer; using SM.OGL.Framebuffer;
namespace SM.Base.Windows #endregion
namespace SM.Base.Window
{ {
public interface IGenericWindow : IFramebufferWindow public interface IGenericWindow : IFramebufferWindow
{ {
@ -26,12 +29,12 @@ namespace SM.Base.Windows
ISetup AppliedSetup { get; } ISetup AppliedSetup { get; }
event Action<IGenericWindow> Resize;
event Action<IGenericWindow> Load;
GenericScene CurrentScene { get; } GenericScene CurrentScene { get; }
RenderPipeline CurrentRenderPipeline { get; } RenderPipeline CurrentRenderPipeline { get; }
event Action<IGenericWindow> Resize;
event Action<IGenericWindow> Load;
void Update(UpdateContext context); void Update(UpdateContext context);
void ApplySetup(ISetup setup); void ApplySetup(ISetup setup);

View file

@ -1,4 +1,4 @@
namespace SM.Base.Windows namespace SM.Base.Window
{ {
public interface ISetup public interface ISetup
{ {

View file

@ -1,11 +1,16 @@
using System.Collections.Generic; #region usings
using System.Collections.Generic;
using System.Threading; using System.Threading;
using SM.Base.Drawing; using SM.Base.Drawing;
using SM.Base.Shaders;
using SM.Base.Utility;
using SM.OGL.Framebuffer; using SM.OGL.Framebuffer;
using SM.OGL.Texture; using SM.OGL.Texture;
using SM.Utility;
namespace SM.Base.Windows #endregion
namespace SM.Base.Window
{ {
public abstract class RenderPipeline : IInitializable public abstract class RenderPipeline : IInitializable
{ {
@ -20,7 +25,20 @@ namespace SM.Base.Windows
public bool IsInitialized { get; set; } public bool IsInitialized { get; set; }
internal void Render(ref DrawContext context) => RenderProcess(ref context); public virtual void Activate()
{
}
public virtual void Initialization()
{
if (MainFramebuffer != null) Framebuffers.Add(MainFramebuffer);
DefaultShader ??= SMRenderer.DefaultMaterialShader;
}
internal void Render(ref DrawContext context)
{
RenderProcess(ref context);
}
protected abstract void RenderProcess(ref DrawContext context); protected abstract void RenderProcess(ref DrawContext context);
@ -36,24 +54,15 @@ namespace SM.Base.Windows
framebuffer.Compile(); framebuffer.Compile();
} }
public virtual void Activate()
{
}
public virtual void Initialization()
{
if (MainFramebuffer != null) Framebuffers.Add(MainFramebuffer);
DefaultShader ??= SMRenderer.DefaultMaterialShader;
}
public Framebuffer CreateWindowFramebuffer(int multisamples = 0) public Framebuffer CreateWindowFramebuffer(int multisamples = 0)
{ {
Framebuffer framebuffer = new Framebuffer(window: ConnectedWindow); Framebuffer framebuffer = new Framebuffer(ConnectedWindow);
framebuffer.Append("color", new ColorAttachment(0, PixelInformation.RGBA_LDR, multisamples)); framebuffer.Append("color", new ColorAttachment(0, PixelInformation.RGBA_LDR, multisamples));
RenderbufferAttachment depthAttach = RenderbufferAttachment.Depth; RenderbufferAttachment depthAttach = RenderbufferAttachment.Depth;
depthAttach.Multisample = multisamples; depthAttach.Multisample = multisamples;
framebuffer.AppendRenderbuffer(depthAttach); framebuffer.AppendRenderbuffer(depthAttach);
return framebuffer; return framebuffer;
} }
} }

View file

@ -1,7 +1,7 @@
using System; #region usings
using System.Collections.Generic;
using System;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using OpenTK; using OpenTK;
using OpenTK.Graphics.OpenGL4; using OpenTK.Graphics.OpenGL4;
using OpenTK.Input; using OpenTK.Input;
@ -9,13 +9,16 @@ using SM.Base.Drawing;
using SM.Base.Objects.Static; using SM.Base.Objects.Static;
using SM.Base.PostProcess; using SM.Base.PostProcess;
using SM.Base.Scene; using SM.Base.Scene;
using SM.Base.ShaderExtension; using SM.Base.Shaders.Extensions;
using SM.Base.Time; using SM.Base.Time;
using SM.Base.Utility;
using SM.OGL; using SM.OGL;
using SM.Utility;
using Keyboard = SM.Base.Controls.Keyboard; using Keyboard = SM.Base.Controls.Keyboard;
using Mouse = SM.Base.Controls.Mouse;
namespace SM.Base.Windows #endregion
namespace SM.Base.Window
{ {
internal class WindowCode internal class WindowCode
{ {
@ -69,19 +72,16 @@ namespace SM.Base.Windows
internal static void Update(IGenericWindow window, float deltatime) internal static void Update(IGenericWindow window, float deltatime)
{ {
Deltatime.UpdateDelta = deltatime; Deltatime.UpdateDelta = deltatime;
SM.Base.Controls.Mouse.SetState(); Mouse.SetState();
Controls.Keyboard.SetStage(); Keyboard.SetStage();
var context = new UpdateContext() var context = new UpdateContext
{ {
Window = window, Window = window,
Scene = window.CurrentScene Scene = window.CurrentScene
}; };
if (Keyboard.IsDown(Key.AltLeft) && Keyboard.IsDown(Key.F4)) if (Keyboard.IsDown(Key.AltLeft) && Keyboard.IsDown(Key.F4)) window.Close();
{
window.Close();
}
Stopwatch.PerformTicks(context); Stopwatch.PerformTicks(context);
window.CurrentScene?.Update(context); window.CurrentScene?.Update(context);
@ -97,7 +97,7 @@ namespace SM.Base.Windows
GLObject.DisposeMarkedObjects(); GLObject.DisposeMarkedObjects();
Deltatime.RenderDelta = deltatime; Deltatime.RenderDelta = deltatime;
var drawContext = new DrawContext() var drawContext = new DrawContext
{ {
Window = window, Window = window,
Scene = window.CurrentScene, Scene = window.CurrentScene,
@ -110,7 +110,7 @@ namespace SM.Base.Windows
TextureMatrix = Matrix3.Identity, TextureMatrix = Matrix3.Identity,
Instances = new Instance[1] Instances = new Instance[1]
{ {
new Instance() {ModelMatrix = Matrix4.Identity, TextureMatrix = Matrix3.Identity} new Instance {ModelMatrix = Matrix4.Identity, TextureMatrix = Matrix3.Identity}
} }
}; };
drawContext.SetCamera(window.ViewportCamera); drawContext.SetCamera(window.ViewportCamera);

View file

@ -1,4 +1,4 @@
namespace SM.Base.Windows namespace SM.Base.Window
{ {
public enum WindowFlags public enum WindowFlags
{ {

View file

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="OpenTK" version="3.3.1" targetFramework="net452" /> <package id="OpenTK" version="3.3.1" targetFramework="net452" />
<package id="OpenTK.GLWpfControl" version="3.2.3" targetFramework="net452" /> <package id="OpenTK.GLWpfControl" version="3.2.3" targetFramework="net452" />

View file

@ -38,6 +38,9 @@ namespace SM.OGL.Framebuffer
/// </summary> /// </summary>
public DrawBuffersEnum DrawBuffersEnum => DrawBuffersEnum.ColorAttachment0 + AttachmentID; public DrawBuffersEnum DrawBuffersEnum => DrawBuffersEnum.ColorAttachment0 + AttachmentID;
/// <summary>
/// Returns true, if multisamples are above 0.
/// </summary>
public bool IsMultisampled => _multisamples > 0; public bool IsMultisampled => _multisamples > 0;
/// <summary> /// <summary>

View file

@ -14,7 +14,7 @@ namespace SM.OGL.Framebuffer
/// </summary> /// </summary>
public class Framebuffer : GLObject public class Framebuffer : GLObject
{ {
protected override bool AutoCompile { get; } = true; protected override bool AutoCompile { get; set; } = true;
/// <summary> /// <summary>
/// Represents the screen buffer. /// Represents the screen buffer.
@ -22,11 +22,9 @@ namespace SM.OGL.Framebuffer
public static readonly Framebuffer Screen = new Framebuffer public static readonly Framebuffer Screen = new Framebuffer
{ {
_id = 0, _id = 0,
_canBeCompiled = false CanCompile = false,
}; };
private bool _canBeCompiled = true;
private IFramebufferWindow _window; private IFramebufferWindow _window;
private float _windowScale; private float _windowScale;
@ -77,8 +75,6 @@ namespace SM.OGL.Framebuffer
/// <inheritdoc /> /// <inheritdoc />
public override void Compile() public override void Compile()
{ {
if (!_canBeCompiled) return;
if (_window != null) Size = new Vector2(_window.Width * _windowScale, _window.Height * _windowScale); if (_window != null) Size = new Vector2(_window.Width * _windowScale, _window.Height * _windowScale);
base.Compile(); base.Compile();
@ -181,7 +177,7 @@ namespace SM.OGL.Framebuffer
{ {
Framebuffer buffer = new Framebuffer() Framebuffer buffer = new Framebuffer()
{ {
_canBeCompiled = false, CanCompile = false,
ReportAsNotCompiled = true ReportAsNotCompiled = true
}; };
switch (target) switch (target)

View file

@ -1,5 +1,8 @@
namespace SM.OGL.Framebuffer namespace SM.OGL.Framebuffer
{ {
/// <summary>
/// A interface, so the framebuffer system can react to changes of windows.
/// </summary>
public interface IFramebufferWindow public interface IFramebufferWindow
{ {
int Width { get; } int Width { get; }

View file

@ -2,15 +2,33 @@
namespace SM.OGL.Framebuffer namespace SM.OGL.Framebuffer
{ {
/// <summary>
/// Describes a renderbuffer attachment.
/// </summary>
public struct RenderbufferAttachment public struct RenderbufferAttachment
{ {
/// <summary>
/// Preset for the depthbuffer attachment.
/// </summary>
public static readonly RenderbufferAttachment Depth = new RenderbufferAttachment(RenderbufferStorage.Depth24Stencil8, FramebufferAttachment.DepthStencilAttachment); public static readonly RenderbufferAttachment Depth = new RenderbufferAttachment(RenderbufferStorage.Depth24Stencil8, FramebufferAttachment.DepthStencilAttachment);
/// <summary>
/// Storage describes the internal format for the renderbuffer.
/// </summary>
public RenderbufferStorage Storage; public RenderbufferStorage Storage;
/// <summary>
/// FramebufferAttachment describes the attachment for the framebuffer.
/// </summary>
public FramebufferAttachment FramebufferAttachment; public FramebufferAttachment FramebufferAttachment;
/// <summary>
/// This contains the amount of multisampling for the attachment.
/// </summary>
public int Multisample; public int Multisample;
/// <summary>
/// Constructor
/// </summary>
public RenderbufferAttachment(RenderbufferStorage storage, FramebufferAttachment framebufferAttachment, int multisample = 0) public RenderbufferAttachment(RenderbufferStorage storage, FramebufferAttachment framebufferAttachment, int multisample = 0)
{ {
Storage = storage; Storage = storage;
@ -18,18 +36,23 @@ namespace SM.OGL.Framebuffer
Multisample = multisample; Multisample = multisample;
} }
/// <summary>
/// This generates the renderbuffer for the framebuffer to add.
/// </summary>
/// <param name="f">The framebuffer</param>
/// <returns>The ID of the renderbuffer.</returns>
public int Generate(Framebuffer f) public int Generate(Framebuffer f)
{ {
int rbo = GL.GenRenderbuffer(); int rb = GL.GenRenderbuffer();
GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, rbo); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, rb);
if (Multisample != 0) if (Multisample != 0)
GL.RenderbufferStorageMultisample(RenderbufferTarget.Renderbuffer, Multisample, Storage, (int)f.Size.X, (int)f.Size.Y); GL.RenderbufferStorageMultisample(RenderbufferTarget.Renderbuffer, Multisample, Storage, (int)f.Size.X, (int)f.Size.Y);
else else
GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, Storage, (int)f.Size.X, (int)f.Size.Y); GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, Storage, (int)f.Size.X, (int)f.Size.Y);
GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0);
return rbo; return rb;
} }
} }
} }

View file

@ -1,9 +1,8 @@
#region usings #region usings
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices; using OpenTK.Audio;
using OpenTK.Graphics.OpenGL4; using OpenTK.Graphics.OpenGL4;
#endregion #endregion
@ -16,6 +15,7 @@ namespace SM.OGL
public abstract class GLObject public abstract class GLObject
{ {
private static List<GLObject> _disposableObjects = new List<GLObject>(); private static List<GLObject> _disposableObjects = new List<GLObject>();
private string _name = "";
protected bool ReportAsNotCompiled; protected bool ReportAsNotCompiled;
@ -24,16 +24,28 @@ namespace SM.OGL
/// </summary> /// </summary>
protected int _id = -1; protected int _id = -1;
protected bool CanCompile = true;
/// <summary> /// <summary>
/// If true, the system will call "Compile()", when "ID" is tried to get, but the id is still -1. /// If true, the system will call "Compile()", when "ID" is tried to get, but the id is still -1.
/// </summary> /// </summary>
protected virtual bool AutoCompile { get; } = false; protected virtual bool AutoCompile { get; set; } = false;
/// <summary> /// <summary>
/// Checks if the object was compiled. /// Checks if the object was compiled.
/// </summary> /// </summary>
public bool WasCompiled => _id > 0 && !ReportAsNotCompiled; public bool WasCompiled => _id > 0 && !ReportAsNotCompiled;
public string Name
{
get => _name;
set
{
_name = value;
if (GLSystem.Debugging && WasCompiled) GL.ObjectLabel(TypeIdentifier, _id, _name.Length, _name);
}
}
/// <summary> /// <summary>
/// Returns the id for this object. /// Returns the id for this object.
/// <para>It will auto compile, if needed and allowed.</para> /// <para>It will auto compile, if needed and allowed.</para>
@ -55,7 +67,21 @@ namespace SM.OGL
[DebuggerStepThrough] [DebuggerStepThrough]
private void PerformCompile() private void PerformCompile()
{ {
if (!CanCompile) return;
Compile(); Compile();
if (GLSystem.Debugging && string.IsNullOrEmpty(_name))
{
try
{
GL.ObjectLabel(TypeIdentifier, _id, _name.Length, _name);
}
catch
{
// ignore
}
}
} }
/// <summary> /// <summary>
@ -85,13 +111,9 @@ namespace SM.OGL
Compile(); Compile();
} }
/// <summary> public override string ToString()
/// Names the object for debugging.
/// </summary>
/// <param name="name"></param>
public void Name(string name)
{ {
if (GLSystem.Debugging) GL.ObjectLabel(TypeIdentifier, _id, name.Length, name); return $"{GetType().Name} {(string.IsNullOrEmpty(_name) ? "" : $"\"{_name}\" ")}[{_id}]";
} }
public static void DisposeMarkedObjects() public static void DisposeMarkedObjects()

View file

@ -2,7 +2,6 @@
using System; using System;
using OpenTK; using OpenTK;
using OpenTK.Graphics.OpenGL;
#endregion #endregion

View file

@ -1,7 +1,6 @@
#region usings #region usings
using System; using System;
using System.Collections.Generic;
using OpenTK.Graphics.OpenGL4; using OpenTK.Graphics.OpenGL4;
#endregion #endregion
@ -17,21 +16,8 @@ namespace SM.OGL.Mesh
public static int LastID { get; internal set; } = -1; public static int LastID { get; internal set; } = -1;
/// <summary>
/// Generates the AttribDataIndex
/// </summary>
protected GenericMesh()
{
Attributes = new MeshAttributeList()
{
{0, "vertex", Vertex},
{1, "uv", UVs},
{2, "normal", Normals}
};
}
/// <inheritdoc /> /// <inheritdoc />
protected override bool AutoCompile { get; } = true; protected override bool AutoCompile { get; set; } = true;
/// <inheritdoc /> /// <inheritdoc />
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.VertexArray; public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.VertexArray;
@ -72,6 +58,19 @@ namespace SM.OGL.Mesh
/// </summary> /// </summary>
public virtual int[] Indices { get; set; } public virtual int[] Indices { get; set; }
/// <summary>
/// Generates the AttribDataIndex
/// </summary>
protected GenericMesh()
{
Attributes = new MeshAttributeList()
{
{0, "vertex", Vertex},
{1, "uv", UVs},
{2, "normal", Normals}
};
}
public void UpdateBoundingBox() public void UpdateBoundingBox()
{ {
BoundingBox.Update(this); BoundingBox.Update(this);

View file

@ -1,7 +1,13 @@
namespace SM.OGL.Mesh namespace SM.OGL.Mesh
{ {
/// <summary>
/// Represents a mesh that can be a line object.
/// </summary>
public interface ILineMesh public interface ILineMesh
{ {
/// <summary>
/// The width of a line.
/// </summary>
float LineWidth { get; set; } float LineWidth { get; set; }
} }
} }

View file

@ -1,7 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using OpenTK.Graphics.OpenGL;
namespace SM.OGL.Mesh namespace SM.OGL.Mesh
{ {

View file

@ -40,6 +40,10 @@ namespace SM.OGL.Mesh
/// </summary> /// </summary>
public int PointerStride; public int PointerStride;
/// <summary>
/// The VBO gets ignored when true.
/// <para>Default: true</para>
/// </summary>
public bool Active = true; public bool Active = true;
/// <summary> /// <summary>

View file

@ -1,7 +1,6 @@
#region usings #region usings
using System; using System;
using System.Linq;
using OpenTK.Graphics.OpenGL4; using OpenTK.Graphics.OpenGL4;
using SM.OGL.Mesh; using SM.OGL.Mesh;
@ -15,7 +14,7 @@ namespace SM.OGL.Shaders
public abstract class GenericShader : GLObject public abstract class GenericShader : GLObject
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override bool AutoCompile { get; } = true; protected override bool AutoCompile { get; set; } = true;
/// <summary> /// <summary>
/// Contains the different files for the shader. /// Contains the different files for the shader.
@ -97,7 +96,6 @@ namespace SM.OGL.Shaders
ShaderFileFiles.Append(this); ShaderFileFiles.Append(this);
GL.LinkProgram(_id); GL.LinkProgram(_id);
Name(GetType().Name);
ShaderFileFiles.Detach(this); ShaderFileFiles.Detach(this);
Uniforms = new UniformCollection {ParentShader = this}; Uniforms = new UniformCollection {ParentShader = this};

View file

@ -80,6 +80,7 @@ namespace SM.OGL.Shaders
for (var i = 0; i < GLSLExtensions.Count; i++) GLSLExtensions[i].Compile(shader, type); for (var i = 0; i < GLSLExtensions.Count; i++) GLSLExtensions[i].Compile(shader, type);
} }
/// <inheritdoc />
public override void Dispose() public override void Dispose()
{ {
GL.DeleteShader(this); GL.DeleteShader(this);

View file

@ -51,6 +51,12 @@ namespace SM.OGL.Shaders
Fragment = new []{fragment}; Fragment = new []{fragment};
} }
/// <summary>
/// Creates a collection with arrays of shader files.
/// </summary>
/// <param name="vertex"></param>
/// <param name="fragment"></param>
/// <param name="geometry"></param>
public ShaderFileCollection(ShaderFile[] vertex, ShaderFile[] fragment, ShaderFile[] geometry = default) public ShaderFileCollection(ShaderFile[] vertex, ShaderFile[] fragment, ShaderFile[] geometry = default)
{ {
Vertex = vertex; Vertex = vertex;

View file

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using OpenTK.Graphics.OpenGL;
namespace SM.OGL.Shaders namespace SM.OGL.Shaders
{ {

View file

@ -2,17 +2,47 @@
namespace SM.OGL.Texture namespace SM.OGL.Texture
{ {
/// <summary>
/// Stores information how pixels are stored in textures.
/// </summary>
public struct PixelInformation public struct PixelInformation
{ {
/// <summary>
/// RGB without Alpha channel, Low Dynamic Range (0 - 1)
/// </summary>
public static PixelInformation RGB_LDR = new PixelInformation(PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.UnsignedByte); public static PixelInformation RGB_LDR = new PixelInformation(PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.UnsignedByte);
/// <summary>
/// RGB without Alpha channel, High Dynamic Range (0 - n)
/// </summary>
public static PixelInformation RGB_HDR = new PixelInformation(PixelInternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.Float); public static PixelInformation RGB_HDR = new PixelInformation(PixelInternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.Float);
/// <summary>
/// RGB with Alpha channel, Low Dynamic Range (0 - 1)
/// </summary>
public static PixelInformation RGBA_LDR = new PixelInformation(PixelInternalFormat.Rgba, PixelFormat.Rgba, PixelType.UnsignedByte); public static PixelInformation RGBA_LDR = new PixelInformation(PixelInternalFormat.Rgba, PixelFormat.Rgba, PixelType.UnsignedByte);
/// <summary>
/// RGB with Alpha channel, High Dynamic Range (0 - n)
/// </summary>
public static PixelInformation RGBA_HDR = new PixelInformation(PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.Float); public static PixelInformation RGBA_HDR = new PixelInformation(PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.Float);
/// <summary>
/// The internal format of the pixels.
/// </summary>
public PixelInternalFormat InternalFormat { get; } public PixelInternalFormat InternalFormat { get; }
/// <summary>
/// The format of the pixels.
/// </summary>
public PixelFormat Format { get; } public PixelFormat Format { get; }
/// <summary>
/// The data type of the pixels,
/// </summary>
public PixelType DataType { get; } public PixelType DataType { get; }
/// <summary>
/// The constructor
/// </summary>
/// <param name="internalFormat"></param>
/// <param name="format"></param>
/// <param name="dataType"></param>
public PixelInformation(PixelInternalFormat internalFormat, PixelFormat format, PixelType dataType) public PixelInformation(PixelInternalFormat internalFormat, PixelFormat format, PixelType dataType)
{ {
InternalFormat = internalFormat; InternalFormat = internalFormat;

View file

@ -12,14 +12,20 @@ namespace SM.OGL.Texture
public abstract class TextureBase : GLObject public abstract class TextureBase : GLObject
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override bool AutoCompile { get; } = true; protected override bool AutoCompile { get; set; } = true;
/// <inheritdoc /> /// <inheritdoc />
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Texture; public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Texture;
/// <summary>
/// Contains the specific information of each pixel.
/// </summary>
public PixelInformation PixelInformation; public PixelInformation PixelInformation;
/// <summary>
/// The target of the texture.
/// </summary>
public TextureTarget Target { get; set; } = TextureTarget.Texture2D; public TextureTarget Target { get; set; } = TextureTarget.Texture2D;
/// <summary> /// <summary>
@ -44,6 +50,7 @@ namespace SM.OGL.Texture
/// </summary> /// </summary>
public virtual int Height { get; protected set; } public virtual int Height { get; protected set; }
/// <inheritdoc />
public override void Dispose() public override void Dispose()
{ {
GL.DeleteTexture(_id); GL.DeleteTexture(_id);

View file

@ -1,10 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Controls;
using OpenTK; using OpenTK;
using SM.Base.Controls; using SM.Base.Controls;
using SM.Base.Drawing;
using SM.Base.Scene; using SM.Base.Scene;
using SM.Utility;
using SM2D.Scene; using SM2D.Scene;
using SM2D.Types; using SM2D.Types;

View file

@ -1,15 +1,12 @@
#region usings #region usings
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using SM.Base;
using SM.Base.Drawing; using SM.Base.Drawing;
using SM.Base.Objects.Static;
using SM.Base.Scene; using SM.Base.Scene;
using SM.Base.Textures; using SM.Base.Textures;
using SM.Base.Windows; using SM.Base.Window;
using SM.OGL.Texture; using SM.OGL.Texture;
using SM2D.Scene; using SM2D.Scene;

View file

@ -1,15 +1,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using SM.Base;
using SM.Base.Drawing; using SM.Base.Drawing;
using SM.Base.Objects; using SM.Base.Shaders;
using SM.Base.Textures; using SM.Base.Textures;
using SM.Base.Windows; using SM.Base.Window;
using SM.OGL.Mesh;
using SM2D.Object; using SM2D.Object;
using SM2D.Scene;
using SM2D.Types; using SM2D.Types;
namespace SM2D.Drawing namespace SM2D.Drawing

View file

@ -1,8 +1,7 @@
using System; using System;
using OpenTK; using OpenTK;
using SM.Base.Drawing.Particles; using SM.Base.Drawing.Particles;
using SM.Utility; using SM.Base.Utility;
using SM2D.Scene;
using SM2D.Types; using SM2D.Types;
namespace SM2D.Drawing namespace SM2D.Drawing

View file

@ -1,10 +1,8 @@
#region usings #region usings
using SM.Base;
using SM.Base.Drawing.Text; using SM.Base.Drawing.Text;
using SM.Base.Types; using SM.Base.Types;
using SM.Base.Windows; using SM.Base.Window;
using SM2D.Scene;
using SM2D.Types; using SM2D.Types;
#endregion #endregion

View file

@ -1,8 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using OpenTK; using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL4; using OpenTK.Graphics.OpenGL4;
using SM.Base.Objects;
using SM.OGL.Mesh; using SM.OGL.Mesh;
namespace SM2D.Object namespace SM2D.Object
@ -16,8 +14,6 @@ namespace SM2D.Object
public class PolyLine : Polygon, ILineMesh public class PolyLine : Polygon, ILineMesh
{ {
public float LineWidth { get; set; } = 1;
public PolyLine(ICollection<Vector2> vertices, PolyLineType lineType = PolyLineType.NotConnected) : base(vertices) public PolyLine(ICollection<Vector2> vertices, PolyLineType lineType = PolyLineType.NotConnected) : base(vertices)
{ {
UVs.Active = false; UVs.Active = false;

View file

@ -3,7 +3,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using OpenTK; using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL4; using OpenTK.Graphics.OpenGL4;
using SM.Base.Objects; using SM.Base.Objects;
using SM.OGL.Mesh; using SM.OGL.Mesh;

View file

@ -1,9 +1,5 @@
using System; using SM.Base.Shaders;
using OpenTK.Graphics.OpenGL4; using SM.Base.Window;
using SM.Base;
using SM.Base.Drawing;
using SM.Base.Windows;
using SM.OGL.Framebuffer;
using SM2D.Shader; using SM2D.Shader;
namespace SM2D.Pipelines namespace SM2D.Pipelines

View file

@ -31,13 +31,9 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Controls\Mouse2D.cs" /> <Compile Include="Controls\Mouse2D.cs" />

View file

@ -1,12 +1,10 @@
#region usings #region usings
using System; using System;
using System.Runtime.Serialization.Formatters;
using OpenTK; using OpenTK;
using SM.Base;
using SM.Base.Scene; using SM.Base.Scene;
using SM.Base.Types; using SM.Base.Types;
using SM.Base.Windows; using SM.Base.Window;
#endregion #endregion

View file

@ -1,9 +1,8 @@
#region usings #region usings
using SM.Base;
using SM.Base.Scene; using SM.Base.Scene;
using SM.Base.Types; using SM.Base.Types;
using SM.Base.Windows; using SM.Base.Window;
using SM2D.Types; using SM2D.Types;
#endregion #endregion

View file

@ -1,12 +1,10 @@
#region usings #region usings
using System.Drawing.Drawing2D;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using SM.Base;
using SM.Base.Objects.Static; using SM.Base.Objects.Static;
using SM.Base.Scene; using SM.Base.Scene;
using SM.Base.Windows; using SM.Base.Window;
using SM2D.Drawing; using SM2D.Drawing;
#endregion #endregion

View file

@ -1,7 +1,7 @@
using SM.Base.Drawing; using SM.Base.Shaders;
using SM.Base.Windows; using SM.Base.Utility;
using SM.Base.Window;
using SM.OGL.Shaders; using SM.OGL.Shaders;
using SM.Utility;
namespace SM2D.Shader namespace SM2D.Shader
{ {

View file

@ -1,13 +1,10 @@
#region usings #region usings
using System;
using System.Drawing.Drawing2D;
using OpenTK; using OpenTK;
using SM.Base.Drawing; using SM.Base.Drawing;
using SM.Base.Scene;
using SM.Base.Textures; using SM.Base.Textures;
using SM.Base.Types; using SM.Base.Types;
using SM.Utility; using SM.Base.Utility;
#endregion #endregion

View file

@ -1,5 +1,5 @@
using OpenTK; using OpenTK;
using SM.Base.Windows; using SM.Base.Window;
namespace SM2D namespace SM2D
{ {

View file

@ -1,9 +1,7 @@
using System.Drawing.Drawing2D; using OpenTK;
using OpenTK;
using OpenTK.Graphics.OpenGL4; using OpenTK.Graphics.OpenGL4;
using SM.Base; using SM.Base;
using SM.Base.PostProcess; using SM.Base.Window;
using SM.Base.Windows;
using SM2D.Scene; using SM2D.Scene;
using SM2D.Shader; using SM2D.Shader;

View file

@ -1,5 +1,4 @@
using System; using System;
using OpenTK.Input;
namespace SM.Game.Controls namespace SM.Game.Controls
{ {

View file

@ -1,6 +1,4 @@
using System; using OpenTK.Input;
using System.Collections.Generic;
using OpenTK.Input;
namespace SM.Game.Controls namespace SM.Game.Controls
{ {

View file

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using OpenTK.Input;
namespace SM.Game.Controls namespace SM.Game.Controls
{ {

View file

@ -1,7 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using OpenTK.Input;
namespace SM.Game.Controls namespace SM.Game.Controls
{ {

View file

@ -1,5 +1,4 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following

View file

@ -42,12 +42,6 @@
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Controls\GameController.cs" /> <Compile Include="Controls\GameController.cs" />

View file

@ -1,9 +1,7 @@
using System; using OpenTK;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input; using OpenTK.Input;
using SM.Base; using SM.Base;
using SM.Base.Windows; using SM.Base.Window;
using SM.Game.Controls; using SM.Game.Controls;
using SM2D; using SM2D;
using SM2D.Drawing; using SM2D.Drawing;

View file

@ -1,5 +1,4 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following

View file

@ -45,12 +45,6 @@
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />

View file

@ -1,25 +1,25 @@
using System.Collections.Generic; using OpenTK.Graphics.OpenGL4;
using OpenTK.Graphics.OpenGL4;
using SM.Base;
using SM.Base;
using SM.Base.Drawing;
using SM.Base.PostEffects; using SM.Base.PostEffects;
using SM.Base.Windows; using SM.Base.Window;
using SM.OGL.Framebuffer; using SM.OGL.Framebuffer;
using SM2D.Scene;
namespace SM_TEST namespace SM_TEST
{ {
public class TestRenderPipeline : RenderPipeline public class TestRenderPipeline : RenderPipeline
{ {
private BloomEffect _bloom; private BloomEffect _bloom;
private Framebuffer _postBuffer;
public override void Initialization() public override void Initialization()
{ {
_bloom = new BloomEffect(hdr: true);
MainFramebuffer = CreateWindowFramebuffer(); MainFramebuffer = CreateWindowFramebuffer(2);
_postBuffer = CreateWindowFramebuffer();
Framebuffers.Add(_postBuffer);
_bloom = new BloomEffect(_postBuffer, hdr: true);
_bloom.Initilize(this); _bloom.Initilize(this);
base.Initialization(); base.Initialization();
} }
@ -29,11 +29,13 @@ namespace SM_TEST
MainFramebuffer.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); MainFramebuffer.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
context.Scene.DrawBackground(context); context.Scene.DrawBackground(context);
context.Scene.DrawMainObjects(context); context.Scene.DrawMainObjects(context);
context.Scene.DrawHUD(context);
PostProcessFinals.ResolveMultisampledBuffers(MainFramebuffer, _postBuffer);
Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
_bloom.Draw(context); _bloom.Draw(context);
context.Scene.DrawHUD(context);
context.Scene.DrawDebug(context); context.Scene.DrawDebug(context);
} }
} }

View file

@ -1,10 +1,4 @@
using System; using System.Windows;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace SM_WPF_TEST namespace SM_WPF_TEST
{ {

View file

@ -1,22 +1,4 @@
using System; using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using OpenTK.Graphics;
using SM2D;
using SM2D.Drawing;
using SM2D.Pipelines;
using SM2D.Scene;
namespace SM_WPF_TEST namespace SM_WPF_TEST
{ {

Some files were not shown because too many files have changed in this diff Show more