Generated opengl function binding added. All opengl core profile function is now available but not in C# flavour.

This commit is contained in:
Youmu Liu
2025-12-30 19:16:05 +08:00
parent b7c32bdf6d
commit 6484307b8a
40 changed files with 14965 additions and 3893 deletions
+45 -135
View File
@@ -113,15 +113,6 @@ namespace StgSharp.Graphics.OpenGL
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AttachShader(
GlHandle program,
GlHandle shader
)
{
Context.glAttachShader(program.Value, shader.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void BindBuffer(
BufferType bufferType,
@@ -147,7 +138,7 @@ namespace StgSharp.Graphics.OpenGL
GlHandle handle
)
{
Context.glBindFramebuffer((uint)target, handle.SignedValue);
Context.glBindFramebuffer((uint)target, handle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -158,15 +149,6 @@ namespace StgSharp.Graphics.OpenGL
Context.glBindRenderbuffer(glConst.RENDERBUFFER, handle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void BindTexture(
uint type,
GlHandle texture
)
{
Context.glBindTexture(type, texture.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void BindVertexArray(
GlHandle handle
@@ -191,17 +173,6 @@ namespace StgSharp.Graphics.OpenGL
Context.glClear((uint)mask);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void ClearColor(
float R,
float G,
float B,
float A
)
{
Context.glClearColor(R, G, B, A);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ClearError()
{
@@ -237,26 +208,12 @@ namespace StgSharp.Graphics.OpenGL
glConst.RENDERBUFFER, rboHandle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void CompileShader(
GlHandle shaderhandle
)
{
Context.glCompileShader(shaderhandle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe GlHandle CreateGraphicProgram()
{
return GlHandle.Create(Context.glCreateProgram());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public GlHandle CreateProgram()
{
return GlHandle.Create(Context.glCreateProgram());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe GlHandle[] CreateProgram(
int count
@@ -349,7 +306,7 @@ namespace StgSharp.Graphics.OpenGL
bool isWrite
)
{
Context.glDepthMask(isWrite);
Context.glDepthMask(isWrite ? (byte)1 : (byte)0);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -364,7 +321,7 @@ namespace StgSharp.Graphics.OpenGL
public unsafe void DrawArrays(
GeometryType mode,
int first,
uint count
int count
)
{
Context.glDrawArrays((uint)mode, first, count);
@@ -373,7 +330,7 @@ namespace StgSharp.Graphics.OpenGL
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void DrawElements(
GeometryType mode,
uint count,
int count,
TypeCode type,
IntPtr ptr
)
@@ -387,39 +344,28 @@ namespace StgSharp.Graphics.OpenGL
_ => throw new ArgumentException(
$"{$"{$"Parameter error in parameter {nameof(type)} method DrawElements. "}"}{$"{$"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are supported."}"}")
};
Context.glDrawElements((uint)mode, count, a, (void*)ptr);
Context.glDrawElements((uint)mode, count, a, (nint*)ptr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawElementsInstanced(
GeometryType mode,
uint count,
int count,
TypeCode type,
IntPtr ptr,
uint amount
int amount
)
{
uint a;
switch (type)
a = type switch
{
case TypeCode.UInt32:
a = glConst.UNSIGNED_INT;
break;
case TypeCode.UInt16:
a = glConst.UNSIGNED_SHORT;
break;
case TypeCode.Byte:
a = glConst.UNSIGNED_BYTE;
break;
default:
DefaultLog.InternalWriteLog(
$"{$"Parameter error in parameter {nameof(type)} method DrawElements. "}{$"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are supported."}",
LogType.Error);
return;
}
Context.glDrawElementsInstanced((uint)mode, count, a, (void*)ptr, amount);
TypeCode.UInt32 => glConst.UNSIGNED_INT,
TypeCode.UInt16 => glConst.UNSIGNED_SHORT,
TypeCode.Byte => glConst.UNSIGNED_BYTE,
_ => throw new ArgumentException(
$"{$"{$"Parameter error in parameter {nameof(type)} method DrawElements. "}"}{$"{$"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are supported."}"}")
};
Context.glDrawElementsInstanced((uint)mode, count, a, (nint*)ptr, amount);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -512,12 +458,6 @@ namespace StgSharp.Graphics.OpenGL
return h;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public uint GetError()
{
return Context.glGetError();
}
public unsafe int GetMaskInteger(
uint statusCode
)
@@ -552,7 +492,7 @@ namespace StgSharp.Graphics.OpenGL
{
fixed (T* tptr = dataStream) {
Context.glGetTexImage((uint)target, level, (uint)channel, (uint)channelLayout,
tptr);
(nint*)tptr);
}
}
@@ -599,19 +539,18 @@ namespace StgSharp.Graphics.OpenGL
)
{
fixed (byte* streamPtr = codeStream) {
Context.glShaderSource(shaderHandle.Value, 1, &streamPtr, (void*)0);
Context.glShaderSource(shaderHandle.Value, 1, &streamPtr, (int*)0);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void LoadShaderSource(
GlHandle shaderHandle,
ReadOnlySpan<char> codeStream
)
{
fixed (char* streamPtr = codeStream)
{
byte* bptr = (byte*)streamPtr;
Context.glShaderSource(shaderHandle.Value, 1, &bptr, (void*)0);
fixed (char* streamPtr = codeStream) {
Context.glShaderSource(shaderHandle.Value, 1, (byte**)&streamPtr, (int*)0);
}
}
@@ -623,7 +562,7 @@ namespace StgSharp.Graphics.OpenGL
fixed (byte* streamPtr = codeStream)
{
byte* bptr = streamPtr;
Context.glShaderSource(shaderHandle.Value, 1, &bptr, (void*)0);
Context.glShaderSource(shaderHandle.Value, 1, &bptr, (int*)0);
}
}
@@ -635,15 +574,6 @@ namespace StgSharp.Graphics.OpenGL
Context.glPolygonMode(glConst.FRONT_AND_BACK, (uint)mode);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PolygonOffset(
float factor,
float unit
)
{
Context.glPolygonOffset(factor, unit);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ReadPixels(
(int X, int Y) beginPosition,
@@ -655,7 +585,7 @@ namespace StgSharp.Graphics.OpenGL
{
fixed (byte* bptr = stream) {
Context.glReadPixels(beginPosition.X, beginPosition.Y, size.width, size.height,
(uint)format, (uint)dataType, bptr);
(uint)format, (uint)dataType, (nint*)bptr);
}
}
@@ -672,7 +602,7 @@ namespace StgSharp.Graphics.OpenGL
}
fixed (byte* bptr = pixels) {
Context.glReadPixels(beginPosition.X, beginPosition.Y, i.Width, i.Height,
(uint)format, (uint)dataType, bptr);
(uint)format, (uint)dataType, (nint*)bptr);
}
i.PixelUpdateCount++;
}
@@ -688,7 +618,7 @@ namespace StgSharp.Graphics.OpenGL
T* p = &bufferData;
Context.glBufferData((uint)bufferType, (IntPtr)size, (IntPtr)p, (uint)usage);
Context.glBufferData((uint)bufferType, (nuint)size, (nint*)p, (uint)usage);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -704,8 +634,7 @@ namespace StgSharp.Graphics.OpenGL
}
fixed (void* bufferPtr = bufferArray) {
Context.glBufferData((uint)bufferType, (IntPtr)size, (IntPtr)bufferPtr,
(uint)usage);
Context.glBufferData((uint)bufferType, (nuint)size, (nint*)bufferPtr, (uint)usage);
}
}
@@ -716,13 +645,13 @@ namespace StgSharp.Graphics.OpenGL
BufferUsage usage
) where T : unmanaged,INumber<T>
{
int size = bufferSpan.Length * Marshal.SizeOf(typeof(T));
if (bufferSpan == null) {
int size = bufferSpan.Length * Marshal.SizeOf<T>();
if (bufferSpan.IsEmpty) {
return;
}
fixed (void* bufferPtr = bufferSpan) {
Context.glBufferData((uint)bufferType, (IntPtr)size, (IntPtr)bufferPtr,
Context.glBufferData((uint)bufferType, (nuint)size, (IntPtr*)bufferPtr,
(uint)usage);
}
}
@@ -734,14 +663,14 @@ namespace StgSharp.Graphics.OpenGL
BufferUsage usage
) where T : unmanaged, INumber<T>
{
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
if (bufferArray == null) {
int size = bufferArray.Length * Marshal.SizeOf<T>();
if (bufferArray.IsEmpty) {
return;
}
fixed (void* bufferPtr = bufferArray) {
Context.glBufferData((uint)bufferType, (IntPtr)size, (IntPtr)bufferPtr,
Context.glBufferData((uint)bufferType, (nuint)size, (IntPtr*)bufferPtr,
(uint)usage);
}
}
@@ -753,10 +682,10 @@ namespace StgSharp.Graphics.OpenGL
BufferUsage usage
) where T : unmanaged, IUnmanagedVector<T>
{
int size = bufferSpan.Length * Marshal.SizeOf(typeof(T));
int size = bufferSpan.Length * Marshal.SizeOf<T>();
fixed (void* bufferPtr = bufferSpan) {
Context.glBufferData((uint)bufferType, (IntPtr)size, (IntPtr)bufferPtr,
Context.glBufferData((uint)bufferType, (nuint)size, (IntPtr*)bufferPtr,
(uint)usage);
}
}
@@ -773,7 +702,7 @@ namespace StgSharp.Graphics.OpenGL
return;
}
fixed (void* bufferPtr = bufferArray) {
Context.glBufferData((uint)bufferType, (IntPtr)size, (IntPtr)bufferPtr,
Context.glBufferData((uint)bufferType, (nuint)size, (IntPtr*)bufferPtr,
(uint)usage);
}
}
@@ -804,13 +733,13 @@ namespace StgSharp.Graphics.OpenGL
int size,
TypeCode t,
bool normalized,
uint stride,
int stride,
int pointer
)
{
uint type = GraphicFramework.GLtype[(int)t];
Context.glVertexAttribPointer(index, size, type, normalized ? 1 : 0, stride,
(void*)pointer);
Context.glVertexAttribPointer(index, size, type, (byte)(normalized ? 1 : 0), stride,
(nint*)pointer);
Context.glEnableVertexAttribArray(index);
}
@@ -819,8 +748,8 @@ namespace StgSharp.Graphics.OpenGL
Texture2DTarget target,
int level,
ImageChannel sourceChannel,
uint width,
uint height,
int width,
int height,
ImageChannel targetChannel,
PixelChannelLayout type,
T[] pixels
@@ -829,8 +758,8 @@ namespace StgSharp.Graphics.OpenGL
fixed (T* tptr = pixels)
{
T* ptr = ((pixels == null) || (pixels.Length == 0)) ? (T*)IntPtr.Zero : tptr;
Context.glTexImage2D((uint)target, level, (uint)sourceChannel, width, height, 0,
(uint)targetChannel, (uint)type, tptr);
Context.glTexImage2D((uint)target, level, (int)sourceChannel, width, height, 0,
(uint)targetChannel, (uint)type, (nint*)tptr);
}
}
@@ -839,16 +768,16 @@ namespace StgSharp.Graphics.OpenGL
Texture2DTarget target,
int level,
ImageChannel sourceChannel,
uint width,
uint height,
int width,
int height,
ImageChannel targetChannel,
PixelChannelLayout type,
Span<T> pixelSpan
) where T : unmanaged, INumber<T>
{
fixed (T* tPtr = pixelSpan) {
Context.glTexImage2D((uint)target, level, (uint)sourceChannel, width, height, 0,
(uint)targetChannel, (uint)type, tPtr);
Context.glTexImage2D((uint)target, level, (int)sourceChannel, width, height, 0,
(uint)targetChannel, (uint)type, (nint*)tPtr);
}
}
@@ -870,14 +799,6 @@ namespace StgSharp.Graphics.OpenGL
return contextToGLMap.TryGetValue(handle, out functionPackage);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void UseProgram(
GlHandle program
)
{
Context.glUseProgram(program.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void VertexAttributeDivisor(
uint layoutIndex,
@@ -887,17 +808,6 @@ namespace StgSharp.Graphics.OpenGL
Context.glVertexAttribDivisor(layoutIndex, divisor);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Viewport(
int x,
int y,
uint width,
uint height
)
{
Context.glViewport(x, y, width, height);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void WaitAccomplishment()
{