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

View file

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

View file

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

View file

@ -12,12 +12,18 @@ namespace SM.Base.Drawing
public abstract class GenericTransformation
{
/// <summary>
/// If true, ignores the transformation and sends <see cref="Matrix4.Identity"/>, when requested.
/// If true, ignores the transformation and sends <see cref="Matrix4.Identity" />, when requested.
/// </summary>
public bool Ignore = false;
/// <summary>
/// The last matrix that was used to calculate the real world matrix.
/// </summary>
public Matrix4 LastMaster { get; internal set; }
/// <summary>
/// The transformation in world space.
/// </summary>
public Matrix4 InWorldSpace => MergeMatrix(LastMaster);
/// <summary>

View file

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

View file

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

View file

@ -1,4 +1,8 @@
using SM.Base.Time;
#region usings
using SM.Base.Time;
#endregion
namespace SM.Base.Drawing.Particles
{
@ -8,11 +12,12 @@ namespace SM.Base.Drawing.Particles
public struct ParticleContext
{
/// <summary>
/// The Timer of the particles
/// The Timer of the particles
/// </summary>
public Timer Timer;
/// <summary>
/// The current speed of the particles.
/// The current speed of the particles.
/// </summary>
public float Speed;
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,31 +1,54 @@
using System.Windows.Controls;
#region usings
using OpenTK.Graphics.OpenGL4;
using SM.Base.PostProcess;
using SM.Base.Windows;
using SM.Base.Utility;
using SM.OGL.Framebuffer;
using SM.Utility;
#endregion
namespace SM.Base.PostEffects
{
public class PostProcessFinals
/// <summary>
/// This class has some utility for render pipelines
/// </summary>
public static class PostProcessFinals
{
static PostProcessShader _hdrExposureShader = new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath+".finalize_hdr.glsl"));
static PostProcessShader _gammaShader = new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".finalize_gamma.glsl"));
private static readonly PostProcessShader _hdrExposureShader =
new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".finalize_hdr.glsl"));
private static readonly PostProcessShader _gammaShader =
new PostProcessShader(
AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".finalize_gamma.glsl"));
/// <summary>
/// The gamma that is used for <see cref="FinalizeGamma"/> and <see cref="FinalizeHDR"/>.
/// </summary>
public static float Gamma = 2.2f;
/// <summary>
/// This resolves a multisampled framebuffer to a non-multisampled renderbuffer.
/// </summary>
/// <param name="multisampledBuffers"></param>
/// <param name="target"></param>
public static void ResolveMultisampledBuffers(Framebuffer multisampledBuffers, Framebuffer target)
{
multisampledBuffers.Activate(FramebufferTarget.ReadFramebuffer);
target.Activate(FramebufferTarget.DrawFramebuffer);
GL.BlitFramebuffer(0, 0, (int)multisampledBuffers.Size.X, (int)multisampledBuffers.Size.Y, 0, 0, (int)target.Size.X, (int)target.Size.Y, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Nearest);
GL.BlitFramebuffer(0, 0, (int) multisampledBuffers.Size.X, (int) multisampledBuffers.Size.Y, 0, 0,
(int) target.Size.X, (int) target.Size.Y, ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit,
BlitFramebufferFilter.Nearest);
target.Activate();
}
/// <summary>
/// This converts HDR to LDR and applys gamma.
/// </summary>
/// <param name="attachment"></param>
/// <param name="exposure"></param>
public static void FinalizeHDR(ColorAttachment attachment, float exposure)
{
_hdrExposureShader.Draw(u =>
{
u["Gamma"].SetUniform1(Gamma);
@ -34,6 +57,10 @@ namespace SM.Base.PostEffects
});
}
/// <summary>
/// This applys gamma
/// </summary>
/// <param name="attachment"></param>
public static void FinalizeGamma(ColorAttachment attachment)
{
_gammaShader.Draw(u =>

View file

@ -1,19 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
#region usings
using OpenTK;
using OpenTK.Graphics.OpenGL4;
using SM.Base;
using SM.Base.Objects.Static;
using SM.Base.Scene;
using SM.Base.Windows;
using SM.OGL.Framebuffer;
using SM.OGL.Shaders;
using SM.Base.Window;
#endregion
namespace SM.Base.PostProcess
{
/// <summary>
/// Basis for a post process effect
/// Basis for a post process effect
/// </summary>
public abstract class PostProcessEffect
{
@ -22,7 +18,7 @@ namespace SM.Base.PostProcess
protected RenderPipeline Pipeline;
/// <summary>
/// Initialize the effect.
/// Initialize the effect.
/// </summary>
/// <param name="pipeline"></param>
public void Initilize(RenderPipeline pipeline)
@ -30,24 +26,25 @@ namespace SM.Base.PostProcess
Pipeline = pipeline;
InitProcess();
}
/// <summary>
/// Method, to initialize the shader.
/// </summary>
protected virtual void InitProcess() {}
/// <summary>
/// Method to draw the actual effect.
/// Method, to initialize the shader.
/// </summary>
protected virtual void InitProcess()
{
}
/// <summary>
/// Method to draw the actual effect.
/// </summary>
public abstract void Draw(DrawContext context);
/// <summary>
/// Event, when the scene changed.
/// Event, when the scene changed.
/// </summary>
public virtual void SceneChanged(GenericScene scene)
{
}
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,9 +1,8 @@
#region usings
using System.Collections.Generic;
using SM.Base;
using SM.Base.Drawing;
using SM.Base.Windows;
using SM.Base.Window;
using SM.OGL.Mesh;
#endregion
@ -50,7 +49,7 @@ namespace SM.Base.Scene
void OnRemoved(object sender);
}
public interface ITransformItem<TTransform>
public interface ITransformItem<TTransform>
where TTransform : GenericTransformation
{
TTransform Transform { get; set; }
@ -58,7 +57,8 @@ namespace SM.Base.Scene
public interface IShowTransformItem<TTransform> : IShowItem, ITransformItem<TTransform>
where TTransform : GenericTransformation
{}
{
}
public interface IModelItem
{

View file

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

View file

@ -1,14 +1,13 @@
#region usings
using OpenTK.Graphics.OpenGL4;
using SM.Base;
using SM.Base.Windows;
using SM.Base.Window;
using SM.OGL.Mesh;
using SM.OGL.Shaders;
#endregion
namespace SM.Base.Drawing
namespace SM.Base.Shaders
{
/// <summary>
/// A general class to work with material shaders properly.
@ -17,7 +16,8 @@ namespace SM.Base.Drawing
{
/// <inheritdoc />
protected MaterialShader(string combinedData) : base(combinedData)
{}
{
}
/// <inheritdoc />
protected MaterialShader(string vertex, string fragment) : base(vertex, fragment)
@ -39,16 +39,20 @@ namespace SM.Base.Drawing
context.Mesh.Activate();
if (context.Mesh is ILineMesh lineMesh)
GL.LineWidth(context.Material.ShaderArguments.Get("LineWidth", lineMesh.LineWidth));
if (context.Mesh is ILineMesh lineMesh)
GL.LineWidth(context.Material.ShaderArguments.Get("LineWidth", lineMesh.LineWidth));
else if (context.Material.ShaderArguments.ContainsKey("LineWidth"))
GL.LineWidth((float)context.Material.ShaderArguments["LineWidth"]);
GL.LineWidth((float) context.Material.ShaderArguments["LineWidth"]);
if (context.Material.Blending)
{
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
} else GL.Disable(EnableCap.Blend);
}
else
{
GL.Disable(EnableCap.Blend);
}
DrawProcess(context);

View file

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

View file

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

View file

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

View file

@ -2,8 +2,7 @@
using System;
using System.Collections.Generic;
using SM.Base;
using SM.Base.Windows;
using SM.Base.Window;
#endregion
@ -14,17 +13,17 @@ namespace SM.Base.Time
/// </summary>
public class Stopwatch
{
private static List<Stopwatch> _activeStopwatches = new List<Stopwatch>();
private bool _paused = false;
private static readonly List<Stopwatch> _activeStopwatches = new List<Stopwatch>();
private bool _paused;
/// <summary>
/// If true, the stopwatch was started.
/// <para>This doesn't changed when paused.</para>
/// If true, the stopwatch was started.
/// <para>This doesn't changed when paused.</para>
/// </summary>
public bool Active { get; private set; } = false;
public bool Active { get; private set; }
/// <summary>
/// Gets/Sets if the stopwatch is paused.
/// Gets/Sets if the stopwatch is paused.
/// </summary>
public bool Paused
{
@ -39,7 +38,7 @@ namespace SM.Base.Time
}
/// <summary>
/// If true, the stopwatch is active and not paused... (who would have guessed...)
/// If true, the stopwatch is active and not paused... (who would have guessed...)
/// </summary>
public bool Running => Active && !Paused;
@ -53,6 +52,9 @@ namespace SM.Base.Time
/// </summary>
public TimeSpan ElapsedSpan { get; protected set; }
/// <summary>
/// This event gets triggered every tick.
/// </summary>
public event Action<Stopwatch, UpdateContext> Tick;
/// <summary>
@ -66,7 +68,6 @@ namespace SM.Base.Time
Active = true;
}
/// <summary>
/// Performs a tick.
@ -81,15 +82,15 @@ namespace SM.Base.Time
}
/// <summary>
/// Resumes the timer.
/// Resumes the timer.
/// </summary>
protected virtual void Resume()
{
_paused = false;
}
/// <summary>
/// Pauses the timer.
/// Pauses the timer.
/// </summary>
protected virtual void Pause()
{

View file

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

View file

@ -1,39 +1,18 @@
using System;
using OpenTK;
#region usings
using System;
#endregion
namespace SM.Base.Types
{
/// <summary>
/// A One-dimensional Vector (also known as <see cref="float"/>), in a class.
/// A One-dimensional Vector (also known as <see cref="float" />), in a class.
/// </summary>
public class CVector1
{
/// <summary>
/// X - Component
/// </summary>
public float X
{
get;
set;
}
/// <summary>
/// The length/magnitute of the vector.
/// </summary>
public float Length => GetLength();
/// <summary>
/// Gets the square of the vector length (magnitude).
/// </summary>
/// <remarks>
/// This property avoids the costly square root operation required by the Length property. This makes it more suitable
/// for comparisons.
/// </remarks>
public float LengthSquared => GetLength(true);
public event Action Changed;
/// <summary>
/// Creates a class vector
/// Creates a class vector
/// </summary>
/// <param name="x">X-Component</param>
public CVector1(float x)
@ -41,10 +20,33 @@ namespace SM.Base.Types
X = x;
}
/// <summary>
/// X - Component
/// </summary>
public float X { get; set; }
/// <summary>
/// Get the length of the vector.
/// The length/magnitute of the vector.
/// </summary>
public float Length => GetLength();
/// <summary>
/// Gets the square of the vector length (magnitude).
/// </summary>
/// <remarks>
/// This property avoids the costly square root operation required by the Length property. This makes it more suitable
/// for comparisons.
/// </remarks>
public float LengthSquared => GetLength(true);
/// <summary>
/// This event triggers when a component changed.
/// </summary>
public event Action Changed;
/// <summary>
/// Get the length of the vector.
/// </summary>
/// <param name="squared">If true, it will return the squared product.</param>
/// <returns></returns>
@ -57,7 +59,7 @@ namespace SM.Base.Types
/// <summary>
/// Normalizes the vector.
/// Normalizes the vector.
/// </summary>
public void Normalize()
{
@ -66,7 +68,7 @@ namespace SM.Base.Types
}
/// <summary>
/// Sets the X-Component.
/// Sets the X-Component.
/// </summary>
/// <param name="x">X-Component</param>
public virtual void Set(float uniform, bool triggerChanged = true)
@ -75,6 +77,11 @@ namespace SM.Base.Types
if (triggerChanged) TriggerChanged();
}
/// <summary>
/// Adds the value to the components.
/// </summary>
/// <param name="uniform"></param>
/// <param name="triggerChanged"></param>
public virtual void Add(float uniform, bool triggerChanged = true)
{
X += uniform;
@ -82,20 +89,24 @@ namespace SM.Base.Types
}
/// <summary>
/// Conversion into <see cref="float"/>
/// Conversion into <see cref="float" />
/// </summary>
public static implicit operator float(CVector1 vector1) => vector1.X;
public static implicit operator float(CVector1 vector1)
{
return vector1.X;
}
/// <summary>
/// Conversion from <see cref="float"/> to One-dimensional Vector.
/// Conversion from <see cref="float" /> to One-dimensional Vector.
/// </summary>
/// <param name="f"></param>
/// <returns></returns>
//public static implicit operator CVector1(float f) => new CVector1(f);
protected virtual float GetLengthProcess()
{
return X * X;
}
protected virtual void NormalizationProcess(float length)
{
X *= length;

View file

@ -1,19 +1,18 @@
using OpenTK;
#region usings
using OpenTK;
#endregion
namespace SM.Base.Types
{
/// <summary>
/// A two-dimensional vector.
/// A two-dimensional vector.
/// </summary>
public class CVector2 : CVector1
{
/// <summary>
/// Y-component
/// </summary>
public float Y { get; set; }
/// <summary>
/// Creates a vector, where each component is the same value.
/// Creates a vector, where each component is the same value.
/// </summary>
/// <param name="uniform">The Value</param>
public CVector2(float uniform) : base(uniform)
@ -22,18 +21,25 @@ namespace SM.Base.Types
}
/// <summary>
/// Creates a vector
/// Creates a vector
/// </summary>
public CVector2(float x, float y) : base(x)
{
Y = y;
}
/// <summary>
/// Y-component
/// </summary>
public float Y { get; set; }
/// <inheritdoc />
protected override float GetLengthProcess()
{
return base.GetLengthProcess() + Y * Y;
}
/// <inheritdoc />
protected override void NormalizationProcess(float length)
{
base.NormalizationProcess(length);
@ -41,7 +47,7 @@ namespace SM.Base.Types
}
/// <summary>
/// Sets each component to the same value
/// Sets each component to the same value
/// </summary>
/// <param name="uniform"></param>
public override void Set(float uniform, bool triggerChanged = true)
@ -51,7 +57,7 @@ namespace SM.Base.Types
}
/// <summary>
/// Sets each component to the <see cref="Vector2"/> counter-part.
/// Sets each component to the <see cref="Vector2" /> counter-part.
/// </summary>
/// <param name="vector"></param>
public void Set(Vector2 vector, bool triggerChanged = true)
@ -60,7 +66,7 @@ namespace SM.Base.Types
}
/// <summary>
/// Sets the a own value to each component.
/// Sets the a own value to each component.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
@ -70,17 +76,29 @@ namespace SM.Base.Types
base.Set(x, triggerChanged);
}
/// <inheritdoc />
public override void Add(float uniform, bool triggerChanged = true)
{
Y += uniform;
base.Add(uniform, triggerChanged);
}
/// <summary>
/// Adds <see cref="Vector2"/> to the CVector.
/// </summary>
/// <param name="vector"></param>
/// <param name="triggerChanged">If false, the event Changed doesn't gets triggered </param>
public void Add(Vector2 vector, bool triggerChanged = true)
{
Add(vector.X, vector.Y, triggerChanged);
}
/// <summary>
/// Adds the values to the CVector.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="triggerChanged">If false, the event Changed doesn't gets triggered </param>
public void Add(float x, float y, bool triggerChanged = true)
{
Y += y;
@ -88,12 +106,19 @@ namespace SM.Base.Types
}
/// <summary>
/// Converts to <see cref="Vector2"/>
/// Converts to <see cref="Vector2" />
/// </summary>
public static implicit operator Vector2(CVector2 vector2) => new Vector2(vector2.X, vector2.Y);
public static implicit operator Vector2(CVector2 vector2)
{
return new Vector2(vector2.X, vector2.Y);
}
/// <summary>
/// Converts from <see cref="Vector2"/> to <see cref="CVector2"/>.
/// Converts from <see cref="Vector2" /> to <see cref="CVector2" />.
/// </summary>
public static implicit operator CVector2(Vector2 vector2) => new CVector2(vector2.X, vector2.Y);
public static implicit operator CVector2(Vector2 vector2)
{
return new CVector2(vector2.X, vector2.Y);
}
}
}

View file

@ -1,38 +1,45 @@
using OpenTK;
#region usings
using OpenTK;
#endregion
namespace SM.Base.Types
{
/// <summary>
/// A three-dimensional vector.
/// A three-dimensional vector.
/// </summary>
public class CVector3 : CVector2
{
/// <summary>
/// Z-component
/// </summary>
public float Z { get; set; }
/// <summary>
/// Creates a vector, where each component is the same value.
/// Creates a vector, where each component is the same value.
/// </summary>
/// <param name="uniform">The Value</param>
public CVector3(float uniform) : base(uniform)
{
Z = uniform;
}
/// <summary>
/// Creates a vector
/// Creates a vector
/// </summary>
public CVector3(float x, float y, float z) : base(x, y)
{
Z = z;
}
/// <summary>
/// Z-component
/// </summary>
public float Z { get; set; }
/// <inheritdoc />
protected override float GetLengthProcess()
{
return base.GetLengthProcess() + Z * Z;
}
/// <inheritdoc />
protected override void NormalizationProcess(float length)
{
base.NormalizationProcess(length);
@ -47,15 +54,16 @@ namespace SM.Base.Types
}
/// <summary>
/// Sets the a own value to each component.
/// Sets the a own value to each component.
/// </summary>
public void Set(float x, float y, float z, bool triggerChanged = true)
{
Z = z;
base.Set(x,y, triggerChanged);
base.Set(x, y, triggerChanged);
}
/// <summary>
/// Sets each component to the <see cref="Vector3"/> counter-part.
/// Sets each component to the <see cref="Vector3" /> counter-part.
/// </summary>
/// <param name="vector"></param>
public void Set(Vector3 vector, bool triggerChanged = true)
@ -63,30 +71,50 @@ namespace SM.Base.Types
Set(vector.X, vector.Y, vector.Z, triggerChanged);
}
/// <inheritdoc />
public override void Add(float uniform, bool triggerChanged = true)
{
Z += uniform;
base.Add(uniform, triggerChanged);
}
/// <summary>
/// Adds a <see cref="Vector3"/> to the CVector.
/// </summary>
/// <param name="vector"></param>
/// <param name="triggerChanged">If false, the event Changed doesn't gets triggered </param>
public void Add(Vector3 vector, bool triggerChanged = true)
{
Add(vector.X, vector.Y, vector.Z, triggerChanged);
}
/// <summary>
/// Adds the values to the CVector.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <param name="triggerChanged">If false, the event Changed doesn't gets triggered </param>
public void Add(float x, float y, float z, bool triggerChanged = true)
{
Z += z;
base.Add(x,y, triggerChanged);
base.Add(x, y, triggerChanged);
}
/// <summary>
/// Converts to <see cref="Vector3"/>
/// Converts to <see cref="Vector3" />
/// </summary>
public static implicit operator Vector3(CVector3 vector) => new Vector3(vector.X, vector.Y, vector.Z);
public static implicit operator Vector3(CVector3 vector)
{
return new Vector3(vector.X, vector.Y, vector.Z);
}
/// <summary>
/// Converts from <see cref="Vector3"/> to <see cref="CVector3"/>.
/// Converts from <see cref="Vector3" /> to <see cref="CVector3" />.
/// </summary>
public static implicit operator CVector3(Vector3 vector) => new CVector3(vector.X, vector.Y, vector.Z);
public static implicit operator CVector3(Vector3 vector)
{
return new CVector3(vector.X, vector.Y, vector.Z);
}
}
}

View file

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

View file

@ -1,4 +1,4 @@
namespace SM.Utility
namespace SM.Base.Utility
{
/// <summary>
/// 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
{
bool IsInitialized { get; set; }

View file

@ -1,13 +1,11 @@
#region usings
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace SM.Utility
namespace SM.Base.Utility
{
/// <summary>
/// A global helper class for randomization.
@ -85,7 +83,7 @@ namespace SM.Utility
}
/// <summary>
/// Gets a random item from the provided list.
/// Gets a random item from the provided list.
/// </summary>
public static TSource GetRandomItem<TSource>(this IList<TSource> list)
{

View file

@ -1,11 +1,12 @@
using System;
using System.Windows;
#region usings
using System;
using OpenTK;
using SM.Base.Drawing;
using SM.Base.Scene;
using SM.OGL.Mesh;
namespace SM.Utility
#endregion
namespace SM.Base.Utility
{
public struct Ray
{
@ -23,9 +24,9 @@ namespace SM.Utility
distance = 0.0f;
float tMin = 0.0f;
float tMax = 100000.0f;
Vector3 delta = modelMatrix.Row3.Xyz - Position;
for (int i = 0; i < 3; i++)
{
Vector3 axis = new Vector3(modelMatrix[i, 0], modelMatrix[i, 1], modelMatrix[i, 2]);
@ -35,7 +36,6 @@ namespace SM.Utility
if (Math.Abs(f) > 0.001f)
{
float t1 = (e + box.Min[i]) / f;
float t2 = (e + box.Max[i]) / f;
@ -54,7 +54,7 @@ namespace SM.Utility
}
else
{
if (-e + box.Min[i] > 0.0f || -e + box.Max[i] < 0.0f)
if (-e + box.Min[i] > 0.0f || -e + box.Max[i] < 0.0f)
return false;
}
}

View file

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

View file

@ -1,7 +1,6 @@
namespace SM.Utility
namespace SM.Base.Utility
{
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
{
@ -11,6 +15,7 @@ namespace SM.Utility
obj.Initialization();
obj.IsInitialized = true;
}
obj.Activate();
}

View file

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

View file

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

View file

@ -1,20 +1,39 @@
using System;
using System.Windows;
#region usings
using System;
using System.Windows.Forms;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
using SM.Base.Controls;
using SM.Base.Scene;
using SM.OGL;
using Mouse = SM.Base.Controls.Mouse;
namespace SM.Base.Windows
#endregion
namespace SM.Base.Window
{
public class GLWindow : GameWindow, IGenericWindow
{
private Vector2 _flagWindowSize;
public WindowFlags WindowFlags;
public GLWindow() : this(1280, 720, "Generic OpenGL Title", WindowFlags.Window)
{
}
public GLWindow(int width, int height, string title, WindowFlags flags, VSyncMode vSync = VSyncMode.On) :
base(width, height, default, title, (GameWindowFlags) flags, DisplayDevice.Default,
GLSettings.ForcedVersion.MajorVersion, GLSettings.ForcedVersion.MinorVersion,
GraphicsContextFlags.Default)
{
VSync = vSync;
_flagWindowSize = new Vector2(width, height);
ChangeWindowFlag(flags);
}
public bool Loading { get; private set; } = true;
public float AspectRatio { get; set; }
@ -29,78 +48,12 @@ namespace SM.Base.Windows
public ISetup AppliedSetup { get; private set; }
public event Action<IGenericWindow> Resize;
public event Action<IGenericWindow> Load;
public event Action<IGenericWindow> Loaded;
public GenericScene CurrentScene { get; private set; }
public RenderPipeline CurrentRenderPipeline { get; private set; }
public WindowFlags WindowFlags;
public GLWindow() : this(1280, 720, "Generic OpenGL Title", WindowFlags.Window) {}
public GLWindow(int width, int height, string title, WindowFlags flags, VSyncMode vSync = VSyncMode.On) :
base(width, height, default, title, (GameWindowFlags)flags, DisplayDevice.Default, GLSettings.ForcedVersion.MajorVersion, GLSettings.ForcedVersion.MinorVersion, GraphicsContextFlags.Default)
{
VSync = vSync;
_flagWindowSize = new Vector2(width, height);
ChangeWindowFlag(flags);
}
protected override void OnLoad(EventArgs e)
{
WindowCode.Load(this);
SMRenderer.CurrentWindow = this;
base.OnLoad(e);
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
WindowCode.Resize(this);
if (WindowFlags == WindowFlags.Window) _flagWindowSize = WindowSize;
if (Loading)
{
Loading = false;
Loaded?.Invoke(this);
AppliedSetup?.Loaded(this);
}
}
protected override void OnUpdateFrame(FrameEventArgs e)
{
if (!Focused && !UpdateWhileUnfocused) return;
base.OnUpdateFrame(e);
WindowCode.Update(this, (float)e.Time);
}
protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);
WindowCode.Render(this, (float)e.Time);
SwapBuffers();
GLDebugging.CheckGLErrors();
}
protected override void OnMouseMove(MouseMoveEventArgs e)
{
base.OnMouseMove(e);
Mouse.MouseMoveEvent(e, this);
}
public void Update(UpdateContext context)
{
}
public void ApplySetup(ISetup setup)
@ -133,9 +86,68 @@ namespace SM.Base.Windows
CurrentRenderPipeline = renderPipeline;
}
public void TriggerLoad() => Load?.Invoke(this);
public void TriggerLoad()
{
Load?.Invoke(this);
}
public void TriggerResize() => Resize?.Invoke(this);
public void TriggerResize()
{
Resize?.Invoke(this);
}
public event Action<IGenericWindow> Loaded;
protected override void OnLoad(EventArgs e)
{
WindowCode.Load(this);
SMRenderer.CurrentWindow = this;
base.OnLoad(e);
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
WindowCode.Resize(this);
if (WindowFlags == WindowFlags.Window) _flagWindowSize = WindowSize;
if (Loading)
{
Loading = false;
Loaded?.Invoke(this);
AppliedSetup?.Loaded(this);
}
}
protected override void OnUpdateFrame(FrameEventArgs e)
{
if (!Focused && !UpdateWhileUnfocused) return;
base.OnUpdateFrame(e);
WindowCode.Update(this, (float) e.Time);
}
protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);
WindowCode.Render(this, (float) e.Time);
SwapBuffers();
GLDebugging.CheckGLErrors();
}
protected override void OnMouseMove(MouseMoveEventArgs e)
{
base.OnMouseMove(e);
Mouse.MouseMoveEvent(e, this);
}
public void ChangeWindowFlag(WindowFlags newFlag)
{
@ -144,14 +156,14 @@ namespace SM.Base.Windows
switch (newFlag)
{
case WindowFlags.Window:
Width = (int)_flagWindowSize.X;
Height = (int)_flagWindowSize.Y;
Width = (int) _flagWindowSize.X;
Height = (int) _flagWindowSize.Y;
WindowBorder = WindowBorder.Resizable;
break;
case WindowFlags.BorderlessWindow:
WindowBorder = WindowBorder.Hidden;
X = Screen.PrimaryScreen.Bounds.Left;
Y = Screen.PrimaryScreen.Bounds.Top;
Width = Screen.PrimaryScreen.Bounds.Width;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,7 +1,6 @@
#region usings
using System;
using System.Collections.Generic;
using OpenTK.Graphics.OpenGL4;
#endregion
@ -17,21 +16,8 @@ namespace SM.OGL.Mesh
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 />
protected override bool AutoCompile { get; } = true;
protected override bool AutoCompile { get; set; } = true;
/// <inheritdoc />
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.VertexArray;
@ -72,6 +58,19 @@ namespace SM.OGL.Mesh
/// </summary>
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()
{
BoundingBox.Update(this);

View file

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

View file

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

View file

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

View file

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

View file

@ -51,6 +51,12 @@ namespace SM.OGL.Shaders
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)
{
Vertex = vertex;

View file

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

View file

@ -2,17 +2,47 @@
namespace SM.OGL.Texture
{
/// <summary>
/// Stores information how pixels are stored in textures.
/// </summary>
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);
/// <summary>
/// RGB without Alpha channel, High Dynamic Range (0 - n)
/// </summary>
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);
/// <summary>
/// RGB with Alpha channel, High Dynamic Range (0 - n)
/// </summary>
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; }
/// <summary>
/// The format of the pixels.
/// </summary>
public PixelFormat Format { get; }
/// <summary>
/// The data type of the pixels,
/// </summary>
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)
{
InternalFormat = internalFormat;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -42,12 +42,6 @@
</Reference>
<Reference Include="System" />
<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>
<Compile Include="Controls\GameController.cs" />

View file

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

View file

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

View file

@ -45,12 +45,6 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<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>
<Compile Include="Program.cs" />

View file

@ -1,25 +1,25 @@
using System.Collections.Generic;
using OpenTK.Graphics.OpenGL4;
using SM.Base;
using SM.Base;
using SM.Base.Drawing;
using OpenTK.Graphics.OpenGL4;
using SM.Base.PostEffects;
using SM.Base.Windows;
using SM.Base.Window;
using SM.OGL.Framebuffer;
using SM2D.Scene;
namespace SM_TEST
{
public class TestRenderPipeline : RenderPipeline
{
private BloomEffect _bloom;
private Framebuffer _postBuffer;
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);
base.Initialization();
}
@ -29,11 +29,13 @@ namespace SM_TEST
MainFramebuffer.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
context.Scene.DrawBackground(context);
context.Scene.DrawMainObjects(context);
context.Scene.DrawHUD(context);
PostProcessFinals.ResolveMultisampledBuffers(MainFramebuffer, _postBuffer);
Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
_bloom.Draw(context);
context.Scene.DrawHUD(context);
context.Scene.DrawDebug(context);
}
}

View file

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

View file

@ -1,22 +1,4 @@
using System;
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;
using System.Windows;
namespace SM_WPF_TEST
{

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