daily update on 20241002 by nitload youmu, intrinsic function rebuild, syntax style arrange

This commit is contained in:
Nitload
2024-10-03 04:03:06 +08:00
parent 0979123ac0
commit 6e2f93b053
265 changed files with 26732 additions and 19058 deletions
@@ -36,6 +36,8 @@ namespace StgSharp.Graphics
{
public interface IImageProvider
{
Image ProvideImage();
}
}
@@ -30,23 +30,35 @@
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace StgSharp.Graphics
{
public static class ImageHelper
{
public static void Resize(Image i, int width, int height, ImageMovement move)
public static void Resize(
Image i,
int width,
int height,
ImageMovement move )
{
if (i == null)
{
throw new ArgumentNullException(nameof(i));
if( i == null ) {
throw new ArgumentNullException( nameof( i ) );
}
Array.Resize(ref i.Data, width * height * i.PixelSize);
if( i.Size == (width, height) ) {
return;
}
if( !Enum.IsDefined( typeof( ImageMovement ), move ) ) {
throw new InvalidEnumArgumentException( nameof( move ) );
}
byte[] oldData = i.Data;
i.Data = new byte[width * height * i.PixelSize];
i.Height = height;
i.Width = width;
switch (move)
{
i.PixelUpdateCount++;
switch( move ) {
case ImageMovement.Discard:
break;
case ImageMovement.Top:
@@ -54,8 +66,8 @@ namespace StgSharp.Graphics
default:
throw new NotImplementedException();
}
i.PixelUpdateCount++;
}
}
[Flags]
@@ -63,7 +75,7 @@ namespace StgSharp.Graphics
{
#pragma warning disable CA1008
Discard = 0,
#pragma warning restore CA1008
#pragma warning restore CA1008
Top = 1,
Bottom = 2,
Left = 4,
@@ -72,5 +84,6 @@ namespace StgSharp.Graphics
BottomLeft = Bottom | Left,
TopRight = Top | Right,
BottomRight = Bottom | Right,
}
}
@@ -52,31 +52,31 @@ namespace StgSharp.Graphics
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public GlHandle this[int index] => _bufferHandle[index];
public GlHandle this[ int index ] => _bufferHandle[ index ];
/// <summary>
/// Bind a buffer instance to OpenGL
/// </summary>
/// <param name="index">Index of handle of the object in this instance to be bind</param>
public abstract void Bind(int index);
/// <param name="index"> Index of handle of the object in this instance to be bind </param>
public abstract void Bind( int index );
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
Dispose( disposing: true );
GC.SuppressFinalize( this );
}
/// <inheritdoc/>
/// <inheritdoc />
public override string ToString()
{
return $"This is a {GetType().FullName}, containing {_bufferHandle.Length} buffer handles: {_bufferHandle.ToString()}.";
}
protected abstract void Dispose(bool disposing);
protected abstract void Dispose( bool disposing );
~BufferObjectBase()
{
Dispose(disposing: false);
Dispose( disposing: false );
}
}
@@ -45,7 +45,7 @@ namespace StgSharp.Graphics
#region GLFW3 struct
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWcontext
{
@@ -116,12 +116,12 @@ namespace StgSharp.Graphics
//GLFW_PLATFORM_CONTEXT_STATE
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
public unsafe struct glfwVideomode
{
/*! The refresh rate, in Hz, of the video mode.
*/
private int refreshRate;
/*! The bit depth of the blue channel of the video mode.
*/
@@ -142,12 +142,12 @@ namespace StgSharp.Graphics
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
public unsafe struct glfwGammaramp
{
/*! An array of value describing the response of the blue channel.
*/
private ushort* blue;
/*! An array of value describing the response of the green channel.
*/
@@ -162,12 +162,12 @@ namespace StgSharp.Graphics
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWimage
{
/*! The pixel _data of this image, arranged left-to-right, top-to-bottom.
*/
private byte* pixels;
/*! The height, in pixels, of this image.
@@ -177,26 +177,25 @@ namespace StgSharp.Graphics
*/
private int width;
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWgamepadstate
{
/*! The states of each [gamepad button](@ref gamepad_buttons), `GLFW_PRESS`
* or `GLFW_RELEASE`.
*/
public fixed byte buttons[15];
public fixed byte buttons[ 15 ];
/*! The states of each [gamepad axis](@ref gamepad_axes), in the range -1.0
* to 1.0 inclusive.
*/
public fixed float axes[6];
public fixed float axes[ 6 ];
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWallocator
{
@@ -213,7 +212,7 @@ namespace StgSharp.Graphics
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
public unsafe struct glfwMonitor
{
@@ -221,7 +220,7 @@ namespace StgSharp.Graphics
private glfwWindow* window;
private fixed byte name[128];
private fixed byte name[ 128 ];
private glfwGammaramp currentRamp;
private glfwGammaramp originalRamp;
@@ -231,57 +230,55 @@ namespace StgSharp.Graphics
private int width, height;
private IntPtr userPointer;
public glfwMonitor()
{ }
public glfwMonitor() { }
public unsafe string Name
{
get
{
fixed (byte* cptr = name)
{
return Marshal.PtrToStringAnsi((IntPtr)cptr);
fixed( byte* cptr = name ) {
return Marshal.PtrToStringAnsi( ( IntPtr )cptr );
}
}
}
}
[StructLayout(LayoutKind.Sequential)]
unsafe struct glfwWindow
[StructLayout( LayoutKind.Sequential )]
internal unsafe struct glfwWindow
{
glfwWindow* next;
void* userPointer;
bool rawMouseMotion;
Callbacks callbacks;
private glfwWindow* next;
private void* userPointer;
private bool rawMouseMotion;
private Callbacks callbacks;
// Virtual cursor position when cursor is disabled
double virtualCursorPosX, virtualCursorPosY;
int autoIconify;
int cursorMode;
int decorated;
int doublebuffer;
int floating;
int focusOnShow;
int lockKeyMods;
int maxwidth, maxheight;
private double virtualCursorPosX, virtualCursorPosY;
private int autoIconify;
private int cursorMode;
private int decorated;
private int doublebuffer;
private int floating;
private int focusOnShow;
private int lockKeyMods;
private int maxwidth, maxheight;
int minwidth, minheight;
int mousePassthrough;
int numer, denom;
private int minwidth, minheight;
private int mousePassthrough;
private int numer, denom;
// Window settings and state
int resizable;
int shouldClose;
private int resizable;
private int shouldClose;
int stickyKeys;
int stickyMouseButtons;
IntPtr cursor; // _GLFWcursor* cursor;
private int stickyKeys;
private int stickyMouseButtons;
private IntPtr cursor; // _GLFWcursor* cursor;
// glfwVideomode videoMode; // 根据GLFWvidmode的定义转换
IntPtr monitor; // _GLFWmonitor* monitor;
public fixed byte keys[GLconst.GLFW_KEY_LAST + 1];
public fixed byte mouseButtons[GLconst.GLFW_MOUSE_BUTTON_LAST + 1];
private IntPtr monitor; // _GLFWmonitor* monitor;
public fixed byte keys[ GLconst.GLFW_KEY_LAST + 1 ];
public fixed byte mouseButtons[ GLconst.GLFW_MOUSE_BUTTON_LAST + 1 ];
// _GLFWcontext viewPortDisplay; // 根据_GLFWcontext的定义转换
@@ -312,14 +309,10 @@ namespace StgSharp.Graphics
// GLFW_PLATFORM_WINDOW_STATE platformWindowState;
}
[StructLayout( LayoutKind.Sequential )]
public struct GLFWwindowCallback { }
[StructLayout(LayoutKind.Sequential)]
public struct GLFWwindowCallback
{
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
public struct GLFWcursor
{
@@ -347,7 +340,7 @@ namespace StgSharp.Graphics
}
*/
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWinitconfig
{
@@ -361,7 +354,7 @@ namespace StgSharp.Graphics
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWwndconfig
{
@@ -392,31 +385,25 @@ namespace StgSharp.Graphics
internal X11 x11 = new X11();
public GLFWwndconfig()
{
}
public GLFWwndconfig() { }
internal struct Ns
{
private GLFWbool retina = false;
public fixed byte frameName[256];
public fixed byte frameName[ 256 ];
public Ns()
{
}
public Ns() { }
}
internal struct X11
{
public fixed byte className[256];
public fixed byte instanceName[256];
public fixed byte className[ 256 ];
public fixed byte instanceName[ 256 ];
public X11()
{
}
public X11() { }
}
@@ -430,17 +417,15 @@ namespace StgSharp.Graphics
internal struct Wl
{
public fixed byte appId[256];
public fixed byte appId[ 256 ];
public Wl()
{
}
public Wl() { }
}
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWctxconfig
{
@@ -461,9 +446,7 @@ namespace StgSharp.Graphics
internal Nsgl nsgl = new Nsgl();
public GLFWctxconfig()
{
}
public GLFWctxconfig() { }
internal struct Nsgl
{
@@ -474,7 +457,7 @@ namespace StgSharp.Graphics
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWfbconfig
{
@@ -500,11 +483,13 @@ namespace StgSharp.Graphics
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
internal unsafe struct GLFWlibrary
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = GLconst.GLFW_JOYSTICK_LAST + 1)]
[MarshalAs(
UnmanagedType.ByValArray,
SizeConst = GLconst.GLFW_JOYSTICK_LAST + 1 )]
private GLFWjoystick[] joysticks = new GLFWjoystick[GLconst.GLFW_JOYSTICK_LAST + 1];
private GLFWallocator allocator;
@@ -546,9 +531,7 @@ namespace StgSharp.Graphics
internal Osmesa osmesa = new Osmesa();
public GLFWlibrary()
{
}
public GLFWlibrary() { }
internal unsafe struct Hints
{
@@ -566,6 +549,7 @@ namespace StgSharp.Graphics
{
private ulong offset;
// This is defined in platform.h
//not transformed function defination
@@ -652,11 +636,9 @@ namespace StgSharp.Graphics
private GLFWbool KHR_xlib_surface;
private GLFWbool MVK_macos_surface;
private IntPtr GetInstanceProcAddr;
private fixed ulong extensions[2];
private fixed ulong extensions[ 2 ];
public vk()
{
}
public vk() { }
}
@@ -671,7 +653,7 @@ namespace StgSharp.Graphics
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWmapelement
{
@@ -684,25 +666,24 @@ namespace StgSharp.Graphics
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWmapping
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
[MarshalAs( UnmanagedType.ByValArray, SizeConst = 6 )]
private GLFWmapelement[] axes = new GLFWmapelement[6];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)]
[MarshalAs( UnmanagedType.ByValArray, SizeConst = 15 )]
private GLFWmapelement[] buttons = new GLFWmapelement[15];
private fixed byte guid[33];
private fixed byte guid[ 33 ];
private fixed byte name[128];
private fixed byte name[ 128 ];
public GLFWmapping()
{ }
public GLFWmapping() { }
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWjoystick
{
@@ -710,8 +691,8 @@ namespace StgSharp.Graphics
private byte* buttons;
private byte* hats;
private void* userPointer;
private fixed byte guid[33];
private fixed byte name[128];
private fixed byte guid[ 33 ];
private fixed byte name[ 128 ];
private GLFWbool allocated;
private GLFWbool connected;
@@ -726,20 +707,20 @@ namespace StgSharp.Graphics
// not completed in transforming
// GLFW_PLATFORM_JOYSTICK_STATE;
public GLFWjoystick()
{ }
public GLFWjoystick() { }
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWls
{
// This is defined in platform.h
//GLFW_PLATFORM_TLS_STATE
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWplatform
{
@@ -812,6 +793,7 @@ namespace StgSharp.Graphics
internal IntPtr setCursorMode;
#region input
/* void (* getCursorPos) (glfwWindow*, double*, double*);
void (* setCursorPos) (glfwWindow*, double, double);
void (* setCursorMode) (glfwWindow*, int);
@@ -878,6 +860,7 @@ namespace StgSharp.Graphics
void (* waitEventsTimeout) (double);
void (* postEmptyEvent) (void);
*/
#endregion
internal IntPtr setCursorPos;
@@ -910,25 +893,24 @@ namespace StgSharp.Graphics
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
public unsafe struct GLFWmutex
{
// This is defined in platform.h
//GLFW_PLATFORM_MUTEX_STATE
}
//public unsafe struct VkAllocationCallbacks { }
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
internal unsafe struct VkExtensionProperties
{
private fixed byte extensionName[256];
private fixed byte extensionName[ 256 ];
private uint specVersion;
public VkExtensionProperties()
{
}
public VkExtensionProperties() { }
}
@@ -947,14 +929,14 @@ namespace StgSharp.Graphics
}
*/
[StructLayout(LayoutKind.Explicit, Size = 16)]
[StructLayout( LayoutKind.Explicit, Size = 16 )]
public struct uintptr_t
{
[FieldOffset(0)]
[FieldOffset( 0 )]
private long part1;
[FieldOffset(8)]
[FieldOffset( 8 )]
private long part2;
}
@@ -963,7 +945,7 @@ namespace StgSharp.Graphics
#region glad struct
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
internal struct GLsync
{
@@ -39,27 +39,59 @@ namespace StgSharp.Graphics
/// <summary>
/// Function handler to load an opengl function by searching its name.
/// </summary>
/// <param name="name">the name of the Opengl function</param>
/// <returns>An Intptr value representing the pointer to the function</returns>
public delegate IntPtr glLoader(string name);
/// <param name="name"> the name of the Opengl function </param>
/// <returns> An Intptr value representing the pointer to the function </returns>
public delegate IntPtr glLoader( string name );
#region StgSharpDele
public unsafe delegate void FrameBufferSizeHandler(IntPtr window, uint width, uint height);
public unsafe delegate void FrameBufferSizeHandler(
IntPtr window,
int width,
int height );
public unsafe delegate void FramePositionHandler(IntPtr window, float width, float height);
public unsafe delegate void FramePositionHandler(
IntPtr window,
float width,
float height );
#endregion
#region glDEBUG
internal unsafe delegate void GLDEBUGPROC(int source, int type, uint id, int severity, int length, sbyte* message, void* userParam);
internal unsafe delegate void GLDEBUGPROCARB(int source, int type, uint id, int severity, int length, sbyte* message, void* userParam);
internal unsafe delegate void GLDEBUGPROCKHR(int source, int type, uint id, int severity, int length, sbyte* message, void* userParam);
internal unsafe delegate void GLDEBUGPROCAMD(uint id, int category, int severity, int length, sbyte* message, void* userParam);
#endregion
internal unsafe delegate void GLDEBUGPROC(
int source,
int type,
uint id,
int severity,
int length,
sbyte* message,
void* userParam );
internal unsafe delegate void GLDEBUGPROCARB(
int source,
int type,
uint id,
int severity,
int length,
sbyte* message,
void* userParam );
internal unsafe delegate void GLDEBUGPROCKHR(
int source,
int type,
uint id,
int severity,
int length,
sbyte* message,
void* userParam );
internal unsafe delegate void GLDEBUGPROCAMD(
uint id,
int category,
int severity,
int length,
sbyte* message,
void* userParam );
#endregion
}
+5 -15
View File
@@ -337,7 +337,6 @@ namespace StgSharp.Graphics.OpenGL
#region glad
public const int _1PASS_EXT = 0x80A1;
public const int _1PASS_SGIS = 0x80A1;
public const int _2PASS_0_EXT = 0x80A2;
@@ -4839,12 +4838,7 @@ namespace StgSharp.Graphics.OpenGL
public const int ZERO_TO_ONE = 0x935F;
public const int Z_EXT = 0x87D7;
#endregion
}
public static class glAttachment
@@ -4854,18 +4848,14 @@ namespace StgSharp.Graphics.OpenGL
public const uint DepthAndStencil = GLconst.DEPTH_STENCIL_ATTACHMENT;
public const uint Stencil = GLconst.STENCIL_ATTACHMENT;
private static int colorRange =
OpenGLFunction.CurrentGL.GetMaskInteger((uint)GLconst.MAX_COLOR_ATTACHMENTS);
public static uint Color(int i)
public static uint Color( int i )
{
#if DEBUG
if ((i > colorRange) || (i < 0))
{
#if DEBUG
if( ( i > OpenGLFunction.CurrentGL.AttachmentColorRange ) || ( i < 0 ) ) {
throw new ArgumentOutOfRangeException();
}
#endif
return (uint)(GLconst.COLOR_ATTACHMENT0 + i);
#endif
return ( uint )( GLconst.COLOR_ATTACHMENT0 + i );
}
}
+37 -8
View File
@@ -29,13 +29,13 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System.Runtime.CompilerServices;
namespace StgSharp.Graphics.OpenGL
{
public enum PixelChannelLayout
{
UByte = GLconst.UNSIGNED_BYTE,
Byte = GLconst.BYTE,
UShort = GLconst.UNSIGNED_SHORT,
@@ -55,10 +55,12 @@ namespace StgSharp.Graphics.OpenGL
UInt8888Rev = GLconst.UNSIGNED_INT_8_8_8_8_REV,
UInt1010102 = GLconst.UNSIGNED_INT_10_10_10_2,
UInt2101010Rev = GLconst.UNSIGNED_INT_2_10_10_10_REV
}
public enum FrameBufferStatus
{
Complete = GLconst.FRAMEBUFFER_COMPLETE, // GL_FRAMEBUFFER_COMPLETE
IncompleteAttachment = GLconst.FRAMEBUFFER_INCOMPLETE_ATTACHMENT, // GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
IncompleteMissingAttachment = GLconst.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, // GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
@@ -67,10 +69,12 @@ namespace StgSharp.Graphics.OpenGL
Unsupported = GLconst.FRAMEBUFFER_UNSUPPORTED, // GL_FRAMEBUFFER_UNSUPPORTED
IncompleteMultisample = GLconst.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, // GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
IncompleteLayerTargets = GLconst.FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS // GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
}
internal enum VkStructureType : uint
{
VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR = 1000004000,
VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR = 1000005000,
VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR = 1000006000,
@@ -78,10 +82,12 @@ namespace StgSharp.Graphics.OpenGL
VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK = 1000123000,
VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT = 1000217000,
VK_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF
}
public enum FrameBufferChannel
{
STENCIL_INDEX = GLconst.STENCIL_INDEX,
DEPTH_COMPONENT = GLconst.DEPTH_COMPONENT,
DEPTH_STENCIL = GLconst.DEPTH_STENCIL,
@@ -92,17 +98,22 @@ namespace StgSharp.Graphics.OpenGL
BGR = GLconst.BGR,
RGBA = GLconst.RGBA,
BGRA = GLconst.BGRA
}
public enum FrameBufferAttachment
{
Color = GLconst.COLOR_ATTACHMENT0,
Depth = GLconst.DEPTH_ATTACHMENT,
Stencil = GLconst.STENCIL_ATTACHMENT,
DepthAndStencil = GLconst.DEPTH_STENCIL_ATTACHMENT,
}
public enum Texture2DTarget
{
Texture2D = GLconst.TEXTURE_2D,
ProxyTexture2D = GLconst.PROXY_TEXTURE_2D,
Texture1DArray = GLconst.TEXTURE_1D_ARRAY,
@@ -116,21 +127,27 @@ namespace StgSharp.Graphics.OpenGL
TextureCubeMapPositiveZ = GLconst.TEXTURE_CUBE_MAP_POSITIVE_Z,
TextureCubeMapNegativeZ = GLconst.TEXTURE_CUBE_MAP_NEGATIVE_Z,
ProxyTextureCubeMap = GLconst.PROXY_TEXTURE_CUBE_MAP
}
public enum RenderBufferInternalFormat : uint
{
RGBA8 = GLconst.RGBA8,
Depth24_Stencil8 = GLconst.DEPTH24_STENCIL8,
}
public enum GLOperation : uint
{
StencilTest = GLconst.STENCIL_TEST,
}
internal enum VkResult
{
VK_SUCCESS = 0,
VK_NOT_READY = 1,
VK_TIMEOUT = 2,
@@ -155,22 +172,26 @@ namespace StgSharp.Graphics.OpenGL
VK_ERROR_NATIVE_WINDOW_IN_USE_KHR = -1000000001,
VK_ERROR_VALIDATION_FAILED_EXT = -1000011001,
VK_RESULT_MAX_ENUM = 0x7FFFFFFF
}
#pragma warning disable CA1008
#pragma warning disable CA1008
public enum ShaderType : int
#pragma warning restore CA1008
#pragma warning restore CA1008
{
Fragment = GLconst.FRAGMENT_SHADER,
Vertex = GLconst.VERTEX_SHADER,
Compute = GLconst.COMPUTE_SHADER,
Geometry = GLconst.GEOMETRY_SHADER,
}
#pragma warning disable CA1008 // 枚举应具有零值
#pragma warning disable CA1008 // 枚举应具有零值
public enum BufferType : int
#pragma warning restore CA1008 // 枚举应具有零值
#pragma warning restore CA1008 // 枚举应具有零值
{
ArrayBuffer = GLconst.ARRAY_BUFFER,
ElementArrayBuffer = GLconst.ELEMENT_ARRAY_BUFFER,
AtomicCounterBuffer = GLconst.ATOMIC_COUNTER_BUFFER,
@@ -185,12 +206,14 @@ namespace StgSharp.Graphics.OpenGL
TEXTURE_BUFFER = GLconst.TEXTURE_BUFFER,
TRANSFORM_FEEDBACK_BUFFER = GLconst.TRANSFORM_FEEDBACK_BUFFER,
UNIFORM_BUFFER = GLconst.UNIFORM_BUFFER,
}
#pragma warning disable CA1008 // 枚举应具有零值
#pragma warning disable CA1008 // 枚举应具有零值
public enum BufferUsage : int
#pragma warning restore CA1008 // 枚举应具有零值
#pragma warning restore CA1008 // 枚举应具有零值
{
StreamDraw = 0x88E0,
StreamRead = 0x88E1,
StreamCopy = 0x88E2,
@@ -200,18 +223,21 @@ namespace StgSharp.Graphics.OpenGL
DynamicDraw = 0x88E8,
DynamicRead = 0x88E9,
DynamicCopy = 0x88EA
}
}
public enum MaskBufferBit
{
COLOR = GLconst.COLOR_BUFFER_BIT,
DEPTH = GLconst.DEPTH_BUFFER_BIT,
STENCIL = GLconst.STENCIL_BUFFER_BIT,
}
public enum GeometryType : uint
{
POINTS = 0x0000,
LINES = 0x0001,
LINE_LOOP = 0x0002,
@@ -219,11 +245,14 @@ namespace StgSharp.Graphics.OpenGL
TRIANGLES = 0x0004,
TRIANGLE_STRIP = 0x0005,
TRIANGLE_FAN = 0x0006
}
public enum TextureFiltering
{
Nearest = 0x2600,
Linear = 0x2601
}
}
+75 -42
View File
@@ -36,81 +36,114 @@ using System.Collections.ObjectModel;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics
{
public delegate IntPtr GLfuncLoader(string name);
public delegate IntPtr GLfuncLoader( string name );
internal delegate void GLVULKANPROCNV();
public unsafe struct GLhandleARB
{
dynamic value;
private dynamic value;
public unsafe GLhandleARB(dynamic value)
public unsafe GLhandleARB( dynamic value )
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
if (value.GetType().Name != "Uint32")
{
if( !RuntimeInformation.IsOSPlatform( OSPlatform.OSX ) ) {
if( value.GetType().Name != "Uint32" ) {
goto errorlog;
}
this.value = value;
}
else
{
if (value.GetType().Name != "IntPtr")
{
} else {
if( value.GetType().Name != "IntPtr" ) {
goto errorlog;
}
this.value = value;
}
errorlog:
errorlog:
{
InternalIO.InternalWriteLog(
$"{value.GetType().Name} does not match definination of GLhandlARB on OS {Environment.OSVersion.Platform} ",
LogType.Error);
LogType.Error );
}
}
public static implicit operator uint(GLhandleARB value)
public static implicit operator uint( GLhandleARB value )
{
return (uint)value;
return ( uint )value;
}
}
#region GLFW_dele
internal unsafe delegate void GLFWwindowsizefun(glfwWindow* window, int width, int height);
internal unsafe delegate void GLFWwindowrefreshfun(glfwWindow* window);
internal unsafe delegate void GLFWwindowposfun(glfwWindow* window, int xpos, int ypos);
internal unsafe delegate void GLFWwindowmaximizefun(glfwWindow* window, int maximized);
internal unsafe delegate void GLFWwindowiconifyfun(glfwWindow* window, int iconified);
internal unsafe delegate void GLFWwindowfocusfun(glfwWindow* window, int focused);
internal unsafe delegate void GLFWwindowcontentscalefun(glfwWindow* window, float xscale, float yscale);
internal unsafe delegate void GLFWwindowclosefun(glfwWindow* window);
internal unsafe delegate void GLFWwindowsizefun(
glfwWindow* window,
int width,
int height );
internal unsafe delegate void GLFWwindowrefreshfun( glfwWindow* window );
internal unsafe delegate void GLFWwindowposfun(
glfwWindow* window,
int xpos,
int ypos );
internal unsafe delegate void GLFWwindowmaximizefun(
glfwWindow* window,
int maximized );
internal unsafe delegate void GLFWwindowiconifyfun(
glfwWindow* window,
int iconified );
internal unsafe delegate void GLFWwindowfocusfun(
glfwWindow* window,
int focused );
internal unsafe delegate void GLFWwindowcontentscalefun(
glfwWindow* window,
float xscale,
float yscale );
internal unsafe delegate void GLFWwindowclosefun( glfwWindow* window );
internal unsafe delegate void GLFWvkproc();
internal unsafe delegate void GLFWscrollfun(glfwWindow* window, double xoffset, double yoffset);
internal unsafe delegate void GLFWmousebuttonfun(glfwWindow* window, int button, int action, int mods);
internal unsafe delegate void GLFWmonitorfun(glfwMonitor* monitor, int monitorevent);
internal unsafe delegate void GLFWkeyfun(glfwWindow* window, int key, int scancode, int action, int mods);
internal unsafe delegate void GLFWjoystickfun(int jid, int keyevent);
internal unsafe delegate void GLFWscrollfun(
glfwWindow* window,
double xoffset,
double yoffset );
internal unsafe delegate void GLFWmousebuttonfun(
glfwWindow* window,
int button,
int action,
int mods );
internal unsafe delegate void GLFWmonitorfun(
glfwMonitor* monitor,
int monitorevent );
internal unsafe delegate void GLFWkeyfun(
glfwWindow* window,
int key,
int scancode,
int action,
int mods );
internal unsafe delegate void GLFWjoystickfun( int jid, int keyevent );
public unsafe delegate void GLFWglproc();
internal unsafe delegate void GLFWerrorfun(int error_code, sbyte* description);
internal unsafe delegate void GLFWdropfun(glfwWindow* window, int path_count, sbyte*[] paths);
internal unsafe delegate void GLFWcursorposfun(glfwWindow* window, double xpos, double ypos);
internal unsafe delegate void GLFWcursorenterfun(glfwWindow* window, int entered);
internal unsafe delegate void GLFWcharmodsfun(glfwWindow* window, uint codepoint, int mods);
internal unsafe delegate void GLFWcharfun(glfwWindow* window, uint codepoint);
#endregion
internal unsafe delegate void GLFWerrorfun(
int error_code,
sbyte* description );
internal unsafe delegate void GLFWdropfun(
glfwWindow* window,
int path_count,
sbyte*[] paths );
internal unsafe delegate void GLFWcursorposfun(
glfwWindow* window,
double xpos,
double ypos );
internal unsafe delegate void GLFWcursorenterfun(
glfwWindow* window,
int entered );
internal unsafe delegate void GLFWcharmodsfun(
glfwWindow* window,
uint codepoint,
int mods );
internal unsafe delegate void GLFWcharfun(
glfwWindow* window,
uint codepoint );
#endregion
}
+4 -2
View File
@@ -37,8 +37,10 @@ namespace StgSharp.Graphics
public interface IGraphicAPIs
{
public IntPtr GraphicApiPackageHandle { get; }
public IntPtr GraphicApiPackageHandle
{
get;
}
}
}
+116 -81
View File
@@ -46,32 +46,43 @@ namespace StgSharp.Graphics
{
public class Image : ISSDSerializable, IImageProvider
{
private byte[] _data;
private ImageInfo info;
private ImageInfo _rawInfo;
private int _pixelUpdateCount = 0;
internal unsafe Image()
{
info = new ImageInfo();
_rawInfo = new ImageInfo();
}
internal Image(ImageInfo information)
internal Image( ImageInfo information )
{
info = information;
_rawInfo = information;
_data = Array.Empty<byte>();
//int length = info.width * info.height * info.channel;
}
internal ref byte[] Data
{
get => ref _data;
//int length = _rawInfo.width * _rawInfo.height * _rawInfo.channel;
}
public (int width, int height) Size
{
get => (info.Width, info.Height);
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>
@@ -81,59 +92,51 @@ namespace StgSharp.Graphics
internal set => _pixelUpdateCount = value;
}
public byte[] PixelBuffer
{
get
{
if ((_data.Length == 0) || (_data == null))
{
GetBytes();
return _data!;
}
return _data;
}
}
public int ChannelCount => _rawInfo.ChannelCount;
public ImageChannel Channel => info.Channel;
public int ChannelCount => info.ChannelCount;
public int Height
{
get => info.Height;
internal set => info.Height = value;
get => _rawInfo.Height;
internal set => _rawInfo.Height = value;
}
public int Width
{
get => info.Width;
internal set => info.Width = value;
get => _rawInfo.Width;
internal set => _rawInfo.Width = value;
}
public int PixelSize => GlHelper.GetPixelSize(info.pixelLayout, info.Channel);
public int PixelSize => GlHelper.GetPixelSize(
_rawInfo.pixelLayout, _rawInfo.Channel );
public PixelChannelLayout PixelLayout
{
get => info.pixelLayout;
private set => info.pixelLayout = value;
get => _rawInfo.pixelLayout;
private set => _rawInfo.pixelLayout = value;
}
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
public void FromBytes(byte[] stream)
internal ref byte[] Data
{
get => ref _data;
}
public static unsafe Image FromFile(string route, ImageLoader loader)
public void FromBytes( byte[] stream ) { }
public static unsafe Image FromFile( string route, ImageLoader loader )
{
Image ret = new Image();
fixed (ImageInfo* iptr = &ret.info)
{
InternalIO.InternalLoadImage(route, iptr, loader);
fixed( ImageInfo* iptr = &ret._rawInfo ) {
InternalIO.InternalLoadImage( route, iptr, loader );
}
return ret;
}
public static Image FromMemory((int width, int height) size, ImageChannel channel, byte[] stream)
public static Image FromMemory(
(int width, int height) size,
ImageChannel channel,
byte[] stream )
{
ImageInfo _info = new ImageInfo
{
@@ -142,13 +145,17 @@ namespace StgSharp.Graphics
Channel = channel,
StreamPtr = IntPtr.Zero
};
Image ret = new Image(_info);
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)
public static Image FromMemory(
(int width, int height) size,
ImageChannel channel,
PixelChannelLayout layout,
byte[] stream )
{
ImageInfo _info = new ImageInfo
{
@@ -157,7 +164,7 @@ namespace StgSharp.Graphics
Channel = channel,
StreamPtr = IntPtr.Zero
};
Image ret = new Image(_info);
Image ret = new Image( _info );
ret.PixelLayout = layout;
ret._data = stream;
return ret;
@@ -165,20 +172,34 @@ namespace StgSharp.Graphics
public unsafe byte[] GetBytes()
{
if (_data.Length == 0)
{
int size = Width * Height * GlHelper.GetPixelSize(PixelLayout, Channel);
_data = new Span<byte>((byte*)info.StreamPtr, size).ToArray();
fixed (ImageInfo* pptr = &info)
{
InternalIO.InternalUnloadImage(pptr);
if( _data.Length == 0 ) {
int size = Width * Height * GlHelper.GetPixelSize(
PixelLayout, Channel );
_data = new Span<byte>( ( byte* )_rawInfo.StreamPtr,
size ).ToArray();
fixed( ImageInfo* pptr = &_rawInfo ) {
InternalIO.InternalUnloadImage( pptr );
}
info.StreamPtr = IntPtr.Zero;
_rawInfo.StreamPtr = IntPtr.Zero;
}
return _data;
}
public Image ProvideImage() => 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();
@@ -186,7 +207,7 @@ namespace StgSharp.Graphics
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout( LayoutKind.Sequential )]
internal struct ImageInfo
{
@@ -204,7 +225,7 @@ namespace StgSharp.Graphics
public int ChannelCount
{
get => GlHelper.GetChannelCount(channel);
get => GlHelper.GetChannelCount( channel );
}
public int Height
@@ -215,7 +236,8 @@ namespace StgSharp.Graphics
public int StreamSize
{
get => width * height * GlHelper.GetPixelSize(pixelLayout, channel);
get => width * height * GlHelper.GetPixelSize(
pixelLayout, channel );
}
public int Width
@@ -230,27 +252,30 @@ namespace StgSharp.Graphics
internal set => pixelPtr = value;
}
public override string ToString()
{
return $"{channel}\t{width}\t{height}\t{(ulong)StreamPtr}";
}
public override int GetHashCode()
{
int hash = 17;
hash = hash * 17 + width;
hash = hash * 17 + height;
hash = hash * 17 + (int)channel;
hash = hash * 17 + ( int )channel;
return hash;
}
public override string ToString()
{
return $"{channel}\t{width}\t{height}\t{(ulong)StreamPtr}";
}
}
public enum ImageChannel : uint
{
SingleColor = GLconst.RED,
DoubleColor = GLconst.RG,
TripleColor = GLconst.RGB,
WithAlphaChannel = GLconst.RGBA,
}
}
@@ -259,7 +284,7 @@ namespace StgSharp.Graphics.OpenGL
public static partial class GlHelper
{
internal static int GetChannelCount(ImageChannel channel)
internal static int GetChannelCount( ImageChannel channel )
{
return channel switch
{
@@ -267,34 +292,44 @@ namespace StgSharp.Graphics.OpenGL
ImageChannel.DoubleColor => 2,
ImageChannel.TripleColor => 3,
ImageChannel.WithAlphaChannel => 4,
_ => throw new InvalidCastException("Unknown color channel decoding setting.")
_ => throw new InvalidCastException(
"Unknown color channel decoding setting." )
};
}
internal static int GetPixelSize(PixelChannelLayout layout, ImageChannel cahnnel)
internal static int GetPixelSize(
PixelChannelLayout layout,
ImageChannel cahnnel )
{
return layout switch
{
PixelChannelLayout.UByte => sizeof(byte) * GetChannelCount(cahnnel),
PixelChannelLayout.Byte => sizeof(byte) * GetChannelCount(cahnnel),
PixelChannelLayout.UShort => sizeof(short) * GetChannelCount(cahnnel),
PixelChannelLayout.Short => sizeof(short) * GetChannelCount(cahnnel),
PixelChannelLayout.UInt => sizeof(int) * GetChannelCount(cahnnel),
PixelChannelLayout.Int => sizeof(int) * GetChannelCount(cahnnel),
PixelChannelLayout.Float => sizeof(float) * GetChannelCount(cahnnel),
PixelChannelLayout.UByte332 => sizeof(byte),
PixelChannelLayout.UByte233Rev => sizeof(byte),
PixelChannelLayout.UShort565 => sizeof(short),
PixelChannelLayout.UShort565Rev => sizeof(short),
PixelChannelLayout.UShort4444 => sizeof(short),
PixelChannelLayout.UShort4444Rev => sizeof(short),
PixelChannelLayout.UShort5551 => sizeof(short),
PixelChannelLayout.UShort1555Rev => sizeof(short),
PixelChannelLayout.UInt8888 => sizeof(int),
PixelChannelLayout.UInt8888Rev => sizeof(int),
PixelChannelLayout.UInt1010102 => sizeof(int),
PixelChannelLayout.UInt2101010Rev => sizeof(int),
_ => throw new ArgumentException("Unknown layout type"),
PixelChannelLayout.UByte => sizeof( byte ) * GetChannelCount(
cahnnel ),
PixelChannelLayout.Byte => sizeof( byte ) * GetChannelCount(
cahnnel ),
PixelChannelLayout.UShort => sizeof( short ) * GetChannelCount(
cahnnel ),
PixelChannelLayout.Short => sizeof( short ) * GetChannelCount(
cahnnel ),
PixelChannelLayout.UInt => sizeof( int ) * GetChannelCount(
cahnnel ),
PixelChannelLayout.Int => sizeof( int ) * GetChannelCount(
cahnnel ),
PixelChannelLayout.Float => sizeof( float ) * GetChannelCount(
cahnnel ),
PixelChannelLayout.UByte332 => sizeof( byte ),
PixelChannelLayout.UByte233Rev => sizeof( byte ),
PixelChannelLayout.UShort565 => sizeof( short ),
PixelChannelLayout.UShort565Rev => sizeof( short ),
PixelChannelLayout.UShort4444 => sizeof( short ),
PixelChannelLayout.UShort4444Rev => sizeof( short ),
PixelChannelLayout.UShort5551 => sizeof( short ),
PixelChannelLayout.UShort1555Rev => sizeof( short ),
PixelChannelLayout.UInt8888 => sizeof( int ),
PixelChannelLayout.UInt8888Rev => sizeof( int ),
PixelChannelLayout.UInt1010102 => sizeof( int ),
PixelChannelLayout.UInt2101010Rev => sizeof( int ),
_ => throw new ArgumentException( "Unknown layout type" ),
};
}
@@ -29,60 +29,60 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Collections;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using StgSharp.Collections;
using System.Threading.Tasks;
namespace StgSharp.Graphics.OpenGL
{
/// <summary>
/// A collection of a sets of OpenGL textures. The collection can automatically select one of the
/// texture with minimum costs to upgrade pixels to buffer. Usually <see cref="AutoTextureGL"/> is used for
/// <see cref="IImageProvider"/> loading, but not for target of
/// <see cref="OpenGLFunction.FrameBufferTexture2d(FrameBufferTarget, uint, Texture2DTarget, GlHandle, int)"/>.
/// A collection of a sets of OpenGL textures. The collection can automatically select one of
/// the texture with minimum costs to upgrade pixels to buffer. Usually <see
/// cref="AutoTextureGL" /> is used for <see cref="IImageProvider" /> loading, but not for
/// target of <see cref="OpenGLFunction.FrameBufferTexture2d(FrameBufferTarget, uint,
/// Texture2DTarget, GlHandle, int)" />.
/// </summary>
public sealed class AutoTextureGL
{
private BidirectionalDictionary<Image, int> imageIndexMap = new BidirectionalDictionary<Image, int>();
private Dictionary<Image, int> imageUpdateIndex = new Dictionary<Image, int>();
private TextureProperty[] propertyCache;
private BidirectionalDictionary<Image, int> imageIndexMap = new BidirectionalDictionary<Image, int>(
);
private Dictionary<Image, int> imageUpdateIndex = new Dictionary<Image, int>(
);
private int _size, _currentIndex;
private LinkedList<int> usedTextureIndex;
private Queue<int> unusedTextureUnitIndex;
private TextureProperty[] propertyCache;
private TextureGL texturePackage;
private TextureProperty _textureProperty;
private OpenGLFunction GL
{
get => texturePackage.GL;
}
private AutoTextureGL(TextureGL texture)
private AutoTextureGL( TextureGL texture )
{
texturePackage = texture;
_size = texture.Count;
imageIndexMap = new BidirectionalDictionary<Image, int>();
unusedTextureUnitIndex = new Queue<int>(
Enumerable.Range(0, _size));
Enumerable.Range( 0, _size ) );
usedTextureIndex = new LinkedList<int>();
propertyCache = new TextureProperty[_size];
}
public AutoTextureGL(int textureObjectSize, [NotNull]glRender binding)
public AutoTextureGL( int textureObjectSize, [NotNull]glRender binding )
{
this._size = textureObjectSize;
imageIndexMap = new BidirectionalDictionary<Image, int>();
texturePackage = new TextureGL(textureObjectSize, binding);
texturePackage = new TextureGL( textureObjectSize, binding );
unusedTextureUnitIndex = new Queue<int>(
Enumerable.Range(0, _size));
Enumerable.Range( 0, _size ) );
usedTextureIndex = new LinkedList<int>();
propertyCache = new TextureProperty[_size];
}
@@ -93,75 +93,70 @@ namespace StgSharp.Graphics.OpenGL
set => _textureProperty = value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SelectTextureAndBind(Image i)
private OpenGLFunction GL
{
get => texturePackage.GL;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SelectTextureAndBind( Image i )
{
TextureProperty property = _textureProperty;
SelectTextureAndBind(i, property);
SelectTextureAndBind( i, property );
}
public void SelectTextureAndBind([NotNull]Image i, TextureProperty property)
public void SelectTextureAndBind(
[NotNull]Image i,
TextureProperty property )
{
//usable texture with image match
if (imageIndexMap.TryGetValue(i, out int index))
{
if( imageIndexMap.TryGetValue( i, out int index ) ) {
//prop setting match
if (propertyCache[index] == property)
{
if( propertyCache[ index ] == property ) {
_currentIndex = index; //GL.Assert(true);
texturePackage.Bind2D(index); //GL.Assert(true);
if (i.PixelUpdateCount != imageUpdateIndex[i])
{
texturePackage.LoadTexture(index, i); //GL.Assert(true);
texturePackage.Bind2D( index ); //GL.Assert(true);
if( i.PixelUpdateCount != imageUpdateIndex[ i ] ) {
texturePackage.LoadTexture( index, i ); //GL.Assert(true);
}
} else {
_currentIndex = index; //GL.Assert(true);
texturePackage.Bind2D( index ); //GL.Assert(true);
texturePackage.Set2dProperty( index, property ); //GL.Assert(true);
if( i.PixelUpdateCount != imageUpdateIndex[ i ] ) {
texturePackage.LoadTexture( index, i ); //GL.Assert(true);
}
}
else
{
_currentIndex = index; //GL.Assert(true);
texturePackage.Bind2D(index); //GL.Assert(true);
texturePackage.Set2dProperty(index, property); //GL.Assert(true);
if (i.PixelUpdateCount != imageUpdateIndex[i])
{
texturePackage.LoadTexture(index, i); //GL.Assert(true);
}
}
}
else
{
if (unusedTextureUnitIndex.TryDequeue(out int newIndex))
{
} else {
if( unusedTextureUnitIndex.TryDequeue( out int newIndex ) ) {
//has extra unused texture object
imageIndexMap.Add(i, index);
texturePackage.Bind2D(index);
texturePackage.Set2dProperty(index, property);
texturePackage.LoadTexture(index, i);
usedTextureIndex.AddLast(newIndex);
propertyCache[newIndex] = property;
imageUpdateIndex[i] = i.PixelUpdateCount;
}
else
{
imageIndexMap.Add( i, index );
texturePackage.Bind2D( index );
texturePackage.Set2dProperty( index, property );
texturePackage.LoadTexture( index, i );
usedTextureIndex.AddLast( newIndex );
propertyCache[ newIndex ] = property;
imageUpdateIndex[ i ] = i.PixelUpdateCount;
} else {
//recycle from current
int reusedIndex = usedTextureIndex.First!.Value;
usedTextureIndex.RemoveFirst();
usedTextureIndex.AddLast(reusedIndex);
imageIndexMap[i] = reusedIndex;
propertyCache[newIndex] = property;
imageUpdateIndex[i] = i.PixelUpdateCount;
usedTextureIndex.AddLast( reusedIndex );
imageIndexMap[ i ] = reusedIndex;
propertyCache[ newIndex ] = property;
imageUpdateIndex[ i ] = i.PixelUpdateCount;
}
}
}
public static AutoTextureGL ToAuto([NotNull]TextureGL texture)
public static AutoTextureGL ToAuto( [NotNull]TextureGL texture )
{
if (texture.IndexOfCurrentTexture != -1)
{
throw new InvalidOperationException("Texture to be converted has been editted.");
if( texture.IndexOfCurrentTexture != -1 ) {
throw new InvalidOperationException(
"Texture to be converted has been editted." );
}
return new AutoTextureGL(texture);
return new AutoTextureGL( texture );
}
}
}
@@ -41,42 +41,50 @@ using System.Text;
namespace StgSharp.Graphics.OpenGL
{
/// <summary>
/// A collection of handle to Element Buffer Object in OpenglFunc.
/// Each <see langword="uint"/> value indexed from instance of this class this
/// is the only handle to one Element Buffer Object.
/// A collection of handle to Element Buffer Object in OpenglFunc. Each <see langword="uint" />
/// value indexed from instance of this class this is the only handle to one Element Buffer
/// Object.
/// </summary>
public sealed unsafe class ElementBuffer : GlBufferObjectBase
{
internal ElementBuffer(int n, glRender binding) : base(binding)
internal ElementBuffer( int n, glRender binding )
: base( binding )
{
_bufferHandle = GL.GenBuffers(n);
_bufferHandle = GL.GenBuffers( n );
}
public override sealed void Bind(int index)
public override sealed void Bind( int index )
{
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
GL.BindBuffer(
BufferType.ElementArrayBuffer, _bufferHandle[ index ] );
}
public void SetValue<T>(int index, T[] bufferArray, BufferUsage usage)
where T : struct, IConvertible
public void SetValue<T>( int index, T[] bufferArray, BufferUsage usage )
where T: struct, IConvertible
{
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
GL.SetBufferData(BufferType.ElementArrayBuffer, bufferArray, usage);
GL.BindBuffer(
BufferType.ElementArrayBuffer, _bufferHandle[ index ] );
GL.SetBufferData(
BufferType.ElementArrayBuffer, bufferArray, usage );
}
public void SetValue<T>(int index, ReadOnlySpan<T> bufferSpan, BufferUsage usage)
where T : struct, IConvertible
public void SetValue<T>(
int index,
ReadOnlySpan<T> bufferSpan,
BufferUsage usage )
where T: struct, IConvertible
{
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
GL.SetBufferData(BufferType.ElementArrayBuffer, bufferSpan, usage);
GL.BindBuffer(
BufferType.ElementArrayBuffer, _bufferHandle[ index ] );
GL.SetBufferData( BufferType.ElementArrayBuffer, bufferSpan,
usage );
}
protected override sealed void Dispose(bool disposing)
protected override sealed void Dispose( bool disposing )
{
if (disposing)
{
GL.DeleteBuffers(_bufferHandle);
if( disposing ) {
GL.DeleteBuffers( _bufferHandle );
}
}
@@ -40,55 +40,59 @@ using System.Threading.Tasks;
namespace StgSharp.Graphics.OpenGL
{
#pragma warning disable CA1008
#pragma warning disable CA1028
#pragma warning disable CA1008
#pragma warning disable CA1028
public enum FrameBufferTarget : uint
#pragma warning restore CA1028
#pragma warning restore CA1008
#pragma warning restore CA1028
#pragma warning restore CA1008
{
Read = GLconst.READ_FRAMEBUFFER,
All = GLconst.FRAMEBUFFER,
Draw = GLconst.DRAW_FRAMEBUFFER,
}
public sealed class FrameBuffer : GlBufferObjectBase
{
internal unsafe FrameBuffer(int count, glRender binding) : base(binding)
internal unsafe FrameBuffer( int count, glRender binding )
: base( binding )
{
_bufferHandle = GL.GenFrameBuffers(count);
_bufferHandle = GL.GenFrameBuffers( count );
}
/// <summary>
/// Bind the frame buffer object with name frame buffer to the frame buffer target specified by target.
/// <see langword="FrameBufferTarget.All"/> will be set as default target.
/// Bind the frame buffer object with name frame buffer to the frame buffer target specified
/// by target. <see langword="FrameBufferTarget.All" /> will be set as default target.
/// </summary>
/// <param name="index">Index of object to be binded in handle set</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override unsafe void Bind(int index)
/// <param name="index"> Index of object to be binded in handle set </param>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public override unsafe void Bind( int index )
{
GL.BindFrameBuffer(FrameBufferTarget.All, _bufferHandle[index]);
GL.BindFrameBuffer( FrameBufferTarget.All, _bufferHandle[ index ] );
}
/// <summary>
/// Bind the frame buffer object with name frame buffer to the frame buffer target specified by target.
/// Target of this frame buffer should be set manually.
/// Bind the frame buffer object with name frame buffer to the frame buffer target specified
/// by target. Target of this frame buffer should be set manually.
/// </summary>
/// <param name="target">The frame buffer target of the binding operation.</param>
/// <param name="index">Index of object to be binded in handle set</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Bind(FrameBufferTarget target, int index)
/// <param name="target"> The frame buffer target of the binding operation. </param>
/// <param name="index"> Index of object to be binded in handle set </param>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void Bind( FrameBufferTarget target, int index )
{
GL.BindFrameBuffer(target, _bufferHandle[index]);
GL.BindFrameBuffer( target, _bufferHandle[ index ] );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static void BindNull()
{
OpenGLFunction.CurrentGL.BindFrameBuffer(FrameBufferTarget.All, GlHandle.Zero);
OpenGLFunction.CurrentGL
.BindFrameBuffer( FrameBufferTarget.All, GlHandle.Zero );
}
protected override void Dispose(bool disposing)
protected override void Dispose( bool disposing )
{
throw new NotImplementedException();
}
@@ -41,7 +41,7 @@ namespace StgSharp.Graphics.OpenGL
private readonly glRender _contextBinding;
protected GlBufferObjectBase(glRender contextBinding)
protected GlBufferObjectBase( glRender contextBinding )
{
binding = contextBinding;
_contextBinding = contextBinding;
@@ -35,36 +35,38 @@ using System.Collections.Generic;
using System.Security.Principal;
using System.Text;
namespace StgSharp.Graphics.OpenGL
{
public sealed class RenderBuffer : GlBufferObjectBase
{
public RenderBuffer(int count, glRender binding) : base(binding)
public RenderBuffer( int count, glRender binding )
: base( binding )
{
_bufferHandle = GL.GenRenderBuffer(count);
_bufferHandle = GL.GenRenderBuffer( count );
}
public override void Bind(int index)
public override void Bind( int index )
{
GL.BindRenderBuffer(this[index]);
GL.BindRenderBuffer( this[ index ] );
}
public void Store(RenderBufferInternalFormat format, (int width, int height) size)
public void Store(
RenderBufferInternalFormat format,
(int width, int height) size )
{
if ((size.width > binding.Width) || (size.height > binding.Height))
{
StgSharp.LogWarning("FrameBuffer is larger than current canvas binding");
if( ( size.width > binding.Width ) || ( size.height > binding.Height ) ) {
StgSharp.LogWarning(
"FrameBuffer is larger than current canvas binding" );
}
}
protected override void Dispose(bool disposing)
protected override void Dispose( bool disposing )
{
throw new NotImplementedException();
foreach( GlHandle item in _bufferHandle ) {
Console.WriteLine( "removing a render buffer" );
GL.DeleteRenderBuffer( item );
}
}
}
@@ -28,7 +28,7 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Data;
using StgSharp.Data.Intrinsic;
using StgSharp.Math;
using System;
@@ -58,8 +58,6 @@ namespace StgSharp.Graphics.OpenGL
_textureHandle = _gl.GenTextures( count );
}
internal OpenGLFunction GL => _gl;
public GlHandle this[ int index ]
{
get => _textureHandle[ index ];
@@ -77,12 +75,17 @@ namespace StgSharp.Graphics.OpenGL
get => currentEditingTextureIndex;
}
public void ActivateAs( TextureUnit unit ) { _gl.ActiveTextureUnit( ( uint )unit ); }
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 ] );
_gl.BindTexture( GLconst.TEXTURE_2D, _textureHandle[ index ] );
}
/// <summary>
@@ -94,8 +97,8 @@ namespace StgSharp.Graphics.OpenGL
{
byte[] handle = i.PixelBuffer;
_gl.TextureImage2d(
Texture2DTarget.Texture2D, 0, ( uint )i.Channel, ( uint )i.Width, ( uint )i.Height,
( uint )i.Channel, i.PixelLayout, pixels: handle );
Texture2DTarget.Texture2D, 0, i.Channel, ( uint )i.Width,
( uint )i.Height, i.Channel, i.PixelLayout, pixels: handle );
_gl.GenerateMipmap( Texture2DTarget.Texture2D );
}
@@ -108,14 +111,17 @@ namespace StgSharp.Graphics.OpenGL
TextureFilter onMagnify )
{
#if DEBUG
if( index != currentEditingTextureIndex )
{
if( index != currentEditingTextureIndex ) {
throw new InvalidOperationException(
"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_MAG_FILTER, ( int )onMagnify );
_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 )]
@@ -125,21 +131,25 @@ namespace StgSharp.Graphics.OpenGL
TextureWrap onVertical )
{
#if DEBUG
if( index != currentEditingTextureIndex )
{
if( index != currentEditingTextureIndex ) {
throw new InvalidOperationException(
"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 );
_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 );
Set2dFilterProperty(
index, property.FilterOnMinify, property.FilterOnMagnify );
Set2dWrapProperty(
index, property.WrapOnHorizontial, property.WrapOnVertical );
}
#endregion texture setting
@@ -192,23 +202,35 @@ namespace StgSharp.Graphics.OpenGL
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 bool Equals([NotNullWhen(true)] object obj)
{
return base.Equals(obj);
FilterOnMagnify, FilterOnMagnify, WrapOnHorizontial,
WrapOnVertical );
}
public override string ToString()
{
return $"FilterOnMagnify:{FilterOnMagnify}, " +
$"FilterOnMagnify:{FilterOnMagnify}, " +
$"WrapOnHorizontial:{WrapOnHorizontial}, " +
$"WrapOnVertical:{WrapOnVertical}";
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(
@@ -219,18 +241,10 @@ namespace StgSharp.Graphics.OpenGL
{
return new TextureProperty(
propertyValueTuple.onMagnify, propertyValueTuple.onMinify,
propertyValueTuple.onHorizontial, propertyValueTuple.onVertical );
propertyValueTuple.onHorizontial,
propertyValueTuple.onVertical );
}
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;
}
}
#pragma warning disable CA1008
@@ -29,7 +29,6 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
@@ -40,37 +39,41 @@ namespace StgSharp.Graphics.OpenGL
public sealed unsafe class VertexArray : GlBufferObjectBase
{
internal VertexArray(int n, glRender binding) : base(binding)
internal VertexArray( int n, glRender binding )
: base( binding )
{
_bufferHandle = GL.GenVertexArrays(n);
_bufferHandle = GL.GenVertexArrays( n );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override sealed void Bind(int index)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public override sealed void Bind( int index )
{
GL.BindVertexArray(_bufferHandle[index]);
GL.BindVertexArray( _bufferHandle[ index ] );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static void BindNull()
{
OpenGLFunction.CurrentGL.BindVertexArray(GlHandle.Zero);
OpenGLFunction.CurrentGL.BindVertexArray( GlHandle.Zero );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetVertexAttribute(uint index, int vertexLength, TypeCode dataType, bool isNomalized, uint stride, int pointer)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetVertexAttribute(
uint index,
int vertexLength,
TypeCode dataType,
bool isNomalized,
uint stride,
int pointer )
{
GL.SetVertexAttribute(
index, vertexLength, dataType,
isNomalized,
stride, pointer);
index, vertexLength, dataType, isNomalized, stride, pointer );
}
protected override sealed void Dispose(bool disposing)
protected override sealed void Dispose( bool disposing )
{
if (disposing)
{
GL.DeleteVertexArrays(_bufferHandle);
if( disposing ) {
GL.DeleteVertexArrays( _bufferHandle );
}
}
@@ -43,108 +43,126 @@ namespace StgSharp.Graphics.OpenGL
public sealed unsafe class VertexBuffer : GlBufferObjectBase
{
internal VertexBuffer(int n, glRender binding) : base(binding)
internal VertexBuffer( int n, glRender binding )
: base( binding )
{
_bufferHandle = GL.GenBuffers(n);
_bufferHandle = GL.GenBuffers( n );
}
public override sealed void Bind(int index)
public override sealed void Bind( int index )
{
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
}
/// <summary>
///
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void Unbind()
{
GL.BindBuffer(BufferType.ArrayBuffer, GlHandle.Zero);
GL.BindBuffer( BufferType.ArrayBuffer, GlHandle.Zero );
}
/// <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="bufferData">Data to write in</param>
/// <param name="usage">How OpenGL use these _data, defined by <see cref="BufferUsage"/></param>
public void WriteMatrixData<T>(int index, T bufferData, BufferUsage usage)
where T : struct, IMat
/// <typeparam name="T"> Type of bufferData </typeparam>
/// <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 WriteMatrixData<T>(
int index,
T bufferData,
BufferUsage usage )
where T: struct, IMat
{
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
GL.SetBufferData(BufferType.ArrayBuffer, bufferData, usage);
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
GL.SetBufferData( BufferType.ArrayBuffer, bufferData, 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="bufferArray">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, T[] bufferArray, BufferUsage usage)
where T : struct,
/// <typeparam name="T"> Type of bufferData </typeparam>
/// <param name="index"> Index to find certain VBO in this instance </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 WriteScalerData<T>(
int index,
T[] bufferArray,
BufferUsage usage )
where T: struct,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
#endif
{
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
GL.SetBufferData(BufferType.ArrayBuffer, bufferArray, usage);
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
GL.SetBufferData( BufferType.ArrayBuffer, 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, ReadOnlySpan<T> scalerSpan, BufferUsage usage)
where T : struct,
/// <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,
ReadOnlySpan<T> scalerSpan,
BufferUsage usage )
where T: struct,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
#endif
{
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
GL.SetBufferData(BufferType.ArrayBuffer, scalerSpan, usage);
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
GL.SetBufferData( BufferType.ArrayBuffer, 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, ReadOnlySpan<T> vectorSpan, BufferUsage usage) where T : struct, IVector
/// <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,
ReadOnlySpan<T> vectorSpan,
BufferUsage usage )
where T: struct, IVector
{
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
GL.SetBufferVectorData(BufferType.ArrayBuffer, vectorSpan, usage);
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
GL.SetBufferVectorData( BufferType.ArrayBuffer, 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
/// <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.ArrayBuffer, _bufferHandle[index]);
GL.SetBufferVectorData(BufferType.ArrayBuffer, vectorArray, usage);
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
GL.SetBufferVectorData( BufferType.ArrayBuffer, vectorArray,
usage );
}
protected override sealed void Dispose(bool disposing)
protected override sealed void Dispose( bool disposing )
{
if (disposing)
{
GL.DeleteBuffers(_bufferHandle);
if( disposing ) {
GL.DeleteBuffers( _bufferHandle );
}
}
@@ -42,22 +42,25 @@ namespace StgSharp.Graphics.ShaderEdit
{
/// <summary>
///
///
/// </summary>
public void DisplayGLtypeDefinition();
/// <summary>
///
///
/// </summary>
public void GainAllUniforms(ShaderProgram source, params string[] uniformName);
public void GainAllUniforms(
ShaderProgram source,
params string[] uniformName );
/// <summary>
///
///
/// </summary>
/// <returns></returns>
public ShaderStruct GetConvertedGLtype();
/// <summary>
///
///
/// </summary>
public void SetAllUniforms();
@@ -45,19 +45,21 @@ namespace StgSharp.Graphics.OpenGL
{
/// <summary>
/// Create an instance of <see cref="Shader"/> program
/// Create an instance of <see cref="Shader" /> program
/// </summary>
/// <returns>New instance of <see cref="Shader"/> instance. </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
/// <returns> New instance of <see cref="Shader" /> instance. </returns>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
protected override sealed ShaderProgram CreateShaderProgram()
{
return new ShaderProgram(this);
return new ShaderProgram( this );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override sealed Shader CreateShaderSegment(ShaderType type, int count)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
protected override sealed Shader CreateShaderSegment(
ShaderType type,
int count )
{
return new Shader(GL.CreateShaderSet(count, type), type, this);
return new Shader( GL.CreateShaderSet( count, type ), type, this );
}
}
@@ -69,7 +71,10 @@ namespace StgSharp.Graphics.OpenGL
internal readonly GlHandle[] handle;
public readonly ShaderType type;
internal unsafe Shader(GlHandle[] handle, ShaderType usage, glRender stream)
internal unsafe Shader(
GlHandle[] handle,
ShaderType usage,
glRender stream )
{
this.handle = handle;
GL = stream.GL;
@@ -81,60 +86,58 @@ namespace StgSharp.Graphics.OpenGL
/// <summary>
/// Attach one shader code to a shader program.
/// </summary>
/// <param name="target">Shader program to attach</param>
/// <param name="index">Index of shader code in current shader code set.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AttachTo(int index, ShaderProgram target)
/// <param name="target"> Shader program to attach </param>
/// <param name="index"> Index of shader code in current shader code set. </param>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void AttachTo( int index, ShaderProgram target )
{
GL.AttachShader(target.handle, handle[index]);
GL.AttachShader( target.handle, handle[ index ] );
}
public void CheckStatus(int index, ShaderStatus status)
public void CheckStatus( int index, ShaderStatus status )
{
string log = GL.GetShaderStatus(this, index, (int)status);
if (!string.IsNullOrEmpty(log))
{
throw new Exception($"{$"Shader Error \t{status}\n"}{log}");
string log = GL.GetShaderStatus( this, index, ( int )status );
if( !string.IsNullOrEmpty( log ) ) {
throw new Exception( $"{$"Shader Error \t{status}\n"}{log}" );
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Compile(int index, byte[] codeStream)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void Compile( int index, byte[] codeStream )
{
if (codeStream == null)
{
throw new ArgumentNullException(nameof(codeStream));
if( codeStream == null ) {
throw new ArgumentNullException( nameof( codeStream ) );
}
GL.LoadShaderSource(handle[index], codeStream);
GL.CompileShader(handle[index]);
CheckStatus(index, ShaderStatus.CompileStatus);
GL.LoadShaderSource( handle[ index ], codeStream );
GL.CompileShader( handle[ index ] );
CheckStatus( index, ShaderStatus.CompileStatus );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Compile(int index, string codeStream)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void Compile( int index, string codeStream )
{
if (codeStream == null)
{
throw new ArgumentNullException(nameof(codeStream));
if( codeStream == null ) {
throw new ArgumentNullException( nameof( codeStream ) );
}
GL.LoadShaderSource(handle[index], Encoding.ASCII.GetBytes(codeStream));
GL.CompileShader(handle[index]);
CheckStatus(index, ShaderStatus.CompileStatus);
GL.LoadShaderSource(
handle[ index ], Encoding.ASCII.GetBytes( codeStream ) );
GL.CompileShader( handle[ index ] );
CheckStatus( index, ShaderStatus.CompileStatus );
}
public void FromBytes(byte[] stream)
public void FromBytes( byte[] stream )
{
throw new NotImplementedException();
}
public static byte[] FromCodeFile(string fileRoute)
public static byte[] FromCodeFile( string fileRoute )
{
string str = File.ReadAllText(fileRoute);
if (string.IsNullOrEmpty(str))
{
throw new InvalidOperationException($"Cannot load and GLSL code from {fileRoute}");
string str = File.ReadAllText( fileRoute );
if( string.IsNullOrEmpty( str ) ) {
throw new InvalidOperationException(
$"Cannot load and GLSL code from {fileRoute}" );
}
return Encoding.UTF8.GetBytes(str);
return Encoding.UTF8.GetBytes( str );
}
public byte[] GetBytes()
@@ -142,7 +145,7 @@ namespace StgSharp.Graphics.OpenGL
return Array.Empty<byte>();
}
public byte[] GetBytes(out int length)
public byte[] GetBytes( out int length )
{
throw new NotImplementedException();
}
@@ -156,7 +159,9 @@ namespace StgSharp.Graphics.OpenGL
public enum ShaderStatus : int
{
CompileStatus = GLconst.COMPILE_STATUS,
}
public class ShaderProgram
@@ -168,64 +173,63 @@ namespace StgSharp.Graphics.OpenGL
/// <summary>
/// CustomizeInit a program with no shader attached.
/// </summary>
internal unsafe ShaderProgram(glRender binding)
internal unsafe ShaderProgram( glRender binding )
{
GL = binding.GL;
handle = GL.CreateProgram();
}
/// <summary>
/// Get a uniform form current shader,
/// the value type of the uniform should be provided.
/// Get a uniform form current shader, the value type of the uniform should be provided.
/// </summary>
/// <param name="name">ContextName of the Uniform in shader code</param>
/// <param name="name"> ContextName of the Uniform in shader code </param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe Uniform<T> GetUniform<T>(string name) where T : struct
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe Uniform<T> GetUniform<T>( string name ) where T: struct
{
return new Uniform<T>(GL.GetUniformLocation(this.handle, name));
return new Uniform<T>( GL.GetUniformLocation( this.handle, name ) );
}
/// <summary>
/// Get a uniform form current shader,
/// the value type of the uniform should be provided.
/// Get a uniform form current shader, the value type of the uniform should be provided.
/// </summary>
/// <param name="name">ContextName of the Uniform in shader code</param>
/// <param name="name"> ContextName of the Uniform in shader code </param>
/// <returns></returns>
public unsafe Uniform<T, U> GetUniform<T, U>(string name)
where T : struct
where U : struct
public unsafe Uniform<T, U> GetUniform<T, U>( string name )
where T: struct
where U: struct
{
return new Uniform<T, U>(GL.GetUniformLocation(this.handle, name));
return new Uniform<T, U>(
GL.GetUniformLocation( this.handle, name ) );
}
/// <summary>
/// Get a uniform form current shader,
/// the value type of the uniform should be provided.
/// Get a uniform form current shader, the value type of the uniform should be provided.
/// </summary>
/// <param name="name">ContextName of the Uniform in shader code</param>
/// <param name="name"> ContextName of the Uniform in shader code </param>
/// <returns></returns>
public unsafe Uniform<T, U, V> GetUniform<T, U, V>(string name)
where T : struct
where U : struct
where V : struct
public unsafe Uniform<T, U, V> GetUniform<T, U, V>( string name )
where T: struct
where U: struct
where V: struct
{
return new Uniform<T, U, V>(GL.GetUniformLocation(this.handle, name));
return new Uniform<T, U, V>(
GL.GetUniformLocation( this.handle, name ) );
}
/// <summary>
/// Get a uniform form current shader,
/// the value type of the uniform should be provided.
/// Get a uniform form current shader, the value type of the uniform should be provided.
/// </summary>
/// <param name="name">ContextName of the Uniform in shader code</param>
/// <param name="name"> ContextName of the Uniform in shader code </param>
/// <returns></returns>
public unsafe Uniform<T, U, V, W> GetUniform<T, U, V, W>(string name)
where T : struct
where U : struct
where V : struct
where W : struct
public unsafe Uniform<T, U, V, W> GetUniform<T, U, V, W>( string name )
where T: struct
where U: struct
where V: struct
where W: struct
{
return new Uniform<T, U, V, W>(GL.GetUniformLocation(this.handle, name));
return new Uniform<T, U, V, W>(
GL.GetUniformLocation( this.handle, name ) );
}
/// <summary>
@@ -233,20 +237,18 @@ namespace StgSharp.Graphics.OpenGL
/// </summary>
public unsafe void Link()
{
if (InternalIO.InternalLinkShaderProgram((OpenglContext*)this.GL.ContextHandle, handle.Value) == 0)
{
if( InternalIO.InternalLinkShaderProgram(
( OpenglContext* )this.GL.ContextHandle, handle.Value ) == 0 ) {
IntPtr logPtr = InternalIO.InternalReadSSCLog();
try
{
try {
byte[] logByte = new byte[512];
Marshal.Copy(logPtr, logByte, 0, 512);
string log = Encoding.UTF8.GetString(logByte);
log = log.Replace("\0", string.Empty);
InternalIO.InternalWriteLog(log, LogType.Error);
Marshal.Copy( logPtr, logByte, 0, 512 );
string log = Encoding.UTF8.GetString( logByte );
log = log.Replace( "\0", string.Empty );
InternalIO.InternalWriteLog( log, LogType.Error );
}
catch (Exception ex)
{
InternalIO.InternalWriteLog(ex.Message, LogType.Error);
catch( Exception ex ) {
InternalIO.InternalWriteLog( ex.Message, LogType.Error );
}
}
}
@@ -254,10 +256,10 @@ namespace StgSharp.Graphics.OpenGL
/// <summary>
/// Let the current viewPortDisplay use this shader.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void Use()
{
GL.UseProgram(handle);
GL.UseProgram( handle );
}
~ShaderProgram()
@@ -52,93 +52,73 @@ namespace StgSharp.Graphics.OpenGL
}
public sealed class Uniform<T> : Uniform
where T : struct
public sealed class Uniform<T> : Uniform where T: struct
{
internal Uniform()
{
internal Uniform() { }
}
internal unsafe Uniform(GlHandle id)
internal unsafe Uniform( GlHandle id )
{
this.id = id;
}
internal static Uniform<T> FromHandle(GlHandle handle)
internal static Uniform<T> FromHandle( GlHandle handle )
{
return new Uniform<T> { id = handle };
}
}
public sealed class Uniform<T, U> : Uniform
where T : struct
where U : struct
public sealed class Uniform<T, U> : Uniform where T: struct where U: struct
{
internal Uniform() { }
internal Uniform()
{
}
internal unsafe Uniform(GlHandle id)
internal unsafe Uniform( GlHandle id )
{
this.id = id;
}
internal static Uniform<T, U> FromHandle(GlHandle handle)
internal static Uniform<T, U> FromHandle( GlHandle handle )
{
return new Uniform<T, U> { id = handle };
}
}
public sealed class Uniform<T, U, V> : Uniform
where T : struct
where U : struct
where V : struct
public sealed class Uniform<T, U, V> : Uniform where T: struct
where U: struct
where V: struct
{
internal Uniform()
{
internal Uniform() { }
}
internal unsafe Uniform(GlHandle id)
internal unsafe Uniform( GlHandle id )
{
this.id = id;
}
internal static Uniform<T, U, V> FromHandle(GlHandle handle)
internal static Uniform<T, U, V> FromHandle( GlHandle handle )
{
return new Uniform<T, U, V> { id = handle };
}
}
public sealed class Uniform<T, U, V, W> : Uniform
where T : struct
where U : struct
where V : struct
where W : struct
public sealed class Uniform<T, U, V, W> : Uniform where T: struct
where U: struct
where V: struct
where W: struct
{
internal Uniform()
{
internal Uniform() { }
}
internal unsafe Uniform(GlHandle id)
internal unsafe Uniform( GlHandle id )
{
this.id = id;
}
internal static Uniform<T, U, V, W> FromHandle(GlHandle handle)
internal static Uniform<T, U, V, W> FromHandle( GlHandle handle )
{
return new Uniform<T, U, V, W> { id = handle };
}
@@ -148,59 +128,71 @@ namespace StgSharp.Graphics.OpenGL
public unsafe partial class OpenGLFunction
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue
(Uniform<Matrix44> uniform, Matrix44 mat)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetUniformValue( Uniform<Matrix44> uniform, Matrix44 mat )
{
Matrix44 temp = mat;
Context.glUniformMatrix4fv(uniform.id.SignedValue, 1, false, (float*)&temp);
Context.glUniformMatrix4fv(
uniform.id.SignedValue, 1, false, ( float* )&temp );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue(Uniform<float, float, float, float> uniform, vec4d vec)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetUniformValue(
Uniform<float, float, float, float> uniform,
Vec4 vec )
{
vec4d temp = vec;
Context.glUniform1fv(uniform.id.SignedValue, 4, &temp);
Vec4 temp = vec;
Context.glUniform1fv( uniform.id.SignedValue, 4, &temp );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue(Uniform<vec4d> uniform, vec4d vec)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetUniformValue( Uniform<Vec4> uniform, Vec4 vec )
{
vec4d temp = vec;
Context.glUniform1fv(uniform.id.SignedValue, 4, &temp);
Vec4 temp = vec;
Context.glUniform1fv( uniform.id.SignedValue, 4, &temp );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue(Uniform<float> uniform, float v0)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetUniformValue( Uniform<float> uniform, float v0 )
{
Context.glUniform1f(uniform.id.SignedValue, v0);
Context.glUniform1f( uniform.id.SignedValue, v0 );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue(Uniform<int> uniform, int i0)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetUniformValue( Uniform<int> uniform, int i0 )
{
Context.glUniform1i(uniform.id.SignedValue, i0);
Context.glUniform1i( uniform.id.SignedValue, i0 );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue(Uniform<float, float> uniform, float v0, float v1)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetUniformValue(
Uniform<float, float> uniform,
float v0,
float v1 )
{
Context.glUniform2f(uniform.id.SignedValue, v0, v1);
Context.glUniform2f( uniform.id.SignedValue, v0, v1 );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetUniformValue(
Uniform<float, float, float> uniform,
float v0,
float v1,
float v2 )
{
Context.glUniform3f(uniform.id.SignedValue, v0, v1, v2);
Context.glUniform3f( uniform.id.SignedValue, v0, v1, v2 );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetUniformValue(
Uniform<float, float, float, float> uniform,
float v0,
float v1,
float v2,
float v3 )
{
Context.glUniform4f(uniform.id.SignedValue, v0, v1, v2, v3);
Context.glUniform4f( uniform.id.SignedValue, v0, v1, v2, v3 );
}
}
}
@@ -34,14 +34,11 @@ using System.Text;
namespace StgSharp.Graphics.OpenGL
{
[AttributeUsage(AttributeTargets.Method)]
[AttributeUsage( AttributeTargets.Method )]
public sealed class OpenGLAPICallingAttribute : Attribute
{
public OpenGLAPICallingAttribute()
{
}
public OpenGLAPICallingAttribute() { }
}
}
File diff suppressed because it is too large Load Diff
@@ -36,6 +36,7 @@ namespace StgSharp.Graphics.OpenGL
{
public static partial class glManager
{
#region coreVersion
private static bool core10 = false;
@@ -682,8 +683,6 @@ namespace StgSharp.Graphics.OpenGL
private static bool WIN_phong_shading;
private static bool WIN_specular_fog;
#endregion
}
}
@@ -0,0 +1,92 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glFucntionSourceManager.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;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
namespace StgSharp.Graphics.OpenGL
{
public partial class OpenGLFunction
{
private Lazy<int> textureUnitCountGetter;
private Lazy<ConcurrentQueue<TextureUnit>> unusedTextureImageUintInitilizing;
public int TextureUnitCount
{
get => textureUnitCountGetter.Value;
}
private ConcurrentQueue<TextureUnit> UnusedTextureImageUint
{
get => unusedTextureImageUintInitilizing.Value;
}
internal void ReturnAvailableUnit( IEnumerable<TextureUnit> source )
{
int v = GLconst.TEXTURE0 + TextureUnitCount;
foreach( TextureUnit unit in source ) {
if( ( int )unit > v ) {
throw new InvalidOperationException(
"Source contains texture unit beyond context support." );
}
}
}
internal int TryGetAvailableTextureUnit(
int count,
out IEnumerable<TextureUnit> result )
{
result = new Queue<TextureUnit>();
for( int i = 0; i < count; i++ ) {
if( UnusedTextureImageUint.TryDequeue( out TextureUnit unit ) ) {
( result as Queue<TextureUnit> )!.Enqueue( unit );
} else {
return i;
}
}
return count;
}
private ConcurrentQueue<TextureUnit> InitializeUnusedTextureImageUint()
{
ConcurrentQueue<TextureUnit> result = new ConcurrentQueue<TextureUnit>(
);
for( int index = 0; index < TextureUnitCount; index++ ) {
result.Enqueue( ( TextureUnit )( GLconst.TEXTURE0 + index ) );
}
return result;
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,107 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glRenderSourceGenrator.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.OpenGL
{
public partial class glRender
{
[MethodImpl( MethodImplOptions.AggressiveInlining )]
protected AutoTextureGL CreateAutoTexture( int count )
{
return new AutoTextureGL( count, this );
}
/// <summary>
/// Create a set of <see cref="ElementBuffer" />.
/// </summary>
/// <param name="count"> Amount of EBO to be created. </param>
/// <returns></returns>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
protected ElementBuffer CreateElementBuffer( int count )
{
return new ElementBuffer( count, this );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
protected FrameBuffer CreateFrameBuffer( int count )
{
return new FrameBuffer( count, this );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
protected RenderBuffer CreateRenderBuffer( int count )
{
return new RenderBuffer( count, this );
}
/// <summary>
/// Create a sets of <see cref="TextureGL" />
/// </summary>
/// <param name="count"> Amount of textures to be created. </param>
/// <returns></returns>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
protected TextureGL CreateTexture( int count )
{
return new TextureGL( count, this );
}
/// <summary>
/// Create a set of <see cref="VertexArray" />.
/// </summary>
/// <param name="count"> Amount of VAO to be created. </param>
/// <returns></returns>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
protected VertexArray CreateVertexArray( int count )
{
return new VertexArray( count, this );
}
/// <summary>
/// Create a set of <see cref="VertexBuffer" />.
/// </summary>
/// <param name="count"> Amount of Object to be created. </param>
/// <returns></returns>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
protected VertexBuffer CreateVertexBuffer( int count )
{
return new VertexBuffer( count, this );
}
}
}
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glRender.cs"
// file="glRenderStream.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
@@ -28,24 +28,28 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Math;
using StgSharp.Threading;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Graphics.OpenGL
{
public abstract partial class glRender : RenderStream
{
private protected static readonly ConcurrentDictionary<glRender, Thread> renderToThread
= new ConcurrentDictionary<glRender, Thread>();
private OpenGLFunction _context;
protected internal OpenGLFunction GL
@@ -54,93 +58,134 @@ namespace StgSharp.Graphics.OpenGL
}
/// <summary>
/// Initialize an OpenGl viewPortDisplay if current form has not been binded to any viewPortDisplay.
/// and set the viewPortDisplay binded to current form as current OpenGL viewPortDisplay.
/// Initialize an opengl context and load all opengl functions.
/// </summary>
public unsafe void InitializeContext()
{
if( ContextHandle == default ) {
ContextHandle = Marshal.AllocHGlobal(
Marshal.SizeOf( typeof( OpenglContext ) ) );
OpenglContext* contextID = ( OpenglContext* )ContextHandle;
contextID->glGetString = ( delegate*<uint, IntPtr> )IntPtr.Zero;
}
if( GL == null ) {
_context = OpenGLFunction.BuildGlFunctionPackage(
ContextHandle );
}
}
/// <summary>
/// Initialize an OpenGl viewPortDisplay if current form has not been binded to any
/// viewPortDisplay. and set the viewPortDisplay binded to current form as current OpenGL
/// viewPortDisplay.
/// </summary>
/// <exception cref="Exception">
/// Something goes wrong and StgSharp fails in creating a new OpenGL viewPortDisplay.
/// </exception>
public unsafe void MakeAsCurrentContext()
{
if (ContextHandle == default)
{
ContextHandle = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(OpenglContext)));
OpenglContext* contextID = (OpenglContext*)ContextHandle;
contextID->glGetString = (delegate*<uint, IntPtr>)IntPtr.Zero;
}
if (GL == null)
{
_context = OpenGLFunction.BuildGlFunctionPackage(ContextHandle);
}
if (OpenGLFunction.CurrentGL != GL)
{
OpenGLFunction.CurrentGL = GL;
InternalIO.glfwMakeContextCurrent(CanvasHandle);
}
InternalIO.glfwMakeContextCurrent( CanvasHandle );
OpenGLFunction.CurrentGL = this.GL;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
/// <inheritdoc />
public override void RenderEnd()
{
InternalIO.glfwSetWindowSizeLimits(this.CanvasHandle, minWidth, minHeight, maxWidth, maxHeight);
if( !renderToThread.TryGetValue( this,
out Thread t ) || t != Thread.CurrentThread ) {
throw new InvalidOperationException(
$"Current render has had been binded to thread {t!.ManagedThreadId}" );
}
SwapBuffers();
renderToThread[ this ] = ThreadHelper.EmptyThread;
InternalIO.glfwMakeContextCurrent( IntPtr.Zero );
OpenGLFunction.CurrentGL = null;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal override sealed void Draw()
/// <inheritdoc />
public override void RenderStart()
{
MakeAsCurrentContext();
Main();
Thread current = Thread.CurrentThread;
if( !renderToThread.TryGetValue( this,
out Thread t ) || t == ThreadHelper.EmptyThread ) {
renderToThread[ this ] = current;
MakeAsCurrentContext();
return;
}
if( t != current ) {
throw new InvalidOperationException(
$"Current render has had been binded to thread {t!.ManagedThreadId}" );
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public override void SetSizeLimit(
int minWidth,
int minHeight,
int maxWidth,
int maxHeight )
{
InternalIO.glfwSetWindowSizeLimits(
this.CanvasHandle, minWidth, minHeight, maxWidth, maxHeight );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
internal override sealed void PlatformSpecifiedInitialize()
{
InitializeContext();
MakeAsCurrentContext();
glManager.LoadOpenGLApiTo(Port.GraphicHandle);
glManager.LoadOpenGLApiTo( BindedViewPortContext.GraphicHandle );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[MethodImpl( MethodImplOptions.AggressiveInlining )]
internal override sealed void Terminate()
{
CustomizeDeinit();
}
protected override sealed Uniform<Matrix44> NativeCameraUniform(ShaderProgram source, string name)
protected override sealed Uniform<Matrix44> NativeCameraUniform(
ShaderProgram source,
string name )
{
NativeCamera.GainAllUniforms(source, 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)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
protected override sealed void NativeCameraViewRange(
Radius fieldOfRange,
Vec2 offset,
(float frontDepth, float backDepth) viewDepth )
{
NativeCamera.SetViewRange(fieldOfRange, this.Size, offset, viewDepth);
NativeCamera.SetViewRange(
fieldOfRange, this.Size, offset, viewDepth );
}
protected override sealed void NativeCameraViewTarget(vec3d position, vec3d direction, vec3d up)
protected override sealed void NativeCameraViewTarget(
Vec3 position,
Vec3 direction,
Vec3 up )
{
NativeCamera.SetViewDirection(position, direction, up);
NativeCamera.SetViewDirection( position, direction, up );
}
#region Key Control
protected KeyStatus CheckKey(KeyboardKey key)
protected KeyStatus CheckKey( KeyboardKey key )
{
return InternalIO.glfwGetKey(this.CanvasHandle, (int)key);
return InternalIO.glfwGetKey( this.CanvasHandle, ( int )key );
}
protected KeyStatus CheckKey(Mouse key)
protected KeyStatus CheckKey( Mouse key )
{
return InternalIO.glfwGetKey(this.CanvasHandle, (int)key);
return InternalIO.glfwGetKey( this.CanvasHandle, ( int )key );
}
protected KeyStatus CheckKey(Joystick key)
protected KeyStatus CheckKey( Joystick key )
{
return InternalIO.glfwGetKey(this.CanvasHandle, (int)key);
return InternalIO.glfwGetKey( this.CanvasHandle, ( int )key );
}
#endregion
}
}
@@ -0,0 +1,49 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glRenderThreadSecurity.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Graphics.OpenGL
{
public partial class glRender
{
private static ConcurrentDictionary<Thread, glRender> threadLocalIndex
= new ConcurrentDictionary<Thread, glRender>();
private readonly SynchronizationContext mainThreadContext = SynchronizationContext.Current;
}
}
+28 -10
View File
@@ -38,26 +38,44 @@ 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; }
public float Red
{
get;
set;
}
internal int Size { get; }
public float Green
{
get;
set;
}
public float Blue
{
get;
set;
}
public float Alpha
{
get;
set;
}
internal int Size
{
get;
}
}
[StructLayout(LayoutKind.Explicit, Size = 32)]
[StructLayout( LayoutKind.Explicit, Size = 32 )]
public unsafe struct Pixel32
{
[FieldOffset(0)] private unsafe fixed byte data[4];
[FieldOffset( 0 )] private unsafe fixed byte data[ 4 ];
internal int Size => 4;
}
}
@@ -46,52 +46,57 @@ namespace StgSharp.Graphics
private PlainGeometry _shape;
private TextureProvider _texture;
public PlainGeometryMesh([NotNull] PlainGeometry shape, [NotNull] TextureProvider texture)
public PlainGeometryMesh(
[NotNull] PlainGeometry shape,
[NotNull] TextureProvider texture )
{
if (shape.VertexCount > texture.TextureCoordinate.Length)
{
throw new ArgumentException(paramName: nameof(texture), message: "Amount of texture coordination is too less");
if( shape.VertexCount > texture.TextureCoordinate.Length ) {
throw new ArgumentException(
paramName: nameof( texture ),
message: "Amount of texture coordination is too less" );
}
_texture = texture;
_shape = shape;
}
//private Image _texture;
public PlainGeometryMesh(
PlainGeometry shape, Image texture, vec2d[] texCoord
)
PlainGeometry shape,
Image texture,
Vec2[] texCoord )
{
if (shape == null)
{
throw new ArgumentNullException(nameof(shape));
if( shape == null ) {
throw new ArgumentNullException( nameof( shape ) );
}
if (texCoord == null)
{
throw new ArgumentNullException(nameof(texCoord));
if( texCoord == null ) {
throw new ArgumentNullException( nameof( texCoord ) );
}
if (shape.VertexCount > texCoord.Length)
{
throw new ArgumentException(paramName: nameof(texCoord), message: "Amount of texture coordination is too less");
if( shape.VertexCount > texCoord.Length ) {
throw new ArgumentException(
paramName: nameof( texCoord ),
message: "Amount of texture coordination is too less" );
}
_texture = new TextureProvider(texture, texCoord);
_texture = new TextureProvider( texture, texCoord );
}
public vec4d[] VertexArray => _shape.VertexStream;
public Vec4[] VertexArray => _shape.VertexStream;
public Image TextureImage
{
get => _texture.ProvideImage();
internal set => _texture.ReadImage(value);
internal set => _texture.ReadImage( value );
}
public ReadOnlySpan<int> MeshIndices => _shape.VertexIndices;
public ReadOnlySpan<vec4d> TextureCoord => MemoryMarshal.Cast<vec2d, vec4d>(_texture.TextureCoordinate);
public ReadOnlySpan<Vec4> TextureCoord => MemoryMarshal.Cast<Vec2, Vec4>(
_texture.TextureCoordinate );
public PlainGeometryMesh Resize(PlainGeometry newShape)
public PlainGeometryMesh Resize( PlainGeometry newShape )
{
return new PlainGeometryMesh(newShape, _texture);
return new PlainGeometryMesh( newShape, _texture );
}
}
+76 -53
View File
@@ -29,15 +29,16 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics.OpenGL;
using StgSharp.Timing;
using StgSharp.Math;
using StgSharp.MVVM;
using StgSharp.MVVM.View;
using StgSharp.Timing;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -57,12 +58,6 @@ namespace StgSharp.Graphics
public (int width, int height) Size
{
get => (Width, Height);
internal set
{
primeArgs.Height = value.width;
primeArgs.Width = value.height;
InternalIO.glfwSetWindowSize(this.CanvasHandle, Width, Height);
}
}
public abstract bool IsContextSharable
@@ -73,13 +68,11 @@ namespace StgSharp.Graphics
public int Height
{
get => primeArgs.Height;
internal set { primeArgs.Height = value; }
}
public int Width
{
get => primeArgs.Width;
internal set { primeArgs.Width = value; }
}
public IntPtr Monitor
@@ -93,21 +86,18 @@ namespace StgSharp.Graphics
get => primeArgs.Name;
}
protected bool IsWaitingUserEvent
{
get => primeArgs.IsWaitingEvent;
}
public Vec2 GlobalCoordSize => (( Width * 1.0f ) / _coordStretch.x, ( Height * 1.0f ) / _coordStretch.y);
public vec2d GlobalCoordSize => ((Width * 1.0f) / _coordStretch.x, (Height * 1.0f) / _coordStretch.y);
public ViewPort Port
public ViewPort BindedViewPortContext
{
get => primeArgs;
internal set => primeArgs = value;
}
internal IntPtr CanvasHandle { get => primeArgs.ViewPortID; }
internal IntPtr CanvasHandle
{
get => primeArgs.ViewPortID;
}
internal IntPtr ContextHandle
{
@@ -144,19 +134,26 @@ namespace StgSharp.Graphics
/// <summary>
/// Set the size limit of current form
/// </summary>
/// <param name="minWidth">Minimum width of current form</param>
/// <param name="minHeight">Minimum height of current form</param>
/// <param name="maxWidth">Maximum width of current form</param>
/// <param name="maxHeight">Maximum height of current form</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public abstract void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight);
/// <param name="minWidth"> Minimum width of current form </param>
/// <param name="minHeight"> Minimum height of current form </param>
/// <param name="maxWidth"> Maximum width of current form </param>
/// <param name="maxHeight"> Maximum height of current form </param>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public abstract void SetSizeLimit(
int minWidth,
int minHeight,
int maxWidth,
int maxHeight );
public static TTarget ShareContextFrom<TSource, TTarget>(TSource source)
where TSource : RenderStream
where TTarget : RenderStream, new()
public static TTarget ShareContextFrom<TSource, TTarget>(
[NotNull]TSource source )
where TSource: RenderStream
where TTarget: RenderStream, new()
{
TTarget target = new TTarget();
target.Initialize(source.Port, source._coordStretch, source._timeProvider);
target.Initialize(
source.BindedViewPortContext, source._coordStretch,
source._timeProvider );
return target;
}
@@ -166,38 +163,52 @@ namespace StgSharp.Graphics
InternalIO.glfwPollEvents();
}
protected internal void SwapBuffers()
private protected void SwapBuffers()
{
InternalIO.glfwSwapBuffers(CanvasHandle);
InternalIO.glfwSwapBuffers( CanvasHandle );
}
/**/
#region native camera operation
protected abstract void NativeCameraViewRange(Radius fieldOfRange, vec2d offset, (float frontDepth, float backDepth) viewDepth);
protected abstract void NativeCameraViewTarget(vec3d position, vec3d direction, vec3d up);
protected abstract void NativeCameraViewRange(
Radius fieldOfRange,
Vec2 offset,
(float frontDepth, float backDepth) viewDepth );
protected abstract void NativeCameraViewTarget(
Vec3 position,
Vec3 direction,
Vec3 up );
/// <summary>
/// Get <see cref="Uniform{T}"/>(TView is <see cref="Matrix44"/>) uniform from a shader.
/// This uniform will be used as projection matrix of this camera.
/// Additionally, for multi-shader rendering, each shader requires a uniform,
/// so do not ignore return value of this method.
/// Get <see cref="Uniform{T}" />(TView is <see cref="Matrix44" />) uniform from a shader.
/// This uniform will be used as projection matrix of this camera. Additionally, for multi-
/// shader rendering, each shader requires a uniform, so do not ignore return value of this
/// method.
/// </summary>
/// <param name="source">Shader using this camera</param>
/// <param name="name">ContextName of projection camera named in shader</param>
/// <param name="source"> Shader using this camera </param>
/// <param name="name"> ContextName of projection camera named in shader </param>
/// <returns>
/// <see cref="Uniform{T}"/>(TView is <see cref="Matrix44"/>) representing
/// projection matrix in shader program.
/// <see cref="Uniform{T}" />(TView is <see cref="Matrix44" />) representing projection
/// matrix in shader program.
/// </returns>
protected abstract Uniform<Matrix44> NativeCameraUniform(ShaderProgram source, string name);
protected abstract Uniform<Matrix44> NativeCameraUniform(
ShaderProgram source,
string name );
#endregion
#region internal operation
internal abstract void Draw();
public void Initialize(ViewPort v, (int, int, int) unitCubeSize, TimeSpanProvider timeProvider)
public void Initialize(
ViewPort v,
(int, int, int) unitCubeSize,
TimeSpanProvider timeProvider )
{
if (v == null)
{
throw new ArgumentNullException(nameof(v));
if( v == null ) {
throw new ArgumentNullException( nameof( v ) );
}
primeArgs = v;
this._timeProvider = timeProvider;
@@ -205,30 +216,42 @@ namespace StgSharp.Graphics
nativeCamera = new Camera();
PlatformSpecifiedInitialize();
CustomizeInit();
InternalIO.glfwMakeContextCurrent( IntPtr.Zero );
}
internal abstract void PlatformSpecifiedInitialize();
internal abstract void Terminate();
#endregion
#region public operation
protected abstract void CustomizeDeinit();
protected abstract void CustomizeInit();
protected abstract void Main();
/// <summary>
/// Marking the start of current render operations, and set this renser context as current.
/// </summary>
public abstract void RenderStart();
/// <summary>
/// Marking the end of current render operations, and release the binding of this renser
/// context to current, making it available for another thread as current.
/// </summary>
public abstract void RenderEnd();
#endregion
#region public resource generator
protected abstract Shader CreateShaderSegment(ShaderType type, int count);
protected abstract Shader CreateShaderSegment(
ShaderType type,
int count );
protected abstract ShaderProgram CreateShaderProgram();
#endregion
#endregion
}
}
@@ -48,10 +48,13 @@ namespace StgSharp.Graphics.ShaderEdit
private List<string> codeList;
private List<ShaderFunction> usedShaderFunctions;
public Uniform<T> DefineUniform<T>(string name, int index) where T : struct
public Uniform<T> DefineUniform<T>( string name, int index )
where T: struct
{
ShaderParameter p = new ShaderParameter(name, ShaderParameter.TypeMarshal<T>());
uniformDefine.Add(index, p);
ShaderParameter p = new ShaderParameter(
name, ShaderParameter.TypeMarshal<T>() );
uniformDefine.Add( index, p );
//return new Uniform<TView>();
throw new NotImplementedException();
}
@@ -68,38 +71,39 @@ namespace StgSharp.Graphics.ShaderEdit
public int ParameterCount => inputList.Count;
public void EmitCall(ShaderFunction function, ShaderParameter outPut, params ShaderParameter[] inputParams)
public void EmitCall(
ShaderFunction function,
ShaderParameter outPut,
params ShaderParameter[] inputParams )
{
if (inputParams.Length != function.ParameterCount)
{
if( inputParams.Length != function.ParameterCount ) {
// Param list length not equal
throw new ArgumentException("Provided parameters does not match function's parameter list.");
throw new ArgumentException(
"Provided parameters does not match function's parameter list." );
}
if (!ShaderParameter.IsSameType(outPut, function.outPut))
{
if( !ShaderParameter.IsSameType( outPut, function.outPut ) ) {
// Type of returning value not qual
throw new Exception("Provided parameters does not match function's parameter list.");
throw new Exception(
"Provided parameters does not match function's parameter list." );
}
for (int i = 0; i < inputParams.Length; i++)
{
if (!ShaderParameter.IsSameType(function.inputList[i], inputParams[i]))
{
for( int i = 0; i < inputParams.Length; i++ ) {
if( !ShaderParameter.IsSameType(
function.inputList[ i ], inputParams[ i ] ) ) {
// Input type not match
throw new Exception("Provided parameters does not match function's parameter list.");
throw new Exception(
"Provided parameters does not match function's parameter list." );
}
}
string codeLine = string.Empty; // adding a line like " outvalue = Func(input1, input2,...); "
if (outPut != ShaderParameter.Void)
{
if( outPut != ShaderParameter.Void ) {
codeLine += $"{outPut.name} = ";
}
codeLine += $"{function.name}(";
foreach (ShaderParameter inputParam in inputParams)
{
foreach( ShaderParameter inputParam in inputParams ) {
codeLine += inputParam.name;
}
codeLine += ");\n";
codeList.Add(codeLine);
codeList.Add( codeLine );
}
}
@@ -107,34 +111,33 @@ namespace StgSharp.Graphics.ShaderEdit
public class ShaderParameter
{
public static readonly ShaderParameter Void = new ShaderParameter(string.Empty, InternalShaderType.Void);
public static readonly ShaderParameter Void = new ShaderParameter(
string.Empty, InternalShaderType.Void );
internal readonly bool isReadOnly;
internal readonly InternalShaderType type;
internal readonly string name;
public ShaderParameter(string name, InternalShaderType type)
public ShaderParameter( string name, InternalShaderType type )
{
this.name = name;
this.type = type;
isReadOnly = false;
}
public static bool IsSameType(ShaderParameter param1, ShaderParameter param2)
public static bool IsSameType(
ShaderParameter param1,
ShaderParameter param2 )
{
if (param1.type != InternalShaderType.Struct)
{
if( param1.type != InternalShaderType.Struct ) {
return param1.type == param2.type;
}
else
{
throw new Exception("Struct is currently not supported.");
} else {
throw new Exception( "Struct is currently not supported." );
}
}
public static InternalShaderType TypeMarshal<T>() where T : struct
public static InternalShaderType TypeMarshal<T>() where T: struct
{
switch (Type.GetTypeCode(typeof(T)))
{
switch( Type.GetTypeCode( typeof( T ) ) ) {
case TypeCode.Single:
return InternalShaderType.Float;
case TypeCode.Double:
@@ -146,8 +149,7 @@ namespace StgSharp.Graphics.ShaderEdit
default:
break;
}
switch (typeof(T).Name)
{
switch( typeof( T ).Name ) {
case "vec4d":
return InternalShaderType.Vector4;
case "Matrix2x2":
@@ -169,7 +171,8 @@ namespace StgSharp.Graphics.ShaderEdit
case "Matrix4x4":
return InternalShaderType.Matrix4x4;
default:
throw new ArgumentException("Not supported shader data type.");
throw new ArgumentException(
"Not supported shader data type." );
}
}
@@ -178,14 +181,27 @@ namespace StgSharp.Graphics.ShaderEdit
public enum InternalShaderType
{
#pragma warning disable CS1591
Struct, Void,
Int, UInt,
Float, Double,
Vector2, Vector3, Vector4,
VectorD2, VectorD3, VectorD4,
Matrix2x2, Matrix2x3, Matrix2x4,
Matrix3x2, Matrix3x3, Matrix3x4,
Matrix4x2, Matrix4x3, Matrix4x4,
Struct,
Void,
Int,
UInt,
Float,
Double,
Vector2,
Vector3,
Vector4,
VectorD2,
VectorD3,
VectorD4,
Matrix2x2,
Matrix2x3,
Matrix2x4,
Matrix3x2,
Matrix3x3,
Matrix3x4,
Matrix4x2,
Matrix4x3,
Matrix4x4,
#pragma warning restore CS1591
}
}
@@ -53,47 +53,42 @@ namespace StgSharp.Graphics.ShaderEdit
internal ShaderStruct() { }
public ShaderStruct(params (GlHandle, ShaderStructMember)[] uniformPairs)
public ShaderStruct(
params (GlHandle, ShaderStructMember)[] uniformPairs )
{
uniformPair = new Dictionary<GlHandle, ShaderStructMember>();
if (uniformPairs.Length == 0)
{
if( uniformPairs.Length == 0 ) {
return;
}
foreach ((GlHandle, ShaderStructMember) item in uniformPairs)
{
uniformPair.Add(item.Item1, item.Item2);
foreach( (GlHandle, ShaderStructMember) item in uniformPairs ) {
uniformPair.Add( item.Item1, item.Item2 );
}
}
public unsafe void SetAllUniforms()
{
OpenglContext* gl = (OpenglContext*)OpenGL.OpenGLFunction.CurrentGL.ContextHandle;
foreach (KeyValuePair<GlHandle, ShaderStructMember> uniform in uniformPair)
{
OpenglContext* gl = ( OpenglContext* )OpenGL.OpenGLFunction.CurrentGL.ContextHandle;
foreach( KeyValuePair<GlHandle, ShaderStructMember> uniform in uniformPair ) {
int id = uniform.Key.SignedValue;
ShaderStructMember s = uniform.Value;
switch (s.type)
{
switch( s.type ) {
case InternalShaderType.Struct:
throw new ArgumentException(
"Incorrect type \"Struct\" defined in this self define type");
"Incorrect type \"Struct\" defined in this self define type" );
case InternalShaderType.Void:
throw new ArgumentException(
"Incorrect type \"Void\" defined in this self define type");
"Incorrect type \"Void\" defined in this self define type" );
case InternalShaderType.Float:
gl->glUniform1f(id, (float)s.value);
gl->glUniform1f( id, ( float )s.value );
break;
case InternalShaderType.Int:
gl->glUniform1f(id, (int)s.value);
gl->glUniform1f( id, ( int )s.value );
break;
default:
throw new NotImplementedException();
throw new ArgumentException(
"Incorrect type \"Unknown\" defined in this self define type");
"Incorrect type \"Unknown\" defined in this self define type" );
}
}
}//------------------------------------ End of Class ---------------------------------------
@@ -0,0 +1,98 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="TextureBufferImage.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;
using StgSharp.Graphics.OpenGL;
using StgSharp.Math;
using System;
namespace StgSharp.Graphics
{
public class TextureImage : IImageProvider
{
private byte[] _data;
private ImageInfo _imageInfo;
private int _pixelUpdateCount = 0;
public TextureImage(
Vec2 size,
ImageChannel channel,
PixelChannelLayout layout,
int bufferSize )
{
this._imageInfo = new ImageInfo
{
Width = ( int )size.X,
Height = ( int )size.Y,
Channel = channel,
pixelLayout = layout,
};
if( bufferSize < _imageInfo.Width * _imageInfo.Height * GlHelper.GetPixelSize(
layout, channel ) ) {
throw new OverflowException(
"Size of data buffer is smaller than default image size." );
}
_data = new byte[bufferSize];
}
public int Width
{
get => _imageInfo.Width;
internal set => _imageInfo.Width = value;
}
public int Height
{
get => _imageInfo.Height;
internal set => _imageInfo.Height = value;
}
public Image ProvideImage()
{
return Image.FromMemory( _imageInfo, _data, _pixelUpdateCount );
}
public void Resize( int width, int height )
{
if( _data.Length < width * height * GlHelper.GetPixelSize(
_imageInfo.pixelLayout, _imageInfo.Channel ) ) {
throw new OverflowException(
"Size of image is larger than capacity of sata buffer." );
}
Width = width;
Height = height;
_pixelUpdateCount++;
}
}
}
@@ -29,7 +29,6 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.BluePrint;
using System;
@@ -45,7 +44,7 @@ namespace StgSharp.Graphics
private Image _value;
public TexturePipeline(Image i)
public TexturePipeline( Image i )
{
_value = i;
}
@@ -53,7 +52,8 @@ namespace StgSharp.Graphics
public new Image Value
{
get => _value;
set => _value = value ?? throw new ArgumentNullException(nameof(value));
set => _value = value ??
throw new ArgumentNullException( nameof( value ) );
}
}
+13 -17
View File
@@ -40,23 +40,23 @@ namespace StgSharp.Graphics
public class TextureProvider : IImageProvider
{
private vec2d[] _texCoord;
private Vec2[] _texCoord;
private Image _tex;
public TextureProvider(Image image, vec2d[] coord)
public TextureProvider( Image image, Vec2[] coord )
{
_tex = image;
_texCoord = coord;
}
public ref vec2d this[int index]
public ref Vec2 this[ int index ]
{
get => ref _texCoord[index];
get => ref _texCoord[ index ];
}
public Span<vec2d> TextureCoordinate
public Span<Vec2> TextureCoordinate
{
get => new Span<vec2d>(_texCoord);
get => new Span<Vec2>( _texCoord );
}
public Image ProvideImage()
@@ -64,26 +64,22 @@ namespace StgSharp.Graphics
return _tex;
}
public void ReadImage(IImageProvider provider)
public void ReadImage( IImageProvider provider )
{
_tex = provider.ProvideImage();
}
public void UpdateFromImage(Image i)
public void UpdateFromImage( Image i )
{
if (i == _tex)
{
if( i == _tex ) {
return;
}
if (i.Size == _tex.Size)
{
if( i.Size == _tex.Size ) {
_tex = i;
} else {
throw new ArgumentException(
$"Size of {nameof(i)} does not equals to current image." );
}
else
{
throw new ArgumentException($"Size of {nameof(i)} does not equals to current image.");
}
}
}
@@ -0,0 +1,51 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="vkHandle.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.Vulkan
{
[StructLayout( LayoutKind.Explicit, Size = 8 )]
public struct vkHandle
{
[FieldOffset( 0 )] public int SignedHalfValue;
[FieldOffset( 0 )] public IntPtr Handle;
[FieldOffset( 0 )] public IntPtr UnsignedHandle;
[FieldOffset( 0 )] public uint HalfValue;
}
}
+381 -160
View File
@@ -32,6 +32,7 @@ using StgSharp.Graphics;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -45,239 +46,459 @@ namespace StgSharp
{
internal partial class InternalIO
{
#region api call
[DllImport(SSC_libName, EntryPoint = "glfwInit")] internal static extern unsafe int glfwInit();
[DllImport( SSC_libName, EntryPoint = "glfwInit" )] internal static extern unsafe int glfwInit(
);
[DllImport(SSC_libName, EntryPoint = "glfwTerminate")] internal static extern unsafe void glfwTerminate();
[DllImport( SSC_libName, EntryPoint = "glfwTerminate" )] internal static extern unsafe void glfwTerminate(
);
[DllImport(SSC_libName, EntryPoint = "glfwInitHint")] internal static extern unsafe void glfwInitHint(int hint, int value);
[DllImport( SSC_libName, EntryPoint = "glfwInitHint" )] internal static extern unsafe void glfwInitHint(
int hint,
int value );
[DllImport(SSC_libName, EntryPoint = "glfwGetVersion")] internal static extern unsafe void glfwGetVersion(int* major, int* minor, int* rev);
[DllImport( SSC_libName, EntryPoint = "glfwGetVersion" )] internal static extern unsafe void glfwGetVersion(
int* major,
int* minor,
int* rev );
[DllImport(SSC_libName, EntryPoint = "glfwGetVersionString")] internal static extern unsafe byte* glfwGetVersionString();
[DllImport( SSC_libName, EntryPoint = "glfwGetVersionString" )] internal static extern unsafe byte* glfwGetVersionString(
);
[DllImport(SSC_libName, EntryPoint = "glfwGetError")] internal static extern unsafe int glfwGetError(byte** description);
[DllImport( SSC_libName, EntryPoint = "glfwGetError" )] internal static extern unsafe int glfwGetError(
byte** description );
[DllImport(SSC_libName, EntryPoint = "glfwSetErrorCallback")] internal static extern unsafe GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun callback);
[DllImport( SSC_libName, EntryPoint = "glfwSetErrorCallback" )] internal static extern unsafe GLFWerrorfun glfwSetErrorCallback(
GLFWerrorfun callback );
[DllImport(SSC_libName, EntryPoint = "glfwGetMonitors")] internal static extern unsafe IntPtr* glfwGetMonitors(int* count);
[DllImport( SSC_libName, EntryPoint = "glfwGetMonitors" )] internal static extern unsafe IntPtr* glfwGetMonitors(
int* count );
[DllImport(SSC_libName, EntryPoint = "glfwGetPrimaryMonitor")] internal static extern unsafe IntPtr glfwGetPrimaryMonitor();
[DllImport( SSC_libName, EntryPoint = "glfwGetPrimaryMonitor" )] internal static extern unsafe IntPtr glfwGetPrimaryMonitor(
);
[DllImport(SSC_libName, EntryPoint = "glfwGetMonitorPos")] internal static extern unsafe void glfwGetMonitorPos(IntPtr monitor, int* xpos, int* ypos);
[DllImport( SSC_libName, EntryPoint = "glfwGetMonitorPos" )] internal static extern unsafe void glfwGetMonitorPos(
IntPtr monitor,
int* xpos,
int* ypos );
[DllImport(SSC_libName, EntryPoint = "glfwGetMonitorWorkarea")] internal static extern unsafe void glfwGetMonitorWorkarea(IntPtr monitor, int* xpos, int* ypos, int* width, int* height);
[DllImport( SSC_libName, EntryPoint = "glfwGetMonitorWorkarea" )] internal static extern unsafe void glfwGetMonitorWorkarea(
IntPtr monitor,
int* xpos,
int* ypos,
int* width,
int* height );
[DllImport(SSC_libName, EntryPoint = "glfwGetMonitorPhysicalSize")] internal static extern unsafe void glfwGetMonitorPhysicalSize(IntPtr monitor, int* widthMM, int* heightMM);
[DllImport( SSC_libName, EntryPoint = "glfwGetMonitorPhysicalSize" )] internal static extern unsafe void glfwGetMonitorPhysicalSize(
IntPtr monitor,
int* widthMM,
int* heightMM );
[DllImport(SSC_libName, EntryPoint = "glfwGetMonitorContentScale")] internal static extern unsafe void glfwGetMonitorContentScale(IntPtr monitor, float* xscale, float* yscale);
[DllImport( SSC_libName, EntryPoint = "glfwGetMonitorContentScale" )] internal static extern unsafe void glfwGetMonitorContentScale(
IntPtr monitor,
float* xscale,
float* yscale );
[DllImport( SSC_libName, EntryPoint = "glfwGetMonitorName" )] internal static extern unsafe byte* glfwGetMonitorName(
IntPtr monitor );
[DllImport( SSC_libName, EntryPoint = "glfwSetMonitorUserPointer" )] internal static extern unsafe void glfwSetMonitorUserPointer(
IntPtr monitor,
void* pointer );
[DllImport( SSC_libName, EntryPoint = "glfwGetMonitorUserPointer" )] internal static extern unsafe void* glfwGetMonitorUserPointer(
IntPtr monitor );
[DllImport( SSC_libName, EntryPoint = "glfwSetMonitorCallback" )] internal static extern unsafe GLFWmonitorfun glfwSetMonitorCallback(
GLFWmonitorfun callback );
[DllImport( SSC_libName, EntryPoint = "glfwGetVideoModes" )] internal static extern unsafe glfwVideomode* glfwGetVideoModes(
IntPtr monitor,
int* count );
[DllImport( SSC_libName, EntryPoint = "glfwGetVideoMode" )] internal static extern unsafe glfwVideomode* glfwGetVideoMode(
IntPtr monitor );
[DllImport( SSC_libName, EntryPoint = "glfwSetGamma" )] internal static extern unsafe void glfwSetGamma(
IntPtr monitor,
float gamma );
[DllImport( SSC_libName, EntryPoint = "glfwGetGammaRamp" )] internal static extern unsafe glfwGammaramp* glfwGetGammaRamp(
IntPtr monitor );
[DllImport( SSC_libName, EntryPoint = "glfwSetGammaRamp" )] internal static extern unsafe void glfwSetGammaRamp(
IntPtr monitor,
glfwGammaramp* ramp );
[DllImport( SSC_libName, EntryPoint = "glfwDefaultWindowHints" )] internal static extern unsafe void glfwDefaultWindowHints(
);
[DllImport( SSC_libName, EntryPoint = "glfwWindowHint" )] internal static extern unsafe void glfwWindowHint(
int hint,
int value );
[DllImport( SSC_libName, EntryPoint = "glfwWindowHintString" )] internal static extern unsafe void glfwWindowHintString(
int hint,
byte* value );
[DllImport(SSC_libName, EntryPoint = "glfwGetMonitorName")] internal static extern unsafe byte* glfwGetMonitorName(IntPtr monitor);
[DllImport( SSC_libName, EntryPoint = "glfwCreateWindow" )] internal static extern unsafe IntPtr glfwCreateWindow(
int width,
int height,
byte[] title,
IntPtr monitor,
IntPtr share );
[DllImport(SSC_libName, EntryPoint = "glfwSetMonitorUserPointer")] internal static extern unsafe void glfwSetMonitorUserPointer(IntPtr monitor, void* pointer);
[DllImport( SSC_libName, EntryPoint = "glfwDestroyWindow" )] internal static extern unsafe void glfwDestroyWindow(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwWindowShouldClose" )] internal static extern unsafe int glfwWindowShouldClose(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowShouldClose" )] internal static extern unsafe void glfwSetWindowShouldClose(
IntPtr window,
int value );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowTitle" )] internal static extern unsafe void glfwSetWindowTitle(
IntPtr window,
byte* title );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowIcon" )] internal static extern unsafe void glfwSetWindowIcon(
IntPtr window,
int count,
GLFWimage* images );
[DllImport( SSC_libName, EntryPoint = "glfwGetWindowPos" )] internal static extern unsafe void glfwGetWindowPos(
IntPtr window,
int* xpos,
int* ypos );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowPos" )] internal static extern unsafe void glfwSetWindowPos(
IntPtr window,
int xpos,
int ypos );
[DllImport( SSC_libName, EntryPoint = "glfwGetWindowSize" )] internal static extern unsafe void glfwGetWindowSize(
IntPtr window,
int* width,
int* height );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowSizeLimits" )] internal static extern unsafe void glfwSetWindowSizeLimits(
IntPtr window,
int minwidth,
int minheight,
int maxwidth,
int maxheight );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowAspectRatio" )] internal static extern unsafe void glfwSetWindowAspectRatio(
IntPtr window,
int numer,
int denom );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowSize" )] internal static extern unsafe void glfwSetWindowSize(
IntPtr window,
int width,
int height );
[DllImport( SSC_libName, EntryPoint = "glfwGetFramebufferSize" )] internal static extern unsafe void glfwGetFramebufferSize(
IntPtr window,
int* width,
int* height );
[DllImport( SSC_libName, EntryPoint = "glfwGetWindowFrameSize" )] internal static extern unsafe void glfwGetWindowFrameSize(
IntPtr window,
int* left,
int* top,
int* right,
int* bottom );
[DllImport( SSC_libName, EntryPoint = "glfwGetWindowContentScale" )] internal static extern unsafe void glfwGetWindowContentScale(
IntPtr window,
float* xscale,
float* yscale );
[DllImport( SSC_libName, EntryPoint = "glfwGetWindowOpacity" )] internal static extern unsafe float glfwGetWindowOpacity(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowOpacity" )] internal static extern unsafe void glfwSetWindowOpacity(
IntPtr window,
float opacity );
[DllImport( SSC_libName, EntryPoint = "glfwIconifyWindow" )] internal static extern unsafe void glfwIconifyWindow(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwRestoreWindow" )] internal static extern unsafe void glfwRestoreWindow(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwMaximizeWindow" )] internal static extern unsafe void glfwMaximizeWindow(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwShowWindow" )] internal static extern unsafe void glfwShowWindow(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwHideWindow" )] internal static extern unsafe void glfwHideWindow(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwFocusWindow" )] internal static extern unsafe void glfwFocusWindow(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwRequestWindowAttention" )] internal static extern unsafe void glfwRequestWindowAttention(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwGetWindowMonitor" )] internal static extern unsafe IntPtr glfwGetWindowMonitor(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowMonitor" )] internal static extern unsafe void glfwSetWindowMonitor(
IntPtr window,
IntPtr monitor,
int xpos,
int ypos,
int width,
int height,
int refreshRate );
[DllImport( SSC_libName, EntryPoint = "glfwGetWindowAttrib" )] internal static extern unsafe int glfwGetWindowAttrib(
IntPtr window,
int attrib );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowAttrib" )] internal static extern unsafe void glfwSetWindowAttrib(
IntPtr window,
int attrib,
int value );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowUserPointer" )] internal static extern unsafe void glfwSetWindowUserPointer(
IntPtr window,
void* pointer );
[DllImport( SSC_libName, EntryPoint = "glfwGetWindowUserPointer" )] internal static extern unsafe void* glfwGetWindowUserPointer(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowPosCallback" )] internal static extern unsafe GLFWwindowposfun glfwSetWindowPosCallback(
IntPtr window,
IntPtr callback );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowSizeCallback" )] internal static extern unsafe GLFWwindowsizefun glfwSetWindowSizeCallback(
IntPtr window,
GLFWwindowsizefun callback );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowCloseCallback" )] internal static extern unsafe GLFWwindowclosefun glfwSetWindowCloseCallback(
IntPtr window,
GLFWwindowclosefun callback );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowRefreshCallback" )] internal static extern unsafe GLFWwindowrefreshfun glfwSetWindowRefreshCallback(
IntPtr window,
GLFWwindowrefreshfun callback );
[DllImport(SSC_libName, EntryPoint = "glfwGetMonitorUserPointer")] internal static extern unsafe void* glfwGetMonitorUserPointer(IntPtr monitor);
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowFocusCallback" )] internal static extern unsafe GLFWwindowfocusfun glfwSetWindowFocusCallback(
IntPtr window,
GLFWwindowfocusfun callback );
[DllImport(SSC_libName, EntryPoint = "glfwSetMonitorCallback")] internal static extern unsafe GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun callback);
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowIconifyCallback" )] internal static extern unsafe GLFWwindowiconifyfun glfwSetWindowIconifyCallback(
IntPtr window,
GLFWwindowiconifyfun callback );
[DllImport(SSC_libName, EntryPoint = "glfwGetVideoModes")] internal static extern unsafe glfwVideomode* glfwGetVideoModes(IntPtr monitor, int* count);
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowMaximizeCallback" )] internal static extern unsafe GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(
IntPtr window,
GLFWwindowmaximizefun callback );
[DllImport(SSC_libName, EntryPoint = "glfwGetVideoMode")] internal static extern unsafe glfwVideomode* glfwGetVideoMode(IntPtr monitor);
[DllImport( SSC_libName, EntryPoint = "glfwSetFramebufferSizeCallback" )] internal static extern unsafe FrameBufferSizeHandler glfwSetFramebufferSizeCallback(
IntPtr window,
IntPtr callback );
[DllImport(SSC_libName, EntryPoint = "glfwSetGamma")] internal static extern unsafe void glfwSetGamma(IntPtr monitor, float gamma);
[DllImport(
SSC_libName,
EntryPoint = "glfwSetWindowContentScaleCallback" )] internal static extern unsafe GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(
IntPtr window,
GLFWwindowcontentscalefun callback );
[DllImport(SSC_libName, EntryPoint = "glfwGetGammaRamp")] internal static extern unsafe glfwGammaramp* glfwGetGammaRamp(IntPtr monitor);
[DllImport( SSC_libName, EntryPoint = "glfwPollEvents" )] internal static extern unsafe void glfwPollEvents(
);
[DllImport(SSC_libName, EntryPoint = "glfwSetGammaRamp")] internal static extern unsafe void glfwSetGammaRamp(IntPtr monitor, glfwGammaramp* ramp);
[DllImport( SSC_libName, EntryPoint = "glfwWaitEvents" )] internal static extern unsafe void glfwWaitEvents(
);
[DllImport(SSC_libName, EntryPoint = "glfwDefaultWindowHints")] internal static extern unsafe void glfwDefaultWindowHints();
[DllImport( SSC_libName, EntryPoint = "glfwWaitEventsTimeout" )] internal static extern unsafe void glfwWaitEventsTimeout(
double timeout );
[DllImport(SSC_libName, EntryPoint = "glfwWindowHint")] internal static extern unsafe void glfwWindowHint(int hint, int value);
[DllImport( SSC_libName, EntryPoint = "glfwPostEmptyEvent" )] internal static extern unsafe void glfwPostEmptyEvent(
);
[DllImport(SSC_libName, EntryPoint = "glfwWindowHintString")] internal static extern unsafe void glfwWindowHintString(int hint, byte* value);
[DllImport( SSC_libName, EntryPoint = "glfwGetInputMode" )] internal static extern unsafe int glfwGetInputMode(
IntPtr window,
int mode );
[DllImport(SSC_libName, EntryPoint = "glfwCreateWindow")] internal static extern unsafe IntPtr glfwCreateWindow(int width, int height, byte[] title, IntPtr monitor, IntPtr share);
[DllImport( SSC_libName, EntryPoint = "glfwSetInputMode" )] internal static extern unsafe void glfwSetInputMode(
IntPtr window,
int mode,
int value );
[DllImport(SSC_libName, EntryPoint = "glfwDestroyWindow")] internal static extern unsafe void glfwDestroyWindow(IntPtr window);
[DllImport( SSC_libName, EntryPoint = "glfwRawMouseMotionSupported" )] internal static extern unsafe int glfwRawMouseMotionSupported(
);
[DllImport(SSC_libName, EntryPoint = "glfwWindowShouldClose")] internal static extern unsafe int glfwWindowShouldClose(IntPtr window);
[DllImport( SSC_libName, EntryPoint = "glfwGetKeyName" )] internal static extern unsafe byte* glfwGetKeyName(
int key,
int scancode );
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowShouldClose")] internal static extern unsafe void glfwSetWindowShouldClose(IntPtr window, int value);
[DllImport( SSC_libName, EntryPoint = "glfwGetKeyScancode" )] internal static extern unsafe int glfwGetKeyScancode(
int key );
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowTitle")] internal static extern unsafe void glfwSetWindowTitle(IntPtr window, byte* title);
[DllImport( SSC_libName, EntryPoint = "glfwGetKey" )] internal static extern unsafe KeyStatus glfwGetKey(
IntPtr window,
int key );
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowIcon")] internal static extern unsafe void glfwSetWindowIcon(IntPtr window, int count, GLFWimage* images);
[DllImport( SSC_libName, EntryPoint = "glfwGetMouseButton" )] internal static extern unsafe int glfwGetMouseButton(
IntPtr window,
int button );
[DllImport(SSC_libName, EntryPoint = "glfwGetWindowPos")] internal static extern unsafe void glfwGetWindowPos(IntPtr window, int* xpos, int* ypos);
[DllImport( SSC_libName, EntryPoint = "glfwGetCursorPos" )] internal static extern unsafe void glfwGetCursorPos(
IntPtr window,
double* xpos,
double* ypos );
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowPos")] internal static extern unsafe void glfwSetWindowPos(IntPtr window, int xpos, int ypos);
[DllImport( SSC_libName, EntryPoint = "glfwSetCursorPos" )] internal static extern unsafe void glfwSetCursorPos(
IntPtr window,
double xpos,
double ypos );
[DllImport(SSC_libName, EntryPoint = "glfwGetWindowSize")] internal static extern unsafe void glfwGetWindowSize(IntPtr window, int* width, int* height);
[DllImport( SSC_libName, EntryPoint = "glfwCreateCursor" )] internal static extern unsafe GLFWcursor* glfwCreateCursor(
GLFWimage* image,
int xhot,
int yhot );
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowSizeLimits")] internal static extern unsafe void glfwSetWindowSizeLimits(IntPtr window, int minwidth, int minheight, int maxwidth, int maxheight);
[DllImport( SSC_libName, EntryPoint = "glfwCreateStandardCursor" )] internal static extern unsafe GLFWcursor* glfwCreateStandardCursor(
int shape );
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowAspectRatio")] internal static extern unsafe void glfwSetWindowAspectRatio(IntPtr window, int numer, int denom);
[DllImport( SSC_libName, EntryPoint = "glfwDestroyCursor" )] internal static extern unsafe void glfwDestroyCursor(
GLFWcursor* cursor );
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowSize")] internal static extern unsafe void glfwSetWindowSize(IntPtr window, int width, int height);
[DllImport( SSC_libName, EntryPoint = "glfwSetCursor" )] internal static extern unsafe void glfwSetCursor(
IntPtr window,
GLFWcursor* cursor );
[DllImport(SSC_libName, EntryPoint = "glfwGetFramebufferSize")] internal static extern unsafe void glfwGetFramebufferSize(IntPtr window, int* width, int* height);
[DllImport( SSC_libName, EntryPoint = "glfwSetKeyCallback" )] internal static extern unsafe GLFWkeyfun glfwSetKeyCallback(
IntPtr window,
GLFWkeyfun callback );
[DllImport(SSC_libName, EntryPoint = "glfwGetWindowFrameSize")] internal static extern unsafe void glfwGetWindowFrameSize(IntPtr window, int* left, int* top, int* right, int* bottom);
[DllImport( SSC_libName, EntryPoint = "glfwSetCharCallback" )] internal static extern unsafe GLFWcharfun glfwSetCharCallback(
IntPtr window,
GLFWcharfun callback );
[DllImport(SSC_libName, EntryPoint = "glfwGetWindowContentScale")] internal static extern unsafe void glfwGetWindowContentScale(IntPtr window, float* xscale, float* yscale);
[DllImport( SSC_libName, EntryPoint = "glfwSetCharModsCallback" )] internal static extern unsafe GLFWcharmodsfun glfwSetCharModsCallback(
IntPtr window,
GLFWcharmodsfun callback );
[DllImport(SSC_libName, EntryPoint = "glfwGetWindowOpacity")] internal static extern unsafe float glfwGetWindowOpacity(IntPtr window);
[DllImport( SSC_libName, EntryPoint = "glfwSetMouseButtonCallback" )] internal static extern unsafe GLFWmousebuttonfun glfwSetMouseButtonCallback(
IntPtr window,
GLFWmousebuttonfun callback );
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowOpacity")] internal static extern unsafe void glfwSetWindowOpacity(IntPtr window, float opacity);
[DllImport( SSC_libName, EntryPoint = "glfwSetCursorPosCallback" )] internal static extern unsafe GLFWcursorposfun glfwSetCursorPosCallback(
IntPtr window,
GLFWcursorposfun callback );
[DllImport(SSC_libName, EntryPoint = "glfwIconifyWindow")] internal static extern unsafe void glfwIconifyWindow(IntPtr window);
[DllImport( SSC_libName, EntryPoint = "glfwSetCursorEnterCallback" )] internal static extern unsafe GLFWcursorenterfun glfwSetCursorEnterCallback(
IntPtr window,
GLFWcursorenterfun callback );
[DllImport(SSC_libName, EntryPoint = "glfwRestoreWindow")] internal static extern unsafe void glfwRestoreWindow(IntPtr window);
[DllImport( SSC_libName, EntryPoint = "glfwSetScrollCallback" )] internal static extern unsafe GLFWscrollfun glfwSetScrollCallback(
IntPtr window,
GLFWscrollfun callback );
[DllImport(SSC_libName, EntryPoint = "glfwMaximizeWindow")] internal static extern unsafe void glfwMaximizeWindow(IntPtr window);
[DllImport( SSC_libName, EntryPoint = "glfwSetDropCallback" )] internal static extern unsafe GLFWdropfun glfwSetDropCallback(
IntPtr window,
GLFWdropfun callback );
[DllImport(SSC_libName, EntryPoint = "glfwShowWindow")] internal static extern unsafe void glfwShowWindow(IntPtr window);
[DllImport( SSC_libName, EntryPoint = "glfwJoystickPresent" )] internal static extern unsafe int glfwJoystickPresent(
int jid );
[DllImport(SSC_libName, EntryPoint = "glfwHideWindow")] internal static extern unsafe void glfwHideWindow(IntPtr window);
[DllImport( SSC_libName, EntryPoint = "glfwGetJoystickAxes" )] internal static extern unsafe float* glfwGetJoystickAxes(
int jid,
int* count );
[DllImport(SSC_libName, EntryPoint = "glfwFocusWindow")] internal static extern unsafe void glfwFocusWindow(IntPtr window);
[DllImport( SSC_libName, EntryPoint = "glfwGetJoystickButtons" )] internal static extern unsafe byte* glfwGetJoystickButtons(
int jid,
int* count );
[DllImport(SSC_libName, EntryPoint = "glfwRequestWindowAttention")] internal static extern unsafe void glfwRequestWindowAttention(IntPtr window);
[DllImport( SSC_libName, EntryPoint = "glfwGetJoystickHats" )] internal static extern unsafe byte* glfwGetJoystickHats(
int jid,
int* count );
[DllImport(SSC_libName, EntryPoint = "glfwGetWindowMonitor")] internal static extern unsafe IntPtr glfwGetWindowMonitor(IntPtr window);
[DllImport( SSC_libName, EntryPoint = "glfwGetJoystickName" )] internal static extern unsafe byte* glfwGetJoystickName(
int jid );
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowMonitor")] internal static extern unsafe void glfwSetWindowMonitor(IntPtr window, IntPtr monitor, int xpos, int ypos, int width, int height, int refreshRate);
[DllImport( SSC_libName, EntryPoint = "glfwGetJoystickGUID" )] internal static extern unsafe byte* glfwGetJoystickGUID(
int jid );
[DllImport(SSC_libName, EntryPoint = "glfwGetWindowAttrib")] internal static extern unsafe int glfwGetWindowAttrib(IntPtr window, int attrib);
[DllImport( SSC_libName, EntryPoint = "glfwSetJoystickUserPointer" )] internal static extern unsafe void glfwSetJoystickUserPointer(
int jid,
void* pointer );
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowAttrib")] internal static extern unsafe void glfwSetWindowAttrib(IntPtr window, int attrib, int value);
[DllImport( SSC_libName, EntryPoint = "glfwGetJoystickUserPointer" )] internal static extern unsafe void* glfwGetJoystickUserPointer(
int jid );
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowUserPointer")] internal static extern unsafe void glfwSetWindowUserPointer(IntPtr window, void* pointer);
[DllImport( SSC_libName, EntryPoint = "glfwJoystickIsGamepad" )] internal static extern unsafe int glfwJoystickIsGamepad(
int jid );
[DllImport(SSC_libName, EntryPoint = "glfwGetWindowUserPointer")] internal static extern unsafe void* glfwGetWindowUserPointer(IntPtr window);
[DllImport( SSC_libName, EntryPoint = "glfwSetJoystickCallback" )] internal static extern unsafe GLFWjoystickfun glfwSetJoystickCallback(
GLFWjoystickfun callback );
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowPosCallback")] internal static extern unsafe GLFWwindowposfun glfwSetWindowPosCallback(IntPtr window, IntPtr callback);
[DllImport( SSC_libName, EntryPoint = "glfwUpdateGamepadMappings" )] internal static extern unsafe int glfwUpdateGamepadMappings(
byte* str );
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowSizeCallback")] internal static extern unsafe GLFWwindowsizefun glfwSetWindowSizeCallback(IntPtr window, GLFWwindowsizefun callback);
[DllImport( SSC_libName, EntryPoint = "glfwGetGamepadName" )] internal static extern unsafe byte* glfwGetGamepadName(
int jid );
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowCloseCallback")] internal static extern unsafe GLFWwindowclosefun glfwSetWindowCloseCallback(IntPtr window, GLFWwindowclosefun callback);
[DllImport( SSC_libName, EntryPoint = "glfwGetGamepadState" )] internal static extern unsafe int glfwGetGamepadState(
int jid,
GLFWgamepadstate* state );
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowRefreshCallback")] internal static extern unsafe GLFWwindowrefreshfun glfwSetWindowRefreshCallback(IntPtr window, GLFWwindowrefreshfun callback);
[DllImport( SSC_libName, EntryPoint = "glfwSetClipboardString" )] internal static extern unsafe void glfwSetClipboardString(
IntPtr window,
byte* str );
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowFocusCallback")] internal static extern unsafe GLFWwindowfocusfun glfwSetWindowFocusCallback(IntPtr window, GLFWwindowfocusfun callback);
[DllImport( SSC_libName, EntryPoint = "glfwGetClipboardString" )] internal static extern unsafe byte* glfwGetClipboardString(
IntPtr window );
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowIconifyCallback")] internal static extern unsafe GLFWwindowiconifyfun glfwSetWindowIconifyCallback(IntPtr window, GLFWwindowiconifyfun callback);
[DllImport( SSC_libName, EntryPoint = "glfwGetTime" )] internal static extern unsafe double glfwGetTime(
);
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowMaximizeCallback")] internal static extern unsafe GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(IntPtr window, GLFWwindowmaximizefun callback);
[DllImport( SSC_libName, EntryPoint = "glfwSetTime" )] internal static extern unsafe void glfwSetTime(
double time );
[DllImport(SSC_libName, EntryPoint = "glfwSetFramebufferSizeCallback")] internal static extern unsafe FrameBufferSizeHandler glfwSetFramebufferSizeCallback(IntPtr window, IntPtr callback);
[DllImport( SSC_libName, EntryPoint = "glfwGetTimerValue" )] internal static extern unsafe ulong* glfwGetTimerValue(
);
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowContentScaleCallback")] internal static extern unsafe GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(IntPtr window, GLFWwindowcontentscalefun callback);
[DllImport( SSC_libName, EntryPoint = "glfwGetTimerFrequency" )] internal static extern unsafe ulong* glfwGetTimerFrequency(
);
[DllImport(SSC_libName, EntryPoint = "glfwPollEvents")] internal static extern unsafe void glfwPollEvents();
[DllImport( SSC_libName, EntryPoint = "glfwMakeContextCurrent" )] internal static extern unsafe void glfwMakeContextCurrent(
IntPtr window );
[DllImport(SSC_libName, EntryPoint = "glfwWaitEvents")] internal static extern unsafe void glfwWaitEvents();
[DllImport( SSC_libName, EntryPoint = "glfwGetCurrentContext" )] internal static extern unsafe IntPtr glfwGetCurrentContext(
);
[DllImport(SSC_libName, EntryPoint = "glfwWaitEventsTimeout")] internal static extern unsafe void glfwWaitEventsTimeout(double timeout);
[DllImport( SSC_libName, EntryPoint = "glfwSwapBuffers" )] internal static extern unsafe void glfwSwapBuffers(
IntPtr window );
[DllImport(SSC_libName, EntryPoint = "glfwPostEmptyEvent")] internal static extern unsafe void glfwPostEmptyEvent();
[DllImport( SSC_libName, EntryPoint = "glfwSwapInterval" )] internal static extern unsafe void glfwSwapInterval(
int interval );
[DllImport(SSC_libName, EntryPoint = "glfwGetInputMode")] internal static extern unsafe int glfwGetInputMode(IntPtr window, int mode);
[DllImport( SSC_libName, EntryPoint = "glfwExtensionSupported" )] internal static extern unsafe int glfwExtensionSupported(
byte* extension );
[DllImport(SSC_libName, EntryPoint = "glfwSetInputMode")] internal static extern unsafe void glfwSetInputMode(IntPtr window, int mode, int value);
[DllImport(
SSC_libName,
EntryPoint = "glfwGetProcAddress",
CharSet = CharSet.Ansi )] internal static extern unsafe IntPtr glfwGetProcAddress(
string procname );
[DllImport(SSC_libName, EntryPoint = "glfwRawMouseMotionSupported")] internal static extern unsafe int glfwRawMouseMotionSupported();
[DllImport( SSC_libName, EntryPoint = "glfwVulkanSupported" )] internal static extern unsafe int glfwVulkanSupported(
);
[DllImport(SSC_libName, EntryPoint = "glfwGetKeyName")] internal static extern unsafe byte* glfwGetKeyName(int key, int scancode);
[DllImport(SSC_libName, EntryPoint = "glfwGetKeyScancode")] internal static extern unsafe int glfwGetKeyScancode(int key);
[DllImport(SSC_libName, EntryPoint = "glfwGetKey")] internal static extern unsafe KeyStatus glfwGetKey(IntPtr window, int key);
[DllImport(SSC_libName, EntryPoint = "glfwGetMouseButton")] internal static extern unsafe int glfwGetMouseButton(IntPtr window, int button);
[DllImport(SSC_libName, EntryPoint = "glfwGetCursorPos")] internal static extern unsafe void glfwGetCursorPos(IntPtr window, double* xpos, double* ypos);
[DllImport(SSC_libName, EntryPoint = "glfwSetCursorPos")] internal static extern unsafe void glfwSetCursorPos(IntPtr window, double xpos, double ypos);
[DllImport(SSC_libName, EntryPoint = "glfwCreateCursor")] internal static extern unsafe GLFWcursor* glfwCreateCursor(GLFWimage* image, int xhot, int yhot);
[DllImport(SSC_libName, EntryPoint = "glfwCreateStandardCursor")] internal static extern unsafe GLFWcursor* glfwCreateStandardCursor(int shape);
[DllImport(SSC_libName, EntryPoint = "glfwDestroyCursor")] internal static extern unsafe void glfwDestroyCursor(GLFWcursor* cursor);
[DllImport(SSC_libName, EntryPoint = "glfwSetCursor")] internal static extern unsafe void glfwSetCursor(IntPtr window, GLFWcursor* cursor);
[DllImport(SSC_libName, EntryPoint = "glfwSetKeyCallback")] internal static extern unsafe GLFWkeyfun glfwSetKeyCallback(IntPtr window, GLFWkeyfun callback);
[DllImport(SSC_libName, EntryPoint = "glfwSetCharCallback")] internal static extern unsafe GLFWcharfun glfwSetCharCallback(IntPtr window, GLFWcharfun callback);
[DllImport(SSC_libName, EntryPoint = "glfwSetCharModsCallback")] internal static extern unsafe GLFWcharmodsfun glfwSetCharModsCallback(IntPtr window, GLFWcharmodsfun callback);
[DllImport(SSC_libName, EntryPoint = "glfwSetMouseButtonCallback")] internal static extern unsafe GLFWmousebuttonfun glfwSetMouseButtonCallback(IntPtr window, GLFWmousebuttonfun callback);
[DllImport(SSC_libName, EntryPoint = "glfwSetCursorPosCallback")] internal static extern unsafe GLFWcursorposfun glfwSetCursorPosCallback(IntPtr window, GLFWcursorposfun callback);
[DllImport(SSC_libName, EntryPoint = "glfwSetCursorEnterCallback")] internal static extern unsafe GLFWcursorenterfun glfwSetCursorEnterCallback(IntPtr window, GLFWcursorenterfun callback);
[DllImport(SSC_libName, EntryPoint = "glfwSetScrollCallback")] internal static extern unsafe GLFWscrollfun glfwSetScrollCallback(IntPtr window, GLFWscrollfun callback);
[DllImport(SSC_libName, EntryPoint = "glfwSetDropCallback")] internal static extern unsafe GLFWdropfun glfwSetDropCallback(IntPtr window, GLFWdropfun callback);
[DllImport(SSC_libName, EntryPoint = "glfwJoystickPresent")] internal static extern unsafe int glfwJoystickPresent(int jid);
[DllImport(SSC_libName, EntryPoint = "glfwGetJoystickAxes")] internal static extern unsafe float* glfwGetJoystickAxes(int jid, int* count);
[DllImport(SSC_libName, EntryPoint = "glfwGetJoystickButtons")] internal static extern unsafe byte* glfwGetJoystickButtons(int jid, int* count);
[DllImport(SSC_libName, EntryPoint = "glfwGetJoystickHats")] internal static extern unsafe byte* glfwGetJoystickHats(int jid, int* count);
[DllImport(SSC_libName, EntryPoint = "glfwGetJoystickName")] internal static extern unsafe byte* glfwGetJoystickName(int jid);
[DllImport(SSC_libName, EntryPoint = "glfwGetJoystickGUID")] internal static extern unsafe byte* glfwGetJoystickGUID(int jid);
[DllImport(SSC_libName, EntryPoint = "glfwSetJoystickUserPointer")] internal static extern unsafe void glfwSetJoystickUserPointer(int jid, void* pointer);
[DllImport(SSC_libName, EntryPoint = "glfwGetJoystickUserPointer")] internal static extern unsafe void* glfwGetJoystickUserPointer(int jid);
[DllImport(SSC_libName, EntryPoint = "glfwJoystickIsGamepad")] internal static extern unsafe int glfwJoystickIsGamepad(int jid);
[DllImport(SSC_libName, EntryPoint = "glfwSetJoystickCallback")] internal static extern unsafe GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun callback);
[DllImport(SSC_libName, EntryPoint = "glfwUpdateGamepadMappings")] internal static extern unsafe int glfwUpdateGamepadMappings(byte* str);
[DllImport(SSC_libName, EntryPoint = "glfwGetGamepadName")] internal static extern unsafe byte* glfwGetGamepadName(int jid);
[DllImport(SSC_libName, EntryPoint = "glfwGetGamepadState")] internal static extern unsafe int glfwGetGamepadState(int jid, GLFWgamepadstate* state);
[DllImport(SSC_libName, EntryPoint = "glfwSetClipboardString")] internal static extern unsafe void glfwSetClipboardString(IntPtr window, byte* str);
[DllImport(SSC_libName, EntryPoint = "glfwGetClipboardString")] internal static extern unsafe byte* glfwGetClipboardString(IntPtr window);
[DllImport(SSC_libName, EntryPoint = "glfwGetTime")] internal static extern unsafe double glfwGetTime();
[DllImport(SSC_libName, EntryPoint = "glfwSetTime")] internal static extern unsafe void glfwSetTime(double time);
[DllImport(SSC_libName, EntryPoint = "glfwGetTimerValue")] internal static extern unsafe ulong* glfwGetTimerValue();
[DllImport(SSC_libName, EntryPoint = "glfwGetTimerFrequency")] internal static extern unsafe ulong* glfwGetTimerFrequency();
[DllImport(SSC_libName, EntryPoint = "glfwMakeContextCurrent")] internal static extern unsafe void glfwMakeContextCurrent(IntPtr window);
[DllImport(SSC_libName, EntryPoint = "glfwGetCurrentContext")] internal static extern unsafe IntPtr glfwGetCurrentContext();
[DllImport(SSC_libName, EntryPoint = "glfwSwapBuffers")] internal static extern unsafe void glfwSwapBuffers(IntPtr window);
[DllImport(SSC_libName, EntryPoint = "glfwSwapInterval")] internal static extern unsafe void glfwSwapInterval(int interval);
[DllImport(SSC_libName, EntryPoint = "glfwExtensionSupported")] internal static extern unsafe int glfwExtensionSupported(byte* extension);
[DllImport(SSC_libName, EntryPoint = "glfwGetProcAddress", CharSet = CharSet.Ansi)] internal static extern unsafe IntPtr glfwGetProcAddress(string procname);
[DllImport(SSC_libName, EntryPoint = "glfwVulkanSupported")] internal static extern unsafe int glfwVulkanSupported();
[DllImport(SSC_libName, EntryPoint = "glfwGetRequiredInstanceExtensions")] internal static extern unsafe byte** glfwGetRequiredInstanceExtensions(uint* count);
[DllImport(
SSC_libName,
EntryPoint = "glfwGetRequiredInstanceExtensions" )] internal static extern unsafe byte** glfwGetRequiredInstanceExtensions(
uint* count );
//[DllImport(InternalIO.SSC_libname, EntryPoint = "glfwGetInstanceProcAddress")] internal extern unsafe static GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, byte* procname);
//[DllImport(InternalIO.SSC_libname, EntryPoint = "glfwGetPhysicalDevicePresentationSupport")] internal extern unsafe static int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint* queuefamily);
@@ -0,0 +1,78 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="frameworkSyncContext.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Threading
{
public class FrameworkSyncContext : SynchronizationContext
{
private static readonly FrameworkSyncContext _mainThreadContext = new FrameworkSyncContext(
);
private readonly BlockingCollection<SendOrPostCallback> _syncContexts = new BlockingCollection<SendOrPostCallback>(
);
private readonly Thread _mainThread = Thread.CurrentThread;
public FrameworkSyncContext()
{
_syncContexts = new BlockingCollection<SendOrPostCallback>();
_mainThread = Thread.CurrentThread;
}
public static FrameworkSyncContext MainThreadContext
{
get => _mainThreadContext;
}
public override void Post( SendOrPostCallback d, object state )
{
_syncContexts.Add( d );
}
public override void Send( SendOrPostCallback d, object state )
{
if( Thread.CurrentThread == _mainThread ) {
d( state );
} else {
Post( d, state );
}
}
}
}