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
+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()