daily update on 20240104 by nitload youmu, double threading not work
This commit is contained in:
@@ -1,28 +1,55 @@
|
||||
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 partial class GLonUpdate : IglFunc
|
||||
{
|
||||
private FrameTimeoutException refreshSignal = new();
|
||||
internal readonly GLcontext api;
|
||||
using glMetaData = (
|
||||
int i0, int i1, int i2, int i3,
|
||||
double d0, double d1, double d2, double d3,
|
||||
IntPtr p0, IntPtr p1, IntPtr p2, IntPtr p3
|
||||
);
|
||||
|
||||
internal GLonUpdate(GLcontext context)
|
||||
internal unsafe partial class GLonUpdate : IglFunc
|
||||
{
|
||||
|
||||
internal GLcontext* api;
|
||||
private ConcurrentQueue<Action> glActionQueue;
|
||||
private FrameTimeoutException refreshSignal = new();
|
||||
private DynamicArrayList<glMetaData> threadBuffer = new DynamicArrayList<glMetaData>(16, default);
|
||||
|
||||
ConcurrentQueue<Action<int>> GLactionQueue
|
||||
{
|
||||
get
|
||||
{
|
||||
return glActionQueue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal GLonUpdate(GLcontext* context)
|
||||
{
|
||||
api = context;
|
||||
glActionQueue = new ConcurrentQueue<Action>();
|
||||
glActionQueue.Enqueue(() => { });
|
||||
}
|
||||
|
||||
void IglFunc.ActiveTexture(uint type)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
api->glActiveTexture(type);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,52 +69,125 @@ namespace StgSharp.Graphics
|
||||
throw refreshSignal;
|
||||
}
|
||||
|
||||
void IglFunc.AttachShader(uint program, uint shader)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.AttachShader(uint program, uint shader)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() => api->glAttachShader(program, shader)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.BindBuffer(BufferType bufferType, uint index)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() => api->glBindBuffer((uint)bufferType, index)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.BindTexture(uint type, uint texture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() => api->glBindTexture((uint)type, texture)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.BindVertexArray(uint index)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() => api->glBindVertexArray((uint)index)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.Clear(MaskBufferBit mask)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() => api->glClear((uint)mask)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void IglFunc.ClearColor(float R, float G, float B, float A)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() => api->glClearColor(R, G, B, A)
|
||||
);
|
||||
}
|
||||
|
||||
void IglFunc.ClearGraphicError()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
while (api->glGetError() != 0) { };
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
uint IglFunc.CompileShader(string shaderCode, ShaderType shaderType)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
int id = -1;
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
uint shaderID;
|
||||
shaderCode += '\0';
|
||||
shaderID = InternalIO.InternalLoadShaderCode(shaderCode, (int)shaderType);
|
||||
if (shaderID == 0)
|
||||
{
|
||||
IntPtr logPtr = InternalIO.InternalReadLog();
|
||||
string log;
|
||||
try
|
||||
{
|
||||
byte[] logByte = new byte[512];
|
||||
Marshal.Copy(logPtr, logByte, 0, 512);
|
||||
log = Encoding.UTF8.GetString(logByte);
|
||||
log = log.Replace("\0", "");
|
||||
|
||||
bool isUseful = false;
|
||||
foreach (char item in log)
|
||||
{
|
||||
if (!char.IsControl(item))
|
||||
{
|
||||
isUseful = true; break;
|
||||
}
|
||||
}
|
||||
if (!isUseful)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
log = "Failed to compile shader.\nFailed to get GLSL compiler log";
|
||||
}
|
||||
|
||||
InternalIO.InternalWriteLog(log, LogType.Error);
|
||||
}
|
||||
Interlocked.Add(ref id, (int)(shaderID + 1));
|
||||
}
|
||||
);
|
||||
while (id < 0) { }
|
||||
return (uint)id;
|
||||
}
|
||||
|
||||
|
||||
uint IglFunc.CreateProgram()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
int id = -1;
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
int ret = (int)api->glCreateProgram();
|
||||
Interlocked.Add(ref id, ret + 1);
|
||||
}
|
||||
);
|
||||
while (id < 0) { }
|
||||
return (uint)id;
|
||||
}
|
||||
|
||||
IntPtr IglFunc.CreateWindowHandle(int width, int height, string tittle, IntPtr monitor, Form share)
|
||||
@@ -118,44 +218,118 @@ namespace StgSharp.Graphics
|
||||
|
||||
uint IglFunc.CreatGraphicProgram()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
int id = 0;
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
Interlocked.Add(ref id, (int)(api->glCreateProgram() + 1));
|
||||
}
|
||||
);
|
||||
while (id < 0) { }
|
||||
return (uint)id;
|
||||
}
|
||||
|
||||
|
||||
unsafe void IglFunc.DeleteBuffers(int count, uint* ptr)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.SetWindowShouldClose(Form form, bool mark)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
InternalIO.glfw.SetWindowShouldClose(form.windowID, mark ? 1 : 0);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.DeleteVertexArrays(int count, uint* ptr)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.DeleteBuffer(uint handle)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
uint target = handle;
|
||||
api->glDeleteBuffers(1, &target);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public void DrawElements(GepmetryType mode, int count, Type type, IntPtr ptr)
|
||||
unsafe void IglFunc.DeleteBuffers(uint count, uint[] handle)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
uint[] h = handle;
|
||||
fixed (uint* p = h)
|
||||
{
|
||||
api->glDeleteBuffers(count, p);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void IglFunc.DrawElements(GepmetryType mode, int count, Type type, IntPtr ptr)
|
||||
unsafe void IglFunc.DeleteVertexArrays(uint count, uint[] arrays)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
uint[] target = arrays;
|
||||
fixed (uint* ptr = target)
|
||||
{
|
||||
api->glDeleteVertexArrays(count, ptr);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.GenBuffers(int count, uint* ptr)
|
||||
void IglFunc.DrawElements(GepmetryType mode, uint count, Type type, IntPtr ptr)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
uint a;
|
||||
switch (Type.GetTypeCode(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 {nameof(type)} method DrawElements. " +
|
||||
$"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are suporrted.",
|
||||
LogType.Error);
|
||||
return;
|
||||
}
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{ api->glDrawElements((uint)mode, count, a, (void*)ptr); }
|
||||
);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.GenTextures(int count, uint* ptr)
|
||||
unsafe void IglFunc.GenBuffers(uint count, uint* ptr)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
api->glGenBuffers(count, ptr);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.GenVertexArrays(int count, uint* ptr)
|
||||
unsafe void IglFunc.GenTextures(uint count, uint* ptr)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
api->glGenTextures(count, ptr);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.GenVertexArrays(uint count, uint* ptr)
|
||||
{
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
api->glGenVertexArrays(count, ptr);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public void GetGraphicError()
|
||||
@@ -168,25 +342,26 @@ namespace StgSharp.Graphics
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public unsafe int GetUniformLocation(uint program, byte* ptr)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
unsafe int IglFunc.GetUniformLocation(uint program, byte* ptr)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
int ret = -1;
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
int location = api->glGetUniformLocation(program, ptr);
|
||||
Interlocked.Add(ref ret, location + 1);
|
||||
}
|
||||
);
|
||||
while (ret < 0) { }
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool GetWindowShouldClose(Form form)
|
||||
{
|
||||
return InternalIO.glfw.WindowShouldClose(form.windowID) == 0;
|
||||
}
|
||||
|
||||
bool IglFunc.GetWindowShouldClose(Form form)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return InternalIO.glfw.WindowShouldClose(form.windowID) == 0;
|
||||
}
|
||||
|
||||
public void GLswapBuffers(Form form)
|
||||
@@ -198,7 +373,8 @@ namespace StgSharp.Graphics
|
||||
InternalIO.glfw.SwapBuffers(form.windowID);
|
||||
}
|
||||
|
||||
public void MakeContexCurrent(Form form)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.MakeContexCurrent(Form form)
|
||||
{
|
||||
if (form.windowID == IntPtr.Zero)
|
||||
{
|
||||
@@ -207,29 +383,40 @@ namespace StgSharp.Graphics
|
||||
InternalIO.glfw.MakeContextCurrent(form.windowID);
|
||||
}
|
||||
|
||||
void IglFunc.MakeContexCurrent(Form form)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage) where T : IMat
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage) where T : struct, IConvertible
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
T data = bufferData;
|
||||
int size = sizeof(T);
|
||||
api->glBufferData(
|
||||
(uint)bufferType,
|
||||
(UIntPtr)size,
|
||||
&data,
|
||||
(uint)usage);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void IglFunc.SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
|
||||
if (bufferArray == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
fixed (void* bufferPtr = bufferArray)
|
||||
api->glBufferData(
|
||||
(uint)bufferType,
|
||||
(UIntPtr)size,
|
||||
bufferPtr,
|
||||
(uint)usage);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -240,44 +427,70 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
|
||||
void IglFunc.SetVertexAttribute(uint index, int size, Type t, bool normalized, int stride, int pointer)
|
||||
void IglFunc.SetVertexAttribute(uint index, int size, Type t, bool normalized, uint stride, int pointer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
uint type = InternalIO.GLtype[t];
|
||||
api->glVertexAttribPointer(index, size, type, normalized, stride, (void*)pointer);
|
||||
api->glEnableVertexAttribArray(index);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void IglFunc.SwapBuffers(Form form)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
if (form.windowID == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
InternalIO.glfw.SwapBuffers(form.windowID);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public unsafe void TextureImage2d(uint target, int level, uint internalformat, int width, int height, uint format, uint type, void* pixels)
|
||||
unsafe void IglFunc.TextureImage2d(uint target, int level, uint internalformat, uint width, uint height, uint format, uint type, void* pixels)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
unsafe void IglFunc.TextureImage2d(uint target, int level, uint internalformat, int width, int height, uint format, uint type, void* pixels)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void TextureParameter(uint target, uint pname, int param)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
api->glTexImage2D(target, level, internalformat, width, height, 0, format, type, pixels);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void IglFunc.TextureParameter(uint target, uint pname, int param)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
api->glTextureParameteri(target, pname, param);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void IglFunc.UseProgram(uint rogram)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
api->glUseProgram(rogram);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void IglFunc.Viewport(int x, int y, int width, int height)
|
||||
void IglFunc.Viewport(int x, int y, uint width, uint height)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
api->glViewport(x, y, width, height);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user