MVVM frame work done, under unit test
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
using StgSharp.Data;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.GL;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
|
||||
@@ -45,23 +45,12 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Stg
|
||||
{
|
||||
public class CollisionTextureInput : BlueprintPipelineArgs
|
||||
public interface IOneDimensionalCollisionTexture2D
|
||||
{
|
||||
|
||||
#pragma warning disable CS8618
|
||||
public CollisionTextureInput()
|
||||
#pragma warning restore CS8618
|
||||
{
|
||||
}
|
||||
|
||||
public new List<IInstancingBuffer> Value
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public void Init(Radius angleStride, string name);
|
||||
}
|
||||
|
||||
public class OneDimensionalCollisionTexture2D : glRenderStream
|
||||
public sealed class OneDimensionalCollisionTexture2D_GL :glRenderStream, IOneDimensionalCollisionTexture2D
|
||||
{
|
||||
|
||||
private const string inputName = "InstanceBufferList";
|
||||
@@ -75,44 +64,22 @@ namespace StgSharp.Stg
|
||||
VertexBuffer vbo;
|
||||
ElementBuffer ebo;
|
||||
|
||||
public OneDimensionalCollisionTexture2D(ViewPort args) : base(args,(1,1,1))
|
||||
public OneDimensionalCollisionTexture2D_GL()
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Collision TextureGL unit cannot share context with other render stream or set as mainstream of a form," +
|
||||
$"and cannot be inited by {typeof(ViewPort).Name} as well."
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CS8618
|
||||
public OneDimensionalCollisionTexture2D(Radius angleStride, string name) :
|
||||
#pragma warning restore CS8618
|
||||
base( new ViewPort()
|
||||
{
|
||||
Height = 1,
|
||||
Width = (int)((new Radius(Scaler.Pi)) / angleStride),
|
||||
Name = name,
|
||||
},(1, 1, 1))
|
||||
{
|
||||
InternalInit();
|
||||
}
|
||||
public override bool IsContextSharable => false;
|
||||
|
||||
protected override string[] InputPortsName =>
|
||||
[
|
||||
inputName,
|
||||
];
|
||||
|
||||
protected override string[] OutputPortsName =>
|
||||
[
|
||||
outputName,
|
||||
];
|
||||
#pragma warning disable CS8618
|
||||
|
||||
|
||||
protected override void Deinit()
|
||||
protected override void CustomizeDeinit()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
protected override void CustomizeInit()
|
||||
{
|
||||
generatingShader = CreateShaderProgram();
|
||||
|
||||
@@ -133,51 +100,45 @@ namespace StgSharp.Stg
|
||||
|
||||
|
||||
fbo = CreateFrameBuffer(1);
|
||||
RenderBuffer rbo = CreateRenderBuffer(1);
|
||||
glFunc.SetRenderBufferStorage(
|
||||
rbo = CreateRenderBuffer(1);
|
||||
GL.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);
|
||||
GL.TextureImage2d<byte>(Texture2DTarget.Texture2D, 0, (int)ImageChannel.WithAlphaChannel,
|
||||
(uint)Width, (uint)Height, (int)ImageChannel.WithAlphaChannel, PixelChannelLayout.Byte, Array.Empty<byte>());
|
||||
|
||||
t.Set2dWrapProperty(Wrap.Repeat, Wrap.Repeat);
|
||||
t.Set2dFilterProperty(Filter.Nearest, Filter.Nearest);
|
||||
|
||||
glFunc.FrameBufferTexture2d(FrameBufferTarget.All, glAttachment.Color(0),
|
||||
GL.FrameBufferTexture2d(FrameBufferTarget.All, glAttachment.Color(0),
|
||||
Texture2DTarget.Texture2D, t[0], 0);
|
||||
|
||||
glFunc.CombineFrameBufferRenderBuffer(fbo[0], rbo[0]);
|
||||
GL.CombineFrameBufferRenderBuffer(fbo[0], rbo[0]);
|
||||
|
||||
textureOutput = new float[this.Width];
|
||||
}
|
||||
|
||||
TextureGL t;
|
||||
RenderBuffer rbo;
|
||||
float[] textureOutput;
|
||||
|
||||
protected override void Main(
|
||||
in Dictionary<string, BlueprintPipeline> input,
|
||||
in Dictionary<string, BlueprintPipeline> output)
|
||||
protected override void Main()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public void GenerateCollisionTexture(IEnumerable<IInstancingBuffer> bufferEnumeration)
|
||||
{
|
||||
if (input == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Unknown operation lead to null ref of {nameof(input)}");
|
||||
}
|
||||
if (input[inputName].Args is not CollisionTextureInput inpipeline || inpipeline.Value == null || inpipeline.Value.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
List<IInstancingBuffer> bufferList = inpipeline.Value;
|
||||
|
||||
fbo.Bind(0);
|
||||
glFunc.ClearColor(0, 0, 0, 1);
|
||||
glFunc.Clear(MaskBufferBit.DEPTH|MaskBufferBit.COLOR);
|
||||
GL.ClearColor(0, 0, 0, 1);
|
||||
GL.Clear(MaskBufferBit.DEPTH | MaskBufferBit.COLOR);
|
||||
generatingShader.Use();
|
||||
vao.Bind(0);
|
||||
|
||||
foreach (IInstancingBuffer item in bufferList)
|
||||
foreach (IInstancingBuffer item in bufferEnumeration)
|
||||
{
|
||||
IGeometry g = item.TypicalShape;
|
||||
|
||||
@@ -187,26 +148,40 @@ namespace StgSharp.Stg
|
||||
}
|
||||
|
||||
ebo.Bind(0);
|
||||
ebo.SetValue<int>(0,g.VertexIndices,BufferUsage.StreamDraw);
|
||||
ebo.SetValue<int>(0, g.VertexIndices, BufferUsage.StreamDraw);
|
||||
|
||||
vbo.WriteVectorData<vec4d>(0,item.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));
|
||||
vbo.WriteVectorData<vec4d>(0, item.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));
|
||||
|
||||
vbo.WriteScalerData<float>(2, item.ScalingSpan, BufferUsage.StreamDraw);
|
||||
VertexArray.SetVertexAttribute(3, 1, TypeCode.Single, false, sizeof(float), 0);
|
||||
vao.SetVertexAttribute(3, 1, TypeCode.Single, false, sizeof(float), 0);
|
||||
|
||||
vbo.WriteVectorData(1,g.VertexStream,BufferUsage.StreamDraw);
|
||||
VertexArray.SetVertexAttribute(0,3,TypeCode.Single,false,4*sizeof(float),0);
|
||||
vbo.WriteVectorData(1, g.VertexStream, BufferUsage.StreamDraw);
|
||||
vao.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
|
||||
glFunc.DrawElementsInstanced(GeometryType.TRIANGLES,(uint)g.VertexIndices.Length / 3,
|
||||
TypeCode.UInt32,IntPtr.Zero,(uint)item.ScalingSpan.Length);
|
||||
GL.DrawElementsInstanced(GeometryType.TRIANGLES, (uint)g.VertexIndices.Length / 3,
|
||||
TypeCode.UInt32, IntPtr.Zero, (uint)item.ScalingSpan.Length);
|
||||
}
|
||||
|
||||
t.Bind2D(0);
|
||||
glFunc.GetTextureImage(Texture2DTarget.Texture2D,0,ImageChannel.SingleColor,ImageChannelLayout.Float,ref textureOutput);
|
||||
GL.GetTextureImage(Texture2DTarget.Texture2D, 0, ImageChannel.SingleColor, PixelChannelLayout.Float, textureOutput);
|
||||
VertexArray.BindNull();
|
||||
}
|
||||
|
||||
public void Init(Radius angleStride, string name)
|
||||
{
|
||||
primeArgs = new ViewPort()
|
||||
{
|
||||
Height = 1,
|
||||
Width = (int)((new Radius(Scaler.Pi)) / angleStride),
|
||||
Name = name,
|
||||
};
|
||||
|
||||
_coordStretch = (1, 1, 1);
|
||||
|
||||
PlatformSpecifiedInit();
|
||||
CustomizeInit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user