daily update on 20230927 by nitload youmu, all polygon4 display available, optimizing on C/C# interoperation
This commit is contained in:
+132
-1
@@ -1,9 +1,13 @@
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
@@ -25,6 +29,117 @@ namespace StgSharp
|
||||
GetApiRep();
|
||||
Graphic.InitGLAD(Graphic.GetProcAddress);
|
||||
|
||||
string vertstr = File.ReadAllText("Shader\\vertex.vert", Encoding.ASCII);
|
||||
byte[] vert = Encoding.ASCII.GetBytes(vertstr + '\0');
|
||||
uint vertexShader;
|
||||
fixed (byte* shaderSource = vert)
|
||||
{
|
||||
vertexShader = internalIO.InternalLoadShaderCode(shaderSource, GLFW.GL_VERTEX_SHADER);
|
||||
if (vertexShader == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
string fragstr = File.ReadAllText("Shader\\fragment.frag", Encoding.ASCII);
|
||||
byte[] frag = Encoding.ASCII.GetBytes(fragstr + '\0');
|
||||
|
||||
uint fragmentShader;
|
||||
fixed (byte* shaderSource = frag)
|
||||
{
|
||||
fragmentShader = internalIO.InternalLoadShaderCode(shaderSource, GLFW.GL_FRAGMENT_SHADER);
|
||||
if (fragmentShader == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint shaderProgram = Graphic.glCreateProgram();
|
||||
|
||||
Graphic.glAttachShader(shaderProgram, vertexShader);
|
||||
Graphic.glAttachShader(shaderProgram, fragmentShader);
|
||||
|
||||
if (internalIO.InternalLinkShaderProgram(shaderProgram) == 0)
|
||||
{
|
||||
IntPtr log = internalIO.InternalReadLog();
|
||||
Console.WriteLine(Marshal.PtrToStringAnsi(log));
|
||||
}
|
||||
|
||||
Graphic.glDeleteShader(vertexShader);
|
||||
Graphic.glDeleteShader(fragmentShader);
|
||||
|
||||
|
||||
|
||||
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
|
||||
);
|
||||
|
||||
uint VAO;
|
||||
Graphic.glGenVertexArrays(1, &VAO);
|
||||
Graphic.glBindBuffer(GLFW.GL_ARRAY_BUFFER, VAO);
|
||||
Graphic.glBindVertexArray(VAO);
|
||||
|
||||
/*
|
||||
// for triangle rendering
|
||||
uint VBO;
|
||||
Graphic.glGenBuffers(1, &VBO);
|
||||
Graphic.glBindBuffer(GLFW.GL_ARRAY_BUFFER, VBO);
|
||||
fixed (void* data = &tri.vertexMap)
|
||||
{
|
||||
Graphic.glBufferData(GLFW.GL_ARRAY_BUFFER, 12 * sizeof(float), data, GLFW.GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
Graphic.glVertexAttribPointer(0, 3, GLFW.GL_FLOAT, false, 4 * sizeof(float), (void*)0);
|
||||
Graphic.glEnableVertexAttribArray(0);
|
||||
|
||||
/**/
|
||||
|
||||
/**/
|
||||
// for rectangle rendering
|
||||
|
||||
uint VBO;
|
||||
Graphic.glGenBuffers(1, &VBO);
|
||||
Graphic.glBindBuffer(GLFW.GL_ARRAY_BUFFER, VBO);
|
||||
fixed (void* data = &rec.vertexMat)
|
||||
{
|
||||
Graphic.glBufferData(GLFW.GL_ARRAY_BUFFER, 16 * sizeof(float), data, GLFW.GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
uint[] indices = new uint[6]
|
||||
{
|
||||
0,1,3,
|
||||
1,2,3
|
||||
};
|
||||
|
||||
uint EBO;
|
||||
Graphic.glGenBuffers(1, &EBO);
|
||||
Graphic.glBindBuffer(GLFW.GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||
fixed (void* data = &indices[0])
|
||||
{
|
||||
Graphic.glBufferData(GLFW.GL_ELEMENT_ARRAY_BUFFER, indices.Length * sizeof(uint), data, GLFW.GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
Graphic.glVertexAttribPointer(0, 3, GLFW.GL_FLOAT, false, 4 * sizeof(float), (void*)0);
|
||||
Graphic.glEnableVertexAttribArray(0);
|
||||
|
||||
/**/
|
||||
|
||||
Graphic.glBindBuffer(GLFW.GL_ARRAY_BUFFER, 0);
|
||||
Graphic.glBindVertexArray(0);
|
||||
|
||||
|
||||
while (internalIO.glfwWindowShouldClose(f.windowID) == 0)
|
||||
{
|
||||
ProcessInput(f.windowID);
|
||||
@@ -32,10 +147,21 @@ namespace StgSharp
|
||||
Graphic.glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
Graphic.glClear(GLFW.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
Graphic.glUseProgram(shaderProgram);
|
||||
Graphic.glBindVertexArray(VAO);
|
||||
|
||||
//Graphic.glDrawArrays(GLFW.GL_TRIANGLES, 0, 3);
|
||||
Graphic.glDrawElements(GLFW.GL_TRIANGLES, 6, GLFW.GL_UNSIGNED_INT, (void*)0);
|
||||
|
||||
Graphic.glBindVertexArray(0);
|
||||
|
||||
internalIO.glfwSwapBuffers(f.windowID);
|
||||
internalIO.glfwPollEvents();
|
||||
}
|
||||
|
||||
Graphic.glDeleteVertexArrays(1, &VAO);
|
||||
Graphic.glDeleteBuffers(1, &VBO);
|
||||
Graphic.glDeleteBuffers(1, &EBO);
|
||||
internalIO.glfwTerminate();
|
||||
|
||||
}
|
||||
@@ -69,6 +195,11 @@ namespace StgSharp
|
||||
Console.WriteLine(address);
|
||||
}
|
||||
|
||||
[DllImport(internalIO.SSGC_libname, EntryPoint = "printShaderCode",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal extern unsafe static void PrintShader(byte** shadercode);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user