daily update on 20231217 by nitload youmu
This commit is contained in:
@@ -24,31 +24,29 @@ namespace StgSharp.Graphics
|
||||
internal LinkedList<Control> allControl;
|
||||
internal Vector4 color;
|
||||
internal Thread formThread;
|
||||
internal IglFunc GL;
|
||||
internal int height;
|
||||
internal IntPtr monitor;
|
||||
internal string name;
|
||||
internal FormRenderBuffer RenderBuffer;
|
||||
internal Form sharedForm;
|
||||
internal FrameUpdateTimer timer = new FrameUpdateTimer();
|
||||
internal FormUpdateBuffer UpdateBuffer;
|
||||
internal int width;
|
||||
internal IntPtr windowID;
|
||||
|
||||
internal IglFunc GL;
|
||||
internal FormUpdateBuffer UpdateBuffer;
|
||||
internal FormRenderBuffer RenderBuffer;
|
||||
private bool alignAtRender;
|
||||
private bool alignAtUpdate;
|
||||
private bool isSingleThread;
|
||||
|
||||
internal FrameUpdateTimer timer = new FrameUpdateTimer();
|
||||
private Action OnRender;
|
||||
private Action OnUpdate;
|
||||
|
||||
#region thread sync
|
||||
internal readonly SemaphoreSlim ouetrPong = new SemaphoreSlim(0, 1);
|
||||
private SemaphoreSlim ping = new SemaphoreSlim(1, 1);
|
||||
private SemaphoreSlim pong = new SemaphoreSlim(0, 1);
|
||||
internal readonly SemaphoreSlim ouetrPong = new SemaphoreSlim(0, 1);
|
||||
|
||||
/// <summary>
|
||||
/// Height of this form, represent in <see cref="int"/>
|
||||
/// </summary>
|
||||
public int Height
|
||||
{
|
||||
get => height;
|
||||
set => height = value;
|
||||
}
|
||||
#endregion
|
||||
|
||||
private Form()
|
||||
{
|
||||
@@ -59,6 +57,22 @@ namespace StgSharp.Graphics
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Height of this form, represent in <see cref="int"/>
|
||||
/// </summary>
|
||||
public int Height
|
||||
{
|
||||
get => height;
|
||||
set => height = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Representing
|
||||
/// </summary>
|
||||
public bool IsDoubleRendering
|
||||
{
|
||||
get { return isSingleThread; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Width of this form, represent in <see cref="int"/>
|
||||
/// </summary>
|
||||
@@ -94,9 +108,13 @@ namespace StgSharp.Graphics
|
||||
/// <param name="args"></param>
|
||||
public abstract void Init(object[] args);
|
||||
|
||||
public abstract void OnRenderFrame(object[] args);
|
||||
/// <summary>
|
||||
/// Behaviour of current form when in a render cycle.
|
||||
/// When this form
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
public abstract void Main(object[] args);
|
||||
|
||||
public abstract void OnUpdateFrame(object[] args);
|
||||
|
||||
/// <summary>
|
||||
/// Init this form and render it on screen, and respond with operation
|
||||
@@ -145,17 +163,15 @@ namespace StgSharp.Graphics
|
||||
Init((object[])args);
|
||||
}
|
||||
|
||||
|
||||
internal void InternalRenderFrame(object args)
|
||||
internal void InternalRenderFrame()
|
||||
{
|
||||
while (InternalIO.glfw.WindowShouldClose(windowID) != 0)
|
||||
{
|
||||
ping.Wait();
|
||||
try
|
||||
{
|
||||
OnRenderFrame((object[])args);
|
||||
OnRender();
|
||||
timer.WaitNextFrame();
|
||||
|
||||
pong.Release();
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
@@ -166,16 +182,15 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
internal void InternalUpdateFrame(object args)
|
||||
internal void InternalUpdateFrame()
|
||||
{
|
||||
while (InternalIO.glfw.WindowShouldClose(windowID) != 0)
|
||||
{
|
||||
pong.Wait();
|
||||
try
|
||||
{
|
||||
OnUpdateFrame((object[])args);
|
||||
OnUpdate();
|
||||
timer.WaitNextFrame();
|
||||
throw new Exception("Forget to reload GL apis");
|
||||
ping.Release();
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
@@ -186,6 +201,26 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Define how current form render in one frame.
|
||||
/// </summary>
|
||||
/// <param name="totalThread">
|
||||
///
|
||||
/// Please define
|
||||
/// </param>
|
||||
protected void SetRenderThreads(bool requireDoubleRendering)
|
||||
{
|
||||
switch (requireDoubleRendering)
|
||||
{
|
||||
case true:
|
||||
isSingleThread = false;
|
||||
OnUpdate = new Action(() => { });
|
||||
break;
|
||||
case false:
|
||||
isSingleThread = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
@@ -232,13 +267,14 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
windowID = windowPtr;
|
||||
}
|
||||
GLonRender glRender = new GLonRender();
|
||||
GLcontext glContext = new GLcontext();
|
||||
IntPtr ptr = Marshal.AllocHGlobal(sizeof(GLcontextIO));
|
||||
contextID = (GLcontextIO*)ptr;
|
||||
*contextID = new GLcontextIO();
|
||||
InternalIO.InternalWriteLog("Successfully create a context binded to current form. " +
|
||||
$"Its ID is {(ulong)ptr}", LogType.Info);
|
||||
GLonRender glRender = new GLonRender(glContext);
|
||||
GLonUpdate glUpdate = new GLonUpdate(glContext);
|
||||
}
|
||||
InternalIO.InternalSetCurrentGLContext(windowID, (IntPtr)contextID);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace StgSharp.Graphics
|
||||
internal VertexArray(int n)
|
||||
{
|
||||
_bufferID = new uint[n];
|
||||
GL = glFunc;
|
||||
//GL = glFunc;
|
||||
fixed (uint* id = _bufferID)
|
||||
{
|
||||
GL.GenVertexArrays(n, id);
|
||||
|
||||
@@ -17,11 +17,6 @@ namespace StgSharp.Graphics
|
||||
internal GLcontext glContext
|
||||
{
|
||||
get { return RenderBuffer.GL.api; }
|
||||
set
|
||||
{
|
||||
UpdateBuffer.GL.api = value;
|
||||
RenderBuffer.GL.api = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using StgSharp.Math;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
@@ -10,6 +11,8 @@ namespace StgSharp.Graphics
|
||||
|
||||
internal unsafe partial class GLonRender : IglFunc
|
||||
{
|
||||
FrameTimeoutException refreshSIgnal = new FrameTimeoutException();
|
||||
|
||||
internal GLonRender(GLcontext context)
|
||||
{
|
||||
api = context;
|
||||
@@ -34,12 +37,9 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
form.timer.WaitNextFrame();
|
||||
form.timer.alignSign.byte0++;
|
||||
if (form.timer.)
|
||||
{
|
||||
|
||||
}
|
||||
form.timer.WaitNextFrame();
|
||||
throw refreshSIgnal;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
@@ -10,6 +10,9 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
internal class GLonTimeout : IglFunc
|
||||
{
|
||||
FrameTimeoutException refreshSIgnal = new FrameTimeoutException();
|
||||
FrameTimeoutException signal = new FrameTimeoutException("This frame is timeout");
|
||||
|
||||
private static readonly GLonTimeout singleInstance
|
||||
= new GLonTimeout();
|
||||
|
||||
@@ -22,202 +25,202 @@ namespace StgSharp.Graphics
|
||||
|
||||
void IglFunc.ActiveTexture(uint type)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.AfterAlign(Form form, Action action)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.AlignFrame(Form form)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.AttachShader(uint program, uint shader)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.BindBuffer(BufferType bufferType, uint index)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.BindTexture(uint type, uint texture)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.BindVertexArray(uint index)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.Clear(MaskBufferBit mask)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.ClearColor(float R, float G, float B, float A)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.ClearGraphicError()
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
uint IglFunc.CompileShader(string shaderCode, ShaderType shaderType)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
uint IglFunc.CreateProgram()
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
IntPtr IglFunc.CreateWindowHandle(int width, int height, string tittle, IntPtr monitor, Form share)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
uint IglFunc.CreatGraphicProgram()
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
unsafe void IglFunc.DeleteBuffers(int count, uint* ptr)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
unsafe void IglFunc.DeleteVertexArrays(int count, uint* ptr)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.DrawElements(GepmetryType mode, int count, Type type, IntPtr ptr)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
unsafe void IglFunc.GenBuffers(int count, uint* ptr)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
unsafe void IglFunc.GenTextures(int count, uint* ptr)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
unsafe void IglFunc.GenVertexArrays(int count, uint* ptr)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.GetGraphicError()
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
unsafe int IglFunc.GetUniformLocation(uint program, byte* ptr)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
bool IglFunc.GetWindowShouldClose(Form form)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.MakeContexCurrent(Form form)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.SetFrameBufferSizeCallback(IntPtr id, FrameBufferSizeHandler handler)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<float> uniform, float v0)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<int> uniform, int i0)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<Vec4d> uniform, Vec4d vec)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.SetVertexAttribute(uint index, int size, Type t, bool normalized, int stride, int pointer)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.SwapBuffers(Form form)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
unsafe void IglFunc.TextureImage2d(uint target, int level, uint internalformat, int width, int height, uint format, uint type, void* pixels)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.TextureParameter(uint target, uint pname, int param)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.UseProgram(uint program)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.Viewport(int x, int y, int width, int height)
|
||||
{
|
||||
throw new FrameTimeoutException();
|
||||
throw signal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using StgSharp.Math;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -11,8 +12,13 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
internal partial class GLonUpdate : IglFunc
|
||||
{
|
||||
internal GLcontext api;
|
||||
private FrameTimeoutException refreshSignal = new();
|
||||
internal readonly GLcontext api;
|
||||
|
||||
internal GLonUpdate(GLcontext context)
|
||||
{
|
||||
api = context;
|
||||
}
|
||||
|
||||
void IglFunc.ActiveTexture(uint type)
|
||||
{
|
||||
@@ -20,6 +26,22 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
|
||||
void IglFunc.AfterAlign(Form form, Action action)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.AlignFrame(Form form)
|
||||
{
|
||||
if (form.timer.alignSign.byte0 > 0)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
form.timer.alignSign.byte0++;
|
||||
form.timer.WaitNextFrame();
|
||||
throw refreshSignal;
|
||||
}
|
||||
|
||||
void IglFunc.AttachShader(uint program, uint shader)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
Reference in New Issue
Block a user