daily update on 20240528 by nitload youmu
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,51 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="BattleField.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.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
//TODO 这玩意如何加载一个渲染流程以获得各个图元还没搞清楚
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public class BattleField : ControllingItem
|
||||
{
|
||||
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public class CharacterLineIndexImage : ControllingItem
|
||||
{
|
||||
private int length;
|
||||
private char[] displayIndex;
|
||||
private char defaultChar;
|
||||
|
||||
Dictionary<char, PlainGeometryMesh> texIndex;
|
||||
|
||||
PlainGeometryMesh _tittleMesh;
|
||||
|
||||
public void Display(string message)
|
||||
{
|
||||
if (string.IsNullOrEmpty(message))
|
||||
{
|
||||
message = string.Empty;
|
||||
}
|
||||
|
||||
string result = message.Length >= length ?
|
||||
message.Substring(message.Length - displayIndex.Length) :
|
||||
message.PadLeft(length,defaultChar);
|
||||
|
||||
displayIndex = result.ToCharArray();
|
||||
}
|
||||
|
||||
|
||||
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
yield return _tittleMesh;
|
||||
foreach (char item in displayIndex)
|
||||
{
|
||||
yield return texIndex[item];
|
||||
}
|
||||
}
|
||||
|
||||
public CharacterLineIndexImage(
|
||||
int length, char defaultChar, PlainGeometryMesh tittleMesh,
|
||||
IEnumerable<(char, PlainGeometryMesh)> indexEnumeration)
|
||||
{
|
||||
this.length = length;
|
||||
displayIndex = new char[length];
|
||||
_tittleMesh = tittleMesh;
|
||||
texIndex = indexEnumeration.ToDictionary(item => item.Item1, item => item.Item2);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public abstract partial class ControllingItem: IEnumerable<PlainGeometryMesh>
|
||||
{
|
||||
public vec2d Position { get; set; }
|
||||
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public abstract IEnumerator<PlainGeometryMesh> GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using StgSharp.Controls;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public class DecorationBox : ControllingItem
|
||||
{
|
||||
private PlainGeometryMesh renderMesh;
|
||||
|
||||
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
yield return renderMesh;
|
||||
}
|
||||
|
||||
public DecorationBox(Rectangle bound, Image texture, vec2d[] texCoord)
|
||||
{
|
||||
renderMesh = new PlainGeometryMesh(BoundingBox, texture, texCoord);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="KeyboardButton.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.Controls;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public class KeyboardButton : ControllingItem
|
||||
{
|
||||
private PlainGeometryMesh current;
|
||||
private AnimationBuilder switchAnimationBuilder;
|
||||
|
||||
private Action? enableAction;
|
||||
private Action? disableAction;
|
||||
private Action? confirmAction;
|
||||
|
||||
public bool IsHighLighted { get; internal set; }
|
||||
public bool IsDisabled { get; internal set; }
|
||||
|
||||
public event Action EnableEvent
|
||||
{
|
||||
add { enableAction += value; }
|
||||
remove { enableAction -= value; }
|
||||
}
|
||||
|
||||
public event Action DisableEvent
|
||||
{
|
||||
add { disableAction += value; }
|
||||
remove { disableAction -= value; }
|
||||
}
|
||||
|
||||
public event Action ConfirmEvent
|
||||
{
|
||||
add { confirmAction += value; }
|
||||
remove { confirmAction -= value; }
|
||||
}
|
||||
|
||||
public void Enable(AnimationBuilder animation)
|
||||
{
|
||||
if (!IsDisabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (switchAnimationBuilder.IsComplete || switchAnimationBuilder == null)
|
||||
{
|
||||
switchAnimationBuilder = animation;
|
||||
}
|
||||
if( enableAction != null)enableAction();
|
||||
}
|
||||
|
||||
public void Disable(AnimationBuilder animation)
|
||||
{
|
||||
if (switchAnimationBuilder.IsComplete || switchAnimationBuilder == null)
|
||||
{
|
||||
switchAnimationBuilder = animation;
|
||||
}
|
||||
if (disableAction != null) disableAction();
|
||||
}
|
||||
|
||||
public void Highlight(AnimationBuilder animation)
|
||||
{
|
||||
if (switchAnimationBuilder.IsComplete || switchAnimationBuilder == null)
|
||||
{
|
||||
switchAnimationBuilder = animation;
|
||||
}
|
||||
if (confirmAction != null) confirmAction();
|
||||
}
|
||||
|
||||
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
current.Texture = switchAnimationBuilder.GetAnimationFrame();
|
||||
yield return current;
|
||||
}
|
||||
|
||||
}//----------------------------------- End of class --------------------------------------------
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using StgSharp.Controls;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controlling.Controls
|
||||
{
|
||||
public class MarkingLabel : ControllingItem
|
||||
{
|
||||
public vec2d Position { get; set; }
|
||||
|
||||
private vec2d _currentPosition, _movementVec;
|
||||
|
||||
private TimeFunction _movement;
|
||||
private PlainGeometryMesh marker;
|
||||
|
||||
public void MoveTo(vec2d target)
|
||||
{
|
||||
Move(target - Position);
|
||||
}
|
||||
|
||||
public void Move(vec2d movement)
|
||||
{
|
||||
if (!_movement.IsComplete)
|
||||
{
|
||||
Position = _currentPosition + _movement.Calculate() * _movementVec;
|
||||
}
|
||||
}
|
||||
|
||||
public MarkingLabel(PlainGeometryMesh marker, TimeFunction movement)
|
||||
{
|
||||
this.marker = marker;
|
||||
_movement = movement;
|
||||
}
|
||||
|
||||
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using StgSharp.Controls;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class ViewDesigner
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
}//---------------------------------- End of Class -----------------------------------------
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Get.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.Logic;
|
||||
using StgSharp.Math;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public partial class ViewModel
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Get the status of a certain key on the keyboard.
|
||||
/// </summary>
|
||||
/// <param name="form"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static KeyStatus GetKeyStatus(ViewModel form, KeyboardKey key)
|
||||
{
|
||||
return InternalIO.glfwGetKey(form.id, (int)key);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,155 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="InternalIO.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.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.GL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
|
||||
#if Windows
|
||||
|
||||
#endif
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public enum LogType
|
||||
{
|
||||
Error,
|
||||
Warning,
|
||||
Info,
|
||||
InfoError,
|
||||
InfoWarning,
|
||||
}
|
||||
|
||||
internal static unsafe partial class InternalIO
|
||||
{
|
||||
internal const string SS_errorLog =
|
||||
"SS_errorlog.log";
|
||||
|
||||
internal const string SSC_libName =
|
||||
"StgSharpC";
|
||||
|
||||
internal static Dictionary<TypeCode, uint> GLtype =
|
||||
new Dictionary<TypeCode, uint>();
|
||||
|
||||
internal static SemaphoreSlim logSyncSemaphore = new SemaphoreSlim(1, 1);
|
||||
|
||||
internal static readonly GCHandle ssc_logHandle =
|
||||
GCHandle.Alloc(new byte[512], GCHandleType.Pinned);
|
||||
|
||||
internal static IntPtr SSClibPtr = IntPtr.Zero;
|
||||
|
||||
static InternalIO()
|
||||
{
|
||||
GLtype.Add(TypeCode.Single, GLconst.FLOAT);
|
||||
GLtype.Add(TypeCode.Int32, GLconst.INT);
|
||||
GLtype.Add(TypeCode.UInt32, GLconst.UNSIGNED_INT);
|
||||
GLtype.Add(TypeCode.Int16, GLconst.SHORT);
|
||||
GLtype.Add(TypeCode.UInt16, GLconst.UNSIGNED_SHORT);
|
||||
GLtype.Add(TypeCode.SByte, GLconst.BYTE);
|
||||
GLtype.Add(TypeCode.Byte, GLconst.UNSIGNED_BYTE);
|
||||
}
|
||||
|
||||
internal static void InternalAppendLog(string log)
|
||||
{
|
||||
if (!File.Exists(SS_errorLog))
|
||||
{
|
||||
FileStream stream = File.Create(SS_errorLog);
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
using (StreamWriter logStream = File.AppendText(SS_errorLog))
|
||||
{
|
||||
logStream.WriteLine(log);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Not completed", true)]
|
||||
internal static IntPtr InternalLoadProc<T>(IntPtr lib, string name) where T : Delegate
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr procPtr =
|
||||
#if Windows
|
||||
IntPtr.Zero;
|
||||
#elif Linux
|
||||
|
||||
#endif
|
||||
return procPtr;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void InternalWriteLog(string logLine, LogType logType)
|
||||
{
|
||||
logSyncSemaphore.Wait();
|
||||
if (!File.Exists(SS_errorLog))
|
||||
{
|
||||
FileStream stream = File.Create(SS_errorLog);
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
using (StreamWriter logStream = File.AppendText(SS_errorLog))
|
||||
{
|
||||
logStream.WriteLine($"{logType}\t{DateTime.Now.ToString("o")}");
|
||||
logStream.WriteLine(logLine);
|
||||
}
|
||||
logSyncSemaphore.Release();
|
||||
}
|
||||
|
||||
internal static void InternalWriteLog(string beforeTime, string logLine, LogType logType)
|
||||
{
|
||||
logSyncSemaphore.Wait();
|
||||
if (!File.Exists(InternalIO.SS_errorLog))
|
||||
{
|
||||
FileStream stream = File.Create(InternalIO.SS_errorLog);
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
using (StreamWriter logStream = File.AppendText(SS_errorLog))
|
||||
{
|
||||
logStream.WriteLine(beforeTime);
|
||||
logStream.WriteLine($"{logType}\t@\t{DateTime.Now.ToString("o")}");
|
||||
logStream.WriteLine(logLine);
|
||||
}
|
||||
logSyncSemaphore.Release(1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="KeyControl.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 System;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public enum KeyboardKey : int
|
||||
{
|
||||
UNKNOWN = -1,
|
||||
None = 0,
|
||||
SPACE = 32,
|
||||
APOSTROPHE = 39/*'*/,
|
||||
COMMA = 44/*,*/,
|
||||
MINUS = 45/*-*/,
|
||||
PERIOD = 46/*.*/,
|
||||
SLASH = 47/*/*/,
|
||||
ZERO = 48,
|
||||
ONE = 49,
|
||||
TWO = 50,
|
||||
THREE = 51,
|
||||
FOUR = 52,
|
||||
FIVE = 53,
|
||||
SIX = 54,
|
||||
SEVEN = 55,
|
||||
EIGHT = 56,
|
||||
NINE = 57,
|
||||
SEMICOLON = 59/*,*/,
|
||||
EQUAL = 61/*=*/,
|
||||
A = 65,
|
||||
B = 66,
|
||||
C = 67,
|
||||
D = 68,
|
||||
E = 69,
|
||||
F = 70,
|
||||
G = 71,
|
||||
H = 72,
|
||||
I = 73,
|
||||
J = 74,
|
||||
K = 75,
|
||||
L = 76,
|
||||
M = 77,
|
||||
N = 78,
|
||||
O = 79,
|
||||
P = 80,
|
||||
Q = 81,
|
||||
R = 82,
|
||||
S = 83,
|
||||
T = 84,
|
||||
U = 85,
|
||||
V = 86,
|
||||
W = 87,
|
||||
X = 88,
|
||||
Y = 89,
|
||||
Z = 90,
|
||||
LeftBracket = 91/*[*/,
|
||||
BACKSLASH = 92/*\*/,
|
||||
RightBracket = 93/*]*/,
|
||||
GraveAccent = 96/*`*/,
|
||||
World1 = 161/*non-US#1*/,
|
||||
World2 = 162/*non-US#2*/,
|
||||
ESCAPE = 256,
|
||||
ENTER = 257,
|
||||
TAB = 258,
|
||||
BACKSPACE = 259,
|
||||
INSERT = 260,
|
||||
DELETE = 261,
|
||||
RIGHT = 262,
|
||||
LEFT = 263,
|
||||
DOWN = 264,
|
||||
UP = 265,
|
||||
PgUp = 266,
|
||||
PgDown = 267,
|
||||
HOME = 268,
|
||||
END = 269,
|
||||
CapsLock = 280,
|
||||
ScrollLock = 281,
|
||||
NumLock = 282,
|
||||
PrintScreen = 283,
|
||||
PAUSE = 284,
|
||||
F1 = 290,
|
||||
F2 = 291,
|
||||
F3 = 292,
|
||||
F4 = 293,
|
||||
F5 = 294,
|
||||
F6 = 295,
|
||||
F7 = 296,
|
||||
F8 = 297,
|
||||
F9 = 298,
|
||||
F10 = 299,
|
||||
F11 = 300,
|
||||
F12 = 301,
|
||||
F13 = 302,
|
||||
F14 = 303,
|
||||
F15 = 304,
|
||||
F16 = 305,
|
||||
F17 = 306,
|
||||
F18 = 307,
|
||||
F19 = 308,
|
||||
F20 = 309,
|
||||
F21 = 310,
|
||||
F22 = 311,
|
||||
F23 = 312,
|
||||
F24 = 313,
|
||||
F25 = 314,
|
||||
NumPad0 = 320,
|
||||
NumPad1 = 321,
|
||||
NumPad2 = 322,
|
||||
NumPad3 = 323,
|
||||
NumPad4 = 324,
|
||||
NumPad5 = 325,
|
||||
NumPad6 = 326,
|
||||
NumPad7 = 327,
|
||||
NumPad8 = 328,
|
||||
NumPad9 = 329,
|
||||
NumPadDec = 330,
|
||||
NumPadSiv = 331,
|
||||
NumPadMul = 332,
|
||||
NumPadSub = 333,
|
||||
NumPadAdd = 334,
|
||||
NumPadAnter = 335,
|
||||
NumPadEqual = 336,
|
||||
LeftShift = 340,
|
||||
LeftControl = 341,
|
||||
LeftAlt = 342,
|
||||
LeftSuper = 343,
|
||||
RightShift = 344,
|
||||
RightControl = 345,
|
||||
RightAlt = 346,
|
||||
RightSuper = 347,
|
||||
Menu = 348
|
||||
}
|
||||
|
||||
#pragma warning disable CA1707
|
||||
#pragma warning disable CA1712
|
||||
#pragma warning disable CA1008
|
||||
[System.Flags]
|
||||
public enum Joystick : int
|
||||
{
|
||||
JOYSTICK_1 = 0,
|
||||
JOYSTICK_2 = 1,
|
||||
JOYSTICK_3 = 2,
|
||||
JOYSTICK_4 = 3,
|
||||
JOYSTICK_5 = 4,
|
||||
JOYSTICK_6 = 5,
|
||||
JOYSTICK_7 = 6,
|
||||
JOYSTICK_8 = 7,
|
||||
JOYSTICK_9 = 8,
|
||||
JOYSTICK_10 = 9,
|
||||
JOYSTICK_11 = 10,
|
||||
JOYSTICK_12 = 11,
|
||||
JOYSTICK_13 = 12,
|
||||
JOYSTICK_14 = 13,
|
||||
JOYSTICK_15 = 14,
|
||||
JOYSTICK_16 = 15,
|
||||
JOYSTICK_LAST = JOYSTICK_16
|
||||
}
|
||||
|
||||
[System.Flags]
|
||||
public enum Mouse : int
|
||||
{
|
||||
BUTTON_1 = 0,
|
||||
BUTTON_2 = 1,
|
||||
BUTTON_3 = 2,
|
||||
BUTTON_4 = 3,
|
||||
BUTTON_5 = 4,
|
||||
BUTTON_6 = 5,
|
||||
BUTTON_7 = 6,
|
||||
BUTTON_8 = 7,
|
||||
BUTTON_LAST = BUTTON_8,
|
||||
BUTTON_LEFT = BUTTON_1,
|
||||
BUTTON_RIGHT = BUTTON_2,
|
||||
BUTTON_MIDDLE = BUTTON_3
|
||||
}
|
||||
#pragma warning restore CA1707
|
||||
#pragma warning restore CA1712
|
||||
#pragma warning restore CA7008
|
||||
|
||||
internal enum InputEquipment
|
||||
{
|
||||
Keyboard,
|
||||
Mouse,
|
||||
Joystick
|
||||
}
|
||||
|
||||
public enum KeyStatus : int
|
||||
{
|
||||
RELEASE = 0,
|
||||
PRESS = 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
[AttributeUsage( AttributeTargets.Method)]
|
||||
public class KeyEventAttribute:Attribute
|
||||
{
|
||||
internal int _keyTarget;
|
||||
internal int _equipment;
|
||||
internal int _keyStat;
|
||||
|
||||
public KeyEventAttribute(KeyboardKey key ,KeyStatus status)
|
||||
{
|
||||
_equipment = (int)InputEquipment.Keyboard;
|
||||
_keyTarget = (int)key;
|
||||
_keyStat = (int)status;
|
||||
}
|
||||
|
||||
public KeyEventAttribute(Joystick joystick, KeyStatus status)
|
||||
{
|
||||
_equipment = (int)InputEquipment.Keyboard;
|
||||
_keyTarget = (int)joystick;
|
||||
_keyStat = (int)status;
|
||||
}
|
||||
|
||||
public KeyEventAttribute(Mouse mouse, KeyStatus status)
|
||||
{
|
||||
_equipment = (int)InputEquipment.Keyboard;
|
||||
_keyTarget = (int)mouse;
|
||||
_keyStat = (int)status;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
|
||||
|
||||
public partial class ViewModel
|
||||
{
|
||||
Dictionary<KeyboardKey, KeyBoardEvent> keyEventDictionary = new Dictionary<KeyboardKey, KeyBoardEvent>();
|
||||
|
||||
internal void InternalLoadInput(MethodInfo[] methods)
|
||||
{
|
||||
if (methods.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (MethodInfo m in methods) //find all methods decorated by RenderActivityAttribute
|
||||
{
|
||||
KeyEventAttribute attr = m.GetCustomAttribute<KeyEventAttribute>(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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void InternalProcessInput()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public delegate void KeyBoardEvent(KeyboardKey key, KeyStatus status);
|
||||
public delegate void MouseEvent(Mouse mouse, KeyStatus status);
|
||||
public delegate void JoystickEvent(Joystick joystick, KeyStatus status);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using StgSharp;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal partial class InternalIO
|
||||
{
|
||||
internal const string CollisionTextureVertexShader ="#version 430 core\r\n\r\nlayout(location = 0) in vec2 localCollisionCoord;\r\nlayout(location = 1) in vec2 spaceCoord;\r\nlayout(location = 2) in float rotation;\r\nlayout(location = 3) in float scaling;\r\n\r\nuniform vec2 target;\r\nuniform mat2 projection;\r\n\r\nvoid main()\r\n{\r\n mat2 scaling = mat2(\r\n scaling,0,\r\n 0,scaling\r\n );\r\n mat2 rotation = mat2(\r\n cos(rotation),-sin(rotation),\r\n sin(rotation),cos(rotation) \r\n );\r\n vec2 realCoord = (rotation * scaling * localCollisionCoord) + spaceCoord - target;\r\n realCoord = projection * realCoord;\r\n\r\n float dist = distance(realCoord, vec2(0,0));\r\n float angle = atan(realCoord.y, realCoord.x);\r\n \r\n gl_Position = vec4(angle, realCoord.y, dist, 1);\r\n}";
|
||||
internal const string CollisionTextureFragmentShader = "#version 430 core\r\n\r\nout vec4 Color;\r\n\r\nuniform float range;\r\n\r\nvoid main()\r\n{\r\n float dist = gl_FragCoord.z;\r\n\r\n if(dist > range)\r\n {\r\n discard;\r\n }\r\n dist /= range;\r\n gl_FragDepth = min(dist, gl_FragDepth);\r\n\r\n Color = vec4(dist,0,0,1);\r\n}";
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Controlling;
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -67,11 +67,6 @@ namespace StgSharp.Entities
|
||||
new NotImplementedException();
|
||||
}
|
||||
|
||||
internal void InternalDieOperation(Control home)
|
||||
{
|
||||
_dieBulletLauncher.Launch();
|
||||
_awardLauncher.Launch();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Controlling;
|
||||
|
||||
|
||||
namespace StgSharp.Entities
|
||||
{
|
||||
@@ -49,11 +49,6 @@ namespace StgSharp.Entities
|
||||
CommonBulletLauncher.Launch();
|
||||
}
|
||||
|
||||
internal void InternalDieOperation(Control home)
|
||||
{
|
||||
_dieBulletLauncher.Launch();
|
||||
_awardLauncher.Launch();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace StgSharp
|
||||
/// </summary>
|
||||
public vec2d Location { get; }
|
||||
|
||||
public string Texture { get; set; }
|
||||
public string TextureGL { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// X position of an enenmy entity
|
||||
|
||||
@@ -64,6 +64,8 @@ namespace StgSharp
|
||||
VK
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static partial class StgSharp
|
||||
{
|
||||
|
||||
@@ -89,6 +91,25 @@ namespace StgSharp
|
||||
LogType.Info);
|
||||
}
|
||||
|
||||
public static void LogError(Exception ex)
|
||||
{
|
||||
InternalIO.InternalWriteLog(ex.Message, LogType.Error);
|
||||
}
|
||||
|
||||
public static void LogWarning(string log)
|
||||
{
|
||||
InternalIO.InternalWriteLog(log, LogType.Warning);
|
||||
}
|
||||
public static void LogWarning(Exception notVerySeriesException)
|
||||
{
|
||||
InternalIO.InternalWriteLog(notVerySeriesException.Message, LogType.Warning);
|
||||
}
|
||||
|
||||
public static void LogInfo(string log)
|
||||
{
|
||||
InternalIO.InternalWriteLog(log, LogType.Info);
|
||||
}
|
||||
|
||||
public static void Mark(bool needConsole)
|
||||
{
|
||||
markCount++;
|
||||
@@ -134,7 +155,7 @@ namespace StgSharp
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a log message to log file, and mark the level of this message.
|
||||
/// Write a log message to log file, and mark the _level of this message.
|
||||
/// </summary>
|
||||
/// <param name="message">A string contains information of how current evironment runs.</param>
|
||||
/// <param name="logType">The severity of current message.</param>
|
||||
|
||||
@@ -55,18 +55,5 @@ namespace StgSharp.Geometries
|
||||
get => ref coordMat;
|
||||
}
|
||||
|
||||
//TODO 几何体构建器需要重写
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +104,12 @@ namespace StgSharp.Math
|
||||
return new Radius(left._radius - Right._radius);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float operator /(Radius left, Radius right)
|
||||
{
|
||||
return left._radius / right._radius;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Radius operator +(Radius left, Radius Right)
|
||||
{
|
||||
|
||||
@@ -53,14 +53,17 @@ namespace StgSharp.Geometries
|
||||
get;
|
||||
}
|
||||
|
||||
#pragma warning disable CA1819
|
||||
public vec4d[] VertexStream
|
||||
#pragma warning restore CA1819
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public void GetVertexHandle(ICoord coordinate, int count);
|
||||
|
||||
public void Transform(Matrix44 transFormMatrix);
|
||||
public ReadOnlySpan<int> VertexIndices
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="IInstancing.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.Linq;
|
||||
using System.Numerics;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public interface IInstancing
|
||||
{
|
||||
|
||||
public int BufferId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public vec3d CenterPositionGlobal
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public vec3d Coord
|
||||
{
|
||||
get { return GlobalBuffer.CoordAndRotationList[BufferId].XYZ; }
|
||||
set { GlobalBuffer.CoordAndRotationList[BufferId] = new vec4d(value.vec); }
|
||||
}
|
||||
|
||||
public IInstancingBuffer GlobalBuffer
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public float Rotation
|
||||
{
|
||||
get { return GlobalBuffer.CoordAndRotationList[BufferId].W; }
|
||||
set
|
||||
{
|
||||
vec4d temp = GlobalBuffer.CoordAndRotationList[BufferId];
|
||||
temp.W = value;
|
||||
GlobalBuffer.CoordAndRotationList[BufferId] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
public float Scale
|
||||
{
|
||||
get { return GlobalBuffer.ScalingList[BufferId]; }
|
||||
set { GlobalBuffer.ScalingList[BufferId] = value; }
|
||||
}
|
||||
|
||||
public GeometryMotion Motion
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public void Move()
|
||||
{
|
||||
(vec3d coord, float rotation) = (Coord, Rotation);
|
||||
Motion.RunMotion(ref coord, ref rotation);
|
||||
(Coord, Rotation) = (coord, rotation);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public interface IInstancingBuffer
|
||||
{
|
||||
|
||||
internal IGeometry TypicalShape { get; }
|
||||
|
||||
internal List<IInstancing> InstanceList { get; }
|
||||
|
||||
internal List<vec4d> CoordAndRotationList { get; }
|
||||
|
||||
internal List<float> ScalingList { get; }
|
||||
|
||||
public Span<vec4d> CoordAndRotationSpan { get; }
|
||||
|
||||
public Span<float> ScalingSpan { get; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,6 @@ namespace StgSharp.Geometries
|
||||
public vec2d CenterPosition { get; set; }
|
||||
|
||||
public bool CollideWith(IPlainEntity entity);
|
||||
|
||||
}
|
||||
|
||||
public class PlainEntity:IPlainEntity
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="IInstancing.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.Linq;
|
||||
using System.Numerics;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class ParticleOnPlain : IInstancing, IPlainEntity
|
||||
{
|
||||
|
||||
public ParticleOnPlain(PlainInstancingBuffer<ParticleOnPlain> buffer)
|
||||
{
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new ArgumentNullException(paramName: nameof(buffer));
|
||||
}
|
||||
GlobalBuffer = buffer;
|
||||
BufferId = buffer.CreateInstanceID();
|
||||
((IInstancingBuffer)buffer).InstanceList.Add(this);
|
||||
}
|
||||
|
||||
public int BufferId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public IInstancingBuffer GlobalBuffer
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public GeometryMotion Motion
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
vec3d IInstancing.CenterPositionGlobal
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
vec2d IPlainEntity.CenterPosition { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
bool IPlainEntity.CollideWith(IPlainEntity entity)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,68 +32,39 @@ using StgSharp.Graphics;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
/// <summary>
|
||||
/// 平面几何体。包含三角形,对称四边形,自由多边形等。最多可由16个点参数定义。
|
||||
/// Plain geometry only contains straight sides.
|
||||
/// </summary>
|
||||
public abstract class PlainGeometry : IGeometry
|
||||
{
|
||||
|
||||
protected TimeSpanProvider time;
|
||||
|
||||
protected vec4d[] vertexMat;
|
||||
internal ICoord coordinate;
|
||||
|
||||
public static int VertexCount { get; }
|
||||
|
||||
public PlainGeometry()
|
||||
{
|
||||
}
|
||||
|
||||
vec4d IGeometry.this[int index]
|
||||
public vec4d this[int index]
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
set => throw new NotImplementedException();
|
||||
get => vertexMat[index];
|
||||
set => vertexMat[index] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tick time this geometry eas crested
|
||||
/// </summary>
|
||||
public int BornTime => time;
|
||||
|
||||
public ICoord ReferenceCoordinate => this.coordinate;
|
||||
|
||||
internal abstract int[] Indices { get; }
|
||||
public int VertexCount => this.vertexMat.Length;
|
||||
|
||||
int IGeometry.VertexCount => throw new NotImplementedException();
|
||||
public abstract ReadOnlySpan<int> VertexIndices { get; }
|
||||
|
||||
vec4d[] IGeometry.VertexStream => throw new NotImplementedException();
|
||||
#pragma warning disable CA1819
|
||||
public vec4d[] VertexStream => vertexMat;
|
||||
#pragma warning restore CA1819
|
||||
|
||||
/// <summary>
|
||||
/// Get all sides of this <see cref="PlainGeometry"/>.
|
||||
/// </summary>
|
||||
/// <returns>A array contains all straight <see cref="Line"/>s of current geometry item.</returns>
|
||||
public abstract Line[] GetAllSides();
|
||||
|
||||
/// <summary>
|
||||
/// Get a flat <see cref="Plain"/> coincide with current geometry.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public abstract Plain GetPlain();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -44,12 +44,15 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class PlainInstancingBuffer<T> : IDisposable,IEnumerable<T> where T : IInstancing<T>
|
||||
public class PlainInstancingBuffer<T> :
|
||||
IDisposable,IEnumerable<T>, IInstancingBuffer
|
||||
where T :
|
||||
IInstancing
|
||||
{
|
||||
|
||||
private CoordinatePlain globalCorrdinnate;
|
||||
private List<vec4d> coordList;
|
||||
private List<IInstancing<T>> instanceList;
|
||||
private List<IInstancing> instanceList;
|
||||
private List<float> scalingList;
|
||||
private Mutex mutex;
|
||||
private bool disposedValue;
|
||||
@@ -64,29 +67,29 @@ namespace StgSharp.Geometries
|
||||
public PlainInstancingBuffer()
|
||||
{
|
||||
coordList = new List<vec4d>(capacity: 100);
|
||||
instanceList = new List<IInstancing<T>>(capacity:100);
|
||||
instanceList = new List<IInstancing>(capacity:100);
|
||||
scalingList = new List<float>(capacity: 100);
|
||||
coordArray = new vec4d[0];
|
||||
scaleArray = new float[0];
|
||||
coordArray = Array.Empty<vec4d>();
|
||||
scaleArray = Array.Empty<float>();
|
||||
mutex = new Mutex();
|
||||
}
|
||||
|
||||
internal List<IInstancing<T>> InstanceList
|
||||
List<IInstancing> IInstancingBuffer.InstanceList
|
||||
{
|
||||
get => instanceList;
|
||||
}
|
||||
|
||||
internal List<vec4d> CoordList
|
||||
List<vec4d> IInstancingBuffer.CoordAndRotationList
|
||||
{
|
||||
get => coordList;
|
||||
}
|
||||
|
||||
internal List<float> ScalingList
|
||||
List<float> IInstancingBuffer.ScalingList
|
||||
{
|
||||
get => scalingList;
|
||||
}
|
||||
|
||||
public Span<vec4d> CoordSpan
|
||||
public Span<vec4d> CoordAndRotationSpan
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -96,7 +99,11 @@ namespace StgSharp.Geometries
|
||||
GetField("_items", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (fieldInfo == null)
|
||||
{
|
||||
#pragma warning disable CA1065
|
||||
#pragma warning disable CA2201
|
||||
throw new NullReferenceException();
|
||||
#pragma warning restore CA2201
|
||||
#pragma warning restore CA1065
|
||||
}
|
||||
coordArray = (vec4d[])fieldInfo.GetValue(coordList);
|
||||
}
|
||||
@@ -114,7 +121,11 @@ namespace StgSharp.Geometries
|
||||
GetField("_items", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (fieldInfo == null)
|
||||
{
|
||||
#pragma warning disable CA1065
|
||||
#pragma warning disable CA2201
|
||||
throw new NullReferenceException();
|
||||
#pragma warning restore CA2201
|
||||
#pragma warning restore CA1065
|
||||
}
|
||||
scaleArray = (float[])fieldInfo.GetValue(scalingList);
|
||||
}
|
||||
@@ -122,6 +133,8 @@ namespace StgSharp.Geometries
|
||||
}
|
||||
}
|
||||
|
||||
IGeometry IInstancingBuffer.TypicalShape => throw new NotImplementedException();
|
||||
|
||||
public int CreateInstanceID()
|
||||
{
|
||||
mutex.WaitOne();
|
||||
@@ -142,7 +155,7 @@ namespace StgSharp.Geometries
|
||||
paramName: nameof(instance));
|
||||
}
|
||||
int index = instance.BufferId;
|
||||
IInstancing<T> temp = instanceList[instanceList.Count - 1];
|
||||
IInstancing temp = instanceList[instanceList.Count - 1];
|
||||
instanceList[instance.BufferId] = temp;
|
||||
temp.BufferId = instance.BufferId;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Controlling;
|
||||
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -56,48 +56,14 @@ namespace StgSharp.Geometries
|
||||
)
|
||||
{
|
||||
if (
|
||||
vertexMat.colum0 + vertexMat.colum2 !=
|
||||
vertexMat.colum1 + vertexMat.colum3
|
||||
this[0] + this[2] !=
|
||||
this[1] + this[3]
|
||||
)
|
||||
{
|
||||
InternalIO.InternalWriteLog("Init of geometry item failed, because four vertices cannot form a rectangle.", LogType.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
public Func<int,vec3d> MovCenterOperation => movCenterOperation;
|
||||
public Func<int,vec3d> MovVertex01Operation => moveVertex0Operation;
|
||||
public Func<int,vec3d> MovVertex02Operation => moveVertex1Operation;
|
||||
|
||||
public virtual vec3d MovCenter(int tick)
|
||||
{
|
||||
return movCenterOperation.Invoke(tick);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move the third vertex. this is a useless method for Parallelograms.
|
||||
/// </summary>
|
||||
/// <param name="tick">Current time tick</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UnusedVertexException">Geometry over defined</exception>
|
||||
public override sealed vec3d MoveVertex2(int tick)
|
||||
{
|
||||
throw new UnusedVertexException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move the third vertex. This method is useless for Parallelograms.
|
||||
/// </summary>
|
||||
/// <param name="tick">Current time tick</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UnusedVertexException">Geometry over defined</exception>
|
||||
public override sealed vec3d MoveVertex3(int tick)
|
||||
{
|
||||
throw new UnusedVertexException();
|
||||
}
|
||||
|
||||
internal override sealed void UpdateCoordinate(int tick)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,11 +92,6 @@ namespace StgSharp.Geometries
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool IsOnPlain(PlainGeometry geo)
|
||||
{
|
||||
return position * geo.GetPlain().plainParameter == 1;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Update the coordinate of the point. If this is a moving point,
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Controlling;
|
||||
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -38,41 +38,35 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
public class Polygon4 : PlainGeometry
|
||||
{
|
||||
|
||||
internal readonly Func<int,vec3d> moveVertex0Operation = GeometryOperation.DefaultMotion;
|
||||
internal readonly Func<int,vec3d> moveVertex1Operation = GeometryOperation.DefaultMotion;
|
||||
internal readonly Func<int,vec3d> moveVertex2Operation = GeometryOperation.DefaultMotion;
|
||||
internal readonly Func<int,vec3d> moveVertex3Operation = GeometryOperation.DefaultMotion;
|
||||
|
||||
internal Mat4 vertexMat;
|
||||
protected static int[] Indices = [0, 1, 2, 0, 2, 3];
|
||||
|
||||
internal Polygon4()
|
||||
{
|
||||
}
|
||||
|
||||
public Polygon4(ICoord coordinate,
|
||||
vec2d topLeft,
|
||||
vec2d topRight,
|
||||
vec2d bottomRight,
|
||||
vec2d bottomLeft
|
||||
vec3d topLeft,
|
||||
vec3d topRight,
|
||||
vec3d bottomRight,
|
||||
vec3d bottomLeft
|
||||
)
|
||||
{
|
||||
this.coordinate = coordinate;
|
||||
vertexMat.colum0 = topLeft.vec;
|
||||
vertexMat.colum1 = topRight.vec;
|
||||
vertexMat.colum2 = bottomRight.vec;
|
||||
vertexMat.colum3 = bottomLeft.vec;
|
||||
this[0] = new vec4d(topLeft.vec);
|
||||
this[1] = new vec4d(topRight.vec);
|
||||
this[2] = new vec4d(bottomRight.vec);
|
||||
this[3] = new vec4d(bottomLeft.vec);
|
||||
|
||||
Vector4 maxCoord = vertexMat.colum0;
|
||||
Vector4 minCoord = vertexMat.colum0;
|
||||
Vector4 maxCoord = this[0].vec;
|
||||
Vector4 minCoord = this[0].vec;
|
||||
|
||||
maxCoord = Vector4.Max(maxCoord, vertexMat.colum1);
|
||||
maxCoord = Vector4.Max(maxCoord, vertexMat.colum2);
|
||||
maxCoord = Vector4.Max(maxCoord, vertexMat.colum3);
|
||||
maxCoord = Vector4.Max(maxCoord, this[1].vec);
|
||||
maxCoord = Vector4.Max(maxCoord, this[2].vec);
|
||||
maxCoord = Vector4.Max(maxCoord, this[3].vec);
|
||||
|
||||
minCoord = Vector4.Min(minCoord, vertexMat.colum1);
|
||||
minCoord = Vector4.Min(minCoord, vertexMat.colum2);
|
||||
minCoord = Vector4.Min(minCoord, vertexMat.colum3);
|
||||
minCoord = Vector4.Min(minCoord, this[1].vec);
|
||||
minCoord = Vector4.Min(minCoord, this[2].vec);
|
||||
minCoord = Vector4.Min(minCoord, this[3].vec);
|
||||
}
|
||||
|
||||
public Polygon4(
|
||||
@@ -82,92 +76,15 @@ namespace StgSharp.Geometries
|
||||
float v3x, float v3y, float v3z
|
||||
)
|
||||
{
|
||||
vertexMat.colum0 = new Vector4(v0x, v0y, v0z, 0);
|
||||
vertexMat.colum1 = new Vector4(v1x, v1y, v1z, 0);
|
||||
vertexMat.colum2 = new Vector4(v2x, v2y, v2z, 0);
|
||||
vertexMat.colum3 = new Vector4(v3x, v3y, v3z, 0);
|
||||
vertexMat = new vec4d[4];
|
||||
|
||||
this[0] = new vec4d(v0x, v0y, v0z, 0);
|
||||
this[1] = new vec4d(v1x, v1y, v1z, 0);
|
||||
this[2] = new vec4d(v2x, v2y, v2z, 0);
|
||||
this[3] = new vec4d(v3x, v3y, v3z, 0);
|
||||
}
|
||||
|
||||
public Func<int,vec3d> MovVertex0Operation => moveVertex0Operation;
|
||||
public Func<int,vec3d> MovVertex1Operation => moveVertex1Operation;
|
||||
public Func<int,vec3d> MovVertex2Operation => moveVertex2Operation;
|
||||
public Func<int,vec3d> MovVertex3Operation => moveVertex3Operation;
|
||||
|
||||
public Point Vertex0
|
||||
{
|
||||
get => new Point(vertexMat.colum0);
|
||||
set => vertexMat.colum0 = value.position.vec;
|
||||
}
|
||||
|
||||
public Point Vertex1
|
||||
{
|
||||
get => new Point(vertexMat.colum1);
|
||||
set => vertexMat.colum1 = value.position.vec;
|
||||
}
|
||||
|
||||
public Point Vertex2
|
||||
{
|
||||
get => new Point(vertexMat.colum2);
|
||||
set => vertexMat.colum1 = value.position.vec;
|
||||
}
|
||||
|
||||
public Mat4 VertexBuffer => vertexMat;
|
||||
|
||||
|
||||
|
||||
internal override sealed int[] Indices => new int[6] { 0, 1, 2, 0, 2, 3 };
|
||||
|
||||
internal Point Vertex3
|
||||
{
|
||||
get => new Point(vertexMat.colum3);
|
||||
set => vertexMat.colum1 = value.position.vec;
|
||||
}
|
||||
|
||||
|
||||
public override Line[] GetAllSides()
|
||||
{
|
||||
Line[] sides =
|
||||
[
|
||||
new Line(Vertex0, Vertex1),
|
||||
new Line(Vertex1, Vertex2),
|
||||
new Line(Vertex2, Vertex3),
|
||||
new Line(Vertex3, Vertex0)
|
||||
];
|
||||
|
||||
return sides;
|
||||
}
|
||||
|
||||
public override Plain GetPlain()
|
||||
{
|
||||
return new Plain(
|
||||
vertexMat.colum0,
|
||||
vertexMat.colum1,
|
||||
vertexMat.colum2);
|
||||
}
|
||||
|
||||
public virtual vec3d MoveVertex0(int tick)
|
||||
{
|
||||
return moveVertex0Operation(tick);
|
||||
}
|
||||
|
||||
public virtual vec3d MoveVertex1(int tick)
|
||||
{
|
||||
return moveVertex1Operation(tick);
|
||||
}
|
||||
|
||||
public virtual vec3d MoveVertex2(int tick)
|
||||
{
|
||||
return moveVertex2Operation(tick);
|
||||
}
|
||||
|
||||
public virtual vec3d MoveVertex3(int tick)
|
||||
{
|
||||
return moveVertex3Operation(tick);
|
||||
}
|
||||
|
||||
internal override void UpdateCoordinate(int tick)
|
||||
{
|
||||
}
|
||||
public override ReadOnlySpan<int> VertexIndices => Indices;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Controlling;
|
||||
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -39,16 +39,9 @@ namespace StgSharp.Geometries
|
||||
public unsafe class Polygon5 : PlainGeometry
|
||||
{
|
||||
|
||||
internal Point _refOrigin;
|
||||
internal Func<int,vec3d> movP01Operation = default;
|
||||
internal Func<int,vec3d> movP02Operation = default;
|
||||
internal Func<int,vec3d> movP03Operation = default;
|
||||
internal Func<int,vec3d> movP04Operation = default;
|
||||
internal Func<int,vec3d> movP05Operation = default;
|
||||
internal mat5 vertexMat;
|
||||
|
||||
public unsafe Polygon5()
|
||||
{
|
||||
vertexMat = new vec4d[5];
|
||||
}
|
||||
|
||||
public Polygon5(
|
||||
@@ -59,106 +52,16 @@ namespace StgSharp.Geometries
|
||||
float v4x, float v4y, float v4z
|
||||
)
|
||||
{
|
||||
vertexMat.vec0 = new Vector4(v0x, v0y, v0z, 0);
|
||||
vertexMat.vec1 = new Vector4(v1x, v1y, v1z, 0);
|
||||
vertexMat.vec2 = new Vector4(v2x, v2y, v2z, 0);
|
||||
vertexMat.vec3 = new Vector4(v3x, v3y, v3z, 0);
|
||||
vertexMat.vec4 = new Vector4(v4x, v4y, v4z, 0);
|
||||
vertexMat = new vec4d[5];
|
||||
this[0] = new vec4d(v0x, v0y, v0z, 0);
|
||||
this[1] = new vec4d(v1x, v1y, v1z, 0);
|
||||
this[2] = new vec4d(v2x, v2y, v2z, 0);
|
||||
this[3] = new vec4d(v3x, v3y, v3z, 0);
|
||||
this[4] = new vec4d(v4x, v4y, v4z, 0);
|
||||
}
|
||||
|
||||
internal static int[] Indices = [ 0, 1, 2, 0, 2, 3, 0, 3, 4 ];
|
||||
|
||||
public Func<int,vec3d> MovP01Operation => movP01Operation;
|
||||
public Func<int,vec3d> MovP02Operation => movP02Operation;
|
||||
public Func<int,vec3d> MovP03Operation => movP03Operation;
|
||||
public Func<int,vec3d> MovP04Operation => movP04Operation;
|
||||
public Func<int,vec3d> MovP05Operation => movP05Operation;
|
||||
|
||||
public Point Vertex0
|
||||
{
|
||||
get => new Point(vertexMat.vec0);
|
||||
set => vertexMat.vec0 = value.position.vec;
|
||||
}
|
||||
|
||||
public Point Vertex1
|
||||
{
|
||||
get => new Point(vertexMat.vec1);
|
||||
set => vertexMat.vec1 = value.position.vec;
|
||||
}
|
||||
|
||||
public Point Vertex2
|
||||
{
|
||||
get => new Point(vertexMat.vec2);
|
||||
set => vertexMat.vec2 = value.position.vec;
|
||||
}
|
||||
|
||||
public Point Vertex3
|
||||
{
|
||||
get => new Point(vertexMat.vec3);
|
||||
set => vertexMat.vec3 = value.position.vec;
|
||||
}
|
||||
|
||||
public Point Vertex4
|
||||
{
|
||||
get => new Point(vertexMat.vec4);
|
||||
set => vertexMat.vec4 = value.position.vec;
|
||||
}
|
||||
|
||||
public mat5 VertexBuffer => vertexMat;
|
||||
|
||||
internal override int[] Indices => new int[9] { 0, 1, 2, 0, 2, 3, 0, 3, 4 };
|
||||
|
||||
public override Line[] GetAllSides()
|
||||
{
|
||||
return new Line[5]
|
||||
{
|
||||
new Line(Vertex0,Vertex1),
|
||||
new Line(Vertex1,Vertex2),
|
||||
new Line(Vertex2,Vertex3),
|
||||
new Line(Vertex3,Vertex4),
|
||||
new Line(Vertex4,Vertex0)
|
||||
};
|
||||
}
|
||||
|
||||
public override Plain GetPlain()
|
||||
{
|
||||
return new Plain(Vertex0, Vertex1, Vertex2);
|
||||
}
|
||||
|
||||
public virtual vec3d movVertex01(int tick)
|
||||
{
|
||||
return movP01Operation.Invoke(time);
|
||||
}
|
||||
|
||||
public virtual vec3d movVertex02(int tick)
|
||||
{
|
||||
return movP02Operation.Invoke(time);
|
||||
}
|
||||
|
||||
public virtual vec3d movVertex03(int tick)
|
||||
{
|
||||
return movP03Operation.Invoke(time);
|
||||
}
|
||||
|
||||
public virtual vec3d movVertex04(int tick)
|
||||
{
|
||||
return movP04Operation.Invoke(time);
|
||||
}
|
||||
|
||||
public virtual vec3d movVertex05(int tick)
|
||||
{
|
||||
return movP05Operation.Invoke(time);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public override ReadOnlySpan<int> VertexIndices => Indices;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Controlling;
|
||||
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -38,120 +38,13 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
public class Polygon6 : PlainGeometry
|
||||
{
|
||||
|
||||
internal Point _refOrigin;
|
||||
internal Func<int,vec3d> movVertex0Operation;
|
||||
internal Func<int,vec3d> movVertex1Operation;
|
||||
internal Func<int,vec3d> movVertex2Operation;
|
||||
internal Func<int,vec3d> movVertex3Operation;
|
||||
internal Func<int,vec3d> movVertex4Operation;
|
||||
internal Func<int,vec3d> movVertex5Operation;
|
||||
internal mat6 vertexMat;
|
||||
|
||||
public Func<int,vec3d> MovVertex0Operation => movVertex0Operation;
|
||||
public Func<int,vec3d> MovVertex1Operation => movVertex1Operation;
|
||||
public Func<int,vec3d> MovVertex2Operation => movVertex2Operation;
|
||||
public Func<int,vec3d> MovVertex3Operation => movVertex3Operation;
|
||||
public Func<int,vec3d> MovVertex4Operation => movVertex4Operation;
|
||||
public Func<int,vec3d> MovVertex5Operation => movVertex5Operation;
|
||||
|
||||
public Point Vertex0
|
||||
public Polygon6()
|
||||
{
|
||||
get => new Point(vertexMat.vec0);
|
||||
set => vertexMat.vec0 = value.position.vec;
|
||||
vertexMat = new vec4d[6];
|
||||
}
|
||||
|
||||
public Point Vertex1
|
||||
{
|
||||
get => new Point(vertexMat.vec1);
|
||||
set => vertexMat.vec1 = value.position.vec;
|
||||
}
|
||||
|
||||
public Point Vertex2
|
||||
{
|
||||
get => new Point(vertexMat.vec2);
|
||||
set => vertexMat.vec2 = value.position.vec;
|
||||
}
|
||||
|
||||
public Point Vertex3
|
||||
{
|
||||
get => new Point(vertexMat.vec3);
|
||||
set => vertexMat.vec3 = value.position.vec;
|
||||
}
|
||||
|
||||
public Point Vertex4
|
||||
{
|
||||
get => new Point(vertexMat.vec4);
|
||||
set => vertexMat.vec4 = value.position.vec;
|
||||
}
|
||||
|
||||
public Point Vertex5
|
||||
{
|
||||
get => new Point(vertexMat.vec5);
|
||||
set => vertexMat.vec5 = value.position.vec;
|
||||
}
|
||||
|
||||
internal override int[] Indices => new int[12] { 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5 };
|
||||
|
||||
public override Line[] GetAllSides()
|
||||
{
|
||||
return new Line[6]
|
||||
{
|
||||
new Line(Vertex0,Vertex1),
|
||||
new Line(Vertex1,Vertex2),
|
||||
new Line(Vertex2,Vertex3),
|
||||
new Line(Vertex3,Vertex4),
|
||||
new Line(Vertex4,Vertex5),
|
||||
new Line(Vertex5,Vertex0)
|
||||
};
|
||||
}
|
||||
|
||||
public override Plain GetPlain()
|
||||
{
|
||||
return new Plain(Vertex0, Vertex1, Vertex2);
|
||||
}
|
||||
|
||||
public virtual vec3d movVertex0(int tick)
|
||||
{
|
||||
return movVertex0Operation.Invoke(time);
|
||||
}
|
||||
|
||||
public virtual vec3d movVertex1(int tick)
|
||||
{
|
||||
return movVertex1Operation.Invoke(time);
|
||||
}
|
||||
|
||||
public virtual vec3d movVertex2(int tick)
|
||||
{
|
||||
return movVertex2Operation.Invoke(time);
|
||||
}
|
||||
|
||||
public virtual vec3d movVertex3(int tick)
|
||||
{
|
||||
return movVertex3Operation.Invoke(time);
|
||||
}
|
||||
|
||||
public virtual vec3d movVertex4(int tick)
|
||||
{
|
||||
return movVertex4Operation.Invoke(time);
|
||||
}
|
||||
|
||||
public virtual vec3d movVertex5(int tick)
|
||||
{
|
||||
return movVertex5Operation.Invoke(time);
|
||||
}
|
||||
|
||||
internal override void UpdateCoordinate(int tick)
|
||||
{
|
||||
int nowTick = tick - BornTime;
|
||||
Vector4 origin = coordinate.Origin.vec;
|
||||
vertexMat.vec0 = origin + movVertex0(nowTick).vec;
|
||||
vertexMat.vec1 = origin + movVertex1(nowTick).vec;
|
||||
vertexMat.vec2 = origin + movVertex2(nowTick).vec;
|
||||
vertexMat.vec3 = origin + movVertex3(nowTick).vec;
|
||||
vertexMat.vec4 = origin + movVertex4(nowTick).vec;
|
||||
vertexMat.vec5 = origin + movVertex5(nowTick).vec;
|
||||
}
|
||||
internal static int[] Indices = [ 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5 ];
|
||||
|
||||
public override ReadOnlySpan<int> VertexIndices => Indices;
|
||||
}
|
||||
}
|
||||
@@ -50,8 +50,8 @@ namespace StgSharp.Geometries
|
||||
)
|
||||
{
|
||||
#if DEBUG
|
||||
vec2d side0 = new vec2d( vertexMat.colum0 - vertexMat.colum1);
|
||||
vec2d side1 = new vec2d( vertexMat.colum2 - vertexMat.colum1);
|
||||
vec2d side0 = (this[0] - this[1]).XY;
|
||||
vec2d side1 = (this[2] - this[1]).XY;
|
||||
if (side0.Cross(side1) == 0)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
|
||||
@@ -51,12 +51,12 @@ namespace StgSharp.Geometries
|
||||
v2x, v2y, v2z,
|
||||
v3x, v3y, v3z)
|
||||
{
|
||||
}
|
||||
|
||||
public override sealed vec3d MoveVertex1(int tick)
|
||||
if (true)
|
||||
{
|
||||
return default;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,8 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Controlling;
|
||||
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -41,15 +42,9 @@ namespace StgSharp.Geometries
|
||||
public unsafe class Triangle : PlainGeometry
|
||||
{
|
||||
|
||||
internal Func<int,vec3d> movVertex01Operation = GeometryOperation.DefaultMotion;
|
||||
internal Func<int,vec3d> movVertex02Operation = GeometryOperation.DefaultMotion;
|
||||
internal Func<int,vec3d> movVertex03Operation = GeometryOperation.DefaultMotion;
|
||||
|
||||
internal Mat3 vertexMat;
|
||||
|
||||
public Triangle()
|
||||
{
|
||||
vertexMat = new Mat3();
|
||||
vertexMat = new vec4d[3];
|
||||
}
|
||||
|
||||
public Triangle(
|
||||
@@ -58,9 +53,9 @@ namespace StgSharp.Geometries
|
||||
vec3d vertex03
|
||||
)
|
||||
{
|
||||
vertexMat.colum0 = vertex01.vec;
|
||||
vertexMat.colum1 = vertex02.vec;
|
||||
vertexMat.colum2 = vertex03.vec;
|
||||
this[0] = new vec4d( vertex01.vec);
|
||||
this[1] = new vec4d( vertex02.vec);
|
||||
this[2] = new vec4d( vertex03.vec);
|
||||
}
|
||||
|
||||
public Triangle(
|
||||
@@ -69,56 +64,14 @@ namespace StgSharp.Geometries
|
||||
float v2x, float v2y, float v2z
|
||||
)
|
||||
{
|
||||
vertexMat.colum0 = new Vector4(v0x, v0y, v0z, 0);
|
||||
vertexMat.colum1 = new Vector4(v1x, v1y, v1z, 0);
|
||||
vertexMat.colum2 = new Vector4(v2x, v2y, v2z, 0);
|
||||
this[0] = new vec4d(v0x, v0y, v0z, 0);
|
||||
this[1] = new vec4d(v1x, v1y, v1z, 0);
|
||||
this[2] = new vec4d(v2x, v2y, v2z, 0);
|
||||
}
|
||||
|
||||
public Func<int,vec3d> MovVertex01Operation => this.movVertex01Operation;
|
||||
public Func<int,vec3d> MovVertex02Operation => this.movVertex02Operation;
|
||||
public Func<int,vec3d> MovVertex03Operation => this.movVertex03Operation;
|
||||
internal static int[] Indices = [ 0, 1, 2 ];
|
||||
|
||||
public Mat3 VertexBuffer => vertexMat;
|
||||
|
||||
internal override sealed int[] Indices => new int[3] { 0, 1, 2 };
|
||||
|
||||
public override Line[] GetAllSides()
|
||||
{
|
||||
return
|
||||
[
|
||||
new Line(vertexMat.colum0,vertexMat.colum1),
|
||||
new Line(vertexMat.colum1,vertexMat.colum2),
|
||||
new Line(vertexMat.colum2,vertexMat.colum0)
|
||||
];
|
||||
}
|
||||
|
||||
public override Plain GetPlain()
|
||||
{
|
||||
return new Plain(this.vertexMat.colum0, this.vertexMat.colum1, this.vertexMat.colum2);
|
||||
}
|
||||
|
||||
public virtual vec3d MovVertex01(int tick)
|
||||
{
|
||||
return movVertex01Operation(tick);
|
||||
}
|
||||
|
||||
public virtual vec3d MovVertex02(int tick)
|
||||
{
|
||||
return movVertex02Operation(tick);
|
||||
}
|
||||
|
||||
public virtual vec3d MovVertex03(int tick)
|
||||
{
|
||||
return movVertex03Operation(tick);
|
||||
}
|
||||
|
||||
internal override sealed void UpdateCoordinate(int tick)
|
||||
{
|
||||
tick = time;
|
||||
vertexMat.colum0 = coordinate.Origin.vec + MovVertex01(time).vec;
|
||||
vertexMat.colum1 = coordinate.Origin.vec + MovVertex02(time).vec;
|
||||
vertexMat.colum2 = coordinate.Origin.vec + MovVertex03(time).vec;
|
||||
}
|
||||
public override ReadOnlySpan<int> VertexIndices => Indices;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="AnimationBuilder.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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public sealed class AnimationBuilder: IImageProvider
|
||||
{
|
||||
|
||||
private Image cache;
|
||||
|
||||
private TimeFunction time;
|
||||
|
||||
public AnimationBuilder(
|
||||
Func<float, Image> builderFunc,
|
||||
TimeFunction timeline
|
||||
)
|
||||
{
|
||||
time = timeline;
|
||||
BuilderFunc = builderFunc;
|
||||
}
|
||||
|
||||
public Func<float, Image> BuilderFunc { get; set; }
|
||||
|
||||
public bool IsComplete
|
||||
{
|
||||
get => time.IsComplete;
|
||||
}
|
||||
|
||||
public Image GetAnimationFrame()
|
||||
{
|
||||
if (!time.IsComplete)
|
||||
{
|
||||
cache = BuilderFunc(time.Calculate());
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
time.Reset();
|
||||
}
|
||||
|
||||
Image IImageProvider.ProvideImage()
|
||||
{
|
||||
return GetAnimationFrame();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public interface IImageProvider
|
||||
{
|
||||
Image ProvideImage();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,8 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.GL;
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
||||
+4813
-4794
File diff suppressed because it is too large
Load Diff
@@ -30,8 +30,32 @@
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public enum ImageChannelLayout
|
||||
{
|
||||
UByte = GLconst.UNSIGNED_BYTE,
|
||||
Byte = GLconst.BYTE,
|
||||
UShort = GLconst.UNSIGNED_SHORT,
|
||||
Short = GLconst.SHORT,
|
||||
UInt = GLconst.UNSIGNED_INT,
|
||||
Int = GLconst.INT,
|
||||
Float = GLconst.FLOAT,
|
||||
UByte332 = 0x8032, // GL_UNSIGNED_BYTE_3_3_2
|
||||
UByte233Rev = 0x8362, // GL_UNSIGNED_BYTE_2_3_3_REV
|
||||
UShort565 = 0x8363, // GL_UNSIGNED_SHORT_5_6_5
|
||||
UShort565Rev = 0x8364, // GL_UNSIGNED_SHORT_5_6_5_REV
|
||||
UShort4444 = 0x8033, // GL_UNSIGNED_SHORT_4_4_4_4
|
||||
UShort4444Rev = 0x8034, // GL_UNSIGNED_SHORT_4_4_4_4_REV
|
||||
UShort5551 = 0x8035, // GL_UNSIGNED_SHORT_5_5_5_1
|
||||
UShort1555Rev = 0x8366, // GL_UNSIGNED_SHORT_1_5_5_5_REV
|
||||
UInt8888 = 0x8035, // GL_UNSIGNED_INT_8_8_8_8
|
||||
UInt8888Rev = 0x8367, // GL_UNSIGNED_INT_8_8_8_8_REV
|
||||
UInt1010102 = 0x8036, // GL_UNSIGNED_INT_10_10_10_2
|
||||
UInt2101010Rev = 0x8368 // GL_UNSIGNED_INT_2_10_10_10_REV
|
||||
}
|
||||
|
||||
|
||||
internal enum VkStructureType : uint
|
||||
{
|
||||
VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR = 1000004000,
|
||||
@@ -43,6 +67,44 @@ namespace StgSharp.Graphics
|
||||
VK_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF
|
||||
}
|
||||
|
||||
public enum FrameBufferChannel
|
||||
{
|
||||
STENCIL_INDEX = GLconst.STENCIL_INDEX,
|
||||
DEPTH_COMPONENT = GLconst.DEPTH_COMPONENT,
|
||||
DEPTH_STENCIL = GLconst.DEPTH_STENCIL,
|
||||
RED = GLconst.RED,
|
||||
GREEN = GLconst.GREEN,
|
||||
BLUE = GLconst.BLUE,
|
||||
RGB = GLconst.RGB,
|
||||
BGR = GLconst.BGR,
|
||||
RGBA = GLconst.RGBA,
|
||||
BGRA = GLconst.BGRA
|
||||
}
|
||||
|
||||
|
||||
public enum Texture2DTarget
|
||||
{
|
||||
Texture2D = GLconst.TEXTURE_2D,
|
||||
ProxyTexture2D = GLconst.PROXY_TEXTURE_2D,
|
||||
Texture1DArray = GLconst.TEXTURE_1D_ARRAY,
|
||||
ProxyTexture1DArray = GLconst.PROXY_TEXTURE_1D_ARRAY,
|
||||
TextureRectangle = GLconst.TEXTURE_RECTANGLE,
|
||||
ProxyTextureRectangle = GLconst.PROXY_TEXTURE_RECTANGLE,
|
||||
TextureCubeMapPositiveX = GLconst.TEXTURE_CUBE_MAP_POSITIVE_X,
|
||||
TextureCubeMapNegativeX = GLconst.TEXTURE_CUBE_MAP_NEGATIVE_X,
|
||||
TextureCubeMapPositiveY = GLconst.TEXTURE_CUBE_MAP_POSITIVE_Y,
|
||||
TextureCubeMapNegativeY = GLconst.TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
||||
TextureCubeMapPositiveZ = GLconst.TEXTURE_CUBE_MAP_POSITIVE_Z,
|
||||
TextureCubeMapNegativeZ = GLconst.TEXTURE_CUBE_MAP_NEGATIVE_Z,
|
||||
ProxyTextureCubeMap = GLconst.PROXY_TEXTURE_CUBE_MAP
|
||||
}
|
||||
|
||||
public enum RenderBufferInternalFormat : uint
|
||||
{
|
||||
RGBA8 = GLconst.RGBA8,
|
||||
Depth24_Stencil8 = GLconst.DEPTH24_STENCIL8,
|
||||
}
|
||||
|
||||
public enum GLOperation : uint
|
||||
{
|
||||
StencilTest = GLconst.STENCIL_TEST,
|
||||
@@ -76,17 +138,23 @@ namespace StgSharp.Graphics
|
||||
VK_RESULT_MAX_ENUM = 0x7FFFFFFF
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum ShaderType : int
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
Fragment = 0x8B30,
|
||||
Vertex = 0x8B31,
|
||||
Fragment = GLconst.FRAGMENT_SHADER,
|
||||
Vertex = GLconst.VERTEX_SHADER,
|
||||
Compute = GLconst.COMPUTE_SHADER,
|
||||
Geometry = GLconst.GEOMETRY_SHADER,
|
||||
}
|
||||
|
||||
public enum BufferType : uint
|
||||
#pragma warning disable CA1008 // 枚举应具有零值
|
||||
public enum BufferType : int
|
||||
#pragma warning restore CA1008 // 枚举应具有零值
|
||||
{
|
||||
ARRAY_BUFFER = 0x8892,
|
||||
ELEMENT_ARRAY_BUFFER = 0x8893,
|
||||
ATOMIC_COUNTER_BUFFER = GLconst.ATOMIC_COUNTER_BUFFER,
|
||||
ArrayBuffer = GLconst.ARRAY_BUFFER,
|
||||
ElementArrayBuffer = GLconst.ELEMENT_ARRAY_BUFFER,
|
||||
AtomicCounterBuffer = GLconst.ATOMIC_COUNTER_BUFFER,
|
||||
COPY_READ_BUFFER = GLconst.COPY_READ_BUFFER,
|
||||
COPY_WRITE_BUFFER = GLconst.COPY_WRITE_BUFFER,
|
||||
DISPATCH_INDIRECT_BUFFER = GLconst.DISPATCH_INDIRECT_BUFFER,
|
||||
@@ -100,19 +168,22 @@ namespace StgSharp.Graphics
|
||||
UNIFORM_BUFFER = GLconst.UNIFORM_BUFFER,
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008 // 枚举应具有零值
|
||||
public enum BufferUsage : int
|
||||
#pragma warning restore CA1008 // 枚举应具有零值
|
||||
{
|
||||
STREAM_DRAW = 0x88E0,
|
||||
STREAM_READ = 0x88E1,
|
||||
STREAM_COPY = 0x88E2,
|
||||
STATIC_DRAW = 0x88E4,
|
||||
STATIC_READ = 0x88E5,
|
||||
STATIC_COPY = 0x88E6,
|
||||
DYNAMIC_DRAW = 0x88E8,
|
||||
DYNAMIC_READ = 0x88E9,
|
||||
DYNAMIC_COPY = 0x88EA
|
||||
StreamDraw = 0x88E0,
|
||||
StreamRead = 0x88E1,
|
||||
StreamCopy = 0x88E2,
|
||||
StaticDraw = 0x88E4,
|
||||
StaticRead = 0x88E5,
|
||||
StaticCopy = 0x88E6,
|
||||
DynamicDraw = 0x88E8,
|
||||
DynamicRead = 0x88E9,
|
||||
DynamicCopy = 0x88EA
|
||||
}
|
||||
|
||||
|
||||
public enum MaskBufferBit
|
||||
{
|
||||
COLOR = GLconst.COLOR_BUFFER_BIT,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Form.cs"
|
||||
// file="ViewModel.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
@@ -46,7 +46,7 @@ namespace StgSharp.Graphics
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public abstract unsafe partial class Form
|
||||
public abstract unsafe partial class ViewModel
|
||||
{
|
||||
|
||||
private int _frameCount;
|
||||
@@ -54,20 +54,18 @@ namespace StgSharp.Graphics
|
||||
|
||||
private IntPtr windowID;
|
||||
|
||||
private short fpsCount;
|
||||
internal Form sharedForm;
|
||||
internal ViewModel sharedForm;
|
||||
|
||||
internal int height;
|
||||
internal int width;
|
||||
internal IntPtr monitor;
|
||||
|
||||
internal LinkedList<Control> allControl;
|
||||
internal string name;
|
||||
internal TimeSpanProvider fpsCountProvider;
|
||||
internal TimeSpanProvider frameTimeProvider;
|
||||
internal Vector4 backgroundColor;
|
||||
|
||||
protected Form((int width, int height) size, string name)
|
||||
protected ViewModel((int width, int height) size, string name)
|
||||
{
|
||||
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
|
||||
_frameSpeed = 0;
|
||||
@@ -92,7 +90,7 @@ namespace StgSharp.Graphics
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Form()
|
||||
protected ViewModel()
|
||||
{
|
||||
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
|
||||
_frameSpeed = 0;
|
||||
@@ -102,8 +100,6 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
Interlocked.Exchange(ref _frameSpeed, _frameCount);
|
||||
Interlocked.Exchange(ref _frameCount, 0);
|
||||
Console.Clear();
|
||||
Console.WriteLine(_frameSpeed);
|
||||
};
|
||||
frameTimeProvider = new TimeSpanProvider(
|
||||
(1000L * 1000L) / 60, TimeSpanProvider.DefaultProvider
|
||||
@@ -218,7 +214,7 @@ namespace StgSharp.Graphics
|
||||
/// <summary>
|
||||
/// Set all necessary metadata to current form instance
|
||||
/// </summary>
|
||||
public void SetMetadata(int width, int height, string name, IntPtr monitor, Form sharedForm)
|
||||
public void SetMetadata(int width, int height, string name, IntPtr monitor, ViewModel sharedForm)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
@@ -41,7 +41,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public abstract partial class Form
|
||||
public abstract partial class ViewModel
|
||||
{
|
||||
private Blueprint renderLogic;
|
||||
|
||||
@@ -64,6 +64,40 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public T BuildMainRenderStream<T>((int x, int y, int z) unitCubeSize) where T : RenderStream
|
||||
{
|
||||
RenderStreamConstructArgs args = new RenderStreamConstructArgs();
|
||||
args.UnitCubeSize = unitCubeSize;
|
||||
args.Name = this.name;
|
||||
args.Height = this.Height;
|
||||
args.Width = this.Width;
|
||||
T? ret = Activator.CreateInstance(typeof(T), args) as T;
|
||||
if (ret == null)
|
||||
{
|
||||
throw new InvalidOperationException("Failed in building a new RenderStream when calling AsMainStreamOf");
|
||||
}
|
||||
ret!.InternalInit();
|
||||
this.WindowID = ret.CanvasHandle;
|
||||
ret.timeProvider = this.frameTimeProvider;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public T BuildNewRenderStream<T>(RenderStreamConstructArgs arg, (int x, int y, int z) unitCubeSize) where T : RenderStream
|
||||
{
|
||||
T? ret = Activator.CreateInstance(typeof(T), arg) as T;
|
||||
if (ret == null)
|
||||
{
|
||||
throw new InvalidOperationException("Failed in building a new RenderStream when calling AsMainStreamOf");
|
||||
}
|
||||
ret!.InternalInit();
|
||||
this.WindowID = ret.CanvasHandle;
|
||||
ret.timeProvider = this.frameTimeProvider;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
private void GatherSingleFrameAsyncThread(MethodInfo[] methods)
|
||||
{
|
||||
|
||||
@@ -11,16 +11,16 @@ namespace StgSharp.Graphics
|
||||
|
||||
}
|
||||
|
||||
public abstract unsafe partial class Form
|
||||
public abstract unsafe partial class ViewModel
|
||||
{
|
||||
|
||||
static internal Dictionary<IntPtr, Form> activatedForms ;
|
||||
static internal Dictionary<IntPtr, ViewModel> activatedForms ;
|
||||
|
||||
public static void ShowForm<T>(FormFormatter f) where T : Form
|
||||
public static void ShowForm<T>(FormFormatter f) where T : ViewModel
|
||||
{
|
||||
if (activatedForms == null)
|
||||
{
|
||||
activatedForms = new Dictionary<IntPtr, Form>();
|
||||
activatedForms = new Dictionary<IntPtr, ViewModel>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,14 +34,14 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface of all kinds OpenGL buffer objects
|
||||
/// </summary>
|
||||
public abstract class BufferObjectBase : IDisposable
|
||||
{
|
||||
protected IntPtr binding;
|
||||
protected RenderStream binding;
|
||||
protected glHandleSet _bufferHandle;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -36,7 +36,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
/// <summary>
|
||||
/// A collection of handle to Element Buffer Object in OpenGL.
|
||||
@@ -48,27 +48,34 @@ namespace StgSharp.Graphics
|
||||
|
||||
internal ElementBuffer(int n, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
_bufferHandle = GL.GenBuffers(n);
|
||||
this.binding = binding;
|
||||
_bufferHandle = glFunc.GenBuffers(n);
|
||||
}
|
||||
|
||||
public override sealed void Bind(int index)
|
||||
{
|
||||
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferHandle[index]);
|
||||
glFunc.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
public void SetValue<T>(int index, T[] bufferArray, BufferUsage usage)
|
||||
where T : struct, IConvertible
|
||||
{
|
||||
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ELEMENT_ARRAY_BUFFER, bufferArray, usage);
|
||||
glFunc.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferData(BufferType.ElementArrayBuffer, bufferArray, usage);
|
||||
}
|
||||
|
||||
public void SetValue<T>(int index, ReadOnlySpan<T> bufferSpan, BufferUsage usage)
|
||||
where T : struct, IConvertible
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferData(BufferType.ElementArrayBuffer, bufferSpan, usage);
|
||||
}
|
||||
|
||||
protected override sealed void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
GL.DeleteBuffers(_bufferHandle);
|
||||
glFunc.DeleteBuffers(_bufferHandle);
|
||||
_bufferHandle.Release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,13 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
#pragma warning disable CA1008
|
||||
#pragma warning disable CA1028
|
||||
public enum FrameBufferTarget:uint
|
||||
#pragma warning restore CA1028
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
Read = GLconst.READ_FRAMEBUFFER,
|
||||
All = GLconst.FRAMEBUFFER,
|
||||
@@ -17,9 +21,9 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
internal unsafe FrameBuffer(int count, glRenderStream contextBinding)
|
||||
{
|
||||
binding = contextBinding.ContextHandle;
|
||||
binding = contextBinding;
|
||||
_bufferHandle = new glHandleSet(count);
|
||||
((GLcontext*)binding)->glGenFramebuffers((uint)count,_bufferHandle.handle);
|
||||
((GLcontext*)binding.ContextHandle)->glGenFramebuffers((uint)count,_bufferHandle.handle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -29,7 +33,12 @@ namespace StgSharp.Graphics
|
||||
/// <param name="index">Index of object to be binded in handle set</param>
|
||||
public unsafe override void Bind(int index)
|
||||
{
|
||||
((GLcontext*)binding)->glBindFramebuffer(GLconst.FRAMEBUFFER, _bufferHandle[index].Value);
|
||||
glFunc.BindFrameBuffer(FrameBufferTarget.All,_bufferHandle[index]);
|
||||
}
|
||||
|
||||
public static void BindNull()
|
||||
{
|
||||
glFunc.BindFrameBuffer(FrameBufferTarget.All,glHandle.Zero);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -40,7 +49,7 @@ namespace StgSharp.Graphics
|
||||
/// <param name="index">Index of object to be binded in handle set</param>
|
||||
public unsafe void Bind(FrameBufferTarget target, int index)
|
||||
{
|
||||
((GLcontext*)binding)->glBindFramebuffer((uint)target, _bufferHandle[index].Value);
|
||||
((GLcontext*)binding.ContextHandle)->glBindFramebuffer((uint)target, _bufferHandle[index].Value);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
|
||||
|
||||
|
||||
public class RenderBuffer : BufferObjectBase
|
||||
{
|
||||
public RenderBuffer(int count, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
_bufferHandle = glFunc.GenRenderBuffer(count);
|
||||
}
|
||||
|
||||
public override void Bind(int index)
|
||||
{
|
||||
glFunc.BindRenderBuffer(this[index]);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Store(RenderBufferInternalFormat format, (int width,int height) size)
|
||||
{
|
||||
if (size.width > binding.Width || size.height>binding.Height)
|
||||
{
|
||||
StgSharp.LogWarning("FrameBuffer is larger than current canvas binding");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="texture.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.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public unsafe class TextureGL
|
||||
{
|
||||
|
||||
internal static bool[] unitActivated = new bool[16];
|
||||
private IntPtr binding;
|
||||
internal glHandleSet _textureHandle;
|
||||
internal Image[] sourceList;
|
||||
|
||||
public glHandle this[int index]
|
||||
{
|
||||
get => _textureHandle[index];
|
||||
}
|
||||
|
||||
internal TextureGL(int n, glRenderStream binding)
|
||||
{
|
||||
sourceList = new Image[n];
|
||||
this.binding = binding.ContextHandle;
|
||||
_textureHandle = glFunc.GenTextures(n);
|
||||
}
|
||||
|
||||
public static void Activate(TextureUnit unit)
|
||||
{
|
||||
glFunc.ActiveTexture((uint)unit);
|
||||
}
|
||||
|
||||
public void Bind2D(int index)
|
||||
{
|
||||
glFunc.BindTexture(GLconst.TEXTURE_2D, _textureHandle[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="index"> </param>
|
||||
/// <param name="i"> </param>
|
||||
public unsafe void LoadTexture(int index, Image i)
|
||||
{
|
||||
sourceList[index] = i;
|
||||
glArrayHandle handle = sourceList[index].GetArrayHandle();
|
||||
glFunc.TextureImage2d(
|
||||
Texture2DTarget.Texture2D, 0, (uint)i.Channel,
|
||||
(uint)sourceList[index].Width, (uint)sourceList[index].Height,
|
||||
(uint)i.Channel, ImageChannelLayout.Byte,
|
||||
pixelArrayHandle: handle
|
||||
);
|
||||
handle.Release();
|
||||
}
|
||||
|
||||
|
||||
#region texture setting
|
||||
|
||||
public void Set2dFilterProperty(
|
||||
Filter onMinify, Filter onMagnify)
|
||||
{
|
||||
glFunc.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MIN_FILTER, (int)onMinify);
|
||||
glFunc.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MAG_FILTER, (int)onMagnify);
|
||||
}
|
||||
|
||||
public void Set2dWrapProperty(
|
||||
Wrap onHorizontial, Wrap onVertical)
|
||||
{
|
||||
glFunc.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_S, (int)onHorizontial);
|
||||
glFunc.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_T, (int)onVertical);
|
||||
}
|
||||
|
||||
#endregion texture setting
|
||||
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum Filter
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
Nearest = GLconst.NEAREST,
|
||||
Linear = GLconst.LINEAR,
|
||||
NearestLinearMipmap = GLconst.NEAREST_MIPMAP_LINEAR,
|
||||
LinearLinearMipmap = GLconst.LINEAR_MIPMAP_LINEAR,
|
||||
NearestNearestMipmap = GLconst.NEAREST_MIPMAP_NEAREST,
|
||||
LinearNearestMipmap = GLconst.LINEAR_MIPMAP_NEAREST,
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum TextureUnit
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
Unit0 = GLconst.TEXTURE0,
|
||||
Unit1 = GLconst.TEXTURE1,
|
||||
Unit2 = GLconst.TEXTURE2,
|
||||
Unit3 = GLconst.TEXTURE3,
|
||||
Unit4 = GLconst.TEXTURE4,
|
||||
Unit5 = GLconst.TEXTURE5,
|
||||
Unit6 = GLconst.TEXTURE6,
|
||||
Unit7 = GLconst.TEXTURE7,
|
||||
Unit8 = GLconst.TEXTURE8,
|
||||
Unit9 = GLconst.TEXTURE9,
|
||||
Unit10 = GLconst.TEXTURE10,
|
||||
Unit11 = GLconst.TEXTURE11,
|
||||
Unit12 = GLconst.TEXTURE12,
|
||||
Unit13 = GLconst.TEXTURE13,
|
||||
Unit14 = GLconst.TEXTURE14,
|
||||
Unit15 = GLconst.TEXTURE15,
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum Wrap
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
Repeat = GLconst.REPEAT,
|
||||
MirroredRepeat = GLconst.MIRRORED_REPEAT,
|
||||
ClampToEdge = GLconst.CLAMP_TO_EDGE,
|
||||
ClampToBorder = GLconst.CLAMP_TO_BORDER,
|
||||
}
|
||||
}
|
||||
@@ -28,38 +28,40 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public unsafe class VertexArray : BufferObjectBase
|
||||
{
|
||||
|
||||
internal VertexArray(int n, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
_bufferHandle = GL.GenVertexArrays(n);
|
||||
this.binding = binding;
|
||||
_bufferHandle = glFunc.GenVertexArrays(n);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override sealed void Bind(int index)
|
||||
{
|
||||
GL.BindVertexArray(_bufferHandle[index]);
|
||||
glFunc.BindVertexArray(_bufferHandle[index]);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BindNull()
|
||||
public static void BindNull()
|
||||
{
|
||||
GL.BindVertexArray(glHandle.Zero);
|
||||
glFunc.BindVertexArray(glHandle.Zero);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetVertexAttribute(uint index, int vertexLength, TypeCode dataType, bool isNomalized, uint stride, int pointer)
|
||||
public static void SetVertexAttribute(uint index, int vertexLength, TypeCode dataType, bool isNomalized, uint stride, int pointer)
|
||||
{
|
||||
GL.SetVertexAttribute(
|
||||
glFunc.SetVertexAttribute(
|
||||
index, vertexLength, dataType,
|
||||
isNomalized,
|
||||
stride, pointer);
|
||||
@@ -69,7 +71,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
GL.DeleteVertexArrays(_bufferHandle);
|
||||
glFunc.DeleteVertexArrays(_bufferHandle);
|
||||
_bufferHandle.Release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.GL;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -38,20 +39,20 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public unsafe class VertexBuffer : BufferObjectBase
|
||||
{
|
||||
|
||||
internal VertexBuffer(int n, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
_bufferHandle = GL.GenBuffers(n);
|
||||
this.binding = binding;
|
||||
_bufferHandle = glFunc.GenBuffers(n);
|
||||
}
|
||||
|
||||
public override sealed void Bind(int index)
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -64,8 +65,8 @@ namespace StgSharp.Graphics
|
||||
public void WriteMatrixData<T>(int index, T bufferData, BufferUsage usage)
|
||||
where T : struct, IMat
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferData, usage);
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferData(BufferType.ArrayBuffer, bufferData, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -83,8 +84,8 @@ namespace StgSharp.Graphics
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferArray, usage);
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferData(BufferType.ArrayBuffer, bufferArray, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -94,7 +95,7 @@ namespace StgSharp.Graphics
|
||||
/// <param name="index">Index to find certain VBO in this instance</param>
|
||||
/// <param name="scalerSpan">A <see cref="Span{T}"/> of data to write in</param>
|
||||
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
|
||||
public void WriteScalerData<T>(int index, Span<T> scalerSpan, BufferUsage usage)
|
||||
public void WriteScalerData<T>(int index, ReadOnlySpan<T> scalerSpan, BufferUsage usage)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
@@ -102,8 +103,8 @@ namespace StgSharp.Graphics
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ARRAY_BUFFER, scalerSpan, usage);
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferData(BufferType.ArrayBuffer, scalerSpan, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -113,10 +114,10 @@ namespace StgSharp.Graphics
|
||||
/// <param name="index">Index to find certain VBO in this instance</param>
|
||||
/// <param name="vectorSpan">A <see cref="Span{T}"/> of data to write in</param>
|
||||
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
|
||||
public void WriteVectorData<T>(int index, Span<T> vectorSpan, BufferUsage usage) where T : struct, IVector
|
||||
public void WriteVectorData<T>(int index, ReadOnlySpan<T> vectorSpan, BufferUsage usage) where T : struct, IVector
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferVectorData(BufferType.ARRAY_BUFFER, vectorSpan, usage);
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferVectorData(BufferType.ArrayBuffer, vectorSpan, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -128,8 +129,8 @@ namespace StgSharp.Graphics
|
||||
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
|
||||
public void WriteVectorData<T>(int index, T[] vectorArray, BufferUsage usage) where T : struct, IVector
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferVectorData(BufferType.ARRAY_BUFFER, vectorArray, usage);
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferVectorData(BufferType.ArrayBuffer, vectorArray, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -138,14 +139,14 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Unbind()
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, glHandle.Zero);
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, glHandle.Zero);
|
||||
}
|
||||
|
||||
protected override sealed void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
GL.DeleteBuffers(_bufferHandle);
|
||||
glFunc.DeleteBuffers(_bufferHandle);
|
||||
_bufferHandle.Release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -46,7 +47,7 @@ namespace StgSharp.Graphics
|
||||
/// must be indexed from a <see cref="glHandleSet"/>.
|
||||
/// Direct call will cause <see langword="InvalidOperationException"/>
|
||||
/// </summary>
|
||||
public unsafe class glHandle
|
||||
public unsafe class glHandle: IDisposable
|
||||
{
|
||||
private static uint* zeroHandle = (uint*)Marshal.AllocHGlobal(Marshal.SizeOf<uint>());
|
||||
|
||||
@@ -93,6 +94,8 @@ namespace StgSharp.Graphics
|
||||
set => *valuePtr = value;
|
||||
}
|
||||
|
||||
public static glHandle ZeroHandle => FromPtr(IntPtr.Zero);
|
||||
|
||||
public static glHandle Zero => Alloc(0);
|
||||
|
||||
public static glHandle Alloc(uint value)
|
||||
@@ -113,6 +116,30 @@ namespace StgSharp.Graphics
|
||||
Marshal.FreeHGlobal((IntPtr)valuePtr);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (IsIsolated)
|
||||
{
|
||||
GCHandle.FromIntPtr((IntPtr)valuePtr).Free();
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// ~glHandle()
|
||||
// {
|
||||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe class glSHandle
|
||||
@@ -188,9 +215,9 @@ namespace StgSharp.Graphics
|
||||
|
||||
public unsafe class glArrayHandle
|
||||
{
|
||||
|
||||
internal readonly Array a;
|
||||
internal GCHandle handle;
|
||||
private bool disposedValue;
|
||||
|
||||
internal glArrayHandle(Array array)
|
||||
{
|
||||
@@ -230,7 +257,6 @@ namespace StgSharp.Graphics
|
||||
handle.Free();
|
||||
handle = default;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -43,14 +43,19 @@ namespace StgSharp
|
||||
{
|
||||
internal static unsafe partial class InternalIO
|
||||
{
|
||||
|
||||
[DllImport(SSC_libName, EntryPoint = "glCheckShaderStat",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
#pragma warning disable CA5392
|
||||
internal static extern int glCheckShaderStatus(ref GLcontext context, uint shaderHandle, int key, ref IntPtr logPtr);
|
||||
#pragma warning restore CA5392
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
internal static unsafe partial class GL
|
||||
internal static unsafe partial class glFunc
|
||||
{
|
||||
|
||||
private static GLcontext* context;
|
||||
@@ -58,10 +63,7 @@ namespace StgSharp.Graphics
|
||||
public static IntPtr CurrentContextHandle
|
||||
{
|
||||
get { return (IntPtr)context; }
|
||||
set
|
||||
{
|
||||
context = (GLcontext*)value;
|
||||
}
|
||||
set { context = (GLcontext*)value; }
|
||||
}
|
||||
|
||||
private static ref GLcontext Context
|
||||
@@ -74,7 +76,7 @@ namespace StgSharp.Graphics
|
||||
throw new NullReferenceException();
|
||||
}
|
||||
#endif
|
||||
return ref *context;
|
||||
return ref (*context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,14 +98,21 @@ namespace StgSharp.Graphics
|
||||
Context.glBindBuffer((uint)bufferType, handle.Value);
|
||||
}
|
||||
|
||||
public static string GetShaderStatus(Shader s, int index, int key)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void GetTextureImage<T>(Texture2DTarget target, int level, ImageChannel channel, ImageChannelLayout channelLayout, ref T[] dataStream)where T: struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
|
||||
{
|
||||
IntPtr sptr = IntPtr.Zero;
|
||||
if (InternalIO.glCheckShaderStatus(ref Context, s.handle[index].Value, key,ref sptr) == 0)
|
||||
#pragma warning disable CS8500
|
||||
fixed (T* tptr = dataStream)
|
||||
{
|
||||
return Marshal.PtrToStringAnsi(sptr);
|
||||
Context.glGetTexImage((uint)target, level, (uint)channel, (uint)channelLayout, tptr);
|
||||
}
|
||||
return "";
|
||||
#pragma warning restore CS8500
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -118,12 +127,30 @@ namespace StgSharp.Graphics
|
||||
Context.glBindFramebuffer((uint)target, handle.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindRenderBuffer(glHandle handle)
|
||||
{
|
||||
Context.glBindRenderbuffer(GLconst.RENDERBUFFER, handle.Value);
|
||||
}
|
||||
|
||||
|
||||
public static void WaitAccomplishment()
|
||||
{
|
||||
Context.glFinish();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindTexture(uint type, glHandle texture)
|
||||
{
|
||||
Context.glBindTexture(type, texture.Value);
|
||||
}
|
||||
|
||||
public static unsafe int GetMaskInteger(uint statusCode)
|
||||
{
|
||||
int ret = 0;
|
||||
Context.glGetIntegerv(statusCode,&ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindVertexArray(glHandle handle)
|
||||
@@ -131,10 +158,35 @@ namespace StgSharp.Graphics
|
||||
Context.glBindVertexArray(handle.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void VertexAttributeDivisor(uint layoutIndex, uint divisor)
|
||||
public static void RereadImage(
|
||||
this Image i, (int X, int Y) beginPosition, FrameBufferChannel format, ImageChannelLayout dataType)
|
||||
{
|
||||
Context.glVertexAttribDivisor(layoutIndex, divisor);
|
||||
glArrayHandle handle = i.GetArrayHandle();
|
||||
Context.glReadPixels(
|
||||
beginPosition.X, beginPosition.Y, i.Width, i.Height, (uint)format, (uint)dataType, (byte*)handle.AddressOfArray()
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void FrameBufferTexture2d(FrameBufferTarget target, uint attachment, Texture2DTarget texTarget,glHandle textureHandle ,int level)
|
||||
{
|
||||
Context.glFramebufferTexture2D(
|
||||
(uint)target, attachment, (uint)texTarget,textureHandle.Value, level
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ReadPixels(
|
||||
(int X, int Y) beginPosition, (int width, int height) size, FrameBufferChannel format, ImageChannelLayout dataType, ref byte[] stream
|
||||
)
|
||||
{
|
||||
fixed (byte* bptr = stream)
|
||||
{
|
||||
Context.glReadPixels(
|
||||
beginPosition.X, beginPosition.Y,
|
||||
size.width, size.height, (uint)format, (uint)dataType, bptr);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -143,6 +195,11 @@ namespace StgSharp.Graphics
|
||||
Context.glClear((uint)mask);
|
||||
}
|
||||
|
||||
public static void CombineFrameBufferRenderBuffer(glHandle fboHandle, glHandle rboHandle)
|
||||
{
|
||||
Context.glFramebufferRenderbuffer(GLconst.FRAMEBUFFER,fboHandle.Value,GLconst.RENDERBUFFER, rboHandle.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void ClearColor(float R, float G, float B, float A)
|
||||
{
|
||||
@@ -203,31 +260,8 @@ namespace StgSharp.Graphics
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static unsafe IntPtr CreateWindowHandle(
|
||||
int width, int height, string tittle, IntPtr monitor, Form share)
|
||||
{
|
||||
byte[] tittleBytes = Encoding.UTF8.GetBytes(tittle);
|
||||
IntPtr windowPtr;
|
||||
if (share == null)
|
||||
{
|
||||
windowPtr = InternalIO.glfwCreateWindow(
|
||||
width, height, tittleBytes, monitor, IntPtr.Zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
windowPtr = InternalIO.glfwCreateWindow(
|
||||
width, height, tittleBytes, monitor, share.id);
|
||||
}
|
||||
|
||||
if (((long)windowPtr == -1) || ((long)windowPtr == -2))
|
||||
{
|
||||
throw new Exception("Cannot create window instance!");
|
||||
}
|
||||
else
|
||||
{
|
||||
return windowPtr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void DeleteBuffer(glHandle handle)
|
||||
@@ -319,6 +353,15 @@ namespace StgSharp.Graphics
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe glHandleSet GenRenderBuffer(int count)
|
||||
{
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
Context.glGenRenderbuffers(count, (uint*)h.Handle);
|
||||
return h;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe glHandleSet GenTextures(int count)
|
||||
{
|
||||
@@ -328,6 +371,14 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetRenderBufferStorage(RenderBufferInternalFormat internalFormat ,(int width, int height) size)
|
||||
{
|
||||
Context.glRenderbufferStorage(
|
||||
GLconst.RENDERBUFFER, (uint)internalFormat,size.width,size.height
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public static unsafe glHandleSet GenVertexArrays(int count)
|
||||
{
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
@@ -335,6 +386,16 @@ namespace StgSharp.Graphics
|
||||
return h;
|
||||
}
|
||||
|
||||
public static string GetShaderStatus(Shader s, int index, int key)
|
||||
{
|
||||
IntPtr sptr = IntPtr.Zero;
|
||||
if (InternalIO.glCheckShaderStatus(ref Context, s.handle[index].Value, key, ref sptr) == 0)
|
||||
{
|
||||
return Marshal.PtrToStringAnsi(sptr);
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe glSHandle GetUniformLocation(glHandle program, string name)
|
||||
@@ -359,17 +420,16 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void LoadShaderSource(glHandle shaderHandle, string codeStream)
|
||||
public static unsafe void LoadShaderSource(glHandle shaderHandle, byte[] codeStream)
|
||||
{
|
||||
byte[] stream = Encoding.UTF8.GetBytes(codeStream);
|
||||
fixed (byte* streamPtr = stream)
|
||||
fixed (byte* streamPtr = codeStream)
|
||||
{
|
||||
Context.glShaderSource(shaderHandle.Value, 1, &streamPtr, (void*)0);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void MakeContextCurrent(Form form)
|
||||
public static unsafe void MakeContextCurrent(ViewModel form)
|
||||
{
|
||||
if (form.WindowID == IntPtr.Zero)
|
||||
{
|
||||
@@ -420,6 +480,34 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferData<T>(BufferType bufferType, ReadOnlySpan<T> bufferArray, BufferUsage usage)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
|
||||
if (bufferArray == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#pragma warning disable CS8500
|
||||
fixed (void* bufferPtr = bufferArray)
|
||||
#pragma warning restore CS8500
|
||||
{
|
||||
Context.glBufferData(
|
||||
(uint)bufferType,
|
||||
(IntPtr)size,
|
||||
(IntPtr)bufferPtr,
|
||||
(uint)usage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferData<T>(BufferType bufferType, Span<T> bufferArray, BufferUsage usage)
|
||||
where T : struct,
|
||||
@@ -449,7 +537,7 @@ namespace StgSharp.Graphics
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferVectorData<T>(BufferType bufferType, Span<T> bufferArray, BufferUsage usage)
|
||||
public static unsafe void SetBufferVectorData<T>(BufferType bufferType, ReadOnlySpan<T> bufferArray, BufferUsage usage)
|
||||
where T : struct, IVector
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
|
||||
@@ -499,10 +587,20 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void TextureImage2d<T>(int target, int level, uint internalformat, uint width, uint height, uint format, uint type, glHandle pixels)
|
||||
public static void TextureImage2d(Texture2DTarget target, int level, uint internalformat, uint width, uint height,
|
||||
uint format, ImageChannelLayout type, glHandle pixels)
|
||||
{
|
||||
Context.glTexImage2D(
|
||||
(uint)target, level, internalformat, width, height, 0, format, type, pixels.valuePtr
|
||||
(uint)target, level, internalformat, width, height, 0, format, (uint)type, pixels.valuePtr
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void TextureImage2d(Texture2DTarget target, int level, uint internalformat, uint width, uint height,
|
||||
uint format, ImageChannelLayout type, glArrayHandle pixelArrayHandle)
|
||||
{
|
||||
Context.glTexImage2D(
|
||||
(uint)target, level, internalformat, width, height, 0, format, (uint)type, (void*)pixelArrayHandle.handle.AddrOfPinnedObject()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -518,6 +616,12 @@ namespace StgSharp.Graphics
|
||||
Context.glUseProgram(program.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void VertexAttributeDivisor(uint layoutIndex, uint divisor)
|
||||
{
|
||||
Context.glVertexAttribDivisor(layoutIndex, divisor);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Viewport(int x, int y, uint width, uint height)
|
||||
{
|
||||
|
||||
@@ -35,7 +35,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public partial class glRenderStream
|
||||
{
|
||||
@@ -51,15 +51,28 @@ namespace StgSharp.Graphics
|
||||
return new ElementBuffer(count, this);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected RenderBuffer CreateRenderBuffer(int count)
|
||||
{
|
||||
return new RenderBuffer(count, this);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected FrameBuffer CreateFrameBuffer(int count)
|
||||
{
|
||||
return new FrameBuffer(count, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a sets of <see cref="Texture"/>
|
||||
/// Create a sets of <see cref="TextureGL"/>
|
||||
/// </summary>
|
||||
/// <param name="count">Amount of textures to be created.</param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected Texture CreateTexture(int count)
|
||||
protected TextureGL CreateTexture(int count)
|
||||
{
|
||||
return new Texture(count, this);
|
||||
return new TextureGL(count, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using StgSharp.Graphics.GL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
@@ -39,15 +39,15 @@ using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public partial class glRenderStream
|
||||
public abstract partial class glRenderStream : RenderStream
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override Shader CreateShaderSegment(ShaderType type, int count)
|
||||
{
|
||||
return new Shader( GL.CreateShaderSet(count, type), type);
|
||||
return new Shader( glFunc.CreateShaderSet(count, type), type);
|
||||
}
|
||||
/// <summary>
|
||||
/// Create an instance of <see cref="Shader"/> program
|
||||
@@ -72,7 +72,7 @@ namespace StgSharp.Graphics
|
||||
internal unsafe Shader(glHandleSet handle, ShaderType usage)
|
||||
{
|
||||
this.handle = handle;
|
||||
context = GL.CurrentContextHandle;
|
||||
context = glFunc.CurrentContextHandle;
|
||||
type = usage;
|
||||
}
|
||||
|
||||
@@ -84,28 +84,40 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void AttachTo(int index, ShaderProgram target)
|
||||
{
|
||||
GL.AttachShader(target.handle, handle[index]);
|
||||
glFunc.AttachShader(target.handle, handle[index]);
|
||||
}
|
||||
|
||||
public static string FromCodeFile(string fileRoute)
|
||||
public static byte[] FromCodeFile(string fileRoute)
|
||||
{
|
||||
string str = File.ReadAllText(fileRoute);
|
||||
if (str == "")
|
||||
if (string.IsNullOrEmpty(str))
|
||||
{
|
||||
throw new Exception($"Cannot load and GLSL code from {fileRoute}");
|
||||
throw new InvalidOperationException($"Cannot load and GLSL code from {fileRoute}");
|
||||
}
|
||||
return str;
|
||||
return Encoding.UTF8.GetBytes(str);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Compile(int index, string code)
|
||||
public unsafe void Compile(int index, byte[] codeStream)
|
||||
{
|
||||
if (code == null)
|
||||
if (codeStream == null)
|
||||
{
|
||||
throw new ArgumentNullException("Must provide enough code");
|
||||
throw new ArgumentNullException(nameof(codeStream));
|
||||
}
|
||||
GL.LoadShaderSource(handle[index], $"{code}\0");
|
||||
GL.CompileShader(handle[index]);
|
||||
glFunc.LoadShaderSource(handle[index], codeStream);
|
||||
glFunc.CompileShader(handle[index]);
|
||||
CheckStatus(index,ShaderStatus.CompileStatus);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Compile(int index, string codeStream)
|
||||
{
|
||||
if (codeStream == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(codeStream));
|
||||
}
|
||||
glFunc.LoadShaderSource(handle[index],Encoding.ASCII.GetBytes( codeStream));
|
||||
glFunc.CompileShader(handle[index]);
|
||||
CheckStatus(index, ShaderStatus.CompileStatus);
|
||||
}
|
||||
|
||||
@@ -122,7 +134,7 @@ namespace StgSharp.Graphics
|
||||
|
||||
public void CheckStatus(int index, ShaderStatus status)
|
||||
{
|
||||
string log = GL.GetShaderStatus(this,index, (int)status);
|
||||
string log = glFunc.GetShaderStatus(this,index, (int)status);
|
||||
if (log != "")
|
||||
{
|
||||
throw new Exception($"Shader Error\n{status}\n" + log);
|
||||
@@ -147,7 +159,6 @@ namespace StgSharp.Graphics
|
||||
|
||||
public class ShaderProgram
|
||||
{
|
||||
|
||||
private readonly IntPtr binding;
|
||||
internal readonly glHandle handle;
|
||||
|
||||
@@ -157,7 +168,7 @@ namespace StgSharp.Graphics
|
||||
internal unsafe ShaderProgram(glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
handle = GL.CreateProgram();
|
||||
handle = glFunc.CreateProgram();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -242,7 +253,7 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Use()
|
||||
{
|
||||
GL.UseProgram(handle);
|
||||
glFunc.UseProgram(handle);
|
||||
}
|
||||
|
||||
~ShaderProgram()
|
||||
|
||||
@@ -38,7 +38,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public class Uniform
|
||||
{
|
||||
@@ -65,14 +65,14 @@ namespace StgSharp.Graphics
|
||||
ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, IntPtr binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
@@ -101,14 +101,14 @@ namespace StgSharp.Graphics
|
||||
ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, IntPtr binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
@@ -137,14 +137,14 @@ namespace StgSharp.Graphics
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name)
|
||||
{
|
||||
this.binding = GL.CurrentContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
this.binding = glFunc.CurrentContextHandle;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
public unsafe Uniform(ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
@@ -175,14 +175,14 @@ namespace StgSharp.Graphics
|
||||
internal unsafe Uniform(ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name)
|
||||
{
|
||||
this.binding = GL.CurrentContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
this.binding = glFunc.CurrentContextHandle;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
@@ -197,55 +197,57 @@ namespace StgSharp.Graphics
|
||||
|
||||
}
|
||||
|
||||
internal static partial class GL
|
||||
internal static partial class glFunc
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static void SetValue(Uniform<Matrix44> uniform, Matrix44 mat)
|
||||
public unsafe static void SetUniformValue
|
||||
(Uniform<Matrix44> uniform, Matrix44 mat)
|
||||
{
|
||||
Matrix44 temp = mat;
|
||||
Context.glUniformMatrix4fv(uniform.id.Value, 1, false, (float*)&temp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static void SetValue(Uniform<float, float, float, float> uniform, vec4d vec)
|
||||
public unsafe static void SetUniformValue(Uniform<float, float, float, float> uniform, vec4d vec)
|
||||
{
|
||||
vec4d temp = vec;
|
||||
Context.glUniform1fv(uniform.id.Value , 4, &temp);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static void SetUniformValue(Uniform<vec4d> uniform, vec4d vec)
|
||||
{
|
||||
vec4d temp = vec;
|
||||
Context.glUniform1fv(uniform.id.Value , 4, &temp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static void SetValue(Uniform<vec4d> uniform, vec4d vec)
|
||||
{
|
||||
vec4d temp = vec;
|
||||
Context.glUniform1fv(uniform.id.Value , 4, &temp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetValue(Uniform<float> uniform, float v0)
|
||||
public static unsafe void SetUniformValue(Uniform<float> uniform, float v0)
|
||||
{
|
||||
Context.glUniform1f(uniform.id.Value , v0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetValue(Uniform<int> uniform, int i0)
|
||||
public static unsafe void SetUniformValue(Uniform<int> uniform, int i0)
|
||||
{
|
||||
Context.glUniform1i(uniform.id.Value , i0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
public static unsafe void SetUniformValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
{
|
||||
Context.glUniform2f(uniform.id.Value , v0, v1);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
||||
public static unsafe void SetUniformValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
||||
{
|
||||
Context.glUniform3f(uniform.id.Value , v0, v1, v2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
public static unsafe void SetUniformValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
{
|
||||
Context.glUniform4f(uniform.id.Value , v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public static partial class glManager
|
||||
{
|
||||
@@ -56,9 +56,9 @@ namespace StgSharp.Graphics
|
||||
private static string glExtensionList;
|
||||
|
||||
/// <summary>
|
||||
/// Load all supported OpenGL APIs and bind them to given <see cref="Form"/> context.
|
||||
/// Load all supported OpenGL APIs and bind them to given <see cref="ViewModel"/> context.
|
||||
/// </summary>
|
||||
/// <param name="stream">The <see cref="Form"/> used as current OpenGL context</param>
|
||||
/// <param name="stream">The <see cref="ViewModel"/> used as current OpenGL context</param>
|
||||
public static unsafe void LoadGLapi(this glRenderStream stream)
|
||||
{
|
||||
GLcontext* context = (GLcontext*)stream.ContextHandle;
|
||||
@@ -1044,7 +1044,7 @@ namespace StgSharp.Graphics
|
||||
contextPtr->glPointSize = (delegate*<float, void>)load("glPointSize");
|
||||
contextPtr->glPolygonMode = (delegate*<uint, uint, void>)load("glPolygonMode");
|
||||
contextPtr->glReadBuffer = (delegate*<uint, void>)load("glReadBuffer");
|
||||
contextPtr->glReadPixels = (delegate*<int, int, uint, uint, uint, uint, void*, void>)load("glReadPixels");
|
||||
contextPtr->glReadPixels = (delegate*<int, int, int, int, uint, uint, void*, void>)load("glReadPixels");
|
||||
contextPtr->glScissor = (delegate*<int, int, uint, uint, void>)load("glScissor");
|
||||
contextPtr->glStencilFunc = (delegate*<uint, int, uint, void>)load("glStencilFunc");
|
||||
contextPtr->glStencilMask = (delegate*<uint, void>)load("glStencilMask");
|
||||
@@ -1368,7 +1368,7 @@ namespace StgSharp.Graphics
|
||||
contextPtr->glFramebufferTexture3D = (delegate*<uint, uint, uint, uint, int, int, void>)load("glFramebufferTexture3D");
|
||||
contextPtr->glFramebufferTextureLayer = (delegate*<uint, uint, uint, int, int, void>)load("glFramebufferTextureLayer");
|
||||
contextPtr->glGenFramebuffers = (delegate*<uint, uint*, void>)load("glGenFramebuffers");
|
||||
contextPtr->glGenRenderbuffers = (delegate*<uint, uint*, void>)load("glGenRenderbuffers");
|
||||
contextPtr->glGenRenderbuffers = (delegate*<int, uint*, void>)load("glGenRenderbuffers");
|
||||
contextPtr->glGenVertexArrays = (delegate*<int, uint*, void>)load("glGenVertexArrays");
|
||||
contextPtr->glGenerateMipmap = (delegate*<uint, void>)load("glGenerateMipmap");
|
||||
contextPtr->glGetBooleani_v = (delegate*<uint, uint, bool*, void>)load("glGetBooleani_v");
|
||||
@@ -1388,7 +1388,7 @@ namespace StgSharp.Graphics
|
||||
contextPtr->glIsRenderbuffer = (delegate*<uint, bool>)load("glIsRenderbuffer");
|
||||
contextPtr->glIsVertexArray = (delegate*<uint, bool>)load("glIsVertexArray");
|
||||
contextPtr->glMapBufferRange = (delegate*<uint, IntPtr, UIntPtr, uint, void*>)load("glMapBufferRange");
|
||||
contextPtr->glRenderbufferStorage = (delegate*<uint, uint, uint, uint, void>)load("glRenderbufferStorage");
|
||||
contextPtr->glRenderbufferStorage = (delegate*<uint, uint, int, int, void>)load("glRenderbufferStorage");
|
||||
contextPtr->glRenderbufferStorageMultisample = (delegate*<uint, uint, uint, uint, uint, void>)load("glRenderbufferStorageMultisample");
|
||||
contextPtr->glTexParameterIiv = (delegate*<uint, uint, int*, void>)load("glTexParameterIiv");
|
||||
contextPtr->glTexParameterIuiv = (delegate*<uint, uint, uint*, void>)load("glTexParameterIuiv");
|
||||
@@ -1908,7 +1908,7 @@ namespace StgSharp.Graphics
|
||||
contextPtr->glNamedFramebufferTextureLayer = (delegate*<uint, uint, uint, int, int, void>)load("glNamedFramebufferTextureLayer");
|
||||
contextPtr->glNamedRenderbufferStorage = (delegate*<uint, uint, uint, uint, void>)load("glNamedRenderbufferStorage");
|
||||
contextPtr->glNamedRenderbufferStorageMultisample = (delegate*<uint, uint, uint, uint, uint, void>)load("glNamedRenderbufferStorageMultisample");
|
||||
contextPtr->glReadnPixels = (delegate*<int, int, uint, uint, uint, uint, uint, void*, void>)load("glReadnPixels");
|
||||
contextPtr->glReadnPixels = (delegate*<int, int, int, int, uint, uint, uint, void*, void>)load("glReadnPixels");
|
||||
contextPtr->glTextureBarrier = (delegate*<void>)load("glTextureBarrier");
|
||||
contextPtr->glTextureBuffer = (delegate*<uint, uint, uint, void>)load("glTextureBuffer");
|
||||
contextPtr->glTextureBufferRange = (delegate*<uint, uint, uint, IntPtr, UIntPtr, void>)load("glTextureBufferRange");
|
||||
|
||||
@@ -32,7 +32,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public static partial class glManager
|
||||
{
|
||||
|
||||
@@ -39,14 +39,18 @@ using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
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 IntPtr glContextHandle
|
||||
{
|
||||
@@ -54,19 +58,6 @@ namespace StgSharp.Graphics
|
||||
set { ContextHandle = value; }
|
||||
}
|
||||
|
||||
public static T AsMainStreamOf<T>(Form f, (int x, int y, int z) unitCubeSize) where T : glRenderStream
|
||||
{
|
||||
RenderStreamConstructArgs args = new RenderStreamConstructArgs();
|
||||
args.UnitCubeSize = unitCubeSize;
|
||||
args.Name = f.name;
|
||||
args.Height = f.Height;
|
||||
args.Width = f.Width;
|
||||
T ret = Activator.CreateInstance(typeof(T), args) as T;
|
||||
ret!.InternalInit();
|
||||
f.WindowID = ret.CanvasHandle;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <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.
|
||||
@@ -82,10 +73,10 @@ namespace StgSharp.Graphics
|
||||
GLcontext* contextID = (GLcontext*)ContextHandle;
|
||||
contextID->glGetString = (delegate*<uint, IntPtr>)IntPtr.Zero;
|
||||
}
|
||||
if (GL.CurrentContextHandle != ContextHandle)
|
||||
if (glFunc.CurrentContextHandle != ContextHandle)
|
||||
{
|
||||
GL.CurrentContextHandle = ContextHandle;
|
||||
//Console.WriteLine($"context set as {(ulong)GL.CurrentContextHandle}");
|
||||
glFunc.CurrentContextHandle = ContextHandle;
|
||||
//Console.WriteLine($"context set as {(ulong)glFunc.CurrentContextHandle}");
|
||||
InternalIO.glfwMakeContextCurrent(CanvasHandle);
|
||||
}
|
||||
}
|
||||
@@ -98,11 +89,10 @@ namespace StgSharp.Graphics
|
||||
|
||||
internal override sealed unsafe void CreateCanvas()
|
||||
{
|
||||
byte[] nameCode = Encoding.UTF8.GetBytes(name);
|
||||
byte[] nameCode = Encoding.UTF8.GetBytes(Name);
|
||||
CanvasHandle = InternalIO.glfwCreateWindow(
|
||||
Width, Height, nameCode, Monitor, IntPtr.Zero
|
||||
);
|
||||
NativeCamera = new Camera();
|
||||
}
|
||||
|
||||
internal override sealed void InternalDraw(
|
||||
@@ -113,6 +103,7 @@ namespace StgSharp.Graphics
|
||||
ProcessInput();
|
||||
Main(in input, in output);
|
||||
}
|
||||
|
||||
internal override sealed void InternalInit()
|
||||
{
|
||||
CreateCanvas();
|
||||
|
||||
+208
-85
@@ -29,11 +29,13 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data;
|
||||
using StgSharp.Graphics.GL;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
@@ -41,18 +43,21 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class Image : SSDSerializable
|
||||
public class Image : SSDSerializable, IImageProvider
|
||||
{
|
||||
|
||||
internal ImageInfo info;
|
||||
internal byte[] data;
|
||||
internal glHandle pixelArrayHandle;
|
||||
internal ImageInfo info;
|
||||
|
||||
internal Image(ImageInfo information)
|
||||
{
|
||||
info = information;
|
||||
int length = info.width * info.height * info.channel;
|
||||
pixelArrayHandle = glHandle.FromPtr(information.pixelPtr);
|
||||
data = Array.Empty<byte>();
|
||||
//int length = info.width * info.height * info.channel;
|
||||
}
|
||||
|
||||
public ref byte[] DataStream
|
||||
{
|
||||
get => ref data;
|
||||
}
|
||||
|
||||
public unsafe Image()
|
||||
@@ -60,104 +65,222 @@ namespace StgSharp.Graphics
|
||||
info = new ImageInfo();
|
||||
}
|
||||
|
||||
public int Channel => info.channel;
|
||||
public int Height => info.height;
|
||||
public ImageChannel Channel => info.Channel;
|
||||
public int ChannelCount => info.ChannelCount;
|
||||
public int Height => info.Height;
|
||||
|
||||
public int Width => info.width;
|
||||
public (int width, int height) Size
|
||||
{
|
||||
get => (info.Width, info.Height);
|
||||
}
|
||||
|
||||
public override SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
|
||||
public int Width => info.Width;
|
||||
|
||||
public static unsafe Image FromFile(string route, ImageLoader loader)
|
||||
{
|
||||
Image ret = new Image();
|
||||
fixed (ImageInfo* iptr = &ret.info)
|
||||
{
|
||||
InternalIO.InternalLoadImage(route, iptr, loader);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Image FromMemory((int width, int height) size, int channelCount, byte[] stream)
|
||||
{
|
||||
ImageInfo _info = new ImageInfo
|
||||
{
|
||||
Height = size.height,
|
||||
Width = size.width,
|
||||
ChannelCount = channelCount,
|
||||
StreamPtr = IntPtr.Zero
|
||||
};
|
||||
Image ret = new Image(_info);
|
||||
ret.data = stream;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public glArrayHandle GetArrayHandle()
|
||||
{
|
||||
if ((data == Array.Empty<byte>()) || (data == null))
|
||||
{
|
||||
this.GetBytes();
|
||||
return new glArrayHandle(data);
|
||||
}
|
||||
return new glArrayHandle(data);
|
||||
}
|
||||
|
||||
public override unsafe byte[] GetBytes()
|
||||
{
|
||||
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;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public override unsafe byte[] GetBytes(out int length)
|
||||
{
|
||||
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()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
~Image()
|
||||
{
|
||||
if (info.pixelPtr!= IntPtr.Zero)
|
||||
if (info.StreamPtr != IntPtr.Zero)
|
||||
{
|
||||
// Marshal.FreeHGlobal(info.pixelPtr);
|
||||
// Marshal.FreeHGlobal(info.StreamPtr);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe override byte[] GetBytes()
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
int size = Width * Height * Channel + 1 + 8;
|
||||
data = new byte[size];
|
||||
int i = 0;
|
||||
fixed (byte* bptr = data)
|
||||
{
|
||||
*(int*)bptr = Width;
|
||||
*(int*)(bptr + 4) = Height;
|
||||
*(bptr + 8) = (byte)Channel;
|
||||
byte* pptr = bptr;
|
||||
for (; i < size; i += 16)
|
||||
{
|
||||
*(M128*)(pptr + i) = *(M128*)(info.pixelPtr + i);
|
||||
}
|
||||
for (; i < size; i++)
|
||||
{
|
||||
*(pptr + i) = *(byte*)(info.pixelPtr + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
Marshal.FreeHGlobal(info.pixelPtr);
|
||||
info.pixelPtr = IntPtr.Zero;
|
||||
return data;
|
||||
}
|
||||
|
||||
public unsafe override byte[] GetBytes(out int length)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
int size = Width * Height * Channel + 1 + 8;
|
||||
data = new byte[size];
|
||||
int i = 0;
|
||||
fixed (byte* bptr = data)
|
||||
{
|
||||
*(int*)bptr = Width;
|
||||
*(int*)(bptr + 4) = Height;
|
||||
*(bptr + 8) = (byte)Channel;
|
||||
byte* pptr = bptr;
|
||||
for (; i < size; i += 16)
|
||||
{
|
||||
*(M128*)(pptr + i) = *(M128*)(info.pixelPtr + i);
|
||||
}
|
||||
for (; i < size; i++)
|
||||
{
|
||||
*(pptr + i) = *(byte*)(info.pixelPtr + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
length = data.Length;
|
||||
Marshal.FreeHGlobal(info.pixelPtr);
|
||||
info.pixelPtr = IntPtr.Zero;
|
||||
return data;
|
||||
}
|
||||
|
||||
internal unsafe override void BuildFromByteStream(byte[] stream)
|
||||
{
|
||||
info = new ImageInfo();
|
||||
fixed (byte* bptr = stream)
|
||||
{
|
||||
info.width = *(int*)bptr;
|
||||
info.height = *(int*)(bptr + 4);
|
||||
info.channel = *(bptr + 8);
|
||||
info.pixelPtr = IntPtr.Zero;
|
||||
}
|
||||
data = stream;
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct ImageInfo
|
||||
{
|
||||
internal int width;
|
||||
internal int height;
|
||||
internal int channel;
|
||||
internal IntPtr pixelPtr;
|
||||
|
||||
private ImageChannel channel;
|
||||
private int channelCount;
|
||||
private int height;
|
||||
private int width;
|
||||
private IntPtr pixelPtr;
|
||||
|
||||
public ImageChannel Channel
|
||||
{
|
||||
get => channel;
|
||||
set
|
||||
{
|
||||
channel = value;
|
||||
switch (channel)
|
||||
{
|
||||
case ImageChannel.SingleColor:
|
||||
channelCount = 1; break;
|
||||
case ImageChannel.DoubleColor:
|
||||
channelCount = 2; break;
|
||||
case ImageChannel.FullColor:
|
||||
channelCount = 3; break;
|
||||
case ImageChannel.WithAlphaChannel:
|
||||
channelCount = 4; break;
|
||||
default:
|
||||
throw new InvalidCastException("Unknown color channel decoding setting.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int ChannelCount
|
||||
{
|
||||
get => channelCount;
|
||||
set
|
||||
{
|
||||
channelCount = value;
|
||||
switch (channelCount)
|
||||
{
|
||||
case 1:
|
||||
channel = ImageChannel.SingleColor; break;
|
||||
case 2:
|
||||
channel = ImageChannel.DoubleColor; break;
|
||||
case 3:
|
||||
channel = ImageChannel.FullColor; break;
|
||||
case 4:
|
||||
channel = ImageChannel.WithAlphaChannel; break;
|
||||
default:
|
||||
throw new InvalidCastException("Unknown color channel decoding setting.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get => height;
|
||||
set => height = value;
|
||||
}
|
||||
|
||||
public IntPtr StreamPtr
|
||||
{
|
||||
get => pixelPtr;
|
||||
internal set => pixelPtr = value;
|
||||
}
|
||||
|
||||
public int StreamSize
|
||||
{
|
||||
get => width * height * channelCount;
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => width;
|
||||
set => width = value;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{channel}\t{width}\t{height}\t{pixelPtr}";
|
||||
return $"{channel}\t{width}\t{height}\t{(ulong)StreamPtr}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum ImageChannel : uint
|
||||
{
|
||||
SingleColor = GLconst.RED,
|
||||
DoubleColor = GLconst.RG,
|
||||
FullColor = GLconst.RGB,
|
||||
WithAlphaChannel = GLconst.RGBA,
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class PlainGeometryMesh
|
||||
{
|
||||
private IGeometry _shape;
|
||||
private Image _texture;
|
||||
private vec2d[] textureCoord;
|
||||
|
||||
public PlainGeometryMesh(
|
||||
IGeometry shape, Image texture, IEnumerable<vec2d> texCoord
|
||||
)
|
||||
{
|
||||
if (shape==null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(shape));
|
||||
}
|
||||
if (texCoord == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(texCoord));
|
||||
}
|
||||
|
||||
_shape = shape;
|
||||
textureCoord = new vec2d[shape.VertexCount];
|
||||
_texture = texture;
|
||||
if (texCoord is not vec2d[] source)
|
||||
{
|
||||
source = texCoord.ToArray();
|
||||
}
|
||||
if (textureCoord.Length > source.Length)
|
||||
{
|
||||
throw new ArgumentException(paramName: nameof(texCoord), message: "Amount of texture coordination is too less");
|
||||
}
|
||||
Array.Copy(sourceArray: source, textureCoord, textureCoord.Length);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
public ReadOnlySpan<int> MeshIndices => _shape.VertexIndices;
|
||||
|
||||
public vec4d[] VertexArray => _shape.VertexStream;
|
||||
|
||||
public Image Texture
|
||||
{
|
||||
get => _texture;
|
||||
internal set => _texture = value;
|
||||
}
|
||||
|
||||
public vec2d[] TextureCoord => textureCoord;
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.GL;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
|
||||
@@ -45,25 +46,53 @@ namespace StgSharp.Graphics
|
||||
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
|
||||
@@ -97,10 +120,10 @@ namespace StgSharp.Graphics
|
||||
|
||||
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.
|
||||
@@ -210,15 +274,28 @@ namespace StgSharp.Graphics
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.GL;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using StgSharp.Graphics.GL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -36,7 +38,7 @@ namespace StgSharp.Graphics.ShaderEdit
|
||||
|
||||
public unsafe void SetAllUniforms()
|
||||
{
|
||||
GLcontext* gl = (GLcontext*) GL.CurrentContextHandle;
|
||||
GLcontext* gl = (GLcontext*) glFunc.CurrentContextHandle;
|
||||
foreach (var uniform in uniformPair)
|
||||
{
|
||||
int id = uniform.Key.Value;
|
||||
@@ -59,6 +61,6 @@ namespace StgSharp.Graphics.ShaderEdit
|
||||
"Incorrect type \"Unknown\" defined in this self define type");
|
||||
}
|
||||
}
|
||||
}
|
||||
}//------------------------------------ End of Class ---------------------------------------
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using StgSharp.Logic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class TexturePipeline:BlueprintPipelineArgs
|
||||
{
|
||||
public TexturePipeline(Image i)
|
||||
{
|
||||
value = i;
|
||||
}
|
||||
|
||||
private Image value;
|
||||
|
||||
public Image Value
|
||||
{
|
||||
get => value;
|
||||
set => value = value ?? throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ using System.Xml.Serialization;
|
||||
|
||||
namespace StgSharp.Logic
|
||||
{
|
||||
public class Blueprint : IConvertableToBlueprintNode
|
||||
public partial class Blueprint : IConvertableToBlueprintNode
|
||||
{
|
||||
private BeginningNode beginNode;
|
||||
private Dictionary<string, BlueprintNode> allNode;
|
||||
|
||||
@@ -30,9 +30,12 @@
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
using StgSharp.Entities;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -52,59 +55,64 @@ namespace StgSharp.Logic
|
||||
/// Reset pipeline has risk, this operation is a direct operation to port
|
||||
/// in current node, the port on the other node cannot get the change.
|
||||
/// </risk>
|
||||
#pragma warning disable CA1036
|
||||
public class BlueprintNode : IComparable<BlueprintNode>
|
||||
#pragma warning restore CA1036
|
||||
{
|
||||
|
||||
private Blueprint local;
|
||||
private BlueprintNodeAction mainOperation;
|
||||
|
||||
private bool levelAvailabel, nativeRequested;
|
||||
private int level;
|
||||
private protected bool levelAvailable, nativeRequested;
|
||||
private protected int _level;
|
||||
private string name;
|
||||
|
||||
protected Dictionary<string, BlueprintPipeline> inputInterfaces;
|
||||
protected Dictionary<string, BlueprintPipeline> outputInterfaces;
|
||||
private protected Dictionary<string, BlueprintPipeline> _inputInterfaces;
|
||||
private protected Dictionary<string, BlueprintPipeline> _outputInterfaces;
|
||||
|
||||
|
||||
internal BlueprintNode(string name,
|
||||
BlueprintNodeAction operation, bool isNative,
|
||||
string[] inputPorts,
|
||||
string[] outputPorts)
|
||||
{
|
||||
this.levelAvailabel = false;
|
||||
this.levelAvailable = false;
|
||||
this.name = name;
|
||||
nativeRequested = isNative;
|
||||
mainOperation = operation;
|
||||
inputInterfaces = new Dictionary<string, BlueprintPipeline>();
|
||||
outputInterfaces = new Dictionary<string, BlueprintPipeline>();
|
||||
if (inputPorts.Length * outputPorts.Length == 0)
|
||||
_inputInterfaces = new Dictionary<string, BlueprintPipeline>();
|
||||
_outputInterfaces = new Dictionary<string, BlueprintPipeline>();
|
||||
if (inputPorts.Length == 0 )
|
||||
{
|
||||
throw new Exception();
|
||||
throw new ArgumentNullException(nameof(inputPorts));
|
||||
}
|
||||
if (outputPorts.Length == 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(outputPorts));
|
||||
}
|
||||
foreach (var portName in inputPorts)
|
||||
{
|
||||
inputInterfaces.Add(portName, null);
|
||||
_inputInterfaces.Add(portName, null);
|
||||
}
|
||||
foreach (var portName in outputPorts)
|
||||
{
|
||||
outputInterfaces.Add(portName, null);
|
||||
_outputInterfaces.Add(portName, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public BlueprintNode(string name, IConvertableToBlueprintNode convertable)
|
||||
{
|
||||
this.levelAvailabel = false;
|
||||
this.levelAvailable = false;
|
||||
this.name = name;
|
||||
inputInterfaces = new Dictionary<string, BlueprintPipeline>();
|
||||
outputInterfaces = new Dictionary<string, BlueprintPipeline>();
|
||||
_inputInterfaces = new Dictionary<string, BlueprintPipeline>();
|
||||
_outputInterfaces = new Dictionary<string, BlueprintPipeline>();
|
||||
mainOperation = convertable.MainExecution;
|
||||
foreach (var soket in convertable.InputInterfacesName)
|
||||
{
|
||||
inputInterfaces.Add(soket, null);
|
||||
_inputInterfaces.Add(soket, null);
|
||||
}
|
||||
foreach (var soket in convertable.OutputInterfacesName)
|
||||
{
|
||||
outputInterfaces.Add(soket, null);
|
||||
_outputInterfaces.Add(soket, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,21 +121,21 @@ namespace StgSharp.Logic
|
||||
string[] outputPorts
|
||||
)
|
||||
{
|
||||
this.levelAvailabel = false;
|
||||
this.levelAvailable = false;
|
||||
this.name = name;
|
||||
inputInterfaces = new Dictionary<string, BlueprintPipeline>();
|
||||
outputInterfaces = new Dictionary<string, BlueprintPipeline>();
|
||||
_inputInterfaces = new Dictionary<string, BlueprintPipeline>();
|
||||
_outputInterfaces = new Dictionary<string, BlueprintPipeline>();
|
||||
if (inputPorts.Length * outputPorts.Length == 0)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
foreach (var portName in inputPorts)
|
||||
{
|
||||
inputInterfaces.Add(portName, null);
|
||||
_inputInterfaces.Add(portName, null);
|
||||
}
|
||||
foreach (var portName in outputPorts)
|
||||
{
|
||||
outputInterfaces.Add(portName, null);
|
||||
_outputInterfaces.Add(portName, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,35 +144,36 @@ namespace StgSharp.Logic
|
||||
get => nativeRequested;
|
||||
internal set => nativeRequested = value;
|
||||
}
|
||||
|
||||
public int Level
|
||||
{
|
||||
get
|
||||
{
|
||||
if (levelAvailabel)
|
||||
if (levelAvailable)
|
||||
{
|
||||
return level;
|
||||
return _level;
|
||||
}
|
||||
level = 0;
|
||||
foreach (var item in inputInterfaces)
|
||||
_level = 0;
|
||||
foreach (var item in _inputInterfaces)
|
||||
{
|
||||
if (item.Value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (level <= item.Value.Level)
|
||||
if (_level <= item.Value.Level)
|
||||
{
|
||||
level = item.Value.Level;
|
||||
_level = item.Value.Level;
|
||||
}
|
||||
}
|
||||
level += 1;
|
||||
return level;
|
||||
_level += 1;
|
||||
return _level;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name => name;
|
||||
|
||||
internal Dictionary<string, BlueprintPipeline> InputInterfaces => inputInterfaces;
|
||||
internal Dictionary<string, BlueprintPipeline> OutputInterfaces => outputInterfaces;
|
||||
internal Dictionary<string, BlueprintPipeline> InputInterfaces => _inputInterfaces;
|
||||
internal Dictionary<string, BlueprintPipeline> OutputInterfaces => _outputInterfaces;
|
||||
|
||||
|
||||
public void AddAfter(
|
||||
@@ -172,7 +181,7 @@ namespace StgSharp.Logic
|
||||
string formerOutputPortName,
|
||||
string thisInputPortName)
|
||||
{
|
||||
this.levelAvailabel = false;
|
||||
this.levelAvailable = false;
|
||||
BlueprintPipeline pipeline = new BlueprintPipeline(former, this);
|
||||
if (former is BeginningNode bnode)
|
||||
{
|
||||
@@ -191,7 +200,7 @@ namespace StgSharp.Logic
|
||||
string thisOutputPortName,
|
||||
string afterInputPortName)
|
||||
{
|
||||
this.levelAvailabel = false;
|
||||
this.levelAvailable = false;
|
||||
BlueprintPipeline pipeline = new BlueprintPipeline(this, after);
|
||||
if (after is EndingNode enode)
|
||||
{
|
||||
@@ -210,8 +219,8 @@ namespace StgSharp.Logic
|
||||
try
|
||||
{
|
||||
//Console.WriteLine(name);
|
||||
BlueprintPipeline.WaitAll(inputInterfaces);
|
||||
mainOperation(in inputInterfaces, in outputInterfaces);
|
||||
BlueprintPipeline.WaitAll(_inputInterfaces);
|
||||
mainOperation(in _inputInterfaces, in _outputInterfaces);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -219,55 +228,58 @@ namespace StgSharp.Logic
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int IComparable<BlueprintNode>.CompareTo(BlueprintNode other)
|
||||
public int CompareTo(BlueprintNode other)
|
||||
{
|
||||
#pragma warning disable CA1062
|
||||
return this.Level.CompareTo(other.Level);
|
||||
#pragma warning restore CA1062
|
||||
}
|
||||
|
||||
#region port operation
|
||||
|
||||
public BlueprintPipeline GetCertainInputPort(string name)
|
||||
{
|
||||
if (!inputInterfaces.ContainsKey(name))
|
||||
BlueprintPipeline ret;
|
||||
if (!_inputInterfaces.TryGetValue(name,out ret))
|
||||
{
|
||||
throw new Exception($"Cannot find the interface named {name} in node {Name}.");
|
||||
}
|
||||
return inputInterfaces[name];
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public BlueprintPipeline GetCertainOutputPort(string name)
|
||||
{
|
||||
if (!outputInterfaces.ContainsKey(name))
|
||||
BlueprintPipeline ret;
|
||||
if (!_outputInterfaces.TryGetValue(name, out ret))
|
||||
{
|
||||
throw new Exception($"Cannot find the interface named {name} in node {Name}.");
|
||||
}
|
||||
return outputInterfaces[name];
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void SetCertainInputPort(string name, BlueprintPipeline pipeline)
|
||||
{
|
||||
if (!inputInterfaces.ContainsKey(name))
|
||||
if (!_inputInterfaces.ContainsKey(name))
|
||||
{
|
||||
throw new Exception($"Cannot find the interface named {name} in node {Name}.");
|
||||
}
|
||||
inputInterfaces[name] = pipeline;
|
||||
_inputInterfaces[name] = pipeline;
|
||||
}
|
||||
|
||||
public void SetCertainOutputPort(string name, BlueprintPipeline pipeline)
|
||||
{
|
||||
if (!outputInterfaces.ContainsKey(name))
|
||||
if (!_outputInterfaces.ContainsKey(name))
|
||||
{
|
||||
throw new Exception($"Cannot find the interface named {name} in node {Name}.");
|
||||
}
|
||||
outputInterfaces[name] = pipeline;
|
||||
_outputInterfaces[name] = pipeline;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}//--------------------------------- end of class -----------------------------
|
||||
}//--------------------------------- end of class -----------------------------------
|
||||
|
||||
public interface IConvertableToBlueprintNode
|
||||
{
|
||||
@@ -280,15 +292,25 @@ namespace StgSharp.Logic
|
||||
|
||||
public class BlueprintNodeRunException : Exception
|
||||
{
|
||||
public BlueprintNodeRunException()
|
||||
{
|
||||
}
|
||||
|
||||
public BlueprintNodeRunException(Exception ex) : base(string.Empty, ex)
|
||||
{
|
||||
}
|
||||
|
||||
public BlueprintNodeRunException(string message, Exception ex) : base(message, ex)
|
||||
public BlueprintNodeRunException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public BlueprintNodeRunException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected BlueprintNodeRunException(SerializationInfo info, StreamingContext context) : base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace StgSharp.Logic
|
||||
|
||||
public int Level => former.Level;
|
||||
|
||||
public BlueprintPipelineArgs Value
|
||||
public BlueprintPipelineArgs Args
|
||||
{
|
||||
get => args;
|
||||
set => args = value;
|
||||
@@ -120,5 +120,7 @@ namespace StgSharp.Logic
|
||||
|
||||
public abstract class BlueprintPipelineArgs
|
||||
{
|
||||
public object? Value { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="RouteSwitch.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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Emit;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Logic
|
||||
{
|
||||
public class RouteSwitch : BlueprintNode
|
||||
{
|
||||
private protected Dictionary<string, (BlueprintPipeline pipeline, Func<bool> openingRule)> outputDictionary;
|
||||
|
||||
public RouteSwitch(string name, string inputPorts) :
|
||||
base(name, [inputPorts], [string.Empty])
|
||||
{
|
||||
outputDictionary = new Dictionary<string, (BlueprintPipeline pipeline, Func<bool> openingRule)>();
|
||||
}
|
||||
|
||||
public new int Level
|
||||
{
|
||||
get
|
||||
{
|
||||
if (levelAvailable)
|
||||
{
|
||||
return _level;
|
||||
}
|
||||
_level = 0;
|
||||
KeyValuePair<string, BlueprintPipeline> item = _inputInterfaces.First();
|
||||
if (item.Value == null)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
if (_level <= item.Value.Level)
|
||||
{
|
||||
_level = item.Value.Level;
|
||||
}
|
||||
return _level;
|
||||
}
|
||||
}
|
||||
|
||||
public new void AddBefore(
|
||||
BlueprintNode after,
|
||||
string thisOutputPortName,
|
||||
string afterInputPortName)
|
||||
{
|
||||
this.AppendNode(after, afterInputPortName, () => true);
|
||||
}
|
||||
|
||||
public void AppendNode(BlueprintNode node, string portName, Func<bool> openningRule)
|
||||
{
|
||||
if (node == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(node));
|
||||
}
|
||||
string indexName = $"{node.Name}.{portName}";
|
||||
BlueprintPipeline p = new BlueprintPipeline(this, node);
|
||||
node.InputInterfaces[portName] = p;
|
||||
outputDictionary.Add(indexName, (p, openningRule));
|
||||
}
|
||||
|
||||
public new void Run()
|
||||
{
|
||||
try
|
||||
{
|
||||
BlueprintPipeline input = InputInterfaces.First().Value;
|
||||
input.WaitForStart();
|
||||
foreach (KeyValuePair<string, (BlueprintPipeline pipeline, Func<bool> openingRule)> item in outputDictionary)
|
||||
{
|
||||
if (item.Value.openingRule())
|
||||
{
|
||||
item.Value.pipeline.CompleteAndWriteData(input.Args);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public sealed class RouteHub : BlueprintNode
|
||||
{
|
||||
|
||||
private Dictionary<string, (BlueprintPipeline pipeline, Func<bool> controllingFunc)> inputDictionary;
|
||||
|
||||
public RouteHub(string name, string[] inputPorts, string[] outputPorts) : base(name, inputPorts, outputPorts)
|
||||
{
|
||||
inputDictionary = new Dictionary<string, (BlueprintPipeline pipeline, Func<bool> controllingFunc)>();
|
||||
}
|
||||
|
||||
|
||||
public new int Level
|
||||
{
|
||||
get
|
||||
{
|
||||
if (levelAvailable)
|
||||
{
|
||||
return _level;
|
||||
}
|
||||
_level = 0;
|
||||
foreach (KeyValuePair<string, BlueprintPipeline> item in _inputInterfaces)
|
||||
{
|
||||
if (item.Value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (_level <= item.Value.Level)
|
||||
{
|
||||
_level = item.Value.Level;
|
||||
}
|
||||
}
|
||||
return _level;
|
||||
}
|
||||
}
|
||||
|
||||
public void PrependNode(BlueprintNode node, string portName, Func<bool> usingRule)
|
||||
{
|
||||
if (node == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(node));
|
||||
}
|
||||
string indexName = $"{node.Name}.{portName}";
|
||||
BlueprintPipeline p = new BlueprintPipeline(this, node);
|
||||
node.InputInterfaces[portName] = p;
|
||||
inputDictionary.Add(indexName, (p, usingRule));
|
||||
}
|
||||
|
||||
public new void Run()
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (KeyValuePair<string, (BlueprintPipeline pipeline, Func<bool> controllingFunc)> item in inputDictionary)
|
||||
{
|
||||
item.Value.pipeline.WaitForStart();
|
||||
if (item.Value.controllingFunc())
|
||||
{
|
||||
_outputInterfaces.First().Value.CompleteAndWriteData(item.Value.pipeline.Args);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,8 @@ namespace StgSharp.Logic
|
||||
{
|
||||
public BeginningNode() : base(name: "BeginningNode", null,
|
||||
true, ["default"], ["default"]
|
||||
) { }
|
||||
)
|
||||
{ }
|
||||
|
||||
internal (string name, BlueprintPipelineArgs arg)[] InputData
|
||||
{
|
||||
@@ -25,23 +26,23 @@ namespace StgSharp.Logic
|
||||
}
|
||||
foreach (var parameter in value)
|
||||
{
|
||||
OutputInterfaces[parameter.name].Value = parameter.arg;
|
||||
OutputInterfaces[parameter.name].Args = parameter.arg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public new void SetCertainOutputPort(string name, BlueprintPipeline pipeline)
|
||||
{
|
||||
if (outputInterfaces.ContainsKey(name))
|
||||
if (_outputInterfaces.ContainsKey(name))
|
||||
{
|
||||
outputInterfaces[name] = pipeline;
|
||||
_outputInterfaces[name] = pipeline;
|
||||
}
|
||||
outputInterfaces.Add(name,pipeline);
|
||||
_outputInterfaces.Add(name, pipeline);
|
||||
}
|
||||
|
||||
public new void Run()
|
||||
{
|
||||
BlueprintPipeline.SkipAll(outputInterfaces);
|
||||
BlueprintPipeline.SkipAll(_outputInterfaces);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,30 +56,31 @@ namespace StgSharp.Logic
|
||||
{
|
||||
},
|
||||
true, ["default"], ["default"]
|
||||
) { }
|
||||
)
|
||||
{ }
|
||||
|
||||
internal (string name, BlueprintPipelineArgs arg)[] OutputData
|
||||
{
|
||||
get
|
||||
{
|
||||
return InputInterfaces.Select(
|
||||
key => (key.Key, key.Value.Value) ).
|
||||
key => (key.Key, key.Value.Args)).
|
||||
ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public new void SetCertainInputPort(string name, BlueprintPipeline pipeline)
|
||||
{
|
||||
if (inputInterfaces.ContainsKey(name))
|
||||
if (_inputInterfaces.ContainsKey(name))
|
||||
{
|
||||
inputInterfaces[name] = pipeline;
|
||||
_inputInterfaces[name] = pipeline;
|
||||
}
|
||||
inputInterfaces.Add(name, pipeline);
|
||||
_inputInterfaces.Add(name, pipeline);
|
||||
}
|
||||
|
||||
public new void Run()
|
||||
{
|
||||
BlueprintPipeline.WaitAll(inputInterfaces);
|
||||
BlueprintPipeline.WaitAll(_inputInterfaces);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="TimeFunction.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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public class TimeFunction
|
||||
{
|
||||
private float _beginning, _ending;
|
||||
private Func<float, float> _timeRelatedCalculation;
|
||||
private TimeSpanProvider _timeProvider;
|
||||
|
||||
public TimeFunction(
|
||||
TimeSpanProvider timeSpanProvider,
|
||||
Func<float, float> timeRelatedCalculation,
|
||||
float range)
|
||||
{
|
||||
_timeProvider = timeSpanProvider;
|
||||
_timeRelatedCalculation = timeRelatedCalculation;
|
||||
if (timeSpanProvider == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_beginning = _timeProvider.CurrentSecond;
|
||||
_ending = _timeProvider.CurrentSecond + range;
|
||||
}
|
||||
|
||||
internal TimeFunction() { }
|
||||
|
||||
public bool IsComplete
|
||||
{
|
||||
get => _timeProvider.CurrentSecond > _ending;
|
||||
}
|
||||
|
||||
public Func<float, float> TimeRelatedCalculation
|
||||
{
|
||||
get { return _timeRelatedCalculation; }
|
||||
set { _timeRelatedCalculation = value; }
|
||||
}
|
||||
|
||||
public TimeSpanProvider TimeSpanProvider
|
||||
{
|
||||
get { return _timeProvider; }
|
||||
set { _timeProvider = value; }
|
||||
}
|
||||
|
||||
public float Calculate()
|
||||
{
|
||||
if (_timeProvider.CurrentSecond < _ending)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return _timeRelatedCalculation(_timeProvider.CurrentSecond - _beginning);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
float range = _ending - _beginning;
|
||||
_beginning = _timeProvider.CurrentSecond;
|
||||
_ending = _beginning + range;
|
||||
}
|
||||
|
||||
public TimeFunction Renew(Func<float,float> func,float range)
|
||||
{
|
||||
return new TimeFunction(_timeProvider,func,range);
|
||||
}
|
||||
|
||||
public TimeFunction Renew((Func<float, float> func, float range) funcPair)
|
||||
{
|
||||
return new TimeFunction(_timeProvider, funcPair.func, funcPair.range);
|
||||
}
|
||||
|
||||
public static TimeFunction One
|
||||
{
|
||||
get => new TimeFunctionOne();
|
||||
}
|
||||
|
||||
public static TimeFunction Proportional(TimeSpanProvider time,float begin, float range)
|
||||
{
|
||||
return new TimeFunction(
|
||||
time, (float t) => t + begin, range
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class TimeFunctionOne : TimeFunction
|
||||
{
|
||||
internal TimeFunctionOne() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public new bool IsCompleted
|
||||
{
|
||||
get => true;
|
||||
}
|
||||
|
||||
public new void Reset()
|
||||
{
|
||||
}
|
||||
|
||||
public new TimeFunction Renew(Func<float, float> func, float range)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
public new TimeFunction Renew((Func<float, float> func, float range) funcPair)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public float Calculate()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,15 +43,17 @@ namespace StgSharp
|
||||
public class TimeSpanProvider
|
||||
{
|
||||
|
||||
private Action _frameUpdateMissCallback = null;
|
||||
|
||||
private readonly int _maxSpanCount;
|
||||
private Action _frameUpdateMissCallback = () => { };
|
||||
private Action _refreshCallback;
|
||||
private SemaphoreSlim _refreshSemaphore = new SemaphoreSlim(0, 1);
|
||||
private long _spanBegin;
|
||||
private readonly long _spanLength;
|
||||
private bool _subscribed;
|
||||
private Counter<int> timeSpanCount = new Counter<int>(-1, 1, 1);
|
||||
private readonly int _maxSpanCount;
|
||||
private long _spanBegin;
|
||||
private readonly long _spanLength;
|
||||
private SemaphoreSlim _refreshSemaphore = new SemaphoreSlim(0, 1);
|
||||
private readonly TimeSourceProviderBase _timeSource;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="TimeSpanProvider"/> and define the length of time span. Length of a single time span is defined in microseconds.
|
||||
@@ -60,6 +62,11 @@ namespace StgSharp
|
||||
/// <param name="provider"></param>
|
||||
public TimeSpanProvider(long spanMicroSeconds, TimeSourceProviderBase provider)
|
||||
{
|
||||
if (provider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(provider));
|
||||
}
|
||||
_timeSource = provider;
|
||||
_spanLength = spanMicroSeconds;
|
||||
_maxSpanCount = int.MaxValue;
|
||||
provider.AddSubscriber(this);
|
||||
@@ -75,6 +82,10 @@ namespace StgSharp
|
||||
/// <param name="provider"></param>
|
||||
public TimeSpanProvider(double spanSeconds, TimeSourceProviderBase provider)
|
||||
{
|
||||
if (provider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(provider));
|
||||
}
|
||||
_spanLength = (long)(spanSeconds * 1000L * 1000L);
|
||||
_spanBegin = -_spanLength;
|
||||
_maxSpanCount = int.MaxValue;
|
||||
@@ -91,6 +102,10 @@ namespace StgSharp
|
||||
/// <param name="provider"></param>
|
||||
public TimeSpanProvider(long spanLength, int maxSpan, TimeSourceProviderBase provider)
|
||||
{
|
||||
if (provider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(provider));
|
||||
}
|
||||
if (maxSpan <= 0)
|
||||
{
|
||||
maxSpan = int.MaxValue;
|
||||
@@ -101,7 +116,14 @@ namespace StgSharp
|
||||
}
|
||||
|
||||
public int CurrentSpan
|
||||
=> timeSpanCount.Value;
|
||||
{
|
||||
get => timeSpanCount.Value;
|
||||
}
|
||||
|
||||
public float CurrentSecond
|
||||
{
|
||||
get => timeSpanCount.Value * SpanLengthLowPrecession;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Time source provider provided in <see cref="StgSharp"/> internal framework.
|
||||
@@ -114,6 +136,16 @@ namespace StgSharp
|
||||
set => _frameUpdateMissCallback = value;
|
||||
}
|
||||
|
||||
public double SpanLength
|
||||
{
|
||||
get => (_spanLength * 1.0) / (1000L * 1000L);
|
||||
}
|
||||
|
||||
public float SpanLengthLowPrecession
|
||||
{
|
||||
get => (_spanLength * 1.0f) / (1000 * 1000);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The method this <see cref="TimeSpanProvider"/> will call every time a new time span started.
|
||||
/// </summary>
|
||||
@@ -125,6 +157,10 @@ namespace StgSharp
|
||||
|
||||
public void SubscribeToTimeSource(TimeSourceProviderBase serviceHandler)
|
||||
{
|
||||
if (serviceHandler == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(serviceHandler));
|
||||
}
|
||||
if (_subscribed)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.GL;
|
||||
using StgSharp.Graphics.ShaderEdit;
|
||||
using StgSharp.Math;
|
||||
|
||||
@@ -142,7 +143,7 @@ namespace StgSharp.Graphics
|
||||
public unsafe void SetAllUniforms()
|
||||
{
|
||||
//Console.WriteLine(Projection * View);
|
||||
GL.SetValue(convertedUniform, Projection * View);
|
||||
glFunc.SetUniformValue(convertedUniform, Projection * View);
|
||||
}
|
||||
|
||||
public void SetViewDirection(vec3d position, vec3d target, vec3d up)
|
||||
@@ -224,7 +225,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
}
|
||||
|
||||
#region ratation
|
||||
#region rotation
|
||||
|
||||
public void Yaw(Radius r)
|
||||
{
|
||||
@@ -313,6 +314,7 @@ namespace StgSharp.Graphics
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
@@ -102,6 +102,10 @@ namespace StgSharp.Math
|
||||
{
|
||||
return new vec2d(vec.v / value);
|
||||
}
|
||||
public static vec2d operator *(float value, vec2d vec)
|
||||
{
|
||||
return new vec2d(vec.v * value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static vec2d operator +(vec2d left, vec2d right)
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Controlling;
|
||||
|
||||
using StgSharp.Data;
|
||||
|
||||
using System;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="vec4d.cs"
|
||||
// file="Vec4d.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
@@ -28,7 +28,8 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Controlling;
|
||||
|
||||
using StgSharp.Data;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -42,26 +43,41 @@ namespace StgSharp.Math
|
||||
public static class Vec4d
|
||||
{
|
||||
|
||||
public static vec4d One
|
||||
{
|
||||
get => new vec4d(Vector4.One);
|
||||
}
|
||||
public static vec4d Zero
|
||||
{
|
||||
get => new vec4d(Vector4.Zero);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
|
||||
public struct vec4d
|
||||
public struct vec4d : IEquatable<vec4d>, IVector
|
||||
{
|
||||
|
||||
[FieldOffset(0)] internal unsafe fixed float num[4];
|
||||
|
||||
[FieldOffset(0)] internal M128 reg;
|
||||
|
||||
[FieldOffset(0)] internal Vector4 vec;
|
||||
|
||||
[FieldOffset(0)] internal unsafe fixed float num[4];
|
||||
[FieldOffset(12)] public float W;
|
||||
|
||||
[FieldOffset(0)] public float X;
|
||||
[FieldOffset(4)] public float Y;
|
||||
[FieldOffset(8)] public float Z;
|
||||
[FieldOffset(12)] public float W;
|
||||
|
||||
public override string ToString()
|
||||
internal vec4d(Vector4 v)
|
||||
{
|
||||
return vec.ToString();
|
||||
vec = v;
|
||||
}
|
||||
|
||||
public vec4d(vec3d v, float w)
|
||||
{
|
||||
vec = v.vec;
|
||||
W = w;
|
||||
}
|
||||
|
||||
public vec4d(float x, float y, float z, float w)
|
||||
@@ -69,9 +85,44 @@ namespace StgSharp.Math
|
||||
vec = new Vector4(x, y, z, w);
|
||||
}
|
||||
|
||||
public static implicit operator M128(vec4d vec)
|
||||
public unsafe vec3d XYZ
|
||||
{
|
||||
return vec.reg;
|
||||
get => new vec3d(vec);
|
||||
set
|
||||
{
|
||||
float w = W;
|
||||
vec = value.vec;
|
||||
W = w;
|
||||
}
|
||||
}
|
||||
public unsafe vec2d XY
|
||||
{
|
||||
get => new vec2d(vec);
|
||||
set
|
||||
{
|
||||
X = value.X;
|
||||
Y = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is vec4d v) ? (v == this) : false;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return vec.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return vec.ToString();
|
||||
}
|
||||
|
||||
public static bool operator !=(vec4d left, vec4d right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -86,5 +137,43 @@ namespace StgSharp.Math
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static vec4d operator +(vec4d left, vec4d right)
|
||||
{
|
||||
return new vec4d(left.vec + right.vec);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static vec4d operator -(vec4d left, vec4d right)
|
||||
{
|
||||
return new vec4d(left.vec - right.vec);
|
||||
}
|
||||
|
||||
public static bool operator ==(vec4d left, vec4d right)
|
||||
{
|
||||
return left.vec == right.vec;
|
||||
}
|
||||
|
||||
public static implicit operator M128(vec4d vec)
|
||||
{
|
||||
return vec.reg;
|
||||
}
|
||||
|
||||
bool IEquatable<vec4d>.Equals(vec4d other)
|
||||
{
|
||||
return vec == other.vec;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static vec4d Subtract(vec4d left, vec4d right)
|
||||
{
|
||||
return left - right;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static vec4d Add(vec4d left, vec4d right)
|
||||
{
|
||||
return left + right;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Controlling;
|
||||
|
||||
using StgSharp.Math.HighPrecession;
|
||||
|
||||
using System;
|
||||
|
||||
@@ -36,7 +36,7 @@ using System;
|
||||
|
||||
namespace StgSharp.Gaming
|
||||
{
|
||||
public abstract class Bullet : IInstancing<Bullet>, IPlainEntity
|
||||
public abstract class Bullet : IInstancing, IPlainEntity
|
||||
{
|
||||
protected Bullet
|
||||
(
|
||||
@@ -53,9 +53,9 @@ namespace StgSharp.Gaming
|
||||
}
|
||||
GlobalBuffer = buffer;
|
||||
BufferId = buffer.CreateInstanceID();
|
||||
((IInstancing<Bullet>)this).Scale = scale;
|
||||
((IInstancing<Bullet>)this).Coord = new vec3d( beginPosition,0);
|
||||
((IInstancing<Bullet>)this).Rotation = angle;
|
||||
((IInstancing)this).Scale = scale;
|
||||
((IInstancing)this).Coord = new vec3d( beginPosition,0);
|
||||
((IInstancing)this).Rotation = angle;
|
||||
Motion = movement;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace StgSharp.Gaming
|
||||
set;
|
||||
}
|
||||
|
||||
public PlainInstancingBuffer<Bullet> GlobalBuffer
|
||||
public IInstancingBuffer GlobalBuffer
|
||||
{
|
||||
get;
|
||||
set;
|
||||
@@ -83,7 +83,7 @@ namespace StgSharp.Gaming
|
||||
set;
|
||||
}
|
||||
|
||||
vec3d IInstancing<Bullet>.CenterPositionGlobal
|
||||
vec3d IInstancing.CenterPositionGlobal
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
||||
@@ -1,34 +1,112 @@
|
||||
using StgSharp.Graphics;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="CollisionTexture.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.Data;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.GL;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Resources;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Stg
|
||||
{
|
||||
public class CollisionTexture : glRenderStream
|
||||
public class CollisionTextureInput : BlueprintPipelineArgs
|
||||
{
|
||||
string vertexShader = "";
|
||||
|
||||
string fragmentShader = "";
|
||||
|
||||
public CollisionTexture(RenderStreamConstructArgs args) : base(args)
|
||||
#pragma warning disable CS8618
|
||||
public CollisionTextureInput()
|
||||
#pragma warning restore CS8618
|
||||
{
|
||||
}
|
||||
|
||||
public new List<IInstancingBuffer> Value
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class OneDimensionalCollisionTexture2D : glRenderStream
|
||||
{
|
||||
|
||||
private const string inputName = "InstanceBufferList";
|
||||
private const string outputName = "CollisionTextureOutput";
|
||||
|
||||
private FrameBuffer fbo;
|
||||
|
||||
ShaderProgram generatingShader;
|
||||
|
||||
VertexArray vao;
|
||||
VertexBuffer vbo;
|
||||
ElementBuffer ebo;
|
||||
|
||||
public OneDimensionalCollisionTexture2D(RenderStreamConstructArgs args) : base(args)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Collision TextureGL unit cannot share context with other render stream or set as mainstream of a form,{($"and cannot be inited by {typeof(RenderStreamConstructArgs).Name} as well.")}"
|
||||
);
|
||||
}
|
||||
|
||||
#pragma warning disable CS8618
|
||||
public OneDimensionalCollisionTexture2D(Radius angleStride, string name) :
|
||||
#pragma warning restore CS8618
|
||||
base(new RenderStreamConstructArgs
|
||||
{
|
||||
Height = 1,
|
||||
Width = (int)((new Radius(Scaler.Pi)) / angleStride),
|
||||
UnitCubeSize = (1, 1, 1),
|
||||
Name = name
|
||||
})
|
||||
{
|
||||
InternalInit();
|
||||
}
|
||||
|
||||
protected override string[] InputPortsName =>
|
||||
[
|
||||
"InstanceBufferList",
|
||||
inputName,
|
||||
];
|
||||
|
||||
protected override string[] OutputPortsName =>
|
||||
[
|
||||
""
|
||||
outputName,
|
||||
];
|
||||
|
||||
|
||||
protected override void Deinit()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -36,19 +114,104 @@ namespace StgSharp.Stg
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
generatingShader = CreateShaderProgram();
|
||||
|
||||
Shader vertexShader = CreateShaderSegment(ShaderType.Vertex, 1);
|
||||
Shader fragmentShader = CreateShaderSegment(ShaderType.Fragment, 1);
|
||||
|
||||
vertexShader.Compile(0, InternalIO.CollisionTextureVertexShader);
|
||||
fragmentShader.Compile(0, InternalIO.CollisionTextureFragmentShader);
|
||||
vertexShader.AttachTo(0, generatingShader);
|
||||
fragmentShader.AttachTo(0, generatingShader);
|
||||
|
||||
generatingShader.Link();
|
||||
generatingShader.Use();
|
||||
|
||||
vbo = CreateVertexBuffer(3);
|
||||
vao = CreateVertexArray(1);
|
||||
ebo = CreateElementBuffer(1);
|
||||
|
||||
|
||||
fbo = CreateFrameBuffer(1);
|
||||
RenderBuffer rbo = CreateRenderBuffer(1);
|
||||
glFunc.SetRenderBufferStorage(
|
||||
RenderBufferInternalFormat.Depth24_Stencil8, this.Size);
|
||||
|
||||
|
||||
t = CreateTexture(1);
|
||||
t.Bind2D(0);
|
||||
glFunc.TextureImage2d(Texture2DTarget.Texture2D, 0, (int)ImageChannel.WithAlphaChannel,
|
||||
(uint)Width, (uint)Height, (int)ImageChannel.WithAlphaChannel, ImageChannelLayout.Byte, glHandle.ZeroHandle);
|
||||
|
||||
t.Set2dWrapProperty(Wrap.Repeat, Wrap.Repeat);
|
||||
t.Set2dFilterProperty(Filter.Nearest, Filter.Nearest);
|
||||
|
||||
glFunc.FrameBufferTexture2d(FrameBufferTarget.All, glAttachment.Color(0),
|
||||
Texture2DTarget.Texture2D, t[0], 0);
|
||||
|
||||
glFunc.CombineFrameBufferRenderBuffer(fbo[0], rbo[0]);
|
||||
|
||||
textureOutput = new float[this.Width];
|
||||
}
|
||||
|
||||
TextureGL t;
|
||||
float[] textureOutput;
|
||||
|
||||
protected override void Main(
|
||||
in Dictionary<string, BlueprintPipeline> input,
|
||||
in Dictionary<string, BlueprintPipeline> output)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (input == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Unknown operation lead to null ref of {nameof(input)}");
|
||||
}
|
||||
if (input[inputName].Args is not CollisionTextureInput inpipeline || inpipeline.Value == null || inpipeline.Value.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
List<IInstancingBuffer> bufferList = inpipeline.Value;
|
||||
|
||||
fbo.Bind(0);
|
||||
glFunc.ClearColor(0, 0, 0, 1);
|
||||
glFunc.Clear(MaskBufferBit.DEPTH|MaskBufferBit.COLOR);
|
||||
generatingShader.Use();
|
||||
vao.Bind(0);
|
||||
|
||||
foreach (IInstancingBuffer item in bufferList)
|
||||
{
|
||||
IGeometry g = item.TypicalShape;
|
||||
|
||||
if (!(g is PlainGeometry))
|
||||
{
|
||||
throw new InvalidOperationException("The current particle buffer contains non-planar geometry,");
|
||||
}
|
||||
|
||||
ebo.Bind(0);
|
||||
ebo.SetValue<int>(0,g.VertexIndices,BufferUsage.StreamDraw);
|
||||
|
||||
vbo.WriteVectorData<vec4d>(0,item.CoordAndRotationSpan,BufferUsage.StreamDraw);
|
||||
VertexArray.SetVertexAttribute(1,3,TypeCode.Single,false, 4 * sizeof(float), 0);
|
||||
VertexArray.SetVertexAttribute(2,1, TypeCode.Single,false,4*sizeof(float), 3 * sizeof(float));
|
||||
|
||||
vbo.WriteScalerData<float>(2, item.ScalingSpan, BufferUsage.StreamDraw);
|
||||
VertexArray.SetVertexAttribute(3, 1, TypeCode.Single, false, sizeof(float), 0);
|
||||
|
||||
vbo.WriteVectorData(1,g.VertexStream,BufferUsage.StreamDraw);
|
||||
VertexArray.SetVertexAttribute(0,3,TypeCode.Single,false,4*sizeof(float),0);
|
||||
|
||||
glFunc.DrawElementsInstanced(GeometryType.TRIANGLES,(uint)g.VertexIndices.Length / 3,
|
||||
TypeCode.UInt32,IntPtr.Zero,(uint)item.ScalingSpan.Length);
|
||||
}
|
||||
|
||||
t.Bind2D(0);
|
||||
glFunc.GetTextureImage(Texture2DTarget.Texture2D,0,ImageChannel.SingleColor,ImageChannelLayout.Float,ref textureOutput);
|
||||
VertexArray.BindNull();
|
||||
}
|
||||
|
||||
protected override void ProcessInput()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Stg
|
||||
{
|
||||
public class TimeLine
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Touhou;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Stg.Touhou
|
||||
{
|
||||
public static class TouhouBuilder
|
||||
{
|
||||
|
||||
|
||||
|
||||
public static ViewModel BuildTouhouWorld()
|
||||
{
|
||||
|
||||
TouhouForm form = new TouhouForm();
|
||||
|
||||
|
||||
|
||||
return form;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using StgSharp.Graphics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Touhou
|
||||
{
|
||||
public class TouhouForm:ViewModel
|
||||
{
|
||||
public TouhouForm():
|
||||
base()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -107,7 +107,6 @@
|
||||
<DefineConstants>Linux</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta">
|
||||
@@ -121,8 +120,24 @@
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
|
||||
</Target>
|
||||
|
||||
<PropertyGroup>
|
||||
<MySymbol>$(ColiisionTextureVertexShader)</MySymbol>
|
||||
<MySymbol>$(ColiisionTextureFragmentShader)</MySymbol>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- 在编译前读取文件内容 -->
|
||||
<Target Name="BeforeBuild">
|
||||
<ReadLinesFromFile File="Data\InternalEssentialData\CollisionTextureFS.frag">
|
||||
<Output TaskParameter="Lines" PropertyName="MySymbolValue" />
|
||||
</ReadLinesFromFile>
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.202\\RuntimeIdentifierGraph.json"
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.205\\RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,7 +478,7 @@
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.202\\RuntimeIdentifierGraph.json"
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.205\\RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a3506c96a3f6c7df608c22594ca2eaec41efa511")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2e57126ab72b0065e6ff52c0a2d1c9425307043e")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
Reference in New Issue
Block a user