daily update on 20240203 by nitloadd youmu. New glhandle setup.

This commit is contained in:
Nitload
2024-02-03 23:20:50 +08:00
parent 8148c10acd
commit 5d778e0f2f
258 changed files with 10025 additions and 1220 deletions
@@ -41,11 +41,11 @@ namespace StgSharp.Graphics
void (* destroy) (GLFWwindow*);
*/
IntPtr makeCurrent;
IntPtr swapBuffer;
IntPtr swapInterval;
IntPtr extensionSupported;
IntPtr getProcAddress;
delegate*<GLFWwindow*> makeCurrent;
delegate*<GLFWwindow*> swapBuffer;
delegate*<int> swapInterval;
delegate*<byte*> extensionSupported;
delegate*<delegate*<void>, void> getProcAddress;
IntPtr destroy;
internal struct egl
+3 -2
View File
@@ -41,8 +41,9 @@
public enum ShaderType : int
{
FRAGMENT = 0x8B30,
VERTEX = 0x8B31
Fragment = 0x8B30,
Vertex = 0x8B31,
Program,
}
public enum BufferType : int
+23 -6
View File
@@ -34,7 +34,7 @@ namespace StgSharp.Graphics
internal Form sharedForm;
internal int width;
internal IntPtr windowID;
protected IglFunc gl;
private IglFunc gl;
private bool closed;
#endregion
@@ -173,17 +173,17 @@ namespace StgSharp.Graphics
}
}
private void InternalRender()
private unsafe void InternalRender()
{
#pragma warning disable CS8602
ConcurrentQueue<Action> glActions = (gl as GLonUpdate).GLactionQueue;
ConcurrentQueue<IntPtr> glActions = (gl as GLonUpdate).GLactionQueue;
#pragma warning restore CS8602
Action currentAction = new Action(() => { return; });
IntPtr currentOperation;
while (gl.GetWindowShouldClose(this))
{
if (glActions.TryDequeue(out currentAction))
if (glActions.TryDequeue(out currentOperation))
{
currentAction();
((delegate*<void>)currentOperation)();
}
}
}
@@ -198,6 +198,23 @@ namespace StgSharp.Graphics
Init((object[])args);
}
/// <summary>
/// Get OpenGL library of this form's context.
/// </summary>
/// <returns>A <see cref="IglFunc"/> package contains all opengl APIs </returns>
protected IglFunc GetGL()
{
if (Platform.API == GraphicAPI.GL)
{
return this.GL;
}
else
{
InternalIO.InternalWriteLog("Attempt to get OpenGL API package in other graphic envitronment.", LogType.Error);
throw new Exception();
}
}
/// <summary>
/// Define how current form render in one frame.
/// </summary>
+7 -22
View File
@@ -7,19 +7,7 @@ using System.Text;
namespace StgSharp.Graphics
{
public partial class Form
{
/// <summary>
/// Create a set of <see cref="ElementBuffer"/>.
/// </summary>
/// <param name="count">Amount of EBO to be created.</param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected ElementBuffer CreateElementBuffer(uint count)
{
return new ElementBuffer(count, this.gl);
}
}
/// <summary>
/// A collecion of handle to Element Buffer Object in OpenGL.
@@ -30,28 +18,25 @@ namespace StgSharp.Graphics
{
internal ElementBuffer(uint n, IglFunc gl)
{
_bufferID = new uint[n];
_bufferHandle = new glHandle((int)n);
GL = gl;
fixed (uint* id = _bufferID)
{
GL.GenBuffers(n, id);
}
GL.GenBuffers(n, _bufferHandle);
}
public uint this[int n]
{
get { return _bufferID[n]; }
get { return _bufferHandle[n]; }
}
public override void Bind(int index)
{
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferID[index]);
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferHandle[index]);
}
public void SetValue<T>(int index, T[] bufferArray, BufferUsage usage)
where T : struct, IConvertible
{
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferID[index]);
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferHandle[index]);
GL.SetBufferData(BufferType.ELEMENT_ARRAY_BUFFER, bufferArray, usage);
}
@@ -59,7 +44,7 @@ namespace StgSharp.Graphics
{
if (disposing)
{
GL.DeleteBuffers((uint)_bufferID.Length, _bufferID);
GL.DeleteBuffers(_bufferHandle);
}
}
}
@@ -11,7 +11,7 @@ namespace StgSharp.Graphics
/// </summary>
public abstract class IBufferObject : IDisposable
{
protected uint[] _bufferID;
protected glHandle _bufferHandle;
protected IglFunc GL;
/// <summary>
@@ -21,7 +21,7 @@ namespace StgSharp.Graphics
/// <returns></returns>
public uint this[int index]
{
get { return _bufferID[index]; }
get { return _bufferHandle[index]; }
}
/// <summary>
+4 -20
View File
@@ -5,36 +5,20 @@ using System.Text;
namespace StgSharp.Graphics
{
public partial class Form
{
/// <summary>
/// Create a set of <see cref="VertexArray"/>.
/// </summary>
/// <param name="count">Amount of VAO to be crated.</param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected VertexArray CreateVertexArray(uint count)
{
return new VertexArray(count, gl);
}
}
public unsafe class VertexArray : IBufferObject
{
internal VertexArray(uint n, IglFunc gl)
{
_bufferID = new uint[n];
_bufferHandle = new glHandle((int)n);
GL = gl;
fixed (uint* id = _bufferID)
{
GL.GenVertexArrays(n, id);
}
GL.GenVertexArrays(n, _bufferHandle);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public sealed override void Bind(int index)
{
GL.BindVertexArray(_bufferID[index]);
GL.BindVertexArray(_bufferHandle[index]);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -56,7 +40,7 @@ namespace StgSharp.Graphics
{
if (disposing)
{
GL.DeleteVertexArrays((uint)_bufferID.Length, _bufferID);
GL.DeleteVertexArrays(_bufferHandle);
}
}
}
+25 -45
View File
@@ -9,39 +9,14 @@ using System.Text;
namespace StgSharp.Graphics
{
public partial class Form
{
/// <summary>
/// Create aset of <see cref="VertexBuffer"/>.
/// </summary>
/// <param name="count">Amount of Object to be created.</param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected VertexBuffer CreateVertexBuffer(uint count)
{
return new VertexBuffer(count, gl);
}
}
public unsafe class VertexBuffer : IBufferObject
{
internal VertexBuffer(uint n, IglFunc glFunc)
{
_bufferID = new uint[n];
_bufferHandle = new glHandle((int)n);
GL = glFunc;
fixed (uint* ptr = _bufferID)
{
GL.GenBuffers(n, ptr);
}
}
/// <summary>
///
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Unbind()
{
GL.BindBuffer(BufferType.ARRAY_BUFFER, 0);
GL.GenBuffers(n, _bufferHandle);
}
public sealed override void Bind(int index)
@@ -49,22 +24,6 @@ namespace StgSharp.Graphics
GL.BindBuffer(BufferType.ARRAY_BUFFER, (uint)index);
}
internal void ChangeEnvironment(IglFunc gl)
{
GL = gl;
}
protected sealed override void Dispose(bool disposing)
{
if (disposing)
{
fixed (uint* id = _bufferID)
{
GL.DeleteBuffers((uint)_bufferID.Length, _bufferID);
}
}
}
/// <summary>
/// Set data to current vertex buffer object
/// </summary>
@@ -74,7 +33,7 @@ namespace StgSharp.Graphics
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
public void SetValue<T>(int index, T bufferData, BufferUsage usage) where T : IMat
{
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferID[index]);
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferData, usage);
}
@@ -88,9 +47,30 @@ namespace StgSharp.Graphics
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
public void SetValueArray<T>(int index, T[] bufferArray, BufferUsage usage) where T : struct, IConvertible
{
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferID[index]);
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferArray, usage);
}
/// <summary>
///
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Unbind()
{
GL.BindBuffer(BufferType.ARRAY_BUFFER, 0);
}
internal void ChangeEnvironment(IglFunc gl)
{
GL = gl;
}
protected sealed override void Dispose(bool disposing)
{
if (disposing)
{
GL.DeleteBuffers(_bufferHandle);
}
}
}
}
@@ -9,47 +9,37 @@ using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public partial class Form
{
protected Texture CreateTexture(uint n)
{
return new Texture(n, this.GL);
}
}
public unsafe class Texture
{
internal uint[] textureId;
internal Image[] sourceList;
internal static bool[] unitActivated = new bool[16];
internal glHandle _textureHandle;
internal Image[] sourceList;
private IglFunc GL;
internal void ChangeEnvironment(IglFunc gl)
{
GL = gl;
}
internal Texture(uint n, IglFunc gl)
{
textureId = new uint[n];
_textureHandle = new glHandle((int)n);
sourceList = new Image[n];
GL = gl;
fixed (uint* id = textureId)
{
GL.GenTextures(n, id);
}
GL.GenTextures(n, _textureHandle);
}
public void Activate(TextureUnit unit)
{
GL.ActiveTexture((uint)unit);
}
public void Bind2D(int index)
{
GL.BindTexture(GLconst.TEXTURE_2D, textureId[index]);
GL.BindTexture(GLconst.TEXTURE_2D, _textureHandle[index]);
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="index"></param>
/// <param name="loader"></param>
/// <param name="name"> </param>
/// <param name="index"> </param>
/// <param name="loader"> </param>
public unsafe void LoadTexture(int index, string name, ImageLoader loader)
{
sourceList[index] = new Image();
@@ -87,6 +77,11 @@ namespace StgSharp.Graphics
}
}
internal void ChangeEnvironment(IglFunc gl)
{
GL = gl;
}
#region texture set
public void Set2dFilterProperty(
@@ -103,13 +98,17 @@ namespace StgSharp.Graphics
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_T, (int)onVertical);
}
#endregion
public void Activate(TextureUnit unit)
{
GL.ActiveTexture((uint)unit);
}
#endregion texture set
}
public enum Filter
{
Nearest = GLconst.NEAREST,
Linear = GLconst.LINEAR,
Nearest_LinearMipmap = GLconst.NEAREST_MIPMAP_LINEAR,
Linear_LinearMipmap = GLconst.LINEAR_MIPMAP_LINEAR,
Nearest_NearestMipmap = GLconst.NEAREST_MIPMAP_NEAREST,
Linear_NearestMipmap = GLconst.LINEAR_MIPMAP_NEAREST,
}
public enum TextureUnit
@@ -139,15 +138,4 @@ namespace StgSharp.Graphics
ClampToEdge = GLconst.CLAMP_TO_EDGE,
ClampToBorder = GLconst.CLAMP_TO_BORDER,
}
public enum Filter
{
Nearest = GLconst.NEAREST,
Linear = GLconst.LINEAR,
Nearest_LinearMipmap = GLconst.NEAREST_MIPMAP_LINEAR,
Linear_LinearMipmap = GLconst.LINEAR_MIPMAP_LINEAR,
Nearest_NearestMipmap = GLconst.NEAREST_MIPMAP_NEAREST,
Linear_NearestMipmap = GLconst.LINEAR_MIPMAP_NEAREST,
}
}
@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
namespace System
{
/// <summary>
/// A handle to an OpenGL object.
/// </summary>
public unsafe class glHandle
{
private readonly uint[] _value;
internal int length;
internal uint* handle;
public uint this[int index]
{
get
{
if (index > length)
{
throw new IndexOutOfRangeException();
}
return *(handle + index);
}
set
{
if (index > length)
{
throw new IndexOutOfRangeException();
}
*(handle + index) = value;
}
}
public glHandle(int count)
{
_value = new uint[count];
length = count;
handle = (uint*)GCHandle.Alloc(_value, GCHandleType.Pinned).AddrOfPinnedObject();
}
internal glHandle(uint[] val)
{
_value = val;
length = val.Length;
handle = (uint*)GCHandle.Alloc(_value, GCHandleType.Pinned).AddrOfPinnedObject();
}
internal glHandle(uint val)
{
_value = [val];
length = 1;
handle = (uint*)GCHandle.Alloc(_value, GCHandleType.Pinned).AddrOfPinnedObject();
}
public void Free()
{
if (_value == null)
{
return;
}
GCHandle h = GCHandle.FromIntPtr((IntPtr)handle);
h.Free();
}
/// <summary>
/// Realse all resource in this handle.
/// This will release all resource in this <see cref="glHandle"/>.
/// This <see langword="glHandle"/> will be not usable.
/// </summary>
public void Release()
{
if (_value == null)
{
return;
}
else
{
GCHandle.FromIntPtr((IntPtr)handle).Free();
handle = (uint*)IntPtr.Zero;
}
}
}
}
+36 -22
View File
@@ -3,6 +3,7 @@ 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;
@@ -43,9 +44,9 @@ namespace StgSharp.Graphics
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.AttachShader(uint program, uint shader)
void IglFunc.AttachShader(glHandle program, glHandle shader)
{
api->glAttachShader(program, shader);
api->glAttachShader(program[0], shader[0]);
}
void IglFunc.BindBuffer(BufferType bufferType, uint index)
@@ -83,12 +84,12 @@ namespace StgSharp.Graphics
while (api->glGetError() != 0) { }
}
uint IglFunc.CompileShader(string shaderCode, ShaderType shaderType)
glHandle IglFunc.CompileShader(string shaderCode, ShaderType shaderType)
{
uint shaderID;
shaderCode += '\0';
shaderID = InternalIO.InternalLoadShaderCode(shaderCode, (int)shaderType);
if (shaderID == 0)
if (shaderID == 0) //compile error handler
{
IntPtr logPtr = InternalIO.InternalReadLog();
string log;
@@ -114,19 +115,32 @@ namespace StgSharp.Graphics
}
catch (Exception)
{
log = "Failed to compile shader.\nFailed to get GLSL compiler log";
log = "Failed to compile shader.\n" +
"Failed to get GLSL compiler log";
}
InternalIO.InternalWriteLog(log, LogType.Error);
}
return shaderID;
return new glHandle(shaderID);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
uint IglFunc.CreateProgram()
glHandle IglFunc.CreateProgram()
{
return api->glCreateProgram();
return new glHandle(api->glCreateProgram());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe glHandle IglFunc.CreateProgram(int count)
{
glHandle h = new glHandle(count);
uint* p = h.handle;
for (int i = 0; i < count; i++)
{
*(p + i) = api->glCreateProgram();
}
return h;
}
unsafe IntPtr IglFunc.CreateWindowHandle(
@@ -156,9 +170,9 @@ namespace StgSharp.Graphics
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe uint IglFunc.CreatGraphicProgram()
unsafe glHandle IglFunc.CreatGraphicProgram()
{
return api->glCreateProgram();
return new glHandle(api->glCreateProgram());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -167,17 +181,17 @@ namespace StgSharp.Graphics
api->glDeleteBuffers(1, &handle);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.DeleteBuffers(uint count, uint[] handle)
unsafe void IglFunc.DeleteBuffers(glHandle handle)
{
fixed (uint* ptr = handle)
api->glDeleteBuffers(count, ptr);
api->glDeleteBuffers((uint)handle.length, handle.handle);
handle.Free();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.DeleteVertexArrays(uint count, uint[] arrays)
unsafe void IglFunc.DeleteVertexArrays(glHandle arrays)
{
fixed (uint* ptr = arrays)
api->glDeleteVertexArrays(count, ptr);
api->glDeleteVertexArrays((uint)arrays.length, arrays.handle);
arrays.Free();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -206,20 +220,20 @@ namespace StgSharp.Graphics
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.GenBuffers(uint count, uint* ptr)
unsafe void IglFunc.GenBuffers(uint count, glHandle handle)
{
api->glGenBuffers(count, ptr);
api->glGenBuffers(count, handle.handle);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.GenTextures(uint count, uint* ptr)
unsafe void IglFunc.GenTextures(uint count, glHandle handle)
{
api->glGenTextures(count, ptr);
api->glGenTextures(count, handle.handle);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.GenVertexArrays(uint count, uint* ptr)
unsafe void IglFunc.GenVertexArrays(uint count, glHandle handle)
{
api->glGenVertexArrays(count, ptr);
api->glGenVertexArrays(count, handle.handle);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
+20 -11
View File
@@ -24,7 +24,7 @@ namespace StgSharp.Graphics
void IglFunc.AlignFrame(Form form) => throw signal;
void IglFunc.AttachShader(uint program, uint shader) => throw signal;
void IglFunc.AttachShader(glHandle program, glHandle shader) => throw signal;
void IglFunc.BindBuffer(BufferType bufferType, uint index) => throw signal;
@@ -38,27 +38,36 @@ namespace StgSharp.Graphics
void IglFunc.ClearGraphicError() => throw signal;
uint IglFunc.CompileShader(string shaderCode, ShaderType shaderType) => throw signal;
glHandle IglFunc.CompileShader(string shaderCode, ShaderType shaderType) => throw signal;
glHandle IglFunc.CreateProgram() => throw signal;
glHandle IglFunc.CreateProgram(int count) => throw signal;
uint IglFunc.CreateProgram() => throw signal;
IntPtr IglFunc.CreateWindowHandle(int width, int height, string tittle, IntPtr monitor, Form share) => throw signal;
uint IglFunc.CreatGraphicProgram() => throw signal;
glHandle IglFunc.CreatGraphicProgram() => throw signal;
public void DeleteBuffer(uint handle) => throw signal;
unsafe void IglFunc.DeleteBuffers(uint count, uint[] ptr) => throw signal;
void IglFunc.DeleteBuffers(glHandle handle) => throw signal;
void IglFunc.DeleteVertexArrays(glHandle handle) => throw signal;
unsafe void IglFunc.DeleteVertexArrays(uint count, uint[] ptr) => throw signal;
void IglFunc.DrawElements(GepmetryType mode, uint count, Type type, IntPtr ptr) => throw signal;
unsafe void IglFunc.GenBuffers(uint count, uint* ptr) => throw signal;
void IglFunc.GenBuffers(uint count, glHandle ptr) => throw signal;
unsafe void IglFunc.GenTextures(uint count, uint* ptr) => throw signal;
unsafe void IglFunc.GenVertexArrays(uint count, uint* ptr) => throw signal;
void IglFunc.GenTextures(uint count, glHandle handle) => throw signal;
void IglFunc.GenVertexArrays(uint count, glHandle handle) => throw signal;
void IglFunc.GetGraphicError() => throw signal;
@@ -90,6 +99,8 @@ namespace StgSharp.Graphics
void IglFunc.SetVertexAttribute(uint index, int size, Type t, bool normalized, uint stride, int pointer) => throw signal;
void IglFunc.SetWindowShouldClose(Form form, bool mark) => throw signal;
void IglFunc.SwapBuffers(Form form) => throw signal;
unsafe void IglFunc.TextureImage2d(uint target, int level, uint internalformat, uint width, uint height, uint format, uint type, void* pixels) => throw signal;
@@ -101,7 +112,5 @@ namespace StgSharp.Graphics
void IglFunc.Viewport(int x, int y, uint width, uint height) => throw signal;
internal static GLonTimeout Set() => singleInstance;
void IglFunc.SetWindowShouldClose(Form form, bool mark) => throw signal;
}
}
+43 -47
View File
@@ -18,9 +18,16 @@ namespace StgSharp.Graphics
{
internal GLonUpdateInternal glUpdateInternal;
private ConcurrentQueue<IntPtr> glActionQueue;
private ConcurrentQueue<Vec4d> glParamQueue;
private GLparamQueue paramQueue;
private FrameTimeoutException refreshSignal = new();
internal GLonUpdate(GLcontext* context)
{
glUpdateInternal = new GLonUpdateInternal();
paramQueue = glUpdateInternal.paramQueue;
glActionQueue = new ConcurrentQueue<IntPtr>();
}
internal ConcurrentQueue<IntPtr> GLactionQueue
{
get
@@ -28,18 +35,9 @@ namespace StgSharp.Graphics
return glActionQueue;
}
}
internal GLonUpdate(GLcontext* context)
{
glUpdateInternal = new GLonUpdateInternal();
glParamQueue = glUpdateInternal.paramQueue;
glActionQueue = new ConcurrentQueue<IntPtr>();
}
void IglFunc.ActiveTexture(uint type)
{
glParamQueue.Enqueue(new Vec4d(type));
paramQueue.Enqueue(type);
glActionQueue.Enqueue(glUpdateInternal.ActiveTexturePtr);
}
@@ -61,18 +59,17 @@ namespace StgSharp.Graphics
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.AttachShader(uint program, uint shader)
unsafe void IglFunc.AttachShader(glHandle program, glHandle shader)
{
glActionQueue.Enqueue(
() => api->glAttachShader(program, shader)
);
paramQueue.Enqueue(program[0], shader[0]);
glActionQueue.Enqueue(glUpdateInternal.AttachShaderPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.BindBuffer(BufferType bufferType, uint index)
{
glActionQueue.Enqueue(
() => api->glBindBuffer((uint)bufferType, index)
paramQueue.Enqueue((uint)bufferType, index);
glActionQueue.Enqueue(glUpdateInternal.BindBufferPtr
);
}
@@ -100,7 +97,7 @@ namespace StgSharp.Graphics
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.ClearColor(float R, float G, float B, float A)
{
glActionQueue.Enqueue(
@@ -108,6 +105,7 @@ namespace StgSharp.Graphics
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.ClearGraphicError()
{
glActionQueue.Enqueue(
@@ -119,9 +117,9 @@ namespace StgSharp.Graphics
}
uint IglFunc.CompileShader(string shaderCode, ShaderType shaderType)
glHandle IglFunc.CompileShader(string shaderCode, ShaderType shaderType)
{
int id = -1;
glHandle h = new glHandle(1);
glActionQueue.Enqueue(
() =>
{
@@ -162,14 +160,14 @@ namespace StgSharp.Graphics
Interlocked.Add(ref id, (int)(shaderID + 1));
}
);
while (id < 0) { }
return (uint)id;
return h;
}
uint IglFunc.CreateProgram()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
glHandle IglFunc.CreateProgram()
{
int id = -1;
glHandle h = new glHandle(1);
glActionQueue.Enqueue(
() =>
{
@@ -177,8 +175,13 @@ namespace StgSharp.Graphics
Interlocked.Add(ref id, ret + 1);
}
);
while (id < 0) { }
return (uint)id;
return h;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
glHandle IglFunc.CreateProgram(int count)
{
throw new NotImplementedException();
}
IntPtr IglFunc.CreateWindowHandle(int width, int height, string tittle, IntPtr monitor, Form share)
@@ -207,23 +210,17 @@ namespace StgSharp.Graphics
}
uint IglFunc.CreatGraphicProgram()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
glHandle IglFunc.CreatGraphicProgram()
{
int id = 0;
glHandle h = new glHandle(1);
glActionQueue.Enqueue(
() =>
{
Interlocked.Add(ref id, (int)(api->glCreateProgram() + 1));
}
);
while (id < 0) { }
return (uint)id;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.SetWindowShouldClose(Form form, bool mark)
{
InternalIO.glfw.SetWindowShouldClose(form.windowID, mark ? 1 : 0);
return h;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -238,7 +235,7 @@ namespace StgSharp.Graphics
);
}
unsafe void IglFunc.DeleteBuffers(uint count, uint[] handle)
unsafe void IglFunc.DeleteBuffers(glHandle handle)
{
glActionQueue.Enqueue(
() =>
@@ -252,7 +249,7 @@ namespace StgSharp.Graphics
);
}
unsafe void IglFunc.DeleteVertexArrays(uint count, uint[] arrays)
unsafe void IglFunc.DeleteVertexArrays(glHandle arrays)
{
glActionQueue.Enqueue(
() =>
@@ -293,27 +290,25 @@ namespace StgSharp.Graphics
);
}
unsafe void IglFunc.GenBuffers(uint count, uint* ptr)
unsafe void IglFunc.GenBuffers(uint count, glHandle handle)
{
glActionQueue.Enqueue(
() =>
{
api->glGenBuffers(count, ptr);
}
);
}
unsafe void IglFunc.GenTextures(uint count, uint* ptr)
unsafe void IglFunc.GenTextures(uint count, glHandle handle)
{
glActionQueue.Enqueue(
() =>
{
api->glGenTextures(count, ptr);
}
);
}
unsafe void IglFunc.GenVertexArrays(uint count, uint* ptr)
unsafe void IglFunc.GenVertexArrays(uint count, glHandle ptr)
{
glActionQueue.Enqueue(
() =>
@@ -347,8 +342,6 @@ namespace StgSharp.Graphics
return ret;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
bool IglFunc.GetWindowShouldClose(Form form)
{
@@ -410,14 +403,12 @@ namespace StgSharp.Graphics
);
}
void IglFunc.SetFrameBufferSizeCallback(IntPtr id, FrameBufferSizeHandler handler)
{
IntPtr handlerPtr = Marshal.GetFunctionPointerForDelegate(handler);
InternalIO.glfw.SetFramebufferSizeCallback(id, handlerPtr);
}
void IglFunc.SetVertexAttribute(uint index, int size, Type t, bool normalized, uint stride, int pointer)
{
glActionQueue.Enqueue(
@@ -430,6 +421,11 @@ namespace StgSharp.Graphics
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.SetWindowShouldClose(Form form, bool mark)
{
InternalIO.glfw.SetWindowShouldClose(form.windowID, mark ? 1 : 0);
}
void IglFunc.SwapBuffers(Form form)
{
glActionQueue.Enqueue(
@@ -10,25 +10,414 @@ using System.Threading.Tasks;
namespace StgSharp.Graphics
{
internal unsafe struct GLonUpdateInternal
internal unsafe struct GLonUpdateInternal : IglFunc
{
private GLcontext* gl;
internal ConcurrentQueue<Vec4d> paramQueue;
public IntPtr ActiveTexturePtr;
public IntPtr AttachShaderPtr;
public IntPtr BindBufferPtr;
internal IntPtr ClearColorPtr;
internal IntPtr ClearGraphicErrorPtr;
internal IntPtr CompileShaderPtr;
internal GLparamQueue paramQueue;
private GLcontext* gl;
public GLonUpdateInternal(GLcontext* api)
{
gl = api;
ActiveTexturePtr = Marshal.GetFunctionPointerForDelegate(ActiveTexture);
}
private void ActiveTexture()
public void ActivePointer()
{
uint type;
IglFunc gl = this;
ActiveTexturePtr = Marshal.GetFunctionPointerForDelegate(gl.ActiveTexture);
AttachShaderPtr = Marshal.GetFunctionPointerForDelegate(gl.AttachShader);
BindBufferPtr = Marshal.GetFunctionPointerForDelegate(gl.BindBuffer);
CompileShaderPtr = Marshal.GetFunctionPointerForDelegate(gl.CompileShader);
}
void IglFunc.ActiveTexture(uint type)
{
uint t;
paramQueue.TryDequeue(out t);
gl->glActiveTexture(t);
}
void IglFunc.AfterAlign(Form form, Action action)
{
throw new NotImplementedException();
}
void IglFunc.AlignFrame(Form form)
{
throw new NotImplementedException();
}
void IglFunc.AttachShader(glHandle program, glHandle shader)
{
uint p, s;
paramQueue.TryDequeue(out p, out s);
gl->glAttachShader(p, s);
}
void IglFunc.BindBuffer(BufferType bufferType, uint index)
{
uint t, i;
paramQueue.TryDequeue(out t, out i);
gl->glBindBuffer(t, i);
}
void IglFunc.BindTexture(uint type, uint texture)
{
uint t, te;
paramQueue.TryDequeue(out t, out te);
gl->glBindTexture(t, te);
}
void IglFunc.BindVertexArray(uint index)
{
uint i;
paramQueue.TryDequeue(out i);
gl->glBindVertexArray(i);
}
void IglFunc.Clear(MaskBufferBit mask)
{
uint mt;
paramQueue.TryDequeue(out mt);
gl->glClear(mt);
}
void IglFunc.ClearColor(float R, float G, float B, float A)
{
float r, g, b, a;
paramQueue.TryDequeue(out r, out g, out b, out a);
gl->glClearColor(r, g, b, a);
}
void IglFunc.ClearGraphicError()
{
while (gl->glGetError() != 0) { }
}
glHandle IglFunc.CompileShader(string shaderCode, ShaderType shaderType)
{
IntPtr shaderHandle, codeHandle;
paramQueue.TryDequeue(out codeHandle, out shaderHandle);
uint shaderID;
shaderCode += '\0';
shaderID = InternalIO.InternalLoadShaderCode(shaderCode, (int)shaderType);
if (shaderID == 0)
{
IntPtr logPtr = InternalIO.InternalReadLog();
string log;
try
{
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)
{
if (!char.IsControl(item))
{
isUseful = true; break;
}
}
if (!isUseful)
{
throw new Exception();
}
}
catch (Exception)
{
log = "Failed to compile shader.\nFailed to get GLSL compiler log";
}
InternalIO.InternalWriteLog(log, LogType.Error);
}
*(uint*)shaderHandle = shaderID;
return default;
}
glHandle IglFunc.CreateProgram()
{
throw new NotImplementedException();
}
glHandle IglFunc.CreateProgram(int count)
{
throw new NotImplementedException();
}
IntPtr IglFunc.CreateWindowHandle(int width, int height, string tittle, IntPtr monitor, Form share)
{
throw new NotImplementedException();
}
glHandle IglFunc.CreatGraphicProgram()
{
throw new NotImplementedException();
}
void IglFunc.DeleteBuffer(uint handle)
{
throw new NotImplementedException();
}
void IglFunc.DeleteBuffers(glHandle handle)
{
throw new NotImplementedException();
}
void IglFunc.DeleteVertexArrays(glHandle arrays)
{
throw new NotImplementedException();
}
void IglFunc.DrawElements(GepmetryType mode, uint count, Type type, IntPtr ptr)
{
throw new NotImplementedException();
}
void IglFunc.GenBuffers(uint count, glHandle ptr)
{
throw new NotImplementedException();
}
void IglFunc.GenTextures(uint count, glHandle ptr)
{
throw new NotImplementedException();
}
void IglFunc.GenVertexArrays(uint count, glHandle ptr)
{
throw new NotImplementedException();
}
void IglFunc.GetGraphicError()
{
throw new NotImplementedException();
}
int IglFunc.GetUniformLocation(uint program, byte* ptr)
{
throw new NotImplementedException();
}
bool IglFunc.GetWindowShouldClose(Form form)
{
throw new NotImplementedException();
}
void IglFunc.MakeContexCurrent(Form form)
{
throw new NotImplementedException();
}
void IglFunc.SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
{
throw new NotImplementedException();
}
void IglFunc.SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
{
throw new NotImplementedException();
}
void IglFunc.SetFrameBufferSizeCallback(IntPtr id, FrameBufferSizeHandler handler)
{
throw new NotImplementedException();
}
void IglFunc.SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
{
throw new NotImplementedException();
}
void IglFunc.SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
{
throw new NotImplementedException();
}
void IglFunc.SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
{
throw new NotImplementedException();
}
void IglFunc.SetValue(Uniform<float, float> uniform, float v0, float v1)
{
throw new NotImplementedException();
}
void IglFunc.SetValue(Uniform<float> uniform, float v0)
{
throw new NotImplementedException();
}
void IglFunc.SetValue(Uniform<int> uniform, int i0)
{
throw new NotImplementedException();
}
void IglFunc.SetValue(Uniform<Vec4d> uniform, Vec4d vec)
{
throw new NotImplementedException();
}
void IglFunc.SetVertexAttribute(uint index, int size, Type t, bool normalized, uint stride, int pointer)
{
throw new NotImplementedException();
}
void IglFunc.SetWindowShouldClose(Form form, bool mark)
{
throw new NotImplementedException();
}
void IglFunc.SwapBuffers(Form form)
{
throw new NotImplementedException();
}
void IglFunc.TextureImage2d(uint target, int level, uint internalformat, uint width, uint height, uint format, uint type, void* pixels)
{
throw new NotImplementedException();
}
void IglFunc.TextureParameter(uint target, uint pname, int param)
{
throw new NotImplementedException();
}
void IglFunc.UseProgram(uint program)
{
throw new NotImplementedException();
}
void IglFunc.Viewport(int x, int y, uint width, uint height)
{
throw new NotImplementedException();
}
}
internal unsafe class GLparamQueue
{
private ConcurrentQueue<M128> paramQueue;
public GLparamQueue()
{
paramQueue = new ConcurrentQueue<M128>();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(Vec4d v)
{
paramQueue.Enqueue(v);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(uint u0)
{
M128 m = default;
m.UInt32[0] = u0;
paramQueue.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(uint u0, uint u1)
{
M128 m = default;
m.UInt32[0] = u0;
m.UInt32[1] = u1;
paramQueue.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(float f0, float f1, float f2, float f3)
{
M128 m = default;
m.Single[0] = f0;
m.Single[1] = f1;
m.Single[2] = f2;
m.Single[3] = f3;
paramQueue.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(IntPtr p0, IntPtr p1)
{
M128 m = default;
m.IntPtr0 = p0;
m.IntPtr1 = p1;
paramQueue.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out IntPtr p0, out IntPtr p1)
{
M128 ret;
if (paramQueue.TryDequeue(out ret))
{
p0 = ret.IntPtr0;
p1 = ret.IntPtr1;
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out float f0, out float f1, out float f2, out float f3)
{
M128 ret;
if (paramQueue.TryDequeue(out ret))
{
f0 = ret.UInt32[0];
f1 = ret.UInt32[1];
f2 = ret.UInt32[2];
f3 = ret.UInt32[3];
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out uint u0)
{
M128 ret;
if (paramQueue.TryDequeue(out ret))
{
u0 = ret.UInt32[0];
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out uint u0, out uint u1)
{
M128 ret;
if (paramQueue.TryDequeue(out ret))
{
u0 = ret.UInt32[0];
u1 = ret.UInt32[1];
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
}
}
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public partial class Form
{
/// <summary>
/// Create a set of <see cref="ElementBuffer"/>.
/// </summary>
/// <param name="count">Amount of EBO to be created.</param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected ElementBuffer CreateElementBuffer(uint count)
{
return new ElementBuffer(count, this.gl);
}
/// <summary>
/// Create a set of <see cref="VertexArray"/>.
/// </summary>
/// <param name="count">Amount of VAO to be crated.</param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected VertexArray CreateVertexArray(uint count)
{
return new VertexArray(count, gl);
}
/// <summary>
/// Create a sets of <see cref="Texture"/>
/// </summary>
/// <param name="n">Amount of textures to be crated.</param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected Texture CreateTexture(uint n)
{
return new Texture(n, this.GL);
}
/// <summary>
/// Create aset of <see cref="VertexBuffer"/>.
/// </summary>
/// <param name="count">Amount of Object to be created.</param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected VertexBuffer CreateVertexBuffer(uint count)
{
return new VertexBuffer(count, gl);
}
}
}
@@ -20,23 +20,24 @@ namespace StgSharp.Graphics
}
}
public class Shader
{
/// <summary>
/// A <see cref="uint"/> value represent this shader.
/// </summary>
public readonly uint programID;
internal uint vertexShaderID;
internal uint fragmentShaderID;
internal readonly glHandle Handle;
public readonly ShaderType type;
private IglFunc GL;
/// <summary>
/// Inti a shader with no program attached.
/// </summary>
internal unsafe Shader(IglFunc gl)
internal unsafe Shader(IglFunc gl, ShaderType t, int count)
{
GL = gl;
programID = GL.CreateProgram();
type = t;
if (type == ShaderType.Program)
{
Handle = GL.CreateProgram();
}
}
internal void ChangeEnvironment(IglFunc gl)
@@ -48,10 +49,10 @@ namespace StgSharp.Graphics
/// Compile the vertex shader to be attached to this shader.
/// </summary>
/// <param name="shaderCode">GLSL code of vertex shader.</param>
public unsafe void CompileVertexShader(string shaderCode)
public unsafe void CompileShader(string shaderCode)
{
vertexShaderID = GL.CompileShader(shaderCode, ShaderType.VERTEX);
GL.AttachShader(programID, vertexShaderID);
vertexHandle = GL.CompileShader(shaderCode, type);
GL.AttachShader(programHandle, vertexHandle);
}
/// <summary>
@@ -60,8 +61,8 @@ namespace StgSharp.Graphics
/// <param name="shaderCode">GLSL code of fragment shader.</param>
public unsafe void CompileFragmentShader(string shaderCode)
{
fragmentShaderID = GL.CompileShader(shaderCode, ShaderType.FRAGMENT);
GL.AttachShader(programID, fragmentShaderID);
fragmentHandle = GL.CompileShader(shaderCode, ShaderType.FRAGMENT);
GL.AttachShader(programHandle, fragmentHandle);
}
/// <summary>
@@ -69,7 +70,7 @@ namespace StgSharp.Graphics
/// </summary>
public void Link()
{
if (InternalIO.InternalLinkShaderProgram(programID) == 0)
if (InternalIO.InternalLinkShaderProgram(programHandle) == 0)
{
IntPtr logPtr = InternalIO.InternalReadLog();
try
@@ -99,7 +100,7 @@ namespace StgSharp.Graphics
int uniform;
fixed (byte* ptr = bytes)
{
uniform = GL.GetUniformLocation(programID, ptr);
uniform = GL.GetUniformLocation(programHandle, ptr);
}
if (uniform != -1)
{
@@ -107,7 +108,7 @@ namespace StgSharp.Graphics
}
else
{
throw new Exception($"Cannot find the uniform {name} in shader {programID}");
throw new Exception($"Cannot find the uniform {name} in shader {programHandle}");
}
}
/// <summary>
@@ -124,7 +125,7 @@ namespace StgSharp.Graphics
int uniform;
fixed (byte* ptr = bytes)
{
uniform = GL.GetUniformLocation(programID, ptr);
uniform = GL.GetUniformLocation(programHandle, ptr);
}
if (uniform != -1)
{
@@ -132,7 +133,7 @@ namespace StgSharp.Graphics
}
else
{
throw new Exception($"Cannot find the uniform {name} in shader {programID}");
throw new Exception($"Cannot find the uniform {name} in shader {programHandle}");
}
}
/// <summary>
@@ -150,7 +151,7 @@ namespace StgSharp.Graphics
int uniform;
fixed (byte* ptr = bytes)
{
uniform = GL.GetUniformLocation(programID, ptr);
uniform = GL.GetUniformLocation(programHandle, ptr);
}
if (uniform != -1)
{
@@ -158,7 +159,7 @@ namespace StgSharp.Graphics
}
else
{
throw new Exception($"Cannot find the uniform {name} in shader {programID}");
throw new Exception($"Cannot find the uniform {name} in shader {programHandle}");
}
}
@@ -168,7 +169,7 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Use()
{
GL.UseProgram(programID);
GL.UseProgram(programHandle);
}
}
+32 -18
View File
@@ -36,11 +36,14 @@ namespace StgSharp.Graphics
void AlignFrame(Form form);
/// <summary>
/// Same fucntion as OpenGL api glAttachShader
/// Same fucntion as OpenGL api glAttachShader.
/// Only the first <see href="shader"/> in handle
/// will be attached to the first <see href="program"/> in handle.
/// The rest shader and program will be ignored.
/// </summary>
/// <param name="program">Shader program to be attachec</param>
/// <param name="shader">A shader part to attach</param>
void AttachShader(uint program, uint shader);
void AttachShader(glHandle program, glHandle shader);
/// <summary>
/// Bind the indexed buffer object to certain type of buffer
@@ -87,19 +90,25 @@ namespace StgSharp.Graphics
/// <param name="shaderCode">A string represent the shader's code</param>
/// <param name="shaderType">An <see cref="ShaderType"/> enum represent the type of the shader to
/// conpile, including vertex shader and fragment shader.</param>
/// <returns>An uint value as the only mark of conpiled shader</returns>
uint CompileShader(string shaderCode, ShaderType shaderType);
/// <returns>An handle of conpiled shader</returns>
glHandle CompileShader(string shaderCode, ShaderType shaderType);
/// <summary>
/// Same function as OpenGL api, glCreateProgram
/// </summary>
/// <returns></returns>
uint CreateProgram();
/// <returns>A handle representing a single shader program</returns>
glHandle CreateProgram();
/// <summary>
/// Same function as OpenGL api, glCreateProgram.
/// Used for creating multiple shader program.
/// </summary>
/// <returns>A handle representing all shader programs</returns>
glHandle CreateProgram(int count);
/// <summary>
/// Creates a form and its associated
/// </summary>
/// <param name="handle">The instance of created form</param>
/// <param name="width">Required width</param>
/// <param name="height">Required width</param>
/// <param name="tittle">Tittle of the window </param>
@@ -108,7 +117,7 @@ namespace StgSharp.Graphics
/// <exception cref="Exception"></exception>
IntPtr CreateWindowHandle(int width, int height, string tittle, IntPtr monitor, Form share);
uint CreatGraphicProgram();
glHandle CreatGraphicProgram();
/// <summary>
/// Same function as OpenGL api, glDeleteBuffer. This method can delete one buffer in one call
@@ -119,17 +128,22 @@ namespace StgSharp.Graphics
/// <summary>
/// Same function as OpenGL api, glDeleteBuffer. This method can delete a sets of buffers in one call.
/// </summary>
/// <param name="count">Amount of bufferd to be deleted</param>
/// <param name="handle">Array of buffers to be deleted</param>
unsafe void DeleteBuffers(uint count, uint[] handle);
unsafe void DeleteBuffers(glHandle handle);
/// <summary>
/// Same function as OpenGL api, glDeleteVertexArrays
/// </summary>
/// <param name="count">Amount of vao to be deleted</param>
/// <param name="arrays">A array representing a colletion of vertex objects.</param>
unsafe void DeleteVertexArrays(uint count, uint[] arrays);
/// <param name="handle">Handle of vertex objects.</param>
unsafe void DeleteVertexArrays(glHandle handle);
/// <summary>
///
/// </summary>
/// <param name="mode"></param>
/// <param name="count"></param>
/// <param name="type"></param>
/// <param name="ptr"></param>
void DrawElements(GepmetryType mode, uint count, Type type, IntPtr ptr);
/// <summary>
@@ -137,21 +151,21 @@ namespace StgSharp.Graphics
/// </summary>
/// <param name="count"></param>
/// <param name="ptr"></param>
unsafe void GenBuffers(uint count, uint* ptr);
unsafe void GenBuffers(uint count, glHandle ptr);
/// <summary>
/// Same fucnction as OpenGL api glGenTextures.
/// </summary>
/// <param name="count">amount of textures to generate</param>
/// <param name="ptr">pointer to texture signs' array</param>
unsafe void GenTextures(uint count, uint* ptr);
/// <param name="handle">Handle of texture</param>
unsafe void GenTextures(uint count, glHandle handle);
/// <summary>
/// Same fucntion as OpenGL api, glGenVertexArray
/// </summary>
/// <param name="count">Amount of vao to be generated</param>
/// <param name="ptr">Pointer of vao sign array</param>
unsafe void GenVertexArrays(uint count, uint* ptr);
/// <param name="handle">Handle of vao sign array</param>
unsafe void GenVertexArrays(uint count, glHandle handle);
void GetGraphicError();
+25 -42
View File
@@ -1,70 +1,53 @@
using StgSharp.Controlling;
using StgSharp.Math;
using System.Data.Common;
using System.Numerics;
using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Sequential)]
internal struct M128F
[StructLayout(LayoutKind.Explicit)]
public unsafe struct M128
{
internal float X;
internal float Y;
internal float Z;
internal float W;
[FieldOffset(0)] internal fixed float Single[4];
[FieldOffset(0)] internal fixed double Double[2];
[FieldOffset(0)] internal fixed sbyte Int8[16];
[FieldOffset(0)] internal fixed short Int16[8];
[FieldOffset(0)] internal fixed int Int32[4];
[FieldOffset(0)] internal fixed long Int64[2];
[FieldOffset(0)] internal fixed byte UInt8[16];
[FieldOffset(0)] internal fixed ushort UInt16[8];
[FieldOffset(0)] internal fixed uint UInt32[4];
[FieldOffset(0)] internal fixed ulong UInt64[2];
[FieldOffset(0)] internal IntPtr IntPtr0;
[FieldOffset(1)] internal IntPtr IntPtr1;
}
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
public struct Vec4d
{
[FieldOffset(0)] internal Vector4 vec;
[FieldOffset(0)] internal M128F fvec;
[FieldOffset(0)] internal M128 reg;
[FieldOffset(0)] public float X;
[FieldOffset(4)] public float Y;
[FieldOffset(8)] public float Z;
[FieldOffset(12)] public float W;
[FieldOffset(0)] public int X_int;
[FieldOffset(4)] public int Y_int;
[FieldOffset(8)] public int Z_int;
[FieldOffset(12)] public int W_int;
[FieldOffset(0)] public uint X_uint;
[FieldOffset(4)] public uint Y_uint;
[FieldOffset(8)] public uint Z_uint;
[FieldOffset(12)] public uint W_uint;
[FieldOffset(0)] public long X_long;
[FieldOffset(8)] public long Y_long;
[FieldOffset(0)] public long X_ulong;
[FieldOffset(8)] public long Y_ulong;
[FieldOffset(0)] public byte byte_0;
[FieldOffset(1)] public byte byte_1;
[FieldOffset(2)] public byte byte_2;
[FieldOffset(3)] public byte byte_3;
[FieldOffset(4)] public byte byte_4;
[FieldOffset(5)] public byte byte_5;
[FieldOffset(6)] public byte byte_6;
[FieldOffset(7)] public byte byte_7;
[FieldOffset(8)] public byte byte_8;
[FieldOffset(9)] public byte byte_9;
[FieldOffset(10)] public byte byte_10;
[FieldOffset(11)] public byte byte_11;
[FieldOffset(12)] public byte byte_12;
[FieldOffset(13)] public byte byte_13;
[FieldOffset(14)] public byte byte_14;
[FieldOffset(15)] public byte byte_15;
public Vec4d(
float x, float y, float z, float w)
{
X = x; Y = y; Z = z; W = w;
}
internal Vec4d(uint x) => X_uint = x;
public static implicit operator M128(Vec4d vec)
{
return vec.reg;
}
}
}
+17 -1
View File
@@ -14,13 +14,17 @@
<AnalysisLevel>preview-all</AnalysisLevel>
<OutputType>Library</OutputType>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;NoOps;RealDebug</Configurations>
<Configurations>Debug;Release;NoOps;RealDebug;Benchmark</Configurations>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Optimize>True</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Benchmark|x64'">
<Optimize>True</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RealDebug|x64'">
<Optimize>True</Optimize>
</PropertyGroup>
@@ -31,6 +35,12 @@
<NoWarn>1701;1702;0649;1591;0169</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Benchmark|x64'">
<Optimize>True</Optimize>
<DebugType>embedded</DebugType>
<NoWarn>1701;1702;0649;1591;0169</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RealDebug|x64'">
<Optimize>True</Optimize>
<DebugType>embedded</DebugType>
@@ -43,6 +53,12 @@
<NoWarn>1701;1702;0649;1591;0169</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Benchmark|AnyCPU'">
<DebugType>embedded</DebugType>
<Optimize>True</Optimize>
<NoWarn>1701;1702;0649;1591;0169</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RealDebug|AnyCPU'">
<DebugType>embedded</DebugType>
<Optimize>True</Optimize>
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
@@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Benchmark")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// 由 MSBuild WriteCodeFragment 类生成。
@@ -0,0 +1 @@
c782ea188f9ee670e520e8011602cc522e95f62c52058a3f3649f6c7b720223f
@@ -0,0 +1,13 @@
is_global = true
build_property.TargetFramework = netstandard2.1
build_property.TargetPlatformMinVersion = 7.0
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = StgSharp
build_property.ProjectDir = D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
@@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// 由 MSBuild WriteCodeFragment 类生成。
@@ -0,0 +1 @@
e8b19b35bca753348ef94df4faf984102d2e81946d465d23132400b7d6c8fb6d
@@ -0,0 +1,13 @@
is_global = true
build_property.TargetFramework = netstandard2.1
build_property.TargetPlatformMinVersion = 7.0
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = StgSharp
build_property.ProjectDir = D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
@@ -0,0 +1 @@
24c5df41ae49edf025d2ed9b429a230b0b1d6265c75acbe5047db47eef8de12f
@@ -0,0 +1,6 @@
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\obj\x64\Debug\netstandard2.1\StgSharp.csproj.AssemblyReference.cache
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\obj\x64\Debug\netstandard2.1\StgSharp.GeneratedMSBuildEditorConfig.editorconfig
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\obj\x64\Debug\netstandard2.1\StgSharp.AssemblyInfoInputs.cache
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\obj\x64\Debug\netstandard2.1\StgSharp.AssemblyInfo.cs
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\obj\x64\Debug\netstandard2.1\StgSharp.csproj.CoreCompileInputs.cache
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\obj\x64\Debug\netstandard2.1\StgSharp.sourcelink.json
@@ -0,0 +1 @@
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/8148c10acd65bd764d3e12418a1ebd37938d8501/*"}}
@@ -1 +1 @@
a17d2db0cff348a20c6b942c4e896961df0865a7
325fd20b7cecc12107d64856bd314604a71db361d7a8920198f265b6aa4fc835
@@ -9,3 +9,5 @@ build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = StgSharp
build_property.ProjectDir = D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("RealDebug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ae804553ce830ceaa07a752049a8a8fee9981ad8")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8148c10acd65bd764d3e12418a1ebd37938d8501")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
ef774f8e221005539f6096a7006906b62494ddf898c07bc1b1142c4f67324745
ca93447f31769911dc8294620befd7f0decfe42c9da322cc9f2b829b17d173fb
@@ -1 +1 @@
e6e7a7ff7c8acfcc09d9871e7b0b8915601d076ce02bbd3bab9c398a458d904d
14600979b7047444373c4005ac1629cd56f39a50173cc96850f6c359889fb1d1
@@ -1 +1 @@
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/ae804553ce830ceaa07a752049a8a8fee9981ad8/*"}}
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/8148c10acd65bd764d3e12418a1ebd37938d8501/*"}}