daily update on 20240315 by nitload youmu

This commit is contained in:
YoumuLiu
2024-03-16 03:09:00 +08:00
parent a770bbe685
commit 15bf989285
84 changed files with 1064 additions and 1981 deletions
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -795,58 +795,6 @@
The second <see cref="T:System.Boolean"/> value. The second <see cref="T:System.Boolean"/> value.
</summary> </summary>
</member> </member>
<member name="P:StgSharp.LinkedList`1.IsEmpty">
<summary>
Whether this linked list has no members or not.
</summary>
</member>
<member name="P:StgSharp.LinkedList`1.First">
<summary>
The first memeber of this linkec list.
Set value to this property will reset the first node.
</summary>
</member>
<member name="P:StgSharp.LinkedList`1.Tail">
<summary>
The last memeber of this linkec list.
Set value to this property will reset the first node.
</summary>
</member>
<member name="M:StgSharp.LinkedList`1.Add(`0)">
<summary>
Add an item to the tail of linked list.
</summary>
<param name="t">The item ready to add to the list</param>
</member>
<member name="M:StgSharp.LinkedList`1.Clear">
<summary>
Remove all members from this list
</summary>
</member>
<member name="M:StgSharp.LinkedList`1.InsertAfter(`0,`0)">
<summary>
Insert a member to current linkedlist,
the new member will be after a certain existed member.
</summary>
<param name="target">New member will be inserted after this member</param>
<param name="newMember">The new member to be inserted</param>
</member>
<member name="M:StgSharp.LinkedList`1.Remove(`0)">
<summary>
Remove a member from this linkedlist.
</summary>
<param name="value">Member to be removed from this list</param>
</member>
<member name="M:StgSharp.LinkedList`1.RemoveFirst">
<summary>
remove the first member of the list
</summary>
</member>
<member name="M:StgSharp.LinkedList`1.RemoveTail">
<summary>
remove the last member of the list
</summary>
</member>
<member name="T:StgSharp.Math.GLclampf"> <member name="T:StgSharp.Math.GLclampf">
<summary> <summary>
OpenGL numeric type. OpenGL numeric type.
-4
View File
@@ -24,10 +24,6 @@ namespace StgSharp
CallingConvention = CallingConvention.Cdecl)] CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe uint InternalLinkShaderProgram(GLcontext* context, uint shaderProgram); internal static extern unsafe uint InternalLinkShaderProgram(GLcontext* context, uint shaderProgram);
[DllImport(SSC_libname, EntryPoint = "loadShaderCode",
CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern unsafe uint InternalLoadShaderCode(GLcontext* context, byte* shaderCode, int shaderType);
[DllImport(SSC_libname, EntryPoint = "readLog", [DllImport(SSC_libname, EntryPoint = "readLog",
CallingConvention = CallingConvention.Cdecl)] CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe IntPtr InternalReadSSCLog(); internal static extern unsafe IntPtr InternalReadSSCLog();
@@ -1,5 +1,7 @@
using StgSharp.Controlling; using StgSharp.Controlling;
using System; using System;
using System.Collections.Generic;
namespace StgSharp.Entities namespace StgSharp.Entities
{ {
+2 -1
View File
@@ -1,6 +1,8 @@
using StgSharp.Geometries; using StgSharp.Geometries;
using StgSharp.Math; using StgSharp.Math;
using System.Collections.Generic;
namespace StgSharp namespace StgSharp
{ {
public abstract class IEntity public abstract class IEntity
@@ -52,6 +54,5 @@ namespace StgSharp
} }
public abstract void OnRenderFrame(); public abstract void OnRenderFrame();
} }
} }
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp
{
public static unsafe partial class StgSharp
{
/// <summary>
/// Init an instance of OpenGL program,
/// This method should be called before any other StgSharp api.
/// </summary>
public static void InitGL(int majorVersion, int minorVersion)
{
if (API == default)
{
API = GraphicAPI.GL;
}
if (API != GraphicAPI.GL)
{
return;
}
InternalIO.InternalInitGL(majorVersion, minorVersion);
}
public static class GlobalSetting
{
private static bool vSyncActivated;
public static bool VSyncActivated
{
get { return vsyncActivated; }
set
{
InternalIO.glfwSwapInterval(value ? 1 : 0);
vsyncActivated = value;
}
}
}
}
}
+3 -18
View File
@@ -6,6 +6,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@@ -33,10 +34,10 @@ namespace StgSharp
VK VK
} }
public static partial class Platform public static partial class StgSharp
{ {
internal static GraphicAPI API = default; internal static GraphicAPI API = default;
private static bool vsyncActivated;
private static uint markCount = 0; private static uint markCount = 0;
public static void Mark(bool needConsole) public static void Mark(bool needConsole)
@@ -55,22 +56,6 @@ namespace StgSharp
/// </summary> /// </summary>
public const long version = 430; public const long version = 430;
/// <summary>
/// Init an instance of OpenGL program,
/// This method should be called before other
/// graphic methods, after LoadGL method.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void InitGL(int majorVersion, int minorVersion)
{
if (API != default)
{
return;
}
InternalIO.InternalInitGL(majorVersion, minorVersion);
}
/// <summary> /// <summary>
/// Write a log message to log file, and mark the level of this message. /// Write a log message to log file, and mark the level of this message.
/// </summary> /// </summary>
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp
{
public static partial class StgSharp
{
private static Stopwatch mainProvider = new Stopwatch();
private static List<TimeProvider> subscriberList = new List<TimeProvider>();
private static Thread timeProvideThread;
private static long accuracy;
private static void ProvideTime()
{
long totalMS, previousFrameMS = 0,
internalFrequncy = Stopwatch.Frequency;
lock (mainProvider)
{
mainProvider.Restart();
}
while (mainProvider.IsRunning)
{
totalMS = mainProvider.ElapsedTicks / (internalFrequncy / (1000L * 1000L));
foreach (TimeProvider subscriber in subscriberList)
{
subscriber.CheckTime(totalMS);
}
}
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public static void TimerActivate(int maxFrameUpdateSensitiveTimeProviderCount)
{
if (!mainProvider.IsRunning)
{
mainProvider.Start();
//speed test
long totalMS, previousSecondMS = 0,
internalFrequncy = Stopwatch.Frequency;
for (int i = 0; i < 100; i++)
{
totalMS = mainProvider.ElapsedTicks / (internalFrequncy / (1000L * 1000L));
for (int t = 0; t < 10; t++)
{
if (totalMS < 1000)
{
subscriberList.Add(new TimeProvider(100L));
}
}
}
mainProvider.Stop();
subscriberList.Clear();
totalMS = (mainProvider.ElapsedTicks / (internalFrequncy / (1000L * 1000L))) / 100L;
accuracy = totalMS * 2 / 3;
mainProvider.Reset();
timeProvideThread = new Thread(new ThreadStart(ProvideTime));
timeProvideThread.Start();
}
}
public static void SubscribeTimeProvider(TimeProvider provider)
{
}
public static void TimerDeactivate()
{
lock (mainProvider)
{
mainProvider.Stop();
}
}
}
}
@@ -3,13 +3,12 @@ using StgSharp.Math;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
/// <summary> /// <summary>
/// 平面几何体。包含三角形,对称四边形,自由多边形等。最多可由16个点参数定义。 /// 平面几何体。包含三角形,对称四边形,自由多边形等。最多可由16个点参数定义。
/// </summary> /// </summary>
public abstract class PlainGeometry public abstract class PlainGeometry
{ {
protected FrameTimer time; protected TimeProvider time;
internal PartialPlainCoordinate coordinate; internal PartialPlainCoordinate coordinate;
internal Matrix2x4 textureFrame; internal Matrix2x4 textureFrame;
@@ -22,16 +21,18 @@ namespace StgSharp.Geometries
/// <summary> /// <summary>
/// Tick time this geometry eas crested /// Tick time this geometry eas crested
/// </summary> /// </summary>
/// </summary>
public uint BornTime => time; public uint BornTime => time;
internal abstract int[] Indices { get; } internal abstract int[] Indices { get; }
public PlainGeometry(Form form) public PlainGeometry(Form form)
{ {
time = new FrameTimer(form); time = new TimeProvider(form);
} }
public PlainGeometry() { } public PlainGeometry()
{ }
internal abstract void UpdateCoordinate(uint tick); internal abstract void UpdateCoordinate(uint tick);
@@ -48,8 +49,5 @@ namespace StgSharp.Geometries
public abstract Plain GetPlain(); public abstract Plain GetPlain();
//public abstract Rectangle GetRenderFrame(); //public abstract Rectangle GetRenderFrame();
} }
} }
@@ -1,6 +1,7 @@
using StgSharp.Controlling; using StgSharp.Controlling;
using StgSharp.Math; using StgSharp.Math;
using StgSharp.Math.Linear; using StgSharp.Math.Linear;
using System.Numerics; using System.Numerics;
namespace StgSharp.Geometries namespace StgSharp.Geometries
+49 -90
View File
@@ -29,9 +29,8 @@ namespace StgSharp.Graphics
internal LinkedList<Control> allControl; internal LinkedList<Control> allControl;
internal Vector4 backgroundColor; internal Vector4 backgroundColor;
internal unsafe GLcontext* contextID;
internal DynamicArrayList<IntPtr> formBuffer;
internal IglFunc gl; internal IglFunc gl;
internal unsafe IntPtr graphicContextID;
internal int height; internal int height;
internal IntPtr monitor; internal IntPtr monitor;
internal string name; internal string name;
@@ -39,13 +38,12 @@ namespace StgSharp.Graphics
internal int width; internal int width;
internal IntPtr windowID; internal IntPtr windowID;
protected readonly TimeProvider FrameTimeFrocider;
#endregion metadata #endregion metadata
#region form thread setting #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; private bool isSingleThread = true;
#endregion form thread setting #endregion form thread setting
@@ -57,15 +55,12 @@ namespace StgSharp.Graphics
#endregion glapicount #endregion glapicount
private int _shouldClose = 0;
protected Form() protected Form()
{ {
} }
unsafe ~Form()
{
Marshal.FreeHGlobal((IntPtr)contextID);
}
/// <summary> /// <summary>
/// OpenGL package used by current form context. /// OpenGL package used by current form context.
/// </summary> /// </summary>
@@ -92,8 +87,6 @@ namespace StgSharp.Graphics
get { return isSingleThread; } get { return isSingleThread; }
} }
private int _shouldClose = 0;
public bool ShouldClose public bool ShouldClose
{ {
get get
@@ -136,18 +129,6 @@ namespace StgSharp.Graphics
get { return isSingleThread; } get { return isSingleThread; }
} }
internal SemaphoreSlim RenderFinishSignal
{
get { return _renderFinishSignal; }
set { _renderFinishSignal = value; }
}
internal SemaphoreSlim RenderStrartSignal
{
get { return _renderStartSignal; }
set { _renderStartSignal = value; }
}
protected FrameBufferSizeHandler FrameBufferSizeCallback protected FrameBufferSizeHandler FrameBufferSizeCallback
{ {
set set
@@ -188,8 +169,8 @@ namespace StgSharp.Graphics
windowID = windowPtr; windowID = windowPtr;
} }
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GLcontext))); graphicContextID = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GLcontext)));
contextID = (GLcontext*)ptr; GLcontext* contextID = (GLcontext*)graphicContextID;
*contextID = new GLcontext(); *contextID = new GLcontext();
contextID->glGetString = (delegate*<uint, IntPtr>)IntPtr.Zero; contextID->glGetString = (delegate*<uint, IntPtr>)IntPtr.Zero;
gl = new GLonRender(contextID); gl = new GLonRender(contextID);
@@ -267,6 +248,11 @@ namespace StgSharp.Graphics
(int)minSize.X, (int)minSize.Y, (int)maxSize.X, (int)maxSize.Y); (int)minSize.X, (int)minSize.Y, (int)maxSize.X, (int)maxSize.Y);
} }
unsafe ~Form()
{
Marshal.FreeHGlobal(graphicContextID);
}
#region form main #region form main
private static unsafe delegate*<void> pollEventPtr = &InternalIO.glfwPollEvents; 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); InternalIO.InternalWriteLog($"Attempt to show form {name} before init", LogType.Error);
} }
else if (isSingleThread)
{
while (!ShouldClose)
{
Main(args);
}
}
else else
{ {
gl = new GLonUpdate(contextID); if (isSingleThread)
Thread renderThread = new Thread(new ThreadStart(InternalRender));
renderThread.Start();
int a = 0;
while (!ShouldClose)
{ {
if (gl.FrameCanUpdate) while (!ShouldClose)
{ {
Main(args); Main(args);
SwapBuffers();
} }
} }
//TODO 对逻辑线程和渲染线程进行同步,两种gl模式包需要改名字 else
renderThread.Join(); {
//Thread.Sleep(1000 * 20); GLonUpdate update = new GLonUpdate((GLcontext*)graphicContextID);
//ShouldClose = true; FrameThread renderThread = new FrameThread(update);
//(gl as GLonUpdate).GLactionQueue.Clear(); 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) 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> /// <summary>
/// Get OpenGL library of this form's context. /// Get OpenGL library of this form's context.
/// </summary> /// </summary>
/// <returns>A <see cref="IglFunc"/> package contains all opengl APIs </returns> /// <returns>A <see cref="IglFunc"/> package contains all opengl APIs </returns>
protected IglFunc GetGL() protected IglFunc GetGL()
{ {
if (Platform.API == GraphicAPI.GL) if (StgSharp.API == GraphicAPI.GL)
{ {
return this.GL; return this.GL;
} }
@@ -409,33 +395,6 @@ namespace StgSharp.Graphics
{ {
throw new ArgumentException("Amount of threads should be bigger than 0"); 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 #endregion form main
+71 -40
View File
@@ -7,22 +7,22 @@ using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.Graphics namespace StgSharp.Graphics
{ {
internal sealed class FrameOperationBuffer internal sealed class FrameOperationBuffer
{ {
private readonly unsafe GLcontext* currentContext;
private IntPtr _func; private IntPtr _func;
private ConcurrentQueue<IntPtr> _funcQueue; private ConcurrentQueue<IntPtr> _funcQueue;
private GLparamQueue _param;
internal unsafe GLcontext* context;
public unsafe bool CallNext() public unsafe bool CallNext()
{ {
if (_funcQueue.TryDequeue(out _func)) if (_funcQueue.TryDequeue(out _func))
{ {
((delegate*<void>)_func)(); ((delegate*<FrameOperationBuffer, GLcontext*, void>)_func)(this, currentContext);
return true; return true;
} }
else else
@@ -37,148 +37,154 @@ namespace StgSharp.Graphics
private ConcurrentQueue<glArrayHandle> streamQueue = new ConcurrentQueue<glArrayHandle>(); private ConcurrentQueue<glArrayHandle> streamQueue = new ConcurrentQueue<glArrayHandle>();
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(Vec4d v) public void MethodEnqueue(IntPtr p)
{
_funcQueue.Enqueue(p);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ParamEnqueue(Vec4d v)
{ {
paramQueue.Enqueue(v); paramQueue.Enqueue(v);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(M128 m) public void ParamEnqueue(M128 m)
{ {
paramQueue.Enqueue(m); paramQueue.Enqueue(m);
Console.WriteLine(paramQueue.Count + streamQueue.Count); Console.WriteLine(paramQueue.Count + streamQueue.Count);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(uint u0) public void ParamEnqueue(uint u0)
{ {
M128 m = default; M128 m = default;
m.Write<uint>(0, u0); m.Write<uint>(0, u0);
this.Enqueue(m); this.ParamEnqueue(m);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(uint u0, uint u1) public void ParamEnqueue(uint u0, uint u1)
{ {
M128 m = default; M128 m = default;
m.Write<uint>(0, u0); m.Write<uint>(0, u0);
m.Write<uint>(1, u1); m.Write<uint>(1, u1);
this.Enqueue(m); this.ParamEnqueue(m);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(ulong u0, ulong u1) public void ParamEnqueue(ulong u0, ulong u1)
{ {
M128 m = default; M128 m = default;
m.Write<ulong>(0, u0); m.Write<ulong>(0, u0);
m.Write<ulong>(1, u1); m.Write<ulong>(1, u1);
this.Enqueue(m); this.ParamEnqueue(m);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(uint u0, uint u1, uint u2) public void ParamEnqueue(uint u0, uint u1, uint u2)
{ {
M128 m = default; M128 m = default;
m.Write<uint>(0, u0); m.Write<uint>(0, u0);
m.Write<uint>(1, u1); m.Write<uint>(1, u1);
m.Write<uint>(2, u2); m.Write<uint>(2, u2);
this.Enqueue(m); this.ParamEnqueue(m);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(float f0, float f1, float f2) public void ParamEnqueue(float f0, float f1, float f2)
{ {
M128 m = default; M128 m = default;
m.Write<float>(0, f0); m.Write<float>(0, f0);
m.Write<float>(1, f1); m.Write<float>(1, f1);
this.Enqueue(m); this.ParamEnqueue(m);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(float f0, float f1, float f2, float f3) public void ParamEnqueue(float f0, float f1, float f2, float f3)
{ {
M128 m = default; M128 m = default;
m.Write<float>(0, f0); m.Write<float>(0, f0);
m.Write<float>(1, f1); m.Write<float>(1, f1);
m.Write<float>(2, f2); m.Write<float>(2, f2);
m.Write<float>(3, f3); m.Write<float>(3, f3);
this.Enqueue(m); this.ParamEnqueue(m);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(IntPtr p0, IntPtr p1) public void ParamEnqueue(IntPtr p0, IntPtr p1)
{ {
M128 m = default; M128 m = default;
m.Write<ulong>(0, (ulong)p0); m.Write<ulong>(0, (ulong)p0);
m.Write<ulong>(1, (ulong)p1); m.Write<ulong>(1, (ulong)p1);
this.Enqueue(m); this.ParamEnqueue(m);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(IntPtr p) public void ParamEnqueue(IntPtr p)
{ {
M128 m = default; M128 m = default;
m.Write<ulong>(0, (ulong)p); m.Write<ulong>(0, (ulong)p);
this.Enqueue(m); this.ParamEnqueue(m);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Enqueue(glHandle handle) public unsafe void ParamEnqueue(glHandle handle)
{ {
M128 m = default; M128 m = default;
m.Write<ulong>(0, (ulong)handle.valuePtr); m.Write<ulong>(0, (ulong)handle.valuePtr);
this.Enqueue(m); this.ParamEnqueue(m);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Enqueue(glHandle handle, glHandle handle1) public unsafe void ParamEnqueue(glHandle handle, glHandle handle1)
{ {
M128 m = default; M128 m = default;
m.Write<ulong>(0, (ulong)handle.valuePtr); m.Write<ulong>(0, (ulong)handle.valuePtr);
m.Write<ulong>(1, (ulong)handle1.valuePtr); m.Write<ulong>(1, (ulong)handle1.valuePtr);
this.Enqueue(m); this.ParamEnqueue(m);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(int i0) public void ParamEnqueue(int i0)
{ {
M128 m = default; M128 m = default;
m.Write<int>(0, i0); m.Write<int>(0, i0);
this.Enqueue(m); this.ParamEnqueue(m);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(int i0, int i1) public void ParamEnqueue(int i0, int i1)
{ {
M128 m = default; M128 m = default;
m.Write<int>(0, i0); m.Write<int>(0, i0);
m.Write<int>(1, i1); m.Write<int>(1, i1);
this.Enqueue(m); this.ParamEnqueue(m);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(int i0, int i1, int i2) public void ParamEnqueue(int i0, int i1, int i2)
{ {
M128 m = default; M128 m = default;
m.Write<int>(0, i0); m.Write<int>(0, i0);
m.Write<int>(1, i1); m.Write<int>(1, i1);
m.Write<int>(2, i2); m.Write<int>(2, i2);
this.Enqueue(m); this.ParamEnqueue(m);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(int i0, int i1, int i2, int i3) public void ParamEnqueue(int i0, int i1, int i2, int i3)
{ {
M128 m = default; M128 m = default;
m.Write<int>(0, i0); m.Write<int>(0, i0);
m.Write<int>(1, i1); m.Write<int>(1, i1);
m.Write<int>(2, i2); m.Write<int>(2, i2);
m.Write<int>(3, i3); m.Write<int>(3, i3);
this.Enqueue(m); this.ParamEnqueue(m);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(string str) public void ParamEnqueue(string str)
{ {
byte[] code = Encoding.UTF8.GetBytes(str); byte[] code = Encoding.UTF8.GetBytes(str);
streamQueue.Enqueue(glArrayHandle.Alloc<byte>(code)); streamQueue.Enqueue(glArrayHandle.Alloc<byte>(code));
@@ -186,7 +192,7 @@ namespace StgSharp.Graphics
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue<T>(T[] array) where T : struct public void ParamEnqueue<T>(T[] array) where T : struct
{ {
streamQueue.Enqueue(glArrayHandle.Alloc<T>(array)); streamQueue.Enqueue(glArrayHandle.Alloc<T>(array));
Console.WriteLine(paramQueue.Count + streamQueue.Count); Console.WriteLine(paramQueue.Count + streamQueue.Count);
@@ -452,18 +458,43 @@ namespace StgSharp.Graphics
private Thread _thread; private Thread _thread;
private FrameOperationBuffer renderBuffer; private FrameOperationBuffer renderBuffer;
private SemaphoreSlim renderCompleteSemaphore = new SemaphoreSlim(1, 1); private SemaphoreSlim renderCompleteSemaphore = new SemaphoreSlim(1, 1);
private int terminateSignal; private SemaphoreSlim renderStartSemaphore;
private bool shouldTerminate;
private FrameOperationBuffer updateBuffer; private FrameOperationBuffer updateBuffer;
public FrameThread(IglFunc gl) internal FrameThread(GLonUpdate gl)
{ {
updateBuffer = gl.ActivatedOperationBuffer;
_thread = new Thread(new ThreadStart(PrivateMain));
}
public bool IsRunning
{
get { return _thread.IsAlive; }
}
public void Start()
{
_thread.Start();
}
public void Terminate()
{
shouldTerminate = true;
} }
private void PrivateMain() private void PrivateMain()
{ {
while (renderBuffer.CallNext()) renderStartSemaphore.Wait();
{ while (shouldTerminate && renderBuffer.CallNext())
} { }
renderCompleteSemaphore.Release();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetNext(FrameThread thread)
{
renderStartSemaphore = thread.renderCompleteSemaphore;
} }
} }
} }
-88
View File
@@ -1,88 +0,0 @@
using StgSharp;
using StgSharp.Logic;
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public partial class Form
{
private bool isFullyRendered = false;
internal class FrameUpdateTimer
{
internal Bool2 alignSign;
private float frameLength;
private double frameBegin;
private bool refreshed;
private Counter<uint> tickCounter;
public double timeAfterFrame
{
get { return InternalIO.glfwGetTime() - frameBegin; }
}
public uint totalFrame
{
get { return tickCounter; }
}
internal void Refresh()
{
refreshed = false;
}
internal bool WaitNextFrame()
{
try
{
while (refreshed) { }
refreshed = true;
return true;
}
catch (Exception ex)
{
InternalIO.InternalWriteLog(ex.Message, LogType.Error);
return false;
}
}
}
}
/// <summary>
/// A timer counting frames after its construction.
/// </summary>
public class FrameTimer
{
internal readonly uint bornTick;
private Form timeProvider;
public FrameTimer(Form provaider)
{
timeProvider = provaider;
bornTick = timeProvider.timer.totalFrame;
}
/// <summary>
/// Frames after this timer created.
/// </summary>
public uint Time
{
get { return timeProvider.timer.totalFrame - bornTick; }
}
/// <summary>
/// Convert a <see cref="FrameTimer"/> into uint value.
/// this will get total frames since the timer was created.
/// </summary>
/// <param name="timer"><see cref="FrameTimer"/> to be converted</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator uint(FrameTimer timer)
{
return timer.Time;
}
}
}
@@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics
{
public unsafe partial class Form
{
}
}
+2 -10
View File
@@ -42,13 +42,7 @@ namespace StgSharp.Graphics
void IglFunc.AlignFrame(Form form) void IglFunc.AlignFrame(Form form)
{ {
if (form.timer.alignSign.byte0 > 0) throw new NotImplementedException();
{
throw new InvalidOperationException();
}
form.timer.alignSign.byte0++;
form.timer.WaitNextFrame();
throw refreshSIgnal;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -337,11 +331,9 @@ namespace StgSharp.Graphics
api->glViewport(x, y, width, height); api->glViewport(x, y, width, height);
} }
void IglFunc.frameworkHandleEnqueue(System.IntPtr handle, params StgSharp.Math.M128[] param) void IglFunc.frameworkHandleEnqueue(System.IntPtr handle, params M128[] param)
{ {
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
bool IglFunc.FrameCanUpdate => true;
} }
} }
+70 -90
View File
@@ -15,10 +15,10 @@ namespace StgSharp.Graphics
{ {
internal unsafe partial class GLonUpdate : IglFunc internal unsafe partial class GLonUpdate : IglFunc
{ {
private static FrameOperationBuffer frameOpBuffer;
private GLcontext* api; private GLcontext* api;
private IntPtr SwapBufferPtr = (IntPtr)(delegate*<IntPtr, void>)&InternalIO.glfwSwapBuffers; private IntPtr SwapBufferPtr = (IntPtr)(delegate*<IntPtr, void>)&InternalIO.glfwSwapBuffers;
private glSHandle unupdatedFrame = glSHandle.Alloc(0); private glSHandle unupdatedFrame = glSHandle.Alloc(0);
private FrameOperationBuffer frameOpBuffer;
internal GLonUpdate(GLcontext* context) internal GLonUpdate(GLcontext* context)
{ {
@@ -42,8 +42,8 @@ namespace StgSharp.Graphics
void IglFunc.ActiveTexture(uint type) void IglFunc.ActiveTexture(uint type)
{ {
frameOpBuffer.Enqueue(type); frameOpBuffer.ParamEnqueue(type);
frameOpBuffer.Enqueue(ActiveTexturePtr); frameOpBuffer.MethodEnqueue(ActiveTexturePtr);
} }
void IglFunc.AfterAlign(Form form, Action action) void IglFunc.AfterAlign(Form form, Action action)
@@ -59,8 +59,8 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.AttachShader(glHandle program, glHandle shader) unsafe void IglFunc.AttachShader(glHandle program, glHandle shader)
{ {
frameOpBuffer.Enqueue(program, shader); frameOpBuffer.ParamEnqueue(program, shader);
frameOpBuffer.Enqueue(AttachShaderPtr); frameOpBuffer.MethodEnqueue(AttachShaderPtr);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -69,8 +69,8 @@ namespace StgSharp.Graphics
M128 m = default; M128 m = default;
m.Write<uint>(0, (uint)bufferType); m.Write<uint>(0, (uint)bufferType);
m.Write<ulong>(1, (ulong)handle.valuePtr); m.Write<ulong>(1, (ulong)handle.valuePtr);
frameOpBuffer.Enqueue(m); frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.Enqueue(BindBufferPtr); frameOpBuffer.MethodEnqueue(BindBufferPtr);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -79,49 +79,49 @@ namespace StgSharp.Graphics
M128 m = default; M128 m = default;
m.Write<uint>(0, (uint)type); m.Write<uint>(0, (uint)type);
m.Write<ulong>(1, (ulong)texture.valuePtr); m.Write<ulong>(1, (ulong)texture.valuePtr);
frameOpBuffer.Enqueue(m); frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.Enqueue(BindTexturePtr); frameOpBuffer.MethodEnqueue(BindTexturePtr);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.BindVertexArray(glHandle index) void IglFunc.BindVertexArray(glHandle index)
{ {
frameOpBuffer.Enqueue(index); frameOpBuffer.ParamEnqueue(index);
frameOpBuffer.Enqueue(BindVertexArrayPtr); frameOpBuffer.MethodEnqueue(BindVertexArrayPtr);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.Clear(MaskBufferBit mask) void IglFunc.Clear(MaskBufferBit mask)
{ {
frameOpBuffer.Enqueue((int)mask); frameOpBuffer.ParamEnqueue((int)mask);
frameOpBuffer.Enqueue(ClearPtr); frameOpBuffer.MethodEnqueue(ClearPtr);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.ClearColor(float R, float G, float B, float A) void IglFunc.ClearColor(float R, float G, float B, float A)
{ {
frameOpBuffer.Enqueue(R, G, B, A); frameOpBuffer.ParamEnqueue(R, G, B, A);
frameOpBuffer.Enqueue(ClearColorPtr); frameOpBuffer.MethodEnqueue(ClearColorPtr);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.ClearGraphicError() void IglFunc.ClearGraphicError()
{ {
frameOpBuffer.Enqueue(ClearGraphicErrorPtr); frameOpBuffer.MethodEnqueue(ClearGraphicErrorPtr);
} }
unsafe void IglFunc.CompileShader(glHandle shaderhandle) unsafe void IglFunc.CompileShader(glHandle shaderhandle)
{ {
frameOpBuffer.Enqueue((IntPtr)shaderhandle.valuePtr); frameOpBuffer.ParamEnqueue((IntPtr)shaderhandle.valuePtr);
frameOpBuffer.Enqueue(CompileShaderPtr); frameOpBuffer.MethodEnqueue(CompileShaderPtr);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
glHandle IglFunc.CreateProgram() glHandle IglFunc.CreateProgram()
{ {
glHandle h = glHandle.Alloc(1); glHandle h = glHandle.Alloc(1);
frameOpBuffer.Enqueue(h); frameOpBuffer.ParamEnqueue(h);
frameOpBuffer.Enqueue(CreateProgramPtr); frameOpBuffer.MethodEnqueue(CreateProgramPtr);
return h; return h;
} }
@@ -132,8 +132,8 @@ namespace StgSharp.Graphics
glHandleSet h = new glHandleSet(count); glHandleSet h = new glHandleSet(count);
m.Write<ulong>(0, (ulong)h.handle); m.Write<ulong>(0, (ulong)h.handle);
m.Write<int>(2, count); m.Write<int>(2, count);
frameOpBuffer.Enqueue(m); frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.Enqueue(CreateProgramSetPtr); frameOpBuffer.MethodEnqueue(CreateProgramSetPtr);
return h; return h;
} }
@@ -144,8 +144,8 @@ namespace StgSharp.Graphics
m.Write<int>(0, count); m.Write<int>(0, count);
m.Write<uint>(1, (uint)type); m.Write<uint>(1, (uint)type);
m.Write<ulong>(1, (ulong)ret.handle); m.Write<ulong>(1, (ulong)ret.handle);
frameOpBuffer.Enqueue(m); frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.Enqueue(CreateShaderPtr); frameOpBuffer.MethodEnqueue(CreateShaderPtr);
return ret; return ret;
} }
@@ -178,8 +178,8 @@ namespace StgSharp.Graphics
glHandle IglFunc.CreatGraphicProgram() glHandle IglFunc.CreatGraphicProgram()
{ {
glHandle h = glHandle.Alloc(1); glHandle h = glHandle.Alloc(1);
frameOpBuffer.Enqueue(h); frameOpBuffer.ParamEnqueue(h);
frameOpBuffer.Enqueue(CreateProgramPtr); frameOpBuffer.MethodEnqueue(CreateProgramPtr);
return h; return h;
} }
@@ -189,8 +189,8 @@ namespace StgSharp.Graphics
M128 m = default; M128 m = default;
m.Write<ulong>(0, (ulong)handle.valuePtr); m.Write<ulong>(0, (ulong)handle.valuePtr);
m.Write(2, 1); m.Write(2, 1);
frameOpBuffer.Enqueue(m); frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.Enqueue(DeleBufferPtr); frameOpBuffer.MethodEnqueue(DeleBufferPtr);
} }
unsafe void IglFunc.DeleteBuffers(glHandleSet handle) unsafe void IglFunc.DeleteBuffers(glHandleSet handle)
@@ -198,16 +198,16 @@ namespace StgSharp.Graphics
M128 m = default; M128 m = default;
m.Write<ulong>(0, (ulong)handle.handle); m.Write<ulong>(0, (ulong)handle.handle);
m.Write<uint>(2, (uint)handle.length); m.Write<uint>(2, (uint)handle.length);
frameOpBuffer.Enqueue(m); frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.Enqueue(DeleBufferPtr); frameOpBuffer.MethodEnqueue(DeleBufferPtr);
} }
unsafe void IglFunc.DeleteVertexArrays(glHandleSet arrays) unsafe void IglFunc.DeleteVertexArrays(glHandleSet arrays)
{ {
M128 m = default; m.Write<ulong>(1, (ulong)arrays.handle); M128 m = default; m.Write<ulong>(1, (ulong)arrays.handle);
m.Write<int>(0, arrays.length); m.Write<int>(0, arrays.length);
frameOpBuffer.Enqueue(m); frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.Enqueue(DeleteVertexArrayPtr); frameOpBuffer.MethodEnqueue(DeleteVertexArrayPtr);
} }
void IglFunc.DrawElements(GepmetryType mode, uint count, TypeCode type, IntPtr ptr) void IglFunc.DrawElements(GepmetryType mode, uint count, TypeCode type, IntPtr ptr)
@@ -234,17 +234,17 @@ namespace StgSharp.Graphics
LogType.Error); LogType.Error);
return; return;
} }
frameOpBuffer.Enqueue((uint)mode, count, a); frameOpBuffer.ParamEnqueue((uint)mode, count, a);
frameOpBuffer.Enqueue(ptr); frameOpBuffer.ParamEnqueue(ptr);
frameOpBuffer.Enqueue(DrawElementsPtr); frameOpBuffer.MethodEnqueue(DrawElementsPtr);
} }
unsafe glHandleSet IglFunc.GenBuffers(int count) unsafe glHandleSet IglFunc.GenBuffers(int count)
{ {
glHandleSet h = new glHandleSet(count); glHandleSet h = new glHandleSet(count);
M128 m = default; m.Write<uint>(2, (uint)count); m.Write<ulong>(0, (ulong)h.handle); M128 m = default; m.Write<uint>(2, (uint)count); m.Write<ulong>(0, (ulong)h.handle);
frameOpBuffer.Enqueue(m); frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.Enqueue(GenBufferPtr); frameOpBuffer.MethodEnqueue(GenBufferPtr);
return h; return h;
} }
@@ -252,8 +252,8 @@ namespace StgSharp.Graphics
{ {
glHandleSet h = new glHandleSet(count); glHandleSet h = new glHandleSet(count);
M128 m = default; m.Write<uint>(2, (uint)count); m.Write<ulong>(0, (ulong)h.handle); M128 m = default; m.Write<uint>(2, (uint)count); m.Write<ulong>(0, (ulong)h.handle);
frameOpBuffer.Enqueue(m); frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.Enqueue(GenTexturesPtr); frameOpBuffer.MethodEnqueue(GenTexturesPtr);
return h; return h;
} }
@@ -261,8 +261,8 @@ namespace StgSharp.Graphics
{ {
glHandleSet h = new glHandleSet(count); glHandleSet h = new glHandleSet(count);
M128 m = default; m.Write<uint>(2, (uint)count); m.Write<ulong>(0, (ulong)h.handle); M128 m = default; m.Write<uint>(2, (uint)count); m.Write<ulong>(0, (ulong)h.handle);
frameOpBuffer.Enqueue(m); frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.Enqueue(GenTexturesPtr); frameOpBuffer.MethodEnqueue(GenTexturesPtr);
return h; return h;
} }
@@ -273,9 +273,9 @@ namespace StgSharp.Graphics
M128 m = default; M128 m = default;
m.Write<ulong>(0, (ulong)program.Handle); m.Write<ulong>(0, (ulong)program.Handle);
m.Write<ulong>(1, (ulong)GCHandle.Alloc(Encoding.UTF8.GetBytes(ptr), GCHandleType.Pinned).AddrOfPinnedObject()); m.Write<ulong>(1, (ulong)GCHandle.Alloc(Encoding.UTF8.GetBytes(ptr), GCHandleType.Pinned).AddrOfPinnedObject());
frameOpBuffer.Enqueue(m); frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.Enqueue((IntPtr)h.valuePtr); frameOpBuffer.ParamEnqueue((IntPtr)h.valuePtr);
frameOpBuffer.Enqueue(GetUniformLocationPtr); frameOpBuffer.MethodEnqueue(GetUniformLocationPtr);
return h; return h;
} }
@@ -296,9 +296,9 @@ namespace StgSharp.Graphics
void IglFunc.LoadShaderSource(glHandle shaderHandle, string codeStream) void IglFunc.LoadShaderSource(glHandle shaderHandle, string codeStream)
{ {
frameOpBuffer.Enqueue(shaderHandle); frameOpBuffer.ParamEnqueue(shaderHandle);
frameOpBuffer.Enqueue(codeStream); frameOpBuffer.ParamEnqueue(codeStream);
frameOpBuffer.Enqueue(ShaderSourcePtr); frameOpBuffer.MethodEnqueue(ShaderSourcePtr);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -313,40 +313,38 @@ namespace StgSharp.Graphics
void IglFunc.SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage) void IglFunc.SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
{ {
frameOpBuffer.Enqueue((uint)bufferType, (uint)usage); frameOpBuffer.ParamEnqueue((uint)bufferType, (uint)usage);
frameOpBuffer.Enqueue((IntPtr)sizeof(T)); frameOpBuffer.ParamEnqueue((IntPtr)sizeof(T));
frameOpBuffer.Enqueue<T>(new T[] { bufferData }); frameOpBuffer.ParamEnqueue<T>(new T[] { bufferData });
frameOpBuffer.Enqueue(BufferDataPtr); frameOpBuffer.MethodEnqueue(BufferDataPtr);
} }
void IglFunc.SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage) void IglFunc.SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
{ {
frameOpBuffer.Enqueue((uint)bufferType, (uint)usage); frameOpBuffer.ParamEnqueue((uint)bufferType, (uint)usage);
frameOpBuffer.Enqueue((IntPtr)(Marshal.SizeOf<T>() * bufferArray.Length)); frameOpBuffer.ParamEnqueue((IntPtr)(Marshal.SizeOf<T>() * bufferArray.Length));
frameOpBuffer.Enqueue<T>(bufferArray); frameOpBuffer.ParamEnqueue<T>(bufferArray);
frameOpBuffer.Enqueue(BufferDataPtr); frameOpBuffer.MethodEnqueue(BufferDataPtr);
} }
void IglFunc.SetVertexAttribute(uint index, int size, TypeCode t, bool normalized, uint stride, int pointer) void IglFunc.SetVertexAttribute(uint index, int size, TypeCode t, bool normalized, uint stride, int pointer)
{ {
uint type = InternalIO.GLtype[t]; uint type = InternalIO.GLtype[t];
frameOpBuffer.Enqueue(index, type, stride); frameOpBuffer.ParamEnqueue(index, type, stride);
frameOpBuffer.Enqueue(size, normalized ? 1 : 0, pointer); frameOpBuffer.ParamEnqueue(size, normalized ? 1 : 0, pointer);
frameOpBuffer.Enqueue(SetVertexArrayPtr); frameOpBuffer.MethodEnqueue(SetVertexArrayPtr);
} }
//TODO:双线程,换运行环境
void IglFunc.SwitchContext() void IglFunc.SwitchContext()
{ {
frameOpBuffer.context = api;
} }
unsafe void IglFunc.TextureImage2d<T>(int target, int level, uint internalformat, uint width, uint height, uint format, uint type, glHandle pixels) unsafe void IglFunc.TextureImage2d<T>(int target, int level, uint internalformat, uint width, uint height, uint format, uint type, glHandle pixels)
{ {
frameOpBuffer.Enqueue(pixels); frameOpBuffer.ParamEnqueue(pixels);
frameOpBuffer.Enqueue((uint)level, internalformat, width, height); frameOpBuffer.ParamEnqueue((uint)level, internalformat, width, height);
frameOpBuffer.Enqueue((uint)target, format, type); frameOpBuffer.ParamEnqueue((uint)target, format, type);
frameOpBuffer.Enqueue(textureImage2dPtr); frameOpBuffer.MethodEnqueue(textureImage2dPtr);
} }
void IglFunc.TextureParameter(int target, uint pname, int param) void IglFunc.TextureParameter(int target, uint pname, int param)
@@ -355,21 +353,21 @@ namespace StgSharp.Graphics
m.Write<int>(0, target); m.Write<int>(0, target);
m.Write<uint>(2, pname); m.Write<uint>(2, pname);
m.Write<int>(3, param); m.Write<int>(3, param);
frameOpBuffer.Enqueue(m); frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.Enqueue(TextureParameterPtr); frameOpBuffer.MethodEnqueue(TextureParameterPtr);
} }
void IglFunc.UseProgram(glHandle program) void IglFunc.UseProgram(glHandle program)
{ {
frameOpBuffer.Enqueue((IntPtr)program.valuePtr); frameOpBuffer.ParamEnqueue((IntPtr)program.valuePtr);
frameOpBuffer.Enqueue(UseProgramPtr); frameOpBuffer.MethodEnqueue(UseProgramPtr);
} }
void IglFunc.Viewport(int x, int y, uint width, uint height) void IglFunc.Viewport(int x, int y, uint width, uint height)
{ {
Vec4d v = new Vec4d(x, y, (int)width, (int)height); Vec4d v = new Vec4d(x, y, (int)width, (int)height);
frameOpBuffer.Enqueue(v); frameOpBuffer.ParamEnqueue(v);
frameOpBuffer.Enqueue(ViewPortPtr); frameOpBuffer.MethodEnqueue(ViewPortPtr);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -377,27 +375,9 @@ namespace StgSharp.Graphics
{ {
foreach (M128 item in param) foreach (M128 item in param)
{ {
frameOpBuffer.Enqueue(item); frameOpBuffer.ParamEnqueue(item);
}
frameOpBuffer.Enqueue(methodHandle);
}
bool IglFunc.FrameCanUpdate
{
get
{
if (unupdatedFrame.DirectValue > 5)
{
return false;
}
else
{
*unupdatedFrame.valuePtr += 1;
frameOpBuffer.Enqueue((IntPtr)unupdatedFrame.valuePtr);
frameOpBuffer.Enqueue(CanUpdatePtr);
return true;
}
} }
frameOpBuffer.ParamEnqueue(methodHandle);
} }
} }
} }
@@ -16,253 +16,253 @@ namespace StgSharp.Graphics
{ {
internal unsafe partial class GLonUpdate : IglFunc internal unsafe partial class GLonUpdate : IglFunc
{ {
private IntPtr ActiveTexturePtr = (IntPtr)(delegate*<void>)&InternalActiveTexture; private IntPtr ActiveTexturePtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalActiveTexture;
private IntPtr AttachShaderPtr = (IntPtr)(delegate*<void>)&InternalAttachShader; private IntPtr AttachShaderPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalAttachShader;
private IntPtr BindBufferPtr = (IntPtr)(delegate*<void>)&InternalBindBuffer; private IntPtr BindBufferPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalBindBuffer;
private IntPtr BindTexturePtr = (IntPtr)(delegate*<void>)&InternalBindTexture; private IntPtr BindTexturePtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalBindTexture;
private IntPtr BindVertexArrayPtr = (IntPtr)(delegate*<void>)&InternalBindVertexArray; private IntPtr BindVertexArrayPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalBindVertexArray;
private IntPtr BufferDataPtr = (IntPtr)(delegate*<void>)&InternalSetBufferData; private IntPtr BufferDataPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalSetBufferData;
private IntPtr CanUpdatePtr = (IntPtr)(delegate*<void>)&InternalFrameCanUpdate; private IntPtr CanUpdatePtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalFrameCanUpdate;
private IntPtr ClearColorPtr = (IntPtr)(delegate*<void>)&InternalClearColor; private IntPtr ClearColorPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalClearColor;
private IntPtr ClearGraphicErrorPtr = (IntPtr)(delegate*<void>)&InternalClearGraphicError; private IntPtr ClearGraphicErrorPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalClearGraphicError;
private IntPtr ClearPtr = (IntPtr)(delegate*<void>)&InternalClear; private IntPtr ClearPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalClear;
private IntPtr CompileShaderPtr = (IntPtr)(delegate*<void>)&InternalCompileShader; private IntPtr CompileShaderPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalCompileShader;
private IntPtr CreateProgramPtr = (IntPtr)(delegate*<void>)&InternalCreateProgram; private IntPtr CreateProgramPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalCreateProgram;
private IntPtr CreateProgramSetPtr = (IntPtr)(delegate*<void>)&InternalCreateProgramSet; private IntPtr CreateProgramSetPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalCreateProgramSet;
private IntPtr CreateShaderPtr = (IntPtr)(delegate*<void>)&InternalCreateShader; private IntPtr CreateShaderPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalCreateShader;
private IntPtr DeleBufferPtr = (IntPtr)(delegate*<void>)&InternalDeleteBuffer; private IntPtr DeleBufferPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalDeleteBuffer;
private IntPtr DeleteVertexArrayPtr = (IntPtr)(delegate*<void>)&InternalDeleteVertexArrays; private IntPtr DeleteVertexArrayPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalDeleteVertexArrays;
private IntPtr DrawElementsPtr = (IntPtr)(delegate*<void>)&InternalDrawElements; private IntPtr DrawElementsPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalDrawElements;
private IntPtr GenBufferPtr = (IntPtr)(delegate*<void>)&InternalGenBuffers; private IntPtr GenBufferPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalGenBuffers;
private IntPtr GenTexturesPtr = (IntPtr)(delegate*<void>)&InternalGenTextures; private IntPtr GenTexturesPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalGenTextures;
private IntPtr GenVertexArraysPtr = (IntPtr)(delegate*<void>)&InternalGenVertexArrays; private IntPtr GenVertexArraysPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalGenVertexArrays;
private IntPtr GetUniformLocationPtr = (IntPtr)(delegate*<void>)&InternalGetUniformLocation; private IntPtr GetUniformLocationPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalGetUniformLocation;
private IntPtr SetVertexArrayPtr = (IntPtr)(delegate*<void>)&InternalSetVertexAttribute; private IntPtr SetVertexArrayPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalSetVertexAttribute;
private IntPtr ShaderSourcePtr = (IntPtr)(delegate*<void>)&InternalShaderSource; private IntPtr ShaderSourcePtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalShaderSource;
private IntPtr textureImage2dPtr = (IntPtr)(delegate*<void>)&InternalTextureImage2d; private IntPtr textureImage2dPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalTextureImage2d;
private IntPtr TextureParameterPtr = (IntPtr)(delegate*<void>)&InternalTextureParameter; private IntPtr TextureParameterPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalTextureParameter;
private IntPtr UseProgramPtr = (IntPtr)(delegate*<void>)&InternalUseProgram; private IntPtr UseProgramPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalUseProgram;
private IntPtr ViewPortPtr = (IntPtr)(delegate*<void>)&InternalViewport; private IntPtr ViewPortPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalViewport;
private static void InternalActiveTexture() private static void InternalActiveTexture(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
uint t; uint t;
paramQueue.TryDequeue(out t); frameBuffer.TryDequeue(out t);
paramQueue.context->glActiveTexture(t); activatedContext->glActiveTexture(t);
} }
private static void InternalAttachShader() private static void InternalAttachShader(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
uint p, s; uint p, s;
paramQueue.TryDequeue(out p, out s); frameBuffer.TryDequeue(out p, out s);
paramQueue.context->glAttachShader(p, s); activatedContext->glAttachShader(p, s);
} }
private static void InternalBindBuffer() private static void InternalBindBuffer(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
M128 m = new M128(); M128 m = new M128();
paramQueue.TryDequeue(out m); frameBuffer.TryDequeue(out m);
uint usage = m.Read<uint>(0); uint usage = m.Read<uint>(0);
uint handle = *(uint*)m.Read<ulong>(1); uint handle = *(uint*)m.Read<ulong>(1);
paramQueue.context->glBindBuffer(usage, handle); activatedContext->glBindBuffer(usage, handle);
} }
private static void InternalBindTexture() private static void InternalBindTexture(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
M128 m = default; M128 m = default;
paramQueue.TryDequeue(out m); frameBuffer.TryDequeue(out m);
paramQueue.context->glBindTexture( activatedContext->glBindTexture(
m.Read<uint>(0), m.Read<uint>(0),
*(uint*)m.Read<ulong>(1) *(uint*)m.Read<ulong>(1)
); );
} }
private static void InternalBindVertexArray() private static void InternalBindVertexArray(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
IntPtr i; IntPtr i;
paramQueue.TryDequeue(out i); frameBuffer.TryDequeue(out i);
paramQueue.context->glBindVertexArray(*(uint*)i); activatedContext->glBindVertexArray(*(uint*)i);
} }
private static void InternalClear() private static void InternalClear(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
uint mt; uint mt;
paramQueue.TryDequeue(out mt); frameBuffer.TryDequeue(out mt);
paramQueue.context->glClear(mt); activatedContext->glClear(mt);
} }
private static void InternalClearColor() private static void InternalClearColor(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
float r, g, b, a; float r, g, b, a;
paramQueue.TryDequeue(out r, out g, out b, out a); frameBuffer.TryDequeue(out r, out g, out b, out a);
paramQueue.context->glClearColor(r, g, b, a); activatedContext->glClearColor(r, g, b, a);
} }
private static void InternalClearGraphicError() private static void InternalClearGraphicError(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
while (paramQueue.context->glGetError() != 0) { } while (activatedContext->glGetError() != 0) { }
} }
private static unsafe void InternalCompileShader() private static unsafe void InternalCompileShader(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
IntPtr handle = default; IntPtr handle = default;
paramQueue.TryDequeue(out handle); frameBuffer.TryDequeue(out handle);
paramQueue.context->glCompileShader(*(uint*)handle); activatedContext->glCompileShader(*(uint*)handle);
} }
private static void InternalCreateProgram() private static void InternalCreateProgram(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
IntPtr programHandle = default; IntPtr programHandle = default;
paramQueue.TryDequeue(out programHandle); frameBuffer.TryDequeue(out programHandle);
*(uint*)programHandle = paramQueue.context->glCreateProgram(); *(uint*)programHandle = activatedContext->glCreateProgram();
} }
private static void InternalCreateProgramSet() private static void InternalCreateProgramSet(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
uint* programHandle; uint* programHandle;
M128 m = default; M128 m = default;
paramQueue.TryDequeue(out m); frameBuffer.TryDequeue(out m);
programHandle = (uint*)m.Read<ulong>(0); programHandle = (uint*)m.Read<ulong>(0);
for (int i = 0; i < m.Read<int>(2); i++) for (int i = 0; i < m.Read<int>(2); i++)
{ {
*(programHandle + i) = paramQueue.context->glCreateProgram(); *(programHandle + i) = activatedContext->glCreateProgram();
} }
} }
private static unsafe void InternalCreateShader() private static unsafe void InternalCreateShader(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
M128 m = default; M128 m = default;
paramQueue.TryDequeue(out m); frameBuffer.TryDequeue(out m);
int count = m.Read<int>(0); uint type = m.Read<uint>(1); uint* handle = (uint*)m.Read<ulong>(1); int count = m.Read<int>(0); uint type = m.Read<uint>(1); uint* handle = (uint*)m.Read<ulong>(1);
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
*(handle + i) = paramQueue.context->glCreateShader(type); *(handle + i) = activatedContext->glCreateShader(type);
} }
} }
private static void InternalDeleteBuffer() private static void InternalDeleteBuffer(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
M128 m = default; M128 m = default;
paramQueue.TryDequeue(out m); frameBuffer.TryDequeue(out m);
paramQueue.context->glDeleteBuffers(m.Read<uint>(2), (uint*)m.Read<ulong>(0)); activatedContext->glDeleteBuffers(m.Read<uint>(2), (uint*)m.Read<ulong>(0));
for (int i = 0; i < m.Read<uint>(2); i++) for (int i = 0; i < m.Read<uint>(2); i++)
{ {
*((uint*)m.Read<ulong>(0) + i) = 0; *((uint*)m.Read<ulong>(0) + i) = 0;
} }
} }
private static void InternalDeleteVertexArrays() private static void InternalDeleteVertexArrays(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
M128 m = default; M128 m = default;
paramQueue.TryDequeue(out m); frameBuffer.TryDequeue(out m);
paramQueue.context->glDeleteVertexArrays((uint)m.Read<int>(0), (uint*)m.Read<ulong>(0)); activatedContext->glDeleteVertexArrays((uint)m.Read<int>(0), (uint*)m.Read<ulong>(0));
} }
private static void InternalDrawElements() private static void InternalDrawElements(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
uint mode, count, type; uint mode, count, type;
IntPtr ptr; IntPtr ptr;
paramQueue.TryDequeue(out mode, out count, out type); frameBuffer.TryDequeue(out mode, out count, out type);
paramQueue.TryDequeue(out ptr); frameBuffer.TryDequeue(out ptr);
paramQueue.context->glDrawElements(mode, count, type, (void*)ptr); activatedContext->glDrawElements(mode, count, type, (void*)ptr);
} }
private static void InternalFrameCanUpdate() private static void InternalFrameCanUpdate(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
IntPtr ptr; IntPtr ptr;
paramQueue.TryDequeue(out ptr); frameBuffer.TryDequeue(out ptr);
Interlocked.Add(ref *(int*)ptr, -1); Interlocked.Add(ref *(int*)ptr, -1);
} }
private static void InternalGenBuffers() private static void InternalGenBuffers(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
M128 m = default; M128 m = default;
paramQueue.TryDequeue(out m); frameBuffer.TryDequeue(out m);
paramQueue.context->glGenBuffers(m.Read<uint>(2), (uint*)m.Read<ulong>(0)); activatedContext->glGenBuffers(m.Read<uint>(2), (uint*)m.Read<ulong>(0));
} }
private static void InternalGenTextures() private static void InternalGenTextures(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
M128 m = default; M128 m = default;
paramQueue.TryDequeue(out m); frameBuffer.TryDequeue(out m);
paramQueue.context->glGenTextures(m.Read<uint>(2), (uint*)m.Read<ulong>(0)); activatedContext->glGenTextures(m.Read<uint>(2), (uint*)m.Read<ulong>(0));
} }
private static void InternalGenVertexArrays() private static void InternalGenVertexArrays(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
M128 m = default; M128 m = default;
paramQueue.TryDequeue(out m); frameBuffer.TryDequeue(out m);
paramQueue.context->glGenVertexArrays(m.Read<uint>(2), (uint*)m.Read<ulong>(0)); activatedContext->glGenVertexArrays(m.Read<uint>(2), (uint*)m.Read<ulong>(0));
} }
private static void InternalGetUniformLocation() private static void InternalGetUniformLocation(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
IntPtr programHandle = default, nameHandle = default, targetHandle = default; IntPtr programHandle = default, nameHandle = default, targetHandle = default;
paramQueue.TryDequeue(out programHandle, out nameHandle); frameBuffer.TryDequeue(out programHandle, out nameHandle);
paramQueue.TryDequeue(out targetHandle); frameBuffer.TryDequeue(out targetHandle);
*(int*)targetHandle = paramQueue.context->glGetUniformLocation(*(uint*)programHandle, (byte*)nameHandle); *(int*)targetHandle = activatedContext->glGetUniformLocation(*(uint*)programHandle, (byte*)nameHandle);
} }
private static void InternalSetBufferData() private static void InternalSetBufferData(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
uint type = 0, use = 0; uint type = 0, use = 0;
IntPtr size = default; IntPtr size = default;
glArrayHandle array = default; glArrayHandle array = default;
paramQueue.TryDequeue(out type, out use); frameBuffer.TryDequeue(out type, out use);
paramQueue.TryDequeue(out size); frameBuffer.TryDequeue(out size);
paramQueue.TryDequeue(out array); frameBuffer.TryDequeue(out array);
paramQueue.context->glBufferData(type, size, array.AddressOfArray(), use); activatedContext->glBufferData(type, size, array.AddressOfArray(), use);
} }
private static void InternalSetVertexAttribute() private static void InternalSetVertexAttribute(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
uint index, type, stride; uint index, type, stride;
int size, normalized, pointer; int size, normalized, pointer;
paramQueue.TryDequeue(out index, out type, out stride); frameBuffer.TryDequeue(out index, out type, out stride);
paramQueue.TryDequeue(out size, out normalized, out pointer); frameBuffer.TryDequeue(out size, out normalized, out pointer);
paramQueue.context->glVertexAttribPointer(index, size, type, normalized, stride, (void*)pointer); activatedContext->glVertexAttribPointer(index, size, type, normalized, stride, (void*)pointer);
paramQueue.context->glEnableVertexAttribArray(index); activatedContext->glEnableVertexAttribArray(index);
} }
private static unsafe void InternalShaderSource() private static unsafe void InternalShaderSource(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
IntPtr handle = default; IntPtr handle = default;
glArrayHandle stream = default; glArrayHandle stream = default;
paramQueue.TryDequeue(out handle); frameBuffer.TryDequeue(out handle);
paramQueue.TryDequeue(out stream); frameBuffer.TryDequeue(out stream);
IntPtr buffer = stream.AddressOfArray(); IntPtr buffer = stream.AddressOfArray();
paramQueue.context->glShaderSource(*(uint*)handle, 1, (byte**)&buffer, (void*)0); activatedContext->glShaderSource(*(uint*)handle, 1, (byte**)&buffer, (void*)0);
} }
private static void InternalTextureImage2d() private static void InternalTextureImage2d(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
IntPtr pix = IntPtr.Zero; IntPtr pix = IntPtr.Zero;
uint target, level, internalFormat, width, height, format, type; uint target, level, internalFormat, width, height, format, type;
paramQueue.TryDequeue(out pix); frameBuffer.TryDequeue(out pix);
paramQueue.TryDequeue(out level, out internalFormat, out width, out height); frameBuffer.TryDequeue(out level, out internalFormat, out width, out height);
paramQueue.TryDequeue(out target, out format, out type); frameBuffer.TryDequeue(out target, out format, out type);
paramQueue.context->glTexImage2D(target, (int)level, internalFormat, width, height, 0, format, type, (void*)pix); activatedContext->glTexImage2D(target, (int)level, internalFormat, width, height, 0, format, type, (void*)pix);
} }
private static void InternalTextureParameter() private static void InternalTextureParameter(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
M128 m = default; M128 m = default;
paramQueue.TryDequeue(out m); frameBuffer.TryDequeue(out m);
paramQueue.context->glTextureParameteri(m.Read<uint>(0), m.Read<uint>(2), m.Read<int>(3)); activatedContext->glTextureParameteri(m.Read<uint>(0), m.Read<uint>(2), m.Read<int>(3));
} }
private static void InternalUseProgram() private static void InternalUseProgram(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
IntPtr handle = IntPtr.Zero; IntPtr handle = IntPtr.Zero;
paramQueue.TryDequeue(out handle); frameBuffer.TryDequeue(out handle);
paramQueue.context->glUseProgram(*(uint*)handle); activatedContext->glUseProgram(*(uint*)handle);
} }
private static void InternalViewport() private static void InternalViewport(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{ {
M128 m = default; M128 m = default;
paramQueue.TryDequeue(out m); frameBuffer.TryDequeue(out m);
paramQueue.context->glViewport(m.Read<int>(0), m.Read<int>(1), m.Read<uint>(2), m.Read<uint>(3)); activatedContext->glViewport(m.Read<int>(0), m.Read<int>(1), m.Read<uint>(2), m.Read<uint>(3));
} }
private void InternalMakeContexCurrent(Form form) private void InternalMakeContexCurrent(Form form)
@@ -20,7 +20,6 @@ namespace StgSharp.Graphics
return new ElementBuffer(count, this.gl); return new ElementBuffer(count, this.gl);
} }
/// <summary> /// <summary>
/// Create a set of <see cref="VertexArray"/>. /// Create a set of <see cref="VertexArray"/>.
/// </summary> /// </summary>
@@ -53,6 +52,5 @@ namespace StgSharp.Graphics
{ {
return new VertexBuffer(count, gl); return new VertexBuffer(count, gl);
} }
} }
} }
@@ -36,20 +36,23 @@ namespace StgSharp.Graphics.GL.ShaderEdit
{ {
if (inputParams.Length != function.ParameterCount) if (inputParams.Length != function.ParameterCount)
{ {
// Param list length not equal
throw new ArgumentException("Provided parameters does not match function's parameter list."); throw new ArgumentException("Provided parameters does not match function's parameter list.");
} }
if (!ShaderParameter.IsSameType(outPut, function.outPut)) if (!ShaderParameter.IsSameType(outPut, function.outPut))
{ {
// Type of returning value not qual
throw new Exception("Provided parameters does not match function's parameter list."); throw new Exception("Provided parameters does not match function's parameter list.");
} }
for (int i = 0; i < inputParams.Length; i++) for (int i = 0; i < inputParams.Length; i++)
{ {
if (!ShaderParameter.IsSameType(function.inputList[i], inputParams[i])) if (!ShaderParameter.IsSameType(function.inputList[i], inputParams[i]))
{ {
// Input type not match
throw new Exception("Provided parameters does not match function's parameter list."); throw new Exception("Provided parameters does not match function's parameter list.");
} }
} }
string codeLine = ""; string codeLine = ""; // adding a line like " outvalue = Func(input1, input2,...); "
if (outPut != ShaderParameter.Void) if (outPut != ShaderParameter.Void)
{ {
codeLine += $"{outPut.name} = "; codeLine += $"{outPut.name} = ";
@@ -135,18 +135,18 @@ namespace StgSharp.Graphics
internal unsafe partial class GLonUpdate internal unsafe partial class GLonUpdate
{ {
private IntPtr UniformVal1fPtr = (IntPtr)(delegate*<void>)&UniformVal1f; private IntPtr UniformVal1fPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal1f;
private IntPtr UniformVal1fvPtr = (IntPtr)(delegate*<void>)&UniformVal1fv; private IntPtr UniformVal1fvPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal1fv;
private IntPtr UniformVal1iPtr = (IntPtr)(delegate*<void>)&UniformVal1i; private IntPtr UniformVal1iPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal1i;
private IntPtr UniformVal2fPtr = (IntPtr)(delegate*<void>)&UniformVal2f; private IntPtr UniformVal2fPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal2f;
private IntPtr UniformVal3fPtr = (IntPtr)(delegate*<void>)&UniformVal3f; private IntPtr UniformVal3fPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal3f;
private IntPtr UniformVal4fPtr = (IntPtr)(delegate*<void>)&UniformVal4f; private IntPtr UniformVal4fPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal4f;
unsafe void IglFunc.SetValue(Uniform<float, float, float> uniform, float f0, float f1, float f2) unsafe void IglFunc.SetValue(Uniform<float, float, float> uniform, float f0, float f1, float f2)
{ {
paramQueue.Enqueue((IntPtr)uniform.id.valuePtr); frameOpBuffer.ParamEnqueue((IntPtr)uniform.id.valuePtr);
paramQueue.Enqueue(f0, f1, f2); frameOpBuffer.ParamEnqueue(f0, f1, f2);
glActionQueue.Enqueue(UniformVal3fPtr); frameOpBuffer.MethodEnqueue(UniformVal3fPtr);
} }
unsafe void IglFunc.SetValue(Uniform<float, float> uniform, float f0, float f1) unsafe void IglFunc.SetValue(Uniform<float, float> uniform, float f0, float f1)
@@ -155,22 +155,22 @@ namespace StgSharp.Graphics
m.Write<ulong>(0, (ulong)uniform.id.valuePtr); m.Write<ulong>(0, (ulong)uniform.id.valuePtr);
m.Write<float>(2, f0); m.Write<float>(2, f0);
m.Write<float>(3, f1); m.Write<float>(3, f1);
paramQueue.Enqueue(m); frameOpBuffer.ParamEnqueue(m);
glActionQueue.Enqueue(UniformVal2fPtr); frameOpBuffer.MethodEnqueue(UniformVal2fPtr);
} }
unsafe void IglFunc.SetValue(Uniform<float, float, float, float> uniform, float f0, float f1, float f2, float f3) unsafe void IglFunc.SetValue(Uniform<float, float, float, float> uniform, float f0, float f1, float f2, float f3)
{ {
paramQueue.Enqueue((IntPtr)uniform.id.valuePtr); frameOpBuffer.ParamEnqueue((IntPtr)uniform.id.valuePtr);
paramQueue.Enqueue(f0, f1, f2, f3); frameOpBuffer.ParamEnqueue(f0, f1, f2, f3);
glActionQueue.Enqueue(UniformVal4fPtr); frameOpBuffer.MethodEnqueue(UniformVal4fPtr);
} }
unsafe void IglFunc.SetValue(Uniform<float, float, float, float> uniform, Vec4d vec) unsafe void IglFunc.SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
{ {
Vec4d m = vec; frameOpBuffer.ParamEnqueue((IntPtr)uniform.id.valuePtr);
paramQueue.Enqueue((IntPtr)uniform.id.valuePtr, (IntPtr)(Vec4d*)&m); frameOpBuffer.ParamEnqueue(vec);
glActionQueue.Enqueue(UniformVal1fvPtr); frameOpBuffer.MethodEnqueue(UniformVal1fvPtr);
} }
unsafe void IglFunc.SetValue(Uniform<float> uniform, float f0) unsafe void IglFunc.SetValue(Uniform<float> uniform, float f0)
@@ -178,8 +178,8 @@ namespace StgSharp.Graphics
M128 m = default; M128 m = default;
m.Write<ulong>(0, (ulong)uniform.id.valuePtr); m.Write<ulong>(0, (ulong)uniform.id.valuePtr);
m.Write<float>(2, f0); m.Write<float>(2, f0);
paramQueue.Enqueue(m); frameOpBuffer.ParamEnqueue(m);
glActionQueue.Enqueue(UniformVal1fPtr); frameOpBuffer.MethodEnqueue(UniformVal1fPtr);
} }
unsafe void IglFunc.SetValue(Uniform<int> uniform, int i0) unsafe void IglFunc.SetValue(Uniform<int> uniform, int i0)
@@ -187,61 +187,62 @@ namespace StgSharp.Graphics
M128 m = default; M128 m = default;
m.Write<ulong>(0, (ulong)uniform.id.valuePtr); m.Write<ulong>(0, (ulong)uniform.id.valuePtr);
m.Write<int>(2, i0); m.Write<int>(2, i0);
paramQueue.Enqueue(m); frameOpBuffer.ParamEnqueue(m);
glActionQueue.Enqueue(UniformVal1fPtr); frameOpBuffer.MethodEnqueue(UniformVal1fPtr);
} }
unsafe void IglFunc.SetValue(Uniform<Vec4d> uniform, Vec4d vec) unsafe void IglFunc.SetValue(Uniform<Vec4d> uniform, Vec4d vec)
{ {
Vec4d m = vec; Vec4d m = vec;
paramQueue.Enqueue((IntPtr)uniform.id.valuePtr, (IntPtr)(Vec4d*)&m); frameOpBuffer.ParamEnqueue((IntPtr)uniform.id.valuePtr, (IntPtr)(Vec4d*)&m);
glActionQueue.Enqueue(UniformVal1fvPtr); frameOpBuffer.MethodEnqueue(UniformVal1fvPtr);
} }
private static void UniformVal1f() private static void UniformVal1f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{ {
M128 m = default; M128 m = default;
paramQueue.TryDequeue(out m); frameOpBuffer.TryDequeue(out m);
paramQueue.context->glUniform1f(*(int*)m.Read<ulong>(0), m.Read<uint>(2)); activatedContext->glUniform1f(*(int*)m.Read<ulong>(0), m.Read<uint>(2));
} }
private static unsafe void UniformVal1fv() private static unsafe void UniformVal1fv(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default, v = default;
frameOpBuffer.TryDequeue(out m);
frameOpBuffer.TryDequeue(out v);
activatedContext->glUniform1fv(*(int*)m.Read<ulong>(0), 4, (Vec4d*)&v);
}
private static void UniformVal1i(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{ {
M128 m = default; M128 m = default;
paramQueue.TryDequeue(out m); frameOpBuffer.TryDequeue(out m);
paramQueue.context->glUniform1fv(*(int*)m.Read<ulong>(0), 4, (Vec4d*)&m.vec); activatedContext->glUniform1i(*(int*)m.Read<ulong>(0), m.Read<int>(2));
} }
private static void UniformVal1i() private static void UniformVal2f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{ {
M128 m = default; M128 m = default;
paramQueue.TryDequeue(out m); frameOpBuffer.TryDequeue(out m);
paramQueue.context->glUniform1i(*(int*)m.Read<ulong>(0), m.Read<int>(2)); activatedContext->glUniform2f(*(int*)m.Read<ulong>(0), m.Read<float>(2), m.Read<float>(3));
} }
private static void UniformVal2f() private static void UniformVal3f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default;
paramQueue.TryDequeue(out m);
paramQueue.context->glUniform2f(*(int*)m.Read<ulong>(0), m.Read<float>(2), m.Read<float>(3));
}
private static void UniformVal3f()
{ {
IntPtr handle = IntPtr.Zero; IntPtr handle = IntPtr.Zero;
M128 m = default; M128 m = default;
paramQueue.TryDequeue(out handle); frameOpBuffer.TryDequeue(out handle);
paramQueue.TryDequeue(out m); frameOpBuffer.TryDequeue(out m);
paramQueue.context->glUniform3f(*(int*)handle, m.Read<float>(0), m.Read<float>(1), m.Read<float>(2)); activatedContext->glUniform3f(*(int*)handle, m.Read<float>(0), m.Read<float>(1), m.Read<float>(2));
} }
private static void UniformVal4f() private static void UniformVal4f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{ {
IntPtr handle = IntPtr.Zero; IntPtr handle = IntPtr.Zero;
M128 m = default; M128 m = default;
paramQueue.TryDequeue(out handle); frameOpBuffer.TryDequeue(out handle);
paramQueue.TryDequeue(out m); frameOpBuffer.TryDequeue(out m);
paramQueue.context->glUniform4f(*(int*)handle, m.Read<float>(0), m.Read<float>(1), m.Read<float>(2), m.Read<float>(3)); activatedContext->glUniform4f(*(int*)handle, m.Read<float>(0), m.Read<float>(1), m.Read<float>(2), m.Read<float>(3));
} }
} }
} }
+21 -21
View File
@@ -31,13 +31,13 @@ namespace StgSharp.Graphics
/// <param name="loader">A delegate to get address of OprnGL api</param> /// <param name="loader">A delegate to get address of OprnGL api</param>
public static unsafe void LoadGLapi(this Form form, GLfuncLoader loader) public static unsafe void LoadGLapi(this Form form, GLfuncLoader loader)
{ {
GLcontext* context = form.contextID; GLcontext* context = (GLcontext*)form.graphicContextID;
if (loader == null) if (loader == null)
{ {
loader = InternalIO.glfwGetProcAddress; loader = InternalIO.glfwGetProcAddress;
} }
#pragma warning disable CS8909 #pragma warning disable CS8909
if ((form.contextID->glGetString) != (delegate*<uint, IntPtr>)IntPtr.Zero) if (((GLcontext*)form.graphicContextID)->glGetString != (delegate*<uint, IntPtr>)IntPtr.Zero)
#pragma warning restore CS8909 #pragma warning restore CS8909
{ {
return; return;
@@ -75,25 +75,25 @@ namespace StgSharp.Graphics
{ {
#region load_core_gl #region load_core_gl
LoadGLcore10(form.contextID, loader); LoadGLcore10((GLcontext*)form.graphicContextID, loader);
LoadGLcore11(form.contextID, loader); LoadGLcore11((GLcontext*)form.graphicContextID, loader);
LoadGLcore12(form.contextID, loader); LoadGLcore12((GLcontext*)form.graphicContextID, loader);
LoadGLcore13(form.contextID, loader); LoadGLcore13((GLcontext*)form.graphicContextID, loader);
LoadGLcore14(form.contextID, loader); LoadGLcore14((GLcontext*)form.graphicContextID, loader);
LoadGLcore15(form.contextID, loader); LoadGLcore15((GLcontext*)form.graphicContextID, loader);
LoadGLcore20(form.contextID, loader); LoadGLcore20((GLcontext*)form.graphicContextID, loader);
LoadGLcore21(form.contextID, loader); LoadGLcore21((GLcontext*)form.graphicContextID, loader);
LoadGLcore30(form.contextID, loader); LoadGLcore30((GLcontext*)form.graphicContextID, loader);
LoadGLcore31(form.contextID, loader); LoadGLcore31((GLcontext*)form.graphicContextID, loader);
LoadGLcore32(form.contextID, loader); LoadGLcore32((GLcontext*)form.graphicContextID, loader);
LoadGLcore33(form.contextID, loader); LoadGLcore33((GLcontext*)form.graphicContextID, loader);
LoadGLcore40(form.contextID, loader); LoadGLcore40((GLcontext*)form.graphicContextID, loader);
LoadGLcore41(form.contextID, loader); LoadGLcore41((GLcontext*)form.graphicContextID, loader);
LoadGLcore42(form.contextID, loader); LoadGLcore42((GLcontext*)form.graphicContextID, loader);
LoadGLcore43(form.contextID, loader); LoadGLcore43((GLcontext*)form.graphicContextID, loader);
LoadGLcore44(form.contextID, loader); LoadGLcore44((GLcontext*)form.graphicContextID, loader);
LoadGLcore45(form.contextID, loader); LoadGLcore45((GLcontext*)form.graphicContextID, loader);
LoadGLcore46(form.contextID, loader); LoadGLcore46((GLcontext*)form.graphicContextID, loader);
#endregion load_core_gl #endregion load_core_gl
} }
-5
View File
@@ -301,10 +301,5 @@ namespace StgSharp.Graphics
} }
internal void frameworkHandleEnqueue(IntPtr handle, params M128[] param); internal void frameworkHandleEnqueue(IntPtr handle, params M128[] param);
public bool FrameCanUpdate
{
get;
}
} }
} }
-1
View File
@@ -28,7 +28,6 @@ namespace StgSharp.Graphics
public int Height { get => info.height; } public int Height { get => info.height; }
public int Channel { get => info.channel; } public int Channel { get => info.channel; }
//TODO fix the bug
internal Image(ImageInfo information) internal Image(ImageInfo information)
{ {
info = information; info = information;
+54 -2
View File
@@ -1,7 +1,51 @@
using System; using System;
using System.Xml.Serialization;
namespace StgSharp namespace StgSharp
{ {
public delegate void TimeSourceProvider(TimeProvider subscriber);
public class TimeProvider
{
private readonly long _spanLength;
private long _spanBegin;
private Counter<uint> timeSpanCount = new Counter<uint>(0, 1, 1);
public static TimeSourceProvider DefaultProvider
{
get
{
return new(StgSharp.SubscribeTimeProvider);
}
}
public TimeProvider(
long spanLength
)
{
_spanLength = spanLength;
}
internal void CheckTime(long microseconds)
{
if (microseconds - _spanBegin > _spanLength)
{
_spanBegin = microseconds;
timeSpanCount++;
}
}
public void SubcsribeToTimeSource(TimeSourceProvider serviceHandler)
{
serviceHandler(this);
}
public static implicit operator uint(TimeProvider provider)
{
return provider.timeSpanCount.Value;
}
}
public class Counter<T> where T : struct, IConvertible, IFormattable, IComparable public class Counter<T> where T : struct, IConvertible, IFormattable, IComparable
{ {
internal readonly T _defualtValue; internal readonly T _defualtValue;
@@ -38,24 +82,34 @@ namespace StgSharp
{ {
case TypeCode.Byte: case TypeCode.Byte:
break; break;
case TypeCode.Int16: case TypeCode.Int16:
break; break;
case TypeCode.Int32: case TypeCode.Int32:
break; break;
case TypeCode.Int64: case TypeCode.Int64:
break; break;
case TypeCode.Double: case TypeCode.Double:
break; break;
case TypeCode.Single: case TypeCode.Single:
break; break;
case TypeCode.SByte: case TypeCode.SByte:
break; break;
case TypeCode.UInt16: case TypeCode.UInt16:
break; break;
case TypeCode.UInt32: case TypeCode.UInt32:
break; break;
case TypeCode.UInt64: case TypeCode.UInt64:
break; break;
default: default:
throw new ArgumentException("Input is not number value type"); throw new ArgumentException("Input is not number value type");
break; break;
@@ -66,7 +120,6 @@ namespace StgSharp
_defualtSubValue = defualtSubValue; _defualtSubValue = defualtSubValue;
} }
public void Add(T value) public void Add(T value)
{ {
_value += value; _value += value;
@@ -113,6 +166,5 @@ namespace StgSharp
{ {
return counter.Value; return counter.Value;
} }
} }
} }
+14 -6
View File
@@ -1,4 +1,5 @@
using StgSharp.Graphics; using StgSharp.Graphics;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -10,14 +11,21 @@ namespace StgSharp.Logic
[System.Serializable] [System.Serializable]
internal class FrameTimeoutException : Exception internal class FrameTimeoutException : Exception
{ {
internal FrameTimeoutException() { } internal FrameTimeoutException()
internal FrameTimeoutException(string message) : base(message) { }
internal FrameTimeoutException(Form form) :
base($"Form {nameof(form)} cannot accoplish all render work at frame {form.timer.totalFrame}")
{ } { }
internal FrameTimeoutException(string message, Exception inner) : base(message, inner) { }
internal FrameTimeoutException(string message) : base(message)
{
}
internal FrameTimeoutException(string message, Exception inner) : base(message, inner)
{
}
protected FrameTimeoutException( protected FrameTimeoutException(
System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { } System.Runtime.Serialization.StreamingContext context) : base(info, context)
{
}
} }
} }
-249
View File
@@ -1,249 +0,0 @@
using StgSharp.Graphics;
using System;
using System.Collections;
namespace StgSharp
{
public class LinkedList<T> : IEnumerable
{
public Counter<uint> count = new Counter<uint>(0, 1, 1);
internal readonly LinkedListNode<T> _hook;
private LinkedListNode<T> _cache;
public LinkedList()
{
_hook = new LinkedListNode<T>();
}
/// <summary>
/// Whether this linked list has no members or not.
/// </summary>
public bool IsEmpty
{
get { return count == 0; }
}
/// <summary>
/// The first memeber of this linkec list.
/// Set value to this property will reset the first node.
/// </summary>
public T First
{
get { return _hook._next._value; }
/*
* This setter is ued to reset the First node,
* be careful when use this setter to avoid
* unexpected risk of this List lose all nodes.
*/
private set { _hook._next = default; }
}
/// <summary>
/// The last memeber of this linkec list.
/// Set value to this property will reset the first node.
/// </summary>
public T Tail
{
get { return _hook._previous._value; }
/*
* This setter is ued to reset the Last node,
* be careful when use this setter to avoid
* unexpected risk of this List lose all nodes.
*/
private set { _hook._previous = default; }
}
/// <summary>
/// Add an item to the tail of linked list.
/// </summary>
/// <param name="t">The item ready to add to the list</param>
public void Add(T t)
{
//checkout if the linkedlist is null
if (IsEmpty)
{
LinkedListNode<T> node = new LinkedListNode<T>(t);
_hook._next = node;
_hook._previous = node;
node.Next = _hook;
node.Previous = _hook;
}
else
{
LinkedListNode<T> node = new LinkedListNode<T>(t);
node.Next = _hook;
node.Previous = _hook.Previous;
_hook._previous._next = node;
_hook._previous = node;
}
count++;
}
/// <summary>
/// Remove all members from this list
/// </summary>
public void Clear()
{
_hook._previous = null;
_hook._next = null;
count.Reset();
GC.Collect();
}
IEnumerator IEnumerable.GetEnumerator()
{
return new LinkedListEnumrator<T>(this);
}
/// <summary>
/// Insert a member to current linkedlist,
/// the new member will be after a certain existed member.
/// </summary>
/// <param name="target">New member will be inserted after this member</param>
/// <param name="newMember">The new member to be inserted</param>
public void InsertAfter(T target, T newMember)
{
try
{
LinkedListNode<T> targetNode = Find(target);
LinkedListNode<T> targetNext = targetNode._next;
LinkedListNode<T> newNode = new LinkedListNode<T>(newMember);
targetNode._next = newNode;
newNode._next = targetNext;
targetNode._previous = newNode;
newNode._previous = targetNode;
count++;
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// Remove a member from this linkedlist.
/// </summary>
/// <param name="value">Member to be removed from this list</param>
public void Remove(T value)
{
LinkedListNode<T> node = Find(value);
node._next._previous = node._previous;
node._previous._next = node._next;
node._previous = null;
node._next = null;
count--;
}
/// <summary>
/// remove the first member of the list
/// </summary>
public void RemoveFirst()
{
if (count._value == 1)
{
First = default;
}
else
{
_hook._next.Remove();
}
count--;
}
/// <summary>
/// remove the last member of the list
/// </summary>
public void RemoveTail()
{
//check out if the list has only one member
if (count._value == 1)
{
First = default;
}
else
{
_hook.Previous = _hook.Previous.Previous;
_hook.Previous.Next = _hook;
}
count--;
}
internal LinkedListNode<T> Find(T value)
{
LinkedListNode<T> enumerator = this._hook;
do
{
enumerator = enumerator._next;
} while (!enumerator.Value.Equals(value)
|| enumerator == _hook);
if (enumerator == _hook)
{
throw new Exception();
}
return enumerator;
}
/**/
internal struct LinkedListEnumrator<T> : IEnumerator
{
private LinkedList<T> _target;
private T _value;
private LinkedListNode<T> enumerator;
private uint index = 0;
public LinkedListEnumrator(LinkedList<T> target)
{
_target = target;
enumerator = target._hook;
}
object IEnumerator.Current
{
get
{
if (index == 0 || enumerator == _target._hook)
{
throw new InvalidOperationException("Out of index range");
}
else
{
_value = enumerator._value;
return _value;
}
}
}
public T Current
{
get
{
return _value;
}
}
bool IEnumerator.MoveNext()
{
enumerator = enumerator._next;
if (enumerator == _target._hook)
{
return false;
}
index++;
return true;
}
void IEnumerator.Reset()
{
enumerator = _target._hook;
}
}
/**/
}
}
@@ -1,49 +0,0 @@
using System.Diagnostics.CodeAnalysis;
namespace StgSharp
{
internal class LinkedListNode<T>
{
internal readonly T _value;
internal LinkedListNode<T> _previous;
internal LinkedListNode<T> _next;
internal LinkedList<T> list;
internal LinkedListNode()
{
}
public LinkedListNode(T t)
{
_value = t;
}
public virtual LinkedListNode<T> Previous
{
get { return _previous; }
set { _previous = value; }
}
public LinkedListNode<T> Next
{
get { return _next; }
set { _next = value; }
}
public T Value
{
get { return _value; }
}
public void Remove()
{
_previous.Next = _next;
_next.Previous = _previous;
_next = null;
_previous = null;
}
}
}
@@ -1,23 +0,0 @@
namespace StgSharp.Logic
{
public abstract class QuickClearNode<T> where T : QuickClearNode<T>
{
internal LinkedList<LinkedListNode<T>> _idList
= new LinkedList<LinkedListNode<T>>();
internal void QuickDestruct(LinkedList<T> list)
{
foreach (LinkedListNode<T> id in _idList)
{
if (id.list == list)
{
RecycleBin.Add(id);
break;
}
}
}
internal static LinkedList<LinkedListNode<T>> RecycleBin
= new LinkedList<LinkedListNode<T>>();
}
}
+3 -2
View File
@@ -1,11 +1,12 @@
using System; using System;
using System.Globalization; using System.Globalization;
using System.Runtime.CompilerServices;
namespace StgSharp.Math namespace StgSharp.Math
{ {
public static unsafe partial class Scaler public static unsafe partial class Scaler
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe float Abs(float x) public static unsafe float Abs(float x)
{ {
uint* a = (uint*)&x; uint* a = (uint*)&x;
@@ -13,6 +14,7 @@ namespace StgSharp.Math
return *(float*)a; return *(float*)a;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe int Abs(int x) public static unsafe int Abs(int x)
{ {
uint* a = (uint*)&x; uint* a = (uint*)&x;
@@ -34,6 +36,5 @@ namespace StgSharp.Math
return CultureInfo.CurrentCulture.TextInfo.ListSeparator; return CultureInfo.CurrentCulture.TextInfo.ListSeparator;
} }
} }
} }
@@ -795,58 +795,6 @@
The second <see cref="T:System.Boolean"/> value. The second <see cref="T:System.Boolean"/> value.
</summary> </summary>
</member> </member>
<member name="P:StgSharp.LinkedList`1.IsEmpty">
<summary>
Whether this linked list has no members or not.
</summary>
</member>
<member name="P:StgSharp.LinkedList`1.First">
<summary>
The first memeber of this linkec list.
Set value to this property will reset the first node.
</summary>
</member>
<member name="P:StgSharp.LinkedList`1.Tail">
<summary>
The last memeber of this linkec list.
Set value to this property will reset the first node.
</summary>
</member>
<member name="M:StgSharp.LinkedList`1.Add(`0)">
<summary>
Add an item to the tail of linked list.
</summary>
<param name="t">The item ready to add to the list</param>
</member>
<member name="M:StgSharp.LinkedList`1.Clear">
<summary>
Remove all members from this list
</summary>
</member>
<member name="M:StgSharp.LinkedList`1.InsertAfter(`0,`0)">
<summary>
Insert a member to current linkedlist,
the new member will be after a certain existed member.
</summary>
<param name="target">New member will be inserted after this member</param>
<param name="newMember">The new member to be inserted</param>
</member>
<member name="M:StgSharp.LinkedList`1.Remove(`0)">
<summary>
Remove a member from this linkedlist.
</summary>
<param name="value">Member to be removed from this list</param>
</member>
<member name="M:StgSharp.LinkedList`1.RemoveFirst">
<summary>
remove the first member of the list
</summary>
</member>
<member name="M:StgSharp.LinkedList`1.RemoveTail">
<summary>
remove the last member of the list
</summary>
</member>
<member name="T:StgSharp.Math.GLclampf"> <member name="T:StgSharp.Math.GLclampf">
<summary> <summary>
OpenGL numeric type. OpenGL numeric type.
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp")] [assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6a0cccae795127fdb83793160f33597edcdd736b")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a770bbe68567b43385bb30c9c86eb80e5b1e23e8")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp")] [assembly: System.Reflection.AssemblyProductAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp")] [assembly: System.Reflection.AssemblyTitleAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
a249a1b1d40a3abbceec68e9d369d3856611858d100648d3446f8f62f277dc6b 559b4f40232d6149ba7b0f1f8a02c2a2db80768c9617d556a49bc6d74abbd942
@@ -1 +1 @@
1a8e1802d5a508dcd983ae4f5d79408adb0743ed41648884055a8a411bac563f e8717691e705c7b75c1986d0e9dbd7e0de7ddd4858970bab93baeea5f7aae833
@@ -1 +1 @@
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/6a0cccae795127fdb83793160f33597edcdd736b/*"}} {"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/a770bbe68567b43385bb30c9c86eb80e5b1e23e8/*"}}
@@ -795,58 +795,6 @@
The second <see cref="T:System.Boolean"/> value. The second <see cref="T:System.Boolean"/> value.
</summary> </summary>
</member> </member>
<member name="P:StgSharp.LinkedList`1.IsEmpty">
<summary>
Whether this linked list has no members or not.
</summary>
</member>
<member name="P:StgSharp.LinkedList`1.First">
<summary>
The first memeber of this linkec list.
Set value to this property will reset the first node.
</summary>
</member>
<member name="P:StgSharp.LinkedList`1.Tail">
<summary>
The last memeber of this linkec list.
Set value to this property will reset the first node.
</summary>
</member>
<member name="M:StgSharp.LinkedList`1.Add(`0)">
<summary>
Add an item to the tail of linked list.
</summary>
<param name="t">The item ready to add to the list</param>
</member>
<member name="M:StgSharp.LinkedList`1.Clear">
<summary>
Remove all members from this list
</summary>
</member>
<member name="M:StgSharp.LinkedList`1.InsertAfter(`0,`0)">
<summary>
Insert a member to current linkedlist,
the new member will be after a certain existed member.
</summary>
<param name="target">New member will be inserted after this member</param>
<param name="newMember">The new member to be inserted</param>
</member>
<member name="M:StgSharp.LinkedList`1.Remove(`0)">
<summary>
Remove a member from this linkedlist.
</summary>
<param name="value">Member to be removed from this list</param>
</member>
<member name="M:StgSharp.LinkedList`1.RemoveFirst">
<summary>
remove the first member of the list
</summary>
</member>
<member name="M:StgSharp.LinkedList`1.RemoveTail">
<summary>
remove the last member of the list
</summary>
</member>
<member name="T:StgSharp.Math.GLclampf"> <member name="T:StgSharp.Math.GLclampf">
<summary> <summary>
OpenGL numeric type. OpenGL numeric type.
-25
View File
@@ -15,31 +15,6 @@ SSCAPI void SSCDECL initGL(int majorVersion, int minorVersion)
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
} }
SSCAPI unsigned int SSCDECL loadShaderCode(GladGLContext* context, char* const shaderCode, GLint shadertype)
{
unsigned int shader = context->CreateShader(GL_VERTEX_SHADER);
if (!shader)
{
return 0xffffffff;
}
printf("%s\n", shaderCode);
context->ShaderSource(shader, 1, shaderCode, NULL);
printf("%s\n", shaderCode);
context->CompileShader(shader);
int success;
context->GetShaderiv(shader, GL_COMPILE_STATUS, &success);
if (!success)
{
context->GetShaderInfoLog(shader, 512, NULL, infolog);
infolog[511] = '\0';
return 0;
}
else
{
return shader;
}
}
SSCAPI GLFWglproc SSCDECL loadGlfuncDefault(char* procName) SSCAPI GLFWglproc SSCDECL loadGlfuncDefault(char* procName)
{ {
void* ret = glfwGetProcAddress(procName); void* ret = glfwGetProcAddress(procName);
-1
View File
@@ -38,7 +38,6 @@ extern "C"
SSCAPI char infolog[512]; SSCAPI char infolog[512];
SSCAPI void SSCDECL initGL(int majorVersion, int minorVersion); SSCAPI void SSCDECL initGL(int majorVersion, int minorVersion);
SSCAPI unsigned int SSCDECL loadShaderCode(GladGLContext* context, char* const shaderCode, GLint shadertype);
SSCAPI unsigned int SSCDECL linkShaderProgram(GladGLContext* context, GLuint shadertype); SSCAPI unsigned int SSCDECL linkShaderProgram(GladGLContext* context, GLuint shadertype);
SSCAPI void SSCDECL loadImageData(char* location, Image* out, imageLoader loader); SSCAPI void SSCDECL loadImageData(char* location, Image* out, imageLoader loader);
SSCAPI GLFWglproc SSCDECL loadGlfuncDefault(char* procName); SSCAPI GLFWglproc SSCDECL loadGlfuncDefault(char* procName);
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp
{
public static unsafe partial class StgSharp
{
/// <summary>
/// Init an instance of OpenGL program,
/// This method should be called before any other StgSharp api.
/// </summary>
public static void InitGL(int majorVersion, int minorVersion)
{
if (API == default)
{
API = GraphicAPI.GL;
}
if (API != GraphicAPI.GL)
{
return;
}
InternalIO.InternalInitGL(majorVersion, minorVersion);
}
public static class GlobalSetting
{
private static bool vSyncActivated;
public static bool VSyncActivated
{
get { return vsyncActivated; }
set
{
InternalIO.glfwSwapInterval(value ? 1 : 0);
vsyncActivated = value;
}
}
}
}
}
@@ -6,6 +6,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@@ -33,10 +34,10 @@ namespace StgSharp
VK VK
} }
public static partial class Platform public static partial class StgSharp
{ {
internal static GraphicAPI API = default; internal static GraphicAPI API = default;
private static bool vsyncActivated;
private static uint markCount = 0; private static uint markCount = 0;
public static void Mark(bool needConsole) public static void Mark(bool needConsole)
@@ -55,22 +56,6 @@ namespace StgSharp
/// </summary> /// </summary>
public const long version = 430; public const long version = 430;
/// <summary>
/// Init an instance of OpenGL program,
/// This method should be called before other
/// graphic methods, after LoadGL method.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void InitGL(int majorVersion, int minorVersion)
{
if (API != default)
{
return;
}
InternalIO.InternalInitGL(majorVersion, minorVersion);
}
/// <summary> /// <summary>
/// Write a log message to log file, and mark the level of this message. /// Write a log message to log file, and mark the level of this message.
/// </summary> /// </summary>
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp
{
public static partial class StgSharp
{
private static Stopwatch mainProvider = new Stopwatch();
private static List<TimeProvider> subscriberList = new List<TimeProvider>();
private static Thread timeProvideThread;
private static long accuracy;
private static void ProvideTime()
{
long totalMS, previousFrameMS = 0,
internalFrequncy = Stopwatch.Frequency;
lock (mainProvider)
{
mainProvider.Restart();
}
while (mainProvider.IsRunning)
{
totalMS = mainProvider.ElapsedTicks / (internalFrequncy / (1000L * 1000L));
foreach (TimeProvider subscriber in subscriberList)
{
subscriber.CheckTime(totalMS);
}
}
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public static void TimerActivate(int maxFrameUpdateSensitiveTimeProviderCount)
{
if (!mainProvider.IsRunning)
{
mainProvider.Start();
//speed test
long totalMS, previousSecondMS = 0,
internalFrequncy = Stopwatch.Frequency;
for (int i = 0; i < 100; i++)
{
totalMS = mainProvider.ElapsedTicks / (internalFrequncy / (1000L * 1000L));
for (int t = 0; t < 10; t++)
{
if (totalMS < 1000)
{
subscriberList.Add(new TimeProvider(100L));
}
}
}
mainProvider.Stop();
subscriberList.Clear();
totalMS = (mainProvider.ElapsedTicks / (internalFrequncy / (1000L * 1000L))) / 100L;
accuracy = totalMS * 2 / 3;
mainProvider.Reset();
timeProvideThread = new Thread(new ThreadStart(ProvideTime));
timeProvideThread.Start();
}
}
public static void SubscribeTimeProvider(TimeProvider provider)
{
}
public static void TimerDeactivate()
{
lock (mainProvider)
{
mainProvider.Stop();
}
}
}
}
+4 -6
View File
@@ -55,7 +55,6 @@ namespace StgSharp
{ {
InternalIO.InternalWriteLog("\n\n\n", "Program start", LogType.Info); InternalIO.InternalWriteLog("\n\n\n", "Program start", LogType.Info);
Platform.InitGL(4, 6);
SetRenderThreads(2); SetRenderThreads(2);
SetMetadata(800, 600, "Hello, STG#!", IntPtr.Zero, null); SetMetadata(800, 600, "Hello, STG#!", IntPtr.Zero, null);
@@ -186,9 +185,12 @@ namespace StgSharp
{ {
try try
{ {
//Platform.TryCreatWindow(); //StgSharp.TryCreatWindow();
/**/ /**/
StgSharp.InitGL(4, 6);
StgSharp.GlobalSetting.VSyncActivated = false;
StgSharpDemoForm demoForm = new StgSharpDemoForm(); StgSharpDemoForm demoForm = new StgSharpDemoForm();
demoForm.Init(); demoForm.Init();
demoForm.Show(); demoForm.Show();
@@ -232,9 +234,5 @@ namespace StgSharp
LogType.Error); LogType.Error);
} }
} }
[DllImport(InternalIO.SSC_libname, EntryPoint = "printShaderCode",
CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe void PrintShader(byte** shadercode);
} }
} }
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpDebug")] [assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6a0cccae795127fdb83793160f33597edcdd736b")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a770bbe68567b43385bb30c9c86eb80e5b1e23e8")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharpDebug")] [assembly: System.Reflection.AssemblyProductAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharpDebug")] [assembly: System.Reflection.AssemblyTitleAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
8ae247055df878dabde901431f74bbb5c355dc1c4551c9916e86797b50b30796 a30a9fd1462f450229b650c6f00eadf2b5bbe11b75c90e2b6d0f6e8aab7ab56e
@@ -1 +1 @@
c55fdcf5347f885d1031021c599a5f342bcfdf8d8bb3a34371e4f37879f74d7d d0739f6dcc2b7c56b30c8bf5da3b96332ce6e8031f525daae9acdf819b2e29b3
@@ -1 +1 @@
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/6a0cccae795127fdb83793160f33597edcdd736b/*"}} {"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/a770bbe68567b43385bb30c9c86eb80e5b1e23e8/*"}}
@@ -795,58 +795,6 @@
The second <see cref="T:System.Boolean"/> value. The second <see cref="T:System.Boolean"/> value.
</summary> </summary>
</member> </member>
<member name="P:StgSharp.LinkedList`1.IsEmpty">
<summary>
Whether this linked list has no members or not.
</summary>
</member>
<member name="P:StgSharp.LinkedList`1.First">
<summary>
The first memeber of this linkec list.
Set value to this property will reset the first node.
</summary>
</member>
<member name="P:StgSharp.LinkedList`1.Tail">
<summary>
The last memeber of this linkec list.
Set value to this property will reset the first node.
</summary>
</member>
<member name="M:StgSharp.LinkedList`1.Add(`0)">
<summary>
Add an item to the tail of linked list.
</summary>
<param name="t">The item ready to add to the list</param>
</member>
<member name="M:StgSharp.LinkedList`1.Clear">
<summary>
Remove all members from this list
</summary>
</member>
<member name="M:StgSharp.LinkedList`1.InsertAfter(`0,`0)">
<summary>
Insert a member to current linkedlist,
the new member will be after a certain existed member.
</summary>
<param name="target">New member will be inserted after this member</param>
<param name="newMember">The new member to be inserted</param>
</member>
<member name="M:StgSharp.LinkedList`1.Remove(`0)">
<summary>
Remove a member from this linkedlist.
</summary>
<param name="value">Member to be removed from this list</param>
</member>
<member name="M:StgSharp.LinkedList`1.RemoveFirst">
<summary>
remove the first member of the list
</summary>
</member>
<member name="M:StgSharp.LinkedList`1.RemoveTail">
<summary>
remove the last member of the list
</summary>
</member>
<member name="T:StgSharp.Math.GLclampf"> <member name="T:StgSharp.Math.GLclampf">
<summary> <summary>
OpenGL numeric type. OpenGL numeric type.
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgsharpEnvDebug")] [assembly: System.Reflection.AssemblyCompanyAttribute("StgsharpEnvDebug")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6a0cccae795127fdb83793160f33597edcdd736b")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a770bbe68567b43385bb30c9c86eb80e5b1e23e8")]
[assembly: System.Reflection.AssemblyProductAttribute("StgsharpEnvDebug")] [assembly: System.Reflection.AssemblyProductAttribute("StgsharpEnvDebug")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgsharpEnvDebug")] [assembly: System.Reflection.AssemblyTitleAttribute("StgsharpEnvDebug")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
85114024ddf0e115a84852eab07a2b0be96658756632868011a23358776ed19e 79f2b872051c7619fff5b34141b27643e9f666037c4cc5c361301d43678b13a2