daily update on 20241129 by nitload youmu, frameworkDialogue added

This commit is contained in:
Nitload
2024-11-29 05:47:53 +08:00
parent 6e2f93b053
commit 7c8d462ca5
2190 changed files with 49578 additions and 72052 deletions
+17
View File
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<package>
<metadata>
<id>StgSharp</id>
<version>1.0.0</version>
<authors>Nitload</authors>
<owners>Nitload</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description></description>
<tags></tags>
</metadata>
<files>
<file src="netstandard2.1\StgSharp.dll" target="lib\netstandard2.1\StgSharp.dll" />
<file src="netstandard2.1\StgSharp.xml" target="lib\netstandard2.1\StgSharp.xml" />
<file src="netstandard2.1\StgSharpC.dll" target="lib\netstandard2.1\StgSharpC.dll" />
</files>
</package>
Binary file not shown.
@@ -0,0 +1,72 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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.Math;
using System;
using System.Collections.Generic;
using System.Text;
//TODO 这玩意如何加载一个渲染流程以获得各个图元还没搞清楚
namespace StgSharp.Controls
{
public class BattleField : ControllingItem
{
public bool IsEntity => true;
public ReadOnlySpan<Vec4> TextureBox
{
get => throw new NotImplementedException();
}
public Rectangle BoundingBox
{
get;
set;
}
public Vec2 Position
{
get;
set;
}
public IEnumerator<PlainGeometryMesh> GetEnumerator()
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,159 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ButtonGroup.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.Math;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Transactions;
namespace StgSharp.Controls
{
public abstract class KeyboardButtonGroup : ControllingItem
{
private List<TriggerButton> buttonList;
private TriggerButton current;
public KeyboardButtonGroup()
{
buttonList = new List<TriggerButton>();
}
public bool IsEntity
{
get => false;
}
public ReadOnlySpan<Vec4> TextureBox
{
get => throw new NotSupportedException();
}
public Rectangle BoundingBox
{
get;
set;
}
public TriggerButton CurrentButton
{
get => current;
}
public Vec2 Position
{
get;
set;
}
protected List<TriggerButton> AllButton
{
get => buttonList;
}
public void AddButton( TriggerButton button )
{
buttonList.Add( button );
}
public abstract void Confirm();
public IEnumerator<PlainGeometryMesh> GetEnumerator()
{
foreach( TriggerButton item in buttonList ) {
yield return item.Single();
}
}
public void MoveDown()
{
TriggerButton button = current;
while( ( button.Down != null ) && button.Down.IsDisabled ) {
button = button.Right;
}
if( current == button ) {
return;
}
current.DeHighlight();
button.Enable();
current = button;
}
public void MoveLeft()
{
TriggerButton button = current;
while( ( button.Left != null ) && button.Left.IsDisabled ) {
button = button.Left;
}
if( current == button ) {
return;
}
current.DeHighlight();
button.Enable();
current = button;
}
public void MoveRight()
{
TriggerButton button = current;
while( ( button.Right != null ) && button.Right.IsDisabled ) {
button = button.Right;
}
if( current == button ) {
return;
}
current.DeHighlight();
button.Enable();
current = button;
}
public void MoveUp()
{
TriggerButton button = current;
while( ( button.Up != null ) && button.Up.IsDisabled ) {
button = button.Right;
}
if( current == button ) {
return;
}
current.DeHighlight();
button.Enable();
current = button;
}
}
}
@@ -0,0 +1,111 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="CharacterIndexImage.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.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 char[] displayIndex;
private char defaultChar;
private Dictionary<char, PlainGeometryMesh> texIndex;
private int length;
private PlainGeometryMesh _tittleMesh;
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 );
}
public bool IsEntity
{
get => true;
}
public ReadOnlySpan<Vec4> TextureBox
{
get => throw new NotSupportedException();
}
public Rectangle BoundingBox
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
}
public Vec2 Position
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
}
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 IEnumerator<PlainGeometryMesh> GetEnumerator()
{
yield return _tittleMesh;
foreach( char item in displayIndex ) {
yield return texIndex[ item ];
}
}
}
}
@@ -0,0 +1,73 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ControllingIntem.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.Math;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Controls
{
public interface ControllingItem : IEnumerable<PlainGeometryMesh>
{
public abstract bool IsEntity
{
get;
}
public abstract ReadOnlySpan<Vec4> TextureBox
{
get;
}
public abstract Rectangle BoundingBox
{
get;
set;
}
public abstract Vec2 Position
{
get;
set;
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}
@@ -0,0 +1,78 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="DecorationBox.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 DecorationBox : ControllingItem
{
private PlainGeometryMesh renderMesh;
public DecorationBox( Rectangle bound, Image texture, Vec2[] texCoord )
{
renderMesh = new PlainGeometryMesh(
BoundingBox, new TextureProvider( texture, texCoord ) );
}
public bool IsEntity => true;
public ReadOnlySpan<Vec4> TextureBox
{
get => renderMesh.TextureCoord;
}
public Rectangle BoundingBox
{
get;
set;
}
public Vec2 Position
{
get;
set;
}
public IEnumerator<PlainGeometryMesh> GetEnumerator()
{
yield return renderMesh;
}
}
}
@@ -0,0 +1,96 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="MarkingLable.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 StgSharp.Timing;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace StgSharp.Controls
{
public class MarkingLabel : ControllingItem
{
private PlainGeometryMesh marker;
private TimeFunction _movement;
private Vec2 _currentPosition, _movementVec;
public MarkingLabel( PlainGeometryMesh marker, TimeFunction movement )
{
this.marker = marker;
_movement = movement;
}
public bool IsEntity => true;
public ReadOnlySpan<Vec4> TextureBox
{
get => marker.TextureCoord;
}
public Rectangle BoundingBox
{
get;
set;
}
public Vec2 Position
{
get;
set;
}
public IEnumerator<PlainGeometryMesh> GetEnumerator()
{
yield return marker;
}
public void Move( Vec2 movement )
{
if( !_movement.IsComplete ) {
Position = _currentPosition + ( _movement.Calculate() * _movementVec );
}
}
public void MoveTo( Vec2 target )
{
Move( target - Position );
}
}
}
@@ -0,0 +1,248 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="TriggerButton.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.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Controls
{
public delegate void RenderButtonTextureCallback(
ButtonStatus status,
float beginTime,
in TextureProvider texture );
public enum ButtonStatus
{
Error = 0b0,
Disable = 0b1,
Enable = 0b10,
Highlight = 0b100,
Confirm = 0b1000,
DisableToEnable = Disable | Enable,
EnableToDisable = -( Enable | DisableToEnable ),
EnableToHighlight = Enable | Highlight,
HighlightToEnable = -( Enable | Highlight ),
HighlightToDisable = -( Highlight | Disable ),
}
public class TriggerButton : ControllingItem
{
private Action? confirmCallback;
private Action? disableCallback;
#nullable enable
private Action? enableCallback;
private float _statusBeginTime;
private RenderButtonTextureCallback _renderButton;
private TextureProvider _texture;
#nullable restore
public TriggerButton()
{
CurrentStatus = ButtonStatus.Disable;
}
public event Action ConfirmEvent
{
add { confirmCallback += value; }
remove { confirmCallback -= value; }
}
public event Action DisableEvent
{
add { disableCallback += value; }
remove { disableCallback -= value; }
}
public event Action EnableEvent
{
add { enableCallback += value; }
remove { enableCallback -= value; }
}
public event RenderButtonTextureCallback RenderButtonTexture
{
add
{
if( _renderButton == null ) {
_renderButton = value;
} else {
_renderButton += value;
}
}
remove
{
if( _renderButton != null ) {
_renderButton -= value;
}
}
}
public bool IsHighLighted
{
get;
internal set;
}
public bool IsDisabled
{
get;
internal set;
}
public bool IsEntity => true;
public ReadOnlySpan<Vec4> TextureBox
{
get => MemoryMarshal.Cast<Vec2, Vec4>( _texture.TextureCoordinate );
}
public Rectangle BoundingBox
{
get;
set;
}
public TriggerButton Left
{
get;
internal set;
}
public TriggerButton Right
{
get;
internal set;
}
public TriggerButton Up
{
get;
internal set;
}
public TriggerButton Down
{
get;
internal set;
}
public Vec2 Position
{
get;
set;
}
internal TextureProvider Texture
{
get => _texture;
set => _texture = value;
}
protected ButtonStatus CurrentStatus
{
get;
set;
}
public void DeHighlight()
{
if( CurrentStatus == ButtonStatus.Highlight ) {
CurrentStatus = ButtonStatus.HighlightToEnable;
}
}
public void Disable()
{
CurrentStatus = CurrentStatus switch
{
ButtonStatus.Enable => ButtonStatus.EnableToDisable,
ButtonStatus.Highlight => ButtonStatus.HighlightToDisable,
_ => CurrentStatus,
};
if( disableCallback != null ) {
disableCallback();
}
}
public void Enable()
{
if( CurrentStatus == ButtonStatus.Disable ) {
CurrentStatus = ButtonStatus.DisableToEnable;
} else {
return;
}
if( enableCallback != null ) {
enableCallback();
}
}
public IEnumerator<PlainGeometryMesh> GetEnumerator()
{
_renderButton( CurrentStatus, _statusBeginTime, in _texture );
yield return new PlainGeometryMesh( this.BoundingBox, _texture );
}
public void Highlight()
{
if( CurrentStatus == ButtonStatus.Enable ) {
CurrentStatus |= ButtonStatus.EnableToHighlight;
} else {
return;
}
if( confirmCallback != null ) {
confirmCallback();
}
}
internal void Init( ButtonStatus status )
{
if( CurrentStatus == ButtonStatus.Error ) {
CurrentStatus = status;
}
}
}//----------------------------------- End of class --------------------------------------------
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,171 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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.Data.Intrinsic;
using StgSharp.Geometries;
using StgSharp.Graphics;
using StgSharp.Graphics.OpenGL;
using System;
using System.Collections.Generic;
using System.Diagnostics;
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 readonly GCHandle ssc_logHandle =
GCHandle.Alloc( new byte[512], GCHandleType.Pinned );
internal static IntPtr SSClibPtr = IntPtr.Zero;
internal static SemaphoreSlim logSyncSemaphore = new SemaphoreSlim(
1, 1 );
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 );
int statCode;
fixed( IntrinsicContext* cptr = &_intrinsicContext ) {
statCode = LoadIntrinsicFunction( cptr );
}
if (statCode == -1)
{
throw new NotSupportedException();
}
}
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
#else
IntPtr.Zero;
#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,237 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="KeyEnum.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.Graphics.OpenGL;
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*/,
Esc = 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,
NumPadDiv = 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,
First = Space,
Last = Menu,
}
#pragma warning disable CA1707
#pragma warning disable CA1712
#pragma warning disable CA1008
#pragma warning disable CA1027
public enum Joystick : int
#pragma warning restore CA1027
{
Joystick_1 = GLconst.GLFW_JOYSTICK_1,
Joystick_2 = GLconst.GLFW_JOYSTICK_2,
Joystick_3 = GLconst.GLFW_JOYSTICK_3,
Joystick_4 = GLconst.GLFW_JOYSTICK_4,
Joystick_5 = GLconst.GLFW_JOYSTICK_5,
Joystick_6 = GLconst.GLFW_JOYSTICK_6,
Joystick_7 = GLconst.GLFW_JOYSTICK_7,
Joystick_8 = GLconst.GLFW_JOYSTICK_8,
Joystick_9 = GLconst.GLFW_JOYSTICK_9,
Joystick_10 = GLconst.GLFW_JOYSTICK_10,
Joystick_11 = GLconst.GLFW_JOYSTICK_11,
Joystick_12 = GLconst.GLFW_JOYSTICK_12,
Joystick_13 = GLconst.GLFW_JOYSTICK_13,
Joystick_14 = GLconst.GLFW_JOYSTICK_14,
Joystick_15 = GLconst.GLFW_JOYSTICK_15,
Joystick_16 = GLconst.GLFW_JOYSTICK_16,
First = Joystick_1,
Last = Joystick_16
}
[System.Flags]
public enum Mouse : int
{
Button1 = 0,
Button2 = 1,
Button3 = 2,
Button4 = 3,
Button5 = 4,
Button6 = 5,
Button7 = 6,
Button8 = 7,
First = Button1,
Last = Button8,
Left = Button1,
Right = Button2,
Middle = Button3
}
#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,69 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="KeyEventAttribute.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.Text;
using System.Threading.Tasks;
namespace StgSharp
{
[AttributeUsage( AttributeTargets.Method )]
public class KeyEventAttribute : Attribute
{
internal int _equipment;
internal int _keyStat;
internal int _keyTarget;
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,51 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IClickTrigger.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.Controlling.UsrActivity
{
public interface IClickTrigger
{
public int TargetKeyOrButtonID
{
get;
}
public KeyStatus TriggeredStatus
{
get;
}
}
}
@@ -0,0 +1,93 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="JoystickTrigger.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.Controlling.UsrActivity
{
public readonly struct JoystickTrigger : IClickTrigger, IEquatable<JoystickTrigger>
{
private readonly Joystick _stick;
private readonly KeyStatus _status;
public JoystickTrigger( Joystick targetKey, KeyStatus status )
{
this._stick = targetKey;
_status = status;
}
public int TargetKeyOrButtonID => ( int )_stick;
public Joystick Stick
{
get => _stick;
}
public KeyStatus TriggeredStatus => _status;
public override bool Equals( object obj )
{
return base.Equals( obj );
}
public override int GetHashCode()
{
return ( ( int )_stick ) + ( 17 * ( ( int )_status ) );
}
public override string ToString()
{
return $"Key {_stick} triggered when {_status}";
}
public static bool operator !=(
JoystickTrigger left,
JoystickTrigger right )
{
return !( left == right );
}
public static bool operator ==(
JoystickTrigger left,
JoystickTrigger right )
{
return ( left._status == right._status ) && ( left._stick == right._stick );
}
bool IEquatable<JoystickTrigger>.Equals( JoystickTrigger other )
{
return other == this;
}
}
}
@@ -0,0 +1,85 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="KeyTrigger.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.Data.Common;
using System.Text;
namespace StgSharp.Controlling.UsrActivity
{
public readonly struct KeyTrigger : IClickTrigger, IEquatable<KeyTrigger>
{
private readonly KeyboardKey _targetKey;
private readonly KeyStatus _triggerStat;
public KeyTrigger( KeyboardKey targetKey, KeyStatus targetStat )
{
this._targetKey = targetKey;
this._triggerStat = targetStat;
}
public int TargetKeyOrButtonID => ( int )_targetKey;
public KeyStatus TriggeredStatus => _triggerStat;
public override bool Equals( object obj )
{
return base.Equals( obj );
}
public override int GetHashCode()
{
return ( ( int )_targetKey ) + ( 17 * ( ( int )_triggerStat ) );
}
public override string ToString()
{
return $"Key {_targetKey} triggered when {_triggerStat}";
}
public static bool operator !=( KeyTrigger left, KeyTrigger right )
{
return !( left == right );
}
public static bool operator ==( KeyTrigger left, KeyTrigger right )
{
return ( left._triggerStat == right._triggerStat ) && ( left._targetKey == right._targetKey );
}
bool IEquatable<KeyTrigger>.Equals( KeyTrigger other )
{
return other == this;
}
}
}
@@ -0,0 +1,72 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="MouseTrigger.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Diagnostics.SymbolStore;
using System.Text;
namespace StgSharp.Controlling.UsrActivity
{
public readonly struct MouseTrigger : IClickTrigger, IEquatable<MouseTrigger>
{
private readonly KeyStatus _status;
private readonly Mouse _mouse;
public MouseTrigger( Mouse mouse, KeyStatus status )
{
_mouse = mouse;
_status = status;
}
public int TargetKeyOrButtonID => ( int )_mouse;
public KeyStatus TriggeredStatus => _status;
public bool Equals( MouseTrigger other )
{
return this == other;
}
public static bool operator !=( MouseTrigger left, MouseTrigger right )
{
return left._mouse != right._mouse || left._status != right._status;
}
public static bool operator ==( MouseTrigger left, MouseTrigger right )
{
return left._mouse == right._mouse && left._status == right._status;
}
}
}
@@ -0,0 +1,102 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="TriggetFactory.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.Text;
namespace StgSharp.Controlling.UsrActivity
{
public static class TriggetBuilder
{
private const int JoystickMax = ( int )Joystick.Last + 1;
private const int JoystickMin = ( int )Joystick.First - 1;
private const int KeyboardMax = ( int )KeyboardKey.Last + 1;
private const int KeyboardMin = ( int )KeyboardKey.First - 1;
private const int MouseMax = ( int )Mouse.Last + 1;
private const int MouseMin = ( int )Mouse.First - 1;
private static KeyTrigger keyboardtemp;
private static MouseTrigger mousetemp;
public static JoystickTrigger BuildJoystickClickTrigger(
int keyCode,
KeyStatus status )
{
if( keyCode > MouseMin && keyCode < MouseMax ) {
return new JoystickTrigger( ( Joystick )keyCode, status );
}
throw new InvalidOperationException(
"Known key code or key is not on joystick." );
}
public static KeyTrigger BuildKeyboardClickTrigger(
int keyCode,
KeyStatus status )
{
if( keyCode > KeyboardMin && keyCode < KeyboardMax ) {
return new KeyTrigger( ( KeyboardKey )keyCode, status );
}
throw new InvalidOperationException(
"Known key code or kay is not on keyboard." );
}
public static MouseTrigger BuildMouseClickTrigger(
int keyCode,
KeyStatus status )
{
if( keyCode >= MouseMin && keyCode <= MouseMax ) {
return new MouseTrigger( ( Mouse )keyCode, status );
}
throw new InvalidOperationException(
"Known key code or key is not on mouse." );
}
public static IClickTrigger BuildTrigger(
int keyCode,
KeyStatus status )
{
if( keyCode > KeyboardMin && keyCode < KeyboardMax ) {
return new KeyTrigger( ( KeyboardKey )keyCode, status );
}
if( keyCode > JoystickMin && keyCode < JoystickMax ) {
return new JoystickTrigger( ( Joystick )keyCode, status );
}
if( keyCode >= MouseMin && keyCode <= MouseMax ) {
return new MouseTrigger( ( Mouse )keyCode, status );
}
throw new InvalidOperationException( "Known key code." );
}
}
}
@@ -0,0 +1,56 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="root.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 System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp
{
public static unsafe partial class StgSharp
{
private static byte leastUnusedArea;
private static List<Area> root = new List<Area>();
private static SSD defaultIdProvider = new SSD();
public static byte NewArea()
{
byte ret = leastUnusedArea;
leastUnusedArea++;
return ret;
}
}//------------------ end of class ---------------------
}
@@ -0,0 +1,101 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="InternalData.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;
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp
{
internal partial class InternalIO
{
#region ControllingItemRender
internal const string ControlItemRenderVertexShader = """
""";
#endregion
#region CollisionTexture
internal const string CollisionTextureVertexShader = """
#version 430 core
layout(location = 0) in vec2 localCollisionCoord;
layout(location = 1) in vec2 spaceCoord;
layout(location = 2) in float rotation;
layout(location = 3) in float scaling;
uniform vec2 target;
uniform mat2 projection;
void main()
{
mat2 scaling = mat2(
scaling,0,
0,scaling );
mat2 rotation = mat2(
cos(rotation),-sin(rotation),
sin(rotation),cos(rotation) );
vec2 realCoord = (rotation * scaling * localCollisionCoord) + spaceCoord - target;
realCoord = projection * realCoord;
float dist = distance(realCoord, vec2(0,0));
float angle = atan(realCoord.y, realCoord.x);
gl_Position = vec4(angle, realCoord.y, dist, 1);
}
""";
internal const string CollisionTextureFragmentShader = """
#version 430 core
out vec4 Color;
uniform float range;
void main()
{
float dist = gl_FragCoord.z;
if(dist > range)
{
discard;
}
dist /= range;
gl_FragDepth = min(dist, gl_FragDepth);
Color = vec4(dist,0,0,1);
}
""";
#endregion
}
}
@@ -0,0 +1,90 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ColumnSet2.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.Intrinsic;
using StgSharp.Math;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Data.Intrinsic
{
[StructLayout( LayoutKind.Explicit, Size = 12 * sizeof( float ), Pack = 16 )]
internal struct ColumnSet2 : IEquatable<ColumnSet2>
{
[FieldOffset( 0 * sizeof( float ) )] internal float m00;
[FieldOffset( 4 * sizeof( float ) )] internal float m01;
[FieldOffset( 1 * sizeof( float ) )] internal float m10;
[FieldOffset( 5 * sizeof( float ) )] internal float m11;
[FieldOffset( 2 * sizeof( float ) )] internal float m20;
[FieldOffset( 6 * sizeof( float ) )] internal float m21;
[FieldOffset( 3 * sizeof( float ) )] internal float m30;
[FieldOffset( 7 * sizeof( float ) )] internal float m31;
[FieldOffset( 0 )] internal Vector4 colum0;
[FieldOffset( 4 * sizeof( float ) )] internal Vector4 colum1;
internal ColumnSet2( Vector4 c0, Vector4 c1 )
{
colum0 = c0;
colum1 = c1;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public override bool Equals( object? obj )
{
return ( obj is ColumnSet2 mat ) && Equals( mat );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public bool Equals( ColumnSet2 other )
{
return colum0.Equals( other.colum0 ) && colum1.Equals(
other.colum1 );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static bool operator !=( ColumnSet2 left, ColumnSet2 right )
{
return !( left == right );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static bool operator ==( ColumnSet2 left, ColumnSet2 right )
{
return left.Equals( right );
}
}
}
@@ -0,0 +1,87 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ColumnSet3.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.Intrinsic;
using StgSharp.Math;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Data.Intrinsic
{
[StructLayout( LayoutKind.Explicit, Size = 12 * sizeof( float ), Pack = 16 )]
internal struct ColumnSet3 : IEquatable<ColumnSet3>, IMat
{
[FieldOffset( 0 * sizeof( float ) )] internal float m00;
[FieldOffset( 4 * sizeof( float ) )] internal float m01;
[FieldOffset( 8 * sizeof( float ) )] internal float m02;
[FieldOffset( 1 * sizeof( float ) )] internal float m10;
[FieldOffset( 5 * sizeof( float ) )] internal float m11;
[FieldOffset( 9 * sizeof( float ) )] internal float m12;
[FieldOffset( 2 * sizeof( float ) )] internal float m20;
[FieldOffset( 6 * sizeof( float ) )] internal float m21;
[FieldOffset( 10 * sizeof( float ) )] internal float m22;
[FieldOffset( 3 * sizeof( float ) )] internal float m30;
[FieldOffset( 7 * sizeof( float ) )] internal float m31;
[FieldOffset( 11 * sizeof( float ) )] internal float m32;
[FieldOffset( 0 )] internal Vector4 colum0;
[FieldOffset( 4 * sizeof( float ) )] internal Vector4 colum1;
[FieldOffset( 8 * sizeof( float ) )] internal Vector4 colum2;
public override bool Equals( object? obj )
{
return ( obj is ColumnSet3 mat ) && Equals( mat );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public bool Equals( ColumnSet3 other )
{
return colum0.Equals( other.colum0 ) && colum1.Equals(
other.colum1 ) && colum2.Equals( other.colum2 );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static bool operator !=( ColumnSet3 left, ColumnSet3 right )
{
return !( left == right );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static bool operator ==( ColumnSet3 left, ColumnSet3 right )
{
return left.Equals( right );
}
}
}
@@ -0,0 +1,110 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ColumnSet4.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;
using StgSharp.Data.Intrinsic;
using StgSharp.Math;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Data.Intrinsic
{
[StructLayout( LayoutKind.Explicit, Size = 16 * sizeof( float ) )]
internal struct ColumnSet4 : IEquatable<ColumnSet4>, IMat
{
[FieldOffset( 0 )] internal Vector4 colum0;
[FieldOffset( 16 )] internal Vector4 colum1;
[FieldOffset( 32 )] internal Vector4 colum2;
[FieldOffset( 48 )] internal Vector4 colum3;
[FieldOffset( 0 )] public float m00;
[FieldOffset( 16 )] public float m01;
[FieldOffset( 32 )] public float m02;
[FieldOffset( 48 )] public float m03;
[FieldOffset( 4 )] public float m10;
[FieldOffset( 20 )] public float m11;
[FieldOffset( 36 )] public float m12;
[FieldOffset( 52 )] public float m13;
[FieldOffset( 8 )] public float m20;
[FieldOffset( 24 )] public float m21;
[FieldOffset( 40 )] public float m22;
[FieldOffset( 56 )] public float m23;
[FieldOffset( 12 )] public float m30;
[FieldOffset( 28 )] public float m31;
[FieldOffset( 44 )] public float m32;
[FieldOffset( 60 )] public float m33;
[MethodImpl( MethodImplOptions.AggressiveInlining )]
internal ColumnSet4(
Vector4 colum0,
Vector4 colum1,
Vector4 colum2,
Vector4 colum3 )
{
this.colum0 = colum0;
this.colum1 = colum1;
this.colum2 = colum2;
this.colum3 = colum3;
}
public override bool Equals( object? obj )
{
return ( obj is ColumnSet4 mat ) && Equals( mat );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public bool Equals( ColumnSet4 other )
{
return colum0.Equals( other.colum0 ) && colum1.Equals(
other.colum1 ) && colum2.Equals( other.colum2 ) && colum3.Equals(
other.colum3 );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static bool operator !=( ColumnSet4 left, ColumnSet4 right )
{
return !( left == right );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static bool operator ==( ColumnSet4 left, ColumnSet4 right )
{
return left.Equals( right );
}
}
}
@@ -0,0 +1,61 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IRegisterType.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.Text;
using System.Threading.Tasks;
namespace StgSharp.Data.Intrinsic
{
public interface IRegisterType
{
public T Read<T>( int index )
where T: struct
#if NET8_0_OR_GREATER
, INumber
#else
, IConvertible
#endif
;
public void Write<T>( int index, T value )
where T: struct
#if NET8_0_OR_GREATER
, INumber
#else
, IConvertible
#endif
;
}
}
@@ -0,0 +1,62 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IntrinsicContext.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.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Data.Intrinsic
{
[StructLayout( LayoutKind.Sequential )]
internal unsafe struct IntrinsicContext
{
public delegate* unmanaged[Cdecl]<ColumnSet2*, ColumnSet2*, ColumnSet2*, void> add_mat_2;
public delegate* unmanaged[Cdecl]<ColumnSet3*, ColumnSet3*, ColumnSet3*, void> add_mat_3;
public delegate* unmanaged[Cdecl]<ColumnSet4*, ColumnSet4*, ColumnSet4*, void> add_mat_4;
public delegate* unmanaged[Cdecl]<ColumnSet3*, ColumnSet3*, float> det_mat_3;
public delegate* unmanaged[Cdecl]<ColumnSet4*, ColumnSet4*, float> det_mat_4;
public delegate* unmanaged[Cdecl]<M128*, M128*, void> normalize_v3;
public delegate* unmanaged[Cdecl]<char*, int, int> string_quickHash;
public delegate* unmanaged[Cdecl]<ColumnSet2*, ColumnSet3*, void> transpose23;
public delegate* unmanaged[Cdecl]<ColumnSet2*, ColumnSet4*, void> transpose24;
public delegate* unmanaged[Cdecl]<ColumnSet3*, ColumnSet2*, void> transpose32;
public delegate* unmanaged[Cdecl]<ColumnSet3*, ColumnSet3*, void> transpose33;
public delegate* unmanaged[Cdecl]<ColumnSet3*, ColumnSet4*, void> transpose34;
public delegate* unmanaged[Cdecl]<ColumnSet4*, ColumnSet2*, void> transpose42;
public delegate* unmanaged[Cdecl]<ColumnSet4*, ColumnSet3*, void> transpose43;
public delegate* unmanaged[Cdecl]<ColumnSet4*, ColumnSet4*, void> transpose44;
}
}
@@ -0,0 +1,193 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="M128.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
#if NET5_0_OR_GREATER
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
#endif
using System.Text;
namespace StgSharp.Data.Intrinsic
{
[StructLayout( LayoutKind.Explicit, Pack = 16 )]
public unsafe struct M128 : IRegisterType
{
[FieldOffset( 0 )] internal Vector4 vec;
internal M128( Vector4 v )
{
vec = v;
}
public override bool Equals( [NotNullWhen( true )] object obj )
{
if( obj is not M128 other ) {
return false;
}
return this == other;
}
public override int GetHashCode()
{
return vec.GetHashCode();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public T Read<T>( int index )
where T: struct
#if NET8_0_OR_GREATER
, INumber
#else
, IConvertible
#endif
{
fixed( Vector4* p = &vec ) {
#pragma warning disable CS8500
return *( ( T* )p + index );
#pragma warning restore CS8500
}
}
public override string ToString()
{
return string.Empty;
}
public string ToString( int sample )
{
string str = string.Empty;
for( int i = 15; i >= 0; i-- ) {
str += $"{Convert.ToString(Read<byte>(i), sample)} ";
}
return str;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void Write<T>( int index, T value )
where T: struct
#if NET8_0_OR_GREATER
, INumber
#else
, IConvertible
#endif
{
fixed( Vector4* p = &vec ) {
#pragma warning disable CS8500
*( ( T* )p + index ) = value;
#pragma warning restore CS8500
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static bool operator !=( M128 left, M128 right )
{
return left.vec != right.vec;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static bool operator ==( M128 left, M128 right )
{
return left.vec == right.vec;
}
#if NET5_0_OR_GREATER
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<byte>( M128 m )
{
return m.vec.AsVector128().As<float, byte>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<sbyte>( M128 m )
{
return m.vec.AsVector128().As<float, sbyte>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<short>( M128 m )
{
return m.vec.AsVector128().As<float, short>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<ushort>( M128 m )
{
return m.vec.AsVector128().As<float, ushort>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<int>( M128 m )
{
return m.vec.AsVector128().As<float, int>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<uint>( M128 m )
{
return m.vec.AsVector128().As<float, uint>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<long>( M128 m )
{
return m.vec.AsVector128().As<float, long>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<ulong>( M128 m )
{
return m.vec.AsVector128().As<float, ulong>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<float>( M128 m )
{
return m.vec.AsVector128().As<float, float>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<double>( M128 m )
{
return m.vec.AsVector128().As<float, double>();
}
#endif
}
}
@@ -0,0 +1,75 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="M256.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.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Data.Intrinsic
{
[StructLayout( LayoutKind.Sequential )]
public unsafe struct M256 : IRegisterType
{
private M128 v0;
private M128 v1;
public T Read<T>( int index)
where T : struct
#if NET8_0_OR_GREATER
, INumber
#else
, IConvertible
#endif
{
fixed ( M128* mptr = &v0 ) {
return *( ( T* )mptr + index );
}
}
public void Write<T>( int index, T value)
where T : struct
#if NET8_0_OR_GREATER
, INumber
#else
, IConvertible
#endif
{
fixed ( M128* mptr = &v0 ) {
*( ( T* )mptr + index ) = value;
}
}
}
}
@@ -0,0 +1,55 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="intrinsicContextProvider.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.Intrinsic;
using System;
using System.Runtime.InteropServices;
namespace StgSharp
{
internal static unsafe partial class InternalIO
{
private static readonly IntrinsicContext _intrinsicContext = new IntrinsicContext();
internal static IntrinsicContext Intrinsic
{
get => _intrinsicContext;
}
[DllImport(SSC_libName,
CallingConvention = CallingConvention.Cdecl,
EntryPoint = "load_intrinsic_function" )]
private static extern int LoadIntrinsicFunction(
IntrinsicContext* context );
}
}
+70
View File
@@ -0,0 +1,70 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Lable.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;
using System;
using System.Runtime.CompilerServices;
namespace StgSharp.Data
{
public class DataLabel
{
private readonly string _name;
public DataLabel( string lableName )
{
_name = lableName;
}
public string Name
{
get => _name;
}
public override unsafe int GetHashCode()
{
ReadOnlySpan<char> nameSpan = _name.AsSpan();
fixed( char* cptr = nameSpan ) {
return InternalIO.Intrinsic
.string_quickHash( cptr, _name.Length );
}
}
}
public static class DataLabelBuilder
{
public static DataLabel AsLabel(this string name)
{
return new DataLabel(name);
}
}
}
@@ -0,0 +1,172 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="RandomGenerator.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.Intrinsic;
using System;
using System.IO;
using System.Numerics;
using System.Security.Cryptography;
using System.Text;
using System.Transactions;
using System.Xml;
using System.Xml.Serialization;
namespace StgSharp.Data
{
public class RandomGenerator
{
private byte[] currentKey;
private readonly byte[] originKey;
private int cycleCount;
private SHA512 hash;
public RandomGenerator() : this( DateTime.UtcNow.ToBinary() ) { }
public RandomGenerator( object source )
{
try {
if( source == null ) {
throw new ArgumentNullException( nameof( source ) );
}
XmlSerializer s = new XmlSerializer( source.GetType() );
using( StringWriter sw = new StringWriter() ) {
s.Serialize( sw, source );
string data = sw.ToString();
originKey = Encoding.UTF8.GetBytes( data );
}
}
catch( Exception ) {
throw;
}
hash = SHA512.Create();
originKey = hash.ComputeHash( originKey );
currentKey = originKey;
cycleCount = 0;
}
public int TotalGeneratedRandom
{
get => cycleCount;
}
public unsafe int GenRandomInt()
{
M128 source = PrivateRand();
cycleCount++;
/*
float d0 = MathF.Sin(1 / source.Read<float>(0));
float d1 = MathF.Sin(1 / source.Read<float>(1));
float d2 = MathF.Sin(1 / source.Read<float>(2));
float d3 = MathF.Sin(1 / source.Read<float>(3));
source.Write<short>(0, *( short*)&d3);
source.Write<short>(2, *((short*)&d2+1));
source.Write<short>(4, *( short*)&d1);
source.Write<short>(6, *((short*)&d0+1));
/**/
return source.Read<int>( cycleCount % 4 );
}
public byte GenRandomInt8()
{
cycleCount++;
if( cycleCount % 64 == 0 ) {
PrivateRand();
}
return currentKey[ cycleCount % 64 ];
}
public float GenRandomSingle()
{
cycleCount++;
while( true ) {
M128 source = PrivateRand();
uint
temp0 = source.Read<uint>( 0 ),
temp1 = source.Read<uint>( 2 );
if( temp0 * temp1 != 0 ) {
float ret = ( ( temp0 % temp1 ) * 1.0f ) / temp1;
if( ret < 0.335f ) {
ret = ret * ( ( ret * ( -0.7811934f ) ) + 1.4489113f );
} else {
ret = ( ret * ( ( ret * ( -0.1158368f ) ) + 1.0580600f ) ) + 0.0590584f;
}
if( ret > 1 ) {
continue;
}
return ret;
}
}
}
public void Reset()
{
currentKey = originKey;
cycleCount = 0;
}
private unsafe M128 PrivateRand()
{
currentKey = hash.ComputeHash( currentKey );
M128 ret;
fixed( byte* bptr = currentKey ) {
switch( ( cycleCount % 16 ) / 4 ) {
case 0:
ret = *( ( ( M128* )bptr ) + 0 );
break;
case 1:
ret = *( ( ( M128* )bptr ) + 1 );
break;
case 2:
ret = *( ( ( M128* )bptr ) + 2 );
break;
case 3:
ret = *( ( ( M128* )bptr ) + 3 );
break;
default:
throw new InvalidOperationException();
}
}
//Console.WriteLine(ret.ToString(16));
return ret;
}
}
}
+47
View File
@@ -0,0 +1,47 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Area.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.FileIO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Data
{
/// <summary>
/// An independent storage area, used as the only folder type in root folder. Contains several
/// <see cref="SSD" /> files reference as virtual disc. Data is actually stored in <see
/// cref="SSD" />s in certain RAID mode.
/// </summary>
public partial class Area { }
}
@@ -0,0 +1,83 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="DataHead.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.Intrinsic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
namespace StgSharp.Data
{
[StructLayout( LayoutKind.Explicit, Size = 16 )]
public struct SSDSegmentHead
{
[FieldOffset( 12 )] internal byte size;
[FieldOffset( 0 )] internal M128 data;
[FieldOffset( 13 )] public byte selfDefine_1;
[FieldOffset( 14 )] public byte selfDefine_2;
[FieldOffset( 15 )] public byte selfDefine_3;
[FieldOffset( 0 )] public int globalID;
[FieldOffset( 4 )] public int nextID;
[FieldOffset( 8 )] public int previousHash;
public int Size
{
get => ( ( int )size ) + 1;
set
{
if( ( value > 256 ) || ( value < 0 ) ) {
throw new ArgumentOutOfRangeException();
}
size = ( byte )( value - 1 );
}
}
public unsafe byte[] GetBytes()
{
byte[] ret = new byte[16];
fixed( Vector4* vptr = &data.vec ) {
byte* bptr = ( byte* )vptr;
for( int i = 0; i < 15; i++ ) {
ret[ i ] = *bptr;
}
}
return ret;
}
}
}
@@ -0,0 +1,181 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="DataSegment.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.Intrinsic;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Data
{
[StructLayout( LayoutKind.Explicit, Size = StgSharp.ssdSegmentLength * 16 )]
public unsafe struct SSDSegment : IComparable<int>, IComparable<SSDSegment>
{
[FieldOffset( 16 )] public fixed byte Data[
16 * ( StgSharp.ssdSegmentLength - 1 ) ];
[FieldOffset( 12 )] public int DataHash;
[FieldOffset( 8 )] public int PreviousHash;
[FieldOffset( 0 * 16 )] public SSDSegmentHead Head;
public SSDSegment( int previousHash )
{
this.PreviousHash = previousHash;
}
public byte this[ int index ]
{
get
{
if( index > ( 16 * ( StgSharp.ssdSegmentLength - 1 ) ) - 1 ) {
throw new IndexOutOfRangeException();
}
return Data[ index ];
}
set
{
if( index > ( 16 * ( StgSharp.ssdSegmentLength - 1 ) ) - 1 ) {
throw new IndexOutOfRangeException();
}
Data[ index ] = value;
}
}
public int ID
{
get { return Head.globalID; }
set { Head.globalID = value; }
}
public short Size => Head.size;
public void FillRandomBytes( int begin )
{
if( begin > 255 ) {
return;
}
for( int i = begin; i < 255; i++ ) {
Data[ i ] = Scaler.Random<byte>(); //TODO: 使用STGSHARP内部随机数工具处理它
}
}
public static SSDSegment FromStream( byte[] stream )
{
if( stream.Length != 16 * StgSharp.ssdSegmentLength ) {
throw new ArgumentException();
}
SSDSegment ret = new SSDSegment();
fixed( byte* bptr = stream ) {
ret.Head.data = *( M128* )bptr;
for( int i = 1; i < StgSharp.ssdSegmentLength; i++ ) {
ret.WriteData<M128>(
i - 1, *( M128* )( bptr + ( 16 * i ) ) );
}
}
return ret;
}
public byte[] GetBytes()
{
byte[] ret = new byte[16 * StgSharp.ssdSegmentLength];
fixed( M128* mptr = &Head.data ) {
fixed( byte* aptr = ret ) {
Vector4* vsptr = ( Vector4* )mptr;
Vector4* vtptr = ( Vector4* )aptr;
for( int i = 0; i < 18; i++ ) {
*( vtptr + i ) = *( vsptr + i );
}
}
}
return ret;
}
public int GetDataHash()
{
Vector4 v = Vector4.One;
fixed( M128* mptr = &Head.data ) {
Vector4* vptr = ( Vector4* )mptr;
for( int i = 0; i < StgSharp.ssdSegmentLength - 1; i += 1 ) {
v += ( *vptr ) * 31;
}
}
M128 m = new M128( v );
DataHash = m.vec.GetHashCode();
return DataHash;
}
public override int GetHashCode()
{
int ret = 17;
fixed( M128* mptr = &Head.data ) {
Vector4* vptr = ( Vector4* )mptr;
for( int i = 0; i < StgSharp.ssdSegmentLength; i++ ) {
ret = ( ret + ( *vptr ).GetHashCode() ) * 31;
}
}
return ret;
}
public unsafe T ReadData<T>( int index ) where T: struct
{
fixed( byte* bptr = Data ) {
T* tptr = ( T* )bptr;
return *( tptr + index );
}
}
public unsafe void WriteData<T>( int index, T value ) where T: struct
{
fixed( byte* bptr = Data ) {
T* tptr = ( T* )bptr;
*( tptr + index ) = value;
}
}
int IComparable<int>.CompareTo( int other )
{
return ID.CompareTo( other );
}
int IComparable<SSDSegment>.CompareTo( SSDSegment other )
{
return ID.CompareTo( other.ID );
}
}
}
+68
View File
@@ -0,0 +1,68 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="SSD.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.FileIO;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace StgSharp.Data
{
public partial class SSD
{
private Dictionary<string, SSDraw> fileList;
private FileStream file;
private SSDrawHead head;
public SSD()
{
fileList = new Dictionary<string, SSDraw>();
}
public SSD( FileStream fileStream )
{
fileList = new Dictionary<string, SSDraw>();
file = fileStream;
}
public static SSD FromFile( string fileRoute )
{
return new SSD(
new FileStream( fileRoute, FileMode.Open, FileAccess.Read ) )
{
};
}
}
}
@@ -0,0 +1,80 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="SSDVirtualFolder.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.FileIO;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Data
{
public class SSDFolder : ISSDSerializable
{
internal Dictionary<string, SSDFolder> folders;
internal int _folderID;
internal string _name;
internal SSDFolder()
{
folders = new Dictionary<string, SSDFolder>();
}
internal SSDFolder( string name )
{
if( name == "root" ) {
throw new ArgumentException(
"Name cannot be root," + "it is preserved for root file indexer." );
}
if( name == "default" ) {
throw new ArgumentException(
"Name cannot be default," + "it is preserved for default file id provider." );
}
_name = name;
folders = new Dictionary<string, SSDFolder>();
}
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.VirtualFolder;
public void FromBytes( byte[] stream )
{
throw new NotImplementedException();
}
//TODO 虚拟文件夹的GetBytes好难写
public byte[] GetBytes()
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,79 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="SSDraw.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.ShaderEdit;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Xml.Serialization;
namespace StgSharp.Data.FileIO
{
public class SSDraw
{
private byte[] data;
public SSDraw( string name, Stream streamSource )
{
if( ( streamSource == null ) || ( streamSource.Length == 0 ) ) {
throw new ArgumentNullException( nameof( streamSource ) );
}
Name = name;
data = new byte[streamSource.Length];
streamSource.Read( data.AsSpan() );
}
public SSDrawHead Head
{
get;
set;
}
public string Name
{
get;
set;
}
}
[StructLayout( LayoutKind.Explicit, Size = 32 * 16 )]
public unsafe struct SSDrawHead { }
}
@@ -0,0 +1,41 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Define.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.Data
{
/// <summary>
/// A class contains a sets of methods to serialize several types
/// </summary>
public static partial class Serializer { }
}
@@ -0,0 +1,109 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ISSDSerializable.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.Text;
using System.Threading.Tasks;
namespace StgSharp.Data
{
public interface ISSDSerializable
{
public SerializableTypeCode SSDTypeCode
{
get;
}
public byte[] GetBytes();
internal void FromBytes( byte[] stream );
}
public enum SerializableTypeCode
{
Unknown = 0,
IndexTable = 1,
PixelImage = 2,
VectorImage = 3,
Audio = 4,
Shader = 5,
Text = 6,
RawData = 7,
VirtualFolder = int.MaxValue,
}
public static partial class Serializer
{
public static T Deserialize<T>( byte[] stream )
where T: ISSDSerializable
{
T serializableObject = Activator.CreateInstance<T>();
serializableObject.FromBytes( stream );
return serializableObject;
}
public static string GetNameTail( SerializableTypeCode typeCode )
{
switch( typeCode ) {
case SerializableTypeCode.IndexTable:
return "_idt";
case SerializableTypeCode.PixelImage:
return "_pim";
case SerializableTypeCode.VectorImage:
return "_vim";
case SerializableTypeCode.Audio:
return "_wav";
case SerializableTypeCode.Shader:
return "_gls";
case SerializableTypeCode.Text:
return "_txt";
case SerializableTypeCode.RawData:
return "_raw";
case SerializableTypeCode.VirtualFolder:
return "_fod";
default:
throw new ArgumentException( "Unknown file type" );
}
}
public static byte[] Serialize( ISSDSerializable serializableObject )
{
return serializableObject.GetBytes();
}
}
}
@@ -0,0 +1,34 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BehaviorArgs.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp.Entities
{
public abstract class BehaviorArgs { }
}
@@ -0,0 +1,83 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="EliteEnemy.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;
namespace StgSharp.Entities
{
public class EliteEnemy : IEntity
{
internal Launcher<EntityPartical> _awardLauncher;
internal Launcher<EntityPartical> _dieBulletLauncher;
internal LinkedList<Launcher<EntityPartical>> _commonBulletLauncher;
public bool _selectalbe;
public Launcher<EntityPartical> AwardLauncher
{
get;
set;
}
public Launcher<EntityPartical> DieBulletLauncher
{
get;
set;
}
public LinkedList<Launcher<EntityPartical>> CommonBulletLauncher
{
get;
set;
}
public virtual void OnRender()
{
new NotImplementedException();
}
public override void OnRenderFrame()
{
this.OnUpdate();
foreach( Launcher<EntityPartical> launcher in CommonBulletLauncher ) {
launcher.Launch();
}
this.OnRender();
}
public virtual void OnUpdate()
{
new NotImplementedException();
}
}
}
@@ -0,0 +1,66 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Enemy.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp.Entities
{
public class Enemy : IEntity
{
internal Launcher<EntityPartical> _awardLauncher;
internal Launcher<EntityPartical> _commonBulletLauncher;
internal Launcher<EntityPartical> _dieBulletLauncher;
public bool _selectalbe;
public Launcher<EntityPartical> AwardLauncher
{
get;
set;
}
public Launcher<EntityPartical> CommonBulletLauncher
{
get;
set;
}
public Launcher<EntityPartical> DieBulletLauncher
{
get;
set;
}
public override void OnRenderFrame()
{
CommonBulletLauncher.Launch();
}
}
}
@@ -0,0 +1,34 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="EntityPartical.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp.Entities
{
public abstract class EntityPartical : IEntity { }
}
@@ -0,0 +1,107 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IEntity.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.Math;
using System;
using System.Collections.Generic;
namespace StgSharp
{
public abstract class IEntity
{
protected uint _bornTick;
internal Func<int, Vec3> _movHandler;
internal LinkedList<PlainGeometry> _collisionBox;
internal Point _basePoint;
internal Point _pos;
internal Point _position;
internal Sensor<PlainGeometry> _collisionSensor;
internal string _texture;
/// <summary>
/// X position of an enenmy entity
/// </summary>
public float X
{
get;
set;
}
/// <summary>
/// Y position of an enemy entity
/// </summary>
public float Y
{
get;
set;
}
public LinkedList<PlainGeometry> CollisionBox
{
get => _collisionBox;
set => _collisionBox = value;
}
/// <summary>
/// A sensor used for checking out if a bullet hit a player or something else
/// </summary>
public Sensor<PlainGeometry> CollisionSensor
{
get => _collisionSensor;
set => _collisionSensor = value;
}
public string TextureGL
{
get;
set;
}
/// <summary>
/// A 2D vector presenting the position of an enemy entity, position can also be visited by
/// X, Y
/// </summary>
public Vec2 Location
{
get;
}
public abstract void OnRenderFrame();
public void SetLocation( Point p )
{
_pos = p;
}
}
}
@@ -0,0 +1,58 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Launcher.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.Entities;
using StgSharp.Math;
namespace StgSharp
{
public class Launcher<T> where T: IEntity
{
internal uint[] launchtick; //发射子弹的内部计时
internal Counter<int> _internalParameter; //发射器的内部计时器
internal EntityPartical _bulletSample; //发射的子弹类型
/*
*用于发射其他的实体,主要是子弹 和 掉落物
*/
internal Vec2 _center; //发射器的参考位置,运动轨迹的方程应当基于这个参考点构建
public EntityPartical Bullet
{
get => _bulletSample;
set => _bulletSample = value;
}
internal virtual void Launch() { }
}
}
@@ -0,0 +1,44 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Partical.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;
namespace StgSharp
{
public class Partical : IEntity
{
public override void OnRenderFrame()
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,41 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Player.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp
{
public abstract class Player : IEntity
{
internal float _velocity;
public float Velocity => _velocity;
}
}
@@ -0,0 +1,113 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Dialogue.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.Diagnostics;
using System.IO;
using System.IO.Pipes;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp
{
public static class Dialogue
{
private static Process? _dialogueProcess;
private static AnonymousPipeServerStream _dialogueClientPipe,_dialogueServerPipe;
private static ProcessStartInfo _dialogueProcessInfo;
internal static void LoadDialogue()
{
_dialogueServerPipe = new AnonymousPipeServerStream(
PipeDirection.Out, HandleInheritability.Inheritable );
_dialogueClientPipe = new AnonymousPipeServerStream(
PipeDirection.In, HandleInheritability.Inheritable );
string route = Assembly.GetAssembly( typeof( StgSharp ) ).Location;
string path = Path.GetDirectoryName( route );
string exeName;
if( RuntimeInformation.IsOSPlatform( OSPlatform.Windows ) ) {
exeName = ".exe";
} else if( RuntimeInformation.IsOSPlatform( OSPlatform.Linux ) || RuntimeInformation.IsOSPlatform(
OSPlatform.OSX ) ) {
exeName = string.Empty;
} else {
throw new PlatformNotSupportedException( "Unknown OS platform" );
}
string consoleRoute = $"{path}{Path.DirectorySeparatorChar}StgSharpErrorConsole{exeName}";
ProcessStartInfo info = new ProcessStartInfo
{
FileName = path,
Arguments = _dialogueServerPipe.GetClientHandleAsString() + " " + _dialogueClientPipe.GetClientHandleAsString(),
UseShellExecute = true,
RedirectStandardOutput = false,
};
}
internal static void PostMessage(
string instruction,
params string[] operands ) { }
internal static void UnloadDialogue()
{
if( _dialogueProcess != null ) {
_dialogueProcess.Kill();
}
_dialogueProcess = null;
_dialogueServerPipe.Dispose();
_dialogueClientPipe.Dispose();
}
private static void CreateDialogueProcessIfNotExist()
{
if( _dialogueProcess != null ) {
return;
}
_dialogueProcess = Process.Start( _dialogueProcessInfo );
_dialogueProcess.Exited += ( sender, e ) => {
_dialogueProcess = null;
_dialogueProcess = null;
};
_dialogueServerPipe.DisposeLocalCopyOfClientHandle();
_dialogueClientPipe.DisposeLocalCopyOfClientHandle();
}
}
}
@@ -0,0 +1,47 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ErrorDefine.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.Text;
using System.Threading.Tasks;
namespace StgSharp
{
public class UniformEmptyReferenceException : Exception
{
public UniformEmptyReferenceException( string program, string name )
: base(
$"Location -1 returned when trying to find uniform {name} in shader program {program}" ) { }
}
}
@@ -0,0 +1,108 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GlobalSetting.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;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp
{
public static unsafe partial class StgSharp
{
internal const int ssdSegmentLength = 16;
private static byte[] _currentHash;
private static bool _inited;
private static int _mainThreadID = -1;
public static byte[] CurrentAssemblyHash
{
get
{
if( _currentHash == null ) {
string route = Assembly.GetExecutingAssembly().Location;
string time = DateTime.UtcNow.ToString();
using( SHA256 sh = SHA256.Create() ) {
byte[] bytes = Encoding.UTF8.GetBytes( route );
_currentHash = sh.ComputeHash( bytes );
}
}
return _currentHash;
}
}
public static int MainThreadID
{
get => ( _mainThreadID == -1 ) ?
throw new InvalidOperationException(
"StgSharp environment is not inited. " + "Main thread id is not available" ) : _mainThreadID;
}
/// <summary>
/// CustomizeInit an instance of OpenGL program, This method should be called before any
/// other StgSharp api.
/// </summary>
public static void InitGL( int majorVersion, int minorVersion )
{
if( API == default ) {
API = GraphicAPI.GL;
}
if( API != GraphicAPI.GL ) {
return;
}
InternalIO.InternalInitGL( majorVersion, minorVersion );
}
public static class GlobalSetting
{
private static bool vSyncActivated;
public static bool VSyncActivated
{
get => vsyncActivated;
set
{
InternalIO.glfwSwapInterval( value ? 1 : 0 );
vsyncActivated = value;
}
}
}
}//-------------------------------------- End of Class ---------------------------------------//
}
@@ -0,0 +1,69 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Monitors.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;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp
{
public static partial class StgSharp
{
private static unsafe IntPtr[] monitorsArray;
public static unsafe IntPtr[] MonitorsHandleArray
{
get
{
if( monitorsArray == null ) {
int count = 0;
IntPtr* arrayhandle = InternalIO.glfwGetMonitors( &count );
monitorsArray = new IntPtr[count];
Marshal.Copy(
( IntPtr )arrayhandle, monitorsArray, 0, count );
Marshal.FreeHGlobal( ( IntPtr )arrayhandle );
}
return monitorsArray;
}
}
public static IntPtr DefaultMonitor
{
get { return MonitorsHandleArray[ 0 ]; }
}
}
}
@@ -0,0 +1,197 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Platform.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.Envitronment;
// using StgSharp.Envitronment.Win32;
// using StgSharp.Graphics;
// using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
#if Windows
// using Windows.Win32.UI.WindowsAndMessaging;
// using Windows.Win32;
// using Windows.Win32.Foundation;
// using Windows.Win32.Graphics.OpenGL;
// using Windows.Win32.Graphics.Gdi;
// using Windows.Win32.UI;
#endif
namespace StgSharp
{
internal enum GraphicAPI : byte
{
GL,
DX,
VK
}
public static partial class StgSharp
{
/// <summary>
/// Version of current StgSharp platform. Main version represent in hundred's digit, and sub
/// version represent in ten's digit.
/// </summary>
public const long version = 430;
private static bool vsyncActivated;
private static uint markCount = 0;
internal static GraphicAPI API = default;
public static void Init()
{
mainTimeProvider = new StgSharpTime();
MainTimeProvider.StartProvidingTime();
InternalIO.glfwInit();
InternalIO.InternalAppendLog( "\n\n\n" );
InternalIO.InternalWriteLog(
$"Program {Assembly.GetEntryAssembly()!.FullName} Started.",
LogType.Info );
_mainThreadID = Environment.CurrentManagedThreadId;
}
public static void LogError( Exception ex )
{
InternalIO.InternalWriteLog( ex.Message, LogType.Error );
}
public static void LogInfo( string log )
{
InternalIO.InternalWriteLog( log, LogType.Info );
}
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 Mark( bool needConsole )
{
markCount++;
if( needConsole ) {
Console.WriteLine( markCount );
}
}
public static void Terminate()
{
MainTimeProvider.StopProvidingTime();
InternalIO.glfwTerminate();
}
public static void Track(
object target,
string message,
bool isConsole,
[CallerFilePath] string filePath = "",
[CallerMemberName] string callerName = "",
[CallerLineNumber] int lineNumber = 0 )
{
Type t = target.GetType();
string log = $"Tracked object: {nameof(target)}\t\tType:{t.Name}\n";
FieldInfo[] fieldInfo = t.GetFields(
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance );
log += "|\tFieldName\t|\tFieldType\t|\tFieldValue\t|\n";
foreach( FieldInfo field in fieldInfo ) {
log += $"|{field.Name}\t\t|{field.FieldType}\t\t|{field.GetValue(target)}\t\t|\n";
}
log += $"Tracking at:\n{filePath}\t{callerName}\tline {lineNumber}\n";
log += $"Additional information:\n{message}\n";
if( isConsole ) {
Console.WriteLine( log );
} else {
InternalIO.InternalWriteLog( log, LogType.Info );
}
}
/// <summary>
/// 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>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static void WriteLog( string message, LogType logType )
{
InternalIO.InternalWriteLog( message, logType );
}
internal static TDele ConvertAPI<TDele>( IntPtr funcPtr )
{
if( funcPtr == IntPtr.Zero ) {
throw new InvalidCastException(
"Failed to convert api, the function pointer is zero." );
}
try {
return Marshal.GetDelegateForFunctionPointer<TDele>( funcPtr );
}
catch( Exception ) {
throw;
}
}
internal static Delegate ConvertAPI( IntPtr funcPtr, Type T )
{
if( funcPtr == IntPtr.Zero ) {
throw new InvalidCastException(
"Failed to convert api, the function pointer is zero." );
}
try {
return Marshal.GetDelegateForFunctionPointer( funcPtr, T );
}
catch( Exception ) {
throw;
}
}
}
}
@@ -0,0 +1,52 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="globalKeyStat.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.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp
{
public static partial class StgSharp
{
private static ConcurrentDictionary<int, KeyStatus> keyListener
= new ConcurrentDictionary<int, KeyStatus>();
public static KeyStatus CheckKey( KeyboardKey key )
{
return keyListener.GetOrAdd( ( int )key, KeyStatus.RELEASE );
}
}
}
@@ -0,0 +1,84 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="CoordinationBase.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.Text;
using System.Threading.Tasks;
namespace StgSharp.Geometries
{
public abstract class CoordinationBase
{
private bool globalCoordAvailable;
private CoordinationBase localCoordination;
private Matrix44 coordMat;
public CoordinationBase( CoordinationBase localCoordination )
{
this.localCoordination = localCoordination;
coordMat = new Matrix44();
}
public virtual Point LocalOrigin
{
get => new Point( coordMat.colum3.XYZ );
internal set => coordMat.colum3.XYZ = value.Coord;
}
public virtual Vec3 LocalX
{
get => coordMat.colum0.XYZ;
internal set => coordMat.colum0.XYZ = value;
}
public virtual Vec3 LocalY
{
get => coordMat.colum1.XYZ;
internal set => coordMat.colum1.XYZ = value;
}
public virtual Vec3 LocalZ
{
get => coordMat.colum2.XYZ;
set => coordMat.colum2.XYZ = value;
}
protected ref Matrix44 CoordMat
{
get => ref coordMat;
}
}
}
@@ -0,0 +1,67 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="PlainCoordinate.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.Net.Http.Headers;
using System.Text;
namespace StgSharp.Geometries
{
public class PlainCoordinate : CoordinationBase
{
private static PlainCoordinate statndardPlainCoordination = new PlainCoordinate(
null, new Point( 0, 0, 0 ), new Vec3( 1, 0, 0 ),
new Vec3( 0, 1, 0 ) );
public PlainCoordinate(
CoordinationBase local,
Point origin,
Vec3 xAxis,
Vec3 yAxis )
: base( local )
{
CoordMat = Matrix44.Unit;
CoordMat.colum0 = new Vec4( xAxis, 0 );
CoordMat.colum1 = new Vec4( yAxis, 0 );
CoordMat.colum2 = new Vec4(
Linear.Normalize( Vec3.Cross( xAxis, yAxis ) ), 0 );
LocalOrigin = origin;
}
public static PlainCoordinate StandardPlainCoordination => statndardPlainCoordination;
}
}
@@ -0,0 +1,51 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="SpaceCoordinate.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.Text;
namespace StgSharp.Geometries
{
public class SpaceCoordinate : CoordinationBase
{
public SpaceCoordinate(
CoordinationBase localCoordination,
Point origin,
Vec3 xAxis,
Vec3 yAxis,
Vec3 zAxis )
: base( localCoordination ) { }
}
}
@@ -0,0 +1,46 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="StreamLocalCoordinate.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.Text;
using System.Threading.Tasks;
namespace StgSharp.Geometries
{
/*
public class StreamLocalCoordinate : CoordinationBase
{
}
/**/
}
@@ -0,0 +1,74 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GemoryException.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.Runtime.Serialization;
namespace StgSharp.Geometries
{
public unsafe class ToUpperDimensionException : Exception
{
protected ToUpperDimensionException(
SerializationInfo info,
StreamingContext context )
: base( info, context ) { }
public ToUpperDimensionException() { }
public ToUpperDimensionException( string message ) : base( message ) { }
public ToUpperDimensionException(
string message,
Exception innerException )
: base( message, innerException ) { }
}
/// <summary>
/// 当几何体调用了过多的CalcVec方法时,产生UnusedVertexException异常
/// </summary>
public class UnusedVertexException : Exception
{
protected UnusedVertexException(
SerializationInfo info,
StreamingContext context )
: base( info, context ) { }
public UnusedVertexException() { }
public UnusedVertexException( string message ) : base( message ) { }
public UnusedVertexException( string message, Exception innerException )
: base( message, innerException ) { }
}
}
@@ -0,0 +1,116 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GeometryOperation.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Math;
using StgSharp.Timing;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Geometries
{
[UnmanagedFunctionPointer( CallingConvention.Cdecl )]
public delegate Vec3 GeometryMotionDelegate(
TimeSpanProvider timeSource,
out float rotation );
public class GeometryMotion
{
private bool isIncrementMode;
private bool sourceIsStatic;
private GeometryMotionDelegate movement;
private IntPtr handle;
private TimeSpanProvider time;
public unsafe GeometryMotion(
bool isIncreament,
TimeSpanProvider timeSource,
GeometryMotionDelegate motionDelegate )
{
isIncrementMode = isIncreament;
time = timeSource;
if( motionDelegate == null ) {
handle = ( IntPtr )( delegate*<TimeSpanProvider, out float, Vec3> )&defaultMotion;
movement = defaultMotion;
} else if( motionDelegate.Method.IsStatic ) {
sourceIsStatic = true;
handle = Marshal.GetFunctionPointerForDelegate( motionDelegate );
movement = motionDelegate;
} else {
movement = motionDelegate;
}
//sourceIsStatic = false;
}
public bool IsIncrement
{
get => isIncrementMode;
}
public static GeometryMotion DefaultMotion
{
get => new GeometryMotion( true, null, null );
}
public unsafe void RunMotion( ref Vec3 coord, ref float rotation )
{
float rot;
Vec3 vec;
if( sourceIsStatic ) {
vec = ( ( delegate* unmanaged[Cdecl]<TimeSpanProvider, out float, Vec3> )handle )(
time, out rot );
} else {
vec = movement( time, out rot );
}
if( isIncrementMode ) {
coord += vec;
rotation += rot;
} else {
coord = vec;
rotation = rot;
}
}
private static Vec3 defaultMotion(
TimeSpanProvider provider,
out float rotation )
{
rotation = 0;
return Vec3.Zero;
}
}//------------------------------- End of Class -------------------------------
}
@@ -0,0 +1,178 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Angle.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.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Math
{
public static partial class GeometryScaler
{
internal const float DegToRad = 180 / Scaler.Pi;
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static float Cos( Radius r )
{
return MathF.Cos( r._radius );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static float Cos( Degree r )
{
return MathF.Cos( r._degree / DegToRad );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static float Sin( Radius r )
{
return MathF.Sin( r._radius );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static float Sin( Degree r )
{
return MathF.Sin( r._degree / DegToRad );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static float Tan( Radius r )
{
return MathF.Tan( r._radius );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static float Tan( Degree r )
{
return MathF.Tan( r._degree / DegToRad );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Degree ToDegree( float value )
{
return new Degree( value );
}
}
public struct Degree
{
internal float _degree;
internal Degree( float dgree )
{
_degree = dgree;
}
public static implicit operator Radius( Degree d )
{
return new Radius( d._degree / GeometryScaler.DegToRad );
}
}
public struct Radius
{
internal float _radius;
[Obsolete( "Unsafe, you may forget this is radius.", true )]
public Radius() { }
public Radius( float radius )
{
_radius = radius;
}
public static Radius Zero
{
get => new Radius( 0 );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Radius operator -( Radius r )
{
return new Radius( -r._radius );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Radius operator -( Radius left, Radius Right )
{
return new Radius( left._radius - Right._radius );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static bool operator !=( Radius left, Radius right )
{
return left._radius != right._radius;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Radius operator *( Radius left, float right )
{
return new Radius( left._radius * right );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Radius operator /( Radius left, float right )
{
return new Radius( left._radius / right );
}
[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 )
{
return new Radius( left._radius + Right._radius );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static bool operator ==( Radius left, Radius right )
{
return left._radius == right._radius;
}
public static implicit operator Degree( Radius r )
{
return new Degree( ( r._radius * 180 ) / Scaler.Pi );
}
}
}
@@ -0,0 +1,74 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IGeometry.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Geometries
{
public interface IGeometry
{
public Point this[ int index ]
{
get;
set;
}
#pragma warning disable CA1819
public Vec4[] VertexStream
#pragma warning restore CA1819
{
get;
}
public CoordinationBase Coordination
{
get;
}
public int VertexCount
{
get;
}
public ReadOnlySpan<int> VertexIndices
{
get;
}
}
}
@@ -0,0 +1,40 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IGeomtryBuffer.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.Text;
using System.Threading.Tasks;
namespace StgSharp.Geometries
{
public interface IGeomtryBuffer { }
}
@@ -0,0 +1,102 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 float Rotation
{
get { return GlobalBuffer.CoordAndRotationList[ BufferId ].W; }
set
{
Vec4 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 IInstancingBuffer GlobalBuffer
{
get;
internal set;
}
public int BufferId
{
get;
internal set;
}
public Vec3 CenterPositionGlobal
{
get;
internal set;
}
public Vec3 Coord
{
get { return GlobalBuffer.CoordAndRotationList[ BufferId ].XYZ; }
set { GlobalBuffer.CoordAndRotationList[ BufferId ] = new Vec4(
value.vec ); }
}
public void Move()
{
(Vec3 coord, float rotation) = (Coord, Rotation);
Motion.RunMotion( ref coord, ref rotation );
(Coord, Rotation) = (coord, rotation);
}
}
}
@@ -0,0 +1,73 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IInstancingBuffer.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.Text;
namespace StgSharp.Geometries
{
public interface IInstancingBuffer
{
public Span<Vec4> CoordAndRotationSpan
{
get;
}
public Span<float> ScalingSpan
{
get;
}
internal IGeometry TypicalShape
{
get;
}
internal List<IInstancing> InstanceList
{
get;
}
internal List<Vec4> CoordAndRotationList
{
get;
}
internal List<float> ScalingList
{
get;
}
}
}
@@ -0,0 +1,85 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Cordinate.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.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Geometries
{
[StructLayout( LayoutKind.Sequential )]
public struct PartialPlainCoordinate
{
internal Matrix32 axis;
/// <summary>
/// The origin of this coordinate.
/// </summary>
public Vec3 origin;
public PartialPlainCoordinate(
Vec3 origin,
Vec3 horiziontial,
Vec3 vertical )
{
this.origin = origin;
axis = new Matrix32();
#if NET5_0_OR_GREATER
Unsafe.SkipInit( out axis.mat );
#endif
axis.colum0 = horiziontial;
axis.colum1 = vertical;
}
/// <summary>
/// The horizontial axis of the coordinate. Point to the right direction.
/// </summary>
public Vec3 axis_H => axis.colum0;
/// <summary>
/// The vertical axis of the coordinate. Point to the top direction.
/// </summary>
public Vec3 axis_V => axis.colum1;
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public Vec3 GetRealLocate( Vec2 raletiveLocation )
{
return origin + axis.VerticalVecMultiply( raletiveLocation );
}
}
}
@@ -0,0 +1,47 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GeometryOperation.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.Runtime.CompilerServices;
namespace StgSharp.Geometries
{
public static unsafe class GeometryOperation
{
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Vec3 DefaultMotion( int tick )
{
return default( Vec3 );
}
}
}
@@ -0,0 +1,76 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IPlainEntity.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.Text;
using System.Threading.Tasks;
namespace StgSharp.Geometries
{
public interface IPlainEntity
{
public Vec2 CenterPosition
{
get;
set;
}
public bool CollideWith( IPlainEntity entity );
}
public class PlainEntity : IPlainEntity
{
private PlainGeometry _shape;
public PlainEntity( PlainGeometry shape )
{
_shape = shape;
}
bool IPlainEntity.CollideWith( IPlainEntity entity )
{
throw new NotImplementedException();
}
Vec2 IPlainEntity.CenterPosition
{
get => _shape.Coordination.LocalOrigin.Coord.XY;
set => throw new InvalidOperationException();
}
}
}
@@ -0,0 +1,92 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ParticleOnPlain.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 GeometryMotion Motion
{
get;
set;
}
public IInstancingBuffer GlobalBuffer
{
get;
set;
}
public int BufferId
{
get;
set;
}
Vec3 IInstancing.CenterPositionGlobal
{
get;
set;
}
bool IPlainEntity.CollideWith( IPlainEntity entity )
{
throw new NotImplementedException();
}
Vec2 IPlainEntity.CenterPosition
{
get => GlobalBuffer.CoordAndRotationList[ BufferId ].XY;
set => throw new NotImplementedException();
}
}
}
@@ -0,0 +1,72 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="PlainGeometry.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics;
using StgSharp.Math;
using System;
using System.ComponentModel;
namespace StgSharp.Geometries
{
/// <summary>
/// Plain geometry only contains straight sides.
/// </summary>
public abstract class PlainGeometry : IGeometry
{
protected Vec4[] vertexMat;
internal CoordinationBase coordinate;
internal PlainGeometry( CoordinationBase coordination )
{
coordinate = coordination;
}
public Point this[ int index ]
{
get => new Point( vertexMat[ index ] );
set => vertexMat[ index ].vec = value.coordVec;
}
public int VertexCount => this.vertexMat.Length;
public abstract ReadOnlySpan<int> VertexIndices
{
get;
}
#pragma warning disable CA1819
public Vec4[] VertexStream => vertexMat;
public CoordinationBase Coordination => this.coordinate;
#pragma warning restore CA1819
}
}
@@ -0,0 +1,217 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="PlainInstancingBuffer.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;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Geometries
{
public class PlainInstancingBuffer<T> : IDisposable, IEnumerable<T>, IInstancingBuffer
where T: IInstancing
{
private bool disposedValue;
private CoordinatePlain globalCorrdinnate;
private List<Vec4> coordList;
private List<IInstancing> instanceList;
private List<float> scalingList;
private Mutex mutex;
public PlainInstancingBuffer()
{
coordList = new List<Vec4>( capacity: 100 );
instanceList = new List<IInstancing>( capacity: 100 );
scalingList = new List<float>( capacity: 100 );
coordArray = Array.Empty<Vec4>();
scaleArray = Array.Empty<float>();
mutex = new Mutex();
}
public List<IInstancing> InstanceList
{
get => instanceList;
}
public List<Vec4> CoordAndRotationList
{
get => coordList;
}
public List<float> ScalingList
{
get => scalingList;
}
public Span<Vec4> CoordAndRotationSpan
{
get
{
if( coordArray.Length != coordList.Capacity ) {
FieldInfo fieldInfo = typeof( List<Vec4> ).
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 = ( Vec4[] )fieldInfo.GetValue( coordList );
}
return new Span<Vec4>( coordArray, 0, coordList.Count );
}
}
public Span<float> ScalingSpan
{
get
{
if( scaleArray.Length != coordList.Capacity ) {
FieldInfo fieldInfo = typeof( List<float> ).
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 );
}
return new Span<float>( scaleArray, 0, coordList.Count );
}
}
public int CreateInstanceID()
{
mutex.WaitOne();
int ret = instanceList.Count;
coordList.Add( new Vec4() );
scalingList.Add( 0 );
mutex.ReleaseMutex();
return ret;
}
// ~PlainInstancingBuffer()
// {
// Dispose(disposing: false);
// }
public void Dispose()
{
Dispose( disposing: true );
GC.SuppressFinalize( this );
}
public IEnumerator<T> GetEnumerator()
{
foreach( IInstancing item in instanceList ) {
yield return ( T )item;
}
}
public void Remove( T instance )
{
mutex.WaitOne();
if( instance.GlobalBuffer != this ) {
throw new ArgumentException(
message: "instance does not belong to current Particle Buffer",
paramName: nameof( instance ) );
}
int index = instance.BufferId;
IInstancing temp = instanceList[ instanceList.Count - 1 ];
instanceList[ instance.BufferId ] = temp;
temp.BufferId = instance.BufferId;
coordList[ instance.BufferId ] = coordList[ coordList.Count - 1 ];
scalingList[ instance.BufferId ] = scalingList[
scalingList.Count - 1 ];
instanceList.RemoveAt( instanceList.Count - 1 );
coordList.RemoveAt( coordList.Count - 1 );
scalingList.RemoveAt( scalingList.Count - 1 );
mutex.ReleaseMutex();
}
public void UpdateAllParticles()
{
foreach( IInstancing particle in instanceList ) {
particle.Move();
}
}
protected virtual void Dispose( bool disposing )
{
if( !disposedValue ) {
if( disposing ) {
mutex.Dispose();
}
coordList.Clear();
instanceList.Clear();
scalingList.Clear();
disposedValue = true;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
foreach( IInstancing item in instanceList ) {
yield return ( T )item;
}
}
IGeometry IInstancingBuffer.TypicalShape => throw new NotImplementedException(
);
#region field of mem opt
private Vec4[] coordArray;
private float[] scaleArray;
#endregion
}
}
@@ -0,0 +1,88 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Parallelogram.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;
namespace StgSharp.Geometries
{
public class Parallelogram : Polygon4
{
internal readonly Func<int, Vec3> movCenterOperation =
new Func<int, Vec3>( GeometryOperation.DefaultMotion );
internal Point center;
public Parallelogram(
float v0x,
float v0y,
float v1x,
float v1y,
float v2x,
float v2y,
float v3x,
float v3y )
: base( v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y )
{
#if DEBUG
if( this[ 0 ].Coord + this[ 2 ].Coord != this[ 1 ].Coord + this[ 3 ].Coord ) {
InternalIO.InternalWriteLog(
"Init of geometry item failed, because four vertices cannot form a rectangle.",
LogType.Warning );
}
#endif
}
public Parallelogram(
PlainCoordinate coordination,
float v0x,
float v0y,
float v1x,
float v1y,
float v2x,
float v2y,
float v3x,
float v3y )
: base( coordination, v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y )
{
#if DEBUG
if( this[ 0 ].Coord + this[ 2 ].Coord != this[ 1 ].Coord + this[ 3 ].Coord ) {
InternalIO.InternalWriteLog(
"Init of geometry item failed, because four vertices cannot form a rectangle.",
LogType.Warning );
}
#endif
}
}
}
@@ -0,0 +1,96 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Plain.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.Numerics;
namespace StgSharp.Geometries
{
public unsafe class Plain
{
internal readonly float d = -1;
internal Vec3 origin;
internal Vec3 plainParameter;
internal Vec3 vec1;
internal Vec3 vec2;
internal Plain( Vector4 origin, Vector4 p1, Vector4 p2 )
{
this.origin = new Vec3( origin );
vec1 = new Vec3( p1 - origin );
vec2 = new Vec3( p2 - origin );
}
public Plain( Vec3 o, Vec3 v1, Vec3 v2 )
{
this.origin = o;
this.vec1 = v1 - ( v2 * ( v1.Y / v2.Y ) ); //计算平面在xz平面上的方向投影
this.vec2 = v2 - ( vec1 * ( v2.X / v1.X ) ); //计算平面在yz平面上的方向投影
//|origin|-k1*|vec1|-k2*|vec2|计算plainParameter.Z;
plainParameter.Z = origin.Z - ( vec1.Z * ( origin.X / vec1.X ) ) - ( vec2.Z * ( origin.Y / vec2.Y ) );
//根据plainParameter.Z和对应的方向矢量计算plainParameter.X和plainParameter.Y
plainParameter.X = vec1.X * ( vec1.Z / plainParameter.Z );
plainParameter.Y = vec2.Y * ( vec2.Z / plainParameter.Z );
plainParameter.X = 1 / plainParameter.X;
plainParameter.Y = 1 / plainParameter.Y;
plainParameter.Z = 1 / plainParameter.Z;
}
public Plain( Point p1, Point p2, Point p3 )
{
Vec3 origin = p1.Coord;
Vec3 v1 = p2.Coord - origin;
Vec3 v2 = p3.Coord - origin;
vec1 = v1 - ( v2 * ( v1.Y / v2.Y ) ); //计算平面在xz平面上的方向投影
vec2 = v2 - ( vec1 * ( v2.X / v1.X ) ); //计算平面在yz平面上的方向投影
//|origin|-k1*|vec1|-k2*|vec2|计算plainParameter.Z;
plainParameter.Z = origin.Z - ( vec1.Z * ( origin.X / vec1.X ) ) - ( vec2.Z * ( origin.Y / vec2.Y ) );
//根据plainParameter.Z和对应的方向矢量计算plainParameter.X和plainParameter.Y
plainParameter.X = vec1.X * ( vec1.Z / plainParameter.Z );
plainParameter.Y = vec2.Y * ( vec2.Z / plainParameter.Z );
plainParameter.X = 1 / plainParameter.X;
plainParameter.Y = 1 / plainParameter.Y;
plainParameter.Z = 1 / plainParameter.Z;
}
}
}
@@ -0,0 +1,129 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Polygon4.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.Numerics;
namespace StgSharp.Geometries
{
public class Polygon4 : PlainGeometry
{
protected static int[] Indices = [0, 1, 2, 0, 2, 3];
internal Polygon4()
: base( PlainCoordinate.StandardPlainCoordination )
{
vertexMat = new Vec4[4];
}
internal Polygon4( Vec4[] rawCoord )
: base( PlainCoordinate.StandardPlainCoordination )
{
if( rawCoord.Length != 4 ) {
throw new ArgumentOutOfRangeException( nameof( rawCoord ) );
}
vertexMat = rawCoord;
}
public Polygon4(
Point topLeft,
Point topRight,
Point bottomRight,
Point bottomLeft )
: base( PlainCoordinate.StandardPlainCoordination )
{
this[ 0 ] = topLeft;
this[ 1 ] = topRight;
this[ 2 ] = bottomRight;
this[ 3 ] = bottomLeft;
}
public Polygon4(
CoordinationBase coordinate,
PlainCoordinate coordination,
Point topLeft,
Point topRight,
Point bottomRight,
Point bottomLeft )
: base( coordinate )
{
this[ 0 ] = topLeft;
this[ 1 ] = topRight;
this[ 2 ] = bottomRight;
this[ 3 ] = bottomLeft;
}
public Polygon4(
float v0x,
float v0y,
float v1x,
float v1y,
float v2x,
float v2y,
float v3x,
float v3y )
: base( PlainCoordinate.StandardPlainCoordination )
{
vertexMat = new Vec4[4];
this[ 0 ] = new Point( v0x, v0y, 0 );
this[ 1 ] = new Point( v1x, v1y, 0 );
this[ 2 ] = new Point( v2x, v2y, 0 );
this[ 3 ] = new Point( v3x, v3y, 0 );
}
public Polygon4(
PlainCoordinate coordination,
float v0x,
float v0y,
float v1x,
float v1y,
float v2x,
float v2y,
float v3x,
float v3y )
: base( coordination )
{
vertexMat = new Vec4[4];
this[ 0 ] = new Point( v0x, v0y, 0 );
this[ 1 ] = new Point( v1x, v1y, 0 );
this[ 2 ] = new Point( v2x, v2y, 0 );
this[ 3 ] = new Point( v3x, v3y, 0 );
}
public override ReadOnlySpan<int> VertexIndices => Indices;
}
}
@@ -0,0 +1,96 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Polygon5.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.Numerics;
namespace StgSharp.Geometries
{
public unsafe class Polygon5 : PlainGeometry
{
internal static int[] Indices = [0, 1, 2, 0, 2, 3, 0, 3, 4];
public unsafe Polygon5()
: base( PlainCoordinate.StandardPlainCoordination )
{
vertexMat = new Vec4[5];
}
public Polygon5(
float v0x,
float v0y,
float v1x,
float v1y,
float v2x,
float v2y,
float v3x,
float v3y,
float v4x,
float v4y )
: base( PlainCoordinate.StandardPlainCoordination )
{
vertexMat = new Vec4[5];
this[ 0 ] = new Point( v0x, v0y, 0 );
this[ 1 ] = new Point( v1x, v1y, 0 );
this[ 2 ] = new Point( v2x, v2y, 0 );
this[ 3 ] = new Point( v3x, v3y, 0 );
this[ 4 ] = new Point( v4x, v4y, 0 );
}
public Polygon5(
PlainCoordinate coordination,
float v0x,
float v0y,
float v1x,
float v1y,
float v2x,
float v2y,
float v3x,
float v3y,
float v4x,
float v4y )
: base( coordination )
{
vertexMat = new Vec4[5];
this[ 0 ] = new Point( v0x, v0y, 0 );
this[ 1 ] = new Point( v1x, v1y, 0 );
this[ 2 ] = new Point( v2x, v2y, 0 );
this[ 3 ] = new Point( v3x, v3y, 0 );
this[ 4 ] = new Point( v4x, v4y, 0 );
}
public override ReadOnlySpan<int> VertexIndices => Indices;
}
}
@@ -0,0 +1,74 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Polygon6.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.Numerics;
namespace StgSharp.Geometries
{
public class Polygon6 : PlainGeometry
{
internal static int[] Indices = [0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5];
public Polygon6()
: base( PlainCoordinate.StandardPlainCoordination )
{
vertexMat = new Vec4[6];
}
public Polygon6(
PlainCoordinate coordination,
Vec2 vert0,
Vec2 vert1,
Vec2 vert2,
Vec2 vert3,
Vec2 vert4,
Vec2 vert5,
Vec2 vert6 )
: base( coordination )
{
vertexMat = new Vec4[6];
vertexMat[ 0 ].vec = vert0.vec;
vertexMat[ 1 ].vec = vert1.vec;
vertexMat[ 2 ].vec = vert2.vec;
vertexMat[ 3 ].vec = vert3.vec;
vertexMat[ 4 ].vec = vert4.vec;
vertexMat[ 5 ].vec = vert5.vec;
vertexMat[ 6 ].vec = vert6.vec;
}
public override ReadOnlySpan<int> VertexIndices => Indices;
}
}
@@ -0,0 +1,93 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Rectangle.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.Numerics;
namespace StgSharp.Geometries
{
public class Rectangle : Parallelogram
{
public Rectangle(
float v0x,
float v0y,
float v1x,
float v1y,
float v2x,
float v2y,
float v3x,
float v3y )
: base( v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y )
{
#if DEBUG
Vec2 side0 = ( this[ 0 ].Coord - this[ 1 ].Coord ).XY;
Vec2 side1 = ( this[ 2 ].Coord - this[ 1 ].Coord ).XY;
if( side0.Cross( side1 ) == 0 ) {
throw new ArgumentException();
}
#endif
}
public Rectangle(
PlainCoordinate coordination,
float v0x,
float v0y,
float v1x,
float v1y,
float v2x,
float v2y,
float v3x,
float v3y )
: base( coordination, v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y )
{
#if DEBUG
Vec2 side0 = ( this[ 0 ].Coord - this[ 1 ].Coord ).XY;
Vec2 side1 = ( this[ 2 ].Coord - this[ 1 ].Coord ).XY;
if( side0.Cross( side1 ) == 0 ) {
throw new ArgumentException();
}
#endif
}
/// <summary>
/// Calculate movement to center
/// </summary>
/// <param name="tick"> CurrentBlueprint time tick </param>
/// <returns></returns>
public virtual Vec3 MovCenter( uint tick )
{
return default( Vec3 );
}
}
}
@@ -0,0 +1,58 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Square.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.Numerics;
namespace StgSharp.Geometries
{
/// <summary>
/// A square
/// </summary>
public class Square : Rectangle
{
public Square(
float v0x,
float v0y,
float v1x,
float v1y,
float v2x,
float v2y,
float v3x,
float v3y )
: base( v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y )
{
if( true ) { }
}
}
}
@@ -0,0 +1,103 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Triangle.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics;
using StgSharp.Math;
using System;
using System.Numerics;
namespace StgSharp.Geometries
{
public unsafe class Triangle : PlainGeometry
{
internal static int[] Indices = [0, 1, 2];
public Triangle()
: base( PlainCoordinate.StandardPlainCoordination )
{
vertexMat = new Vec4[3];
}
public Triangle( Point vertex01, Point vertex02, Point vertex03 )
: base( PlainCoordinate.StandardPlainCoordination )
{
this[ 0 ] = vertex01;
this[ 1 ] = vertex02;
this[ 2 ] = vertex03;
}
public Triangle(
PlainCoordinate coordination,
Point vertex01,
Point vertex02,
Point vertex03 )
: base( coordination )
{
this[ 0 ] = vertex01;
this[ 1 ] = vertex02;
this[ 2 ] = vertex03;
}
public Triangle(
float v0x,
float v0y,
float v1x,
float v1y,
float v2x,
float v2y )
: base( PlainCoordinate.StandardPlainCoordination )
{
this[ 0 ] = new Point( v0x, v0y, 0 );
this[ 1 ] = new Point( v1x, v1y, 0 );
this[ 2 ] = new Point( v2x, v2y, 0 );
}
public Triangle(
PlainCoordinate coordination,
float v0x,
float v0y,
float v1x,
float v1y,
float v2x,
float v2y )
: base( coordination )
{
this[ 0 ] = new Point( v0x, v0y, 0 );
this[ 1 ] = new Point( v1x, v1y, 0 );
this[ 2 ] = new Point( v2x, v2y, 0 );
}
public override ReadOnlySpan<int> VertexIndices => Indices;
}
}
@@ -0,0 +1,76 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Point.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.Numerics;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Geometries
{
[StructLayout( LayoutKind.Explicit, Size = 16 )]
public struct Point
{
[FieldOffset( 0 )] private Vec3 coord;
[FieldOffset( 0 )] internal Vector4 coordVec;
internal Point( Vec4 vector )
{
coordVec = vector.vec;
coordVec.W = 1;
}
public Point( Vec3 coord )
{
Coord = coord;
coordVec.W = 1;
}
public Point( float x, float y, float z )
{
coordVec = new Vector4( x, y, z, 1 );
}
public Vec3 Coord
{
get => coord;
set
{
coord = value;
coordVec.W = 1;
}
}
}
}
@@ -0,0 +1,38 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Class1.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.Geometries.SpaceGeometry
{
internal class Class1 { }
}
@@ -0,0 +1,17 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Design", "CA1008:枚举应具有零值", Justification = "<挂起>", Scope = "type", Target = "~T:StgSharp.Graphics.OpenGL.ShaderStatus")]
[assembly: SuppressMessage("Naming", "CA1715:标识符应具有正确的前缀", Justification = "<挂起>", Scope = "member", Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``2(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1}")]
[assembly: SuppressMessage("Naming", "CA1715:标识符应具有正确的前缀", Justification = "<挂起>", Scope = "member", Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``3(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1,``2}")]
[assembly: SuppressMessage("Naming", "CA1715:标识符应具有正确的前缀", Justification = "<挂起>", Scope = "member", Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``4(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1,``2,``3}")]
[assembly: SuppressMessage("Naming", "CA1715:标识符应具有正确的前缀", Justification = "<挂起>", Scope = "type", Target = "~T:StgSharp.Graphics.OpenGL.Uniform`4")]
[assembly: SuppressMessage("Design", "CA1043:将整型或字符串参数用于索引器", Justification = "<挂起>", Scope = "member", Target = "~P:StgSharp.MVVM.View.ViewBase.IViewResponder`1.Item(StgSharp.Controlling.UsrActivity.ITrigger)")]
[assembly: SuppressMessage("Design", "CA1043:将整型或字符串参数用于索引器", Justification = "<挂起>", Scope = "member", Target = "~P:StgSharp.MVVM.View.ViewBase.ViewResponder`1.Item(StgSharp.Controlling.UsrActivity.ITrigger)")]
[assembly: SuppressMessage("Performance", "CA1864:首选 \"IDictionary.TryAdd(TKey, TValue)\" 方法", Justification = "<挂起>", Scope = "member", Target = "~P:StgSharp.MVVM.View.ViewBase.ViewRender`1.Item(System.String)")]
[assembly: SuppressMessage("Design", "CA1033:接口方法应可由子类型调用", Justification = "<挂起>", Scope = "member", Target = "~P:StgSharp.Collections.IBidirectionalDictionary`2.System#Collections#Generic#IDictionary<TFirst,TSecond>#Keys")]
[assembly: SuppressMessage("Design", "CA1033:接口方法应可由子类型调用", Justification = "<挂起>", Scope = "member", Target = "~P:StgSharp.Collections.IBidirectionalDictionary`2.System#Collections#Generic#IDictionary<TFirst,TSecond>#Values")]
@@ -0,0 +1,43 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IImageProvider.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.Graphics
{
public interface IImageProvider
{
Image ProvideImage();
}
}
@@ -0,0 +1,89 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ImageHelper.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.ComponentModel;
using System.Text;
namespace StgSharp.Graphics
{
public static class ImageHelper
{
public static void Resize(
Image i,
int width,
int height,
ImageMovement move )
{
if( i == null ) {
throw new ArgumentNullException( nameof( i ) );
}
if( i.Size == (width, height) ) {
return;
}
if( !Enum.IsDefined( typeof( ImageMovement ), move ) ) {
throw new InvalidEnumArgumentException( nameof( move ) );
}
byte[] oldData = i.Data;
i.Data = new byte[width * height * i.PixelSize];
i.Height = height;
i.Width = width;
i.PixelUpdateCount++;
switch( move ) {
case ImageMovement.Discard:
break;
case ImageMovement.Top:
break;
default:
throw new NotImplementedException();
}
}
}
[Flags]
public enum ImageMovement
{
#pragma warning disable CA1008
Discard = 0,
#pragma warning restore CA1008
Top = 1,
Bottom = 2,
Left = 4,
Right = 8,
TopLeft = Top | Left,
BottomLeft = Bottom | Left,
TopRight = Top | Right,
BottomRight = Bottom | Right,
}
}
@@ -0,0 +1,83 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BufferObjectBase.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.OpenGL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
/// <summary>
/// Interface of all kinds OpenGL buffer objects
/// </summary>
public abstract class BufferObjectBase : IDisposable
{
protected GlHandle[] _bufferHandle;
protected RenderStream binding;
/// <summary>
/// Get the only handle to one of the Object instance
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public GlHandle this[ int index ] => _bufferHandle[ index ];
/// <summary>
/// Bind a buffer instance to OpenGL
/// </summary>
/// <param name="index"> Index of handle of the object in this instance to be bind </param>
public abstract void Bind( int index );
public void Dispose()
{
Dispose( disposing: true );
GC.SuppressFinalize( this );
}
/// <inheritdoc />
public override string ToString()
{
return $"This is a {GetType().FullName}, containing {_bufferHandle.Length} buffer handles: {_bufferHandle.ToString()}.";
}
protected abstract void Dispose( bool disposing );
~BufferObjectBase()
{
Dispose( disposing: false );
}
}
}
@@ -0,0 +1,959 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="StructDefine.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.OpenGL;
using System;
using System.Runtime.InteropServices;
/**/
namespace StgSharp.Graphics
{
//rename types in style of GLFW
using GLFWbool = Boolean;
//strucs defined in GLFW3.h
#region GLFW3 struct
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWcontext
{
private delegate*<byte*> extensionSupported;
private delegate*<delegate*<void>, void> getProcAddress;
/*
void (* makeCurrent) (glfwWindow*);
void (* swapBuffers) (glfwWindow*);
void (* swapInterval) (int);
int (* extensionSupported) (const byte*);
GLFWglproc(*getProcAddress)(const byte*);
void (* destroy) (glfwWindow*);
*/
private delegate*<glfwWindow*> makeCurrent;
private delegate*<glfwWindow*> swapBuffer;
private delegate*<int> swapInterval;
private GLFWbool forward, debug, noerror;
private int client;
private int major, minor, revision;
private int profile;
private int release;
private int robustness;
private int source;
private IntPtr destroy;
//PFNGLGETINTEGERVPROC GetIntegerv;
private IntPtr GetIntegerv;
//PFNGLGETSTRINGPROC GetString;
private IntPtr GetString;
//PFNGLGETSTRINGIPROC GetStringi;
private IntPtr GetStringi;
internal struct egl
{
private void* client;
/*
EGLConfig config;
EGLContext handle;
EGLSurface surface;
*/
private void* config;
private void* handle;
private void* surface;
}
internal struct osmesa
{
private void* buffer;
//OSMesaContext handle;
private void* handle;
private int height;
private int width;
}
// This is defined in platform.h
//GLFW_PLATFORM_CONTEXT_STATE
}
[StructLayout( LayoutKind.Sequential )]
public unsafe struct glfwVideomode
{
/*! The refresh rate, in Hz, of the video mode.
*/
private int refreshRate;
/*! The bit depth of the blue channel of the video mode.
*/
public int blueBits;
/*! The bit depth of the green channel of the video mode.
*/
public int greenBits;
/*! The height, in screen coordinates, of the video mode.
*/
public int height;
/*! The bit depth of the red channel of the video mode.
*/
public int redBits;
/*! The width, in screen coordinates, of the video mode.
*/
public int width;
}
[StructLayout( LayoutKind.Sequential )]
public unsafe struct glfwGammaramp
{
/*! An array of value describing the response of the blue channel.
*/
private ushort* blue;
/*! An array of value describing the response of the green channel.
*/
private ushort* green;
/*! An array of value describing the response of the red channel.
*/
private ushort* red;
/*! The number of elements in each array.
*/
private uint size;
}
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWimage
{
/*! The pixel _data of this image, arranged left-to-right, top-to-bottom.
*/
private byte* pixels;
/*! The height, in pixels, of this image.
*/
private int height;
/*! The width, in pixels, of this image.
*/
private int width;
}
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWgamepadstate
{
/*! The states of each [gamepad button](@ref gamepad_buttons), `GLFW_PRESS`
* or `GLFW_RELEASE`.
*/
public fixed byte buttons[ 15 ];
/*! The states of each [gamepad axis](@ref gamepad_axes), in the range -1.0
* to 1.0 inclusive.
*/
public fixed float axes[ 6 ];
}
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWallocator
{
private void* user;
//GLFWallocatefun allocate;
private IntPtr allocate;
//GLFWdeallocatefun deallocate;
private IntPtr deallocate;
//GLFWreallocatefun reallocate;
private IntPtr reallocate;
}
[StructLayout( LayoutKind.Sequential )]
public unsafe struct glfwMonitor
{
private glfwVideomode* modes;
private glfwWindow* window;
private fixed byte name[ 128 ];
private glfwGammaramp currentRamp;
private glfwGammaramp originalRamp;
private glfwVideomode currentMode;
private int modeCount;
private int width, height;
private IntPtr userPointer;
public glfwMonitor() { }
public unsafe string Name
{
get
{
fixed( byte* cptr = name ) {
return Marshal.PtrToStringAnsi( ( IntPtr )cptr );
}
}
}
}
[StructLayout( LayoutKind.Sequential )]
internal unsafe struct glfwWindow
{
private glfwWindow* next;
private void* userPointer;
private bool rawMouseMotion;
private Callbacks callbacks;
// Virtual cursor position when cursor is disabled
private double virtualCursorPosX, virtualCursorPosY;
private int autoIconify;
private int cursorMode;
private int decorated;
private int doublebuffer;
private int floating;
private int focusOnShow;
private int lockKeyMods;
private int maxwidth, maxheight;
private int minwidth, minheight;
private int mousePassthrough;
private int numer, denom;
// Window settings and state
private int resizable;
private int shouldClose;
private int stickyKeys;
private int stickyMouseButtons;
private IntPtr cursor; // _GLFWcursor* cursor;
// glfwVideomode videoMode; // 根据GLFWvidmode的定义转换
private IntPtr monitor; // _GLFWmonitor* monitor;
public fixed byte keys[ GLconst.GLFW_KEY_LAST + 1 ];
public fixed byte mouseButtons[ GLconst.GLFW_MOUSE_BUTTON_LAST + 1 ];
// _GLFWcontext viewPortDisplay; // 根据_GLFWcontext的定义转换
// Callbacks are represented as IntPtr since we don't need the actual function pointers in C#
internal struct Callbacks
{
internal IntPtr character;
internal IntPtr charmods;
internal IntPtr close;
internal IntPtr cursorEnter;
internal IntPtr cursorPos;
internal IntPtr drop;
internal IntPtr fbsize;
internal IntPtr focus;
internal IntPtr iconify;
internal IntPtr key;
internal IntPtr maximize;
internal IntPtr mouseButton;
internal IntPtr pos;
internal IntPtr refresh;
internal IntPtr scale;
internal IntPtr scroll;
internal IntPtr size;
}
// GLFW_PLATFORM_WINDOW_STATE platformWindowState;
}
[StructLayout( LayoutKind.Sequential )]
public struct GLFWwindowCallback { }
[StructLayout( LayoutKind.Sequential )]
public struct GLFWcursor
{
//GLFWcursor* next;
private IntPtr next;
// This is defined in platform.h
// not completed in tranformation
// GLFW_PLATFORM_CURSOR_STATE;
}
/*
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWerror
{
//GLFWerror* next;
IntPtr next;
int code;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)GLconst.GLFW_MESSAGE_SIZE)]
byte[] description = new byte[GLconst.GLFW_MESSAGE_SIZE];
public GLFWerror()
{
}
}
*/
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWinitconfig
{
private GLFWbool hatButtons;
private int angleType;
private int platformID;
//PFN_vkGetInstanceProcAddr vulkanLoader;
private IntPtr vulkanLoader;
}
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWwndconfig
{
private byte* title;
private GLFWbool autoIconify;
private GLFWbool centerCursor;
private GLFWbool decorated;
private GLFWbool floating;
private GLFWbool focused;
private GLFWbool focusOnShow;
private GLFWbool maximized;
private GLFWbool mousePassthrough;
private GLFWbool resizable;
private GLFWbool scaleToMonitor;
private GLFWbool visible;
private int height;
private int width;
private int xpos;
private int ypos;
internal Ns ns = new Ns();
internal Win32 win32 = new Win32();
internal Wl wl = new Wl();
internal X11 x11 = new X11();
public GLFWwndconfig() { }
internal struct Ns
{
private GLFWbool retina = false;
public fixed byte frameName[ 256 ];
public Ns() { }
}
internal struct X11
{
public fixed byte className[ 256 ];
public fixed byte instanceName[ 256 ];
public X11() { }
}
internal struct Win32
{
private GLFWbool keymenu;
}
internal struct Wl
{
public fixed byte appId[ 256 ];
public Wl() { }
}
}
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWctxconfig
{
private GLFWbool debug;
private GLFWbool forward;
private GLFWbool noerror;
private int client;
private int major;
private int minor;
private int profile;
private int release;
private int robustness;
private int source;
//glfwWindow* share;
private IntPtr share;
internal Nsgl nsgl = new Nsgl();
public GLFWctxconfig() { }
internal struct Nsgl
{
private GLFWbool offline;
}
}
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWfbconfig
{
private GLFWbool doublebuffer;
private GLFWbool sRGB;
private GLFWbool stereo;
private GLFWbool transparent;
private int accumAlphaBits;
private int accumBlueBits;
private int accumGreenBits;
private int accumRedBits;
private int alphaBits;
private int auxBuffers;
private int blueBits;
private int depthBits;
private int greenBits;
private int redBits;
private int samples;
private int stencilBits;
private uintptr_t handle;
}
[StructLayout( LayoutKind.Sequential )]
internal unsafe struct GLFWlibrary
{
[MarshalAs(
UnmanagedType.ByValArray,
SizeConst = GLconst.GLFW_JOYSTICK_LAST + 1 )]
private GLFWjoystick[] joysticks = new GLFWjoystick[GLconst.GLFW_JOYSTICK_LAST + 1];
private GLFWallocator allocator;
private GLFWbool initialized;
private GLFWbool joysticksInitialized;
private GLFWls contextSlot;
private GLFWls errorSlot;
private GLFWmutex errorLock;
private GLFWplatform platform;
private int mappingCount;
private int monitorCount;
//GLFWcursor* cursorListHead;
private IntPtr cursorListHead;
//GLFWerror* errorListHead;
private IntPtr errorListHead;
//GLFWmapping* mappings;
private IntPtr mappings;
//GLFWmonitor** monitors;
private IntPtr monitors;
//glfwWindow* windowListHead;
private IntPtr windowListHead;
internal Callbacks callbacks = new Callbacks();
internal Egl egl = new Egl();
internal Hints hints = new Hints();
internal Osmesa osmesa = new Osmesa();
public GLFWlibrary() { }
internal unsafe struct Hints
{
private GLFWctxconfig context;
private GLFWfbconfig framebuffer;
private GLFWinitconfig init;
private GLFWwndconfig window;
private int refreshRate;
}
internal unsafe struct timer
{
private ulong offset;
// This is defined in platform.h
//not transformed function defination
//GLFW_PLATFORM_LIBRARY_TIMER_STATE
}
internal unsafe struct Egl
{
internal void* display;
internal void* handle;
internal bool ANGLE_platform_angle;
internal bool ANGLE_platform_angle_d3d;
internal bool ANGLE_platform_angle_metal;
internal bool ANGLE_platform_angle_opengl;
internal bool ANGLE_platform_angle_vulkan;
internal bool EXT_client_extensions;
internal bool EXT_platform_base;
internal bool EXT_platform_wayland;
internal bool EXT_platform_x11;
internal bool EXT_present_opaque;
internal bool KHR_colorSpace;
internal bool KHR_context_flush_control;
internal bool KHR_create_context;
internal bool KHR_create_context_no_error;
internal bool KHR_get_all_proc_addresses;
internal bool prefix;
internal int major, minor;
internal int platform;
internal IntPtr BindAPI;
internal IntPtr CreateContext;
internal IntPtr CreatePlatformWindowSurfaceEXT;
internal IntPtr CreateWindowSurface;
internal IntPtr DestroyContext;
internal IntPtr DestroySurface;
internal IntPtr GetConfigAttrib;
internal IntPtr GetConfigs;
internal IntPtr GetDisplay;
internal IntPtr GetError;
internal IntPtr GetPlatformDisplayEXT;
internal IntPtr GetProcAddress;
internal IntPtr Initialize;
internal IntPtr MakeCurrent;
internal IntPtr QueryString;
internal IntPtr SwapBuffers;
internal IntPtr SwapInterval;
internal IntPtr Terminate;
}
internal unsafe struct Osmesa
{
private void* handle;
private IntPtr CreateContextAttribs;
private IntPtr CreateContextExt;
private IntPtr DestroyContext;
private IntPtr GetColorBuffer;
private IntPtr GetDepthBuffer;
private IntPtr GetProcAddress;
private IntPtr MakeCurrent;
}
internal unsafe struct vk
{
private void* handle;
private GLFWbool available;
private GLFWbool EXT_metal_surface;
private GLFWbool KHR_surface;
private GLFWbool KHR_wayland_surface;
private GLFWbool KHR_win32_surface;
private GLFWbool KHR_xcb_surface;
private GLFWbool KHR_xlib_surface;
private GLFWbool MVK_macos_surface;
private IntPtr GetInstanceProcAddr;
private fixed ulong extensions[ 2 ];
public vk() { }
}
internal unsafe struct Callbacks
{
private IntPtr joystick;
private IntPtr monitor;
}
}
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWmapelement
{
private byte index;
private byte type;
private sbyte axisOffset;
private sbyte axisScale;
}
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWmapping
{
[MarshalAs( UnmanagedType.ByValArray, SizeConst = 6 )]
private GLFWmapelement[] axes = new GLFWmapelement[6];
[MarshalAs( UnmanagedType.ByValArray, SizeConst = 15 )]
private GLFWmapelement[] buttons = new GLFWmapelement[15];
private fixed byte guid[ 33 ];
private fixed byte name[ 128 ];
public GLFWmapping() { }
}
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWjoystick
{
private float* axes;
private byte* buttons;
private byte* hats;
private void* userPointer;
private fixed byte guid[ 33 ];
private fixed byte name[ 128 ];
private GLFWbool allocated;
private GLFWbool connected;
private int axisCount;
private int buttonCount;
private int hatCount;
//GLFWmapping* mapping;
private IntPtr mapping;
// This is defined in platform.h
// not completed in transforming
// GLFW_PLATFORM_JOYSTICK_STATE;
public GLFWjoystick() { }
}
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWls
{
// This is defined in platform.h
//GLFW_PLATFORM_TLS_STATE
}
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWplatform
{
private int platformID;
// init
//GLFWbool(*init)(void);
private IntPtr init;
//void (* terminate) (void);
private IntPtr terminate;
internal IntPtr createCursor;
internal IntPtr createStandardCursor;
// window
internal IntPtr createWindow;
internal IntPtr destroyCursor;
internal IntPtr destroyWindow;
internal IntPtr focusWindow;
internal IntPtr framebufferTransparent;
// monitor
internal IntPtr freeMonitor;
internal IntPtr getClipboardString;
internal IntPtr getEGLNativeDisplay;
internal IntPtr getEGLNativeWindow;
// EGL
//EGLenum(*getEGLPlatform)(EGLint**);
//EGLNativeDisplayType(*getEGLNativeDisplay)(void);
//EGLNativeWindowType(*getEGLNativeWindow)(glfwWindow*);
internal IntPtr getEGLPlatform;
internal IntPtr getFramebufferSize;
internal IntPtr getGammaRamp;
internal IntPtr getKeyScancode;
internal IntPtr getMappingName;
internal IntPtr getMonitorContentScale;
internal IntPtr getMonitorPos;
internal IntPtr getMonitorWorkarea;
// vulkan
//void (* getRequiredInstanceExtensions) (byte**);
//GLFWbool(*getPhysicalDevicePresentationSupport)(VkInstance, VkPhysicalDevice, uint32_t);
//VkResult(*createWindowSurface)(VkInstance, glfwWindow*,const VkAllocationCallbacks*, VkSurfaceKHR*);
internal IntPtr getRequiredInstanceExtensions;
internal IntPtr getScancodeName;
internal IntPtr getVideoMode;
internal IntPtr getVideoModes;
internal IntPtr getWindowContentScale;
internal IntPtr getWindowFrameSize;
internal IntPtr getWindowOpacity;
internal IntPtr getWindowPos;
internal IntPtr getWindowSize;
internal IntPtr GLFWwindow;
internal IntPtr hideWindow;
internal IntPtr iconifyWindow;
internal IntPtr initJoysticks;
internal IntPtr maximizeWindow;
internal IntPtr pollEvents;
internal IntPtr pollJoystick;
internal IntPtr postEmptyEvent;
internal IntPtr rawMouseMotionSupported;
internal IntPtr requestWindowAttention;
internal IntPtr restoreWindow;
internal IntPtr setClipboardString;
internal IntPtr setCursor;
internal IntPtr setCursorMode;
#region input
/* void (* getCursorPos) (glfwWindow*, double*, double*);
void (* setCursorPos) (glfwWindow*, double, double);
void (* setCursorMode) (glfwWindow*, int);
void (* setRawMouseMotion) (glfwWindow*, GLFWbool);
GLFWbool(*rawMouseMotionSupported)(void);
GLFWbool(*createCursor)(GLFWcursor*,const GLFWimage*,int,int);
GLFWbool(*createStandardCursor)(GLFWcursor*, int);
void (* destroyCursor) (GLFWcursor*);
void (* setCursor) (glfwWindow*, GLFWcursor*);
const byte* (*getScancodeName)(int);
int (* getKeyScancode) (int);
void (* setClipboardString) (const byte*);
const byte* (*getClipboardString)(void);
GLFWbool(*initJoysticks)(void);
void (* terminateJoysticks) (void);
GLFWbool(*pollJoystick)(GLFWjoystick*, int);
const byte* (*getMappingName)(void);
void (* updateGamepadGUID) (byte*);
// monitor
void (* freeMonitor) (GLFWmonitor*);
void (* getMonitorPos) (GLFWmonitor*, int*, int*);
void (* getMonitorContentScale) (GLFWmonitor*, float*, float*);
void (* getMonitorWorkarea) (GLFWmonitor*, int*, int*, int*, int*);
glfwVideomode* (* getVideoModes) (GLFWmonitor*, int*);
void (* getVideoMode) (GLFWmonitor*, glfwVideomode*);
GLFWbool(*getGammaRamp)(GLFWmonitor*, glfwGammaramp*);
void (* setGammaRamp) (GLFWmonitor*,const glfwGammaramp*);
// window
GLFWbool(*createWindow)(glfwWindow*,const GLFWwndconfig*,const GLFWctxconfig*,const GLFWfbconfig*);
void (* destroyWindow) (glfwWindow*);
void (* setWindowTitle) (glfwWindow*,const byte*);
void (* setWindowIcon) (glfwWindow*, int,const GLFWimage*);
void (* getWindowPos) (glfwWindow*, int*, int*);
void (* setWindowPos) (glfwWindow*, int, int);
void (* getWindowSize) (glfwWindow*, int*, int*);
void (* setWindowSize) (glfwWindow*, int, int);
void (* setWindowSizeLimits) (glfwWindow*, int, int, int, int);
void (* setWindowAspectRatio) (glfwWindow*, int, int);
void (* getFramebufferSize) (glfwWindow*, int*, int*);
void (* getWindowFrameSize) (glfwWindow*, int*, int*, int*, int*);
void (* getWindowContentScale) (glfwWindow*, float*, float*);
void (* iconifyWindow) (glfwWindow*);
void (* restoreWindow) (glfwWindow*);
void (* maximizeWindow) (glfwWindow*);
void (* showWindow) (glfwWindow*);
void (* hideWindow) (glfwWindow*);
void (* requestWindowAttention) (glfwWindow*);
void (* focusWindow) (glfwWindow*);
void (* setWindowMonitor) (glfwWindow*, GLFWmonitor*, int, int, int, int, int);
GLFWbool(*windowFocused)(glfwWindow*);
GLFWbool(*windowIconified)(glfwWindow*);
GLFWbool(*windowVisible)(glfwWindow*);
GLFWbool(*windowMaximized)(glfwWindow*);
GLFWbool(*windowHovered)(glfwWindow*);
GLFWbool(*framebufferTransparent)(glfwWindow*);
float (* getWindowOpacity) (glfwWindow*);
void (* setWindowResizable) (glfwWindow*, GLFWbool);
void (* setWindowDecorated) (glfwWindow*, GLFWbool);
void (* setWindowFloating) (glfwWindow*, GLFWbool);
void (* setWindowOpacity) (glfwWindow*, float);
void (* setWindowMousePassthrough) (glfwWindow*, GLFWbool);
void (* pollEvents) (void);
void (* waitEvents) (void);
void (* waitEventsTimeout) (double);
void (* postEmptyEvent) (void);
*/
#endregion
internal IntPtr setCursorPos;
internal IntPtr setGammaRamp;
internal IntPtr setRawMouseMotion;
internal IntPtr setWindowAspectRatio;
internal IntPtr setWindowDecorated;
internal IntPtr setWindowFloating;
internal IntPtr setWindowIcon;
internal IntPtr setWindowMonitor;
internal IntPtr setWindowMousePassthrough;
internal IntPtr setWindowOpacity;
internal IntPtr setWindowPos;
internal IntPtr setWindowResizable;
internal IntPtr setWindowSize;
internal IntPtr setWindowSizeLimits;
internal IntPtr setWindowTitle;
internal IntPtr showWindow;
internal IntPtr terminateJoysticks;
internal IntPtr updateGamepadGUID;
internal IntPtr VkPhysicalDevice;
internal IntPtr waitEvents;
internal IntPtr waitEventsTimeout;
internal IntPtr windowFocused;
internal IntPtr windowHovered;
internal IntPtr windowIconified;
internal IntPtr windowMaximized;
internal IntPtr windowVisible;
}
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWmutex
{
// This is defined in platform.h
//GLFW_PLATFORM_MUTEX_STATE
}
//public unsafe struct VkAllocationCallbacks { }
[StructLayout( LayoutKind.Sequential )]
internal unsafe struct VkExtensionProperties
{
private fixed byte extensionName[ 256 ];
private uint specVersion;
public VkExtensionProperties() { }
}
/*
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct GLFWerror
{
IntPtr next;
int code;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]
byte[] description = new byte[1024];
public GLFWerror()
{
}
}
*/
[StructLayout( LayoutKind.Explicit, Size = 16 )]
public struct uintptr_t
{
[FieldOffset( 0 )]
private long part1;
[FieldOffset( 8 )]
private long part2;
}
#endregion GLFW3 struct
#region glad struct
[StructLayout( LayoutKind.Sequential )]
internal struct GLsync
{
public IntPtr Handle;
}
#endregion glad struct
}
/**/
@@ -0,0 +1,97 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glApiDefine.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.Numerics;
using System.Runtime.InteropServices;
namespace StgSharp.Graphics
{
/// <summary>
/// Function handler to load an opengl function by searching its name.
/// </summary>
/// <param name="name"> the name of the Opengl function </param>
/// <returns> An Intptr value representing the pointer to the function </returns>
public delegate IntPtr glLoader( string name );
#region StgSharpDele
public unsafe delegate void FrameBufferSizeHandler(
IntPtr window,
int width,
int height );
public unsafe delegate void FramePositionHandler(
IntPtr window,
float width,
float height );
#endregion
#region glDEBUG
internal unsafe delegate void GLDEBUGPROC(
int source,
int type,
uint id,
int severity,
int length,
sbyte* message,
void* userParam );
internal unsafe delegate void GLDEBUGPROCARB(
int source,
int type,
uint id,
int severity,
int length,
sbyte* message,
void* userParam );
internal unsafe delegate void GLDEBUGPROCKHR(
int source,
int type,
uint id,
int severity,
int length,
sbyte* message,
void* userParam );
internal unsafe delegate void GLDEBUGPROCAMD(
uint id,
int category,
int severity,
int length,
sbyte* message,
void* userParam );
#endregion
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,258 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glEnum.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.Runtime.CompilerServices;
namespace StgSharp.Graphics.OpenGL
{
public enum PixelChannelLayout
{
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 = GLconst.UNSIGNED_BYTE_3_3_2,
UByte233Rev = GLconst.UNSIGNED_BYTE_2_3_3_REV,
UShort565 = GLconst.UNSIGNED_SHORT_5_6_5,
UShort565Rev = GLconst.UNSIGNED_SHORT_5_6_5_REV,
UShort4444 = GLconst.UNSIGNED_SHORT_4_4_4_4,
UShort4444Rev = GLconst.UNSIGNED_SHORT_4_4_4_4_REV,
UShort5551 = GLconst.UNSIGNED_SHORT_5_5_5_1,
UShort1555Rev = GLconst.UNSIGNED_SHORT_1_5_5_5_REV,
UInt8888 = GLconst.UNSIGNED_INT_8_8_8_8,
UInt8888Rev = GLconst.UNSIGNED_INT_8_8_8_8_REV,
UInt1010102 = GLconst.UNSIGNED_INT_10_10_10_2,
UInt2101010Rev = GLconst.UNSIGNED_INT_2_10_10_10_REV
}
public enum FrameBufferStatus
{
Complete = GLconst.FRAMEBUFFER_COMPLETE, // GL_FRAMEBUFFER_COMPLETE
IncompleteAttachment = GLconst.FRAMEBUFFER_INCOMPLETE_ATTACHMENT, // GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
IncompleteMissingAttachment = GLconst.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, // GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
IncompleteDrawBuffer = GLconst.FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER, // GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
IncompleteReadBuffer = GLconst.FRAMEBUFFER_INCOMPLETE_READ_BUFFER, // GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
Unsupported = GLconst.FRAMEBUFFER_UNSUPPORTED, // GL_FRAMEBUFFER_UNSUPPORTED
IncompleteMultisample = GLconst.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, // GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
IncompleteLayerTargets = GLconst.FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS // GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
}
internal enum VkStructureType : uint
{
VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR = 1000004000,
VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR = 1000005000,
VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR = 1000006000,
VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR = 1000009000,
VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK = 1000123000,
VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT = 1000217000,
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 FrameBufferAttachment
{
Color = GLconst.COLOR_ATTACHMENT0,
Depth = GLconst.DEPTH_ATTACHMENT,
Stencil = GLconst.STENCIL_ATTACHMENT,
DepthAndStencil = GLconst.DEPTH_STENCIL_ATTACHMENT,
}
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,
}
internal enum VkResult
{
VK_SUCCESS = 0,
VK_NOT_READY = 1,
VK_TIMEOUT = 2,
VK_EVENT_SET = 3,
VK_EVENT_RESET = 4,
VK_INCOMPLETE = 5,
VK_ERROR_OUT_OF_HOST_MEMORY = -1,
VK_ERROR_OUT_OF_DEVICE_MEMORY = -2,
VK_ERROR_INITIALIZATION_FAILED = -3,
VK_ERROR_DEVICE_LOST = -4,
VK_ERROR_MEMORY_MAP_FAILED = -5,
VK_ERROR_LAYER_NOT_PRESENT = -6,
VK_ERROR_EXTENSION_NOT_PRESENT = -7,
VK_ERROR_FEATURE_NOT_PRESENT = -8,
VK_ERROR_INCOMPATIBLE_DRIVER = -9,
VK_ERROR_TOO_MANY_OBJECTS = -10,
VK_ERROR_FORMAT_NOT_SUPPORTED = -11,
VK_ERROR_SURFACE_LOST_KHR = -1000000000,
VK_SUBOPTIMAL_KHR = 1000001003,
VK_ERROR_OUT_OF_DATE_KHR = -1000001004,
VK_ERROR_INCOMPATIBLE_DISPLAY_KHR = -1000003001,
VK_ERROR_NATIVE_WINDOW_IN_USE_KHR = -1000000001,
VK_ERROR_VALIDATION_FAILED_EXT = -1000011001,
VK_RESULT_MAX_ENUM = 0x7FFFFFFF
}
#pragma warning disable CA1008
public enum ShaderType : int
#pragma warning restore CA1008
{
Fragment = GLconst.FRAGMENT_SHADER,
Vertex = GLconst.VERTEX_SHADER,
Compute = GLconst.COMPUTE_SHADER,
Geometry = GLconst.GEOMETRY_SHADER,
}
#pragma warning disable CA1008 // 枚举应具有零值
public enum BufferType : int
#pragma warning restore CA1008 // 枚举应具有零值
{
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,
DRAW_INDIRECT_BUFFER = GLconst.DRAW_INDIRECT_BUFFER,
PIXEL_PACK_BUFFER = GLconst.PIXEL_PACK_BUFFER,
PIXEL_UNPACK_BUFFER = GLconst.PIXEL_UNPACK_BUFFER,
QUERY_BUFFER = GLconst.QUERY_BUFFER,
SHADER_STORAGE_BUFFER = GLconst.SHADER_STORAGE_BUFFER,
TEXTURE_BUFFER = GLconst.TEXTURE_BUFFER,
TRANSFORM_FEEDBACK_BUFFER = GLconst.TRANSFORM_FEEDBACK_BUFFER,
UNIFORM_BUFFER = GLconst.UNIFORM_BUFFER,
}
#pragma warning disable CA1008 // 枚举应具有零值
public enum BufferUsage : int
#pragma warning restore CA1008 // 枚举应具有零值
{
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,
DEPTH = GLconst.DEPTH_BUFFER_BIT,
STENCIL = GLconst.STENCIL_BUFFER_BIT,
}
public enum GeometryType : uint
{
POINTS = 0x0000,
LINES = 0x0001,
LINE_LOOP = 0x0002,
LINE_STRIP = 0x0003,
TRIANGLES = 0x0004,
TRIANGLE_STRIP = 0x0005,
TRIANGLE_FAN = 0x0006
}
public enum TextureFiltering
{
Nearest = 0x2600,
Linear = 0x2601
}
}
@@ -0,0 +1,149 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glType.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 System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics
{
public delegate IntPtr GLfuncLoader( string name );
internal delegate void GLVULKANPROCNV();
public unsafe struct GLhandleARB
{
private dynamic value;
public unsafe GLhandleARB( dynamic value )
{
if( !RuntimeInformation.IsOSPlatform( OSPlatform.OSX ) ) {
if( value.GetType().Name != "Uint32" ) {
goto errorlog;
}
this.value = value;
} else {
if( value.GetType().Name != "IntPtr" ) {
goto errorlog;
}
this.value = value;
}
errorlog:
{
InternalIO.InternalWriteLog(
$"{value.GetType().Name} does not match definination of GLhandlARB on OS {Environment.OSVersion.Platform} ",
LogType.Error );
}
}
public static implicit operator uint( GLhandleARB value )
{
return ( uint )value;
}
}
#region GLFW_dele
internal unsafe delegate void GLFWwindowsizefun(
glfwWindow* window,
int width,
int height );
internal unsafe delegate void GLFWwindowrefreshfun( glfwWindow* window );
internal unsafe delegate void GLFWwindowposfun(
glfwWindow* window,
int xpos,
int ypos );
internal unsafe delegate void GLFWwindowmaximizefun(
glfwWindow* window,
int maximized );
internal unsafe delegate void GLFWwindowiconifyfun(
glfwWindow* window,
int iconified );
internal unsafe delegate void GLFWwindowfocusfun(
glfwWindow* window,
int focused );
internal unsafe delegate void GLFWwindowcontentscalefun(
glfwWindow* window,
float xscale,
float yscale );
internal unsafe delegate void GLFWwindowclosefun( glfwWindow* window );
internal unsafe delegate void GLFWvkproc();
internal unsafe delegate void GLFWscrollfun(
glfwWindow* window,
double xoffset,
double yoffset );
internal unsafe delegate void GLFWmousebuttonfun(
glfwWindow* window,
int button,
int action,
int mods );
internal unsafe delegate void GLFWmonitorfun(
glfwMonitor* monitor,
int monitorevent );
internal unsafe delegate void GLFWkeyfun(
glfwWindow* window,
int key,
int scancode,
int action,
int mods );
internal unsafe delegate void GLFWjoystickfun( int jid, int keyevent );
public unsafe delegate void GLFWglproc();
internal unsafe delegate void GLFWerrorfun(
int error_code,
sbyte* description );
internal unsafe delegate void GLFWdropfun(
glfwWindow* window,
int path_count,
sbyte*[] paths );
internal unsafe delegate void GLFWcursorposfun(
glfwWindow* window,
double xpos,
double ypos );
internal unsafe delegate void GLFWcursorenterfun(
glfwWindow* window,
int entered );
internal unsafe delegate void GLFWcharmodsfun(
glfwWindow* window,
uint codepoint,
int mods );
internal unsafe delegate void GLFWcharfun(
glfwWindow* window,
uint codepoint );
#endregion
}
@@ -0,0 +1,46 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IGraphicAPIs.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.Graphics
{
public interface IGraphicAPIs
{
public IntPtr GraphicApiPackageHandle
{
get;
}
}
}
+337
View File
@@ -0,0 +1,337 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Image.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.Graphics.OpenGL;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public class Image : ISSDSerializable, IImageProvider
{
private byte[] _data;
private ImageInfo _rawInfo;
private int _pixelUpdateCount = 0;
internal unsafe Image()
{
_rawInfo = new ImageInfo();
}
internal Image( ImageInfo information )
{
_rawInfo = information;
_data = Array.Empty<byte>();
//int length = _rawInfo.width * _rawInfo.height * _rawInfo.channel;
}
public (int width, int height) Size
{
get => (_rawInfo.Width, _rawInfo.Height);
}
public byte[] PixelBuffer
{
get
{
if( ( _data.Length == 0 ) || ( _data == null ) ) {
GetBytes();
return _data!;
}
return _data;
}
}
public ImageChannel Channel => _rawInfo.Channel;
/// <summary>
/// Hash code of time pixels updated last time.
/// </summary>
public int PixelUpdateCount
{
get => _pixelUpdateCount;
internal set => _pixelUpdateCount = value;
}
public int ChannelCount => _rawInfo.ChannelCount;
public int Height
{
get => _rawInfo.Height;
internal set => _rawInfo.Height = value;
}
public int Width
{
get => _rawInfo.Width;
internal set => _rawInfo.Width = value;
}
public int PixelSize => GlHelper.GetPixelSize(
_rawInfo.pixelLayout, _rawInfo.Channel );
public PixelChannelLayout PixelLayout
{
get => _rawInfo.pixelLayout;
private set => _rawInfo.pixelLayout = value;
}
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
internal ref byte[] Data
{
get => ref _data;
}
public void FromBytes( byte[] stream ) { }
public static unsafe Image FromFile( string route, ImageLoader loader )
{
Image ret = new Image();
fixed( ImageInfo* iptr = &ret._rawInfo ) {
InternalIO.InternalLoadImage( route, iptr, loader );
}
return ret;
}
public static Image FromMemory(
(int width, int height) size,
ImageChannel channel,
byte[] stream )
{
ImageInfo _info = new ImageInfo
{
Height = size.height,
Width = size.width,
Channel = channel,
StreamPtr = IntPtr.Zero
};
Image ret = new Image( _info );
ret.PixelLayout = PixelChannelLayout.Byte;
ret._data = stream;
return ret;
}
public static Image FromMemory(
(int width, int height) size,
ImageChannel channel,
PixelChannelLayout layout,
byte[] stream )
{
ImageInfo _info = new ImageInfo
{
Height = size.height,
Width = size.width,
Channel = channel,
StreamPtr = IntPtr.Zero
};
Image ret = new Image( _info );
ret.PixelLayout = layout;
ret._data = stream;
return ret;
}
public unsafe byte[] GetBytes()
{
if( _data.Length == 0 ) {
int size = Width * Height * GlHelper.GetPixelSize(
PixelLayout, Channel );
_data = new Span<byte>( ( byte* )_rawInfo.StreamPtr,
size ).ToArray();
fixed( ImageInfo* pptr = &_rawInfo ) {
InternalIO.InternalUnloadImage( pptr );
}
_rawInfo.StreamPtr = IntPtr.Zero;
}
return _data;
}
public Image ProvideImage() => this;
internal static Image FromMemory(
ImageInfo info,
byte[] data,
int operationCount )
{
return new Image
{
_rawInfo = info,
_data = data,
_pixelUpdateCount = operationCount
};
}
byte[] ISSDSerializable.GetBytes()
{
throw new NotImplementedException();
}
}
[StructLayout( LayoutKind.Sequential )]
internal struct ImageInfo
{
private ImageChannel channel;
private int height;
private int width;
private IntPtr pixelPtr;
internal PixelChannelLayout pixelLayout;
public ImageChannel Channel
{
get => channel;
set { channel = value; }
}
public int ChannelCount
{
get => GlHelper.GetChannelCount( channel );
}
public int Height
{
get => height;
set => height = value;
}
public int StreamSize
{
get => width * height * GlHelper.GetPixelSize(
pixelLayout, channel );
}
public int Width
{
get => width;
set => width = value;
}
public IntPtr StreamPtr
{
get => pixelPtr;
internal set => pixelPtr = value;
}
public override int GetHashCode()
{
int hash = 17;
hash = hash * 17 + width;
hash = hash * 17 + height;
hash = hash * 17 + ( int )channel;
return hash;
}
public override string ToString()
{
return $"{channel}\t{width}\t{height}\t{(ulong)StreamPtr}";
}
}
public enum ImageChannel : uint
{
SingleColor = GLconst.RED,
DoubleColor = GLconst.RG,
TripleColor = GLconst.RGB,
WithAlphaChannel = GLconst.RGBA,
}
}
namespace StgSharp.Graphics.OpenGL
{
public static partial class GlHelper
{
internal static int GetChannelCount( ImageChannel channel )
{
return channel switch
{
ImageChannel.SingleColor => 1,
ImageChannel.DoubleColor => 2,
ImageChannel.TripleColor => 3,
ImageChannel.WithAlphaChannel => 4,
_ => throw new InvalidCastException(
"Unknown color channel decoding setting." )
};
}
internal static int GetPixelSize(
PixelChannelLayout layout,
ImageChannel cahnnel )
{
return layout switch
{
PixelChannelLayout.UByte => sizeof( byte ) * GetChannelCount(
cahnnel ),
PixelChannelLayout.Byte => sizeof( byte ) * GetChannelCount(
cahnnel ),
PixelChannelLayout.UShort => sizeof( short ) * GetChannelCount(
cahnnel ),
PixelChannelLayout.Short => sizeof( short ) * GetChannelCount(
cahnnel ),
PixelChannelLayout.UInt => sizeof( int ) * GetChannelCount(
cahnnel ),
PixelChannelLayout.Int => sizeof( int ) * GetChannelCount(
cahnnel ),
PixelChannelLayout.Float => sizeof( float ) * GetChannelCount(
cahnnel ),
PixelChannelLayout.UByte332 => sizeof( byte ),
PixelChannelLayout.UByte233Rev => sizeof( byte ),
PixelChannelLayout.UShort565 => sizeof( short ),
PixelChannelLayout.UShort565Rev => sizeof( short ),
PixelChannelLayout.UShort4444 => sizeof( short ),
PixelChannelLayout.UShort4444Rev => sizeof( short ),
PixelChannelLayout.UShort5551 => sizeof( short ),
PixelChannelLayout.UShort1555Rev => sizeof( short ),
PixelChannelLayout.UInt8888 => sizeof( int ),
PixelChannelLayout.UInt8888Rev => sizeof( int ),
PixelChannelLayout.UInt1010102 => sizeof( int ),
PixelChannelLayout.UInt2101010Rev => sizeof( int ),
_ => throw new ArgumentException( "Unknown layout type" ),
};
}
}
}
@@ -0,0 +1,162 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="AutoTexture.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.Collections;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.OpenGL
{
/// <summary>
/// A collection of a sets of OpenGL textures. The collection can automatically select one of
/// the texture with minimum costs to upgrade pixels to buffer. Usually <see
/// cref="AutoTextureGL" /> is used for <see cref="IImageProvider" /> loading, but not for
/// target of <see cref="OpenGLFunction.FrameBufferTexture2d(FrameBufferTarget, uint,
/// Texture2DTarget, GlHandle, int)" />.
/// </summary>
public sealed class AutoTextureGL
{
private TextureProperty[] propertyCache;
private BidirectionalDictionary<Image, int> imageIndexMap = new BidirectionalDictionary<Image, int>(
);
private Dictionary<Image, int> imageUpdateIndex = new Dictionary<Image, int>(
);
private int _size, _currentIndex;
private LinkedList<int> usedTextureIndex;
private Queue<int> unusedTextureUnitIndex;
private TextureGL texturePackage;
private TextureProperty _textureProperty;
private AutoTextureGL( TextureGL texture )
{
texturePackage = texture;
_size = texture.Count;
imageIndexMap = new BidirectionalDictionary<Image, int>();
unusedTextureUnitIndex = new Queue<int>(
Enumerable.Range( 0, _size ) );
usedTextureIndex = new LinkedList<int>();
propertyCache = new TextureProperty[_size];
}
public AutoTextureGL( int textureObjectSize, [NotNull]glRender binding )
{
this._size = textureObjectSize;
imageIndexMap = new BidirectionalDictionary<Image, int>();
texturePackage = new TextureGL( textureObjectSize, binding );
unusedTextureUnitIndex = new Queue<int>(
Enumerable.Range( 0, _size ) );
usedTextureIndex = new LinkedList<int>();
propertyCache = new TextureProperty[_size];
}
public TextureProperty DefaultTextureProperty
{
get => _textureProperty;
set => _textureProperty = value;
}
private OpenGLFunction GL
{
get => texturePackage.GL;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SelectTextureAndBind( Image i )
{
TextureProperty property = _textureProperty;
SelectTextureAndBind( i, property );
}
public void SelectTextureAndBind(
[NotNull]Image i,
TextureProperty property )
{
//usable texture with image match
if( imageIndexMap.TryGetValue( i, out int index ) ) {
//prop setting match
if( propertyCache[ index ] == property ) {
_currentIndex = index; //GL.Assert(true);
texturePackage.Bind2D( index ); //GL.Assert(true);
if( i.PixelUpdateCount != imageUpdateIndex[ i ] ) {
texturePackage.LoadTexture( index, i ); //GL.Assert(true);
}
} else {
_currentIndex = index; //GL.Assert(true);
texturePackage.Bind2D( index ); //GL.Assert(true);
texturePackage.Set2dProperty( index, property ); //GL.Assert(true);
if( i.PixelUpdateCount != imageUpdateIndex[ i ] ) {
texturePackage.LoadTexture( index, i ); //GL.Assert(true);
}
}
} else {
if( unusedTextureUnitIndex.TryDequeue( out int newIndex ) ) {
//has extra unused texture object
imageIndexMap.Add( i, index );
texturePackage.Bind2D( index );
texturePackage.Set2dProperty( index, property );
texturePackage.LoadTexture( index, i );
usedTextureIndex.AddLast( newIndex );
propertyCache[ newIndex ] = property;
imageUpdateIndex[ i ] = i.PixelUpdateCount;
} else {
//recycle from current
int reusedIndex = usedTextureIndex.First!.Value;
usedTextureIndex.RemoveFirst();
usedTextureIndex.AddLast( reusedIndex );
imageIndexMap[ i ] = reusedIndex;
propertyCache[ newIndex ] = property;
imageUpdateIndex[ i ] = i.PixelUpdateCount;
}
}
}
public static AutoTextureGL ToAuto( [NotNull]TextureGL texture )
{
if( texture.IndexOfCurrentTexture != -1 ) {
throw new InvalidOperationException(
"Texture to be converted has been editted." );
}
return new AutoTextureGL( texture );
}
}
}
@@ -0,0 +1,92 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="EBO.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.Graphics.OpenGL;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics.OpenGL
{
/// <summary>
/// A collection of handle to Element Buffer Object in OpenglFunc. Each <see langword="uint" />
/// value indexed from instance of this class this is the only handle to one Element Buffer
/// Object.
/// </summary>
public sealed unsafe class ElementBuffer : GlBufferObjectBase
{
internal ElementBuffer( int n, glRender binding )
: base( binding )
{
_bufferHandle = GL.GenBuffers( n );
}
public override sealed void Bind( int index )
{
GL.BindBuffer(
BufferType.ElementArrayBuffer, _bufferHandle[ index ] );
}
public void SetValue<T>( int index, T[] bufferArray, BufferUsage usage )
where T: struct, IConvertible
{
GL.BindBuffer(
BufferType.ElementArrayBuffer, _bufferHandle[ index ] );
GL.SetBufferData(
BufferType.ElementArrayBuffer, bufferArray, usage );
}
public void SetValue<T>(
int index,
ReadOnlySpan<T> bufferSpan,
BufferUsage usage )
where T: struct, IConvertible
{
GL.BindBuffer(
BufferType.ElementArrayBuffer, _bufferHandle[ index ] );
GL.SetBufferData( BufferType.ElementArrayBuffer, bufferSpan,
usage );
}
protected override sealed void Dispose( bool disposing )
{
if( disposing ) {
GL.DeleteBuffers( _bufferHandle );
}
}
}
}
@@ -0,0 +1,101 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="FBO.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.OpenGL;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.OpenGL
{
#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,
Draw = GLconst.DRAW_FRAMEBUFFER,
}
public sealed class FrameBuffer : GlBufferObjectBase
{
internal unsafe FrameBuffer( int count, glRender binding )
: base( binding )
{
_bufferHandle = GL.GenFrameBuffers( count );
}
/// <summary>
/// Bind the frame buffer object with name frame buffer to the frame buffer target specified
/// by target. <see langword="FrameBufferTarget.All" /> will be set as default target.
/// </summary>
/// <param name="index"> Index of object to be binded in handle set </param>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public override unsafe void Bind( int index )
{
GL.BindFrameBuffer( FrameBufferTarget.All, _bufferHandle[ index ] );
}
/// <summary>
/// Bind the frame buffer object with name frame buffer to the frame buffer target specified
/// by target. Target of this frame buffer should be set manually.
/// </summary>
/// <param name="target"> The frame buffer target of the binding operation. </param>
/// <param name="index"> Index of object to be binded in handle set </param>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void Bind( FrameBufferTarget target, int index )
{
GL.BindFrameBuffer( target, _bufferHandle[ index ] );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static void BindNull()
{
OpenGLFunction.CurrentGL
.BindFrameBuffer( FrameBufferTarget.All, GlHandle.Zero );
}
protected override void Dispose( bool disposing )
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,53 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GLBufferObjectBase.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.OpenGL;
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Graphics.OpenGL
{
public abstract class GlBufferObjectBase : BufferObjectBase
{
private readonly glRender _contextBinding;
protected GlBufferObjectBase( glRender contextBinding )
{
binding = contextBinding;
_contextBinding = contextBinding;
}
protected OpenGLFunction GL => _contextBinding.GL;
}
}
@@ -0,0 +1,73 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="RBO.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.OpenGL;
using System;
using System.Collections.Generic;
using System.Security.Principal;
using System.Text;
namespace StgSharp.Graphics.OpenGL
{
public sealed class RenderBuffer : GlBufferObjectBase
{
public RenderBuffer( int count, glRender binding )
: base( binding )
{
_bufferHandle = GL.GenRenderBuffer( count );
}
public override void Bind( int index )
{
GL.BindRenderBuffer( this[ index ] );
}
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" );
}
}
protected override void Dispose( bool disposing )
{
foreach( GlHandle item in _bufferHandle ) {
Console.WriteLine( "removing a render buffer" );
GL.DeleteRenderBuffer( item );
}
}
}
}
@@ -0,0 +1,299 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="TextureGL.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.Intrinsic;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.OpenGL
{
public sealed unsafe class TextureGL
{
private int currentEditingTextureIndex;
private OpenGLFunction _gl;
internal GlHandle[] _textureHandle;
internal TextureGL( int count, glRender binding )
{
//sourceList = new Image[count];
this._gl = binding.GL;
_textureHandle = _gl.GenTextures( count );
}
public GlHandle this[ int index ]
{
get => _textureHandle[ index ];
}
public int Count
{
get => _textureHandle.Length;
}
//internal Image[] sourceList;
public int IndexOfCurrentTexture
{
get => currentEditingTextureIndex;
}
internal OpenGLFunction GL => _gl;
public void ActivateAs( TextureUnit unit )
{
_gl.ActiveTextureUnit( ( uint )unit );
}
public void Bind2D( int index )
{
currentEditingTextureIndex = index;
_gl.BindTexture( GLconst.TEXTURE_2D, _textureHandle[ index ] );
}
/// <summary>
/// Load an <see cref="Image" /> to certain texture.
/// </summary>
/// <param name="index"> </param>
/// <param name="i"> </param>
public unsafe void LoadTexture( int index, Image i )
{
byte[] handle = i.PixelBuffer;
_gl.TextureImage2d(
Texture2DTarget.Texture2D, 0, i.Channel, ( uint )i.Width,
( uint )i.Height, i.Channel, i.PixelLayout, pixels: handle );
_gl.GenerateMipmap( Texture2DTarget.Texture2D );
}
#region texture setting
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void Set2dFilterProperty(
int index,
TextureFilter onMinify,
TextureFilter onMagnify )
{
#if DEBUG
if( index != currentEditingTextureIndex ) {
throw new InvalidOperationException(
"Texture to be editted is not the one being activated." );
}
#endif
_gl.TextureParameter(
GLconst.TEXTURE_2D, GLconst.TEXTURE_MIN_FILTER,
( int )onMinify );
_gl.TextureParameter(
GLconst.TEXTURE_2D, GLconst.TEXTURE_MAG_FILTER,
( int )onMagnify );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void Set2dWrapProperty(
int index,
TextureWrap onHorizontial,
TextureWrap onVertical )
{
#if DEBUG
if( index != currentEditingTextureIndex ) {
throw new InvalidOperationException(
"Texture to be editted is not the one being activated." );
}
#endif
_gl.TextureParameter(
GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_S,
( int )onHorizontial );
_gl.TextureParameter(
GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_T, ( int )onVertical );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void Set2dProperty( int index, TextureProperty property )
{
Set2dFilterProperty(
index, property.FilterOnMinify, property.FilterOnMagnify );
Set2dWrapProperty(
index, property.WrapOnHorizontial, property.WrapOnVertical );
}
#endregion texture setting
}
[StructLayout( LayoutKind.Explicit )]
public struct TextureProperty
{
[FieldOffset( 0 )] private M128 mask;
[FieldOffset( 0 )] private TextureFilter mag;
[FieldOffset( 4 )] private TextureFilter min;
[FieldOffset( 8 )] private TextureWrap hori;
[FieldOffset( 12 )] private TextureWrap vert;
public TextureProperty(
TextureFilter onMagnify,
TextureFilter onMinify,
TextureWrap onHorizontial,
TextureWrap onVertical )
{
FilterOnMagnify = onMagnify;
FilterOnMinify = onMinify;
WrapOnHorizontial = onHorizontial;
WrapOnVertical = onVertical;
}
public TextureFilter FilterOnMagnify
{
get => mag;
set => mag = value;
}
public TextureFilter FilterOnMinify
{
get => min;
set => min = value;
}
public TextureWrap WrapOnHorizontial
{
get => hori;
set => hori = value;
}
public TextureWrap WrapOnVertical
{
get => vert;
set => vert = value;
}
public override bool Equals( [NotNullWhen( true )] object obj )
{
return base.Equals( obj );
}
public override int GetHashCode()
{
return HashCode.Combine(
FilterOnMagnify, FilterOnMagnify, WrapOnHorizontial,
WrapOnVertical );
}
public override string ToString()
{
return $"FilterOnMagnify:{FilterOnMagnify}, " + $"FilterOnMagnify:{FilterOnMagnify}, " + $"WrapOnHorizontial:{WrapOnHorizontial}, " + $"WrapOnVertical:{WrapOnVertical}";
}
public static bool operator !=(
TextureProperty left,
TextureProperty right )
{
return left.mask != right.mask;
}
public static bool operator ==(
TextureProperty left,
TextureProperty right )
{
return left.mask == right.mask;
}
public static implicit operator TextureProperty(
(
TextureFilter onMagnify, TextureFilter onMinify,
TextureWrap onHorizontial, TextureWrap onVertical
) propertyValueTuple )
{
return new TextureProperty(
propertyValueTuple.onMagnify, propertyValueTuple.onMinify,
propertyValueTuple.onHorizontial,
propertyValueTuple.onVertical );
}
}
#pragma warning disable CA1008
public enum TextureFilter
#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 TextureWrap
#pragma warning restore CA1008
{
Repeat = GLconst.REPEAT,
MirroredRepeat = GLconst.MIRRORED_REPEAT,
ClampToEdge = GLconst.CLAMP_TO_EDGE,
ClampToBorder = GLconst.CLAMP_TO_BORDER,
}
}
@@ -0,0 +1,81 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="VAO.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.Runtime.CompilerServices;
using System.Text;
namespace StgSharp.Graphics.OpenGL
{
public sealed unsafe class VertexArray : GlBufferObjectBase
{
internal VertexArray( int n, glRender binding )
: base( binding )
{
_bufferHandle = GL.GenVertexArrays( n );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public override sealed void Bind( int index )
{
GL.BindVertexArray( _bufferHandle[ index ] );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static void BindNull()
{
OpenGLFunction.CurrentGL.BindVertexArray( GlHandle.Zero );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetVertexAttribute(
uint index,
int vertexLength,
TypeCode dataType,
bool isNomalized,
uint stride,
int pointer )
{
GL.SetVertexAttribute(
index, vertexLength, dataType, isNomalized, stride, pointer );
}
protected override sealed void Dispose( bool disposing )
{
if( disposing ) {
GL.DeleteVertexArrays( _bufferHandle );
}
}
}
}
@@ -0,0 +1,170 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="VBO.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.Net.Security;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics.OpenGL
{
public sealed unsafe class VertexBuffer : GlBufferObjectBase
{
internal VertexBuffer( int n, glRender binding )
: base( binding )
{
_bufferHandle = GL.GenBuffers( n );
}
public override sealed void Bind( int index )
{
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
}
/// <summary>
///
/// </summary>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void Unbind()
{
GL.BindBuffer( BufferType.ArrayBuffer, GlHandle.Zero );
}
/// <summary>
/// Set _data to current vertex buffer object
/// </summary>
/// <typeparam name="T"> Type of bufferData </typeparam>
/// <param name="index"> Index to find certain VBO in this instance </param>
/// <param name="bufferData"> Data to write in </param>
/// <param name="usage"> How OpenGL use these _data, defined by <see cref="BufferUsage" /></param>
public void WriteMatrixData<T>(
int index,
T bufferData,
BufferUsage usage )
where T: struct, IMat
{
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
GL.SetBufferData( BufferType.ArrayBuffer, bufferData, usage );
}
/// <summary>
/// Set _data to current vertex buffer object
/// </summary>
/// <typeparam name="T"> Type of bufferData </typeparam>
/// <param name="index"> Index to find certain VBO in this instance </param>
/// <param name="bufferArray"> 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,
T[] bufferArray,
BufferUsage usage )
where T: struct,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
{
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
GL.SetBufferData( BufferType.ArrayBuffer, bufferArray, usage );
}
/// <summary>
/// Set _data to current vertex buffer object
/// </summary>
/// <typeparam name="T"> Type of bufferData </typeparam>
/// <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,
ReadOnlySpan<T> scalerSpan,
BufferUsage usage )
where T: struct,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
{
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
GL.SetBufferData( BufferType.ArrayBuffer, scalerSpan, usage );
}
/// <summary>
/// Set _data to current vertex buffer object
/// </summary>
/// <typeparam name="T"> Type of bufferData </typeparam>
/// <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,
ReadOnlySpan<T> vectorSpan,
BufferUsage usage )
where T: struct, IVector
{
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
GL.SetBufferVectorData( BufferType.ArrayBuffer, vectorSpan, usage );
}
/// <summary>
/// Set _data to current vertex buffer object
/// </summary>
/// <typeparam name="T"> Type of bufferData </typeparam>
/// <param name="index"> Index to find certain VBO in this instance </param>
/// <param name="vectorArray"> A array 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,
T[] vectorArray,
BufferUsage usage )
where T: struct, IVector
{
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
GL.SetBufferVectorData( BufferType.ArrayBuffer, vectorArray,
usage );
}
protected override sealed void Dispose( bool disposing )
{
if( disposing ) {
GL.DeleteBuffers( _bufferHandle );
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More