daily update on 20240209 by nitload youmu

This commit is contained in:
Nitload
2024-02-09 23:31:33 +08:00
parent 6fe6b3b3cf
commit 8391569482
159 changed files with 948 additions and 2431 deletions
+175 -136
View File
@@ -1,4 +1,5 @@
using StgSharp.Controlling;
using StgSharp;
using StgSharp.Controlling;
using StgSharp.Logic;
using StgSharp.Math;
using System;
@@ -10,8 +11,10 @@ using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Reflection.Emit;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Threading;
@@ -34,8 +37,8 @@ namespace StgSharp.Graphics
internal Form sharedForm;
internal int width;
internal IntPtr windowID;
private IglFunc gl;
private bool closed;
private IglFunc gl;
#endregion
#region form thread setting
@@ -55,12 +58,13 @@ namespace StgSharp.Graphics
{
}
protected FrameBufferSizeHandler FrameBufferSizeCallback
/// <summary>
/// OpenGL package used by current form context.
/// </summary>
public IglFunc GL
{
set
{
gl.SetFrameBufferSizeCallback(this.windowID, value);
}
get => gl;
internal set => gl = value;
}
/// <summary>
@@ -72,20 +76,6 @@ namespace StgSharp.Graphics
set => height = value;
}
/// <summary>
/// OpenGL package used by current form context.
/// </summary>
public IglFunc GL
{
get => gl;
internal set => gl = value;
}
internal Thread RenderThread
{
get { return renderThread; }
}
/// <summary>
/// Representing
/// </summary>
@@ -94,6 +84,14 @@ namespace StgSharp.Graphics
get { return isSingleThread; }
}
public bool ShouldClose
{
set
{
InternalIO.glfwSetWindowShouldClose(windowID, value ? 1 : 0);
}
}
/// <summary>
/// Width of this form, represent in <see cref="int"/>
/// </summary>
@@ -132,11 +130,158 @@ namespace StgSharp.Graphics
get { return _renderStartSignal; }
set { _renderStartSignal = value; }
}
internal Thread RenderThread
{
get { return renderThread; }
}
protected FrameBufferSizeHandler FrameBufferSizeCallback
{
set
{
IntPtr handlerPtr = Marshal.GetFunctionPointerForDelegate(value);
InternalIO.glfwSetFramebufferSizeCallback(windowID, handlerPtr);
}
}
unsafe ~Form()
{
Marshal.FreeHGlobal((IntPtr)contextID);
}
/// <summary>
/// Init an OpenGl context if current form has not been binded to any context.
/// and set the context binded to current form as current OpenGL context.
/// </summary>
/// <exception cref="Exception">Something goes wrong and
/// StgSharp fails in creating a new OpenGL context. </exception>
public unsafe void MakeAsCurrentContext()
{
if (windowID == default)
{
IntPtr windowPtr;
byte[] tittleBytes = Encoding.UTF8.GetBytes(name);
if (sharedForm == null)
{
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, IntPtr.Zero);
}
else
{
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, sharedForm.windowID);
}
if ((long)windowPtr == -1 || (long)windowPtr == -2)
{
throw new Exception("Cannot create window instance!");
}
else
{
windowID = windowPtr;
}
}
InternalIO.InternalSetCurrentGLContext(windowID, contextID);
}
/// <summary>
/// Set all necessary metadata to current form instance
/// </summary>
public void SetMetadata(int width, int height, string name, IntPtr monitor, Form sharedForm)
{
this.width = width;
this.height = height;
this.name = name;
this.sharedForm = sharedForm;
this.monitor = monitor;
}
/// <summary>
/// Resize the current form
/// </summary>
/// <param name="width">New width of the window</param>
/// <param name="height">New height of the window</param>
public void SetSize(int width, int height)
{
this.Width = width;
this.Height = height;
InternalIO.glfwSetWindowSize(this.windowID, width, height);
}
/// <summary>
/// Resize the current form
/// </summary>
/// <param name="size">
/// A <see cref="Vec2d"/> (width,height) representing the new size of current form
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetSize(Vec2d size)
{
this.Size = size;
InternalIO.glfwSetWindowSize(this.windowID, (int)size.X, (int)size.Y);
}
/// <summary>
/// Set the size limit of current form
/// </summary>
/// <param name="minWidth">Minimum width of current form </param>
/// <param name="minHeight">Minimum height of current form</param>
/// <param name="maxWidth">Maximum width of curent form</param>
/// <param name="maxHeight">Maximum height of current form</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
{
InternalIO.glfwSetWindowSizeLimits(
this.windowID,
minWidth, minHeight, maxWidth, maxHeight);
}
/// <summary>
/// Set the size limit of current form
/// </summary>
/// <param name="minSize">
/// Minimun size of current form. In form of a <see cref="Vec2d"/> of (width,height)
/// </param>
/// <param name="maxSize">
/// Maximum size of current form. In form of a <see cref="Vec2d"/> of (width,height)
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetSizeLimit(Vec2d minSize, Vec2d maxSize)
{
InternalIO.glfwSetWindowSizeLimits(
this.windowID,
(int)minSize.X, (int)minSize.Y, (int)maxSize.X, (int)maxSize.Y);
}
public unsafe void SwapAndPollEvent()
{
if (windowID == IntPtr.Zero)
{
return;
}
if (isSingleThread)
{
InternalIO.glfwSwapBuffers(windowID);
InternalIO.glfwPollEvents();
}
else
{
M128 m = default;
m.IntPtr0 = windowID;
GLonUpdate glu = gl as GLonUpdate;
glu.frameworkHandleEnqueue(
(IntPtr)(delegate*<void>)&InternalSwapBuffer, m);
}
}
internal static void InternalSwapBuffer()
{
IntPtr handle = default;
GLonUpdate.ParamQueue.TryDequeue(out handle);
InternalIO.glfwSwapBuffers(handle);
InternalIO.glfwPollEvents();
}
#region form main
public abstract void Deinit(params object[] args);
@@ -181,21 +326,6 @@ namespace StgSharp.Graphics
}
}
private unsafe void InternalRender()
{
#pragma warning disable CS8602
ConcurrentQueue<IntPtr> glActions = (gl as GLonUpdate).GLactionQueue;
#pragma warning restore CS8602
IntPtr currentOperation;
while (gl.GetWindowShouldClose(this))
{
if (glActions.TryDequeue(out currentOperation))
{
((delegate*<void>)currentOperation)();
}
}
}
internal void InternalDeinit(params object[] args)
{
Deinit(args);
@@ -264,112 +394,21 @@ namespace StgSharp.Graphics
renderThread = new Thread(new ThreadStart(InternalRender));
}
}
#endregion
/// <summary>
/// Set all necessary metadata to current form instance
/// </summary>
public void SetMetadata(int width, int height, string name, IntPtr monitor, Form sharedForm)
private unsafe void InternalRender()
{
this.width = width;
this.height = height;
this.name = name;
this.sharedForm = sharedForm;
this.monitor = monitor;
}
/// <summary>
/// Init an OpenGl context if current form has not been binded to any context.
/// and set the context binded to current form as current OpenGL context.
/// </summary>
/// <exception cref="Exception">Something goes wrong and
/// StgSharp fails in creating a new OpenGL context. </exception>
public unsafe void MakeAsCurrentContext()
{
if (windowID == default)
#pragma warning disable CS8602
ConcurrentQueue<IntPtr> glActions = (gl as GLonUpdate).GLactionQueue;
#pragma warning restore CS8602
IntPtr currentOperation;
while (gl.GetWindowShouldClose(this))
{
IntPtr windowPtr;
byte[] tittleBytes = Encoding.UTF8.GetBytes(name);
if (sharedForm == null)
if (glActions.TryDequeue(out currentOperation))
{
windowPtr = InternalIO.glfw.CreateWindow(
width, height, tittleBytes, monitor, IntPtr.Zero);
}
else
{
windowPtr = InternalIO.glfw.CreateWindow(
width, height, tittleBytes, monitor, sharedForm.windowID);
}
if ((long)windowPtr == -1 || (long)windowPtr == -2)
{
throw new Exception("Cannot create window instance!");
}
else
{
windowID = windowPtr;
((delegate*<void>)currentOperation)();
}
}
InternalIO.InternalSetCurrentGLContext(windowID, contextID);
}
/// <summary>
/// Resize the current form
/// </summary>
/// <param name="width">New width of the window</param>
/// <param name="height">New height of the window</param>
public void SetSize(int width, int height)
{
this.Width = width;
this.Height = height;
InternalIO.glfw.SetWindowSize(this.windowID, width, height);
}
/// <summary>
/// Resize the current form
/// </summary>
/// <param name="size">
/// A <see cref="Vec2d"/> (width,height) representing the new size of current form
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetSize(Vec2d size)
{
this.Size = size;
InternalIO.glfw.SetWindowSize(this.windowID, (int)size.X, (int)size.Y);
}
/// <summary>
/// Set the size limit of current form
/// </summary>
/// <param name="minWidth">Minimum width of current form </param>
/// <param name="minHeight">Minimum height of current form</param>
/// <param name="maxWidth">Maximum width of curent form</param>
/// <param name="maxHeight">Maximum height of current form</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
{
InternalIO.glfw.SetWindowSizeLimits(
this.windowID,
minWidth, minHeight, maxWidth, maxHeight);
}
/// <summary>
/// Set the size limit of current form
/// </summary>
/// <param name="minSize">
/// Minimun size of current form. In form of a <see cref="Vec2d"/> of (width,height)
/// </param>
/// <param name="maxSize">
/// Maximum size of current form. In form of a <see cref="Vec2d"/> of (width,height)
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetSizeLimit(Vec2d minSize, Vec2d maxSize)
{
InternalIO.glfw.SetWindowSizeLimits(
this.windowID,
(int)minSize.X, (int)minSize.Y, (int)maxSize.X, (int)maxSize.Y);
}
#endregion
}
}