daily update on 20240427 by nitload youmu

This commit is contained in:
YoumuLiu
2024-04-27 05:09:38 +08:00
parent dd6e8247bf
commit f83a130074
52 changed files with 1470 additions and 271 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ namespace StgSharp.Data.FileIO
internal SSDraw()
{
segments = new List<SSDSegment>();
ID = home.
}
public SSDraw(string name)
@@ -11,13 +11,19 @@ namespace StgSharp.Geometries
public abstract class ICoord
{
protected Matrix44 coordMat;
protected List<vec4d> pointBuffer;
public ICoord()
{
pointBuffer = new List<vec4d>();
}
public abstract Matrix44 GlobalCoordTransformation
{
get;
}
public abstract vec3d Center
public abstract vec3d Origin
{
get;
}
@@ -36,5 +42,18 @@ namespace StgSharp.Geometries
{
get;
}
public T BuildGeometry<T>(params vec4d[] defaultVertex) where T : IGeometry
{
T ret = Activator.CreateInstance<T>();
ret.GetVertexHandle(this, ret.VertexCount);
for (int i = 0; i < ret.VertexCount; i++)
{
ret[i] = defaultVertex[i];
}
return ret;
}
}
}
@@ -1,4 +1,6 @@
using System;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -6,9 +8,18 @@ using System.Threading.Tasks;
namespace StgSharp.Geometries
{
public class StreamLocalCoordinate:ICoord
public class StreamLocalCoordinate : ICoord
{
public override Matrix44 GlobalCoordTransformation => throw new NotImplementedException();
public override vec3d Origin => Vec3d.Zero;
public override vec3d X_axis => coordMat.colum0.XYZ;
public override vec3d Y_axis => throw new NotImplementedException();
public override vec3d Z_axis => throw new NotImplementedException();
}
}
@@ -0,0 +1,66 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IGeometry.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.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Geometries
{
public interface IGeometry
{
public vec4d this[int index]
{
get;
set;
}
public int VertexCount
{
get;
}
public vec4d[] VertexStream
{
get;
}
public void GetVertexHandle(ICoord coordinate, int count);
public void Transform(Matrix44 transFormMatrix);
}
}
@@ -77,9 +77,9 @@ namespace StgSharp.Geometries
internal override void UpdateCoordinate(int tick)
{
tick = time;
center.Position = this.coordinate.origin + MoveCenter(tick);
beginPoint.Position = this.coordinate.origin + MovBegin(tick);
endPoint.Position = this.coordinate.origin + MovEnd(tick);
center.Position = this.coordinate.Origin + MoveCenter(tick);
beginPoint.Position = this.coordinate.Origin + MovBegin(tick);
endPoint.Position = this.coordinate.Origin + MovEnd(tick);
}
}
@@ -79,9 +79,9 @@ namespace StgSharp.Geometries
internal override void UpdateCoordinate(int tick)
{
tick = time;
center.Position = this.coordinate.origin + MoveCenter(tick);
pointOnCircle.Position = this.coordinate.origin + UpdateRadius(tick);
pointOnPlain.Position = this.coordinate.origin + UpdatePlain(tick);
center.Position = this.coordinate.Origin + MoveCenter(tick);
pointOnCircle.Position = this.coordinate.Origin + UpdateRadius(tick);
pointOnPlain.Position = this.coordinate.Origin + UpdatePlain(tick);
}
}
@@ -96,8 +96,8 @@ namespace StgSharp.Geometries
internal override void UpdateCoordinate(int tick)
{
beginPoint.Position = coordinate.origin + MoveBeginPoint(time);
endPoint.Position = coordinate.origin + MoveEndPoint(time);
beginPoint.Position = coordinate.Origin + MoveBeginPoint(time);
endPoint.Position = coordinate.Origin + MoveEndPoint(time);
}
}
@@ -31,32 +31,44 @@
using StgSharp.Graphics;
using StgSharp.Math;
using System;
namespace StgSharp.Geometries
{
/// <summary>
/// 平面几何体。包含三角形,对称四边形,自由多边形等。最多可由16个点参数定义。
/// </summary>
public abstract class PlainGeometry
public abstract class PlainGeometry: IGeometry
{
protected TimeSpanProvider time;
internal PartialPlainCoordinate coordinate;
internal ICoord coordinate;
internal Matrix24 textureFrame;
public PlainGeometry()
{
}
vec4d IGeometry.this[int index]
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
}
/// <summary>
/// Tick time this geometry eas crested
/// </summary>
public int BornTime => time;
public PartialPlainCoordinate ReferenceCoordinate => this.coordinate;
public ICoord ReferenceCoordinate => this.coordinate;
internal abstract int[] Indices { get; }
int IGeometry.VertexCount => throw new NotImplementedException();
vec4d[] IGeometry.VertexStream => throw new NotImplementedException();
/// <summary>
/// Get all sides of this <see cref="PlainGeometry"/>.
/// </summary>
@@ -72,6 +84,16 @@ namespace StgSharp.Geometries
internal abstract void UpdateCoordinate(int tick);
void IGeometry.GetVertexHandle(ICoord coordinate, int count)
{
throw new NotImplementedException();
}
void IGeometry.Transform(Matrix44 transFormMatrix)
{
throw new NotImplementedException();
}
//public abstract Rectangle GetRenderFrame();
}
}
@@ -49,7 +49,7 @@ namespace StgSharp.Geometries
{
}
public Polygon4(PartialPlainCoordinate coordinate,
public Polygon4(ICoord coordinate,
vec2d topLeft,
vec2d topRight,
vec2d bottomRight,
@@ -153,11 +153,11 @@ namespace StgSharp.Geometries
internal override void UpdateCoordinate(int tick)
{
int nowTick = tick - BornTime;
vertexMat.vec0 = (coordinate.origin + movVertex01(nowTick)).vec;
vertexMat.vec1 = (coordinate.origin + movVertex02(nowTick)).vec;
vertexMat.vec2 = (coordinate.origin + movVertex03(nowTick)).vec;
vertexMat.vec3 = (coordinate.origin + movVertex04(nowTick)).vec;
vertexMat.vec4 = (coordinate.origin + movVertex05(nowTick)).vec;
vertexMat.vec0 = (coordinate.Origin + movVertex01(nowTick)).vec;
vertexMat.vec1 = (coordinate.Origin + movVertex02(nowTick)).vec;
vertexMat.vec2 = (coordinate.Origin + movVertex03(nowTick)).vec;
vertexMat.vec3 = (coordinate.Origin + movVertex04(nowTick)).vec;
vertexMat.vec4 = (coordinate.Origin + movVertex05(nowTick)).vec;
}
}
@@ -144,7 +144,7 @@ namespace StgSharp.Geometries
internal override void UpdateCoordinate(int tick)
{
int nowTick = tick - BornTime;
Vector4 origin = coordinate.origin.vec;
Vector4 origin = coordinate.Origin.vec;
vertexMat.vec0 = origin + movVertex0(nowTick).vec;
vertexMat.vec1 = origin + movVertex1(nowTick).vec;
vertexMat.vec2 = origin + movVertex2(nowTick).vec;
@@ -116,9 +116,9 @@ namespace StgSharp.Geometries
internal override sealed void UpdateCoordinate(int tick)
{
tick = time;
vertexMat.mat.colum0 = coordinate.origin.vec + MovVertex01(time).vec;
vertexMat.mat.colum1 = coordinate.origin.vec + MovVertex02(time).vec;
vertexMat.mat.colum2 = coordinate.origin.vec + MovVertex03(time).vec;
vertexMat.mat.colum0 = coordinate.Origin.vec + MovVertex01(time).vec;
vertexMat.mat.colum1 = coordinate.Origin.vec + MovVertex02(time).vec;
vertexMat.mat.colum2 = coordinate.Origin.vec + MovVertex03(time).vec;
}
}
@@ -279,25 +279,25 @@ namespace StgSharp.Graphics
// _GLFWcontext context; // 根据_GLFWcontext的定义转换
// Callbacks are represented as IntPtr since we don't need the actual function pointers in C#
struct Callbacks
internal struct Callbacks
{
IntPtr pos;
IntPtr size;
IntPtr close;
IntPtr refresh;
IntPtr focus;
IntPtr iconify;
IntPtr maximize;
IntPtr fbsize;
IntPtr scale;
IntPtr mouseButton;
IntPtr cursorPos;
IntPtr cursorEnter;
IntPtr scroll;
IntPtr key;
IntPtr character;
IntPtr charmods;
IntPtr drop;
internal IntPtr pos;
internal IntPtr size;
internal IntPtr close;
internal IntPtr refresh;
internal IntPtr focus;
internal IntPtr iconify;
internal IntPtr maximize;
internal IntPtr fbsize;
internal IntPtr scale;
internal IntPtr mouseButton;
internal IntPtr cursorPos;
internal IntPtr cursorEnter;
internal IntPtr scroll;
internal IntPtr key;
internal IntPtr character;
internal IntPtr charmods;
internal IntPtr drop;
}
Callbacks callbacks;
+1 -1
View File
@@ -99,7 +99,7 @@ namespace StgSharp.Graphics
internal unsafe delegate void GLFWvkproc();
internal unsafe delegate void GLFWscrollfun(glfwWindow* window, double xoffset, double yoffset);
internal unsafe delegate void GLFWmousebuttonfun(glfwWindow* window, int button, int action, int mods);
internal unsafe delegate void GLFWmonitorfun(GLFWmonitor* monitor, int monitorevent);
internal unsafe delegate void GLFWmonitorfun(glfwMonitor* monitor, int monitorevent);
internal unsafe delegate void GLFWkeyfun(glfwWindow* window, int key, int scancode, int action, int mods);
internal unsafe delegate void GLFWjoystickfun(int jid, int keyevent);
public unsafe delegate void GLFWglproc();
+5 -2
View File
@@ -188,7 +188,7 @@ namespace StgSharp.Graphics
/// Set the size limit of current form
/// </summary>
/// <param name="minSize">
/// Minimun size of current form. In form of a <see cref="vec2d"/> of (width,height)
/// Minimum size of current form. In form of a <see cref="vec2d"/> of (width,height)
/// </param>
/// <param name="maxSize">
/// Maximum size of current form. In form of a <see cref="vec2d"/> of (width,height)
@@ -213,7 +213,10 @@ namespace StgSharp.Graphics
/// <param name="maxHeight">Maximum height of current form</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
{ InternalIO.glfwSetWindowSizeLimits(this.windowID, minWidth, minHeight, maxWidth, maxHeight); }
{
//TODO 重做form的尺寸极限控制
InternalIO.glfwSetWindowSizeLimits(this.windowID, minWidth, minHeight, maxWidth, maxHeight);
}
}
@@ -42,6 +42,7 @@ namespace StgSharp.Graphics
{
public abstract partial class Form
{
private List<FrameAsyncThread> multiFrameAsyncThreadList = new List<FrameAsyncThread>();
private List<FrameAsyncThread> singleFrameAsyncThreadList = new List<FrameAsyncThread>();
@@ -54,7 +54,7 @@ namespace StgSharp.Graphics
/// <summary>
/// Create a sets of <see cref="Texture"/>
/// </summary>
/// <param name="count">Amount of textures to be crated.</param>
/// <param name="count">Amount of textures to be created.</param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected Texture CreateTexture(int count)
@@ -65,7 +65,7 @@ namespace StgSharp.Graphics
/// <summary>
/// Create a set of <see cref="VertexArray"/>.
/// </summary>
/// <param name="count">Amount of VAO to be crated.</param>
/// <param name="count">Amount of VAO to be created.</param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected VertexArray CreateVertexArray(int count)
@@ -74,7 +74,7 @@ namespace StgSharp.Graphics
}
/// <summary>
/// Create aset of <see cref="VertexBuffer"/>.
/// Create a set of <see cref="VertexBuffer"/>.
/// </summary>
/// <param name="count">Amount of Object to be created.</param>
/// <returns></returns>
@@ -84,5 +84,6 @@ namespace StgSharp.Graphics
return new VertexBuffer(count, this);
}
}
}
@@ -39,10 +39,14 @@ using System.Text;
namespace StgSharp.Graphics
{
public partial class Form
public partial class glRenderStream
{
protected glRenderStream(RenderStreamConstructArgs args) : base(args)
{
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected Shader CreateShader(ShaderType type, int count)
protected sealed override Shader CreateShaderSegment(ShaderType type, int count)
{
return new Shader( GL.CreateShaderSet(count, type), type);
}
@@ -51,7 +55,7 @@ namespace StgSharp.Graphics
/// </summary>
/// <returns>New instance of <see cref="Shader"/> instance. </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected ShaderProgram CreateShaderProgram()
protected sealed override ShaderProgram CreateShaderProgram()
{
return new ShaderProgram(this);
}
@@ -126,9 +130,9 @@ namespace StgSharp.Graphics
/// <summary>
/// Init a program with no shader attached.
/// </summary>
internal unsafe ShaderProgram(Form binding)
internal unsafe ShaderProgram(glRenderStream binding)
{
this.binding = binding.graphicContextID;
this.binding = binding.ContextHandle;
handle = GL.CreateProgram();
}
@@ -62,9 +62,9 @@ namespace StgSharp.Graphics
}
internal unsafe Uniform(
ShaderProgram program, string name, Form binding)
ShaderProgram program, string name, glRenderStream binding)
{
this.binding = binding.graphicContextID;
this.binding = binding.ContextHandle;
id = GL.GetUniformLocation(program.handle, name);
}
@@ -98,9 +98,9 @@ namespace StgSharp.Graphics
}
internal unsafe Uniform(
ShaderProgram program, string name, Form binding)
ShaderProgram program, string name, glRenderStream binding)
{
this.binding = binding.graphicContextID;
this.binding = binding.ContextHandle;
id = GL.GetUniformLocation(program.handle, name);
}
@@ -141,9 +141,9 @@ namespace StgSharp.Graphics
id = GL.GetUniformLocation(program.handle, name);
}
public unsafe Uniform(ShaderProgram program, string name, Form binding)
public unsafe Uniform(ShaderProgram program, string name, glRenderStream binding)
{
this.binding = binding.graphicContextID;
this.binding = binding.ContextHandle;
id = GL.GetUniformLocation(program.handle, name);
}
@@ -172,9 +172,9 @@ namespace StgSharp.Graphics
this.id = id;
}
internal unsafe Uniform(ShaderProgram program, string name, Form binding)
internal unsafe Uniform(ShaderProgram program, string name, glRenderStream binding)
{
this.binding = binding.graphicContextID;
this.binding = binding.ContextHandle;
id = GL.GetUniformLocation(program.handle, name);
}
+26 -26
View File
@@ -56,16 +56,16 @@ namespace StgSharp.Graphics
private static string glExtensionList;
/// <summary>
/// Load all aupportable OpenGL APIs and bind them to given <see cref="Form"/> context.
/// Load all supportted OpenGL APIs and bind them to given <see cref="Form"/> context.
/// </summary>
/// <param name="form">The <see cref="Form"/> used as current OpenGL context</param>
/// <param name="loader">A delegate to get address of OprnGL api</param>
public static unsafe void LoadGLapi(this Form form)
/// <param name="stream">The <see cref="Form"/> used as current OpenGL context</param>
/// <param name="loader">A delegate to get address of OpenGL api</param>
public static unsafe void LoadGLapi(this glRenderStream stream)
{
GLcontext* context = (GLcontext*)form.graphicContextID;
GLcontext* context = (GLcontext*)stream.ContextHandle;
GLfuncLoader loader = InternalIO.glfwGetProcAddress;
#pragma warning disable CS8909
if (((GLcontext*)form.graphicContextID)->glGetString != (delegate*<uint, IntPtr>)IntPtr.Zero)
if (((GLcontext*)stream.ContextHandle)->glGetString != (delegate*<uint, IntPtr>)IntPtr.Zero)
#pragma warning restore CS8909
{
return;
@@ -103,25 +103,25 @@ namespace StgSharp.Graphics
{
#region load_core_gl
LoadGLcore10((GLcontext*)form.graphicContextID, loader);
LoadGLcore11((GLcontext*)form.graphicContextID, loader);
LoadGLcore12((GLcontext*)form.graphicContextID, loader);
LoadGLcore13((GLcontext*)form.graphicContextID, loader);
LoadGLcore14((GLcontext*)form.graphicContextID, loader);
LoadGLcore15((GLcontext*)form.graphicContextID, loader);
LoadGLcore20((GLcontext*)form.graphicContextID, loader);
LoadGLcore21((GLcontext*)form.graphicContextID, loader);
LoadGLcore30((GLcontext*)form.graphicContextID, loader);
LoadGLcore31((GLcontext*)form.graphicContextID, loader);
LoadGLcore32((GLcontext*)form.graphicContextID, loader);
LoadGLcore33((GLcontext*)form.graphicContextID, loader);
LoadGLcore40((GLcontext*)form.graphicContextID, loader);
LoadGLcore41((GLcontext*)form.graphicContextID, loader);
LoadGLcore42((GLcontext*)form.graphicContextID, loader);
LoadGLcore43((GLcontext*)form.graphicContextID, loader);
LoadGLcore44((GLcontext*)form.graphicContextID, loader);
LoadGLcore45((GLcontext*)form.graphicContextID, loader);
LoadGLcore46((GLcontext*)form.graphicContextID, loader);
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);
#endregion load_core_gl
}
@@ -779,7 +779,7 @@ namespace StgSharp.Graphics
/// Get the function pointer of given OpenGL api name
/// </summary>
/// <param name="name">Name of the OpenGL api</param>
/// <returns>The funtion pointer of the api in form of <see cref="IntPtr"/></returns>
/// <returns>The funtion pointer of the api in stream of <see cref="IntPtr"/></returns>
public static IntPtr LoadGLfunc(string name)
{
IntPtr ret = InternalIO.glfwGetProcAddress(name);
@@ -1,28 +1,47 @@
using System;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public abstract partial class glRenderStream:RenderStream
public abstract partial class glRenderStream: RenderStream
{
protected sealed override void NativeCameraViewTarget(vec3d position, vec3d direction, vec3d up)
{
NativeCamera.SetViewDirection(position, direction, up);
}
protected sealed override Uniform<Matrix44> NativeCameraUniform(ShaderProgram source, string name)
{
NativeCamera.GainAllUniforms(source, name);
return NativeCamera.convertedUniform;
}
protected IntPtr glContextHandle
{
get { return ContextHandle; }
set { ContextHandle = value; }
}
internal sealed override void CreateCanvas((int width, int height, int depth) size, (int x_stretch, int y_stretch, int z_stretch) coordStrech, string name)
internal unsafe sealed override void CreateCanvas()
{
Width = size.width; Height = size.height;
Depth = size.depth;
_coordStretch = coordStrech;
Name = name;
byte[] nameCode = Encoding.UTF8.GetBytes(name);
CanvasHandle = InternalIO.glfwCreateWindow(
Width,Height,nameCode,Monitor,IntPtr.Zero
);
NativeCamera = new Camera();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected sealed override void NativeCameraViewRange(Radius fieldOfRange,vec2d offset, (float frontDepth, float backDepth) viewDepth)
{
NativeCamera.SetViewRange(fieldOfRange,this.Size, offset, viewDepth);
}
/// <summary>
@@ -40,11 +59,11 @@ namespace StgSharp.Graphics
byte[] tittleBytes = Encoding.UTF8.GetBytes(name);
if (SharedCanvas == IntPtr.Zero)
{
windowPtr = InternalIO.glfwCreateWindow(Width, Height, tittleBytes, monitor, IntPtr.Zero);
windowPtr = InternalIO.glfwCreateWindow(Width, Height, tittleBytes, Monitor, IntPtr.Zero);
}
else
{
windowPtr = InternalIO.glfwCreateWindow(Width, Height, tittleBytes, monitor, SharedCanvas.CanvasHandle);
windowPtr = InternalIO.glfwCreateWindow(Width, Height, tittleBytes, Monitor, SharedCanvas);
}
if (((long)windowPtr == -1) || ((long)windowPtr == -2))
{
@@ -64,8 +83,16 @@ namespace StgSharp.Graphics
InternalIO.glfwMakeContextCurrent(CanvasHandle);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
{
InternalIO.glfwSetWindowSizeLimits(this.CanvasHandle, minWidth, minHeight, maxWidth, maxHeight);
}
internal sealed override void InternalInit()
{
CreateCanvas();
MakeAsCurrentContext();
this.LoadGLapi();
Init();
}
@@ -80,5 +107,6 @@ namespace StgSharp.Graphics
{
Deinit();
}
}
}
+103 -26
View File
@@ -34,6 +34,8 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
@@ -41,18 +43,27 @@ namespace StgSharp.Graphics
{
public abstract class RenderStream
{
protected (int x, int y, int z) _coordStretch;
private int refDepth;
protected Camera NativeCamera;
private IntPtr canvasHandle;
private IntPtr contextHandle;
private IntPtr monitor;
private IntPtr sharedCanvas;
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;
protected RenderStream(RenderStreamConstructArgs args)
{
height = args.Height;
monitor = args.Monitor;
width = args.Width;
name = args.Name;
monitor = args.Monitor;
_coordStretch = args.UnitCubeSize;
}
public IntPtr CanvasHandle
{
@@ -66,26 +77,30 @@ namespace StgSharp.Graphics
internal set => contextHandle = value;
}
public int Depth
internal protected Camera NativeCamera
{
get => refDepth;
internal set => refDepth = value;
get => nativeCamera;
internal set => nativeCamera = value;
}
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 => height;
internal set => height = value;
}
public vec3d GlobalCoordSize
{
get
internal set
{
return (
Width * 1.0f / _coordStrech.x,
Height * 1.0f / _coordStrech.y,
refDepth * 1.0f / _coordStrech.z);
height = value;
InternalIO.glfwSetWindowSize(this.canvasHandle, Width, Height);
}
}
@@ -107,24 +122,86 @@ namespace StgSharp.Graphics
internal set => sharedCanvas = value;
}
public vec2d Size
{
get => new vec2d(width, height);
internal set
{
height = (int)value.Y;
width = (int)value.X;
InternalIO.glfwSetWindowSize(this.canvasHandle, Width, Height);
}
}
public int Width
{
get => width;
internal set => width = value;
internal set
{
width = value;
InternalIO.glfwSetWindowSize(this.canvasHandle, Width, Height);
}
}
internal abstract void CreateCanvas(
(int width,int height,int depth) size, (int x_stretch,int y_stretch, int z_stretch) coordStrech, string name
);
/// <summary>
/// Set the size limit of current form
/// </summary>
/// <param name="minWidth">Minimum width of current form</param>
/// <param name="minHeight">Minimum height of current form</param>
/// <param name="maxWidth">Maximum width of current form</param>
/// <param name="maxHeight">Maximum height of current form</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public abstract void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight);
internal abstract void CreateCanvas();
#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{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.
/// </summary>
/// <param name="source">Shader using this camera</param>
/// <param name="name">Name of projection camera named in shader</param>
/// <returns>
/// <see cref="Uniform{T}"/>(T 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();
internal abstract void InternalInit();
internal abstract void InternalTerminate();
#endregion
#region public operation
protected abstract void Deinit();
protected abstract void Init();
protected abstract void Main();
protected abstract void Deinit();
protected abstract void ProcessInput();
#endregion
internal abstract void InternalInit();
internal abstract void InternalDraw();
internal abstract void InternalTerminate();
#region public resource generator
protected abstract Shader CreateShaderSegment(ShaderType type, int count);
protected abstract ShaderProgram CreateShaderProgram();
#endregion
}
public class RenderStreamConstructArgs
{
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; }
}
}
@@ -0,0 +1,187 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ShaderGenerator.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.Graphics;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.ShaderEdit
{
public class ShaderGenerator
{
private Dictionary<int,ShaderParameter> uniformDefine;
private List<string> codeList;
private List<ShaderFunction> usedShaderFunctions;
public Uniform<T> DefineUniform<T>(string name, int index) where T : struct
{
ShaderParameter p = new ShaderParameter(name,ShaderParameter.TypeMarshal<T>());
uniformDefine.Add(index,p);
//return new Uniform<T>();
throw new NotImplementedException();
}
}
public class ShaderFunction
{
private List<string> codeList;
private List<ShaderParameter> inputList;
private string name;
private ShaderParameter outPut;
public int ParameterCount => inputList.Count;
public void EmitCall(ShaderFunction function, ShaderParameter outPut, params ShaderParameter[] inputParams)
{
if (inputParams.Length != function.ParameterCount)
{
// Param list length not equal
throw new ArgumentException("Provided parameters does not match function's parameter list.");
}
if (!ShaderParameter.IsSameType(outPut, function.outPut))
{
// Type of returning value not qual
throw new Exception("Provided parameters does not match function's parameter list.");
}
for (int i = 0; i < inputParams.Length; i++)
{
if (!ShaderParameter.IsSameType(function.inputList[i], inputParams[i]))
{
// Input type not match
throw new Exception("Provided parameters does not match function's parameter list.");
}
}
string codeLine = string.Empty; // adding a line like " outvalue = Func(input1, input2,...); "
if (outPut != ShaderParameter.Void)
{
codeLine += $"{outPut.name} = ";
}
codeLine += $"{function.name}(";
foreach (ShaderParameter inputParam in inputParams)
{
codeLine += inputParam.name;
}
codeLine += ");\n";
codeList.Add(codeLine);
}
}
public class ShaderParameter
{
public static readonly ShaderParameter Void = new ShaderParameter(string.Empty, InternalShaderType.Void);
internal readonly bool isReadOnly;
internal readonly string name;
internal readonly InternalShaderType type;
public ShaderParameter(string name, InternalShaderType type)
{
this.name = name;
this.type = type;
isReadOnly = false;
}
public static bool IsSameType(ShaderParameter param1, ShaderParameter param2)
{
if (param1.type != InternalShaderType.Struct)
{
return param1.type == param2.type;
}
else
{
throw new Exception("Struct is currently not supported.");
}
}
public static InternalShaderType TypeMarshal<T>() where T : struct
{
switch (Type.GetTypeCode(typeof(T)))
{
case TypeCode.Single:
return InternalShaderType.Float;
case TypeCode.Double:
return InternalShaderType.Double;
case TypeCode.Int32:
return InternalShaderType.Int;
case TypeCode.UInt32:
return InternalShaderType.UInt;
default:
break;
}
switch (typeof(T).Name)
{
case "vec4d":
return InternalShaderType.Vector4;
case "Matrix2x2":
return InternalShaderType.Matrix2x2;
case "Matrix2x3":
return InternalShaderType.Matrix2x3;
case "Matrix2x4":
return InternalShaderType.Matrix2x4;
case "Matrix3x2":
return InternalShaderType.Matrix3x2;
case "Matrix3x3":
return InternalShaderType.Matrix3x3;
case "Matrix3x4":
return InternalShaderType.Matrix3x4;
case "Matrix4x2":
return InternalShaderType.Matrix4x2;
case "Matrix4x3":
return InternalShaderType.Matrix4x3;
case "Matrix4x4":
return InternalShaderType.Matrix4x4;
default:
throw new ArgumentException("Not supported shader data type.");
}
}
}
public enum InternalShaderType
{
#pragma warning disable CS1591
Struct, Void,
Int, UInt,
Float, Double,
Vector2, Vector3, Vector4,
VectorD2, VectorD3, VectorD4,
Matrix2x2, Matrix2x3, Matrix2x4,
Matrix3x2, Matrix3x3, Matrix3x4,
Matrix4x2, Matrix4x3, Matrix4x4,
#pragma warning restore CS1591
}
}
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.ShaderEdit
{
public class ShaderStructMember
{
internal InternalShaderType type;
internal object value;
}
public class ShaderStruct
{
internal Dictionary<glSHandle, ShaderStructMember> uniformPair;
public ShaderStruct(params (glSHandle, ShaderStructMember)[] UniformPais)
{
uniformPair = new Dictionary<glSHandle, ShaderStructMember>();
if (UniformPais.Length == 0)
{
return;
}
foreach (var item in UniformPais)
{
uniformPair.Add(item.Item1,item.Item2);
}
}
internal ShaderStruct() { }
public unsafe void SetAllUniforms()
{
GLcontext* gl = GL.api;
foreach (var uniform in uniformPair)
{
int id = uniform.Key.Value;
ShaderStructMember s = uniform.Value;
switch (s.type)
{
case InternalShaderType.Struct: throw new ArgumentException(
"Incorrect type \"Struct\" defined in this self define type");
case InternalShaderType.Void:throw new ArgumentException(
"Incorrect type \"Void\" defined in this self define type");
case InternalShaderType.Float:
gl->glUniform1f(id, (float)s.value);
break;
case InternalShaderType.Int:
gl->glUniform1f(id, (int)s.value);
break;
default:
throw new NotImplementedException();
throw new ArgumentException(
"Incorrect type \"Unknown\" defined in this self define type");
}
}
}
}
}
+60
View File
@@ -0,0 +1,60 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BluePaint.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.Logic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharpDebug.Logic
{
public class BluePaint
{
private bool running;
private List<BluePaintNode> allNode;
private BluePaintNode beginNode;
public bool IsRunning
{
get => running; set => running = value;
}
public void Start()
{
}
}
}
+114
View File
@@ -0,0 +1,114 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BluePaintNode.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 StgSharpDebug.Logic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Logic
{
public delegate void BluePaintNodeAction(
in Dictionary<string, BluePaintPipeline> inpput,
in Dictionary<string, BluePaintPipeline> output);
public abstract class BluePaintNode
{
private BluePaintNodeAction mainOperation;
private BluePaint local;
private bool survivalTask;
private Dictionary<string, BluePaintPipeline> inputInterfaces;
private Dictionary<string, BluePaintPipeline> outputInterface;
private string name;
private Task mainTask;
internal BluePaintNode(string name, bool isTaskSurvival)
{
this.name = name;
SurvivalTask = isTaskSurvival;
}
protected BluePaintNode(string name, BluePaintNodeAction operation)
{
this.name = name;
mainOperation = operation;
}
internal bool SurvivalTask
{
get; set;
}
public void Run()
{
if (survivalTask)
{
if (mainTask == null)
{
mainTask = new Task(
() =>
{
while (local.IsRunning)
{
mainOperation(in inputInterfaces, in outputInterface);
}
}
);
}
return;
}
}//--------------------------------- end of class -----------------------------
}
public class BluePaintPipeline
{
private Barrier formerCompleteBarrier;
private BluePaintPipelineArgs args;
public void CompleteAndWriteData(BluePaintPipelineArgs args)
{
formerCompleteBarrier.SignalAndWait();
}
}
public abstract class BluePaintPipelineArgs
{
}
}
+1 -2
View File
@@ -43,8 +43,7 @@ namespace StgSharp.Graphics
public sealed class Camera : IglConvertable
{
private Uniform<Matrix44> convertedUniform ;
internal Uniform<Matrix44> convertedUniform;
internal bool _isLookAtAvailable;
internal Matrix44 cameraAtt;
internal vec3d _target, up, cameraCoord;
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+32c0a0f99bffeed87de8eedfd6d8a27bbcc94012")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+dd6e8247bf5c1a1ddc9401e652ebeee72ff913e1")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/915a560b4309adf0aa201a011f972121196e6b02/*"}}
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/dd6e8247bf5c1a1ddc9401e652ebeee72ff913e1/*"}}