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
-4
View File
@@ -24,10 +24,6 @@ namespace StgSharp
CallingConvention = CallingConvention.Cdecl)]
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",
CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe IntPtr InternalReadSSCLog();
+3 -1
View File
@@ -1,5 +1,7 @@
using StgSharp.Controlling;
using System;
using System.Collections.Generic;
namespace StgSharp.Entities
{
@@ -35,4 +37,4 @@ namespace StgSharp.Entities
public virtual void OnUpdate() => new NotImplementedException();
}
}
}
+3 -2
View File
@@ -1,6 +1,8 @@
using StgSharp.Geometries;
using StgSharp.Math;
using System.Collections.Generic;
namespace StgSharp
{
public abstract class IEntity
@@ -52,6 +54,5 @@ namespace StgSharp
}
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.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
@@ -33,10 +34,10 @@ namespace StgSharp
VK
}
public static partial class Platform
public static partial class StgSharp
{
internal static GraphicAPI API = default;
private static bool vsyncActivated;
private static uint markCount = 0;
public static void Mark(bool needConsole)
@@ -55,22 +56,6 @@ namespace StgSharp
/// </summary>
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>
/// Write a log message to log file, and mark the level of this message.
/// </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
{
/// <summary>
/// 平面几何体。包含三角形,对称四边形,自由多边形等。最多可由16个点参数定义。
/// </summary>
public abstract class PlainGeometry
{
protected FrameTimer time;
protected TimeProvider time;
internal PartialPlainCoordinate coordinate;
internal Matrix2x4 textureFrame;
@@ -22,16 +21,18 @@ namespace StgSharp.Geometries
/// <summary>
/// Tick time this geometry eas crested
/// </summary>
/// </summary>
public uint BornTime => time;
internal abstract int[] Indices { get; }
public PlainGeometry(Form form)
{
time = new FrameTimer(form);
time = new TimeProvider(form);
}
public PlainGeometry() { }
public PlainGeometry()
{ }
internal abstract void UpdateCoordinate(uint tick);
@@ -48,8 +49,5 @@ namespace StgSharp.Geometries
public abstract Plain GetPlain();
//public abstract Rectangle GetRenderFrame();
}
}
}
@@ -1,6 +1,7 @@
using StgSharp.Controlling;
using StgSharp.Math;
using StgSharp.Math.Linear;
using System.Numerics;
namespace StgSharp.Geometries
@@ -131,4 +132,4 @@ namespace StgSharp.Geometries
vertexMat.vec5 = origin + movVertex5(nowTick).vec;
}
}
}
}
+49 -90
View File
@@ -29,9 +29,8 @@ namespace StgSharp.Graphics
internal LinkedList<Control> allControl;
internal Vector4 backgroundColor;
internal unsafe GLcontext* contextID;
internal DynamicArrayList<IntPtr> formBuffer;
internal IglFunc gl;
internal unsafe IntPtr graphicContextID;
internal int height;
internal IntPtr monitor;
internal string name;
@@ -39,13 +38,12 @@ namespace StgSharp.Graphics
internal int width;
internal IntPtr windowID;
protected readonly TimeProvider FrameTimeFrocider;
#endregion metadata
#region form thread setting
internal FrameUpdateTimer timer = new FrameUpdateTimer();
private SemaphoreSlim _renderFinishSignal = new SemaphoreSlim(0, 1);
private SemaphoreSlim _renderStartSignal = new SemaphoreSlim(1, 1);
private bool isSingleThread = true;
#endregion form thread setting
@@ -57,15 +55,12 @@ namespace StgSharp.Graphics
#endregion glapicount
private int _shouldClose = 0;
protected Form()
{
}
unsafe ~Form()
{
Marshal.FreeHGlobal((IntPtr)contextID);
}
/// <summary>
/// OpenGL package used by current form context.
/// </summary>
@@ -92,8 +87,6 @@ namespace StgSharp.Graphics
get { return isSingleThread; }
}
private int _shouldClose = 0;
public bool ShouldClose
{
get
@@ -136,18 +129,6 @@ namespace StgSharp.Graphics
get { return isSingleThread; }
}
internal SemaphoreSlim RenderFinishSignal
{
get { return _renderFinishSignal; }
set { _renderFinishSignal = value; }
}
internal SemaphoreSlim RenderStrartSignal
{
get { return _renderStartSignal; }
set { _renderStartSignal = value; }
}
protected FrameBufferSizeHandler FrameBufferSizeCallback
{
set
@@ -188,8 +169,8 @@ namespace StgSharp.Graphics
windowID = windowPtr;
}
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GLcontext)));
contextID = (GLcontext*)ptr;
graphicContextID = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GLcontext)));
GLcontext* contextID = (GLcontext*)graphicContextID;
*contextID = new GLcontext();
contextID->glGetString = (delegate*<uint, IntPtr>)IntPtr.Zero;
gl = new GLonRender(contextID);
@@ -267,6 +248,11 @@ namespace StgSharp.Graphics
(int)minSize.X, (int)minSize.Y, (int)maxSize.X, (int)maxSize.Y);
}
unsafe ~Form()
{
Marshal.FreeHGlobal(graphicContextID);
}
#region form main
private static unsafe delegate*<void> pollEventPtr = &InternalIO.glfwPollEvents;
@@ -309,35 +295,52 @@ namespace StgSharp.Graphics
{
InternalIO.InternalWriteLog($"Attempt to show form {name} before init", LogType.Error);
}
else if (isSingleThread)
{
while (!ShouldClose)
{
Main(args);
}
}
else
{
gl = new GLonUpdate(contextID);
Thread renderThread = new Thread(new ThreadStart(InternalRender));
renderThread.Start();
int a = 0;
while (!ShouldClose)
if (isSingleThread)
{
if (gl.FrameCanUpdate)
while (!ShouldClose)
{
Main(args);
SwapBuffers();
}
}
//TODO 对逻辑线程和渲染线程进行同步,两种gl模式包需要改名字
renderThread.Join();
//Thread.Sleep(1000 * 20);
//ShouldClose = true;
//(gl as GLonUpdate).GLactionQueue.Clear();
else
{
GLonUpdate update = new GLonUpdate((GLcontext*)graphicContextID);
FrameThread renderThread = new FrameThread(update);
FrameThread updateThread = new FrameThread(update);
renderThread.SetNext(updateThread);
updateThread.SetNext(renderThread);
gl = update;
int a = 0;
while (!ShouldClose)
{
}
//TODO 对逻辑线程和渲染线程进行同步,两种gl模式包需要改名字
}
}
}
public unsafe void SwapBuffers()
internal static unsafe void InternalSwapBuffers()
{
IntPtr winHandle = default;
InternalIO.glfwSwapBuffers(winHandle);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void InternalDeinit(params object[] args)
{
Deinit(args);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void InternalInit(params object[] args)
{
Init(args);
}
internal unsafe void SwapBuffers()
{
if (isSingleThread)
{
@@ -351,30 +354,13 @@ namespace StgSharp.Graphics
}
}
internal static unsafe void InternalSwapBuffers()
{
IntPtr winHandle = default;
GLonUpdate.ParamQueue.TryDequeue(out winHandle);
InternalIO.glfwSwapBuffers(winHandle);
}
internal void InternalDeinit(params object[] args)
{
Deinit(args);
}
internal void InternalInit(params object[] args)
{
Init(args);
}
/// <summary>
/// Get OpenGL library of this form's context.
/// </summary>
/// <returns>A <see cref="IglFunc"/> package contains all opengl APIs </returns>
protected IglFunc GetGL()
{
if (Platform.API == GraphicAPI.GL)
if (StgSharp.API == GraphicAPI.GL)
{
return this.GL;
}
@@ -409,33 +395,6 @@ namespace StgSharp.Graphics
{
throw new ArgumentException("Amount of threads should be bigger than 0");
}
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GLcontext)));
contextID = (GLcontext*)ptr;
*contextID = new GLcontext();
contextID->glGetString = (delegate*<uint, IntPtr>)IntPtr.Zero;
}
private unsafe void InternalRender()
{
#pragma warning disable CS8602
ConcurrentQueue<IntPtr> glActions = (gl as GLonUpdate).GLactionQueue;
#pragma warning restore CS8602
IntPtr currentOperation;
try
{
while (_shouldClose == 0)
{
if (glActions.TryDequeue(out currentOperation))
{
((delegate*<void>)currentOperation)();
}
}
}
catch (Exception e)
{
this.ShouldClose = true;
throw;
}
}
#endregion form main
+71 -40
View File
@@ -7,22 +7,22 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
internal sealed class FrameOperationBuffer
{
private readonly unsafe GLcontext* currentContext;
private IntPtr _func;
private ConcurrentQueue<IntPtr> _funcQueue;
private GLparamQueue _param;
internal unsafe GLcontext* context;
public unsafe bool CallNext()
{
if (_funcQueue.TryDequeue(out _func))
{
((delegate*<void>)_func)();
((delegate*<FrameOperationBuffer, GLcontext*, void>)_func)(this, currentContext);
return true;
}
else
@@ -37,148 +37,154 @@ namespace StgSharp.Graphics
private ConcurrentQueue<glArrayHandle> streamQueue = new ConcurrentQueue<glArrayHandle>();
[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);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(M128 m)
public void ParamEnqueue(M128 m)
{
paramQueue.Enqueue(m);
Console.WriteLine(paramQueue.Count + streamQueue.Count);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(uint u0)
public void ParamEnqueue(uint u0)
{
M128 m = default;
m.Write<uint>(0, u0);
this.Enqueue(m);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(uint u0, uint u1)
public void ParamEnqueue(uint u0, uint u1)
{
M128 m = default;
m.Write<uint>(0, u0);
m.Write<uint>(1, u1);
this.Enqueue(m);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(ulong u0, ulong u1)
public void ParamEnqueue(ulong u0, ulong u1)
{
M128 m = default;
m.Write<ulong>(0, u0);
m.Write<ulong>(1, u1);
this.Enqueue(m);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(uint u0, uint u1, uint u2)
public void ParamEnqueue(uint u0, uint u1, uint u2)
{
M128 m = default;
m.Write<uint>(0, u0);
m.Write<uint>(1, u1);
m.Write<uint>(2, u2);
this.Enqueue(m);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(float f0, float f1, float f2)
public void ParamEnqueue(float f0, float f1, float f2)
{
M128 m = default;
m.Write<float>(0, f0);
m.Write<float>(1, f1);
this.Enqueue(m);
this.ParamEnqueue(m);
}
[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;
m.Write<float>(0, f0);
m.Write<float>(1, f1);
m.Write<float>(2, f2);
m.Write<float>(3, f3);
this.Enqueue(m);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(IntPtr p0, IntPtr p1)
public void ParamEnqueue(IntPtr p0, IntPtr p1)
{
M128 m = default;
m.Write<ulong>(0, (ulong)p0);
m.Write<ulong>(1, (ulong)p1);
this.Enqueue(m);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(IntPtr p)
public void ParamEnqueue(IntPtr p)
{
M128 m = default;
m.Write<ulong>(0, (ulong)p);
this.Enqueue(m);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Enqueue(glHandle handle)
public unsafe void ParamEnqueue(glHandle handle)
{
M128 m = default;
m.Write<ulong>(0, (ulong)handle.valuePtr);
this.Enqueue(m);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Enqueue(glHandle handle, glHandle handle1)
public unsafe void ParamEnqueue(glHandle handle, glHandle handle1)
{
M128 m = default;
m.Write<ulong>(0, (ulong)handle.valuePtr);
m.Write<ulong>(1, (ulong)handle1.valuePtr);
this.Enqueue(m);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(int i0)
public void ParamEnqueue(int i0)
{
M128 m = default;
m.Write<int>(0, i0);
this.Enqueue(m);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(int i0, int i1)
public void ParamEnqueue(int i0, int i1)
{
M128 m = default;
m.Write<int>(0, i0);
m.Write<int>(1, i1);
this.Enqueue(m);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(int i0, int i1, int i2)
public void ParamEnqueue(int i0, int i1, int i2)
{
M128 m = default;
m.Write<int>(0, i0);
m.Write<int>(1, i1);
m.Write<int>(2, i2);
this.Enqueue(m);
this.ParamEnqueue(m);
}
[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;
m.Write<int>(0, i0);
m.Write<int>(1, i1);
m.Write<int>(2, i2);
m.Write<int>(3, i3);
this.Enqueue(m);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(string str)
public void ParamEnqueue(string str)
{
byte[] code = Encoding.UTF8.GetBytes(str);
streamQueue.Enqueue(glArrayHandle.Alloc<byte>(code));
@@ -186,7 +192,7 @@ namespace StgSharp.Graphics
}
[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));
Console.WriteLine(paramQueue.Count + streamQueue.Count);
@@ -452,18 +458,43 @@ namespace StgSharp.Graphics
private Thread _thread;
private FrameOperationBuffer renderBuffer;
private SemaphoreSlim renderCompleteSemaphore = new SemaphoreSlim(1, 1);
private int terminateSignal;
private SemaphoreSlim renderStartSemaphore;
private bool shouldTerminate;
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()
{
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)
{
if (form.timer.alignSign.byte0 > 0)
{
throw new InvalidOperationException();
}
form.timer.alignSign.byte0++;
form.timer.WaitNextFrame();
throw refreshSIgnal;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -337,11 +331,9 @@ namespace StgSharp.Graphics
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();
}
bool IglFunc.FrameCanUpdate => true;
}
}
+70 -90
View File
@@ -15,10 +15,10 @@ namespace StgSharp.Graphics
{
internal unsafe partial class GLonUpdate : IglFunc
{
private static FrameOperationBuffer frameOpBuffer;
private GLcontext* api;
private IntPtr SwapBufferPtr = (IntPtr)(delegate*<IntPtr, void>)&InternalIO.glfwSwapBuffers;
private glSHandle unupdatedFrame = glSHandle.Alloc(0);
private FrameOperationBuffer frameOpBuffer;
internal GLonUpdate(GLcontext* context)
{
@@ -42,8 +42,8 @@ namespace StgSharp.Graphics
void IglFunc.ActiveTexture(uint type)
{
frameOpBuffer.Enqueue(type);
frameOpBuffer.Enqueue(ActiveTexturePtr);
frameOpBuffer.ParamEnqueue(type);
frameOpBuffer.MethodEnqueue(ActiveTexturePtr);
}
void IglFunc.AfterAlign(Form form, Action action)
@@ -59,8 +59,8 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.AttachShader(glHandle program, glHandle shader)
{
frameOpBuffer.Enqueue(program, shader);
frameOpBuffer.Enqueue(AttachShaderPtr);
frameOpBuffer.ParamEnqueue(program, shader);
frameOpBuffer.MethodEnqueue(AttachShaderPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -69,8 +69,8 @@ namespace StgSharp.Graphics
M128 m = default;
m.Write<uint>(0, (uint)bufferType);
m.Write<ulong>(1, (ulong)handle.valuePtr);
frameOpBuffer.Enqueue(m);
frameOpBuffer.Enqueue(BindBufferPtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(BindBufferPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -79,49 +79,49 @@ namespace StgSharp.Graphics
M128 m = default;
m.Write<uint>(0, (uint)type);
m.Write<ulong>(1, (ulong)texture.valuePtr);
frameOpBuffer.Enqueue(m);
frameOpBuffer.Enqueue(BindTexturePtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(BindTexturePtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.BindVertexArray(glHandle index)
{
frameOpBuffer.Enqueue(index);
frameOpBuffer.Enqueue(BindVertexArrayPtr);
frameOpBuffer.ParamEnqueue(index);
frameOpBuffer.MethodEnqueue(BindVertexArrayPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.Clear(MaskBufferBit mask)
{
frameOpBuffer.Enqueue((int)mask);
frameOpBuffer.Enqueue(ClearPtr);
frameOpBuffer.ParamEnqueue((int)mask);
frameOpBuffer.MethodEnqueue(ClearPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.ClearColor(float R, float G, float B, float A)
{
frameOpBuffer.Enqueue(R, G, B, A);
frameOpBuffer.Enqueue(ClearColorPtr);
frameOpBuffer.ParamEnqueue(R, G, B, A);
frameOpBuffer.MethodEnqueue(ClearColorPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.ClearGraphicError()
{
frameOpBuffer.Enqueue(ClearGraphicErrorPtr);
frameOpBuffer.MethodEnqueue(ClearGraphicErrorPtr);
}
unsafe void IglFunc.CompileShader(glHandle shaderhandle)
{
frameOpBuffer.Enqueue((IntPtr)shaderhandle.valuePtr);
frameOpBuffer.Enqueue(CompileShaderPtr);
frameOpBuffer.ParamEnqueue((IntPtr)shaderhandle.valuePtr);
frameOpBuffer.MethodEnqueue(CompileShaderPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
glHandle IglFunc.CreateProgram()
{
glHandle h = glHandle.Alloc(1);
frameOpBuffer.Enqueue(h);
frameOpBuffer.Enqueue(CreateProgramPtr);
frameOpBuffer.ParamEnqueue(h);
frameOpBuffer.MethodEnqueue(CreateProgramPtr);
return h;
}
@@ -132,8 +132,8 @@ namespace StgSharp.Graphics
glHandleSet h = new glHandleSet(count);
m.Write<ulong>(0, (ulong)h.handle);
m.Write<int>(2, count);
frameOpBuffer.Enqueue(m);
frameOpBuffer.Enqueue(CreateProgramSetPtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(CreateProgramSetPtr);
return h;
}
@@ -144,8 +144,8 @@ namespace StgSharp.Graphics
m.Write<int>(0, count);
m.Write<uint>(1, (uint)type);
m.Write<ulong>(1, (ulong)ret.handle);
frameOpBuffer.Enqueue(m);
frameOpBuffer.Enqueue(CreateShaderPtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(CreateShaderPtr);
return ret;
}
@@ -178,8 +178,8 @@ namespace StgSharp.Graphics
glHandle IglFunc.CreatGraphicProgram()
{
glHandle h = glHandle.Alloc(1);
frameOpBuffer.Enqueue(h);
frameOpBuffer.Enqueue(CreateProgramPtr);
frameOpBuffer.ParamEnqueue(h);
frameOpBuffer.MethodEnqueue(CreateProgramPtr);
return h;
}
@@ -189,8 +189,8 @@ namespace StgSharp.Graphics
M128 m = default;
m.Write<ulong>(0, (ulong)handle.valuePtr);
m.Write(2, 1);
frameOpBuffer.Enqueue(m);
frameOpBuffer.Enqueue(DeleBufferPtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(DeleBufferPtr);
}
unsafe void IglFunc.DeleteBuffers(glHandleSet handle)
@@ -198,16 +198,16 @@ namespace StgSharp.Graphics
M128 m = default;
m.Write<ulong>(0, (ulong)handle.handle);
m.Write<uint>(2, (uint)handle.length);
frameOpBuffer.Enqueue(m);
frameOpBuffer.Enqueue(DeleBufferPtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(DeleBufferPtr);
}
unsafe void IglFunc.DeleteVertexArrays(glHandleSet arrays)
{
M128 m = default; m.Write<ulong>(1, (ulong)arrays.handle);
m.Write<int>(0, arrays.length);
frameOpBuffer.Enqueue(m);
frameOpBuffer.Enqueue(DeleteVertexArrayPtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(DeleteVertexArrayPtr);
}
void IglFunc.DrawElements(GepmetryType mode, uint count, TypeCode type, IntPtr ptr)
@@ -234,17 +234,17 @@ namespace StgSharp.Graphics
LogType.Error);
return;
}
frameOpBuffer.Enqueue((uint)mode, count, a);
frameOpBuffer.Enqueue(ptr);
frameOpBuffer.Enqueue(DrawElementsPtr);
frameOpBuffer.ParamEnqueue((uint)mode, count, a);
frameOpBuffer.ParamEnqueue(ptr);
frameOpBuffer.MethodEnqueue(DrawElementsPtr);
}
unsafe glHandleSet IglFunc.GenBuffers(int count)
{
glHandleSet h = new glHandleSet(count);
M128 m = default; m.Write<uint>(2, (uint)count); m.Write<ulong>(0, (ulong)h.handle);
frameOpBuffer.Enqueue(m);
frameOpBuffer.Enqueue(GenBufferPtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(GenBufferPtr);
return h;
}
@@ -252,8 +252,8 @@ namespace StgSharp.Graphics
{
glHandleSet h = new glHandleSet(count);
M128 m = default; m.Write<uint>(2, (uint)count); m.Write<ulong>(0, (ulong)h.handle);
frameOpBuffer.Enqueue(m);
frameOpBuffer.Enqueue(GenTexturesPtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(GenTexturesPtr);
return h;
}
@@ -261,8 +261,8 @@ namespace StgSharp.Graphics
{
glHandleSet h = new glHandleSet(count);
M128 m = default; m.Write<uint>(2, (uint)count); m.Write<ulong>(0, (ulong)h.handle);
frameOpBuffer.Enqueue(m);
frameOpBuffer.Enqueue(GenTexturesPtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(GenTexturesPtr);
return h;
}
@@ -273,9 +273,9 @@ namespace StgSharp.Graphics
M128 m = default;
m.Write<ulong>(0, (ulong)program.Handle);
m.Write<ulong>(1, (ulong)GCHandle.Alloc(Encoding.UTF8.GetBytes(ptr), GCHandleType.Pinned).AddrOfPinnedObject());
frameOpBuffer.Enqueue(m);
frameOpBuffer.Enqueue((IntPtr)h.valuePtr);
frameOpBuffer.Enqueue(GetUniformLocationPtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.ParamEnqueue((IntPtr)h.valuePtr);
frameOpBuffer.MethodEnqueue(GetUniformLocationPtr);
return h;
}
@@ -296,9 +296,9 @@ namespace StgSharp.Graphics
void IglFunc.LoadShaderSource(glHandle shaderHandle, string codeStream)
{
frameOpBuffer.Enqueue(shaderHandle);
frameOpBuffer.Enqueue(codeStream);
frameOpBuffer.Enqueue(ShaderSourcePtr);
frameOpBuffer.ParamEnqueue(shaderHandle);
frameOpBuffer.ParamEnqueue(codeStream);
frameOpBuffer.MethodEnqueue(ShaderSourcePtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -313,40 +313,38 @@ namespace StgSharp.Graphics
void IglFunc.SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
{
frameOpBuffer.Enqueue((uint)bufferType, (uint)usage);
frameOpBuffer.Enqueue((IntPtr)sizeof(T));
frameOpBuffer.Enqueue<T>(new T[] { bufferData });
frameOpBuffer.Enqueue(BufferDataPtr);
frameOpBuffer.ParamEnqueue((uint)bufferType, (uint)usage);
frameOpBuffer.ParamEnqueue((IntPtr)sizeof(T));
frameOpBuffer.ParamEnqueue<T>(new T[] { bufferData });
frameOpBuffer.MethodEnqueue(BufferDataPtr);
}
void IglFunc.SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
{
frameOpBuffer.Enqueue((uint)bufferType, (uint)usage);
frameOpBuffer.Enqueue((IntPtr)(Marshal.SizeOf<T>() * bufferArray.Length));
frameOpBuffer.Enqueue<T>(bufferArray);
frameOpBuffer.Enqueue(BufferDataPtr);
frameOpBuffer.ParamEnqueue((uint)bufferType, (uint)usage);
frameOpBuffer.ParamEnqueue((IntPtr)(Marshal.SizeOf<T>() * bufferArray.Length));
frameOpBuffer.ParamEnqueue<T>(bufferArray);
frameOpBuffer.MethodEnqueue(BufferDataPtr);
}
void IglFunc.SetVertexAttribute(uint index, int size, TypeCode t, bool normalized, uint stride, int pointer)
{
uint type = InternalIO.GLtype[t];
frameOpBuffer.Enqueue(index, type, stride);
frameOpBuffer.Enqueue(size, normalized ? 1 : 0, pointer);
frameOpBuffer.Enqueue(SetVertexArrayPtr);
frameOpBuffer.ParamEnqueue(index, type, stride);
frameOpBuffer.ParamEnqueue(size, normalized ? 1 : 0, pointer);
frameOpBuffer.MethodEnqueue(SetVertexArrayPtr);
}
//TODO:双线程,换运行环境
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)
{
frameOpBuffer.Enqueue(pixels);
frameOpBuffer.Enqueue((uint)level, internalformat, width, height);
frameOpBuffer.Enqueue((uint)target, format, type);
frameOpBuffer.Enqueue(textureImage2dPtr);
frameOpBuffer.ParamEnqueue(pixels);
frameOpBuffer.ParamEnqueue((uint)level, internalformat, width, height);
frameOpBuffer.ParamEnqueue((uint)target, format, type);
frameOpBuffer.MethodEnqueue(textureImage2dPtr);
}
void IglFunc.TextureParameter(int target, uint pname, int param)
@@ -355,21 +353,21 @@ namespace StgSharp.Graphics
m.Write<int>(0, target);
m.Write<uint>(2, pname);
m.Write<int>(3, param);
frameOpBuffer.Enqueue(m);
frameOpBuffer.Enqueue(TextureParameterPtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(TextureParameterPtr);
}
void IglFunc.UseProgram(glHandle program)
{
frameOpBuffer.Enqueue((IntPtr)program.valuePtr);
frameOpBuffer.Enqueue(UseProgramPtr);
frameOpBuffer.ParamEnqueue((IntPtr)program.valuePtr);
frameOpBuffer.MethodEnqueue(UseProgramPtr);
}
void IglFunc.Viewport(int x, int y, uint width, uint height)
{
Vec4d v = new Vec4d(x, y, (int)width, (int)height);
frameOpBuffer.Enqueue(v);
frameOpBuffer.Enqueue(ViewPortPtr);
frameOpBuffer.ParamEnqueue(v);
frameOpBuffer.MethodEnqueue(ViewPortPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -377,27 +375,9 @@ namespace StgSharp.Graphics
{
foreach (M128 item in param)
{
frameOpBuffer.Enqueue(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(item);
}
frameOpBuffer.ParamEnqueue(methodHandle);
}
}
}
@@ -16,253 +16,253 @@ namespace StgSharp.Graphics
{
internal unsafe partial class GLonUpdate : IglFunc
{
private IntPtr ActiveTexturePtr = (IntPtr)(delegate*<void>)&InternalActiveTexture;
private IntPtr AttachShaderPtr = (IntPtr)(delegate*<void>)&InternalAttachShader;
private IntPtr BindBufferPtr = (IntPtr)(delegate*<void>)&InternalBindBuffer;
private IntPtr BindTexturePtr = (IntPtr)(delegate*<void>)&InternalBindTexture;
private IntPtr BindVertexArrayPtr = (IntPtr)(delegate*<void>)&InternalBindVertexArray;
private IntPtr BufferDataPtr = (IntPtr)(delegate*<void>)&InternalSetBufferData;
private IntPtr CanUpdatePtr = (IntPtr)(delegate*<void>)&InternalFrameCanUpdate;
private IntPtr ClearColorPtr = (IntPtr)(delegate*<void>)&InternalClearColor;
private IntPtr ClearGraphicErrorPtr = (IntPtr)(delegate*<void>)&InternalClearGraphicError;
private IntPtr ClearPtr = (IntPtr)(delegate*<void>)&InternalClear;
private IntPtr CompileShaderPtr = (IntPtr)(delegate*<void>)&InternalCompileShader;
private IntPtr CreateProgramPtr = (IntPtr)(delegate*<void>)&InternalCreateProgram;
private IntPtr CreateProgramSetPtr = (IntPtr)(delegate*<void>)&InternalCreateProgramSet;
private IntPtr CreateShaderPtr = (IntPtr)(delegate*<void>)&InternalCreateShader;
private IntPtr DeleBufferPtr = (IntPtr)(delegate*<void>)&InternalDeleteBuffer;
private IntPtr DeleteVertexArrayPtr = (IntPtr)(delegate*<void>)&InternalDeleteVertexArrays;
private IntPtr DrawElementsPtr = (IntPtr)(delegate*<void>)&InternalDrawElements;
private IntPtr GenBufferPtr = (IntPtr)(delegate*<void>)&InternalGenBuffers;
private IntPtr GenTexturesPtr = (IntPtr)(delegate*<void>)&InternalGenTextures;
private IntPtr GenVertexArraysPtr = (IntPtr)(delegate*<void>)&InternalGenVertexArrays;
private IntPtr GetUniformLocationPtr = (IntPtr)(delegate*<void>)&InternalGetUniformLocation;
private IntPtr SetVertexArrayPtr = (IntPtr)(delegate*<void>)&InternalSetVertexAttribute;
private IntPtr ShaderSourcePtr = (IntPtr)(delegate*<void>)&InternalShaderSource;
private IntPtr textureImage2dPtr = (IntPtr)(delegate*<void>)&InternalTextureImage2d;
private IntPtr TextureParameterPtr = (IntPtr)(delegate*<void>)&InternalTextureParameter;
private IntPtr UseProgramPtr = (IntPtr)(delegate*<void>)&InternalUseProgram;
private IntPtr ViewPortPtr = (IntPtr)(delegate*<void>)&InternalViewport;
private IntPtr ActiveTexturePtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalActiveTexture;
private IntPtr AttachShaderPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalAttachShader;
private IntPtr BindBufferPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalBindBuffer;
private IntPtr BindTexturePtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalBindTexture;
private IntPtr BindVertexArrayPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalBindVertexArray;
private IntPtr BufferDataPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalSetBufferData;
private IntPtr CanUpdatePtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalFrameCanUpdate;
private IntPtr ClearColorPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalClearColor;
private IntPtr ClearGraphicErrorPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalClearGraphicError;
private IntPtr ClearPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalClear;
private IntPtr CompileShaderPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalCompileShader;
private IntPtr CreateProgramPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalCreateProgram;
private IntPtr CreateProgramSetPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalCreateProgramSet;
private IntPtr CreateShaderPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalCreateShader;
private IntPtr DeleBufferPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalDeleteBuffer;
private IntPtr DeleteVertexArrayPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalDeleteVertexArrays;
private IntPtr DrawElementsPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalDrawElements;
private IntPtr GenBufferPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalGenBuffers;
private IntPtr GenTexturesPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalGenTextures;
private IntPtr GenVertexArraysPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalGenVertexArrays;
private IntPtr GetUniformLocationPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalGetUniformLocation;
private IntPtr SetVertexArrayPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalSetVertexAttribute;
private IntPtr ShaderSourcePtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalShaderSource;
private IntPtr textureImage2dPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalTextureImage2d;
private IntPtr TextureParameterPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalTextureParameter;
private IntPtr UseProgramPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalUseProgram;
private IntPtr ViewPortPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalViewport;
private static void InternalActiveTexture()
private static void InternalActiveTexture(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
uint t;
paramQueue.TryDequeue(out t);
paramQueue.context->glActiveTexture(t);
frameBuffer.TryDequeue(out t);
activatedContext->glActiveTexture(t);
}
private static void InternalAttachShader()
private static void InternalAttachShader(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
uint p, s;
paramQueue.TryDequeue(out p, out s);
paramQueue.context->glAttachShader(p, s);
frameBuffer.TryDequeue(out p, out s);
activatedContext->glAttachShader(p, s);
}
private static void InternalBindBuffer()
private static void InternalBindBuffer(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
M128 m = new M128();
paramQueue.TryDequeue(out m);
frameBuffer.TryDequeue(out m);
uint usage = m.Read<uint>(0);
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;
paramQueue.TryDequeue(out m);
paramQueue.context->glBindTexture(
frameBuffer.TryDequeue(out m);
activatedContext->glBindTexture(
m.Read<uint>(0),
*(uint*)m.Read<ulong>(1)
);
}
private static void InternalBindVertexArray()
private static void InternalBindVertexArray(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
IntPtr i;
paramQueue.TryDequeue(out i);
paramQueue.context->glBindVertexArray(*(uint*)i);
frameBuffer.TryDequeue(out i);
activatedContext->glBindVertexArray(*(uint*)i);
}
private static void InternalClear()
private static void InternalClear(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
uint mt;
paramQueue.TryDequeue(out mt);
paramQueue.context->glClear(mt);
frameBuffer.TryDequeue(out mt);
activatedContext->glClear(mt);
}
private static void InternalClearColor()
private static void InternalClearColor(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
float r, g, b, a;
paramQueue.TryDequeue(out r, out g, out b, out a);
paramQueue.context->glClearColor(r, g, b, a);
frameBuffer.TryDequeue(out r, out g, out b, out 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;
paramQueue.TryDequeue(out handle);
paramQueue.context->glCompileShader(*(uint*)handle);
frameBuffer.TryDequeue(out handle);
activatedContext->glCompileShader(*(uint*)handle);
}
private static void InternalCreateProgram()
private static void InternalCreateProgram(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
IntPtr programHandle = default;
paramQueue.TryDequeue(out programHandle);
*(uint*)programHandle = paramQueue.context->glCreateProgram();
frameBuffer.TryDequeue(out programHandle);
*(uint*)programHandle = activatedContext->glCreateProgram();
}
private static void InternalCreateProgramSet()
private static void InternalCreateProgramSet(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
uint* programHandle;
M128 m = default;
paramQueue.TryDequeue(out m);
frameBuffer.TryDequeue(out m);
programHandle = (uint*)m.Read<ulong>(0);
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;
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);
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;
paramQueue.TryDequeue(out m);
paramQueue.context->glDeleteBuffers(m.Read<uint>(2), (uint*)m.Read<ulong>(0));
frameBuffer.TryDequeue(out m);
activatedContext->glDeleteBuffers(m.Read<uint>(2), (uint*)m.Read<ulong>(0));
for (int i = 0; i < m.Read<uint>(2); i++)
{
*((uint*)m.Read<ulong>(0) + i) = 0;
}
}
private static void InternalDeleteVertexArrays()
private static void InternalDeleteVertexArrays(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
M128 m = default;
paramQueue.TryDequeue(out m);
paramQueue.context->glDeleteVertexArrays((uint)m.Read<int>(0), (uint*)m.Read<ulong>(0));
frameBuffer.TryDequeue(out m);
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;
IntPtr ptr;
paramQueue.TryDequeue(out mode, out count, out type);
paramQueue.TryDequeue(out ptr);
paramQueue.context->glDrawElements(mode, count, type, (void*)ptr);
frameBuffer.TryDequeue(out mode, out count, out type);
frameBuffer.TryDequeue(out ptr);
activatedContext->glDrawElements(mode, count, type, (void*)ptr);
}
private static void InternalFrameCanUpdate()
private static void InternalFrameCanUpdate(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
IntPtr ptr;
paramQueue.TryDequeue(out ptr);
frameBuffer.TryDequeue(out ptr);
Interlocked.Add(ref *(int*)ptr, -1);
}
private static void InternalGenBuffers()
private static void InternalGenBuffers(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
M128 m = default;
paramQueue.TryDequeue(out m);
paramQueue.context->glGenBuffers(m.Read<uint>(2), (uint*)m.Read<ulong>(0));
frameBuffer.TryDequeue(out m);
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;
paramQueue.TryDequeue(out m);
paramQueue.context->glGenTextures(m.Read<uint>(2), (uint*)m.Read<ulong>(0));
frameBuffer.TryDequeue(out m);
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;
paramQueue.TryDequeue(out m);
paramQueue.context->glGenVertexArrays(m.Read<uint>(2), (uint*)m.Read<ulong>(0));
frameBuffer.TryDequeue(out m);
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;
paramQueue.TryDequeue(out programHandle, out nameHandle);
paramQueue.TryDequeue(out targetHandle);
*(int*)targetHandle = paramQueue.context->glGetUniformLocation(*(uint*)programHandle, (byte*)nameHandle);
frameBuffer.TryDequeue(out programHandle, out nameHandle);
frameBuffer.TryDequeue(out targetHandle);
*(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;
IntPtr size = default;
glArrayHandle array = default;
paramQueue.TryDequeue(out type, out use);
paramQueue.TryDequeue(out size);
paramQueue.TryDequeue(out array);
paramQueue.context->glBufferData(type, size, array.AddressOfArray(), use);
frameBuffer.TryDequeue(out type, out use);
frameBuffer.TryDequeue(out size);
frameBuffer.TryDequeue(out array);
activatedContext->glBufferData(type, size, array.AddressOfArray(), use);
}
private static void InternalSetVertexAttribute()
private static void InternalSetVertexAttribute(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
uint index, type, stride;
int size, normalized, pointer;
paramQueue.TryDequeue(out index, out type, out stride);
paramQueue.TryDequeue(out size, out normalized, out pointer);
paramQueue.context->glVertexAttribPointer(index, size, type, normalized, stride, (void*)pointer);
paramQueue.context->glEnableVertexAttribArray(index);
frameBuffer.TryDequeue(out index, out type, out stride);
frameBuffer.TryDequeue(out size, out normalized, out pointer);
activatedContext->glVertexAttribPointer(index, size, type, normalized, stride, (void*)pointer);
activatedContext->glEnableVertexAttribArray(index);
}
private static unsafe void InternalShaderSource()
private static unsafe void InternalShaderSource(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
IntPtr handle = default;
glArrayHandle stream = default;
paramQueue.TryDequeue(out handle);
paramQueue.TryDequeue(out stream);
frameBuffer.TryDequeue(out handle);
frameBuffer.TryDequeue(out stream);
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;
uint target, level, internalFormat, width, height, format, type;
paramQueue.TryDequeue(out pix);
paramQueue.TryDequeue(out level, out internalFormat, out width, out height);
paramQueue.TryDequeue(out target, out format, out type);
paramQueue.context->glTexImage2D(target, (int)level, internalFormat, width, height, 0, format, type, (void*)pix);
frameBuffer.TryDequeue(out pix);
frameBuffer.TryDequeue(out level, out internalFormat, out width, out height);
frameBuffer.TryDequeue(out target, out format, out type);
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;
paramQueue.TryDequeue(out m);
paramQueue.context->glTextureParameteri(m.Read<uint>(0), m.Read<uint>(2), m.Read<int>(3));
frameBuffer.TryDequeue(out m);
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;
paramQueue.TryDequeue(out handle);
paramQueue.context->glUseProgram(*(uint*)handle);
frameBuffer.TryDequeue(out handle);
activatedContext->glUseProgram(*(uint*)handle);
}
private static void InternalViewport()
private static void InternalViewport(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
M128 m = default;
paramQueue.TryDequeue(out m);
paramQueue.context->glViewport(m.Read<int>(0), m.Read<int>(1), m.Read<uint>(2), m.Read<uint>(3));
frameBuffer.TryDequeue(out m);
activatedContext->glViewport(m.Read<int>(0), m.Read<int>(1), m.Read<uint>(2), m.Read<uint>(3));
}
private void InternalMakeContexCurrent(Form form)
@@ -20,7 +20,6 @@ namespace StgSharp.Graphics
return new ElementBuffer(count, this.gl);
}
/// <summary>
/// Create a set of <see cref="VertexArray"/>.
/// </summary>
@@ -53,6 +52,5 @@ namespace StgSharp.Graphics
{
return new VertexBuffer(count, gl);
}
}
}
}
@@ -36,20 +36,23 @@ namespace StgSharp.Graphics.GL.ShaderEdit
{
if (inputParams.Length != function.ParameterCount)
{
// Param list length not equal
throw new ArgumentException("Provided parameters does not match function's parameter list.");
}
if (!ShaderParameter.IsSameType(outPut, function.outPut))
{
// Type of returning value not qual
throw new Exception("Provided parameters does not match function's parameter list.");
}
for (int i = 0; i < inputParams.Length; 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.");
}
}
string codeLine = "";
string codeLine = ""; // adding a line like " outvalue = Func(input1, input2,...); "
if (outPut != ShaderParameter.Void)
{
codeLine += $"{outPut.name} = ";
@@ -135,18 +135,18 @@ namespace StgSharp.Graphics
internal unsafe partial class GLonUpdate
{
private IntPtr UniformVal1fPtr = (IntPtr)(delegate*<void>)&UniformVal1f;
private IntPtr UniformVal1fvPtr = (IntPtr)(delegate*<void>)&UniformVal1fv;
private IntPtr UniformVal1iPtr = (IntPtr)(delegate*<void>)&UniformVal1i;
private IntPtr UniformVal2fPtr = (IntPtr)(delegate*<void>)&UniformVal2f;
private IntPtr UniformVal3fPtr = (IntPtr)(delegate*<void>)&UniformVal3f;
private IntPtr UniformVal4fPtr = (IntPtr)(delegate*<void>)&UniformVal4f;
private IntPtr UniformVal1fPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal1f;
private IntPtr UniformVal1fvPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal1fv;
private IntPtr UniformVal1iPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal1i;
private IntPtr UniformVal2fPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal2f;
private IntPtr UniformVal3fPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal3f;
private IntPtr UniformVal4fPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal4f;
unsafe void IglFunc.SetValue(Uniform<float, float, float> uniform, float f0, float f1, float f2)
{
paramQueue.Enqueue((IntPtr)uniform.id.valuePtr);
paramQueue.Enqueue(f0, f1, f2);
glActionQueue.Enqueue(UniformVal3fPtr);
frameOpBuffer.ParamEnqueue((IntPtr)uniform.id.valuePtr);
frameOpBuffer.ParamEnqueue(f0, f1, f2);
frameOpBuffer.MethodEnqueue(UniformVal3fPtr);
}
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<float>(2, f0);
m.Write<float>(3, f1);
paramQueue.Enqueue(m);
glActionQueue.Enqueue(UniformVal2fPtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(UniformVal2fPtr);
}
unsafe void IglFunc.SetValue(Uniform<float, float, float, float> uniform, float f0, float f1, float f2, float f3)
{
paramQueue.Enqueue((IntPtr)uniform.id.valuePtr);
paramQueue.Enqueue(f0, f1, f2, f3);
glActionQueue.Enqueue(UniformVal4fPtr);
frameOpBuffer.ParamEnqueue((IntPtr)uniform.id.valuePtr);
frameOpBuffer.ParamEnqueue(f0, f1, f2, f3);
frameOpBuffer.MethodEnqueue(UniformVal4fPtr);
}
unsafe void IglFunc.SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
{
Vec4d m = vec;
paramQueue.Enqueue((IntPtr)uniform.id.valuePtr, (IntPtr)(Vec4d*)&m);
glActionQueue.Enqueue(UniformVal1fvPtr);
frameOpBuffer.ParamEnqueue((IntPtr)uniform.id.valuePtr);
frameOpBuffer.ParamEnqueue(vec);
frameOpBuffer.MethodEnqueue(UniformVal1fvPtr);
}
unsafe void IglFunc.SetValue(Uniform<float> uniform, float f0)
@@ -178,8 +178,8 @@ namespace StgSharp.Graphics
M128 m = default;
m.Write<ulong>(0, (ulong)uniform.id.valuePtr);
m.Write<float>(2, f0);
paramQueue.Enqueue(m);
glActionQueue.Enqueue(UniformVal1fPtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(UniformVal1fPtr);
}
unsafe void IglFunc.SetValue(Uniform<int> uniform, int i0)
@@ -187,61 +187,62 @@ namespace StgSharp.Graphics
M128 m = default;
m.Write<ulong>(0, (ulong)uniform.id.valuePtr);
m.Write<int>(2, i0);
paramQueue.Enqueue(m);
glActionQueue.Enqueue(UniformVal1fPtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(UniformVal1fPtr);
}
unsafe void IglFunc.SetValue(Uniform<Vec4d> uniform, Vec4d vec)
{
Vec4d m = vec;
paramQueue.Enqueue((IntPtr)uniform.id.valuePtr, (IntPtr)(Vec4d*)&m);
glActionQueue.Enqueue(UniformVal1fvPtr);
frameOpBuffer.ParamEnqueue((IntPtr)uniform.id.valuePtr, (IntPtr)(Vec4d*)&m);
frameOpBuffer.MethodEnqueue(UniformVal1fvPtr);
}
private static void UniformVal1f()
private static void UniformVal1f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default;
paramQueue.TryDequeue(out m);
paramQueue.context->glUniform1f(*(int*)m.Read<ulong>(0), m.Read<uint>(2));
frameOpBuffer.TryDequeue(out m);
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;
paramQueue.TryDequeue(out m);
paramQueue.context->glUniform1fv(*(int*)m.Read<ulong>(0), 4, (Vec4d*)&m.vec);
frameOpBuffer.TryDequeue(out m);
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;
paramQueue.TryDequeue(out m);
paramQueue.context->glUniform1i(*(int*)m.Read<ulong>(0), m.Read<int>(2));
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform2f(*(int*)m.Read<ulong>(0), m.Read<float>(2), m.Read<float>(3));
}
private static void UniformVal2f()
{
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()
private static void UniformVal3f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
IntPtr handle = IntPtr.Zero;
M128 m = default;
paramQueue.TryDequeue(out handle);
paramQueue.TryDequeue(out m);
paramQueue.context->glUniform3f(*(int*)handle, m.Read<float>(0), m.Read<float>(1), m.Read<float>(2));
frameOpBuffer.TryDequeue(out handle);
frameOpBuffer.TryDequeue(out m);
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;
M128 m = default;
paramQueue.TryDequeue(out handle);
paramQueue.TryDequeue(out m);
paramQueue.context->glUniform4f(*(int*)handle, m.Read<float>(0), m.Read<float>(1), m.Read<float>(2), m.Read<float>(3));
frameOpBuffer.TryDequeue(out handle);
frameOpBuffer.TryDequeue(out m);
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>
public static unsafe void LoadGLapi(this Form form, GLfuncLoader loader)
{
GLcontext* context = form.contextID;
GLcontext* context = (GLcontext*)form.graphicContextID;
if (loader == null)
{
loader = InternalIO.glfwGetProcAddress;
}
#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
{
return;
@@ -75,25 +75,25 @@ namespace StgSharp.Graphics
{
#region load_core_gl
LoadGLcore10(form.contextID, loader);
LoadGLcore11(form.contextID, loader);
LoadGLcore12(form.contextID, loader);
LoadGLcore13(form.contextID, loader);
LoadGLcore14(form.contextID, loader);
LoadGLcore15(form.contextID, loader);
LoadGLcore20(form.contextID, loader);
LoadGLcore21(form.contextID, loader);
LoadGLcore30(form.contextID, loader);
LoadGLcore31(form.contextID, loader);
LoadGLcore32(form.contextID, loader);
LoadGLcore33(form.contextID, loader);
LoadGLcore40(form.contextID, loader);
LoadGLcore41(form.contextID, loader);
LoadGLcore42(form.contextID, loader);
LoadGLcore43(form.contextID, loader);
LoadGLcore44(form.contextID, loader);
LoadGLcore45(form.contextID, loader);
LoadGLcore46(form.contextID, loader);
LoadGLcore10((GLcontext*)form.graphicContextID, loader);
LoadGLcore11((GLcontext*)form.graphicContextID, loader);
LoadGLcore12((GLcontext*)form.graphicContextID, loader);
LoadGLcore13((GLcontext*)form.graphicContextID, loader);
LoadGLcore14((GLcontext*)form.graphicContextID, loader);
LoadGLcore15((GLcontext*)form.graphicContextID, loader);
LoadGLcore20((GLcontext*)form.graphicContextID, loader);
LoadGLcore21((GLcontext*)form.graphicContextID, loader);
LoadGLcore30((GLcontext*)form.graphicContextID, loader);
LoadGLcore31((GLcontext*)form.graphicContextID, loader);
LoadGLcore32((GLcontext*)form.graphicContextID, loader);
LoadGLcore33((GLcontext*)form.graphicContextID, loader);
LoadGLcore40((GLcontext*)form.graphicContextID, loader);
LoadGLcore41((GLcontext*)form.graphicContextID, loader);
LoadGLcore42((GLcontext*)form.graphicContextID, loader);
LoadGLcore43((GLcontext*)form.graphicContextID, loader);
LoadGLcore44((GLcontext*)form.graphicContextID, loader);
LoadGLcore45((GLcontext*)form.graphicContextID, loader);
LoadGLcore46((GLcontext*)form.graphicContextID, loader);
#endregion load_core_gl
}
-5
View File
@@ -301,10 +301,5 @@ namespace StgSharp.Graphics
}
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 Channel { get => info.channel; }
//TODO fix the bug
internal Image(ImageInfo information)
{
info = information;
+55 -3
View File
@@ -1,7 +1,51 @@
using System;
using System.Xml.Serialization;
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
{
internal readonly T _defualtValue;
@@ -38,24 +82,34 @@ namespace StgSharp
{
case TypeCode.Byte:
break;
case TypeCode.Int16:
break;
case TypeCode.Int32:
break;
case TypeCode.Int64:
break;
case TypeCode.Double:
break;
case TypeCode.Single:
break;
case TypeCode.SByte:
break;
case TypeCode.UInt16:
break;
case TypeCode.UInt32:
break;
case TypeCode.UInt64:
break;
default:
throw new ArgumentException("Input is not number value type");
break;
@@ -66,7 +120,6 @@ namespace StgSharp
_defualtSubValue = defualtSubValue;
}
public void Add(T value)
{
_value += value;
@@ -113,6 +166,5 @@ namespace StgSharp
{
return counter.Value;
}
}
}
}
+15 -7
View File
@@ -1,4 +1,5 @@
using StgSharp.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -10,14 +11,21 @@ namespace StgSharp.Logic
[System.Serializable]
internal class FrameTimeoutException : Exception
{
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()
{ }
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(
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>>();
}
}
+4 -3
View File
@@ -1,11 +1,12 @@
using System;
using System.Globalization;
using System.Runtime.CompilerServices;
namespace StgSharp.Math
{
public static unsafe partial class Scaler
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe float Abs(float x)
{
uint* a = (uint*)&x;
@@ -13,6 +14,7 @@ namespace StgSharp.Math
return *(float*)a;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe int Abs(int x)
{
uint* a = (uint*)&x;
@@ -34,6 +36,5 @@ namespace StgSharp.Math
return CultureInfo.CurrentCulture.TextInfo.ListSeparator;
}
}
}
}
@@ -795,58 +795,6 @@
The second <see cref="T:System.Boolean"/> value.
</summary>
</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">
<summary>
OpenGL numeric type.
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[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.AssemblyTitleAttribute("StgSharp")]
[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.
</summary>
</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">
<summary>
OpenGL numeric type.