MVVM rebuild complete
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("OEM")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+924fe6eef7b6b9441b297f211c82b4684f23d002")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+da75200347e2ff7f483c83ff224678d05b0aefd1")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("OEM")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("OEM")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -9,5 +9,5 @@ uniform sampler2D tex;
|
||||
void main()
|
||||
{
|
||||
fragColor = texture(tex, texCoord.xy);
|
||||
//fragColor = vec4(0.0f,0.0f,0.0f,0.0f);
|
||||
//fragColor = vec4(0.099f,0.226f,0.335f,0.0f);
|
||||
}
|
||||
@@ -43,12 +43,16 @@ namespace StgSharp.Controls
|
||||
{
|
||||
public class BattleField : ControllingItem
|
||||
{
|
||||
public override ReadOnlySpan<vec4d> TextureBox
|
||||
public ReadOnlySpan<vec4d> TextureBox
|
||||
{
|
||||
get => throw new NotImplementedException() ;
|
||||
}
|
||||
public vec2d Position { get; set; }
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
public bool IsEntity => true;
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace StgSharp.Controls
|
||||
buttonList = new List<TriggerButton>();
|
||||
}
|
||||
|
||||
public override ReadOnlySpan<vec4d> TextureBox
|
||||
public ReadOnlySpan<vec4d> TextureBox
|
||||
{
|
||||
get => throw new NotSupportedException();
|
||||
}
|
||||
@@ -63,6 +63,12 @@ namespace StgSharp.Controls
|
||||
get => current;
|
||||
}
|
||||
|
||||
public vec2d Position { get; set; }
|
||||
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public bool IsEntity { get => false; }
|
||||
|
||||
protected List<TriggerButton> AllButton
|
||||
{
|
||||
get => buttonList;
|
||||
@@ -75,7 +81,7 @@ namespace StgSharp.Controls
|
||||
|
||||
public abstract void Confirm();
|
||||
|
||||
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
foreach (TriggerButton item in buttonList)
|
||||
{
|
||||
|
||||
@@ -20,10 +20,17 @@ namespace StgSharp.Controls
|
||||
Dictionary<char, PlainGeometryMesh> texIndex;
|
||||
PlainGeometryMesh _tittleMesh;
|
||||
|
||||
public override ReadOnlySpan<vec4d> TextureBox
|
||||
public bool IsEntity
|
||||
{
|
||||
get => true;
|
||||
}
|
||||
|
||||
public ReadOnlySpan<vec4d> TextureBox
|
||||
{
|
||||
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 void Display(string message)
|
||||
{
|
||||
@@ -39,7 +46,7 @@ namespace StgSharp.Controls
|
||||
displayIndex = result.ToCharArray();
|
||||
}
|
||||
|
||||
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
yield return _tittleMesh;
|
||||
foreach (char item in displayIndex)
|
||||
|
||||
@@ -9,16 +9,15 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public abstract partial class ControllingItem: IEnumerable<PlainGeometryMesh>
|
||||
public interface ControllingItem: IEnumerable<PlainGeometryMesh>
|
||||
{
|
||||
public vec2d Position { get; set; }
|
||||
public abstract vec2d Position { get; set; }
|
||||
public abstract Rectangle BoundingBox { get; set; }
|
||||
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
public abstract ReadOnlySpan<vec4d> TextureBox { get; }
|
||||
public abstract bool IsEntity { get; }
|
||||
|
||||
|
||||
public abstract IEnumerator<PlainGeometryMesh> GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
|
||||
@@ -13,12 +13,17 @@ namespace StgSharp.Controls
|
||||
{
|
||||
private PlainGeometryMesh renderMesh;
|
||||
|
||||
public override ReadOnlySpan<vec4d> TextureBox
|
||||
public ReadOnlySpan<vec4d> TextureBox
|
||||
{
|
||||
get => renderMesh.TextureCoord;
|
||||
}
|
||||
|
||||
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
public vec2d Position { get ; set ; }
|
||||
public Rectangle BoundingBox { get ; set ; }
|
||||
|
||||
public bool IsEntity => true;
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
yield return renderMesh;
|
||||
}
|
||||
|
||||
@@ -12,10 +12,14 @@ namespace StgSharp.Controls
|
||||
{
|
||||
public class MarkingLabel : ControllingItem
|
||||
{
|
||||
public override ReadOnlySpan<vec4d> TextureBox
|
||||
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;
|
||||
|
||||
@@ -41,7 +45,7 @@ namespace StgSharp.Controls
|
||||
_movement = movement;
|
||||
}
|
||||
|
||||
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
yield return marker;
|
||||
}
|
||||
|
||||
@@ -75,6 +75,11 @@ namespace StgSharp.Controls
|
||||
private Action? confirmCallback;
|
||||
#nullable restore
|
||||
|
||||
public TriggerButton()
|
||||
{
|
||||
CurrentStatus = ButtonStatus.Disable;
|
||||
}
|
||||
|
||||
protected ButtonStatus CurrentStatus { get; set; }
|
||||
|
||||
private RenderButtonTextureCallback _renderButton;
|
||||
@@ -101,7 +106,13 @@ namespace StgSharp.Controls
|
||||
}
|
||||
}
|
||||
|
||||
public override ReadOnlySpan<vec4d> TextureBox
|
||||
internal TextureProvider Texture
|
||||
{
|
||||
get => _texture;
|
||||
set => _texture = value;
|
||||
}
|
||||
|
||||
public ReadOnlySpan<vec4d> TextureBox
|
||||
{
|
||||
get => MemoryMarshal.Cast<vec2d, vec4d>(_texture.TextureCoordinate);
|
||||
}
|
||||
@@ -109,7 +120,11 @@ namespace StgSharp.Controls
|
||||
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; }
|
||||
@@ -128,6 +143,14 @@ namespace StgSharp.Controls
|
||||
remove { confirmCallback -= value; }
|
||||
}
|
||||
|
||||
internal void Init( ButtonStatus status )
|
||||
{
|
||||
if (CurrentStatus == ButtonStatus.Error)
|
||||
{
|
||||
CurrentStatus = status;
|
||||
}
|
||||
}
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
if (CurrentStatus == ButtonStatus.Disable)
|
||||
@@ -173,7 +196,7 @@ namespace StgSharp.Controls
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
_renderButton(CurrentStatus,_statusBeginTime, in _texture);
|
||||
yield return new PlainGeometryMesh(this.BoundingBox, _texture);
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace StgSharp
|
||||
|
||||
[DllImport(SSC_libName, EntryPoint = "linkShaderProgram",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe uint InternalLinkShaderProgram(GLcontext* context, uint shaderProgram);
|
||||
internal static extern unsafe uint InternalLinkShaderProgram(OpenglContext* context, uint shaderProgram);
|
||||
|
||||
[DllImport(SSC_libName, EntryPoint = "readLog",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
@@ -76,7 +76,7 @@ namespace StgSharp.Graphics
|
||||
public delegate IntPtr ImageLoader(string name, ref int width, ref int height, ref int definedChannel, int desiredChannel);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct GLcontext
|
||||
public struct OpenglContext
|
||||
{
|
||||
#region glapi
|
||||
|
||||
@@ -2622,18 +2622,18 @@ namespace StgSharp.Graphics
|
||||
|
||||
public unsafe override int GetHashCode()
|
||||
{
|
||||
fixed (GLcontext* sptr = &this)
|
||||
fixed (OpenglContext* sptr = &this)
|
||||
{
|
||||
return sptr->GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(GLcontext left, GLcontext right)
|
||||
public static bool operator ==(OpenglContext left, OpenglContext right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(GLcontext left, GLcontext right)
|
||||
public static bool operator !=(OpenglContext left, OpenglContext right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace StgSharp.Geometries
|
||||
protected vec4d[] vertexMat;
|
||||
internal CoordinationBase coordinate;
|
||||
|
||||
|
||||
internal PlainGeometry(CoordinationBase coordination)
|
||||
{
|
||||
coordinate = coordination;
|
||||
|
||||
@@ -93,7 +93,5 @@ namespace StgSharp.Geometries
|
||||
return default(vec3d);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,3 +10,6 @@ using System.Diagnostics.CodeAnalysis;
|
||||
[assembly: SuppressMessage("Naming", "CA1715:标识符应具有正确的前缀", Justification = "<挂起>", Scope = "member", Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``3(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1,``2}")]
|
||||
[assembly: SuppressMessage("Naming", "CA1715:标识符应具有正确的前缀", Justification = "<挂起>", Scope = "member", Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``4(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1,``2,``3}")]
|
||||
[assembly: SuppressMessage("Naming", "CA1715:标识符应具有正确的前缀", Justification = "<挂起>", Scope = "type", Target = "~T:StgSharp.Graphics.OpenGL.Uniform`4")]
|
||||
[assembly: SuppressMessage("Design", "CA1043:将整型或字符串参数用于索引器", Justification = "<挂起>", Scope = "member", Target = "~P:StgSharp.MVVM.View.ViewBase.IViewResponder`1.Item(StgSharp.Controlling.UsrActivity.ITrigger)")]
|
||||
[assembly: SuppressMessage("Design", "CA1043:将整型或字符串参数用于索引器", Justification = "<挂起>", Scope = "member", Target = "~P:StgSharp.MVVM.View.ViewBase.ViewResponder`1.Item(StgSharp.Controlling.UsrActivity.ITrigger)")]
|
||||
[assembly: SuppressMessage("Performance", "CA1864:首选 \"IDictionary.TryAdd(TKey, TValue)\" 方法", Justification = "<挂起>", Scope = "member", Target = "~P:StgSharp.MVVM.View.ViewBase.ViewRender`1.Item(System.String)")]
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace StgSharp.Graphics
|
||||
case ImageMovement.Top:
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException("Invalid or not supported data remanence");
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -953,6 +953,7 @@ namespace StgSharp.Graphics
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct GLsync
|
||||
{
|
||||
public IntPtr Handle;
|
||||
}
|
||||
|
||||
#endregion glad struct
|
||||
|
||||
@@ -94,6 +94,12 @@ namespace StgSharp.Graphics.OpenGL
|
||||
BGRA = GLconst.BGRA
|
||||
}
|
||||
|
||||
public enum FrameBufferAttachment
|
||||
{
|
||||
Color = GLconst.COLOR_ATTACHMENT0,
|
||||
Depth = GLconst.DEPTH_ATTACHMENT,
|
||||
Stencil = GLconst.STENCIL_ATTACHMENT,
|
||||
}
|
||||
|
||||
public enum Texture2DTarget
|
||||
{
|
||||
|
||||
@@ -7,6 +7,18 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed class GlExecutionException : Exception
|
||||
{
|
||||
public GlExecutionException()
|
||||
{
|
||||
}
|
||||
|
||||
public GlExecutionException(uint errorCode) : base($"Critical OpenGL error: {errorCode}")
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class GlArrayFormatException : Exception
|
||||
{
|
||||
public GlArrayFormatException(PixelChannelLayout layout, string arrayname):
|
||||
|
||||
@@ -228,7 +228,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
/// </summary>
|
||||
public unsafe void Link()
|
||||
{
|
||||
if (InternalIO.InternalLinkShaderProgram((GLcontext*)this.GL.ContextHandle, handle.Value) == 0)
|
||||
if (InternalIO.InternalLinkShaderProgram((OpenglContext*)this.GL.ContextHandle, handle.Value) == 0)
|
||||
{
|
||||
IntPtr logPtr = InternalIO.InternalReadSSCLog();
|
||||
try
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Math;
|
||||
using StgSharp.MVVM;
|
||||
using StgSharp.MVVM.View;
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -45,8 +48,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
private const int glExtension = 0x1f03;
|
||||
private const int glVersion = 0x1f02;
|
||||
|
||||
private static readonly string[] glBranch =
|
||||
new string[] {
|
||||
private static readonly string[] glBranch = {
|
||||
"OpenGL ES-CM ",
|
||||
"OpenGL ES-CL ",
|
||||
"OpenGL ES ",
|
||||
@@ -56,16 +58,14 @@ namespace StgSharp.Graphics.OpenGL
|
||||
private static string glExtensionList;
|
||||
|
||||
/// <summary>
|
||||
/// Load all supported OpenGL APIs and bind them to given <see cref="ViewPort"/> viewPortDisplay.
|
||||
/// Load all supported OpenGL APIs and bind them to given <see cref="ViewPort"/>.
|
||||
/// </summary>
|
||||
/// <param name="vp">The <see cref="ViewPort"/> used as current OpenGL viewPortDisplay</param>
|
||||
/// <param name="contextHandle">The handle to current OpenGL viewPortDisplay</param>
|
||||
public static unsafe void LoadOpenGLApiTo(IntPtr contextHandle)
|
||||
{
|
||||
GLcontext* context = (GLcontext*)contextHandle;
|
||||
OpenglContext* context = (OpenglContext*)contextHandle;
|
||||
delegate*<string,IntPtr> loader = &InternalIO.glfwGetProcAddress;
|
||||
#pragma warning disable CS8909
|
||||
if (context->glGetString != (delegate*<uint, IntPtr>)IntPtr.Zero)
|
||||
#pragma warning restore CS8909
|
||||
if ((IntPtr)context->glGetString != IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
InternalIO.InternalWriteLog("Failed to call glGetString", LogType.Error);
|
||||
}
|
||||
coreVersion = Marshal.PtrToStringAnsi(context->glGetString(glVersion));
|
||||
coreVersion = Marshal.PtrToStringAnsi(context->glGetString(glVersion))??string.Empty;
|
||||
|
||||
foreach (string branch in glBranch)
|
||||
{
|
||||
@@ -132,20 +132,32 @@ namespace StgSharp.Graphics.OpenGL
|
||||
}
|
||||
}
|
||||
|
||||
IntPtr strPtr = context->glGetString(glExtension);
|
||||
string extension;
|
||||
if (strPtr == IntPtr.Zero)
|
||||
uint code = context->glGetError();
|
||||
Console.WriteLine(code);
|
||||
if (code != 0)
|
||||
{
|
||||
throw new GlExecutionException(code);
|
||||
}
|
||||
|
||||
int extensionCount;
|
||||
context->glGetIntegerv(GLconst.NUM_EXTENSIONS,&extensionCount);
|
||||
if (extensionCount == 0)
|
||||
{
|
||||
InternalIO.InternalWriteLog("No supported OpenGL extensions are found.", LogType.Info);
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
List<string> extensions = new List<string>();
|
||||
|
||||
for (uint i = 0; i < extensionCount; i++)
|
||||
{
|
||||
extension = Marshal.PtrToStringAnsi(strPtr);
|
||||
byte* strPtr = context->glGetStringi(GLconst.EXTENSIONS,i);
|
||||
extensions.Add(Marshal.PtrToStringAnsi((IntPtr)strPtr));
|
||||
}
|
||||
|
||||
List<string> extensions =
|
||||
extension.Split(" ").ToList();
|
||||
InternalIO.InternalWriteLog($"Find OpenGL extensions:" + Environment.NewLine +
|
||||
$"{string.Join(';', extensions)}",
|
||||
LogType.Info);
|
||||
|
||||
#region checkGLextensions
|
||||
|
||||
@@ -771,9 +783,11 @@ namespace StgSharp.Graphics.OpenGL
|
||||
|
||||
#endregion checkGLextensions
|
||||
|
||||
InternalIO.InternalWriteLog("Find OpenGL extensions.", LogType.Info);
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Get the function pointer of given OpenGL api name
|
||||
/// </summary>
|
||||
@@ -793,6 +807,11 @@ namespace StgSharp.Graphics.OpenGL
|
||||
|
||||
internal static void CheckCoreVersion(int majorVersion, int minorVersion)
|
||||
{
|
||||
if (majorVersion < 3)
|
||||
{
|
||||
throw new InvalidOperationException("StgSharp does not support OpenGL immediate mode.");
|
||||
}
|
||||
|
||||
if ((majorVersion >= 1) || ((majorVersion == 1) && (minorVersion == 0)))
|
||||
{
|
||||
core10 = true;
|
||||
@@ -971,7 +990,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
}
|
||||
}
|
||||
|
||||
internal static unsafe string GetExtensions(this GLcontext context)
|
||||
internal static unsafe string GetExtensions(this OpenglContext context)
|
||||
{
|
||||
if (context.glGetString == null)
|
||||
{
|
||||
@@ -998,7 +1017,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
}
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore10(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore10(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core10)
|
||||
{
|
||||
@@ -1062,7 +1081,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.0 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore11(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore11(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core11)
|
||||
{
|
||||
@@ -1092,7 +1111,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.1 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore12(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore12(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core12)
|
||||
{
|
||||
@@ -1112,7 +1131,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.2 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore13(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore13(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core13)
|
||||
{
|
||||
@@ -1137,7 +1156,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.3 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore14(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore14(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core14)
|
||||
{
|
||||
@@ -1162,7 +1181,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.4 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore15(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore15(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core15)
|
||||
{
|
||||
@@ -1197,7 +1216,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.5 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore20(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore20(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core20)
|
||||
{
|
||||
@@ -1306,7 +1325,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 2.0 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore21(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore21(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core21)
|
||||
{
|
||||
@@ -1328,7 +1347,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 2.1 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore30(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore30(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core30)
|
||||
{
|
||||
@@ -1428,7 +1447,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 3.0 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore31(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore31(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core31)
|
||||
{
|
||||
@@ -1459,7 +1478,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 3.1 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore32(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore32(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core32)
|
||||
{
|
||||
@@ -1494,7 +1513,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 3.2 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore33(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore33(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core33)
|
||||
{
|
||||
@@ -1538,7 +1557,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 3.3 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore40(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore40(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core40)
|
||||
{
|
||||
@@ -1600,7 +1619,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.0 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore41(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore41(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core41)
|
||||
{
|
||||
@@ -1704,7 +1723,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.1 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore42(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore42(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core42)
|
||||
{
|
||||
@@ -1732,7 +1751,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.2 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore43(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore43(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core43)
|
||||
{
|
||||
@@ -1792,7 +1811,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.3 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore44(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore44(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core44)
|
||||
{
|
||||
@@ -1817,7 +1836,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.4 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore45(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore45(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core45)
|
||||
{
|
||||
@@ -1943,7 +1962,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.5 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore46(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore46(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core46)
|
||||
{
|
||||
|
||||
@@ -37,6 +37,7 @@ using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
@@ -48,19 +49,22 @@ namespace StgSharp
|
||||
[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);
|
||||
internal static extern int glCheckShaderStatus(ref OpenglContext context, uint shaderHandle, int key, ref IntPtr logPtr);
|
||||
#pragma warning restore CA5392
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
|
||||
|
||||
public unsafe partial class GlFunction
|
||||
{
|
||||
|
||||
private static Dictionary<IntPtr, GlFunction> contextToGLMap = new Dictionary<IntPtr, GlFunction>();
|
||||
private GLcontext* _context;
|
||||
private OpenglContext* _context;
|
||||
|
||||
private GlFunction()
|
||||
{
|
||||
@@ -70,7 +74,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
|
||||
internal IntPtr ContextHandle => (IntPtr)_context;
|
||||
|
||||
protected ref GLcontext Context
|
||||
protected ref OpenglContext Context
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -156,6 +160,27 @@ namespace StgSharp.Graphics.OpenGL
|
||||
while (Context.glGetError() != 0) { }
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
public void Assert(bool shouldReportWhenNormal)
|
||||
{
|
||||
try
|
||||
{
|
||||
uint code = Context.glGetError();
|
||||
if (code != GLconst.NO_ERROR)
|
||||
{
|
||||
throw new GlExecutionException(code);
|
||||
}
|
||||
if (shouldReportWhenNormal)
|
||||
{
|
||||
Console.WriteLine("OpenGL runs normally");
|
||||
}
|
||||
}
|
||||
catch (GlExecutionException ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void GenerateMipmap(Texture2DTarget target)
|
||||
{
|
||||
@@ -169,9 +194,9 @@ namespace StgSharp.Graphics.OpenGL
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void CombineFrameBufferRenderBuffer(GlHandle fboHandle, GlHandle rboHandle)
|
||||
public void CombineFrameBufferRenderBuffer(FrameBufferAttachment attachment, GlHandle rboHandle)
|
||||
{
|
||||
Context.glFramebufferRenderbuffer(GLconst.FRAMEBUFFER, fboHandle.Value, GLconst.RENDERBUFFER, rboHandle.Value);
|
||||
Context.glFramebufferRenderbuffer(GLconst.FRAMEBUFFER, (uint)attachment, GLconst.RENDERBUFFER, rboHandle.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -708,7 +733,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
return pack;
|
||||
}
|
||||
pack = new GlFunction { _context = (GLcontext*)handle };
|
||||
pack = new GlFunction { _context = (OpenglContext*)handle };
|
||||
contextToGLMap.Add(handle, pack);
|
||||
return pack;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Init an OpenGl viewPortDisplay if current form has not been binded to any viewPortDisplay.
|
||||
/// Initialize 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">
|
||||
@@ -63,8 +63,8 @@ namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
if (ContextHandle == default)
|
||||
{
|
||||
ContextHandle = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GLcontext)));
|
||||
GLcontext* contextID = (GLcontext*)ContextHandle;
|
||||
ContextHandle = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(OpenglContext)));
|
||||
OpenglContext* contextID = (OpenglContext*)ContextHandle;
|
||||
contextID->glGetString = (delegate*<uint, IntPtr>)IntPtr.Zero;
|
||||
}
|
||||
if (GL == null)
|
||||
@@ -92,7 +92,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal override sealed void PlatformSpecifiedInit()
|
||||
internal override sealed void PlatformSpecifiedInitialize()
|
||||
{
|
||||
MakeAsCurrentContext();
|
||||
glManager.LoadOpenGLApiTo(Port.GraphicHandle);
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
throw new ArgumentException(paramName: nameof(texture), message: "Amount of texture coordination is too less");
|
||||
}
|
||||
_texture = texture;
|
||||
_shape = shape;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
using StgSharp.MVVM;
|
||||
using StgSharp.MVVM.View;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -45,16 +47,11 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
public abstract class RenderStream
|
||||
{
|
||||
|
||||
private protected (int x, int y, int z) _coordStretch;
|
||||
|
||||
private Camera nativeCamera;
|
||||
|
||||
private protected ViewPort primeArgs;
|
||||
|
||||
internal TimeSpanProvider timeProvider;
|
||||
internal TimeSpanProvider _timeProvider;
|
||||
|
||||
|
||||
public (int width, int height) Size
|
||||
{
|
||||
get => (Width, Height);
|
||||
@@ -96,8 +93,11 @@ namespace StgSharp.Graphics
|
||||
|
||||
public vec2d GlobalCoordSize => ((Width * 1.0f) / _coordStretch.x, (Height * 1.0f) / _coordStretch.y);
|
||||
|
||||
public ViewPort Port => primeArgs;
|
||||
|
||||
public ViewPort Port
|
||||
{
|
||||
get => primeArgs;
|
||||
internal set => primeArgs = value;
|
||||
}
|
||||
internal IntPtr CanvasHandle { get => primeArgs.ViewPortID; }
|
||||
|
||||
|
||||
@@ -113,25 +113,24 @@ namespace StgSharp.Graphics
|
||||
internal set => nativeCamera = value;
|
||||
}
|
||||
|
||||
protected int Frames
|
||||
protected int PassedFrames
|
||||
{
|
||||
get => timeProvider.CurrentSpan;
|
||||
get => _timeProvider.CurrentSpan;
|
||||
}
|
||||
|
||||
|
||||
protected float TimePassed
|
||||
{
|
||||
get => timeProvider.CurrentSecond;
|
||||
get => _timeProvider.CurrentSecond;
|
||||
}
|
||||
|
||||
protected float FramePassed
|
||||
{
|
||||
get => timeProvider.CurrentSpan;
|
||||
get => _timeProvider.CurrentSpan;
|
||||
}
|
||||
|
||||
protected TimeSpanProvider TimeProvider
|
||||
{
|
||||
get => timeProvider;
|
||||
get => _timeProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -146,19 +145,10 @@ namespace StgSharp.Graphics
|
||||
|
||||
public static TTarget ShareContextFrom<TSource, TTarget>(TSource source)
|
||||
where TSource : RenderStream
|
||||
where TTarget : RenderStream
|
||||
where TTarget : RenderStream, new()
|
||||
{
|
||||
#nullable enable
|
||||
TTarget? target = Activator.CreateInstance(typeof(TTarget), source.primeArgs, source._coordStretch) as TTarget;
|
||||
#nullable restore
|
||||
if (target == null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Failed in creating a new {typeof(TTarget).Name} instance when calling ShareContextWith."
|
||||
);
|
||||
}
|
||||
target.timeProvider = source.timeProvider;
|
||||
target.PlatformSpecifiedInit();
|
||||
TTarget target = new TTarget();
|
||||
target.Initialize(source.Port,source._coordStretch,source._timeProvider);
|
||||
return target;
|
||||
}
|
||||
|
||||
@@ -175,6 +165,7 @@ namespace StgSharp.Graphics
|
||||
#region native camera operation
|
||||
protected abstract void NativeCameraViewRange(Radius fieldOfRange, vec2d offset, (float frontDepth, float backDepth) viewDepth);
|
||||
protected abstract void NativeCameraViewTarget(vec3d position, vec3d direction, vec3d up);
|
||||
|
||||
/// <summary>
|
||||
/// Get <see cref="Uniform{T}"/>(TView is <see cref="Matrix44"/>) uniform from a shader.
|
||||
/// This uniform will be used as projection matrix of this camera.
|
||||
@@ -193,21 +184,21 @@ namespace StgSharp.Graphics
|
||||
#region internal operation
|
||||
internal abstract void Draw();
|
||||
|
||||
public void Init(ViewPort v, (int, int, int) unitCubeSize)
|
||||
public void Initialize(ViewPort v, (int, int, int) unitCubeSize, TimeSpanProvider timeProvider)
|
||||
{
|
||||
if (v == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(v));
|
||||
}
|
||||
primeArgs = v;
|
||||
|
||||
this._timeProvider = timeProvider;
|
||||
_coordStretch = unitCubeSize;
|
||||
nativeCamera = new Camera();
|
||||
PlatformSpecifiedInit();
|
||||
PlatformSpecifiedInitialize();
|
||||
CustomizeInit();
|
||||
}
|
||||
|
||||
internal abstract void PlatformSpecifiedInit();
|
||||
internal abstract void PlatformSpecifiedInitialize();
|
||||
|
||||
internal abstract void Terminate();
|
||||
#endregion
|
||||
@@ -226,7 +217,6 @@ namespace StgSharp.Graphics
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace StgSharp.Graphics.ShaderEdit
|
||||
|
||||
public unsafe void SetAllUniforms()
|
||||
{
|
||||
GLcontext* gl = (GLcontext*)OpenGL.GlFunction.CurrentGL.ContextHandle;
|
||||
OpenglContext* gl = (OpenglContext*)OpenGL.GlFunction.CurrentGL.ContextHandle;
|
||||
foreach (var uniform in uniformPair)
|
||||
{
|
||||
int id = uniform.Key.SignedValue;
|
||||
|
||||
@@ -33,6 +33,23 @@ namespace StgSharp.Graphics
|
||||
get => ref _texCoord[index];
|
||||
}
|
||||
|
||||
public void UpdateFromImage(Image i)
|
||||
{
|
||||
if (i == _tex)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (i.Size == _tex.Size)
|
||||
{
|
||||
_tex = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException($"Size of {nameof(i)} does not equals to current image.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void ReadImage(IImageProvider provider)
|
||||
{
|
||||
_tex = provider.ProvideImage();
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ViewBase.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 StgSharp.MVVM.ViewModel;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.MVVM.View
|
||||
{
|
||||
/// <summary>
|
||||
/// ViewBase is the base type for all view types, providing context binding and control element binding.
|
||||
/// A complete view should contain one complete <see cref="ViewDesigner{T}"/>, <see cref="ViewRender{TView}"/>, and <see cref="ViewResponder"/>,
|
||||
/// which provide layout descriptions of control elements, user responses, and rendering implementations in the view.
|
||||
/// Data between instances of <see cref="ViewDesigner{T}"/>, <see cref="ViewRender{TView}"/>, and <see cref="ViewResponder{T}"/> is shared through <see cref="ViewBase"/>.
|
||||
/// </summary>
|
||||
|
||||
public abstract unsafe partial class ViewBase
|
||||
{
|
||||
|
||||
private (int x, int y, int z) unitCubeSize;
|
||||
|
||||
private GetDataBindingEntryDelegate getDataBindingEntry;
|
||||
|
||||
private int usedFrame = 0;
|
||||
private IViewDesigner<ViewBase> _design;
|
||||
private IViewRender<ViewBase> _render;
|
||||
private IViewResponder<ViewBase> _responder;
|
||||
private TimeSpanProvider time;
|
||||
|
||||
private ViewPort context;
|
||||
|
||||
private delegate bool GetDataBindingEntryDelegate(string name, out DataBindingEntry entry);
|
||||
|
||||
public DataBindingEntry this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (TryGetObjectReference(name, out DataBindingEntry entry))
|
||||
{
|
||||
return entry;
|
||||
}
|
||||
if (getDataBindingEntry(name, out entry))
|
||||
{
|
||||
return entry;
|
||||
}
|
||||
throw new KeyNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
public (int x, int y, int z) UnitCubeSize
|
||||
{
|
||||
get => unitCubeSize;
|
||||
}
|
||||
|
||||
public bool Activated { get; internal set; }
|
||||
|
||||
public int Height
|
||||
{
|
||||
get => context.Height;
|
||||
private set { context.Height = value; }
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => context.Width;
|
||||
private set { context.Width = value; }
|
||||
}
|
||||
|
||||
public IntPtr Monitor => context.Monitor;
|
||||
|
||||
public IntPtr ViewHandle => context.ViewPortID;
|
||||
|
||||
public IViewDesigner<ViewBase> Designer
|
||||
{
|
||||
get => _design;
|
||||
protected set => _design = value;
|
||||
}
|
||||
|
||||
public string ContextName => context.Name;
|
||||
|
||||
public string SelfName { get; set; }
|
||||
|
||||
public ViewPort Port
|
||||
{
|
||||
get => context;
|
||||
}
|
||||
|
||||
internal TimeSpanProvider TimeProvider
|
||||
{
|
||||
get => time;
|
||||
}
|
||||
|
||||
protected IViewRender<ViewBase> Render
|
||||
{
|
||||
get => _render;
|
||||
set => _render = value;
|
||||
}
|
||||
|
||||
protected IViewResponder<ViewBase> Responder
|
||||
{
|
||||
get => _responder;
|
||||
set => _responder = value;
|
||||
}
|
||||
|
||||
public abstract void CustomizedInitialize(ViewModelBase viewModelBinding);
|
||||
|
||||
/// <summary>
|
||||
/// Get the status of a certain key on the keyboard.
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns><see cref="KeyStatus"/> representing if a key is pressed or released.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public KeyStatus GetKeyStatus(KeyboardKey key)
|
||||
{
|
||||
return InternalIO.glfwGetKey(context.ViewPortID, (int)key);
|
||||
}
|
||||
|
||||
public void InternalInitialize(string name,(int,int,int) cubeSize, ViewModelBase viewModelBinding)
|
||||
{
|
||||
SelfName = name;
|
||||
unitCubeSize = cubeSize;
|
||||
getDataBindingEntry = viewModelBinding.TryGetObjectReference;
|
||||
context = viewModelBinding.ViewPortBinding;
|
||||
time = viewModelBinding.frameTimeProvider;
|
||||
|
||||
CustomizedInitialize(viewModelBinding);
|
||||
}
|
||||
|
||||
public abstract bool TryGetObjectReference(string name, out DataBindingEntry entry);
|
||||
|
||||
public void Use()
|
||||
{
|
||||
if (usedFrame == 0)
|
||||
{
|
||||
if (!ValidateInitialization())
|
||||
{
|
||||
throw new InvalidOperationException("This view is not correctly initialized before rendering.");
|
||||
}
|
||||
}
|
||||
Show();
|
||||
}
|
||||
|
||||
public bool ValidateInitialization()
|
||||
{
|
||||
return (_design != null) && (_render != null) && (getDataBindingEntry != null) && (_responder != null)
|
||||
&& (_design.ValidateInitializing()) && (_responder.ValidateInitializing()) && (_render.ValidateInitializing())
|
||||
;
|
||||
}
|
||||
|
||||
protected internal abstract void Show();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ViewDesigner.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.Controlling.UsrActivity;
|
||||
using StgSharp.Controls;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.MVVM.View
|
||||
{
|
||||
public abstract partial class ViewBase
|
||||
{
|
||||
public interface IViewDesigner<out TView> where TView : ViewBase
|
||||
{
|
||||
abstract void Initialize();
|
||||
|
||||
abstract void CustomizedInitialize();
|
||||
|
||||
abstract bool ValidateInitializing();
|
||||
|
||||
}
|
||||
|
||||
/// <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> : IViewDesigner<TView> where TView : ViewBase
|
||||
{
|
||||
|
||||
private KeyboardButtonGroup currentButtonGroup;
|
||||
|
||||
private List<ControllingItem> _controlList;
|
||||
protected TView _binding;
|
||||
|
||||
public ViewDesigner(TView binding)
|
||||
{
|
||||
_binding = binding;
|
||||
_controlList = new List<ControllingItem>();
|
||||
}
|
||||
|
||||
protected TView Binding
|
||||
{
|
||||
get => _binding;
|
||||
}
|
||||
|
||||
public CharacterLineIndexImage CreateCharacterLine(
|
||||
int length, char blankFilling, PlainGeometryMesh tittle, IEnumerable<(char, PlainGeometryMesh)> charList
|
||||
)
|
||||
{
|
||||
CharacterLineIndexImage ret = new CharacterLineIndexImage(length, blankFilling, tittle, charList);
|
||||
_controlList.Add(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public TriggerButton CreateKeyboardButton(
|
||||
Rectangle bonding, TextureProvider defaultAnimation, bool isEnable
|
||||
)
|
||||
{
|
||||
TriggerButton ret = new TriggerButton();
|
||||
ret.BoundingBox = bonding;
|
||||
ret.Texture = defaultAnimation;
|
||||
if (isEnable)
|
||||
{
|
||||
ret.IsDisabled = false;
|
||||
ret.Enable();
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.IsDisabled = true;
|
||||
ret.Disable();
|
||||
}
|
||||
currentButtonGroup.AddButton(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public TButtonGroup CreateKeyboardButtonGroup<TButtonGroup>(
|
||||
ITrigger leftBidning,
|
||||
ITrigger rightBinding,
|
||||
ITrigger upBinding,
|
||||
ITrigger downBinding,
|
||||
ITrigger confirmBinding
|
||||
)
|
||||
where TButtonGroup : KeyboardButtonGroup, new()
|
||||
{
|
||||
TButtonGroup 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 void Initialize()
|
||||
{
|
||||
CustomizedInitialize();
|
||||
}
|
||||
|
||||
public abstract void CustomizedInitialize();
|
||||
|
||||
public abstract bool ValidateInitializing();
|
||||
|
||||
}//---------------------------------- End of Class -----------------------------------------
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ViewRender.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 StgSharp.MVVM.ViewModel;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.MVVM.View
|
||||
{
|
||||
public abstract partial class ViewBase
|
||||
{
|
||||
protected interface IViewRender<out TView> where TView : ViewBase
|
||||
{
|
||||
|
||||
RenderStream this[string renderName] { get; }
|
||||
|
||||
void CustomizedInitialize();
|
||||
|
||||
void Initialize();
|
||||
|
||||
bool ValidateInitializing();
|
||||
|
||||
}
|
||||
|
||||
protected abstract class ViewRender<TView> : IViewRender<TView>
|
||||
where TView : ViewBase
|
||||
{
|
||||
|
||||
#pragma warning disable CS8618
|
||||
private Dictionary<string, RenderStream> _render;
|
||||
private TView _binding;
|
||||
#pragma warning restore CS8618
|
||||
|
||||
protected ViewRender(TView binding)
|
||||
{
|
||||
_binding = binding;
|
||||
}
|
||||
|
||||
public RenderStream this[string renderName]
|
||||
{
|
||||
get => _render.TryGetValue(renderName, out RenderStream stream) ? stream : null!;
|
||||
protected set
|
||||
{
|
||||
|
||||
if (_render.ContainsKey(renderName))
|
||||
{
|
||||
_render[renderName] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
_render.Add(renderName, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TView Binding => _binding;
|
||||
|
||||
protected ViewPort ContextBinding => _binding.context;
|
||||
|
||||
protected ViewDesigner<TView> Design => (_binding.Designer as ViewDesigner<TView>)!;
|
||||
|
||||
protected Dictionary<string, RenderStream> Render
|
||||
{
|
||||
get => _render;
|
||||
}
|
||||
|
||||
protected ViewResponder<TView> Responder => (_binding.Responder as ViewResponder<TView>)!;
|
||||
|
||||
public T CreateRenderStream<T>(ViewPort vp, (int x, int y, int z) unitCubeSize) where T : RenderStream, new()
|
||||
{
|
||||
T ret = new T();
|
||||
ret.Initialize(vp, unitCubeSize, Binding.TimeProvider);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public T CreateRenderStream<T>((int x, int y, int z) unitCubeSize) where T : RenderStream, new()
|
||||
{
|
||||
T ret = new T();
|
||||
ret.Initialize(_binding.context, unitCubeSize, Binding.TimeProvider);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public abstract void CustomizedInitialize();
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
CustomizedInitialize();
|
||||
}
|
||||
|
||||
public abstract bool ValidateInitializing();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ViewResponder.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.Controlling.UsrActivity;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.MVVM.View
|
||||
{
|
||||
public partial class ViewBase
|
||||
{
|
||||
protected interface IViewResponder<out TVIew> where TVIew : ViewBase
|
||||
{
|
||||
|
||||
Action? this[ITrigger trigger] { get; set; }
|
||||
|
||||
void CustomizedInitialize(Func<ITrigger, string, Action> keyRegister);
|
||||
|
||||
void ProcessUserInput();
|
||||
|
||||
bool ValidateInitializing();
|
||||
|
||||
void Initialize(Func<string, Action> keyGetter);
|
||||
|
||||
}
|
||||
|
||||
protected abstract class ViewResponder<TView> : IViewResponder<TView> where TView : ViewBase
|
||||
{
|
||||
|
||||
private bool _isInitialized;
|
||||
private Dictionary<ITrigger, Action> keyCallbackIndex;
|
||||
private Dictionary<string, Action> nameToCallbackMap;
|
||||
private TView _binding;
|
||||
|
||||
protected ViewResponder(TView binding)
|
||||
{
|
||||
keyCallbackIndex = new Dictionary<ITrigger, Action>();
|
||||
nameToCallbackMap = new Dictionary<string, Action>();
|
||||
_binding = binding;
|
||||
}
|
||||
|
||||
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 ?? throw new ArgumentNullException(nameof(value)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected TView Binding => _binding;
|
||||
|
||||
public abstract void CustomizedInitialize(Func<ITrigger, string, Action> keyRegister);
|
||||
|
||||
public void ProcessUserInput()
|
||||
{
|
||||
foreach (KeyValuePair<ITrigger, Action> pair in keyCallbackIndex)
|
||||
{
|
||||
if (InternalIO.glfwGetKey(_binding.ViewHandle, pair.Key.TargetKeyOrButtonID) == pair.Key.TriggeredStatus)
|
||||
{
|
||||
pair.Value();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract bool ValidateInitializing();
|
||||
|
||||
public void Initialize(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;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="DataBinding.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.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.MVVM.ViewModel
|
||||
{
|
||||
#nullable enable
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate ref object BindingDataGetter();
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void BindingDataSetter(ref object value);
|
||||
|
||||
public unsafe struct DataBindingEntry
|
||||
{
|
||||
private IntPtr getterPtr, setterPtr;
|
||||
|
||||
public DataBindingEntry(
|
||||
[NotNull] BindingDataGetter gettingCallback,
|
||||
[NotNull] BindingDataSetter settingCallback)
|
||||
{
|
||||
getterPtr = Marshal.GetFunctionPointerForDelegate(gettingCallback);
|
||||
setterPtr = Marshal.GetFunctionPointerForDelegate(settingCallback);
|
||||
}
|
||||
|
||||
public static DataBindingEntry NullBinding
|
||||
{
|
||||
get => new DataBindingEntry();
|
||||
}
|
||||
|
||||
public bool ExactEqual(DataBindingEntry other)
|
||||
{
|
||||
return (getterPtr == other.getterPtr) && (setterPtr == other.setterPtr);
|
||||
}
|
||||
|
||||
public ref object GetValue()
|
||||
{
|
||||
return ref ((delegate* unmanaged[Cdecl]<ref object>)getterPtr)();
|
||||
}
|
||||
|
||||
public void SetData(ref object value)
|
||||
{
|
||||
((delegate* unmanaged[Cdecl]<ref object, void>)setterPtr)(ref value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#nullable restore
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ShowViewPort.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.MVVM.View;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.MVVM.ViewModel
|
||||
{
|
||||
public abstract partial class ViewModelBase
|
||||
{
|
||||
|
||||
private ViewBase _nextView, _currentView;
|
||||
|
||||
protected ViewBase CurrentView
|
||||
{
|
||||
get => _currentView;
|
||||
set => _nextView = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// CustomizeInit this form and render it on screen, and respond with operation
|
||||
/// </summary>
|
||||
public unsafe void UseViewModel(string viewEntryName)
|
||||
{
|
||||
CustomizeInitialize();
|
||||
//BuildGlobalKeyControl();
|
||||
UseViewInNextFrame(viewEntryName);
|
||||
while (0 == InternalIO.glfwWindowShouldClose(this.viewPortDisplay.ViewPortID))
|
||||
{
|
||||
ShowFrameOnce();
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowFrameOnce()
|
||||
{
|
||||
viewPortDisplay.FlushSize();
|
||||
if (_nextView != _currentView)
|
||||
{
|
||||
Interlocked.Exchange(ref _currentView, _nextView);
|
||||
}
|
||||
CurrentView.Use();
|
||||
RenderStream.PollEvents();
|
||||
frameTimeProvider.WaitNextSpan();
|
||||
Interlocked.Add(ref _frameCount, 1);
|
||||
}
|
||||
|
||||
protected void UseViewInNextFrame(string name)
|
||||
{
|
||||
if (!allView.TryGetValue(name, out ViewBase v))
|
||||
{
|
||||
throw new KeyNotFoundException($"{($"Cannot find View named {name} ")}{($"in current View Model of {GetType().FullName}")}");
|
||||
}
|
||||
CurrentView = v;
|
||||
}
|
||||
|
||||
private unsafe void PrivateShow()
|
||||
{
|
||||
if (0 == InternalIO.glfwWindowShouldClose(this.viewPortDisplay.ViewPortID))
|
||||
{
|
||||
CurrentView.Use();
|
||||
RenderStream.PollEvents();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ViewManage.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.MVVM.View;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.MVVM.ViewModel
|
||||
{
|
||||
public partial class ViewModelBase
|
||||
{
|
||||
private Dictionary<string, ViewBase> allView;
|
||||
|
||||
public T CreateAndBindView<T>(string name, (int x, int y, int z) unitCubeSize)
|
||||
where T : ViewBase, new()
|
||||
{
|
||||
T ret = new T();
|
||||
ret.SelfName = name;
|
||||
ret.InternalInitialize(name,unitCubeSize,this);
|
||||
allView.Add(name, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,320 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ViewModel.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.Controlling.UsrActivity;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Math;
|
||||
using StgSharp.MVVM.View;
|
||||
using StgSharp.MVVM.ViewModel;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.MVVM.ViewModel
|
||||
{
|
||||
public abstract partial class ViewModelBase
|
||||
{
|
||||
|
||||
private int _frameCount;
|
||||
private int _frameSpeed;
|
||||
private ViewPort viewPortDisplay;
|
||||
|
||||
//internal IntPtr monitor;
|
||||
|
||||
internal TimeSpanProvider fpsCountProvider;
|
||||
internal TimeSpanProvider frameTimeProvider;
|
||||
internal Vector4 backgroundColor;
|
||||
|
||||
protected ViewModelBase(int frameSpeed)
|
||||
{
|
||||
viewPortDisplay = new ViewPort();
|
||||
allView = new();
|
||||
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
|
||||
_frameSpeed = 0;
|
||||
_frameCount = 0;
|
||||
fpsCountProvider.SpanRefreshCallback = CountFps;
|
||||
long frameLength = (FrameSpeed > 0) ? ((1000L * 1000L) / FrameSpeed) : 0;
|
||||
frameTimeProvider = new TimeSpanProvider(
|
||||
frameLength, TimeSpanProvider.DefaultProvider
|
||||
);
|
||||
frameTimeProvider.SpanRefreshCallback =
|
||||
() =>
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
protected ViewModelBase(float frameLength)
|
||||
{
|
||||
viewPortDisplay = new ViewPort();
|
||||
allView = new();
|
||||
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
|
||||
_frameSpeed = 0;
|
||||
_frameCount = 0;
|
||||
fpsCountProvider.SpanRefreshCallback = CountFps;
|
||||
long _frameLength = (FrameSpeed > 0) ? ((long)(1000 * frameLength)) : 0;
|
||||
frameTimeProvider = new TimeSpanProvider(
|
||||
_frameLength, TimeSpanProvider.DefaultProvider
|
||||
);
|
||||
frameTimeProvider.SpanRefreshCallback =
|
||||
() =>
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
public ViewModelBase(ViewPort vbinding, int framespeed)
|
||||
{
|
||||
viewPortDisplay = vbinding;
|
||||
allView = new();
|
||||
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
|
||||
_frameSpeed = 0;
|
||||
_frameCount = 0;
|
||||
fpsCountProvider.SpanRefreshCallback = CountFps;
|
||||
long frameLength = (framespeed > 0) ? ((1000L * 1000L) / framespeed) : 0;
|
||||
frameTimeProvider = new TimeSpanProvider(
|
||||
frameLength, TimeSpanProvider.DefaultProvider
|
||||
);
|
||||
frameTimeProvider.SpanRefreshCallback =
|
||||
() =>
|
||||
{
|
||||
};
|
||||
viewPortDisplay.FrameSizeCallback = (handle, width, height)
|
||||
=>
|
||||
{
|
||||
InternalIO.glfwMakeContextCurrent(viewPortDisplay.ViewPortID);
|
||||
GlFunction.CurrentGL.Viewport(0, 0, width, height);
|
||||
PrivateShow();
|
||||
};
|
||||
viewPortDisplay.FramePostionCallback = (handle, xpos, ypos)
|
||||
=>
|
||||
{
|
||||
PrivateShow();
|
||||
};
|
||||
}
|
||||
|
||||
public ViewModelBase(ViewPort vbinding, float frameLength)
|
||||
{
|
||||
viewPortDisplay = vbinding;
|
||||
allView = new();
|
||||
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
|
||||
_frameSpeed = 0;
|
||||
_frameCount = 0;
|
||||
fpsCountProvider.SpanRefreshCallback = CountFps;
|
||||
long _frameLength = (frameLength > 0) ? ((long)(1000 * frameLength)) : 0;
|
||||
frameTimeProvider = new TimeSpanProvider(
|
||||
_frameLength, TimeSpanProvider.DefaultProvider
|
||||
);
|
||||
frameTimeProvider.SpanRefreshCallback =
|
||||
() =>
|
||||
{
|
||||
};
|
||||
|
||||
viewPortDisplay.FrameSizeCallback = (handle, width, height)
|
||||
=>
|
||||
{
|
||||
InternalIO.glfwMakeContextCurrent(viewPortDisplay.ViewPortID);
|
||||
GlFunction.CurrentGL.Viewport(0, 0, width, height);
|
||||
PrivateShow();
|
||||
};
|
||||
viewPortDisplay.FramePostionCallback = (handle, xpos, ypos)
|
||||
=>
|
||||
{
|
||||
PrivateShow();
|
||||
};
|
||||
}
|
||||
|
||||
public DataBindingEntry this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.TryGetObjectReference(name, out DataBindingEntry entry))
|
||||
{
|
||||
return entry;
|
||||
}
|
||||
throw new KeyNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShouldClose
|
||||
{
|
||||
get => InternalIO.glfwWindowShouldClose(viewPortDisplay.ViewPortID) != 0;
|
||||
set => InternalIO.glfwSetWindowShouldClose(viewPortDisplay.ViewPortID, value ? 1 : 0);
|
||||
}
|
||||
|
||||
public int CurrentFrameCount => frameTimeProvider.CurrentSpan;
|
||||
|
||||
public int FrameSpeed => _frameSpeed;
|
||||
|
||||
/// <summary>
|
||||
/// Height of this form, represent in <see cref="int"/>
|
||||
/// </summary>
|
||||
public int Height
|
||||
{
|
||||
get => viewPortDisplay.Height;
|
||||
set { viewPortDisplay.Height = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Width of this form, represent in <see cref="int"/>
|
||||
/// </summary>
|
||||
public int Width
|
||||
{
|
||||
get => viewPortDisplay.Width;
|
||||
set
|
||||
{
|
||||
viewPortDisplay.Width = value;
|
||||
if (WindowID != IntPtr.Zero)
|
||||
{
|
||||
InternalIO.glfwSetWindowSize(viewPortDisplay.ViewPortID, Width, Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe IntPtr WindowID
|
||||
{
|
||||
get => viewPortDisplay.ViewPortID;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => viewPortDisplay.Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Width of this form, represent in <see cref="int"/>
|
||||
/// </summary>
|
||||
public vec2d Size
|
||||
{
|
||||
get => new vec2d(Width, Height);
|
||||
set
|
||||
{
|
||||
Width = (int)value.X;
|
||||
Height = (int)value.Y;
|
||||
if (WindowID != IntPtr.Zero)
|
||||
{
|
||||
InternalIO.glfwSetWindowSize(viewPortDisplay.ViewPortID, Width, Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ViewPort ViewPortBinding
|
||||
{
|
||||
get => viewPortDisplay;
|
||||
}
|
||||
|
||||
#pragma warning disable CA1044
|
||||
protected FrameBufferSizeHandler FrameSizeCallback
|
||||
{
|
||||
set
|
||||
{
|
||||
IntPtr handlerPtr = Marshal.GetFunctionPointerForDelegate(value);
|
||||
InternalIO.glfwSetFramebufferSizeCallback(viewPortDisplay.ViewPortID, handlerPtr);
|
||||
}
|
||||
}
|
||||
#pragma warning restore CA1044
|
||||
|
||||
|
||||
public abstract void CustomizeInitialize();
|
||||
|
||||
public Action MethodLookup(string methodName)
|
||||
{
|
||||
MethodInfo method = GetType().GetMethod(methodName);
|
||||
return (method != null) ? ((Action)Delegate.CreateDelegate(typeof(Action), this, method)) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resize the current form
|
||||
/// </summary>
|
||||
/// <param name="size">
|
||||
/// A <see cref="vec2d"/> (width,height) representing the new size of current form
|
||||
/// </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetSize(vec2d size)
|
||||
{
|
||||
this.Size = size;
|
||||
InternalIO.glfwSetWindowSize(this.viewPortDisplay.ViewPortID, (int)size.X, (int)size.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the size limit of current form
|
||||
/// </summary>
|
||||
/// <param name="minSize">
|
||||
/// Minimum size of current form. In form of a <see cref="vec2d"/> of (width,height)
|
||||
/// </param>
|
||||
/// <param name="maxSize">
|
||||
/// Maximum size of current form. In form of a <see cref="vec2d"/> of (width,height)
|
||||
/// </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetSizeLimit(vec2d minSize, vec2d maxSize)
|
||||
{
|
||||
InternalIO.glfwSetWindowSizeLimits(
|
||||
this.viewPortDisplay.ViewPortID,
|
||||
(int)minSize.X,
|
||||
(int)minSize.Y,
|
||||
(int)maxSize.X,
|
||||
(int)maxSize.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the size limit of current form
|
||||
/// </summary>
|
||||
/// <param name="minWidth">Minimum width of current form</param>
|
||||
/// <param name="minHeight">Minimum height of current form</param>
|
||||
/// <param name="maxWidth">Maximum width of current form</param>
|
||||
/// <param name="maxHeight">Maximum height of current form</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
|
||||
{
|
||||
//TODO 重做form的尺寸极限控制
|
||||
InternalIO.glfwSetWindowSizeLimits(this.viewPortDisplay.ViewPortID, minWidth, minHeight, maxWidth, maxHeight);
|
||||
}
|
||||
|
||||
public abstract bool TryGetObjectReference(string name, out DataBindingEntry entry);
|
||||
|
||||
private void CountFps()
|
||||
{
|
||||
/**/
|
||||
Console.Clear();
|
||||
Console.WriteLine(FrameSpeed);
|
||||
/**/
|
||||
Interlocked.Exchange(ref _frameSpeed, _frameCount);
|
||||
Interlocked.Exchange(ref _frameCount, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ViewPort.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.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.MVVM
|
||||
{
|
||||
public class ViewPort
|
||||
{
|
||||
|
||||
private FrameBufferSizeHandler _sizeHandler;
|
||||
private FramePositionHandler _positionHandler;
|
||||
private int _width, _height;
|
||||
|
||||
internal ViewPort()
|
||||
{
|
||||
_height = 600;
|
||||
_width = 800;
|
||||
Name = new StackFrame(1, false).
|
||||
GetMethod()!.DeclaringType!.Name;
|
||||
Monitor = IntPtr.Zero;
|
||||
ViewPortID = InternalIO.glfwCreateWindow(_width, _height,
|
||||
Encoding.UTF8.GetBytes(Name), Monitor, IntPtr.Zero
|
||||
);
|
||||
if (ViewPortID == IntPtr.Zero)
|
||||
{
|
||||
throw new InvalidOperationException("Unable to create viewport handle.");
|
||||
}
|
||||
}
|
||||
|
||||
public ViewPort(vec2d size, string name, IntPtr monitor)
|
||||
{
|
||||
_width = (int)size.X;
|
||||
_height = (int)size.Y;
|
||||
Name = name;
|
||||
Monitor = monitor;
|
||||
ViewPortID = InternalIO.glfwCreateWindow(_width, _height,
|
||||
Encoding.UTF8.GetBytes(Name), Monitor, IntPtr.Zero
|
||||
);
|
||||
if (ViewPortID == IntPtr.Zero)
|
||||
{
|
||||
throw new InvalidOperationException("Unable to create viewport handle.");
|
||||
}
|
||||
}
|
||||
|
||||
public FrameBufferSizeHandler FrameSizeCallback
|
||||
{
|
||||
set
|
||||
{
|
||||
_sizeHandler = value;
|
||||
IntPtr handlerPtr = Marshal.GetFunctionPointerForDelegate(_sizeHandler);
|
||||
InternalIO.glfwSetFramebufferSizeCallback(ViewPortID, handlerPtr);
|
||||
}
|
||||
}
|
||||
|
||||
public FramePositionHandler FramePostionCallback
|
||||
{
|
||||
set
|
||||
{
|
||||
_positionHandler = value;
|
||||
IntPtr handlerPtr = Marshal.GetFunctionPointerForDelegate(_positionHandler);
|
||||
InternalIO.glfwSetWindowPosCallback(ViewPortID, handlerPtr);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe int Height
|
||||
{
|
||||
get { return _height; }
|
||||
set { InternalIO.glfwSetWindowSize(ViewPortID, _width, value); }
|
||||
}
|
||||
|
||||
public unsafe int Width
|
||||
{
|
||||
get { return _width; }
|
||||
set { InternalIO.glfwSetWindowSize(ViewPortID, value, _height); }
|
||||
}
|
||||
|
||||
public IntPtr GraphicHandle { get; internal set; }
|
||||
|
||||
public IntPtr Monitor { get; internal set; }
|
||||
|
||||
public IntPtr ViewPortID { get; private set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public void Close()
|
||||
{
|
||||
InternalIO.glfwSetWindowShouldClose(ViewPortID, 1);
|
||||
}
|
||||
|
||||
internal unsafe void FlushSize()
|
||||
{
|
||||
fixed (int* wptr = &_width, hptr = &_height)
|
||||
{
|
||||
InternalIO.glfwGetWindowSize(ViewPortID, wptr, hptr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -142,7 +142,7 @@ namespace StgSharp.Graphics
|
||||
|
||||
public unsafe void SetAllUniforms()
|
||||
{
|
||||
//Console.WriteLine(Projection * View);
|
||||
//Console.WriteLine(Projection * ViewBase);
|
||||
OpenGL.GlFunction.CurrentGL.SetUniformValue(convertedUniform, Projection * View);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
using StgSharp.MVVM;
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
@@ -116,7 +117,7 @@ namespace StgSharp.Stg
|
||||
GL.FrameBufferTexture2d(FrameBufferTarget.All, glAttachment.Color(0),
|
||||
Texture2DTarget.Texture2D, t[0], 0);
|
||||
|
||||
GL.CombineFrameBufferRenderBuffer(fbo[0], rbo[0]);
|
||||
GL.CombineFrameBufferRenderBuffer(FrameBufferAttachment.Color, rbo[0]);
|
||||
|
||||
textureOutput = new float[this.Width];
|
||||
}
|
||||
@@ -180,7 +181,7 @@ namespace StgSharp.Stg
|
||||
|
||||
_coordStretch = (1, 1, 1);
|
||||
|
||||
PlatformSpecifiedInit();
|
||||
PlatformSpecifiedInitialize();
|
||||
CustomizeInit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace StgSharp.Stg.Touhou
|
||||
|
||||
|
||||
/*
|
||||
public static View BuildTouhouWorld()
|
||||
public static ViewBase BuildTouhouWorld()
|
||||
{
|
||||
|
||||
TouhouForm form = new TouhouForm();
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+924fe6eef7b6b9441b297f211c82b4684f23d002")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+da75200347e2ff7f483c83ff224678d05b0aefd1")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -4,6 +4,7 @@ using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
using StgSharp.MVVM;
|
||||
|
||||
using StgSharpDebug.Logic;
|
||||
|
||||
@@ -27,8 +28,12 @@ namespace StgSharp
|
||||
StgSharp.InitGL(4, 6);
|
||||
StgSharp.GlobalSetting.VSyncActivated = false;
|
||||
|
||||
ViewPort vp = new ViewPort();
|
||||
|
||||
ViewModelMain mainModel = new ViewModelMain(vp);
|
||||
mainModel.CreateAndBindView<ViewMain>("MainView", (1, 1, 1));
|
||||
|
||||
mainModel.UseViewModel("MainView");
|
||||
|
||||
StgSharp.Terminate();
|
||||
/**/
|
||||
@@ -36,10 +41,10 @@ namespace StgSharp
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
|
||||
InternalIO.InternalWriteLog(
|
||||
ex.Message + "\n" + ex.StackTrace,
|
||||
LogType.Error);
|
||||
Environment.FailFast(ex.Message + "\n" + ex.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Controls;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Partical.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Controls;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
@@ -17,40 +47,91 @@ namespace StgSharp
|
||||
{
|
||||
|
||||
ElementBuffer ebo;
|
||||
|
||||
ElementBuffer f_ebo;
|
||||
FrameBuffer fbo;
|
||||
Image i;
|
||||
PlainInstancingBuffer<ParticleOnPlain> buffer;
|
||||
RenderBuffer rbo;
|
||||
|
||||
ShaderProgram frameMainShader;
|
||||
ShaderProgram s;
|
||||
|
||||
TextureGL t;
|
||||
Uniform<int> texUniform;
|
||||
Uniform<float> time;
|
||||
VertexArray f_vao;
|
||||
VertexArray vao;
|
||||
|
||||
VertexBuffer f_vbo;
|
||||
VertexBuffer vbo;
|
||||
|
||||
Uniform<float> time;
|
||||
public ParticleRenderStream()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool IsContextSharable => true;
|
||||
|
||||
public Rectangle ButtonBounding
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public TextureProvider ButtonTextureProvider { get; private set; }
|
||||
|
||||
//render a controlling item
|
||||
public void AnotherMain(IEnumerable<PlainGeometryMesh> items)
|
||||
{
|
||||
//Console.WriteLine("Render Button Itself");
|
||||
|
||||
GL.BindFrameBuffer(FrameBufferTarget.All, GlHandle.Zero); //GL.Assert(true);
|
||||
GL.ClearColor(0.4f, TimePassed % 1.0f, 0f, 1.0f); //GL.Assert(true);
|
||||
GL.Clear(MaskBufferBit.COLOR /**/| MaskBufferBit.DEPTH/**/); //GL.Assert(true);
|
||||
|
||||
f_vao.Bind(0); //GL.Assert(true);
|
||||
|
||||
foreach (PlainGeometryMesh mesh in items)
|
||||
{
|
||||
f_t.LoadTexture(0, mesh.TextureImage);
|
||||
}
|
||||
//GL.Assert(true);
|
||||
|
||||
frameMainShader.Use(); //GL.Assert(true);
|
||||
|
||||
GL.DrawElements(GeometryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero);
|
||||
//GL.Assert(true);
|
||||
|
||||
//GL.DrawElements(GeometryType.LINES, 6, TypeCode.UInt32, IntPtr.Zero);
|
||||
//BlueprintPipeline.SkipAll(output);
|
||||
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
public void RenderButton(ButtonStatus status, float statusBegin, in TextureProvider provider)
|
||||
{
|
||||
provider.UpdateFromImage(i);
|
||||
}
|
||||
|
||||
internal static vec3d DefaultRotation(TimeSpanProvider provider, out float rotation)
|
||||
{
|
||||
rotation = provider.SpanLengthLowPrecession;
|
||||
float angle = provider.CurrentSecond * 2;
|
||||
return (new vec3d(
|
||||
Scaler.Cos(angle),
|
||||
Scaler.Sin(angle),
|
||||
0
|
||||
)) * provider.SpanLengthLowPrecession;
|
||||
}
|
||||
|
||||
protected override void CustomizeDeinit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static vec3d DefaultRotation(TimeSpanProvider provider, out float rotation)
|
||||
{
|
||||
rotation = provider.SpanLengthLowPrecession * 2 * Scaler.Pi;
|
||||
float angle = provider.CurrentSecond * 2 * Scaler.Pi;
|
||||
return new vec3d(
|
||||
Scaler.Cos(rotation),
|
||||
Scaler.Sin(rotation),
|
||||
0
|
||||
) * provider.SpanLengthLowPrecession;
|
||||
}
|
||||
|
||||
ShaderProgram frameMainShader;
|
||||
|
||||
protected override void CustomizeInit()
|
||||
{
|
||||
//GL.ClearError();
|
||||
//GL.Assert(true);
|
||||
|
||||
buffer = new PlainInstancingBuffer<ParticleOnPlain>();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
@@ -65,12 +146,14 @@ namespace StgSharp
|
||||
((IInstancing)p).Scale =
|
||||
Scaler.MinOf(i, t) * 0.15f;
|
||||
((IInstancing)p).Motion = new GeometryMotion(
|
||||
true, this.timeProvider,
|
||||
true, this._timeProvider,
|
||||
DefaultRotation)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
//GL.Assert(true);
|
||||
|
||||
//SetSizeLimit(800, 800, 800, 800);
|
||||
|
||||
s = CreateShaderProgram();
|
||||
@@ -78,11 +161,15 @@ namespace StgSharp
|
||||
Shader pvs = CreateShaderSegment(ShaderType.Vertex, 2);
|
||||
Shader pfs = CreateShaderSegment(ShaderType.Fragment, 2);
|
||||
|
||||
//GL.Assert(true);
|
||||
pvs.Compile(0, Shader.FromCodeFile("Shader\\particle.vert"));
|
||||
//GL.Assert(true);
|
||||
pvs.AttachTo(0, s);
|
||||
//GL.Assert(true);
|
||||
pfs.Compile(0, Shader.FromCodeFile("Shader\\particle.frag"));
|
||||
pfs.AttachTo(0, s);
|
||||
s.Link();
|
||||
//GL.Assert(true);
|
||||
|
||||
pvs.Compile(1, Shader.FromCodeFile("Shader\\fbo.vert"));
|
||||
pvs.AttachTo(1, frameMainShader);
|
||||
@@ -90,6 +177,7 @@ namespace StgSharp
|
||||
pfs.AttachTo(1, frameMainShader);
|
||||
frameMainShader.Link();
|
||||
|
||||
//GL.Assert(true);
|
||||
vbo = CreateVertexBuffer(3);
|
||||
vao = CreateVertexArray(1);
|
||||
ebo = CreateElementBuffer(1);
|
||||
@@ -103,6 +191,7 @@ namespace StgSharp
|
||||
-0.05f, 0.05f
|
||||
);
|
||||
|
||||
//GL.Assert(true);
|
||||
vao.Bind(0);
|
||||
vbo.WriteVectorData(0, rec.VertexStream, BufferUsage.StaticDraw);
|
||||
ebo.SetValue(0, rec.VertexIndices, BufferUsage.StaticDraw);
|
||||
@@ -141,97 +230,111 @@ namespace StgSharp
|
||||
GL.SetRenderBufferStorage(
|
||||
RenderBufferInternalFormat.Depth24_Stencil8, this.Size);
|
||||
|
||||
|
||||
//GL.Assert(true);
|
||||
t = CreateTexture(1);
|
||||
t.Bind2D(0);
|
||||
/**/
|
||||
GL.TextureImage2d<byte>(Texture2DTarget.Texture2D, 0, (int)ImageChannel.WithAlphaChannel,
|
||||
(uint)Width, (uint)Height, (int)ImageChannel.WithAlphaChannel, PixelChannelLayout.Byte, null);
|
||||
/**/
|
||||
t.Set2dWrapProperty(Wrap.Repeat, Wrap.Repeat);
|
||||
t.Set2dFilterProperty(Filter.Nearest, Filter.Nearest);
|
||||
|
||||
|
||||
//GL.Assert(true);
|
||||
GL.FrameBufferTexture2d(FrameBufferTarget.All, glAttachment.Color(0),
|
||||
Texture2DTarget.Texture2D, t[0], 0);
|
||||
|
||||
GL.CombineFrameBufferRenderBuffer(fbo[0], rbo[0]);
|
||||
//GL.Assert(true);
|
||||
GL.CombineFrameBufferRenderBuffer(FrameBufferAttachment.Stencil|FrameBufferAttachment.Depth, rbo[0]);
|
||||
|
||||
Console.WriteLine(GL.CheckFrameBufferStatus(FrameBufferTarget.All));
|
||||
|
||||
FrameBuffer.BindNull();
|
||||
|
||||
//GL.Assert(true);
|
||||
int streamLength = this.Width * this.Height * 4;
|
||||
byte[] imageStream = new byte[streamLength];
|
||||
i = Image.FromMemory(this.Size, ImageChannel.WithAlphaChannel, imageStream);
|
||||
|
||||
time = s.GetUniform<float>("time");
|
||||
|
||||
vec2d[] coordArray = {
|
||||
vec2d[] buttonTextureCoordArray = {
|
||||
(0f, 1f),
|
||||
(1f, 1f),
|
||||
(1f, 0f),
|
||||
(0f, 0f)
|
||||
};
|
||||
ButtonBounding = new Rectangle(
|
||||
-0.9f, 0.9f,
|
||||
0.9f, 0.9f,
|
||||
0.9f, -0.9f,
|
||||
-0.9f, -0.9f
|
||||
);
|
||||
|
||||
buttonTextureProvider = new TextureProvider(i,coordArray);
|
||||
//GL.Assert(true);
|
||||
ButtonTextureProvider = new TextureProvider(i, buttonTextureCoordArray);
|
||||
|
||||
f_vao = CreateVertexArray(1);
|
||||
f_vbo = CreateVertexBuffer(2);
|
||||
f_ebo = CreateElementBuffer(1);
|
||||
|
||||
//GL.Assert(true);
|
||||
f_vao.Bind(0);
|
||||
|
||||
f_ebo.Bind(0);
|
||||
f_ebo.SetValue(0, rec.VertexIndices, BufferUsage.StaticDraw);
|
||||
f_ebo.SetValue(0, ButtonBounding.VertexIndices, BufferUsage.StaticDraw);
|
||||
|
||||
//GL.Assert(true);
|
||||
f_vbo.Bind(0);
|
||||
f_vbo.WriteVectorData(0, rec.VertexStream, BufferUsage.StaticDraw);
|
||||
f_vbo.WriteVectorData(0, ButtonBounding.VertexStream, BufferUsage.StaticDraw);
|
||||
f_vao.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
|
||||
//GL.Assert(true);
|
||||
f_vbo.Bind(1);
|
||||
f_vbo.WriteVectorData(1, coordArray, BufferUsage.StaticDraw);
|
||||
f_vbo.WriteVectorData(1, buttonTextureCoordArray, BufferUsage.StaticDraw);
|
||||
f_vao.SetVertexAttribute(1, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
|
||||
//GL.Assert(true);
|
||||
f_t = CreateTexture(1);
|
||||
f_t.Bind2D(0);
|
||||
f_t.Set2dWrapProperty(Wrap.Repeat, Wrap.Repeat);
|
||||
f_t.Set2dFilterProperty(Filter.Nearest, Filter.Nearest);
|
||||
|
||||
t = CreateTexture(1);
|
||||
t.Bind2D(0);
|
||||
t.Set2dWrapProperty(Wrap.Repeat, Wrap.Repeat);
|
||||
t.Set2dFilterProperty(Filter.Nearest, Filter.Nearest);
|
||||
|
||||
t.ActivateAs(TextureUnit.Unit0);
|
||||
//GL.Assert(true);
|
||||
f_t.ActivateAs(TextureUnit.Unit1);
|
||||
|
||||
//GL.Assert(true);
|
||||
frameMainShader.Use();
|
||||
texUniform = frameMainShader.GetUniform<int>("tex");
|
||||
//GL.Assert(true);
|
||||
GL.SetUniformValue(texUniform, 1);
|
||||
//GL.Assert(true);
|
||||
|
||||
}
|
||||
|
||||
VertexBuffer f_vbo;
|
||||
VertexArray f_vao;
|
||||
ElementBuffer f_ebo;
|
||||
Uniform<int> texUniform;
|
||||
|
||||
public void RenderButton(ButtonStatus status, float statusBegin, in TextureProvider provider)
|
||||
{
|
||||
provider.ReadImage(i);
|
||||
}
|
||||
TextureGL f_t;
|
||||
|
||||
protected override void Main()
|
||||
{
|
||||
//GL.ClearError();
|
||||
//Console.Clear();
|
||||
//Console.WriteLine($"{Width} {Height}");
|
||||
buffer.UpdateAllParticles();
|
||||
|
||||
//Console.WriteLine(GL.CheckFrameBufferStatus(FrameBufferTarget.All));
|
||||
|
||||
fbo.Bind(0); // Console.Write($"{GL.GetError()}\t");
|
||||
vao.Bind(0); // Console.Write($"{GL.GetError()}\t");
|
||||
t.Bind2D(0); // Console.Write($"{GL.GetError()}\t");
|
||||
fbo.Bind(0); //GL.Assert(true);
|
||||
vao.Bind(0); //GL.Assert(true);
|
||||
t.Bind2D(0); //GL.Assert(true);
|
||||
/**/
|
||||
|
||||
GL.TextureImage2d(Texture2DTarget.Texture2D, 0, (int)ImageChannel.WithAlphaChannel,
|
||||
(uint)Width, (uint)Height, (int)ImageChannel.WithAlphaChannel, PixelChannelLayout.Byte, new byte[1]);
|
||||
/**/
|
||||
|
||||
//Console.Write($"{GL.GetError()}\t");
|
||||
//GL.Assert(true);
|
||||
|
||||
GL.ClearColor((0.6f + TimePassed) % 1.0f, 0.1f, 0.3f, 1);
|
||||
GL.Clear(MaskBufferBit.COLOR | MaskBufferBit.DEPTH);
|
||||
|
||||
//Console.Write($"{GL.GetError()}\t");
|
||||
//GL.Assert(true);
|
||||
|
||||
vbo.Bind(1);
|
||||
vbo.WriteVectorData<vec4d>(1, buffer.CoordAndRotationSpan, BufferUsage.StreamDraw);
|
||||
@@ -245,14 +348,14 @@ namespace StgSharp
|
||||
GeometryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero, 100
|
||||
);
|
||||
//Console.WriteLine(TimePassed);
|
||||
//Console.Write($"{GL.GetError()}\t");
|
||||
//GL.Assert(true);
|
||||
|
||||
GL.WaitAccomplishment();
|
||||
GL.BindVertexArray(GlHandle.Zero);
|
||||
/**/
|
||||
//Console.Write($"{GL.GetError()}\t");
|
||||
//GL.Assert(true);
|
||||
|
||||
ImageHelper.Resize(i, this.Width, this.Height, ImageMovement.Discard);
|
||||
ImageHelper.Resize(i, Width, Height, ImageMovement.Discard);
|
||||
|
||||
//GL.ClearError();
|
||||
|
||||
@@ -264,12 +367,12 @@ namespace StgSharp
|
||||
Console.Write($"{i.PixelBuffer[num]}\t");
|
||||
}
|
||||
/**/
|
||||
//Console.Write($"{GL.GetError()}\t");
|
||||
//GL.Assert(true);
|
||||
//Array.Fill<byte>(i.PixelBuffer, 24);
|
||||
|
||||
GL.BindFrameBuffer(FrameBufferTarget.All, GlHandle.Zero);
|
||||
|
||||
//Console.Write($"{GL.GetError()}\t");
|
||||
//GL.Assert(true);
|
||||
/**/
|
||||
|
||||
/*
|
||||
@@ -279,34 +382,5 @@ namespace StgSharp
|
||||
/**/
|
||||
}
|
||||
|
||||
public void AnotherMain(IEnumerable<PlainGeometryMesh> items)
|
||||
{
|
||||
GL.BindFrameBuffer(FrameBufferTarget.All, GlHandle.Zero); //Console.Write($"{GL.GetError()}\t");
|
||||
GL.ClearColor(0.4f, TimePassed % 1.0f, 0f, 1.0f); //Console.Write($"{GL.GetError()}\t");
|
||||
GL.Clear(MaskBufferBit.COLOR /**/| MaskBufferBit.DEPTH/**/); //Console.Write($"{GL.GetError()}\t");
|
||||
|
||||
vao.Bind(0); //Console.Write($"{GL.GetError()}\t");
|
||||
|
||||
foreach (PlainGeometryMesh mesh in items)
|
||||
{
|
||||
t.LoadTexture(0, mesh.TextureImage);
|
||||
}
|
||||
//Console.Write($"{GL.GetError()}\t");
|
||||
|
||||
s.Use(); //Console.Write($"{GL.GetError()}\t");
|
||||
|
||||
|
||||
GL.DrawElements(GeometryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero);
|
||||
//Console.Write($"{GL.GetError()}\t");
|
||||
|
||||
//GL.DrawElements(GeometryType.LINES, 6, TypeCode.UInt32, IntPtr.Zero);
|
||||
//BlueprintPipeline.SkipAll(output);
|
||||
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
TextureProvider buttonTextureProvider;
|
||||
|
||||
public override bool IsContextSharable => true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using StgSharp.Controlling.UsrActivity;
|
||||
using StgSharp.MVVM.View;
|
||||
using StgSharp.Controlling.UsrActivity;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,19 +8,25 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public class Control : ViewResponder<ViewMain>
|
||||
{
|
||||
public partial class ViewMain
|
||||
{
|
||||
|
||||
|
||||
public override void CustomizedInitialize(Func<ITrigger, string, Action> keyRegister)
|
||||
protected class Control : ViewResponder<ViewMain>
|
||||
{
|
||||
public Control(ViewMain view):base(view)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public override void CustomizedInitialize(Func<ITrigger, string, Action> keyRegister)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool ValidateInitializing()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
public override bool ValidateInitializing()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Controlling;
|
||||
using StgSharp.Controlling.UsrActivity;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,21 +8,45 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using StgSharp.Controls;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Runtime.CompilerServices;
|
||||
using StgSharp.Geometries;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal class Design : ViewDesigner<ViewMain>
|
||||
public partial class ViewMain
|
||||
{
|
||||
DemoButtonGroup group;
|
||||
internal DemoButtonGroup Group { get; set; }
|
||||
internal TriggerButton OnlyButton { get; set; }
|
||||
|
||||
public override sealed void CustomizedInitialize()
|
||||
internal class Design : ViewDesigner<ViewMain>
|
||||
{
|
||||
group = new DemoButtonGroup();
|
||||
}
|
||||
public Design(ViewMain view):base(view)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool ValidateInitializing()
|
||||
{
|
||||
return true;
|
||||
public override sealed void CustomizedInitialize()
|
||||
{
|
||||
Binding.Group = CreateKeyboardButtonGroup<DemoButtonGroup>(
|
||||
new KeyTrigger(KeyboardKey.LEFT,KeyStatus.PRESS),
|
||||
new KeyTrigger(KeyboardKey.RIGHT, KeyStatus.PRESS),
|
||||
new KeyTrigger(KeyboardKey.UP, KeyStatus.PRESS),
|
||||
new KeyTrigger(KeyboardKey.DOWN, KeyStatus.PRESS),
|
||||
new KeyTrigger(KeyboardKey.ENTER, KeyStatus.PRESS)
|
||||
);
|
||||
Binding.OnlyButton = CreateKeyboardButton(
|
||||
Binding.Stream.ButtonBounding,
|
||||
Binding.Stream.ButtonTextureProvider,
|
||||
true
|
||||
);
|
||||
Binding.OnlyButton.RenderButtonTexture += Binding.Stream.RenderButton;
|
||||
}
|
||||
|
||||
public override bool ValidateInitializing()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +56,5 @@ namespace StgSharp
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using StgSharp.Graphics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public partial class ViewMain
|
||||
{
|
||||
public ParticleRenderStream Stream { get; set; }
|
||||
|
||||
|
||||
private class NewRender : ViewRender<ViewMain>
|
||||
{
|
||||
public NewRender(ViewMain view):base(view)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CustomizedInitialize()
|
||||
{
|
||||
Binding.Stream = CreateRenderStream<ParticleRenderStream>((1,1,1));
|
||||
}
|
||||
|
||||
public override bool ValidateInitializing()
|
||||
{
|
||||
return Binding.Stream != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Logic;
|
||||
|
||||
using StgSharpDebug.Logic;
|
||||
using StgSharp.MVVM;
|
||||
using StgSharp.MVVM.View;
|
||||
using StgSharp.MVVM.ViewModel;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -11,30 +12,51 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public class ViewMain : View
|
||||
public partial class ViewMain : ViewBase
|
||||
{
|
||||
public DemoButtonGroup DemoGroup
|
||||
public ViewMain()
|
||||
{
|
||||
get; set;
|
||||
_databindingIndexMap = new Dictionary<string, DataBindingEntry>();
|
||||
}
|
||||
|
||||
Dictionary<string, DataBindingEntry> _databindingIndexMap;
|
||||
|
||||
public override void CustomizedInitialize(ViewModelBase viewModelBinding)
|
||||
{
|
||||
Designer = new Design();
|
||||
Responder = new Control();
|
||||
Render = new Render();
|
||||
Designer = new Design(this);
|
||||
Responder = new Control(this);
|
||||
Render = new NewRender(this);
|
||||
|
||||
DemoGroup = new DemoButtonGroup();
|
||||
Render.Initialize();
|
||||
Designer.Initialize();
|
||||
Responder.Initialize(viewModelBinding.MethodLookup);
|
||||
}
|
||||
|
||||
public override bool TryGetObjectReference(string name, out DataBindingEntry entry)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (_databindingIndexMap.TryGetValue(name,out entry))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
try
|
||||
{
|
||||
entry = name switch
|
||||
{
|
||||
_ => default(DataBindingEntry),
|
||||
};
|
||||
return !entry.ExactEqual(default(DataBindingEntry));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
entry = default(DataBindingEntry);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal protected override void Show()
|
||||
protected internal override void Show()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
Stream.Draw();
|
||||
Stream.AnotherMain(OnlyButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.MVVM.ViewModel;
|
||||
using StgSharp.MVVM;
|
||||
|
||||
using StgSharpDebug.Logic;
|
||||
|
||||
|
||||
@@ -9,5 +9,5 @@ uniform sampler2D tex;
|
||||
void main()
|
||||
{
|
||||
fragColor = texture(tex, texCoord.xy);
|
||||
//fragColor = vec4(0.0f,0.0f,0.0f,0.0f);
|
||||
//fragColor = vec4(0.099f,0.226f,0.335f,0.0f);
|
||||
}
|
||||
@@ -22,43 +22,53 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<Optimize>True</Optimize>
|
||||
<Optimize>False</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Benchmark|AnyCPU'">
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Toollist|AnyCPU'">
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RealDebug|AnyCPU'">
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Optimize>True</Optimize>
|
||||
<Optimize>False</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Benchmark|x64'">
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Toollist|x64'">
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RealDebug|x64'">
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpDebug")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+924fe6eef7b6b9441b297f211c82b4684f23d002")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+da75200347e2ff7f483c83ff224678d05b0aefd1")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharpDebug")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharpDebug")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/924fe6eef7b6b9441b297f211c82b4684f23d002/*"}}
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/da75200347e2ff7f483c83ff224678d05b0aefd1/*"}}
|
||||
@@ -26,7 +26,7 @@ namespace StgsharpEnvDebug
|
||||
}
|
||||
|
||||
/*
|
||||
public sealed class DemoForm : View
|
||||
public sealed class DemoForm : ViewBase
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgsharpEnvDebug")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+924fe6eef7b6b9441b297f211c82b4684f23d002")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+da75200347e2ff7f483c83ff224678d05b0aefd1")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgsharpEnvDebug")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgsharpEnvDebug")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
Reference in New Issue
Block a user