daily update on 20240528 by nitload youmu

This commit is contained in:
Nitload
2024-05-28 17:45:54 +08:00
parent de399e22c2
commit 70890e3e33
88 changed files with 10678 additions and 5761 deletions
+115 -38
View File
@@ -28,6 +28,7 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics.GL;
using StgSharp.Logic;
using StgSharp.Math;
@@ -42,28 +43,56 @@ using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public abstract class RenderStream: IConvertableToBlueprintNode
public abstract class RenderStream : IConvertableToBlueprintNode
{
private protected (int x, int y, int z) _coordStretch;
private protected RenderStreamConstructArgs primeArgs;
private Camera nativeCamera;
private IntPtr canvasHandle;
private IntPtr contextHandle;
private int height;
private IntPtr monitor;
private IntPtr sharedCanvas;
private int width;
protected (int x, int y, int z) _coordStretch;
protected string name;
private Camera nativeCamera;
internal TimeSpanProvider timeProvider;
protected RenderStream(RenderStreamConstructArgs args, bool isSharing)
{
if (args == null)
{
throw new ArgumentNullException(nameof(args));
}
if (isSharing)
{
primeArgs = args;
}
else
{
RenderStreamConstructArgs? newArgs = args.Clone() as RenderStreamConstructArgs;
primeArgs = newArgs;
}
monitor = args.Monitor;
_coordStretch = args.UnitCubeSize;
NativeCamera = new Camera();
}
public RenderStream(RenderStreamConstructArgs args)
{
height = args.Height;
monitor = args.Monitor;
width = args.Width;
name = args.Name;
monitor = args.Monitor;
_coordStretch = args.UnitCubeSize;
if (args == null)
{
throw new ArgumentNullException(nameof(args));
}
RenderStreamConstructArgs? newArgs = args.Clone() as RenderStreamConstructArgs;
primeArgs = newArgs;
monitor = newArgs!.Monitor;
_coordStretch = newArgs.UnitCubeSize;
NativeCamera = new Camera();
}
public IntPtr CanvasHandle
@@ -78,12 +107,6 @@ namespace StgSharp.Graphics
internal set => contextHandle = value;
}
internal protected Camera NativeCamera
{
get => nativeCamera;
internal set => nativeCamera = value;
}
public FrameBufferSizeHandler FrameSizeCallback
{
set
@@ -94,13 +117,13 @@ namespace StgSharp.Graphics
}
public vec2d GlobalCoordSize => ((Width * 1.0f) / _coordStretch.x, (Height * 1.0f) / _coordStretch.y);
public int Height
{
get => height;
get => primeArgs.Height;
internal set
{
height = value;
primeArgs.Height = value;
InternalIO.glfwSetWindowSize(this.canvasHandle, Width, Height);
}
}
@@ -113,8 +136,8 @@ namespace StgSharp.Graphics
public string Name
{
get => name;
internal set => name = value;
get => primeArgs.Name;
internal set => primeArgs.Name = value;
}
public IntPtr SharedCanvas
@@ -123,35 +146,50 @@ namespace StgSharp.Graphics
internal set => sharedCanvas = value;
}
public vec2d Size
public (int width, int height) Size
{
get => new vec2d(width, height);
get => (Width, Height);
internal set
{
height = (int)value.Y;
width = (int)value.X;
primeArgs.Height = value.width;
primeArgs.Width = value.height;
InternalIO.glfwSetWindowSize(this.canvasHandle, Width, Height);
}
}
public int Width
{
get => width;
get => primeArgs.Width;
internal set
{
width = value;
primeArgs.Width = value;
InternalIO.glfwSetWindowSize(this.canvasHandle, Width, Height);
}
}
protected internal Camera NativeCamera
{
get => nativeCamera;
internal set => nativeCamera = value;
}
protected int Frames
{
get => timeProvider.CurrentSpan;
}
protected abstract string[] InputPortsName { get; }
protected abstract string[] OutputPortsName { get; }
string[] IConvertableToBlueprintNode.InputInterfacesName => InputPortsName;
protected float TimePassed
{
get => timeProvider.CurrentSpan;
}
string[] IConvertableToBlueprintNode.OutputInterfacesName => OutputPortsName;
BlueprintNodeAction IConvertableToBlueprintNode.MainExecution => InternalDraw;
protected TimeSpanProvider TimeProvider
{
get => timeProvider;
}
/// <summary>
/// Set the size limit of current form
@@ -163,10 +201,36 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public abstract void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight);
public static TTarget ShareContextWith<TSource, TTarget>(TSource source)
where TSource : RenderStream
where TTarget : RenderStream
{
TTarget? target = Activator.CreateInstance(typeof(TTarget), source.primeArgs, true) as TTarget;
if (target == null)
{
throw new InvalidOperationException(
$"Failed in creating a new {typeof(TTarget).Name} instance when calling ShareContextWith."
);
}
target.timeProvider = source.timeProvider;
target.canvasHandle = source.canvasHandle;
target.contextHandle = source.contextHandle;
target.Init();
return target;
}
internal abstract void CreateCanvas();
string[] IConvertableToBlueprintNode.InputInterfacesName => InputPortsName;
BlueprintNodeAction IConvertableToBlueprintNode.MainExecution => InternalDraw;
string[] IConvertableToBlueprintNode.OutputInterfacesName => OutputPortsName;
#region native camera operation
protected abstract void NativeCameraViewRange(Radius FieldOfRange,vec2d offset, (float frontDepth, float backDepth ) viewDepth );
protected abstract void NativeCameraViewRange(Radius fieldOfRange, vec2d offset, (float frontDepth, float backDepth) viewDepth);
protected abstract void NativeCameraViewTarget(vec3d position, vec3d direction, vec3d up);
/// <summary>
/// Get <see cref="Uniform{T}"/>(T is <see cref="Matrix44"/>) uniform from a shader.
@@ -198,7 +262,7 @@ namespace StgSharp.Graphics
in Dictionary<string, BlueprintPipeline> input,
in Dictionary<string, BlueprintPipeline> output);
protected abstract void ProcessInput();
#endregion
#region public resource generator
@@ -206,19 +270,32 @@ namespace StgSharp.Graphics
protected abstract Shader CreateShaderSegment(ShaderType type, int count);
protected abstract ShaderProgram CreateShaderProgram();
#endregion
}
public class RenderStreamConstructArgs
public class RenderStreamConstructArgs : ICloneable
{
public int Height { get; set; }
public IntPtr Monitor { get; set; }
public string Name { get; set; }
public int Width { get; set; }
public (int x, int y, int z) UnitCubeSize { get; set; }
public int Width { get; set; }
public object Clone()
{
RenderStreamConstructArgs ret = new RenderStreamConstructArgs();
ret.Height = Height;
ret.Width = Width;
ret.Monitor = Monitor;
ret.Name = Name;
ret.UnitCubeSize = UnitCubeSize;
return ret;
}
}
}