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);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#version 330 core
|
||||
layout(location = 0) in vec3 aPos;
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(aPos.x,aPos.y,aPos.z,1.0);
|
||||
}
|
||||
@@ -52,6 +52,17 @@
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Shader\fragment.frag">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Shader\vertex.vert">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
</Target>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#version 330 core
|
||||
layout(location = 0) in vec3 aPos;
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(aPos.x,aPos.y,aPos.z,1.0);
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
#version 330 core
|
||||
layout(location = 0) in vec3 aPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(aPos.x,aPos.y,aPos.z,1.0);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -60,7 +60,7 @@
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.400\\RuntimeIdentifierGraph.json"
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.401\\RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.400\\RuntimeIdentifierGraph.json"
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.401\\RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"version": 2,
|
||||
"dgSpecHash": "mBiaYlmdKY7pcEUrgIYHWdVJNFdlkIpvBftTAU0ZhHli28Y+yj1le28eTUH+fFgrKOlwKEBtHixyqvrNNYgqaw==",
|
||||
"dgSpecHash": "8o0e+XOPWIUCetvIpnINKGDtJ+TxlAo2pRPckDXb7oQQr3e4VczHCbYgbtt4FmavrHYsLJnBPvDsledArmY/bg==",
|
||||
"success": true,
|
||||
"projectFilePath": "D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\源代码\\StgSharpDebug\\StgSharpDebug.csproj",
|
||||
"expectedPackageFiles": [],
|
||||
|
||||
@@ -1 +1 @@
|
||||
f63f47dc6ac0f86b87f2fbb526ea68ed23d9fec7
|
||||
208acf897e20abb578d5ef8df864296ff6184c25
|
||||
|
||||
@@ -11,3 +11,5 @@ D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\refint\StgSharpDebug.dll
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\StgSharpDebug.genruntimeconfig.cache
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\ref\StgSharpDebug.dll
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\bin\x64\Debug\net6.0\Shader\fragment.frag
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\bin\x64\Debug\net6.0\Shader\vertex.vert
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
-1
@@ -1 +1 @@
|
||||
999d9ef8ee91b460e93e22f24f66316913caf649
|
||||
bce6f2a08848a162fd84bd06fa09fef779ecbeb9
|
||||
|
||||
@@ -11,3 +11,5 @@ D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Release\net6.0\refint\StgSharpDebug.dll
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Release\net6.0\StgSharpDebug.genruntimeconfig.cache
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Release\net6.0\ref\StgSharpDebug.dll
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\bin\x64\Release\net6.0\Shader\fragment.frag
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\bin\x64\Release\net6.0\Shader\Vertexshaer.vert
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user