daily update on 20240209 by nitload youmu

This commit is contained in:
Nitload
2024-02-09 23:31:33 +08:00
parent 6fe6b3b3cf
commit 8391569482
159 changed files with 948 additions and 2431 deletions
+40 -78
View File
@@ -3,7 +3,6 @@ using StgSharp.Math;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
@@ -62,9 +61,9 @@ namespace StgSharp.Graphics
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.BindTexture(uint type, uint texture)
void IglFunc.BindTexture(uint type, glHandle texture)
{
api->glBindTexture(type, texture);
api->glBindTexture(type, texture.DirectValue);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -169,12 +168,12 @@ namespace StgSharp.Graphics
IntPtr windowPtr;
if (share == null)
{
windowPtr = InternalIO.glfw.CreateWindow(
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, IntPtr.Zero);
}
else
{
windowPtr = InternalIO.glfw.CreateWindow(
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, share.windowID);
}
@@ -195,9 +194,9 @@ namespace StgSharp.Graphics
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.DeleteBuffer(uint handle)
unsafe void IglFunc.DeleteBuffer(glHandle handle)
{
api->glDeleteBuffers(1, &handle);
api->glDeleteBuffers(1, (uint*)handle.Handle);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.DeleteBuffers(glHandleSet handle)
@@ -214,10 +213,10 @@ namespace StgSharp.Graphics
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.DrawElements(GepmetryType mode, uint count, Type type, IntPtr ptr)
unsafe void IglFunc.DrawElements(GepmetryType mode, uint count, TypeCode type, IntPtr ptr)
{
uint a;
switch (Type.GetTypeCode(type))
switch (type)
{
case TypeCode.UInt32:
a = GLconst.UNSIGNED_INT;
@@ -239,68 +238,53 @@ namespace StgSharp.Graphics
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.GenBuffers(uint count, glHandleSet handle)
unsafe glHandleSet IglFunc.GenBuffers(int count)
{
api->glGenBuffers(count, (uint*)handle.handle);
glHandleSet h = new glHandleSet((int)count);
api->glGenBuffers((uint)count, h.handle);
return h;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.GenTextures(uint count, glHandleSet handle)
unsafe glHandleSet IglFunc.GenTextures(int count)
{
api->glGenTextures(count, (uint*)handle.handle);
glHandleSet h = new glHandleSet((int)count);
api->glGenTextures((uint)count, h.handle);
return h;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.GenVertexArrays(uint count, glHandleSet handle)
unsafe glHandleSet IglFunc.GenVertexArrays(int count)
{
api->glGenVertexArrays(count, (uint*)handle.handle);
glHandleSet h = new glHandleSet(count);
api->glGenVertexArrays((uint)count, h.handle);
return h;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.GetGraphicError()
unsafe glSHandle IglFunc.GetUniformLocation(glHandle program, string name)
{
string error = null;
uint code = api->glGetError();
while (code != 0)
byte[] code = Encoding.UTF8.GetBytes(name);
fixed (byte* ptr = code)
{
error += $"OpenGL error {code}\n";
return glSHandle.Alloc(api->glGetUniformLocation(program.DirectValue, ptr));
}
try
{
if (error != null)
{
throw new Exception();
}
}
catch (Exception ex)
{
/**/
InternalIO.InternalWriteLog(
error + ex.StackTrace,
LogType.Error
);
/**/
}
return;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe int IglFunc.GetUniformLocation(uint program, byte* ptr)
{
return api->glGetUniformLocation(program, ptr);
}
unsafe bool IglFunc.GetWindowShouldClose(Form form)
{
return InternalIO.glfw.WindowShouldClose(form.windowID) == 0;
return InternalIO.glfwWindowShouldClose(form.windowID) == 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.MakeContexCurrent(Form form)
{
if (form.windowID == IntPtr.Zero)
{
InternalIO.InternalWriteLog($"From {nameof(form)} is not initted.", LogType.Warning);
return;
}
InternalIO.glfw.MakeContextCurrent(form.windowID);
InternalIO.glfwMakeContextCurrent(form.windowID);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -309,7 +293,7 @@ namespace StgSharp.Graphics
int size = sizeof(T);
api->glBufferData(
(uint)bufferType,
(UIntPtr)size,
(IntPtr)size,
&bufferData,
(uint)usage);
}
@@ -325,62 +309,40 @@ namespace StgSharp.Graphics
fixed (void* bufferPtr = bufferArray)
api->glBufferData(
(uint)bufferType,
(UIntPtr)size,
(IntPtr)size,
bufferPtr,
(uint)usage);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.SetFrameBufferSizeCallback(IntPtr id, FrameBufferSizeHandler handler)
{
IntPtr handlerPtr = Marshal.GetFunctionPointerForDelegate(handler);
InternalIO.glfw.SetFramebufferSizeCallback(id, handlerPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.SetVertexAttribute(uint index, int size, Type t, bool normalized, uint stride, int pointer)
void IglFunc.SetVertexAttribute(uint index, int size, TypeCode t, bool normalized, uint stride, int pointer)
{
uint type = InternalIO.GLtype[t];
api->glVertexAttribPointer(index, size, type, normalized, stride, (void*)pointer);
api->glVertexAttribPointer(index, size, type, normalized ? 1 : 0, stride, (void*)pointer);
api->glEnableVertexAttribArray(index);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.SetWindowShouldClose(Form form, bool mark)
{
InternalIO.glfw.SetWindowShouldClose(form.windowID, mark ? 1 : 0);
}
unsafe void IglFunc.SwapBuffers(Form form)
{
if (form.windowID == IntPtr.Zero)
{
return;
}
InternalIO.glfw.SwapBuffers(form.windowID);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.TextureImage2d(uint target, int level, uint internalformat, uint width, uint height, uint format, uint type, void* pixels)
void IglFunc.TextureImage2d<T>(int target, int level, uint internalformat, uint width, uint height, uint format, uint type, T[] pixels)
{
IntPtr source = GCHandle.Alloc(pixels, GCHandleType.Pinned).AddrOfPinnedObject();
api->glTexImage2D(
target, level, internalformat, width, height, 0, format, type, pixels
(uint)target, level, internalformat, width, height, 0, format, type, (void*)source
);
GCHandle.FromIntPtr(source).Free();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.TextureParameter(uint target, uint pname, int param)
void IglFunc.TextureParameter(int target, uint pname, int param)
{
api->glTexParameteri(target, pname, param);
api->glTexParameteri((uint)target, pname, param);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.UseProgram(uint program)
void IglFunc.UseProgram(glHandle program)
{
api->glUseProgram(program);
api->glUseProgram(program.DirectValue);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]