Create some high level classes.
This commit is contained in:
parent
49257574f4
commit
2c957a0c1a
102
Dashboard.Common/IWindow.cs
Normal file
102
Dashboard.Common/IWindow.cs
Normal file
@ -0,0 +1,102 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace Dashboard
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class of all Dashboard windows.
|
||||
/// </summary>
|
||||
public interface IWindow : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the window.
|
||||
/// </summary>
|
||||
string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The size of the window that includes the window extents.
|
||||
/// </summary>
|
||||
SizeF OuterSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The size of the window that excludes the window extents.
|
||||
/// </summary>
|
||||
SizeF ClientSize { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base class for all Dashboard windows that are DPI-aware.
|
||||
/// </summary>
|
||||
public interface IDpiAwareWindow : IWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// DPI of the window.
|
||||
/// </summary>
|
||||
float Dpi { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Scale of the window.
|
||||
/// </summary>
|
||||
float Scale { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An object that represents a window in a virtual space, usually another window or a rendering system.
|
||||
/// </summary>
|
||||
public interface IVirtualWindow : IWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// Send an event to this window.
|
||||
/// </summary>
|
||||
/// <param name="args">The event arguments</param>
|
||||
/// TODO:
|
||||
void SendEvent(EventArgs args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generic interface for the rendering system present in a <see cref="IPhysicalWindow"/>
|
||||
/// </summary>
|
||||
public interface IDeviceContext
|
||||
{
|
||||
/// <summary>
|
||||
/// The swap group for this device context.
|
||||
/// </summary>
|
||||
ISwapGroup SwapGroup { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The size of the window framebuffer in pixels.
|
||||
/// </summary>
|
||||
Size FramebufferSize { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface that is used to swap the buffers of
|
||||
/// </summary>
|
||||
public interface ISwapGroup
|
||||
{
|
||||
/// <summary>
|
||||
/// The swap interval for this swap group.
|
||||
/// </summary>
|
||||
public int SwapInterval { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Swap buffers.
|
||||
/// </summary>
|
||||
void Swap();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An object that represents a native operating system window.
|
||||
/// </summary>
|
||||
public interface IPhysicalWindow : IWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// The device context for this window.
|
||||
/// </summary>
|
||||
IDeviceContext DeviceContext { get; }
|
||||
|
||||
/// <summary>
|
||||
/// True if the window is double buffered.
|
||||
/// </summary>
|
||||
public bool DoubleBuffered { get; }
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using System.Drawing;
|
||||
using Dashboard.Drawing.OpenGL.Executors;
|
||||
using Dashboard.OpenGL;
|
||||
|
||||
namespace Dashboard.Drawing.OpenGL
|
||||
{
|
||||
|
@ -1,3 +1,5 @@
|
||||
using Dashboard.OpenGL;
|
||||
|
||||
namespace Dashboard.Drawing.OpenGL
|
||||
{
|
||||
public class ContextResourcePoolManager
|
||||
|
@ -9,11 +9,12 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BlurgText" Version="0.1.0-nightly-19" />
|
||||
<PackageReference Include="OpenTK.Graphics" Version="5.0.0-pre.13" />
|
||||
<PackageReference Include="OpenTK.Graphics" Version="[5.0.0-pre*,5.1)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Dashboard.Drawing\Dashboard.Drawing.csproj" />
|
||||
<ProjectReference Include="..\Dashboard.OpenGL\Dashboard.OpenGL.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using Dashboard.OpenGL;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using OpenTK.Mathematics;
|
||||
using Vector2 = System.Numerics.Vector2;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Dashboard.Drawing.OpenGL.Text;
|
||||
using Dashboard.OpenGL;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using Dashboard.OpenGL;
|
||||
using OpenTK.Mathematics;
|
||||
|
||||
namespace Dashboard.Drawing.OpenGL
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Dashboard.OpenGL;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
namespace Dashboard.Drawing.OpenGL
|
||||
|
@ -2,6 +2,7 @@ using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
using BlurgText;
|
||||
using Dashboard.OpenGL;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using OPENGL = OpenTK.Graphics.OpenGL;
|
||||
|
||||
@ -54,7 +55,7 @@ namespace Dashboard.Drawing.OpenGL.Text
|
||||
path = Path.GetTempFileName();
|
||||
try
|
||||
{
|
||||
dest = File.Open(path, FileMode.CreateNew, FileAccess.Write, FileShare.None);
|
||||
dest = File.Open(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
@ -71,14 +72,13 @@ namespace Dashboard.Drawing.OpenGL.Text
|
||||
dest.Dispose();
|
||||
|
||||
DbBlurgFont font = (DbBlurgFont)LoadFont(path);
|
||||
File.Delete(path);
|
||||
return font;
|
||||
}
|
||||
|
||||
public IFont LoadFont(string path)
|
||||
{
|
||||
BlurgFont? font = Blurg.AddFontFile(path) ?? throw new Exception("Failed to load the font file.");
|
||||
return new DbBlurgFont(Blurg, font, 12f);
|
||||
return new DbBlurgFont(Blurg, font, 12f) { Path = path };
|
||||
}
|
||||
|
||||
public IFont LoadFont(NamedFont font)
|
||||
@ -103,7 +103,12 @@ namespace Dashboard.Drawing.OpenGL.Text
|
||||
{
|
||||
if (dblurg.Owner != Blurg)
|
||||
{
|
||||
throw new Exception();
|
||||
if (dblurg.Path == null)
|
||||
return (DbBlurgFont)LoadFont(new NamedFont(dblurg.Family, dblurg.Size, dblurg.Weight,
|
||||
dblurg.Slant,
|
||||
dblurg.Stretch));
|
||||
else
|
||||
return (DbBlurgFont)LoadFont(dblurg.Path);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -13,6 +13,8 @@ namespace Dashboard.Drawing.OpenGL.Text
|
||||
public FontSlant Slant => Font.Italic ? FontSlant.Italic : FontSlant.Normal;
|
||||
public FontStretch Stretch => FontStretch.Normal;
|
||||
|
||||
internal string? Path { get; init; }
|
||||
|
||||
public DbBlurgFont(Blurg owner, BlurgFont font, float size)
|
||||
{
|
||||
Owner = owner;
|
||||
|
@ -2,9 +2,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Dashboard.Drawing
|
||||
{
|
||||
@ -160,7 +158,7 @@ namespace Dashboard.Drawing
|
||||
{
|
||||
byte b = bytes[i];
|
||||
|
||||
value = (value << 7) | b;
|
||||
value |= (b & 0x7F) << (7*i);
|
||||
|
||||
if ((b & (1 << 7)) == 0)
|
||||
{
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Drawing;
|
||||
using System.Net.Http;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using Dashboard.Drawing;
|
||||
|
13
Dashboard.OpenGL/Dashboard.OpenGL.csproj
Normal file
13
Dashboard.OpenGL/Dashboard.OpenGL.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Dashboard.Common\Dashboard.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,11 +1,11 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace Dashboard.Drawing.OpenGL
|
||||
namespace Dashboard.OpenGL
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for GL context operations
|
||||
/// </summary>
|
||||
public interface IGLContext
|
||||
public interface IGLContext : IDeviceContext
|
||||
{
|
||||
/// <summary>
|
||||
/// The associated group for context sharing.
|
||||
@ -22,21 +22,10 @@ namespace Dashboard.Drawing.OpenGL
|
||||
/// Called when the context is disposed.
|
||||
/// </summary>
|
||||
event Action Disposed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extension interface for GL contexts in a DPI-aware environment.
|
||||
/// Activate this OpenGL Context.
|
||||
/// </summary>
|
||||
public interface IDpiAwareGLContext : IGLContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Dpi for current context.
|
||||
/// </summary>
|
||||
public float Dpi { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Scale for the current context. This will be used to scale drawn geometry.
|
||||
/// </summary>
|
||||
public float Scale { get; }
|
||||
void MakeCurrent();
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace Dashboard.Drawing.OpenGL
|
||||
namespace Dashboard.OpenGL
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface much like <see cref="IDisposable"/> except GL resources are dropped.
|
18
Dashboard.OpenTK/Dashboard.OpenTK.csproj
Normal file
18
Dashboard.OpenTK/Dashboard.OpenTK.csproj
Normal file
@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="OpenTK" Version="[5.0.0-pre*,5.1)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Dashboard.OpenGL\Dashboard.OpenGL.csproj" />
|
||||
<ProjectReference Include="..\Dashboard\Dashboard.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
117
Dashboard.OpenTK/PAL2/OpenGLDeviceContext.cs
Normal file
117
Dashboard.OpenTK/PAL2/OpenGLDeviceContext.cs
Normal file
@ -0,0 +1,117 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Drawing;
|
||||
using Dashboard.OpenGL;
|
||||
using OpenTK.Mathematics;
|
||||
using OpenTK.Platform;
|
||||
using TK = OpenTK.Platform.Toolkit;
|
||||
|
||||
namespace Dashboard.OpenTK.PAL2
|
||||
{
|
||||
public class OpenGLDeviceContext : IGLContext, IGLDisposable
|
||||
{
|
||||
public OpenGLContextHandle ContextHandle { get; }
|
||||
public WindowHandle WindowHandle { get; }
|
||||
|
||||
public ISwapGroup SwapGroup { get; }
|
||||
public int ContextGroup { get; }
|
||||
|
||||
public Size FramebufferSize
|
||||
{
|
||||
get
|
||||
{
|
||||
TK.Window.GetFramebufferSize(WindowHandle, out Vector2i size);
|
||||
return new Size(size.X, size.Y);
|
||||
}
|
||||
}
|
||||
|
||||
public event Action? Disposed;
|
||||
|
||||
public OpenGLDeviceContext(WindowHandle window, OpenGLContextHandle context, ISwapGroup? group = null)
|
||||
{
|
||||
WindowHandle = window;
|
||||
ContextHandle = context;
|
||||
SwapGroup = group ?? new DummySwapGroup(context);
|
||||
ContextGroup = GetContextGroup(context);
|
||||
}
|
||||
|
||||
public void MakeCurrent()
|
||||
{
|
||||
TK.OpenGL.SetCurrentContext(ContextHandle);
|
||||
}
|
||||
|
||||
private bool _isDisposed = false;
|
||||
|
||||
public void Dispose() => Dispose(true);
|
||||
|
||||
public void Dispose(bool safeExit)
|
||||
{
|
||||
if (_isDisposed) return;
|
||||
_isDisposed = true;
|
||||
|
||||
if (SwapGroup is IGLDisposable glDisposable)
|
||||
{
|
||||
glDisposable.Dispose(safeExit);
|
||||
}
|
||||
else if (SwapGroup is IDisposable disposable)
|
||||
{
|
||||
disposable.Dispose();
|
||||
}
|
||||
|
||||
Disposed?.Invoke();
|
||||
}
|
||||
|
||||
private static int _contextGroupId = 0;
|
||||
private static ConcurrentDictionary<OpenGLContextHandle, int> _contextGroupRootContexts = new ConcurrentDictionary<OpenGLContextHandle, int>();
|
||||
|
||||
private static int GetContextGroup(OpenGLContextHandle handle)
|
||||
{
|
||||
OpenGLContextHandle? shared = TK.OpenGL.GetSharedContext(handle);
|
||||
|
||||
if (shared == null)
|
||||
{
|
||||
if (_contextGroupRootContexts.TryGetValue(handle, out int group))
|
||||
return group;
|
||||
|
||||
group = Interlocked.Increment(ref _contextGroupId);
|
||||
_contextGroupRootContexts.TryAdd(handle, group);
|
||||
return GetContextGroup(handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_contextGroupRootContexts.TryGetValue(shared, out int group))
|
||||
return group;
|
||||
|
||||
return GetContextGroup(shared);
|
||||
}
|
||||
}
|
||||
|
||||
public class DummySwapGroup : ISwapGroup
|
||||
{
|
||||
public OpenGLContextHandle ContextHandle { get; }
|
||||
|
||||
public int SwapInterval
|
||||
{
|
||||
get
|
||||
{
|
||||
TK.OpenGL.SetCurrentContext(ContextHandle);
|
||||
return TK.OpenGL.GetSwapInterval();
|
||||
}
|
||||
set
|
||||
{
|
||||
TK.OpenGL.SetCurrentContext(ContextHandle);
|
||||
TK.OpenGL.SetSwapInterval(value);
|
||||
}
|
||||
}
|
||||
|
||||
public DummySwapGroup(OpenGLContextHandle handle)
|
||||
{
|
||||
ContextHandle = handle;
|
||||
}
|
||||
|
||||
public void Swap()
|
||||
{
|
||||
TK.OpenGL.SwapBuffers(ContextHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
81
Dashboard.OpenTK/PAL2/PhysicalWindow.cs
Normal file
81
Dashboard.OpenTK/PAL2/PhysicalWindow.cs
Normal file
@ -0,0 +1,81 @@
|
||||
using System.Drawing;
|
||||
using OpenTK.Mathematics;
|
||||
using OpenTK.Platform;
|
||||
using TK = OpenTK.Platform.Toolkit;
|
||||
|
||||
namespace Dashboard.OpenTK.PAL2
|
||||
{
|
||||
public class PhysicalWindow : IPhysicalWindow
|
||||
{
|
||||
public WindowHandle WindowHandle { get; }
|
||||
public IDeviceContext DeviceContext { get; }
|
||||
public bool DoubleBuffered => true; // Always true for OpenTK windows.
|
||||
|
||||
public string Title
|
||||
{
|
||||
get => TK.Window.GetTitle(WindowHandle);
|
||||
set => TK.Window.SetTitle(WindowHandle, value);
|
||||
}
|
||||
|
||||
public SizeF OuterSize
|
||||
{
|
||||
get
|
||||
{
|
||||
TK.Window.GetSize(WindowHandle, out Vector2i size);
|
||||
return new SizeF(size.X, size.Y);
|
||||
}
|
||||
set => TK.Window.SetSize(WindowHandle, new Vector2i((int)value.Width, (int)value.Height));
|
||||
}
|
||||
|
||||
public SizeF ClientSize
|
||||
{
|
||||
get
|
||||
{
|
||||
TK.Window.GetClientSize(WindowHandle, out Vector2i size);
|
||||
return new SizeF(size.X, size.Y);
|
||||
}
|
||||
set => TK.Window.SetClientSize(WindowHandle, new Vector2i((int)value.Width, (int)value.Height));
|
||||
}
|
||||
|
||||
public PhysicalWindow(WindowHandle window, IDeviceContext dc)
|
||||
{
|
||||
WindowHandle = window;
|
||||
DeviceContext = dc;
|
||||
}
|
||||
|
||||
public PhysicalWindow(WindowHandle window, OpenGLContextHandle context, ISwapGroup? swapGroup = null)
|
||||
{
|
||||
WindowHandle = window;
|
||||
DeviceContext = new OpenGLDeviceContext(window, context, swapGroup);
|
||||
}
|
||||
|
||||
public PhysicalWindow(GraphicsApiHints hints)
|
||||
{
|
||||
WindowHandle = TK.Window.Create(hints);
|
||||
DeviceContext = CreateDeviceContext(WindowHandle, hints);
|
||||
}
|
||||
|
||||
private static IDeviceContext CreateDeviceContext(WindowHandle window, GraphicsApiHints hints)
|
||||
{
|
||||
switch (hints.Api)
|
||||
{
|
||||
case GraphicsApi.OpenGL:
|
||||
case GraphicsApi.OpenGLES:
|
||||
OpenGLContextHandle context = TK.OpenGL.CreateFromWindow(window);
|
||||
return new OpenGLDeviceContext(window, context);
|
||||
default:
|
||||
throw new Exception($"Unknown graphics API {hints.Api}.");
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isDisposed = false;
|
||||
public void Dispose()
|
||||
{
|
||||
if (_isDisposed) return;
|
||||
_isDisposed = true;
|
||||
|
||||
(DeviceContext as IDisposable)?.Dispose();
|
||||
TK.Window.Destroy(WindowHandle);
|
||||
}
|
||||
}
|
||||
}
|
@ -21,6 +21,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dashboard.Drawing.OpenGL",
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dashboard.ImmediateUI", "Dashboard.ImmediateUI\Dashboard.ImmediateUI.csproj", "{3F33197F-0B7B-4CD8-98BD-05D6D5EC76B2}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Frameworks", "Frameworks", "{9B62A92D-ABF5-4704-B831-FD075515A82F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dashboard.OpenTK", "Dashboard.OpenTK\Dashboard.OpenTK.csproj", "{7B064228-2629-486E-95C6-BDDD4B4602C4}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dashboard.OpenGL", "Dashboard.OpenGL\Dashboard.OpenGL.csproj", "{33EB657C-B53A-41B4-BC3C-F38C09ABA577}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -51,11 +57,20 @@ Global
|
||||
{3F33197F-0B7B-4CD8-98BD-05D6D5EC76B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3F33197F-0B7B-4CD8-98BD-05D6D5EC76B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3F33197F-0B7B-4CD8-98BD-05D6D5EC76B2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7B064228-2629-486E-95C6-BDDD4B4602C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7B064228-2629-486E-95C6-BDDD4B4602C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7B064228-2629-486E-95C6-BDDD4B4602C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7B064228-2629-486E-95C6-BDDD4B4602C4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{33EB657C-B53A-41B4-BC3C-F38C09ABA577}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{33EB657C-B53A-41B4-BC3C-F38C09ABA577}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{33EB657C-B53A-41B4-BC3C-F38C09ABA577}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{33EB657C-B53A-41B4-BC3C-F38C09ABA577}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{7C90B90B-DF31-439B-9080-CD805383B014} = {9D6CCC74-4DF3-47CB-B9B2-6BB75DF2BC40}
|
||||
{7B064228-2629-486E-95C6-BDDD4B4602C4} = {9B62A92D-ABF5-4704-B831-FD075515A82F}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
@ -6,4 +6,9 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Dashboard.Common\Dashboard.Common.csproj" />
|
||||
<ProjectReference Include="..\Dashboard.Drawing\Dashboard.Drawing.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -11,6 +11,7 @@
|
||||
<ProjectReference Include="..\..\Dashboard.Drawing.OpenGL\Dashboard.Drawing.OpenGL.csproj" />
|
||||
<ProjectReference Include="..\..\Dashboard.Drawing\Dashboard.Drawing.csproj" />
|
||||
<ProjectReference Include="..\..\Dashboard.ImmediateUI\Dashboard.ImmediateUI.csproj" />
|
||||
<ProjectReference Include="..\..\Dashboard.OpenTK\Dashboard.OpenTK.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,18 +1,15 @@
|
||||
using Dashboard.Drawing;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using Dashboard;
|
||||
using Dashboard.Drawing.OpenGL;
|
||||
using Dashboard.Drawing.OpenGL.Text;
|
||||
using Dashboard.ImmediateUI;
|
||||
using Dashboard.OpenTK.PAL2;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Platform;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using OpenTK.Mathematics;
|
||||
using Box2d = Dashboard.Box2d;
|
||||
using TK = OpenTK.Platform.Toolkit;
|
||||
using sys = System.Numerics;
|
||||
using otk = OpenTK.Mathematics;
|
||||
|
||||
TK.Init(new ToolkitOptions()
|
||||
{
|
||||
@ -24,7 +21,7 @@ TK.Init(new ToolkitOptions()
|
||||
}
|
||||
});
|
||||
|
||||
WindowHandle wnd = TK.Window.Create(new OpenGLGraphicsApiHints()
|
||||
PhysicalWindow window = new PhysicalWindow(new OpenGLGraphicsApiHints()
|
||||
{
|
||||
Version = new Version(3, 2),
|
||||
ForwardCompatibleFlag = true,
|
||||
@ -42,18 +39,19 @@ WindowHandle wnd = TK.Window.Create(new OpenGLGraphicsApiHints()
|
||||
|
||||
SupportTransparentFramebufferX11 = true,
|
||||
});
|
||||
TK.Window.SetTitle(wnd, "DashTerm");
|
||||
TK.Window.SetMinClientSize(wnd, 300, 200);
|
||||
TK.Window.SetClientSize(wnd, new Vector2i(320, 240));
|
||||
TK.Window.SetBorderStyle(wnd, WindowBorderStyle.ResizableBorder);
|
||||
|
||||
window.Title = "DashTerm";
|
||||
TK.Window.SetMinClientSize(window.WindowHandle, 300, 200);
|
||||
TK.Window.SetClientSize(window.WindowHandle, new Vector2i(320, 240));
|
||||
TK.Window.SetBorderStyle(window.WindowHandle, WindowBorderStyle.ResizableBorder);
|
||||
// TK.Window.SetTransparencyMode(wnd, WindowTransparencyMode.TransparentFramebuffer, 0.1f);
|
||||
|
||||
OpenGLContextHandle context = TK.OpenGL.CreateFromWindow(wnd);
|
||||
OpenGLDeviceContext context = (OpenGLDeviceContext)window.DeviceContext;
|
||||
|
||||
TK.OpenGL.SetCurrentContext(context);
|
||||
TK.OpenGL.SetSwapInterval(1);
|
||||
context.MakeCurrent();
|
||||
context.SwapGroup.SwapInterval = 1;
|
||||
|
||||
GLLoader.LoadBindings(new Pal2BindingsContext(TK.OpenGL, context));
|
||||
GLLoader.LoadBindings(new Pal2BindingsContext(TK.OpenGL, context.ContextHandle));
|
||||
|
||||
DrawQueue queue = new DrawQueue();
|
||||
SolidBrush fg = new SolidBrush(Color.FromArgb(0, 0, 0, 0));
|
||||
@ -63,8 +61,7 @@ bool shouldExit = false;
|
||||
GLEngine engine = new GLEngine();
|
||||
engine.Initialize();
|
||||
|
||||
GlContext dbGlContext = new GlContext(wnd, context);
|
||||
ContextExecutor executor = engine.GetExecutor(dbGlContext);
|
||||
ContextExecutor executor = engine.GetExecutor(context);
|
||||
DimUI dimUI = new DimUI(new DimUIConfig()
|
||||
{
|
||||
Font = new NamedFont("Noto Sans", 9f),
|
||||
@ -74,7 +71,7 @@ Vector2 mousePos = Vector2.Zero;
|
||||
Random r = new Random();
|
||||
EventQueue.EventRaised += (handle, type, eventArgs) =>
|
||||
{
|
||||
if (handle != wnd)
|
||||
if (handle != window.WindowHandle)
|
||||
return;
|
||||
|
||||
switch (type)
|
||||
@ -88,7 +85,7 @@ EventQueue.EventRaised += (handle, type, eventArgs) =>
|
||||
}
|
||||
};
|
||||
|
||||
TK.Window.SetMode(wnd, WindowMode.Normal);
|
||||
TK.Window.SetMode(window.WindowHandle, WindowMode.Normal);
|
||||
|
||||
List<Vector3> points = new List<Vector3>();
|
||||
|
||||
@ -98,7 +95,7 @@ StringBuilder builder = new StringBuilder();
|
||||
while (!shouldExit)
|
||||
{
|
||||
TK.Window.ProcessEvents(true);
|
||||
TK.Window.GetFramebufferSize(wnd, out Vector2i framebufferSize);
|
||||
TK.Window.GetFramebufferSize(context.WindowHandle, out Vector2i framebufferSize);
|
||||
executor.BeginFrame();
|
||||
|
||||
dimUI.Begin(new Box2d(0, 0, framebufferSize.X, framebufferSize.Y), queue);
|
||||
@ -168,41 +165,5 @@ while (!shouldExit)
|
||||
executor.EndFrame();
|
||||
queue.Clear();
|
||||
|
||||
TK.OpenGL.SwapBuffers(context);
|
||||
}
|
||||
|
||||
class GlContext : IGLContext
|
||||
{
|
||||
public WindowHandle Window { get; }
|
||||
public OpenGLContextHandle Context { get; }
|
||||
public int ContextGroup { get; } = -1;
|
||||
|
||||
public Size FramebufferSize
|
||||
{
|
||||
get
|
||||
{
|
||||
TK.Window.GetFramebufferSize(Window, out Vector2i framebufferSize);
|
||||
return new Size(framebufferSize.X, framebufferSize.Y);
|
||||
}
|
||||
}
|
||||
|
||||
public event Action? Disposed;
|
||||
|
||||
public GlContext(WindowHandle window, OpenGLContextHandle context)
|
||||
{
|
||||
Window = window;
|
||||
Context = context;
|
||||
|
||||
OpenGLContextHandle? shared = TK.OpenGL.GetSharedContext(context);
|
||||
if (shared != null)
|
||||
{
|
||||
ContextGroup = _contexts.IndexOf(shared);
|
||||
}
|
||||
else
|
||||
{
|
||||
_contexts.Add(context);
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly List<OpenGLContextHandle> _contexts = new List<OpenGLContextHandle>();
|
||||
context.SwapGroup.Swap();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user