daily update on 20240828 by nitload youmu, autotexture added
This commit is contained in:
@@ -1,199 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="FBOframe.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Controls;
|
||||
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
|
||||
{
|
||||
|
||||
ElementBuffer ebo;
|
||||
|
||||
TriggerButton button;
|
||||
|
||||
Rectangle tex;
|
||||
|
||||
ShaderProgram s;
|
||||
TextureGL t;
|
||||
|
||||
Uniform<int> texUniform;
|
||||
VertexArray vao;
|
||||
VertexBuffer vbo;
|
||||
|
||||
internal TimeSpanProvider spanProvider;
|
||||
|
||||
public fboFrame(ViewPort args, (int,int,int) cube) : base(args,cube)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override string[] InputPortsName
|
||||
=>
|
||||
[
|
||||
"TextureInput"
|
||||
];
|
||||
|
||||
protected override string[] OutputPortsName
|
||||
=>
|
||||
[
|
||||
"Output"
|
||||
];
|
||||
|
||||
protected override void Deinit()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
//SetSizeLimit(800, 800, 800, 800);
|
||||
|
||||
vbo = CreateVertexBuffer(2);
|
||||
vao = CreateVertexArray(1);
|
||||
ebo = CreateElementBuffer(1);
|
||||
|
||||
Rectangle rec = new Rectangle(
|
||||
-0.9f, 0.9f,
|
||||
0.9f, 0.9f,
|
||||
0.9f, -0.9f,
|
||||
-0.9f, -0.9f
|
||||
);
|
||||
|
||||
/*
|
||||
Rectangle tex = new Rectangle(
|
||||
-0.8f, 0.8f, 0,
|
||||
0.8f, 0.8f, 0,
|
||||
0.8f, -0.8f, 0,
|
||||
-0.8f, -0.8f, 0
|
||||
);
|
||||
/**/
|
||||
|
||||
/**/
|
||||
tex = new Rectangle(
|
||||
0f, 1f,
|
||||
1f, 1f,
|
||||
1f, 0f,
|
||||
0f, 0f
|
||||
);
|
||||
|
||||
/**/
|
||||
|
||||
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);
|
||||
|
||||
ViewPortDesigner vpDesigner = new ViewPortDesigner();
|
||||
vpDesigner.CreateKeyboardButtonGroup(null,null,null,null,null);
|
||||
button = vpDesigner.CreateKeyboardButton(
|
||||
rec,null,false
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
AnimationBuilder animation = new AnimationBuilder(
|
||||
(float f, out Polygon4 frame) =>
|
||||
{
|
||||
frame = tex;
|
||||
return i;
|
||||
}, TimeFunction.One);
|
||||
button.Enable(animation);
|
||||
|
||||
|
||||
FrameBuffer.BindNull();
|
||||
glFunc.ClearColor(0.4f, 0.1f, 0f, 1.0f);
|
||||
glFunc.Clear(MaskBufferBit.COLOR | MaskBufferBit.DEPTH);
|
||||
|
||||
s.Use();
|
||||
|
||||
vao.Bind(0);
|
||||
|
||||
foreach (PlainGeometryMesh item in button)
|
||||
{
|
||||
t.LoadTexture(0, item.TextureImage);
|
||||
}
|
||||
|
||||
glFunc.DrawElements(GeometryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero);
|
||||
//glFunc.DrawElements(GeometryType.LINES, 6, TypeCode.UInt32, IntPtr.Zero);
|
||||
BlueprintPipeline.SkipAll(output);
|
||||
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,245 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Particle.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
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
|
||||
{
|
||||
|
||||
ElementBuffer ebo;
|
||||
|
||||
FrameBuffer fbo;
|
||||
Image i;
|
||||
PlainInstancingBuffer<ParticleOnPlain> buffer;
|
||||
RenderBuffer rbo;
|
||||
|
||||
ShaderProgram s;
|
||||
|
||||
TextureGL t;
|
||||
VertexArray vao;
|
||||
VertexBuffer vbo;
|
||||
|
||||
public ParticleStream(ViewPort args, (int, int, int) cube) : base(args, (100, 100, 100))
|
||||
{
|
||||
}
|
||||
|
||||
protected override string[] InputPortsName => ["input_1"];
|
||||
|
||||
protected override string[] OutputPortsName => ["output_1"];
|
||||
|
||||
internal static vec3d DefaultRotation(TimeSpanProvider provider, out float rotation)
|
||||
{
|
||||
rotation = 0.1f;
|
||||
float angle = provider.CurrentSpan * 0.1f;
|
||||
return new vec3d(
|
||||
0.01f * Scaler.Cos(angle),
|
||||
(-0.01f) * Scaler.Sin(angle),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
protected override void Deinit()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
buffer = new PlainInstancingBuffer<ParticleOnPlain>();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
float ai = Scaler.Abs(i - 5.0f);
|
||||
for (int t = 0; t < 10; t++)
|
||||
{
|
||||
float at = Scaler.Abs(t - 5.0f);
|
||||
|
||||
ParticleOnPlain p = new ParticleOnPlain(buffer);
|
||||
((IInstancing)p).Coord = new vec3d(
|
||||
(((-5) + i) * 0.2f) + 0.1f, (((-5) + t) * 0.2f) + 0.1f, 0);
|
||||
((IInstancing)p).Scale =
|
||||
Scaler.MinOf(i, t) * 0.15f;
|
||||
((IInstancing)p).Motion = new GeometryMotion(
|
||||
true, this.timeProvider,
|
||||
DefaultRotation)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
//SetSizeLimit(800, 800, 800, 800);
|
||||
|
||||
s = CreateShaderProgram();
|
||||
Shader pvs = CreateShaderSegment(ShaderType.Vertex, 1);
|
||||
Shader pfs = CreateShaderSegment(ShaderType.Fragment, 1);
|
||||
|
||||
pvs.Compile(0, Shader.FromCodeFile("Shader\\particle.vert"));
|
||||
pvs.AttachTo(0, s);
|
||||
pfs.Compile(0, Shader.FromCodeFile("Shader\\particle.frag"));
|
||||
pfs.AttachTo(0, s);
|
||||
s.Link();
|
||||
|
||||
vbo = CreateVertexBuffer(3);
|
||||
vao = CreateVertexArray(1);
|
||||
ebo = CreateElementBuffer(1);
|
||||
vbo.Bind(0);
|
||||
|
||||
Rectangle rec = new Rectangle
|
||||
(
|
||||
0.05f, 0.05f,
|
||||
0.05f, -0.05f,
|
||||
-0.05f, -0.05f,
|
||||
-0.05f, 0.05f
|
||||
);
|
||||
|
||||
vao.Bind(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<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));
|
||||
|
||||
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.Unbind();
|
||||
VertexArray.BindNull();
|
||||
|
||||
NativeCameraViewTarget
|
||||
(
|
||||
(0, 0, -100),
|
||||
(0, 0, 0),
|
||||
(0, 1, 0)
|
||||
);
|
||||
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)
|
||||
{
|
||||
//Console.WriteLine($"{Width} {Height}");
|
||||
buffer.UpdateAllParticles();
|
||||
|
||||
fbo.Bind(0);
|
||||
vao.Bind(0);
|
||||
t.Bind2D(0);
|
||||
/**/
|
||||
glFunc.TextureImage2d(Texture2DTarget.Texture2D, 0, (int)ImageChannel.WithAlphaChannel,
|
||||
(uint)Width, (uint)Height, (int)ImageChannel.WithAlphaChannel, ImageChannelLayout.Byte, glHandle.ZeroHandle);
|
||||
/**/
|
||||
|
||||
glFunc.ClearColor(0.6f, 0.1f, 0.3f, 1);
|
||||
glFunc.Clear(MaskBufferBit.COLOR | MaskBufferBit.DEPTH);
|
||||
|
||||
vbo.Bind(1);
|
||||
vbo.WriteVectorData<vec4d>(1, buffer.CoordAndRotationSpan, BufferUsage.StreamDraw);
|
||||
|
||||
s.Use();
|
||||
NativeCamera.SetAllUniforms();
|
||||
|
||||
glFunc.DrawElementsInstanced(
|
||||
GeometryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero, 100
|
||||
);
|
||||
glFunc.WaitAccomplishment();
|
||||
VertexArray.BindNull();
|
||||
|
||||
/**/
|
||||
|
||||
ImageProcessor.Resize(i, this.Width, this.Height, ImageMovement.Discard);
|
||||
|
||||
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();
|
||||
/**/
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
//using StgSharp.Environment.Win32;
|
||||
using StgSharp.Controlling.UsrActivity;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Xml.XPath;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public class StgSharpDemoForm : ViewModelBase
|
||||
{
|
||||
public StgSharpDemoForm(int frameSpeed) : base(frameSpeed)
|
||||
{
|
||||
}
|
||||
public StgSharpDemoForm(ViewPort vp, int frameSpeed) : base(vp, frameSpeed)
|
||||
{
|
||||
}
|
||||
|
||||
protected sealed override void BuildGlobalKeyControl()
|
||||
{
|
||||
GlobalKeyAction.Add(
|
||||
new KeyTrigger(KeyboardKey.ESCAPE,KeyStatus.PRESS),
|
||||
new Action(() => {
|
||||
InternalIO.glfwSetWindowShouldClose(this.WindowID, 1);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
internal static unsafe void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
//StgSharp.TryCreatWindow();
|
||||
|
||||
/**/
|
||||
StgSharp.Init();
|
||||
StgSharp.InitGL(4, 6);
|
||||
StgSharp.GlobalSetting.VSyncActivated = false;
|
||||
|
||||
ViewPort viewport = new ViewPort(
|
||||
name: "Hello, Stg#!",
|
||||
size: (800,800),
|
||||
monitor: IntPtr.Zero
|
||||
);
|
||||
StgSharpDemoForm demoForm = new StgSharpDemoForm(vp: viewport,60);
|
||||
|
||||
View v = demoForm.BuildNewView(null, (1,1,1));
|
||||
|
||||
var stream = demoForm.BuildRenderStream
|
||||
//<MainRenderStream>
|
||||
//<ParticleStream>
|
||||
<fboFrame>
|
||||
(v);
|
||||
|
||||
var rstream = RenderStream.ShareContextWith
|
||||
<fboFrame,ParticleStream>(stream);
|
||||
Blueprint blueprint = new Blueprint();
|
||||
|
||||
//CrossFrameOperation cross = new CrossFrameOperation(() => Console.Beep(), 60 );
|
||||
var cross = new Action([BpNodeAction(60)] () => Console.Beep()).AsBlueprintNodeMainExecution();
|
||||
|
||||
BlueprintNode node0 = new BlueprintNode("BufferGenerateStream", rstream,true);
|
||||
BlueprintNode node1 = new BlueprintNode("MainRenderStream",stream,true);
|
||||
BlueprintNode node2 = new BlueprintNode("Beep", cross,false);
|
||||
|
||||
node0.AddAfter(blueprint.BeginLayer,
|
||||
"port_1", "input_1");
|
||||
node0.AddBefore(node1,
|
||||
"output_1", "TextureInput");
|
||||
|
||||
|
||||
|
||||
/*
|
||||
node1.AddBefore(blueprint.EndLayer,
|
||||
"Output", "port2");
|
||||
node2.AddAfter(blueprint.BeginLayer,
|
||||
"port_2", CrossFrameOperation.InputInterfacesName);
|
||||
/**/
|
||||
/**/
|
||||
node2.AddAfter(blueprint.BeginLayer,
|
||||
"input_2", CrossFrameOperation.InputInterfacesName);
|
||||
/**/
|
||||
node2.AddBefore(blueprint.EndLayer,
|
||||
CrossFrameOperation.OutputInterfacesName, "port_1");
|
||||
|
||||
blueprint.AddNode(node0,true);
|
||||
blueprint.AddNode(node1, true);
|
||||
blueprint.AddNode(node2, false);
|
||||
blueprint.Init();
|
||||
|
||||
BlueprintRunner.SetMaxTaskCount(1);
|
||||
|
||||
Console.WriteLine(2);
|
||||
|
||||
demoForm.GeneralRenderLogic = blueprint;
|
||||
demoForm.Show();
|
||||
StgSharp.Terminate();
|
||||
/**/
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
|
||||
InternalIO.InternalWriteLog(
|
||||
ex.Message + "\n" + ex.StackTrace,
|
||||
LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user