rubuild file struct 2

This commit is contained in:
Nitload
2024-05-28 20:32:45 +08:00
parent 0cac40255b
commit 5033a6d50b
45 changed files with 886 additions and 618 deletions
+157
View File
@@ -0,0 +1,157 @@
using StgSharp.Geometries;
using StgSharp.Graphics;
using StgSharp.Graphics.GL;
using StgSharp.Logic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp
{
public class fboFrame : glRenderStream
{
public fboFrame(RenderStreamConstructArgs args):base(args)
{
}
protected override string[] InputPortsName
=>
[
"TextureInput"
];
protected override string[] OutputPortsName
=>
[
"Output"
];
protected override void Deinit()
{
throw new NotImplementedException();
}
ShaderProgram s;
TextureGL t;
VertexBuffer vbo;
VertexArray vao;
ElementBuffer ebo;
internal TimeSpanProvider spanProvider;
protected override void Init()
{
//spanProvider = new TimeSpanProvider(1 / 60.00f, TimeSpanProvider.DefaultProvider);
SetSizeLimit(800,800,800,800);
FrameSizeCallback = new FrameBufferSizeHandler(
(window, width,height) => {
glFunc.Viewport(0, 0, width, height);
});
vbo = CreateVertexBuffer(2);
vao = CreateVertexArray(1);
ebo = CreateElementBuffer(1);
Rectangle rec = new Rectangle(
-0.9f, 0.9f, 0,
0.9f, 0.9f, 0,
0.9f, -0.9f, 0,
-0.9f, -0.9f, 0
);
/*
Rectangle tex = new Rectangle(
-0.8f, 0.8f, 0,
0.8f, 0.8f, 0,
0.8f, -0.8f, 0,
-0.8f, -0.8f, 0
);
/**/
/**/
Rectangle tex = new Rectangle(
0f, 1f, 0,
1f, 1f, 0,
1f, 0f, 0,
0f, 0f, 0
);
/**/
s = CreateShaderProgram();
Shader vert = CreateShaderSegment(ShaderType.Vertex, 1);
Shader frag = CreateShaderSegment(ShaderType.Fragment,1);
vert.Compile(0, Shader.FromCodeFile("Shader\\fbo.vert"));
frag.Compile(0, Shader.FromCodeFile("Shader\\fbo.frag"));
vert.AttachTo(0,s);
frag.AttachTo(0,s);
s.Link();
vao.Bind(0);
ebo.Bind(0);
ebo.SetValue(0,rec.VertexIndices,BufferUsage.StaticDraw);
vbo.Bind(0);
vbo.WriteVectorData(0,rec.VertexStream, BufferUsage.StaticDraw);
VertexArray.SetVertexAttribute(0,3,TypeCode.Single,false,4*sizeof(float),0);
vbo.Bind(1);
vbo.WriteVectorData(1, tex.VertexStream, BufferUsage.StaticDraw);
VertexArray.SetVertexAttribute(1, 3, TypeCode.Single, false,4*sizeof(float),0);
t = CreateTexture(1);
t.Bind2D(0);
t.Set2dWrapProperty(Wrap.Repeat, Wrap.Repeat);
t.Set2dFilterProperty(Filter.Nearest, Filter.Nearest);
TextureGL.Activate(TextureUnit.Unit0);
texUniform = s.GetUniform<int>("tex");
glFunc.SetUniformValue(texUniform, 0);
}
Uniform<int> texUniform;
protected override void Main(
in Dictionary<string, BlueprintPipeline> input,
in Dictionary<string, BlueprintPipeline> output)
{
TexturePipeline p = input["TextureInput"].Args as TexturePipeline;
Image i = (p??throw new Exception("Pipeline has null value")).Value;
FrameBuffer.BindNull();
glFunc.ClearColor(0.4f, 0.1f, 0f, 1.0f);
glFunc.Clear(MaskBufferBit.COLOR | MaskBufferBit.DEPTH);
s.Use();
vao.Bind(0);
t.LoadTexture(0, i);
glFunc.DrawElements(GeometryType.TRIANGLES,6,TypeCode.UInt32,IntPtr.Zero);
//glFunc.DrawElements(GeometryType.LINES, 6, TypeCode.UInt32, IntPtr.Zero);
BlueprintPipeline.SkipAll(output);
PollEvents();
SwapBuffers();
}
protected override void ProcessInput()
{
}
}
}
@@ -31,6 +31,7 @@
using StgSharp;
using StgSharp.Geometries;
using StgSharp.Graphics;
using StgSharp.Graphics.GL;
using StgSharp.Logic;
using StgSharp.Math;
@@ -48,7 +49,7 @@ namespace StgSharp
private ElementBuffer ebo;
private ShaderProgram shader;
private Texture texture;
private TextureGL texture;
private Uniform<float, float, float, float> color;
private Uniform<int> ourTexture;
private Uniform<int> ourTexture2;
@@ -77,16 +78,15 @@ namespace StgSharp
{
SetSizeLimit(800, 800, 800, 800);
FrameSizeCallback =
(IntPtr id, uint width, uint height) => GL.Viewport(0, 0, width, height);
(IntPtr id, uint width, uint height) => glFunc.Viewport(0, 0, width, height);
shader = CreateShaderProgram();
Shader vertex = CreateShaderSegment(ShaderType.Vertex, 1);
Shader fragment = CreateShaderSegment(ShaderType.Fragment, 1);
vertex.Compile(0, File.ReadAllText("Shader\\vertex.vert"));
vertex.Compile(0, Shader.FromCodeFile("Shader\\main.vert"));
vertex.AttachTo(0, shader);
fragment.Compile(0, File.ReadAllText("Shader\\fragment.frag"));
fragment.Compile(0, Shader.FromCodeFile("Shader\\main.frag"));
fragment.AttachTo(0, shader);
shader.Link();
Triangle tri = new Triangle(
@@ -119,35 +119,35 @@ namespace StgSharp
vao.Bind(0);
ebo.SetValue(0, rec.Indices, BufferUsage.STATIC_DRAW);
ebo.SetValue(0, rec.VertexIndices, BufferUsage.StaticDraw);
vbo.WriteMatrixData(0, rec.VertexBuffer, BufferUsage.STATIC_DRAW);
vao.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
vbo.WriteVectorData(0, rec.VertexStream, BufferUsage.StaticDraw);
VertexArray.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
vbo.WriteScalerData(1, texCoord, BufferUsage.STATIC_DRAW);
vao.SetVertexAttribute(2, 2, TypeCode.Single, false, 2 * sizeof(float), 0);
vbo.WriteScalerData(1, texCoord, BufferUsage.StaticDraw);
VertexArray.SetVertexAttribute(2, 2, TypeCode.Single, false, 2 * sizeof(float), 0);
/**/
vbo.Unbind();
vao.BindNull();
VertexArray.BindNull();
/**/
texture.Bind2D(0);
texture.Set2dWrapProperty(Wrap.Repeat, Wrap.Repeat);
texture.Set2dFilterProperty(Filter.Nearest, Filter.Nearest);
texture.LoadTexture(0, "Shader\\Image1.png", null);
texture.LoadTexture(0,Image.FromFile( "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);
texture.LoadTexture(1, Image.FromFile( "Shader\\awesomeface.png", null));
shader.Use();
/**/
color = shader.GetUniform<float, float, float, float>("color");
ourTexture = shader.GetUniform<int>("ourTexture");
GL.SetValue(ourTexture, 0);
glFunc.SetUniformValue(ourTexture, 0);
ourTexture2 = shader.GetUniform<int>("ourTexture2");
GL.SetValue(ourTexture2, 1);
glFunc.SetUniformValue(ourTexture2, 1);
/**/
NativeCameraViewTarget(
@@ -158,6 +158,12 @@ namespace StgSharp
NativeCameraViewRange(new Degree(10f), (0, 0), (50f, 50f));
NativeCameraUniform(shader, "camera");
TextureGL.Activate(TextureUnit.Unit0);
texture.Bind2D(0);
TextureGL.Activate(TextureUnit.Unit1);
texture.Bind2D(1);
}
protected override sealed void Main(
@@ -165,26 +171,22 @@ namespace StgSharp
in Dictionary<string, BlueprintPipeline> output
)
{
GL.ClearColor(0.333f, 0.555f, 0.555f, 1.0f);
glFunc.ClearColor(0.333f, 0.555f, 0.555f, 1.0f);
//Console.WriteLine(1);
GL.Clear(MaskBufferBit.COLOR /**/| MaskBufferBit.DEPTH /**/ );
glFunc.Clear(MaskBufferBit.COLOR /**/| MaskBufferBit.DEPTH /**/ );
/**/
vao.Bind(0);
shader.Use();
/**/
/**/
texture.Activate(TextureUnit.Unit0);
texture.Bind2D(0);
texture.Activate(TextureUnit.Unit1);
texture.Bind2D(1);
/**/
/**/
float time = /* CurrentFrameCount, / /**/ 60.0f;
float time = /* CurrentFrameCount, / /**/ 0.003f;
GL.SetValue(color,
glFunc.SetUniformValue(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)),
@@ -196,9 +198,9 @@ namespace StgSharp
//Console.WriteLine(NativeCamera.Projection);
GL.DrawElements(GeometryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero);
glFunc.DrawElements(GeometryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero);
vao.BindNull();
VertexArray.BindNull();
/**/
BlueprintPipeline.SkipAll(output);
+86 -35
View File
@@ -1,21 +1,23 @@
using StgSharp.Geometries;
using StgSharp.Graphics;
using StgSharp.Graphics.GL;
using StgSharp.Logic;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Channels;
using System.Threading.Tasks;
namespace StgSharp
{
public class ParticleStream : glRenderStream
{
public ParticleStream(RenderStreamConstructArgs args) : base(args)
public ParticleStream(RenderStreamConstructArgs args, bool isSharing) : base(args, isSharing)
{
}
protected override string[] InputPortsName => ["input_1"];
@@ -33,7 +35,9 @@ namespace StgSharp
VertexArray vao;
ElementBuffer ebo;
internal TimeSpanProvider spanProvider;
FrameBuffer fbo;
internal static vec3d DefaultRotation(TimeSpanProvider provider, out float rotation)
{
@@ -48,8 +52,6 @@ namespace StgSharp
protected override void Init()
{
spanProvider = new TimeSpanProvider(1 / 60.00f, TimeSpanProvider.DefaultProvider);
buffer = new PlainInstancingBuffer<ParticleOnPlain>();
for (int i = 0; i < 10; i++)
{
@@ -59,12 +61,12 @@ namespace StgSharp
float at = Scaler.Abs(t - 5.0f);
ParticleOnPlain p = new ParticleOnPlain(buffer);
((IInstancing<ParticleOnPlain>)p).Coord = new vec3d(
((IInstancing)p).Coord = new vec3d(
(-5 + i) * 0.2f + 0.1f, (-5 + t) * 0.2f + 0.1f, 0);
((IInstancing<ParticleOnPlain>)p).Scale =
Scaler.MinOf(ai, at) * 0.4f + 0.1f;
((IInstancing<ParticleOnPlain>)p).Motion = new GeometryMotion(
true,spanProvider,
((IInstancing)p).Scale =
Scaler.MinOf(i, t) * 0.15f;
((IInstancing)p).Motion = new GeometryMotion(
true, this.timeProvider,
DefaultRotation)
;
}
@@ -73,7 +75,7 @@ namespace StgSharp
SetSizeLimit(800, 800, 800, 800);
FrameSizeCallback =
(IntPtr id, uint width, uint height) => GL.Viewport(0, 0, width, height);
(IntPtr id, uint width, uint height) => glFunc.Viewport(0, 0, width, height);
s = CreateShaderProgram();
Shader pvs = CreateShaderSegment(ShaderType.Vertex ,1);
@@ -97,26 +99,28 @@ namespace StgSharp
-0.05f,-0.05f,0.0f,
-0.05f,0.05f,0.0f
);
vao.Bind(0);
vbo.WriteMatrixData(0, rec.vertexMat, BufferUsage.STATIC_DRAW);
ebo.SetValue(0, rec.Indices, BufferUsage.STATIC_DRAW);
vao.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float),0);
vbo.WriteVectorData(0, rec.VertexStream, BufferUsage.StaticDraw);
ebo.SetValue(0, rec.VertexIndices, BufferUsage.StaticDraw);
VertexArray.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float),0);
vbo.WriteVectorData(1, buffer.CoordSpan,BufferUsage.STREAM_DRAW);
vao.SetVertexAttribute(1, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
vao.SetVertexAttribute(2, 1, TypeCode.Single, false, 4 * sizeof(float), 3 * sizeof(float));
vbo.WriteVectorData<vec4d>(1, buffer.CoordAndRotationSpan,BufferUsage.StreamDraw);
VertexArray.SetVertexAttribute(1, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
VertexArray.SetVertexAttribute(2, 1, TypeCode.Single, false, 4 * sizeof(float), 3 * sizeof(float));
GL.VertexAttributeDivisor(1, 1);
GL.VertexAttributeDivisor(2, 1);
glFunc.VertexAttributeDivisor(1, 1);
glFunc.VertexAttributeDivisor(2, 1);
vbo.WriteScalerData<float>(2, buffer.ScalingSpan, BufferUsage.StaticDraw);
VertexArray.SetVertexAttribute(3,1,TypeCode.Single,false,sizeof(float),0);
glFunc.VertexAttributeDivisor(3, 1);
vbo.WriteScalerData(2, buffer.ScalingSpan, BufferUsage.STATIC_DRAW);
vao.SetVertexAttribute(3,1,TypeCode.Single,false,sizeof(float),0);
GL.VertexAttributeDivisor(3, 1);
vbo.Unbind();
vao.BindNull();
VertexArray.BindNull();
NativeCameraViewTarget
(
@@ -124,38 +128,85 @@ namespace StgSharp
(0,0,0),
(0,1,0)
);
NativeCameraViewRange(new Degree(1.7f),Vec2d.Zero,(50,50));
NativeCameraViewRange(new Degree(1.5f),Vec2d.Zero,(50,50));
NativeCameraUniform(s,"Camera");
s.Use();
fbo = CreateFrameBuffer(1);
rbo = CreateRenderBuffer(1);
fbo.Bind(0);
rbo.Bind(0);
glFunc.SetRenderBufferStorage(
RenderBufferInternalFormat.Depth24_Stencil8, this.Size);
t = CreateTexture(1);
t.Bind2D(0);
glFunc.TextureImage2d(Texture2DTarget.Texture2D, 0, (int)ImageChannel.WithAlphaChannel,
(uint)Width, (uint)Height, (int)ImageChannel.WithAlphaChannel, ImageChannelLayout.Byte, glHandle.ZeroHandle);
t.Set2dWrapProperty(Wrap.Repeat, Wrap.Repeat);
t.Set2dFilterProperty(Filter.Nearest, Filter.Nearest);
glFunc.FrameBufferTexture2d(FrameBufferTarget.All, glAttachment.Color(0),
Texture2DTarget.Texture2D,t[0],0);
glFunc.CombineFrameBufferRenderBuffer(fbo[0], rbo[0]);
int streamLength = this.Width * this.Height * 4;
byte[] imageStream = new byte[streamLength];
i = Image.FromMemory(this.Size,4,imageStream);
}
protected override void Main(in Dictionary<string, BlueprintPipeline> input, in Dictionary<string, BlueprintPipeline> output)
{
TextureGL t;
RenderBuffer rbo;
Image i;
protected override void Main(
in Dictionary<string, BlueprintPipeline> input,
in Dictionary<string, BlueprintPipeline> output)
{
buffer.UpdateAllParticles();
GL.ClearColor(0.6f,0.1f,0.3f,1);
GL.Clear(MaskBufferBit.COLOR | MaskBufferBit.DEPTH);
fbo.Bind(0);
vao.Bind(0);
glFunc.ClearColor(0.6f,0.1f,0.3f,1);
glFunc.Clear(MaskBufferBit.COLOR | MaskBufferBit.DEPTH);
vbo.Bind(1);
vbo.WriteVectorData(1, buffer.CoordSpan, BufferUsage.STREAM_DRAW);
vbo.WriteVectorData<vec4d>(1, buffer.CoordAndRotationSpan, BufferUsage.StreamDraw);
s.Use();
NativeCamera.SetAllUniforms();
GL.DrawElementsInstanced(
glFunc.DrawElementsInstanced(
GeometryType.TRIANGLES, 6, TypeCode.UInt32,IntPtr.Zero,100
);
glFunc.WaitAccomplishment();
VertexArray.BindNull();
vao.BindNull();
/**/
BlueprintPipeline.SkipAll(output);
t.Bind2D(0);
glFunc.GetTextureImage(Texture2DTarget.Texture2D, 0,ImageChannel.WithAlphaChannel,
ImageChannelLayout.Byte,ref i.data);
//Array.Fill<byte>(i.DataStream, 24);
output["output_1"].CompleteAndWriteData( new TexturePipeline(i));
FrameBuffer.BindNull();
/**/
/*
//BlueprintPipeline.SkipAll(output);
SwapBuffers();
PollEvents();
/**/
}
protected override void ProcessInput()
+20 -12
View File
@@ -9,7 +9,7 @@ using System.Runtime.CompilerServices;
namespace StgSharp
{
public class StgSharpDemoForm : Form
public class StgSharpDemoForm : ViewModel
{
public void Beep()
@@ -20,8 +20,6 @@ namespace StgSharp
}
}
//[RenderActivity(RenderPriority.Pre_1)]
public void NoOp()
{
@@ -45,20 +43,30 @@ namespace StgSharp
demoForm.Size = (800, 800);
demoForm.name = "Hello, Stg#!";
var stream = glRenderStream.AsMainStreamOf
//<MainRenderStream>
<ParticleStream>
(demoForm,(1,1,1));
var stream = demoForm.BuildMainRenderStream
//<MainRenderStream>
//<ParticleStream>
<fboFrame>
((1,1,1));
var rstream = RenderStream.ShareContextWith
<fboFrame,ParticleStream>(stream);
Blueprint blueprint = new Blueprint();
BlueprintNode node = new BlueprintNode("MainRenderStream",stream);
node.AddAfter(blueprint.BeginLayer,
BlueprintNode node0 = new BlueprintNode("BufferGenerateStream", rstream);
BlueprintNode node1 = new BlueprintNode("MainRenderStream",stream);
node0.AddAfter(blueprint.BeginLayer,
"input_1", "input_1");
node.AddBefore(blueprint.EndLayer,
"output_1", "output_1");
node0.AddBefore(node1,
"output_1", "TextureInput");
node1.AddBefore(blueprint.EndLayer,
"Output", "output_1");
blueprint.AddNativeNode(node);
blueprint.AddNativeNode(node0);
blueprint.AddNativeNode(node1);
blueprint.Init(0);
//Console.WriteLine(2);