daily update on 20240423 by nitload youmu, mvvm confirm
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public abstract partial class glRenderStream:RenderStream
|
||||
{
|
||||
protected IntPtr glContextHandle
|
||||
{
|
||||
get { return ContextHandle; }
|
||||
set { ContextHandle = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Init an OpenGl context if current form has not been binded to any context. and set the context binded to
|
||||
/// current form as current OpenGL context.
|
||||
/// </summary>
|
||||
/// <exception cref="Exception">
|
||||
/// Something goes wrong and StgSharp fails in creating a new OpenGL context.
|
||||
/// </exception>
|
||||
public unsafe void MakeAsCurrentContext()
|
||||
{
|
||||
if (CanvasHandle == default)
|
||||
{
|
||||
IntPtr windowPtr;
|
||||
byte[] tittleBytes = Encoding.UTF8.GetBytes(name);
|
||||
if (SharedCanvas == IntPtr.Zero)
|
||||
{
|
||||
windowPtr = InternalIO.glfwCreateWindow(Width, Height, tittleBytes, monitor, IntPtr.Zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
windowPtr = InternalIO.glfwCreateWindow(Width, Height, tittleBytes, monitor, SharedCanvas.CanvasHandle);
|
||||
}
|
||||
if (((long)windowPtr == -1) || ((long)windowPtr == -2))
|
||||
{
|
||||
throw new Exception("Cannot create window instance!");
|
||||
}
|
||||
else
|
||||
{
|
||||
CanvasHandle = windowPtr;
|
||||
}
|
||||
|
||||
ContextHandle = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GLcontext)));
|
||||
GLcontext* contextID = (GLcontext*)ContextHandle;
|
||||
*contextID = new GLcontext();
|
||||
contextID->glGetString = (delegate*<uint, IntPtr>)IntPtr.Zero;
|
||||
}
|
||||
GL.api = (GLcontext*)ContextHandle;
|
||||
InternalIO.glfwMakeContextCurrent(CanvasHandle);
|
||||
}
|
||||
|
||||
internal sealed override void InternalInit()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
internal sealed override void InternalDraw()
|
||||
{
|
||||
MakeAsCurrentContext();
|
||||
Main();
|
||||
}
|
||||
|
||||
|
||||
internal sealed override void InternalTerminate()
|
||||
{
|
||||
Deinit();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user