daily update on 20230609 by nitload youmu, graphic arragement for better form init
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
using StgSharp.Graphics.GL;
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct formInfo
|
||||
{
|
||||
public int width;
|
||||
public int height;
|
||||
public vec4d color;
|
||||
public string name;
|
||||
}
|
||||
|
||||
public unsafe class Form:INode<Form>
|
||||
{
|
||||
internal IntPtr windowPtr;
|
||||
internal formInfo info;
|
||||
internal shaderObject shader;
|
||||
internal LinkedList<Pool> allControl;
|
||||
|
||||
public vec2d Size
|
||||
{
|
||||
get { return new vec2d(info.width,info.height); }
|
||||
set
|
||||
{
|
||||
info.width = (int)value.X;
|
||||
info.height = (int)value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => info.width;
|
||||
set => info.width = value;
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get => info.height;
|
||||
set => info.height = value;
|
||||
}
|
||||
|
||||
public vec4d Color
|
||||
{
|
||||
get => info.color;
|
||||
set => info.color = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor of a Form, creats an instance of a form and
|
||||
/// initilize all the customizing operations.
|
||||
/// </summary>
|
||||
public Form()
|
||||
{
|
||||
info = new formInfo();
|
||||
allControl = new LinkedList<Pool>();
|
||||
Init();
|
||||
StgSharp.Graphic.LoadForm(this);
|
||||
|
||||
}
|
||||
|
||||
//used for internal control purpose
|
||||
internal Form(int instruction)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal unsafe void defualtInit()
|
||||
{
|
||||
fixed (shaderObject* shaderObj = &this.shader)
|
||||
{
|
||||
IntPtr windowPtr = Graphic.InitWindow(this);
|
||||
internalIO.InternalCompileShader(shaderObj);
|
||||
internalIO.InternalRenderWindow(windowPtr, this.info, shaderObj);
|
||||
internalIO.TerminateWindow(shaderObj);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Init()
|
||||
{
|
||||
info.color = new vec4d(0.95, 0.93, 0.92, 0);
|
||||
info.width = 800;
|
||||
info.height = 600;
|
||||
this.windowPtr = Graphic.InitWindow(this);
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
fixed (shaderObject* shaderObj = &this.shader)
|
||||
{
|
||||
internalIO.InternalCompileShader(shaderObj);
|
||||
internalIO.InternalRenderWindow(this.windowPtr, this.info, shaderObj);
|
||||
internalIO.TerminateWindow(shaderObj);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct shaderObject
|
||||
{
|
||||
uint VBO;
|
||||
uint VAO;
|
||||
uint shaderProgram;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,47 @@
|
||||
using StgSharp.Control;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.GL;
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public static class Graphic
|
||||
public static unsafe class Graphic
|
||||
{
|
||||
private const string glPackageName = "StgSharpGraphics.dll";
|
||||
//private static GraphicIO glIO;
|
||||
|
||||
static Graphic()
|
||||
/// <summary>
|
||||
/// Init a form, attach its data to GLFW program,
|
||||
/// and return the pointer of the GLFW package of the form.
|
||||
/// </summary>
|
||||
/// <param name="form">The C# instance of the form</param>
|
||||
/// <returns>Pointer of the GLFW package of this form</returns>
|
||||
/// <exception cref="Exception">The issue that form is not successfully initilized
|
||||
/// or GLAD program fail to init</exception>
|
||||
public static unsafe IntPtr InitWindow(Form form)
|
||||
{
|
||||
//glIO = InitPackage();
|
||||
//initWindow = glIO.initWindowPtr;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe void LoadForm(Form form)
|
||||
{
|
||||
ProgramTimeLine.allForm.Add(form);
|
||||
}
|
||||
|
||||
public static InitWindow initWindow ;
|
||||
|
||||
/*
|
||||
[DllImport(glPackageName, EntryPoint = "initPackage")]
|
||||
internal static extern GraphicIO InitPackage();
|
||||
/**/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Window
|
||||
{
|
||||
public int width;
|
||||
public int height;
|
||||
public vec4d color;
|
||||
public string name;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user