daily update on 20240328 by nitload youmu, building thread blueprint

This commit is contained in:
YoumuLiu
2024-03-29 11:05:57 +08:00
parent ea2a4a7dcb
commit b207f16616
68 changed files with 1083 additions and 2181 deletions
@@ -53,12 +53,6 @@ namespace StgSharp.Graphics
private short fpsCount;
#region form thread setting
private List<FrameAsyncThread> frameAsyncTaskList;
#endregion form thread setting
private IntPtr windowID;
internal LinkedList<Control> allControl;
@@ -75,8 +69,16 @@ namespace StgSharp.Graphics
protected Form()
{
frameAsyncTaskList = new List<FrameAsyncThread>();
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
_frameSpeed = 0;
_frameCount = 0;
fpsCountProvider.SpanRefreshCallback = new TimeSpanRefeshCallback(
() =>
{
Interlocked.Exchange(ref _frameSpeed, _frameCount);
Interlocked.Exchange(ref _frameCount, 0);
});
frameAsyncThreadList = new List<FrameAsyncThread>();
}
@@ -100,7 +102,10 @@ namespace StgSharp.Graphics
public bool ShouldClose
{
get => InternalIO.glfwWindowShouldClose(windowID) != 0;
get
{
return InternalIO.glfwWindowShouldClose(windowID) != 0;
}
set => InternalIO.glfwSetWindowShouldClose(windowID, value ? 1 : 0);
}
@@ -126,6 +131,7 @@ namespace StgSharp.Graphics
set => width = value;
}
public unsafe IntPtr WindowID => windowID;
internal unsafe IntPtr id => windowID;
@@ -185,7 +191,7 @@ namespace StgSharp.Graphics
GLcontext* contextID = (GLcontext*)graphicContextID;
*contextID = new GLcontext();
contextID->glGetString = (delegate*<uint, IntPtr>)IntPtr.Zero;
gl = new GLonRender(contextID);
gl = new GLpack(contextID);
}
InternalIO.glfwMakeContextCurrent(windowID);
}
@@ -264,57 +270,11 @@ namespace StgSharp.Graphics
public void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
{ InternalIO.glfwSetWindowSizeLimits(this.windowID, minWidth, minHeight, maxWidth, maxHeight); }
#region form main
/// <summary>
/// Init this form and render it on screen, and respond with operation
/// </summary>
public unsafe void Show()
{
if (gl == null)
{
InternalIO.InternalWriteLog($"Attempt to show form {name} before init", LogType.Error);
}
else
{
frameTimeProvider = new TimeSpanProvider(1 / 60.0, TimeSpanProvider.DefaultProvider);
MethodInfo[] methods = this.GetType().GetMethods(
BindingFlags.Public |
BindingFlags.Instance |
BindingFlags.DeclaredOnly);
if (methods.Length != 0)
foreach (MethodInfo m in methods)
{
if (m.GetCustomAttribute<RenderActivityAttribute>(false) != null)
{
if (!m.IsStatic && m.GetParameters().Length == 0 && m.ReturnType == typeof(void) )
{
if (m.Name != "Main")
{
FrameAsyncThread t = new();
}
}
else
{
throw new NotSupportedException("A render activity cannot have parameters, returning value or be static.");
}
}
}
while (!ShouldClose)
{
Main();
SwapBuffers();
PollEvents();
frameTimeProvider.WaitNextSpan();
}
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void InternalDeinit(params object[] args) { Deinit(args); }
internal void InternalDeinit() { Deinit(); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -345,14 +305,8 @@ namespace StgSharp.Graphics
unsafe ~Form() { Marshal.FreeHGlobal(graphicContextID); }
#endregion form main
}
/// <summary>
/// Mark that a method in a <see cref="Form"/>
/// should be called when rendering.
/// </summary>
public class RenderActivityAttribute : Attribute
{
}
}
@@ -0,0 +1,102 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="FormThreadAttribute.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Graphics
{
/// <summary>
/// Mark that a method in a <see cref="Form"/>
/// should be called when rendering.
/// </summary>
public class RenderActivityAttribute : Attribute
{
internal bool _isRenderProgress;
internal int _priority;
public RenderActivityAttribute(RenderPriority priority, bool IsRenderProgress)
{
_priority = (int)priority; _isRenderProgress = IsRenderProgress;
}
public RenderActivityAttribute(int priority, bool IsRenderProgress)
{
_priority = priority; _isRenderProgress = IsRenderProgress;
}
public int Priority { get => _priority; set => _priority = value; }
}
/// <summary>
/// Priority level of a render activity.
/// </summary>
public enum RenderPriority: int
{
/// <summary>
/// One level higher than <see cref="RenderPriority.Default"/>.
/// </summary>
Pre_1 = -1,
/// <summary>
/// Two level higher than <see cref="RenderPriority.Default"/>.
/// </summary>
Pre_2 = -2,
/// <summary>
/// Three level higher than <see cref="RenderPriority.Default"/>.
/// </summary>
Pre_3 = -3,
/// <summary>
/// One level lower than <see cref="RenderPriority.Default"/>.
/// </summary>
Aft_1 = 1,
/// <summary>
/// Two level lower than <see cref="RenderPriority.Default"/>.
/// </summary>
Aft_2 = 2,
/// <summary>
/// Three level lower than <see cref="RenderPriority.Default"/>.
/// </summary>
Aft_3 = 3,
/// <summary>
/// Highest priority, in <see cref="RenderPriority"/>, it is <see cref="Pre_3"/>.
/// </summary>
Highest = Pre_3,
/// <summary>
/// Default priority, usually <see cref="Form.Main"/> is in this priority.
/// </summary>
Default = 0,
/// <summary>
/// Lowest priority, in <see cref="RenderPriority"/>, it is <see cref="Aft_3"/>.
/// </summary>
Least = Aft_3,
}
}
@@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public abstract partial class Form
{
#region form thread setting
private List<FrameAsyncThread> frameAsyncThreadList;
#endregion form thread setting
/// <summary>
/// Init this form and render it on screen, and respond with operation
/// </summary>
public unsafe void Show()
{
if (gl == null)
{
InternalIO.InternalWriteLog($"Attempt to show form {name} before init", LogType.Error);
}
else
{
frameTimeProvider = new TimeSpanProvider(1 / 60.0, TimeSpanProvider.DefaultProvider);
MethodInfo[] methods = this.GetType().GetMethods(
BindingFlags.Public |
BindingFlags.Instance |
BindingFlags.DeclaredOnly);
if (methods.Length != 0)
{
foreach (MethodInfo m in methods) //find all methods decorated by RenderActivityAttribute
{
RenderActivityAttribute attr = m.GetCustomAttribute<RenderActivityAttribute>(false);
if (attr == null)
{
continue;
}
if (!m.IsStatic && (m.GetParameters().Length != 0) && (m.ReturnType != typeof(void)))
{
throw new NotSupportedException("A render activity cannot have parameters, returning value or be static.");
}
if (m.Name != "Main")
{
ThreadStart s = (ThreadStart)Delegate.CreateDelegate(typeof(ThreadStart), this, m);
FrameAsyncThread t = new(s,attr._priority);
frameAsyncThreadList.Add(t);
}
}
}
List<IGrouping<int,FrameAsyncThread>> threadGroup = frameAsyncThreadList.GroupBy<FrameAsyncThread, int>((t) => t.Priority).ToList();
int priority = 0;
foreach (var group in threadGroup)
{
foreach (var t in group)
{
t.Priority = priority;
}
priority++;
}
(Barrier, Barrier) b = FrameAsyncThread.CombineAsync(true, frameAsyncThreadList);
FrameAsyncThread.AsyncStartAll(frameAsyncThreadList);
if (b.Item1 == null)
{
while (!ShouldClose)
{
Main();
SwapBuffers();
PollEvents();
frameTimeProvider.WaitNextSpan();
Interlocked.Add(ref _frameCount, 1);
}
}
else
{
while (!ShouldClose)
{
b.Item1.SignalAndWait();
Main();
b.Item2.SignalAndWait();
SwapBuffers();
PollEvents();
frameTimeProvider.WaitNextSpan();
Interlocked.Add(ref _frameCount, 1);
}
FrameAsyncThread.TerminateAll(frameAsyncThreadList);
b.Item1.SignalAndWait();
FrameAsyncThread.WaitAll(frameAsyncThreadList);
}
//InternalDeinit();
}
}
}
}
@@ -498,98 +498,128 @@ namespace StgSharp.Graphics
{
private Thread _task;
private int _terminateToken;
private volatile int _terminateToken;
private int _priority;
protected Barrier _frameSpeedSyncBarrier;
protected Barrier _spanCompleteBarrier;
protected Action _taskTODO;
internal FrameOperationBuffer opBuffer;
protected ThreadStart _taskTODO;
internal FrameAsyncThread(Action action, IglFunc gl)
public FrameAsyncThread(ThreadStart action, int priority)
{
_taskTODO = action;
opBuffer = new FrameOperationBuffer(gl);
_terminateToken = 1;
_spanCompleteBarrier = new Barrier(2);
_priority = priority;
}
public Action TaskTODO
public int Priority
{
get => _priority;
internal set { _priority = value; }
}
public ThreadStart TaskTODO
{
get => _taskTODO;
set => _taskTODO = value;
}
public Barrier TodoCompleteBarrier
=> _spanCompleteBarrier;
public virtual void AsyncStart()
public void AsyncStart()
{
_task = new Thread(
() =>
{
while (_terminateToken != 0)
while (true)
{
_frameSpeedSyncBarrier.SignalAndWait();
if (_terminateToken == 0)
{
break;
}
_taskTODO();
_spanCompleteBarrier.SignalAndWait();
}
Console.WriteLine("Thread terminated");
});
_task.Start();
}
public static Barrier CombineAsync(bool needOuterMonitor, List<FrameAsyncThread> taskList)
public static void AsyncStartAll(IEnumerable<FrameAsyncThread> threadList)
{
if (taskList.Count == 0)
foreach (FrameAsyncThread t in threadList)
{
return null;
t.AsyncStart();
}
Barrier b = new Barrier(taskList.Count + (needOuterMonitor ? 1 : 0));
foreach (FrameAsyncThread item in taskList)
{
item._frameSpeedSyncBarrier = b;
}
return b;
}
public static Barrier CombineBeginningAsync(bool needOuterMonitor, params FrameAsyncThread[] taskList)
public static void WaitAll(IEnumerable<FrameAsyncThread> threadList)
{
foreach (FrameAsyncThread t in threadList)
{
t._task.Join();
}
}
public static (Barrier, Barrier) CombineAsync(bool needOuterMonitor, IEnumerable<FrameAsyncThread> taskList)
{
if (taskList.Count() == 0)
{
return (null, null);
}
Barrier b_start = new Barrier(taskList.Count() + (needOuterMonitor ? 1 : 0));
Barrier b_complete = new Barrier(taskList.Count() + (needOuterMonitor ? 1 : 0));
foreach (FrameAsyncThread item in taskList)
{
item._frameSpeedSyncBarrier = b_start;
item._spanCompleteBarrier = b_complete;
}
return (b_start, b_complete);
}
public static (Barrier, Barrier) CombineAsync(bool needOuterMonitor, params FrameAsyncThread[] taskList)
{
if (taskList.Length == 0)
{
return null;
return (null, null);
}
Barrier b = new Barrier(taskList.Length + (needOuterMonitor ? 1 : 0));
Barrier b_start = new Barrier(taskList.Length + (needOuterMonitor ? 1 : 0));
Barrier b_complete = new Barrier(taskList.Length + (needOuterMonitor ? 1 : 0));
foreach (FrameAsyncThread item in taskList)
{
item._frameSpeedSyncBarrier = b;
item._frameSpeedSyncBarrier = b_start;
item._spanCompleteBarrier = b_complete;
}
return b;
}
public static void ExchangeBuffer(FrameAsyncThread task0, FrameAsyncThread task1)
{
FrameOperationBuffer cache = task0.opBuffer;
task0.opBuffer = task1.opBuffer;
task1.opBuffer = cache;
return (b_start, b_complete);
}
public void Terminate()
{
Interlocked.Exchange(ref _terminateToken, 0);
Interlocked.Exchange(ref _terminateToken,0);
}
}
internal sealed class AsyncUpdateDataTask : FrameAsyncThread
{
public AsyncUpdateDataTask(Form f) : base(f.Main, f.GL)
public static void TerminateAll(params FrameAsyncThread[] threadList)
{
foreach (FrameAsyncThread t in threadList)
{
t.Terminate();
}
}
public static void TerminateAll(IEnumerable<FrameAsyncThread> threadList)
{
foreach (FrameAsyncThread t in threadList)
{
t.Terminate();
}
}
}
}
@@ -37,13 +37,13 @@ using System.Threading.Tasks;
namespace StgSharp.Graphics
{
/// <summary>
/// Interface of all kinds OpenGL buffer onjects
/// Interface of all kinds OpenGL buffer objects
/// </summary>
public abstract class BufferObjectBase : IDisposable
{
protected glHandleSet _bufferHandle;
protected Form binding;
protected IglFunc binding;
/// <summary>
/// Get the only handle to one of the Object instance
+6 -6
View File
@@ -48,27 +48,27 @@ namespace StgSharp.Graphics
internal ElementBuffer(int n, Form binding)
{
this.binding = binding;
_bufferHandle = binding.GL.GenBuffers(n);
this.binding = binding.GL;
_bufferHandle = this.binding.GenBuffers(n);
}
public override sealed void Bind(int index)
{
binding.GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferHandle[index]);
binding.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferHandle[index]);
}
public void SetValue<T>(int index, T[] bufferArray, BufferUsage usage)
where T : struct, IConvertible
{
binding.GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferHandle[index]);
binding.GL.SetBufferData(BufferType.ELEMENT_ARRAY_BUFFER, bufferArray, usage);
binding.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferHandle[index]);
binding.SetBufferData(BufferType.ELEMENT_ARRAY_BUFFER, bufferArray, usage);
}
protected override sealed void Dispose(bool disposing)
{
if (disposing)
{
binding.GL.DeleteBuffers(_bufferHandle);
binding.DeleteBuffers(_bufferHandle);
_bufferHandle.Release();
}
}
+6 -6
View File
@@ -40,26 +40,26 @@ namespace StgSharp.Graphics
internal VertexArray(int n, Form binding)
{
this.binding = binding;
_bufferHandle = binding.GL.GenVertexArrays(n);
this.binding = binding.GL;
_bufferHandle = this.binding.GenVertexArrays(n);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override sealed void Bind(int index)
{
binding.GL.BindVertexArray(_bufferHandle[index]);
binding.BindVertexArray(_bufferHandle[index]);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void BindNull()
{
binding.GL.BindVertexArray(glHandle.Zero);
binding.BindVertexArray(glHandle.Zero);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetVertexAttribute(uint index, int vertexLength, TypeCode dataType, bool isNomalized, uint stride, int pointer)
{
binding.GL.SetVertexAttribute(
binding.SetVertexAttribute(
index, vertexLength, dataType,
isNomalized,
stride, pointer);
@@ -69,7 +69,7 @@ namespace StgSharp.Graphics
{
if (disposing)
{
binding.GL.DeleteVertexArrays(_bufferHandle);
binding.DeleteVertexArrays(_bufferHandle);
_bufferHandle.Release();
}
}
+9 -11
View File
@@ -45,13 +45,13 @@ namespace StgSharp.Graphics
internal VertexBuffer(int n, Form binding)
{
this.binding = binding;
_bufferHandle = binding.GL.GenBuffers(n);
this.binding = binding.GL;
_bufferHandle = this.binding.GenBuffers(n);
}
public override sealed void Bind(int index)
{
binding.GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
binding.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
}
/// <summary>
@@ -63,8 +63,8 @@ namespace StgSharp.Graphics
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
public void SetValue<T>(int index, T bufferData, BufferUsage usage) where T : struct, IMat
{
binding.GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
binding.GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferData, usage);
binding.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
binding.SetBufferData(BufferType.ARRAY_BUFFER, bufferData, usage);
}
/// <summary>
@@ -76,8 +76,8 @@ namespace StgSharp.Graphics
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
public void SetValueArray<T>(int index, T[] bufferArray, BufferUsage usage) where T : struct, IConvertible
{
binding.GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
binding.GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferArray, usage);
binding.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
binding.SetBufferData(BufferType.ARRAY_BUFFER, bufferArray, usage);
}
/// <summary>
@@ -86,16 +86,14 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Unbind()
{
binding.GL.BindBuffer(BufferType.ARRAY_BUFFER, glHandle.Zero);
binding.BindBuffer(BufferType.ARRAY_BUFFER, glHandle.Zero);
}
protected override sealed void Dispose(bool disposing)
{
if (disposing)
{
binding.GL.DeleteBuffers(_bufferHandle);
binding.DeleteBuffers(_bufferHandle);
_bufferHandle.Release();
}
}
+1 -1
View File
@@ -278,7 +278,7 @@ namespace StgSharp.Graphics
}
/// <summary>
/// Realse all resource in this handle.
/// Release all resource in this handle.
/// This will release all resource in this <see cref="glHandle"/>.
/// This <see langword="glHandle"/> will be not usable.
/// </summary>
+2 -2
View File
@@ -40,13 +40,13 @@ using System.Text;
namespace StgSharp.Graphics
{
internal unsafe partial class GLonRender : IglFunc
internal unsafe partial class GLpack : IglFunc
{
private FrameTimeoutException refreshSIgnal = new FrameTimeoutException();
internal GLcontext* api;
internal GLonRender(GLcontext* context)
internal GLpack(GLcontext* context)
{
api = context;
}
@@ -1,407 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GLonUpdate.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Logic;
using StgSharp.Math;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
internal sealed unsafe partial class GLonUpdate : IglFunc
{
private GLcontext* api;
private FrameOperationBuffer frameOpBuffer;
internal GLonUpdate(GLcontext* context)
{
api = context;
}
public FrameOperationBuffer ActivatedOperationBuffer
{
get => frameOpBuffer;
set => frameOpBuffer = value;
}
public void GLswapBuffers(Form form)
{
if (form.WindowID == IntPtr.Zero)
{
return;
}
InternalIO.glfwSwapBuffers(form.id);
}
void IglFunc.ActiveTexture(uint type)
{
frameOpBuffer.ParamEnqueue(type);
frameOpBuffer.MethodEnqueue(ActiveTexturePtr);
}
void IglFunc.AfterAlign(Form form, Action action)
{
throw new NotImplementedException();
}
void IglFunc.AlignFrame(Form form)
{
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.AttachShader(glHandle program, glHandle shader)
{
frameOpBuffer.ParamEnqueue(program, shader);
frameOpBuffer.MethodEnqueue(AttachShaderPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.BindBuffer(BufferType bufferType, glHandle handle)
{
M128 m = default;
m.Write<uint>(0, (uint)bufferType);
m.Write<ulong>(1, (ulong)handle.valuePtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(BindBufferPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.BindTexture(uint type, glHandle texture)
{
M128 m = default;
m.Write<uint>(0, type);
m.Write<ulong>(1, (ulong)texture.valuePtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(BindTexturePtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.BindVertexArray(glHandle index)
{
frameOpBuffer.ParamEnqueue(index);
frameOpBuffer.MethodEnqueue(BindVertexArrayPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.Clear(MaskBufferBit mask)
{
frameOpBuffer.ParamEnqueue((uint)mask);
frameOpBuffer.MethodEnqueue(ClearPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.ClearColor(float R, float G, float B, float A)
{
frameOpBuffer.ParamEnqueue(R, G, B, A);
frameOpBuffer.MethodEnqueue(ClearColorPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.ClearGraphicError()
{
frameOpBuffer.MethodEnqueue(ClearGraphicErrorPtr);
}
unsafe void IglFunc.CompileShader(glHandle shaderhandle)
{
frameOpBuffer.ParamEnqueue((IntPtr)shaderhandle.valuePtr);
frameOpBuffer.MethodEnqueue(CompileShaderPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
glHandle IglFunc.CreateProgram()
{
glHandle h = glHandle.Alloc(1);
frameOpBuffer.ParamEnqueue(h);
frameOpBuffer.MethodEnqueue(CreateProgramPtr);
return h;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
glHandleSet IglFunc.CreateProgram(int count)
{
M128 m = default;
glHandleSet h = new glHandleSet(count);
m.Write<ulong>(0, (ulong)h.handle);
m.Write<int>(2, count);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(CreateProgramSetPtr);
return h;
}
glHandleSet IglFunc.CreateShaderSet(int count, ShaderType type)
{
glHandleSet ret = new glHandleSet(count);
M128 m = new M128();
m.Write<int>(0, count);
m.Write<uint>(1, (uint)type);
m.Write<ulong>(1, (ulong)ret.handle);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(CreateShaderPtr);
return ret;
}
IntPtr IglFunc.CreateWindowHandle(int width, int height, string tittle, IntPtr monitor, Form share)
{
byte[] tittleBytes = Encoding.UTF8.GetBytes(tittle);
IntPtr windowPtr;
if (share == null)
{
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, IntPtr.Zero);
}
else
{
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, share.id);
}
if (((long)windowPtr == -1) || ((long)windowPtr == -2))
{
throw new Exception("Cannot create window instance!");
}
else
{
return windowPtr;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
glHandle IglFunc.CreatGraphicProgram()
{
glHandle h = glHandle.Alloc(1);
frameOpBuffer.ParamEnqueue(h);
frameOpBuffer.MethodEnqueue(CreateProgramPtr);
return h;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.DeleteBuffer(glHandle handle)
{
M128 m = default;
m.Write<ulong>(0, (ulong)handle.valuePtr);
m.Write(2, 1);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(DeleBufferPtr);
}
unsafe void IglFunc.DeleteBuffers(glHandleSet handle)
{
M128 m = default;
m.Write<ulong>(0, (ulong)handle.handle);
m.Write<uint>(2, (uint)handle.length);
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.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(DeleteVertexArrayPtr);
}
void IglFunc.DrawElements(GepmetryType mode, uint count, TypeCode type, IntPtr ptr)
{
uint a;
switch (type)
{
case TypeCode.UInt32:
a = GLconst.UNSIGNED_INT;
break;
case TypeCode.UInt16:
a = GLconst.UNSIGNED_SHORT;
break;
case TypeCode.Byte:
a = GLconst.UNSIGNED_BYTE;
break;
default:
InternalIO.InternalWriteLog(
$"{$"Parameter error in parameter {type} method DrawElements. "}{$"Only {TypeCode.Byte}, {TypeCode.UInt16}, {TypeCode.UInt32} types are suporrted."}",
LogType.Error);
return;
}
frameOpBuffer.ParamEnqueue((uint)mode, count, a);
frameOpBuffer.ParamEnqueue(ptr);
frameOpBuffer.MethodEnqueue(DrawElementsPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.frameworkHandleEnqueue(IntPtr methodHandle, params M128[] param)
{
foreach (M128 item in param)
{
frameOpBuffer.ParamEnqueue(item);
}
frameOpBuffer.ParamEnqueue(methodHandle);
}
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.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(GenBufferPtr);
return h;
}
unsafe glHandleSet IglFunc.GenTextures(int count)
{
glHandleSet h = new glHandleSet(count);
M128 m = default; m.Write<uint>(2, (uint)count); m.Write<ulong>(0, (ulong)h.handle);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(GenTexturesPtr);
return h;
}
unsafe glHandleSet IglFunc.GenVertexArrays(int count)
{
glHandleSet h = new glHandleSet(count);
M128 m = default; m.Write<uint>(2, (uint)count); m.Write<ulong>(0, (ulong)h.handle);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(GenTexturesPtr);
return h;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe glSHandle IglFunc.GetUniformLocation(glHandle program, string ptr)
{
glSHandle h = glSHandle.Alloc(0);
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.ParamEnqueue(m);
frameOpBuffer.ParamEnqueue((IntPtr)h.valuePtr);
frameOpBuffer.MethodEnqueue(GetUniformLocationPtr);
return h;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
bool IglFunc.GetWindowShouldClose(Form form)
{
return InternalIO.glfwWindowShouldClose(form.id) == 0;
}
void IglFunc.LoadShaderSource(glHandle shaderHandle, string codeStream)
{
frameOpBuffer.ParamEnqueue(shaderHandle);
frameOpBuffer.ParamEnqueue(codeStream);
frameOpBuffer.MethodEnqueue(ShaderSourcePtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.MakeContexCurrent(Form form)
{
if (form.WindowID == IntPtr.Zero)
{
return;
}
InternalIO.glfwMakeContextCurrent(form.id);
}
void IglFunc.SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
{
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)
{
T[] copy = new T[bufferArray.Length];
lock (bufferArray)
{
bufferArray.CopyTo(copy, 0);
}
frameOpBuffer.ParamEnqueue((uint)bufferType, (uint)usage);
frameOpBuffer.ParamEnqueue((IntPtr)(Marshal.SizeOf<T>() * bufferArray.Length));
frameOpBuffer.ParamEnqueue<T>(copy);
frameOpBuffer.MethodEnqueue(BufferDataPtr);
}
void IglFunc.SetVertexAttribute(uint index, int size, TypeCode t, bool normalized, uint stride, int pointer)
{
uint type = InternalIO.GLtype[t];
frameOpBuffer.ParamEnqueue(index, type, stride);
frameOpBuffer.ParamEnqueue(size, normalized ? 1 : 0, pointer);
frameOpBuffer.MethodEnqueue(SetVertexArrayPtr);
}
unsafe void IglFunc.TextureImage2d<T>(int target, int level, uint internalFormat, uint width, uint height, uint format, uint type, glHandle pixels)
{
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)
{
M128 m = default;
m.Write<int>(0, target);
m.Write<uint>(2, pname);
m.Write<int>(3, param);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(TextureParameterPtr);
}
void IglFunc.UseProgram(glHandle program)
{
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.ParamEnqueue(v);
frameOpBuffer.MethodEnqueue(ViewPortPtr);
}
GLcontext* IglFunc.Context => api;
}
}
@@ -1,275 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GLonUpdateInternal.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Math;
using System;
using System.Linq;
namespace StgSharp.Graphics
{
internal unsafe partial class GLonUpdate : IglFunc
{
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 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 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(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
uint t;
frameBuffer.TryDequeue(out t);
activatedContext->glActiveTexture(t);
}
private static void InternalAttachShader(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
uint p, s;
frameBuffer.TryDequeue(out p, out s);
activatedContext->glAttachShader(p, s);
}
private static void InternalBindBuffer(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
M128 m = new M128();
frameBuffer.TryDequeue(out m);
uint usage = m.Read<uint>(0);
uint handle = *(uint*)m.Read<ulong>(1);
activatedContext->glBindBuffer(usage, handle);
}
private static void InternalBindTexture(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameBuffer.TryDequeue(out m);
activatedContext->glBindTexture(
m.Read<uint>(0),
*(uint*)m.Read<ulong>(1)
);
}
private static void InternalBindVertexArray(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
IntPtr i;
frameBuffer.TryDequeue(out i);
activatedContext->glBindVertexArray(*(uint*)i);
}
private static void InternalClear(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
uint mt;
frameBuffer.TryDequeue(out mt);
activatedContext->glClear(mt);
}
private static void InternalClearColor(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
float r, g, b, a;
frameBuffer.TryDequeue(out r, out g, out b, out a);
activatedContext->glClearColor(r, g, b, a);
}
private static void InternalClearGraphicError(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
while (activatedContext->glGetError() != 0) { }
}
private static unsafe void InternalCompileShader(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
IntPtr handle = default;
frameBuffer.TryDequeue(out handle);
activatedContext->glCompileShader(*(uint*)handle);
}
private static void InternalCreateProgram(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
IntPtr programHandle = default;
frameBuffer.TryDequeue(out programHandle);
*(uint*)programHandle = activatedContext->glCreateProgram();
}
private static void InternalCreateProgramSet(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
uint* programHandle;
M128 m = default;
frameBuffer.TryDequeue(out m);
programHandle = (uint*)m.Read<ulong>(0);
for (int i = 0; i < m.Read<int>(2); i++)
{
*(programHandle + i) = activatedContext->glCreateProgram();
}
}
private static unsafe void InternalCreateShader(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
M128 m = default;
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) = activatedContext->glCreateShader(type);
}
}
private static void InternalDeleteBuffer(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
M128 m = default;
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(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameBuffer.TryDequeue(out m);
activatedContext->glDeleteVertexArrays((uint)m.Read<int>(0), (uint*)m.Read<ulong>(0));
}
private static void InternalDrawElements(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
uint mode, count, type;
IntPtr ptr;
frameBuffer.TryDequeue(out mode, out count, out type);
frameBuffer.TryDequeue(out ptr);
activatedContext->glDrawElements(mode, count, type, (void*)ptr);
}
private static void InternalGenBuffers(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameBuffer.TryDequeue(out m);
activatedContext->glGenBuffers(m.Read<uint>(2), (uint*)m.Read<ulong>(0));
}
private static void InternalGenTextures(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameBuffer.TryDequeue(out m);
activatedContext->glGenTextures(m.Read<uint>(2), (uint*)m.Read<ulong>(0));
}
private static void InternalGetUniformLocation(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
IntPtr programHandle = default, nameHandle = default, targetHandle = default;
frameBuffer.TryDequeue(out programHandle, out nameHandle);
frameBuffer.TryDequeue(out targetHandle);
*(int*)targetHandle = activatedContext->glGetUniformLocation(*(uint*)programHandle, (byte*)nameHandle);
}
private static void InternalSetBufferData(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
uint type = 0, use = 0;
IntPtr size = default;
glArrayHandle array = default;
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(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
uint index, type, stride;
int size, normalized, pointer;
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(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
IntPtr handle = default;
glArrayHandle stream = default;
frameBuffer.TryDequeue(out handle);
frameBuffer.TryDequeue(out stream);
IntPtr buffer = stream.AddressOfArray();
activatedContext->glShaderSource(*(uint*)handle, 1, (byte**)&buffer, (void*)0);
}
private static void InternalTextureImage2d(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
IntPtr pix = IntPtr.Zero;
uint target, level, internalFormat, width, height, format, type;
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(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameBuffer.TryDequeue(out m);
activatedContext->glTextureParameteri(m.Read<uint>(0), m.Read<uint>(2), m.Read<int>(3));
}
private static void InternalUseProgram(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
IntPtr handle = IntPtr.Zero;
frameBuffer.TryDequeue(out handle);
activatedContext->glUseProgram(*(uint*)handle);
}
private static void InternalViewport(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameBuffer.TryDequeue(out m);
activatedContext->glViewport(m.Read<int>(0), m.Read<int>(1), m.Read<uint>(2), m.Read<uint>(3));
}
}
}
@@ -126,7 +126,7 @@ namespace StgSharp.Graphics
}
internal partial class GLonRender : IglFunc
internal partial class GLpack : IglFunc
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -173,118 +173,4 @@ namespace StgSharp.Graphics
}
internal unsafe partial class GLonUpdate
{
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;
private static void UniformVal1f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform1f(*(int*)m.Read<ulong>(0), m.Read<uint>(2));
}
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;
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform1i(*(int*)m.Read<ulong>(0), m.Read<int>(2));
}
private static void UniformVal2f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform2f(*(int*)m.Read<ulong>(0), m.Read<float>(2), m.Read<float>(3));
}
private static void UniformVal3f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
IntPtr handle = IntPtr.Zero;
M128 m = default;
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(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
IntPtr handle = IntPtr.Zero;
M128 m = default;
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));
}
unsafe void IglFunc.SetValue(Uniform<float, float, float> uniform, float f0, float f1, float f2)
{
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)
{
M128 m = default;
m.Write<ulong>(0, (ulong)uniform.id.valuePtr);
m.Write<float>(2, f0);
m.Write<float>(3, f1);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(UniformVal2fPtr);
}
unsafe void IglFunc.SetValue(Uniform<float, float, float, float> uniform, float f0, float f1, float f2, float f3)
{
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)
{
frameOpBuffer.ParamEnqueue((IntPtr)uniform.id.valuePtr);
frameOpBuffer.ParamEnqueue(vec);
frameOpBuffer.MethodEnqueue(UniformVal1fvPtr);
}
unsafe void IglFunc.SetValue(Uniform<float> uniform, float f0)
{
M128 m = default;
m.Write<ulong>(0, (ulong)uniform.id.valuePtr);
m.Write<float>(2, f0);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(UniformVal1fPtr);
}
unsafe void IglFunc.SetValue(Uniform<int> uniform, int i0)
{
M128 m = default;
m.Write<ulong>(0, (ulong)uniform.id.valuePtr);
m.Write<int>(2, i0);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(UniformVal1fPtr);
}
unsafe void IglFunc.SetValue(Uniform<Vec4d> uniform, Vec4d vec)
{
frameOpBuffer.ParamEnqueue((IntPtr)uniform.id.valuePtr);
frameOpBuffer.ParamEnqueue(vec);
frameOpBuffer.MethodEnqueue(UniformVal1fvPtr);
}
}
}