daily update on 20240206 by nitload youmu
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using StgSharp.Math;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
@@ -10,414 +11,290 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
internal unsafe struct GLonUpdateInternal : IglFunc
|
||||
internal unsafe partial class GLonUpdate : IglFunc
|
||||
{
|
||||
public IntPtr ActiveTexturePtr;
|
||||
public IntPtr AttachShaderPtr;
|
||||
public IntPtr BindBufferPtr;
|
||||
internal IntPtr ClearColorPtr;
|
||||
internal IntPtr ClearGraphicErrorPtr;
|
||||
internal IntPtr CompileShaderPtr;
|
||||
internal GLparamQueue paramQueue;
|
||||
private GLcontext* gl;
|
||||
public GLonUpdateInternal(GLcontext* api)
|
||||
{
|
||||
gl = api;
|
||||
}
|
||||
internal IntPtr ActiveTexturePtr = (IntPtr)(delegate*<void>)&InternalActiveTexture;
|
||||
internal IntPtr AttachShaderPtr = (IntPtr)(delegate*<void>)&InternalAttachShader;
|
||||
internal IntPtr BindBufferPtr = (IntPtr)(delegate*<void>)&InternalBindBuffer;
|
||||
internal IntPtr ClearColorPtr = (IntPtr)(delegate*<void>)&InternalClearColor;
|
||||
internal IntPtr ClearGraphicErrorPtr = (IntPtr)(delegate*<void>)&InternalClearGraphicError;
|
||||
internal IntPtr CompileShaderPtr = (IntPtr)(delegate*<void>)&InternalCompileShader;
|
||||
private IntPtr ClearPtr = (IntPtr)(delegate*<void>)&InternalClear;
|
||||
|
||||
public void ActivePointer()
|
||||
{
|
||||
IglFunc gl = this;
|
||||
ActiveTexturePtr = Marshal.GetFunctionPointerForDelegate(gl.ActiveTexture);
|
||||
AttachShaderPtr = Marshal.GetFunctionPointerForDelegate(gl.AttachShader);
|
||||
BindBufferPtr = Marshal.GetFunctionPointerForDelegate(gl.BindBuffer);
|
||||
CompileShaderPtr = Marshal.GetFunctionPointerForDelegate(gl.CompileShader);
|
||||
}
|
||||
|
||||
void IglFunc.ActiveTexture(uint type)
|
||||
private static void InternalActiveTexture()
|
||||
{
|
||||
uint t;
|
||||
paramQueue.TryDequeue(out t);
|
||||
gl->glActiveTexture(t);
|
||||
paramQueue.context->glActiveTexture(t);
|
||||
}
|
||||
|
||||
void IglFunc.AfterAlign(Form form, Action action)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.AlignFrame(Form form)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.AttachShader(glHandle program, glHandle shader)
|
||||
private static void InternalAttachShader()
|
||||
{
|
||||
uint p, s;
|
||||
paramQueue.TryDequeue(out p, out s);
|
||||
gl->glAttachShader(p, s);
|
||||
paramQueue.context->glAttachShader(p, s);
|
||||
}
|
||||
|
||||
void IglFunc.BindBuffer(BufferType bufferType, uint index)
|
||||
private static void InternalBindBuffer()
|
||||
{
|
||||
uint t, i;
|
||||
paramQueue.TryDequeue(out t, out i);
|
||||
gl->glBindBuffer(t, i);
|
||||
paramQueue.context->glBindBuffer(t, i);
|
||||
}
|
||||
|
||||
void IglFunc.BindTexture(uint type, uint texture)
|
||||
{
|
||||
uint t, te;
|
||||
paramQueue.TryDequeue(out t, out te);
|
||||
gl->glBindTexture(t, te);
|
||||
}
|
||||
|
||||
void IglFunc.BindVertexArray(uint index)
|
||||
{
|
||||
uint i;
|
||||
paramQueue.TryDequeue(out i);
|
||||
gl->glBindVertexArray(i);
|
||||
}
|
||||
|
||||
void IglFunc.Clear(MaskBufferBit mask)
|
||||
private static void InternalClear()
|
||||
{
|
||||
uint mt;
|
||||
paramQueue.TryDequeue(out mt);
|
||||
gl->glClear(mt);
|
||||
paramQueue.context->glClear(mt);
|
||||
}
|
||||
|
||||
void IglFunc.ClearColor(float R, float G, float B, float A)
|
||||
private static void InternalClearColor()
|
||||
{
|
||||
float r, g, b, a;
|
||||
paramQueue.TryDequeue(out r, out g, out b, out a);
|
||||
gl->glClearColor(r, g, b, a);
|
||||
paramQueue.context->glClearColor(r, g, b, a);
|
||||
}
|
||||
|
||||
void IglFunc.ClearGraphicError()
|
||||
private static void InternalClearGraphicError()
|
||||
{
|
||||
while (gl->glGetError() != 0) { }
|
||||
while (paramQueue.context->glGetError() != 0) { }
|
||||
}
|
||||
|
||||
|
||||
glHandle IglFunc.CompileShader(string shaderCode, ShaderType shaderType)
|
||||
private static void InternalCompileShader()
|
||||
{
|
||||
IntPtr shaderHandle, codeHandle;
|
||||
paramQueue.TryDequeue(out codeHandle, out shaderHandle);
|
||||
uint shaderID;
|
||||
shaderCode += '\0';
|
||||
shaderID = InternalIO.InternalLoadShaderCode(shaderCode, (int)shaderType);
|
||||
if (shaderID == 0)
|
||||
int count, type;
|
||||
paramQueue.TryDequeue(out type, out count);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
IntPtr logPtr = InternalIO.InternalReadLog();
|
||||
string log;
|
||||
try
|
||||
paramQueue.TryDequeue(out shaderHandle, out codeHandle);
|
||||
*(uint*)shaderHandle = InternalIO.InternalLoadShaderCode((byte*)codeHandle, type);
|
||||
if (*(uint*)shaderHandle == 0)
|
||||
{
|
||||
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)
|
||||
IntPtr logPtr = InternalIO.InternalReadLog();
|
||||
string log;
|
||||
try
|
||||
{
|
||||
if (!char.IsControl(item))
|
||||
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)
|
||||
{
|
||||
isUseful = true; break;
|
||||
if (!char.IsControl(item))
|
||||
{
|
||||
isUseful = true; break;
|
||||
}
|
||||
}
|
||||
if (!isUseful)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
if (!isUseful)
|
||||
catch (Exception)
|
||||
{
|
||||
throw new Exception();
|
||||
log = "Failed to compile shader.\nFailed to get GLSL compiler log";
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
log = "Failed to compile shader.\nFailed to get GLSL compiler log";
|
||||
}
|
||||
|
||||
InternalIO.InternalWriteLog(log, LogType.Error);
|
||||
InternalIO.InternalWriteLog(log, LogType.Error);
|
||||
}
|
||||
GCHandle.FromIntPtr(codeHandle).Free();
|
||||
}
|
||||
*(uint*)shaderHandle = shaderID;
|
||||
}
|
||||
|
||||
private void InternalAfterAlign(Form form, Action action)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private void InternalAlignFrame(Form form)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private void InternalBindTexture(uint type, uint texture)
|
||||
{
|
||||
uint t, te;
|
||||
paramQueue.TryDequeue(out t, out te);
|
||||
paramQueue.context->glBindTexture(t, te);
|
||||
}
|
||||
|
||||
private void InternalBindVertexArray(uint index)
|
||||
{
|
||||
uint i;
|
||||
paramQueue.TryDequeue(out i);
|
||||
paramQueue.context->glBindVertexArray(i);
|
||||
}
|
||||
|
||||
private glHandle InternalCreateProgram()
|
||||
{
|
||||
IntPtr programHandle = default;
|
||||
paramQueue.TryDequeue(out programHandle);
|
||||
*(uint*)programHandle = paramQueue.context->glCreateProgram();
|
||||
return default;
|
||||
}
|
||||
|
||||
glHandle IglFunc.CreateProgram()
|
||||
private glHandleSet InternalCreateProgram(int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
glHandle IglFunc.CreateProgram(int count)
|
||||
private IntPtr InternalCreateWindowHandle(int width, int height, string tittle, IntPtr monitor, Form share)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
IntPtr IglFunc.CreateWindowHandle(int width, int height, string tittle, IntPtr monitor, Form share)
|
||||
private glHandle InternalCreatGraphicProgram()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
glHandle IglFunc.CreatGraphicProgram()
|
||||
private void InternalDeleteBuffer(uint handle)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.DeleteBuffer(uint handle)
|
||||
private void InternalDeleteBuffers(glHandleSet handle)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.DeleteBuffers(glHandle handle)
|
||||
private void InternalDeleteVertexArrays(glHandleSet arrays)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.DeleteVertexArrays(glHandle arrays)
|
||||
private void InternalDrawElements(GepmetryType mode, uint count, Type type, IntPtr ptr)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.DrawElements(GepmetryType mode, uint count, Type type, IntPtr ptr)
|
||||
private void InternalGenBuffers(uint count, glHandleSet ptr)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.GenBuffers(uint count, glHandle ptr)
|
||||
private void InternalGenTextures(uint count, glHandleSet ptr)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.GenTextures(uint count, glHandle ptr)
|
||||
private void InternalGenVertexArrays(uint count, glHandleSet ptr)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.GenVertexArrays(uint count, glHandle ptr)
|
||||
private void InternalGetGraphicError()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.GetGraphicError()
|
||||
private int InternalGetUniformLocation(uint program, byte* ptr)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
int IglFunc.GetUniformLocation(uint program, byte* ptr)
|
||||
private bool InternalGetWindowShouldClose(Form form)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
bool IglFunc.GetWindowShouldClose(Form form)
|
||||
private void InternalMakeContexCurrent(Form form)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.MakeContexCurrent(Form form)
|
||||
private void InternalSetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
|
||||
private void InternalSetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
|
||||
private void InternalSetFrameBufferSizeCallback(IntPtr id, FrameBufferSizeHandler handler)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.SetFrameBufferSizeCallback(IntPtr id, FrameBufferSizeHandler handler)
|
||||
private void InternalSetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
private void InternalSetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
|
||||
private void InternalSetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
||||
private void InternalSetValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
private void InternalSetValue(Uniform<float> uniform, float v0)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<float> uniform, float v0)
|
||||
private void InternalSetValue(Uniform<int> uniform, int i0)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<int> uniform, int i0)
|
||||
private void InternalSetValue(Uniform<Vec4d> uniform, Vec4d vec)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<Vec4d> uniform, Vec4d vec)
|
||||
private void InternalSetVertexAttribute(uint index, int size, Type t, bool normalized, uint stride, int pointer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.SetVertexAttribute(uint index, int size, Type t, bool normalized, uint stride, int pointer)
|
||||
private void InternalSetWindowShouldClose(Form form, bool mark)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.SetWindowShouldClose(Form form, bool mark)
|
||||
private void InternalSwapBuffers(Form form)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.SwapBuffers(Form form)
|
||||
private void InternalSwitchContext()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.TextureImage2d(uint target, int level, uint internalformat, uint width, uint height, uint format, uint type, void* pixels)
|
||||
private void InternalTextureImage2d(uint target, int level, uint internalformat, uint width, uint height, uint format, uint type, void* pixels)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.TextureParameter(uint target, uint pname, int param)
|
||||
private void InternalTextureParameter(uint target, uint pname, int param)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.UseProgram(uint program)
|
||||
private void InternalUseProgram(uint program)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.Viewport(int x, int y, uint width, uint height)
|
||||
private void InternalViewport(int x, int y, uint width, uint height)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
internal unsafe class GLparamQueue
|
||||
{
|
||||
private ConcurrentQueue<M128> paramQueue;
|
||||
|
||||
public GLparamQueue()
|
||||
{
|
||||
paramQueue = new ConcurrentQueue<M128>();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Enqueue(Vec4d v)
|
||||
{
|
||||
paramQueue.Enqueue(v);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Enqueue(uint u0)
|
||||
{
|
||||
M128 m = default;
|
||||
m.UInt32[0] = u0;
|
||||
paramQueue.Enqueue(m);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Enqueue(uint u0, uint u1)
|
||||
{
|
||||
M128 m = default;
|
||||
m.UInt32[0] = u0;
|
||||
m.UInt32[1] = u1;
|
||||
paramQueue.Enqueue(m);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Enqueue(float f0, float f1, float f2, float f3)
|
||||
{
|
||||
M128 m = default;
|
||||
m.Single[0] = f0;
|
||||
m.Single[1] = f1;
|
||||
m.Single[2] = f2;
|
||||
m.Single[3] = f3;
|
||||
paramQueue.Enqueue(m);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Enqueue(IntPtr p0, IntPtr p1)
|
||||
{
|
||||
M128 m = default;
|
||||
m.IntPtr0 = p0;
|
||||
m.IntPtr1 = p1;
|
||||
paramQueue.Enqueue(m);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void TryDequeue(out IntPtr p0, out IntPtr p1)
|
||||
{
|
||||
|
||||
M128 ret;
|
||||
if (paramQueue.TryDequeue(out ret))
|
||||
{
|
||||
p0 = ret.IntPtr0;
|
||||
p1 = ret.IntPtr1;
|
||||
}
|
||||
else
|
||||
{
|
||||
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void TryDequeue(out float f0, out float f1, out float f2, out float f3)
|
||||
{
|
||||
M128 ret;
|
||||
if (paramQueue.TryDequeue(out ret))
|
||||
{
|
||||
f0 = ret.UInt32[0];
|
||||
f1 = ret.UInt32[1];
|
||||
f2 = ret.UInt32[2];
|
||||
f3 = ret.UInt32[3];
|
||||
}
|
||||
else
|
||||
{
|
||||
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void TryDequeue(out uint u0)
|
||||
{
|
||||
M128 ret;
|
||||
if (paramQueue.TryDequeue(out ret))
|
||||
{
|
||||
u0 = ret.UInt32[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void TryDequeue(out uint u0, out uint u1)
|
||||
{
|
||||
M128 ret;
|
||||
if (paramQueue.TryDequeue(out ret))
|
||||
{
|
||||
u0 = ret.UInt32[0];
|
||||
u1 = ret.UInt32[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user