daily update on 20240104 by nitload youmu, double threading not work
This commit is contained in:
@@ -132,21 +132,17 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct GLFWgamepadstate
|
||||
public unsafe struct GLFWgamepadstate
|
||||
{
|
||||
|
||||
/*! The states of each [gamepad button](@ref gamepad_buttons), `GLFW_PRESS`
|
||||
* or `GLFW_RELEASE`.
|
||||
*/
|
||||
byte[] buttons = new byte[15];
|
||||
public fixed byte buttons[15];
|
||||
/*! The states of each [gamepad axis](@ref gamepad_axes), in the range -1.0
|
||||
* to 1.0 inclusive.
|
||||
*/
|
||||
float[] axes = new float[6];
|
||||
|
||||
public GLFWgamepadstate()
|
||||
{
|
||||
}
|
||||
public fixed float axes[6];
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
@@ -216,10 +212,8 @@ namespace StgSharp.Graphics
|
||||
public bool stickyMouseButtons = false;
|
||||
public bool lockKeyMods = false;
|
||||
public int cursorMode = 0;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
||||
public byte[] mouseButtons = new byte[8];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 349)]
|
||||
public byte[] keys = new byte[349];
|
||||
public fixed byte mouseButtons[8];
|
||||
public fixed byte keys[349];
|
||||
// Virtual cursor position when cursor is disabled
|
||||
public double virtualCursorPosX = 0, virtualCursorPosY = 0;
|
||||
public bool rawMouseMotion = false;
|
||||
@@ -307,8 +301,7 @@ namespace StgSharp.Graphics
|
||||
internal struct Ns
|
||||
{
|
||||
GLFWbool retina = false;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
|
||||
byte[] frameName = new byte[256];
|
||||
public fixed byte frameName[256];
|
||||
|
||||
public Ns()
|
||||
{
|
||||
@@ -318,10 +311,9 @@ namespace StgSharp.Graphics
|
||||
|
||||
internal struct X11
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
|
||||
byte[] className = new byte[256];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
|
||||
byte[] instanceName = new byte[256];
|
||||
|
||||
public fixed byte className[256];
|
||||
public fixed byte instanceName[256];
|
||||
|
||||
public X11()
|
||||
{
|
||||
@@ -337,8 +329,7 @@ namespace StgSharp.Graphics
|
||||
|
||||
internal struct Wl
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
|
||||
byte[] appId = new byte[256];
|
||||
public fixed byte appId[256];
|
||||
|
||||
public Wl()
|
||||
{
|
||||
@@ -517,8 +508,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
GLFWbool available;
|
||||
void* handle;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
|
||||
byte*[] extensions = new byte*[2];
|
||||
fixed ulong extensions[2];
|
||||
IntPtr GetInstanceProcAddr;
|
||||
GLFWbool KHR_surface;
|
||||
GLFWbool KHR_win32_surface;
|
||||
@@ -560,10 +550,8 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWmapping
|
||||
{
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
|
||||
byte[] name = new byte[128];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 33)]
|
||||
byte[] guid = new byte[33];
|
||||
fixed byte name[128];
|
||||
fixed byte guid[33];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)]
|
||||
GLFWmapelement[] buttons = new GLFWmapelement[15];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
|
||||
@@ -584,11 +572,9 @@ namespace StgSharp.Graphics
|
||||
int buttonCount;
|
||||
byte* hats;
|
||||
int hatCount;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
|
||||
byte[] name = new byte[128];
|
||||
fixed byte name[128];
|
||||
void* userPointer;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 33)]
|
||||
byte[] guid = new byte[33];
|
||||
fixed byte guid[33];
|
||||
//GLFWmapping* mapping;
|
||||
IntPtr mapping;
|
||||
|
||||
@@ -783,8 +769,7 @@ namespace StgSharp.Graphics
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal unsafe struct VkExtensionProperties
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
|
||||
byte[] extensionName = new byte[256];
|
||||
fixed byte extensionName[256];
|
||||
uint specVersion;
|
||||
|
||||
public VkExtensionProperties()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+131
-119
@@ -1,6 +1,8 @@
|
||||
using StgSharp.Controlling;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
@@ -21,40 +23,36 @@ namespace StgSharp.Graphics
|
||||
/// </summary>
|
||||
public abstract partial class Form
|
||||
{
|
||||
#region metadata
|
||||
internal LinkedList<Control> allControl;
|
||||
internal Vector4 color;
|
||||
internal Thread formThread;
|
||||
internal IglFunc GL;
|
||||
internal Vector4 backgroundColor;
|
||||
internal unsafe GLcontext* contextID;
|
||||
internal DynamicArrayList<IntPtr> formBuffer;
|
||||
internal int height;
|
||||
internal IntPtr monitor;
|
||||
internal string name;
|
||||
internal FormRenderBuffer RenderBuffer;
|
||||
internal Form sharedForm;
|
||||
internal FrameUpdateTimer timer = new FrameUpdateTimer();
|
||||
internal FormUpdateBuffer UpdateBuffer;
|
||||
internal int width;
|
||||
internal IntPtr windowID;
|
||||
|
||||
private bool alignAtRender;
|
||||
private bool alignAtUpdate;
|
||||
private bool isSingleThread;
|
||||
|
||||
private Action OnRender;
|
||||
private Action OnUpdate;
|
||||
|
||||
#region thread sync
|
||||
internal readonly SemaphoreSlim ouetrPong = new SemaphoreSlim(0, 1);
|
||||
private SemaphoreSlim ping = new SemaphoreSlim(1, 1);
|
||||
private SemaphoreSlim pong = new SemaphoreSlim(0, 1);
|
||||
protected IglFunc gl;
|
||||
private bool closed;
|
||||
#endregion
|
||||
|
||||
private Form()
|
||||
#region form thread setting
|
||||
internal FrameUpdateTimer timer = new FrameUpdateTimer();
|
||||
private SemaphoreSlim _renderFinishSignal = new SemaphoreSlim(0, 1);
|
||||
private SemaphoreSlim _renderStartSignal = new SemaphoreSlim(1, 1);
|
||||
private bool isSingleThread = true;
|
||||
private Thread renderThread;
|
||||
#endregion
|
||||
|
||||
#region glapicount
|
||||
private int missingAPIcount = 0;
|
||||
private int problemAPIcount = 0;
|
||||
#endregion
|
||||
|
||||
protected Form()
|
||||
{
|
||||
#if NET5_0_OR_GREATER
|
||||
Unsafe.SkipInit(out UpdateBuffer);
|
||||
Unsafe.SkipInit(out RenderBuffer);
|
||||
Unsafe.SkipInit(out GL);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -66,6 +64,20 @@ namespace StgSharp.Graphics
|
||||
set => height = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OpenGL package used by current form context.
|
||||
/// </summary>
|
||||
public IglFunc GL
|
||||
{
|
||||
get => gl;
|
||||
internal set => gl = value;
|
||||
}
|
||||
|
||||
internal Thread RenderThread
|
||||
{
|
||||
get { return renderThread; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Representing
|
||||
/// </summary>
|
||||
@@ -73,6 +85,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
get { return isSingleThread; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Width of this form, represent in <see cref="int"/>
|
||||
/// </summary>
|
||||
@@ -86,148 +99,152 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Width of this form, represent in <see cref="int"/>
|
||||
/// </summary>
|
||||
public int Width
|
||||
{
|
||||
get => width;
|
||||
set => width = value;
|
||||
}
|
||||
|
||||
internal bool IsSingleThread
|
||||
{
|
||||
get { return isSingleThread; }
|
||||
}
|
||||
|
||||
internal SemaphoreSlim RenderFinishSignal
|
||||
{
|
||||
get { return _renderFinishSignal; }
|
||||
set { _renderFinishSignal = value; }
|
||||
}
|
||||
|
||||
internal SemaphoreSlim RenderStrartSignal
|
||||
{
|
||||
get { return _renderStartSignal; }
|
||||
set { _renderStartSignal = value; }
|
||||
}
|
||||
unsafe ~Form()
|
||||
{
|
||||
Marshal.FreeHGlobal((IntPtr)contextID);
|
||||
RenderBuffer.GL.api = default;
|
||||
}
|
||||
|
||||
#region form main
|
||||
|
||||
public abstract void Deinit(object[] args);
|
||||
public abstract void Deinit(params object[] args);
|
||||
|
||||
/// <summary>
|
||||
/// Necessary operation to init this form.
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
public abstract void Init(object[] args);
|
||||
public abstract void Init(params object[] args);
|
||||
|
||||
/// <summary>
|
||||
/// Behaviour of current form when in a render cycle.
|
||||
/// When this form
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
public abstract void Main(object[] args);
|
||||
public abstract void Main(params object[] args);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Init this form and render it on screen, and respond with operation
|
||||
/// </summary>
|
||||
public void Show(object[] args)
|
||||
public void Show(params object[] args)
|
||||
{
|
||||
if (args == null)
|
||||
if (gl == null)
|
||||
{
|
||||
args = new object[4] { null, null, null, null };
|
||||
InternalIO.InternalWriteLog($"Attempt to show form {name} before init", LogType.Error);
|
||||
}
|
||||
Operation.RegistForm(this);
|
||||
if (!TimeLine.RenderStarted)
|
||||
else if (isSingleThread)
|
||||
{
|
||||
TimeLine.RenderAll();
|
||||
while (gl.GetWindowShouldClose(this))
|
||||
{
|
||||
Main(args);
|
||||
}
|
||||
}
|
||||
try
|
||||
else
|
||||
{
|
||||
Thread updateThread = new Thread(InternalUpdateFrame);
|
||||
Thread renderThread = new Thread(InternalRenderFrame);
|
||||
|
||||
updateThread.Start(args[1]);
|
||||
renderThread.Start(args[2]);
|
||||
|
||||
updateThread.Join();
|
||||
while (gl.GetWindowShouldClose(this))
|
||||
{
|
||||
Main(args);
|
||||
}
|
||||
renderThread.Join();
|
||||
|
||||
ping.Dispose();
|
||||
pong.Dispose();
|
||||
|
||||
InternalDeinit(args[3]);
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
internal void InternalDeinit(object args)
|
||||
private void InternalRender()
|
||||
{
|
||||
Deinit((object[])args);
|
||||
#pragma warning disable CS8602
|
||||
ConcurrentQueue<Action<int>> glActions = (gl as GLonUpdate).GLactionQueue;
|
||||
#pragma warning restore CS8602
|
||||
Action currentAction = new Action(() => { return; });
|
||||
while (gl.GetWindowShouldClose(this))
|
||||
{
|
||||
if (glActions.TryDequeue(out currentAction))
|
||||
{
|
||||
currentAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void InternalInit(object args)
|
||||
internal void InternalDeinit(params object[] args)
|
||||
{
|
||||
Deinit(args);
|
||||
}
|
||||
|
||||
internal void InternalInit(params object[] args)
|
||||
{
|
||||
Init((object[])args);
|
||||
}
|
||||
|
||||
internal void InternalRenderFrame()
|
||||
{
|
||||
while (InternalIO.glfw.WindowShouldClose(windowID) != 0)
|
||||
{
|
||||
ping.Wait();
|
||||
try
|
||||
{
|
||||
OnRender();
|
||||
timer.WaitNextFrame();
|
||||
pong.Release();
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
throw new Exception("Forget to reload GL apis");
|
||||
pong.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void InternalUpdateFrame()
|
||||
{
|
||||
while (InternalIO.glfw.WindowShouldClose(windowID) != 0)
|
||||
{
|
||||
pong.Wait();
|
||||
try
|
||||
{
|
||||
OnUpdate();
|
||||
timer.WaitNextFrame();
|
||||
ping.Release();
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
throw new Exception("Forget to reload GL apis");
|
||||
ping.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Define how current form render in one frame.
|
||||
/// </summary>
|
||||
/// <param name="totalThread">
|
||||
///
|
||||
/// Please define
|
||||
/// <param name="requireDoubleRendering">
|
||||
/// Please define this befor calling any OpenGL api and other graphic methods.
|
||||
/// </param>
|
||||
protected void SetRenderThreads(bool requireDoubleRendering)
|
||||
protected unsafe void SetRenderThreads(int requiredThreds)
|
||||
{
|
||||
switch (requireDoubleRendering)
|
||||
if (gl != default)
|
||||
{
|
||||
case true:
|
||||
isSingleThread = false;
|
||||
OnUpdate = new Action(() => { });
|
||||
break;
|
||||
case false:
|
||||
isSingleThread = false;
|
||||
break;
|
||||
throw new InvalidOperationException("Cannot define threads after loading gl context.");
|
||||
}
|
||||
if (requiredThreds == 1)
|
||||
{
|
||||
isSingleThread = true;
|
||||
}
|
||||
else if (requiredThreds == 2)
|
||||
{
|
||||
isSingleThread = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GLcontext)));
|
||||
contextID = (GLcontext*)ptr;
|
||||
*contextID = new GLcontext();
|
||||
contextID->glGetString = (delegate*<uint, IntPtr>)IntPtr.Zero;
|
||||
InternalIO.InternalWriteLog("Successfully create a context binded to current form. " +
|
||||
$"Its ID is {(ulong)ptr}", LogType.Info);
|
||||
if (isSingleThread)
|
||||
{
|
||||
gl = new GLonRender(contextID);
|
||||
}
|
||||
else
|
||||
{
|
||||
GLonUpdate pack = new GLonUpdate(contextID);
|
||||
gl = pack;
|
||||
renderThread = new Thread(new ThreadStart(InternalRender));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Constructor of a Form, creats an instance of a form and
|
||||
/// initilize all the customizing operations.
|
||||
/// Set all necessary metadata to current form instance
|
||||
/// </summary>
|
||||
public void InitForm(int width, int height, string name, IntPtr monitor, Form sharedForm)
|
||||
public void SetMetadata(int width, int height, string name, IntPtr monitor, Form sharedForm)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
@@ -267,18 +284,10 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
windowID = windowPtr;
|
||||
}
|
||||
GLcontext glContext = new GLcontext();
|
||||
IntPtr ptr = Marshal.AllocHGlobal(sizeof(GLcontextIO));
|
||||
contextID = (GLcontextIO*)ptr;
|
||||
*contextID = new GLcontextIO();
|
||||
InternalIO.InternalWriteLog("Successfully create a context binded to current form. " +
|
||||
$"Its ID is {(ulong)ptr}", LogType.Info);
|
||||
GLonRender glRender = new GLonRender(glContext);
|
||||
GLonUpdate glUpdate = new GLonUpdate(glContext);
|
||||
}
|
||||
InternalIO.InternalSetCurrentGLContext(windowID, (IntPtr)contextID);
|
||||
}
|
||||
|
||||
}
|
||||
InternalIO.InternalSetCurrentGLContext(windowID, contextID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resize the current form
|
||||
@@ -298,6 +307,7 @@ namespace StgSharp.Graphics
|
||||
/// <param name="size">
|
||||
/// A <see cref="Vec2d"/> (width,height) representing the new size of current form
|
||||
/// </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetSize(Vec2d size)
|
||||
{
|
||||
this.Size = size;
|
||||
@@ -312,6 +322,7 @@ namespace StgSharp.Graphics
|
||||
/// <param name="minHeight">Minimum height of current form</param>
|
||||
/// <param name="maxWidth">Maximum width of curent form</param>
|
||||
/// <param name="maxHeight">Maximum height of current form</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
|
||||
{
|
||||
InternalIO.glfw.SetWindowSizeLimits(
|
||||
@@ -328,6 +339,7 @@ namespace StgSharp.Graphics
|
||||
/// <param name="maxSize">
|
||||
/// Maximum size of current form. In form of a <see cref="Vec2d"/> of (width,height)
|
||||
/// </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetSizeLimit(Vec2d minSize, Vec2d maxSize)
|
||||
{
|
||||
InternalIO.glfw.SetWindowSizeLimits(
|
||||
|
||||
@@ -1,20 +1,37 @@
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public unsafe class ElementBuffer : IDisposable, IBufferObject
|
||||
public partial class Form
|
||||
{
|
||||
uint[] _bufferID;
|
||||
private IglFunc GL;
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
|
||||
internal ElementBuffer(int n, IglFunc glFunc)
|
||||
/// <summary>
|
||||
/// A collecion of handle to Element Buffer Object in OpenGL.
|
||||
/// Each <see cref="uint"/> value indexed from instance of this class this
|
||||
/// is the only handle to one Element Buffer Object.
|
||||
/// </summary>
|
||||
public unsafe class ElementBuffer : IBufferObject
|
||||
{
|
||||
internal ElementBuffer(uint n, IglFunc gl)
|
||||
{
|
||||
_bufferID = new uint[n];
|
||||
GL = glFunc;
|
||||
GL = gl;
|
||||
fixed (uint* id = _bufferID)
|
||||
{
|
||||
GL.GenBuffers(n, id);
|
||||
@@ -26,7 +43,7 @@ namespace StgSharp.Graphics
|
||||
get { return _bufferID[n]; }
|
||||
}
|
||||
|
||||
public void Bind(int index)
|
||||
public override void Bind(int index)
|
||||
{
|
||||
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferID[index]);
|
||||
}
|
||||
@@ -38,14 +55,12 @@ namespace StgSharp.Graphics
|
||||
GL.SetBufferData(BufferType.ELEMENT_ARRAY_BUFFER, bufferArray, usage);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
protected sealed override void Dispose(bool disposing)
|
||||
{
|
||||
fixed (uint* id = _bufferID)
|
||||
if (disposing)
|
||||
{
|
||||
GL.DeleteBuffers(_bufferID.Length, id);
|
||||
GL.DeleteBuffers((uint)_bufferID.Length, _bufferID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
internal class FormRenderBuffer
|
||||
{
|
||||
internal GLonRender GL;
|
||||
internal InternalFormBuffer data;
|
||||
}
|
||||
|
||||
internal class FormUpdateBuffer
|
||||
{
|
||||
internal GLonUpdate GL;
|
||||
internal InternalFormBuffer data;
|
||||
}
|
||||
|
||||
internal class InternalFormBuffer
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,38 @@ namespace StgSharp.Graphics
|
||||
/// <summary>
|
||||
/// Interface of all kinds OpenGL buffer onjects
|
||||
/// </summary>
|
||||
public interface IBufferObject
|
||||
public abstract class IBufferObject : IDisposable
|
||||
{
|
||||
uint this[int index] { get; }
|
||||
void Bind(int index);
|
||||
protected uint[] _bufferID;
|
||||
protected IglFunc GL;
|
||||
|
||||
/// <summary>
|
||||
/// Get the only handle to one of the Object instance
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
public uint this[int index]
|
||||
{
|
||||
get { return _bufferID[index]; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bind a buffer instance to OpenGL
|
||||
/// </summary>
|
||||
/// <param name="index">Index of handle of the object in this instance to be bind</param>
|
||||
public abstract void Bind(int index);
|
||||
|
||||
protected abstract void Dispose(bool disposing);
|
||||
|
||||
~IBufferObject()
|
||||
{
|
||||
Dispose(disposing: false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,55 +5,59 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
|
||||
public unsafe struct VertexArray : IDisposable, IBufferObject
|
||||
public partial class Form
|
||||
{
|
||||
internal uint[] _bufferID;
|
||||
private IglFunc 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);
|
||||
}
|
||||
}
|
||||
|
||||
internal VertexArray(int n)
|
||||
public unsafe class VertexArray : IBufferObject
|
||||
{
|
||||
internal VertexArray(uint n, IglFunc gl)
|
||||
{
|
||||
_bufferID = new uint[n];
|
||||
//GL = glFunc;
|
||||
GL = gl;
|
||||
fixed (uint* id = _bufferID)
|
||||
{
|
||||
GL.GenVertexArrays(n, id);
|
||||
}
|
||||
}
|
||||
|
||||
public uint this[int n]
|
||||
{
|
||||
get
|
||||
{
|
||||
return _bufferID[n];
|
||||
}
|
||||
}
|
||||
|
||||
public void Bind(int index)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public sealed override void Bind(int index)
|
||||
{
|
||||
GL.BindVertexArray(_bufferID[index]);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
fixed (uint* id = _bufferID)
|
||||
{
|
||||
GL.DeleteVertexArrays(_bufferID.Length, id);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BindNull()
|
||||
{
|
||||
GL.BindVertexArray(0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetVertexAttribute(uint index, int vertexLength, Type dataType, bool isNomalized, int stride, int pointer)
|
||||
public void SetVertexAttribute(uint index, int vertexLength, Type dataType, bool isNomalized, uint stride, int pointer)
|
||||
{
|
||||
GL.SetVertexAttribute(
|
||||
index, vertexLength, dataType,
|
||||
isNomalized,
|
||||
stride, pointer);
|
||||
}
|
||||
|
||||
protected sealed override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
GL.DeleteVertexArrays((uint)_bufferID.Length, _bufferID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,17 +3,29 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Security;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public unsafe struct VertexBuffer : IDisposable, IBufferObject
|
||||
public partial class Form
|
||||
{
|
||||
internal uint[] _bufferID;
|
||||
private IglFunc 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);
|
||||
}
|
||||
}
|
||||
|
||||
internal VertexBuffer(int n, IglFunc glFunc)
|
||||
public unsafe class VertexBuffer : IBufferObject
|
||||
{
|
||||
internal VertexBuffer(uint n, IglFunc glFunc)
|
||||
{
|
||||
_bufferID = new uint[n];
|
||||
GL = glFunc;
|
||||
@@ -23,29 +35,33 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
public uint this[int n]
|
||||
{
|
||||
get { return _bufferID[n]; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Unbind()
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
public void Bind(int index)
|
||||
public sealed override void Bind(int index)
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferID[index]);
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, (uint)index);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
internal void ChangeEnvironment(IglFunc gl)
|
||||
{
|
||||
fixed (uint* id = _bufferID)
|
||||
GL = gl;
|
||||
}
|
||||
|
||||
protected sealed override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
GL.DeleteBuffers(_bufferID.Length, id);
|
||||
fixed (uint* id = _bufferID)
|
||||
{
|
||||
GL.DeleteBuffers((uint)_bufferID.Length, _bufferID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,139 +11,143 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
public partial class Form
|
||||
{
|
||||
protected Texture CreateTexture(int n)
|
||||
protected Texture CreateTexture(uint n)
|
||||
{
|
||||
return new Texture(n, GL);
|
||||
return new Texture(n, this.GL);
|
||||
}
|
||||
}
|
||||
public unsafe class Texture
|
||||
{
|
||||
internal uint[] textureId;
|
||||
internal Image[] sourceList;
|
||||
internal static bool[] unitActivated = new bool[16];
|
||||
private IglFunc GL;
|
||||
|
||||
internal void ChangeEnvironment(IglFunc gl)
|
||||
{
|
||||
GL = gl;
|
||||
}
|
||||
|
||||
protected unsafe class Texture
|
||||
internal Texture(uint n, IglFunc gl)
|
||||
{
|
||||
internal uint[] textureId;
|
||||
internal Image[] sourceList;
|
||||
internal static bool[] unitActivated = new bool[16];
|
||||
private IglFunc GL;
|
||||
|
||||
internal Texture(int n, IglFunc glFunc)
|
||||
textureId = new uint[n];
|
||||
sourceList = new Image[n];
|
||||
GL = gl;
|
||||
fixed (uint* id = textureId)
|
||||
{
|
||||
textureId = new uint[n];
|
||||
sourceList = new Image[n];
|
||||
GL = glFunc;
|
||||
fixed (uint* id = textureId)
|
||||
{
|
||||
GL.GenTextures(n, id);
|
||||
}
|
||||
GL.GenTextures(n, id);
|
||||
}
|
||||
|
||||
public void Bind2D(int index)
|
||||
{
|
||||
GL.BindTexture(GLconst.TEXTURE_2D, textureId[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <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();
|
||||
fixed (Image.ImageInfo* textureInfo = &sourceList[index].info)
|
||||
{
|
||||
InternalIO.InternalLoadImage(name, textureInfo, loader);
|
||||
}
|
||||
|
||||
if (sourceList[index].info.pixelPtr != IntPtr.Zero)
|
||||
{
|
||||
uint channel;
|
||||
switch (sourceList[index].info.channel)
|
||||
{
|
||||
case 1:
|
||||
channel = GLconst.RED; break;
|
||||
case 2:
|
||||
channel = GLconst.RG; break;
|
||||
case 3:
|
||||
channel = GLconst.RGB; break;
|
||||
case 4:
|
||||
channel = GLconst.RGBA; break;
|
||||
default:
|
||||
channel = 0;
|
||||
break;
|
||||
}
|
||||
GL.TextureImage2d(
|
||||
GLconst.TEXTURE_2D, 0, channel,
|
||||
sourceList[index].Width, sourceList[index].Height,
|
||||
channel, GLconst.UNSIGNED_BYTE, (byte*)sourceList[index].info.pixelPtr
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
InternalIO.InternalWriteLog($"Failed to load image file of \"{name}\".", LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
#region texture set
|
||||
|
||||
public void Set2dFilterProperty(
|
||||
Filter onMinify, Filter onMagnify)
|
||||
{
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MIN_FILTER, (int)onMinify);
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MAG_FILTER, (int)onMagnify);
|
||||
}
|
||||
|
||||
public void Set2dWrapProperty(
|
||||
Wrap onHorizontial, Wrap onVertical)
|
||||
{
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_S, (int)onHorizontial);
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_T, (int)onVertical);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void Activate(TextureUnit unit)
|
||||
{
|
||||
GL.ActiveTexture((uint)unit);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum TextureUnit
|
||||
public void Bind2D(int index)
|
||||
{
|
||||
Unit0 = GLconst.TEXTURE0,
|
||||
Unit1 = GLconst.TEXTURE1,
|
||||
Unit2 = GLconst.TEXTURE2,
|
||||
Unit3 = GLconst.TEXTURE3,
|
||||
Unit4 = GLconst.TEXTURE4,
|
||||
Unit5 = GLconst.TEXTURE5,
|
||||
Unit6 = GLconst.TEXTURE6,
|
||||
Unit7 = GLconst.TEXTURE7,
|
||||
Unit8 = GLconst.TEXTURE8,
|
||||
Unit9 = GLconst.TEXTURE9,
|
||||
Unit10 = GLconst.TEXTURE10,
|
||||
Unit11 = GLconst.TEXTURE11,
|
||||
Unit12 = GLconst.TEXTURE12,
|
||||
Unit13 = GLconst.TEXTURE13,
|
||||
Unit14 = GLconst.TEXTURE14,
|
||||
Unit15 = GLconst.TEXTURE15,
|
||||
GL.BindTexture(GLconst.TEXTURE_2D, textureId[index]);
|
||||
}
|
||||
|
||||
public enum Wrap
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="loader"></param>
|
||||
public unsafe void LoadTexture(int index, string name, ImageLoader loader)
|
||||
{
|
||||
Repeat = GLconst.REPEAT,
|
||||
MirroredRepeat = GLconst.MIRRORED_REPEAT,
|
||||
ClampToEdge = GLconst.CLAMP_TO_EDGE,
|
||||
ClampToBorder = GLconst.CLAMP_TO_BORDER,
|
||||
sourceList[index] = new Image();
|
||||
fixed (Image.ImageInfo* textureInfo = &sourceList[index].info)
|
||||
{
|
||||
InternalIO.InternalLoadImage(name, textureInfo, loader);
|
||||
}
|
||||
|
||||
if (sourceList[index].info.pixelPtr != IntPtr.Zero)
|
||||
{
|
||||
uint channel;
|
||||
switch (sourceList[index].info.channel)
|
||||
{
|
||||
case 1:
|
||||
channel = GLconst.RED; break;
|
||||
case 2:
|
||||
channel = GLconst.RG; break;
|
||||
case 3:
|
||||
channel = GLconst.RGB; break;
|
||||
case 4:
|
||||
channel = GLconst.RGBA; break;
|
||||
default:
|
||||
channel = 0;
|
||||
break;
|
||||
}
|
||||
GL.TextureImage2d(
|
||||
GLconst.TEXTURE_2D, 0, channel,
|
||||
(uint)sourceList[index].Width, (uint)sourceList[index].Height,
|
||||
channel, GLconst.UNSIGNED_BYTE, (byte*)sourceList[index].info.pixelPtr
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
InternalIO.InternalWriteLog($"Failed to load image file of \"{name}\".", LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
public enum Filter
|
||||
#region texture set
|
||||
|
||||
public void Set2dFilterProperty(
|
||||
Filter onMinify, Filter onMagnify)
|
||||
{
|
||||
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,
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MIN_FILTER, (int)onMinify);
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MAG_FILTER, (int)onMagnify);
|
||||
}
|
||||
|
||||
public void Set2dWrapProperty(
|
||||
Wrap onHorizontial, Wrap onVertical)
|
||||
{
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_S, (int)onHorizontial);
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_T, (int)onVertical);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void Activate(TextureUnit unit)
|
||||
{
|
||||
GL.ActiveTexture((uint)unit);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum TextureUnit
|
||||
{
|
||||
Unit0 = GLconst.TEXTURE0,
|
||||
Unit1 = GLconst.TEXTURE1,
|
||||
Unit2 = GLconst.TEXTURE2,
|
||||
Unit3 = GLconst.TEXTURE3,
|
||||
Unit4 = GLconst.TEXTURE4,
|
||||
Unit5 = GLconst.TEXTURE5,
|
||||
Unit6 = GLconst.TEXTURE6,
|
||||
Unit7 = GLconst.TEXTURE7,
|
||||
Unit8 = GLconst.TEXTURE8,
|
||||
Unit9 = GLconst.TEXTURE9,
|
||||
Unit10 = GLconst.TEXTURE10,
|
||||
Unit11 = GLconst.TEXTURE11,
|
||||
Unit12 = GLconst.TEXTURE12,
|
||||
Unit13 = GLconst.TEXTURE13,
|
||||
Unit14 = GLconst.TEXTURE14,
|
||||
Unit15 = GLconst.TEXTURE15,
|
||||
}
|
||||
|
||||
public enum Wrap
|
||||
{
|
||||
Repeat = GLconst.REPEAT,
|
||||
MirroredRepeat = GLconst.MIRRORED_REPEAT,
|
||||
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,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,15 +9,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
public unsafe partial class Form
|
||||
{
|
||||
internal GLcontextIO* contextID;
|
||||
|
||||
private int missingAPIcount = 0;
|
||||
private int problemAPIcount = 0;
|
||||
|
||||
internal GLcontext glContext
|
||||
{
|
||||
get { return RenderBuffer.GL.api; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -11,19 +12,18 @@ namespace StgSharp.Graphics
|
||||
|
||||
internal unsafe partial class GLonRender : IglFunc
|
||||
{
|
||||
internal GLcontext* api;
|
||||
FrameTimeoutException refreshSIgnal = new FrameTimeoutException();
|
||||
|
||||
internal GLonRender(GLcontext context)
|
||||
|
||||
internal GLonRender(GLcontext* context)
|
||||
{
|
||||
api = context;
|
||||
}
|
||||
|
||||
internal GLcontext api;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.ActiveTexture(uint type)
|
||||
{
|
||||
api.ActiveTexture(type);
|
||||
api->glActiveTexture(type);
|
||||
}
|
||||
|
||||
void IglFunc.AfterAlign(Form form, Action action)
|
||||
@@ -45,41 +45,44 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.AttachShader(uint program, uint shader)
|
||||
{
|
||||
api.AttachShader(program, shader);
|
||||
api->glAttachShader(program, shader);
|
||||
}
|
||||
|
||||
void IglFunc.BindBuffer(BufferType bufferType, uint index)
|
||||
{
|
||||
api.BindBuffer((uint)bufferType, index);
|
||||
api->glBindBuffer((uint)bufferType, index);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.BindTexture(uint type, uint texture)
|
||||
{
|
||||
api.BindTexture(type, texture);
|
||||
api->glBindTexture(type, texture);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.BindVertexArray(uint index)
|
||||
{
|
||||
api.BindVertexArray(index);
|
||||
api->glBindVertexArray(index);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.Clear(MaskBufferBit mask)
|
||||
{
|
||||
api.Clear((uint)mask);
|
||||
api->glClear((uint)mask);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.ClearColor(float R, float G, float B, float A)
|
||||
{
|
||||
api.ClearColor(R, G, B, A);
|
||||
api->glClearColor(R, G, B, A);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.ClearGraphicError()
|
||||
{
|
||||
while (api.GetError() != 0) { }
|
||||
while (api->glGetError() != 0) { }
|
||||
}
|
||||
|
||||
uint IglFunc.CompileShader(string shaderCode, ShaderType shaderType)
|
||||
{
|
||||
uint shaderID;
|
||||
@@ -123,7 +126,7 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
uint IglFunc.CreateProgram()
|
||||
{
|
||||
return api.CreateProgram();
|
||||
return api->glCreateProgram();
|
||||
}
|
||||
|
||||
unsafe IntPtr IglFunc.CreateWindowHandle(
|
||||
@@ -152,36 +155,44 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe uint IglFunc.CreatGraphicProgram()
|
||||
{
|
||||
return api.CreateProgram();
|
||||
return api->glCreateProgram();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.DeleteBuffers(int count, uint* ptr)
|
||||
unsafe void IglFunc.DeleteBuffer(uint handle)
|
||||
{
|
||||
api.DeleteBuffers(count, ptr);
|
||||
api->glDeleteBuffers(1, &handle);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.DeleteVertexArrays(int count, uint* ptr)
|
||||
unsafe void IglFunc.DeleteBuffers(uint count, uint[] handle)
|
||||
{
|
||||
api.DeleteVertexArrays(count, ptr);
|
||||
fixed (uint* ptr = handle)
|
||||
api->glDeleteBuffers(count, ptr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.DrawElements(GepmetryType mode, int count, Type type, IntPtr ptr)
|
||||
unsafe void IglFunc.DeleteVertexArrays(uint count, uint[] arrays)
|
||||
{
|
||||
fixed (uint* ptr = arrays)
|
||||
api->glDeleteVertexArrays(count, ptr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.DrawElements(GepmetryType mode, uint count, Type type, IntPtr ptr)
|
||||
{
|
||||
uint a;
|
||||
switch (type.Name)
|
||||
switch (Type.GetTypeCode(type))
|
||||
{
|
||||
case "UInt32":
|
||||
case TypeCode.UInt32:
|
||||
a = GLconst.UNSIGNED_INT;
|
||||
break;
|
||||
case "UInt16":
|
||||
case TypeCode.UInt16:
|
||||
a = GLconst.UNSIGNED_SHORT;
|
||||
break;
|
||||
case "Byte":
|
||||
case TypeCode.Byte:
|
||||
a = GLconst.UNSIGNED_BYTE;
|
||||
break;
|
||||
default:
|
||||
@@ -191,31 +202,31 @@ namespace StgSharp.Graphics
|
||||
LogType.Error);
|
||||
return;
|
||||
}
|
||||
api.DrawElements((uint)mode, count, a, (void*)ptr);
|
||||
api->glDrawElements((uint)mode, count, a, (void*)ptr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.GenBuffers(int count, uint* ptr)
|
||||
unsafe void IglFunc.GenBuffers(uint count, uint* ptr)
|
||||
{
|
||||
api.GenBuffers(count, ptr);
|
||||
api->glGenBuffers(count, ptr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.GenTextures(int count, uint* ptr)
|
||||
unsafe void IglFunc.GenTextures(uint count, uint* ptr)
|
||||
{
|
||||
api.GenTextures(count, ptr);
|
||||
api->glGenTextures(count, ptr);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.GenVertexArrays(int count, uint* ptr)
|
||||
unsafe void IglFunc.GenVertexArrays(uint count, uint* ptr)
|
||||
{
|
||||
api.GenVertexArrays(count, ptr);
|
||||
api->glGenVertexArrays(count, ptr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.GetGraphicError()
|
||||
{
|
||||
string error = null;
|
||||
uint code = api.GetError();
|
||||
uint code = api->glGetError();
|
||||
while (code != 0)
|
||||
{
|
||||
error += $"OpenGL error {code}\n";
|
||||
@@ -242,7 +253,7 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe int IglFunc.GetUniformLocation(uint program, byte* ptr)
|
||||
{
|
||||
return api.GetUniformLocation(program, ptr);
|
||||
return api->glGetUniformLocation(program, ptr);
|
||||
}
|
||||
|
||||
unsafe bool IglFunc.GetWindowShouldClose(Form form)
|
||||
@@ -263,9 +274,9 @@ namespace StgSharp.Graphics
|
||||
unsafe void IglFunc.SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
|
||||
{
|
||||
int size = sizeof(T);
|
||||
api.BufferData(
|
||||
api->glBufferData(
|
||||
(uint)bufferType,
|
||||
size,
|
||||
(UIntPtr)size,
|
||||
&bufferData,
|
||||
(uint)usage);
|
||||
}
|
||||
@@ -274,14 +285,20 @@ namespace StgSharp.Graphics
|
||||
unsafe void IglFunc.SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
|
||||
fixed (void* bufferPtr = &bufferArray[0])
|
||||
api.BufferData(
|
||||
if (bufferArray == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
fixed (void* bufferPtr = bufferArray)
|
||||
api->glBufferData(
|
||||
(uint)bufferType,
|
||||
size,
|
||||
(UIntPtr)size,
|
||||
bufferPtr,
|
||||
(uint)usage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.SetFrameBufferSizeCallback(IntPtr id, FrameBufferSizeHandler handler)
|
||||
{
|
||||
@@ -290,11 +307,17 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.SetVertexAttribute(uint index, int size, Type t, bool normalized, int stride, int pointer)
|
||||
void IglFunc.SetVertexAttribute(uint index, int size, Type t, bool normalized, uint stride, int pointer)
|
||||
{
|
||||
uint type = InternalIO.GLtype[t];
|
||||
api.VertexAttribPointer(index, size, type, normalized, stride, (void*)pointer);
|
||||
api.EnableVertexAttribArray(index);
|
||||
api->glVertexAttribPointer(index, size, type, normalized, stride, (void*)pointer);
|
||||
api->glEnableVertexAttribArray(index);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.SetWindowShouldClose(Form form, bool mark)
|
||||
{
|
||||
InternalIO.glfw.SetWindowShouldClose(form.windowID, mark ? 1 : 0);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.SwapBuffers(Form form)
|
||||
@@ -306,27 +329,31 @@ namespace StgSharp.Graphics
|
||||
InternalIO.glfw.SwapBuffers(form.windowID);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.TextureImage2d(uint target, int level, uint internalformat, int width, int height, uint format, uint type, void* pixels)
|
||||
void IglFunc.TextureImage2d(uint target, int level, uint internalformat, uint width, uint height, uint format, uint type, void* pixels)
|
||||
{
|
||||
api.TexImage2D(
|
||||
api->glTexImage2D(
|
||||
target, level, internalformat, width, height, 0, format, type, pixels
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.TextureParameter(uint target, uint pname, int param)
|
||||
{
|
||||
api.TexParameteri(target, pname, param);
|
||||
api->glTexParameteri(target, pname, param);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.UseProgram(uint program)
|
||||
{
|
||||
api.UseProgram(program);
|
||||
api->glUseProgram(program);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.Viewport(int x, int y, int width, int height)
|
||||
void IglFunc.Viewport(int x, int y, uint width, uint height)
|
||||
{
|
||||
api.Viewport(x, y, width, height);
|
||||
api->glViewport(x, y, width, height);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -10,217 +11,97 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
internal class GLonTimeout : IglFunc
|
||||
{
|
||||
FrameTimeoutException refreshSIgnal = new FrameTimeoutException();
|
||||
FrameTimeoutException signal = new FrameTimeoutException("This frame is timeout");
|
||||
|
||||
private static readonly GLonTimeout singleInstance
|
||||
= new GLonTimeout();
|
||||
|
||||
FrameTimeoutException refreshSIgnal = new FrameTimeoutException();
|
||||
FrameTimeoutException signal = new FrameTimeoutException("This frame is timeout");
|
||||
private GLonTimeout() { }
|
||||
|
||||
internal static GLonTimeout Set()
|
||||
{
|
||||
return singleInstance;
|
||||
}
|
||||
void IglFunc.ActiveTexture(uint type) => throw signal;
|
||||
|
||||
void IglFunc.ActiveTexture(uint type)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
void IglFunc.AfterAlign(Form form, Action action) => throw signal;
|
||||
|
||||
void IglFunc.AfterAlign(Form form, Action action)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
void IglFunc.AlignFrame(Form form) => throw signal;
|
||||
|
||||
void IglFunc.AlignFrame(Form form)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
void IglFunc.AttachShader(uint program, uint shader) => throw signal;
|
||||
|
||||
void IglFunc.AttachShader(uint program, uint shader)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
void IglFunc.BindBuffer(BufferType bufferType, uint index) => throw signal;
|
||||
|
||||
void IglFunc.BindBuffer(BufferType bufferType, uint index)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
void IglFunc.BindTexture(uint type, uint texture) => throw signal;
|
||||
|
||||
void IglFunc.BindTexture(uint type, uint texture)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
void IglFunc.BindVertexArray(uint index) => throw signal;
|
||||
|
||||
void IglFunc.BindVertexArray(uint index)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
void IglFunc.Clear(MaskBufferBit mask) => throw signal;
|
||||
|
||||
void IglFunc.Clear(MaskBufferBit mask)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
void IglFunc.ClearColor(float R, float G, float B, float A) => throw signal;
|
||||
|
||||
void IglFunc.ClearColor(float R, float G, float B, float A)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
void IglFunc.ClearGraphicError() => throw signal;
|
||||
|
||||
void IglFunc.ClearGraphicError()
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
uint IglFunc.CompileShader(string shaderCode, ShaderType shaderType) => throw signal;
|
||||
|
||||
uint IglFunc.CompileShader(string shaderCode, ShaderType shaderType)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
uint IglFunc.CreateProgram() => throw signal;
|
||||
|
||||
uint IglFunc.CreateProgram()
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
IntPtr IglFunc.CreateWindowHandle(int width, int height, string tittle, IntPtr monitor, Form share) => throw signal;
|
||||
|
||||
IntPtr IglFunc.CreateWindowHandle(int width, int height, string tittle, IntPtr monitor, Form share)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
uint IglFunc.CreatGraphicProgram() => throw signal;
|
||||
|
||||
uint IglFunc.CreatGraphicProgram()
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
public void DeleteBuffer(uint handle) => throw signal;
|
||||
|
||||
unsafe void IglFunc.DeleteBuffers(int count, uint* ptr)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
unsafe void IglFunc.DeleteBuffers(uint count, uint[] ptr) => throw signal;
|
||||
|
||||
unsafe void IglFunc.DeleteVertexArrays(int count, uint* ptr)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
unsafe void IglFunc.DeleteVertexArrays(uint count, uint[] ptr) => throw signal;
|
||||
|
||||
void IglFunc.DrawElements(GepmetryType mode, int count, Type type, IntPtr ptr)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
void IglFunc.DrawElements(GepmetryType mode, uint count, Type type, IntPtr ptr) => throw signal;
|
||||
|
||||
unsafe void IglFunc.GenBuffers(int count, uint* ptr)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
unsafe void IglFunc.GenBuffers(uint count, uint* ptr) => throw signal;
|
||||
|
||||
unsafe void IglFunc.GenTextures(int count, uint* ptr)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
unsafe void IglFunc.GenTextures(uint count, uint* ptr) => throw signal;
|
||||
|
||||
unsafe void IglFunc.GenVertexArrays(int count, uint* ptr)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
unsafe void IglFunc.GenVertexArrays(uint count, uint* ptr) => throw signal;
|
||||
|
||||
void IglFunc.GetGraphicError()
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
void IglFunc.GetGraphicError() => throw signal;
|
||||
|
||||
unsafe int IglFunc.GetUniformLocation(uint program, byte* ptr)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
unsafe int IglFunc.GetUniformLocation(uint program, byte* ptr) => throw signal;
|
||||
|
||||
bool IglFunc.GetWindowShouldClose(Form form)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
bool IglFunc.GetWindowShouldClose(Form form) => throw signal;
|
||||
|
||||
void IglFunc.MakeContexCurrent(Form form)
|
||||
{
|
||||
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 bufferData, BufferUsage usage) => throw signal;
|
||||
|
||||
void IglFunc.SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
void IglFunc.SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage) => throw signal;
|
||||
|
||||
void IglFunc.SetFrameBufferSizeCallback(IntPtr id, FrameBufferSizeHandler handler)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
void IglFunc.SetFrameBufferSizeCallback(IntPtr id, FrameBufferSizeHandler handler) => 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, 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, 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, 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, float> uniform, float v0, float v1) => throw signal;
|
||||
|
||||
void IglFunc.SetValue(Uniform<float> uniform, float v0)
|
||||
{
|
||||
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<int> uniform, int i0) => throw signal;
|
||||
|
||||
void IglFunc.SetValue(Uniform<Vec4d> uniform, Vec4d vec)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
void IglFunc.SetValue(Uniform<Vec4d> uniform, Vec4d vec) => throw signal;
|
||||
|
||||
void IglFunc.SetVertexAttribute(uint index, int size, Type t, bool normalized, int stride, int pointer)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
void IglFunc.SetVertexAttribute(uint index, int size, Type t, bool normalized, uint stride, int pointer) => throw signal;
|
||||
|
||||
void IglFunc.SwapBuffers(Form form)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
void IglFunc.SwapBuffers(Form form) => throw signal;
|
||||
|
||||
unsafe void IglFunc.TextureImage2d(uint target, int level, uint internalformat, int width, int height, uint format, uint type, void* pixels)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
unsafe void IglFunc.TextureImage2d(uint target, int level, uint internalformat, uint width, uint height, uint format, uint type, void* pixels) => throw signal;
|
||||
|
||||
void IglFunc.TextureParameter(uint target, uint pname, int param)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
void IglFunc.TextureParameter(uint target, uint pname, int param) => throw signal;
|
||||
|
||||
void IglFunc.UseProgram(uint program)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
void IglFunc.UseProgram(uint program) => throw signal;
|
||||
|
||||
void IglFunc.Viewport(int x, int y, int width, int height)
|
||||
{
|
||||
throw signal;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,55 @@
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
internal partial class GLonUpdate : IglFunc
|
||||
{
|
||||
private FrameTimeoutException refreshSignal = new();
|
||||
internal readonly GLcontext api;
|
||||
using glMetaData = (
|
||||
int i0, int i1, int i2, int i3,
|
||||
double d0, double d1, double d2, double d3,
|
||||
IntPtr p0, IntPtr p1, IntPtr p2, IntPtr p3
|
||||
);
|
||||
|
||||
internal GLonUpdate(GLcontext context)
|
||||
internal unsafe partial class GLonUpdate : IglFunc
|
||||
{
|
||||
|
||||
internal GLcontext* api;
|
||||
private ConcurrentQueue<Action> glActionQueue;
|
||||
private FrameTimeoutException refreshSignal = new();
|
||||
private DynamicArrayList<glMetaData> threadBuffer = new DynamicArrayList<glMetaData>(16, default);
|
||||
|
||||
ConcurrentQueue<Action<int>> GLactionQueue
|
||||
{
|
||||
get
|
||||
{
|
||||
return glActionQueue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal GLonUpdate(GLcontext* context)
|
||||
{
|
||||
api = context;
|
||||
glActionQueue = new ConcurrentQueue<Action>();
|
||||
glActionQueue.Enqueue(() => { });
|
||||
}
|
||||
|
||||
void IglFunc.ActiveTexture(uint type)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
api->glActiveTexture(type);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,52 +69,125 @@ namespace StgSharp.Graphics
|
||||
throw refreshSignal;
|
||||
}
|
||||
|
||||
void IglFunc.AttachShader(uint program, uint shader)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.AttachShader(uint program, uint shader)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() => api->glAttachShader(program, shader)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.BindBuffer(BufferType bufferType, uint index)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() => api->glBindBuffer((uint)bufferType, index)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.BindTexture(uint type, uint texture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() => api->glBindTexture((uint)type, texture)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.BindVertexArray(uint index)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() => api->glBindVertexArray((uint)index)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.Clear(MaskBufferBit mask)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() => api->glClear((uint)mask)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void IglFunc.ClearColor(float R, float G, float B, float A)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() => api->glClearColor(R, G, B, A)
|
||||
);
|
||||
}
|
||||
|
||||
void IglFunc.ClearGraphicError()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
while (api->glGetError() != 0) { };
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
uint IglFunc.CompileShader(string shaderCode, ShaderType shaderType)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
int id = -1;
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
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);
|
||||
}
|
||||
Interlocked.Add(ref id, (int)(shaderID + 1));
|
||||
}
|
||||
);
|
||||
while (id < 0) { }
|
||||
return (uint)id;
|
||||
}
|
||||
|
||||
|
||||
uint IglFunc.CreateProgram()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
int id = -1;
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
int ret = (int)api->glCreateProgram();
|
||||
Interlocked.Add(ref id, ret + 1);
|
||||
}
|
||||
);
|
||||
while (id < 0) { }
|
||||
return (uint)id;
|
||||
}
|
||||
|
||||
IntPtr IglFunc.CreateWindowHandle(int width, int height, string tittle, IntPtr monitor, Form share)
|
||||
@@ -118,44 +218,118 @@ namespace StgSharp.Graphics
|
||||
|
||||
uint IglFunc.CreatGraphicProgram()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
int id = 0;
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
Interlocked.Add(ref id, (int)(api->glCreateProgram() + 1));
|
||||
}
|
||||
);
|
||||
while (id < 0) { }
|
||||
return (uint)id;
|
||||
}
|
||||
|
||||
|
||||
unsafe void IglFunc.DeleteBuffers(int count, uint* ptr)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.SetWindowShouldClose(Form form, bool mark)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
InternalIO.glfw.SetWindowShouldClose(form.windowID, mark ? 1 : 0);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.DeleteVertexArrays(int count, uint* ptr)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.DeleteBuffer(uint handle)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
uint target = handle;
|
||||
api->glDeleteBuffers(1, &target);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public void DrawElements(GepmetryType mode, int count, Type type, IntPtr ptr)
|
||||
unsafe void IglFunc.DeleteBuffers(uint count, uint[] handle)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
uint[] h = handle;
|
||||
fixed (uint* p = h)
|
||||
{
|
||||
api->glDeleteBuffers(count, p);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void IglFunc.DrawElements(GepmetryType mode, int count, Type type, IntPtr ptr)
|
||||
unsafe void IglFunc.DeleteVertexArrays(uint count, uint[] arrays)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
uint[] target = arrays;
|
||||
fixed (uint* ptr = target)
|
||||
{
|
||||
api->glDeleteVertexArrays(count, ptr);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.GenBuffers(int count, uint* ptr)
|
||||
void IglFunc.DrawElements(GepmetryType mode, uint count, Type type, IntPtr ptr)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
uint a;
|
||||
switch (Type.GetTypeCode(type))
|
||||
{
|
||||
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:
|
||||
InternalIO.InternalWriteLog(
|
||||
$"Parameter error in parameter {nameof(type)} method DrawElements. " +
|
||||
$"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are suporrted.",
|
||||
LogType.Error);
|
||||
return;
|
||||
}
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{ api->glDrawElements((uint)mode, count, a, (void*)ptr); }
|
||||
);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.GenTextures(int count, uint* ptr)
|
||||
unsafe void IglFunc.GenBuffers(uint count, uint* ptr)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
api->glGenBuffers(count, ptr);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.GenVertexArrays(int count, uint* ptr)
|
||||
unsafe void IglFunc.GenTextures(uint count, uint* ptr)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
api->glGenTextures(count, ptr);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
unsafe void IglFunc.GenVertexArrays(uint count, uint* ptr)
|
||||
{
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
api->glGenVertexArrays(count, ptr);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public void GetGraphicError()
|
||||
@@ -168,25 +342,26 @@ namespace StgSharp.Graphics
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public unsafe int GetUniformLocation(uint program, byte* ptr)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
unsafe int IglFunc.GetUniformLocation(uint program, byte* ptr)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
int ret = -1;
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
int location = api->glGetUniformLocation(program, ptr);
|
||||
Interlocked.Add(ref ret, location + 1);
|
||||
}
|
||||
);
|
||||
while (ret < 0) { }
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool GetWindowShouldClose(Form form)
|
||||
{
|
||||
return InternalIO.glfw.WindowShouldClose(form.windowID) == 0;
|
||||
}
|
||||
|
||||
bool IglFunc.GetWindowShouldClose(Form form)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return InternalIO.glfw.WindowShouldClose(form.windowID) == 0;
|
||||
}
|
||||
|
||||
public void GLswapBuffers(Form form)
|
||||
@@ -198,7 +373,8 @@ namespace StgSharp.Graphics
|
||||
InternalIO.glfw.SwapBuffers(form.windowID);
|
||||
}
|
||||
|
||||
public void MakeContexCurrent(Form form)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.MakeContexCurrent(Form form)
|
||||
{
|
||||
if (form.windowID == IntPtr.Zero)
|
||||
{
|
||||
@@ -207,29 +383,40 @@ namespace StgSharp.Graphics
|
||||
InternalIO.glfw.MakeContextCurrent(form.windowID);
|
||||
}
|
||||
|
||||
void IglFunc.MakeContexCurrent(Form form)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage) where T : IMat
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage) where T : struct, IConvertible
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IglFunc.SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
T data = bufferData;
|
||||
int size = sizeof(T);
|
||||
api->glBufferData(
|
||||
(uint)bufferType,
|
||||
(UIntPtr)size,
|
||||
&data,
|
||||
(uint)usage);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void IglFunc.SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
|
||||
if (bufferArray == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
fixed (void* bufferPtr = bufferArray)
|
||||
api->glBufferData(
|
||||
(uint)bufferType,
|
||||
(UIntPtr)size,
|
||||
bufferPtr,
|
||||
(uint)usage);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -240,44 +427,70 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
|
||||
void IglFunc.SetVertexAttribute(uint index, int size, Type t, bool normalized, int stride, int pointer)
|
||||
void IglFunc.SetVertexAttribute(uint index, int size, Type t, bool normalized, uint stride, int pointer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
uint type = InternalIO.GLtype[t];
|
||||
api->glVertexAttribPointer(index, size, type, normalized, stride, (void*)pointer);
|
||||
api->glEnableVertexAttribArray(index);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void IglFunc.SwapBuffers(Form form)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
if (form.windowID == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
InternalIO.glfw.SwapBuffers(form.windowID);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public unsafe void TextureImage2d(uint target, int level, uint internalformat, int width, int height, uint format, uint type, void* pixels)
|
||||
unsafe void IglFunc.TextureImage2d(uint target, int level, uint internalformat, uint width, uint height, uint format, uint type, void* pixels)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
unsafe void IglFunc.TextureImage2d(uint target, int level, uint internalformat, int width, int height, uint format, uint type, void* pixels)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void TextureParameter(uint target, uint pname, int param)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
api->glTexImage2D(target, level, internalformat, width, height, 0, format, type, pixels);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void IglFunc.TextureParameter(uint target, uint pname, int param)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
api->glTextureParameteri(target, pname, param);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void IglFunc.UseProgram(uint rogram)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
api->glUseProgram(rogram);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void IglFunc.Viewport(int x, int y, int width, int height)
|
||||
void IglFunc.Viewport(int x, int y, uint width, uint height)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
api->glViewport(x, y, width, height);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,102 +18,158 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
return new Shader(GL);
|
||||
}
|
||||
}
|
||||
|
||||
public class Shader
|
||||
public class Shader
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="uint"/> value represent this shader.
|
||||
/// </summary>
|
||||
public readonly uint programID;
|
||||
internal uint vertexShaderID;
|
||||
internal uint fragmentShaderID;
|
||||
private IglFunc GL;
|
||||
|
||||
/// <summary>
|
||||
/// Inti a shader with no program attached.
|
||||
/// </summary>
|
||||
internal unsafe Shader(IglFunc gl)
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="uint"/> value represent this shader.
|
||||
/// </summary>
|
||||
public readonly uint programID;
|
||||
internal uint vertexShaderID;
|
||||
internal uint fragmentShaderID;
|
||||
private IglFunc GL;
|
||||
|
||||
/// <summary>
|
||||
/// Inti a shader with no program attached.
|
||||
/// </summary>
|
||||
internal unsafe Shader(IglFunc glFunc)
|
||||
{
|
||||
GL = glFunc;
|
||||
programID = GL.CreateProgram();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
{
|
||||
vertexShaderID = GL.CompileShader(shaderCode, ShaderType.VERTEX);
|
||||
GL.AttachShader(programID, vertexShaderID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compile the fragment shader to be attached to this shader.
|
||||
/// </summary>
|
||||
/// <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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Link the shader to current context.
|
||||
/// </summary>
|
||||
public void Link()
|
||||
{
|
||||
if (InternalIO.InternalLinkShaderProgram(programID) == 0)
|
||||
{
|
||||
IntPtr logPtr = InternalIO.InternalReadLog();
|
||||
try
|
||||
{
|
||||
byte[] logByte = new byte[512];
|
||||
Marshal.Copy(logPtr, logByte, 0, 512);
|
||||
string log = Encoding.UTF8.GetString(logByte);
|
||||
log = log.Replace("\0", "");
|
||||
InternalIO.InternalWriteLog(log, LogType.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
InternalIO.InternalWriteLog(ex.Message, LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader,
|
||||
/// the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public unsafe Uniform<T> GetUniform<T>(string name) where T : struct
|
||||
{
|
||||
byte[] bytes = Encoding.ASCII.GetBytes(name);
|
||||
int uniform;
|
||||
fixed (byte* ptr = bytes)
|
||||
{
|
||||
uniform = GL.GetUniformLocation(programID, ptr);
|
||||
}
|
||||
if (uniform != -1)
|
||||
{
|
||||
return new Uniform<T>(uniform);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Cannot find the uniform {name} in shader {programID}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Let the current context use this shader.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Use()
|
||||
{
|
||||
GL.UseProgram(programID);
|
||||
}
|
||||
|
||||
GL = gl;
|
||||
programID = GL.CreateProgram();
|
||||
}
|
||||
|
||||
internal void ChangeEnvironment(IglFunc gl)
|
||||
{
|
||||
GL = gl;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
{
|
||||
vertexShaderID = GL.CompileShader(shaderCode, ShaderType.VERTEX);
|
||||
GL.AttachShader(programID, vertexShaderID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compile the fragment shader to be attached to this shader.
|
||||
/// </summary>
|
||||
/// <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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Link the shader to current context.
|
||||
/// </summary>
|
||||
public void Link()
|
||||
{
|
||||
if (InternalIO.InternalLinkShaderProgram(programID) == 0)
|
||||
{
|
||||
IntPtr logPtr = InternalIO.InternalReadLog();
|
||||
try
|
||||
{
|
||||
byte[] logByte = new byte[512];
|
||||
Marshal.Copy(logPtr, logByte, 0, 512);
|
||||
string log = Encoding.UTF8.GetString(logByte);
|
||||
log = log.Replace("\0", "");
|
||||
InternalIO.InternalWriteLog(log, LogType.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
InternalIO.InternalWriteLog(ex.Message, LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader,
|
||||
/// the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the Uniform in shader code</param>
|
||||
/// <returns></returns>
|
||||
public unsafe Uniform<T> GetUniform<T>(string name) where T : struct
|
||||
{
|
||||
byte[] bytes = Encoding.ASCII.GetBytes(name);
|
||||
int uniform;
|
||||
fixed (byte* ptr = bytes)
|
||||
{
|
||||
uniform = GL.GetUniformLocation(programID, ptr);
|
||||
}
|
||||
if (uniform != -1)
|
||||
{
|
||||
return new Uniform<T>(uniform);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Cannot find the uniform {name} in shader {programID}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader,
|
||||
/// the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the Uniform in shader code</param>
|
||||
/// <returns></returns>
|
||||
public unsafe Uniform<T, U> GetUniform<T, U>(string name)
|
||||
where T : struct
|
||||
where U : struct
|
||||
{
|
||||
byte[] bytes = Encoding.ASCII.GetBytes(name);
|
||||
int uniform;
|
||||
fixed (byte* ptr = bytes)
|
||||
{
|
||||
uniform = GL.GetUniformLocation(programID, ptr);
|
||||
}
|
||||
if (uniform != -1)
|
||||
{
|
||||
return new Uniform<T, U>(uniform);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Cannot find the uniform {name} in shader {programID}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader,
|
||||
/// the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the Uniform in shader code</param>
|
||||
/// <returns></returns>
|
||||
public unsafe Uniform<T, U, V> GetUniform<T, U, V>(string name)
|
||||
where T : struct
|
||||
where U : struct
|
||||
where V : struct
|
||||
{
|
||||
byte[] bytes = Encoding.ASCII.GetBytes(name);
|
||||
int uniform;
|
||||
fixed (byte* ptr = bytes)
|
||||
{
|
||||
uniform = GL.GetUniformLocation(programID, ptr);
|
||||
}
|
||||
if (uniform != -1)
|
||||
{
|
||||
return new Uniform<T, U, V>(uniform);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Cannot find the uniform {name} in shader {programID}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Let the current context use this shader.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Use()
|
||||
{
|
||||
GL.UseProgram(programID);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
@@ -14,13 +15,13 @@ namespace StgSharp.Graphics
|
||||
private IglFunc GL;
|
||||
|
||||
internal unsafe Uniform(
|
||||
Form.Shader program, string name, IglFunc gL)
|
||||
uint shaderID, string name, IglFunc gL)
|
||||
{
|
||||
byte[] namearray = Encoding.ASCII.GetBytes(name);
|
||||
GL = gL;
|
||||
fixed (byte* ptr = namearray)
|
||||
{
|
||||
id = GL.GetUniformLocation(program.programID, ptr);
|
||||
id = GL.GetUniformLocation(shaderID, ptr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +41,7 @@ namespace StgSharp.Graphics
|
||||
private IglFunc GL;
|
||||
|
||||
internal unsafe Uniform(
|
||||
Form.Shader program, string name, IglFunc glFunc)
|
||||
Shader program, string name, IglFunc glFunc)
|
||||
{
|
||||
byte[] namearray = Encoding.ASCII.GetBytes(name);
|
||||
GL = glFunc;
|
||||
@@ -64,7 +65,7 @@ namespace StgSharp.Graphics
|
||||
internal int id;
|
||||
private IglFunc GL;
|
||||
|
||||
public unsafe Uniform(Form.Shader program, string name, IglFunc glFunc)
|
||||
public unsafe Uniform(Shader program, string name, IglFunc glFunc)
|
||||
{
|
||||
byte[] namearray = Encoding.ASCII.GetBytes(name);
|
||||
GL = glFunc;
|
||||
@@ -89,7 +90,7 @@ namespace StgSharp.Graphics
|
||||
internal int id;
|
||||
private IglFunc GL;
|
||||
|
||||
internal unsafe Uniform(Form.Shader program, string name, IglFunc glFunc)
|
||||
internal unsafe Uniform(Shader program, string name, IglFunc glFunc)
|
||||
{
|
||||
byte[] namearray = Encoding.ASCII.GetBytes(name);
|
||||
fixed (byte* ptr = namearray)
|
||||
@@ -108,125 +109,107 @@ namespace StgSharp.Graphics
|
||||
|
||||
internal partial class GLonRender : IglFunc
|
||||
{
|
||||
/// <summary>
|
||||
/// Set data value to a float <see cref="Uniform{T}"/>,
|
||||
/// all types of parameters are float.
|
||||
/// </summary>
|
||||
/// <param name="uniform">The <see cref="Uniform{T}"/> target</param>
|
||||
/// <param name="v0">The value to be set</param>
|
||||
void IglFunc.SetValue(Uniform<float> uniform, float v0)
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.SetValue(Uniform<float> uniform, float v0)
|
||||
{
|
||||
api.Uniform1f(uniform.id, v0);
|
||||
api->glUniform1f(uniform.id, v0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data value to a int <see cref="Uniform{T}"/>,
|
||||
/// all types of parameters are int.
|
||||
/// </summary>
|
||||
/// <param name="uniform">The <see cref="Uniform{T}"/> target</param>
|
||||
/// <param name="i0">The value to be set</param>
|
||||
void IglFunc.SetValue(Uniform<int> uniform, int i0)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.SetValue(Uniform<int> uniform, int i0)
|
||||
{
|
||||
api.Uniform1i(uniform.id, i0);
|
||||
api->glUniform1i(uniform.id, i0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data value to a float <see cref="Uniform{T,U}"/>,
|
||||
/// all types of parameters are float.
|
||||
/// </summary>
|
||||
/// <param name="uniform">The <see cref="Uniform{T,U}"/> target</param>
|
||||
/// <param name="v0">The first value to be set</param>
|
||||
/// <param name="v1">The second value to be set</param>
|
||||
void IglFunc.SetValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.SetValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
{
|
||||
api.Uniform2f(uniform.id, v0, v1);
|
||||
api->glUniform2f(uniform.id, v0, v1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data value to a float <see cref="Uniform{T,U,V}"/>,
|
||||
/// all types of parameters are float.
|
||||
/// </summary>
|
||||
/// <param name="uniform">The <see cref="Uniform{T,U,V}"/> target</param>
|
||||
/// <param name="v0">The first value to be set</param>
|
||||
/// <param name="v1">The second value to be set</param>
|
||||
/// <param name="v2">The third value to be set</param>
|
||||
void IglFunc.SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
||||
{
|
||||
api.Uniform3f(uniform.id, v0, v1, v2);
|
||||
api->glUniform3f(uniform.id, v0, v1, v2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data value to a float <see cref="Uniform{T,U,V,W}"/>,
|
||||
/// all types of parameters are float.
|
||||
/// </summary>
|
||||
/// <param name="uniform">The <see cref="Uniform{T,U,V,W}"/> target</param>
|
||||
/// <param name="v0">The first value to be set</param>
|
||||
/// <param name="v1">The second value to be set</param>
|
||||
/// <param name="v2">The third value to be set</param>
|
||||
/// <param name="v3">The forth value to be set</param>
|
||||
void IglFunc.SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
{
|
||||
api.Uniform4f(uniform.id, v0, v1, v2, v3);
|
||||
api->glUniform4f(uniform.id, v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data value to a float <see cref="Uniform{T,U,V,W}"/>,
|
||||
/// all types of parameters are float.
|
||||
/// </summary>
|
||||
/// <param name="uniform">The <see cref="Uniform{T,U,V,W}"/> target</param>
|
||||
/// <param name="vec">A <see cref="Vec4d"/> packing four parameters of the uniform </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
|
||||
{
|
||||
api.Uniform1fv(uniform.id, 4, &vec.fvec);
|
||||
api->glUniform1fv(uniform.id, 4, &vec);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data value to a float <see cref="Uniform{T}"/>,
|
||||
/// all types of parameters are <see cref="Vec4d"/>.
|
||||
/// </summary>
|
||||
/// <param name="uniform">The <see cref="Uniform{T}"/> target</param>
|
||||
/// <param name="vec">A <see cref="Vec4d"/> value of the uniform </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void SetValue(Uniform<Vec4d> uniform, Vec4d vec)
|
||||
{
|
||||
api.Uniform1fv(uniform.id, 4, &vec.fvec);
|
||||
api->glUniform1fv(uniform.id, 4, &vec);
|
||||
}
|
||||
}
|
||||
|
||||
internal partial class GLonUpdate
|
||||
{
|
||||
void IglFunc.SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
||||
unsafe void IglFunc.SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() => { api->glUniform3f(uniform.id, v0, v1, v2); }
|
||||
);
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
unsafe void IglFunc.SetValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() => { api->glUniform2f(uniform.id, v0, v1); }
|
||||
);
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
unsafe void IglFunc.SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() => { api->glUniform4f(uniform.id, v0, v1, v2, v3); }
|
||||
);
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
|
||||
unsafe void IglFunc.SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
Vec4d cache = vec;
|
||||
api->glUniform1fv(uniform.id, 4, &cache);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<float> uniform, float v0)
|
||||
unsafe void IglFunc.SetValue(Uniform<float> uniform, float v0)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() => { api->glUniform1f(uniform.id, v0); }
|
||||
);
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<int> uniform, int i0)
|
||||
unsafe void IglFunc.SetValue(Uniform<int> uniform, int i0)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() => { api->glUniform1d(uniform.id, i0); }
|
||||
);
|
||||
}
|
||||
|
||||
void IglFunc.SetValue(Uniform<Vec4d> uniform, Vec4d vec)
|
||||
unsafe void IglFunc.SetValue(Uniform<Vec4d> uniform, Vec4d vec)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
glActionQueue.Enqueue(
|
||||
() =>
|
||||
{
|
||||
Vec4d cache = vec;
|
||||
api->glUniform1fv(uniform.id, 4, &cache);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Controlling
|
||||
{
|
||||
public static class Graphic
|
||||
{
|
||||
public static void Render()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,17 @@
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public interface IglFunc
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Align a sets of code to frame update of a <see cref="Form"/>.
|
||||
/// Usually, a call of <see cref="AfterAlign(Form,Action)"/> is required.
|
||||
/// This method is used as sigle thread method. If more than one
|
||||
/// alignment is requested, a <see cref="InvalidOperationException"/> will throw.
|
||||
/// Same function as OpenGL api glActiveTexture
|
||||
/// </summary>
|
||||
/// <param name="form">The form used as frame update benchmark.</param>
|
||||
/// <exception cref="InvalidOperationException">More than one alingment attached to one form timer</exception>
|
||||
void AlignFrame(Form form);
|
||||
/// <param name="type">type of texture to activate</param>
|
||||
void ActiveTexture(uint type);
|
||||
|
||||
/// <summary>
|
||||
/// Operation after alignment by calling <see cref="AlignFrame(Form)"/>.
|
||||
@@ -28,10 +26,14 @@ namespace StgSharp.Graphics
|
||||
void AfterAlign(Form form, Action action);
|
||||
|
||||
/// <summary>
|
||||
/// Same function as OpenGL api glActiveTexture
|
||||
/// Align a sets of code to frame update of a <see cref="Form"/>.
|
||||
/// Usually, a call of <see cref="AfterAlign(Form,Action)"/> is required.
|
||||
/// This method is used as sigle thread method. If more than one
|
||||
/// alignment is requested, a <see cref="InvalidOperationException"/> will throw.
|
||||
/// </summary>
|
||||
/// <param name="type">type of texture to activate</param>
|
||||
void ActiveTexture(uint type);
|
||||
/// <param name="form">The form used as frame update benchmark.</param>
|
||||
/// <exception cref="InvalidOperationException">More than one alingment attached to one form timer</exception>
|
||||
void AlignFrame(Form form);
|
||||
|
||||
/// <summary>
|
||||
/// Same fucntion as OpenGL api glAttachShader
|
||||
@@ -76,6 +78,7 @@ namespace StgSharp.Graphics
|
||||
/// <param name="B">Specify the red values used when the color buffers are cleared.</param>
|
||||
/// <param name="A">Specify the red values used when the color buffers are cleared.</param>
|
||||
void ClearColor(float R, float G, float B, float A);
|
||||
|
||||
void ClearGraphicError();
|
||||
|
||||
/// <summary>
|
||||
@@ -96,53 +99,59 @@ namespace StgSharp.Graphics
|
||||
/// <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>
|
||||
/// <param name="monitor"></param>
|
||||
/// <param name="share"></param>
|
||||
/// <returns>The instance of created form</returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
IntPtr CreateWindowHandle(int width, int height, string tittle, IntPtr monitor, Form share);
|
||||
|
||||
uint CreatGraphicProgram();
|
||||
|
||||
/// <summary>
|
||||
/// Same function as OpenGL api, glDeleteBuffer.
|
||||
/// Same function as OpenGL api, glDeleteBuffer. This method can delete one buffer in one call
|
||||
/// </summary>
|
||||
/// <param name="handle">a handle representing the buffer to be deleted</param>
|
||||
unsafe void DeleteBuffer(uint handle);
|
||||
|
||||
/// <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="ptr">Pointer of buffer to be deleted</param>
|
||||
unsafe void DeleteBuffers(int count, uint* ptr);
|
||||
/// <param name="handle">Array of buffers to be deleted</param>
|
||||
unsafe void DeleteBuffers(uint count, uint[] handle);
|
||||
|
||||
/// <summary>
|
||||
/// Same function as OpenGL api, glDeleteVertexArrays
|
||||
/// </summary>
|
||||
/// <param name="count">Amount of vao to be deleted</param>
|
||||
/// <param name="ptr">pointer of vao sign array</param>
|
||||
unsafe void DeleteVertexArrays(int count, uint* ptr);
|
||||
/// <param name="arrays">A array representing a colletion of vertex objects.</param>
|
||||
unsafe void DeleteVertexArrays(uint count, uint[] arrays);
|
||||
|
||||
void DrawElements(GepmetryType mode, int count, Type type, IntPtr ptr);
|
||||
void DrawElements(GepmetryType mode, uint count, Type type, IntPtr ptr);
|
||||
|
||||
/// <summary>
|
||||
/// Same fucntion as the OpenGL api glGenBuffers
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
/// <param name="ptr"></param>
|
||||
unsafe void GenBuffers(int count, uint* ptr);
|
||||
unsafe void GenBuffers(uint count, uint* 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(int count, uint* ptr);
|
||||
unsafe void GenTextures(uint count, uint* ptr);
|
||||
|
||||
/// <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(int count, uint* ptr);
|
||||
unsafe void GenVertexArrays(uint count, uint* ptr);
|
||||
|
||||
void GetGraphicError();
|
||||
|
||||
@@ -174,18 +183,66 @@ namespace StgSharp.Graphics
|
||||
/// <param name="handler">Method hadler </param>
|
||||
void SetFrameBufferSizeCallback(IntPtr id, FrameBufferSizeHandler handler);
|
||||
|
||||
/// <summary>
|
||||
/// Set data value to a float <see cref="Uniform{T,U,V,W}"/>,
|
||||
/// all types of parameters are float.
|
||||
/// </summary>
|
||||
/// <param name="uniform">The <see cref="Uniform{T,U,V,W}"/> target</param>
|
||||
/// <param name="v0">The first value to be set</param>
|
||||
/// <param name="v1">The second value to be set</param>
|
||||
/// <param name="v2">The third value to be set</param>
|
||||
/// <param name="v3">The forth value to be set</param>
|
||||
void SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3);
|
||||
|
||||
/// <summary>
|
||||
/// Set data value to a float <see cref="Uniform{T,U,V,W}"/>,
|
||||
/// all types of parameters are float.
|
||||
/// </summary>
|
||||
/// <param name="uniform">The <see cref="Uniform{T,U,V,W}"/> target</param>
|
||||
/// <param name="vec">A <see cref="Vec4d"/> packing four parameters of the uniform </param>
|
||||
void SetValue(Uniform<float, float, float, float> uniform, Vec4d vec);
|
||||
|
||||
/// <summary>
|
||||
/// Set data value to a float <see cref="Uniform{T,U,V}"/>,
|
||||
/// all types of parameters are float.
|
||||
/// </summary>
|
||||
/// <param name="uniform">The <see cref="Uniform{T,U,V}"/> target</param>
|
||||
/// <param name="v0">The first value to be set</param>
|
||||
/// <param name="v1">The second value to be set</param>
|
||||
/// <param name="v2">The third value to be set</param>
|
||||
void SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2);
|
||||
|
||||
/// <summary>
|
||||
/// Set data value to a float <see cref="Uniform{T,U}"/>,
|
||||
/// all types of parameters are float.
|
||||
/// </summary>
|
||||
/// <param name="uniform">The <see cref="Uniform{T,U}"/> target</param>
|
||||
/// <param name="v0">The first value to be set</param>
|
||||
/// <param name="v1">The second value to be set</param>
|
||||
void SetValue(Uniform<float, float> uniform, float v0, float v1);
|
||||
|
||||
/// <summary>
|
||||
/// Set data value to a float <see cref="Uniform{T}"/>,
|
||||
/// all types of parameters are float.
|
||||
/// </summary>
|
||||
/// <param name="uniform">The <see cref="Uniform{T}"/> target</param>
|
||||
/// <param name="v0">The value to be set</param>
|
||||
void SetValue(Uniform<float> uniform, float v0);
|
||||
|
||||
/// <summary>
|
||||
/// Set data value to a int <see cref="Uniform{T}"/>,
|
||||
/// all types of parameters are int.
|
||||
/// </summary>
|
||||
/// <param name="uniform">The <see cref="Uniform{T}"/> target</param>
|
||||
/// <param name="i0">The value to be set</param>
|
||||
void SetValue(Uniform<int> uniform, int i0);
|
||||
|
||||
/// <summary>
|
||||
/// Set data value to a float <see cref="Uniform{T}"/>,
|
||||
/// all types of parameters are <see cref="Vec4d"/>.
|
||||
/// </summary>
|
||||
/// <param name="uniform">The <see cref="Uniform{T}"/> target</param>
|
||||
/// <param name="vec">A <see cref="Vec4d"/> value of the uniform </param>
|
||||
void SetValue(Uniform<Vec4d> uniform, Vec4d vec);
|
||||
|
||||
/// <summary>
|
||||
@@ -197,7 +254,7 @@ namespace StgSharp.Graphics
|
||||
/// <param name="normalized"></param>
|
||||
/// <param name="stride">Pixels stride of each sets of data</param>
|
||||
/// <param name="pointer"></param>
|
||||
void SetVertexAttribute(uint index, int size, Type t, bool normalized, int stride, int pointer);
|
||||
void SetVertexAttribute(uint index, int size, Type t, bool normalized, uint stride, int pointer);
|
||||
|
||||
void SwapBuffers(Form form);
|
||||
|
||||
@@ -212,7 +269,7 @@ namespace StgSharp.Graphics
|
||||
/// <param name="format">color channels of this image</param>
|
||||
/// <param name="type">how this image express each pixel</param>
|
||||
/// <param name="pixels">pointer to data array of pixels</param>
|
||||
unsafe void TextureImage2d(uint target, int level, uint internalformat, int width, int height, uint format, uint type, void* pixels);
|
||||
unsafe void TextureImage2d(uint target, int level, uint internalformat, uint width, uint height, uint format, uint type, void* pixels);
|
||||
|
||||
/// <summary>
|
||||
/// Same fucntion as OpenGL api glTexParameteri
|
||||
@@ -227,6 +284,7 @@ namespace StgSharp.Graphics
|
||||
/// </summary>
|
||||
/// <param name="program">Sign of program to be used</param>
|
||||
void UseProgram(uint program);
|
||||
|
||||
/// <summary>
|
||||
/// Same function as the OpenGL api, glViewPort
|
||||
/// </summary>
|
||||
@@ -234,7 +292,9 @@ namespace StgSharp.Graphics
|
||||
/// <param name="y"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
void Viewport(int x, int y, int width, int height);
|
||||
void Viewport(int x, int y, uint width, uint height);
|
||||
|
||||
void SetWindowShouldClose(Form form, bool mark);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user