MVVM frame work done, under unit test
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
//using StgSharp.Environment.Win32;
|
||||
using StgSharp.Controlling.UsrActivity;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
|
||||
using StgSharpDebug.Logic;
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Xml.XPath;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
internal static unsafe void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
//StgSharp.TryCreatWindow();
|
||||
|
||||
/**/
|
||||
StgSharp.Init();
|
||||
StgSharp.InitGL(4, 6);
|
||||
StgSharp.GlobalSetting.VSyncActivated = false;
|
||||
|
||||
|
||||
|
||||
|
||||
StgSharp.Terminate();
|
||||
/**/
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
|
||||
InternalIO.InternalWriteLog(
|
||||
ex.Message + "\n" + ex.StackTrace,
|
||||
LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
using StgSharp.Controls;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public class ParticleRenderStream : glRenderStream
|
||||
{
|
||||
|
||||
ElementBuffer ebo;
|
||||
|
||||
FrameBuffer fbo;
|
||||
Image i;
|
||||
PlainInstancingBuffer<ParticleOnPlain> buffer;
|
||||
RenderBuffer rbo;
|
||||
|
||||
ShaderProgram s;
|
||||
|
||||
TextureGL t;
|
||||
VertexArray vao;
|
||||
VertexBuffer vbo;
|
||||
|
||||
Uniform<float> time;
|
||||
|
||||
protected override void CustomizeDeinit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static vec3d DefaultRotation(TimeSpanProvider provider, out float rotation)
|
||||
{
|
||||
rotation = provider.SpanLengthLowPrecession * 2 * Scaler.Pi;
|
||||
float angle = provider.CurrentSecond * 2 * Scaler.Pi;
|
||||
return new vec3d(
|
||||
Scaler.Cos(rotation),
|
||||
Scaler.Sin(rotation),
|
||||
0
|
||||
) * provider.SpanLengthLowPrecession;
|
||||
}
|
||||
|
||||
ShaderProgram frameMainShader;
|
||||
|
||||
protected override void CustomizeInit()
|
||||
{
|
||||
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();
|
||||
frameMainShader = CreateShaderProgram();
|
||||
Shader pvs = CreateShaderSegment(ShaderType.Vertex, 2);
|
||||
Shader pfs = CreateShaderSegment(ShaderType.Fragment, 2);
|
||||
|
||||
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();
|
||||
|
||||
pvs.Compile(1, Shader.FromCodeFile("Shader\\fbo.vert"));
|
||||
pvs.AttachTo(1, frameMainShader);
|
||||
pfs.Compile(1, Shader.FromCodeFile("Shader\\fbo.frag"));
|
||||
pfs.AttachTo(1, frameMainShader);
|
||||
frameMainShader.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);
|
||||
vao.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
|
||||
vbo.WriteVectorData<vec4d>(1, buffer.CoordAndRotationSpan, BufferUsage.StreamDraw);
|
||||
vao.SetVertexAttribute(1, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
vao.SetVertexAttribute(2, 1, TypeCode.Single, false, 4 * sizeof(float), 3 * sizeof(float));
|
||||
|
||||
GL.VertexAttributeDivisor(1, 1);
|
||||
GL.VertexAttributeDivisor(2, 1);
|
||||
|
||||
vbo.WriteScalerData<float>(2, buffer.ScalingSpan, BufferUsage.StaticDraw);
|
||||
vao.SetVertexAttribute(3, 1, TypeCode.Single, false, sizeof(float), 0);
|
||||
|
||||
GL.VertexAttributeDivisor(3, 1);
|
||||
|
||||
vbo.Unbind();
|
||||
GL.BindVertexArray(GlHandle.Zero);
|
||||
|
||||
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);
|
||||
GL.SetRenderBufferStorage(
|
||||
RenderBufferInternalFormat.Depth24_Stencil8, this.Size);
|
||||
|
||||
|
||||
t = CreateTexture(1);
|
||||
t.Bind2D(0);
|
||||
/**/
|
||||
GL.TextureImage2d<byte>(Texture2DTarget.Texture2D, 0, (int)ImageChannel.WithAlphaChannel,
|
||||
(uint)Width, (uint)Height, (int)ImageChannel.WithAlphaChannel, PixelChannelLayout.Byte, null);
|
||||
/**/
|
||||
t.Set2dWrapProperty(Wrap.Repeat, Wrap.Repeat);
|
||||
t.Set2dFilterProperty(Filter.Nearest, Filter.Nearest);
|
||||
|
||||
|
||||
GL.FrameBufferTexture2d(FrameBufferTarget.All, glAttachment.Color(0),
|
||||
Texture2DTarget.Texture2D, t[0], 0);
|
||||
|
||||
GL.CombineFrameBufferRenderBuffer(fbo[0], rbo[0]);
|
||||
|
||||
int streamLength = this.Width * this.Height * 4;
|
||||
byte[] imageStream = new byte[streamLength];
|
||||
i = Image.FromMemory(this.Size, ImageChannel.WithAlphaChannel, imageStream);
|
||||
|
||||
time = s.GetUniform<float>("time");
|
||||
|
||||
vec2d[] coordArray = {
|
||||
(0f, 1f),
|
||||
(1f, 1f),
|
||||
(1f, 0f),
|
||||
(0f, 0f)
|
||||
};
|
||||
|
||||
buttonTextureProvider = new TextureProvider(i,coordArray);
|
||||
|
||||
|
||||
f_vao.Bind(0);
|
||||
|
||||
f_ebo.Bind(0);
|
||||
f_ebo.SetValue(0, rec.VertexIndices, BufferUsage.StaticDraw);
|
||||
|
||||
f_vbo.Bind(0);
|
||||
f_vbo.WriteVectorData(0, rec.VertexStream, BufferUsage.StaticDraw);
|
||||
f_vao.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
|
||||
f_vbo.Bind(1);
|
||||
f_vbo.WriteVectorData(1, coordArray, BufferUsage.StaticDraw);
|
||||
f_vao.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);
|
||||
|
||||
t.ActivateAs(TextureUnit.Unit0);
|
||||
|
||||
texUniform = frameMainShader.GetUniform<int>("tex");
|
||||
GL.SetUniformValue(texUniform, 1);
|
||||
}
|
||||
|
||||
VertexBuffer f_vbo;
|
||||
VertexArray f_vao;
|
||||
ElementBuffer f_ebo;
|
||||
Uniform<int> texUniform;
|
||||
|
||||
public void RenderButton(ButtonStatus status, float statusBegin, in TextureProvider provider)
|
||||
{
|
||||
provider.ReadImage(i);
|
||||
}
|
||||
|
||||
protected override void Main()
|
||||
{
|
||||
//GL.ClearError();
|
||||
//Console.Clear();
|
||||
//Console.WriteLine($"{Width} {Height}");
|
||||
buffer.UpdateAllParticles();
|
||||
|
||||
//Console.WriteLine(GL.CheckFrameBufferStatus(FrameBufferTarget.All));
|
||||
|
||||
fbo.Bind(0); // Console.Write($"{GL.GetError()}\t");
|
||||
vao.Bind(0); // Console.Write($"{GL.GetError()}\t");
|
||||
t.Bind2D(0); // Console.Write($"{GL.GetError()}\t");
|
||||
/**/
|
||||
|
||||
GL.TextureImage2d(Texture2DTarget.Texture2D, 0, (int)ImageChannel.WithAlphaChannel,
|
||||
(uint)Width, (uint)Height, (int)ImageChannel.WithAlphaChannel, PixelChannelLayout.Byte, new byte[1]);
|
||||
/**/
|
||||
|
||||
//Console.Write($"{GL.GetError()}\t");
|
||||
|
||||
GL.ClearColor((0.6f + TimePassed) % 1.0f, 0.1f, 0.3f, 1);
|
||||
GL.Clear(MaskBufferBit.COLOR | MaskBufferBit.DEPTH);
|
||||
|
||||
//Console.Write($"{GL.GetError()}\t");
|
||||
|
||||
vbo.Bind(1);
|
||||
vbo.WriteVectorData<vec4d>(1, buffer.CoordAndRotationSpan, BufferUsage.StreamDraw);
|
||||
|
||||
|
||||
s.Use();
|
||||
NativeCamera.SetAllUniforms();
|
||||
GL.SetUniformValue(time, TimePassed);
|
||||
|
||||
GL.DrawElementsInstanced(
|
||||
GeometryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero, 100
|
||||
);
|
||||
//Console.WriteLine(TimePassed);
|
||||
//Console.Write($"{GL.GetError()}\t");
|
||||
|
||||
GL.WaitAccomplishment();
|
||||
GL.BindVertexArray(GlHandle.Zero);
|
||||
/**/
|
||||
//Console.Write($"{GL.GetError()}\t");
|
||||
|
||||
ImageHelper.Resize(i, this.Width, this.Height, ImageMovement.Discard);
|
||||
|
||||
//GL.ClearError();
|
||||
|
||||
GL.GetTextureImage(Texture2DTarget.Texture2D, 0, ImageChannel.WithAlphaChannel,
|
||||
PixelChannelLayout.Byte, i.PixelBuffer);
|
||||
/*
|
||||
for (int num = 0; num < i.PixelBuffer.Length; num+=10000)
|
||||
{
|
||||
Console.Write($"{i.PixelBuffer[num]}\t");
|
||||
}
|
||||
/**/
|
||||
//Console.Write($"{GL.GetError()}\t");
|
||||
//Array.Fill<byte>(i.PixelBuffer, 24);
|
||||
|
||||
GL.BindFrameBuffer(FrameBufferTarget.All, GlHandle.Zero);
|
||||
|
||||
//Console.Write($"{GL.GetError()}\t");
|
||||
/**/
|
||||
|
||||
/*
|
||||
//BlueprintPipeline.SkipAll(output);
|
||||
SwapBuffers();
|
||||
PollEvents();
|
||||
/**/
|
||||
}
|
||||
|
||||
public void AnotherMain(IEnumerable<PlainGeometryMesh> items)
|
||||
{
|
||||
GL.BindFrameBuffer(FrameBufferTarget.All, GlHandle.Zero); //Console.Write($"{GL.GetError()}\t");
|
||||
GL.ClearColor(0.4f, TimePassed % 1.0f, 0f, 1.0f); //Console.Write($"{GL.GetError()}\t");
|
||||
GL.Clear(MaskBufferBit.COLOR /**/| MaskBufferBit.DEPTH/**/); //Console.Write($"{GL.GetError()}\t");
|
||||
|
||||
vao.Bind(0); //Console.Write($"{GL.GetError()}\t");
|
||||
|
||||
foreach (PlainGeometryMesh mesh in items)
|
||||
{
|
||||
t.LoadTexture(0, mesh.TextureImage);
|
||||
}
|
||||
//Console.Write($"{GL.GetError()}\t");
|
||||
|
||||
s.Use(); //Console.Write($"{GL.GetError()}\t");
|
||||
|
||||
|
||||
GL.DrawElements(GeometryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero);
|
||||
//Console.Write($"{GL.GetError()}\t");
|
||||
|
||||
//GL.DrawElements(GeometryType.LINES, 6, TypeCode.UInt32, IntPtr.Zero);
|
||||
//BlueprintPipeline.SkipAll(output);
|
||||
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
TextureProvider buttonTextureProvider;
|
||||
|
||||
public override bool IsContextSharable => true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using StgSharp.Controlling.UsrActivity;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public class Control : ViewResponder<ViewMain>
|
||||
{
|
||||
|
||||
|
||||
public override void CustomizedInitialize(Func<ITrigger, string, Action> keyRegister)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool ValidateInitializing()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Controlling;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using StgSharp.Controls;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal class Design : ViewDesigner<ViewMain>
|
||||
{
|
||||
DemoButtonGroup group;
|
||||
|
||||
public override sealed void CustomizedInitialize()
|
||||
{
|
||||
group = new DemoButtonGroup();
|
||||
}
|
||||
|
||||
public override bool ValidateInitializing()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class DemoButtonGroup : KeyboardButtonGroup
|
||||
{
|
||||
public override sealed void Confirm()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using StgSharp.Graphics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public class Render : ViewRender<ViewMain>
|
||||
{
|
||||
|
||||
public override void CustomizedInitialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool ValidateInitializing()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Logic;
|
||||
|
||||
using StgSharpDebug.Logic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public class ViewMain : View
|
||||
{
|
||||
public DemoButtonGroup DemoGroup
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public override void CustomizedInitialize(ViewModelBase viewModelBinding)
|
||||
{
|
||||
Designer = new Design();
|
||||
Responder = new Control();
|
||||
Render = new Render();
|
||||
|
||||
DemoGroup = new DemoButtonGroup();
|
||||
}
|
||||
|
||||
public override bool TryGetObjectReference(string name, out DataBindingEntry entry)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
internal protected override void Show()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Logic;
|
||||
|
||||
using StgSharpDebug.Logic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public class ViewModelMain : ViewModelBase
|
||||
{
|
||||
public ViewModelMain(ViewPort vp):base(vp,60)
|
||||
{
|
||||
dataBindingEntryIndexmap = new Dictionary<string, DataBindingEntry>();
|
||||
}
|
||||
|
||||
Dictionary<string, DataBindingEntry> dataBindingEntryIndexmap;
|
||||
|
||||
public override bool TryGetObjectReference(string name, out DataBindingEntry entry)
|
||||
{
|
||||
if (dataBindingEntryIndexmap.TryGetValue(name, out entry))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
entry = name switch
|
||||
{
|
||||
|
||||
_ => DataBindingEntry.NullBinding,
|
||||
};
|
||||
|
||||
if (entry.ExactEqual(DataBindingEntry.NullBinding))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
dataBindingEntryIndexmap.Add(name, entry);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void CustomizeInitialize()
|
||||
{
|
||||
|
||||
}
|
||||
}//------------------------------------- End of Class ------------------------------------------
|
||||
}
|
||||
Reference in New Issue
Block a user