daily update on 20240610 by nitload youmu
This commit is contained in:
@@ -28,6 +28,8 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Geometries;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
@@ -35,23 +37,29 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public delegate Image BuildAnimationDelegate(float time, out Polygon4 texutreFrame);
|
||||
|
||||
public sealed class AnimationBuilder: IImageProvider
|
||||
{
|
||||
|
||||
private Image cache;
|
||||
|
||||
private Polygon4 textureFrame;
|
||||
private TimeFunction time;
|
||||
|
||||
public AnimationBuilder(
|
||||
Func<float, Image> builderFunc,
|
||||
BuildAnimationDelegate builderFunc,
|
||||
TimeFunction timeline
|
||||
)
|
||||
{
|
||||
textureFrame = new Polygon4();
|
||||
time = timeline;
|
||||
BuilderFunc = builderFunc;
|
||||
cache = BuilderFunc(time.Calculate(), out textureFrame);
|
||||
}
|
||||
|
||||
public Func<float, Image> BuilderFunc { get; set; }
|
||||
public Polygon4 TextureFrame { get => textureFrame; }
|
||||
|
||||
public BuildAnimationDelegate BuilderFunc { get; set; }
|
||||
|
||||
public bool IsComplete
|
||||
{
|
||||
@@ -62,7 +70,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
if (!time.IsComplete)
|
||||
{
|
||||
cache = BuilderFunc(time.Calculate());
|
||||
cache = BuilderFunc(time.Calculate(),out textureFrame);
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
@@ -428,17 +428,6 @@ namespace StgSharp.Graphics.GL
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void MakeContextCurrent(ViewModel form)
|
||||
{
|
||||
if (form.WindowID == IntPtr.Zero)
|
||||
{
|
||||
InternalIO.InternalWriteLog($"From {nameof(form)} is not inited.", LogType.Warning);
|
||||
return;
|
||||
}
|
||||
InternalIO.glfwMakeContextCurrent(form.id);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
|
||||
where T : struct
|
||||
|
||||
@@ -60,14 +60,14 @@ namespace StgSharp.Graphics.GL
|
||||
}
|
||||
}
|
||||
|
||||
public class Shader : SSDSerializable
|
||||
public class Shader : ISSDSerializable
|
||||
{
|
||||
|
||||
private readonly IntPtr context;
|
||||
internal readonly glHandleSet handle;
|
||||
public readonly ShaderType type;
|
||||
|
||||
public override SerializableTypeCode SSDTypeCode => SerializableTypeCode.Shader;
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.Shader;
|
||||
|
||||
internal unsafe Shader(glHandleSet handle, ShaderType usage)
|
||||
{
|
||||
@@ -126,27 +126,26 @@ namespace StgSharp.Graphics.GL
|
||||
return $"This is a {type} shader, its shader handles are {handle.ToString()}.";
|
||||
}
|
||||
|
||||
//TODO shader 的序列化究极麻烦,原因是shader的架构问题
|
||||
public override byte[] GetBytes()
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
public void CheckStatus(int index, ShaderStatus status)
|
||||
{
|
||||
string log = glFunc.GetShaderStatus(this,index, (int)status);
|
||||
if (log != "")
|
||||
if (!string.IsNullOrEmpty(log))
|
||||
{
|
||||
throw new Exception($"Shader Error\n{status}\n" + log);
|
||||
throw new Exception($"Shader Error \t{status}\n" + log);
|
||||
}
|
||||
}
|
||||
|
||||
public override byte[] GetBytes(out int length)
|
||||
public byte[] GetBytes(out int length)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
internal override void BuildFromByteStream(byte[] stream)
|
||||
public void FromBytes(byte[] stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -175,7 +174,7 @@ namespace StgSharp.Graphics.GL
|
||||
/// Get a uniform form current shader,
|
||||
/// the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the Uniform in shader code</param>
|
||||
/// <param name="name">ContextName of the Uniform in shader code</param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe Uniform<T> GetUniform<T>(string name) where T : struct
|
||||
@@ -187,7 +186,7 @@ namespace StgSharp.Graphics.GL
|
||||
/// Get a uniform form current shader,
|
||||
/// the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the Uniform in shader code</param>
|
||||
/// <param name="name">ContextName of the Uniform in shader code</param>
|
||||
/// <returns></returns>
|
||||
public unsafe Uniform<T, U> GetUniform<T, U>(string name)
|
||||
where T : struct
|
||||
@@ -200,7 +199,7 @@ namespace StgSharp.Graphics.GL
|
||||
/// Get a uniform form current shader,
|
||||
/// the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the Uniform in shader code</param>
|
||||
/// <param name="name">ContextName of the Uniform in shader code</param>
|
||||
/// <returns></returns>
|
||||
public unsafe Uniform<T, U, V> GetUniform<T, U, V>(string name)
|
||||
where T : struct
|
||||
@@ -213,7 +212,7 @@ namespace StgSharp.Graphics.GL
|
||||
/// Get a uniform form current shader,
|
||||
/// the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the Uniform in shader code</param>
|
||||
/// <param name="name">ContextName of the Uniform in shader code</param>
|
||||
/// <returns></returns>
|
||||
public unsafe Uniform<T, U, V, W> GetUniform<T, U, V, W>(string name)
|
||||
where T : struct
|
||||
|
||||
@@ -56,15 +56,15 @@ namespace StgSharp.Graphics.GL
|
||||
private static string glExtensionList;
|
||||
|
||||
/// <summary>
|
||||
/// Load all supported OpenGL APIs and bind them to given <see cref="ViewModel"/> context.
|
||||
/// Load all supported OpenGL APIs and bind them to given <see cref="ViewPort"/> context.
|
||||
/// </summary>
|
||||
/// <param name="stream">The <see cref="ViewModel"/> used as current OpenGL context</param>
|
||||
public static unsafe void LoadGLapi(this glRenderStream stream)
|
||||
/// <param name="vp">The <see cref="ViewPort"/> used as current OpenGL context</param>
|
||||
public static unsafe void LoadGLapi(this ViewPort vp)
|
||||
{
|
||||
GLcontext* context = (GLcontext*)stream.ContextHandle;
|
||||
GLcontext* context = (GLcontext*)vp.GraphicHandle;
|
||||
delegate*<string,IntPtr> loader = &InternalIO.glfwGetProcAddress;
|
||||
#pragma warning disable CS8909
|
||||
if (((GLcontext*)stream.ContextHandle)->glGetString != (delegate*<uint, IntPtr>)IntPtr.Zero)
|
||||
if (context->glGetString != (delegate*<uint, IntPtr>)IntPtr.Zero)
|
||||
#pragma warning restore CS8909
|
||||
{
|
||||
return;
|
||||
@@ -102,25 +102,25 @@ namespace StgSharp.Graphics.GL
|
||||
{
|
||||
#region load_core_gl
|
||||
|
||||
LoadGLcore10((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore11((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore12((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore13((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore14((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore15((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore20((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore21((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore30((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore31((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore32((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore33((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore40((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore41((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore42((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore43((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore44((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore45((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore46((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore10(context, loader);
|
||||
LoadGLcore11(context, loader);
|
||||
LoadGLcore12(context, loader);
|
||||
LoadGLcore13(context, loader);
|
||||
LoadGLcore14(context, loader);
|
||||
LoadGLcore15(context, loader);
|
||||
LoadGLcore20(context, loader);
|
||||
LoadGLcore21(context, loader);
|
||||
LoadGLcore30(context, loader);
|
||||
LoadGLcore31(context, loader);
|
||||
LoadGLcore32(context, loader);
|
||||
LoadGLcore33(context, loader);
|
||||
LoadGLcore40(context, loader);
|
||||
LoadGLcore41(context, loader);
|
||||
LoadGLcore42(context, loader);
|
||||
LoadGLcore43(context, loader);
|
||||
LoadGLcore44(context, loader);
|
||||
LoadGLcore45(context, loader);
|
||||
LoadGLcore46(context, loader);
|
||||
|
||||
#endregion load_core_gl
|
||||
}
|
||||
@@ -777,7 +777,7 @@ namespace StgSharp.Graphics.GL
|
||||
/// <summary>
|
||||
/// Get the function pointer of given OpenGL api name
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the OpenGL api</param>
|
||||
/// <param name="name">ContextName of the OpenGL api</param>
|
||||
/// <returns>The funtion pointer of the api in stream of <see cref="IntPtr"/></returns>
|
||||
public static IntPtr LoadGLfunc(string name)
|
||||
{
|
||||
|
||||
@@ -45,17 +45,14 @@ namespace StgSharp.Graphics.GL
|
||||
public abstract partial class glRenderStream : RenderStream
|
||||
{
|
||||
|
||||
protected glRenderStream(RenderStreamConstructArgs args) : base(args)
|
||||
{
|
||||
}
|
||||
protected glRenderStream(RenderStreamConstructArgs args,bool isSharing) : base(args,isSharing)
|
||||
protected glRenderStream(ViewPort v, (int,int,int) cube) : base(v,cube)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
protected IntPtr glContextHandle
|
||||
{
|
||||
get { return ContextHandle; }
|
||||
set { ContextHandle = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -87,14 +84,6 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.glfwSetWindowSizeLimits(this.CanvasHandle, minWidth, minHeight, maxWidth, maxHeight);
|
||||
}
|
||||
|
||||
internal override sealed unsafe void CreateCanvas()
|
||||
{
|
||||
byte[] nameCode = Encoding.UTF8.GetBytes(Name);
|
||||
CanvasHandle = InternalIO.glfwCreateWindow(
|
||||
Width, Height, nameCode, Monitor, IntPtr.Zero
|
||||
);
|
||||
}
|
||||
|
||||
internal override sealed void InternalDraw(
|
||||
in Dictionary<string, BlueprintPipeline> input,
|
||||
in Dictionary<string, BlueprintPipeline> output)
|
||||
@@ -106,9 +95,8 @@ namespace StgSharp.Graphics.GL
|
||||
|
||||
internal override sealed void InternalInit()
|
||||
{
|
||||
CreateCanvas();
|
||||
MakeAsCurrentContext();
|
||||
this.LoadGLapi();
|
||||
this.Port.LoadGLapi();
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class Image : SSDSerializable, IImageProvider
|
||||
public class Image : ISSDSerializable, IImageProvider
|
||||
{
|
||||
internal byte[] data;
|
||||
internal ImageInfo info;
|
||||
@@ -74,7 +74,7 @@ namespace StgSharp.Graphics
|
||||
get => (info.Width, info.Height);
|
||||
}
|
||||
|
||||
public override SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
|
||||
public int Width => info.Width;
|
||||
|
||||
public static unsafe Image FromFile(string route, ImageLoader loader)
|
||||
@@ -111,7 +111,7 @@ namespace StgSharp.Graphics
|
||||
return new glArrayHandle(data);
|
||||
}
|
||||
|
||||
public override unsafe byte[] GetBytes()
|
||||
public unsafe byte[] GetBytes()
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
@@ -139,40 +139,9 @@ namespace StgSharp.Graphics
|
||||
return data;
|
||||
}
|
||||
|
||||
public override unsafe byte[] GetBytes(out int length)
|
||||
public void FromBytes(byte[] stream)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
int size = Width * Height * ChannelCount;
|
||||
data = new byte[size];
|
||||
int i = 0;
|
||||
fixed (byte* bptr = data)
|
||||
{
|
||||
byte* pptr = bptr;
|
||||
for (; i < size; i += 16)
|
||||
{
|
||||
*(M128*)(pptr + i) = *(M128*)(info.StreamPtr + i);
|
||||
}
|
||||
for (; i < size; i++)
|
||||
{
|
||||
*(pptr + i) = *(byte*)(info.StreamPtr + i);
|
||||
}
|
||||
}
|
||||
fixed (ImageInfo* pptr = &info)
|
||||
{
|
||||
InternalIO.InternalUnloadImage(pptr);
|
||||
}
|
||||
info.StreamPtr = IntPtr.Zero;
|
||||
}
|
||||
length = data.Length;
|
||||
return data;
|
||||
}
|
||||
|
||||
internal override unsafe void BuildFromByteStream(byte[] stream)
|
||||
{
|
||||
throw new NotSupportedException(
|
||||
$"{($"{typeof(Image).Name} does not support BuildFromByteStream,")}{($"please use Image.FromMemory instead.")}"
|
||||
);
|
||||
}
|
||||
|
||||
public Image ProvideImage()
|
||||
|
||||
@@ -10,12 +10,12 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
public class PlainGeometryMesh
|
||||
{
|
||||
private IGeometry _shape;
|
||||
private PlainGeometry _shape;
|
||||
private Image _texture;
|
||||
private vec2d[] textureCoord;
|
||||
private vec4d[] textureCoord;
|
||||
|
||||
public PlainGeometryMesh(
|
||||
IGeometry shape, Image texture, IEnumerable<vec2d> texCoord
|
||||
PlainGeometry shape, Image texture, vec4d[] texCoord
|
||||
)
|
||||
{
|
||||
if (shape==null)
|
||||
@@ -28,31 +28,30 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
_shape = shape;
|
||||
textureCoord = new vec2d[shape.VertexCount];
|
||||
_texture = texture;
|
||||
if (texCoord is not vec2d[] source)
|
||||
{
|
||||
source = texCoord.ToArray();
|
||||
}
|
||||
if (textureCoord.Length > source.Length)
|
||||
if (shape.VertexCount > texCoord.Length)
|
||||
{
|
||||
throw new ArgumentException(paramName: nameof(texCoord), message: "Amount of texture coordination is too less");
|
||||
}
|
||||
Array.Copy(sourceArray: source, textureCoord, textureCoord.Length);
|
||||
textureCoord = texCoord;
|
||||
return;
|
||||
}
|
||||
|
||||
public PlainGeometryMesh Resize(PlainGeometry newShape)
|
||||
{
|
||||
return new PlainGeometryMesh(newShape, _texture, textureCoord);
|
||||
}
|
||||
|
||||
public ReadOnlySpan<int> MeshIndices => _shape.VertexIndices;
|
||||
|
||||
public vec4d[] VertexArray => _shape.VertexStream;
|
||||
|
||||
public Image Texture
|
||||
public Image TextureImage
|
||||
{
|
||||
get => _texture;
|
||||
internal set => _texture = value;
|
||||
}
|
||||
|
||||
public vec2d[] TextureCoord => textureCoord;
|
||||
public vec4d[] TextureCoord => textureCoord;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,34 +45,41 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
public abstract class RenderStream : IConvertableToBlueprintNode
|
||||
{
|
||||
private ViewPort primeArgs;
|
||||
|
||||
private protected (int x, int y, int z) _coordStretch;
|
||||
|
||||
private protected RenderStreamConstructArgs primeArgs;
|
||||
|
||||
private Camera nativeCamera;
|
||||
|
||||
private IntPtr canvasHandle;
|
||||
private IntPtr contextHandle;
|
||||
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(RenderStreamConstructArgs args, bool isSharing)
|
||||
/*
|
||||
protected RenderStream(View v, bool isSharing)
|
||||
{
|
||||
if (args == null)
|
||||
if (v == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
throw new ArgumentNullException(nameof(v));
|
||||
}
|
||||
if (isSharing)
|
||||
{
|
||||
primeArgs = args;
|
||||
primeArgs = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderStreamConstructArgs? newArgs = args.Clone() as RenderStreamConstructArgs;
|
||||
View? newArgs = args.Clone() as View;
|
||||
primeArgs = newArgs;
|
||||
}
|
||||
|
||||
@@ -80,32 +87,21 @@ namespace StgSharp.Graphics
|
||||
_coordStretch = args.UnitCubeSize;
|
||||
NativeCamera = new Camera();
|
||||
}
|
||||
/**/
|
||||
|
||||
public RenderStream(RenderStreamConstructArgs args)
|
||||
public RenderStream(ViewPort v, (int,int,int) unitCubeSize)
|
||||
{
|
||||
if (args == null)
|
||||
if (v == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
throw new ArgumentNullException(nameof(v));
|
||||
}
|
||||
RenderStreamConstructArgs? newArgs = args.Clone() as RenderStreamConstructArgs;
|
||||
primeArgs = newArgs;
|
||||
primeArgs = v;
|
||||
|
||||
monitor = newArgs!.Monitor;
|
||||
_coordStretch = newArgs.UnitCubeSize;
|
||||
monitor = v!.Monitor;
|
||||
_coordStretch = unitCubeSize;
|
||||
NativeCamera = new Camera();
|
||||
}
|
||||
|
||||
public IntPtr CanvasHandle
|
||||
{
|
||||
get => canvasHandle;
|
||||
internal set => canvasHandle = value;
|
||||
}
|
||||
|
||||
public IntPtr ContextHandle
|
||||
{
|
||||
get => contextHandle;
|
||||
internal set => contextHandle = value;
|
||||
}
|
||||
|
||||
public FrameBufferSizeHandler FrameSizeCallback
|
||||
{
|
||||
@@ -124,7 +120,7 @@ namespace StgSharp.Graphics
|
||||
internal set
|
||||
{
|
||||
primeArgs.Height = value;
|
||||
InternalIO.glfwSetWindowSize(this.canvasHandle, Width, Height);
|
||||
InternalIO.glfwSetWindowSize(this.CanvasHandle, Width, Height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +133,6 @@ namespace StgSharp.Graphics
|
||||
public string Name
|
||||
{
|
||||
get => primeArgs.Name;
|
||||
internal set => primeArgs.Name = value;
|
||||
}
|
||||
|
||||
public IntPtr SharedCanvas
|
||||
@@ -153,7 +148,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
primeArgs.Height = value.width;
|
||||
primeArgs.Width = value.height;
|
||||
InternalIO.glfwSetWindowSize(this.canvasHandle, Width, Height);
|
||||
InternalIO.glfwSetWindowSize(this.CanvasHandle, Width, Height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +158,7 @@ namespace StgSharp.Graphics
|
||||
internal set
|
||||
{
|
||||
primeArgs.Width = value;
|
||||
InternalIO.glfwSetWindowSize(this.canvasHandle, Width, Height);
|
||||
InternalIO.glfwSetWindowSize(this.CanvasHandle, Width, Height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +200,7 @@ namespace StgSharp.Graphics
|
||||
where TSource : RenderStream
|
||||
where TTarget : RenderStream
|
||||
{
|
||||
TTarget? target = Activator.CreateInstance(typeof(TTarget), source.primeArgs, true) as TTarget;
|
||||
TTarget target = Activator.CreateInstance(typeof(TTarget), source.primeArgs, source._coordStretch) as TTarget;
|
||||
if (target == null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
@@ -213,16 +208,11 @@ namespace StgSharp.Graphics
|
||||
);
|
||||
}
|
||||
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;
|
||||
@@ -239,7 +229,7 @@ namespace StgSharp.Graphics
|
||||
/// so do not ignore return value of this method.
|
||||
/// </summary>
|
||||
/// <param name="source">Shader using this camera</param>
|
||||
/// <param name="name">Name of projection camera named in shader</param>
|
||||
/// <param name="name">ContextName of projection camera named in shader</param>
|
||||
/// <returns>
|
||||
/// <see cref="Uniform{T}"/>(T is <see cref="Matrix44"/>) representing
|
||||
/// projection matrix in shader program.
|
||||
@@ -277,25 +267,4 @@ namespace StgSharp.Graphics
|
||||
|
||||
}
|
||||
|
||||
public class RenderStreamConstructArgs : ICloneable
|
||||
{
|
||||
|
||||
public int Height { get; set; }
|
||||
public IntPtr Monitor { get; set; }
|
||||
public string Name { 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="FormThreading.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 StgSharp.Logic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public partial class View
|
||||
{
|
||||
internal Blueprint localLogic;
|
||||
|
||||
/*
|
||||
private void GatherSingleFrameAsyncThread(MethodInfo[] methods)
|
||||
{
|
||||
if (methods.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (MethodInfo m in methods) //find all methods decorated by RenderActivityAttribute
|
||||
{
|
||||
RenderActivityAttribute attr = m.GetCustomAttribute<RenderActivityAttribute>(false);
|
||||
if (attr == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!m.IsStatic && (m.GetParameters().Length != 0) && (m.ReturnType != typeof(void)))
|
||||
{
|
||||
throw new NotSupportedException("A render activity cannot have parameters, returning value or be static.");
|
||||
}
|
||||
ThreadStart s = (ThreadStart)Delegate.CreateDelegate(typeof(ThreadStart), this, m);
|
||||
FrameAsyncThread thread = new(s, attr._priority);
|
||||
//singleFrameAsyncThreadList.Add(thread);
|
||||
}
|
||||
}
|
||||
/**/
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="View.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.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
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;
|
||||
SelfName = string.Empty;
|
||||
}
|
||||
|
||||
public View(ViewPort vp, ViewPortDesigner design, (int, int, int) cubeSize)
|
||||
{
|
||||
context = vp;
|
||||
sizeCache = (0, 0);
|
||||
unitCubeSize = cubeSize;
|
||||
localLogic = new Logic.Blueprint();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public IntPtr Monitor => context.Monitor;
|
||||
|
||||
public IntPtr ViewHandle => context.ViewPortID;
|
||||
|
||||
public string ContextName => context.Name;
|
||||
|
||||
public string SelfName { get; set; }
|
||||
|
||||
public (int x, int y, int z) UnitCubeSize
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class ViewPort
|
||||
{
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public IntPtr Monitor { get; internal set; }
|
||||
|
||||
public IntPtr ViewPortID { get; private set; }
|
||||
public IntPtr GraphicHandle { get; internal 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
|
||||
);
|
||||
}
|
||||
|
||||
public ViewPort(vec2d size,string name, IntPtr monitor)
|
||||
{
|
||||
Height = (int) size.Y;
|
||||
Width = (int) size.X;
|
||||
Name = name;
|
||||
Monitor = monitor;
|
||||
ViewPortID = InternalIO.glfwCreateWindow(Width, Height,
|
||||
Encoding.UTF8.GetBytes(Name), Monitor, IntPtr.Zero
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user