2021-15-03

+ GenericTransformation.InWorldSpace (Merges the object transformation and the last master transformation)
+ Ray class for Raycasting (may not work correctly)
+ Util.CallGarbageCollector() can call the garbage collector.
+ GLWindow.WindowFlags allow to easly switch between Window <-> Borderless Window (this will cause the window to fill the entire screen) <-> Exclusive Fullscreen.

~ Made the bloom-texture scale a constructor-parameter.

SM.OGL:
+ OpenGL-GarbageCollector integration.
+ BoundingBox.GetBounds(Matrix4, out Vector3,out Vector3) allows for easy transformation of the bounding box.
+ GLObjects can now marked as not compiled. Where it always returns false at WasCompiled.

SM2D:
~ Improved the Mouse2D.MouseOver Algorithm.
This commit is contained in:
Michel Fedde 2021-03-15 18:11:58 +01:00
parent 4efc47d75a
commit 5bb690e45f
18 changed files with 224 additions and 20 deletions

View file

@ -96,7 +96,7 @@ namespace SM.Base.Drawing
{
base.DrawContext(ref context);
Transform.LastMaster = context.ModelMatrix;
context.ModelMatrix = Transform.MergeMatrix(context.ModelMatrix);
context.ModelMatrix = Transform.InWorldSpace;
}
}
}

View file

@ -18,6 +18,8 @@ namespace SM.Base.Drawing
public Matrix4 LastMaster { get; internal set; }
public Matrix4 InWorldSpace => MergeMatrix(LastMaster);
/// <summary>
/// Contains the current model matrix.
/// </summary>

View file

@ -15,7 +15,9 @@ namespace SM.Base.PostEffects
{
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 _textureScale = .75f;
private const float _defaultTextureScale = .75f;
private float _textureScale = .75f;
private Framebuffer _bloomBuffer1;
private Framebuffer _bloomBuffer2;
@ -56,10 +58,11 @@ namespace SM.Base.PostEffects
public int WeightCurvePickAmount = 4;
public BloomEffect(Framebuffer source = null, bool hdr = false)
public BloomEffect(Framebuffer source = null, bool hdr = false, float? textureScale = null)
{
_source = source;
_hdr = hdr;
_textureScale = textureScale.GetValueOrDefault(_defaultTextureScale);
WeightCurve = _defaultCurve;
}

View file

@ -73,6 +73,7 @@
<Compile Include="Drawing\Particles\ParticleDrawingBasis.cs" />
<Compile Include="Shaders\SimpleShader.cs" />
<Compile Include="Utility\IInitializable.cs" />
<Compile Include="Utility\Ray.cs" />
<Compile Include="Utility\Util.cs" />
<Compile Include="Window\Contexts\DrawContext.cs" />
<Compile Include="Window\Contexts\UpdateContext.cs" />
@ -116,6 +117,7 @@
<Compile Include="Window\ISetup.cs" />
<Compile Include="Window\RenderPipeline.cs" />
<Compile Include="Window\WindowCode.cs" />
<Compile Include="Window\WindowFlags.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Shaders\Extensions\vertex\basic.vert" />

View file

@ -0,0 +1,66 @@
using System;
using System.Windows;
using OpenTK;
using SM.Base.Drawing;
using SM.Base.Scene;
using SM.OGL.Mesh;
namespace SM.Utility
{
public struct Ray
{
public Vector3 Position;
public Vector3 Direction;
public Ray(Vector3 position, Vector3 direction)
{
Position = position;
Direction = direction.Normalized();
}
public bool ObjectIntersection(BoundingBox box, Matrix4 modelMatrix, out float distance)
{
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]);
float e = Vector3.Dot(axis, delta);
float f = Vector3.Dot(Direction, axis);
if (Math.Abs(f) > 0.001f)
{
float t1 = (e + box.Min[i]) / f;
float t2 = (e + box.Max[i]) / f;
if (t1 > t2)
{
float w = t1;
t1 = t2;
t2 = w;
}
if (t2 < tMax) tMax = t2;
if (t1 > tMin) tMin = t1;
if (tMax < tMin)
return false;
}
else
{
if (-e + box.Min[i] > 0.0f || -e + box.Max[i] < 0.0f)
return false;
}
}
distance = tMin;
return true;
}
}
}

View file

@ -1,4 +1,6 @@
namespace SM.Utility
using System;
namespace SM.Utility
{
public class Util
{
@ -11,5 +13,11 @@
}
obj.Activate();
}
public static void CallGarbageCollector()
{
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
}

View file

@ -1,4 +1,6 @@
using System;
using System.Windows;
using System.Windows.Forms;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
@ -11,6 +13,8 @@ namespace SM.Base.Windows
{
public class GLWindow : GameWindow, IGenericWindow
{
private Vector2 _flagWindowSize;
public bool Loading { get; private set; } = true;
public float AspectRatio { get; set; }
@ -30,12 +34,17 @@ namespace SM.Base.Windows
public GenericScene CurrentScene { get; private set; }
public RenderPipeline CurrentRenderPipeline { get; private set; }
public GLWindow() : this(1280, 720, "Generic OpenGL Title", GameWindowFlags.Default) {}
public WindowFlags WindowFlags;
public GLWindow() : this(1280, 720, "Generic OpenGL Title", WindowFlags.Window) {}
public GLWindow(int width, int height, string title, GameWindowFlags flags, VSyncMode vSync = VSyncMode.On) :
base(width, height, default, title, flags, DisplayDevice.Default, GLSettings.ForcedVersion.MajorVersion, GLSettings.ForcedVersion.MinorVersion, GraphicsContextFlags.Default)
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)
@ -52,6 +61,8 @@ namespace SM.Base.Windows
WindowCode.Resize(this);
if (WindowFlags == WindowFlags.Window) _flagWindowSize = WindowSize;
if (Loading)
{
Loading = false;
@ -125,5 +136,40 @@ namespace SM.Base.Windows
public void TriggerLoad() => Load?.Invoke(this);
public void TriggerResize() => Resize?.Invoke(this);
public void ChangeWindowFlag(WindowFlags newFlag)
{
WindowFlags = newFlag;
switch (newFlag)
{
case WindowFlags.Window:
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;
Height = Screen.PrimaryScreen.Bounds.Height;
break;
case WindowFlags.ExclusiveFullscreen:
break;
default:
throw new ArgumentOutOfRangeException(nameof(newFlag), newFlag, null);
}
if (newFlag == WindowFlags.BorderlessWindow)
{
WindowBorder = WindowBorder.Hidden;
X = Screen.PrimaryScreen.Bounds.X;
Y = Screen.PrimaryScreen.Bounds.Y;
}
}
}
}

View file

@ -94,6 +94,8 @@ namespace SM.Base.Windows
SMRenderer.CurrentFrame++;
GLObject.DisposeMarkedObjects();
Deltatime.RenderDelta = deltatime;
var drawContext = new DrawContext()
{

View file

@ -0,0 +1,9 @@
namespace SM.Base.Windows
{
public enum WindowFlags
{
Window = 0,
BorderlessWindow = 2,
ExclusiveFullscreen = 1
}
}