daily update on 20240528 by nitload youmu

This commit is contained in:
Nitload
2024-05-28 17:45:54 +08:00
parent de399e22c2
commit 70890e3e33
88 changed files with 10678 additions and 5761 deletions
+154 -50
View File
@@ -43,14 +43,19 @@ namespace StgSharp
{
internal static unsafe partial class InternalIO
{
[DllImport(SSC_libName, EntryPoint = "glCheckShaderStat",
CallingConvention = CallingConvention.Cdecl)]
internal static extern int glCheckShaderStatus(ref GLcontext context, uint shaderHandle,int key, ref IntPtr logPtr);
#pragma warning disable CA5392
internal static extern int glCheckShaderStatus(ref GLcontext context, uint shaderHandle, int key, ref IntPtr logPtr);
#pragma warning restore CA5392
}
}
namespace StgSharp.Graphics
namespace StgSharp.Graphics.GL
{
internal static unsafe partial class GL
internal static unsafe partial class glFunc
{
private static GLcontext* context;
@@ -58,15 +63,12 @@ namespace StgSharp.Graphics
public static IntPtr CurrentContextHandle
{
get { return (IntPtr)context; }
set
{
context = (GLcontext*)value;
}
set { context = (GLcontext*)value; }
}
private static ref GLcontext Context
{
get
get
{
#if DEBUG
if ((IntPtr)context==IntPtr.Zero)
@@ -74,7 +76,7 @@ namespace StgSharp.Graphics
throw new NullReferenceException();
}
#endif
return ref *context;
return ref (*context);
}
}
@@ -96,14 +98,21 @@ namespace StgSharp.Graphics
Context.glBindBuffer((uint)bufferType, handle.Value);
}
public static string GetShaderStatus(Shader s, int index, int key)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void GetTextureImage<T>(Texture2DTarget target, int level, ImageChannel channel, ImageChannelLayout channelLayout, ref T[] dataStream)where T: struct,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
{
IntPtr sptr = IntPtr.Zero;
if (InternalIO.glCheckShaderStatus(ref Context, s.handle[index].Value, key,ref sptr) == 0)
#pragma warning disable CS8500
fixed (T* tptr = dataStream)
{
return Marshal.PtrToStringAnsi(sptr);
Context.glGetTexImage((uint)target, level, (uint)channel, (uint)channelLayout, tptr);
}
return "";
#pragma warning restore CS8500
}
/// <summary>
@@ -118,12 +127,30 @@ namespace StgSharp.Graphics
Context.glBindFramebuffer((uint)target, handle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindRenderBuffer(glHandle handle)
{
Context.glBindRenderbuffer(GLconst.RENDERBUFFER, handle.Value);
}
public static void WaitAccomplishment()
{
Context.glFinish();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindTexture(uint type, glHandle texture)
{
Context.glBindTexture(type, texture.Value);
}
public static unsafe int GetMaskInteger(uint statusCode)
{
int ret = 0;
Context.glGetIntegerv(statusCode,&ret);
return ret;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindVertexArray(glHandle handle)
@@ -131,10 +158,35 @@ namespace StgSharp.Graphics
Context.glBindVertexArray(handle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void VertexAttributeDivisor(uint layoutIndex, uint divisor)
public static void RereadImage(
this Image i, (int X, int Y) beginPosition, FrameBufferChannel format, ImageChannelLayout dataType)
{
Context.glVertexAttribDivisor(layoutIndex, divisor);
glArrayHandle handle = i.GetArrayHandle();
Context.glReadPixels(
beginPosition.X, beginPosition.Y, i.Width, i.Height, (uint)format, (uint)dataType, (byte*)handle.AddressOfArray()
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void FrameBufferTexture2d(FrameBufferTarget target, uint attachment, Texture2DTarget texTarget,glHandle textureHandle ,int level)
{
Context.glFramebufferTexture2D(
(uint)target, attachment, (uint)texTarget,textureHandle.Value, level
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ReadPixels(
(int X, int Y) beginPosition, (int width, int height) size, FrameBufferChannel format, ImageChannelLayout dataType, ref byte[] stream
)
{
fixed (byte* bptr = stream)
{
Context.glReadPixels(
beginPosition.X, beginPosition.Y,
size.width, size.height, (uint)format, (uint)dataType, bptr);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -143,6 +195,11 @@ namespace StgSharp.Graphics
Context.glClear((uint)mask);
}
public static void CombineFrameBufferRenderBuffer(glHandle fboHandle, glHandle rboHandle)
{
Context.glFramebufferRenderbuffer(GLconst.FRAMEBUFFER,fboHandle.Value,GLconst.RENDERBUFFER, rboHandle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void ClearColor(float R, float G, float B, float A)
{
@@ -203,31 +260,8 @@ namespace StgSharp.Graphics
return ret;
}
public static unsafe IntPtr CreateWindowHandle(
int width, int height, string tittle, IntPtr monitor, Form share)
{
byte[] tittleBytes = Encoding.UTF8.GetBytes(tittle);
IntPtr windowPtr;
if (share == null)
{
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, IntPtr.Zero);
}
else
{
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, share.id);
}
if (((long)windowPtr == -1) || ((long)windowPtr == -2))
{
throw new Exception("Cannot create window instance!");
}
else
{
return windowPtr;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void DeleteBuffer(glHandle handle)
@@ -278,7 +312,7 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void DrawElementsInstanced(
GeometryType mode , uint count, TypeCode type, IntPtr ptr, uint amount
GeometryType mode, uint count, TypeCode type, IntPtr ptr, uint amount
)
{
uint a;
@@ -302,7 +336,7 @@ namespace StgSharp.Graphics
LogType.Error);
return;
}
Context.glDrawElementsInstanced((uint)mode, count, a, (void*)ptr,amount);
Context.glDrawElementsInstanced((uint)mode, count, a, (void*)ptr, amount);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -319,6 +353,15 @@ namespace StgSharp.Graphics
return h;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe glHandleSet GenRenderBuffer(int count)
{
glHandleSet h = new glHandleSet(count);
Context.glGenRenderbuffers(count, (uint*)h.Handle);
return h;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe glHandleSet GenTextures(int count)
{
@@ -328,6 +371,14 @@ namespace StgSharp.Graphics
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetRenderBufferStorage(RenderBufferInternalFormat internalFormat ,(int width, int height) size)
{
Context.glRenderbufferStorage(
GLconst.RENDERBUFFER, (uint)internalFormat,size.width,size.height
);
}
public static unsafe glHandleSet GenVertexArrays(int count)
{
glHandleSet h = new glHandleSet(count);
@@ -335,6 +386,16 @@ namespace StgSharp.Graphics
return h;
}
public static string GetShaderStatus(Shader s, int index, int key)
{
IntPtr sptr = IntPtr.Zero;
if (InternalIO.glCheckShaderStatus(ref Context, s.handle[index].Value, key, ref sptr) == 0)
{
return Marshal.PtrToStringAnsi(sptr);
}
return string.Empty;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe glSHandle GetUniformLocation(glHandle program, string name)
@@ -359,17 +420,16 @@ namespace StgSharp.Graphics
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void LoadShaderSource(glHandle shaderHandle, string codeStream)
public static unsafe void LoadShaderSource(glHandle shaderHandle, byte[] codeStream)
{
byte[] stream = Encoding.UTF8.GetBytes(codeStream);
fixed (byte* streamPtr = stream)
fixed (byte* streamPtr = codeStream)
{
Context.glShaderSource(shaderHandle.Value, 1, &streamPtr, (void*)0);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void MakeContextCurrent(Form form)
public static unsafe void MakeContextCurrent(ViewModel form)
{
if (form.WindowID == IntPtr.Zero)
{
@@ -420,6 +480,34 @@ namespace StgSharp.Graphics
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetBufferData<T>(BufferType bufferType, ReadOnlySpan<T> bufferArray, BufferUsage usage)
where T : struct,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
{
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
if (bufferArray == null)
{
return;
}
#pragma warning disable CS8500
fixed (void* bufferPtr = bufferArray)
#pragma warning restore CS8500
{
Context.glBufferData(
(uint)bufferType,
(IntPtr)size,
(IntPtr)bufferPtr,
(uint)usage);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetBufferData<T>(BufferType bufferType, Span<T> bufferArray, BufferUsage usage)
where T : struct,
@@ -449,7 +537,7 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetBufferVectorData<T>(BufferType bufferType, Span<T> bufferArray, BufferUsage usage)
public static unsafe void SetBufferVectorData<T>(BufferType bufferType, ReadOnlySpan<T> bufferArray, BufferUsage usage)
where T : struct, IVector
{
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
@@ -499,10 +587,20 @@ namespace StgSharp.Graphics
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void TextureImage2d<T>(int target, int level, uint internalformat, uint width, uint height, uint format, uint type, glHandle pixels)
public static void TextureImage2d(Texture2DTarget target, int level, uint internalformat, uint width, uint height,
uint format, ImageChannelLayout type, glHandle pixels)
{
Context.glTexImage2D(
(uint)target, level, internalformat, width, height, 0, format, type, pixels.valuePtr
(uint)target, level, internalformat, width, height, 0, format, (uint)type, pixels.valuePtr
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void TextureImage2d(Texture2DTarget target, int level, uint internalformat, uint width, uint height,
uint format, ImageChannelLayout type, glArrayHandle pixelArrayHandle)
{
Context.glTexImage2D(
(uint)target, level, internalformat, width, height, 0, format, (uint)type, (void*)pixelArrayHandle.handle.AddrOfPinnedObject()
);
}
@@ -518,6 +616,12 @@ namespace StgSharp.Graphics
Context.glUseProgram(program.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void VertexAttributeDivisor(uint layoutIndex, uint divisor)
{
Context.glVertexAttribDivisor(layoutIndex, divisor);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Viewport(int x, int y, uint width, uint height)
{