daily update on 20240207 by nitload youmu

This commit is contained in:
Nitload
2024-02-07 13:47:12 +08:00
parent 8548757bbf
commit 6fe6b3b3cf
37 changed files with 231 additions and 196 deletions
+50 -37
View File
@@ -52,12 +52,13 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.AttachShader(glHandle program, glHandle shader)
{
api->glAttachShader(program.value, shader.value);
api->glAttachShader(*program.valuePtr, *shader.valuePtr);
}
void IglFunc.BindBuffer(BufferType bufferType, uint index)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.BindBuffer(BufferType bufferType, glHandle handle)
{
api->glBindBuffer((uint)bufferType, index);
api->glBindBuffer((uint)bufferType, *handle.valuePtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -67,9 +68,9 @@ namespace StgSharp.Graphics
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.BindVertexArray(uint index)
void IglFunc.BindVertexArray(glHandle handle)
{
api->glBindVertexArray(index);
api->glBindVertexArray(handle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -90,61 +91,73 @@ namespace StgSharp.Graphics
while (api->glGetError() != 0) { }
}
glHandle IglFunc.CompileShader(string shaderCode, ShaderType shaderType)
glHandleSet IglFunc.CompileShader(ShaderType shaderType, params string[] shaderCodeArray)
{
uint shaderID;
shaderCode += '\0';
shaderID = InternalIO.InternalLoadShaderCode(shaderCode, (int)shaderType);
if (shaderID == 0) //compile error handler
int l = shaderCodeArray.Length;
if (l == 0)
{
IntPtr logPtr = InternalIO.InternalReadLog();
string log;
try
throw new ArgumentException("At least one pice of code is required.");
}
glHandleSet handleSet = new glHandleSet(l);
for (int i = 0; i < l; i++)
{
uint shaderID;
byte[] data = Encoding.UTF8.GetBytes(shaderCodeArray[i] + '\0');
fixed (byte* codePtr = data)
{
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)
shaderID = InternalIO.InternalLoadShaderCode(codePtr, (int)shaderType);
}
if (shaderID == 0) //compile error handler
{
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.\n" +
"Failed to get GLSL compiler log";
}
}
catch (Exception)
{
log = "Failed to compile shader.\n" +
"Failed to get GLSL compiler log";
}
InternalIO.InternalWriteLog(log, LogType.Error);
InternalIO.InternalWriteLog(log, LogType.Error);
}
handleSet.SetValue(i, shaderID);
}
return new glHandle(shaderID);
return handleSet;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
glHandle IglFunc.CreateProgram()
{
return new glHandle(api->glCreateProgram());
return glHandle.Alloc(api->glCreateProgram());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe glHandleSet IglFunc.CreateProgram(int count)
{
glHandleSet h = new glHandleSet(count);
glHandle* p = h.handle;
for (int i = 0; i < count; i++)
{
*(p + i) = api->glCreateProgram();
h.SetValue(i, api->glCreateProgram());
}
return h;
}
@@ -178,7 +191,7 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe glHandle IglFunc.CreatGraphicProgram()
{
return new glHandle(api->glCreateProgram());
return glHandle.Alloc(api->glCreateProgram());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -260,7 +273,7 @@ namespace StgSharp.Graphics
}
catch (Exception ex)
{
/*
/**/
InternalIO.InternalWriteLog(
error + ex.StackTrace,
LogType.Error