daily update on 20240403 by nitload youmu
This commit is contained in:
@@ -4,12 +4,13 @@ using StgSharp.Graphics;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public class StgSharpDemoForm : Form
|
||||
{
|
||||
private Uniform<float, float, float> color;
|
||||
private Uniform<float, float, float, float> color;
|
||||
private ElementBuffer ebo;
|
||||
private Uniform<int> ourTexture;
|
||||
private Uniform<int> ourTexture2;
|
||||
@@ -18,48 +19,41 @@ namespace StgSharp
|
||||
private VertexArray vao;
|
||||
private VertexBuffer vbo;
|
||||
|
||||
public static unsafe void ProcessInput(IntPtr windowPtr)
|
||||
protected override unsafe void ProcessInput()
|
||||
{
|
||||
if (InternalIO.glfwGetKey(windowPtr, (int)Operation.Key.ESCAPE)
|
||||
if (InternalIO.glfwGetKey(WindowID, (int)Operation.Key.ESCAPE)
|
||||
== KeyStatus.PRESS)
|
||||
{
|
||||
InternalIO.glfwSetWindowShouldClose(windowPtr, 1);
|
||||
InternalIO.glfwSetWindowShouldClose(WindowID, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Deinit()
|
||||
protected override void DeInit()
|
||||
{
|
||||
/**/
|
||||
Console.WriteLine(1);
|
||||
vao.Dispose();
|
||||
Console.WriteLine(2);
|
||||
vbo.Dispose();
|
||||
Console.WriteLine(3);
|
||||
ebo.Dispose();
|
||||
Console.WriteLine(4);
|
||||
/**/
|
||||
|
||||
}
|
||||
|
||||
public unsafe void FormSizeCallback(IntPtr window, uint width, uint height)
|
||||
{
|
||||
gl.Viewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
public override void Init()
|
||||
protected override void Init()
|
||||
{
|
||||
InternalIO.InternalWriteLog("\n\n\n", "Program start", LogType.Info);
|
||||
|
||||
SetMetadata(800, 800, "Hello, STG#!", IntPtr.Zero, null);
|
||||
MakeAsCurrentContext();
|
||||
this.LoadGLapi();
|
||||
SetSizeLimit(800, 800, 800, 800);
|
||||
this.LoadGLapi(null);
|
||||
|
||||
|
||||
FrameBufferSizeCallback =
|
||||
(IntPtr id, uint width, uint height) =>
|
||||
{
|
||||
gl.Viewport(0, 0, width, height);
|
||||
};
|
||||
|
||||
{
|
||||
GL.Viewport(0, 0, width, height);
|
||||
};
|
||||
shader = CreateShaderProgram();
|
||||
var vertex = CreateShader(ShaderType.Vertex, 1);
|
||||
var fragment = CreateShader(ShaderType.Fragment, 1);
|
||||
@@ -67,22 +61,18 @@ namespace StgSharp
|
||||
vertex.AttachTo(0, shader);
|
||||
fragment.Compile(0, File.ReadAllText("Shader\\fragment.frag"));
|
||||
fragment.AttachTo(0, shader);
|
||||
|
||||
shader.Link();
|
||||
|
||||
Triangle tri = new Triangle(
|
||||
-0.5f, -0.3f, 0.0f,
|
||||
0.5f, -0.5f, 0.0f,
|
||||
0.0f, 0.5f, 0.0f
|
||||
);
|
||||
|
||||
Rectangle rec = new Rectangle(
|
||||
-0.5f, 0.5f, 0.0f,
|
||||
0.5f, 0.5f, 0.0f,
|
||||
0.5f, -0.5f, 0.0f,
|
||||
-0.5f, -0.5f, 0.0f
|
||||
);
|
||||
|
||||
Polygon5 polygon = new Polygon5(
|
||||
-0.4f, 0.5f, 0.0f,
|
||||
0.5f, 0.5f, 0.0f,
|
||||
@@ -90,59 +80,50 @@ namespace StgSharp
|
||||
0, -1, 0,
|
||||
-0.7f, -0.5f, 0.0f
|
||||
);
|
||||
|
||||
vao = CreateVertexArray(1);
|
||||
vbo = CreateVertexBuffer(2);
|
||||
ebo = CreateElementBuffer(1);
|
||||
texture = CreateTexture(2);
|
||||
|
||||
float[] texCoord = {
|
||||
0.0f, 0.0f,
|
||||
1.0f, 0.0f,
|
||||
1.0f, 1.0f,
|
||||
0.0f, 1.0f };
|
||||
|
||||
gl.BindVertexArray(vao[0]);
|
||||
|
||||
GL.BindVertexArray(vao[0]);
|
||||
ebo.SetValue(0, rec.Indices, BufferUsage.STATIC_DRAW);
|
||||
vbo.SetValue(0, rec.VertexBuffer, BufferUsage.STATIC_DRAW);
|
||||
gl.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
GL.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
vbo.SetValueArray(1, texCoord, BufferUsage.STATIC_DRAW);
|
||||
gl.SetVertexAttribute(2, 2, TypeCode.Single, false, 2 * sizeof(float), 0);
|
||||
|
||||
GL.SetVertexAttribute(2, 2, TypeCode.Single, false, 2 * sizeof(float), 0);
|
||||
/**/
|
||||
gl.BindBuffer(BufferType.ARRAY_BUFFER, glHandle.Zero);
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, glHandle.Zero);
|
||||
vao.BindNull();
|
||||
/**/
|
||||
texture.Bind2D(0);
|
||||
texture.Set2dWrapProperty(Wrap.Repeat, Wrap.Repeat);
|
||||
texture.Set2dFilterProperty(Filter.Nearest, Filter.Nearest);
|
||||
texture.LoadTexture(0, "Shader\\Image1.png", null);
|
||||
|
||||
|
||||
texture.Bind2D(1);
|
||||
texture.Set2dWrapProperty(Wrap.Repeat, Wrap.Repeat);
|
||||
texture.Set2dFilterProperty(Filter.Nearest, Filter.Nearest);
|
||||
texture.LoadTexture(1, "Shader\\awesomeface.png", null);
|
||||
|
||||
//color = GetUniform<float, float, float>(shader, "color");
|
||||
|
||||
shader.Use();
|
||||
/**/
|
||||
color = shader.GetUniform<float, float, float>("color");
|
||||
color = shader.GetUniform<float, float, float, float>("color");
|
||||
ourTexture = shader.GetUniform<int>("ourTexture");
|
||||
gl.SetValue(ourTexture, 0);
|
||||
GL.SetValue(ourTexture, 0);
|
||||
ourTexture2 = shader.GetUniform<int>("ourTexture2");
|
||||
gl.SetValue(ourTexture2, 1);
|
||||
GL.SetValue(ourTexture2, 1);
|
||||
/**/
|
||||
}
|
||||
|
||||
public override void Main()
|
||||
protected override void Main()
|
||||
{
|
||||
ProcessInput(WindowID);
|
||||
GL.ClearColor(0.333f, 0.555f, 0.555f, 1.0f);
|
||||
|
||||
gl.ClearColor(0.333f, 0.555f, 0.555f, 1.0f);
|
||||
|
||||
gl.Clear(MaskBufferBit.COLOR | MaskBufferBit.DEPTH );
|
||||
GL.Clear(MaskBufferBit.COLOR | MaskBufferBit.DEPTH);
|
||||
|
||||
/**/
|
||||
vao.Bind(0);
|
||||
@@ -154,26 +135,25 @@ namespace StgSharp
|
||||
texture.Activate(TextureUnit.Unit1);
|
||||
texture.Bind2D(1);
|
||||
/**/
|
||||
|
||||
/**/
|
||||
float time = CurrentFrameCount / 60.0f;
|
||||
|
||||
gl.SetValue(color,
|
||||
GL.SetValue(color,
|
||||
0.5f + MathF.Cos(time),
|
||||
0.5f + MathF.Sin(time * 0.66667f + 2 * Scaler.Pi / 3),
|
||||
0.5f + MathF.Sin(time * 0.33333f + Scaler.Pi / 3)
|
||||
0.5f + MathF.Sin(time * 0.33333f + Scaler.Pi / 3),
|
||||
time
|
||||
);
|
||||
|
||||
vao.Bind(0);
|
||||
|
||||
gl.DrawElements(GepmetryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero);
|
||||
|
||||
vao.BindNull();
|
||||
/**/
|
||||
Console.Clear();
|
||||
Console.WriteLine(FrameSpeed);
|
||||
|
||||
GL.DrawElements(GepmetryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero);
|
||||
|
||||
//vao.BindNull();
|
||||
/**/
|
||||
}
|
||||
|
||||
//[RenderActivity(RenderPriority.Default,false)]
|
||||
[MultiFrameActivity()]
|
||||
public void Beep()
|
||||
{
|
||||
if (CurrentFrameCount%60==0)
|
||||
@@ -181,6 +161,14 @@ namespace StgSharp
|
||||
Console.Beep();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoOptimization)]
|
||||
[RenderActivity(RenderPriority.Pre_1)]
|
||||
public void NoOp()
|
||||
{
|
||||
int a = 1;
|
||||
}
|
||||
}
|
||||
|
||||
internal static class Program
|
||||
@@ -196,41 +184,10 @@ namespace StgSharp
|
||||
StgSharp.InitGL(4, 6);
|
||||
StgSharp.GlobalSetting.VSyncActivated = false;
|
||||
StgSharpDemoForm demoForm = new StgSharpDemoForm();
|
||||
demoForm.Init();
|
||||
demoForm.Show();
|
||||
StgSharp.Terminate();
|
||||
/**/
|
||||
|
||||
/*
|
||||
GLparamQueue queue = new GLparamQueue();
|
||||
Thread t = default;
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
M128 m = new M128();
|
||||
m.Write<int>(0, 1 + i);
|
||||
m.Write<int>(1, 10 - i);
|
||||
m.Write<Int64>(1, 511L * i);
|
||||
queue.Enqueue(m);
|
||||
if (i == 10)
|
||||
{
|
||||
t = new Thread(new ThreadStart(
|
||||
() =>
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
M128 m = default;
|
||||
queue.TryDequeue(out m);
|
||||
Console.WriteLine(m.ToString(10));
|
||||
}
|
||||
}
|
||||
));
|
||||
t.Start();
|
||||
}
|
||||
}
|
||||
|
||||
t.Join();
|
||||
|
||||
/**/
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user