Normalize all existing files to LF

This commit is contained in:
Youmu Liu
2026-03-06 18:31:11 +08:00
parent 0a0af53af1
commit 2149bbeede
323 changed files with 113191 additions and 113191 deletions
+59 -59
View File
@@ -1,59 +1,59 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="Monitor"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public static class GraphicsEnvironment
{
private static IntPtr[] _monitorsHandleArray;
public static unsafe ReadOnlySpan<IntPtr> MonitorsHandleArray
{
get
{
if (_monitorsHandleArray == null)
{
int count = 0;
IntPtr* arrayHandle = GraphicFramework.glfwGetMonitors(&count);
_monitorsHandleArray = new IntPtr[count];
Marshal.Copy((IntPtr)arrayHandle, _monitorsHandleArray, 0, count);
Marshal.FreeHGlobal((IntPtr)arrayHandle);
}
return _monitorsHandleArray;
}
}
}
}
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="Monitor"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public static class GraphicsEnvironment
{
private static IntPtr[] _monitorsHandleArray;
public static unsafe ReadOnlySpan<IntPtr> MonitorsHandleArray
{
get
{
if (_monitorsHandleArray == null)
{
int count = 0;
IntPtr* arrayHandle = GraphicFramework.glfwGetMonitors(&count);
_monitorsHandleArray = new IntPtr[count];
Marshal.Copy((IntPtr)arrayHandle, _monitorsHandleArray, 0, count);
Marshal.FreeHGlobal((IntPtr)arrayHandle);
}
return _monitorsHandleArray;
}
}
}
}
+58 -58
View File
@@ -1,58 +1,58 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="GraphicInitializer"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public class GraphicModuel : IStaticModule
{
public string ModuleName => "Graphics";
public void InitializeModule(IModuleInitializeProfile profile)
{
GraphicFramework.LoadGlfw();
if (GraphicFramework.glfwInit() == 0) {
throw new Exception("Failed to init system graphic environment.");
}
}
public void UninitializeModule()
{
GraphicFramework.glfwTerminate();
}
}
}
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="GraphicInitializer"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public class GraphicModuel : IStaticModule
{
public string ModuleName => "Graphics";
public void InitializeModule(IModuleInitializeProfile profile)
{
GraphicFramework.LoadGlfw();
if (GraphicFramework.glfwInit() == 0) {
throw new Exception("Failed to init system graphic environment.");
}
}
public void UninitializeModule()
{
GraphicFramework.glfwTerminate();
}
}
}
+178 -178
View File
@@ -1,187 +1,187 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="Image.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.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="Image.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.Graphics.OpenGL;
using System;
using System.Runtime.CompilerServices;
namespace StgSharp.Graphics
{
public class Image : IImageProvider
{
private byte[] _data;
private ImageInfo _rawInfo;
private int _pixelUpdateCount = 0;
internal unsafe Image()
{
_rawInfo = new ImageInfo();
}
internal Image(ImageInfo information)
{
_rawInfo = information;
using System;
using System.Runtime.CompilerServices;
namespace StgSharp.Graphics
{
public class Image : IImageProvider
{
private byte[] _data;
private ImageInfo _rawInfo;
private int _pixelUpdateCount = 0;
internal unsafe Image()
{
_rawInfo = new ImageInfo();
}
internal Image(ImageInfo information)
{
_rawInfo = information;
_data = [];
// int length = _rawInfo.width * _rawInfo.height * _rawInfo.channel;
}
public (int width, int height) Size
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => (_rawInfo.Width, _rawInfo.Height);
}
public byte[] PixelBuffer
{
get
{
if ((_data.Length == 0) || (_data == null))
{
GetBytes();
return _data!;
}
return _data;
}
}
}
public (int width, int height) Size
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => (_rawInfo.Width, _rawInfo.Height);
}
public byte[] PixelBuffer
{
get
{
if ((_data.Length == 0) || (_data == null))
{
GetBytes();
return _data!;
}
return _data;
}
}
public ImageChannel Channel => _rawInfo.Channel;
/// <summary>
/// Hash code of time pixels updated last time.
/// <summary>
/// Hash code of time pixels updated last time.
/// </summary>
public int PixelUpdateCount
{
get => _pixelUpdateCount;
internal set => _pixelUpdateCount = value;
}
public int ChannelCount => _rawInfo.ChannelCount;
public int Height
{
get => _rawInfo.Height;
internal set => _rawInfo.Height = value;
}
public int Width
{
get => _rawInfo.Width;
internal set => _rawInfo.Width = value;
}
public int PixelSize => ImageInfo.GetPixelSize(_rawInfo.pixelLayout, _rawInfo.Channel);
public PixelChannelLayout PixelLayout
{
get => _rawInfo.pixelLayout;
private set => _rawInfo.pixelLayout = value;
}
internal ref byte[] Data => ref _data;
public void FromBytes(byte[] stream) { }
public static unsafe Image FromFile(string route, ImageLoader loader)
{
Image ret = new Image();
fixed (ImageInfo* iptr = &ret._rawInfo) {
GraphicFramework.InternalLoadImage(route, iptr, loader);
}
return ret;
}
public static Image FromMemory((int width, int height) size, ImageChannel channel, byte[] stream)
{
ImageInfo _info = new ImageInfo
{
Height = size.height,
Width = size.width,
Channel = channel,
StreamPtr = IntPtr.Zero
};
Image ret = new Image(_info);
ret.PixelLayout = PixelChannelLayout.Byte;
ret._data = stream;
return ret;
}
public static Image FromMemory(
(int width, int height) size,
ImageChannel channel,
PixelChannelLayout layout,
byte[] stream)
{
ImageInfo _info = new ImageInfo
{
Height = size.height,
Width = size.width,
Channel = channel,
StreamPtr = IntPtr.Zero
};
Image ret = new Image(_info);
ret.PixelLayout = layout;
ret._data = stream;
return ret;
}
public unsafe byte[] GetBytes()
{
if (_data.Length == 0)
{
int size = Width * Height * ImageInfo.GetPixelSize(PixelLayout, Channel);
_data = new Span<byte>((byte*)_rawInfo.StreamPtr, size).ToArray();
fixed (ImageInfo* pptr = &_rawInfo) {
GraphicFramework.InternalUnloadImage(pptr);
}
_rawInfo.StreamPtr = IntPtr.Zero;
}
return _data;
}
public Image ProvideImage()
{
return this;
}
internal static Image FromMemory(ImageInfo info, byte[] data, int operationCount)
{
return new Image
{
_rawInfo = info,
_data = data,
_pixelUpdateCount = operationCount
};
}
}
public int PixelUpdateCount
{
get => _pixelUpdateCount;
internal set => _pixelUpdateCount = value;
}
public int ChannelCount => _rawInfo.ChannelCount;
public int Height
{
get => _rawInfo.Height;
internal set => _rawInfo.Height = value;
}
public int Width
{
get => _rawInfo.Width;
internal set => _rawInfo.Width = value;
}
public int PixelSize => ImageInfo.GetPixelSize(_rawInfo.pixelLayout, _rawInfo.Channel);
public PixelChannelLayout PixelLayout
{
get => _rawInfo.pixelLayout;
private set => _rawInfo.pixelLayout = value;
}
internal ref byte[] Data => ref _data;
public void FromBytes(byte[] stream) { }
public static unsafe Image FromFile(string route, ImageLoader loader)
{
Image ret = new Image();
fixed (ImageInfo* iptr = &ret._rawInfo) {
GraphicFramework.InternalLoadImage(route, iptr, loader);
}
return ret;
}
public static Image FromMemory((int width, int height) size, ImageChannel channel, byte[] stream)
{
ImageInfo _info = new ImageInfo
{
Height = size.height,
Width = size.width,
Channel = channel,
StreamPtr = IntPtr.Zero
};
Image ret = new Image(_info);
ret.PixelLayout = PixelChannelLayout.Byte;
ret._data = stream;
return ret;
}
public static Image FromMemory(
(int width, int height) size,
ImageChannel channel,
PixelChannelLayout layout,
byte[] stream)
{
ImageInfo _info = new ImageInfo
{
Height = size.height,
Width = size.width,
Channel = channel,
StreamPtr = IntPtr.Zero
};
Image ret = new Image(_info);
ret.PixelLayout = layout;
ret._data = stream;
return ret;
}
public unsafe byte[] GetBytes()
{
if (_data.Length == 0)
{
int size = Width * Height * ImageInfo.GetPixelSize(PixelLayout, Channel);
_data = new Span<byte>((byte*)_rawInfo.StreamPtr, size).ToArray();
fixed (ImageInfo* pptr = &_rawInfo) {
GraphicFramework.InternalUnloadImage(pptr);
}
_rawInfo.StreamPtr = IntPtr.Zero;
}
return _data;
}
public Image ProvideImage()
{
return this;
}
internal static Image FromMemory(ImageInfo info, byte[] data, int operationCount)
{
return new Image
{
_rawInfo = info,
_data = data,
_pixelUpdateCount = operationCount
};
}
}
}
+219 -219
View File
@@ -1,276 +1,276 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="TextureGL"
// 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;
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="TextureGL"
// 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.Mathematics;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Graphics.OpenGL
{
public sealed unsafe class TextureGL
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Graphics.OpenGL
{
public sealed unsafe class TextureGL
{
private int currentEditingTextureIndex;
private OpenGLFunction _gl;
internal GlHandle[] _textureHandle;
internal TextureGL(int count, glRender binding)
{
// sourceList = new Image[count];
this._gl = binding.GL;
_textureHandle = _gl.GenTextures(count);
}
public GlHandle this[int index]
{
get => _textureHandle[index];
}
public int Count
{
get => _textureHandle.Length;
private OpenGLFunction _gl;
internal GlHandle[] _textureHandle;
internal TextureGL(int count, glRender binding)
{
// sourceList = new Image[count];
this._gl = binding.GL;
_textureHandle = _gl.GenTextures(count);
}
public GlHandle this[int index]
{
get => _textureHandle[index];
}
public int Count
{
get => _textureHandle.Length;
}
// internal Image[] sourceList;
public int IndexOfCurrentTexture
{
get => currentEditingTextureIndex;
}
internal OpenGLFunction GL => _gl;
public void ActivateAs(TextureUnit unit)
{
_gl.ActiveTextureUnit((uint)unit);
}
public void Bind2D(int index)
{
currentEditingTextureIndex = index;
_gl.BindTexture(glConst.TEXTURE_2D, _textureHandle[index]);
public int IndexOfCurrentTexture
{
get => currentEditingTextureIndex;
}
/// <summary>
/// Load an <see cref="Image" /> to certain texture.
internal OpenGLFunction GL => _gl;
public void ActivateAs(TextureUnit unit)
{
_gl.ActiveTextureUnit((uint)unit);
}
public void Bind2D(int index)
{
currentEditingTextureIndex = index;
_gl.BindTexture(glConst.TEXTURE_2D, _textureHandle[index]);
}
/// <summary>
/// Load an <see cref="Image" /> to certain texture.
/// </summary>
/// <param _label="index">
///
/// <param _label="index">
///
/// </param>
/// <param _label="i">
///
/// <param _label="i">
///
/// </param>
public unsafe void LoadTexture(int index, Image i)
{
byte[] handle = i.PixelBuffer;
_gl.TextureImage2d(Texture2DTarget.Texture2D, 0, i.Channel, i.Width, i.Height, i.Channel, i.PixelLayout,
pixels:handle);
_gl.GenerateMipmap(Texture2DTarget.Texture2D);
public unsafe void LoadTexture(int index, Image i)
{
byte[] handle = i.PixelBuffer;
_gl.TextureImage2d(Texture2DTarget.Texture2D, 0, i.Channel, i.Width, i.Height, i.Channel, i.PixelLayout,
pixels:handle);
_gl.GenerateMipmap(Texture2DTarget.Texture2D);
}
#region texture setting
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Set2dFilterProperty(int index, TextureFilter onMinify, TextureFilter onMagnify)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Set2dFilterProperty(int index, TextureFilter onMinify, TextureFilter onMagnify)
{
#if DEBUG
if (index != currentEditingTextureIndex)
{
if (index != currentEditingTextureIndex)
{
throw new InvalidOperationException(
"Texture to be editted is not the one being activated.");
"Texture to be editted is not the one being activated.");
}
#endif
_gl.TextureParameter(glConst.TEXTURE_2D, glConst.TEXTURE_MIN_FILTER, (int)onMinify);
_gl.TextureParameter(glConst.TEXTURE_2D, glConst.TEXTURE_MIN_FILTER, (int)onMinify);
_gl.TextureParameter(glConst.TEXTURE_2D, glConst.TEXTURE_MAG_FILTER,
(int)onMagnify);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Set2dWrapProperty(int index, TextureWrap onHorizontial, TextureWrap onVertical)
(int)onMagnify);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Set2dWrapProperty(int index, TextureWrap onHorizontial, TextureWrap onVertical)
{
#if DEBUG
if (index != currentEditingTextureIndex)
{
if (index != currentEditingTextureIndex)
{
throw new InvalidOperationException(
"Texture to be editted is not the one being activated.");
"Texture to be editted is not the one being activated.");
}
#endif
_gl.TextureParameter(glConst.TEXTURE_2D, glConst.TEXTURE_WRAP_S,
(int)onHorizontial);
_gl.TextureParameter(glConst.TEXTURE_2D, glConst.TEXTURE_WRAP_T, (int)onVertical);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Set2dProperty(int index, TextureProperty property)
{
Set2dFilterProperty(index, property.FilterOnMinify, property.FilterOnMagnify);
Set2dWrapProperty(index, property.WrapOnHorizontial, property.WrapOnVertical);
(int)onHorizontial);
_gl.TextureParameter(glConst.TEXTURE_2D, glConst.TEXTURE_WRAP_T, (int)onVertical);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Set2dProperty(int index, TextureProperty property)
{
Set2dFilterProperty(index, property.FilterOnMinify, property.FilterOnMagnify);
Set2dWrapProperty(index, property.WrapOnHorizontial, property.WrapOnVertical);
}
#endregion texture setting
}
[StructLayout(LayoutKind.Explicit)]
public struct TextureProperty
{
[FieldOffset(0)] private M128 mask;
[FieldOffset(0)] private TextureFilter mag;
}
[StructLayout(LayoutKind.Explicit)]
public struct TextureProperty
{
[FieldOffset(0)] private M128 mask;
[FieldOffset(0)] private TextureFilter mag;
[FieldOffset(4)] private TextureFilter min;
[FieldOffset(8)] private TextureWrap hori;
[FieldOffset(12)] private TextureWrap vert;
public TextureProperty(
TextureFilter onMagnify,
TextureFilter onMinify,
TextureWrap onHorizontial,
TextureWrap onVertical)
{
FilterOnMagnify = onMagnify;
FilterOnMinify = onMinify;
WrapOnHorizontial = onHorizontial;
WrapOnVertical = onVertical;
}
public TextureFilter FilterOnMagnify
{
get => mag;
set => mag = value;
}
public TextureFilter FilterOnMinify
{
get => min;
set => min = value;
}
public TextureWrap WrapOnHorizontial
{
get => hori;
set => hori = value;
}
public TextureWrap WrapOnVertical
{
get => vert;
set => vert = value;
}
public override bool Equals([NotNullWhen(true)] object obj)
{
return base.Equals(obj);
}
public override int GetHashCode()
{
return HashCode.Combine(FilterOnMagnify, FilterOnMagnify, WrapOnHorizontial, WrapOnVertical);
}
public override string ToString()
{
return $"FilterOnMagnify:{FilterOnMagnify}, " + $"FilterOnMagnify:{FilterOnMagnify}, " + $"WrapOnHorizontial:{WrapOnHorizontial}, " + $"WrapOnVertical:{WrapOnVertical}";
}
public static bool operator !=(TextureProperty left, TextureProperty right)
{
return left.mask != right.mask;
[FieldOffset(8)] private TextureWrap hori;
[FieldOffset(12)] private TextureWrap vert;
public TextureProperty(
TextureFilter onMagnify,
TextureFilter onMinify,
TextureWrap onHorizontial,
TextureWrap onVertical)
{
FilterOnMagnify = onMagnify;
FilterOnMinify = onMinify;
WrapOnHorizontial = onHorizontial;
WrapOnVertical = onVertical;
}
public static bool operator ==(TextureProperty left, TextureProperty right)
{
return left.mask == right.mask;
public TextureFilter FilterOnMagnify
{
get => mag;
set => mag = value;
}
public static implicit operator TextureProperty(
public TextureFilter FilterOnMinify
{
get => min;
set => min = value;
}
public TextureWrap WrapOnHorizontial
{
get => hori;
set => hori = value;
}
public TextureWrap WrapOnVertical
{
get => vert;
set => vert = value;
}
public override bool Equals([NotNullWhen(true)] object obj)
{
return base.Equals(obj);
}
public override int GetHashCode()
{
return HashCode.Combine(FilterOnMagnify, FilterOnMagnify, WrapOnHorizontial, WrapOnVertical);
}
public override string ToString()
{
return $"FilterOnMagnify:{FilterOnMagnify}, " + $"FilterOnMagnify:{FilterOnMagnify}, " + $"WrapOnHorizontial:{WrapOnHorizontial}, " + $"WrapOnVertical:{WrapOnVertical}";
}
public static bool operator !=(TextureProperty left, TextureProperty right)
{
return left.mask != right.mask;
}
public static bool operator ==(TextureProperty left, TextureProperty right)
{
return left.mask == right.mask;
}
public static implicit operator TextureProperty(
(
TextureFilter onMagnify, TextureFilter onMinify,
TextureWrap onHorizontial, TextureWrap onVertical
) propertyValueTuple)
{
return new TextureProperty(propertyValueTuple.onMagnify, propertyValueTuple.onMinify,
propertyValueTuple.onHorizontial, propertyValueTuple.onVertical);
}
) propertyValueTuple)
{
return new TextureProperty(propertyValueTuple.onMagnify, propertyValueTuple.onMinify,
propertyValueTuple.onHorizontial, propertyValueTuple.onVertical);
}
}
#pragma warning disable CA1008
public enum TextureFilter
#pragma warning restore CA1008
{
Nearest = glConst.NEAREST,
Linear = glConst.LINEAR,
NearestLinearMipmap = glConst.NEAREST_MIPMAP_LINEAR,
LinearLinearMipmap = glConst.LINEAR_MIPMAP_LINEAR,
NearestNearestMipmap = glConst.NEAREST_MIPMAP_NEAREST,
LinearNearestMipmap = glConst.LINEAR_MIPMAP_NEAREST,
{
Nearest = glConst.NEAREST,
Linear = glConst.LINEAR,
NearestLinearMipmap = glConst.NEAREST_MIPMAP_LINEAR,
LinearLinearMipmap = glConst.LINEAR_MIPMAP_LINEAR,
NearestNearestMipmap = glConst.NEAREST_MIPMAP_NEAREST,
LinearNearestMipmap = glConst.LINEAR_MIPMAP_NEAREST,
}
#pragma warning disable CA1008
public enum TextureUnit
#pragma warning restore CA1008
{
Unit0 = glConst.TEXTURE0,
Unit1 = glConst.TEXTURE1,
Unit2 = glConst.TEXTURE2,
Unit3 = glConst.TEXTURE3,
Unit4 = glConst.TEXTURE4,
Unit5 = glConst.TEXTURE5,
Unit6 = glConst.TEXTURE6,
Unit7 = glConst.TEXTURE7,
Unit8 = glConst.TEXTURE8,
Unit9 = glConst.TEXTURE9,
Unit10 = glConst.TEXTURE10,
Unit11 = glConst.TEXTURE11,
Unit12 = glConst.TEXTURE12,
Unit13 = glConst.TEXTURE13,
Unit14 = glConst.TEXTURE14,
Unit15 = glConst.TEXTURE15,
{
Unit0 = glConst.TEXTURE0,
Unit1 = glConst.TEXTURE1,
Unit2 = glConst.TEXTURE2,
Unit3 = glConst.TEXTURE3,
Unit4 = glConst.TEXTURE4,
Unit5 = glConst.TEXTURE5,
Unit6 = glConst.TEXTURE6,
Unit7 = glConst.TEXTURE7,
Unit8 = glConst.TEXTURE8,
Unit9 = glConst.TEXTURE9,
Unit10 = glConst.TEXTURE10,
Unit11 = glConst.TEXTURE11,
Unit12 = glConst.TEXTURE12,
Unit13 = glConst.TEXTURE13,
Unit14 = glConst.TEXTURE14,
Unit15 = glConst.TEXTURE15,
}
#pragma warning disable CA1008
public enum TextureWrap
#pragma warning restore CA1008
{
Repeat = glConst.REPEAT,
MirroredRepeat = glConst.MIRRORED_REPEAT,
ClampToEdge = glConst.CLAMP_TO_EDGE,
ClampToBorder = glConst.CLAMP_TO_BORDER,
}
{
Repeat = glConst.REPEAT,
MirroredRepeat = glConst.MIRRORED_REPEAT,
ClampToEdge = glConst.CLAMP_TO_EDGE,
ClampToBorder = glConst.CLAMP_TO_BORDER,
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+104 -104
View File
@@ -1,104 +1,104 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="Pixels"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics
{
public interface IPixel
{
public float Red { get; set; }
public float Green { get; set; }
public float Blue { get; set; }
public float Alpha { get; set; }
internal int Size { get; }
}
[StructLayout(LayoutKind.Explicit, Size = 32)]
public unsafe struct Pixel32RGBA : IPixel
{
[FieldOffset(0)] private unsafe fixed byte data[4];
[FieldOffset(0)] private readonly int mask;
public readonly int Size => 4;
public override bool Equals(object obj)
{
return obj is not null && obj is Pixel32RGBA pixel && this == pixel;
}
public override readonly int GetHashCode()
{
return mask.GetHashCode();
}
public static bool operator !=(Pixel32RGBA left, Pixel32RGBA right)
{
return !(left == right);
}
public static bool operator ==(Pixel32RGBA left, Pixel32RGBA right)
{
return left.mask == right.mask;
}
float IPixel.Alpha
{
get => data[3] / 256;
set => data[3] = (byte)(value * 256);
}
float IPixel.Blue
{
get => data[2] / 256;
set => data[2] = (byte)(value * 256);
}
float IPixel.Green
{
get => data[1] / 256;
set => data[1] = (byte)(value * 256);
}
float IPixel.Red
{
get => data[0] / 256;
set => data[0] = (byte)(value * 256);
}
}
}
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="Pixels"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics
{
public interface IPixel
{
public float Red { get; set; }
public float Green { get; set; }
public float Blue { get; set; }
public float Alpha { get; set; }
internal int Size { get; }
}
[StructLayout(LayoutKind.Explicit, Size = 32)]
public unsafe struct Pixel32RGBA : IPixel
{
[FieldOffset(0)] private unsafe fixed byte data[4];
[FieldOffset(0)] private readonly int mask;
public readonly int Size => 4;
public override bool Equals(object obj)
{
return obj is not null && obj is Pixel32RGBA pixel && this == pixel;
}
public override readonly int GetHashCode()
{
return mask.GetHashCode();
}
public static bool operator !=(Pixel32RGBA left, Pixel32RGBA right)
{
return !(left == right);
}
public static bool operator ==(Pixel32RGBA left, Pixel32RGBA right)
{
return left.mask == right.mask;
}
float IPixel.Alpha
{
get => data[3] / 256;
set => data[3] = (byte)(value * 256);
}
float IPixel.Blue
{
get => data[2] / 256;
set => data[2] = (byte)(value * 256);
}
float IPixel.Green
{
get => data[1] / 256;
set => data[1] = (byte)(value * 256);
}
float IPixel.Red
{
get => data[0] / 256;
set => data[0] = (byte)(value * 256);
}
}
}
+84 -84
View File
@@ -1,96 +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")]
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// 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,
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) ])]
[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
}
}
}