daily update on 20240312 by nitload youmu
This commit is contained in:
@@ -29,7 +29,6 @@ namespace StgSharp.Graphics
|
||||
public void SetValue<T>(int index, T[] bufferArray, BufferUsage usage)
|
||||
where T : struct, IConvertible
|
||||
{
|
||||
Console.WriteLine("Setting ebo data.");
|
||||
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ELEMENT_ARRAY_BUFFER, bufferArray, usage);
|
||||
}
|
||||
|
||||
@@ -30,9 +30,8 @@ namespace StgSharp.Graphics
|
||||
/// <param name="index">Index to find certain VBO in this instance</param>
|
||||
/// <param name="bufferData">Data to write in</param>
|
||||
/// <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
|
||||
public void SetValue<T>(int index, T bufferData, BufferUsage usage) where T : struct, IMat
|
||||
{
|
||||
Console.WriteLine("Setting vbo data.");
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferData, usage);
|
||||
}
|
||||
|
||||
@@ -11,33 +11,6 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
//TODO 发现一个大问题,paramQueue大多数时候取出的是数组,不是数组句柄,也就是说其内存将被长期固定且不能回收,这是内存泄漏
|
||||
public unsafe class glArrayHandle
|
||||
{
|
||||
internal readonly Array copy;
|
||||
internal GCHandle handle;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public IntPtr AddressOfArray()
|
||||
{
|
||||
return handle.AddrOfPinnedObject();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static glArrayHandle Alloc<T>(T[] array) where T : struct
|
||||
{
|
||||
Array copy = new T[array.Length];
|
||||
array.CopyTo(copy, 0);
|
||||
return new glArrayHandle(copy);
|
||||
}
|
||||
|
||||
internal glArrayHandle(Array array)
|
||||
{
|
||||
copy = array;
|
||||
handle = GCHandle.Alloc(array, GCHandleType.Pinned);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A handle to an OpenGL object,
|
||||
/// must be indexed from a <see cref="glHandleSet"/>.
|
||||
@@ -139,7 +112,7 @@ namespace StgSharp.Graphics
|
||||
|
||||
public static glSHandle Zero
|
||||
{
|
||||
get { return Alloc(1); }
|
||||
get { return Alloc(0); }
|
||||
}
|
||||
|
||||
internal int DirectValue
|
||||
@@ -157,6 +130,52 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
//TODO 发现一个大问题,paramQueue大多数时候取出的是数组,不是数组句柄,也就是说其内存将被长期固定且不能回收,这是内存泄漏
|
||||
public unsafe class glArrayHandle
|
||||
{
|
||||
internal readonly Array a;
|
||||
internal GCHandle handle;
|
||||
|
||||
internal glArrayHandle(Array array)
|
||||
{
|
||||
this.a = array;
|
||||
handle = GCHandle.Alloc(array, GCHandleType.Pinned);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static glArrayHandle CopyAlloc<T>(T[] array) where T : struct
|
||||
{
|
||||
Array copy = new T[array.Length];
|
||||
array.CopyTo(copy, 0);
|
||||
return new glArrayHandle(copy);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static glArrayHandle Alloc<T>(T[] array) where T : struct
|
||||
{
|
||||
return new glArrayHandle(array);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public IntPtr AddressOfArray()
|
||||
{
|
||||
if (handle != default)
|
||||
{
|
||||
return handle.AddrOfPinnedObject();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
handle.Free();
|
||||
handle = default;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A handle to an OpenGL object.
|
||||
/// </summary>
|
||||
|
||||
@@ -336,5 +336,12 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
api->glViewport(x, y, width, height);
|
||||
}
|
||||
|
||||
void IglFunc.frameworkHandleEnqueue(System.IntPtr handle, params StgSharp.Math.M128[] param)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
bool IglFunc.FrameCanUpdate => true;
|
||||
}
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
internal class GLonTimeout : IglFunc
|
||||
{
|
||||
private static readonly GLonTimeout singleInstance
|
||||
= new GLonTimeout();
|
||||
|
||||
private FrameTimeoutException refreshSIgnal = new FrameTimeoutException();
|
||||
private FrameTimeoutException signal = new FrameTimeoutException("This frame is timeout");
|
||||
|
||||
private GLonTimeout()
|
||||
{ }
|
||||
|
||||
unsafe GLcontext* IglFunc.Context => throw signal;
|
||||
|
||||
void IglFunc.ActiveTexture(uint type) => throw signal;
|
||||
|
||||
void IglFunc.AfterAlign(Form form, Action action) => throw signal;
|
||||
|
||||
void IglFunc.AlignFrame(Form form) => throw signal;
|
||||
|
||||
void IglFunc.AttachShader(glHandle program, glHandle shader) => throw signal;
|
||||
|
||||
void IglFunc.BindBuffer(BufferType bufferType, glHandle handle) => throw signal;
|
||||
|
||||
void IglFunc.BindTexture(uint type, glHandle texture) => throw signal;
|
||||
|
||||
void IglFunc.BindVertexArray(glHandle handle) => throw signal;
|
||||
|
||||
void IglFunc.Clear(MaskBufferBit mask) => throw signal;
|
||||
|
||||
void IglFunc.ClearColor(float R, float G, float B, float A) => throw signal;
|
||||
|
||||
void IglFunc.ClearGraphicError() => throw signal;
|
||||
|
||||
public void CompileShader(glHandle shaderhandle)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
|
||||
glHandle IglFunc.CreateProgram() => throw signal;
|
||||
|
||||
glHandleSet IglFunc.CreateProgram(int count) => throw signal;
|
||||
|
||||
glHandleSet IglFunc.CreateShaderSet(int count, StgSharp.Graphics.ShaderType type) => throw signal;
|
||||
|
||||
IntPtr IglFunc.CreateWindowHandle(int width, int height, string tittle, IntPtr monitor, Form share) => throw signal;
|
||||
|
||||
glHandle IglFunc.CreatGraphicProgram() => throw signal;
|
||||
|
||||
void IglFunc.DeleteBuffer(glHandle handle) => throw signal;
|
||||
|
||||
void IglFunc.DeleteBuffers(glHandleSet handle) => throw signal;
|
||||
|
||||
void IglFunc.DeleteVertexArrays(glHandleSet handle) => throw signal;
|
||||
|
||||
void IglFunc.DrawElements(GepmetryType mode, uint count, TypeCode type, IntPtr ptr) => throw signal;
|
||||
|
||||
glHandleSet IglFunc.GenBuffers(int count) => throw signal;
|
||||
|
||||
glHandleSet IglFunc.GenTextures(int count) => throw signal;
|
||||
|
||||
glHandleSet IglFunc.GenVertexArrays(int count) => throw signal;
|
||||
|
||||
unsafe glSHandle IglFunc.GetUniformLocation(glHandle program, string name) => throw signal;
|
||||
|
||||
bool IglFunc.GetWindowShouldClose(Form form) => throw signal;
|
||||
|
||||
void IglFunc.LoadShaderSource(glHandle shaderHandle, string codeStream)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
|
||||
void IglFunc.MakeContexCurrent(Form form) => throw signal;
|
||||
|
||||
void IglFunc.SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage) => throw signal;
|
||||
|
||||
void IglFunc.SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage) => throw signal;
|
||||
|
||||
void IglFunc.SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3) => throw signal;
|
||||
|
||||
void IglFunc.SetValue(Uniform<float, float, float, float> uniform, Vec4d vec) => throw signal;
|
||||
|
||||
void IglFunc.SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2) => throw signal;
|
||||
|
||||
void IglFunc.SetValue(Uniform<float, float> uniform, float v0, float v1) => throw signal;
|
||||
|
||||
void IglFunc.SetValue(Uniform<float> uniform, float v0) => throw signal;
|
||||
|
||||
void IglFunc.SetValue(Uniform<int> uniform, int i0) => throw signal;
|
||||
|
||||
void IglFunc.SetValue(Uniform<Vec4d> uniform, Vec4d vec) => throw signal;
|
||||
|
||||
void IglFunc.SetVertexAttribute(uint index, int size, TypeCode t, bool normalized, uint stride, int pointer) => throw signal;
|
||||
|
||||
void IglFunc.SwitchContext()
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
|
||||
unsafe void IglFunc.TextureImage2d<T>(int target, int level, uint internalformat, uint width, uint height, uint format, uint type, glHandle pixels) => throw signal;
|
||||
|
||||
void IglFunc.TextureParameter(int target, uint pname, int param) => throw signal;
|
||||
|
||||
void IglFunc.UseProgram(glHandle program) => throw signal;
|
||||
|
||||
void IglFunc.Viewport(int x, int y, uint width, uint height) => throw signal;
|
||||
|
||||
internal static GLonTimeout Set() => singleInstance;
|
||||
}
|
||||
}
|
||||
@@ -15,24 +15,17 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
internal unsafe partial class GLonUpdate : IglFunc
|
||||
{
|
||||
private static ConcurrentQueue<IntPtr> glActionQueue;
|
||||
private static GLparamQueue paramQueue;
|
||||
private static FrameOperationBuffer frameOpBuffer;
|
||||
private GLcontext* api;
|
||||
private FrameTimeoutException refreshSignal = new();
|
||||
private IntPtr SwapBufferPtr = (IntPtr)(delegate*<IntPtr, void>)&InternalIO.glfwSwapBuffers;
|
||||
|
||||
internal void ShowDequeueStream()
|
||||
{
|
||||
paramQueue.ShowDequeueLog();
|
||||
}
|
||||
private glSHandle unupdatedFrame = glSHandle.Alloc(0);
|
||||
|
||||
internal GLonUpdate(GLcontext* context)
|
||||
{
|
||||
if (paramQueue == null)
|
||||
if (frameOpBuffer == null)
|
||||
{
|
||||
paramQueue = new GLparamQueue();
|
||||
frameOpBuffer = new FrameOperationBuffer();
|
||||
}
|
||||
glActionQueue = new ConcurrentQueue<IntPtr>();
|
||||
api = context;
|
||||
}
|
||||
|
||||
@@ -41,23 +34,16 @@ namespace StgSharp.Graphics
|
||||
get => api;
|
||||
}
|
||||
|
||||
internal static GLparamQueue ParamQueue
|
||||
public FrameOperationBuffer ActivatedOperationBuffer
|
||||
{
|
||||
get { return paramQueue; }
|
||||
}
|
||||
|
||||
internal ConcurrentQueue<IntPtr> GLactionQueue
|
||||
{
|
||||
get
|
||||
{
|
||||
return glActionQueue;
|
||||
}
|
||||
get { return frameOpBuffer; }
|
||||
set { frameOpBuffer = value; }
|
||||
}
|
||||
|
||||
void IglFunc.ActiveTexture(uint type)
|
||||
{
|
||||
paramQueue.Enqueue(type);
|
||||
glActionQueue.Enqueue(ActiveTexturePtr);
|
||||
frameOpBuffer.Enqueue(type);
|
||||
frameOpBuffer.Enqueue(ActiveTexturePtr);
|
||||
}
|
||||
|
||||
void IglFunc.AfterAlign(Form form, Action action)
|
||||
@@ -67,20 +53,14 @@ namespace StgSharp.Graphics
|
||||
|
||||
void IglFunc.AlignFrame(Form form)
|
||||
{
|
||||
if (form.timer.alignSign.byte0 > 0)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
form.timer.alignSign.byte0++;
|
||||
form.timer.WaitNextFrame();
|
||||
throw refreshSignal;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.AttachShader(glHandle program, glHandle shader)
|
||||
{
|
||||
paramQueue.Enqueue(program, shader);
|
||||
glActionQueue.Enqueue(AttachShaderPtr);
|
||||
frameOpBuffer.Enqueue(program, shader);
|
||||
frameOpBuffer.Enqueue(AttachShaderPtr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -89,8 +69,8 @@ namespace StgSharp.Graphics
|
||||
M128 m = default;
|
||||
m.Write<uint>(0, (uint)bufferType);
|
||||
m.Write<ulong>(1, (ulong)handle.valuePtr);
|
||||
paramQueue.Enqueue(m);
|
||||
glActionQueue.Enqueue(BindBufferPtr);
|
||||
frameOpBuffer.Enqueue(m);
|
||||
frameOpBuffer.Enqueue(BindBufferPtr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -99,53 +79,52 @@ namespace StgSharp.Graphics
|
||||
M128 m = default;
|
||||
m.Write<uint>(0, (uint)type);
|
||||
m.Write<ulong>(1, (ulong)texture.valuePtr);
|
||||
paramQueue.Enqueue(m);
|
||||
glActionQueue.Enqueue(BindTexturePtr);
|
||||
frameOpBuffer.Enqueue(m);
|
||||
frameOpBuffer.Enqueue(BindTexturePtr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.BindVertexArray(glHandle index)
|
||||
{
|
||||
paramQueue.Enqueue(index);
|
||||
glActionQueue.Enqueue(BindVertexArrayPtr);
|
||||
frameOpBuffer.Enqueue(index);
|
||||
frameOpBuffer.Enqueue(BindVertexArrayPtr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.Clear(MaskBufferBit mask)
|
||||
{
|
||||
paramQueue.Enqueue((int)mask);
|
||||
glActionQueue.Enqueue(ClearPtr);
|
||||
frameOpBuffer.Enqueue((int)mask);
|
||||
frameOpBuffer.Enqueue(ClearPtr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.ClearColor(float R, float G, float B, float A)
|
||||
{
|
||||
paramQueue.Enqueue(R, G, B, A);
|
||||
glActionQueue.Enqueue(ClearColorPtr);
|
||||
frameOpBuffer.Enqueue(R, G, B, A);
|
||||
frameOpBuffer.Enqueue(ClearColorPtr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.ClearGraphicError()
|
||||
{
|
||||
glActionQueue.Enqueue(ClearGraphicErrorPtr);
|
||||
frameOpBuffer.Enqueue(ClearGraphicErrorPtr);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.CompileShader(glHandle shaderhandle)
|
||||
{
|
||||
paramQueue.Enqueue((IntPtr)shaderhandle.valuePtr);
|
||||
glActionQueue.Enqueue(CompileShaderPtr);
|
||||
frameOpBuffer.Enqueue((IntPtr)shaderhandle.valuePtr);
|
||||
frameOpBuffer.Enqueue(CompileShaderPtr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
glHandle IglFunc.CreateProgram()
|
||||
{
|
||||
glHandle h = glHandle.Alloc(1);
|
||||
paramQueue.Enqueue(h);
|
||||
glActionQueue.Enqueue(CreateProgramPtr);
|
||||
frameOpBuffer.Enqueue(h);
|
||||
frameOpBuffer.Enqueue(CreateProgramPtr);
|
||||
return h;
|
||||
}
|
||||
|
||||
//TODO
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
glHandleSet IglFunc.CreateProgram(int count)
|
||||
{
|
||||
@@ -153,8 +132,8 @@ namespace StgSharp.Graphics
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
m.Write<ulong>(0, (ulong)h.handle);
|
||||
m.Write<int>(2, count);
|
||||
paramQueue.Enqueue(m);
|
||||
glActionQueue.Enqueue(CreateProgramSetPtr);
|
||||
frameOpBuffer.Enqueue(m);
|
||||
frameOpBuffer.Enqueue(CreateProgramSetPtr);
|
||||
return h;
|
||||
}
|
||||
|
||||
@@ -165,8 +144,8 @@ namespace StgSharp.Graphics
|
||||
m.Write<int>(0, count);
|
||||
m.Write<uint>(1, (uint)type);
|
||||
m.Write<ulong>(1, (ulong)ret.handle);
|
||||
paramQueue.Enqueue(m);
|
||||
glActionQueue.Enqueue(CreateShaderPtr);
|
||||
frameOpBuffer.Enqueue(m);
|
||||
frameOpBuffer.Enqueue(CreateShaderPtr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -199,8 +178,8 @@ namespace StgSharp.Graphics
|
||||
glHandle IglFunc.CreatGraphicProgram()
|
||||
{
|
||||
glHandle h = glHandle.Alloc(1);
|
||||
paramQueue.Enqueue(h);
|
||||
glActionQueue.Enqueue(CreateProgramPtr);
|
||||
frameOpBuffer.Enqueue(h);
|
||||
frameOpBuffer.Enqueue(CreateProgramPtr);
|
||||
return h;
|
||||
}
|
||||
|
||||
@@ -210,25 +189,25 @@ namespace StgSharp.Graphics
|
||||
M128 m = default;
|
||||
m.Write<ulong>(0, (ulong)handle.valuePtr);
|
||||
m.Write(2, 1);
|
||||
paramQueue.Enqueue(m);
|
||||
glActionQueue.Enqueue(DeleBufferPtr);
|
||||
frameOpBuffer.Enqueue(m);
|
||||
frameOpBuffer.Enqueue(DeleBufferPtr);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.DeleteBuffers(glHandleSet handle)
|
||||
{
|
||||
M128 m = default;
|
||||
m.Write<uint>(2, (uint)handle.length);
|
||||
m.Write<ulong>(0, (ulong)handle.handle);
|
||||
paramQueue.Enqueue(m);
|
||||
glActionQueue.Enqueue(DeleBufferPtr);
|
||||
m.Write<uint>(2, (uint)handle.length);
|
||||
frameOpBuffer.Enqueue(m);
|
||||
frameOpBuffer.Enqueue(DeleBufferPtr);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.DeleteVertexArrays(glHandleSet arrays)
|
||||
{
|
||||
M128 m = default; m.Write<ulong>(1, (ulong)arrays.handle);
|
||||
m.Write<int>(0, arrays.length);
|
||||
paramQueue.Enqueue(m);
|
||||
glActionQueue.Enqueue(DeleteVertexArrayPtr);
|
||||
frameOpBuffer.Enqueue(m);
|
||||
frameOpBuffer.Enqueue(DeleteVertexArrayPtr);
|
||||
}
|
||||
|
||||
void IglFunc.DrawElements(GepmetryType mode, uint count, TypeCode type, IntPtr ptr)
|
||||
@@ -255,17 +234,17 @@ namespace StgSharp.Graphics
|
||||
LogType.Error);
|
||||
return;
|
||||
}
|
||||
paramQueue.Enqueue((uint)mode, count, a);
|
||||
paramQueue.Enqueue(ptr);
|
||||
glActionQueue.Enqueue(DrawElementsPtr);
|
||||
frameOpBuffer.Enqueue((uint)mode, count, a);
|
||||
frameOpBuffer.Enqueue(ptr);
|
||||
frameOpBuffer.Enqueue(DrawElementsPtr);
|
||||
}
|
||||
|
||||
unsafe glHandleSet IglFunc.GenBuffers(int count)
|
||||
{
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
M128 m = default; m.Write<uint>(2, (uint)count); m.Write<ulong>(0, (ulong)h.handle);
|
||||
paramQueue.Enqueue(m);
|
||||
glActionQueue.Enqueue(GenBufferPtr);
|
||||
frameOpBuffer.Enqueue(m);
|
||||
frameOpBuffer.Enqueue(GenBufferPtr);
|
||||
return h;
|
||||
}
|
||||
|
||||
@@ -273,8 +252,8 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
M128 m = default; m.Write<uint>(2, (uint)count); m.Write<ulong>(0, (ulong)h.handle);
|
||||
paramQueue.Enqueue(m);
|
||||
glActionQueue.Enqueue(GenTexturesPtr);
|
||||
frameOpBuffer.Enqueue(m);
|
||||
frameOpBuffer.Enqueue(GenTexturesPtr);
|
||||
return h;
|
||||
}
|
||||
|
||||
@@ -282,8 +261,8 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
M128 m = default; m.Write<uint>(2, (uint)count); m.Write<ulong>(0, (ulong)h.handle);
|
||||
paramQueue.Enqueue(m);
|
||||
glActionQueue.Enqueue(GenTexturesPtr);
|
||||
frameOpBuffer.Enqueue(m);
|
||||
frameOpBuffer.Enqueue(GenTexturesPtr);
|
||||
return h;
|
||||
}
|
||||
|
||||
@@ -293,10 +272,10 @@ namespace StgSharp.Graphics
|
||||
glSHandle h = glSHandle.Alloc(0);
|
||||
M128 m = default;
|
||||
m.Write<ulong>(0, (ulong)program.Handle);
|
||||
m.Write<ulong>(1, (ulong)GCHandle.Alloc(Encoding.UTF8.GetBytes(ptr)).AddrOfPinnedObject());
|
||||
paramQueue.Enqueue(m);
|
||||
paramQueue.Enqueue((IntPtr)h.valuePtr);
|
||||
glActionQueue.Enqueue(GetUniformLocationPtr);
|
||||
m.Write<ulong>(1, (ulong)GCHandle.Alloc(Encoding.UTF8.GetBytes(ptr), GCHandleType.Pinned).AddrOfPinnedObject());
|
||||
frameOpBuffer.Enqueue(m);
|
||||
frameOpBuffer.Enqueue((IntPtr)h.valuePtr);
|
||||
frameOpBuffer.Enqueue(GetUniformLocationPtr);
|
||||
return h;
|
||||
}
|
||||
|
||||
@@ -317,8 +296,9 @@ namespace StgSharp.Graphics
|
||||
|
||||
void IglFunc.LoadShaderSource(glHandle shaderHandle, string codeStream)
|
||||
{
|
||||
paramQueue.Enqueue(shaderHandle);
|
||||
paramQueue.Enqueue(codeStream);
|
||||
frameOpBuffer.Enqueue(shaderHandle);
|
||||
frameOpBuffer.Enqueue(codeStream);
|
||||
frameOpBuffer.Enqueue(ShaderSourcePtr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -333,39 +313,40 @@ namespace StgSharp.Graphics
|
||||
|
||||
void IglFunc.SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
|
||||
{
|
||||
paramQueue.Enqueue((uint)bufferType, (uint)usage);
|
||||
paramQueue.Enqueue((IntPtr)sizeof(T), GCHandle.Alloc(bufferData).AddrOfPinnedObject());
|
||||
glActionQueue.Enqueue(BufferDataPtr);
|
||||
frameOpBuffer.Enqueue((uint)bufferType, (uint)usage);
|
||||
frameOpBuffer.Enqueue((IntPtr)sizeof(T));
|
||||
frameOpBuffer.Enqueue<T>(new T[] { bufferData });
|
||||
frameOpBuffer.Enqueue(BufferDataPtr);
|
||||
}
|
||||
|
||||
void IglFunc.SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
|
||||
{
|
||||
paramQueue.Enqueue((uint)bufferType, (uint)usage);
|
||||
paramQueue.Enqueue((IntPtr)(Marshal.SizeOf<T>() * bufferArray.Length));
|
||||
paramQueue.Enqueue<T>(bufferArray);
|
||||
glActionQueue.Enqueue(BufferDataPtr);
|
||||
frameOpBuffer.Enqueue((uint)bufferType, (uint)usage);
|
||||
frameOpBuffer.Enqueue((IntPtr)(Marshal.SizeOf<T>() * bufferArray.Length));
|
||||
frameOpBuffer.Enqueue<T>(bufferArray);
|
||||
frameOpBuffer.Enqueue(BufferDataPtr);
|
||||
}
|
||||
|
||||
void IglFunc.SetVertexAttribute(uint index, int size, TypeCode t, bool normalized, uint stride, int pointer)
|
||||
{
|
||||
uint type = InternalIO.GLtype[t];
|
||||
paramQueue.Enqueue(index, type, stride);
|
||||
paramQueue.Enqueue(size, normalized ? 1 : 0, pointer);
|
||||
glActionQueue.Enqueue(SetVertexArrayPtr);
|
||||
frameOpBuffer.Enqueue(index, type, stride);
|
||||
frameOpBuffer.Enqueue(size, normalized ? 1 : 0, pointer);
|
||||
frameOpBuffer.Enqueue(SetVertexArrayPtr);
|
||||
}
|
||||
|
||||
//TODO:双线程,换运行环境
|
||||
void IglFunc.SwitchContext()
|
||||
{
|
||||
paramQueue.context = api;
|
||||
frameOpBuffer.context = api;
|
||||
}
|
||||
|
||||
unsafe void IglFunc.TextureImage2d<T>(int target, int level, uint internalformat, uint width, uint height, uint format, uint type, glHandle pixels)
|
||||
{
|
||||
paramQueue.Enqueue(pixels);
|
||||
paramQueue.Enqueue((uint)level, internalformat, width, height);
|
||||
paramQueue.Enqueue((uint)target, format, type);
|
||||
glActionQueue.Enqueue(textureImage2dPtr);
|
||||
frameOpBuffer.Enqueue(pixels);
|
||||
frameOpBuffer.Enqueue((uint)level, internalformat, width, height);
|
||||
frameOpBuffer.Enqueue((uint)target, format, type);
|
||||
frameOpBuffer.Enqueue(textureImage2dPtr);
|
||||
}
|
||||
|
||||
void IglFunc.TextureParameter(int target, uint pname, int param)
|
||||
@@ -374,31 +355,49 @@ namespace StgSharp.Graphics
|
||||
m.Write<int>(0, target);
|
||||
m.Write<uint>(2, pname);
|
||||
m.Write<int>(3, param);
|
||||
paramQueue.Enqueue(m);
|
||||
glActionQueue.Enqueue(TextureParameterPtr);
|
||||
frameOpBuffer.Enqueue(m);
|
||||
frameOpBuffer.Enqueue(TextureParameterPtr);
|
||||
}
|
||||
|
||||
void IglFunc.UseProgram(glHandle program)
|
||||
{
|
||||
paramQueue.Enqueue((IntPtr)program.valuePtr);
|
||||
glActionQueue.Enqueue(UseProgramPtr);
|
||||
frameOpBuffer.Enqueue((IntPtr)program.valuePtr);
|
||||
frameOpBuffer.Enqueue(UseProgramPtr);
|
||||
}
|
||||
|
||||
void IglFunc.Viewport(int x, int y, uint width, uint height)
|
||||
{
|
||||
Vec4d v = new Vec4d(x, y, (int)width, (int)height);
|
||||
paramQueue.Enqueue(v);
|
||||
glActionQueue.Enqueue(ViewPortPtr);
|
||||
frameOpBuffer.Enqueue(v);
|
||||
frameOpBuffer.Enqueue(ViewPortPtr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void frameworkHandleEnqueue(IntPtr methodHandle, params M128[] param)
|
||||
void IglFunc.frameworkHandleEnqueue(IntPtr methodHandle, params M128[] param)
|
||||
{
|
||||
foreach (M128 item in param)
|
||||
{
|
||||
paramQueue.Enqueue(item);
|
||||
frameOpBuffer.Enqueue(item);
|
||||
}
|
||||
frameOpBuffer.Enqueue(methodHandle);
|
||||
}
|
||||
|
||||
bool IglFunc.FrameCanUpdate
|
||||
{
|
||||
get
|
||||
{
|
||||
if (unupdatedFrame.DirectValue > 5)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
*unupdatedFrame.valuePtr += 1;
|
||||
frameOpBuffer.Enqueue((IntPtr)unupdatedFrame.valuePtr);
|
||||
frameOpBuffer.Enqueue(CanUpdatePtr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
glActionQueue.Enqueue(methodHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
@@ -21,6 +22,7 @@ namespace StgSharp.Graphics
|
||||
private IntPtr BindTexturePtr = (IntPtr)(delegate*<void>)&InternalBindTexture;
|
||||
private IntPtr BindVertexArrayPtr = (IntPtr)(delegate*<void>)&InternalBindVertexArray;
|
||||
private IntPtr BufferDataPtr = (IntPtr)(delegate*<void>)&InternalSetBufferData;
|
||||
private IntPtr CanUpdatePtr = (IntPtr)(delegate*<void>)&InternalFrameCanUpdate;
|
||||
private IntPtr ClearColorPtr = (IntPtr)(delegate*<void>)&InternalClearColor;
|
||||
private IntPtr ClearGraphicErrorPtr = (IntPtr)(delegate*<void>)&InternalClearGraphicError;
|
||||
private IntPtr ClearPtr = (IntPtr)(delegate*<void>)&InternalClear;
|
||||
@@ -108,7 +110,6 @@ namespace StgSharp.Graphics
|
||||
paramQueue.context->glCompileShader(*(uint*)handle);
|
||||
}
|
||||
|
||||
//TODO
|
||||
private static void InternalCreateProgram()
|
||||
{
|
||||
IntPtr programHandle = default;
|
||||
@@ -144,6 +145,10 @@ namespace StgSharp.Graphics
|
||||
M128 m = default;
|
||||
paramQueue.TryDequeue(out m);
|
||||
paramQueue.context->glDeleteBuffers(m.Read<uint>(2), (uint*)m.Read<ulong>(0));
|
||||
for (int i = 0; i < m.Read<uint>(2); i++)
|
||||
{
|
||||
*((uint*)m.Read<ulong>(0) + i) = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static void InternalDeleteVertexArrays()
|
||||
@@ -162,6 +167,13 @@ namespace StgSharp.Graphics
|
||||
paramQueue.context->glDrawElements(mode, count, type, (void*)ptr);
|
||||
}
|
||||
|
||||
private static void InternalFrameCanUpdate()
|
||||
{
|
||||
IntPtr ptr;
|
||||
paramQueue.TryDequeue(out ptr);
|
||||
Interlocked.Add(ref *(int*)ptr, -1);
|
||||
}
|
||||
|
||||
private static void InternalGenBuffers()
|
||||
{
|
||||
M128 m = default;
|
||||
@@ -215,13 +227,11 @@ namespace StgSharp.Graphics
|
||||
private static unsafe void InternalShaderSource()
|
||||
{
|
||||
IntPtr handle = default;
|
||||
byte[] stream = Array.Empty<byte>();
|
||||
glArrayHandle stream = default;
|
||||
paramQueue.TryDequeue(out handle);
|
||||
paramQueue.TryDequeue(out stream);
|
||||
fixed (byte* sPtr = stream)
|
||||
{
|
||||
paramQueue.context->glShaderSource(*(uint*)handle, 1, &sPtr, (void*)0);
|
||||
}
|
||||
IntPtr buffer = stream.AddressOfArray();
|
||||
paramQueue.context->glShaderSource(*(uint*)handle, 1, (byte**)&buffer, (void*)0);
|
||||
}
|
||||
|
||||
private static void InternalTextureImage2d()
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharpDebug.Graphics.GL.ShaderEdit
|
||||
namespace StgSharp.Graphics.GL.ShaderEdit
|
||||
{
|
||||
public class ShaderGenerator
|
||||
{
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
M128 m = default;
|
||||
paramQueue.TryDequeue(out m);
|
||||
paramQueue.context->glUniform1f(*(int*)m.Read<uint>(0), m.Read<uint>(2));
|
||||
paramQueue.context->glUniform1f(*(int*)m.Read<ulong>(0), m.Read<uint>(2));
|
||||
}
|
||||
|
||||
private static unsafe void UniformVal1fv()
|
||||
@@ -216,14 +216,14 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
M128 m = default;
|
||||
paramQueue.TryDequeue(out m);
|
||||
paramQueue.context->glUniform1i(*(int*)m.Read<uint>(0), m.Read<int>(2));
|
||||
paramQueue.context->glUniform1i(*(int*)m.Read<ulong>(0), m.Read<int>(2));
|
||||
}
|
||||
|
||||
private static void UniformVal2f()
|
||||
{
|
||||
M128 m = default;
|
||||
paramQueue.TryDequeue(out m);
|
||||
paramQueue.context->glUniform2f(*(int*)m.Read<uint>(0), m.Read<float>(2), m.Read<float>(3));
|
||||
paramQueue.context->glUniform2f(*(int*)m.Read<ulong>(0), m.Read<float>(2), m.Read<float>(3));
|
||||
}
|
||||
|
||||
private static void UniformVal3f()
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace StgSharp.Graphics
|
||||
if (strPtr == IntPtr.Zero)
|
||||
{
|
||||
InternalIO.InternalWriteLog("No supported OpenGL extensions are found.", LogType.Info);
|
||||
goto startThread;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -742,14 +742,6 @@ namespace StgSharp.Graphics
|
||||
#endregion checkGLextensions
|
||||
|
||||
InternalIO.InternalWriteLog("Find OpenGL extensions.", LogType.Info);
|
||||
|
||||
startThread:
|
||||
{
|
||||
if (!form.IsSingleThread)
|
||||
{
|
||||
form.RenderThread.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user