daily update on 20240315 by nitload youmu
This commit is contained in:
@@ -29,9 +29,8 @@ namespace StgSharp.Graphics
|
||||
|
||||
internal LinkedList<Control> allControl;
|
||||
internal Vector4 backgroundColor;
|
||||
internal unsafe GLcontext* contextID;
|
||||
internal DynamicArrayList<IntPtr> formBuffer;
|
||||
internal IglFunc gl;
|
||||
internal unsafe IntPtr graphicContextID;
|
||||
internal int height;
|
||||
internal IntPtr monitor;
|
||||
internal string name;
|
||||
@@ -39,13 +38,12 @@ namespace StgSharp.Graphics
|
||||
internal int width;
|
||||
internal IntPtr windowID;
|
||||
|
||||
protected readonly TimeProvider FrameTimeFrocider;
|
||||
|
||||
#endregion metadata
|
||||
|
||||
#region form thread setting
|
||||
|
||||
internal FrameUpdateTimer timer = new FrameUpdateTimer();
|
||||
private SemaphoreSlim _renderFinishSignal = new SemaphoreSlim(0, 1);
|
||||
private SemaphoreSlim _renderStartSignal = new SemaphoreSlim(1, 1);
|
||||
private bool isSingleThread = true;
|
||||
|
||||
#endregion form thread setting
|
||||
@@ -57,15 +55,12 @@ namespace StgSharp.Graphics
|
||||
|
||||
#endregion glapicount
|
||||
|
||||
private int _shouldClose = 0;
|
||||
|
||||
protected Form()
|
||||
{
|
||||
}
|
||||
|
||||
unsafe ~Form()
|
||||
{
|
||||
Marshal.FreeHGlobal((IntPtr)contextID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OpenGL package used by current form context.
|
||||
/// </summary>
|
||||
@@ -92,8 +87,6 @@ namespace StgSharp.Graphics
|
||||
get { return isSingleThread; }
|
||||
}
|
||||
|
||||
private int _shouldClose = 0;
|
||||
|
||||
public bool ShouldClose
|
||||
{
|
||||
get
|
||||
@@ -136,18 +129,6 @@ namespace StgSharp.Graphics
|
||||
get { return isSingleThread; }
|
||||
}
|
||||
|
||||
internal SemaphoreSlim RenderFinishSignal
|
||||
{
|
||||
get { return _renderFinishSignal; }
|
||||
set { _renderFinishSignal = value; }
|
||||
}
|
||||
|
||||
internal SemaphoreSlim RenderStrartSignal
|
||||
{
|
||||
get { return _renderStartSignal; }
|
||||
set { _renderStartSignal = value; }
|
||||
}
|
||||
|
||||
protected FrameBufferSizeHandler FrameBufferSizeCallback
|
||||
{
|
||||
set
|
||||
@@ -188,8 +169,8 @@ namespace StgSharp.Graphics
|
||||
windowID = windowPtr;
|
||||
}
|
||||
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GLcontext)));
|
||||
contextID = (GLcontext*)ptr;
|
||||
graphicContextID = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GLcontext)));
|
||||
GLcontext* contextID = (GLcontext*)graphicContextID;
|
||||
*contextID = new GLcontext();
|
||||
contextID->glGetString = (delegate*<uint, IntPtr>)IntPtr.Zero;
|
||||
gl = new GLonRender(contextID);
|
||||
@@ -267,6 +248,11 @@ namespace StgSharp.Graphics
|
||||
(int)minSize.X, (int)minSize.Y, (int)maxSize.X, (int)maxSize.Y);
|
||||
}
|
||||
|
||||
unsafe ~Form()
|
||||
{
|
||||
Marshal.FreeHGlobal(graphicContextID);
|
||||
}
|
||||
|
||||
#region form main
|
||||
|
||||
private static unsafe delegate*<void> pollEventPtr = &InternalIO.glfwPollEvents;
|
||||
@@ -309,35 +295,52 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
InternalIO.InternalWriteLog($"Attempt to show form {name} before init", LogType.Error);
|
||||
}
|
||||
else if (isSingleThread)
|
||||
{
|
||||
while (!ShouldClose)
|
||||
{
|
||||
Main(args);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gl = new GLonUpdate(contextID);
|
||||
Thread renderThread = new Thread(new ThreadStart(InternalRender));
|
||||
renderThread.Start();
|
||||
int a = 0;
|
||||
while (!ShouldClose)
|
||||
if (isSingleThread)
|
||||
{
|
||||
if (gl.FrameCanUpdate)
|
||||
while (!ShouldClose)
|
||||
{
|
||||
Main(args);
|
||||
SwapBuffers();
|
||||
}
|
||||
}
|
||||
//TODO 对逻辑线程和渲染线程进行同步,两种gl模式包需要改名字
|
||||
renderThread.Join();
|
||||
//Thread.Sleep(1000 * 20);
|
||||
//ShouldClose = true;
|
||||
//(gl as GLonUpdate).GLactionQueue.Clear();
|
||||
else
|
||||
{
|
||||
GLonUpdate update = new GLonUpdate((GLcontext*)graphicContextID);
|
||||
FrameThread renderThread = new FrameThread(update);
|
||||
FrameThread updateThread = new FrameThread(update);
|
||||
renderThread.SetNext(updateThread);
|
||||
updateThread.SetNext(renderThread);
|
||||
gl = update;
|
||||
int a = 0;
|
||||
while (!ShouldClose)
|
||||
{
|
||||
}
|
||||
//TODO 对逻辑线程和渲染线程进行同步,两种gl模式包需要改名字
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe void SwapBuffers()
|
||||
internal static unsafe void InternalSwapBuffers()
|
||||
{
|
||||
IntPtr winHandle = default;
|
||||
InternalIO.glfwSwapBuffers(winHandle);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void InternalDeinit(params object[] args)
|
||||
{
|
||||
Deinit(args);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void InternalInit(params object[] args)
|
||||
{
|
||||
Init(args);
|
||||
}
|
||||
|
||||
internal unsafe void SwapBuffers()
|
||||
{
|
||||
if (isSingleThread)
|
||||
{
|
||||
@@ -351,30 +354,13 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
internal static unsafe void InternalSwapBuffers()
|
||||
{
|
||||
IntPtr winHandle = default;
|
||||
GLonUpdate.ParamQueue.TryDequeue(out winHandle);
|
||||
InternalIO.glfwSwapBuffers(winHandle);
|
||||
}
|
||||
|
||||
internal void InternalDeinit(params object[] args)
|
||||
{
|
||||
Deinit(args);
|
||||
}
|
||||
|
||||
internal void InternalInit(params object[] args)
|
||||
{
|
||||
Init(args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get OpenGL library of this form's context.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="IglFunc"/> package contains all opengl APIs </returns>
|
||||
protected IglFunc GetGL()
|
||||
{
|
||||
if (Platform.API == GraphicAPI.GL)
|
||||
if (StgSharp.API == GraphicAPI.GL)
|
||||
{
|
||||
return this.GL;
|
||||
}
|
||||
@@ -409,33 +395,6 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
throw new ArgumentException("Amount of threads should be bigger than 0");
|
||||
}
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GLcontext)));
|
||||
contextID = (GLcontext*)ptr;
|
||||
*contextID = new GLcontext();
|
||||
contextID->glGetString = (delegate*<uint, IntPtr>)IntPtr.Zero;
|
||||
}
|
||||
|
||||
private unsafe void InternalRender()
|
||||
{
|
||||
#pragma warning disable CS8602
|
||||
ConcurrentQueue<IntPtr> glActions = (gl as GLonUpdate).GLactionQueue;
|
||||
#pragma warning restore CS8602
|
||||
IntPtr currentOperation;
|
||||
try
|
||||
{
|
||||
while (_shouldClose == 0)
|
||||
{
|
||||
if (glActions.TryDequeue(out currentOperation))
|
||||
{
|
||||
((delegate*<void>)currentOperation)();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.ShouldClose = true;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion form main
|
||||
|
||||
Reference in New Issue
Block a user