many thing

This commit is contained in:
Nitload
2026-02-28 00:54:32 +08:00
parent a798ab07f1
commit 55cf3934bb
90 changed files with 288 additions and 321 deletions
+5 -4
View File
@@ -96,6 +96,11 @@
<PropertyGroup Condition="'$(IsLinux)'=='true'"> <PropertyGroup Condition="'$(IsLinux)'=='true'">
<DefineConstants>LINUX</DefineConstants> <DefineConstants>LINUX</DefineConstants>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Compile Remove="Graphics\**" />
<EmbeddedResource Remove="Graphics\**" />
<None Remove="Graphics\**" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Remove=".nuspec" /> <None Remove=".nuspec" />
<None Remove="StgSharp.Common.deps.json" /> <None Remove="StgSharp.Common.deps.json" />
@@ -115,10 +120,6 @@
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Graphics\" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent"> <Target Name="PostBuild" AfterTargets="PostBuildEvent">
</Target> </Target>
@@ -1,207 +1,187 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Image" // file="Image.cs"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload Space
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload Space. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person
// of this software and associated documentation files (the "Software"), to deal // obtaining a copy of this software and associated documentation
// in the Software without restriction, including without limitation the rights // files (the “Software”), to deal in the Software without restriction,
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // including without limitation the rights to use, copy, modify, merge,
// copies of the Software, and to permit persons to whom the Software is // publish, distribute, sublicense, and/or sell copies of the Software,
// furnished to do so, subject to the following conditions: // 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 above copyright notice and
// // this permission notice shall be included in all copies
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // or substantial portions of the Software.
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // THE SOFTWARE IS PROVIDED “AS IS”,
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// SOFTWARE. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ----------------------------------------------------------------------- // ARISING FROM, OUT OF OR IN CONNECTION WITH
// ----------------------------------------------------------------------- // THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.Graphics.OpenGL; using StgSharp.Graphics.OpenGL;
using System; using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace StgSharp.Graphics namespace StgSharp.Graphics
{ {
public class Image : IImageProvider public class Image : IImageProvider
{ {
private byte[] _data; private byte[] _data;
private ImageInfo _rawInfo; private ImageInfo _rawInfo;
private int _pixelUpdateCount = 0; private int _pixelUpdateCount = 0;
internal unsafe Image() internal unsafe Image()
{ {
_rawInfo = new ImageInfo(); _rawInfo = new ImageInfo();
} }
internal Image( internal Image(ImageInfo information)
ImageInfo information {
) _rawInfo = information;
{
_rawInfo = information;
_data = []; _data = [];
// int length = _rawInfo.width * _rawInfo.height * _rawInfo.channel; // int length = _rawInfo.width * _rawInfo.height * _rawInfo.channel;
} }
public (int width, int height) Size public (int width, int height) Size
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => (_rawInfo.Width, _rawInfo.Height); get => (_rawInfo.Width, _rawInfo.Height);
} }
public byte[] PixelBuffer public byte[] PixelBuffer
{ {
get get
{ {
if ((_data.Length == 0) || (_data == null)) if ((_data.Length == 0) || (_data == null))
{ {
GetBytes(); GetBytes();
return _data!; return _data!;
} }
return _data; return _data;
} }
} }
public ImageChannel Channel => _rawInfo.Channel; public ImageChannel Channel => _rawInfo.Channel;
/// <summary> /// <summary>
/// Hash code of time pixels updated last time. /// Hash code of time pixels updated last time.
/// </summary> /// </summary>
public int PixelUpdateCount public int PixelUpdateCount
{ {
get => _pixelUpdateCount; get => _pixelUpdateCount;
internal set => _pixelUpdateCount = value; internal set => _pixelUpdateCount = value;
} }
public int ChannelCount => _rawInfo.ChannelCount; public int ChannelCount => _rawInfo.ChannelCount;
public int Height public int Height
{ {
get => _rawInfo.Height; get => _rawInfo.Height;
internal set => _rawInfo.Height = value; internal set => _rawInfo.Height = value;
} }
public int Width public int Width
{ {
get => _rawInfo.Width; get => _rawInfo.Width;
internal set => _rawInfo.Width = value; internal set => _rawInfo.Width = value;
} }
public int PixelSize => ImageInfo.GetPixelSize(_rawInfo.pixelLayout, _rawInfo.Channel); public int PixelSize => ImageInfo.GetPixelSize(_rawInfo.pixelLayout, _rawInfo.Channel);
public PixelChannelLayout PixelLayout public PixelChannelLayout PixelLayout
{ {
get => _rawInfo.pixelLayout; get => _rawInfo.pixelLayout;
private set => _rawInfo.pixelLayout = value; private set => _rawInfo.pixelLayout = value;
} }
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage; internal ref byte[] Data => ref _data;
internal ref byte[] Data => ref _data; public void FromBytes(byte[] stream) { }
public void FromBytes( public static unsafe Image FromFile(string route, ImageLoader loader)
byte[] stream {
) { } Image ret = new Image();
fixed (ImageInfo* iptr = &ret._rawInfo) {
public static unsafe Image FromFile( GraphicFramework.InternalLoadImage(route, iptr, loader);
string route, }
ImageLoader loader return ret;
) }
{
Image ret = new Image(); public static Image FromMemory((int width, int height) size, ImageChannel channel, byte[] stream)
fixed (ImageInfo* iptr = &ret._rawInfo) { {
GraphicFramework.InternalLoadImage(route, iptr, loader); ImageInfo _info = new ImageInfo
} {
return ret; Height = size.height,
} Width = size.width,
Channel = channel,
public static Image FromMemory( StreamPtr = IntPtr.Zero
(int width, int height) size, };
ImageChannel channel, Image ret = new Image(_info);
byte[] stream ret.PixelLayout = PixelChannelLayout.Byte;
) ret._data = stream;
{ return ret;
ImageInfo _info = new ImageInfo }
{
Height = size.height, public static Image FromMemory(
Width = size.width, (int width, int height) size,
Channel = channel, ImageChannel channel,
StreamPtr = IntPtr.Zero PixelChannelLayout layout,
}; byte[] stream)
Image ret = new Image(_info); {
ret.PixelLayout = PixelChannelLayout.Byte; ImageInfo _info = new ImageInfo
ret._data = stream; {
return ret; Height = size.height,
} Width = size.width,
Channel = channel,
public static Image FromMemory( StreamPtr = IntPtr.Zero
(int width, int height) size, };
ImageChannel channel, Image ret = new Image(_info);
PixelChannelLayout layout, ret.PixelLayout = layout;
byte[] stream ret._data = stream;
) return ret;
{ }
ImageInfo _info = new ImageInfo
{ public unsafe byte[] GetBytes()
Height = size.height, {
Width = size.width, if (_data.Length == 0)
Channel = channel, {
StreamPtr = IntPtr.Zero int size = Width * Height * ImageInfo.GetPixelSize(PixelLayout, Channel);
}; _data = new Span<byte>((byte*)_rawInfo.StreamPtr, size).ToArray();
Image ret = new Image(_info); fixed (ImageInfo* pptr = &_rawInfo) {
ret.PixelLayout = layout; GraphicFramework.InternalUnloadImage(pptr);
ret._data = stream; }
return ret; _rawInfo.StreamPtr = IntPtr.Zero;
} }
return _data;
public unsafe byte[] GetBytes() }
{
if (_data.Length == 0) public Image ProvideImage()
{ {
int size = Width * Height * ImageInfo.GetPixelSize(PixelLayout, Channel); return this;
_data = new Span<byte>((byte*)_rawInfo.StreamPtr, size).ToArray(); }
fixed (ImageInfo* pptr = &_rawInfo) {
GraphicFramework.InternalUnloadImage(pptr); internal static Image FromMemory(ImageInfo info, byte[] data, int operationCount)
} {
_rawInfo.StreamPtr = IntPtr.Zero; return new Image
} {
return _data; _rawInfo = info,
} _data = data,
_pixelUpdateCount = operationCount
public Image ProvideImage() };
{ }
return this;
} }
internal static Image FromMemory(
ImageInfo info,
byte[] data,
int operationCount
)
{
return new Image
{
_rawInfo = info,
_data = data,
_pixelUpdateCount = operationCount
};
}
byte[] ISSDSerializable.GetBytes()
{
throw new NotImplementedException();
}
}
} }
+96
View File
@@ -0,0 +1,96 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="gl.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.Internal;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Graphics
{
internal static partial class GraphicFramework
{
internal static uint[] GLtype = new uint[16];
static GraphicFramework()
{
GLtype[(int)TypeCode.Single] = glConst.FLOAT;
GLtype[(int)TypeCode.Int32] = glConst.INT;
GLtype[(int)TypeCode.UInt32] = glConst.UNSIGNED_INT;
GLtype[(int)TypeCode.Int16] = glConst.SHORT;
GLtype[(int)TypeCode.UInt16] = glConst.UNSIGNED_SHORT;
GLtype[(int)TypeCode.SByte] = glConst.BYTE;
GLtype[(int)TypeCode.Byte] = glConst.UNSIGNED_BYTE;
}
[LibraryImport(Native.LibName, EntryPoint = "glCheckShaderStat")]
[UnmanagedCallConv(CallConvs = [ typeof(CallConvCdecl) ])]
#pragma warning disable CA5392
internal static partial int glCheckShaderStatus(
ref OpenglContext context,
uint shaderHandle,
int key,
ref IntPtr logPtr);
#pragma warning restore CA5392
#region ssgc api define
[LibraryImport(Native.LibName, EntryPoint = "initGL")]
[UnmanagedCallConv(CallConvs =[ typeof(CallConvCdecl) ])]
internal static partial void InternalInitGL(int majorVersion, int minorVersion);
[LibraryImport(Native.LibName, EntryPoint = "loadGlfuncDefault", StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs =[ typeof(CallConvCdecl) ])]
internal static partial IntPtr InternalLoadGlFuncDefault(string name);
[LibraryImport(Native.LibName, EntryPoint = "linkShaderProgram")]
[UnmanagedCallConv(CallConvs =[ typeof(CallConvCdecl) ])]
internal static unsafe partial uint InternalLinkShaderProgram(OpenglContext* context, uint shaderProgram);
[LibraryImport(Native.LibName, EntryPoint = "readLog")]
[UnmanagedCallConv(CallConvs =[ typeof(CallConvCdecl) ])]
internal static unsafe partial IntPtr InternalReadSSCLog();
[LibraryImport(Native.LibName, EntryPoint = "loadImageData", StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs =[ typeof(CallConvCdecl) ])]
internal static unsafe partial void InternalLoadImage(string fileName, ImageInfo* output, ImageLoader loader);
[LibraryImport(Native.LibName, EntryPoint = "unloadImageData")]
[UnmanagedCallConv(CallConvs =[ typeof(CallConvCdecl) ])]
internal static unsafe partial void InternalUnloadImage(ImageInfo* output);
#endregion ssgc api define
}
}
@@ -2,8 +2,8 @@
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="IGeometry" // file="IGeometry"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload Space
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload Space. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@@ -43,9 +43,8 @@ namespace StgSharp.Geometries
public Point this[int index] { get; set; } public Point this[int index] { get; set; }
#pragma warning disable CA1819 #pragma warning disable CA1819
public Vec4[] VertexStream public Vec4[] VertexStream { get; }
#pragma warning restore CA1819 #pragma warning restore CA1819
{ get; }
public CoordinationBase Coordination { get; } public CoordinationBase Coordination { get; }
+1 -1
View File
@@ -34,7 +34,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StgSharp.Mathematics", "Stg
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StgSharp.RegularAnalysis", "StgSharp.RegularAnalysis\StgSharp.RegularAnalysis.csproj", "{46339874-C6B8-4361-997E-2E30387E51F9}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StgSharp.RegularAnalysis", "StgSharp.RegularAnalysis\StgSharp.RegularAnalysis.csproj", "{46339874-C6B8-4361-997E-2E30387E51F9}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StgsSharp.Graphics", "StgsSharp.Graphics\StgsSharp.Graphics.csproj", "{80CD3DDE-0642-451D-82DF-0DE422FC6E34}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StgSharp.Graphics", "StgSharp.Graphics\StgSharp.Graphics.csproj", "{80CD3DDE-0642-451D-82DF-0DE422FC6E34}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
-114
View File
@@ -1,114 +0,0 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="gl"
// 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.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.Graphics;
using StgSharp.Graphics.OpenGL;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Internal
{
internal static partial class GraphicFramework
{
internal static uint[] GLtype = new uint[16];
static GraphicFramework()
{
GLtype[(int)TypeCode.Single] = glConst.FLOAT;
GLtype[(int)TypeCode.Int32] = glConst.INT;
GLtype[(int)TypeCode.UInt32] = glConst.UNSIGNED_INT;
GLtype[(int)TypeCode.Int16] = glConst.SHORT;
GLtype[(int)TypeCode.UInt16] = glConst.UNSIGNED_SHORT;
GLtype[(int)TypeCode.SByte] = glConst.BYTE;
GLtype[(int)TypeCode.Byte] = glConst.UNSIGNED_BYTE;
}
[LibraryImport(Native.LibName, EntryPoint = "glCheckShaderStat")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
#pragma warning disable CA5392
internal static partial int glCheckShaderStatus(
ref OpenglContext context,
uint shaderHandle,
int key,
ref IntPtr logPtr
);
#pragma warning restore CA5392
#region ssgc api define
[LibraryImport(Native.LibName, EntryPoint = "initGL")]
[UnmanagedCallConv(CallConvs =[typeof(CallConvCdecl)])]
internal static partial void InternalInitGL(
int majorVersion,
int minorVersion
);
[LibraryImport(
Native.LibName,
EntryPoint = "loadGlfuncDefault",
StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs =[typeof(CallConvCdecl)])]
internal static partial IntPtr InternalLoadGlFuncDefault(
string name
);
[LibraryImport(Native.LibName, EntryPoint = "linkShaderProgram")]
[UnmanagedCallConv(CallConvs =[typeof(CallConvCdecl)])]
internal static unsafe partial uint InternalLinkShaderProgram(
OpenglContext* context,
uint shaderProgram
);
[LibraryImport(Native.LibName, EntryPoint = "readLog")]
[UnmanagedCallConv(CallConvs =[typeof(CallConvCdecl)])]
internal static unsafe partial IntPtr InternalReadSSCLog();
[LibraryImport(
Native.LibName,
EntryPoint = "loadImageData",
StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs =[typeof(CallConvCdecl)])]
internal static unsafe partial void InternalLoadImage(
string fileName,
ImageInfo* output,
ImageLoader loader
);
[LibraryImport(Native.LibName, EntryPoint = "unloadImageData")]
[UnmanagedCallConv(CallConvs =[typeof(CallConvCdecl)])]
internal static unsafe partial void InternalUnloadImage(
ImageInfo* output
);
#endregion ssgc api define
}
}
+5
View File
@@ -0,0 +1,5 @@
1. native 核函数标识关键字宏和展开宏
2. 核函数参数表重整
3. C#侧核函数调度器重整适配
4. 正则表达式源生成
5. imgae及pixel存储优化