daily update on 20240320 by nitload youmu

This commit is contained in:
YoumuLiu
2024-03-21 02:01:17 +08:00
parent 0c50c6282e
commit 9a10ec201c
91 changed files with 1150 additions and 1815 deletions
+56 -47
View File
@@ -58,22 +58,22 @@ namespace StgSharp.Graphics
internal int width;
private GLFWwindow* windowID;
internal TimeSpanProvider frameTimeProvider;
#endregion metadata
#region glapicount
private int missingAPIcount = 0;
private int problemAPIcount = 0;
#endregion glapicount
#region form main
#region form time
private short fpsCount;
internal TimeSpanProvider frameTimeProvider;
internal TimeSpanProvider fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
#endregion
#region form thread setting
private bool isSingleThread = true;
private List<FrameAsyncTask> frameAsyncTaskList = new List<FrameAsyncTask>();
#endregion form thread setting
protected Form()
{
}
@@ -129,8 +129,6 @@ namespace StgSharp.Graphics
public unsafe IntPtr WindowID => (IntPtr)windowID;
internal unsafe GLFWwindow* id => windowID;
protected FrameBufferSizeHandler FrameBufferSizeCallback
{
set
@@ -140,8 +138,26 @@ namespace StgSharp.Graphics
}
}
internal unsafe GLFWwindow* id => windowID;
internal bool IsSingleThread => isSingleThread;
public abstract void Deinit(params object[] args);
/// <summary>
/// Necessary operation to init this form.
/// </summary>
/// <param name="args"></param>
public abstract void Init(params object[] args);
/// <summary>
/// Behaviour of current form when in a frame cycle.
/// </summary>
/// <param name="args"></param>
public abstract void Main();
/// <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.
@@ -179,7 +195,12 @@ namespace StgSharp.Graphics
gl = new GLonRender(contextID);
}
InternalIO.glfwMakeContextCurrent(windowID);
gl.SwitchContext();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void PollEvents()
{
InternalIO.glfwPollEvents();
}
/// <summary>
@@ -250,33 +271,12 @@ namespace StgSharp.Graphics
public void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
{ InternalIO.glfwSetWindowSizeLimits(this.windowID, minWidth, minHeight, maxWidth, maxHeight); }
unsafe ~Form() { Marshal.FreeHGlobal(graphicContextID); }
public abstract void Deinit(params object[] args);
/// <summary>
/// Necessary operation to init this form.
/// </summary>
/// <param name="args"></param>
public abstract void Init(params object[] args);
/// <summary>
/// Behaviour of current form when in a render cycle. When this form
/// </summary>
/// <param name="args"></param>
public abstract void Main(params object[] args);
public unsafe void PollEvents()
{
InternalIO.glfwPollEvents();
}
#region form main
/// <summary>
/// Init this form and render it on screen, and respond with operation
/// </summary>
public unsafe void Show(params object[] args)
public unsafe void Show()
{
if (gl == null)
{
@@ -284,40 +284,46 @@ namespace StgSharp.Graphics
}
else
{
frameTimeProvider = new TimeSpanProvider(1 / 60.0, TimeSpanProvider.DefaultProvider);
if (isSingleThread)
{
while (!ShouldClose)
{
Main(args);
Main();
SwapBuffers();
PollEvents();
frameTimeProvider.WaitNextSpan();
}
}
else
{
GLonUpdate update = new GLonUpdate((GLcontext*)graphicContextID);
FrameAsyncTask renderTask = new FrameAsyncTask(update);
FrameAsyncTask updateTask = new FrameAsyncTask(update);
FrameAsyncTask updateTask = new AsyncUpdateDataTask(this);
FrameAsyncTask renderTask = new AsyncRenderFrameTask(this);
frameAsyncTaskList.Add(renderTask);
frameAsyncTaskList.Add(updateTask);
gl = update;
update.ActivatedOperationBuffer = updateTask.opBuffer;
SemaphoreSlim frameBeginSemaphore = FrameAsyncTask.CombineAsync(renderTask, updateTask);
SemaphoreSlim renderCompleteSemaphor = renderTask.StartAsync();
SemaphoreSlim updateCompleteSemaphor = updateTask.StartAsync();
while (!ShouldClose)
{
renderTask.StartAsync();
updateTask.StartAsync();
FrameAsyncTask.CombineAsync(renderTask, updateTask);
frameBeginSemaphore.Release(2);
renderCompleteSemaphor.Wait();
updateCompleteSemaphor.Wait();
SwapBuffers();
PollEvents();
FrameAsyncTask.ExchangeBuffer(updateTask, renderTask);
update.ActivatedOperationBuffer = updateTask.opBuffer;
frameTimeProvider.WaitNextSpan();
}
//TODO 对逻辑线程和渲染线程进行同步,两种gl模式包需要改名字
}
}
}
internal static unsafe void InternalSwapBuffers(FrameOperationBuffer operationBuffer, GLcontext* context)
{
IntPtr window = default;
operationBuffer.TryDequeue(out window);
InternalIO.glfwSwapBuffers((GLFWwindow*)window);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void InternalDeinit(params object[] args) { Deinit(args); }
@@ -373,8 +379,11 @@ namespace StgSharp.Graphics
throw new ArgumentException("Amount of threads should be bigger than 0");
}
}
#endregion form main
unsafe ~Form() { Marshal.FreeHGlobal(graphicContextID); }
#endregion form main
}
}