This commit is contained in:
Nitload
2024-06-10 15:12:08 +08:00
parent f6963b8e00
commit be6c2e6b92
305 changed files with 28336 additions and 5938 deletions
-1
View File
@@ -1 +0,0 @@
D:/NitloadIndustry/研究项目/1-Flagship/TH2020/ProjectFile/源代码/StgSharp/Graphics
@@ -0,0 +1,88 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="AnimationBuilder.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.Geometries;
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
namespace StgSharp.Graphics
{
public delegate Image BuildAnimationDelegate(float time, out Polygon4 texutreFrame);
public sealed class AnimationBuilder: IImageProvider
{
private Image cache;
private Polygon4 textureFrame;
private TimeFunction time;
public AnimationBuilder(
BuildAnimationDelegate builderFunc,
TimeFunction timeline
)
{
textureFrame = new Polygon4();
time = timeline;
BuilderFunc = builderFunc;
cache = BuilderFunc(time.Calculate(), out textureFrame);
}
public Polygon4 TextureFrame { get => textureFrame; }
public BuildAnimationDelegate BuilderFunc { get; set; }
public bool IsComplete
{
get => time.IsComplete;
}
public Image GetAnimationFrame()
{
if (!time.IsComplete)
{
cache = BuilderFunc(time.Calculate(),out textureFrame);
}
return cache;
}
public void reset()
{
time.Reset();
}
Image IImageProvider.ProvideImage()
{
return GetAnimationFrame();
}
}
}
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Graphics
{
public interface IImageProvider
{
Image ProvideImage();
}
}
@@ -0,0 +1,961 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="StructDefine.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics.GL;
using System;
using System.Runtime.InteropServices;
/**/
namespace StgSharp.Graphics
{
//rename types in style of GLFW
using GLFWbool = Boolean;
//strucs defined in GLFW3.h
#region GLFW3 struct
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWcontext
{
private int client;
private IntPtr destroy;
private delegate*<byte*> extensionSupported;
private GLFWbool forward, debug, noerror;
//PFNGLGETINTEGERVPROC GetIntegerv;
private IntPtr GetIntegerv;
private delegate*<delegate*<void>, void> getProcAddress;
//PFNGLGETSTRINGPROC GetString;
private IntPtr GetString;
//PFNGLGETSTRINGIPROC GetStringi;
private IntPtr GetStringi;
private int major, minor, revision;
/*
void (* makeCurrent) (glfwWindow*);
void (* swapBuffers) (glfwWindow*);
void (* swapInterval) (int);
int (* extensionSupported) (const byte*);
GLFWglproc(*getProcAddress)(const byte*);
void (* destroy) (glfwWindow*);
*/
private delegate*<glfwWindow*> makeCurrent;
private int profile;
private int release;
private int robustness;
private int source;
private delegate*<glfwWindow*> swapBuffer;
private delegate*<int> swapInterval;
internal struct egl
{
private void* client;
/*
EGLConfig config;
EGLContext handle;
EGLSurface surface;
*/
private void* config;
private void* handle;
private void* surface;
}
internal struct osmesa
{
private void* buffer;
//OSMesaContext handle;
private void* handle;
private int height;
private int width;
}
// This is defined in platform.h
//GLFW_PLATFORM_CONTEXT_STATE
}
[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.
*/
public int blueBits;
/*! The bit depth of the green channel of the video mode.
*/
public int greenBits;
/*! The height, in screen coordinates, of the video mode.
*/
public int height;
/*! The bit depth of the red channel of the video mode.
*/
public int redBits;
/*! The width, in screen coordinates, of the video mode.
*/
public int width;
}
[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.
*/
private ushort* green;
/*! An array of value describing the response of the red channel.
*/
private ushort* red;
/*! The number of elements in each array.
*/
private uint size;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWimage
{
/*! The height, in pixels, of this image.
*/
private int height;
/*! The width, in pixels, of this image.
*/
private int width;
/*! The pixel data of this image, arranged left-to-right, top-to-bottom.
*/
private byte* pixels;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWgamepadstate
{
/*! The states of each [gamepad axis](@ref gamepad_axes), in the range -1.0
* to 1.0 inclusive.
*/
public fixed float axes[6];
/*! The states of each [gamepad button](@ref gamepad_buttons), `GLFW_PRESS`
* or `GLFW_RELEASE`.
*/
public fixed byte buttons[15];
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWallocator
{
//GLFWallocatefun allocate;
private IntPtr allocate;
//GLFWdeallocatefun deallocate;
private IntPtr deallocate;
//GLFWreallocatefun reallocate;
private IntPtr reallocate;
private void* user;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct glfwMonitor
{
private fixed byte name[128];
private IntPtr userPointer;
private int width, height;
private glfwWindow* window;
private glfwVideomode* modes;
private int modeCount;
private glfwVideomode currentMode;
private glfwGammaramp originalRamp;
private glfwGammaramp currentRamp;
public glfwMonitor()
{ }
public unsafe string Name
{
get
{
fixed (byte* cptr = name)
{
return Marshal.PtrToStringAnsi((IntPtr)cptr);
}
}
}
}
[StructLayout(LayoutKind.Sequential)]
unsafe struct glfwWindow
{
glfwWindow* next;
// Window settings and state
int resizable;
int decorated;
int autoIconify;
int floating;
int focusOnShow;
int mousePassthrough;
int shouldClose;
void* userPointer;
int doublebuffer;
// glfwVideomode videoMode; // 根据GLFWvidmode的定义转换
IntPtr monitor; // _GLFWmonitor* monitor;
IntPtr cursor; // _GLFWcursor* cursor;
int minwidth, minheight;
int maxwidth, maxheight;
int numer, denom;
int stickyKeys;
int stickyMouseButtons;
int lockKeyMods;
int cursorMode;
public fixed byte mouseButtons[GLconst.GLFW_MOUSE_BUTTON_LAST + 1];
public fixed byte keys[GLconst.GLFW_KEY_LAST + 1];
// Virtual cursor position when cursor is disabled
double virtualCursorPosX, virtualCursorPosY;
bool rawMouseMotion;
// _GLFWcontext context; // 根据_GLFWcontext的定义转换
// Callbacks are represented as IntPtr since we don't need the actual function pointers in C#
internal struct Callbacks
{
internal IntPtr pos;
internal IntPtr size;
internal IntPtr close;
internal IntPtr refresh;
internal IntPtr focus;
internal IntPtr iconify;
internal IntPtr maximize;
internal IntPtr fbsize;
internal IntPtr scale;
internal IntPtr mouseButton;
internal IntPtr cursorPos;
internal IntPtr cursorEnter;
internal IntPtr scroll;
internal IntPtr key;
internal IntPtr character;
internal IntPtr charmods;
internal IntPtr drop;
}
Callbacks callbacks;
// GLFW_PLATFORM_WINDOW_STATE platformWindowState;
}
[StructLayout(LayoutKind.Sequential)]
public struct GLFWwindowCallback
{
}
[StructLayout(LayoutKind.Sequential)]
public struct GLFWcursor
{
//GLFWcursor* next;
private IntPtr next;
// This is defined in platform.h
// not completed in tranformation
// GLFW_PLATFORM_CURSOR_STATE;
}
/*
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWerror
{
//GLFWerror* next;
IntPtr next;
int code;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)GLconst.GLFW_MESSAGE_SIZE)]
byte[] description = new byte[GLconst.GLFW_MESSAGE_SIZE];
public GLFWerror()
{
}
}
*/
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWinitconfig
{
private int angleType;
private GLFWbool hatButtons;
private int platformID;
//PFN_vkGetInstanceProcAddr vulkanLoader;
private IntPtr vulkanLoader;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWwndconfig
{
private GLFWbool autoIconify;
private GLFWbool centerCursor;
private GLFWbool decorated;
private GLFWbool floating;
private GLFWbool focused;
private GLFWbool focusOnShow;
private int height;
private GLFWbool maximized;
private GLFWbool mousePassthrough;
private GLFWbool resizable;
private GLFWbool scaleToMonitor;
private byte* title;
private GLFWbool visible;
private int width;
private int xpos;
private int ypos;
internal Ns ns = new Ns();
internal Win32 win32 = new Win32();
internal Wl wl = new Wl();
internal X11 x11 = new X11();
public GLFWwndconfig()
{
}
internal struct Ns
{
private GLFWbool retina = false;
public fixed byte frameName[256];
public Ns()
{
}
}
internal struct X11
{
public fixed byte className[256];
public fixed byte instanceName[256];
public X11()
{
}
}
internal struct Win32
{
private GLFWbool keymenu;
}
internal struct Wl
{
public fixed byte appId[256];
public Wl()
{
}
}
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWctxconfig
{
private int client;
private GLFWbool debug;
private GLFWbool forward;
private int major;
private int minor;
private GLFWbool noerror;
private int profile;
private int release;
private int robustness;
//glfwWindow* share;
private IntPtr share;
private int source;
internal Nsgl nsgl = new Nsgl();
public GLFWctxconfig()
{
}
internal struct Nsgl
{
private GLFWbool offline;
}
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWfbconfig
{
private int accumAlphaBits;
private int accumBlueBits;
private int accumGreenBits;
private int accumRedBits;
private int alphaBits;
private int auxBuffers;
private int blueBits;
private int depthBits;
private GLFWbool doublebuffer;
private int greenBits;
private uintptr_t handle;
private int redBits;
private int samples;
private GLFWbool sRGB;
private int stencilBits;
private GLFWbool stereo;
private GLFWbool transparent;
}
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct GLFWlibrary
{
private GLFWallocator allocator;
private GLFWls contextSlot;
//GLFWcursor* cursorListHead;
private IntPtr cursorListHead;
//GLFWerror* errorListHead;
private IntPtr errorListHead;
private GLFWmutex errorLock;
private GLFWls errorSlot;
private GLFWbool initialized;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = GLconst.GLFW_JOYSTICK_LAST + 1)]
private GLFWjoystick[] joysticks = new GLFWjoystick[GLconst.GLFW_JOYSTICK_LAST + 1];
private GLFWbool joysticksInitialized;
private int mappingCount;
//GLFWmapping* mappings;
private IntPtr mappings;
private int monitorCount;
//GLFWmonitor** monitors;
private IntPtr monitors;
private GLFWplatform platform;
//glfwWindow* windowListHead;
private IntPtr windowListHead;
internal Callbacks callbacks = new Callbacks();
internal Egl egl = new Egl();
internal Hints hints = new Hints();
internal Osmesa osmesa = new Osmesa();
public GLFWlibrary()
{
}
internal unsafe struct Hints
{
private GLFWctxconfig context;
private GLFWfbconfig framebuffer;
private GLFWinitconfig init;
private int refreshRate;
private GLFWwndconfig window;
}
internal unsafe struct timer
{
private ulong offset;
// This is defined in platform.h
//not transformed function defination
//GLFW_PLATFORM_LIBRARY_TIMER_STATE
}
internal unsafe struct Egl
{
internal bool ANGLE_platform_angle;
internal bool ANGLE_platform_angle_d3d;
internal bool ANGLE_platform_angle_metal;
internal bool ANGLE_platform_angle_opengl;
internal bool ANGLE_platform_angle_vulkan;
internal IntPtr BindAPI;
internal IntPtr CreateContext;
internal IntPtr CreatePlatformWindowSurfaceEXT;
internal IntPtr CreateWindowSurface;
internal IntPtr DestroyContext;
internal IntPtr DestroySurface;
internal void* display;
internal bool EXT_client_extensions;
internal bool EXT_platform_base;
internal bool EXT_platform_wayland;
internal bool EXT_platform_x11;
internal bool EXT_present_opaque;
internal IntPtr GetConfigAttrib;
internal IntPtr GetConfigs;
internal IntPtr GetDisplay;
internal IntPtr GetError;
internal IntPtr GetPlatformDisplayEXT;
internal IntPtr GetProcAddress;
internal void* handle;
internal IntPtr Initialize;
internal bool KHR_colorSpace;
internal bool KHR_context_flush_control;
internal bool KHR_create_context;
internal bool KHR_create_context_no_error;
internal bool KHR_get_all_proc_addresses;
internal int major, minor;
internal IntPtr MakeCurrent;
internal int platform;
internal bool prefix;
internal IntPtr QueryString;
internal IntPtr SwapBuffers;
internal IntPtr SwapInterval;
internal IntPtr Terminate;
}
internal unsafe struct Osmesa
{
private IntPtr CreateContextAttribs;
private IntPtr CreateContextExt;
private IntPtr DestroyContext;
private IntPtr GetColorBuffer;
private IntPtr GetDepthBuffer;
private IntPtr GetProcAddress;
private void* handle;
private IntPtr MakeCurrent;
}
internal unsafe struct vk
{
private GLFWbool available;
private GLFWbool EXT_metal_surface;
private fixed ulong extensions[2];
private IntPtr GetInstanceProcAddr;
private void* handle;
private GLFWbool KHR_surface;
private GLFWbool KHR_wayland_surface;
private GLFWbool KHR_win32_surface;
private GLFWbool KHR_xcb_surface;
private GLFWbool KHR_xlib_surface;
private GLFWbool MVK_macos_surface;
public vk()
{
}
}
internal unsafe struct Callbacks
{
private IntPtr joystick;
private IntPtr monitor;
}
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWmapelement
{
private sbyte axisOffset;
private sbyte axisScale;
private byte index;
private byte type;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWmapping
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
private GLFWmapelement[] axes = new GLFWmapelement[6];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)]
private GLFWmapelement[] buttons = new GLFWmapelement[15];
private fixed byte guid[33];
private fixed byte name[128];
public GLFWmapping()
{ }
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWjoystick
{
private GLFWbool allocated;
private float* axes;
private int axisCount;
private int buttonCount;
private byte* buttons;
private GLFWbool connected;
private fixed byte guid[33];
private int hatCount;
private byte* hats;
//GLFWmapping* mapping;
private IntPtr mapping;
private fixed byte name[128];
private void* userPointer;
// This is defined in platform.h
// not completed in transforming
// GLFW_PLATFORM_JOYSTICK_STATE;
public GLFWjoystick()
{ }
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWls
{
// This is defined in platform.h
//GLFW_PLATFORM_TLS_STATE
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWplatform
{
// init
//GLFWbool(*init)(void);
private IntPtr init;
private int platformID;
//void (* terminate) (void);
private IntPtr terminate;
internal IntPtr createCursor;
internal IntPtr createStandardCursor;
// window
internal IntPtr createWindow;
internal IntPtr destroyCursor;
internal IntPtr destroyWindow;
internal IntPtr focusWindow;
internal IntPtr framebufferTransparent;
// monitor
internal IntPtr freeMonitor;
internal IntPtr getClipboardString;
internal IntPtr getEGLNativeDisplay;
internal IntPtr getEGLNativeWindow;
// EGL
//EGLenum(*getEGLPlatform)(EGLint**);
//EGLNativeDisplayType(*getEGLNativeDisplay)(void);
//EGLNativeWindowType(*getEGLNativeWindow)(glfwWindow*);
internal IntPtr getEGLPlatform;
internal IntPtr getFramebufferSize;
internal IntPtr getGammaRamp;
internal IntPtr getKeyScancode;
internal IntPtr getMappingName;
internal IntPtr getMonitorContentScale;
internal IntPtr getMonitorPos;
internal IntPtr getMonitorWorkarea;
// vulkan
//void (* getRequiredInstanceExtensions) (byte**);
//GLFWbool(*getPhysicalDevicePresentationSupport)(VkInstance, VkPhysicalDevice, uint32_t);
//VkResult(*createWindowSurface)(VkInstance, glfwWindow*,const VkAllocationCallbacks*, VkSurfaceKHR*);
internal IntPtr getRequiredInstanceExtensions;
internal IntPtr getScancodeName;
internal IntPtr getVideoMode;
internal IntPtr getVideoModes;
internal IntPtr getWindowContentScale;
internal IntPtr getWindowFrameSize;
internal IntPtr getWindowOpacity;
internal IntPtr getWindowPos;
internal IntPtr getWindowSize;
internal IntPtr GLFWwindow;
internal IntPtr hideWindow;
internal IntPtr iconifyWindow;
internal IntPtr initJoysticks;
internal IntPtr maximizeWindow;
internal IntPtr pollEvents;
internal IntPtr pollJoystick;
internal IntPtr postEmptyEvent;
internal IntPtr rawMouseMotionSupported;
internal IntPtr requestWindowAttention;
internal IntPtr restoreWindow;
internal IntPtr setClipboardString;
internal IntPtr setCursor;
internal IntPtr setCursorMode;
#region input
/* void (* getCursorPos) (glfwWindow*, double*, double*);
void (* setCursorPos) (glfwWindow*, double, double);
void (* setCursorMode) (glfwWindow*, int);
void (* setRawMouseMotion) (glfwWindow*, GLFWbool);
GLFWbool(*rawMouseMotionSupported)(void);
GLFWbool(*createCursor)(GLFWcursor*,const GLFWimage*,int,int);
GLFWbool(*createStandardCursor)(GLFWcursor*, int);
void (* destroyCursor) (GLFWcursor*);
void (* setCursor) (glfwWindow*, GLFWcursor*);
const byte* (*getScancodeName)(int);
int (* getKeyScancode) (int);
void (* setClipboardString) (const byte*);
const byte* (*getClipboardString)(void);
GLFWbool(*initJoysticks)(void);
void (* terminateJoysticks) (void);
GLFWbool(*pollJoystick)(GLFWjoystick*, int);
const byte* (*getMappingName)(void);
void (* updateGamepadGUID) (byte*);
// monitor
void (* freeMonitor) (GLFWmonitor*);
void (* getMonitorPos) (GLFWmonitor*, int*, int*);
void (* getMonitorContentScale) (GLFWmonitor*, float*, float*);
void (* getMonitorWorkarea) (GLFWmonitor*, int*, int*, int*, int*);
glfwVideomode* (* getVideoModes) (GLFWmonitor*, int*);
void (* getVideoMode) (GLFWmonitor*, glfwVideomode*);
GLFWbool(*getGammaRamp)(GLFWmonitor*, glfwGammaramp*);
void (* setGammaRamp) (GLFWmonitor*,const glfwGammaramp*);
// window
GLFWbool(*createWindow)(glfwWindow*,const GLFWwndconfig*,const GLFWctxconfig*,const GLFWfbconfig*);
void (* destroyWindow) (glfwWindow*);
void (* setWindowTitle) (glfwWindow*,const byte*);
void (* setWindowIcon) (glfwWindow*, int,const GLFWimage*);
void (* getWindowPos) (glfwWindow*, int*, int*);
void (* setWindowPos) (glfwWindow*, int, int);
void (* getWindowSize) (glfwWindow*, int*, int*);
void (* setWindowSize) (glfwWindow*, int, int);
void (* setWindowSizeLimits) (glfwWindow*, int, int, int, int);
void (* setWindowAspectRatio) (glfwWindow*, int, int);
void (* getFramebufferSize) (glfwWindow*, int*, int*);
void (* getWindowFrameSize) (glfwWindow*, int*, int*, int*, int*);
void (* getWindowContentScale) (glfwWindow*, float*, float*);
void (* iconifyWindow) (glfwWindow*);
void (* restoreWindow) (glfwWindow*);
void (* maximizeWindow) (glfwWindow*);
void (* showWindow) (glfwWindow*);
void (* hideWindow) (glfwWindow*);
void (* requestWindowAttention) (glfwWindow*);
void (* focusWindow) (glfwWindow*);
void (* setWindowMonitor) (glfwWindow*, GLFWmonitor*, int, int, int, int, int);
GLFWbool(*windowFocused)(glfwWindow*);
GLFWbool(*windowIconified)(glfwWindow*);
GLFWbool(*windowVisible)(glfwWindow*);
GLFWbool(*windowMaximized)(glfwWindow*);
GLFWbool(*windowHovered)(glfwWindow*);
GLFWbool(*framebufferTransparent)(glfwWindow*);
float (* getWindowOpacity) (glfwWindow*);
void (* setWindowResizable) (glfwWindow*, GLFWbool);
void (* setWindowDecorated) (glfwWindow*, GLFWbool);
void (* setWindowFloating) (glfwWindow*, GLFWbool);
void (* setWindowOpacity) (glfwWindow*, float);
void (* setWindowMousePassthrough) (glfwWindow*, GLFWbool);
void (* pollEvents) (void);
void (* waitEvents) (void);
void (* waitEventsTimeout) (double);
void (* postEmptyEvent) (void);
*/
#endregion
internal IntPtr setCursorPos;
internal IntPtr setGammaRamp;
internal IntPtr setRawMouseMotion;
internal IntPtr setWindowAspectRatio;
internal IntPtr setWindowDecorated;
internal IntPtr setWindowFloating;
internal IntPtr setWindowIcon;
internal IntPtr setWindowMonitor;
internal IntPtr setWindowMousePassthrough;
internal IntPtr setWindowOpacity;
internal IntPtr setWindowPos;
internal IntPtr setWindowResizable;
internal IntPtr setWindowSize;
internal IntPtr setWindowSizeLimits;
internal IntPtr setWindowTitle;
internal IntPtr showWindow;
internal IntPtr terminateJoysticks;
internal IntPtr updateGamepadGUID;
internal IntPtr VkPhysicalDevice;
internal IntPtr waitEvents;
internal IntPtr waitEventsTimeout;
internal IntPtr windowFocused;
internal IntPtr windowHovered;
internal IntPtr windowIconified;
internal IntPtr windowMaximized;
internal IntPtr windowVisible;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWmutex
{
// This is defined in platform.h
//GLFW_PLATFORM_MUTEX_STATE
}
//public unsafe struct VkAllocationCallbacks { }
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct VkExtensionProperties
{
private fixed byte extensionName[256];
private uint specVersion;
public VkExtensionProperties()
{
}
}
/*
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct GLFWerror
{
IntPtr next;
int code;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]
byte[] description = new byte[1024];
public GLFWerror()
{
}
}
*/
[StructLayout(LayoutKind.Explicit, Size = 16)]
public struct uintptr_t
{
[FieldOffset(0)]
private long part1;
[FieldOffset(8)]
private long part2;
}
#endregion GLFW3 struct
#region glad struct
[StructLayout(LayoutKind.Sequential)]
internal struct GLsync
{
}
#endregion glad struct
}
/**/
@@ -0,0 +1,70 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glApiDefine.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
/*
* This file is created to link functions in OpenGL to version in C#
* The name of delegates and organization to init all these delegates
* are refferd from GLAD1 in agreement of MIT license generated from
* https://glad.dav1d.de/
*/
using StgSharp.Math;
using System;
using System.Numerics;
using System.Runtime.InteropServices;
namespace StgSharp.Graphics
{
#region StgSharpDele
public unsafe delegate void FrameBufferSizeHandler(IntPtr window, uint width, uint height);
#endregion
/// <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);
#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
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,210 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glEnum.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp.Graphics.GL
{
public enum ImageChannelLayout
{
UByte = GLconst.UNSIGNED_BYTE,
Byte = GLconst.BYTE,
UShort = GLconst.UNSIGNED_SHORT,
Short = GLconst.SHORT,
UInt = GLconst.UNSIGNED_INT,
Int = GLconst.INT,
Float = GLconst.FLOAT,
UByte332 = 0x8032, // GL_UNSIGNED_BYTE_3_3_2
UByte233Rev = 0x8362, // GL_UNSIGNED_BYTE_2_3_3_REV
UShort565 = 0x8363, // GL_UNSIGNED_SHORT_5_6_5
UShort565Rev = 0x8364, // GL_UNSIGNED_SHORT_5_6_5_REV
UShort4444 = 0x8033, // GL_UNSIGNED_SHORT_4_4_4_4
UShort4444Rev = 0x8034, // GL_UNSIGNED_SHORT_4_4_4_4_REV
UShort5551 = 0x8035, // GL_UNSIGNED_SHORT_5_5_5_1
UShort1555Rev = 0x8366, // GL_UNSIGNED_SHORT_1_5_5_5_REV
UInt8888 = 0x8035, // GL_UNSIGNED_INT_8_8_8_8
UInt8888Rev = 0x8367, // GL_UNSIGNED_INT_8_8_8_8_REV
UInt1010102 = 0x8036, // GL_UNSIGNED_INT_10_10_10_2
UInt2101010Rev = 0x8368 // GL_UNSIGNED_INT_2_10_10_10_REV
}
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,
VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR = 1000009000,
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,
RED = GLconst.RED,
GREEN = GLconst.GREEN,
BLUE = GLconst.BLUE,
RGB = GLconst.RGB,
BGR = GLconst.BGR,
RGBA = GLconst.RGBA,
BGRA = GLconst.BGRA
}
public enum Texture2DTarget
{
Texture2D = GLconst.TEXTURE_2D,
ProxyTexture2D = GLconst.PROXY_TEXTURE_2D,
Texture1DArray = GLconst.TEXTURE_1D_ARRAY,
ProxyTexture1DArray = GLconst.PROXY_TEXTURE_1D_ARRAY,
TextureRectangle = GLconst.TEXTURE_RECTANGLE,
ProxyTextureRectangle = GLconst.PROXY_TEXTURE_RECTANGLE,
TextureCubeMapPositiveX = GLconst.TEXTURE_CUBE_MAP_POSITIVE_X,
TextureCubeMapNegativeX = GLconst.TEXTURE_CUBE_MAP_NEGATIVE_X,
TextureCubeMapPositiveY = GLconst.TEXTURE_CUBE_MAP_POSITIVE_Y,
TextureCubeMapNegativeY = GLconst.TEXTURE_CUBE_MAP_NEGATIVE_Y,
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,
VK_EVENT_SET = 3,
VK_EVENT_RESET = 4,
VK_INCOMPLETE = 5,
VK_ERROR_OUT_OF_HOST_MEMORY = -1,
VK_ERROR_OUT_OF_DEVICE_MEMORY = -2,
VK_ERROR_INITIALIZATION_FAILED = -3,
VK_ERROR_DEVICE_LOST = -4,
VK_ERROR_MEMORY_MAP_FAILED = -5,
VK_ERROR_LAYER_NOT_PRESENT = -6,
VK_ERROR_EXTENSION_NOT_PRESENT = -7,
VK_ERROR_FEATURE_NOT_PRESENT = -8,
VK_ERROR_INCOMPATIBLE_DRIVER = -9,
VK_ERROR_TOO_MANY_OBJECTS = -10,
VK_ERROR_FORMAT_NOT_SUPPORTED = -11,
VK_ERROR_SURFACE_LOST_KHR = -1000000000,
VK_SUBOPTIMAL_KHR = 1000001003,
VK_ERROR_OUT_OF_DATE_KHR = -1000001004,
VK_ERROR_INCOMPATIBLE_DISPLAY_KHR = -1000003001,
VK_ERROR_NATIVE_WINDOW_IN_USE_KHR = -1000000001,
VK_ERROR_VALIDATION_FAILED_EXT = -1000011001,
VK_RESULT_MAX_ENUM = 0x7FFFFFFF
}
#pragma warning disable CA1008
public enum ShaderType : int
#pragma warning restore CA1008
{
Fragment = GLconst.FRAGMENT_SHADER,
Vertex = GLconst.VERTEX_SHADER,
Compute = GLconst.COMPUTE_SHADER,
Geometry = GLconst.GEOMETRY_SHADER,
}
#pragma warning disable CA1008 // 枚举应具有零值
public enum BufferType : int
#pragma warning restore CA1008 // 枚举应具有零值
{
ArrayBuffer = GLconst.ARRAY_BUFFER,
ElementArrayBuffer = GLconst.ELEMENT_ARRAY_BUFFER,
AtomicCounterBuffer = GLconst.ATOMIC_COUNTER_BUFFER,
COPY_READ_BUFFER = GLconst.COPY_READ_BUFFER,
COPY_WRITE_BUFFER = GLconst.COPY_WRITE_BUFFER,
DISPATCH_INDIRECT_BUFFER = GLconst.DISPATCH_INDIRECT_BUFFER,
DRAW_INDIRECT_BUFFER = GLconst.DRAW_INDIRECT_BUFFER,
PIXEL_PACK_BUFFER = GLconst.PIXEL_PACK_BUFFER,
PIXEL_UNPACK_BUFFER = GLconst.PIXEL_UNPACK_BUFFER,
QUERY_BUFFER = GLconst.QUERY_BUFFER,
SHADER_STORAGE_BUFFER = GLconst.SHADER_STORAGE_BUFFER,
TEXTURE_BUFFER = GLconst.TEXTURE_BUFFER,
TRANSFORM_FEEDBACK_BUFFER = GLconst.TRANSFORM_FEEDBACK_BUFFER,
UNIFORM_BUFFER = GLconst.UNIFORM_BUFFER,
}
#pragma warning disable CA1008 // 枚举应具有零值
public enum BufferUsage : int
#pragma warning restore CA1008 // 枚举应具有零值
{
StreamDraw = 0x88E0,
StreamRead = 0x88E1,
StreamCopy = 0x88E2,
StaticDraw = 0x88E4,
StaticRead = 0x88E5,
StaticCopy = 0x88E6,
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,
LINE_STRIP = 0x0003,
TRIANGLES = 0x0004,
TRIANGLE_STRIP = 0x0005,
TRIANGLE_FAN = 0x0006
}
public enum TextureFiltering
{
Nearest = 0x2600,
Linear = 0x2601
}
}
@@ -0,0 +1,117 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glType.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.Geometries;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics
{
public delegate IntPtr GLfuncLoader(string name);
internal delegate void GLVULKANPROCNV();
public unsafe struct GLhandleARB
{
dynamic value;
public unsafe GLhandleARB(dynamic value)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
if (value.GetType().Name != "Uint32")
{
goto errorlog;
}
this.value = value;
}
else
{
if (value.GetType().Name != "IntPtr")
{
goto errorlog;
}
this.value = value;
}
errorlog:
{
InternalIO.InternalWriteLog(
$"{value.GetType().Name} does not match definination of GLhandlARB on OS {Environment.OSVersion.Platform} ",
LogType.Error);
}
}
public static implicit operator uint(GLhandleARB 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 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);
public unsafe delegate void GLFWglproc();
internal unsafe delegate void FramebuffersizeHandler(IntPtr window, int width, int height); //window is the pointer to a glfwWindow instance
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
}
@@ -0,0 +1,80 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BufferObjectBase.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.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.GL
{
/// <summary>
/// Interface of all kinds OpenGL buffer objects
/// </summary>
public abstract class BufferObjectBase : IDisposable
{
protected RenderStream binding;
protected glHandleSet _bufferHandle;
/// <summary>
/// Get the only handle to one of the Object instance
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
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);
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
/// <inheritdoc/>
public override string ToString()
{
return $"This is a {GetType().FullName}, containing {_bufferHandle.length} buffer handles: {_bufferHandle.ToString()}.";
}
protected abstract void Dispose(bool disposing);
~BufferObjectBase()
{
Dispose(disposing: false);
}
}
}
@@ -0,0 +1,84 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="EBO.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.Math;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics.GL
{
/// <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.
/// </summary>
public unsafe class ElementBuffer : BufferObjectBase
{
internal ElementBuffer(int n, glRenderStream binding)
{
this.binding = binding;
_bufferHandle = glFunc.GenBuffers(n);
}
public override sealed void Bind(int index)
{
glFunc.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
}
public void SetValue<T>(int index, T[] bufferArray, BufferUsage usage)
where T : struct, IConvertible
{
glFunc.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
glFunc.SetBufferData(BufferType.ElementArrayBuffer, bufferArray, usage);
}
public void SetValue<T>(int index, ReadOnlySpan<T> bufferSpan, BufferUsage usage)
where T : struct, IConvertible
{
glFunc.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
glFunc.SetBufferData(BufferType.ElementArrayBuffer, bufferSpan, usage);
}
protected override sealed void Dispose(bool disposing)
{
if (disposing)
{
glFunc.DeleteBuffers(_bufferHandle);
_bufferHandle.Release();
}
}
}
}
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.GL
{
#pragma warning disable CA1008
#pragma warning disable CA1028
public enum FrameBufferTarget:uint
#pragma warning restore CA1028
#pragma warning restore CA1008
{
Read = GLconst.READ_FRAMEBUFFER,
All = GLconst.FRAMEBUFFER,
Draw = GLconst.DRAW_FRAMEBUFFER,
}
public class FrameBuffer : BufferObjectBase
{
internal unsafe FrameBuffer(int count, glRenderStream contextBinding)
{
binding = contextBinding;
_bufferHandle = new glHandleSet(count);
((GLcontext*)binding.ContextHandle)->glGenFramebuffers((uint)count,_bufferHandle.handle);
}
/// <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.
/// </summary>
/// <param name="index">Index of object to be binded in handle set</param>
public unsafe override void Bind(int index)
{
glFunc.BindFrameBuffer(FrameBufferTarget.All,_bufferHandle[index]);
}
public static void BindNull()
{
glFunc.BindFrameBuffer(FrameBufferTarget.All,glHandle.Zero);
}
/// <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.
/// </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>
public unsafe void Bind(FrameBufferTarget target, int index)
{
((GLcontext*)binding.ContextHandle)->glBindFramebuffer((uint)target, _bufferHandle[index].Value);
}
protected override void Dispose(bool disposing)
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Security.Principal;
using System.Text;
namespace StgSharp.Graphics.GL
{
public class RenderBuffer : BufferObjectBase
{
public RenderBuffer(int count, glRenderStream binding)
{
this.binding = binding;
_bufferHandle = glFunc.GenRenderBuffer(count);
}
public override void Bind(int index)
{
glFunc.BindRenderBuffer(this[index]);
}
protected override void Dispose(bool disposing)
{
throw new NotImplementedException();
}
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");
}
}
}
}
@@ -0,0 +1,155 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="texture.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.Math;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.GL
{
public unsafe class TextureGL
{
internal static bool[] unitActivated = new bool[16];
private IntPtr binding;
internal glHandleSet _textureHandle;
internal Image[] sourceList;
public glHandle this[int index]
{
get => _textureHandle[index];
}
internal TextureGL(int n, glRenderStream binding)
{
sourceList = new Image[n];
this.binding = binding.ContextHandle;
_textureHandle = glFunc.GenTextures(n);
}
public static void Activate(TextureUnit unit)
{
glFunc.ActiveTexture((uint)unit);
}
public void Bind2D(int index)
{
glFunc.BindTexture(GLconst.TEXTURE_2D, _textureHandle[index]);
}
/// <summary>
/// </summary>
/// <param name="index"> </param>
/// <param name="i"> </param>
public unsafe void LoadTexture(int index, Image i)
{
sourceList[index] = i;
glArrayHandle handle = sourceList[index].GetArrayHandle();
glFunc.TextureImage2d(
Texture2DTarget.Texture2D, 0, (uint)i.Channel,
(uint)sourceList[index].Width, (uint)sourceList[index].Height,
(uint)i.Channel, ImageChannelLayout.Byte,
pixelArrayHandle: handle
);
handle.Release();
}
#region texture setting
public void Set2dFilterProperty(
Filter onMinify, Filter onMagnify)
{
glFunc.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MIN_FILTER, (int)onMinify);
glFunc.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MAG_FILTER, (int)onMagnify);
}
public void Set2dWrapProperty(
Wrap onHorizontial, Wrap onVertical)
{
glFunc.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_S, (int)onHorizontial);
glFunc.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_T, (int)onVertical);
}
#endregion texture setting
}
#pragma warning disable CA1008
public enum Filter
#pragma warning restore CA1008
{
Nearest = GLconst.NEAREST,
Linear = GLconst.LINEAR,
NearestLinearMipmap = GLconst.NEAREST_MIPMAP_LINEAR,
LinearLinearMipmap = GLconst.LINEAR_MIPMAP_LINEAR,
NearestNearestMipmap = GLconst.NEAREST_MIPMAP_NEAREST,
LinearNearestMipmap = GLconst.LINEAR_MIPMAP_NEAREST,
}
#pragma warning disable CA1008
public enum TextureUnit
#pragma warning restore CA1008
{
Unit0 = GLconst.TEXTURE0,
Unit1 = GLconst.TEXTURE1,
Unit2 = GLconst.TEXTURE2,
Unit3 = GLconst.TEXTURE3,
Unit4 = GLconst.TEXTURE4,
Unit5 = GLconst.TEXTURE5,
Unit6 = GLconst.TEXTURE6,
Unit7 = GLconst.TEXTURE7,
Unit8 = GLconst.TEXTURE8,
Unit9 = GLconst.TEXTURE9,
Unit10 = GLconst.TEXTURE10,
Unit11 = GLconst.TEXTURE11,
Unit12 = GLconst.TEXTURE12,
Unit13 = GLconst.TEXTURE13,
Unit14 = GLconst.TEXTURE14,
Unit15 = GLconst.TEXTURE15,
}
#pragma warning disable CA1008
public enum Wrap
#pragma warning restore CA1008
{
Repeat = GLconst.REPEAT,
MirroredRepeat = GLconst.MIRRORED_REPEAT,
ClampToEdge = GLconst.CLAMP_TO_EDGE,
ClampToBorder = GLconst.CLAMP_TO_BORDER,
}
}
@@ -0,0 +1,80 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="VAO.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.Runtime.CompilerServices;
using System.Text;
namespace StgSharp.Graphics.GL
{
public unsafe class VertexArray : BufferObjectBase
{
internal VertexArray(int n, glRenderStream binding)
{
this.binding = binding;
_bufferHandle = glFunc.GenVertexArrays(n);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override sealed void Bind(int index)
{
glFunc.BindVertexArray(_bufferHandle[index]);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindNull()
{
glFunc.BindVertexArray(glHandle.Zero);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SetVertexAttribute(uint index, int vertexLength, TypeCode dataType, bool isNomalized, uint stride, int pointer)
{
glFunc.SetVertexAttribute(
index, vertexLength, dataType,
isNomalized,
stride, pointer);
}
protected override sealed void Dispose(bool disposing)
{
if (disposing)
{
glFunc.DeleteVertexArrays(_bufferHandle);
_bufferHandle.Release();
}
}
}
}
@@ -0,0 +1,155 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="VBO.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics.GL;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Net.Security;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics.GL
{
public unsafe class VertexBuffer : BufferObjectBase
{
internal VertexBuffer(int n, glRenderStream binding)
{
this.binding = binding;
_bufferHandle = glFunc.GenBuffers(n);
}
public override sealed void Bind(int index)
{
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
}
/// <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
{
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
glFunc.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,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
{
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
glFunc.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,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
{
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
glFunc.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
{
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
glFunc.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
{
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
glFunc.SetBufferVectorData(BufferType.ArrayBuffer, vectorArray, usage);
}
/// <summary>
///
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Unbind()
{
glFunc.BindBuffer(BufferType.ArrayBuffer, glHandle.Zero);
}
protected override sealed void Dispose(bool disposing)
{
if (disposing)
{
glFunc.DeleteBuffers(_bufferHandle);
_bufferHandle.Release();
}
}
}
}
@@ -0,0 +1,362 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GLhandle.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.Data.Common;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.AccessControl;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
/// <summary>
/// A handle to an OpenGL object,
/// must be indexed from a <see cref="glHandleSet"/>.
/// Direct call will cause <see langword="InvalidOperationException"/>
/// </summary>
public unsafe class glHandle: IDisposable
{
private static uint* zeroHandle = (uint*)Marshal.AllocHGlobal(Marshal.SizeOf<uint>());
internal uint* source;
internal uint* valuePtr;
private glHandle(IntPtr handle)
{
this.valuePtr = (uint*)handle;
source = (uint*)0;
}
private glHandle(uint value)
{
source = (uint*)0;
valuePtr = (uint*)Marshal.AllocHGlobal(sizeof(uint));
*valuePtr = value;
}
internal glHandle(uint* val, glHandleSet set)
{
source = set!=null ? set!.handle:(uint*)0;
valuePtr = val;
}
[Obsolete("Cannot init instance of this type", true)]
public glHandle()
{
}
public IntPtr Handle
{
get=> (IntPtr)valuePtr;
}
public bool IsIsolated
{
get => source == (uint*)0;
}
public uint Value
{
get => *valuePtr;
set => *valuePtr = value;
}
public static glHandle ZeroHandle => FromPtr(IntPtr.Zero);
public static glHandle Zero => Alloc(0);
public static glHandle Alloc(uint value)
{
return new glHandle(value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static glHandle FromPtr(IntPtr p)
{
return new glHandle(p);
}
~glHandle()
{
if (valuePtr != zeroHandle && IsIsolated)
{
Marshal.FreeHGlobal((IntPtr)valuePtr);
}
}
protected virtual void Dispose(bool disposing)
{
if (IsIsolated)
{
GCHandle.FromIntPtr((IntPtr)valuePtr).Free();
if (disposing)
{
}
}
}
//
// ~glHandle()
// {
// Dispose(disposing: false);
// }
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
public unsafe class glSHandle
{
private static int* zeroHandle = (int*)Marshal.AllocHGlobal(Marshal.SizeOf<int>());
internal int* source;
internal int* valuePtr;
private glSHandle(IntPtr handle)
{
this.valuePtr = (int*)handle;
source = (int*)0;
}
private glSHandle(int value)
{
source = (int*)0;
valuePtr = (int*)Marshal.AllocHGlobal(sizeof(int));
*valuePtr = value;
}
internal glSHandle(int* val, glHandleSet set)
{
source = set != null ? (int*)set!.handle : (int*)0;
valuePtr = val;
}
[Obsolete("Cannot init instance of this type", true)]
public glSHandle()
{
}
public IntPtr Handle
{
get => (IntPtr)valuePtr;
}
public bool IsIsolated
{
get => source == (uint*)0;
}
public int Value
{
get => *valuePtr;
set => *valuePtr = value;
}
public static glSHandle Zero => Alloc(0);
public static glSHandle Alloc(int value)
{
return new glSHandle(value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static glSHandle FromPtr(IntPtr p)
{
return new glSHandle(p);
}
~glSHandle()
{
if (valuePtr != zeroHandle && IsIsolated)
{
Marshal.FreeHGlobal((IntPtr)valuePtr);
}
}
}
public unsafe class glArrayHandle
{
internal readonly Array a;
internal GCHandle handle;
private bool disposedValue;
internal glArrayHandle(Array array)
{
this.a = array;
handle = GCHandle.Alloc(array, GCHandleType.Pinned);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IntPtr AddressOfArray()
{
if (handle != default)
{
return handle.AddrOfPinnedObject();
}
else
{
throw new InvalidOperationException();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static glArrayHandle Alloc<T>(T[] array) where T : struct
{
return new glArrayHandle(array);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static glArrayHandle CopyAlloc<T>(T[] array) where T : struct
{
Array copy = new T[array.Length];
array.CopyTo(copy, 0);
return new glArrayHandle(copy);
}
public void Release()
{
handle.Free();
handle = default;
}
}
/// <summary>
/// A handle to an OpenGL object.
/// </summary>
public unsafe class glHandleSet
{
private readonly uint[] _value;
internal uint* handle;
internal int length;
public glHandleSet(int count)
{
_value = new uint[count];
length = count;
handle = (uint*)GCHandle.Alloc(_value, GCHandleType.Pinned).AddrOfPinnedObject();
}
public IntPtr Handle
{
get => (IntPtr)handle;
}
public glHandle this[int index]
{
get
{
if (index > length)
{
throw new IndexOutOfRangeException();
}
return new glHandle(handle + index, this);
}
}
public glSHandle this[uint index]
{
get
{
if (index > length)
{
throw new IndexOutOfRangeException();
}
return new glSHandle(((int*)handle) + index, this);
}
}
public static void Copy(in glHandleSet source, glHandleSet target)
{
if ((source == null) || (target == null))
{
throw new NullReferenceException();
}
if (source.length != target.length)
{
throw new Exception($"Lengths of {nameof(source)} and {nameof(target)} are not equal.");
}
for (int i = 0; i < source.length; i++)
{
target._value[i] = source._value[i];
}
}
public void Pin()
{
if (_value == null)
{
return;
}
handle = (uint*)GCHandle.Alloc(_value, GCHandleType.Pinned).AddrOfPinnedObject();
}
/// <summary>
/// Release all resource in this handle.
/// This will release all resource in this <see cref="glHandle"/>.
/// This <see langword="glHandle"/> will be not usable.
/// </summary>
public void Release()
{
if (_value == null)
{
return;
}
else
{
GCHandle.FromIntPtr((IntPtr)handle).Free();
handle = (uint*)IntPtr.Zero;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetValue(int index, uint value)
{
_value[index] = value;
}
~glHandleSet()
{
}
}
}
@@ -0,0 +1,622 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GLpack.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics;
using StgSharp.Logic;
using StgSharp.Math;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp
{
internal static unsafe partial class InternalIO
{
[DllImport(SSC_libName, EntryPoint = "glCheckShaderStat",
CallingConvention = CallingConvention.Cdecl)]
#pragma warning disable CA5392
internal static extern int glCheckShaderStatus(ref GLcontext context, uint shaderHandle, int key, ref IntPtr logPtr);
#pragma warning restore CA5392
}
}
namespace StgSharp.Graphics.GL
{
internal static unsafe partial class glFunc
{
private static GLcontext* context;
public static IntPtr CurrentContextHandle
{
get { return (IntPtr)context; }
set { context = (GLcontext*)value; }
}
private static ref GLcontext Context
{
get
{
#if DEBUG
if ((IntPtr)context==IntPtr.Zero)
{
throw new NullReferenceException();
}
#endif
return ref (*context);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ActiveTexture(uint type)
{
Context.glActiveTexture(type);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AttachShader(glHandle program, glHandle shader)
{
Context.glAttachShader(program.Value, shader.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindBuffer(BufferType bufferType, glHandle handle)
{
Context.glBindBuffer((uint)bufferType, handle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void GetTextureImage<T>(Texture2DTarget target, int level, ImageChannel channel, ImageChannelLayout channelLayout, ref T[] dataStream)where T: struct,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
{
#pragma warning disable CS8500
fixed (T* tptr = dataStream)
{
Context.glGetTexImage((uint)target, level, (uint)channel, (uint)channelLayout, tptr);
}
#pragma warning restore CS8500
}
/// <summary>
/// Bind a frame buffer to a frame buffer target
/// Same function as <see href="https://docs.gl/gl3/glBindFramebuffer">glBindFramebuffer</see>.
/// </summary>
/// <param name="target"> The frame buffer target of the binding operation.</param>
/// <param name="handle"> The handle of the frame buffer object to bind.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindFrameBuffer(FrameBufferTarget target, glHandle handle)
{
Context.glBindFramebuffer((uint)target, handle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindRenderBuffer(glHandle handle)
{
Context.glBindRenderbuffer(GLconst.RENDERBUFFER, handle.Value);
}
public static void WaitAccomplishment()
{
Context.glFinish();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindTexture(uint type, glHandle texture)
{
Context.glBindTexture(type, texture.Value);
}
public static unsafe int GetMaskInteger(uint statusCode)
{
int ret = 0;
Context.glGetIntegerv(statusCode,&ret);
return ret;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindVertexArray(glHandle handle)
{
Context.glBindVertexArray(handle.Value);
}
public static void RereadImage(
this Image i, (int X, int Y) beginPosition, FrameBufferChannel format, ImageChannelLayout dataType)
{
glArrayHandle handle = i.GetArrayHandle();
Context.glReadPixels(
beginPosition.X, beginPosition.Y, i.Width, i.Height, (uint)format, (uint)dataType, (byte*)handle.AddressOfArray()
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void FrameBufferTexture2d(FrameBufferTarget target, uint attachment, Texture2DTarget texTarget,glHandle textureHandle ,int level)
{
Context.glFramebufferTexture2D(
(uint)target, attachment, (uint)texTarget,textureHandle.Value, level
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ReadPixels(
(int X, int Y) beginPosition, (int width, int height) size, FrameBufferChannel format, ImageChannelLayout dataType, ref byte[] stream
)
{
fixed (byte* bptr = stream)
{
Context.glReadPixels(
beginPosition.X, beginPosition.Y,
size.width, size.height, (uint)format, (uint)dataType, bptr);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Clear(MaskBufferBit mask)
{
Context.glClear((uint)mask);
}
public static void CombineFrameBufferRenderBuffer(glHandle fboHandle, glHandle rboHandle)
{
Context.glFramebufferRenderbuffer(GLconst.FRAMEBUFFER,fboHandle.Value,GLconst.RENDERBUFFER, rboHandle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void ClearColor(float R, float G, float B, float A)
{
Context.glClearColor(R, G, B, A);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void ClearGraphicError()
{
while (Context.glGetError() != 0) { }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void CompileShader(glHandle shaderhandle)
{
Context.glCompileShader(shaderhandle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe glHandle CreateGraphicProgram()
{
return glHandle.Alloc(Context.glCreateProgram());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static glHandle CreateProgram()
{
return glHandle.Alloc(Context.glCreateProgram());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe glHandleSet CreateProgram(int count)
{
glHandleSet h = new glHandleSet(count);
for (int i = 0; i < count; i++)
{
h.SetValue(i, Context.glCreateProgram());
}
return h;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static glHandleSet CreateShaderSet(int count, ShaderType type)
{
glHandleSet ret = new glHandleSet(count);
uint t = (uint)type;
for (int i = 0; i < count; i++)
{
uint id = Context.glCreateShader(t);
if (id == 0)
{
uint error = Context.glGetError();
InternalIO.InternalWriteLog($"Failed in creating shader: {error}", LogType.Error);
throw new Exception();
}
ret.SetValue(i, id);
}
return ret;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void DeleteBuffer(glHandle handle)
{
Context.glDeleteBuffers(1, (uint*)handle.Handle);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void DeleteBuffers(glHandleSet handle)
{
Context.glDeleteBuffers(handle.length, (uint*)handle.Handle);
handle.Release();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void DeleteVertexArrays(glHandleSet arrays)
{
Context.glDeleteVertexArrays(arrays.length, (uint*)arrays.Handle);
arrays.Release();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void DrawElements(GeometryType mode, uint count, TypeCode type, IntPtr ptr)
{
uint a;
switch (type)
{
case TypeCode.UInt32:
a = GLconst.UNSIGNED_INT;
break;
case TypeCode.UInt16:
a = GLconst.UNSIGNED_SHORT;
break;
case TypeCode.Byte:
a = GLconst.UNSIGNED_BYTE;
break;
default:
InternalIO.InternalWriteLog(
$"{$"Parameter error in parameter {nameof(type)} method DrawElements. "}{$"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are supported."}",
LogType.Error);
return;
}
Context.glDrawElements((uint)mode, count, a, (void*)ptr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void DrawElementsInstanced(
GeometryType mode, uint count, TypeCode type, IntPtr ptr, uint amount
)
{
uint a;
switch (type)
{
case TypeCode.UInt32:
a = GLconst.UNSIGNED_INT;
break;
case TypeCode.UInt16:
a = GLconst.UNSIGNED_SHORT;
break;
case TypeCode.Byte:
a = GLconst.UNSIGNED_BYTE;
break;
default:
InternalIO.InternalWriteLog(
$"{$"Parameter error in parameter {nameof(type)} method DrawElements. "}{$"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are supported."}",
LogType.Error);
return;
}
Context.glDrawElementsInstanced((uint)mode, count, a, (void*)ptr, amount);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Enable(GLOperation operation)
{
Context.glEnable((uint)operation);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe glHandleSet GenBuffers(int count)
{
glHandleSet h = new glHandleSet(count);
Context.glGenBuffers(count, (uint*)h.Handle);
return h;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe glHandleSet GenRenderBuffer(int count)
{
glHandleSet h = new glHandleSet(count);
Context.glGenRenderbuffers(count, (uint*)h.Handle);
return h;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe glHandleSet GenTextures(int count)
{
glHandleSet h = new glHandleSet(count);
Context.glGenTextures(count, (uint*)h.Handle);
return h;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetRenderBufferStorage(RenderBufferInternalFormat internalFormat ,(int width, int height) size)
{
Context.glRenderbufferStorage(
GLconst.RENDERBUFFER, (uint)internalFormat,size.width,size.height
);
}
public static unsafe glHandleSet GenVertexArrays(int count)
{
glHandleSet h = new glHandleSet(count);
Context.glGenVertexArrays(count, (uint*)h.Handle);
return h;
}
public static string GetShaderStatus(Shader s, int index, int key)
{
IntPtr sptr = IntPtr.Zero;
if (InternalIO.glCheckShaderStatus(ref Context, s.handle[index].Value, key, ref sptr) == 0)
{
return Marshal.PtrToStringAnsi(sptr);
}
return string.Empty;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe glSHandle GetUniformLocation(glHandle program, string name)
{
byte[] code = Encoding.UTF8.GetBytes(name);
fixed (byte* ptr = code)
{
int ret = Context.glGetUniformLocation(program.Value, ptr);
#if DEBUG
if (ret == (int)(GLconst.INVALID_OPERATION) ||
ret == (int)(GLconst.INVALID_VALUE))
{
throw new InvalidOperationException();
}
if (ret == -1 )
{
throw new UniformEmptyReferenceException(nameof(program), name);
}
#endif
return glSHandle.Alloc(ret);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void LoadShaderSource(glHandle shaderHandle, byte[] codeStream)
{
fixed (byte* streamPtr = codeStream)
{
Context.glShaderSource(shaderHandle.Value, 1, &streamPtr, (void*)0);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
where T : struct
{
int size = Marshal.SizeOf<T>();
#pragma warning disable CS8500
T* p = &bufferData;
#pragma warning restore CS8500
Context.glBufferData(
(uint)bufferType,
(IntPtr)size,
(IntPtr)p,
(uint)usage);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
where T : struct,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
{
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
if (bufferArray == null)
{
return;
}
#pragma warning disable CS8500
fixed (void* bufferPtr = bufferArray)
#pragma warning restore CS8500
{
Context.glBufferData(
(uint)bufferType,
(IntPtr)size,
(IntPtr)bufferPtr,
(uint)usage);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetBufferData<T>(BufferType bufferType, ReadOnlySpan<T> bufferArray, BufferUsage usage)
where T : struct,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
{
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
if (bufferArray == null)
{
return;
}
#pragma warning disable CS8500
fixed (void* bufferPtr = bufferArray)
#pragma warning restore CS8500
{
Context.glBufferData(
(uint)bufferType,
(IntPtr)size,
(IntPtr)bufferPtr,
(uint)usage);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetBufferData<T>(BufferType bufferType, Span<T> bufferArray, BufferUsage usage)
where T : struct,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
{
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
if (bufferArray == null)
{
return;
}
#pragma warning disable CS8500
fixed (void* bufferPtr = &bufferArray.GetPinnableReference())
#pragma warning restore CS8500
{
Context.glBufferData(
(uint)bufferType,
(IntPtr)size,
(IntPtr)bufferPtr,
(uint)usage);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetBufferVectorData<T>(BufferType bufferType, ReadOnlySpan<T> bufferArray, BufferUsage usage)
where T : struct, IVector
{
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
if (bufferArray == null)
{
return;
}
#pragma warning disable CS8500
fixed (void* bufferPtr = &bufferArray.GetPinnableReference())
#pragma warning restore CS8500
{
Context.glBufferData(
(uint)bufferType,
(IntPtr)size,
(IntPtr)bufferPtr,
(uint)usage);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetBufferVectorData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
where T : struct, IVector
{
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
if (bufferArray == null)
{
return;
}
#pragma warning disable CS8500
fixed (void* bufferPtr = bufferArray)
#pragma warning restore CS8500
{
Context.glBufferData(
(uint)bufferType,
(IntPtr)size,
(IntPtr)bufferPtr,
(uint)usage);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SetVertexAttribute(uint index, int size, TypeCode t, bool normalized, uint stride, int pointer)
{
uint type = InternalIO.GLtype[t];
Context.glVertexAttribPointer(index, size, type, normalized ? 1 : 0, stride, (void*)pointer);
Context.glEnableVertexAttribArray(index);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void TextureImage2d(Texture2DTarget target, int level, uint internalformat, uint width, uint height,
uint format, ImageChannelLayout type, glHandle pixels)
{
Context.glTexImage2D(
(uint)target, level, internalformat, width, height, 0, format, (uint)type, pixels.valuePtr
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void TextureImage2d(Texture2DTarget target, int level, uint internalformat, uint width, uint height,
uint format, ImageChannelLayout type, glArrayHandle pixelArrayHandle)
{
Context.glTexImage2D(
(uint)target, level, internalformat, width, height, 0, format, (uint)type, (void*)pixelArrayHandle.handle.AddrOfPinnedObject()
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void TextureParameter(int target, uint pname, int param)
{
Context.glTexParameteri((uint)target, pname, param);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void UseProgram(glHandle program)
{
Context.glUseProgram(program.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void VertexAttributeDivisor(uint layoutIndex, uint divisor)
{
Context.glVertexAttribDivisor(layoutIndex, divisor);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Viewport(int x, int y, uint width, uint height)
{
Context.glViewport(x, y, width, height);
}
}
}
@@ -0,0 +1,102 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GLresourceGenrator.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.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.GL
{
public partial class glRenderStream
{
/// <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 RenderBuffer CreateRenderBuffer(int count)
{
return new RenderBuffer(count, this);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected FrameBuffer CreateFrameBuffer(int count)
{
return new FrameBuffer(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);
}
}
}
@@ -0,0 +1,35 @@
using StgSharp.Graphics.GL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.ShaderEdit
{
public interface IglConvertable
{
/// <summary>
///
/// </summary>
public void SetAllUniforms();
/// <summary>
///
/// </summary>
public void GainAllUniforms(ShaderProgram source, params string[] uniformName);
/// <summary>
///
/// </summary>
public void DisplayGLtypeDefinition();
/// <summary>
///
/// </summary>
/// <returns></returns>
public ShaderStruct GetConvertedGLtype();
}
}
@@ -0,0 +1,264 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Shader.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.Data;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Xml.Linq;
namespace StgSharp.Graphics.GL
{
public abstract partial class glRenderStream : RenderStream
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected sealed override Shader CreateShaderSegment(ShaderType type, int count)
{
return new Shader( glFunc.CreateShaderSet(count, type), type);
}
/// <summary>
/// Create an instance of <see cref="Shader"/> program
/// </summary>
/// <returns>New instance of <see cref="Shader"/> instance. </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected sealed override ShaderProgram CreateShaderProgram()
{
return new ShaderProgram(this);
}
}
public class Shader : ISSDSerializable
{
private readonly IntPtr context;
internal readonly glHandleSet handle;
public readonly ShaderType type;
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.Shader;
internal unsafe Shader(glHandleSet handle, ShaderType usage)
{
this.handle = handle;
context = glFunc.CurrentContextHandle;
type = usage;
}
/// <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)
{
glFunc.AttachShader(target.handle, handle[index]);
}
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}");
}
return Encoding.UTF8.GetBytes(str);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Compile(int index, byte[] codeStream)
{
if (codeStream == null)
{
throw new ArgumentNullException(nameof(codeStream));
}
glFunc.LoadShaderSource(handle[index], codeStream);
glFunc.CompileShader(handle[index]);
CheckStatus(index,ShaderStatus.CompileStatus);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Compile(int index, string codeStream)
{
if (codeStream == null)
{
throw new ArgumentNullException(nameof(codeStream));
}
glFunc.LoadShaderSource(handle[index],Encoding.ASCII.GetBytes( codeStream));
glFunc.CompileShader(handle[index]);
CheckStatus(index, ShaderStatus.CompileStatus);
}
public override string ToString()
{
return $"This is a {type} shader, its shader handles are {handle.ToString()}.";
}
public byte[] GetBytes()
{
return Array.Empty<byte>();
}
public void CheckStatus(int index, ShaderStatus status)
{
string log = glFunc.GetShaderStatus(this,index, (int)status);
if (!string.IsNullOrEmpty(log))
{
throw new Exception($"Shader Error \t{status}\n" + log);
}
}
public byte[] GetBytes(out int length)
{
throw new NotImplementedException();
}
public void FromBytes(byte[] stream)
{
throw new NotImplementedException();
}
}
public enum ShaderStatus : int
{
CompileStatus = GLconst.COMPILE_STATUS,
}
public class ShaderProgram
{
private readonly IntPtr binding;
internal readonly glHandle handle;
/// <summary>
/// Init a program with no shader attached.
/// </summary>
internal unsafe ShaderProgram(glRenderStream binding)
{
this.binding = binding.ContextHandle;
handle = glFunc.CreateProgram();
}
/// <summary>
/// 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>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe Uniform<T> GetUniform<T>(string name) where T : struct
{
return new Uniform<T>(this, name, binding);
}
/// <summary>
/// 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>
/// <returns></returns>
public unsafe Uniform<T, U> GetUniform<T, U>(string name)
where T : struct
where U : struct
{
return new Uniform<T, U>(this, name, binding);
}
/// <summary>
/// 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>
/// <returns></returns>
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>(this, name);
}
/// <summary>
/// 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>
/// <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
{
return new Uniform<T, U, V, W>(this, name);
}
/// <summary>
/// Link the shader to current context.
/// </summary>
public unsafe void Link()
{
if (InternalIO.InternalLinkShaderProgram((GLcontext*)this.binding, handle.Value) == 0)
{
IntPtr logPtr = InternalIO.InternalReadSSCLog();
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);
}
catch (Exception ex)
{
InternalIO.InternalWriteLog(ex.Message, LogType.Error);
}
}
}
/// <summary>
/// Let the current context use this shader.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Use()
{
glFunc.UseProgram(handle);
}
~ShaderProgram()
{
//handle.Dispose();
}
}
}
@@ -0,0 +1,257 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Uniform.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics.GL
{
public class Uniform
{
protected IntPtr binding;
internal glSHandle id;
public glSHandle Handle
{
get => id;
}
}
public sealed class Uniform<T> : Uniform
where T : struct
{
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
internal unsafe Uniform(
ShaderProgram program, string name, glRenderStream binding)
{
this.binding = binding.ContextHandle;
id = glFunc.GetUniformLocation(program.handle, name);
}
internal unsafe Uniform(
ShaderProgram program, string name, IntPtr binding)
{
this.binding = binding;
id = glFunc.GetUniformLocation(program.handle, name);
}
internal Uniform()
{
}
internal static Uniform<T> FromHandle(glSHandle handle)
{
return new Uniform<T>() { id = handle };
}
}
public sealed class Uniform<T, U>: Uniform
where T : struct
where U : struct
{
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
internal unsafe Uniform(
ShaderProgram program, string name, glRenderStream binding)
{
this.binding = binding.ContextHandle;
id = glFunc.GetUniformLocation(program.handle, name);
}
internal unsafe Uniform(
ShaderProgram program, string name, IntPtr binding)
{
this.binding = binding;
id = glFunc.GetUniformLocation(program.handle, name);
}
internal Uniform()
{
}
internal static Uniform<T,U> FromHandle(glSHandle 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
{
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
internal unsafe Uniform(
ShaderProgram program, string name)
{
this.binding = glFunc.CurrentContextHandle;
id = glFunc.GetUniformLocation(program.handle, name);
}
public unsafe Uniform(ShaderProgram program, string name, glRenderStream binding)
{
this.binding = binding.ContextHandle;
id = glFunc.GetUniformLocation(program.handle, name);
}
internal Uniform()
{
}
internal static Uniform<T,U,V> FromHandle(glSHandle 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
{
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
internal unsafe Uniform(ShaderProgram program, string name, glRenderStream binding)
{
this.binding = binding.ContextHandle;
id = glFunc.GetUniformLocation(program.handle, name);
}
internal unsafe Uniform(
ShaderProgram program, string name)
{
this.binding = glFunc.CurrentContextHandle;
id = glFunc.GetUniformLocation(program.handle, name);
}
internal Uniform()
{
}
internal static Uniform<T, U, V, W> FromHandle(glSHandle handle)
{
return new Uniform<T, U, V, W>() { id = handle };
}
}
internal static partial class glFunc
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe static void SetUniformValue
(Uniform<Matrix44> uniform, Matrix44 mat)
{
Matrix44 temp = mat;
Context.glUniformMatrix4fv(uniform.id.Value, 1, false, (float*)&temp);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe static void SetUniformValue(Uniform<float, float, float, float> uniform, vec4d vec)
{
vec4d temp = vec;
Context.glUniform1fv(uniform.id.Value , 4, &temp);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe static void SetUniformValue(Uniform<vec4d> uniform, vec4d vec)
{
vec4d temp = vec;
Context.glUniform1fv(uniform.id.Value , 4, &temp);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetUniformValue(Uniform<float> uniform, float v0)
{
Context.glUniform1f(uniform.id.Value , v0);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetUniformValue(Uniform<int> uniform, int i0)
{
Context.glUniform1i(uniform.id.Value , i0);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetUniformValue(Uniform<float, float> uniform, float v0, float v1)
{
Context.glUniform2f(uniform.id.Value , v0, v1);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetUniformValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
{
Context.glUniform3f(uniform.id.Value , v0, v1, v2);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetUniformValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
{
Context.glUniform4f(uniform.id.Value , v0, v1, v2, v3);
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,689 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glApiManagerConst.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.Text;
namespace StgSharp.Graphics.GL
{
public static partial class glManager
{
#region coreVersion
private static bool core10 = false;
private static bool core11 = false;
private static bool core12 = false;
private static bool core13 = false;
private static bool core14 = false;
private static bool core15 = false;
private static bool core20 = false;
private static bool core21 = false;
private static bool core30 = false;
private static bool core31 = false;
private static bool core32 = false;
private static bool core33 = false;
private static bool core40 = false;
private static bool core41 = false;
private static bool core42 = false;
private static bool core43 = false;
private static bool core44 = false;
private static bool core45 = false;
private static bool core46 = false;
#endregion
#region extension
private static bool _3DFX_tbuffer;
private static bool _3DFX_texture_compression_FXT1;
private static bool _4DFX_multisample;
private static bool AMD_blend_minmax_factor;
private static bool AMD_conservative_depth;
private static bool AMD_debug_output;
private static bool AMD_depth_clamp_separate;
private static bool AMD_draw_buffers_blend;
private static bool AMD_framebuffer_multisample_advanced;
private static bool AMD_framebuffer_sample_positions;
private static bool AMD_gcn_shader;
private static bool AMD_gpu_shader_half_float;
private static bool AMD_gpu_shader_int16;
private static bool AMD_gpu_shader_int64;
private static bool AMD_interleaved_elements;
private static bool AMD_multi_draw_indirect;
private static bool AMD_name_gen_delete;
private static bool AMD_occlusion_query_event;
private static bool AMD_performance_monitor;
private static bool AMD_pinned_memory;
private static bool AMD_query_buffer_object;
private static bool AMD_sample_positions;
private static bool AMD_seamless_cubemap_per_texture;
private static bool AMD_shader_atomic_counter_ops;
private static bool AMD_shader_ballot;
private static bool AMD_shader_explicit_vertex_parameter;
private static bool AMD_shader_gpu_shader_half_float_fetch;
private static bool AMD_shader_image_load_store_lod;
private static bool AMD_shader_stencil_export;
private static bool AMD_shader_trinary_minmax;
private static bool AMD_sparse_texture;
private static bool AMD_stencil_operation_extended;
private static bool AMD_texture_gather_bias_lod;
private static bool AMD_texture_texture4;
private static bool AMD_transform_feedback3_lines_triangles;
private static bool AMD_transform_feedback4;
private static bool AMD_vertex_shader_layer;
private static bool AMD_vertex_shader_tessellator;
private static bool AMD_vertex_shader_viewport_index;
private static bool APPLE_aux_depth_stencil;
private static bool APPLE_client_storage;
private static bool APPLE_element_array;
private static bool APPLE_fence;
private static bool APPLE_float_pixels;
private static bool APPLE_flush_buffer_range;
private static bool APPLE_object_purgeable;
private static bool APPLE_rgb_422;
private static bool APPLE_row_bytes;
private static bool APPLE_specular_vector;
private static bool APPLE_texture_range;
private static bool APPLE_transform_hint;
private static bool APPLE_vertex_array_object;
private static bool APPLE_vertex_array_range;
private static bool APPLE_vertex_program_evaluators;
private static bool APPLE_ycbcr_422;
private static bool ARB_arrays_of_arrays;
private static bool ARB_base_instance;
private static bool ARB_bindless_texture;
private static bool ARB_blend_func_extended;
private static bool ARB_buffer_storage;
private static bool ARB_cl_event;
private static bool ARB_clear_buffer_object;
private static bool ARB_clear_texture;
private static bool ARB_clip_control;
private static bool ARB_color_buffer_float;
private static bool ARB_compatibility;
private static bool ARB_compressed_texture_pixel_storage;
private static bool ARB_compute_shader;
private static bool ARB_compute_variable_group_size;
private static bool ARB_conditional_render_inverted;
private static bool ARB_conservative_depth;
private static bool ARB_copy_buffer;
private static bool ARB_copy_image;
private static bool ARB_cull_distance;
private static bool ARB_debug_output;
private static bool ARB_depth_buffer_float;
private static bool ARB_depth_clamp;
private static bool ARB_depth_texture;
private static bool ARB_derivative_control;
private static bool ARB_direct_state_access;
private static bool ARB_draw_buffers;
private static bool ARB_draw_buffers_blend;
private static bool ARB_draw_elements_base_vertex;
private static bool ARB_draw_indirect;
private static bool ARB_draw_instanced;
private static bool ARB_enhanced_layouts;
private static bool ARB_ES2_compatibility;
private static bool ARB_ES3_1_compatibility;
private static bool ARB_ES3_2_compatibility;
private static bool ARB_ES3_compatibility;
private static bool ARB_explicit_attrib_location;
private static bool ARB_explicit_uniform_location;
private static bool ARB_fragment_coord_conventions;
private static bool ARB_fragment_layer_viewport;
private static bool ARB_fragment_program;
private static bool ARB_fragment_program_shadow;
private static bool ARB_fragment_shader;
private static bool ARB_fragment_shader_interlock;
private static bool ARB_framebuffer_no_attachments;
private static bool ARB_framebuffer_object;
private static bool ARB_framebuffer_sRGB;
private static bool ARB_geometry_shader4;
private static bool ARB_get_program_binary;
private static bool ARB_get_texture_sub_image;
private static bool ARB_gl_spirv;
private static bool ARB_gpu_shader_fp64;
private static bool ARB_gpu_shader_int64;
private static bool ARB_gpu_shader5;
private static bool ARB_half_float_pixel;
private static bool ARB_half_float_vertex;
private static bool ARB_imaging;
private static bool ARB_indirect_parameters;
private static bool ARB_instanced_arrays;
private static bool ARB_internalformat_query;
private static bool ARB_internalformat_query2;
private static bool ARB_invalidate_subdata;
private static bool ARB_map_buffer_alignment;
private static bool ARB_map_buffer_range;
private static bool ARB_matrix_palette;
private static bool ARB_multi_bind;
private static bool ARB_multi_draw_indirect;
private static bool ARB_multisample;
private static bool ARB_multitexture;
private static bool ARB_occlusion_query;
private static bool ARB_occlusion_query2;
private static bool ARB_parallel_shader_compile;
private static bool ARB_pipeline_statistics_query;
private static bool ARB_pixel_buffer_object;
private static bool ARB_point_parameters;
private static bool ARB_point_sprite;
private static bool ARB_polygon_offset_clamp;
private static bool ARB_post_depth_coverage;
private static bool ARB_program_interface_query;
private static bool ARB_provoking_vertex;
private static bool ARB_query_buffer_object;
private static bool ARB_robust_buffer_access_behavior;
private static bool ARB_robustness;
private static bool ARB_robustness_isolation;
private static bool ARB_sample_locations;
private static bool ARB_sample_shading;
private static bool ARB_sampler_objects;
private static bool ARB_seamless_cube_map;
private static bool ARB_seamless_cubemap_per_texture;
private static bool ARB_separate_shader_objects;
private static bool ARB_shader_atomic_counter_ops;
private static bool ARB_shader_atomic_counters;
private static bool ARB_shader_ballot;
private static bool ARB_shader_bit_encoding;
private static bool ARB_shader_clock;
private static bool ARB_shader_draw_parameters;
private static bool ARB_shader_group_vote;
private static bool ARB_shader_image_load_store;
private static bool ARB_shader_image_size;
private static bool ARB_shader_objects;
private static bool ARB_shader_precision;
private static bool ARB_shader_stencil_export;
private static bool ARB_shader_storage_buffer_object;
private static bool ARB_shader_subroutine;
private static bool ARB_shader_texture_image_samples;
private static bool ARB_shader_texture_lod;
private static bool ARB_shader_viewport_layer_array;
private static bool ARB_shading_language_100;
private static bool ARB_shading_language_420pack;
private static bool ARB_shading_language_include;
private static bool ARB_shading_language_packing;
private static bool ARB_shadow;
private static bool ARB_shadow_ambient;
private static bool ARB_sparse_buffer;
private static bool ARB_sparse_texture;
private static bool ARB_sparse_texture_clamp;
private static bool ARB_sparse_texture2;
private static bool ARB_spirv_extensions;
private static bool ARB_stencil_texturing;
private static bool ARB_sync;
private static bool ARB_tessellation_shader;
private static bool ARB_texture_barrier;
private static bool ARB_texture_border_clamp;
private static bool ARB_texture_buffer_object;
private static bool ARB_texture_buffer_object_rgb32;
private static bool ARB_texture_buffer_range;
private static bool ARB_texture_compression;
private static bool ARB_texture_compression_bptc;
private static bool ARB_texture_compression_rgtc;
private static bool ARB_texture_cube_map;
private static bool ARB_texture_cube_map_array;
private static bool ARB_texture_env_add;
private static bool ARB_texture_env_combine;
private static bool ARB_texture_env_crossbar;
private static bool ARB_texture_env_dot3;
private static bool ARB_texture_filter_anisotropic;
private static bool ARB_texture_filter_minmax;
private static bool ARB_texture_float;
private static bool ARB_texture_gather;
private static bool ARB_texture_mirror_clamp_to_edge;
private static bool ARB_texture_mirrored_repeat;
private static bool ARB_texture_multisample;
private static bool ARB_texture_non_power_of_two;
private static bool ARB_texture_query_levels;
private static bool ARB_texture_query_lod;
private static bool ARB_texture_rectangle;
private static bool ARB_texture_rg;
private static bool ARB_texture_rgb10_a2ui;
private static bool ARB_texture_stencil8;
private static bool ARB_texture_storage;
private static bool ARB_texture_storage_multisample;
private static bool ARB_texture_swizzle;
private static bool ARB_texture_view;
private static bool ARB_timer_query;
private static bool ARB_transform_feedback_instanced;
private static bool ARB_transform_feedback_overflow_query;
private static bool ARB_transform_feedback2;
private static bool ARB_transform_feedback3;
private static bool ARB_transpose_matrix;
private static bool ARB_uniform_buffer_object;
private static bool ARB_vertex_array_bgra;
private static bool ARB_vertex_array_object;
private static bool ARB_vertex_attrib_64bit;
private static bool ARB_vertex_attrib_binding;
private static bool ARB_vertex_blend;
private static bool ARB_vertex_buffer_object;
private static bool ARB_vertex_program;
private static bool ARB_vertex_shader;
private static bool ARB_vertex_type_10f_11f_11f_rev;
private static bool ARB_vertex_type_2_10_10_10_rev;
private static bool ARB_viewport_array;
private static bool ARB_window_pos;
private static bool ATI_draw_buffers;
private static bool ATI_element_array;
private static bool ATI_envmap_bumpmap;
private static bool ATI_fragment_shader;
private static bool ATI_map_object_buffer;
private static bool ATI_meminfo;
private static bool ATI_pixel_format_float;
private static bool ATI_pn_triangles;
private static bool ATI_separate_stencil;
private static bool ATI_text_fragment_shader;
private static bool ATI_texture_env_combine3;
private static bool ATI_texture_float;
private static bool ATI_texture_mirror_once;
private static bool ATI_vertex_array_object;
private static bool ATI_vertex_attrib_array_object;
private static bool ATI_vertex_streams;
private static bool EXT_422_pixels;
private static bool EXT_abgr;
private static bool EXT_bgra;
private static bool EXT_bindable_uniform;
private static bool EXT_blend_color;
private static bool EXT_blend_equation_separate;
private static bool EXT_blend_func_separate;
private static bool EXT_blend_logic_op;
private static bool EXT_blend_minmax;
private static bool EXT_blend_subtract;
private static bool EXT_clip_volume_hint;
private static bool EXT_cmyka;
private static bool EXT_color_subtable;
private static bool EXT_compiled_vertex_array;
private static bool EXT_convolution;
private static bool EXT_coordinate_frame;
private static bool EXT_copy_texture;
private static bool EXT_cull_vertex;
private static bool EXT_debug_label;
private static bool EXT_debug_marker;
private static bool EXT_depth_bounds_test;
private static bool EXT_direct_state_access;
private static bool EXT_draw_buffers2;
private static bool EXT_draw_instanced;
private static bool EXT_draw_range_elements;
private static bool EXT_EGL_image_storage;
private static bool EXT_EGL_sync;
private static bool EXT_external_buffer;
private static bool EXT_fog_coord;
private static bool EXT_framebuffer_blit;
private static bool EXT_framebuffer_blit_layers;
private static bool EXT_framebuffer_multisample;
private static bool EXT_framebuffer_multisample_blit_scaled;
private static bool EXT_framebuffer_object;
private static bool EXT_framebuffer_sRGB;
private static bool EXT_geometry_shader4;
private static bool EXT_gpu_program_parameters;
private static bool EXT_gpu_shader4;
private static bool EXT_histogram;
private static bool EXT_index_array_formats;
private static bool EXT_index_func;
private static bool EXT_index_material;
private static bool EXT_index_texture;
private static bool EXT_light_texture;
private static bool EXT_memory_object;
private static bool EXT_memory_object_fd;
private static bool EXT_memory_object_win32;
private static bool EXT_misc_attribute;
private static bool EXT_multi_draw_arrays;
private static bool EXT_multisample;
private static bool EXT_multiview_tessellation_geometry_shader;
private static bool EXT_multiview_texture_multisample;
private static bool EXT_multiview_timer_query;
private static bool EXT_packed_depth_stencil;
private static bool EXT_packed_float;
private static bool EXT_packed_pixels;
private static bool EXT_paletted_texture;
private static bool EXT_pixel_buffer_object;
private static bool EXT_pixel_transform;
private static bool EXT_pixel_transform_color_table;
private static bool EXT_point_parameters;
private static bool EXT_polygon_offset;
private static bool EXT_polygon_offset_clamp;
private static bool EXT_post_depth_coverage;
private static bool EXT_provoking_vertex;
private static bool EXT_raster_multisample;
private static bool EXT_rescale_normal;
private static bool EXT_secondary_color;
private static bool EXT_semaphore;
private static bool EXT_semaphore_fd;
private static bool EXT_semaphore_win32;
private static bool EXT_separate_shader_objects;
private static bool EXT_separate_specular_color;
private static bool EXT_shader_framebuffer_fetch;
private static bool EXT_shader_framebuffer_fetch_non_coherent;
private static bool EXT_shader_image_load_formatted;
private static bool EXT_shader_image_load_store;
private static bool EXT_shader_integer_mix;
private static bool EXT_shader_samples_identical;
private static bool EXT_shadow_funcs;
private static bool EXT_shared_texture_palette;
private static bool EXT_sparse_texture2;
private static bool EXT_stencil_clear_tag;
private static bool EXT_stencil_two_side;
private static bool EXT_stencil_wrap;
private static bool EXT_subtexture;
private static bool EXT_texture;
private static bool EXT_texture_array;
private static bool EXT_texture_buffer_object;
private static bool EXT_texture_compression_latc;
private static bool EXT_texture_compression_rgtc;
private static bool EXT_texture_compression_s3tc;
private static bool EXT_texture_cube_map;
private static bool EXT_texture_env_add;
private static bool EXT_texture_env_combine;
private static bool EXT_texture_env_dot3;
private static bool EXT_texture_filter_anisotropic;
private static bool EXT_texture_filter_minmax;
private static bool EXT_texture_integer;
private static bool EXT_texture_lod_bias;
private static bool EXT_texture_mirror_clamp;
private static bool EXT_texture_object;
private static bool EXT_texture_perturb_normal;
private static bool EXT_texture_shadow_lod;
private static bool EXT_texture_shared_exponent;
private static bool EXT_texture_snorm;
private static bool EXT_texture_sRGB;
private static bool EXT_texture_sRGB_decode;
private static bool EXT_texture_sRGB_R8;
private static bool EXT_texture_sRGB_RG8;
private static bool EXT_texture_storage;
private static bool EXT_texture_swizzle;
private static bool EXT_texture3D;
private static bool EXT_timer_query;
private static bool EXT_transform_feedback;
private static bool EXT_vertex_array;
private static bool EXT_vertex_array_bgra;
private static bool EXT_vertex_attrib_64bit;
private static bool EXT_vertex_shader;
private static bool EXT_vertex_weighting;
private static bool EXT_win32_keyed_mutex;
private static bool EXT_window_rectangles;
private static bool EXT_x11_sync_object;
private static bool GREMEDY_frame_terminator;
private static bool GREMEDY_string_marker;
private static bool HP_convolution_border_modes;
private static bool HP_image_transform;
private static bool HP_occlusion_test;
private static bool HP_texture_lighting;
private static bool IBM_cull_vertex;
private static bool IBM_multimode_draw_arrays;
private static bool IBM_rasterpos_clip;
private static bool IBM_static_data;
private static bool IBM_texture_mirrored_repeat;
private static bool IBM_vertex_array_lists;
private static bool INGR_blend_func_separate;
private static bool INGR_color_clamp;
private static bool INGR_interlace_read;
private static bool INTEL_blackhole_render;
private static bool INTEL_conservative_rasterization;
private static bool INTEL_fragment_shader_ordering;
private static bool INTEL_framebuffer_CMAA;
private static bool INTEL_map_texture;
private static bool INTEL_parallel_arrays;
private static bool INTEL_performance_query;
private static bool KHR_blend_equation_advanced;
private static bool KHR_blend_equation_advanced_coherent;
private static bool KHR_context_flush_control;
private static bool KHR_debug;
private static bool KHR_no_error;
private static bool KHR_parallel_shader_compile;
private static bool KHR_robust_buffer_access_behavior;
private static bool KHR_robustness;
private static bool KHR_shader_subgroup;
private static bool KHR_texture_compression_astc_hdr;
private static bool KHR_texture_compression_astc_ldr;
private static bool KHR_texture_compression_astc_sliced_3d;
private static bool MESA_framebuffer_flip_x;
private static bool MESA_framebuffer_flip_y;
private static bool MESA_framebuffer_swap_xy;
private static bool MESA_pack_invert;
private static bool MESA_program_binary_formats;
private static bool MESA_resize_buffers;
private static bool MESA_shader_integer_functions;
private static bool MESA_tile_raster_order;
private static bool MESA_window_pos;
private static bool MESA_ycbcr_texture;
private static bool MESAX_texture_stack;
private static bool NV_alpha_to_coverage_dither_control;
private static bool NV_bindless_multi_draw_indirect;
private static bool NV_bindless_multi_draw_indirect_count;
private static bool NV_bindless_texture;
private static bool NV_blend_equation_advanced;
private static bool NV_blend_equation_advanced_coherent;
private static bool NV_blend_minmax_factor;
private static bool NV_blend_square;
private static bool NV_clip_space_w_scaling;
private static bool NV_command_list;
private static bool NV_compute_program5;
private static bool NV_compute_shader_derivatives;
private static bool NV_conditional_render;
private static bool NV_conservative_raster;
private static bool NV_conservative_raster_dilate;
private static bool NV_conservative_raster_pre_snap;
private static bool NV_conservative_raster_pre_snap_triangles;
private static bool NV_conservative_raster_underestimation;
private static bool NV_copy_depth_to_color;
private static bool NV_copy_image;
private static bool NV_deep_texture3D;
private static bool NV_depth_buffer_float;
private static bool NV_depth_clamp;
private static bool NV_draw_texture;
private static bool NV_draw_vulkan_image;
private static bool NV_evaluators;
private static bool NV_explicit_multisample;
private static bool NV_fence;
private static bool NV_fill_rectangle;
private static bool NV_float_buffer;
private static bool NV_fog_distance;
private static bool NV_fragment_coverage_to_color;
private static bool NV_fragment_program;
private static bool NV_fragment_program_option;
private static bool NV_fragment_program2;
private static bool NV_fragment_program4;
private static bool NV_fragment_shader_barycentric;
private static bool NV_fragment_shader_interlock;
private static bool NV_framebuffer_mixed_samples;
private static bool NV_framebuffer_multisample_coverage;
private static bool NV_geometry_program4;
private static bool NV_geometry_shader_passthrough;
private static bool NV_geometry_shader4;
private static bool NV_gpu_multicast;
private static bool NV_gpu_program4;
private static bool NV_gpu_program5;
private static bool NV_gpu_program5_mem_extended;
private static bool NV_gpu_shader5;
private static bool NV_half_float;
private static bool NV_internalformat_sample_query;
private static bool NV_light_max_exponent;
private static bool NV_memory_attachment;
private static bool NV_memory_object_sparse;
private static bool NV_mesh_shader;
private static bool NV_multisample_coverage;
private static bool NV_multisample_filter_hint;
private static bool NV_occlusion_query;
private static bool NV_packed_depth_stencil;
private static bool NV_parameter_buffer_object;
private static bool NV_parameter_buffer_object2;
private static bool NV_path_rendering;
private static bool NV_path_rendering_shared_edge;
private static bool NV_pixel_data_range;
private static bool NV_point_sprite;
private static bool NV_present_video;
private static bool NV_primitive_restart;
private static bool NV_primitive_shading_rate;
private static bool NV_query_resource;
private static bool NV_query_resource_tag;
private static bool NV_register_combiners;
private static bool NV_register_combiners2;
private static bool NV_representative_fragment_test;
private static bool NV_robustness_video_memory_purge;
private static bool NV_sample_locations;
private static bool NV_sample_mask_override_coverage;
private static bool NV_scissor_exclusive;
private static bool NV_shader_atomic_counters;
private static bool NV_shader_atomic_float;
private static bool NV_shader_atomic_float64;
private static bool NV_shader_atomic_fp16_vector;
private static bool NV_shader_atomic_int64;
private static bool NV_shader_buffer_load;
private static bool NV_shader_buffer_store;
private static bool NV_shader_storage_buffer_object;
private static bool NV_shader_subgroup_partitioned;
private static bool NV_shader_texture_footprint;
private static bool NV_shader_thread_group;
private static bool NV_shader_thread_shuffle;
private static bool NV_shading_rate_image;
private static bool NV_stereo_view_rendering;
private static bool NV_tessellation_program5;
private static bool NV_texgen_emboss;
private static bool NV_texgen_reflection;
private static bool NV_texture_barrier;
private static bool NV_texture_compression_vtc;
private static bool NV_texture_env_combine4;
private static bool NV_texture_expand_normal;
private static bool NV_texture_multisample;
private static bool NV_texture_rectangle;
private static bool NV_texture_rectangle_compressed;
private static bool NV_texture_shader;
private static bool NV_texture_shader2;
private static bool NV_texture_shader3;
private static bool NV_timeline_semaphore;
private static bool NV_transform_feedback;
private static bool NV_transform_feedback2;
private static bool NV_uniform_buffer_std430_layout;
private static bool NV_uniform_buffer_unified_memory;
private static bool NV_vdpau_interop;
private static bool NV_vdpau_interop2;
private static bool NV_vertex_array_range;
private static bool NV_vertex_array_range2;
private static bool NV_vertex_attrib_integer_64bit;
private static bool NV_vertex_buffer_unified_memory;
private static bool NV_vertex_program;
private static bool NV_vertex_program1_1;
private static bool NV_vertex_program2;
private static bool NV_vertex_program2_option;
private static bool NV_vertex_program3;
private static bool NV_vertex_program4;
private static bool NV_video_capture;
private static bool NV_viewport_array2;
private static bool NV_viewport_swizzle;
private static bool NVX_blend_equation_advanced_multi_draw_buffers;
private static bool NVX_conditional_render;
private static bool NVX_gpu_memory_info;
private static bool NVX_gpu_multicast2;
private static bool NVX_linked_gpu_multicast;
private static bool NVX_progress_fence;
private static bool OES_byte_coordinates;
private static bool OES_compressed_paletted_texture;
private static bool OES_fixed_point;
private static bool OES_query_matrix;
private static bool OES_read_format;
private static bool OES_single_precision;
private static bool OML_interlace;
private static bool OML_resample;
private static bool OML_subsample;
private static bool OVR_multiview;
private static bool OVR_multiview2;
private static bool PGI_misc_hints;
private static bool PGI_vertex_hints;
private static bool REND_screen_coordinates;
private static bool S3_s3tc;
private static bool SGI_color_matrix;
private static bool SGI_color_table;
private static bool SGI_texture_color_table;
private static bool SGIS_detail_texture;
private static bool SGIS_fog_function;
private static bool SGIS_generate_mipmap;
private static bool SGIS_multisample;
private static bool SGIS_pixel_texture;
private static bool SGIS_point_line_texgen;
private static bool SGIS_point_parameters;
private static bool SGIS_sharpen_texture;
private static bool SGIS_texture_border_clamp;
private static bool SGIS_texture_color_mask;
private static bool SGIS_texture_edge_clamp;
private static bool SGIS_texture_filter4;
private static bool SGIS_texture_lod;
private static bool SGIS_texture_select;
private static bool SGIS_texture4D;
private static bool SGIX_async;
private static bool SGIX_async_histogram;
private static bool SGIX_async_pixel;
private static bool SGIX_blend_alpha_minmax;
private static bool SGIX_calligraphic_fragment;
private static bool SGIX_clipmap;
private static bool SGIX_convolution_accuracy;
private static bool SGIX_depth_pass_instrument;
private static bool SGIX_depth_texture;
private static bool SGIX_flush_raster;
private static bool SGIX_fog_offset;
private static bool SGIX_fragment_lighting;
private static bool SGIX_framezoom;
private static bool SGIX_igloo_interface;
private static bool SGIX_instruments;
private static bool SGIX_interlace;
private static bool SGIX_ir_instrument1;
private static bool SGIX_list_priority;
private static bool SGIX_pixel_texture;
private static bool SGIX_pixel_tiles;
private static bool SGIX_polynomial_ffd;
private static bool SGIX_reference_plane;
private static bool SGIX_resample;
private static bool SGIX_scalebias_hint;
private static bool SGIX_shadow;
private static bool SGIX_shadow_ambient;
private static bool SGIX_sprite;
private static bool SGIX_subsample;
private static bool SGIX_tag_sample_buffer;
private static bool SGIX_texture_add_env;
private static bool SGIX_texture_coordinate_clamp;
private static bool SGIX_texture_lod_bias;
private static bool SGIX_texture_multi_buffer;
private static bool SGIX_texture_scale_bias;
private static bool SGIX_vertex_preclip;
private static bool SGIX_ycrcb;
private static bool SGIX_ycrcb_subsample;
private static bool SGIX_ycrcba;
private static bool SUN_convolution_border_modes;
private static bool SUN_global_alpha;
private static bool SUN_mesh_array;
private static bool SUN_slice_accum;
private static bool SUN_triangle_list;
private static bool SUN_vertex;
private static bool SUNX_constant_data;
private static bool WIN_phong_shading;
private static bool WIN_specular_fog;
#endregion
}
}
@@ -0,0 +1,155 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glRenderStream.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Logic;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.GL
{
public abstract partial class glRenderStream : RenderStream
{
protected glRenderStream(ViewPort v, (int,int,int) cube) : base(v,cube)
{
}
protected IntPtr glContextHandle
{
get { return ContextHandle; }
}
/// <summary>
/// Init an OpenGl context if current form has not been binded to any context. and set the context binded to
/// current form as current OpenGL context.
/// </summary>
/// <exception cref="Exception">
/// Something goes wrong and StgSharp fails in creating a new OpenGL context.
/// </exception>
public unsafe void MakeAsCurrentContext()
{
if (ContextHandle == default)
{
ContextHandle = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GLcontext)));
GLcontext* contextID = (GLcontext*)ContextHandle;
contextID->glGetString = (delegate*<uint, IntPtr>)IntPtr.Zero;
}
if (glFunc.CurrentContextHandle != ContextHandle)
{
glFunc.CurrentContextHandle = ContextHandle;
//Console.WriteLine($"context set as {(ulong)glFunc.CurrentContextHandle}");
InternalIO.glfwMakeContextCurrent(CanvasHandle);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
{
InternalIO.glfwSetWindowSizeLimits(this.CanvasHandle, minWidth, minHeight, maxWidth, maxHeight);
}
internal override sealed void InternalDraw(
in Dictionary<string, BlueprintPipeline> input,
in Dictionary<string, BlueprintPipeline> output)
{
MakeAsCurrentContext();
ProcessInput();
Main(in input, in output);
}
internal override sealed void InternalInit()
{
MakeAsCurrentContext();
this.Port.LoadGLapi();
Init();
}
internal override sealed void InternalTerminate()
{
Deinit();
}
protected override sealed Uniform<Matrix44> NativeCameraUniform(ShaderProgram source, string name)
{
NativeCamera.GainAllUniforms(source, name);
return NativeCamera.convertedUniform;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override sealed void NativeCameraViewRange(Radius fieldOfRange, vec2d offset, (float frontDepth, float backDepth) viewDepth)
{
NativeCamera.SetViewRange(fieldOfRange, this.Size, offset, viewDepth);
}
protected override sealed void NativeCameraViewTarget(vec3d position, vec3d direction, vec3d up)
{
NativeCamera.SetViewDirection(position, direction, up);
}
protected static void PollEvents()
{
InternalIO.glfwPollEvents();
}
protected void SwapBuffers()
{
InternalIO.glfwSwapBuffers(CanvasHandle);
}
#region Key Control
protected KeyStatus CheckKey(KeyboardKey key)
{
return InternalIO.glfwGetKey(this.CanvasHandle, (int)key);
}
protected KeyStatus CheckKey(Mouse key)
{
return InternalIO.glfwGetKey(this.CanvasHandle, (int)key);
}
protected KeyStatus CheckKey(Joystick key)
{
return InternalIO.glfwGetKey(this.CanvasHandle, (int)key);
}
#endregion
}
}
+255
View File
@@ -0,0 +1,255 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Image.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Data;
using StgSharp.Graphics.GL;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public class Image : ISSDSerializable, IImageProvider
{
internal byte[] data;
internal ImageInfo info;
internal Image(ImageInfo information)
{
info = information;
data = Array.Empty<byte>();
//int length = info.width * info.height * info.channel;
}
public ref byte[] DataStream
{
get => ref data;
}
public unsafe Image()
{
info = new ImageInfo();
}
public ImageChannel Channel => info.Channel;
public int ChannelCount => info.ChannelCount;
public int Height => info.Height;
public (int width, int height) Size
{
get => (info.Width, info.Height);
}
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
public int Width => info.Width;
public static unsafe Image FromFile(string route, ImageLoader loader)
{
Image ret = new Image();
fixed (ImageInfo* iptr = &ret.info)
{
InternalIO.InternalLoadImage(route, iptr, loader);
}
return ret;
}
public static Image FromMemory((int width, int height) size, int channelCount, byte[] stream)
{
ImageInfo _info = new ImageInfo
{
Height = size.height,
Width = size.width,
ChannelCount = channelCount,
StreamPtr = IntPtr.Zero
};
Image ret = new Image(_info);
ret.data = stream;
return ret;
}
public glArrayHandle GetArrayHandle()
{
if ((data == Array.Empty<byte>()) || (data == null))
{
this.GetBytes();
return new glArrayHandle(data);
}
return new glArrayHandle(data);
}
public unsafe byte[] GetBytes()
{
if (data == null)
{
int size = Width * Height * ChannelCount;
data = new byte[size];
int i = 0;
fixed (byte* bptr = data)
{
byte* pptr = bptr;
for (; i < size; i += 16)
{
*(M128*)(pptr + i) = *(M128*)(info.StreamPtr + i);
}
for (; i < size; i++)
{
*(pptr + i) = *(byte*)(info.StreamPtr + i);
}
}
fixed (ImageInfo* pptr = &info)
{
InternalIO.InternalUnloadImage(pptr);
}
info.StreamPtr = IntPtr.Zero;
}
return data;
}
public void FromBytes(byte[] stream)
{
}
public Image ProvideImage()
{
throw new NotImplementedException();
}
~Image()
{
if (info.StreamPtr != IntPtr.Zero)
{
// Marshal.FreeHGlobal(info.StreamPtr);
}
}
}
[StructLayout(LayoutKind.Sequential)]
internal struct ImageInfo
{
private ImageChannel channel;
private int channelCount;
private int height;
private int width;
private IntPtr pixelPtr;
public ImageChannel Channel
{
get => channel;
set
{
channel = value;
switch (channel)
{
case ImageChannel.SingleColor:
channelCount = 1; break;
case ImageChannel.DoubleColor:
channelCount = 2; break;
case ImageChannel.FullColor:
channelCount = 3; break;
case ImageChannel.WithAlphaChannel:
channelCount = 4; break;
default:
throw new InvalidCastException("Unknown color channel decoding setting.");
}
}
}
public int ChannelCount
{
get => channelCount;
set
{
channelCount = value;
switch (channelCount)
{
case 1:
channel = ImageChannel.SingleColor; break;
case 2:
channel = ImageChannel.DoubleColor; break;
case 3:
channel = ImageChannel.FullColor; break;
case 4:
channel = ImageChannel.WithAlphaChannel; break;
default:
throw new InvalidCastException("Unknown color channel decoding setting.");
}
}
}
public int Height
{
get => height;
set => height = value;
}
public IntPtr StreamPtr
{
get => pixelPtr;
internal set => pixelPtr = value;
}
public int StreamSize
{
get => width * height * channelCount;
}
public int Width
{
get => width;
set => width = value;
}
public override string ToString()
{
return $"{channel}\t{width}\t{height}\t{(ulong)StreamPtr}";
}
}
public enum ImageChannel : uint
{
SingleColor = GLconst.RED,
DoubleColor = GLconst.RG,
FullColor = GLconst.RGB,
WithAlphaChannel = GLconst.RGBA,
}
}
@@ -0,0 +1,57 @@
using StgSharp.Geometries;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StgSharp.Graphics
{
public class PlainGeometryMesh
{
private PlainGeometry _shape;
private Image _texture;
private vec4d[] textureCoord;
public PlainGeometryMesh(
PlainGeometry shape, Image texture, vec4d[] texCoord
)
{
if (shape==null)
{
throw new ArgumentNullException(nameof(shape));
}
if (texCoord == null)
{
throw new ArgumentNullException(nameof(texCoord));
}
_shape = shape;
_texture = texture;
if (shape.VertexCount > texCoord.Length)
{
throw new ArgumentException(paramName: nameof(texCoord), message: "Amount of texture coordination is too less");
}
textureCoord = texCoord;
return;
}
public PlainGeometryMesh Resize(PlainGeometry newShape)
{
return new PlainGeometryMesh(newShape, _texture, textureCoord);
}
public ReadOnlySpan<int> MeshIndices => _shape.VertexIndices;
public vec4d[] VertexArray => _shape.VertexStream;
public Image TextureImage
{
get => _texture;
internal set => _texture = value;
}
public vec4d[] TextureCoord => textureCoord;
}
}
@@ -0,0 +1,270 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="RenderStream.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics.GL;
using StgSharp.Logic;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public abstract class RenderStream : IConvertableToBlueprintNode
{
private ViewPort primeArgs;
private protected (int x, int y, int z) _coordStretch;
private Camera nativeCamera;
public ViewPort Port => primeArgs;
internal IntPtr CanvasHandle { get => primeArgs.ViewPortID; }
internal IntPtr ContextHandle
{
get => primeArgs.GraphicHandle;
private protected set => primeArgs.GraphicHandle = value;
}
private IntPtr monitor;
private IntPtr sharedCanvas;
internal TimeSpanProvider timeProvider;
/*
protected RenderStream(View v, bool isSharing)
{
if (v == null)
{
throw new ArgumentNullException(nameof(v));
}
if (isSharing)
{
primeArgs = v;
}
else
{
View? newArgs = args.Clone() as View;
primeArgs = newArgs;
}
monitor = args.Monitor;
_coordStretch = args.UnitCubeSize;
NativeCamera = new Camera();
}
/**/
public RenderStream(ViewPort v, (int,int,int) unitCubeSize)
{
if (v == null)
{
throw new ArgumentNullException(nameof(v));
}
primeArgs = v;
monitor = v!.Monitor;
_coordStretch = unitCubeSize;
NativeCamera = new Camera();
}
public FrameBufferSizeHandler FrameSizeCallback
{
set
{
IntPtr handlerPtr = Marshal.GetFunctionPointerForDelegate(value);
InternalIO.glfwSetFramebufferSizeCallback(CanvasHandle, handlerPtr);
}
}
public vec2d GlobalCoordSize => ((Width * 1.0f) / _coordStretch.x, (Height * 1.0f) / _coordStretch.y);
public int Height
{
get => primeArgs.Height;
internal set
{
primeArgs.Height = value;
InternalIO.glfwSetWindowSize(this.CanvasHandle, Width, Height);
}
}
public IntPtr Monitor
{
get => monitor;
internal set => monitor = value;
}
public string Name
{
get => primeArgs.Name;
}
public IntPtr SharedCanvas
{
get => sharedCanvas;
internal set => sharedCanvas = value;
}
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 int Width
{
get => primeArgs.Width;
internal set
{
primeArgs.Width = value;
InternalIO.glfwSetWindowSize(this.CanvasHandle, Width, Height);
}
}
protected internal Camera NativeCamera
{
get => nativeCamera;
internal set => nativeCamera = value;
}
protected int Frames
{
get => timeProvider.CurrentSpan;
}
protected abstract string[] InputPortsName { get; }
protected abstract string[] OutputPortsName { get; }
protected float TimePassed
{
get => timeProvider.CurrentSpan;
}
protected TimeSpanProvider TimeProvider
{
get => timeProvider;
}
/// <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);
public static TTarget ShareContextWith<TSource, TTarget>(TSource source)
where TSource : RenderStream
where TTarget : RenderStream
{
TTarget target = Activator.CreateInstance(typeof(TTarget), source.primeArgs, source._coordStretch) as TTarget;
if (target == null)
{
throw new InvalidOperationException(
$"Failed in creating a new {typeof(TTarget).Name} instance when calling ShareContextWith."
);
}
target.timeProvider = source.timeProvider;
target.Init();
return target;
}
string[] IConvertableToBlueprintNode.InputInterfacesName => InputPortsName;
BlueprintNodeAction IConvertableToBlueprintNode.MainExecution => InternalDraw;
string[] IConvertableToBlueprintNode.OutputInterfacesName => OutputPortsName;
#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);
/// <summary>
/// Get <see cref="Uniform{T}"/>(T 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>
/// <returns>
/// <see cref="Uniform{T}"/>(T is <see cref="Matrix44"/>) representing
/// projection matrix in shader program.
/// </returns>
protected abstract Uniform<Matrix44> NativeCameraUniform(ShaderProgram source, string name);
#endregion
#region internal operation
internal abstract void InternalDraw(
in Dictionary<string, BlueprintPipeline> input,
in Dictionary<string, BlueprintPipeline> output);
internal abstract void InternalInit();
internal abstract void InternalTerminate();
#endregion
#region public operation
protected abstract void Deinit();
protected abstract void Init();
protected abstract void Main(
in Dictionary<string, BlueprintPipeline> input,
in Dictionary<string, BlueprintPipeline> output);
protected abstract void ProcessInput();
#endregion
#region public resource generator
protected abstract Shader CreateShaderSegment(ShaderType type, int count);
protected abstract ShaderProgram CreateShaderProgram();
#endregion
}
}
@@ -0,0 +1,188 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ShaderGenerator.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics;
using StgSharp.Graphics.GL;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.ShaderEdit
{
public class ShaderGenerator
{
private Dictionary<int,ShaderParameter> uniformDefine;
private List<string> codeList;
private List<ShaderFunction> usedShaderFunctions;
public Uniform<T> DefineUniform<T>(string name, int index) where T : struct
{
ShaderParameter p = new ShaderParameter(name,ShaderParameter.TypeMarshal<T>());
uniformDefine.Add(index,p);
//return new Uniform<T>();
throw new NotImplementedException();
}
}
public class ShaderFunction
{
private List<string> codeList;
private List<ShaderParameter> inputList;
private string name;
private ShaderParameter outPut;
public int ParameterCount => inputList.Count;
public void EmitCall(ShaderFunction function, ShaderParameter outPut, params ShaderParameter[] inputParams)
{
if (inputParams.Length != function.ParameterCount)
{
// Param list length not equal
throw new ArgumentException("Provided parameters does not match function's parameter list.");
}
if (!ShaderParameter.IsSameType(outPut, function.outPut))
{
// Type of returning value not qual
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]))
{
// Input type not match
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)
{
codeLine += $"{outPut.name} = ";
}
codeLine += $"{function.name}(";
foreach (ShaderParameter inputParam in inputParams)
{
codeLine += inputParam.name;
}
codeLine += ");\n";
codeList.Add(codeLine);
}
}
public class ShaderParameter
{
public static readonly ShaderParameter Void = new ShaderParameter(string.Empty, InternalShaderType.Void);
internal readonly bool isReadOnly;
internal readonly string name;
internal readonly InternalShaderType type;
public ShaderParameter(string name, InternalShaderType type)
{
this.name = name;
this.type = type;
isReadOnly = false;
}
public static bool IsSameType(ShaderParameter param1, ShaderParameter param2)
{
if (param1.type != InternalShaderType.Struct)
{
return param1.type == param2.type;
}
else
{
throw new Exception("Struct is currently not supported.");
}
}
public static InternalShaderType TypeMarshal<T>() where T : struct
{
switch (Type.GetTypeCode(typeof(T)))
{
case TypeCode.Single:
return InternalShaderType.Float;
case TypeCode.Double:
return InternalShaderType.Double;
case TypeCode.Int32:
return InternalShaderType.Int;
case TypeCode.UInt32:
return InternalShaderType.UInt;
default:
break;
}
switch (typeof(T).Name)
{
case "vec4d":
return InternalShaderType.Vector4;
case "Matrix2x2":
return InternalShaderType.Matrix2x2;
case "Matrix2x3":
return InternalShaderType.Matrix2x3;
case "Matrix2x4":
return InternalShaderType.Matrix2x4;
case "Matrix3x2":
return InternalShaderType.Matrix3x2;
case "Matrix3x3":
return InternalShaderType.Matrix3x3;
case "Matrix3x4":
return InternalShaderType.Matrix3x4;
case "Matrix4x2":
return InternalShaderType.Matrix4x2;
case "Matrix4x3":
return InternalShaderType.Matrix4x3;
case "Matrix4x4":
return InternalShaderType.Matrix4x4;
default:
throw new ArgumentException("Not supported shader data type.");
}
}
}
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,
#pragma warning restore CS1591
}
}
@@ -0,0 +1,66 @@
using StgSharp.Graphics.GL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.ShaderEdit
{
public class ShaderStructMember
{
internal InternalShaderType type;
internal object value;
}
public class ShaderStruct
{
internal Dictionary<glSHandle, ShaderStructMember> uniformPair;
public ShaderStruct(params (glSHandle, ShaderStructMember)[] uniformPairs)
{
uniformPair = new Dictionary<glSHandle, ShaderStructMember>();
if (uniformPairs.Length == 0)
{
return;
}
foreach (var item in uniformPairs)
{
uniformPair.Add(item.Item1,item.Item2);
}
}
internal ShaderStruct() { }
public unsafe void SetAllUniforms()
{
GLcontext* gl = (GLcontext*) glFunc.CurrentContextHandle;
foreach (var uniform in uniformPair)
{
int id = uniform.Key.Value;
ShaderStructMember s = uniform.Value;
switch (s.type)
{
case InternalShaderType.Struct: throw new ArgumentException(
"Incorrect type \"Struct\" defined in this self define type");
case InternalShaderType.Void:throw new ArgumentException(
"Incorrect type \"Void\" defined in this self define type");
case InternalShaderType.Float:
gl->glUniform1f(id, (float)s.value);
break;
case InternalShaderType.Int:
gl->glUniform1f(id, (int)s.value);
break;
default:
throw new NotImplementedException();
throw new ArgumentException(
"Incorrect type \"Unknown\" defined in this self define type");
}
}
}//------------------------------------ End of Class ---------------------------------------
}
}
@@ -0,0 +1,32 @@
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
namespace StgSharp.Graphics
{
public class TextureImage : IImageProvider
{
private Image _tex;
private vec2d[] _texCoord;
Image IImageProvider.ProvideImage()
{
return _tex;
}
public TextureImage(Image image, vec2d[] coord)
{
_tex = image;
_texCoord = coord;
}
public ref vec2d this[int index]
{
get => ref _texCoord[index];
}
}
}
@@ -0,0 +1,26 @@
using StgSharp.Logic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public class TexturePipeline:BlueprintPipelineArgs
{
public TexturePipeline(Image i)
{
value = i;
}
private Image value;
public Image Value
{
get => value;
set => value = value ?? throw new ArgumentNullException(nameof(value));
}
}
}
@@ -0,0 +1,74 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="FormThreading.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.Math;
using StgSharp.Logic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public partial class View
{
internal Blueprint localLogic;
/*
private void GatherSingleFrameAsyncThread(MethodInfo[] methods)
{
if (methods.Length == 0)
{
return;
}
foreach (MethodInfo m in methods) //find all methods decorated by RenderActivityAttribute
{
RenderActivityAttribute attr = m.GetCustomAttribute<RenderActivityAttribute>(false);
if (attr == null)
{
continue;
}
if (!m.IsStatic && (m.GetParameters().Length != 0) && (m.ReturnType != typeof(void)))
{
throw new NotSupportedException("A render activity cannot have parameters, returning value or be static.");
}
ThreadStart s = (ThreadStart)Delegate.CreateDelegate(typeof(ThreadStart), this, m);
FrameAsyncThread thread = new(s, attr._priority);
//singleFrameAsyncThreadList.Add(thread);
}
}
/**/
}
}
@@ -0,0 +1,137 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="View.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.Math;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace StgSharp.Graphics
{
/// <summary>
///
/// </summary>
public unsafe partial class View
{
private (int w, int h) sizeCache;
private (int x, int y, int z) unitCubeSize;
private ViewPort context;
private ViewPortDesigner design;
public ViewPort Port
{
get => context;
}
public View(ViewPort vp, ViewPortDesigner design)
{
context = vp;
sizeCache = (0, 0);
unitCubeSize = (1, 1, 1);
localLogic = new Logic.Blueprint();
this.design = design;
SelfName = string.Empty;
}
public View(ViewPort vp, ViewPortDesigner design, (int, int, int) cubeSize)
{
context = vp;
sizeCache = (0, 0);
unitCubeSize = cubeSize;
localLogic = new Logic.Blueprint();
}
public bool Activated { get; internal set; }
public int Height
{
get
{
if (context.Height != sizeCache.h)
{
sizeCache.h = context.Height;
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
}
return sizeCache.h;
}
internal set
{
sizeCache.h = value;
context.Height = value;
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
}
}
public IntPtr Monitor => context.Monitor;
public IntPtr ViewHandle => context.ViewPortID;
public string ContextName => context.Name;
public string SelfName { get; set; }
public (int x, int y, int z) UnitCubeSize
{
get => unitCubeSize;
}
public int Width
{
get
{
if (context.Width != sizeCache.w)
{
sizeCache.w = context.Width;
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
}
return sizeCache.h;
}
internal set
{
sizeCache.w = value;
context.Width = value;
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
}
}
}
}
@@ -0,0 +1,46 @@
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading;
namespace StgSharp.Graphics
{
public class ViewPort
{
public int Width { get; set; }
public int Height { get; set; }
public string Name { get; set; }
public IntPtr Monitor { get; internal set; }
public IntPtr ViewPortID { get; private set; }
public IntPtr GraphicHandle { get; internal set; }
internal ViewPort()
{
Height = 800;
Width = 600;
Name = new StackFrame(1, false).
GetMethod()!.DeclaringType!.Name;
Monitor = IntPtr.Zero;
ViewPortID = InternalIO.glfwCreateWindow(Width,Height,
Encoding.UTF8.GetBytes(Name), Monitor, IntPtr.Zero
);
}
public ViewPort(vec2d size,string name, IntPtr monitor)
{
Height = (int) size.Y;
Width = (int) size.X;
Name = name;
Monitor = monitor;
ViewPortID = InternalIO.glfwCreateWindow(Width, Height,
Encoding.UTF8.GetBytes(Name), Monitor, IntPtr.Zero
);
}
}
}
@@ -0,0 +1,288 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="framework.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
#if Windows
// using Windows.Win32;
#endif
namespace StgSharp
{
internal partial class InternalIO
{
#region api call
[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 = "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 = "glfwGetVersionString")] internal static extern unsafe byte* glfwGetVersionString();
[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 = "glfwGetMonitors")] internal static extern unsafe IntPtr* glfwGetMonitors(int* count);
[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 = "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 = "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 = "glfwCreateWindow")] internal static extern unsafe IntPtr glfwCreateWindow(int width, int height, byte[] title, IntPtr monitor, IntPtr share);
[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, GLFWwindowposfun 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 = "glfwSetWindowFocusCallback")] internal static extern unsafe GLFWwindowfocusfun glfwSetWindowFocusCallback(IntPtr window, GLFWwindowfocusfun callback);
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowIconifyCallback")] internal static extern unsafe GLFWwindowiconifyfun glfwSetWindowIconifyCallback(IntPtr window, GLFWwindowiconifyfun callback);
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowMaximizeCallback")] internal static extern unsafe GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(IntPtr window, GLFWwindowmaximizefun callback);
[DllImport(SSC_libName, EntryPoint = "glfwSetFramebufferSizeCallback")] internal static extern unsafe FramebuffersizeHandler glfwSetFramebufferSizeCallback(IntPtr window, IntPtr callback);
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowContentScaleCallback")] internal static extern unsafe GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(IntPtr window, GLFWwindowcontentscalefun callback);
[DllImport(SSC_libName, EntryPoint = "glfwPollEvents")] internal static extern unsafe void glfwPollEvents();
[DllImport(SSC_libName, EntryPoint = "glfwWaitEvents")] internal static extern unsafe void glfwWaitEvents();
[DllImport(SSC_libName, EntryPoint = "glfwWaitEventsTimeout")] internal static extern unsafe void glfwWaitEventsTimeout(double timeout);
[DllImport(SSC_libName, EntryPoint = "glfwPostEmptyEvent")] internal static extern unsafe void glfwPostEmptyEvent();
[DllImport(SSC_libName, EntryPoint = "glfwGetInputMode")] internal static extern unsafe int glfwGetInputMode(IntPtr window, int mode);
[DllImport(SSC_libName, EntryPoint = "glfwSetInputMode")] internal static extern unsafe void glfwSetInputMode(IntPtr window, int mode, int value);
[DllImport(SSC_libName, EntryPoint = "glfwRawMouseMotionSupported")] internal static extern unsafe int glfwRawMouseMotionSupported();
[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(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);
//[DllImport(InternalIO.SSC_libname, EntryPoint = "glfwCreateWindowSurface")] internal extern unsafe static VkResult glfwCreateWindowSurface(VkInstance instance, glfwWindow* window, VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
#endregion api call
}
}