2021-26-03
+ Texture compression ~ General spring cleaning
This commit is contained in:
parent
bf1118c261
commit
7afec9c9ef
8 changed files with 42 additions and 32 deletions
|
|
@ -13,8 +13,8 @@ namespace SM.Base.Controls
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class Keyboard
|
public static class Keyboard
|
||||||
{
|
{
|
||||||
internal static KeyboardState? _keyboardState;
|
private static KeyboardState? _keyboardState;
|
||||||
internal static List<Key> _lastPressedKeys = new List<Key>();
|
private static List<Key> _lastPressedKeys = new List<Key>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// True, when ANY key pressed.
|
/// True, when ANY key pressed.
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ namespace SM.Base.Controls
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Mouse
|
public class Mouse
|
||||||
{
|
{
|
||||||
internal static MouseState? _mouseState;
|
private static MouseState? _mouseState;
|
||||||
internal static List<MouseButton> _lastButtonsPressed = new List<MouseButton>();
|
private static List<MouseButton> _lastButtonsPressed = new List<MouseButton>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current position of the mouse in the screen.
|
/// The current position of the mouse in the screen.
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace SM.Base.Drawing.Particles
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximum speed of the particles
|
/// The maximum speed of the particles
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float MaxSpeed = 1;
|
public float MaxSpeed = 50;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This contains all important information for each particle.
|
/// This contains all important information for each particle.
|
||||||
|
|
@ -67,13 +67,14 @@ namespace SM.Base.Drawing.Particles
|
||||||
public abstract Func<TDirection, ParticleContext, TDirection> MovementCalculation { get; set; }
|
public abstract Func<TDirection, ParticleContext, TDirection> MovementCalculation { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool UpdateActive { get; set; }
|
public bool UpdateActive {
|
||||||
|
get => timer.Active;
|
||||||
|
set { return; }
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Update(UpdateContext context)
|
public void Update(UpdateContext context)
|
||||||
{
|
{
|
||||||
if (!timer.Running) return;
|
|
||||||
|
|
||||||
ParticleContext particleContext = new ParticleContext
|
ParticleContext particleContext = new ParticleContext
|
||||||
{
|
{
|
||||||
Timer = timer
|
Timer = timer
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,21 @@ namespace SM.Base.Textures
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Texture : TextureBase
|
public class Texture : TextureBase
|
||||||
{
|
{
|
||||||
|
static HintMode _hintMode;
|
||||||
|
/// <summary>
|
||||||
|
/// Defines the texture quailty.
|
||||||
|
/// <para>It won't change already compiled textures!</para>
|
||||||
|
/// </summary>
|
||||||
|
public static HintMode TextureQuality
|
||||||
|
{
|
||||||
|
get => _hintMode;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_hintMode = value;
|
||||||
|
GL.Hint(HintTarget.TextureCompressionHint, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private int? _height;
|
private int? _height;
|
||||||
private int? _width;
|
private int? _width;
|
||||||
|
|
||||||
|
|
@ -116,7 +131,7 @@ namespace SM.Base.Textures
|
||||||
var transparenz = map.PixelFormat == PixelFormat.Format32bppArgb;
|
var transparenz = map.PixelFormat == PixelFormat.Format32bppArgb;
|
||||||
|
|
||||||
GL.TexImage2D(TextureTarget.Texture2D, 0,
|
GL.TexImage2D(TextureTarget.Texture2D, 0,
|
||||||
transparenz ? PixelInternalFormat.Rgba : PixelInternalFormat.Rgb,
|
transparenz ? PixelInternalFormat.CompressedRgba : PixelInternalFormat.CompressedRgb,
|
||||||
data.Width, data.Height, 0,
|
data.Width, data.Height, 0,
|
||||||
transparenz ? OpenTK.Graphics.OpenGL4.PixelFormat.Bgra : OpenTK.Graphics.OpenGL4.PixelFormat.Bgr,
|
transparenz ? OpenTK.Graphics.OpenGL4.PixelFormat.Bgra : OpenTK.Graphics.OpenGL4.PixelFormat.Bgr,
|
||||||
PixelType.UnsignedByte, data.Scan0);
|
PixelType.UnsignedByte, data.Scan0);
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ namespace SM.OGL
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks for OpenGL errors, while allowing to put stuff before and behind it.
|
/// Checks for OpenGL errors, while allowing to put stuff before and behind it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="formating"></param>
|
/// <param name="formating">To decided where to put the error code into, just enter "%code%" to that specific place.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool CheckGLErrors(string formating)
|
public static bool CheckGLErrors(string formating)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ namespace SM.OGL.Shaders
|
||||||
foreach (ShaderFile file in Fragment)
|
foreach (ShaderFile file in Fragment)
|
||||||
GL.DetachShader(shader, file);
|
GL.DetachShader(shader, file);
|
||||||
|
|
||||||
GLDebugging.CheckGLErrors($"Error at detaching '{shader.GetType()}'");
|
GLDebugging.CheckGLErrors($"Error at detaching '{shader.GetType()}': %code%");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -14,6 +14,11 @@ namespace SM2D.Drawing
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override Func<Vector2, ParticleContext, Vector2> MovementCalculation { get; set; } = ParticleMovement.Default2D;
|
public override Func<Vector2, ParticleContext, Vector2> MovementCalculation { get; set; } = ParticleMovement.Default2D;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The direction the particles should travel.
|
||||||
|
/// </summary>
|
||||||
|
public Vector2? Direction;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DrawParticles(TimeSpan duration) : base(duration)
|
public DrawParticles(TimeSpan duration) : base(duration)
|
||||||
{
|
{
|
||||||
|
|
@ -25,7 +30,7 @@ namespace SM2D.Drawing
|
||||||
return new ParticleStruct<Vector2>()
|
return new ParticleStruct<Vector2>()
|
||||||
{
|
{
|
||||||
Matrix = Matrix4.CreateScale(1),
|
Matrix = Matrix4.CreateScale(1),
|
||||||
Direction = new Vector2(Randomize.GetFloat(-1, 1), Randomize.GetFloat(-1, 1)),
|
Direction = Direction.GetValueOrDefault(new Vector2(Randomize.GetFloat(-1, 1), Randomize.GetFloat(-1, 1))),
|
||||||
Speed = Randomize.GetFloat(MaxSpeed)
|
Speed = Randomize.GetFloat(MaxSpeed)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,13 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using SM.Base.Controls;
|
||||||
using OpenTK.Input;
|
|
||||||
using SM.Base;
|
|
||||||
using SM.Base.Time;
|
using SM.Base.Time;
|
||||||
using SM.Base.Window;
|
using SM.Base.Window;
|
||||||
using SM2D;
|
using SM2D;
|
||||||
using SM2D.Controls;
|
|
||||||
using SM2D.Drawing;
|
using SM2D.Drawing;
|
||||||
using SM2D.Object;
|
using SM2D.Object;
|
||||||
using SM2D.Pipelines;
|
|
||||||
using SM2D.Scene;
|
using SM2D.Scene;
|
||||||
using Font = SM.Base.Drawing.Text.Font;
|
|
||||||
using Vector2 = OpenTK.Vector2;
|
|
||||||
|
|
||||||
namespace SM_TEST
|
namespace SM_TEST
|
||||||
{
|
{
|
||||||
|
|
@ -22,6 +16,7 @@ namespace SM_TEST
|
||||||
static Scene scene;
|
static Scene scene;
|
||||||
private static GLWindow window;
|
private static GLWindow window;
|
||||||
private static PolyLine line;
|
private static PolyLine line;
|
||||||
|
private static DrawParticles particles;
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
window = new GLWindow(1280, 720, "0ms", WindowFlags.Window, VSyncMode.Off);
|
window = new GLWindow(1280, 720, "0ms", WindowFlags.Window, VSyncMode.Off);
|
||||||
|
|
@ -30,13 +25,12 @@ namespace SM_TEST
|
||||||
|
|
||||||
window.SetScene(scene = new Scene());
|
window.SetScene(scene = new Scene());
|
||||||
|
|
||||||
line = new PolyLine(new Vector2[] { Vector2.Zero, Vector2.One }, PolyLineType.Connected);
|
particles = new DrawParticles(TimeSpan.FromSeconds(5))
|
||||||
var display = new DrawObject2D()
|
|
||||||
{
|
{
|
||||||
Mesh = line
|
MaxSpeed = 50,
|
||||||
};
|
};
|
||||||
display.Transform.Size.Set(1);
|
particles.Transform.Size.Set(20);
|
||||||
scene.Objects.Add(display);
|
scene.Objects.Add(particles);
|
||||||
|
|
||||||
window.UpdateFrame += WindowOnUpdateFrame;
|
window.UpdateFrame += WindowOnUpdateFrame;
|
||||||
window.RenderFrame += Window_RenderFrame;
|
window.RenderFrame += Window_RenderFrame;
|
||||||
|
|
@ -52,13 +46,8 @@ namespace SM_TEST
|
||||||
|
|
||||||
private static void WindowOnUpdateFrame(object sender, FrameEventArgs e)
|
private static void WindowOnUpdateFrame(object sender, FrameEventArgs e)
|
||||||
{
|
{
|
||||||
if (SM.Base.Controls.Mouse.LeftClick)
|
if (Mouse.LeftClick)
|
||||||
line.Vertex.Add(Vector3.Zero);
|
particles.Trigger();
|
||||||
|
|
||||||
line.Vertex[1] = new Vector3(Mouse2D.InWorld(window.ViewportCamera as Camera));
|
|
||||||
line.Update();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue