daily update on 20240206 by nitload youmu
This commit is contained in:
@@ -16,15 +16,16 @@ namespace StgSharp.Graphics
|
||||
|
||||
internal unsafe partial class GLonUpdate : IglFunc
|
||||
{
|
||||
internal GLonUpdateInternal glUpdateInternal;
|
||||
private ConcurrentQueue<IntPtr> glActionQueue;
|
||||
private GLparamQueue paramQueue;
|
||||
private static GLparamQueue paramQueue;
|
||||
private FrameTimeoutException refreshSignal = new();
|
||||
|
||||
internal GLonUpdate(GLcontext* context)
|
||||
{
|
||||
glUpdateInternal = new GLonUpdateInternal();
|
||||
paramQueue = glUpdateInternal.paramQueue;
|
||||
if (paramQueue == null)
|
||||
{
|
||||
paramQueue = new GLparamQueue();
|
||||
}
|
||||
glActionQueue = new ConcurrentQueue<IntPtr>();
|
||||
}
|
||||
|
||||
@@ -38,7 +39,7 @@ namespace StgSharp.Graphics
|
||||
void IglFunc.ActiveTexture(uint type)
|
||||
{
|
||||
paramQueue.Enqueue(type);
|
||||
glActionQueue.Enqueue(glUpdateInternal.ActiveTexturePtr);
|
||||
glActionQueue.Enqueue(ActiveTexturePtr);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,15 +62,15 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.AttachShader(glHandle program, glHandle shader)
|
||||
{
|
||||
paramQueue.Enqueue(program[0], shader[0]);
|
||||
glActionQueue.Enqueue(glUpdateInternal.AttachShaderPtr);
|
||||
paramQueue.Enqueue(program, shader);
|
||||
glActionQueue.Enqueue(AttachShaderPtr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.BindBuffer(BufferType bufferType, uint index)
|
||||
{
|
||||
paramQueue.Enqueue((uint)bufferType, index);
|
||||
glActionQueue.Enqueue(glUpdateInternal.BindBufferPtr
|
||||
glActionQueue.Enqueue(BindBufferPtr
|
||||
);
|
||||
}
|
||||
|
||||
@@ -100,67 +101,37 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.ClearColor(float R, float G, float B, float A)
|
||||
{
|
||||
glActionQueue.Enqueue(
|
||||
() => api->glClearColor(R, G, B, A)
|
||||
);
|
||||
glActionQueue.Enqueue(ClearColorPtr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.ClearGraphicError()
|
||||
{
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
while (api->glGetError() != 0) { };
|
||||
}
|
||||
);
|
||||
glActionQueue.Enqueue(ClearGraphicErrorPtr);
|
||||
}
|
||||
|
||||
|
||||
glHandle IglFunc.CompileShader(string shaderCode, ShaderType shaderType)
|
||||
//TODO:双线程,换运行环境
|
||||
void IglFunc.SwitchContext()
|
||||
{
|
||||
glHandle h = new glHandle(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));
|
||||
}
|
||||
);
|
||||
return h;
|
||||
glHandleSet IglFunc.CompileShader(ShaderType shaderType, params string[] shaderCode)
|
||||
{
|
||||
int l = shaderCode.Length;
|
||||
if (l == 0)
|
||||
{
|
||||
throw new ArgumentException("Should input at least one piece of shader code");
|
||||
}
|
||||
glHandleSet shaderHandle = new glHandleSet(shaderCode.Length);
|
||||
paramQueue.Enqueue((int)shaderType, l);
|
||||
for (int i = 0; i < l; i++)
|
||||
{
|
||||
GCHandle codePtr = GCHandle.Alloc(Encoding.UTF8.GetBytes(shaderCode[i] + '\0'), GCHandleType.Pinned);
|
||||
paramQueue.Enqueue((IntPtr)shaderHandle.handle + i, codePtr.AddrOfPinnedObject());
|
||||
}
|
||||
glActionQueue.Enqueue(CompileShaderPtr);
|
||||
return shaderHandle;
|
||||
}
|
||||
|
||||
|
||||
@@ -179,7 +150,7 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
glHandle IglFunc.CreateProgram(int count)
|
||||
glHandleSet IglFunc.CreateProgram(int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -235,7 +206,7 @@ namespace StgSharp.Graphics
|
||||
);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.DeleteBuffers(glHandle handle)
|
||||
unsafe void IglFunc.DeleteBuffers(glHandleSet handle)
|
||||
{
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
@@ -249,7 +220,7 @@ namespace StgSharp.Graphics
|
||||
);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.DeleteVertexArrays(glHandle arrays)
|
||||
unsafe void IglFunc.DeleteVertexArrays(glHandleSet arrays)
|
||||
{
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
@@ -290,7 +261,7 @@ namespace StgSharp.Graphics
|
||||
);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.GenBuffers(uint count, glHandle handle)
|
||||
unsafe void IglFunc.GenBuffers(uint count, glHandleSet handle)
|
||||
{
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
@@ -299,7 +270,7 @@ namespace StgSharp.Graphics
|
||||
);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.GenTextures(uint count, glHandle handle)
|
||||
unsafe void IglFunc.GenTextures(uint count, glHandleSet handle)
|
||||
{
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
@@ -308,7 +279,7 @@ namespace StgSharp.Graphics
|
||||
);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.GenVertexArrays(uint count, glHandle ptr)
|
||||
unsafe void IglFunc.GenVertexArrays(uint count, glHandleSet ptr)
|
||||
{
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
|
||||
Reference in New Issue
Block a user