daily update on 20240501 by nitload youmu, tracking blueprint coruptr

This commit is contained in:
YoumuLiu
2024-05-02 05:47:27 +08:00
parent 0cd01ed9dd
commit 6324e578ab
60 changed files with 2564 additions and 307 deletions
+44 -34
View File
@@ -42,25 +42,35 @@ namespace StgSharp.Graphics
{
internal static unsafe partial class GL
{
private static IntPtr api;
internal static GLcontext* api;
private static ref GLcontext Context
{
get { return ref *(GLcontext*)api; }
}
public static IntPtr CurrentContextHandle
{
get { return (IntPtr)api; }
set { api = value; }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ActiveTexture(uint type)
{
api->glActiveTexture(type);
Context.glActiveTexture(type);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AttachShader(glHandle program, glHandle shader)
{
api->glAttachShader(program.Value, shader.Value);
Context.glAttachShader(program.Value, shader.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindBuffer(BufferType bufferType, glHandle handle)
{
api->glBindBuffer((uint)bufferType, handle.Value);
Context.glBindBuffer((uint)bufferType, handle.Value);
}
/// <summary>
@@ -72,13 +82,13 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindFrameBuffer(FrameBufferTarget target, glHandle handle)
{
api->glBindFramebuffer((uint)target, handle.Value);
Context.glBindFramebuffer((uint)target, handle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindTexture(uint type, glHandle texture)
{
api->glBindTexture(type, texture.Value);
Context.glBindTexture(type, texture.Value);
}
@@ -86,43 +96,43 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindVertexArray(glHandle handle)
{
api->glBindVertexArray(handle.Value);
Context.glBindVertexArray(handle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Clear(MaskBufferBit mask)
{
api->glClear((uint)mask);
Context.glClear((uint)mask);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void ClearColor(float R, float G, float B, float A)
{
api->glClearColor(R, G, B, A);
Context.glClearColor(R, G, B, A);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void ClearGraphicError()
{
while (api->glGetError() != 0) { }
while (Context.glGetError() != 0) { }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void CompileShader(glHandle shaderhandle)
{
api->glCompileShader(shaderhandle.Value);
Context.glCompileShader(shaderhandle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe glHandle CreateGraphicProgram()
{
return glHandle.Alloc(api->glCreateProgram());
return glHandle.Alloc(Context.glCreateProgram());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static glHandle CreateProgram()
{
return glHandle.Alloc(api->glCreateProgram());
return glHandle.Alloc(Context.glCreateProgram());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -131,7 +141,7 @@ namespace StgSharp.Graphics
glHandleSet h = new glHandleSet(count);
for (int i = 0; i < count; i++)
{
h.SetValue(i, api->glCreateProgram());
h.SetValue(i, Context.glCreateProgram());
}
return h;
}
@@ -143,10 +153,10 @@ namespace StgSharp.Graphics
uint t = (uint)type;
for (int i = 0; i < count; i++)
{
uint id = api->glCreateShader(t);
uint id = Context.glCreateShader(t);
if (id == 0)
{
uint error = api->glGetError();
uint error = Context.glGetError();
InternalIO.InternalWriteLog($"Failed in creating shader: {error}", LogType.Error);
throw new Exception();
}
@@ -184,20 +194,20 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void DeleteBuffer(glHandle handle)
{
api->glDeleteBuffers(1, (uint*)handle.Handle);
Context.glDeleteBuffers(1, (uint*)handle.Handle);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void DeleteBuffers(glHandleSet handle)
{
api->glDeleteBuffers(handle.length, (uint*)handle.Handle);
Context.glDeleteBuffers(handle.length, (uint*)handle.Handle);
handle.Release();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void DeleteVertexArrays(glHandleSet arrays)
{
api->glDeleteVertexArrays(arrays.length, (uint*)arrays.Handle);
Context.glDeleteVertexArrays(arrays.length, (uint*)arrays.Handle);
arrays.Release();
}
@@ -225,20 +235,20 @@ namespace StgSharp.Graphics
LogType.Error);
return;
}
api->glDrawElements((uint)mode, count, a, (void*)ptr);
Context.glDrawElements((uint)mode, count, a, (void*)ptr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Enable(GLOperation operation)
{
api->glEnable((uint)operation);
Context.glEnable((uint)operation);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe glHandleSet GenBuffers(int count)
{
glHandleSet h = new glHandleSet(count);
api->glGenBuffers(count, (uint*)h.Handle);
Context.glGenBuffers(count, (uint*)h.Handle);
return h;
}
@@ -246,7 +256,7 @@ namespace StgSharp.Graphics
public static unsafe glHandleSet GenTextures(int count)
{
glHandleSet h = new glHandleSet(count);
api->glGenTextures(count, (uint*)h.Handle);
Context.glGenTextures(count, (uint*)h.Handle);
return h;
}
@@ -254,7 +264,7 @@ namespace StgSharp.Graphics
public static unsafe glHandleSet GenVertexArrays(int count)
{
glHandleSet h = new glHandleSet(count);
api->glGenVertexArrays(count, (uint*)h.Handle);
Context.glGenVertexArrays(count, (uint*)h.Handle);
return h;
}
@@ -264,7 +274,7 @@ namespace StgSharp.Graphics
byte[] code = Encoding.UTF8.GetBytes(name);
fixed (byte* ptr = code)
{
return glSHandle.Alloc(api->glGetUniformLocation(program.Value, ptr));
return glSHandle.Alloc(Context.glGetUniformLocation(program.Value, ptr));
}
}
@@ -274,7 +284,7 @@ namespace StgSharp.Graphics
byte[] stream = Encoding.UTF8.GetBytes(codeStream);
fixed (byte* streamPtr = stream)
{
api->glShaderSource(shaderHandle.Value, 1, &streamPtr, (void*)0);
Context.glShaderSource(shaderHandle.Value, 1, &streamPtr, (void*)0);
}
}
@@ -294,7 +304,7 @@ namespace StgSharp.Graphics
{
int size = Marshal.SizeOf<T>();
T* p = &bufferData;
api->glBufferData(
Context.glBufferData(
(uint)bufferType,
(IntPtr)size,
(IntPtr)p,
@@ -311,7 +321,7 @@ namespace StgSharp.Graphics
}
fixed (void* bufferPtr = bufferArray)
{
api->glBufferData(
Context.glBufferData(
(uint)bufferType,
(IntPtr)size,
(IntPtr)bufferPtr,
@@ -323,14 +333,14 @@ namespace StgSharp.Graphics
public static void SetVertexAttribute(uint index, int size, TypeCode t, bool normalized, uint stride, int pointer)
{
uint type = InternalIO.GLtype[t];
api->glVertexAttribPointer(index, size, type, normalized ? 1 : 0, stride, (void*)pointer);
api->glEnableVertexAttribArray(index);
Context.glVertexAttribPointer(index, size, type, normalized ? 1 : 0, stride, (void*)pointer);
Context.glEnableVertexAttribArray(index);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void TextureImage2d<T>(int target, int level, uint internalformat, uint width, uint height, uint format, uint type, glHandle pixels)
{
api->glTexImage2D(
Context.glTexImage2D(
(uint)target, level, internalformat, width, height, 0, format, type, pixels.valuePtr
);
}
@@ -338,19 +348,19 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void TextureParameter(int target, uint pname, int param)
{
api->glTexParameteri((uint)target, pname, param);
Context.glTexParameteri((uint)target, pname, param);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void UseProgram(glHandle program)
{
api->glUseProgram(program.Value);
Context.glUseProgram(program.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Viewport(int x, int y, uint width, uint height)
{
api->glViewport(x, y, width, height);
Context.glViewport(x, y, width, height);
}
}