daily update on 20240828 by nitload youmu, autotexture added

This commit is contained in:
Nitload
2024-08-28 10:58:31 +08:00
parent d082071f2d
commit 1ee4e4a42f
586 changed files with 60910 additions and 123106 deletions
+93 -137
View File
@@ -28,9 +28,12 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics.GL;
using StgSharp.Logic;
using StgSharp.Graphics.OpenGL;
using StgSharp.Timing;
using StgSharp.Math;
using StgSharp.MVVM;
using StgSharp.MVVM.View;
using System;
using System.Collections.Generic;
@@ -43,103 +46,13 @@ using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public abstract class RenderStream : IConvertableToBlueprintNode
public abstract class RenderStream
{
private ViewPort primeArgs;
private protected (int x, int y, int z) _coordStretch;
private protected ViewPort primeArgs;
private Camera nativeCamera;
public ViewPort Port => primeArgs;
internal IntPtr CanvasHandle { get => primeArgs.ViewPortID; }
internal IntPtr ContextHandle
{
get => primeArgs.GraphicHandle;
private protected set => primeArgs.GraphicHandle = value;
}
private IntPtr monitor;
private IntPtr sharedCanvas;
internal TimeSpanProvider timeProvider;
/*
protected RenderStream(View v, bool isSharing)
{
if (v == null)
{
throw new ArgumentNullException(nameof(v));
}
if (isSharing)
{
primeArgs = v;
}
else
{
View? newArgs = args.Clone() as View;
primeArgs = newArgs;
}
monitor = args.Monitor;
_coordStretch = args.UnitCubeSize;
NativeCamera = new Camera();
}
/**/
public RenderStream(ViewPort v, (int,int,int) unitCubeSize)
{
if (v == null)
{
throw new ArgumentNullException(nameof(v));
}
primeArgs = v;
monitor = v!.Monitor;
_coordStretch = unitCubeSize;
NativeCamera = new Camera();
}
public FrameBufferSizeHandler FrameSizeCallback
{
set
{
IntPtr handlerPtr = Marshal.GetFunctionPointerForDelegate(value);
InternalIO.glfwSetFramebufferSizeCallback(CanvasHandle, handlerPtr);
}
}
public vec2d GlobalCoordSize => ((Width * 1.0f) / _coordStretch.x, (Height * 1.0f) / _coordStretch.y);
public int Height
{
get => primeArgs.Height;
internal set
{
primeArgs.Height = value;
InternalIO.glfwSetWindowSize(this.CanvasHandle, Width, Height);
}
}
public IntPtr Monitor
{
get => monitor;
internal set => monitor = value;
}
public string Name
{
get => primeArgs.Name;
}
public IntPtr SharedCanvas
{
get => sharedCanvas;
internal set => sharedCanvas = value;
}
internal TimeSpanProvider _timeProvider;
public (int width, int height) Size
{
@@ -152,14 +65,49 @@ namespace StgSharp.Graphics
}
}
public abstract bool IsContextSharable
{
get;
}
public int Height
{
get => primeArgs.Height;
internal set { primeArgs.Height = value; }
}
public int Width
{
get => primeArgs.Width;
internal set
{
primeArgs.Width = value;
InternalIO.glfwSetWindowSize(this.CanvasHandle, Width, Height);
}
internal set { primeArgs.Width = value; }
}
public IntPtr Monitor
{
get => primeArgs.Monitor;
internal set => primeArgs.Monitor = value;
}
public string Name
{
get => primeArgs.Name;
}
public vec2d GlobalCoordSize => ((Width * 1.0f) / _coordStretch.x, (Height * 1.0f) / _coordStretch.y);
public ViewPort Port
{
get => primeArgs;
internal set => primeArgs = value;
}
internal IntPtr CanvasHandle { get => primeArgs.ViewPortID; }
internal IntPtr ContextHandle
{
get => primeArgs.GraphicHandle;
private protected set => primeArgs.GraphicHandle = value;
}
protected internal Camera NativeCamera
@@ -168,22 +116,24 @@ namespace StgSharp.Graphics
internal set => nativeCamera = value;
}
protected int Frames
protected float FramePassed
{
get => timeProvider.CurrentSpan;
get => _timeProvider.CurrentSpan;
}
protected abstract string[] InputPortsName { get; }
protected abstract string[] OutputPortsName { get; }
protected int PassedFrames
{
get => _timeProvider.CurrentSpan;
}
protected float TimePassed
{
get => timeProvider.CurrentSpan;
get => _timeProvider.CurrentSecond;
}
protected TimeSpanProvider TimeProvider
{
get => timeProvider;
get => _timeProvider;
}
/// <summary>
@@ -196,34 +146,31 @@ 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)
public static TTarget ShareContextFrom<TSource, TTarget>(TSource source)
where TSource : RenderStream
where TTarget : RenderStream
where TTarget : RenderStream, new()
{
TTarget target = Activator.CreateInstance(typeof(TTarget), source.primeArgs, source._coordStretch) 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.Init();
TTarget target = new TTarget();
target.Initialize(source.Port, source._coordStretch, source._timeProvider);
return target;
}
protected internal static void PollEvents()
{
InternalIO.glfwPollEvents();
}
string[] IConvertableToBlueprintNode.InputInterfacesName => InputPortsName;
BlueprintNodeAction IConvertableToBlueprintNode.MainExecution => InternalDraw;
string[] IConvertableToBlueprintNode.OutputInterfacesName => OutputPortsName;
protected internal void SwapBuffers()
{
InternalIO.glfwSwapBuffers(CanvasHandle);
}
#region native camera operation
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.
/// Get <see cref="Uniform{T}"/>(TView is <see cref="Matrix44"/>) uniform from a shader.
/// This uniform will be used as projection matrix of this camera.
/// Additionally, for multi-shader rendering, each shader requires a uniform,
/// so do not ignore return value of this method.
@@ -231,27 +178,38 @@ namespace StgSharp.Graphics
/// <param name="source">Shader using this camera</param>
/// <param name="name">ContextName of projection camera named in shader</param>
/// <returns>
/// <see cref="Uniform{T}"/>(T is <see cref="Matrix44"/>) representing
/// <see cref="Uniform{T}"/>(TView is <see cref="Matrix44"/>) representing
/// projection matrix in shader program.
/// </returns>
protected abstract Uniform<Matrix44> NativeCameraUniform(ShaderProgram source, string name);
#endregion
#region internal operation
internal abstract void InternalDraw(
in Dictionary<string, BlueprintPipeline> input,
in Dictionary<string, BlueprintPipeline> output);
internal abstract void InternalInit();
internal abstract void InternalTerminate();
internal abstract void Draw();
public void Initialize(ViewPort v, (int, int, int) unitCubeSize, TimeSpanProvider timeProvider)
{
if (v == null)
{
throw new ArgumentNullException(nameof(v));
}
primeArgs = v;
this._timeProvider = timeProvider;
_coordStretch = unitCubeSize;
nativeCamera = new Camera();
PlatformSpecifiedInitialize();
CustomizeInit();
}
internal abstract void PlatformSpecifiedInitialize();
internal abstract void Terminate();
#endregion
#region public operation
protected abstract void Deinit();
protected abstract void Init();
protected abstract void Main(
in Dictionary<string, BlueprintPipeline> input,
in Dictionary<string, BlueprintPipeline> output);
protected abstract void ProcessInput();
protected abstract void CustomizeDeinit();
protected abstract void CustomizeInit();
protected abstract void Main();
#endregion
@@ -260,8 +218,6 @@ namespace StgSharp.Graphics
protected abstract Shader CreateShaderSegment(ShaderType type, int count);
protected abstract ShaderProgram CreateShaderProgram();
#endregion