daily update on 20240325 by nitload youmu
This commit is contained in:
@@ -46,33 +46,6 @@ namespace StgSharp.Graphics
|
||||
/// </summary>
|
||||
public abstract unsafe partial class Form
|
||||
{
|
||||
#region metadata
|
||||
internal LinkedList<Control> allControl;
|
||||
internal Vector4 backgroundColor;
|
||||
internal IglFunc gl;
|
||||
internal IntPtr graphicContextID;
|
||||
internal int height;
|
||||
internal IntPtr monitor;
|
||||
internal string name;
|
||||
internal Form sharedForm;
|
||||
internal int width;
|
||||
private GLFWwindow* windowID;
|
||||
|
||||
#endregion metadata
|
||||
|
||||
#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()
|
||||
{
|
||||
@@ -127,7 +100,7 @@ namespace StgSharp.Graphics
|
||||
set => width = value;
|
||||
}
|
||||
|
||||
public unsafe IntPtr WindowID => (IntPtr)windowID;
|
||||
public unsafe IntPtr WindowID => windowID;
|
||||
|
||||
protected FrameBufferSizeHandler FrameBufferSizeCallback
|
||||
{
|
||||
@@ -138,7 +111,7 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
internal unsafe GLFWwindow* id => windowID;
|
||||
internal unsafe IntPtr id => windowID;
|
||||
|
||||
internal bool IsSingleThread => isSingleThread;
|
||||
|
||||
@@ -173,7 +146,7 @@ namespace StgSharp.Graphics
|
||||
byte[] tittleBytes = Encoding.UTF8.GetBytes(name);
|
||||
if (sharedForm == null)
|
||||
{
|
||||
windowPtr = InternalIO.glfwCreateWindow(width, height, tittleBytes, monitor, (GLFWwindow*)IntPtr.Zero);
|
||||
windowPtr = InternalIO.glfwCreateWindow(width, height, tittleBytes, monitor, IntPtr.Zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -185,7 +158,7 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
else
|
||||
{
|
||||
windowID = (GLFWwindow*)windowPtr;
|
||||
windowID = windowPtr;
|
||||
}
|
||||
|
||||
graphicContextID = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GLcontext)));
|
||||
@@ -271,6 +244,35 @@ namespace StgSharp.Graphics
|
||||
public void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
|
||||
{ InternalIO.glfwSetWindowSizeLimits(this.windowID, minWidth, minHeight, maxWidth, maxHeight); }
|
||||
|
||||
#region metadata
|
||||
internal LinkedList<Control> allControl;
|
||||
internal Vector4 backgroundColor;
|
||||
internal IglFunc gl;
|
||||
internal IntPtr graphicContextID;
|
||||
internal int height;
|
||||
internal IntPtr monitor;
|
||||
internal string name;
|
||||
internal Form sharedForm;
|
||||
internal int width;
|
||||
private IntPtr windowID;
|
||||
|
||||
#endregion metadata
|
||||
|
||||
#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<FrameAsyncThread> frameAsyncTaskList = new List<FrameAsyncThread>();
|
||||
#endregion form thread setting
|
||||
|
||||
|
||||
#region form main
|
||||
|
||||
/// <summary>
|
||||
@@ -297,33 +299,42 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
else
|
||||
{
|
||||
GLonUpdate update = new GLonUpdate((GLcontext*)graphicContextID);
|
||||
FrameAsyncTask updateTask = new AsyncUpdateDataTask(this);
|
||||
FrameAsyncTask renderTask = new AsyncRenderFrameTask(this);
|
||||
frameAsyncTaskList.Add(renderTask);
|
||||
frameAsyncTaskList.Add(updateTask);
|
||||
GLonUpdate update = new GLonUpdate((GLcontext*)graphicContextID); //更换GL库至双线程模式
|
||||
FrameAsyncThread updateT = new AsyncUpdateDataTask(this); //建立两个异步线程
|
||||
FrameAsyncThread renderT = new AsyncRenderFrameTask(this);
|
||||
|
||||
frameAsyncTaskList.Add(renderT);
|
||||
frameAsyncTaskList.Add(updateT);
|
||||
gl = update;
|
||||
update.ActivatedOperationBuffer = updateTask.opBuffer;
|
||||
SemaphoreSlim frameBeginSemaphore = FrameAsyncTask.CombineAsync(renderTask, updateTask);
|
||||
SemaphoreSlim renderCompleteSemaphor = renderTask.StartAsync();
|
||||
SemaphoreSlim updateCompleteSemaphor = updateTask.StartAsync();
|
||||
|
||||
update.ActivatedOperationBuffer = updateT.opBuffer;
|
||||
SemaphoreSlim frameBeginSemaphore = FrameAsyncThread.CombineAsync(renderT, updateT);
|
||||
SemaphoreSlim renderCompleteSemaphor = renderT.AsyncStart();
|
||||
SemaphoreSlim updateCompleteSemaphor = updateT.AsyncStart();
|
||||
|
||||
while (!ShouldClose)
|
||||
{
|
||||
frameBeginSemaphore.Release(2);
|
||||
renderCompleteSemaphor.Wait();
|
||||
Console.WriteLine(1);
|
||||
frameBeginSemaphore.Release(2); //启动下一个渲染循环
|
||||
Console.WriteLine(2);
|
||||
renderCompleteSemaphor.Wait(); //等待两个线程完成
|
||||
updateCompleteSemaphor.Wait();
|
||||
SwapBuffers();
|
||||
Console.WriteLine(3);
|
||||
SwapBuffers(); //GLFW必要操作
|
||||
PollEvents();
|
||||
FrameAsyncTask.ExchangeBuffer(updateTask, renderTask);
|
||||
update.ActivatedOperationBuffer = updateTask.opBuffer;
|
||||
frameTimeProvider.WaitNextSpan();
|
||||
Console.WriteLine(4);
|
||||
FrameAsyncThread.ExchangeBuffer(updateT, renderT); //交换两个线程的缓冲区
|
||||
update.ActivatedOperationBuffer = updateT.opBuffer;
|
||||
Console.WriteLine(5);
|
||||
frameTimeProvider.WaitNextSpan(); //等待下一帧开始
|
||||
Console.WriteLine(6);
|
||||
}
|
||||
//TODO 对逻辑线程和渲染线程进行同步,两种gl模式包需要改名字
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int CurrentFrameCount
|
||||
=> frameTimeProvider.CurrentSpan;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void InternalDeinit(params object[] args) { Deinit(args); }
|
||||
@@ -384,6 +395,7 @@ namespace StgSharp.Graphics
|
||||
|
||||
|
||||
|
||||
#endregion form main
|
||||
#endregion form main
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user