daily uodate on 20231208 by nitload youmu, preparation for multi thread rendering

This commit is contained in:
Nitload
2023-12-08 05:36:04 +08:00
parent ae804553ce
commit ab85c1a9fe
297 changed files with 157896 additions and 5170 deletions
+84 -27
View File
@@ -1,15 +1,14 @@
using StgSharp.Math;
using StgSharp.Controlling;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Xml.Linq;
namespace StgSharp.Graphics
{
@@ -22,38 +21,29 @@ namespace StgSharp.Graphics
public string name;
}
public unsafe partial class Form
/// <summary>
///
/// </summary>
public unsafe abstract partial class Form
{
internal LinkedList<Pool> allControl;
internal LinkedList<Control> allControl;
internal Vector4 color;
internal Thread formThread;
internal int height;
internal IntPtr monitor;
internal string name;
internal Form sharedForm = null;
internal Form sharedForm;
internal int width;
internal IntPtr windowID = default;
internal IntPtr windowID;
protected IglFunc GL;
/// <summary>
/// Constructor of a Form, creats an instance of a form and
/// initilize all the customizing operations.
/// </summary>
public Form(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;
}
internal Form()
{ }
private GLonRender glRender;
private GLonUpdate glUpdate;
~Form()
{
GL.gl = default;
Marshal.FreeHGlobal((IntPtr)contextID);
glRender.api = default;
}
public int Height
@@ -78,10 +68,53 @@ namespace StgSharp.Graphics
set => width = value;
}
#region form main
public abstract void Deinit(object[] args);
public abstract void Init(object[] args);
public abstract void OnRenderFrame(object[] args);
public abstract void OnUpdateFrame(object[] args);
internal void internalShowForm(object arg)
{
object[] args = (object[])arg;
Init((object[])args[0]);
while (InternalIO.glfw.WindowShouldClose(windowID) == 0)
{
OnUpdateFrame((object[])args[1]);
}
Deinit((object[])args[2]);
}
internal void InternalUpdateFrame(object args)
{
OnUpdateFrame((object[])args);
}
#endregion
/// <summary>
///
/// Constructor of a Form, creats an instance of a form and
/// initilize all the customizing operations.
/// </summary>
/// <exception cref="Exception"></exception>
public void InitForm(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>
/// 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 void MakeAsCurrentContext()
{
if (windowID == default)
@@ -107,6 +140,7 @@ namespace StgSharp.Graphics
{
windowID = windowPtr;
}
glRender = new GLonRender();
glContext = new GLcontext();
IntPtr ptr = Marshal.AllocHGlobal(sizeof(GLcontextIO));
contextID = (GLcontextIO*)ptr;
@@ -114,10 +148,10 @@ namespace StgSharp.Graphics
InternalIO.InternalWriteLog("Successfully create a context binded to current form. " +
$"Its ID is {(ulong)ptr}", LogType.Info);
}
GL.gl = glContext;
InternalIO.InternalSetCurrentGLContext(windowID, (IntPtr)contextID);
}
/// <summary>
/// Resize the current form
/// </summary>
@@ -172,5 +206,28 @@ namespace StgSharp.Graphics
this.windowID,
(int)minSize.X, (int)minSize.Y, (int)maxSize.X, (int)maxSize.Y);
}
public void ShowForm(
object[] initArgs,
object[] updateArgs,
object[] deinitArgs)
{
Thread t = new Thread(new ParameterizedThreadStart(internalShowForm));
t.Start(new object[] { initArgs, updateArgs, deinitArgs });
}
public void ShowForm()
{
Thread t = new Thread(new ParameterizedThreadStart(internalShowForm));
t.Start(new object[3] { null, null, null });
}
/// <summary>
/// Bind this form to StgSharp platform.
/// </summary>
protected void BindToPlatform()
{
TimeLine.allForm.Add(this);
}
}
}