daily update on 20240613 by nitload youmu[4

This commit is contained in:
Nitload
2024-06-14 05:30:19 +08:00
parent be6c2e6b92
commit 7fb220c523
50 changed files with 991 additions and 700 deletions
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Graphics
{
public static class ImageProcessor
{
public static void Resize(Image i, int width, int height, ImageMovement move)
{
if (i == null)
{
throw new ArgumentNullException(nameof(i));
}
Array.Resize(ref i.data, width * height * i.ChannelCount);
i.Height = height;
i.Width = width;
switch (move)
{
case ImageMovement.Discard:
break;
case ImageMovement.Top:
break;
default:
throw new NotSupportedException("Invalid or not supported data remanence");
}
}
}
[Flags]
public enum ImageMovement
{
#pragma warning disable CA1008
Discard = 0,
#pragma warning restore CA1008
Top = 1,
Bottom = 2,
Left = 4,
Right = 8,
TopLeft = Top | Left,
BottomLeft = Bottom | Left,
TopRight = Top | Right,
BottomRight = Bottom | Right,
}
}
@@ -278,7 +278,7 @@ namespace StgSharp.Graphics
double virtualCursorPosX, virtualCursorPosY;
bool rawMouseMotion;
// _GLFWcontext context; // 根据_GLFWcontext的定义转换
// _GLFWcontext viewPortDisplay; // 根据_GLFWcontext的定义转换
// Callbacks are represented as IntPtr since we don't need the actual function pointers in C#
internal struct Callbacks
@@ -71,6 +71,7 @@ namespace StgSharp.Graphics.GL
}
/// <summary>
/// Load an <see cref="Image"/> to certain texture.
/// </summary>
/// <param name="index"> </param>
/// <param name="i"> </param>
@@ -224,7 +224,7 @@ namespace StgSharp.Graphics.GL
}
/// <summary>
/// Link the shader to current context.
/// Link the shader to current viewPortDisplay.
/// </summary>
public unsafe void Link()
{
@@ -247,7 +247,7 @@ namespace StgSharp.Graphics.GL
}
/// <summary>
/// Let the current context use this shader.
/// Let the current viewPortDisplay use this shader.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Use()
@@ -56,9 +56,9 @@ namespace StgSharp.Graphics.GL
private static string glExtensionList;
/// <summary>
/// Load all supported OpenGL APIs and bind them to given <see cref="ViewPort"/> context.
/// Load all supported OpenGL APIs and bind them to given <see cref="ViewPort"/> viewPortDisplay.
/// </summary>
/// <param name="vp">The <see cref="ViewPort"/> used as current OpenGL context</param>
/// <param name="vp">The <see cref="ViewPort"/> used as current OpenGL viewPortDisplay</param>
public static unsafe void LoadGLapi(this ViewPort vp)
{
GLcontext* context = (GLcontext*)vp.GraphicHandle;
@@ -56,11 +56,11 @@ namespace StgSharp.Graphics.GL
}
/// <summary>
/// Init an OpenGl context if current form has not been binded to any context. and set the context binded to
/// current form as current OpenGL context.
/// Init an OpenGl viewPortDisplay if current form has not been binded to any viewPortDisplay. and set the viewPortDisplay binded to
/// current form as current OpenGL viewPortDisplay.
/// </summary>
/// <exception cref="Exception">
/// Something goes wrong and StgSharp fails in creating a new OpenGL context.
/// Something goes wrong and StgSharp fails in creating a new OpenGL viewPortDisplay.
/// </exception>
public unsafe void MakeAsCurrentContext()
{
@@ -73,7 +73,6 @@ namespace StgSharp.Graphics.GL
if (glFunc.CurrentContextHandle != ContextHandle)
{
glFunc.CurrentContextHandle = ContextHandle;
//Console.WriteLine($"context set as {(ulong)glFunc.CurrentContextHandle}");
InternalIO.glfwMakeContextCurrent(CanvasHandle);
}
}
@@ -89,7 +88,6 @@ namespace StgSharp.Graphics.GL
in Dictionary<string, BlueprintPipeline> output)
{
MakeAsCurrentContext();
ProcessInput();
Main(in input, in output);
}
+29 -20
View File
@@ -45,6 +45,7 @@ namespace StgSharp.Graphics
{
public class Image : ISSDSerializable, IImageProvider
{
internal byte[] data;
internal ImageInfo info;
@@ -55,27 +56,40 @@ namespace StgSharp.Graphics
//int length = info.width * info.height * info.channel;
}
public ref byte[] DataStream
{
get => ref data;
}
public unsafe Image()
{
info = new ImageInfo();
}
public ImageChannel Channel => info.Channel;
public int ChannelCount => info.ChannelCount;
public int Height => info.Height;
public ref byte[] DataStream
{
get => ref data;
}
public (int width, int height) Size
{
get => (info.Width, info.Height);
}
public ImageChannel Channel => info.Channel;
public int ChannelCount => info.ChannelCount;
public int Height
{
get => info.Height;
internal set => info.Height = value;
}
public int Width
{
get => info.Width;
internal set => info.Width = value;
}
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
public int Width => info.Width;
public void FromBytes(byte[] stream)
{
}
public static unsafe Image FromFile(string route, ImageLoader loader)
{
@@ -139,11 +153,6 @@ namespace StgSharp.Graphics
return data;
}
public void FromBytes(byte[] stream)
{
}
public Image ProvideImage()
{
throw new NotImplementedException();
@@ -219,12 +228,6 @@ namespace StgSharp.Graphics
set => height = value;
}
public IntPtr StreamPtr
{
get => pixelPtr;
internal set => pixelPtr = value;
}
public int StreamSize
{
get => width * height * channelCount;
@@ -236,6 +239,12 @@ namespace StgSharp.Graphics
set => width = value;
}
public IntPtr StreamPtr
{
get => pixelPtr;
internal set => pixelPtr = value;
}
public override string ToString()
{
return $"{channel}\t{width}\t{height}\t{(ulong)StreamPtr}";
+54 -91
View File
@@ -45,51 +45,17 @@ namespace StgSharp.Graphics
{
public abstract class RenderStream : IConvertableToBlueprintNode
{
private ViewPort primeArgs;
private protected (int x, int y, int z) _coordStretch;
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;
private ViewPort primeArgs;
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)
public RenderStream(ViewPort v, (int, int, int) unitCubeSize)
{
if (v == null)
{
@@ -97,48 +63,8 @@ namespace StgSharp.Graphics
}
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;
nativeCamera = new Camera();
}
public (int width, int height) Size
@@ -152,14 +78,55 @@ namespace StgSharp.Graphics
}
}
public string[] InputInterfacesName => InputPortsName;
public string[] OutputInterfacesName => OutputPortsName;
public FrameBufferSizeHandler FrameSizeCallback
{
set
{
IntPtr handlerPtr = Marshal.GetFunctionPointerForDelegate(value);
InternalIO.glfwSetFramebufferSizeCallback(CanvasHandle, handlerPtr);
}
}
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 => primeArgs;
internal IntPtr CanvasHandle { get => primeArgs.ViewPortID; }
internal IntPtr ContextHandle
{
get => primeArgs.GraphicHandle;
private protected set => primeArgs.GraphicHandle = value;
}
protected internal Camera NativeCamera
@@ -200,7 +167,9 @@ namespace StgSharp.Graphics
where TSource : RenderStream
where TTarget : RenderStream
{
TTarget target = Activator.CreateInstance(typeof(TTarget), source.primeArgs, source._coordStretch) as TTarget;
#nullable enable
TTarget? target = Activator.CreateInstance(typeof(TTarget), source.primeArgs, source._coordStretch) as TTarget;
#nullable restore
if (target == null)
{
throw new InvalidOperationException(
@@ -208,17 +177,12 @@ namespace StgSharp.Graphics
);
}
target.timeProvider = source.timeProvider;
target.Init();
target.InternalInit();
return target;
}
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 NativeCameraViewTarget(vec3d position, vec3d direction, vec3d up);
@@ -251,7 +215,6 @@ namespace StgSharp.Graphics
protected abstract void Main(
in Dictionary<string, BlueprintPipeline> input,
in Dictionary<string, BlueprintPipeline> output);
protected abstract void ProcessInput();
#endregion
@@ -12,15 +12,15 @@ namespace StgSharp.Graphics
{
public TexturePipeline(Image i)
{
value = i;
_value = i;
}
private Image value;
private Image _value;
public Image Value
public new Image Value
{
get => value;
set => value = value ?? throw new ArgumentNullException(nameof(value));
get => _value;
set => _value = value ?? throw new ArgumentNullException(nameof(value));
}
}
}
+15 -44
View File
@@ -49,22 +49,15 @@ namespace StgSharp.Graphics
public unsafe partial class View
{
private (int w, int h) sizeCache;
private (int x, int y, int z) unitCubeSize;
private ViewPort context;
private ViewPortDesigner design;
public ViewPort Port
{
get => context;
}
public View(ViewPort vp, ViewPortDesigner design)
{
context = vp;
sizeCache = (0, 0);
unitCubeSize = (1, 1, 1);
localLogic = new Logic.Blueprint();
this.design = design;
@@ -74,30 +67,27 @@ namespace StgSharp.Graphics
public View(ViewPort vp, ViewPortDesigner design, (int, int, int) cubeSize)
{
context = vp;
sizeCache = (0, 0);
unitCubeSize = cubeSize;
localLogic = new Logic.Blueprint();
}
public (int x, int y, int z) UnitCubeSize
{
get => unitCubeSize;
}
public bool Activated { get; internal set; }
public int Height
{
get
{
if (context.Height != sizeCache.h)
{
sizeCache.h = context.Height;
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
}
return sizeCache.h;
}
internal set
{
sizeCache.h = value;
context.Height = value;
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
}
get => context.Height;
internal set { context.Height = value; }
}
public int Width
{
get => context.Width;
internal set { context.Width = value; }
}
public IntPtr Monitor => context.Monitor;
@@ -108,28 +98,9 @@ namespace StgSharp.Graphics
public string SelfName { get; set; }
public (int x, int y, int z) UnitCubeSize
public ViewPort Port
{
get => unitCubeSize;
}
public int Width
{
get
{
if (context.Width != sizeCache.w)
{
sizeCache.w = context.Width;
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
}
return sizeCache.h;
}
internal set
{
sizeCache.w = value;
context.Width = value;
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
}
get => context;
}
}
+98 -22
View File
@@ -1,7 +1,38 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ViewPort.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.Math;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using System.Threading;
@@ -10,37 +41,82 @@ namespace StgSharp.Graphics
{
public class ViewPort
{
public int Width { get; set; }
public int Height { get; set; }
private int _width, _height;
public string Name { get; set; }
internal ViewPort()
{
_height = 800;
_width = 600;
Name = new StackFrame(1, false).
GetMethod()!.DeclaringType!.Name;
Monitor = IntPtr.Zero;
ViewPortID = InternalIO.glfwCreateWindow(_width, _height,
Encoding.UTF8.GetBytes(Name), Monitor, IntPtr.Zero
);
if (ViewPortID == IntPtr.Zero)
{
throw new InvalidOperationException("Unable to create viewport handle.");
}
}
public ViewPort(vec2d size, string name, IntPtr monitor)
{
_width = (int)size.X;
_height = (int)size.Y;
Name = name;
Monitor = monitor;
ViewPortID = InternalIO.glfwCreateWindow(_width, _height,
Encoding.UTF8.GetBytes(Name), Monitor, IntPtr.Zero
);
if (ViewPortID == IntPtr.Zero)
{
throw new InvalidOperationException("Unable to create viewport handle.");
}
}
public unsafe int Height
{
get
{
return _height;
}
set
{
InternalIO.glfwSetWindowSize(this.ViewPortID, _width, value);
}
}
public unsafe int Width
{
get
{
return _width;
}
set
{
InternalIO.glfwSetWindowSize(this.ViewPortID, value, _height);
}
}
public IntPtr GraphicHandle { get; internal set; }
public IntPtr Monitor { get; internal set; }
public IntPtr ViewPortID { get; private set; }
public IntPtr GraphicHandle { get; internal set; }
internal ViewPort()
public string Name { get; set; }
public void Close()
{
Height = 800;
Width = 600;
Name = new StackFrame(1, false).
GetMethod()!.DeclaringType!.Name;
Monitor = IntPtr.Zero;
ViewPortID = InternalIO.glfwCreateWindow(Width,Height,
Encoding.UTF8.GetBytes(Name), Monitor, IntPtr.Zero
);
InternalIO.glfwSetWindowShouldClose(this.ViewPortID,1);
}
public ViewPort(vec2d size,string name, IntPtr monitor)
internal unsafe void FlushSize()
{
Height = (int) size.Y;
Width = (int) size.X;
Name = name;
Monitor = monitor;
ViewPortID = InternalIO.glfwCreateWindow(Width, Height,
Encoding.UTF8.GetBytes(Name), Monitor, IntPtr.Zero
);
fixed (int* wptr = &_width, hptr = &_height)
{
InternalIO.glfwGetWindowSize(ViewPortID, wptr, hptr);
}
}
}
}