85 lines
2.7 KiB
C#
85 lines
2.7 KiB
C#
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; }
|
|
}
|
|
|
|
internal sealed override void CreateCanvas((int width, int height, int depth) size, (int x_stretch, int y_stretch, int z_stretch) coordStrech, string name)
|
|
{
|
|
Width = size.width; Height = size.height;
|
|
Depth = size.depth;
|
|
_coordStretch = coordStrech;
|
|
Name = name;
|
|
|
|
|
|
}
|
|
|
|
/// <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();
|
|
}
|
|
}
|
|
}
|