daily update on 20231214 by nitload youmu
This commit is contained in:
@@ -15,14 +15,6 @@ using System.Threading;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct formInfo
|
||||
{
|
||||
public int width;
|
||||
public int height;
|
||||
public Vector4 color;
|
||||
public string name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
@@ -39,12 +31,15 @@ namespace StgSharp.Graphics
|
||||
internal int width;
|
||||
internal IntPtr windowID;
|
||||
|
||||
private GLonRender glRender;
|
||||
private GLonUpdate glUpdate;
|
||||
protected IglFunc GL;
|
||||
internal FormUpdateBuffer UpdateBuffer;
|
||||
internal FormRenderBuffer RenderBuffer;
|
||||
|
||||
internal FrameUpdateTimer timer = new FrameUpdateTimer();
|
||||
|
||||
private SemaphoreSlim ping = new SemaphoreSlim(1, 1);
|
||||
private SemaphoreSlim pong = new SemaphoreSlim(0, 1);
|
||||
internal readonly SemaphoreSlim ouetrPong = new SemaphoreSlim(0, 1);
|
||||
|
||||
private UpdateWhenRender updateWhenRender;
|
||||
private DynamicMethod updateWhenRenderDM;
|
||||
@@ -83,18 +78,18 @@ namespace StgSharp.Graphics
|
||||
unsafe ~Form()
|
||||
{
|
||||
Marshal.FreeHGlobal((IntPtr)contextID);
|
||||
glRender.api = default;
|
||||
RenderBuffer.GL.api = default;
|
||||
}
|
||||
|
||||
#region form main
|
||||
|
||||
public abstract void Deinit(object[] args, IglFunc GL);
|
||||
public abstract void Deinit(object[] args);
|
||||
|
||||
public abstract void Init(object[] args, IglFunc GL);
|
||||
public abstract void Init(object[] args);
|
||||
|
||||
public abstract void OnRenderFrame(object[] args, IglFunc GL);
|
||||
public abstract void OnRenderFrame(object[] args);
|
||||
|
||||
public abstract void OnUpdateFrame(object[] args, IglFunc GL);
|
||||
public abstract void OnUpdateFrame(object[] args);
|
||||
|
||||
/// <summary>
|
||||
/// Init this form and render it on screen, and respond with operation
|
||||
@@ -103,16 +98,20 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
if (args == null)
|
||||
{
|
||||
args = new object[3] { null, null, null };
|
||||
args = new object[4] { null, null, null, null };
|
||||
}
|
||||
Operation.RegistForm(this);
|
||||
if (!TimeLine.RenderStarted)
|
||||
{
|
||||
TimeLine.RenderAll();
|
||||
}
|
||||
try
|
||||
{
|
||||
Thread updateThread = new Thread(InternalUpdateFrame);
|
||||
Thread renderThread = new Thread(InternalRenderFrame);
|
||||
|
||||
updateThread.Start();
|
||||
renderThread.Start();
|
||||
updateThread.Start(args[1]);
|
||||
renderThread.Start(args[2]);
|
||||
|
||||
updateThread.Join();
|
||||
renderThread.Join();
|
||||
@@ -120,6 +119,8 @@ namespace StgSharp.Graphics
|
||||
ping.Dispose();
|
||||
pong.Dispose();
|
||||
|
||||
InternalDeinit(args[3]);
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -127,7 +128,12 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
internal void InternalInit(object[] args)
|
||||
internal void InternalDeinit(object args)
|
||||
{
|
||||
Deinit((object[])args);
|
||||
}
|
||||
|
||||
internal void InternalInit(object args)
|
||||
{
|
||||
updateWhenRenderDM = new DynamicMethod(
|
||||
name: "updateWhenRender",
|
||||
@@ -137,7 +143,7 @@ namespace StgSharp.Graphics
|
||||
);
|
||||
updateWhenRenderIL = updateWhenRenderDM.GetILGenerator();
|
||||
|
||||
Init((object[])args, this.glRender);
|
||||
Init((object[])args);
|
||||
|
||||
}
|
||||
|
||||
@@ -149,9 +155,9 @@ namespace StgSharp.Graphics
|
||||
ping.Wait();
|
||||
try
|
||||
{
|
||||
OnRenderFrame((object[])args, glRender);
|
||||
timer.GoNextFrame();
|
||||
throw new Exception("Forget to reload GL apis");
|
||||
OnRenderFrame((object[])args);
|
||||
timer.WaitNextFrame();
|
||||
|
||||
pong.Release();
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
@@ -162,7 +168,6 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void InternalUpdateFrame(object args)
|
||||
{
|
||||
while (InternalIO.glfw.WindowShouldClose(windowID) != 0)
|
||||
@@ -170,8 +175,8 @@ namespace StgSharp.Graphics
|
||||
pong.Wait();
|
||||
try
|
||||
{
|
||||
OnUpdateFrame((object[])args, glUpdate);
|
||||
timer.GoNextFrame();
|
||||
OnUpdateFrame((object[])args);
|
||||
timer.WaitNextFrame();
|
||||
throw new Exception("Forget to reload GL apis");
|
||||
ping.Release();
|
||||
}
|
||||
@@ -297,12 +302,5 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Bind this form to StgSharp platform.
|
||||
/// </summary>
|
||||
protected void BindToPlatform()
|
||||
{
|
||||
TimeLine.allForm.Add(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user