daily update on 20240513 by nitload youmu, instancing render added
This commit is contained in:
@@ -120,7 +120,7 @@ namespace StgSharp.Graphics
|
||||
STENCIL = GLconst.STENCIL_BUFFER_BIT,
|
||||
}
|
||||
|
||||
public enum GepmetryType : uint
|
||||
public enum GeometryType : uint
|
||||
{
|
||||
POINTS = 0x0000,
|
||||
LINES = 0x0001,
|
||||
|
||||
@@ -52,46 +52,20 @@ namespace StgSharp.Graphics
|
||||
private int _frameCount;
|
||||
private int _frameSpeed;
|
||||
|
||||
private short fpsCount;
|
||||
|
||||
private IntPtr windowID;
|
||||
|
||||
internal LinkedList<Control> allControl;
|
||||
internal Vector4 backgroundColor;
|
||||
internal TimeSpanProvider fpsCountProvider;
|
||||
internal TimeSpanProvider frameTimeProvider;
|
||||
private short fpsCount;
|
||||
internal Form sharedForm;
|
||||
|
||||
internal int height;
|
||||
internal IntPtr monitor;
|
||||
internal string name;
|
||||
internal Form sharedForm;
|
||||
internal int width;
|
||||
internal IntPtr monitor;
|
||||
|
||||
public Form()
|
||||
{
|
||||
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
|
||||
_frameSpeed = 0;
|
||||
_frameCount = 0;
|
||||
fpsCountProvider.SpanRefreshCallback =
|
||||
() =>
|
||||
{
|
||||
Interlocked.Exchange(ref _frameSpeed, _frameCount);
|
||||
Interlocked.Exchange(ref _frameCount, 0);
|
||||
Console.Clear();
|
||||
Console.WriteLine(_frameSpeed);
|
||||
};
|
||||
frameTimeProvider = new TimeSpanProvider(
|
||||
1000L * 1000L / 60, TimeSpanProvider.DefaultProvider
|
||||
);
|
||||
frameTimeProvider.SpanRefreshCallback =
|
||||
() =>
|
||||
{
|
||||
};
|
||||
height = 800;
|
||||
width = 600;
|
||||
name = new StackFrame(1, false).
|
||||
GetMethod()!.DeclaringType!.Name;
|
||||
}
|
||||
internal LinkedList<Control> allControl;
|
||||
internal string name;
|
||||
internal TimeSpanProvider fpsCountProvider;
|
||||
internal TimeSpanProvider frameTimeProvider;
|
||||
internal Vector4 backgroundColor;
|
||||
|
||||
protected Form((int width, int height) size, string name)
|
||||
{
|
||||
@@ -107,7 +81,7 @@ namespace StgSharp.Graphics
|
||||
Console.WriteLine(_frameSpeed);
|
||||
};
|
||||
frameTimeProvider = new TimeSpanProvider(
|
||||
1000L * 1000L / 60, TimeSpanProvider.DefaultProvider
|
||||
(1000L * 1000L) / 60, TimeSpanProvider.DefaultProvider
|
||||
);
|
||||
frameTimeProvider.SpanRefreshCallback =
|
||||
() =>
|
||||
@@ -118,6 +92,32 @@ namespace StgSharp.Graphics
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Form()
|
||||
{
|
||||
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
|
||||
_frameSpeed = 0;
|
||||
_frameCount = 0;
|
||||
fpsCountProvider.SpanRefreshCallback =
|
||||
() =>
|
||||
{
|
||||
Interlocked.Exchange(ref _frameSpeed, _frameCount);
|
||||
Interlocked.Exchange(ref _frameCount, 0);
|
||||
Console.Clear();
|
||||
Console.WriteLine(_frameSpeed);
|
||||
};
|
||||
frameTimeProvider = new TimeSpanProvider(
|
||||
(1000L * 1000L) / 60, TimeSpanProvider.DefaultProvider
|
||||
);
|
||||
frameTimeProvider.SpanRefreshCallback =
|
||||
() =>
|
||||
{
|
||||
};
|
||||
height = 800;
|
||||
width = 600;
|
||||
name = new StackFrame(1, false).
|
||||
GetMethod()!.DeclaringType!.Name;
|
||||
}
|
||||
|
||||
public int CurrentFrameCount => frameTimeProvider.CurrentSpan;
|
||||
public int FrameSpeed => _frameSpeed;
|
||||
|
||||
@@ -178,13 +178,14 @@ namespace StgSharp.Graphics
|
||||
|
||||
|
||||
public unsafe IntPtr WindowID
|
||||
{
|
||||
{
|
||||
get => windowID;
|
||||
internal set => windowID = value;
|
||||
}
|
||||
|
||||
internal unsafe IntPtr id => windowID;
|
||||
|
||||
#pragma warning disable CA1044
|
||||
protected FrameBufferSizeHandler FrameSizeCallback
|
||||
{
|
||||
set
|
||||
@@ -193,8 +194,26 @@ namespace StgSharp.Graphics
|
||||
InternalIO.glfwSetFramebufferSizeCallback(windowID, handlerPtr);
|
||||
}
|
||||
}
|
||||
#pragma warning restore CA1044
|
||||
|
||||
#region Key Control
|
||||
|
||||
protected KeyStatus CheckKey(KeyboardKey key)
|
||||
{
|
||||
return InternalIO.glfwGetKey(this.WindowID,(int)key);
|
||||
}
|
||||
|
||||
protected KeyStatus CheckKey(Mouse key)
|
||||
{
|
||||
return InternalIO.glfwGetKey(this.WindowID, (int)key);
|
||||
}
|
||||
|
||||
protected KeyStatus CheckKey(Joystick key)
|
||||
{
|
||||
return InternalIO.glfwGetKey(this.WindowID, (int)key);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Set all necessary metadata to current form instance
|
||||
@@ -251,9 +270,9 @@ namespace StgSharp.Graphics
|
||||
/// <param name="maxHeight">Maximum height of current form</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
|
||||
{
|
||||
{
|
||||
//TODO 重做form的尺寸极限控制
|
||||
InternalIO.glfwSetWindowSizeLimits(this.windowID, minWidth, minHeight, maxWidth, maxHeight);
|
||||
InternalIO.glfwSetWindowSizeLimits(this.windowID, minWidth, minHeight, maxWidth, maxHeight);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,7 +61,8 @@ namespace StgSharp.Graphics
|
||||
/// <param name="index">Index to find certain VBO in this instance</param>
|
||||
/// <param name="bufferData">Data to write in</param>
|
||||
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
|
||||
public void SetValue<T>(int index, T bufferData, BufferUsage usage) where T : struct, IMat
|
||||
public void WriteMatrixData<T>(int index, T bufferData, BufferUsage usage)
|
||||
where T : struct, IMat
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferData, usage);
|
||||
@@ -72,14 +73,65 @@ namespace StgSharp.Graphics
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of bufferData</typeparam>
|
||||
/// <param name="index">Index to find certain VBO in this instance</param>
|
||||
/// <param name="bufferArray">A array of data to write in</param>
|
||||
/// <param name="bufferArray">Data to write in</param>
|
||||
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
|
||||
public void SetValueArray<T>(int index, T[] bufferArray, BufferUsage usage) where T : struct, IConvertible
|
||||
public void WriteScalerData<T>(int index, T[] bufferArray, BufferUsage usage)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferArray, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex buffer object
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of bufferData</typeparam>
|
||||
/// <param name="index">Index to find certain VBO in this instance</param>
|
||||
/// <param name="scalerSpan">A <see cref="Span{T}"/> of data to write in</param>
|
||||
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
|
||||
public void WriteScalerData<T>(int index, Span<T> scalerSpan, BufferUsage usage)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ARRAY_BUFFER, scalerSpan, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex buffer object
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of bufferData</typeparam>
|
||||
/// <param name="index">Index to find certain VBO in this instance</param>
|
||||
/// <param name="vectorSpan">A <see cref="Span{T}"/> of data to write in</param>
|
||||
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
|
||||
public void WriteVectorData<T>(int index, Span<T> vectorSpan, BufferUsage usage) where T : struct, IVector
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferVectorData(BufferType.ARRAY_BUFFER, vectorSpan, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex buffer object
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of bufferData</typeparam>
|
||||
/// <param name="index">Index to find certain VBO in this instance</param>
|
||||
/// <param name="vectorArray">A array of data to write in</param>
|
||||
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
|
||||
public void WriteVectorData<T>(int index, T[] vectorArray, BufferUsage usage) where T : struct, IVector
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferVectorData(BufferType.ARRAY_BUFFER, vectorArray, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
|
||||
@@ -38,6 +39,15 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal static unsafe partial class InternalIO
|
||||
{
|
||||
[DllImport(SSC_libName, EntryPoint = "glCheckShaderStat",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern int glCheckShaderStatus(ref GLcontext context, uint shaderHandle,int key, ref IntPtr logPtr);
|
||||
}
|
||||
}
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
internal static unsafe partial class GL
|
||||
@@ -86,6 +96,16 @@ namespace StgSharp.Graphics
|
||||
Context.glBindBuffer((uint)bufferType, handle.Value);
|
||||
}
|
||||
|
||||
public static string GetShaderStatus(Shader s, int index, int key)
|
||||
{
|
||||
IntPtr sptr = IntPtr.Zero;
|
||||
if (InternalIO.glCheckShaderStatus(ref Context, s.handle[index].Value, key,ref sptr) == 0)
|
||||
{
|
||||
return Marshal.PtrToStringAnsi(sptr);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bind a frame buffer to a frame buffer target
|
||||
/// Same function as <see href="https://docs.gl/gl3/glBindFramebuffer">glBindFramebuffer</see>.
|
||||
@@ -105,13 +125,18 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindVertexArray(glHandle handle)
|
||||
{
|
||||
Context.glBindVertexArray(handle.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void VertexAttributeDivisor(uint layoutIndex, uint divisor)
|
||||
{
|
||||
Context.glVertexAttribDivisor(layoutIndex, divisor);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Clear(MaskBufferBit mask)
|
||||
{
|
||||
@@ -225,7 +250,7 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void DrawElements(GepmetryType mode, uint count, TypeCode type, IntPtr ptr)
|
||||
public static unsafe void DrawElements(GeometryType mode, uint count, TypeCode type, IntPtr ptr)
|
||||
{
|
||||
uint a;
|
||||
switch (type)
|
||||
@@ -251,6 +276,35 @@ namespace StgSharp.Graphics
|
||||
Context.glDrawElements((uint)mode, count, a, (void*)ptr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void DrawElementsInstanced(
|
||||
GeometryType mode , uint count, TypeCode type, IntPtr ptr, uint amount
|
||||
)
|
||||
{
|
||||
uint a;
|
||||
switch (type)
|
||||
{
|
||||
case TypeCode.UInt32:
|
||||
a = GLconst.UNSIGNED_INT;
|
||||
break;
|
||||
|
||||
case TypeCode.UInt16:
|
||||
a = GLconst.UNSIGNED_SHORT;
|
||||
break;
|
||||
|
||||
case TypeCode.Byte:
|
||||
a = GLconst.UNSIGNED_BYTE;
|
||||
break;
|
||||
|
||||
default:
|
||||
InternalIO.InternalWriteLog(
|
||||
$"{$"Parameter error in parameter {nameof(type)} method DrawElements. "}{$"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are supported."}",
|
||||
LogType.Error);
|
||||
return;
|
||||
}
|
||||
Context.glDrawElementsInstanced((uint)mode, count, a, (void*)ptr,amount);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Enable(GLOperation operation)
|
||||
{
|
||||
@@ -327,9 +381,12 @@ namespace StgSharp.Graphics
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
|
||||
where T : struct
|
||||
{
|
||||
int size = Marshal.SizeOf<T>();
|
||||
#pragma warning disable CS8500
|
||||
T* p = &bufferData;
|
||||
#pragma warning restore CS8500
|
||||
Context.glBufferData(
|
||||
(uint)bufferType,
|
||||
(IntPtr)size,
|
||||
@@ -339,13 +396,91 @@ namespace StgSharp.Graphics
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
|
||||
if (bufferArray == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#pragma warning disable CS8500
|
||||
fixed (void* bufferPtr = bufferArray)
|
||||
#pragma warning restore CS8500
|
||||
{
|
||||
Context.glBufferData(
|
||||
(uint)bufferType,
|
||||
(IntPtr)size,
|
||||
(IntPtr)bufferPtr,
|
||||
(uint)usage);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferData<T>(BufferType bufferType, Span<T> bufferArray, BufferUsage usage)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
|
||||
if (bufferArray == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#pragma warning disable CS8500
|
||||
fixed (void* bufferPtr = &bufferArray.GetPinnableReference())
|
||||
#pragma warning restore CS8500
|
||||
{
|
||||
Context.glBufferData(
|
||||
(uint)bufferType,
|
||||
(IntPtr)size,
|
||||
(IntPtr)bufferPtr,
|
||||
(uint)usage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferVectorData<T>(BufferType bufferType, Span<T> bufferArray, BufferUsage usage)
|
||||
where T : struct, IVector
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
|
||||
if (bufferArray == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#pragma warning disable CS8500
|
||||
fixed (void* bufferPtr = &bufferArray.GetPinnableReference())
|
||||
#pragma warning restore CS8500
|
||||
{
|
||||
Context.glBufferData(
|
||||
(uint)bufferType,
|
||||
(IntPtr)size,
|
||||
(IntPtr)bufferPtr,
|
||||
(uint)usage);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferVectorData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
|
||||
where T : struct, IVector
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
|
||||
if (bufferArray == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#pragma warning disable CS8500
|
||||
fixed (void* bufferPtr = bufferArray)
|
||||
#pragma warning restore CS8500
|
||||
{
|
||||
Context.glBufferData(
|
||||
(uint)bufferType,
|
||||
|
||||
@@ -33,9 +33,11 @@ using StgSharp.Data;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
@@ -85,6 +87,16 @@ namespace StgSharp.Graphics
|
||||
GL.AttachShader(target.handle, handle[index]);
|
||||
}
|
||||
|
||||
public static string FromCodeFile(string fileRoute)
|
||||
{
|
||||
string str = File.ReadAllText(fileRoute);
|
||||
if (str == "")
|
||||
{
|
||||
throw new Exception($"Cannot load and GLSL code from {fileRoute}");
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Compile(int index, string code)
|
||||
{
|
||||
@@ -94,6 +106,7 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
GL.LoadShaderSource(handle[index], $"{code}\0");
|
||||
GL.CompileShader(handle[index]);
|
||||
CheckStatus(index,ShaderStatus.CompileStatus);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
@@ -107,6 +120,15 @@ namespace StgSharp.Graphics
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void CheckStatus(int index, ShaderStatus status)
|
||||
{
|
||||
string log = GL.GetShaderStatus(this,index, (int)status);
|
||||
if (log != "")
|
||||
{
|
||||
throw new Exception($"Shader Error\n{status}\n" + log);
|
||||
}
|
||||
}
|
||||
|
||||
public override byte[] GetBytes(out int length)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -118,6 +140,11 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
public enum ShaderStatus : int
|
||||
{
|
||||
CompileStatus = GLconst.COMPILE_STATUS,
|
||||
}
|
||||
|
||||
public class ShaderProgram
|
||||
{
|
||||
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Logic;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glRenderStream.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -11,12 +41,19 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public abstract partial class glRenderStream: RenderStream
|
||||
public abstract partial class glRenderStream : RenderStream
|
||||
{
|
||||
|
||||
protected glRenderStream(RenderStreamConstructArgs args) : base(args)
|
||||
{
|
||||
}
|
||||
|
||||
protected IntPtr glContextHandle
|
||||
{
|
||||
get { return ContextHandle; }
|
||||
set { ContextHandle = value; }
|
||||
}
|
||||
|
||||
public static T AsMainStreamOf<T>(Form f, (int x, int y, int z) unitCubeSize) where T : glRenderStream
|
||||
{
|
||||
RenderStreamConstructArgs args = new RenderStreamConstructArgs();
|
||||
@@ -30,38 +67,6 @@ namespace StgSharp.Graphics
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected sealed override void NativeCameraViewTarget(vec3d position, vec3d direction, vec3d up)
|
||||
{
|
||||
NativeCamera.SetViewDirection(position, direction, up);
|
||||
}
|
||||
|
||||
protected sealed override Uniform<Matrix44> NativeCameraUniform(ShaderProgram source, string name)
|
||||
{
|
||||
NativeCamera.GainAllUniforms(source, name);
|
||||
return NativeCamera.convertedUniform;
|
||||
}
|
||||
|
||||
protected IntPtr glContextHandle
|
||||
{
|
||||
get { return ContextHandle; }
|
||||
set { ContextHandle = value; }
|
||||
}
|
||||
|
||||
internal unsafe sealed override void CreateCanvas()
|
||||
{
|
||||
byte[] nameCode = Encoding.UTF8.GetBytes(name);
|
||||
CanvasHandle = InternalIO.glfwCreateWindow(
|
||||
Width,Height,nameCode,Monitor,IntPtr.Zero
|
||||
);
|
||||
NativeCamera = new Camera();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override void NativeCameraViewRange(Radius fieldOfRange,vec2d offset, (float frontDepth, float backDepth) viewDepth)
|
||||
{
|
||||
NativeCamera.SetViewRange(fieldOfRange,this.Size, offset, viewDepth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Init an OpenGl context if current form has not been binded to any context. and set the context binded to
|
||||
/// current form as current OpenGL context.
|
||||
@@ -90,7 +95,25 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
InternalIO.glfwSetWindowSizeLimits(this.CanvasHandle, minWidth, minHeight, maxWidth, maxHeight);
|
||||
}
|
||||
internal sealed override void InternalInit()
|
||||
|
||||
internal override sealed unsafe void CreateCanvas()
|
||||
{
|
||||
byte[] nameCode = Encoding.UTF8.GetBytes(name);
|
||||
CanvasHandle = InternalIO.glfwCreateWindow(
|
||||
Width, Height, nameCode, Monitor, IntPtr.Zero
|
||||
);
|
||||
NativeCamera = new Camera();
|
||||
}
|
||||
|
||||
internal override sealed void InternalDraw(
|
||||
in Dictionary<string, BlueprintPipeline> input,
|
||||
in Dictionary<string, BlueprintPipeline> output)
|
||||
{
|
||||
MakeAsCurrentContext();
|
||||
ProcessInput();
|
||||
Main(in input, in output);
|
||||
}
|
||||
internal override sealed void InternalInit()
|
||||
{
|
||||
CreateCanvas();
|
||||
MakeAsCurrentContext();
|
||||
@@ -98,21 +121,56 @@ namespace StgSharp.Graphics
|
||||
Init();
|
||||
}
|
||||
|
||||
internal sealed override void InternalDraw(
|
||||
in Dictionary<string, BlueprintPipeline> input,
|
||||
in Dictionary<string, BlueprintPipeline> output)
|
||||
{
|
||||
MakeAsCurrentContext();
|
||||
ProcessInput();
|
||||
Main(in input, in output);
|
||||
InternalIO.glfwSwapBuffers(CanvasHandle);
|
||||
InternalIO.glfwPollEvents();
|
||||
}
|
||||
|
||||
internal sealed override void InternalTerminate()
|
||||
internal override sealed void InternalTerminate()
|
||||
{
|
||||
Deinit();
|
||||
}
|
||||
|
||||
protected override sealed Uniform<Matrix44> NativeCameraUniform(ShaderProgram source, string name)
|
||||
{
|
||||
NativeCamera.GainAllUniforms(source, name);
|
||||
return NativeCamera.convertedUniform;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected override sealed void NativeCameraViewRange(Radius fieldOfRange, vec2d offset, (float frontDepth, float backDepth) viewDepth)
|
||||
{
|
||||
NativeCamera.SetViewRange(fieldOfRange, this.Size, offset, viewDepth);
|
||||
}
|
||||
|
||||
protected override sealed void NativeCameraViewTarget(vec3d position, vec3d direction, vec3d up)
|
||||
{
|
||||
NativeCamera.SetViewDirection(position, direction, up);
|
||||
}
|
||||
|
||||
protected static void PollEvents()
|
||||
{
|
||||
InternalIO.glfwPollEvents();
|
||||
}
|
||||
|
||||
protected void SwapBuffers()
|
||||
{
|
||||
InternalIO.glfwSwapBuffers(CanvasHandle);
|
||||
}
|
||||
|
||||
#region Key Control
|
||||
|
||||
protected KeyStatus CheckKey(KeyboardKey key)
|
||||
{
|
||||
return InternalIO.glfwGetKey(this.CanvasHandle, (int)key);
|
||||
}
|
||||
|
||||
protected KeyStatus CheckKey(Mouse key)
|
||||
{
|
||||
return InternalIO.glfwGetKey(this.CanvasHandle, (int)key);
|
||||
}
|
||||
|
||||
protected KeyStatus CheckKey(Joystick key)
|
||||
{
|
||||
return InternalIO.glfwGetKey(this.CanvasHandle, (int)key);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user