daily uodate on 20231208 by nitload youmu, preparation for multi thread rendering
This commit is contained in:
+123
-72
@@ -12,26 +12,56 @@ using System.Text;
|
||||
namespace StgSharp
|
||||
{
|
||||
|
||||
internal static class Program
|
||||
public class StgSharpDemoForm : Form
|
||||
{
|
||||
|
||||
|
||||
internal unsafe static void DebugMain(string[] args)
|
||||
Uniform<float, float, float> color;
|
||||
ElementBuffer ebo;
|
||||
Uniform<int> ourTexture;
|
||||
Uniform<int> ourTexture2;
|
||||
Shader shader;
|
||||
Texture texture;
|
||||
VertexArray vao;
|
||||
VertexBuffer vbo;
|
||||
public static unsafe void ProcessInput(IntPtr windowPtr)
|
||||
{
|
||||
if (InternalIO.glfw.GetKey(windowPtr, (int)Operation.Key.ESCAPE)
|
||||
== KeyStatus.PRESS)
|
||||
{
|
||||
InternalIO.glfw.SetWindowShouldClose(windowPtr, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Deinit(object[] args)
|
||||
{
|
||||
/**/
|
||||
vao.Dispose();
|
||||
vbo.Dispose();
|
||||
ebo.Dispose();
|
||||
/**/
|
||||
|
||||
InternalIO.glfw.Terminate();
|
||||
}
|
||||
|
||||
public unsafe void FormSizeCallback(IntPtr window, int width, int height)
|
||||
{
|
||||
GL.Viewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
public override void Init(object[] args)
|
||||
{
|
||||
|
||||
InternalIO.InternalWriteLog("\n\n\n", "Program start", LogType.Info);
|
||||
|
||||
Graphic.InitGL(4, 6);
|
||||
Platform.InitGL(4, 6);
|
||||
|
||||
//GL.glfw->WindowHint(GLFW.GLFW_DECORATED, GLFW.GL_FALSE);
|
||||
//Form f = Graphic.CreateWindow(800, 600, "Test STG#!", IntPtr.Zero, null);
|
||||
Form f = new Form(800, 600, "Hello,STG#!", IntPtr.Zero, null);
|
||||
f.MakeAsCurrentContext();
|
||||
f.SetSizeLimit(800, 600, 800, 600);
|
||||
GL.SetFrameBufferSizeCallback(f, FormSizeCallback);
|
||||
InitForm(800, 600, "Hello, STG#!", IntPtr.Zero, null);
|
||||
MakeAsCurrentContext();
|
||||
SetSizeLimit(800, 600, 800, 600);
|
||||
GL.SetFrameBufferSizeCallback(windowID, FormSizeCallback);
|
||||
|
||||
glManager.LoadGLapi(f, glManager.LoadGLfunc);
|
||||
this.LoadGLapi(null);
|
||||
|
||||
Shader shader = new Shader();
|
||||
shader = CreateShader();
|
||||
shader.CompileVertexShader(
|
||||
File.ReadAllText("Shader\\vertex.vert")
|
||||
);
|
||||
@@ -40,7 +70,6 @@ namespace StgSharp
|
||||
);
|
||||
shader.Link();
|
||||
|
||||
|
||||
Triangle tri = new Triangle(
|
||||
-0.5f, -0.3f, 0.0f,
|
||||
0.5f, -0.5f, 0.0f,
|
||||
@@ -48,10 +77,10 @@ namespace StgSharp
|
||||
);
|
||||
|
||||
Rectangle rec = new Rectangle(
|
||||
-0.4f, 0.5f, 0.0f,
|
||||
-0.5f, 0.5f, 0.0f,
|
||||
0.5f, 0.5f, 0.0f,
|
||||
0.6f, -0.5f, 0.0f,
|
||||
-0.7f, -0.5f, 0.0f
|
||||
0.5f, -0.5f, 0.0f,
|
||||
-0.5f, -0.5f, 0.0f
|
||||
);
|
||||
|
||||
Polygon5 polygon = new Polygon5(
|
||||
@@ -63,70 +92,105 @@ namespace StgSharp
|
||||
);
|
||||
|
||||
|
||||
VertexArray vao = new VertexArray(1);
|
||||
VertexBuffer vbo = new VertexBuffer(1);
|
||||
ElementBuffer ebo = new ElementBuffer(1);
|
||||
|
||||
GL.gl.BindVertexArray(vao[0]);
|
||||
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 };
|
||||
|
||||
vbo.SetData(0, polygon.VertexBuffer, BufferUsage.STATIC_DRAW);
|
||||
ebo.SetData(0, polygon.Indices, BufferUsage.STATIC_DRAW);
|
||||
GL.BindVertexArray(vao[0]);
|
||||
|
||||
ebo.SetValue(0, rec.Indices, BufferUsage.STATIC_DRAW);
|
||||
|
||||
vbo.SetValue(0, rec.VertexBuffer, BufferUsage.STATIC_DRAW);
|
||||
GL.SetVertexAttribute(0, 3, typeof(float), false, 4 * sizeof(float), 0);
|
||||
|
||||
GL.gl.VertexAttribPointer(0, 3, GLconst.FLOAT, false, 4 * sizeof(float), (void*)0);
|
||||
GL.gl.EnableVertexAttribArray(0);
|
||||
|
||||
vbo.SetValueArray(1, texCoord, BufferUsage.STATIC_DRAW);
|
||||
GL.SetVertexAttribute(2, 2, typeof(float), false, 2 * sizeof(float), 0);
|
||||
|
||||
/**/
|
||||
GL.gl.BindBuffer(GLconst.ARRAY_BUFFER, 0);
|
||||
GL.gl.BindVertexArray(0);
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, 0);
|
||||
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);
|
||||
|
||||
|
||||
while (InternalIO.glfw.WindowShouldClose(f.windowID) == 0)
|
||||
{
|
||||
ProcessInput(f.windowID);
|
||||
|
||||
GL.ClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
GL.gl.Clear(GLconst.COLOR_BUFFER_BIT);
|
||||
|
||||
shader.Use();
|
||||
|
||||
GL.gl.BindVertexArray(vao._bufferID[0]);
|
||||
|
||||
GL.DrawElements(GepmetryType.TRIANGLES, 9, typeof(uint), IntPtr.Zero);
|
||||
|
||||
GL.gl.BindVertexArray(0);
|
||||
|
||||
InternalIO.glfw.SwapBuffers(f.windowID);
|
||||
InternalIO.glfw.PollEvents();
|
||||
InternalIO.glfw.PollEvents();
|
||||
}
|
||||
//color = GetUniform<float, float, float>(shader, "color");
|
||||
|
||||
shader.Use();
|
||||
/**/
|
||||
vao.Dispose();
|
||||
vbo.Dispose();
|
||||
ebo.Dispose();
|
||||
//ourTexture = GetUniform<int>(shader, "ourTexture");
|
||||
GL.SetValue(ourTexture, 0);
|
||||
//ourTexture2 = GetUniform<int>(shader, "ourTexture2");
|
||||
GL.SetValue(ourTexture2, 1);
|
||||
/**/
|
||||
|
||||
/*
|
||||
Graphic.glDeleteVertexArrays(1, &vao);
|
||||
Graphic.glDeleteBuffers(1, &vao);
|
||||
Graphic.glDeleteBuffers(1, &vao);
|
||||
/**/
|
||||
|
||||
InternalIO.glfw.Terminate();
|
||||
}
|
||||
|
||||
public override void OnRenderFrame(object[] args)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnUpdateFrame(object[] args)
|
||||
{
|
||||
|
||||
ProcessInput(windowID);
|
||||
|
||||
GL.ClearColor(0.333f, 0.555f, 0.555f, 1.0f);
|
||||
//GL.api.Clear(GLconst.COLOR_BUFFER_BIT);
|
||||
GL.Clear(MaskBufferBit.COLOR);
|
||||
|
||||
vao.Bind(0);
|
||||
shader.Use();
|
||||
|
||||
/**/
|
||||
texture.Activate(TextureUnit.Unit0);
|
||||
texture.Bind2D(0);
|
||||
texture.Activate(TextureUnit.Unit1);
|
||||
texture.Bind2D(1);
|
||||
/**/
|
||||
|
||||
float time = (float)InternalIO.glfw.GetTime();
|
||||
GL.SetValue(color,
|
||||
0.5f + MathF.Sin(time),
|
||||
0.5f + MathF.Sin(time/* + 0.667f * 3.14f/**/),
|
||||
0.5f + MathF.Sin(time/* - 0.667f * 3.14f/**/)
|
||||
);
|
||||
|
||||
vao.Bind(0);
|
||||
GL.DrawElements(GepmetryType.TRIANGLES, 6, typeof(uint), IntPtr.Zero);
|
||||
|
||||
vao.BindNull();
|
||||
|
||||
InternalIO.glfw.SwapBuffers(windowID);
|
||||
InternalIO.glfw.PollEvents();
|
||||
}
|
||||
}
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
|
||||
internal unsafe static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
DebugMain(args);
|
||||
StgSharpDemoForm demoForm = new StgSharpDemoForm();
|
||||
demoForm.ShowForm();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -136,19 +200,6 @@ namespace StgSharp
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe void FormSizeCallback(IntPtr window, int width, int height)
|
||||
{
|
||||
GL.gl.Viewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
public static unsafe void ProcessInput(IntPtr windowPtr)
|
||||
{
|
||||
if (InternalIO.glfw.GetKey(windowPtr, (int)Control.Key.ESCAPE)
|
||||
== KeyStatus.PRESS)
|
||||
{
|
||||
InternalIO.glfw.SetWindowShouldClose(windowPtr, 1);
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport(InternalIO.SSC_libname, EntryPoint = "printShaderCode",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
|
||||
Reference in New Issue
Block a user