using StgSharp.Control;
using StgSharp.Graphics;
using System;
namespace StgSharp
{
public static unsafe partial class Graphic
{
internal static GraphicIOPack glIO;
private static bool isGLSet = false;
///
/// Init an instance of OpenGL program,
/// This method should be called before other
/// graphic methods, after LoadGL method.
///
public static void InitGL()
{
internalIO.InternalInitGL();
}
///
/// Load OpenGL API to StgSharp core programm,
/// please call this method before call any other
/// graphic APIs in StgSharp.
///
/// If run this method twice, will throw exception
public static unsafe void LoadGL()
{
if (!isGLSet)
{
glIO = internalIO.InternalInitGraphicApi();
}
else
{
throw new Exception("Do not load GL api twice.");
}
}
///
/// Attach GLFW API to GLAD,
/// this method should be called after LoadGL
/// and before other graphic method.
///
/// The accident that program cannot attach GLFW to GLAD
public static unsafe void LoadGLAD()
{
int a = internalIO.InternalInitGLAD();
if (a!=0)
{
throw new Exception("Cannot attach GLFW to GLAD!");
}
}
internal static byte[] loadShaderCodeStr(string str)
{
byte[] cahrStr;
try
{
cahrStr = System.Text.Encoding.ASCII.GetBytes(str);
return cahrStr;
}
catch (Exception)
{
throw;
}
}
/*
///
/// Init a form, attach its data to GLFW program,
/// and return the pointer of the GLFW package of the form.
///
/// The C# instance of the form
/// Pointer of the GLFW package of this form
/// The issue that form is not successfully initilized
/// or GLAD program fail to init
public static unsafe IntPtr InitWindow(Form form)
{
IntPtr a = internalIO.InternalInitWindow(form.info);
if ((long)a == -1)
{
throw new Exception("Failed to init form.");
}
else if ((long)a == -2)
{
throw new Exception("Failed to load GLAD program.");
}
else
{
return a;
}
}
*/
}
}