swiss ok, needs more benchmark

This commit is contained in:
Youmu Liu
2026-03-06 18:22:30 +08:00
parent 83997f64d0
commit f6e897ed06
70 changed files with 1889 additions and 3371 deletions
+39 -13
View File
@@ -58,7 +58,11 @@ namespace StgSharp.Mathematics.Graphics
_projection = new Matrix44();
}
public Camera(Vec3 position, Vec3 target, Vec3 up)
public Camera(
Vec3 position,
Vec3 target,
Vec3 up
)
: this()
{
rotationAtt = Matrix44.Unit;
@@ -103,13 +107,16 @@ namespace StgSharp.Mathematics.Graphics
/// Shader program requires this camera.
/// </param>
/// <param _label="uniformName">
/// ContextName of all related uniforms. If you fallow form from <see
/// ContextName of all related uniforms. If you fallow form from <see ///
/// cref="IglConvertable.DisplayGLtypeDefinition" />
/// </param>
/// <exception cref="ArgumentException">
///
/// </exception>
public unsafe void GainAllUniforms(ShaderProgram source, params string[] uniformName)
public unsafe void GainAllUniforms(
ShaderProgram source,
params string[] uniformName
)
{
if (uniformName is null || uniformName.Length != 1) {
throw new ArgumentException(
@@ -118,19 +125,25 @@ namespace StgSharp.Mathematics.Graphics
convertedUniform = source.GetUniform<Matrix44>(uniformName[0]);
}
public void MoveNear(float distance)
public void MoveNear(
float distance
)
{
cameraAtt.column[3].Z -= distance;
_isLookAtAvailable = false;
}
public void MoveRight(float distance)
public void MoveRight(
float distance
)
{
cameraAtt.column[3].X -= distance;
_isLookAtAvailable = false;
}
public void MoveUp(float distance)
public void MoveUp(
float distance
)
{
cameraAtt.column[3].Y -= distance;
_isLookAtAvailable = false;
@@ -142,7 +155,11 @@ namespace StgSharp.Mathematics.Graphics
OpenGLFunction.CurrentGL.SetUniformValue(convertedUniform, Projection * View);
}
public void SetViewDirection(Vec3 position, Vec3 target, Vec3 up)
public void SetViewDirection(
Vec3 position,
Vec3 target,
Vec3 up
)
{
Vec3 direction = position - target;
if ((position.reg == cameraAtt.column[3].reg) &&
@@ -181,7 +198,8 @@ namespace StgSharp.Mathematics.Graphics
Radius fovRadius,
Vec2 size,
Vec2 offset,
(float front, float back) depthRange)
(float front, float back) depthRange
)
{
float
distance = _target.GetLength(),
@@ -189,7 +207,7 @@ namespace StgSharp.Mathematics.Graphics
far = distance + depthRange.back,
offsetX = offset.X,
offsetY = offset.Y,
width = Scalar.Abs(GeometryScaler.Tan(fovRadius / 2) * near * 2),
width = MathF.Abs(GeometryScaler.Tan(fovRadius / 2) * near * 2),
height = width * size.Y / size.X;
_projection.column[0].X = 2 * near / width;
@@ -201,7 +219,9 @@ namespace StgSharp.Mathematics.Graphics
_projection.column[3].Z = 2 * near * far / (near - far);
}
public void Test(params Vec4[] vec)
public void Test(
params Vec4[] vec
)
{
Console.WriteLine(View);
Console.WriteLine(Projection);
@@ -221,7 +241,9 @@ namespace StgSharp.Mathematics.Graphics
#region rotation
public void Yaw(Radius r)
public void Yaw(
Radius r
)
{
_yaw -= r;
@@ -230,7 +252,9 @@ namespace StgSharp.Mathematics.Graphics
InternalYaw();
}
public void Pitch(Radius r)
public void Pitch(
Radius r
)
{
_pitch -= r;
@@ -239,7 +263,9 @@ namespace StgSharp.Mathematics.Graphics
InternalPitch();
}
public void Row(Radius r)
public void Row(
Radius r
)
{
_row -= r;
+29
View File
@@ -0,0 +1,29 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="Global"
// Project: StgSharp
// AuthorGroup: Nitload
// Copyright (c) Nitload. 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.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
global using StgSharp.Internal;
global using System;
@@ -66,7 +66,7 @@ namespace StgSharp.Graphics.OpenGL
}
public class Shader : ISSDSerializable
public class Shader
{
private readonly OpenGLFunction GL;
@@ -84,8 +84,6 @@ namespace StgSharp.Graphics.OpenGL
type = usage;
}
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.Shader;
/// <summary>
/// Attach one shader code to a shader program.
/// </summary>
+53 -49
View File
@@ -2,8 +2,8 @@
// -----------------------------------------------------------------------
// file="glApiManager"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
// AuthorGroup: Nitload
// Copyright (c) Nitload. 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
@@ -25,11 +25,9 @@
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.Internal;
using StgSharp.Mathematics;
using StgSharp.Mathematics;
using StgSharp.MVVM;
using StgSharp.MVVM;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -52,15 +50,15 @@ namespace StgSharp.Graphics.OpenGL
"OpenGL SC "
};
private static string glExtensionList;
/// <summary>
/// Load all supported OpenGL APIs and bind them to given <see cref="ViewPort" />.
/// </summary>
/// <param _label="contextHandle">
/// The handle to current OpenGL viewPortDisplay
/// </param>
public static unsafe void LoadOpenGLApiTo(IntPtr contextHandle)
public static unsafe void LoadOpenGLApiTo(
IntPtr contextHandle
)
{
OpenglContext* context = (OpenglContext*)contextHandle;
if (context->glGetString != null) {
@@ -81,12 +79,13 @@ namespace StgSharp.Graphics.OpenGL
if (context->glGetString(glVersion) == null) {
DefaultLog.InternalWriteLog("Failed to call glGetString", LogType.Error);
}
coreVersion = Marshal.PtrToStringAnsi((nint)context->glGetString(glVersion)) ?? string.Empty;
coreVersion = Marshal.PtrToStringAnsi((nint)context->glGetString(glVersion)) ??
string.Empty;
foreach (string branch in glBranch)
{
if (coreVersion.Contains(branch)) {
coreVersion.Replace(branch, string.Empty);
if (coreVersion.Contains(branch, StringComparison.Ordinal)) {
coreVersion.Replace(branch, string.Empty, StringComparison.Ordinal);
}
}
string[] versionSep = coreVersion!.Split('.');
@@ -163,182 +162,182 @@ namespace StgSharp.Graphics.OpenGL
if (extensions.Contains("gl_AMD_blend_minmax_factor"))
{
AMD_blend_minmax_factor = true;
extensions.Remove("glAMD_blend_minmax_factor");
extensions.Remove("gl_AMD_blend_minmax_factor");
}
if (extensions.Contains("gl_AMD_conservative_depth"))
{
AMD_conservative_depth = true;
extensions.Remove("glAMD_conservative_depth");
extensions.Remove("gl_AMD_conservative_depth");
}
if (extensions.Contains("gl_AMD_debug_output"))
{
AMD_debug_output = true;
extensions.Remove("glAMD_debug_output");
extensions.Remove("gl_AMD_debug_output");
}
if (extensions.Contains("gl_AMD_depth_clamp_separate"))
{
AMD_depth_clamp_separate = true;
extensions.Remove("glAMD_depth_clamp_separate");
extensions.Remove("gl_AMD_depth_clamp_separate");
}
if (extensions.Contains("gl_AMD_draw_buffers_blend"))
{
AMD_draw_buffers_blend = true;
extensions.Remove("glAMD_draw_buffers_blend");
extensions.Remove("gl_AMD_draw_buffers_blend");
}
if (extensions.Contains("gl_AMD_framebuffer_multisample_advanced"))
{
AMD_framebuffer_multisample_advanced = true;
extensions.Remove("glAMD_framebuffer_multisample_advanced");
extensions.Remove("gl_AMD_framebuffer_multisample_advanced");
}
if (extensions.Contains("gl_AMD_framebuffer_sample_positions"))
{
AMD_framebuffer_sample_positions = true;
extensions.Remove("glAMD_framebuffer_sample_positions");
extensions.Remove("gl_AMD_framebuffer_sample_positions");
}
if (extensions.Contains("gl_AMD_gcn_shader"))
{
AMD_gcn_shader = true;
extensions.Remove("glAMD_gcn_shader");
extensions.Remove("gl_AMD_gcn_shader");
}
if (extensions.Contains("gl_AMD_gpu_shader_half_float"))
{
AMD_gpu_shader_half_float = true;
extensions.Remove("glAMD_gpu_shader_half_float");
extensions.Remove("gl_AMD_gpu_shader_half_float");
}
if (extensions.Contains("gl_AMD_gpu_shader_int16"))
{
AMD_gpu_shader_int16 = true;
extensions.Remove("glAMD_gpu_shader_int16");
extensions.Remove("gl_AMD_gpu_shader_int16");
}
if (extensions.Contains("gl_AMD_gpu_shader_int64"))
{
AMD_gpu_shader_int64 = true;
extensions.Remove("glAMD_gpu_shader_int64");
extensions.Remove("gl_AMD_gpu_shader_int64");
}
if (extensions.Contains("gl_AMD_interleaved_elements"))
{
AMD_interleaved_elements = true;
extensions.Remove("glAMD_interleaved_elements");
extensions.Remove("gl_AMD_interleaved_elements");
}
if (extensions.Contains("gl_AMD_multi_draw_indirect"))
{
AMD_multi_draw_indirect = true;
extensions.Remove("glAMD_multi_draw_indirect");
extensions.Remove("gl_AMD_multi_draw_indirect");
}
if (extensions.Contains("gl_AMD_name_gen_delete"))
{
AMD_name_gen_delete = true;
extensions.Remove("glAMD_name_gen_delete");
extensions.Remove("gl_AMD_name_gen_delete");
}
if (extensions.Contains("gl_AMD_occlusion_query_event"))
{
AMD_occlusion_query_event = true;
extensions.Remove("glAMD_occlusion_query_event");
extensions.Remove("gl_AMD_occlusion_query_event");
}
if (extensions.Contains("gl_AMD_performance_monitor"))
{
AMD_performance_monitor = true;
extensions.Remove("glAMD_performance_monitor");
extensions.Remove("gl_AMD_performance_monitor");
}
if (extensions.Contains("gl_AMD_pinned_memory"))
{
AMD_pinned_memory = true;
extensions.Remove("glAMD_pinned_memory");
extensions.Remove("gl_AMD_pinned_memory");
}
if (extensions.Contains("gl_AMD_query_buffer_object"))
{
AMD_query_buffer_object = true;
extensions.Remove("glAMD_query_buffer_object");
extensions.Remove("gl_AMD_query_buffer_object");
}
if (extensions.Contains("gl_AMD_sample_positions"))
{
AMD_sample_positions = true;
extensions.Remove("glAMD_sample_positions");
extensions.Remove("gl_AMD_sample_positions");
}
if (extensions.Contains("gl_AMD_seamless_cubemap_per_texture"))
{
AMD_seamless_cubemap_per_texture = true;
extensions.Remove("glAMD_seamless_cubemap_per_texture");
extensions.Remove("gl_AMD_seamless_cubemap_per_texture");
}
if (extensions.Contains("gl_AMD_shader_atomic_counter_ops"))
{
AMD_shader_atomic_counter_ops = true;
extensions.Remove("glAMD_shader_atomic_counter_ops");
extensions.Remove("gl_AMD_shader_atomic_counter_ops");
}
if (extensions.Contains("gl_AMD_shader_ballot"))
{
AMD_shader_ballot = true;
extensions.Remove("glAMD_shader_ballot");
extensions.Remove("gl_AMD_shader_ballot");
}
if (extensions.Contains("gl_AMD_shader_explicit_vertex_parameter"))
{
AMD_shader_explicit_vertex_parameter = true;
extensions.Remove("glAMD_shader_explicit_vertex_parameter");
extensions.Remove("gl_AMD_shader_explicit_vertex_parameter");
}
if (extensions.Contains("gl_AMD_shader_gpu_shader_half_float_fetch"))
{
AMD_shader_gpu_shader_half_float_fetch = true;
extensions.Remove("glAMD_shader_gpu_shader_half_float_fetch");
extensions.Remove("gl_AMD_shader_gpu_shader_half_float_fetch");
}
if (extensions.Contains("gl_AMD_shader_image_load_store_lod"))
{
AMD_shader_image_load_store_lod = true;
extensions.Remove("glAMD_shader_image_load_store_lod");
extensions.Remove("gl_AMD_shader_image_load_store_lod");
}
if (extensions.Contains("gl_AMD_shader_stencil_export"))
{
AMD_shader_stencil_export = true;
extensions.Remove("glAMD_shader_stencil_export");
extensions.Remove("gl_AMD_shader_stencil_export");
}
if (extensions.Contains("gl_AMD_shader_trinary_minmax"))
{
AMD_shader_trinary_minmax = true;
extensions.Remove("glAMD_shader_trinary_minmax");
extensions.Remove("gl_AMD_shader_trinary_minmax");
}
if (extensions.Contains("gl_AMD_sparse_texture"))
{
AMD_sparse_texture = true;
extensions.Remove("glAMD_sparse_texture");
extensions.Remove("gl_AMD_sparse_texture");
}
if (extensions.Contains("gl_AMD_stencil_operation_extended"))
{
AMD_stencil_operation_extended = true;
extensions.Remove("glAMD_stencil_operation_extended");
extensions.Remove("gl_AMD_stencil_operation_extended");
}
if (extensions.Contains("gl_AMD_texture_gather_bias_lod"))
{
AMD_texture_gather_bias_lod = true;
extensions.Remove("glAMD_texture_gather_bias_lod");
extensions.Remove("gl_AMD_texture_gather_bias_lod");
}
if (extensions.Contains("gl_AMD_texture_texture4"))
{
AMD_texture_texture4 = true;
extensions.Remove("glAMD_texture_texture4");
extensions.Remove("gl_AMD_texture_texture4");
}
if (extensions.Contains("gl_AMD_transform_feedback3_lines_triangles"))
{
AMD_transform_feedback3_lines_triangles = true;
extensions.Remove("glAMD_transform_feedback3_lines_triangles");
extensions.Remove("gl_AMD_transform_feedback3_lines_triangles");
}
if (extensions.Contains("gl_AMD_transform_feedback4"))
{
AMD_transform_feedback4 = true;
extensions.Remove("glAMD_transform_feedback4");
extensions.Remove("gl_AMD_transform_feedback4");
}
if (extensions.Contains("gl_AMD_vertex_shader_layer"))
{
AMD_vertex_shader_layer = true;
extensions.Remove("glAMD_vertex_shader_layer");
extensions.Remove("gl_AMD_vertex_shader_layer");
}
if (extensions.Contains("gl_AMD_vertex_shader_tessellator"))
{
AMD_vertex_shader_tessellator = true;
extensions.Remove("glAMD_vertex_shader_tessellator");
extensions.Remove("gl_AMD_vertex_shader_tessellator");
}
if (extensions.Contains("gl_AMD_vertex_shader_viewport_index"))
{
AMD_vertex_shader_viewport_index = true;
extensions.Remove("glAMD_vertex_shader_viewport_index");
extensions.Remove("gl_AMD_vertex_shader_viewport_index");
}
if (extensions.Contains("gl_APPLE_aux_depth_stencil"))
{
@@ -3244,7 +3243,10 @@ namespace StgSharp.Graphics.OpenGL
#endregion checkGLextensions
}
internal static void CheckCoreVersion(int majorVersion, int minorVersion)
internal static void CheckCoreVersion(
int majorVersion,
int minorVersion
)
{
if (majorVersion < 3) {
throw new InvalidOperationException(
@@ -3410,7 +3412,9 @@ namespace StgSharp.Graphics.OpenGL
}
}
internal static unsafe string GetExtensions(this OpenglContext context)
internal static unsafe string GetExtensions(
this OpenglContext context
)
{
if (context.glGetString == null) {
return string.Empty;
+1 -28
View File
@@ -50,10 +50,7 @@ namespace StgSharp.Graphics.OpenGL
private OpenGLFunction _context;
protected internal OpenGLFunction GL
{
get { return _context; }
}
protected internal OpenGLFunction GL => _context;
/// <summary>
/// Initialize an opengl context and load all opengl functions.
@@ -169,29 +166,5 @@ namespace StgSharp.Graphics.OpenGL
NativeCamera.SetViewDirection(position, direction, up);
}
#region Key Control
protected KeyStatus CheckKey(
KeyboardKey key
)
{
return GraphicFramework.glfwGetKey(this.CanvasHandle, (int)key);
}
protected KeyStatus CheckKey(
Mouse key
)
{
return GraphicFramework.glfwGetKey(this.CanvasHandle, (int)key);
}
protected KeyStatus CheckKey(
Joystick key
)
{
return GraphicFramework.glfwGetKey(this.CanvasHandle, (int)key);
}
#endregion
}
}
+20 -8
View File
@@ -39,11 +39,18 @@ namespace StgSharp.Graphics
public string ModuleName => "Graphic";
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void InitializeModule()
public void InitializeModule(
IModuleInitializeProfile profile
)
{
GraphicFramework.LoadGlfw();
}
public void UninitializeModule()
{
GraphicFramework.glfwTerminate();
}
}
internal static unsafe partial class GraphicFramework
@@ -702,12 +709,15 @@ namespace StgSharp.Graphics
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static unsafe byte* glfwGetKeyName(
int key,
int scancode
internal static unsafe ReadOnlySpan<byte> glfwGetKeyName(
int key,
int scancode
)
{
return _glfw.glfwGetKeyName(key, scancode);
byte* ptr = _glfw.glfwGetKeyName(key, scancode);
int count = 0;
for (; ptr[count] != 0; count++) { }
return new ReadOnlySpan<byte>(ptr, count);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -717,15 +727,17 @@ namespace StgSharp.Graphics
{
return _glfw.glfwGetKeyScancode(key);
}
/**/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static unsafe KeyStatus glfwGetKey(
IntPtr window,
int key
internal static unsafe int glfwGetKey(
IntPtr window,
int key
)
{
return _glfw.glfwGetKey(window, key);
}
/**/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static unsafe int glfwGetMouseButton(
+1 -1
View File
@@ -58,7 +58,7 @@ namespace StgSharp.Internal
public delegate* unmanaged[Cdecl]<int, int*, byte*> glfwGetJoystickHats;
public delegate* unmanaged[Cdecl]<int, byte*> glfwGetJoystickName;
public delegate* unmanaged[Cdecl]<int, void*> glfwGetJoystickUserPointer;
public delegate* unmanaged[Cdecl]<IntPtr, int, KeyStatus> glfwGetKey;
public delegate* unmanaged[Cdecl]<IntPtr, int, int> glfwGetKey;
public delegate* unmanaged[Cdecl]<int, int, byte*> glfwGetKeyName;
public delegate* unmanaged[Cdecl]<int, int> glfwGetKeyScancode;
public delegate* unmanaged[Cdecl]<IntPtr, float*, float*, void> glfwGetMonitorContentScale;