daily update on 20240828 by nitload youmu, autotexture added
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Logic;
|
||||
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -43,18 +43,19 @@ namespace StgSharp.Controls
|
||||
{
|
||||
public class BattleField : ControllingItem
|
||||
{
|
||||
public ReadOnlySpan<vec4d> TextureBox
|
||||
{
|
||||
get => throw new NotImplementedException() ;
|
||||
}
|
||||
public vec2d Position { get; set; }
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public bool IsEntity => true;
|
||||
public ReadOnlySpan<vec4d> TextureBox
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
}
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
public vec2d Position { get; set; }
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,11 +53,15 @@ namespace StgSharp.Controls
|
||||
buttonList = new List<TriggerButton>();
|
||||
}
|
||||
|
||||
public bool IsEntity { get => false; }
|
||||
|
||||
public ReadOnlySpan<vec4d> TextureBox
|
||||
{
|
||||
get => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public TriggerButton CurrentButton
|
||||
{
|
||||
get => current;
|
||||
@@ -65,10 +69,6 @@ namespace StgSharp.Controls
|
||||
|
||||
public vec2d Position { get; set; }
|
||||
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public bool IsEntity { get => false; }
|
||||
|
||||
protected List<TriggerButton> AllButton
|
||||
{
|
||||
get => buttonList;
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Geometries;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
|
||||
@@ -13,13 +43,24 @@ namespace StgSharp.Controls
|
||||
{
|
||||
public class CharacterLineIndexImage : ControllingItem
|
||||
{
|
||||
private int length;
|
||||
|
||||
private char[] displayIndex;
|
||||
private char defaultChar;
|
||||
|
||||
Dictionary<char, PlainGeometryMesh> texIndex;
|
||||
private int length;
|
||||
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;
|
||||
@@ -29,8 +70,8 @@ namespace StgSharp.Controls
|
||||
{
|
||||
get => throw new NotSupportedException();
|
||||
}
|
||||
public vec2d Position { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public Rectangle BoundingBox { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public vec2d Position { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public void Display(string message)
|
||||
{
|
||||
@@ -39,9 +80,9 @@ namespace StgSharp.Controls
|
||||
message = string.Empty;
|
||||
}
|
||||
|
||||
string result = message.Length >= length ?
|
||||
message.Substring(message.Length - displayIndex.Length) :
|
||||
message.PadLeft(length,defaultChar);
|
||||
string result = (message.Length >= length) ?
|
||||
message.Substring(message.Length - displayIndex.Length) :
|
||||
message.PadLeft(length, defaultChar);
|
||||
|
||||
displayIndex = result.ToCharArray();
|
||||
}
|
||||
@@ -55,15 +96,5 @@ namespace StgSharp.Controls
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Geometries;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
|
||||
@@ -9,18 +39,20 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public interface ControllingItem: IEnumerable<PlainGeometryMesh>
|
||||
public interface ControllingItem : IEnumerable<PlainGeometryMesh>
|
||||
{
|
||||
public abstract vec2d Position { get; set; }
|
||||
public abstract Rectangle BoundingBox { get; set; }
|
||||
|
||||
public abstract bool IsEntity { get; }
|
||||
|
||||
public abstract ReadOnlySpan<vec4d> TextureBox { get; }
|
||||
public abstract bool IsEntity { get; }
|
||||
public abstract Rectangle BoundingBox { get; set; }
|
||||
public abstract vec2d Position { get; set; }
|
||||
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Controls;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -11,26 +41,28 @@ namespace StgSharp.Controls
|
||||
{
|
||||
public class DecorationBox : ControllingItem
|
||||
{
|
||||
|
||||
private PlainGeometryMesh renderMesh;
|
||||
|
||||
public DecorationBox(Rectangle bound, Image texture, vec2d[] texCoord)
|
||||
{
|
||||
renderMesh = new PlainGeometryMesh(BoundingBox, new TextureProvider(texture, texCoord));
|
||||
}
|
||||
|
||||
public bool IsEntity => true;
|
||||
|
||||
public ReadOnlySpan<vec4d> TextureBox
|
||||
{
|
||||
get => renderMesh.TextureCoord;
|
||||
}
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public vec2d Position { get ; set ; }
|
||||
public Rectangle BoundingBox { get ; set ; }
|
||||
|
||||
public bool IsEntity => true;
|
||||
public vec2d Position { get; set; }
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
yield return renderMesh;
|
||||
}
|
||||
|
||||
public DecorationBox(Rectangle bound, Image texture, vec2d[] texCoord)
|
||||
{
|
||||
renderMesh = new PlainGeometryMesh(BoundingBox, new TextureProvider(texture, texCoord));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,38 @@
|
||||
using StgSharp.Controls;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -12,32 +43,12 @@ namespace StgSharp.Controls
|
||||
{
|
||||
public class MarkingLabel : ControllingItem
|
||||
{
|
||||
public ReadOnlySpan<vec4d> TextureBox
|
||||
{
|
||||
get => marker.TextureCoord;
|
||||
}
|
||||
public vec2d Position { get; set; }
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public bool IsEntity => true;
|
||||
|
||||
private vec2d _currentPosition, _movementVec;
|
||||
|
||||
private TimeFunction _movement;
|
||||
private PlainGeometryMesh marker;
|
||||
|
||||
public void MoveTo(vec2d target)
|
||||
{
|
||||
Move(target - Position);
|
||||
}
|
||||
private TimeFunction _movement;
|
||||
|
||||
public void Move(vec2d movement)
|
||||
{
|
||||
if (!_movement.IsComplete)
|
||||
{
|
||||
Position = _currentPosition + _movement.Calculate() * _movementVec;
|
||||
}
|
||||
}
|
||||
private vec2d _currentPosition, _movementVec;
|
||||
|
||||
public MarkingLabel(PlainGeometryMesh marker, TimeFunction movement)
|
||||
{
|
||||
@@ -45,10 +56,32 @@ namespace StgSharp.Controls
|
||||
_movement = movement;
|
||||
}
|
||||
|
||||
public bool IsEntity => true;
|
||||
public ReadOnlySpan<vec4d> TextureBox
|
||||
{
|
||||
get => marker.TextureCoord;
|
||||
}
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
public vec2d Position { get; set; }
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
yield return marker;
|
||||
}
|
||||
|
||||
public void Move(vec2d movement)
|
||||
{
|
||||
if (!_movement.IsComplete)
|
||||
{
|
||||
Position = _currentPosition + (_movement.Calculate() * _movementVec);
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveTo(vec2d target)
|
||||
{
|
||||
Move(target - Position);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,6 +40,9 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
|
||||
public delegate void RenderButtonTextureCallback(ButtonStatus status, float beginTime, in TextureProvider texture);
|
||||
|
||||
public enum ButtonStatus
|
||||
{
|
||||
Error = 0b0,
|
||||
@@ -57,22 +60,19 @@ namespace StgSharp.Controls
|
||||
HighlightToDisable = -(Highlight | Disable),
|
||||
}
|
||||
|
||||
public delegate void RenderButtonTextureCallback(ButtonStatus status, float beginTime, in TextureProvider texture);
|
||||
|
||||
public class TriggerButton : ControllingItem
|
||||
{
|
||||
private TextureProvider _texture;
|
||||
private float _statusBeginTime;
|
||||
|
||||
public TriggerButton Left { get; internal set; }
|
||||
public TriggerButton Right { get; internal set; }
|
||||
public TriggerButton Up { get; internal set; }
|
||||
public TriggerButton Down { get; internal set; }
|
||||
private Action? confirmCallback;
|
||||
private Action? disableCallback;
|
||||
|
||||
#nullable enable
|
||||
private Action? enableCallback;
|
||||
private Action? disableCallback;
|
||||
private Action? confirmCallback;
|
||||
private float _statusBeginTime;
|
||||
|
||||
private RenderButtonTextureCallback _renderButton;
|
||||
private TextureProvider _texture;
|
||||
|
||||
#nullable restore
|
||||
|
||||
public TriggerButton()
|
||||
@@ -80,11 +80,25 @@ namespace StgSharp.Controls
|
||||
CurrentStatus = ButtonStatus.Disable;
|
||||
}
|
||||
|
||||
protected ButtonStatus CurrentStatus { get; set; }
|
||||
public event Action ConfirmEvent
|
||||
{
|
||||
add { confirmCallback += value; }
|
||||
remove { confirmCallback -= value; }
|
||||
}
|
||||
|
||||
private RenderButtonTextureCallback _renderButton;
|
||||
public event Action DisableEvent
|
||||
{
|
||||
add { disableCallback += value; }
|
||||
remove { disableCallback -= value; }
|
||||
}
|
||||
|
||||
public event RenderButtonTextureCallback RenderButtonTexture
|
||||
public event Action EnableEvent
|
||||
{
|
||||
add { enableCallback += value; }
|
||||
remove { enableCallback -= value; }
|
||||
}
|
||||
|
||||
public event RenderButtonTextureCallback RenderButtonTexture
|
||||
{
|
||||
add
|
||||
{
|
||||
@@ -97,7 +111,7 @@ namespace StgSharp.Controls
|
||||
_renderButton += value;
|
||||
}
|
||||
}
|
||||
remove
|
||||
remove
|
||||
{
|
||||
if (_renderButton != null)
|
||||
{
|
||||
@@ -106,48 +120,51 @@ namespace StgSharp.Controls
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsHighLighted { get; internal set; }
|
||||
|
||||
public bool IsDisabled { get; internal set; }
|
||||
|
||||
public bool IsEntity => true;
|
||||
|
||||
public ReadOnlySpan<vec4d> TextureBox
|
||||
{
|
||||
get => MemoryMarshal.Cast<vec2d, vec4d>(_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 vec2d Position { get; set; }
|
||||
|
||||
internal TextureProvider Texture
|
||||
{
|
||||
get => _texture;
|
||||
set => _texture = value;
|
||||
}
|
||||
|
||||
public ReadOnlySpan<vec4d> TextureBox
|
||||
protected ButtonStatus CurrentStatus { get; set; }
|
||||
|
||||
public void DeHighlight()
|
||||
{
|
||||
get => MemoryMarshal.Cast<vec2d, vec4d>(_texture.TextureCoordinate);
|
||||
}
|
||||
|
||||
public bool IsHighLighted { get; internal set; }
|
||||
|
||||
public bool IsDisabled { get; internal set; }
|
||||
public vec2d Position { get; set; }
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public bool IsEntity => true;
|
||||
|
||||
public event Action EnableEvent
|
||||
{
|
||||
add { enableCallback += value; }
|
||||
remove { enableCallback -= value; }
|
||||
}
|
||||
|
||||
public event Action DisableEvent
|
||||
{
|
||||
add { disableCallback += value; }
|
||||
remove { disableCallback -= value; }
|
||||
}
|
||||
|
||||
public event Action ConfirmEvent
|
||||
{
|
||||
add { confirmCallback += value; }
|
||||
remove { confirmCallback -= value; }
|
||||
}
|
||||
|
||||
internal void Init( ButtonStatus status )
|
||||
{
|
||||
if (CurrentStatus == ButtonStatus.Error)
|
||||
if (CurrentStatus == ButtonStatus.Highlight)
|
||||
{
|
||||
CurrentStatus = status;
|
||||
CurrentStatus = ButtonStatus.HighlightToEnable;
|
||||
}
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
{
|
||||
CurrentStatus = CurrentStatus switch
|
||||
{
|
||||
ButtonStatus.Enable => ButtonStatus.EnableToDisable,
|
||||
ButtonStatus.Highlight => ButtonStatus.HighlightToDisable,
|
||||
_ => CurrentStatus,
|
||||
};
|
||||
if (disableCallback != null)
|
||||
{
|
||||
disableCallback();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,18 +178,16 @@ namespace StgSharp.Controls
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ( enableCallback != null)enableCallback();
|
||||
if (enableCallback != null)
|
||||
{
|
||||
enableCallback();
|
||||
}
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
CurrentStatus = CurrentStatus switch
|
||||
{
|
||||
ButtonStatus.Enable => ButtonStatus.EnableToDisable,
|
||||
ButtonStatus.Highlight => ButtonStatus.HighlightToDisable,
|
||||
_ => CurrentStatus,
|
||||
};
|
||||
if (disableCallback != null) disableCallback();
|
||||
_renderButton(CurrentStatus, _statusBeginTime, in _texture);
|
||||
yield return new PlainGeometryMesh(this.BoundingBox, _texture);
|
||||
}
|
||||
|
||||
public void Highlight()
|
||||
@@ -185,21 +200,18 @@ namespace StgSharp.Controls
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (confirmCallback != null) confirmCallback();
|
||||
}
|
||||
|
||||
public void DeHighlight()
|
||||
{
|
||||
if (CurrentStatus == ButtonStatus.Highlight)
|
||||
if (confirmCallback != null)
|
||||
{
|
||||
CurrentStatus = ButtonStatus.HighlightToEnable;
|
||||
confirmCallback();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
internal void Init(ButtonStatus status)
|
||||
{
|
||||
_renderButton(CurrentStatus,_statusBeginTime, in _texture);
|
||||
yield return new PlainGeometryMesh(this.BoundingBox, _texture);
|
||||
if (CurrentStatus == ButtonStatus.Error)
|
||||
{
|
||||
CurrentStatus = status;
|
||||
}
|
||||
}
|
||||
|
||||
}//----------------------------------- End of class --------------------------------------------
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Controls;
|
||||
using StgSharp.Controlling.UsrActivity;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class ViewPortDesigner
|
||||
{
|
||||
private KeyboardButtonGroup currentButtonGroup;
|
||||
|
||||
private List<ControllingItem> _controlList;
|
||||
|
||||
public ViewPortDesigner()
|
||||
{
|
||||
_controlList = new List<ControllingItem>();
|
||||
}
|
||||
|
||||
public KeyboardButtonGroup CreateKeyboardButtonGroup(
|
||||
ITrigger leftBidning,
|
||||
ITrigger rightBinding,
|
||||
ITrigger upBinding,
|
||||
ITrigger downBinding,
|
||||
ITrigger confirmBinding
|
||||
)
|
||||
{
|
||||
var ret = new KeyboardButtonGroup();
|
||||
_controlList.Add(ret);
|
||||
currentButtonGroup = ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public TriggerButton CreateKeyboardButton(
|
||||
Rectangle bonding, AnimationBuilder defaultAnimation, bool isEnable
|
||||
)
|
||||
{
|
||||
var ret = new TriggerButton();
|
||||
ret.BoundingBox = bonding;
|
||||
if (isEnable)
|
||||
{
|
||||
ret.IsDisabled = false;
|
||||
ret.Enable(defaultAnimation);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.IsDisabled = true;
|
||||
ret.Disable(defaultAnimation);
|
||||
}
|
||||
currentButtonGroup.AddButton(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public CharacterLineIndexImage CreateCharacterLine(
|
||||
int length, char blankFilling, PlainGeometryMesh tittle, IEnumerable<(char,PlainGeometryMesh)> charList
|
||||
)
|
||||
{
|
||||
var ret = new CharacterLineIndexImage(length, blankFilling,tittle,charList);
|
||||
_controlList.Add(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}//---------------------------------- End of Class -----------------------------------------
|
||||
|
||||
}
|
||||
@@ -78,6 +78,30 @@ namespace StgSharp.Graphics
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct OpenglContext
|
||||
{
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override unsafe int GetHashCode()
|
||||
{
|
||||
fixed (OpenglContext* sptr = &this)
|
||||
{
|
||||
return sptr->GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator !=(OpenglContext left, OpenglContext right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public static bool operator ==(OpenglContext left, OpenglContext right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
#region glapi
|
||||
|
||||
internal unsafe delegate*<uint, GLfixed, void> glAccumxOES;
|
||||
@@ -2615,27 +2639,6 @@ namespace StgSharp.Graphics
|
||||
|
||||
#endregion glapi
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public unsafe override int GetHashCode()
|
||||
{
|
||||
fixed (OpenglContext* sptr = &this)
|
||||
{
|
||||
return sptr->GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(OpenglContext left, OpenglContext right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(OpenglContext left, OpenglContext right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,9 +53,10 @@ namespace StgSharp
|
||||
InfoError,
|
||||
InfoWarning,
|
||||
}
|
||||
|
||||
|
||||
internal static unsafe partial class InternalIO
|
||||
{
|
||||
|
||||
internal const string SS_errorLog =
|
||||
"SS_errorlog.log";
|
||||
|
||||
@@ -65,13 +66,13 @@ namespace StgSharp
|
||||
internal static Dictionary<TypeCode, uint> GLtype =
|
||||
new Dictionary<TypeCode, uint>();
|
||||
|
||||
internal static SemaphoreSlim logSyncSemaphore = new SemaphoreSlim(1, 1);
|
||||
|
||||
internal static readonly GCHandle ssc_logHandle =
|
||||
GCHandle.Alloc(new byte[512], GCHandleType.Pinned);
|
||||
|
||||
internal static IntPtr SSClibPtr = IntPtr.Zero;
|
||||
|
||||
internal static SemaphoreSlim logSyncSemaphore = new SemaphoreSlim(1, 1);
|
||||
|
||||
static InternalIO()
|
||||
{
|
||||
GLtype.Add(TypeCode.Single, GLconst.FLOAT);
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using System;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -6,14 +36,15 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
[AttributeUsage( AttributeTargets.Method)]
|
||||
public class KeyEventAttribute:Attribute
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class KeyEventAttribute : Attribute
|
||||
{
|
||||
internal int _keyTarget;
|
||||
|
||||
internal int _equipment;
|
||||
internal int _keyStat;
|
||||
internal int _keyTarget;
|
||||
|
||||
public KeyEventAttribute(KeyboardKey key ,KeyStatus status)
|
||||
public KeyEventAttribute(KeyboardKey key, KeyStatus status)
|
||||
{
|
||||
_equipment = (int)InputEquipment.Keyboard;
|
||||
_keyTarget = (int)key;
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using System;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ITrigger.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;
|
||||
|
||||
@@ -6,7 +36,9 @@ namespace StgSharp.Controlling.UsrActivity
|
||||
{
|
||||
public interface ITrigger
|
||||
{
|
||||
|
||||
public int TargetKeyOrButtonID { get; }
|
||||
public KeyStatus TriggeredStatus { get; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using System;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
|
||||
@@ -6,28 +36,18 @@ namespace StgSharp.Controlling.UsrActivity
|
||||
{
|
||||
public struct JoystickTrigger : ITrigger, IEquatable<JoystickTrigger>
|
||||
{
|
||||
public Joystick Stick;
|
||||
|
||||
private KeyStatus _triggeredStat;
|
||||
|
||||
public int TargetKeyOrButtonID => (int)Stick;
|
||||
|
||||
public KeyStatus TriggeredStatus => _triggeredStat;
|
||||
public Joystick Stick;
|
||||
|
||||
public JoystickTrigger(Joystick targetKey)
|
||||
{
|
||||
this.Stick = targetKey;
|
||||
}
|
||||
|
||||
public static bool operator ==(JoystickTrigger left, JoystickTrigger right)
|
||||
{
|
||||
return left._triggeredStat == right._triggeredStat && left.Stick == right.Stick;
|
||||
}
|
||||
public int TargetKeyOrButtonID => (int)Stick;
|
||||
|
||||
public static bool operator !=(JoystickTrigger left, JoystickTrigger right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
public KeyStatus TriggeredStatus => _triggeredStat;
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
@@ -36,7 +56,7 @@ namespace StgSharp.Controlling.UsrActivity
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return (int)Stick + 17 * (int)_triggeredStat;
|
||||
return ((int)Stick) + (17 * ((int)_triggeredStat));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
@@ -44,9 +64,20 @@ namespace StgSharp.Controlling.UsrActivity
|
||||
return $"Key {Stick} triggered when {_triggeredStat}";
|
||||
}
|
||||
|
||||
public static bool operator !=(JoystickTrigger left, JoystickTrigger right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public static bool operator ==(JoystickTrigger left, JoystickTrigger right)
|
||||
{
|
||||
return (left._triggeredStat == right._triggeredStat) && (left.Stick == right.Stick);
|
||||
}
|
||||
|
||||
bool IEquatable<JoystickTrigger>.Equals(JoystickTrigger other)
|
||||
{
|
||||
return other == this;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using System;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -6,30 +36,21 @@ using System.Text;
|
||||
namespace StgSharp.Controlling.UsrActivity
|
||||
{
|
||||
|
||||
public struct KeyTrigger: ITrigger,IEquatable<KeyTrigger>
|
||||
public struct KeyTrigger : ITrigger, IEquatable<KeyTrigger>
|
||||
{
|
||||
|
||||
private KeyboardKey _targetKey;
|
||||
private KeyStatus _triggerStat;
|
||||
|
||||
public int TargetKeyOrButtonID => (int)_targetKey;
|
||||
|
||||
public KeyStatus TriggeredStatus => _triggerStat;
|
||||
|
||||
public KeyTrigger(KeyboardKey targetKey, KeyStatus targetStat)
|
||||
public KeyTrigger(KeyboardKey targetKey, KeyStatus targetStat)
|
||||
{
|
||||
this._targetKey = targetKey;
|
||||
this._triggerStat = targetStat;
|
||||
}
|
||||
|
||||
public static bool operator ==(KeyTrigger left, KeyTrigger right)
|
||||
{
|
||||
return left._triggerStat == right._triggerStat && left._targetKey == right._targetKey;
|
||||
}
|
||||
public int TargetKeyOrButtonID => (int)_targetKey;
|
||||
|
||||
public static bool operator !=(KeyTrigger left, KeyTrigger right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
public KeyStatus TriggeredStatus => _triggerStat;
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
@@ -38,7 +59,7 @@ namespace StgSharp.Controlling.UsrActivity
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return (int)_targetKey + 17 * (int)_triggerStat;
|
||||
return ((int)_targetKey) + (17 * ((int)_triggerStat));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
@@ -46,9 +67,20 @@ namespace StgSharp.Controlling.UsrActivity
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Controls;
|
||||
using StgSharp.Controlling.UsrActivity;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// ViewDesigner provides descriptions of various controls in the view,
|
||||
/// binds the controls to specific user actions and behaviors,
|
||||
/// and describes the layout and interactions of each control.
|
||||
/// </summary>
|
||||
public abstract class ViewDesigner<TView> where TView:View
|
||||
{
|
||||
protected TView _binding;
|
||||
|
||||
private KeyboardButtonGroup currentButtonGroup;
|
||||
|
||||
private List<ControllingItem> _controlList;
|
||||
|
||||
public ViewDesigner()
|
||||
{
|
||||
_controlList = new List<ControllingItem>();
|
||||
}
|
||||
|
||||
protected TView Binding
|
||||
{
|
||||
get => _binding;
|
||||
}
|
||||
|
||||
public TButtonGroup CreateKeyboardButtonGroup<TButtonGroup>(
|
||||
ITrigger leftBidning,
|
||||
ITrigger rightBinding,
|
||||
ITrigger upBinding,
|
||||
ITrigger downBinding,
|
||||
ITrigger confirmBinding
|
||||
)
|
||||
where TButtonGroup : KeyboardButtonGroup,new()
|
||||
{
|
||||
var ret = new TButtonGroup();
|
||||
_controlList.Add(ret);
|
||||
currentButtonGroup = ret;
|
||||
_binding.Responder[leftBidning] = ret.MoveLeft;
|
||||
_binding.Responder[rightBinding] = ret.MoveRight;
|
||||
_binding.Responder[upBinding] = ret.MoveUp;
|
||||
_binding.Responder[downBinding] = ret.MoveDown;
|
||||
_binding.Responder[confirmBinding] = ret.Confirm;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public TriggerButton CreateKeyboardButton(
|
||||
Rectangle bonding, TextureProvider defaultAnimation, bool isEnable
|
||||
)
|
||||
{
|
||||
var ret = new TriggerButton();
|
||||
ret.BoundingBox = bonding;
|
||||
if (isEnable)
|
||||
{
|
||||
ret.IsDisabled = false;
|
||||
ret.Enable();
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.IsDisabled = true;
|
||||
ret.Disable();
|
||||
}
|
||||
currentButtonGroup.AddButton(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public CharacterLineIndexImage CreateCharacterLine(
|
||||
int length, char blankFilling, PlainGeometryMesh tittle, IEnumerable<(char,PlainGeometryMesh)> charList
|
||||
)
|
||||
{
|
||||
var ret = new CharacterLineIndexImage(length, blankFilling,tittle,charList);
|
||||
_controlList.Add(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public abstract void CustomizedInitialize();
|
||||
|
||||
public abstract bool ValidateInitializing();
|
||||
|
||||
}//---------------------------------- End of Class -----------------------------------------
|
||||
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
using StgSharp.Controlling.UsrActivity;
|
||||
using StgSharp.Graphics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public abstract class ViewResponder<TView> where TView: View
|
||||
{
|
||||
private View _viewbinding;
|
||||
private Dictionary<ITrigger, Action> keyCallbackIndex;
|
||||
private Dictionary<string, Action> nameToCallbackMap;
|
||||
private bool _isInitialized;
|
||||
|
||||
|
||||
protected ViewResponder()
|
||||
{
|
||||
keyCallbackIndex = new Dictionary<ITrigger, Action>();
|
||||
nameToCallbackMap = new Dictionary<string, Action>();
|
||||
}
|
||||
|
||||
internal void ProcessUserInput()
|
||||
{
|
||||
foreach (var pair in keyCallbackIndex)
|
||||
{
|
||||
ITrigger t = pair.Key;
|
||||
if (InternalIO.glfwGetKey(_viewbinding.ViewHandle, t.TargetKeyOrButtonID) == t.TriggeredStatus)
|
||||
{
|
||||
pair.Value();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Action this[ITrigger trigger]
|
||||
{
|
||||
get => keyCallbackIndex.TryGetValue(trigger, out Action callback) ? callback : null;
|
||||
set
|
||||
{
|
||||
if (keyCallbackIndex.TryGetValue(trigger, out Action callback))
|
||||
{
|
||||
callback += value;
|
||||
}
|
||||
else
|
||||
{
|
||||
keyCallbackIndex.Add(trigger, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void Init(Func<string, Action> keyGetter)
|
||||
{
|
||||
if (_isInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
CustomizedInitialize(
|
||||
(trigger, name) =>
|
||||
{
|
||||
if (!nameToCallbackMap.TryGetValue(name, out Action ret))
|
||||
{
|
||||
ret = keyGetter.Invoke(name)??
|
||||
throw new InvalidOperationException($"Cannot find method named {name} in binded view model");
|
||||
}
|
||||
this[trigger] = ret;
|
||||
return ret;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public void ProcessInput()
|
||||
{
|
||||
foreach (var pair in keyCallbackIndex)
|
||||
{
|
||||
if (InternalIO.glfwGetKey(_viewbinding.ViewHandle,(int)pair.Key.TargetKeyOrButtonID) == pair.Key.TriggeredStatus)
|
||||
{
|
||||
pair.Value();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void CustomizedInitialize(Func<ITrigger, string, Action> keyRegister);
|
||||
|
||||
public abstract bool ValidateInitializing();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Data;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -10,10 +40,10 @@ namespace StgSharp
|
||||
{
|
||||
public static unsafe partial class StgSharp
|
||||
{
|
||||
private static SSD defaultIdProvider = new SSD();
|
||||
private static List<Area> root = new List<Area>();
|
||||
|
||||
private static byte leastUnusedArea;
|
||||
private static List<Area> root = new List<Area>();
|
||||
private static SSD defaultIdProvider = new SSD();
|
||||
|
||||
public static byte NewArea()
|
||||
{
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -8,7 +38,66 @@ namespace StgSharp
|
||||
{
|
||||
internal partial class InternalIO
|
||||
{
|
||||
internal const string CollisionTextureVertexShader ="#version 430 core\r\n\r\nlayout(location = 0) in vec2 localCollisionCoord;\r\nlayout(location = 1) in vec2 spaceCoord;\r\nlayout(location = 2) in float rotation;\r\nlayout(location = 3) in float scaling;\r\n\r\nuniform vec2 target;\r\nuniform mat2 projection;\r\n\r\nvoid main()\r\n{\r\n mat2 scaling = mat2(\r\n scaling,0,\r\n 0,scaling\r\n );\r\n mat2 rotation = mat2(\r\n cos(rotation),-sin(rotation),\r\n sin(rotation),cos(rotation) \r\n );\r\n vec2 realCoord = (rotation * scaling * localCollisionCoord) + spaceCoord - target;\r\n realCoord = projection * realCoord;\r\n\r\n float dist = distance(realCoord, vec2(0,0));\r\n float angle = atan(realCoord.y, realCoord.x);\r\n \r\n gl_Position = vec4(angle, realCoord.y, dist, 1);\r\n}";
|
||||
internal const string CollisionTextureFragmentShader = "#version 430 core\r\n\r\nout vec4 Color;\r\n\r\nuniform float range;\r\n\r\nvoid main()\r\n{\r\n float dist = gl_FragCoord.z;\r\n\r\n if(dist > range)\r\n {\r\n discard;\r\n }\r\n dist /= range;\r\n gl_FragDepth = min(dist, gl_FragDepth);\r\n\r\n Color = vec4(dist,0,0,1);\r\n}";
|
||||
|
||||
#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
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -43,8 +44,9 @@ using System.Text;
|
||||
namespace StgSharp.Data
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Pack = 16)]
|
||||
public unsafe struct M128:IMemoryType
|
||||
public unsafe struct M128 : IMemoryType
|
||||
{
|
||||
|
||||
[FieldOffset(0)] internal Vector4 vec;
|
||||
|
||||
internal M128(Vector4 v)
|
||||
@@ -52,6 +54,20 @@ namespace StgSharp.Data
|
||||
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
|
||||
@@ -89,7 +105,7 @@ namespace StgSharp.Data
|
||||
#if NET8_0_OR_GREATER
|
||||
, INumber
|
||||
#else
|
||||
,IConvertible
|
||||
, IConvertible
|
||||
#endif
|
||||
{
|
||||
fixed (Vector4* p = &vec)
|
||||
@@ -100,7 +116,17 @@ namespace StgSharp.Data
|
||||
}
|
||||
}
|
||||
|
||||
[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
|
||||
|
||||
@@ -165,5 +191,6 @@ namespace StgSharp.Data
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Data;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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 StgSharp.Data;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -12,8 +42,9 @@ namespace StgSharp.Math.HighPrecession
|
||||
{
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public unsafe struct M256:IMemoryType
|
||||
public unsafe struct M256 : IMemoryType
|
||||
{
|
||||
|
||||
private M128 v0;
|
||||
private M128 v1;
|
||||
|
||||
@@ -33,5 +64,6 @@ namespace StgSharp.Math.HighPrecession
|
||||
*(((T*)mptr) + index) = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Data;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
@@ -14,15 +44,16 @@ namespace StgSharp.Data
|
||||
public class RandomGenerator
|
||||
{
|
||||
|
||||
private byte[] currentKey;
|
||||
|
||||
|
||||
private readonly byte[] originKey;
|
||||
private byte[] currentKey;
|
||||
private int cycleCount;
|
||||
private SHA512 hash;
|
||||
|
||||
public RandomGenerator():this(DateTime.UtcNow.ToBinary())
|
||||
public RandomGenerator() : this(DateTime.UtcNow.ToBinary())
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public RandomGenerator(object source)
|
||||
@@ -77,28 +108,38 @@ namespace StgSharp.Data
|
||||
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;
|
||||
float ret = ((temp0 % temp1) * 1.0f) / temp1;
|
||||
if (ret < 0.335f)
|
||||
{
|
||||
ret = ret * (ret * -0.7811934f + 1.4489113f);
|
||||
ret = ret * ((ret * (-0.7811934f)) + 1.4489113f);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
ret = ret * (ret * -0.1158368f + 1.0580600f) + 0.0590584f;
|
||||
ret = (ret * ((ret * (-0.1158368f)) + 1.0580600f)) + 0.0590584f;
|
||||
}
|
||||
if (ret > 1)
|
||||
{
|
||||
@@ -111,14 +152,11 @@ namespace StgSharp.Data
|
||||
|
||||
}
|
||||
|
||||
public byte GenRandomInt8()
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
cycleCount++;
|
||||
if (cycleCount % 64 == 0)
|
||||
{
|
||||
PrivateRand();
|
||||
}
|
||||
return (byte)(currentKey[ cycleCount % 64 ]);
|
||||
currentKey = originKey;
|
||||
cycleCount = 0;
|
||||
}
|
||||
|
||||
private unsafe M128 PrivateRand()
|
||||
@@ -127,16 +165,16 @@ namespace StgSharp.Data
|
||||
M128 ret;
|
||||
fixed (byte* bptr = currentKey)
|
||||
{
|
||||
switch ((cycleCount % 16) / 4)
|
||||
switch ((cycleCount % 16) / 4)
|
||||
{
|
||||
case 0:
|
||||
ret= *((M128*)bptr + 0);break;
|
||||
ret = *(((M128*)bptr) + 0); break;
|
||||
case 1:
|
||||
ret= *((M128*)bptr + 1);break;
|
||||
ret = *(((M128*)bptr) + 1); break;
|
||||
case 2:
|
||||
ret= *((M128*)bptr + 2);break;
|
||||
ret = *(((M128*)bptr) + 2); break;
|
||||
case 3:
|
||||
ret= *((M128*)bptr + 3);break;
|
||||
ret = *(((M128*)bptr) + 3); break;
|
||||
default:
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
@@ -145,12 +183,5 @@ namespace StgSharp.Data
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
currentKey = originKey;
|
||||
cycleCount = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Data.FileIO;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -15,6 +45,6 @@ namespace StgSharp.Data
|
||||
/// </summary>
|
||||
public partial class Area
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,19 +43,19 @@ namespace StgSharp.Data
|
||||
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;
|
||||
|
||||
|
||||
[FieldOffset(12)] internal byte size;
|
||||
[FieldOffset(13)] public byte selfDefine_1;
|
||||
[FieldOffset(14)] public byte selfDefine_2;
|
||||
[FieldOffset(15)] public byte selfDefine_3;
|
||||
|
||||
|
||||
public int Size
|
||||
{
|
||||
get => ((int)size) + 1;
|
||||
|
||||
@@ -54,24 +54,6 @@ namespace StgSharp.Data
|
||||
this.PreviousHash = previousHash;
|
||||
}
|
||||
|
||||
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 this[int index]
|
||||
{
|
||||
get
|
||||
@@ -113,6 +95,24 @@ namespace StgSharp.Data
|
||||
}
|
||||
}
|
||||
|
||||
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];
|
||||
|
||||
@@ -39,11 +39,11 @@ namespace StgSharp.Data
|
||||
{
|
||||
public partial class SSD
|
||||
{
|
||||
private SSDrawHead head;
|
||||
|
||||
private Dictionary<string, SSDraw> fileList;
|
||||
|
||||
|
||||
private FileStream file;
|
||||
private SSDrawHead head;
|
||||
|
||||
public SSD()
|
||||
{
|
||||
|
||||
@@ -39,9 +39,10 @@ namespace StgSharp.Data
|
||||
{
|
||||
public class SSDFolder : ISSDSerializable
|
||||
{
|
||||
|
||||
internal Dictionary<string, SSDFolder> folders;
|
||||
internal int _folderID;
|
||||
internal string _name;
|
||||
internal Dictionary<string, SSDFolder> folders;
|
||||
|
||||
internal SSDFolder()
|
||||
{
|
||||
@@ -68,6 +69,11 @@ namespace StgSharp.Data
|
||||
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.VirtualFolder;
|
||||
|
||||
public void FromBytes(byte[] stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
//TODO 虚拟文件夹的GetBytes好难写
|
||||
public byte[] GetBytes()
|
||||
@@ -75,10 +81,5 @@ namespace StgSharp.Data
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void FromBytes(byte[] stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace StgSharp.Data.FileIO
|
||||
{
|
||||
public class SSDraw
|
||||
{
|
||||
|
||||
private byte[] data;
|
||||
|
||||
public SSDraw(string name, Stream streamSource)
|
||||
@@ -62,13 +63,14 @@ namespace StgSharp.Data.FileIO
|
||||
|
||||
public SSDrawHead Head { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 32 * 16)]
|
||||
public unsafe struct SSDrawHead
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using System;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -9,11 +39,13 @@ namespace StgSharp.Data
|
||||
|
||||
public interface ISSDSerializable
|
||||
{
|
||||
|
||||
public SerializableTypeCode SSDTypeCode { get; }
|
||||
|
||||
public byte[] GetBytes();
|
||||
|
||||
internal void FromBytes(byte[] stream);
|
||||
|
||||
}
|
||||
|
||||
public enum SerializableTypeCode
|
||||
@@ -31,14 +63,10 @@ namespace StgSharp.Data
|
||||
|
||||
public static partial class Serializer
|
||||
{
|
||||
public static byte[] Serialize(ISSDSerializable serializableObject)
|
||||
{
|
||||
return serializableObject.GetBytes();
|
||||
}
|
||||
|
||||
public static T Deserialize<T>(byte[] stream)where T : ISSDSerializable
|
||||
public static T Deserialize<T>(byte[] stream) where T : ISSDSerializable
|
||||
{
|
||||
T serializableObject = (T)Activator.CreateInstance<T>();
|
||||
T serializableObject = Activator.CreateInstance<T>();
|
||||
serializableObject.FromBytes(stream);
|
||||
return serializableObject;
|
||||
}
|
||||
@@ -67,5 +95,10 @@ namespace StgSharp.Data
|
||||
throw new ArgumentException("Unknown file type");
|
||||
}
|
||||
}
|
||||
public static byte[] Serialize(ISSDSerializable serializableObject)
|
||||
{
|
||||
return serializableObject.GetBytes();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -39,13 +39,13 @@ namespace StgSharp.Entities
|
||||
{
|
||||
|
||||
internal Launcher<EntityPartical> _awardLauncher;
|
||||
internal LinkedList<Launcher<EntityPartical>> _commonBulletLauncher;
|
||||
internal Launcher<EntityPartical> _dieBulletLauncher;
|
||||
internal LinkedList<Launcher<EntityPartical>> _commonBulletLauncher;
|
||||
public bool _selectalbe;
|
||||
|
||||
public Launcher<EntityPartical> AwardLauncher { get; set; }
|
||||
public LinkedList<Launcher<EntityPartical>> CommonBulletLauncher { get; set; }
|
||||
public Launcher<EntityPartical> DieBulletLauncher { get; set; }
|
||||
public LinkedList<Launcher<EntityPartical>> CommonBulletLauncher { get; set; }
|
||||
|
||||
public virtual void OnRender()
|
||||
{
|
||||
|
||||
@@ -40,14 +40,24 @@ namespace StgSharp
|
||||
{
|
||||
|
||||
protected uint _bornTick;
|
||||
internal Point _basePoint;
|
||||
internal Func<int, vec3d> _movHandler;
|
||||
internal LinkedList<PlainGeometry> _collisionBox;
|
||||
internal Sensor<PlainGeometry> _collisionSensor;
|
||||
internal Func<int,vec3d> _movHandler;
|
||||
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;
|
||||
@@ -63,23 +73,13 @@ namespace StgSharp
|
||||
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 vec2d Location { get; }
|
||||
|
||||
public string TextureGL { get; set; }
|
||||
|
||||
/// <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 abstract void OnRenderFrame();
|
||||
|
||||
public void SetLocation(Point p)
|
||||
|
||||
@@ -36,14 +36,15 @@ namespace StgSharp
|
||||
public class Launcher<T> where T : IEntity
|
||||
{
|
||||
|
||||
internal uint[] launchtick; //发射子弹的内部计时
|
||||
internal Counter<int> _internalParameter; //发射器的内部计时器
|
||||
|
||||
internal EntityPartical _bulletSample; //发射的子弹类型
|
||||
/*
|
||||
*用于发射其他的实体,主要是子弹 和 掉落物
|
||||
*/
|
||||
|
||||
internal vec2d _center; //发射器的参考位置,运动轨迹的方程应当基于这个参考点构建
|
||||
internal Counter<int> _internalParameter; //发射器的内部计时器
|
||||
internal uint[] launchtick; //发射子弹的内部计时
|
||||
|
||||
public EntityPartical Bullet
|
||||
{
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using System;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -8,10 +38,12 @@ namespace StgSharp
|
||||
{
|
||||
public class UniformEmptyReferenceException : Exception
|
||||
{
|
||||
public UniformEmptyReferenceException(string program, string name):
|
||||
|
||||
public UniformEmptyReferenceException(string program, string name) :
|
||||
base($"Location -1 returned when trying to find uniform {name} in shader program {program}")
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,19 +41,13 @@ namespace StgSharp
|
||||
{
|
||||
public static unsafe partial class StgSharp
|
||||
{
|
||||
private static int _mainThreadID = -1;
|
||||
|
||||
internal const int ssdSegmentLength = 16;
|
||||
|
||||
static byte[] _currentHash;
|
||||
|
||||
private static bool _inited;
|
||||
internal const int ssdSegmentLength = 16;
|
||||
|
||||
public static int MainThreadID
|
||||
{
|
||||
get => _mainThreadID == -1 ?
|
||||
throw new InvalidOperationException("StgSharp environment is not inited. " +
|
||||
"Main thread id is not available") :_mainThreadID;
|
||||
}
|
||||
private static int _mainThreadID = -1;
|
||||
|
||||
public static byte[] CurrentAssemblyHash
|
||||
{
|
||||
@@ -73,6 +67,13 @@ namespace StgSharp
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
@@ -104,6 +105,8 @@ namespace StgSharp
|
||||
vsyncActivated = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}//-------------------------------------- End of Class ---------------------------------------//
|
||||
}
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Graphics;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -11,18 +41,19 @@ namespace StgSharp
|
||||
{
|
||||
public static partial class StgSharp
|
||||
{
|
||||
private unsafe static IntPtr[] monitorsArray;
|
||||
|
||||
private static unsafe IntPtr[] monitorsArray;
|
||||
|
||||
public static unsafe IntPtr[] MonitorsHandleArray
|
||||
{
|
||||
get
|
||||
get
|
||||
{
|
||||
if (monitorsArray == null)
|
||||
{
|
||||
int count = 0;
|
||||
IntPtr* arrayhandle = InternalIO.glfwGetMonitors(&count);
|
||||
monitorsArray = new IntPtr[count];
|
||||
Marshal.Copy((IntPtr)arrayhandle,monitorsArray,0,count);
|
||||
Marshal.Copy((IntPtr)arrayhandle, monitorsArray, 0, count);
|
||||
Marshal.FreeHGlobal((IntPtr)arrayhandle);
|
||||
}
|
||||
return monitorsArray;
|
||||
@@ -31,11 +62,9 @@ namespace StgSharp
|
||||
|
||||
public static IntPtr DefaultMonitor
|
||||
{
|
||||
get
|
||||
{
|
||||
return MonitorsHandleArray[0];
|
||||
}
|
||||
get { return MonitorsHandleArray[0]; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -75,8 +75,9 @@ namespace StgSharp
|
||||
/// </summary>
|
||||
public const long version = 430;
|
||||
|
||||
private static uint markCount = 0;
|
||||
private static bool vsyncActivated;
|
||||
|
||||
private static uint markCount = 0;
|
||||
internal static GraphicAPI API = default;
|
||||
|
||||
public static void Init()
|
||||
@@ -96,6 +97,11 @@ namespace StgSharp
|
||||
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);
|
||||
@@ -105,11 +111,6 @@ namespace StgSharp
|
||||
InternalIO.InternalWriteLog(notVerySeriesException.Message, LogType.Warning);
|
||||
}
|
||||
|
||||
public static void LogInfo(string log)
|
||||
{
|
||||
InternalIO.InternalWriteLog(log, LogType.Info);
|
||||
}
|
||||
|
||||
public static void Mark(bool needConsole)
|
||||
{
|
||||
markCount++;
|
||||
|
||||
@@ -28,7 +28,9 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Logic;
|
||||
|
||||
|
||||
using StgSharp.Timing;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -50,9 +52,10 @@ namespace StgSharp
|
||||
|
||||
public sealed class StgSharpTime : TimeSourceProviderBase
|
||||
{
|
||||
|
||||
private static List<TimeSpanProvider> subscriberList = new List<TimeSpanProvider>();
|
||||
private static long accuracy;
|
||||
private static Stopwatch mainProvider = new Stopwatch();
|
||||
private static List<TimeSpanProvider> subscriberList = new List<TimeSpanProvider>();
|
||||
private static Thread timeProvideThread;
|
||||
|
||||
internal StgSharpTime()
|
||||
@@ -90,6 +93,14 @@ namespace StgSharp
|
||||
timeProvideThread.Start();
|
||||
}
|
||||
|
||||
public override void StopProvidingTime()
|
||||
{
|
||||
lock (mainProvider)
|
||||
{
|
||||
mainProvider.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public void Terminate()
|
||||
{
|
||||
lock (mainProvider)
|
||||
@@ -109,14 +120,6 @@ namespace StgSharp
|
||||
subscriberList.Remove(subscriber);
|
||||
}
|
||||
|
||||
public override void StopProvidingTime()
|
||||
{
|
||||
lock (mainProvider)
|
||||
{
|
||||
mainProvider.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private void ProvideTime()
|
||||
{
|
||||
long totalMS, internalFrequncy = Stopwatch.Frequency;
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using System;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -10,7 +40,8 @@ namespace StgSharp
|
||||
|
||||
public static partial class StgSharp
|
||||
{
|
||||
private static ConcurrentDictionary<int, KeyStatus> keyListener
|
||||
|
||||
private static ConcurrentDictionary<int, KeyStatus> keyListener
|
||||
= new ConcurrentDictionary<int, KeyStatus>();
|
||||
|
||||
public static KeyStatus CheckKey(KeyboardKey key)
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Math;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -10,9 +40,10 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
public abstract class CoordinationBase
|
||||
{
|
||||
|
||||
private bool globalCoordAvailable;
|
||||
private CoordinationBase localCoordination;
|
||||
private Matrix44 coordMat;
|
||||
private bool globalCoordAvailable;
|
||||
|
||||
|
||||
public CoordinationBase(
|
||||
@@ -24,7 +55,7 @@ namespace StgSharp.Geometries
|
||||
|
||||
public virtual Point LocalOrigin
|
||||
{
|
||||
get => new Point( coordMat.colum3.XYZ);
|
||||
get => new Point(coordMat.colum3.XYZ);
|
||||
internal set => coordMat.colum3.XYZ = value.Coord;
|
||||
}
|
||||
|
||||
@@ -46,7 +77,7 @@ namespace StgSharp.Geometries
|
||||
set => coordMat.colum2.XYZ = value;
|
||||
}
|
||||
|
||||
protected ref Matrix44 CoordMat
|
||||
protected ref Matrix44 CoordMat
|
||||
{
|
||||
get => ref coordMat;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,13 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
public class PlainCoordinate : CoordinationBase
|
||||
{
|
||||
|
||||
private static PlainCoordinate statndardPlainCoordination = new PlainCoordinate(
|
||||
null, new Point(0, 0, 0),
|
||||
new vec3d(1, 0, 0),
|
||||
new vec3d(0, 1, 0)
|
||||
);
|
||||
|
||||
public PlainCoordinate(
|
||||
CoordinationBase local,
|
||||
Point origin,
|
||||
@@ -55,12 +62,7 @@ namespace StgSharp.Geometries
|
||||
LocalOrigin = origin;
|
||||
}
|
||||
|
||||
private static PlainCoordinate statndardPlainCoordination = new PlainCoordinate(
|
||||
null, new Point(0,0,0),
|
||||
new vec3d(1,0,0),
|
||||
new vec3d(0, 1, 0)
|
||||
);
|
||||
|
||||
public static PlainCoordinate StandardPlainCoordination => statndardPlainCoordination;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Class1.cs"
|
||||
// file="SpaceCoordinate.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
@@ -38,11 +38,13 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
public class SpaceCoordinate : CoordinationBase
|
||||
{
|
||||
|
||||
public SpaceCoordinate(
|
||||
CoordinationBase localCoordination, Point origin,
|
||||
vec3d xAxis, vec3d yAxis, vec3d zAxis
|
||||
) : base(localCoordination)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Math;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
|
||||
@@ -1,4 +1,35 @@
|
||||
using StgSharp.Math;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -13,22 +44,12 @@ namespace StgSharp.Geometries
|
||||
|
||||
public class GeometryMotion
|
||||
{
|
||||
|
||||
private bool isIncrementMode;
|
||||
private bool sourceIsStatic;
|
||||
private TimeSpanProvider time;
|
||||
private GeometryMotionDelegate movement;
|
||||
private IntPtr handle;
|
||||
|
||||
public static GeometryMotion DefaultMotion
|
||||
{
|
||||
get => new GeometryMotion(true, null, null);
|
||||
}
|
||||
|
||||
private static vec3d defaultMotion(TimeSpanProvider provider, out float rotation)
|
||||
{
|
||||
rotation = 0;
|
||||
return Vec3d.Zero;
|
||||
}
|
||||
private TimeSpanProvider time;
|
||||
|
||||
public unsafe GeometryMotion(
|
||||
bool isIncreament,
|
||||
@@ -46,7 +67,7 @@ namespace StgSharp.Geometries
|
||||
else if (motionDelegate.Method.IsStatic)
|
||||
{
|
||||
sourceIsStatic = true;
|
||||
handle = Marshal.GetFunctionPointerForDelegate(motionDelegate);
|
||||
handle = Marshal.GetFunctionPointerForDelegate(motionDelegate);
|
||||
movement = motionDelegate;
|
||||
}
|
||||
else
|
||||
@@ -58,15 +79,20 @@ namespace StgSharp.Geometries
|
||||
|
||||
public bool IsIncrement
|
||||
{
|
||||
get => isIncrementMode;
|
||||
get => isIncrementMode;
|
||||
|
||||
}
|
||||
|
||||
public static GeometryMotion DefaultMotion
|
||||
{
|
||||
get => new GeometryMotion(true, null, null);
|
||||
}
|
||||
|
||||
public unsafe void RunMotion(ref vec3d coord, ref float rotation)
|
||||
{
|
||||
float rot;
|
||||
vec3d vec;
|
||||
if (sourceIsStatic)
|
||||
if (sourceIsStatic)
|
||||
{
|
||||
vec = ((delegate* unmanaged[Cdecl]<TimeSpanProvider, out float, vec3d>)handle)(time, out rot);
|
||||
}
|
||||
@@ -74,7 +100,7 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
vec = movement(time, out rot);
|
||||
}
|
||||
|
||||
|
||||
if (isIncrementMode)
|
||||
{
|
||||
coord += vec;
|
||||
@@ -86,5 +112,12 @@ namespace StgSharp.Geometries
|
||||
rotation = rot;
|
||||
}
|
||||
}
|
||||
|
||||
private static vec3d defaultMotion(TimeSpanProvider provider, out float rotation)
|
||||
{
|
||||
rotation = 0;
|
||||
return Vec3d.Zero;
|
||||
}
|
||||
|
||||
}//------------------------------- End of Class -------------------------------
|
||||
}
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using System;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -9,12 +39,19 @@ namespace StgSharp.Math
|
||||
{
|
||||
public static partial class GeometryScaler
|
||||
{
|
||||
|
||||
internal const float DegToRad = 180 / Scaler.Pi;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Degree ToDegree(float value)
|
||||
public static float Cos(Radius r)
|
||||
{
|
||||
return new Degree(value);
|
||||
return MathF.Cos(r._radius);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Cos(Degree r)
|
||||
{
|
||||
return MathF.Cos(r._degree / DegToRad);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -23,24 +60,18 @@ namespace StgSharp.Math
|
||||
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 Cos(Radius r)
|
||||
{
|
||||
return MathF.Cos(r._radius);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Sin(Degree r)
|
||||
{
|
||||
return MathF.Sin(r._degree/DegToRad);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Tan(Degree r)
|
||||
{
|
||||
@@ -48,18 +79,19 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Cos(Degree r)
|
||||
public static Degree ToDegree(float value)
|
||||
{
|
||||
return MathF.Cos(r._degree / DegToRad);
|
||||
return new Degree(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public struct Degree
|
||||
{
|
||||
|
||||
internal float _degree;
|
||||
|
||||
internal Degree(float dgree)
|
||||
internal Degree(float dgree)
|
||||
{
|
||||
_degree = dgree;
|
||||
}
|
||||
@@ -68,28 +100,25 @@ namespace StgSharp.Math
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
public Radius(float radius)
|
||||
{
|
||||
_radius = radius;
|
||||
}
|
||||
|
||||
[Obsolete("Unsafe, you may forget this is radius.",true)]
|
||||
public Radius() { }
|
||||
|
||||
public static implicit operator Degree(Radius r)
|
||||
{
|
||||
return new Degree(r._radius * 180 / Scaler.Pi);
|
||||
get => new Radius(0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -105,9 +134,9 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Radius operator +(Radius left, Radius Right)
|
||||
public static bool operator !=(Radius left, Radius right)
|
||||
{
|
||||
return new Radius(left._radius + Right._radius);
|
||||
return left._radius != right._radius;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -128,16 +157,21 @@ namespace StgSharp.Math
|
||||
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;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Radius left, Radius right)
|
||||
public static implicit operator Degree(Radius r)
|
||||
{
|
||||
return left._radius != right._radius;
|
||||
return new Degree((r._radius * 180) / Scaler.Pi);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
public interface IGeometry
|
||||
{
|
||||
public CoordinationBase Coordination { get; }
|
||||
|
||||
public Point this[int index]
|
||||
{
|
||||
@@ -49,19 +48,20 @@ namespace StgSharp.Geometries
|
||||
set;
|
||||
}
|
||||
|
||||
public int VertexCount
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
#pragma warning disable CA1819
|
||||
public vec4d[] VertexStream
|
||||
#pragma warning restore CA1819
|
||||
{
|
||||
get;
|
||||
}
|
||||
public CoordinationBase Coordination { get; }
|
||||
|
||||
public ReadOnlySpan<int> VertexIndices
|
||||
public int VertexCount
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public ReadOnlySpan<int> VertexIndices
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Exception.cs"
|
||||
// file="IGeomtryBuffer.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
@@ -28,14 +28,17 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Logic
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
}
|
||||
public interface IGeomtryBuffer
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -43,30 +43,6 @@ namespace StgSharp.Geometries
|
||||
public interface IInstancing
|
||||
{
|
||||
|
||||
public int BufferId
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public vec3d CenterPositionGlobal
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public vec3d Coord
|
||||
{
|
||||
get { return GlobalBuffer.CoordAndRotationList[BufferId].XYZ; }
|
||||
set { GlobalBuffer.CoordAndRotationList[BufferId] = new vec4d(value.vec); }
|
||||
}
|
||||
|
||||
public IInstancingBuffer GlobalBuffer
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public float Rotation
|
||||
{
|
||||
get { return GlobalBuffer.CoordAndRotationList[BufferId].W; }
|
||||
@@ -89,6 +65,30 @@ namespace StgSharp.Geometries
|
||||
get; set;
|
||||
}
|
||||
|
||||
public IInstancingBuffer GlobalBuffer
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public int BufferId
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public vec3d CenterPositionGlobal
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public vec3d Coord
|
||||
{
|
||||
get { return GlobalBuffer.CoordAndRotationList[BufferId].XYZ; }
|
||||
set { GlobalBuffer.CoordAndRotationList[BufferId] = new vec4d(value.vec); }
|
||||
}
|
||||
|
||||
public void Move()
|
||||
{
|
||||
(vec3d coord, float rotation) = (Coord, Rotation);
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Math;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -9,6 +39,10 @@ namespace StgSharp.Geometries
|
||||
public interface IInstancingBuffer
|
||||
{
|
||||
|
||||
public Span<vec4d> CoordAndRotationSpan { get; }
|
||||
|
||||
public Span<float> ScalingSpan { get; }
|
||||
|
||||
internal IGeometry TypicalShape { get; }
|
||||
|
||||
internal List<IInstancing> InstanceList { get; }
|
||||
@@ -17,11 +51,7 @@ namespace StgSharp.Geometries
|
||||
|
||||
internal List<float> ScalingList { get; }
|
||||
|
||||
public Span<vec4d> CoordAndRotationSpan { get; }
|
||||
|
||||
public Span<float> ScalingSpan { get; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace StgSharp.Geometries
|
||||
|
||||
public static unsafe class GeometryOperation
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static vec3d DefaultMotion(int tick)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Math;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -11,22 +41,19 @@ namespace StgSharp.Geometries
|
||||
|
||||
public interface IPlainEntity
|
||||
{
|
||||
|
||||
public vec2d CenterPosition { get; set; }
|
||||
|
||||
public bool CollideWith(IPlainEntity entity);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class PlainEntity:IPlainEntity
|
||||
public class PlainEntity : IPlainEntity
|
||||
{
|
||||
private PlainGeometry _shape;
|
||||
|
||||
vec2d IPlainEntity.CenterPosition
|
||||
{
|
||||
get => _shape.Coordination.LocalOrigin.Coord.XY;
|
||||
set => throw new InvalidOperationException();
|
||||
}
|
||||
private PlainGeometry _shape;
|
||||
|
||||
public PlainEntity(PlainGeometry shape)
|
||||
{
|
||||
@@ -37,6 +64,13 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
vec2d IPlainEntity.CenterPosition
|
||||
{
|
||||
get => _shape.Coordination.LocalOrigin.Coord.XY;
|
||||
set => throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="IInstancing.cs"
|
||||
// file="ParticleOnPlain.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
@@ -54,7 +54,7 @@ namespace StgSharp.Geometries
|
||||
((IInstancingBuffer)buffer).InstanceList.Add(this);
|
||||
}
|
||||
|
||||
public int BufferId
|
||||
public GeometryMotion Motion
|
||||
{
|
||||
get;
|
||||
set;
|
||||
@@ -65,9 +65,10 @@ namespace StgSharp.Geometries
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public GeometryMotion Motion
|
||||
{
|
||||
get;
|
||||
|
||||
public int BufferId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
@@ -77,16 +78,17 @@ namespace StgSharp.Geometries
|
||||
set;
|
||||
}
|
||||
|
||||
vec2d IPlainEntity.CenterPosition
|
||||
{
|
||||
get => GlobalBuffer.CoordAndRotationList[BufferId].XY;
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
bool IPlainEntity.CollideWith(IPlainEntity entity)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
vec2d IPlainEntity.CenterPosition
|
||||
{
|
||||
get => GlobalBuffer.CoordAndRotationList[BufferId].XY;
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace StgSharp.Geometries
|
||||
/// </summary>
|
||||
public abstract class PlainGeometry : IGeometry
|
||||
{
|
||||
|
||||
protected vec4d[] vertexMat;
|
||||
internal CoordinationBase coordinate;
|
||||
|
||||
|
||||
@@ -44,30 +44,24 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class PlainInstancingBuffer<T> :
|
||||
IDisposable,IEnumerable<T>, IInstancingBuffer
|
||||
where T :
|
||||
public class PlainInstancingBuffer<T> :
|
||||
IDisposable, IEnumerable<T>, IInstancingBuffer
|
||||
where T :
|
||||
IInstancing
|
||||
{
|
||||
|
||||
private bool disposedValue;
|
||||
|
||||
private CoordinatePlain globalCorrdinnate;
|
||||
private List<vec4d> coordList;
|
||||
private List<IInstancing> instanceList;
|
||||
private List<float> scalingList;
|
||||
private Mutex mutex;
|
||||
private bool disposedValue;
|
||||
|
||||
#region field of mem opt
|
||||
|
||||
vec4d[] coordArray;
|
||||
float[] scaleArray;
|
||||
|
||||
#endregion
|
||||
|
||||
public PlainInstancingBuffer()
|
||||
{
|
||||
coordList = new List<vec4d>(capacity: 100);
|
||||
instanceList = new List<IInstancing>(capacity:100);
|
||||
instanceList = new List<IInstancing>(capacity: 100);
|
||||
scalingList = new List<float>(capacity: 100);
|
||||
coordArray = Array.Empty<vec4d>();
|
||||
scaleArray = Array.Empty<float>();
|
||||
@@ -133,8 +127,6 @@ namespace StgSharp.Geometries
|
||||
}
|
||||
}
|
||||
|
||||
IGeometry IInstancingBuffer.TypicalShape => throw new NotImplementedException();
|
||||
|
||||
public int CreateInstanceID()
|
||||
{
|
||||
mutex.WaitOne();
|
||||
@@ -145,13 +137,32 @@ namespace StgSharp.Geometries
|
||||
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",
|
||||
message: "instance does not belong to current Particle Buffer",
|
||||
paramName: nameof(instance));
|
||||
}
|
||||
int index = instance.BufferId;
|
||||
@@ -170,7 +181,7 @@ namespace StgSharp.Geometries
|
||||
|
||||
public void UpdateAllParticles()
|
||||
{
|
||||
foreach (var particle in instanceList)
|
||||
foreach (IInstancing particle in instanceList)
|
||||
{
|
||||
particle.Move();
|
||||
}
|
||||
@@ -192,31 +203,23 @@ namespace StgSharp.Geometries
|
||||
}
|
||||
}
|
||||
|
||||
// ~PlainInstancingBuffer()
|
||||
// {
|
||||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
foreach (var item in instanceList)
|
||||
{
|
||||
yield return (T)item;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
foreach (var item in instanceList)
|
||||
foreach (IInstancing item in instanceList)
|
||||
{
|
||||
yield return (T)item;
|
||||
}
|
||||
}
|
||||
|
||||
IGeometry IInstancingBuffer.TypicalShape => throw new NotImplementedException();
|
||||
|
||||
#region field of mem opt
|
||||
|
||||
vec4d[] coordArray;
|
||||
float[] scaleArray;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,14 +38,15 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
public class Polygon4 : PlainGeometry
|
||||
{
|
||||
|
||||
protected static int[] Indices = [0, 1, 2, 0, 2, 3];
|
||||
|
||||
internal Polygon4():base(PlainCoordinate.StandardPlainCoordination)
|
||||
internal Polygon4() : base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new vec4d[4];
|
||||
}
|
||||
|
||||
internal Polygon4(vec4d[] rawCoord):
|
||||
internal Polygon4(vec4d[] rawCoord) :
|
||||
base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
if (rawCoord.Length != 4)
|
||||
@@ -60,7 +61,7 @@ namespace StgSharp.Geometries
|
||||
Point topRight,
|
||||
Point bottomRight,
|
||||
Point bottomLeft
|
||||
):base(PlainCoordinate.StandardPlainCoordination)
|
||||
) : base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
this[0] = topLeft;
|
||||
this[1] = topRight;
|
||||
@@ -69,21 +70,6 @@ namespace StgSharp.Geometries
|
||||
|
||||
}
|
||||
|
||||
public Polygon4(
|
||||
float v0x, float v0y,
|
||||
float v1x, float v1y,
|
||||
float v2x, float v2y,
|
||||
float v3x, float v3y
|
||||
):base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new vec4d[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(CoordinationBase coordinate,
|
||||
PlainCoordinate coordination,
|
||||
@@ -100,6 +86,21 @@ namespace StgSharp.Geometries
|
||||
|
||||
}
|
||||
|
||||
public Polygon4(
|
||||
float v0x, float v0y,
|
||||
float v1x, float v1y,
|
||||
float v2x, float v2y,
|
||||
float v3x, float v3y
|
||||
) : base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new vec4d[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,
|
||||
|
||||
@@ -39,7 +39,9 @@ namespace StgSharp.Geometries
|
||||
public unsafe class Polygon5 : PlainGeometry
|
||||
{
|
||||
|
||||
public unsafe Polygon5():base(PlainCoordinate.StandardPlainCoordination)
|
||||
internal static int[] Indices = [0, 1, 2, 0, 2, 3, 0, 3, 4];
|
||||
|
||||
public unsafe Polygon5() : base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new vec4d[5];
|
||||
}
|
||||
@@ -50,7 +52,7 @@ namespace StgSharp.Geometries
|
||||
float v2x, float v2y,
|
||||
float v3x, float v3y,
|
||||
float v4x, float v4y
|
||||
):base(PlainCoordinate.StandardPlainCoordination)
|
||||
) : base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new vec4d[5];
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
@@ -67,7 +69,7 @@ namespace StgSharp.Geometries
|
||||
float v2x, float v2y,
|
||||
float v3x, float v3y,
|
||||
float v4x, float v4y
|
||||
):base(coordination)
|
||||
) : base(coordination)
|
||||
{
|
||||
vertexMat = new vec4d[5];
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
@@ -77,8 +79,7 @@ namespace StgSharp.Geometries
|
||||
this[4] = new Point(v4x, v4y, 0);
|
||||
}
|
||||
|
||||
internal static int[] Indices = [ 0, 1, 2, 0, 2, 3, 0, 3, 4 ];
|
||||
|
||||
public override ReadOnlySpan<int> VertexIndices => Indices;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,10 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
public class Polygon6 : PlainGeometry
|
||||
{
|
||||
public Polygon6():base(PlainCoordinate.StandardPlainCoordination)
|
||||
|
||||
internal static int[] Indices = [0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5];
|
||||
|
||||
public Polygon6() : base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new vec4d[6];
|
||||
}
|
||||
@@ -64,8 +67,7 @@ namespace StgSharp.Geometries
|
||||
vertexMat[6].vec = vert6.vec;
|
||||
}
|
||||
|
||||
internal static int[] Indices = [ 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5 ];
|
||||
|
||||
public override ReadOnlySpan<int> VertexIndices => Indices;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,9 @@ namespace StgSharp.Geometries
|
||||
public unsafe class Triangle : PlainGeometry
|
||||
{
|
||||
|
||||
public Triangle():base(PlainCoordinate.StandardPlainCoordination)
|
||||
internal static int[] Indices = [0, 1, 2];
|
||||
|
||||
public Triangle() : base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new vec4d[3];
|
||||
}
|
||||
@@ -58,6 +60,17 @@ namespace StgSharp.Geometries
|
||||
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,
|
||||
@@ -69,17 +82,6 @@ namespace StgSharp.Geometries
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
}
|
||||
|
||||
public Triangle(PlainCoordinate coordination,
|
||||
Point vertex01,
|
||||
Point vertex02,
|
||||
Point vertex03
|
||||
) : base(coordination)
|
||||
{
|
||||
this[0] = vertex01;
|
||||
this[1] = vertex02;
|
||||
this[2] = vertex03;
|
||||
}
|
||||
|
||||
public Triangle(PlainCoordinate coordination,
|
||||
float v0x, float v0y,
|
||||
float v1x, float v1y,
|
||||
@@ -90,7 +92,6 @@ namespace StgSharp.Geometries
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
}
|
||||
internal static int[] Indices = [ 0, 1, 2 ];
|
||||
|
||||
public override ReadOnlySpan<int> VertexIndices => Indices;
|
||||
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Math;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -11,12 +41,14 @@ namespace StgSharp.Geometries
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16)]
|
||||
public struct Point
|
||||
{
|
||||
|
||||
[FieldOffset(0)] private vec3d coord;
|
||||
[FieldOffset(0)] internal Vector4 coordVec;
|
||||
|
||||
public Point(float x, float y, float z)
|
||||
internal Point(vec4d vector)
|
||||
{
|
||||
coordVec = new Vector4(x,y,z,1);
|
||||
coordVec = vector.vec;
|
||||
coordVec.W = 1;
|
||||
}
|
||||
|
||||
public Point(vec3d coord)
|
||||
@@ -25,10 +57,9 @@ namespace StgSharp.Geometries
|
||||
coordVec.W = 1;
|
||||
}
|
||||
|
||||
internal Point(vec4d vector)
|
||||
public Point(float x, float y, float z)
|
||||
{
|
||||
coordVec = vector.vec;
|
||||
coordVec.W = 1;
|
||||
coordVec = new Vector4(x, y, z, 1);
|
||||
}
|
||||
|
||||
public vec3d Coord
|
||||
|
||||
@@ -13,3 +13,5 @@ using System.Diagnostics.CodeAnalysis;
|
||||
[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")]
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="AnimationBuilder.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Geometries;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public delegate Image BuildAnimationDelegate(float time, out Polygon4 texutreFrame);
|
||||
|
||||
public sealed class AnimationBuilder: IImageProvider
|
||||
{
|
||||
|
||||
private Image cache;
|
||||
private Polygon4 textureFrame;
|
||||
private TimeFunction time;
|
||||
|
||||
public AnimationBuilder(
|
||||
BuildAnimationDelegate builderFunc,
|
||||
TimeFunction timeline
|
||||
)
|
||||
{
|
||||
textureFrame = new Polygon4();
|
||||
time = timeline;
|
||||
BuilderFunc = builderFunc;
|
||||
cache = BuilderFunc(time.Calculate(), out textureFrame);
|
||||
}
|
||||
|
||||
public Polygon4 TextureFrame { get => textureFrame; }
|
||||
|
||||
public BuildAnimationDelegate BuilderFunc { get; set; }
|
||||
|
||||
public bool IsComplete
|
||||
{
|
||||
get => time.IsComplete;
|
||||
}
|
||||
|
||||
public Image GetAnimationFrame()
|
||||
{
|
||||
if (!time.IsComplete)
|
||||
{
|
||||
cache = BuilderFunc(time.Calculate(),out textureFrame);
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
time.Reset();
|
||||
}
|
||||
|
||||
Image IImageProvider.ProvideImage()
|
||||
{
|
||||
return GetAnimationFrame();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,34 @@
|
||||
using System;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
|
||||
@@ -7,6 +37,5 @@ namespace StgSharp.Graphics
|
||||
public interface IImageProvider
|
||||
{
|
||||
Image ProvideImage();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using System;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.Text;
|
||||
|
||||
@@ -12,10 +42,10 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
throw new ArgumentNullException(nameof(i));
|
||||
}
|
||||
Array.Resize(ref i.data, width * height * i.PixelSize);
|
||||
Array.Resize(ref i.Data, width * height * i.PixelSize);
|
||||
i.Height = height;
|
||||
i.Width = width;
|
||||
switch (move)
|
||||
switch (move)
|
||||
{
|
||||
case ImageMovement.Discard:
|
||||
break;
|
||||
@@ -24,8 +54,8 @@ namespace StgSharp.Graphics
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
i.PixelUpdateCount++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Flags]
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public static class ImageProcessor
|
||||
{
|
||||
public static void Resize(Image i, int width, int height, ImageMovement move)
|
||||
{
|
||||
if (i == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(i));
|
||||
}
|
||||
Array.Resize(ref i.data, width * height * i.ChannelCount);
|
||||
i.Height = height;
|
||||
i.Width = width;
|
||||
switch (move)
|
||||
{
|
||||
case ImageMovement.Discard:
|
||||
break;
|
||||
case ImageMovement.Top:
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException("Invalid or not supported data remanence");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum ImageMovement
|
||||
{
|
||||
#pragma warning disable CA1008
|
||||
Discard = 0,
|
||||
#pragma warning restore CA1008
|
||||
Top = 1,
|
||||
Bottom = 2,
|
||||
Left = 4,
|
||||
Right = 8,
|
||||
TopLeft = Top | Left,
|
||||
BottomLeft = Bottom | Left,
|
||||
TopRight = Top | Right,
|
||||
BottomRight = Bottom | Right,
|
||||
}
|
||||
}
|
||||
@@ -43,8 +43,9 @@ namespace StgSharp.Graphics
|
||||
/// </summary>
|
||||
public abstract class BufferObjectBase : IDisposable
|
||||
{
|
||||
protected RenderStream binding;
|
||||
|
||||
protected GlHandle[] _bufferHandle;
|
||||
protected RenderStream binding;
|
||||
|
||||
/// <summary>
|
||||
/// Get the only handle to one of the Object instance
|
||||
|
||||
@@ -49,22 +49,9 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWcontext
|
||||
{
|
||||
|
||||
private int client;
|
||||
private IntPtr destroy;
|
||||
private delegate*<byte*> extensionSupported;
|
||||
private GLFWbool forward, debug, noerror;
|
||||
|
||||
//PFNGLGETINTEGERVPROC GetIntegerv;
|
||||
private IntPtr GetIntegerv;
|
||||
private delegate*<delegate*<void>, void> getProcAddress;
|
||||
|
||||
//PFNGLGETSTRINGPROC GetString;
|
||||
private IntPtr GetString;
|
||||
|
||||
//PFNGLGETSTRINGIPROC GetStringi;
|
||||
private IntPtr GetStringi;
|
||||
private int major, minor, revision;
|
||||
|
||||
/*
|
||||
void (* makeCurrent) (glfwWindow*);
|
||||
void (* swapBuffers) (glfwWindow*);
|
||||
@@ -75,12 +62,26 @@ namespace StgSharp.Graphics
|
||||
*/
|
||||
|
||||
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 delegate*<glfwWindow*> swapBuffer;
|
||||
private delegate*<int> swapInterval;
|
||||
private IntPtr destroy;
|
||||
|
||||
//PFNGLGETINTEGERVPROC GetIntegerv;
|
||||
private IntPtr GetIntegerv;
|
||||
|
||||
//PFNGLGETSTRINGPROC GetString;
|
||||
private IntPtr GetString;
|
||||
|
||||
//PFNGLGETSTRINGIPROC GetStringi;
|
||||
private IntPtr GetStringi;
|
||||
|
||||
internal struct egl
|
||||
{
|
||||
@@ -165,15 +166,16 @@ namespace StgSharp.Graphics
|
||||
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;
|
||||
/*! The pixel data of this image, arranged left-to-right, top-to-bottom.
|
||||
*/
|
||||
private byte* pixels;
|
||||
|
||||
|
||||
}
|
||||
@@ -182,22 +184,24 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWgamepadstate
|
||||
{
|
||||
|
||||
/*! The states of each [gamepad axis](@ref gamepad_axes), in the range -1.0
|
||||
* to 1.0 inclusive.
|
||||
*/
|
||||
public fixed float axes[6];
|
||||
|
||||
/*! 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;
|
||||
|
||||
@@ -207,34 +211,32 @@ namespace StgSharp.Graphics
|
||||
//GLFWreallocatefun reallocate;
|
||||
private IntPtr reallocate;
|
||||
|
||||
private void* user;
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public unsafe struct glfwMonitor
|
||||
{
|
||||
|
||||
private fixed byte name[128];
|
||||
private IntPtr userPointer;
|
||||
|
||||
private int width, height;
|
||||
private glfwVideomode* modes;
|
||||
|
||||
private glfwWindow* window;
|
||||
|
||||
private glfwVideomode* modes;
|
||||
private int modeCount;
|
||||
private glfwVideomode currentMode;
|
||||
private fixed byte name[128];
|
||||
private glfwGammaramp currentRamp;
|
||||
|
||||
private glfwGammaramp originalRamp;
|
||||
private glfwGammaramp currentRamp;
|
||||
private glfwVideomode currentMode;
|
||||
private int modeCount;
|
||||
|
||||
private int width, height;
|
||||
private IntPtr userPointer;
|
||||
|
||||
public glfwMonitor()
|
||||
{ }
|
||||
|
||||
public unsafe string Name
|
||||
{
|
||||
get
|
||||
get
|
||||
{
|
||||
fixed (byte* cptr = name)
|
||||
{
|
||||
@@ -242,69 +244,73 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
unsafe struct glfwWindow
|
||||
{
|
||||
|
||||
glfwWindow* next;
|
||||
|
||||
// Window settings and state
|
||||
int resizable;
|
||||
int decorated;
|
||||
int autoIconify;
|
||||
int floating;
|
||||
int focusOnShow;
|
||||
int mousePassthrough;
|
||||
int shouldClose;
|
||||
void* userPointer;
|
||||
int doublebuffer;
|
||||
// glfwVideomode videoMode; // 根据GLFWvidmode的定义转换
|
||||
IntPtr monitor; // _GLFWmonitor* monitor;
|
||||
IntPtr cursor; // _GLFWcursor* cursor;
|
||||
|
||||
int minwidth, minheight;
|
||||
int maxwidth, maxheight;
|
||||
int numer, denom;
|
||||
|
||||
int stickyKeys;
|
||||
int stickyMouseButtons;
|
||||
int lockKeyMods;
|
||||
int cursorMode;
|
||||
public fixed byte mouseButtons[GLconst.GLFW_MOUSE_BUTTON_LAST + 1];
|
||||
public fixed byte keys[GLconst.GLFW_KEY_LAST + 1];
|
||||
bool rawMouseMotion;
|
||||
Callbacks callbacks;
|
||||
|
||||
// Virtual cursor position when cursor is disabled
|
||||
double virtualCursorPosX, virtualCursorPosY;
|
||||
bool rawMouseMotion;
|
||||
int autoIconify;
|
||||
int cursorMode;
|
||||
int decorated;
|
||||
int doublebuffer;
|
||||
int floating;
|
||||
int focusOnShow;
|
||||
int lockKeyMods;
|
||||
int maxwidth, maxheight;
|
||||
|
||||
int minwidth, minheight;
|
||||
int mousePassthrough;
|
||||
int numer, denom;
|
||||
|
||||
// Window settings and state
|
||||
int resizable;
|
||||
int shouldClose;
|
||||
|
||||
int stickyKeys;
|
||||
int stickyMouseButtons;
|
||||
IntPtr cursor; // _GLFWcursor* cursor;
|
||||
// glfwVideomode videoMode; // 根据GLFWvidmode的定义转换
|
||||
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 pos;
|
||||
internal IntPtr size;
|
||||
internal IntPtr close;
|
||||
internal IntPtr refresh;
|
||||
internal IntPtr focus;
|
||||
internal IntPtr iconify;
|
||||
internal IntPtr maximize;
|
||||
internal IntPtr fbsize;
|
||||
internal IntPtr scale;
|
||||
internal IntPtr mouseButton;
|
||||
internal IntPtr cursorPos;
|
||||
internal IntPtr cursorEnter;
|
||||
internal IntPtr scroll;
|
||||
internal IntPtr key;
|
||||
|
||||
internal IntPtr character;
|
||||
internal IntPtr charmods;
|
||||
internal IntPtr close;
|
||||
internal IntPtr cursorEnter;
|
||||
internal IntPtr cursorPos;
|
||||
internal IntPtr drop;
|
||||
}
|
||||
Callbacks callbacks;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// GLFW_PLATFORM_WINDOW_STATE platformWindowState;
|
||||
}
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
@@ -345,9 +351,9 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWinitconfig
|
||||
{
|
||||
|
||||
private int angleType;
|
||||
|
||||
private GLFWbool hatButtons;
|
||||
|
||||
private int angleType;
|
||||
private int platformID;
|
||||
|
||||
//PFN_vkGetInstanceProcAddr vulkanLoader;
|
||||
@@ -359,19 +365,20 @@ namespace StgSharp.Graphics
|
||||
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 int height;
|
||||
private GLFWbool maximized;
|
||||
private GLFWbool mousePassthrough;
|
||||
private GLFWbool resizable;
|
||||
private GLFWbool scaleToMonitor;
|
||||
private byte* title;
|
||||
private GLFWbool visible;
|
||||
private int height;
|
||||
private int width;
|
||||
|
||||
private int xpos;
|
||||
@@ -437,19 +444,20 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWctxconfig
|
||||
{
|
||||
|
||||
private int client;
|
||||
private GLFWbool debug;
|
||||
private GLFWbool forward;
|
||||
private GLFWbool noerror;
|
||||
|
||||
private int client;
|
||||
private int major;
|
||||
private int minor;
|
||||
private GLFWbool noerror;
|
||||
private int profile;
|
||||
private int release;
|
||||
private int robustness;
|
||||
private int source;
|
||||
|
||||
//glfwWindow* share;
|
||||
private IntPtr share;
|
||||
private int source;
|
||||
|
||||
internal Nsgl nsgl = new Nsgl();
|
||||
|
||||
@@ -470,6 +478,11 @@ namespace StgSharp.Graphics
|
||||
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;
|
||||
@@ -478,16 +491,12 @@ namespace StgSharp.Graphics
|
||||
private int auxBuffers;
|
||||
private int blueBits;
|
||||
private int depthBits;
|
||||
private GLFWbool doublebuffer;
|
||||
private int greenBits;
|
||||
private uintptr_t handle;
|
||||
|
||||
private int redBits;
|
||||
private int samples;
|
||||
private GLFWbool sRGB;
|
||||
private int stencilBits;
|
||||
private GLFWbool stereo;
|
||||
private GLFWbool transparent;
|
||||
private uintptr_t handle;
|
||||
|
||||
}
|
||||
|
||||
@@ -495,37 +504,37 @@ namespace StgSharp.Graphics
|
||||
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;
|
||||
private GLFWmutex errorLock;
|
||||
|
||||
private GLFWls errorSlot;
|
||||
|
||||
private GLFWbool initialized;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = GLconst.GLFW_JOYSTICK_LAST + 1)]
|
||||
private GLFWjoystick[] joysticks = new GLFWjoystick[GLconst.GLFW_JOYSTICK_LAST + 1];
|
||||
|
||||
private GLFWbool joysticksInitialized;
|
||||
|
||||
private int mappingCount;
|
||||
|
||||
//GLFWmapping* mappings;
|
||||
private IntPtr mappings;
|
||||
|
||||
private int monitorCount;
|
||||
|
||||
//GLFWmonitor** monitors;
|
||||
private IntPtr monitors;
|
||||
|
||||
private GLFWplatform platform;
|
||||
|
||||
//glfwWindow* windowListHead;
|
||||
private IntPtr windowListHead;
|
||||
|
||||
@@ -548,8 +557,8 @@ namespace StgSharp.Graphics
|
||||
private GLFWfbconfig framebuffer;
|
||||
|
||||
private GLFWinitconfig init;
|
||||
private int refreshRate;
|
||||
private GLFWwndconfig window;
|
||||
private int refreshRate;
|
||||
|
||||
}
|
||||
|
||||
@@ -566,23 +575,36 @@ namespace StgSharp.Graphics
|
||||
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 void* display;
|
||||
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 IntPtr GetConfigAttrib;
|
||||
internal IntPtr GetConfigs;
|
||||
@@ -591,20 +613,8 @@ namespace StgSharp.Graphics
|
||||
|
||||
internal IntPtr GetPlatformDisplayEXT;
|
||||
internal IntPtr GetProcAddress;
|
||||
|
||||
internal void* handle;
|
||||
internal IntPtr Initialize;
|
||||
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 int major, minor;
|
||||
internal IntPtr MakeCurrent;
|
||||
|
||||
internal int platform;
|
||||
internal bool prefix;
|
||||
internal IntPtr QueryString;
|
||||
internal IntPtr SwapBuffers;
|
||||
internal IntPtr SwapInterval;
|
||||
@@ -615,6 +625,8 @@ namespace StgSharp.Graphics
|
||||
internal unsafe struct Osmesa
|
||||
{
|
||||
|
||||
private void* handle;
|
||||
|
||||
private IntPtr CreateContextAttribs;
|
||||
|
||||
private IntPtr CreateContextExt;
|
||||
@@ -622,8 +634,6 @@ namespace StgSharp.Graphics
|
||||
private IntPtr GetColorBuffer;
|
||||
private IntPtr GetDepthBuffer;
|
||||
private IntPtr GetProcAddress;
|
||||
|
||||
private void* handle;
|
||||
private IntPtr MakeCurrent;
|
||||
|
||||
}
|
||||
@@ -631,17 +641,18 @@ namespace StgSharp.Graphics
|
||||
internal unsafe struct vk
|
||||
{
|
||||
|
||||
private void* handle;
|
||||
|
||||
private GLFWbool available;
|
||||
private GLFWbool EXT_metal_surface;
|
||||
private fixed ulong extensions[2];
|
||||
private IntPtr GetInstanceProcAddr;
|
||||
private void* handle;
|
||||
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()
|
||||
{
|
||||
@@ -664,12 +675,13 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWmapelement
|
||||
{
|
||||
|
||||
private sbyte axisOffset;
|
||||
private sbyte axisScale;
|
||||
private byte index;
|
||||
|
||||
private byte type;
|
||||
|
||||
private sbyte axisOffset;
|
||||
private sbyte axisScale;
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
@@ -694,20 +706,21 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWjoystick
|
||||
{
|
||||
|
||||
private GLFWbool allocated;
|
||||
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 byte* buttons;
|
||||
private GLFWbool connected;
|
||||
private fixed byte guid[33];
|
||||
private int hatCount;
|
||||
private byte* hats;
|
||||
|
||||
//GLFWmapping* mapping;
|
||||
private IntPtr mapping;
|
||||
private fixed byte name[128];
|
||||
private void* userPointer;
|
||||
|
||||
// This is defined in platform.h
|
||||
// not completed in transforming
|
||||
@@ -730,12 +743,12 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWplatform
|
||||
{
|
||||
|
||||
private int platformID;
|
||||
|
||||
// init
|
||||
//GLFWbool(*init)(void);
|
||||
private IntPtr init;
|
||||
|
||||
private int platformID;
|
||||
|
||||
//void (* terminate) (void);
|
||||
private IntPtr terminate;
|
||||
internal IntPtr createCursor;
|
||||
@@ -953,7 +966,9 @@ namespace StgSharp.Graphics
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct GLsync
|
||||
{
|
||||
|
||||
public IntPtr Handle;
|
||||
|
||||
}
|
||||
|
||||
#endregion glad struct
|
||||
|
||||
@@ -28,14 +28,6 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
/*
|
||||
* This file is created to link functions in OpenGL to version in C#
|
||||
* The name of delegates and organization to init all these delegates
|
||||
* are refferd from GLAD1 in agreement of MIT license generated from
|
||||
* https://glad.dav1d.de/
|
||||
*/
|
||||
|
||||
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -44,6 +36,13 @@ 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, uint width, uint height);
|
||||
@@ -52,12 +51,6 @@ namespace StgSharp.Graphics
|
||||
|
||||
#endregion
|
||||
|
||||
/// <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 glDEBUG
|
||||
|
||||
|
||||
@@ -4849,13 +4849,18 @@ namespace StgSharp.Graphics.OpenGL
|
||||
|
||||
public static class glAttachment
|
||||
{
|
||||
|
||||
public const uint Depth = GLconst.DEPTH_ATTACHMENT;
|
||||
public const uint DepthAndStencil = GLconst.DEPTH_STENCIL_ATTACHMENT;
|
||||
public const uint Stencil = GLconst.STENCIL_ATTACHMENT;
|
||||
|
||||
private static int colorRange =
|
||||
GlFunction.CurrentGL.GetMaskInteger((uint)GLconst.MAX_COLOR_ATTACHMENTS);
|
||||
OpenGLFunction.CurrentGL.GetMaskInteger((uint)GLconst.MAX_COLOR_ATTACHMENTS);
|
||||
|
||||
public static uint Color(int i)
|
||||
{
|
||||
#if DEBUG
|
||||
if (i>colorRange||i<0)
|
||||
if ((i > colorRange) || (i < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
@@ -4863,8 +4868,5 @@ namespace StgSharp.Graphics.OpenGL
|
||||
return (uint)(GLconst.COLOR_ATTACHMENT0 + i);
|
||||
}
|
||||
|
||||
public const uint Depth = GLconst.DEPTH_ATTACHMENT;
|
||||
public const uint Stencil = GLconst.STENCIL_ATTACHMENT;
|
||||
public const uint DepthAndStencil = GLconst.DEPTH_STENCIL_ATTACHMENT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
/// <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 unsafe class ElementBuffer : BufferObjectBase
|
||||
{
|
||||
|
||||
internal ElementBuffer(int n, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
_bufferHandle = glFunc.GenBuffers(n);
|
||||
}
|
||||
|
||||
public override sealed void Bind(int index)
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
public void SetValue<T>(int index, T[] bufferArray, BufferUsage usage)
|
||||
where T : struct, IConvertible
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferData(BufferType.ElementArrayBuffer, bufferArray, usage);
|
||||
}
|
||||
|
||||
public void SetValue<T>(int index, ReadOnlySpan<T> bufferSpan, BufferUsage usage)
|
||||
where T : struct, IConvertible
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferData(BufferType.ElementArrayBuffer, bufferSpan, usage);
|
||||
}
|
||||
|
||||
protected override sealed void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
glFunc.DeleteBuffers(_bufferHandle);
|
||||
_bufferHandle.Release();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
#pragma warning disable CA1008
|
||||
#pragma warning disable CA1028
|
||||
public enum FrameBufferTarget:uint
|
||||
#pragma warning restore CA1028
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
Read = GLconst.READ_FRAMEBUFFER,
|
||||
All = GLconst.FRAMEBUFFER,
|
||||
Draw = GLconst.DRAW_FRAMEBUFFER,
|
||||
}
|
||||
|
||||
public class FrameBuffer : BufferObjectBase
|
||||
{
|
||||
internal unsafe FrameBuffer(int count, glRenderStream contextBinding)
|
||||
{
|
||||
binding = contextBinding;
|
||||
_bufferHandle = new glHandleSet(count);
|
||||
((GLcontext*)binding.ContextHandle)->glGenFramebuffers((uint)count,_bufferHandle.handle);
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public unsafe override void Bind(int index)
|
||||
{
|
||||
glFunc.BindFrameBuffer(FrameBufferTarget.All,_bufferHandle[index]);
|
||||
}
|
||||
|
||||
public static void BindNull()
|
||||
{
|
||||
glFunc.BindFrameBuffer(FrameBufferTarget.All,glHandle.Zero);
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public unsafe void Bind(FrameBufferTarget target, int index)
|
||||
{
|
||||
((GLcontext*)binding.ContextHandle)->glBindFramebuffer((uint)target, _bufferHandle[index].Value);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
|
||||
|
||||
|
||||
public class RenderBuffer : BufferObjectBase
|
||||
{
|
||||
public RenderBuffer(int count, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
_bufferHandle = glFunc.GenRenderBuffer(count);
|
||||
}
|
||||
|
||||
public override void Bind(int index)
|
||||
{
|
||||
glFunc.BindRenderBuffer(this[index]);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Store(RenderBufferInternalFormat format, (int width,int height) size)
|
||||
{
|
||||
if (size.width > binding.Width || size.height>binding.Height)
|
||||
{
|
||||
StgSharp.LogWarning("FrameBuffer is larger than current canvas binding");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="texture.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public unsafe class TextureGL
|
||||
{
|
||||
|
||||
internal static bool[] unitActivated = new bool[16];
|
||||
private IntPtr binding;
|
||||
internal glHandleSet _textureHandle;
|
||||
internal Image[] sourceList;
|
||||
|
||||
public glHandle this[int index]
|
||||
{
|
||||
get => _textureHandle[index];
|
||||
}
|
||||
|
||||
internal TextureGL(int n, glRenderStream binding)
|
||||
{
|
||||
sourceList = new Image[n];
|
||||
this.binding = binding.ContextHandle;
|
||||
_textureHandle = glFunc.GenTextures(n);
|
||||
}
|
||||
|
||||
public static void Activate(TextureUnit unit)
|
||||
{
|
||||
glFunc.ActiveTexture((uint)unit);
|
||||
}
|
||||
|
||||
public void Bind2D(int index)
|
||||
{
|
||||
glFunc.BindTexture(GLconst.TEXTURE_2D, _textureHandle[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
{
|
||||
sourceList[index] = i;
|
||||
glArrayHandle handle = sourceList[index].GetArrayHandle();
|
||||
glFunc.TextureImage2d(
|
||||
Texture2DTarget.Texture2D, 0, (uint)i.Channel,
|
||||
(uint)sourceList[index].Width, (uint)sourceList[index].Height,
|
||||
(uint)i.Channel, ImageChannelLayout.Byte,
|
||||
pixelArrayHandle: handle
|
||||
);
|
||||
handle.Release();
|
||||
}
|
||||
|
||||
|
||||
#region texture setting
|
||||
|
||||
public void Set2dFilterProperty(
|
||||
Filter onMinify, Filter onMagnify)
|
||||
{
|
||||
glFunc.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MIN_FILTER, (int)onMinify);
|
||||
glFunc.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MAG_FILTER, (int)onMagnify);
|
||||
}
|
||||
|
||||
public void Set2dWrapProperty(
|
||||
Wrap onHorizontial, Wrap onVertical)
|
||||
{
|
||||
glFunc.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_S, (int)onHorizontial);
|
||||
glFunc.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_T, (int)onVertical);
|
||||
}
|
||||
|
||||
#endregion texture setting
|
||||
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum Filter
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
Nearest = GLconst.NEAREST,
|
||||
Linear = GLconst.LINEAR,
|
||||
NearestLinearMipmap = GLconst.NEAREST_MIPMAP_LINEAR,
|
||||
LinearLinearMipmap = GLconst.LINEAR_MIPMAP_LINEAR,
|
||||
NearestNearestMipmap = GLconst.NEAREST_MIPMAP_NEAREST,
|
||||
LinearNearestMipmap = GLconst.LINEAR_MIPMAP_NEAREST,
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum TextureUnit
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
Unit0 = GLconst.TEXTURE0,
|
||||
Unit1 = GLconst.TEXTURE1,
|
||||
Unit2 = GLconst.TEXTURE2,
|
||||
Unit3 = GLconst.TEXTURE3,
|
||||
Unit4 = GLconst.TEXTURE4,
|
||||
Unit5 = GLconst.TEXTURE5,
|
||||
Unit6 = GLconst.TEXTURE6,
|
||||
Unit7 = GLconst.TEXTURE7,
|
||||
Unit8 = GLconst.TEXTURE8,
|
||||
Unit9 = GLconst.TEXTURE9,
|
||||
Unit10 = GLconst.TEXTURE10,
|
||||
Unit11 = GLconst.TEXTURE11,
|
||||
Unit12 = GLconst.TEXTURE12,
|
||||
Unit13 = GLconst.TEXTURE13,
|
||||
Unit14 = GLconst.TEXTURE14,
|
||||
Unit15 = GLconst.TEXTURE15,
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum Wrap
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
Repeat = GLconst.REPEAT,
|
||||
MirroredRepeat = GLconst.MIRRORED_REPEAT,
|
||||
ClampToEdge = GLconst.CLAMP_TO_EDGE,
|
||||
ClampToBorder = GLconst.CLAMP_TO_BORDER,
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.GL
|
||||
{
|
||||
public unsafe class VertexArray : BufferObjectBase
|
||||
{
|
||||
|
||||
internal VertexArray(int n, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
_bufferHandle = glFunc.GenVertexArrays(n);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override sealed void Bind(int index)
|
||||
{
|
||||
glFunc.BindVertexArray(_bufferHandle[index]);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindNull()
|
||||
{
|
||||
glFunc.BindVertexArray(glHandle.Zero);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void SetVertexAttribute(uint index, int vertexLength, TypeCode dataType, bool isNomalized, uint stride, int pointer)
|
||||
{
|
||||
glFunc.SetVertexAttribute(
|
||||
index, vertexLength, dataType,
|
||||
isNomalized,
|
||||
stride, pointer);
|
||||
}
|
||||
|
||||
protected override sealed void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
glFunc.DeleteVertexArrays(_bufferHandle);
|
||||
_bufferHandle.Release();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.Graphics.GL;
|
||||
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.GL
|
||||
{
|
||||
public unsafe class VertexBuffer : BufferObjectBase
|
||||
{
|
||||
|
||||
internal VertexBuffer(int n, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
_bufferHandle = glFunc.GenBuffers(n);
|
||||
}
|
||||
|
||||
public override sealed void Bind(int index)
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
/// <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
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.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
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.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
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.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
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.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
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferVectorData(BufferType.ArrayBuffer, vectorArray, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Unbind()
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, glHandle.Zero);
|
||||
}
|
||||
|
||||
protected override sealed void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
glFunc.DeleteBuffers(_bufferHandle);
|
||||
_bufferHandle.Release();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,362 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="GLhandle.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.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// A handle to an OpenGL object,
|
||||
/// must be indexed from a <see cref="glHandleSet"/>.
|
||||
/// Direct call will cause <see langword="InvalidOperationException"/>
|
||||
/// </summary>
|
||||
public unsafe class glHandle: IDisposable
|
||||
{
|
||||
private static uint* zeroHandle = (uint*)Marshal.AllocHGlobal(Marshal.SizeOf<uint>());
|
||||
|
||||
internal uint* source;
|
||||
internal uint* valuePtr;
|
||||
|
||||
private glHandle(IntPtr handle)
|
||||
{
|
||||
this.valuePtr = (uint*)handle;
|
||||
source = (uint*)0;
|
||||
}
|
||||
|
||||
private glHandle(uint value)
|
||||
{
|
||||
source = (uint*)0;
|
||||
valuePtr = (uint*)Marshal.AllocHGlobal(sizeof(uint));
|
||||
*valuePtr = value;
|
||||
}
|
||||
|
||||
internal glHandle(uint* val, glHandleSet set)
|
||||
{
|
||||
source = set!=null ? set!.handle:(uint*)0;
|
||||
valuePtr = val;
|
||||
}
|
||||
|
||||
[Obsolete("Cannot init instance of this type", true)]
|
||||
public glHandle()
|
||||
{
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get=> (IntPtr)valuePtr;
|
||||
}
|
||||
|
||||
public bool IsIsolated
|
||||
{
|
||||
get => source == (uint*)0;
|
||||
}
|
||||
|
||||
public uint Value
|
||||
{
|
||||
get => *valuePtr;
|
||||
set => *valuePtr = value;
|
||||
}
|
||||
|
||||
public static glHandle ZeroHandle => FromPtr(IntPtr.Zero);
|
||||
|
||||
public static glHandle Zero => Alloc(0);
|
||||
|
||||
public static glHandle Alloc(uint value)
|
||||
{
|
||||
return new glHandle(value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static glHandle FromPtr(IntPtr p)
|
||||
{
|
||||
return new glHandle(p);
|
||||
}
|
||||
|
||||
~glHandle()
|
||||
{
|
||||
if (valuePtr != zeroHandle && IsIsolated)
|
||||
{
|
||||
Marshal.FreeHGlobal((IntPtr)valuePtr);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (IsIsolated)
|
||||
{
|
||||
GCHandle.FromIntPtr((IntPtr)valuePtr).Free();
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// ~glHandle()
|
||||
// {
|
||||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe class glSHandle
|
||||
{
|
||||
private static int* zeroHandle = (int*)Marshal.AllocHGlobal(Marshal.SizeOf<int>());
|
||||
|
||||
internal int* source;
|
||||
internal int* valuePtr;
|
||||
|
||||
private glSHandle(IntPtr handle)
|
||||
{
|
||||
this.valuePtr = (int*)handle;
|
||||
source = (int*)0;
|
||||
}
|
||||
|
||||
private glSHandle(int value)
|
||||
{
|
||||
source = (int*)0;
|
||||
valuePtr = (int*)Marshal.AllocHGlobal(sizeof(int));
|
||||
*valuePtr = value;
|
||||
}
|
||||
|
||||
internal glSHandle(int* val, glHandleSet set)
|
||||
{
|
||||
source = set != null ? (int*)set!.handle : (int*)0;
|
||||
valuePtr = val;
|
||||
}
|
||||
|
||||
|
||||
[Obsolete("Cannot init instance of this type", true)]
|
||||
public glSHandle()
|
||||
{
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get => (IntPtr)valuePtr;
|
||||
}
|
||||
|
||||
public bool IsIsolated
|
||||
{
|
||||
get => source == (uint*)0;
|
||||
}
|
||||
|
||||
public int Value
|
||||
{
|
||||
get => *valuePtr;
|
||||
set => *valuePtr = value;
|
||||
}
|
||||
|
||||
public static glSHandle Zero => Alloc(0);
|
||||
|
||||
public static glSHandle Alloc(int value)
|
||||
{
|
||||
return new glSHandle(value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static glSHandle FromPtr(IntPtr p)
|
||||
{
|
||||
return new glSHandle(p);
|
||||
}
|
||||
|
||||
~glSHandle()
|
||||
{
|
||||
if (valuePtr != zeroHandle && IsIsolated)
|
||||
{
|
||||
Marshal.FreeHGlobal((IntPtr)valuePtr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public unsafe class glArrayHandle
|
||||
{
|
||||
internal readonly Array a;
|
||||
internal GCHandle handle;
|
||||
private bool disposedValue;
|
||||
|
||||
internal glArrayHandle(Array array)
|
||||
{
|
||||
this.a = array;
|
||||
handle = GCHandle.Alloc(array, GCHandleType.Pinned);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public IntPtr AddressOfArray()
|
||||
{
|
||||
if (handle != default)
|
||||
{
|
||||
return handle.AddrOfPinnedObject();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static glArrayHandle Alloc<T>(T[] array) where T : struct
|
||||
{
|
||||
return new glArrayHandle(array);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static glArrayHandle CopyAlloc<T>(T[] array) where T : struct
|
||||
{
|
||||
Array copy = new T[array.Length];
|
||||
array.CopyTo(copy, 0);
|
||||
return new glArrayHandle(copy);
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
handle.Free();
|
||||
handle = default;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A handle to an OpenGL object.
|
||||
/// </summary>
|
||||
public unsafe class glHandleSet
|
||||
{
|
||||
|
||||
private readonly uint[] _value;
|
||||
internal uint* handle;
|
||||
internal int length;
|
||||
|
||||
public glHandleSet(int count)
|
||||
{
|
||||
_value = new uint[count];
|
||||
length = count;
|
||||
handle = (uint*)GCHandle.Alloc(_value, GCHandleType.Pinned).AddrOfPinnedObject();
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get => (IntPtr)handle;
|
||||
}
|
||||
|
||||
public glHandle this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index > length)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
return new glHandle(handle + index, this);
|
||||
}
|
||||
}
|
||||
|
||||
public glSHandle this[uint index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index > length)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
return new glSHandle(((int*)handle) + index, this);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Copy(in glHandleSet source, glHandleSet target)
|
||||
{
|
||||
if ((source == null) || (target == null))
|
||||
{
|
||||
throw new NullReferenceException();
|
||||
}
|
||||
if (source.length != target.length)
|
||||
{
|
||||
throw new Exception($"Lengths of {nameof(source)} and {nameof(target)} are not equal.");
|
||||
}
|
||||
for (int i = 0; i < source.length; i++)
|
||||
{
|
||||
target._value[i] = source._value[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void Pin()
|
||||
{
|
||||
if (_value == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
handle = (uint*)GCHandle.Alloc(_value, GCHandleType.Pinned).AddrOfPinnedObject();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Release all resource in this handle.
|
||||
/// This will release all resource in this <see cref="glHandle"/>.
|
||||
/// This <see langword="glHandle"/> will be not usable.
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
if (_value == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
GCHandle.FromIntPtr((IntPtr)handle).Free();
|
||||
handle = (uint*)IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetValue(int index, uint value)
|
||||
{
|
||||
_value[index] = value;
|
||||
}
|
||||
|
||||
~glHandleSet()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,621 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="GLpack.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal static unsafe partial class InternalIO
|
||||
{
|
||||
|
||||
[DllImport(SSC_libName, EntryPoint = "glCheckShaderStat",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
#pragma warning disable CA5392
|
||||
internal static extern int glCheckShaderStatus(ref GLcontext context, uint shaderHandle, int key, ref IntPtr logPtr);
|
||||
#pragma warning restore CA5392
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
internal static unsafe partial class glFunc
|
||||
{
|
||||
private static GLcontext* context;
|
||||
|
||||
public static IntPtr CurrentContextHandle
|
||||
{
|
||||
get { return (IntPtr)context; }
|
||||
set { context = (GLcontext*)value; }
|
||||
}
|
||||
|
||||
private static ref GLcontext Context
|
||||
{
|
||||
get
|
||||
{
|
||||
#if DEBUG
|
||||
if ((IntPtr)context==IntPtr.Zero)
|
||||
{
|
||||
throw new NullReferenceException();
|
||||
}
|
||||
#endif
|
||||
return ref (*context);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ActiveTexture(uint type)
|
||||
{
|
||||
Context.glActiveTexture(type);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void AttachShader(glHandle program, glHandle shader)
|
||||
{
|
||||
Context.glAttachShader(program.Value, shader.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindBuffer(BufferType bufferType, glHandle handle)
|
||||
{
|
||||
Context.glBindBuffer((uint)bufferType, handle.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void GetTextureImage<T>(Texture2DTarget target, int level, ImageChannel channel, ImageChannelLayout channelLayout, ref T[] dataStream)where T: struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
|
||||
{
|
||||
#pragma warning disable CS8500
|
||||
fixed (T* tptr = dataStream)
|
||||
{
|
||||
Context.glGetTexImage((uint)target, level, (uint)channel, (uint)channelLayout, tptr);
|
||||
}
|
||||
#pragma warning restore CS8500
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bind a frame buffer to a frame buffer target
|
||||
/// Same function as <see href="https://docs.gl/gl3/glBindFramebuffer">glBindFramebuffer</see>.
|
||||
/// </summary>
|
||||
/// <param name="target"> The frame buffer target of the binding operation.</param>
|
||||
/// <param name="handle"> The handle of the frame buffer object to bind.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindFrameBuffer(FrameBufferTarget target, glHandle handle)
|
||||
{
|
||||
Context.glBindFramebuffer((uint)target, handle.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindRenderBuffer(glHandle handle)
|
||||
{
|
||||
Context.glBindRenderbuffer(GLconst.RENDERBUFFER, handle.Value);
|
||||
}
|
||||
|
||||
|
||||
public static void WaitAccomplishment()
|
||||
{
|
||||
Context.glFinish();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindTexture(uint type, glHandle texture)
|
||||
{
|
||||
Context.glBindTexture(type, texture.Value);
|
||||
}
|
||||
|
||||
public static unsafe int GetMaskInteger(uint statusCode)
|
||||
{
|
||||
int ret = 0;
|
||||
Context.glGetIntegerv(statusCode,&ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindVertexArray(glHandle handle)
|
||||
{
|
||||
Context.glBindVertexArray(handle.Value);
|
||||
}
|
||||
|
||||
public static void RereadImage(
|
||||
this Image i, (int X, int Y) beginPosition, FrameBufferChannel format, ImageChannelLayout dataType)
|
||||
{
|
||||
glArrayHandle handle = i.GetArrayHandle();
|
||||
Context.glReadPixels(
|
||||
beginPosition.X, beginPosition.Y, i.Width, i.Height, (uint)format, (uint)dataType, (byte*)handle.AddressOfArray()
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void FrameBufferTexture2d(FrameBufferTarget target, uint attachment, Texture2DTarget texTarget,glHandle textureHandle ,int level)
|
||||
{
|
||||
Context.glFramebufferTexture2D(
|
||||
(uint)target, attachment, (uint)texTarget,textureHandle.Value, level
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ReadPixels(
|
||||
(int X, int Y) beginPosition, (int width, int height) size, FrameBufferChannel format, ImageChannelLayout dataType, ref byte[] stream
|
||||
)
|
||||
{
|
||||
fixed (byte* bptr = stream)
|
||||
{
|
||||
Context.glReadPixels(
|
||||
beginPosition.X, beginPosition.Y,
|
||||
size.width, size.height, (uint)format, (uint)dataType, bptr);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Clear(MaskBufferBit mask)
|
||||
{
|
||||
Context.glClear((uint)mask);
|
||||
}
|
||||
|
||||
public static void CombineFrameBufferRenderBuffer(glHandle fboHandle, glHandle rboHandle)
|
||||
{
|
||||
Context.glFramebufferRenderbuffer(GLconst.FRAMEBUFFER,fboHandle.Value,GLconst.RENDERBUFFER, rboHandle.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void ClearColor(float R, float G, float B, float A)
|
||||
{
|
||||
Context.glClearColor(R, G, B, A);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void ClearGraphicError()
|
||||
{
|
||||
while (Context.glGetError() != 0) { }
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void CompileShader(glHandle shaderhandle)
|
||||
{
|
||||
Context.glCompileShader(shaderhandle.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe glHandle CreateGraphicProgram()
|
||||
{
|
||||
return glHandle.Alloc(Context.glCreateProgram());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static glHandle CreateProgram()
|
||||
{
|
||||
return glHandle.Alloc(Context.glCreateProgram());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe glHandleSet CreateProgram(int count)
|
||||
{
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
h.SetValue(i, Context.glCreateProgram());
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static glHandleSet CreateShaderSet(int count, ShaderType type)
|
||||
{
|
||||
glHandleSet ret = new glHandleSet(count);
|
||||
uint t = (uint)type;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
uint id = Context.glCreateShader(t);
|
||||
if (id == 0)
|
||||
{
|
||||
uint error = Context.glGetError();
|
||||
InternalIO.InternalWriteLog($"Failed in creating shader: {error}", LogType.Error);
|
||||
throw new Exception();
|
||||
}
|
||||
ret.SetValue(i, id);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void DeleteBuffer(glHandle handle)
|
||||
{
|
||||
Context.glDeleteBuffers(1, (uint*)handle.Handle);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void DeleteBuffers(glHandleSet handle)
|
||||
{
|
||||
Context.glDeleteBuffers(handle.length, (uint*)handle.Handle);
|
||||
handle.Release();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void DeleteVertexArrays(glHandleSet arrays)
|
||||
{
|
||||
Context.glDeleteVertexArrays(arrays.length, (uint*)arrays.Handle);
|
||||
arrays.Release();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void DrawElements(GeometryType mode, uint count, TypeCode type, IntPtr ptr)
|
||||
{
|
||||
uint a;
|
||||
switch (type)
|
||||
{
|
||||
case TypeCode.UInt32:
|
||||
a = GLconst.UNSIGNED_INT;
|
||||
break;
|
||||
|
||||
case TypeCode.UInt16:
|
||||
a = GLconst.UNSIGNED_SHORT;
|
||||
break;
|
||||
|
||||
case TypeCode.Byte:
|
||||
a = GLconst.UNSIGNED_BYTE;
|
||||
break;
|
||||
|
||||
default:
|
||||
InternalIO.InternalWriteLog(
|
||||
$"{$"Parameter error in parameter {nameof(type)} method DrawElements. "}{$"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are supported."}",
|
||||
LogType.Error);
|
||||
return;
|
||||
}
|
||||
Context.glDrawElements((uint)mode, count, a, (void*)ptr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void DrawElementsInstanced(
|
||||
GeometryType mode, uint count, TypeCode type, IntPtr ptr, uint amount
|
||||
)
|
||||
{
|
||||
uint a;
|
||||
switch (type)
|
||||
{
|
||||
case TypeCode.UInt32:
|
||||
a = GLconst.UNSIGNED_INT;
|
||||
break;
|
||||
|
||||
case TypeCode.UInt16:
|
||||
a = GLconst.UNSIGNED_SHORT;
|
||||
break;
|
||||
|
||||
case TypeCode.Byte:
|
||||
a = GLconst.UNSIGNED_BYTE;
|
||||
break;
|
||||
|
||||
default:
|
||||
InternalIO.InternalWriteLog(
|
||||
$"{$"Parameter error in parameter {nameof(type)} method DrawElements. "}{$"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are supported."}",
|
||||
LogType.Error);
|
||||
return;
|
||||
}
|
||||
Context.glDrawElementsInstanced((uint)mode, count, a, (void*)ptr, amount);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Enable(GLOperation operation)
|
||||
{
|
||||
Context.glEnable((uint)operation);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe glHandleSet GenBuffers(int count)
|
||||
{
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
Context.glGenBuffers(count, (uint*)h.Handle);
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe glHandleSet GenRenderBuffer(int count)
|
||||
{
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
Context.glGenRenderbuffers(count, (uint*)h.Handle);
|
||||
return h;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe glHandleSet GenTextures(int count)
|
||||
{
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
Context.glGenTextures(count, (uint*)h.Handle);
|
||||
return h;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetRenderBufferStorage(RenderBufferInternalFormat internalFormat ,(int width, int height) size)
|
||||
{
|
||||
Context.glRenderbufferStorage(
|
||||
GLconst.RENDERBUFFER, (uint)internalFormat,size.width,size.height
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public static unsafe glHandleSet GenVertexArrays(int count)
|
||||
{
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
Context.glGenVertexArrays(count, (uint*)h.Handle);
|
||||
return h;
|
||||
}
|
||||
|
||||
public static string GetShaderStatus(Shader s, int index, int key)
|
||||
{
|
||||
IntPtr sptr = IntPtr.Zero;
|
||||
if (InternalIO.glCheckShaderStatus(ref Context, s.handle[index].Value, key, ref sptr) == 0)
|
||||
{
|
||||
return Marshal.PtrToStringAnsi(sptr);
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe glSHandle GetUniformLocation(glHandle program, string name)
|
||||
{
|
||||
byte[] code = Encoding.UTF8.GetBytes(name);
|
||||
fixed (byte* ptr = code)
|
||||
{
|
||||
int ret = Context.glGetUniformLocation(program.Value, ptr);
|
||||
#if DEBUG
|
||||
if (ret == (int)(GLconst.INVALID_OPERATION) ||
|
||||
ret == (int)(GLconst.INVALID_VALUE))
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
if (ret == -1 )
|
||||
{
|
||||
throw new UniformEmptyReferenceException(nameof(program), name);
|
||||
}
|
||||
#endif
|
||||
return glSHandle.Alloc(ret);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void LoadShaderSource(glHandle shaderHandle, byte[] codeStream)
|
||||
{
|
||||
fixed (byte* streamPtr = codeStream)
|
||||
{
|
||||
Context.glShaderSource(shaderHandle.Value, 1, &streamPtr, (void*)0);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
|
||||
where T : struct
|
||||
{
|
||||
int size = Marshal.SizeOf<T>();
|
||||
#pragma warning disable CS8500
|
||||
T* p = &bufferData;
|
||||
#pragma warning restore CS8500
|
||||
Context.glBufferData(
|
||||
(uint)bufferType,
|
||||
(IntPtr)size,
|
||||
(IntPtr)p,
|
||||
(uint)usage);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
|
||||
if (bufferArray == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#pragma warning disable CS8500
|
||||
fixed (void* bufferPtr = bufferArray)
|
||||
#pragma warning restore CS8500
|
||||
{
|
||||
Context.glBufferData(
|
||||
(uint)bufferType,
|
||||
(IntPtr)size,
|
||||
(IntPtr)bufferPtr,
|
||||
(uint)usage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferData<T>(BufferType bufferType, ReadOnlySpan<T> bufferArray, BufferUsage usage)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
|
||||
if (bufferArray == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#pragma warning disable CS8500
|
||||
fixed (void* bufferPtr = bufferArray)
|
||||
#pragma warning restore CS8500
|
||||
{
|
||||
Context.glBufferData(
|
||||
(uint)bufferType,
|
||||
(IntPtr)size,
|
||||
(IntPtr)bufferPtr,
|
||||
(uint)usage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferData<T>(BufferType bufferType, Span<T> bufferArray, BufferUsage usage)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
|
||||
if (bufferArray == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#pragma warning disable CS8500
|
||||
fixed (void* bufferPtr = &bufferArray.GetPinnableReference())
|
||||
#pragma warning restore CS8500
|
||||
{
|
||||
Context.glBufferData(
|
||||
(uint)bufferType,
|
||||
(IntPtr)size,
|
||||
(IntPtr)bufferPtr,
|
||||
(uint)usage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferVectorData<T>(BufferType bufferType, ReadOnlySpan<T> bufferArray, BufferUsage usage)
|
||||
where T : struct, IVector
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
|
||||
if (bufferArray == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#pragma warning disable CS8500
|
||||
fixed (void* bufferPtr = &bufferArray.GetPinnableReference())
|
||||
#pragma warning restore CS8500
|
||||
{
|
||||
Context.glBufferData(
|
||||
(uint)bufferType,
|
||||
(IntPtr)size,
|
||||
(IntPtr)bufferPtr,
|
||||
(uint)usage);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferVectorData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
|
||||
where T : struct, IVector
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
|
||||
if (bufferArray == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#pragma warning disable CS8500
|
||||
fixed (void* bufferPtr = bufferArray)
|
||||
#pragma warning restore CS8500
|
||||
{
|
||||
Context.glBufferData(
|
||||
(uint)bufferType,
|
||||
(IntPtr)size,
|
||||
(IntPtr)bufferPtr,
|
||||
(uint)usage);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void SetVertexAttribute(uint index, int size, TypeCode t, bool normalized, uint stride, int pointer)
|
||||
{
|
||||
uint type = InternalIO.GLtype[t];
|
||||
Context.glVertexAttribPointer(index, size, type, normalized ? 1 : 0, stride, (void*)pointer);
|
||||
Context.glEnableVertexAttribArray(index);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void TextureImage2d(Texture2DTarget target, int level, uint internalformat, uint width, uint height,
|
||||
uint format, ImageChannelLayout type, glHandle pixels)
|
||||
{
|
||||
Context.glTexImage2D(
|
||||
(uint)target, level, internalformat, width, height, 0, format, (uint)type, pixels.valuePtr
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void TextureImage2d(Texture2DTarget target, int level, uint internalformat, uint width, uint height,
|
||||
uint format, ImageChannelLayout type, glArrayHandle pixelArrayHandle)
|
||||
{
|
||||
Context.glTexImage2D(
|
||||
(uint)target, level, internalformat, width, height, 0, format, (uint)type, (void*)pixelArrayHandle.handle.AddrOfPinnedObject()
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void TextureParameter(int target, uint pname, int param)
|
||||
{
|
||||
Context.glTexParameteri((uint)target, pname, param);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void UseProgram(glHandle program)
|
||||
{
|
||||
Context.glUseProgram(program.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void VertexAttributeDivisor(uint layoutIndex, uint divisor)
|
||||
{
|
||||
Context.glVertexAttribDivisor(layoutIndex, divisor);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Viewport(int x, int y, uint width, uint height)
|
||||
{
|
||||
Context.glViewport(x, y, width, height);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="GLresourceGenrator.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.Graphics.GL
|
||||
{
|
||||
public partial class glRenderStream
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Create a set of <see cref="ElementBuffer"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">Amount of EBO to be created.</param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected ElementBuffer CreateElementBuffer(int count)
|
||||
{
|
||||
return new ElementBuffer(count, this);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected RenderBuffer CreateRenderBuffer(int count)
|
||||
{
|
||||
return new RenderBuffer(count, this);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected FrameBuffer CreateFrameBuffer(int count)
|
||||
{
|
||||
return new FrameBuffer(count, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a sets of <see cref="TextureGL"/>
|
||||
/// </summary>
|
||||
/// <param name="count">Amount of textures to be created.</param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected TextureGL CreateTexture(int count)
|
||||
{
|
||||
return new TextureGL(count, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a set of <see cref="VertexArray"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">Amount of VAO to be created.</param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected VertexArray CreateVertexArray(int count)
|
||||
{
|
||||
return new VertexArray(count, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a set of <see cref="VertexBuffer"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">Amount of Object to be created.</param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected VertexBuffer CreateVertexBuffer(int count)
|
||||
{
|
||||
return new VertexBuffer(count, this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
using StgSharp.Graphics.GL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.ShaderEdit
|
||||
{
|
||||
public interface IglConvertable
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void SetAllUniforms();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void GainAllUniforms(ShaderProgram source, params string[] uniformName);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void DisplayGLtypeDefinition();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ShaderStruct GetConvertedGLtype();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,264 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Shader.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;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public abstract partial class glRenderStream : RenderStream
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override Shader CreateShaderSegment(ShaderType type, int count)
|
||||
{
|
||||
return new Shader( glFunc.CreateShaderSet(count, type), type);
|
||||
}
|
||||
/// <summary>
|
||||
/// Create an instance of <see cref="Shader"/> program
|
||||
/// </summary>
|
||||
/// <returns>New instance of <see cref="Shader"/> instance. </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override ShaderProgram CreateShaderProgram()
|
||||
{
|
||||
return new ShaderProgram(this);
|
||||
}
|
||||
}
|
||||
|
||||
public class Shader : ISSDSerializable
|
||||
{
|
||||
|
||||
private readonly IntPtr context;
|
||||
internal readonly glHandleSet handle;
|
||||
public readonly ShaderType type;
|
||||
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.Shader;
|
||||
|
||||
internal unsafe Shader(glHandleSet handle, ShaderType usage)
|
||||
{
|
||||
this.handle = handle;
|
||||
context = glFunc.CurrentContextHandle;
|
||||
type = usage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attach one shader code to a shader program.
|
||||
/// </summary>
|
||||
/// <param name="target">Shader program to attach</param>
|
||||
/// <param name="index">Index of shader code in current shader code set.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void AttachTo(int index, ShaderProgram target)
|
||||
{
|
||||
glFunc.AttachShader(target.handle, handle[index]);
|
||||
}
|
||||
|
||||
public static byte[] FromCodeFile(string fileRoute)
|
||||
{
|
||||
string str = File.ReadAllText(fileRoute);
|
||||
if (string.IsNullOrEmpty(str))
|
||||
{
|
||||
throw new InvalidOperationException($"Cannot load and GLSL code from {fileRoute}");
|
||||
}
|
||||
return Encoding.UTF8.GetBytes(str);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Compile(int index, byte[] codeStream)
|
||||
{
|
||||
if (codeStream == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(codeStream));
|
||||
}
|
||||
glFunc.LoadShaderSource(handle[index], codeStream);
|
||||
glFunc.CompileShader(handle[index]);
|
||||
CheckStatus(index,ShaderStatus.CompileStatus);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Compile(int index, string codeStream)
|
||||
{
|
||||
if (codeStream == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(codeStream));
|
||||
}
|
||||
glFunc.LoadShaderSource(handle[index],Encoding.ASCII.GetBytes( codeStream));
|
||||
glFunc.CompileShader(handle[index]);
|
||||
CheckStatus(index, ShaderStatus.CompileStatus);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"This is a {type} shader, its shader handles are {handle.ToString()}.";
|
||||
}
|
||||
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
public void CheckStatus(int index, ShaderStatus status)
|
||||
{
|
||||
string log = glFunc.GetShaderStatus(this,index, (int)status);
|
||||
if (!string.IsNullOrEmpty(log))
|
||||
{
|
||||
throw new Exception($"Shader Error \t{status}\n" + log);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] GetBytes(out int length)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void FromBytes(byte[] stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public enum ShaderStatus : int
|
||||
{
|
||||
CompileStatus = GLconst.COMPILE_STATUS,
|
||||
}
|
||||
|
||||
public class ShaderProgram
|
||||
{
|
||||
private readonly IntPtr binding;
|
||||
internal readonly glHandle handle;
|
||||
|
||||
/// <summary>
|
||||
/// Init a program with no shader attached.
|
||||
/// </summary>
|
||||
internal unsafe ShaderProgram(glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
handle = glFunc.CreateProgram();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader,
|
||||
/// the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param name="name">ContextName of the Uniform in shader code</param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe Uniform<T> GetUniform<T>(string name) where T : struct
|
||||
{
|
||||
return new Uniform<T>(this, name, binding);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader,
|
||||
/// the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param name="name">ContextName of the Uniform in shader code</param>
|
||||
/// <returns></returns>
|
||||
public unsafe Uniform<T, U> GetUniform<T, U>(string name)
|
||||
where T : struct
|
||||
where U : struct
|
||||
{
|
||||
return new Uniform<T, U>(this, name, binding);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader,
|
||||
/// the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param name="name">ContextName of the Uniform in shader code</param>
|
||||
/// <returns></returns>
|
||||
public unsafe Uniform<T, U, V> GetUniform<T, U, V>(string name)
|
||||
where T : struct
|
||||
where U : struct
|
||||
where V : struct
|
||||
{
|
||||
return new Uniform<T, U, V>(this, name);
|
||||
}
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader,
|
||||
/// the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param name="name">ContextName of the Uniform in shader code</param>
|
||||
/// <returns></returns>
|
||||
public unsafe Uniform<T, U, V, W> GetUniform<T, U, V, W>(string name)
|
||||
where T : struct
|
||||
where U : struct
|
||||
where V : struct
|
||||
where W : struct
|
||||
{
|
||||
return new Uniform<T, U, V, W>(this, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Link the shader to current viewPortDisplay.
|
||||
/// </summary>
|
||||
public unsafe void Link()
|
||||
{
|
||||
if (InternalIO.InternalLinkShaderProgram((GLcontext*)this.binding, handle.Value) == 0)
|
||||
{
|
||||
IntPtr logPtr = InternalIO.InternalReadSSCLog();
|
||||
try
|
||||
{
|
||||
byte[] logByte = new byte[512];
|
||||
Marshal.Copy(logPtr, logByte, 0, 512);
|
||||
string log = Encoding.UTF8.GetString(logByte);
|
||||
log = log.Replace("\0", string.Empty);
|
||||
InternalIO.InternalWriteLog(log, LogType.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
InternalIO.InternalWriteLog(ex.Message, LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Let the current viewPortDisplay use this shader.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Use()
|
||||
{
|
||||
glFunc.UseProgram(handle);
|
||||
}
|
||||
|
||||
~ShaderProgram()
|
||||
{
|
||||
//handle.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,257 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Uniform.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public class Uniform
|
||||
{
|
||||
protected IntPtr binding;
|
||||
internal glSHandle id;
|
||||
|
||||
|
||||
public glSHandle Handle
|
||||
{
|
||||
get => id;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Uniform<T> : Uniform
|
||||
where T : struct
|
||||
{
|
||||
|
||||
internal unsafe Uniform(glSHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, IntPtr binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static Uniform<T> FromHandle(glSHandle handle)
|
||||
{
|
||||
return new Uniform<T>() { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U>: Uniform
|
||||
where T : struct
|
||||
where U : struct
|
||||
{
|
||||
|
||||
internal unsafe Uniform(glSHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, IntPtr binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static Uniform<T,U> FromHandle(glSHandle handle)
|
||||
{
|
||||
return new Uniform<T, U>() { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U, V>:Uniform
|
||||
where T : struct
|
||||
where U : struct
|
||||
where V : struct
|
||||
{
|
||||
|
||||
internal unsafe Uniform(glSHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name)
|
||||
{
|
||||
this.binding = glFunc.CurrentContextHandle;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
public unsafe Uniform(ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static Uniform<T,U,V> FromHandle(glSHandle handle)
|
||||
{
|
||||
return new Uniform<T, U, V>() { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U, V, W>:Uniform
|
||||
where T : struct
|
||||
where U : struct
|
||||
where V : struct
|
||||
where W : struct
|
||||
{
|
||||
|
||||
|
||||
internal unsafe Uniform(glSHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal unsafe Uniform(ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name)
|
||||
{
|
||||
this.binding = glFunc.CurrentContextHandle;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static Uniform<T, U, V, W> FromHandle(glSHandle handle)
|
||||
{
|
||||
return new Uniform<T, U, V, W>() { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal partial class glFunc
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static void SetUniformValue
|
||||
(Uniform<Matrix44> uniform, Matrix44 mat)
|
||||
{
|
||||
Matrix44 temp = mat;
|
||||
Context.glUniformMatrix4fv(uniform.id.Value, 1, false, (float*)&temp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static void SetUniformValue(Uniform<float, float, float, float> uniform, vec4d vec)
|
||||
{
|
||||
vec4d temp = vec;
|
||||
Context.glUniform1fv(uniform.id.Value , 4, &temp);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static void SetUniformValue(Uniform<vec4d> uniform, vec4d vec)
|
||||
{
|
||||
vec4d temp = vec;
|
||||
Context.glUniform1fv(uniform.id.Value , 4, &temp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetUniformValue(Uniform<float> uniform, float v0)
|
||||
{
|
||||
Context.glUniform1f(uniform.id.Value , v0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetUniformValue(Uniform<int> uniform, int i0)
|
||||
{
|
||||
Context.glUniform1i(uniform.id.Value , i0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetUniformValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
{
|
||||
Context.glUniform2f(uniform.id.Value , v0, v1);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetUniformValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
||||
{
|
||||
Context.glUniform3f(uniform.id.Value , v0, v1, v2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetUniformValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
{
|
||||
Context.glUniform4f(uniform.id.Value , v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,689 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glApiManagerConst.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.GL
|
||||
{
|
||||
public static partial class glManager
|
||||
{
|
||||
#region coreVersion
|
||||
|
||||
private static bool core10 = false;
|
||||
private static bool core11 = false;
|
||||
private static bool core12 = false;
|
||||
private static bool core13 = false;
|
||||
private static bool core14 = false;
|
||||
private static bool core15 = false;
|
||||
private static bool core20 = false;
|
||||
private static bool core21 = false;
|
||||
private static bool core30 = false;
|
||||
private static bool core31 = false;
|
||||
private static bool core32 = false;
|
||||
private static bool core33 = false;
|
||||
private static bool core40 = false;
|
||||
private static bool core41 = false;
|
||||
private static bool core42 = false;
|
||||
private static bool core43 = false;
|
||||
private static bool core44 = false;
|
||||
private static bool core45 = false;
|
||||
private static bool core46 = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region extension
|
||||
|
||||
private static bool _3DFX_tbuffer;
|
||||
private static bool _3DFX_texture_compression_FXT1;
|
||||
private static bool _4DFX_multisample;
|
||||
private static bool AMD_blend_minmax_factor;
|
||||
private static bool AMD_conservative_depth;
|
||||
private static bool AMD_debug_output;
|
||||
private static bool AMD_depth_clamp_separate;
|
||||
private static bool AMD_draw_buffers_blend;
|
||||
private static bool AMD_framebuffer_multisample_advanced;
|
||||
private static bool AMD_framebuffer_sample_positions;
|
||||
private static bool AMD_gcn_shader;
|
||||
private static bool AMD_gpu_shader_half_float;
|
||||
private static bool AMD_gpu_shader_int16;
|
||||
private static bool AMD_gpu_shader_int64;
|
||||
private static bool AMD_interleaved_elements;
|
||||
private static bool AMD_multi_draw_indirect;
|
||||
private static bool AMD_name_gen_delete;
|
||||
private static bool AMD_occlusion_query_event;
|
||||
private static bool AMD_performance_monitor;
|
||||
private static bool AMD_pinned_memory;
|
||||
private static bool AMD_query_buffer_object;
|
||||
private static bool AMD_sample_positions;
|
||||
private static bool AMD_seamless_cubemap_per_texture;
|
||||
private static bool AMD_shader_atomic_counter_ops;
|
||||
private static bool AMD_shader_ballot;
|
||||
private static bool AMD_shader_explicit_vertex_parameter;
|
||||
private static bool AMD_shader_gpu_shader_half_float_fetch;
|
||||
private static bool AMD_shader_image_load_store_lod;
|
||||
private static bool AMD_shader_stencil_export;
|
||||
private static bool AMD_shader_trinary_minmax;
|
||||
private static bool AMD_sparse_texture;
|
||||
private static bool AMD_stencil_operation_extended;
|
||||
private static bool AMD_texture_gather_bias_lod;
|
||||
private static bool AMD_texture_texture4;
|
||||
private static bool AMD_transform_feedback3_lines_triangles;
|
||||
private static bool AMD_transform_feedback4;
|
||||
private static bool AMD_vertex_shader_layer;
|
||||
private static bool AMD_vertex_shader_tessellator;
|
||||
private static bool AMD_vertex_shader_viewport_index;
|
||||
private static bool APPLE_aux_depth_stencil;
|
||||
private static bool APPLE_client_storage;
|
||||
private static bool APPLE_element_array;
|
||||
private static bool APPLE_fence;
|
||||
private static bool APPLE_float_pixels;
|
||||
private static bool APPLE_flush_buffer_range;
|
||||
private static bool APPLE_object_purgeable;
|
||||
private static bool APPLE_rgb_422;
|
||||
private static bool APPLE_row_bytes;
|
||||
private static bool APPLE_specular_vector;
|
||||
private static bool APPLE_texture_range;
|
||||
private static bool APPLE_transform_hint;
|
||||
private static bool APPLE_vertex_array_object;
|
||||
private static bool APPLE_vertex_array_range;
|
||||
private static bool APPLE_vertex_program_evaluators;
|
||||
private static bool APPLE_ycbcr_422;
|
||||
private static bool ARB_arrays_of_arrays;
|
||||
private static bool ARB_base_instance;
|
||||
private static bool ARB_bindless_texture;
|
||||
private static bool ARB_blend_func_extended;
|
||||
private static bool ARB_buffer_storage;
|
||||
private static bool ARB_cl_event;
|
||||
private static bool ARB_clear_buffer_object;
|
||||
private static bool ARB_clear_texture;
|
||||
private static bool ARB_clip_control;
|
||||
private static bool ARB_color_buffer_float;
|
||||
private static bool ARB_compatibility;
|
||||
private static bool ARB_compressed_texture_pixel_storage;
|
||||
private static bool ARB_compute_shader;
|
||||
private static bool ARB_compute_variable_group_size;
|
||||
private static bool ARB_conditional_render_inverted;
|
||||
private static bool ARB_conservative_depth;
|
||||
private static bool ARB_copy_buffer;
|
||||
private static bool ARB_copy_image;
|
||||
private static bool ARB_cull_distance;
|
||||
private static bool ARB_debug_output;
|
||||
private static bool ARB_depth_buffer_float;
|
||||
private static bool ARB_depth_clamp;
|
||||
private static bool ARB_depth_texture;
|
||||
private static bool ARB_derivative_control;
|
||||
private static bool ARB_direct_state_access;
|
||||
private static bool ARB_draw_buffers;
|
||||
private static bool ARB_draw_buffers_blend;
|
||||
private static bool ARB_draw_elements_base_vertex;
|
||||
private static bool ARB_draw_indirect;
|
||||
private static bool ARB_draw_instanced;
|
||||
private static bool ARB_enhanced_layouts;
|
||||
private static bool ARB_ES2_compatibility;
|
||||
private static bool ARB_ES3_1_compatibility;
|
||||
private static bool ARB_ES3_2_compatibility;
|
||||
private static bool ARB_ES3_compatibility;
|
||||
private static bool ARB_explicit_attrib_location;
|
||||
private static bool ARB_explicit_uniform_location;
|
||||
private static bool ARB_fragment_coord_conventions;
|
||||
private static bool ARB_fragment_layer_viewport;
|
||||
private static bool ARB_fragment_program;
|
||||
private static bool ARB_fragment_program_shadow;
|
||||
private static bool ARB_fragment_shader;
|
||||
private static bool ARB_fragment_shader_interlock;
|
||||
private static bool ARB_framebuffer_no_attachments;
|
||||
private static bool ARB_framebuffer_object;
|
||||
private static bool ARB_framebuffer_sRGB;
|
||||
private static bool ARB_geometry_shader4;
|
||||
private static bool ARB_get_program_binary;
|
||||
private static bool ARB_get_texture_sub_image;
|
||||
private static bool ARB_gl_spirv;
|
||||
private static bool ARB_gpu_shader_fp64;
|
||||
private static bool ARB_gpu_shader_int64;
|
||||
private static bool ARB_gpu_shader5;
|
||||
private static bool ARB_half_float_pixel;
|
||||
private static bool ARB_half_float_vertex;
|
||||
private static bool ARB_imaging;
|
||||
private static bool ARB_indirect_parameters;
|
||||
private static bool ARB_instanced_arrays;
|
||||
private static bool ARB_internalformat_query;
|
||||
private static bool ARB_internalformat_query2;
|
||||
private static bool ARB_invalidate_subdata;
|
||||
private static bool ARB_map_buffer_alignment;
|
||||
private static bool ARB_map_buffer_range;
|
||||
private static bool ARB_matrix_palette;
|
||||
private static bool ARB_multi_bind;
|
||||
private static bool ARB_multi_draw_indirect;
|
||||
private static bool ARB_multisample;
|
||||
private static bool ARB_multitexture;
|
||||
private static bool ARB_occlusion_query;
|
||||
private static bool ARB_occlusion_query2;
|
||||
private static bool ARB_parallel_shader_compile;
|
||||
private static bool ARB_pipeline_statistics_query;
|
||||
private static bool ARB_pixel_buffer_object;
|
||||
private static bool ARB_point_parameters;
|
||||
private static bool ARB_point_sprite;
|
||||
private static bool ARB_polygon_offset_clamp;
|
||||
private static bool ARB_post_depth_coverage;
|
||||
private static bool ARB_program_interface_query;
|
||||
private static bool ARB_provoking_vertex;
|
||||
private static bool ARB_query_buffer_object;
|
||||
private static bool ARB_robust_buffer_access_behavior;
|
||||
private static bool ARB_robustness;
|
||||
private static bool ARB_robustness_isolation;
|
||||
private static bool ARB_sample_locations;
|
||||
private static bool ARB_sample_shading;
|
||||
private static bool ARB_sampler_objects;
|
||||
private static bool ARB_seamless_cube_map;
|
||||
private static bool ARB_seamless_cubemap_per_texture;
|
||||
private static bool ARB_separate_shader_objects;
|
||||
private static bool ARB_shader_atomic_counter_ops;
|
||||
private static bool ARB_shader_atomic_counters;
|
||||
private static bool ARB_shader_ballot;
|
||||
private static bool ARB_shader_bit_encoding;
|
||||
private static bool ARB_shader_clock;
|
||||
private static bool ARB_shader_draw_parameters;
|
||||
private static bool ARB_shader_group_vote;
|
||||
private static bool ARB_shader_image_load_store;
|
||||
private static bool ARB_shader_image_size;
|
||||
private static bool ARB_shader_objects;
|
||||
private static bool ARB_shader_precision;
|
||||
private static bool ARB_shader_stencil_export;
|
||||
private static bool ARB_shader_storage_buffer_object;
|
||||
private static bool ARB_shader_subroutine;
|
||||
private static bool ARB_shader_texture_image_samples;
|
||||
private static bool ARB_shader_texture_lod;
|
||||
private static bool ARB_shader_viewport_layer_array;
|
||||
private static bool ARB_shading_language_100;
|
||||
private static bool ARB_shading_language_420pack;
|
||||
private static bool ARB_shading_language_include;
|
||||
private static bool ARB_shading_language_packing;
|
||||
private static bool ARB_shadow;
|
||||
private static bool ARB_shadow_ambient;
|
||||
private static bool ARB_sparse_buffer;
|
||||
private static bool ARB_sparse_texture;
|
||||
private static bool ARB_sparse_texture_clamp;
|
||||
private static bool ARB_sparse_texture2;
|
||||
private static bool ARB_spirv_extensions;
|
||||
private static bool ARB_stencil_texturing;
|
||||
private static bool ARB_sync;
|
||||
private static bool ARB_tessellation_shader;
|
||||
private static bool ARB_texture_barrier;
|
||||
private static bool ARB_texture_border_clamp;
|
||||
private static bool ARB_texture_buffer_object;
|
||||
private static bool ARB_texture_buffer_object_rgb32;
|
||||
private static bool ARB_texture_buffer_range;
|
||||
private static bool ARB_texture_compression;
|
||||
private static bool ARB_texture_compression_bptc;
|
||||
private static bool ARB_texture_compression_rgtc;
|
||||
private static bool ARB_texture_cube_map;
|
||||
private static bool ARB_texture_cube_map_array;
|
||||
private static bool ARB_texture_env_add;
|
||||
private static bool ARB_texture_env_combine;
|
||||
private static bool ARB_texture_env_crossbar;
|
||||
private static bool ARB_texture_env_dot3;
|
||||
private static bool ARB_texture_filter_anisotropic;
|
||||
private static bool ARB_texture_filter_minmax;
|
||||
private static bool ARB_texture_float;
|
||||
private static bool ARB_texture_gather;
|
||||
private static bool ARB_texture_mirror_clamp_to_edge;
|
||||
private static bool ARB_texture_mirrored_repeat;
|
||||
private static bool ARB_texture_multisample;
|
||||
private static bool ARB_texture_non_power_of_two;
|
||||
private static bool ARB_texture_query_levels;
|
||||
private static bool ARB_texture_query_lod;
|
||||
private static bool ARB_texture_rectangle;
|
||||
private static bool ARB_texture_rg;
|
||||
private static bool ARB_texture_rgb10_a2ui;
|
||||
private static bool ARB_texture_stencil8;
|
||||
private static bool ARB_texture_storage;
|
||||
private static bool ARB_texture_storage_multisample;
|
||||
private static bool ARB_texture_swizzle;
|
||||
private static bool ARB_texture_view;
|
||||
private static bool ARB_timer_query;
|
||||
private static bool ARB_transform_feedback_instanced;
|
||||
private static bool ARB_transform_feedback_overflow_query;
|
||||
private static bool ARB_transform_feedback2;
|
||||
private static bool ARB_transform_feedback3;
|
||||
private static bool ARB_transpose_matrix;
|
||||
private static bool ARB_uniform_buffer_object;
|
||||
private static bool ARB_vertex_array_bgra;
|
||||
private static bool ARB_vertex_array_object;
|
||||
private static bool ARB_vertex_attrib_64bit;
|
||||
private static bool ARB_vertex_attrib_binding;
|
||||
private static bool ARB_vertex_blend;
|
||||
private static bool ARB_vertex_buffer_object;
|
||||
private static bool ARB_vertex_program;
|
||||
private static bool ARB_vertex_shader;
|
||||
private static bool ARB_vertex_type_10f_11f_11f_rev;
|
||||
private static bool ARB_vertex_type_2_10_10_10_rev;
|
||||
private static bool ARB_viewport_array;
|
||||
private static bool ARB_window_pos;
|
||||
private static bool ATI_draw_buffers;
|
||||
private static bool ATI_element_array;
|
||||
private static bool ATI_envmap_bumpmap;
|
||||
private static bool ATI_fragment_shader;
|
||||
private static bool ATI_map_object_buffer;
|
||||
private static bool ATI_meminfo;
|
||||
private static bool ATI_pixel_format_float;
|
||||
private static bool ATI_pn_triangles;
|
||||
private static bool ATI_separate_stencil;
|
||||
private static bool ATI_text_fragment_shader;
|
||||
private static bool ATI_texture_env_combine3;
|
||||
private static bool ATI_texture_float;
|
||||
private static bool ATI_texture_mirror_once;
|
||||
private static bool ATI_vertex_array_object;
|
||||
private static bool ATI_vertex_attrib_array_object;
|
||||
private static bool ATI_vertex_streams;
|
||||
private static bool EXT_422_pixels;
|
||||
private static bool EXT_abgr;
|
||||
private static bool EXT_bgra;
|
||||
private static bool EXT_bindable_uniform;
|
||||
private static bool EXT_blend_color;
|
||||
private static bool EXT_blend_equation_separate;
|
||||
private static bool EXT_blend_func_separate;
|
||||
private static bool EXT_blend_logic_op;
|
||||
private static bool EXT_blend_minmax;
|
||||
private static bool EXT_blend_subtract;
|
||||
private static bool EXT_clip_volume_hint;
|
||||
private static bool EXT_cmyka;
|
||||
private static bool EXT_color_subtable;
|
||||
private static bool EXT_compiled_vertex_array;
|
||||
private static bool EXT_convolution;
|
||||
private static bool EXT_coordinate_frame;
|
||||
private static bool EXT_copy_texture;
|
||||
private static bool EXT_cull_vertex;
|
||||
private static bool EXT_debug_label;
|
||||
private static bool EXT_debug_marker;
|
||||
private static bool EXT_depth_bounds_test;
|
||||
private static bool EXT_direct_state_access;
|
||||
private static bool EXT_draw_buffers2;
|
||||
private static bool EXT_draw_instanced;
|
||||
private static bool EXT_draw_range_elements;
|
||||
private static bool EXT_EGL_image_storage;
|
||||
private static bool EXT_EGL_sync;
|
||||
private static bool EXT_external_buffer;
|
||||
private static bool EXT_fog_coord;
|
||||
private static bool EXT_framebuffer_blit;
|
||||
private static bool EXT_framebuffer_blit_layers;
|
||||
private static bool EXT_framebuffer_multisample;
|
||||
private static bool EXT_framebuffer_multisample_blit_scaled;
|
||||
private static bool EXT_framebuffer_object;
|
||||
private static bool EXT_framebuffer_sRGB;
|
||||
private static bool EXT_geometry_shader4;
|
||||
private static bool EXT_gpu_program_parameters;
|
||||
private static bool EXT_gpu_shader4;
|
||||
private static bool EXT_histogram;
|
||||
private static bool EXT_index_array_formats;
|
||||
private static bool EXT_index_func;
|
||||
private static bool EXT_index_material;
|
||||
private static bool EXT_index_texture;
|
||||
private static bool EXT_light_texture;
|
||||
private static bool EXT_memory_object;
|
||||
private static bool EXT_memory_object_fd;
|
||||
private static bool EXT_memory_object_win32;
|
||||
private static bool EXT_misc_attribute;
|
||||
private static bool EXT_multi_draw_arrays;
|
||||
private static bool EXT_multisample;
|
||||
private static bool EXT_multiview_tessellation_geometry_shader;
|
||||
private static bool EXT_multiview_texture_multisample;
|
||||
private static bool EXT_multiview_timer_query;
|
||||
private static bool EXT_packed_depth_stencil;
|
||||
private static bool EXT_packed_float;
|
||||
private static bool EXT_packed_pixels;
|
||||
private static bool EXT_paletted_texture;
|
||||
private static bool EXT_pixel_buffer_object;
|
||||
private static bool EXT_pixel_transform;
|
||||
private static bool EXT_pixel_transform_color_table;
|
||||
private static bool EXT_point_parameters;
|
||||
private static bool EXT_polygon_offset;
|
||||
private static bool EXT_polygon_offset_clamp;
|
||||
private static bool EXT_post_depth_coverage;
|
||||
private static bool EXT_provoking_vertex;
|
||||
private static bool EXT_raster_multisample;
|
||||
private static bool EXT_rescale_normal;
|
||||
private static bool EXT_secondary_color;
|
||||
private static bool EXT_semaphore;
|
||||
private static bool EXT_semaphore_fd;
|
||||
private static bool EXT_semaphore_win32;
|
||||
private static bool EXT_separate_shader_objects;
|
||||
private static bool EXT_separate_specular_color;
|
||||
private static bool EXT_shader_framebuffer_fetch;
|
||||
private static bool EXT_shader_framebuffer_fetch_non_coherent;
|
||||
private static bool EXT_shader_image_load_formatted;
|
||||
private static bool EXT_shader_image_load_store;
|
||||
private static bool EXT_shader_integer_mix;
|
||||
private static bool EXT_shader_samples_identical;
|
||||
private static bool EXT_shadow_funcs;
|
||||
private static bool EXT_shared_texture_palette;
|
||||
private static bool EXT_sparse_texture2;
|
||||
private static bool EXT_stencil_clear_tag;
|
||||
private static bool EXT_stencil_two_side;
|
||||
private static bool EXT_stencil_wrap;
|
||||
private static bool EXT_subtexture;
|
||||
private static bool EXT_texture;
|
||||
private static bool EXT_texture_array;
|
||||
private static bool EXT_texture_buffer_object;
|
||||
private static bool EXT_texture_compression_latc;
|
||||
private static bool EXT_texture_compression_rgtc;
|
||||
private static bool EXT_texture_compression_s3tc;
|
||||
private static bool EXT_texture_cube_map;
|
||||
private static bool EXT_texture_env_add;
|
||||
private static bool EXT_texture_env_combine;
|
||||
private static bool EXT_texture_env_dot3;
|
||||
private static bool EXT_texture_filter_anisotropic;
|
||||
private static bool EXT_texture_filter_minmax;
|
||||
private static bool EXT_texture_integer;
|
||||
private static bool EXT_texture_lod_bias;
|
||||
private static bool EXT_texture_mirror_clamp;
|
||||
private static bool EXT_texture_object;
|
||||
private static bool EXT_texture_perturb_normal;
|
||||
private static bool EXT_texture_shadow_lod;
|
||||
private static bool EXT_texture_shared_exponent;
|
||||
private static bool EXT_texture_snorm;
|
||||
private static bool EXT_texture_sRGB;
|
||||
private static bool EXT_texture_sRGB_decode;
|
||||
private static bool EXT_texture_sRGB_R8;
|
||||
private static bool EXT_texture_sRGB_RG8;
|
||||
private static bool EXT_texture_storage;
|
||||
private static bool EXT_texture_swizzle;
|
||||
private static bool EXT_texture3D;
|
||||
private static bool EXT_timer_query;
|
||||
private static bool EXT_transform_feedback;
|
||||
private static bool EXT_vertex_array;
|
||||
private static bool EXT_vertex_array_bgra;
|
||||
private static bool EXT_vertex_attrib_64bit;
|
||||
private static bool EXT_vertex_shader;
|
||||
private static bool EXT_vertex_weighting;
|
||||
private static bool EXT_win32_keyed_mutex;
|
||||
private static bool EXT_window_rectangles;
|
||||
private static bool EXT_x11_sync_object;
|
||||
private static bool GREMEDY_frame_terminator;
|
||||
private static bool GREMEDY_string_marker;
|
||||
private static bool HP_convolution_border_modes;
|
||||
private static bool HP_image_transform;
|
||||
private static bool HP_occlusion_test;
|
||||
private static bool HP_texture_lighting;
|
||||
private static bool IBM_cull_vertex;
|
||||
private static bool IBM_multimode_draw_arrays;
|
||||
private static bool IBM_rasterpos_clip;
|
||||
private static bool IBM_static_data;
|
||||
private static bool IBM_texture_mirrored_repeat;
|
||||
private static bool IBM_vertex_array_lists;
|
||||
private static bool INGR_blend_func_separate;
|
||||
private static bool INGR_color_clamp;
|
||||
private static bool INGR_interlace_read;
|
||||
private static bool INTEL_blackhole_render;
|
||||
private static bool INTEL_conservative_rasterization;
|
||||
private static bool INTEL_fragment_shader_ordering;
|
||||
private static bool INTEL_framebuffer_CMAA;
|
||||
private static bool INTEL_map_texture;
|
||||
private static bool INTEL_parallel_arrays;
|
||||
private static bool INTEL_performance_query;
|
||||
private static bool KHR_blend_equation_advanced;
|
||||
private static bool KHR_blend_equation_advanced_coherent;
|
||||
private static bool KHR_context_flush_control;
|
||||
private static bool KHR_debug;
|
||||
private static bool KHR_no_error;
|
||||
private static bool KHR_parallel_shader_compile;
|
||||
private static bool KHR_robust_buffer_access_behavior;
|
||||
private static bool KHR_robustness;
|
||||
private static bool KHR_shader_subgroup;
|
||||
private static bool KHR_texture_compression_astc_hdr;
|
||||
private static bool KHR_texture_compression_astc_ldr;
|
||||
private static bool KHR_texture_compression_astc_sliced_3d;
|
||||
private static bool MESA_framebuffer_flip_x;
|
||||
private static bool MESA_framebuffer_flip_y;
|
||||
private static bool MESA_framebuffer_swap_xy;
|
||||
private static bool MESA_pack_invert;
|
||||
private static bool MESA_program_binary_formats;
|
||||
private static bool MESA_resize_buffers;
|
||||
private static bool MESA_shader_integer_functions;
|
||||
private static bool MESA_tile_raster_order;
|
||||
private static bool MESA_window_pos;
|
||||
private static bool MESA_ycbcr_texture;
|
||||
private static bool MESAX_texture_stack;
|
||||
private static bool NV_alpha_to_coverage_dither_control;
|
||||
private static bool NV_bindless_multi_draw_indirect;
|
||||
private static bool NV_bindless_multi_draw_indirect_count;
|
||||
private static bool NV_bindless_texture;
|
||||
private static bool NV_blend_equation_advanced;
|
||||
private static bool NV_blend_equation_advanced_coherent;
|
||||
private static bool NV_blend_minmax_factor;
|
||||
private static bool NV_blend_square;
|
||||
private static bool NV_clip_space_w_scaling;
|
||||
private static bool NV_command_list;
|
||||
private static bool NV_compute_program5;
|
||||
private static bool NV_compute_shader_derivatives;
|
||||
private static bool NV_conditional_render;
|
||||
private static bool NV_conservative_raster;
|
||||
private static bool NV_conservative_raster_dilate;
|
||||
private static bool NV_conservative_raster_pre_snap;
|
||||
private static bool NV_conservative_raster_pre_snap_triangles;
|
||||
private static bool NV_conservative_raster_underestimation;
|
||||
private static bool NV_copy_depth_to_color;
|
||||
private static bool NV_copy_image;
|
||||
private static bool NV_deep_texture3D;
|
||||
private static bool NV_depth_buffer_float;
|
||||
private static bool NV_depth_clamp;
|
||||
private static bool NV_draw_texture;
|
||||
private static bool NV_draw_vulkan_image;
|
||||
private static bool NV_evaluators;
|
||||
private static bool NV_explicit_multisample;
|
||||
private static bool NV_fence;
|
||||
private static bool NV_fill_rectangle;
|
||||
private static bool NV_float_buffer;
|
||||
private static bool NV_fog_distance;
|
||||
private static bool NV_fragment_coverage_to_color;
|
||||
private static bool NV_fragment_program;
|
||||
private static bool NV_fragment_program_option;
|
||||
private static bool NV_fragment_program2;
|
||||
private static bool NV_fragment_program4;
|
||||
private static bool NV_fragment_shader_barycentric;
|
||||
private static bool NV_fragment_shader_interlock;
|
||||
private static bool NV_framebuffer_mixed_samples;
|
||||
private static bool NV_framebuffer_multisample_coverage;
|
||||
private static bool NV_geometry_program4;
|
||||
private static bool NV_geometry_shader_passthrough;
|
||||
private static bool NV_geometry_shader4;
|
||||
private static bool NV_gpu_multicast;
|
||||
private static bool NV_gpu_program4;
|
||||
private static bool NV_gpu_program5;
|
||||
private static bool NV_gpu_program5_mem_extended;
|
||||
private static bool NV_gpu_shader5;
|
||||
private static bool NV_half_float;
|
||||
private static bool NV_internalformat_sample_query;
|
||||
private static bool NV_light_max_exponent;
|
||||
private static bool NV_memory_attachment;
|
||||
private static bool NV_memory_object_sparse;
|
||||
private static bool NV_mesh_shader;
|
||||
private static bool NV_multisample_coverage;
|
||||
private static bool NV_multisample_filter_hint;
|
||||
private static bool NV_occlusion_query;
|
||||
private static bool NV_packed_depth_stencil;
|
||||
private static bool NV_parameter_buffer_object;
|
||||
private static bool NV_parameter_buffer_object2;
|
||||
private static bool NV_path_rendering;
|
||||
private static bool NV_path_rendering_shared_edge;
|
||||
private static bool NV_pixel_data_range;
|
||||
private static bool NV_point_sprite;
|
||||
private static bool NV_present_video;
|
||||
private static bool NV_primitive_restart;
|
||||
private static bool NV_primitive_shading_rate;
|
||||
private static bool NV_query_resource;
|
||||
private static bool NV_query_resource_tag;
|
||||
private static bool NV_register_combiners;
|
||||
private static bool NV_register_combiners2;
|
||||
private static bool NV_representative_fragment_test;
|
||||
private static bool NV_robustness_video_memory_purge;
|
||||
private static bool NV_sample_locations;
|
||||
private static bool NV_sample_mask_override_coverage;
|
||||
private static bool NV_scissor_exclusive;
|
||||
private static bool NV_shader_atomic_counters;
|
||||
private static bool NV_shader_atomic_float;
|
||||
private static bool NV_shader_atomic_float64;
|
||||
private static bool NV_shader_atomic_fp16_vector;
|
||||
private static bool NV_shader_atomic_int64;
|
||||
private static bool NV_shader_buffer_load;
|
||||
private static bool NV_shader_buffer_store;
|
||||
private static bool NV_shader_storage_buffer_object;
|
||||
private static bool NV_shader_subgroup_partitioned;
|
||||
private static bool NV_shader_texture_footprint;
|
||||
private static bool NV_shader_thread_group;
|
||||
private static bool NV_shader_thread_shuffle;
|
||||
private static bool NV_shading_rate_image;
|
||||
private static bool NV_stereo_view_rendering;
|
||||
private static bool NV_tessellation_program5;
|
||||
private static bool NV_texgen_emboss;
|
||||
private static bool NV_texgen_reflection;
|
||||
private static bool NV_texture_barrier;
|
||||
private static bool NV_texture_compression_vtc;
|
||||
private static bool NV_texture_env_combine4;
|
||||
private static bool NV_texture_expand_normal;
|
||||
private static bool NV_texture_multisample;
|
||||
private static bool NV_texture_rectangle;
|
||||
private static bool NV_texture_rectangle_compressed;
|
||||
private static bool NV_texture_shader;
|
||||
private static bool NV_texture_shader2;
|
||||
private static bool NV_texture_shader3;
|
||||
private static bool NV_timeline_semaphore;
|
||||
private static bool NV_transform_feedback;
|
||||
private static bool NV_transform_feedback2;
|
||||
private static bool NV_uniform_buffer_std430_layout;
|
||||
private static bool NV_uniform_buffer_unified_memory;
|
||||
private static bool NV_vdpau_interop;
|
||||
private static bool NV_vdpau_interop2;
|
||||
private static bool NV_vertex_array_range;
|
||||
private static bool NV_vertex_array_range2;
|
||||
private static bool NV_vertex_attrib_integer_64bit;
|
||||
private static bool NV_vertex_buffer_unified_memory;
|
||||
private static bool NV_vertex_program;
|
||||
private static bool NV_vertex_program1_1;
|
||||
private static bool NV_vertex_program2;
|
||||
private static bool NV_vertex_program2_option;
|
||||
private static bool NV_vertex_program3;
|
||||
private static bool NV_vertex_program4;
|
||||
private static bool NV_video_capture;
|
||||
private static bool NV_viewport_array2;
|
||||
private static bool NV_viewport_swizzle;
|
||||
private static bool NVX_blend_equation_advanced_multi_draw_buffers;
|
||||
private static bool NVX_conditional_render;
|
||||
private static bool NVX_gpu_memory_info;
|
||||
private static bool NVX_gpu_multicast2;
|
||||
private static bool NVX_linked_gpu_multicast;
|
||||
private static bool NVX_progress_fence;
|
||||
private static bool OES_byte_coordinates;
|
||||
private static bool OES_compressed_paletted_texture;
|
||||
private static bool OES_fixed_point;
|
||||
private static bool OES_query_matrix;
|
||||
private static bool OES_read_format;
|
||||
private static bool OES_single_precision;
|
||||
private static bool OML_interlace;
|
||||
private static bool OML_resample;
|
||||
private static bool OML_subsample;
|
||||
private static bool OVR_multiview;
|
||||
private static bool OVR_multiview2;
|
||||
private static bool PGI_misc_hints;
|
||||
private static bool PGI_vertex_hints;
|
||||
private static bool REND_screen_coordinates;
|
||||
private static bool S3_s3tc;
|
||||
private static bool SGI_color_matrix;
|
||||
private static bool SGI_color_table;
|
||||
private static bool SGI_texture_color_table;
|
||||
private static bool SGIS_detail_texture;
|
||||
private static bool SGIS_fog_function;
|
||||
private static bool SGIS_generate_mipmap;
|
||||
private static bool SGIS_multisample;
|
||||
private static bool SGIS_pixel_texture;
|
||||
private static bool SGIS_point_line_texgen;
|
||||
private static bool SGIS_point_parameters;
|
||||
private static bool SGIS_sharpen_texture;
|
||||
private static bool SGIS_texture_border_clamp;
|
||||
private static bool SGIS_texture_color_mask;
|
||||
private static bool SGIS_texture_edge_clamp;
|
||||
private static bool SGIS_texture_filter4;
|
||||
private static bool SGIS_texture_lod;
|
||||
private static bool SGIS_texture_select;
|
||||
private static bool SGIS_texture4D;
|
||||
private static bool SGIX_async;
|
||||
private static bool SGIX_async_histogram;
|
||||
private static bool SGIX_async_pixel;
|
||||
private static bool SGIX_blend_alpha_minmax;
|
||||
private static bool SGIX_calligraphic_fragment;
|
||||
private static bool SGIX_clipmap;
|
||||
private static bool SGIX_convolution_accuracy;
|
||||
private static bool SGIX_depth_pass_instrument;
|
||||
private static bool SGIX_depth_texture;
|
||||
private static bool SGIX_flush_raster;
|
||||
private static bool SGIX_fog_offset;
|
||||
private static bool SGIX_fragment_lighting;
|
||||
private static bool SGIX_framezoom;
|
||||
private static bool SGIX_igloo_interface;
|
||||
private static bool SGIX_instruments;
|
||||
private static bool SGIX_interlace;
|
||||
private static bool SGIX_ir_instrument1;
|
||||
private static bool SGIX_list_priority;
|
||||
private static bool SGIX_pixel_texture;
|
||||
private static bool SGIX_pixel_tiles;
|
||||
private static bool SGIX_polynomial_ffd;
|
||||
private static bool SGIX_reference_plane;
|
||||
private static bool SGIX_resample;
|
||||
private static bool SGIX_scalebias_hint;
|
||||
private static bool SGIX_shadow;
|
||||
private static bool SGIX_shadow_ambient;
|
||||
private static bool SGIX_sprite;
|
||||
private static bool SGIX_subsample;
|
||||
private static bool SGIX_tag_sample_buffer;
|
||||
private static bool SGIX_texture_add_env;
|
||||
private static bool SGIX_texture_coordinate_clamp;
|
||||
private static bool SGIX_texture_lod_bias;
|
||||
private static bool SGIX_texture_multi_buffer;
|
||||
private static bool SGIX_texture_scale_bias;
|
||||
private static bool SGIX_vertex_preclip;
|
||||
private static bool SGIX_ycrcb;
|
||||
private static bool SGIX_ycrcb_subsample;
|
||||
private static bool SGIX_ycrcba;
|
||||
private static bool SUN_convolution_border_modes;
|
||||
private static bool SUN_global_alpha;
|
||||
private static bool SUN_mesh_array;
|
||||
private static bool SUN_slice_accum;
|
||||
private static bool SUN_triangle_list;
|
||||
private static bool SUN_vertex;
|
||||
private static bool SUNX_constant_data;
|
||||
private static bool WIN_phong_shading;
|
||||
private static bool WIN_specular_fog;
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glRenderStream.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
|
||||
public abstract partial class glRenderStream : RenderStream
|
||||
{
|
||||
|
||||
protected glRenderStream(ViewPort v, (int,int,int) cube) : base(v,cube)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
protected IntPtr glContextHandle
|
||||
{
|
||||
get { return ContextHandle; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Init an OpenGl viewPortDisplay if current form has not been binded to any viewPortDisplay. and set the viewPortDisplay binded to
|
||||
/// current form as current OpenGL viewPortDisplay.
|
||||
/// </summary>
|
||||
/// <exception cref="Exception">
|
||||
/// Something goes wrong and StgSharp fails in creating a new OpenGL viewPortDisplay.
|
||||
/// </exception>
|
||||
public unsafe void MakeAsCurrentContext()
|
||||
{
|
||||
if (ContextHandle == default)
|
||||
{
|
||||
ContextHandle = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GLcontext)));
|
||||
GLcontext* contextID = (GLcontext*)ContextHandle;
|
||||
contextID->glGetString = (delegate*<uint, IntPtr>)IntPtr.Zero;
|
||||
}
|
||||
if (glFunc.CurrentContextHandle != ContextHandle)
|
||||
{
|
||||
glFunc.CurrentContextHandle = ContextHandle;
|
||||
InternalIO.glfwMakeContextCurrent(CanvasHandle);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
|
||||
{
|
||||
InternalIO.glfwSetWindowSizeLimits(this.CanvasHandle, minWidth, minHeight, maxWidth, maxHeight);
|
||||
}
|
||||
|
||||
internal override sealed void InternalDraw(
|
||||
in Dictionary<string, BlueprintPipeline> input,
|
||||
in Dictionary<string, BlueprintPipeline> output)
|
||||
{
|
||||
MakeAsCurrentContext();
|
||||
Main(in input, in output);
|
||||
}
|
||||
|
||||
internal override sealed void InternalInit()
|
||||
{
|
||||
MakeAsCurrentContext();
|
||||
this.Port.LoadGLapi();
|
||||
Init();
|
||||
}
|
||||
|
||||
internal override sealed void InternalTerminate()
|
||||
{
|
||||
Deinit();
|
||||
}
|
||||
|
||||
protected override sealed Uniform<Matrix44> NativeCameraUniform(ShaderProgram source, string name)
|
||||
{
|
||||
NativeCamera.GainAllUniforms(source, name);
|
||||
return NativeCamera.convertedUniform;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected override sealed void NativeCameraViewRange(Radius fieldOfRange, vec2d offset, (float frontDepth, float backDepth) viewDepth)
|
||||
{
|
||||
NativeCamera.SetViewRange(fieldOfRange, this.Size, offset, viewDepth);
|
||||
}
|
||||
|
||||
protected override sealed void NativeCameraViewTarget(vec3d position, vec3d direction, vec3d up)
|
||||
{
|
||||
NativeCamera.SetViewDirection(position, direction, up);
|
||||
}
|
||||
|
||||
|
||||
#region Key Control
|
||||
|
||||
protected KeyStatus CheckKey(KeyboardKey key)
|
||||
{
|
||||
return InternalIO.glfwGetKey(this.CanvasHandle, (int)key);
|
||||
}
|
||||
|
||||
protected KeyStatus CheckKey(Mouse key)
|
||||
{
|
||||
return InternalIO.glfwGetKey(this.CanvasHandle, (int)key);
|
||||
}
|
||||
|
||||
protected KeyStatus CheckKey(Joystick key)
|
||||
{
|
||||
return InternalIO.glfwGetKey(this.CanvasHandle, (int)key);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,34 @@
|
||||
using System;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
|
||||
@@ -6,7 +36,9 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
public interface IGraphicAPIs
|
||||
{
|
||||
|
||||
public IntPtr GraphicApiPackageHandle { get; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,15 +46,9 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
public class Image : ISSDSerializable, IImageProvider
|
||||
{
|
||||
|
||||
internal byte[] data;
|
||||
internal ImageInfo info;
|
||||
|
||||
public PixelChannelLayout PixelLayout
|
||||
{
|
||||
get => info.pixelLayout;
|
||||
private set => info.pixelLayout = value;
|
||||
}
|
||||
private byte[] _data;
|
||||
private ImageInfo info;
|
||||
private int _pixelUpdateCount = 0;
|
||||
|
||||
internal unsafe Image()
|
||||
{
|
||||
@@ -64,15 +58,42 @@ namespace StgSharp.Graphics
|
||||
internal Image(ImageInfo information)
|
||||
{
|
||||
info = information;
|
||||
data = Array.Empty<byte>();
|
||||
_data = Array.Empty<byte>();
|
||||
//int length = info.width * info.height * info.channel;
|
||||
}
|
||||
|
||||
internal ref byte[] Data
|
||||
{
|
||||
get => ref _data;
|
||||
}
|
||||
|
||||
public (int width, int height) Size
|
||||
{
|
||||
get => (info.Width, info.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hash code of time pixels updated last time.
|
||||
/// </summary>
|
||||
public int PixelUpdateCount
|
||||
{
|
||||
get => _pixelUpdateCount;
|
||||
internal set => _pixelUpdateCount = value;
|
||||
}
|
||||
|
||||
public byte[] PixelBuffer
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((_data.Length == 0) || (_data == null))
|
||||
{
|
||||
GetBytes();
|
||||
return _data!;
|
||||
}
|
||||
return _data;
|
||||
}
|
||||
}
|
||||
|
||||
public ImageChannel Channel => info.Channel;
|
||||
public int ChannelCount => info.ChannelCount;
|
||||
public int Height
|
||||
@@ -89,6 +110,12 @@ namespace StgSharp.Graphics
|
||||
|
||||
public int PixelSize => GlHelper.GetPixelSize(info.pixelLayout, info.Channel);
|
||||
|
||||
public PixelChannelLayout PixelLayout
|
||||
{
|
||||
get => info.pixelLayout;
|
||||
private set => info.pixelLayout = value;
|
||||
}
|
||||
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
|
||||
|
||||
public void FromBytes(byte[] stream)
|
||||
@@ -106,21 +133,6 @@ namespace StgSharp.Graphics
|
||||
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 static Image FromMemory((int width, int height) size, ImageChannel channel, byte[] stream)
|
||||
{
|
||||
ImageInfo _info = new ImageInfo
|
||||
@@ -132,35 +144,38 @@ namespace StgSharp.Graphics
|
||||
};
|
||||
Image ret = new Image(_info);
|
||||
ret.PixelLayout = PixelChannelLayout.Byte;
|
||||
ret.data = stream;
|
||||
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)
|
||||
if (_data.Length == 0)
|
||||
{
|
||||
int size = Width * Height * GlHelper.GetPixelSize(PixelLayout, Channel);
|
||||
_data = new Span<byte>((byte*)info.StreamPtr, size).ToArray();
|
||||
fixed (ImageInfo* pptr = &info)
|
||||
{
|
||||
int size = Width * Height * GlHelper.GetPixelSize(PixelLayout, Channel);
|
||||
data = new Span<byte>((byte*)info.StreamPtr, size).ToArray();
|
||||
fixed (ImageInfo* pptr = &info)
|
||||
{
|
||||
InternalIO.InternalUnloadImage(pptr);
|
||||
}
|
||||
info.StreamPtr = IntPtr.Zero;
|
||||
InternalIO.InternalUnloadImage(pptr);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public byte[] PixelBuffer
|
||||
{
|
||||
get{
|
||||
if ((data.Length == 0) || (data == null))
|
||||
{
|
||||
GetBytes();
|
||||
return data!;
|
||||
}
|
||||
return data;
|
||||
info.StreamPtr = IntPtr.Zero;
|
||||
}
|
||||
return _data;
|
||||
}
|
||||
public Image ProvideImage() => this;
|
||||
|
||||
@@ -168,6 +183,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
@@ -183,10 +199,7 @@ namespace StgSharp.Graphics
|
||||
public ImageChannel Channel
|
||||
{
|
||||
get => channel;
|
||||
set
|
||||
{
|
||||
channel = value;
|
||||
}
|
||||
set { channel = value; }
|
||||
}
|
||||
|
||||
public int ChannelCount
|
||||
@@ -222,6 +235,14 @@ namespace StgSharp.Graphics
|
||||
return $"{channel}\t{width}\t{height}\t{(ulong)StreamPtr}";
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hash = 17;
|
||||
hash = hash * 17 + width;
|
||||
hash = hash * 17 + height;
|
||||
hash = hash * 17 + (int)channel;
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
public enum ImageChannel : uint
|
||||
@@ -276,5 +297,6 @@ namespace StgSharp.Graphics.OpenGL
|
||||
_ => throw new ArgumentException("Unknown layout type"),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using StgSharp.Collections;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed class AutoTextureGL
|
||||
{
|
||||
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 TextureProperty[] propertyCache;
|
||||
private TextureGL texturePackage;
|
||||
|
||||
private TextureProperty _textureProperty;
|
||||
|
||||
private OpenGLFunction GL
|
||||
{
|
||||
get => texturePackage.GL;
|
||||
}
|
||||
|
||||
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]glRenderStream 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;
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -45,10 +45,10 @@ namespace StgSharp.Graphics.OpenGL
|
||||
/// Each <see langword="uint"/> value indexed from instance of this class this
|
||||
/// is the only handle to one Element Buffer Object.
|
||||
/// </summary>
|
||||
public unsafe class ElementBuffer : GlBufferObjectBase
|
||||
public sealed unsafe class ElementBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal ElementBuffer(int n, glRenderStream binding):base(binding)
|
||||
internal ElementBuffer(int n, glRenderStream binding) : base(binding)
|
||||
{
|
||||
_bufferHandle = GL.GenBuffers(n);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -12,7 +42,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
#pragma warning disable CA1008
|
||||
#pragma warning disable CA1028
|
||||
public enum FrameBufferTarget:uint
|
||||
public enum FrameBufferTarget : uint
|
||||
#pragma warning restore CA1028
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
@@ -21,9 +51,10 @@ namespace StgSharp.Graphics.OpenGL
|
||||
Draw = GLconst.DRAW_FRAMEBUFFER,
|
||||
}
|
||||
|
||||
public class FrameBuffer : GlBufferObjectBase
|
||||
public sealed class FrameBuffer : GlBufferObjectBase
|
||||
{
|
||||
internal unsafe FrameBuffer(int count, glRenderStream binding):base(binding)
|
||||
|
||||
internal unsafe FrameBuffer(int count, glRenderStream binding) : base(binding)
|
||||
{
|
||||
_bufferHandle = GL.GenFrameBuffers(count);
|
||||
}
|
||||
@@ -34,15 +65,9 @@ namespace StgSharp.Graphics.OpenGL
|
||||
/// </summary>
|
||||
/// <param name="index">Index of object to be binded in handle set</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe override void Bind(int index)
|
||||
public override unsafe void Bind(int index)
|
||||
{
|
||||
GL.BindFrameBuffer(FrameBufferTarget.All,_bufferHandle[index]);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindNull()
|
||||
{
|
||||
GlFunction.CurrentGL.BindFrameBuffer(FrameBufferTarget.All,GlHandle.Zero);
|
||||
GL.BindFrameBuffer(FrameBufferTarget.All, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -57,9 +82,16 @@ namespace StgSharp.Graphics.OpenGL
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -8,6 +38,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public abstract class GlBufferObjectBase : BufferObjectBase
|
||||
{
|
||||
|
||||
private readonly glRenderStream _contextBinding;
|
||||
|
||||
protected GlBufferObjectBase(glRenderStream contextBinding)
|
||||
@@ -16,7 +47,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
_contextBinding = contextBinding;
|
||||
}
|
||||
|
||||
protected GlFunction GL => _contextBinding.GL;
|
||||
protected OpenGLFunction GL => _contextBinding.GL;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
@@ -11,9 +41,10 @@ namespace StgSharp.Graphics.OpenGL
|
||||
|
||||
|
||||
|
||||
public class RenderBuffer : GlBufferObjectBase
|
||||
public sealed class RenderBuffer : GlBufferObjectBase
|
||||
{
|
||||
public RenderBuffer(int count, glRenderStream binding):base(binding)
|
||||
|
||||
public RenderBuffer(int count, glRenderStream binding) : base(binding)
|
||||
{
|
||||
_bufferHandle = GL.GenRenderBuffer(count);
|
||||
}
|
||||
@@ -23,17 +54,18 @@ namespace StgSharp.Graphics.OpenGL
|
||||
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)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Store(RenderBufferInternalFormat format, (int width,int height) size)
|
||||
{
|
||||
if (size.width > binding.Width || size.height>binding.Height)
|
||||
{
|
||||
StgSharp.LogWarning("FrameBuffer is larger than current canvas binding");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="texture.cs"
|
||||
// file="TextureGL.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
@@ -28,104 +28,230 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data;
|
||||
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 unsafe class TextureGL
|
||||
public sealed unsafe class TextureGL
|
||||
{
|
||||
private GlFunction GL;
|
||||
internal static bool[] unitActivated = new bool[16];
|
||||
|
||||
private int currentEditingTextureIndex;
|
||||
|
||||
private OpenGLFunction _gl;
|
||||
internal GlHandle[] _textureHandle;
|
||||
internal Image[] sourceList;
|
||||
|
||||
public GlHandle this[int index]
|
||||
internal TextureGL( int count, glRenderStream binding )
|
||||
{
|
||||
get => _textureHandle[index];
|
||||
//sourceList = new Image[count];
|
||||
this._gl = binding.GL;
|
||||
_textureHandle = _gl.GenTextures( count );
|
||||
}
|
||||
|
||||
internal TextureGL(int n, glRenderStream binding)
|
||||
internal OpenGLFunction GL => _gl;
|
||||
|
||||
public GlHandle this[ int index ]
|
||||
{
|
||||
sourceList = new Image[n];
|
||||
this.GL = binding.GL;
|
||||
_textureHandle = GL.GenTextures(n);
|
||||
get => _textureHandle[ index ];
|
||||
}
|
||||
|
||||
public void ActivateAs(TextureUnit unit)
|
||||
public int Count
|
||||
{
|
||||
GL.ActiveTexture((uint)unit);
|
||||
get => _textureHandle.Length;
|
||||
}
|
||||
|
||||
public void Bind2D(int index)
|
||||
//internal Image[] sourceList;
|
||||
|
||||
public int IndexOfCurrentTexture
|
||||
{
|
||||
GL.BindTexture(GLconst.TEXTURE_2D, _textureHandle[index]);
|
||||
get => currentEditingTextureIndex;
|
||||
}
|
||||
|
||||
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.
|
||||
/// 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)
|
||||
public unsafe void LoadTexture( int index, Image i )
|
||||
{
|
||||
sourceList[index] = i;
|
||||
var handle = sourceList[index].PixelBuffer;
|
||||
GL.TextureImage2d(
|
||||
Texture2DTarget.Texture2D, 0, (uint)i.Channel,
|
||||
(uint)sourceList[index].Width, (uint)sourceList[index].Height,
|
||||
(uint)i.Channel, i.PixelLayout,
|
||||
pixels: handle
|
||||
);
|
||||
GL.GenerateMipmap(Texture2DTarget.Texture2D);
|
||||
byte[] handle = i.PixelBuffer;
|
||||
_gl.TextureImage2d(
|
||||
Texture2DTarget.Texture2D, 0, ( uint )i.Channel, ( uint )i.Width, ( uint )i.Height,
|
||||
( uint )i.Channel, i.PixelLayout, pixels: handle );
|
||||
_gl.GenerateMipmap( Texture2DTarget.Texture2D );
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region texture setting
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void Set2dFilterProperty(
|
||||
Filter onMinify, Filter onMagnify)
|
||||
int index,
|
||||
TextureFilter onMinify,
|
||||
TextureFilter onMagnify )
|
||||
{
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MIN_FILTER, (int)onMinify);
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MAG_FILTER, (int)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(
|
||||
Wrap onHorizontial, Wrap onVertical)
|
||||
int index,
|
||||
TextureWrap onHorizontial,
|
||||
TextureWrap onVertical )
|
||||
{
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_S, (int)onHorizontial);
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_T, (int)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
|
||||
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum Filter
|
||||
#pragma warning restore CA1008
|
||||
[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 int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(
|
||||
FilterOnMagnify, FilterOnMagnify, WrapOnHorizontial, WrapOnVertical );
|
||||
}
|
||||
|
||||
public override bool Equals([NotNullWhen(true)] object obj)
|
||||
{
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"FilterOnMagnify:{FilterOnMagnify}, " +
|
||||
$"FilterOnMagnify:{FilterOnMagnify}, " +
|
||||
$"WrapOnHorizontial:{WrapOnHorizontial}, " +
|
||||
$"WrapOnVertical:{WrapOnVertical}";
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
#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
|
||||
#pragma warning disable CA1008
|
||||
public enum TextureUnit
|
||||
#pragma warning restore CA1008
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
Unit0 = GLconst.TEXTURE0,
|
||||
Unit1 = GLconst.TEXTURE1,
|
||||
Unit2 = GLconst.TEXTURE2,
|
||||
@@ -142,15 +268,18 @@ namespace StgSharp.Graphics.OpenGL
|
||||
Unit13 = GLconst.TEXTURE13,
|
||||
Unit14 = GLconst.TEXTURE14,
|
||||
Unit15 = GLconst.TEXTURE15,
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum Wrap
|
||||
#pragma warning restore CA1008
|
||||
#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,
|
||||
|
||||
}
|
||||
}
|
||||
@@ -37,10 +37,10 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public unsafe class VertexArray : GlBufferObjectBase
|
||||
public sealed unsafe class VertexArray : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal VertexArray(int n, glRenderStream binding):base(binding)
|
||||
internal VertexArray(int n, glRenderStream binding) : base(binding)
|
||||
{
|
||||
_bufferHandle = GL.GenVertexArrays(n);
|
||||
}
|
||||
@@ -54,7 +54,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindNull()
|
||||
{
|
||||
GlFunction.CurrentGL.BindVertexArray(GlHandle.Zero);
|
||||
OpenGLFunction.CurrentGL.BindVertexArray(GlHandle.Zero);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
@@ -40,10 +40,10 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public unsafe class VertexBuffer : GlBufferObjectBase
|
||||
public sealed unsafe class VertexBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal VertexBuffer(int n, glRenderStream binding):base(binding)
|
||||
internal VertexBuffer(int n, glRenderStream binding) : base(binding)
|
||||
{
|
||||
_bufferHandle = GL.GenBuffers(n);
|
||||
}
|
||||
@@ -54,13 +54,22 @@ namespace StgSharp.Graphics.OpenGL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex buffer object
|
||||
///
|
||||
/// </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)
|
||||
/// <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]);
|
||||
@@ -68,12 +77,12 @@ namespace StgSharp.Graphics.OpenGL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex buffer object
|
||||
/// 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>
|
||||
/// <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
|
||||
@@ -87,12 +96,12 @@ namespace StgSharp.Graphics.OpenGL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex buffer object
|
||||
/// 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>
|
||||
/// <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
|
||||
@@ -106,12 +115,12 @@ namespace StgSharp.Graphics.OpenGL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex buffer object
|
||||
/// 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>
|
||||
/// <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]);
|
||||
@@ -119,27 +128,18 @@ namespace StgSharp.Graphics.OpenGL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex buffer object
|
||||
/// 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>
|
||||
/// <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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Unbind()
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, GlHandle.Zero);
|
||||
}
|
||||
|
||||
protected override sealed void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="GLresourceGenrator.cs"
|
||||
// file="glResourceGenrator.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
@@ -51,6 +51,12 @@ namespace StgSharp.Graphics.OpenGL
|
||||
return new ElementBuffer(count, this);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected FrameBuffer CreateFrameBuffer(int count)
|
||||
{
|
||||
return new FrameBuffer(count, this);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected RenderBuffer CreateRenderBuffer(int count)
|
||||
@@ -58,12 +64,6 @@ namespace StgSharp.Graphics.OpenGL
|
||||
return new RenderBuffer(count, this);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected FrameBuffer CreateFrameBuffer(int count)
|
||||
{
|
||||
return new FrameBuffer(count, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a sets of <see cref="TextureGL"/>
|
||||
/// </summary>
|
||||
@@ -75,6 +75,13 @@ namespace StgSharp.Graphics.OpenGL
|
||||
return new TextureGL(count, this);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected AutoTextureGL CreateAutoTexture(int count)
|
||||
{
|
||||
return new AutoTextureGL(count, this);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Create a set of <see cref="VertexArray"/>.
|
||||
/// </summary>
|
||||
@@ -97,6 +104,6 @@ namespace StgSharp.Graphics.OpenGL
|
||||
return new VertexBuffer(count, this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,34 @@
|
||||
using System;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glException.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.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
@@ -9,6 +39,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed class GlExecutionException : Exception
|
||||
{
|
||||
|
||||
public GlExecutionException()
|
||||
{
|
||||
}
|
||||
@@ -21,10 +52,6 @@ namespace StgSharp.Graphics.OpenGL
|
||||
|
||||
public sealed class GlArrayFormatException : Exception
|
||||
{
|
||||
public GlArrayFormatException(PixelChannelLayout layout, string arrayname):
|
||||
base($"{arrayname} cannot be used as layout of {layout}")
|
||||
{
|
||||
}
|
||||
|
||||
internal GlArrayFormatException(string message) : base(message)
|
||||
{
|
||||
@@ -37,22 +64,28 @@ namespace StgSharp.Graphics.OpenGL
|
||||
internal GlArrayFormatException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
public GlArrayFormatException(PixelChannelLayout layout, string arrayname) :
|
||||
base($"{arrayname} cannot be used as layout of {layout}")
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static partial class GlHelper
|
||||
{
|
||||
|
||||
public static bool CheckArrayFormat(this Array array, PixelChannelLayout layout)
|
||||
{
|
||||
return layout switch
|
||||
{
|
||||
PixelChannelLayout.Byte or PixelChannelLayout.UByte332 or PixelChannelLayout.UByte233Rev
|
||||
=> array is byte[] || array is sbyte[],
|
||||
=> (array is byte[]) || (array is sbyte[]),
|
||||
PixelChannelLayout.Short => array is short[],
|
||||
PixelChannelLayout.UShort => array is ushort[],
|
||||
PixelChannelLayout.Int => array is int[],
|
||||
PixelChannelLayout.Float => array is float[],
|
||||
PixelChannelLayout.UShort4444 => array is ushort[] || array is byte[],
|
||||
PixelChannelLayout.UByte => array is byte[] || array is sbyte[],
|
||||
PixelChannelLayout.UShort4444 => (array is ushort[]) || (array is byte[]),
|
||||
PixelChannelLayout.UByte => (array is byte[]) || (array is sbyte[]),
|
||||
PixelChannelLayout.UInt => array is uint[],
|
||||
PixelChannelLayout.UShort565 or
|
||||
PixelChannelLayout.UShort565Rev or
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="GLhandle.cs"
|
||||
// file="GlHandle.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
@@ -49,24 +49,25 @@ namespace StgSharp.Graphics.OpenGL
|
||||
[StructLayout(LayoutKind.Explicit, Size = 4)]
|
||||
public struct GlHandle
|
||||
{
|
||||
[FieldOffset(0)] public uint Value;
|
||||
|
||||
[FieldOffset(0)] public int SignedValue;
|
||||
[FieldOffset(0)] public uint Value;
|
||||
|
||||
public static GlHandle Zero
|
||||
{
|
||||
get => new GlHandle { Value = 0 };
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static GlHandle Alloc(uint value)
|
||||
{
|
||||
return new GlHandle() { Value = value };
|
||||
return new GlHandle { Value = value };
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static GlHandle SignedAlloc(int value)
|
||||
{
|
||||
return new GlHandle() { SignedValue = value };
|
||||
}
|
||||
|
||||
public static GlHandle Zero
|
||||
{
|
||||
get => new GlHandle() { Value = 0 };
|
||||
return new GlHandle { SignedValue = value };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public sealed class OpenGLAPICallingAttribute:Attribute
|
||||
{
|
||||
public OpenGLAPICallingAttribute()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="IglConvertable.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;
|
||||
@@ -10,26 +40,26 @@ namespace StgSharp.Graphics.ShaderEdit
|
||||
{
|
||||
public interface IglConvertable
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void SetAllUniforms();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void GainAllUniforms(ShaderProgram source, params string[] uniformName);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void DisplayGLtypeDefinition();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void GainAllUniforms(ShaderProgram source, params string[] uniformName);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ShaderStruct GetConvertedGLtype();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void SetAllUniforms();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,30 +44,31 @@ namespace StgSharp.Graphics.OpenGL
|
||||
public abstract partial class glRenderStream : RenderStream
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override Shader CreateShaderSegment(ShaderType type, int count)
|
||||
{
|
||||
return new Shader( GL.CreateShaderSet(count, type), type, this);
|
||||
}
|
||||
/// <summary>
|
||||
/// Create an instance of <see cref="Shader"/> program
|
||||
/// </summary>
|
||||
/// <returns>New instance of <see cref="Shader"/> instance. </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override ShaderProgram CreateShaderProgram()
|
||||
protected override sealed ShaderProgram CreateShaderProgram()
|
||||
{
|
||||
return new ShaderProgram(this);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected override sealed Shader CreateShaderSegment(ShaderType type, int count)
|
||||
{
|
||||
return new Shader(GL.CreateShaderSet(count, type), type, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class Shader : ISSDSerializable
|
||||
{
|
||||
private readonly GlFunction GL;
|
||||
|
||||
private readonly OpenGLFunction GL;
|
||||
internal readonly GlHandle[] handle;
|
||||
public readonly ShaderType type;
|
||||
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.Shader;
|
||||
|
||||
internal unsafe Shader(GlHandle[] handle, ShaderType usage, glRenderStream stream)
|
||||
{
|
||||
this.handle = handle;
|
||||
@@ -75,6 +76,8 @@ namespace StgSharp.Graphics.OpenGL
|
||||
type = usage;
|
||||
}
|
||||
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.Shader;
|
||||
|
||||
/// <summary>
|
||||
/// Attach one shader code to a shader program.
|
||||
/// </summary>
|
||||
@@ -86,14 +89,13 @@ namespace StgSharp.Graphics.OpenGL
|
||||
GL.AttachShader(target.handle, handle[index]);
|
||||
}
|
||||
|
||||
public static byte[] FromCodeFile(string fileRoute)
|
||||
public void CheckStatus(int index, ShaderStatus status)
|
||||
{
|
||||
string str = File.ReadAllText(fileRoute);
|
||||
if (string.IsNullOrEmpty(str))
|
||||
string log = GL.GetShaderStatus(this, index, (int)status);
|
||||
if (!string.IsNullOrEmpty(log))
|
||||
{
|
||||
throw new InvalidOperationException($"Cannot load and GLSL code from {fileRoute}");
|
||||
throw new Exception($"{$"Shader Error \t{status}\n"}{log}");
|
||||
}
|
||||
return Encoding.UTF8.GetBytes(str);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -105,7 +107,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
}
|
||||
GL.LoadShaderSource(handle[index], codeStream);
|
||||
GL.CompileShader(handle[index]);
|
||||
CheckStatus(index,ShaderStatus.CompileStatus);
|
||||
CheckStatus(index, ShaderStatus.CompileStatus);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -115,14 +117,24 @@ namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
throw new ArgumentNullException(nameof(codeStream));
|
||||
}
|
||||
GL.LoadShaderSource(handle[index],Encoding.ASCII.GetBytes( codeStream));
|
||||
GL.LoadShaderSource(handle[index], Encoding.ASCII.GetBytes(codeStream));
|
||||
GL.CompileShader(handle[index]);
|
||||
CheckStatus(index, ShaderStatus.CompileStatus);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
public void FromBytes(byte[] stream)
|
||||
{
|
||||
return $"This is a {type} shader, its shader handles are {handle.ToString()}.";
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static byte[] FromCodeFile(string fileRoute)
|
||||
{
|
||||
string str = File.ReadAllText(fileRoute);
|
||||
if (string.IsNullOrEmpty(str))
|
||||
{
|
||||
throw new InvalidOperationException($"Cannot load and GLSL code from {fileRoute}");
|
||||
}
|
||||
return Encoding.UTF8.GetBytes(str);
|
||||
}
|
||||
|
||||
public byte[] GetBytes()
|
||||
@@ -130,24 +142,16 @@ namespace StgSharp.Graphics.OpenGL
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
public void CheckStatus(int index, ShaderStatus status)
|
||||
{
|
||||
string log = GL.GetShaderStatus(this,index, (int)status);
|
||||
if (!string.IsNullOrEmpty(log))
|
||||
{
|
||||
throw new Exception($"Shader Error \t{status}\n" + log);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] GetBytes(out int length)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void FromBytes(byte[] stream)
|
||||
public override string ToString()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return $"This is a {type} shader, its shader handles are {handle.ToString()}.";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum ShaderStatus : int
|
||||
@@ -157,7 +161,8 @@ namespace StgSharp.Graphics.OpenGL
|
||||
|
||||
public class ShaderProgram
|
||||
{
|
||||
private readonly GlFunction GL;
|
||||
|
||||
private readonly OpenGLFunction GL;
|
||||
internal readonly GlHandle handle;
|
||||
|
||||
/// <summary>
|
||||
@@ -191,7 +196,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
where T : struct
|
||||
where U : struct
|
||||
{
|
||||
return new Uniform<T, U>(GL.GetUniformLocation(this.handle,name));
|
||||
return new Uniform<T, U>(GL.GetUniformLocation(this.handle, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -42,109 +42,112 @@ namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public class Uniform
|
||||
{
|
||||
|
||||
internal GlHandle id;
|
||||
|
||||
public GlHandle Handle
|
||||
{
|
||||
get => id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T> : Uniform
|
||||
where T : struct
|
||||
{
|
||||
|
||||
internal unsafe Uniform(GlHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal unsafe Uniform(GlHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T> FromHandle(GlHandle handle)
|
||||
{
|
||||
return new Uniform<T>() { id = handle };
|
||||
return new Uniform<T> { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U>: Uniform
|
||||
public sealed class Uniform<T, U> : Uniform
|
||||
where T : struct
|
||||
where U : struct
|
||||
{
|
||||
|
||||
internal unsafe Uniform(GlHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static Uniform<T,U> FromHandle(GlHandle handle)
|
||||
internal unsafe Uniform(GlHandle id)
|
||||
{
|
||||
return new Uniform<T, U>() { id = handle };
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T, U> FromHandle(GlHandle handle)
|
||||
{
|
||||
return new Uniform<T, U> { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U, V>:Uniform
|
||||
public sealed class Uniform<T, U, V> : Uniform
|
||||
where T : struct
|
||||
where U : struct
|
||||
where V : struct
|
||||
{
|
||||
|
||||
internal unsafe Uniform(GlHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static Uniform<T,U,V> FromHandle(GlHandle handle)
|
||||
internal unsafe Uniform(GlHandle id)
|
||||
{
|
||||
return new Uniform<T, U, V>() { id = handle };
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T, U, V> FromHandle(GlHandle handle)
|
||||
{
|
||||
return new Uniform<T, U, V> { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U, V, W>:Uniform
|
||||
public sealed class Uniform<T, U, V, W> : Uniform
|
||||
where T : struct
|
||||
where U : struct
|
||||
where V : struct
|
||||
where W : struct
|
||||
{
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
internal unsafe Uniform(GlHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static Uniform<T, U, V, W> FromHandle(GlHandle handle)
|
||||
{
|
||||
return new Uniform<T, U, V, W>() { id = handle };
|
||||
return new Uniform<T, U, V, W> { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public unsafe partial class GlFunction
|
||||
public unsafe partial class OpenGLFunction
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue
|
||||
(Uniform<Matrix44> uniform, Matrix44 mat)
|
||||
@@ -157,7 +160,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
public void SetUniformValue(Uniform<float, float, float, float> uniform, vec4d vec)
|
||||
{
|
||||
vec4d temp = vec;
|
||||
Context.glUniform1fv(uniform.id.SignedValue , 4, &temp);
|
||||
Context.glUniform1fv(uniform.id.SignedValue, 4, &temp);
|
||||
}
|
||||
|
||||
|
||||
@@ -165,37 +168,37 @@ namespace StgSharp.Graphics.OpenGL
|
||||
public void SetUniformValue(Uniform<vec4d> uniform, vec4d vec)
|
||||
{
|
||||
vec4d temp = vec;
|
||||
Context.glUniform1fv(uniform.id.SignedValue , 4, &temp);
|
||||
Context.glUniform1fv(uniform.id.SignedValue, 4, &temp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(Uniform<float> uniform, float v0)
|
||||
{
|
||||
Context.glUniform1f(uniform.id.SignedValue , v0);
|
||||
Context.glUniform1f(uniform.id.SignedValue, v0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(Uniform<int> uniform, int i0)
|
||||
{
|
||||
Context.glUniform1i(uniform.id.SignedValue , i0);
|
||||
Context.glUniform1i(uniform.id.SignedValue, i0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
{
|
||||
Context.glUniform2f(uniform.id.SignedValue , v0, v1);
|
||||
Context.glUniform2f(uniform.id.SignedValue, v0, v1);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
||||
{
|
||||
Context.glUniform3f(uniform.id.SignedValue , v0, v1, v2);
|
||||
Context.glUniform3f(uniform.id.SignedValue, v0, v1, v2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
{
|
||||
Context.glUniform4f(uniform.id.SignedValue , v0, v1, v2, v3);
|
||||
Context.glUniform4f(uniform.id.SignedValue, v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Get.cs"
|
||||
// file="glAPICalling.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
@@ -28,25 +28,19 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public partial class View
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public sealed class OpenGLAPICallingAttribute : Attribute
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Get the status of a certain key on the keyboard.
|
||||
/// </summary>
|
||||
/// <param name="form"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static KeyStatus GetKeyStatus(ViewModelBase form, KeyboardKey key)
|
||||
public OpenGLAPICallingAttribute()
|
||||
{
|
||||
return InternalIO.glfwGetKey(form.WindowID, (int)key);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -57,6 +57,25 @@ namespace StgSharp.Graphics.OpenGL
|
||||
|
||||
private static string glExtensionList;
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Get the function pointer of given OpenGL api name
|
||||
/// </summary>
|
||||
/// <param name="name">ContextName of the OpenGL api</param>
|
||||
/// <returns>The funtion pointer of the api in stream of <see cref="IntPtr"/></returns>
|
||||
public static IntPtr LoadGLfunc(string name)
|
||||
{
|
||||
IntPtr ret = InternalIO.glfwGetProcAddress(name);
|
||||
if (ret == default)
|
||||
{
|
||||
InternalIO.InternalAppendLog(
|
||||
$"Cannot load OpenGL api called {name}, this api may not exist or supported.");
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load all supported OpenGL APIs and bind them to given <see cref="ViewPort"/>.
|
||||
/// </summary>
|
||||
@@ -64,7 +83,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
public static unsafe void LoadOpenGLApiTo(IntPtr contextHandle)
|
||||
{
|
||||
OpenglContext* context = (OpenglContext*)contextHandle;
|
||||
delegate*<string,IntPtr> loader = &InternalIO.glfwGetProcAddress;
|
||||
delegate*<string, IntPtr> loader = &InternalIO.glfwGetProcAddress;
|
||||
if ((IntPtr)context->glGetString != IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
@@ -84,7 +103,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
InternalIO.InternalWriteLog("Failed to call glGetString", LogType.Error);
|
||||
}
|
||||
coreVersion = Marshal.PtrToStringAnsi(context->glGetString(glVersion))??string.Empty;
|
||||
coreVersion = Marshal.PtrToStringAnsi(context->glGetString(glVersion)) ?? string.Empty;
|
||||
|
||||
foreach (string branch in glBranch)
|
||||
{
|
||||
@@ -140,7 +159,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
}
|
||||
|
||||
int extensionCount;
|
||||
context->glGetIntegerv(GLconst.NUM_EXTENSIONS,&extensionCount);
|
||||
context->glGetIntegerv(GLconst.NUM_EXTENSIONS, &extensionCount);
|
||||
if (extensionCount == 0)
|
||||
{
|
||||
InternalIO.InternalWriteLog("No supported OpenGL extensions are found.", LogType.Info);
|
||||
@@ -151,12 +170,11 @@ namespace StgSharp.Graphics.OpenGL
|
||||
|
||||
for (uint i = 0; i < extensionCount; i++)
|
||||
{
|
||||
byte* strPtr = context->glGetStringi(GLconst.EXTENSIONS,i);
|
||||
byte* strPtr = context->glGetStringi(GLconst.EXTENSIONS, i);
|
||||
extensions.Add(Marshal.PtrToStringAnsi((IntPtr)strPtr));
|
||||
}
|
||||
|
||||
InternalIO.InternalWriteLog($"Find OpenGL extensions:" + Environment.NewLine +
|
||||
$"{string.Join(';', extensions)}",
|
||||
InternalIO.InternalWriteLog($"{$"Find OpenGL extensions:"}{Environment.NewLine}{($"{string.Join(';', extensions)}")}",
|
||||
LogType.Info);
|
||||
|
||||
#region checkGLextensions
|
||||
@@ -786,25 +804,6 @@ namespace StgSharp.Graphics.OpenGL
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Get the function pointer of given OpenGL api name
|
||||
/// </summary>
|
||||
/// <param name="name">ContextName of the OpenGL api</param>
|
||||
/// <returns>The funtion pointer of the api in stream of <see cref="IntPtr"/></returns>
|
||||
public static IntPtr LoadGLfunc(string name)
|
||||
{
|
||||
IntPtr ret = InternalIO.glfwGetProcAddress(name);
|
||||
if (ret == default)
|
||||
{
|
||||
InternalIO.InternalAppendLog(
|
||||
$"Cannot load OpenGL api called {name}, this api may not exist or supported.");
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
internal static void CheckCoreVersion(int majorVersion, int minorVersion)
|
||||
{
|
||||
if (majorVersion < 3)
|
||||
@@ -1017,7 +1016,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
}
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore10(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore10(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core10)
|
||||
{
|
||||
@@ -1081,7 +1080,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.0 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore11(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore11(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core11)
|
||||
{
|
||||
@@ -1111,7 +1110,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.1 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore12(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore12(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core12)
|
||||
{
|
||||
@@ -1131,7 +1130,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.2 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore13(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore13(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core13)
|
||||
{
|
||||
@@ -1156,7 +1155,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.3 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore14(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore14(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core14)
|
||||
{
|
||||
@@ -1181,7 +1180,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.4 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore15(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore15(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core15)
|
||||
{
|
||||
@@ -1216,7 +1215,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.5 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore20(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore20(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core20)
|
||||
{
|
||||
@@ -1325,7 +1324,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 2.0 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore21(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore21(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core21)
|
||||
{
|
||||
@@ -1347,7 +1346,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 2.1 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore30(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore30(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core30)
|
||||
{
|
||||
@@ -1447,7 +1446,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 3.0 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore31(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore31(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core31)
|
||||
{
|
||||
@@ -1478,7 +1477,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 3.1 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore32(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore32(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core32)
|
||||
{
|
||||
@@ -1513,7 +1512,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 3.2 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore33(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore33(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core33)
|
||||
{
|
||||
@@ -1557,7 +1556,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 3.3 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore40(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore40(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core40)
|
||||
{
|
||||
@@ -1619,7 +1618,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.0 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore41(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore41(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core41)
|
||||
{
|
||||
@@ -1723,7 +1722,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.1 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore42(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore42(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core42)
|
||||
{
|
||||
@@ -1751,7 +1750,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.2 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore43(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore43(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core43)
|
||||
{
|
||||
@@ -1811,7 +1810,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.3 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore44(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore44(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core44)
|
||||
{
|
||||
@@ -1836,7 +1835,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.4 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore45(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore45(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core45)
|
||||
{
|
||||
@@ -1962,7 +1961,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.5 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore46(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore46(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core46)
|
||||
{
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user