daily update on 2024.03.18 by itload youmu

This commit is contained in:
YoumuLiu
2024-03-19 02:41:04 +08:00
parent 15bf989285
commit 0c50c6282e
200 changed files with 7663 additions and 3455 deletions
+297 -159
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 System;
using System.Runtime.InteropServices;
/**/
@@ -16,6 +46,7 @@ namespace StgSharp.Graphics
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWcontext
{
private int client;
private int source;
private int major, minor, revision;
@@ -51,6 +82,7 @@ namespace StgSharp.Graphics
internal struct egl
{
/*
EGLConfig config;
EGLContext handle;
@@ -60,16 +92,19 @@ namespace StgSharp.Graphics
private void* handle;
private void* surface;
private void* client;
}
internal struct osmesa
{
//OSMesaContext handle;
private void* handle;
private int width;
private int height;
private void* buffer;
}
// This is defined in platform.h
@@ -79,6 +114,7 @@ namespace StgSharp.Graphics
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWvidmode
{
/*! The width, in screen coordinates, of the video mode.
*/
public int width;
@@ -97,11 +133,13 @@ namespace StgSharp.Graphics
/*! The refresh rate, in Hz, of the video mode.
*/
private int refreshRate;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWgammaramp
{
/*! An array of value describing the response of the red channel.
*/
private ushort* red;
@@ -114,11 +152,13 @@ namespace StgSharp.Graphics
/*! The number of elements in each array.
*/
private uint size;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWimage
{
/*! The width, in pixels, of this image.
*/
private int width;
@@ -128,11 +168,13 @@ namespace StgSharp.Graphics
/*! 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 button](@ref gamepad_buttons), `GLFW_PRESS`
* or `GLFW_RELEASE`.
*/
@@ -141,11 +183,13 @@ namespace StgSharp.Graphics
* to 1.0 inclusive.
*/
public fixed float axes[6];
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWallocator
{
//GLFWallocatefun allocate;
private IntPtr allocate;
@@ -156,11 +200,13 @@ namespace StgSharp.Graphics
private IntPtr deallocate;
private void* user;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWmonitor
{
private byte[] name = new byte[128];
private void* userPointer;
@@ -185,53 +231,116 @@ namespace StgSharp.Graphics
public GLFWmonitor()
{ }
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWwindow
{
//struct GLFWwindow* next in GLFW
public IntPtr next = IntPtr.Zero;
public GLFWwindow* next;
public bool resizable = false;
public bool decorated = false;
public bool autoIconify = false;
public bool floating = false;
public bool focusOnShow = false;
public bool mousePassthrough = false;
public bool shouldClose = false;
public void* userPointer = (void*)0;
public bool doublebuffer = false;
public GLFWvidmode videoMode = default;
public IntPtr monitor = IntPtr.Zero; //public GLFWmonitor* monitor;
public GLFWcursor* cursor = (GLFWcursor*)0;
private int resizable;
private int decorated;
private int autoIconify;
private int floating;
private int focusOnShow;
private int mousePassthrough;
internal int shouldClose;
private void* userPointer = (void*)0;
private bool doubleBuffer;
private GLFWvidmode videoMode = default;
private IntPtr monitor = IntPtr.Zero; //public GLFWmonitor* monitor;
private GLFWcursor* cursor = (GLFWcursor*)0;
public int minwidth = 0, minheight = 0;
public int maxwidth = 0, maxheight = 0;
public int numer = 0, denom = 0;
public bool stickyKeys = false;
public bool stickyMouseButtons = false;
public bool lockKeyMods = false;
public int cursorMode = 0;
public fixed byte mouseButtons[8];
public fixed byte keys[349];
private int minWidth = 0, minHeight = 0;
private int maxWidth = 0, maxHeight = 0;
private int numer = 0, denom = 0;
private int stickyKeys;
private int stickyMouseButtons;
private int lockKeyMods;
private int cursorMode = 0;
private fixed byte mouseButtons[8];
private fixed byte keys[349];
// Virtual cursor position when cursor is disabled
public double virtualCursorPosX = 0, virtualCursorPosY = 0;
public bool rawMouseMotion = false;
private int rawMouseMotion;
public GLFWcontext context = default;
private fixed long callBacks[17];
public GLFWwindow()
{
}
public bool AutoIconify
{
get => autoIconify != 0;
set => autoIconify = value ? 1 : 0;
}
public bool Decorated
{
get => decorated != 0;
set => decorated = value ? 1 : 0;
}
public bool Floating
{
get => floating != 0;
set => floating = value ? 1 : 0;
}
public bool FocusOnShow
{
get => focusOnShow != 0;
set => focusOnShow = value ? 1 : 0;
}
public bool LockKeyMods
{
get => lockKeyMods != 0;
set => lockKeyMods = value ? 1 : 0;
}
public bool MousePassThrough
{
get => mousePassthrough != 0;
set => mousePassthrough = value ? 1 : 0;
}
public bool RawMouseMotion { get => rawMouseMotion != 0; set => rawMouseMotion = value ? 1 : 0; }
public bool Resizable
{
get => resizable != 0;
set => resizable = value ? 1 : 0;
}
public bool ShouldClose
{
get => shouldClose != 0;
set => shouldClose = value ? 1 : 0;
}
public bool StickyKey
{
get => stickyKeys != 0;
set => stickyKeys = value ? 1 : 0;
}
public bool StickyMouseButtons
{
get => stickyMouseButtons != 0;
set => stickyMouseButtons = value ? 1 : 0;
}
}
[StructLayout(LayoutKind.Sequential)]
public struct GLFWwindowCallback
{
}
[StructLayout(LayoutKind.Sequential)]
public struct GLFWcursor
{
//GLFWcursor* next;
private IntPtr next;
@@ -259,6 +368,7 @@ namespace StgSharp.Graphics
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWinitconfig
{
private GLFWbool hatButtons;
private int angleType;
private int platformID;
@@ -266,26 +376,12 @@ namespace StgSharp.Graphics
//PFN_vkGetInstanceProcAddr vulkanLoader;
private IntPtr vulkanLoader;
private struct ns
{
private GLFWbool menubar;
private GLFWbool chdir;
}
private struct x11
{
private GLFWbool xcbVulkanSurface;
}
private struct wl
{
private int libdecorMode;
}
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWwndconfig
{
private int xpos;
private int ypos;
private int width;
@@ -303,56 +399,66 @@ namespace StgSharp.Graphics
private GLFWbool mousePassthrough;
private GLFWbool scaleToMonitor;
internal struct Ns
{
private GLFWbool retina = false;
public fixed byte frameName[256];
public Ns()
{
}
}
internal Ns ns = new Ns();
internal struct X11
{
public fixed byte className[256];
public fixed byte instanceName[256];
public X11()
{
}
}
internal X11 x11 = new X11();
internal struct Win32
{
private GLFWbool keymenu;
}
internal Win32 win32 = new Win32();
internal struct Wl
{
public fixed byte appId[256];
public Wl()
{
}
}
internal Wl wl = new Wl();
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 int source;
private int major;
@@ -367,21 +473,25 @@ namespace StgSharp.Graphics
//GLFWwindow* share;
private IntPtr share;
internal struct Nsgl
{
private GLFWbool offline;
}
internal Nsgl nsgl = new Nsgl();
public GLFWctxconfig()
{
}
internal struct Nsgl
{
private GLFWbool offline;
}
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWfbconfig
{
private int redBits;
private int greenBits;
private int blueBits;
@@ -399,25 +509,18 @@ namespace StgSharp.Graphics
private GLFWbool doublebuffer;
private GLFWbool transparent;
private uintptr_t handle;
}
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct GLFWlibrary
{
private GLFWbool initialized;
private GLFWallocator allocator;
private GLFWplatform platform;
internal unsafe struct Hints
{
private GLFWinitconfig init;
private GLFWfbconfig framebuffer;
private GLFWwndconfig window;
private GLFWctxconfig context;
private int refreshRate;
}
internal Hints hints = new Hints();
//GLFWerror* errorListHead;
@@ -448,8 +551,30 @@ namespace StgSharp.Graphics
private GLFWls contextSlot;
private GLFWmutex errorLock;
internal Egl egl = new Egl();
internal Osmesa osmesa = new Osmesa();
internal Callbacks callbacks = new Callbacks();
public GLFWlibrary()
{
}
internal unsafe struct Hints
{
private GLFWinitconfig init;
private GLFWfbconfig framebuffer;
private GLFWwndconfig window;
private GLFWctxconfig context;
private int refreshRate;
}
internal unsafe struct timer
{
private ulong offset;
// This is defined in platform.h
@@ -459,6 +584,7 @@ namespace StgSharp.Graphics
internal unsafe struct Egl
{
internal int platform;
internal void* display;
internal int major, minor;
@@ -466,7 +592,7 @@ namespace StgSharp.Graphics
internal bool KHR_create_context;
internal bool KHR_create_context_no_error;
internal bool KHR_colorspace;
internal bool KHR_colorSpace;
internal bool KHR_get_all_proc_addresses;
internal bool KHR_context_flush_control;
internal bool EXT_client_extensions;
@@ -501,12 +627,12 @@ namespace StgSharp.Graphics
internal IntPtr GetPlatformDisplayEXT;
internal IntPtr CreatePlatformWindowSurfaceEXT;
}
internal Egl egl = new Egl();
}
internal unsafe struct Osmesa
{
private void* handle;
private IntPtr CreateContextExt;
@@ -516,12 +642,12 @@ namespace StgSharp.Graphics
private IntPtr GetColorBuffer;
private IntPtr GetDepthBuffer;
private IntPtr GetProcAddress;
}
internal Osmesa osmesa = new Osmesa();
}
internal unsafe struct vk
{
private GLFWbool available;
private void* handle;
private fixed ulong extensions[2];
@@ -537,33 +663,34 @@ namespace StgSharp.Graphics
public vk()
{
}
}
internal unsafe struct Callbacks
{
private IntPtr monitor;
private IntPtr joystick;
}
internal Callbacks callbacks = new Callbacks();
public GLFWlibrary()
{
}
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWmapelement
{
private byte type;
private byte index;
private sbyte axisScale;
private sbyte axisOffset;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWmapping
{
private fixed byte name[128];
private fixed byte guid[33];
@@ -575,11 +702,13 @@ namespace StgSharp.Graphics
public GLFWmapping()
{ }
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWjoystick
{
private GLFWbool allocated;
private GLFWbool connected;
private float* axes;
@@ -601,6 +730,7 @@ namespace StgSharp.Graphics
public GLFWjoystick()
{ }
}
[StructLayout(LayoutKind.Sequential)]
@@ -614,6 +744,7 @@ namespace StgSharp.Graphics
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWplatform
{
private int platformID;
// init
@@ -623,73 +754,75 @@ namespace StgSharp.Graphics
//void (* terminate) (void);
private IntPtr terminate;
// input
#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*);
GLFWvidmode* (* getVideoModes) (GLFWmonitor*, int*);
void (* getVideoMode) (GLFWmonitor*, GLFWvidmode*);
GLFWbool(*getGammaRamp)(GLFWmonitor*, GLFWgammaramp*);
void (* setGammaRamp) (GLFWmonitor*,const GLFWgammaramp*);
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*);
GLFWvidmode* (* getVideoModes) (GLFWmonitor*, int*);
void (* getVideoMode) (GLFWmonitor*, GLFWvidmode*);
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 (* 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);
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 setCursorMode;
internal IntPtr setRawMouseMotion;
@@ -776,6 +909,7 @@ namespace StgSharp.Graphics
internal IntPtr VkPhysicalDevice;
internal IntPtr GLFWwindow;
}
[StructLayout(LayoutKind.Sequential)]
@@ -790,12 +924,14 @@ namespace StgSharp.Graphics
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct VkExtensionProperties
{
private fixed byte extensionName[256];
private uint specVersion;
public VkExtensionProperties()
{
}
}
/*
@@ -816,11 +952,13 @@ namespace StgSharp.Graphics
[StructLayout(LayoutKind.Explicit, Size = 16)]
public struct uintptr_t
{
[FieldOffset(0)]
private long part1;
[FieldOffset(8)]
private long part2;
}
#endregion GLFW3 struct
@@ -1,4 +1,34 @@
/*
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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
@@ -7,12 +37,19 @@
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 serching its name.
/// </summary>
@@ -143,12 +180,6 @@ namespace StgSharp.Graphics
//[UnmanagedFunctionPointer(callingConvention: CallingConvention.Cdecl, CharSet = CharSet.Ansi)] internal unsafe delegate VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window, VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
#endregion
#region StgSharpDele
public unsafe delegate void FrameBufferSizeHandler(IntPtr window, uint width, uint height);
#endregion
#region glDEBUG
+35 -5
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glConst.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;
namespace StgSharp.Graphics
{
@@ -22,10 +52,10 @@ namespace StgSharp.Graphics
internal const int GLFW_HAT_RIGHT = 2;
internal const int GLFW_HAT_DOWN = 4;
internal const int GLFW_HAT_LEFT = 8;
internal const int GLFW_HAT_RIGHT_UP = (GLFW_HAT_RIGHT | GLFW_HAT_UP);
internal const int GLFW_HAT_RIGHT_DOWN = (GLFW_HAT_RIGHT | GLFW_HAT_DOWN);
internal const int GLFW_HAT_LEFT_UP = (GLFW_HAT_LEFT | GLFW_HAT_UP);
internal const int GLFW_HAT_LEFT_DOWN = (GLFW_HAT_LEFT | GLFW_HAT_DOWN);
internal const int GLFW_HAT_RIGHT_UP = GLFW_HAT_RIGHT | GLFW_HAT_UP;
internal const int GLFW_HAT_RIGHT_DOWN = GLFW_HAT_RIGHT | GLFW_HAT_DOWN;
internal const int GLFW_HAT_LEFT_UP = GLFW_HAT_LEFT | GLFW_HAT_UP;
internal const int GLFW_HAT_LEFT_DOWN = GLFW_HAT_LEFT | GLFW_HAT_DOWN;
internal const int GLFW_KEY_UNKNOWN = -1;
internal const int GLFW_KEY_SPACE = 32;
internal const int GLFW_KEY_APOSTROPHE = 39;
+31 -1
View File
@@ -1,4 +1,34 @@
namespace StgSharp.Graphics
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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
{
internal enum VkStructureType : uint
{
+61 -29
View File
@@ -1,4 +1,35 @@
using StgSharp.Geometries;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -9,35 +40,10 @@ using System.Text;
namespace StgSharp.Graphics
{
public delegate IntPtr GLfuncLoader(string name);
internal delegate void GLVULKANPROCNV();
#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
public unsafe struct GLhandleARB
{
@@ -80,6 +86,32 @@ namespace StgSharp.Graphics
}
public delegate IntPtr GLfuncLoader(string name);
#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
}
+107 -129
View File
@@ -1,20 +1,41 @@
using StgSharp;
using StgSharp.Controlling;
using StgSharp.Logic;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Form.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.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Threading;
@@ -23,52 +44,45 @@ namespace StgSharp.Graphics
/// <summary>
///
/// </summary>
public abstract partial class Form
public abstract unsafe partial class Form
{
#region metadata
internal LinkedList<Control> allControl;
internal Vector4 backgroundColor;
internal IglFunc gl;
internal unsafe IntPtr graphicContextID;
internal IntPtr graphicContextID;
internal int height;
internal IntPtr monitor;
internal string name;
internal Form sharedForm;
internal int width;
internal IntPtr windowID;
protected readonly TimeProvider FrameTimeFrocider;
private GLFWwindow* windowID;
internal TimeSpanProvider frameTimeProvider;
#endregion metadata
#region form thread setting
private bool isSingleThread = true;
#endregion form thread setting
#region glapicount
private int missingAPIcount = 0;
private int problemAPIcount = 0;
#endregion glapicount
#region form main
#region form thread setting
private bool isSingleThread = true;
#endregion form thread setting
private int _shouldClose = 0;
protected Form()
{
}
/// <summary>
/// OpenGL package used by current form context.
/// OpenGL package binded to current form context.
/// A OpenGL context is only binded to current form.
/// </summary>
public IglFunc GL
{
get => gl;
internal set => gl = value;
}
public IglFunc GL => gl;
/// <summary>
/// Height of this form, represent in <see cref="int"/>
@@ -82,24 +96,13 @@ namespace StgSharp.Graphics
/// <summary>
/// Representing
/// </summary>
public bool IsDoubleRendering
{
get { return isSingleThread; }
}
public bool IsDoubleRendering => isSingleThread;
public bool ShouldClose
{
get
{
Interlocked.Exchange(ref _shouldClose, InternalIO.glfwWindowShouldClose(windowID));
return 0 != _shouldClose;
}
get => InternalIO.glfwWindowShouldClose(windowID) != 0;
set
{
InternalIO.glfwSetWindowShouldClose(windowID, value ? 1 : 0);
Interlocked.Exchange(ref _shouldClose, value ? 1 : 0);
}
set => InternalIO.glfwSetWindowShouldClose(windowID, value ? 1 : 0);
}
/// <summary>
@@ -107,7 +110,7 @@ namespace StgSharp.Graphics
/// </summary>
public Vec2d Size
{
get { return new Vec2d(width, height); }
get => new Vec2d(width, height);
set
{
width = (int)value.X;
@@ -124,10 +127,9 @@ namespace StgSharp.Graphics
set => width = value;
}
internal bool IsSingleThread
{
get { return isSingleThread; }
}
public unsafe IntPtr WindowID => (IntPtr)windowID;
internal unsafe GLFWwindow* id => windowID;
protected FrameBufferSizeHandler FrameBufferSizeCallback
{
@@ -138,12 +140,15 @@ namespace StgSharp.Graphics
}
}
internal bool IsSingleThread => isSingleThread;
/// <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.
/// 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>
/// <exception cref="Exception">
/// Something goes wrong and StgSharp fails in creating a new OpenGL context.
/// </exception>
public unsafe void MakeAsCurrentContext()
{
if (windowID == default)
@@ -152,21 +157,19 @@ namespace StgSharp.Graphics
byte[] tittleBytes = Encoding.UTF8.GetBytes(name);
if (sharedForm == null)
{
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, IntPtr.Zero);
windowPtr = InternalIO.glfwCreateWindow(width, height, tittleBytes, monitor, (GLFWwindow*)IntPtr.Zero);
}
else
{
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, sharedForm.windowID);
windowPtr = InternalIO.glfwCreateWindow(width, height, tittleBytes, monitor, sharedForm.windowID);
}
if ((long)windowPtr == -1 || (long)windowPtr == -2)
if (((long)windowPtr == -1) || ((long)windowPtr == -2))
{
throw new Exception("Cannot create window instance!");
}
else
{
windowID = windowPtr;
windowID = (GLFWwindow*)windowPtr;
}
graphicContextID = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GLcontext)));
@@ -191,18 +194,6 @@ namespace StgSharp.Graphics
this.monitor = monitor;
}
/// <summary>
/// Resize the current form
/// </summary>
/// <param name="width">New width of the window</param>
/// <param name="height">New height of the window</param>
public void SetSize(int width, int height)
{
this.Width = width;
this.Height = height;
InternalIO.glfwSetWindowSize(this.windowID, width, height);
}
/// <summary>
/// Resize the current form
/// </summary>
@@ -217,18 +208,15 @@ namespace StgSharp.Graphics
}
/// <summary>
/// Set the size limit of current form
/// Resize the 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 curent form</param>
/// <param name="maxHeight">Maximum height of current form</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
/// <param name="width">New width of the window</param>
/// <param name="height">New height of the window</param>
public void SetSize(int width, int height)
{
InternalIO.glfwSetWindowSizeLimits(
this.windowID,
minWidth, minHeight, maxWidth, maxHeight);
this.Width = width;
this.Height = height;
InternalIO.glfwSetWindowSize(this.windowID, width, height);
}
/// <summary>
@@ -245,19 +233,26 @@ namespace StgSharp.Graphics
{
InternalIO.glfwSetWindowSizeLimits(
this.windowID,
(int)minSize.X, (int)minSize.Y, (int)maxSize.X, (int)maxSize.Y);
(int)minSize.X,
(int)minSize.Y,
(int)maxSize.X,
(int)maxSize.Y);
}
unsafe ~Form()
{
Marshal.FreeHGlobal(graphicContextID);
}
/// <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 curent form</param>
/// <param name="maxHeight">Maximum height of current form</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
{ InternalIO.glfwSetWindowSizeLimits(this.windowID, minWidth, minHeight, maxWidth, maxHeight); }
#region form main
unsafe ~Form() { Marshal.FreeHGlobal(graphicContextID); }
private static unsafe delegate*<void> pollEventPtr = &InternalIO.glfwPollEvents;
private static unsafe delegate*<void> swapBufferPtr = &InternalSwapBuffers;
public abstract void Deinit(params object[] args);
@@ -268,22 +263,14 @@ namespace StgSharp.Graphics
public abstract void Init(params object[] args);
/// <summary>
/// Behaviour of current form when in a render cycle.
/// When this form
/// Behaviour of current form when in a render cycle. When this form
/// </summary>
/// <param name="args"></param>
public abstract void Main(params object[] args);
public unsafe void PollEvents()
{
if (isSingleThread)
{
InternalIO.glfwPollEvents();
}
else
{
gl.frameworkHandleEnqueue((IntPtr)pollEventPtr);
}
InternalIO.glfwPollEvents();
}
/// <summary>
@@ -303,61 +290,49 @@ namespace StgSharp.Graphics
{
Main(args);
SwapBuffers();
PollEvents();
}
}
else
{
GLonUpdate update = new GLonUpdate((GLcontext*)graphicContextID);
FrameThread renderThread = new FrameThread(update);
FrameThread updateThread = new FrameThread(update);
renderThread.SetNext(updateThread);
updateThread.SetNext(renderThread);
FrameAsyncTask renderTask = new FrameAsyncTask(update);
FrameAsyncTask updateTask = new FrameAsyncTask(update);
gl = update;
int a = 0;
while (!ShouldClose)
{
renderTask.StartAsync();
updateTask.StartAsync();
FrameAsyncTask.CombineAsync(renderTask, updateTask);
SwapBuffers();
PollEvents();
}
//TODO 对逻辑线程和渲染线程进行同步,两种gl模式包需要改名字
}
}
}
internal static unsafe void InternalSwapBuffers()
internal static unsafe void InternalSwapBuffers(FrameOperationBuffer operationBuffer, GLcontext* context)
{
IntPtr winHandle = default;
InternalIO.glfwSwapBuffers(winHandle);
IntPtr window = default;
operationBuffer.TryDequeue(out window);
InternalIO.glfwSwapBuffers((GLFWwindow*)window);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void InternalDeinit(params object[] args)
{
Deinit(args);
}
internal void InternalDeinit(params object[] args) { Deinit(args); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void InternalInit(params object[] args)
{
Init(args);
}
internal unsafe void SwapBuffers()
{
if (isSingleThread)
{
InternalIO.glfwSwapBuffers(windowID);
}
else
{
M128 m = new M128();
m.Write<ulong>(0, (ulong)windowID);
gl.frameworkHandleEnqueue((IntPtr)swapBufferPtr, m);
}
InternalIO.glfwSwapBuffers(windowID);
}
/// <summary>
/// Get OpenGL library of this form's context.
/// </summary>
/// <returns>A <see cref="IglFunc"/> package contains all opengl APIs </returns>
/// <returns>A <see cref="IglFunc"/> package contains all opengl APIs</returns>
protected IglFunc GetGL()
{
if (StgSharp.API == GraphicAPI.GL)
@@ -366,7 +341,9 @@ namespace StgSharp.Graphics
}
else
{
InternalIO.InternalWriteLog("Attempt to get OpenGL API package in other graphic envitronment.", LogType.Error);
InternalIO.InternalWriteLog(
"Attempt to get OpenGL API package in other graphic envitronment.",
LogType.Error);
throw new InvalidOperationException("Attempt to get OpenGL API package in other graphic envitronment.");
}
}
@@ -396,7 +373,8 @@ namespace StgSharp.Graphics
throw new ArgumentException("Amount of threads should be bigger than 0");
}
}
#endregion form main
}
}
@@ -1,11 +1,39 @@
using StgSharp.Logic;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="FrameAsyncTask.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.Runtime.CompilerServices;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -14,9 +42,10 @@ namespace StgSharp.Graphics
{
internal sealed class FrameOperationBuffer
{
private readonly unsafe GLcontext* currentContext;
private IntPtr _func;
private ConcurrentQueue<IntPtr> _funcQueue;
private readonly unsafe GLcontext* currentContext;
public unsafe bool CallNext()
{
@@ -451,50 +480,52 @@ namespace StgSharp.Graphics
/**/
#endregion gl param queue
}
internal sealed class FrameThread
//TODO 任务组绑定机制有问题,现在一次只能绑定两个
//TODO 目前还不能加载任何任务
//TODO 任务的启动逻辑需要重构
internal class FrameAsyncTask
{
private Thread _thread;
private FrameOperationBuffer renderBuffer;
private SemaphoreSlim renderCompleteSemaphore = new SemaphoreSlim(1, 1);
private SemaphoreSlim renderStartSemaphore;
private bool shouldTerminate;
private FrameOperationBuffer updateBuffer;
internal FrameThread(GLonUpdate gl)
private SemaphoreSlim _refrshSemaphore;
private SemaphoreSlim _frameCompleteSemaphore;
private Task _task;
private FrameOperationBuffer opBuffer = new FrameOperationBuffer();
internal FrameAsyncTask(GLonUpdate gl)
{
updateBuffer = gl.ActivatedOperationBuffer;
_thread = new Thread(new ThreadStart(PrivateMain));
}
public bool IsRunning
public static void ExchangeBuffer(FrameAsyncTask task0, FrameAsyncTask task1)
{
get { return _thread.IsAlive; }
FrameOperationBuffer cache = task0.opBuffer;
task0.opBuffer = task1.opBuffer;
task1.opBuffer = cache;
}
public void Start()
public async Task StartAsync()
{
_thread.Start();
_task.Start();
await _task;
}
public void Terminate()
public static SemaphoreSlim CombineAsync(FrameAsyncTask task0, FrameAsyncTask task1)
{
shouldTerminate = true;
SemaphoreSlim refresh = new SemaphoreSlim(2);
task0._refrshSemaphore = refresh;
task1._refrshSemaphore = refresh;
return refresh;
}
public static SemaphoreSlim AsyncWait(FrameAsyncTask task0, FrameAsyncTask task1)
{
SemaphoreSlim refresh = new SemaphoreSlim(2);
task0._refrshSemaphore = refresh;
task1._refrshSemaphore = refresh;
return refresh;
}
private void PrivateMain()
{
renderStartSemaphore.Wait();
while (shouldTerminate && renderBuffer.CallNext())
{ }
renderCompleteSemaphore.Release();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetNext(FrameThread thread)
{
renderStartSemaphore = thread.renderCompleteSemaphore;
}
}
}
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -11,6 +41,7 @@ namespace StgSharp.Graphics
/// </summary>
public abstract class BufferObjectBase : IDisposable
{
protected glHandleSet _bufferHandle;
protected IglFunc GL;
@@ -19,10 +50,7 @@ namespace StgSharp.Graphics
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public glHandle this[int index]
{
get { return _bufferHandle[index]; }
}
public glHandle this[int index] => _bufferHandle[index];
/// <summary>
/// Bind a buffer instance to OpenGL
@@ -30,6 +58,12 @@ namespace StgSharp.Graphics
/// <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()
{
@@ -43,10 +77,5 @@ namespace StgSharp.Graphics
Dispose(disposing: false);
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}
+33 -1
View File
@@ -1,4 +1,34 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -15,6 +45,7 @@ namespace StgSharp.Graphics
/// </summary>
public unsafe class ElementBuffer : BufferObjectBase
{
internal ElementBuffer(int n, IglFunc gl)
{
GL = gl;
@@ -41,5 +72,6 @@ namespace StgSharp.Graphics
_bufferHandle.Release();
}
}
}
}
+33 -1
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -7,6 +37,7 @@ namespace StgSharp.Graphics
{
public unsafe class VertexArray : BufferObjectBase
{
internal VertexArray(int n, IglFunc gl)
{
GL = gl;
@@ -42,5 +73,6 @@ namespace StgSharp.Graphics
_bufferHandle.Release();
}
}
}
}
+33 -1
View File
@@ -1,4 +1,34 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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.Math;
using System;
using System.Collections.Generic;
@@ -12,6 +42,7 @@ namespace StgSharp.Graphics
{
public unsafe class VertexBuffer : BufferObjectBase
{
internal VertexBuffer(int n, IglFunc glFunc)
{
GL = glFunc;
@@ -72,5 +103,6 @@ namespace StgSharp.Graphics
_bufferHandle.Release();
}
}
}
}
@@ -1,4 +1,34 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -12,10 +42,11 @@ namespace StgSharp.Graphics
{
public unsafe class Texture
{
internal static bool[] unitActivated = new bool[16];
private IglFunc GL;
internal glHandleSet _textureHandle;
internal Image[] sourceList;
private IglFunc GL;
internal Texture(int n, IglFunc gl)
{
@@ -96,6 +127,7 @@ namespace StgSharp.Graphics
}
#endregion texture setting
}
public enum Filter
+67 -44
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -18,12 +48,14 @@ namespace StgSharp.Graphics
/// </summary>
public unsafe struct glHandle
{
internal glHandleSet source;
internal uint* valuePtr;
[Obsolete("Cannot init instance of this type", true)]
public glHandle()
private glHandle(IntPtr handle)
{
this.valuePtr = (uint*)handle;
source = null;
}
internal glHandle(uint* val, glHandleSet set)
@@ -32,15 +64,9 @@ namespace StgSharp.Graphics
valuePtr = val;
}
private glHandle(IntPtr handle)
[Obsolete("Cannot init instance of this type", true)]
public glHandle()
{
this.valuePtr = (uint*)handle;
source = null;
}
public static glHandle Zero
{
get { return Alloc(0); }
}
public IntPtr Handle
@@ -75,13 +101,9 @@ namespace StgSharp.Graphics
}
}
internal uint DirectValue
{
get
{
return *valuePtr;
}
}
public static glHandle Zero => Alloc(0);
internal uint DirectValue => *valuePtr;
public static glHandle Alloc(uint value)
{
@@ -97,10 +119,12 @@ namespace StgSharp.Graphics
{
return new glHandle(handle);
}
}
public unsafe struct glSHandle
{
internal glHandleSet source;
internal int* valuePtr;
@@ -110,29 +134,25 @@ namespace StgSharp.Graphics
valuePtr = val;
}
public static glSHandle Zero
{
get { return Alloc(0); }
}
public static glSHandle Zero => Alloc(0);
internal int DirectValue
{
get { return *valuePtr; }
}
internal int DirectValue => *valuePtr;
public static glSHandle Alloc(int value)
{
glSHandle ret = default;
ret.source = new glHandleSet(1);
ret.valuePtr = (int*)ret.source.handle;
*ret.valuePtr = (int)value;
*ret.valuePtr = value;
return ret;
}
}
//TODO 发现一个大问题,paramQueue大多数时候取出的是数组,不是数组句柄,也就是说其内存将被长期固定且不能回收,这是内存泄漏
public unsafe class glArrayHandle
{
internal readonly Array a;
internal GCHandle handle;
@@ -142,20 +162,6 @@ namespace StgSharp.Graphics
handle = GCHandle.Alloc(array, GCHandleType.Pinned);
}
[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);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static glArrayHandle Alloc<T>(T[] array) where T : struct
{
return new glArrayHandle(array);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IntPtr AddressOfArray()
{
@@ -169,11 +175,26 @@ namespace StgSharp.Graphics
}
}
[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>
@@ -181,9 +202,10 @@ namespace StgSharp.Graphics
/// </summary>
public unsafe class glHandleSet
{
private readonly uint[] _value;
internal uint* handle;
internal int length;
private readonly uint[] _value;
public glHandleSet(int count)
{
@@ -212,13 +234,13 @@ namespace StgSharp.Graphics
{
throw new IndexOutOfRangeException();
}
return new glSHandle((int*)handle + index, this);
return new glSHandle(((int*)handle) + index, this);
}
}
public static void Copy(in glHandleSet source, glHandleSet target)
{
if (source == null || target == null)
if ((source == null) || (target == null))
{
throw new NullReferenceException();
}
@@ -279,5 +301,6 @@ namespace StgSharp.Graphics
{
_value[index] = value;
}
}
}
+91 -60
View File
@@ -1,4 +1,34 @@
using StgSharp.Logic;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GLonRender.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;
@@ -12,23 +42,15 @@ namespace StgSharp.Graphics
{
internal unsafe partial class GLonRender : IglFunc
{
internal GLcontext* api;
private FrameTimeoutException refreshSIgnal = new FrameTimeoutException();
internal GLcontext* api;
internal GLonRender(GLcontext* context)
{
api = context;
}
GLcontext* IglFunc.Context
{
get => api;
}
void IglFunc.SwitchContext()
{
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.ActiveTexture(uint type)
{
@@ -87,35 +109,6 @@ namespace StgSharp.Graphics
while (api->glGetError() != 0) { }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.LoadShaderSource(glHandle shaderHandle, string codeStream)
{
byte[] stream = Encoding.UTF8.GetBytes(codeStream);
fixed (byte* streamPtr = stream)
{
api->glShaderSource(shaderHandle.DirectValue, 1, &streamPtr, (void*)0);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
glHandleSet IglFunc.CreateShaderSet(int count, ShaderType type)
{
glHandleSet ret = new glHandleSet(count);
uint t = (uint)type;
for (int i = 0; i < count; i++)
{
uint id = api->glCreateShader(t);
if (id == 0)
{
uint error = api->glGetError();
InternalIO.InternalWriteLog($"Failed in creating shader: {error}", LogType.Error);
throw new Exception();
}
ret.SetValue(i, id);
}
return ret;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.CompileShader(glHandle shaderhandle)
{
@@ -139,6 +132,25 @@ namespace StgSharp.Graphics
return h;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
glHandleSet IglFunc.CreateShaderSet(int count, ShaderType type)
{
glHandleSet ret = new glHandleSet(count);
uint t = (uint)type;
for (int i = 0; i < count; i++)
{
uint id = api->glCreateShader(t);
if (id == 0)
{
uint error = api->glGetError();
InternalIO.InternalWriteLog($"Failed in creating shader: {error}", LogType.Error);
throw new Exception();
}
ret.SetValue(i, id);
}
return ret;
}
unsafe IntPtr IglFunc.CreateWindowHandle(
int width, int height, string tittle, IntPtr monitor, Form share)
{
@@ -147,15 +159,15 @@ namespace StgSharp.Graphics
if (share == null)
{
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, IntPtr.Zero);
width, height, tittleBytes, monitor, (GLFWwindow*)IntPtr.Zero);
}
else
{
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, share.windowID);
width, height, tittleBytes, monitor, share.id);
}
if ((long)windowPtr == -1 || (long)windowPtr == -2)
if (((long)windowPtr == -1) || ((long)windowPtr == -2))
{
throw new Exception("Cannot create window instance!");
}
@@ -180,14 +192,14 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.DeleteBuffers(glHandleSet handle)
{
api->glDeleteBuffers((uint)handle.length, (uint*)handle.handle);
api->glDeleteBuffers((uint)handle.length, handle.handle);
handle.Free();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.DeleteVertexArrays(glHandleSet arrays)
{
api->glDeleteVertexArrays((uint)arrays.length, (uint*)arrays.handle);
api->glDeleteVertexArrays((uint)arrays.length, arrays.handle);
arrays.Free();
}
@@ -211,18 +223,22 @@ namespace StgSharp.Graphics
default:
InternalIO.InternalWriteLog(
$"Parameter error in parameter {nameof(type)} method DrawElements. " +
$"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are suporrted.",
$"{($"Parameter error in parameter {nameof(type)} method DrawElements. ")}{($"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are suporrted.")}",
LogType.Error);
return;
}
api->glDrawElements((uint)mode, count, a, (void*)ptr);
}
void IglFunc.frameworkHandleEnqueue(System.IntPtr handle, params M128[] param)
{
throw new InvalidOperationException();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe glHandleSet IglFunc.GenBuffers(int count)
{
glHandleSet h = new glHandleSet((int)count);
glHandleSet h = new glHandleSet(count);
api->glGenBuffers((uint)count, h.handle);
return h;
}
@@ -230,7 +246,7 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe glHandleSet IglFunc.GenTextures(int count)
{
glHandleSet h = new glHandleSet((int)count);
glHandleSet h = new glHandleSet(count);
api->glGenTextures((uint)count, h.handle);
return h;
}
@@ -256,18 +272,28 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe bool IglFunc.GetWindowShouldClose(Form form)
{
return InternalIO.glfwWindowShouldClose(form.windowID) == 0;
return InternalIO.glfwWindowShouldClose(form.id) == 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.LoadShaderSource(glHandle shaderHandle, string codeStream)
{
byte[] stream = Encoding.UTF8.GetBytes(codeStream);
fixed (byte* streamPtr = stream)
{
api->glShaderSource(shaderHandle.DirectValue, 1, &streamPtr, (void*)0);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.MakeContexCurrent(Form form)
{
if (form.windowID == IntPtr.Zero)
if (form.WindowID == IntPtr.Zero)
{
InternalIO.InternalWriteLog($"From {nameof(form)} is not initted.", LogType.Warning);
return;
}
InternalIO.glfwMakeContextCurrent(form.windowID);
InternalIO.glfwMakeContextCurrent(form.id);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -290,11 +316,13 @@ namespace StgSharp.Graphics
return;
}
fixed (void* bufferPtr = bufferArray)
{
api->glBufferData(
(uint)bufferType,
(IntPtr)size,
(IntPtr)bufferPtr,
(uint)usage);
(uint)bufferType,
(IntPtr)size,
(IntPtr)bufferPtr,
(uint)usage);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -305,6 +333,10 @@ namespace StgSharp.Graphics
api->glEnableVertexAttribArray(index);
}
void IglFunc.SwitchContext()
{
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.TextureImage2d<T>(int target, int level, uint internalformat, uint width, uint height, uint format, uint type, glHandle pixels)
{
@@ -331,9 +363,8 @@ namespace StgSharp.Graphics
api->glViewport(x, y, width, height);
}
void IglFunc.frameworkHandleEnqueue(System.IntPtr handle, params M128[] param)
{
throw new InvalidOperationException();
}
GLcontext* IglFunc.Context
=> api;
}
}
+65 -37
View File
@@ -1,4 +1,34 @@
using StgSharp.Logic;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GLonUpdate.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;
@@ -15,10 +45,10 @@ namespace StgSharp.Graphics
{
internal unsafe partial class GLonUpdate : IglFunc
{
private GLcontext* api;
private IntPtr SwapBufferPtr = (IntPtr)(delegate*<IntPtr, void>)&InternalIO.glfwSwapBuffers;
private glSHandle unupdatedFrame = glSHandle.Alloc(0);
private FrameOperationBuffer frameOpBuffer;
private glSHandle unupdatedFrame = glSHandle.Alloc(0);
internal GLonUpdate(GLcontext* context)
{
@@ -29,15 +59,19 @@ namespace StgSharp.Graphics
api = context;
}
GLcontext* IglFunc.Context
{
get => api;
}
public FrameOperationBuffer ActivatedOperationBuffer
{
get { return frameOpBuffer; }
set { frameOpBuffer = value; }
get => frameOpBuffer;
set => frameOpBuffer = value;
}
public void GLswapBuffers(Form form)
{
if (form.WindowID == IntPtr.Zero)
{
return;
}
InternalIO.glfwSwapBuffers(form.id);
}
void IglFunc.ActiveTexture(uint type)
@@ -77,7 +111,7 @@ namespace StgSharp.Graphics
void IglFunc.BindTexture(uint type, glHandle texture)
{
M128 m = default;
m.Write<uint>(0, (uint)type);
m.Write<uint>(0, type);
m.Write<ulong>(1, (ulong)texture.valuePtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(BindTexturePtr);
@@ -156,15 +190,15 @@ namespace StgSharp.Graphics
if (share == null)
{
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, IntPtr.Zero);
width, height, tittleBytes, monitor, (GLFWwindow*)IntPtr.Zero);
}
else
{
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, share.windowID);
width, height, tittleBytes, monitor, share.id);
}
if ((long)windowPtr == -1 || (long)windowPtr == -2)
if (((long)windowPtr == -1) || ((long)windowPtr == -2))
{
throw new Exception("Cannot create window instance!");
}
@@ -229,8 +263,7 @@ namespace StgSharp.Graphics
default:
InternalIO.InternalWriteLog(
$"Parameter error in parameter {type} method DrawElements. " +
$"Only {TypeCode.Byte}, {TypeCode.UInt16}, {TypeCode.UInt32} types are suporrted.",
$"{($"Parameter error in parameter {type} method DrawElements. ")}{($"Only {TypeCode.Byte}, {TypeCode.UInt16}, {TypeCode.UInt32} types are suporrted.")}",
LogType.Error);
return;
}
@@ -239,6 +272,16 @@ namespace StgSharp.Graphics
frameOpBuffer.MethodEnqueue(DrawElementsPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.frameworkHandleEnqueue(IntPtr methodHandle, params M128[] param)
{
foreach (M128 item in param)
{
frameOpBuffer.ParamEnqueue(item);
}
frameOpBuffer.ParamEnqueue(methodHandle);
}
unsafe glHandleSet IglFunc.GenBuffers(int count)
{
glHandleSet h = new glHandleSet(count);
@@ -282,16 +325,7 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
bool IglFunc.GetWindowShouldClose(Form form)
{
return InternalIO.glfwWindowShouldClose(form.windowID) == 0;
}
public void GLswapBuffers(Form form)
{
if (form.windowID == IntPtr.Zero)
{
return;
}
InternalIO.glfwSwapBuffers(form.windowID);
return InternalIO.glfwWindowShouldClose(form.id) == 0;
}
void IglFunc.LoadShaderSource(glHandle shaderHandle, string codeStream)
@@ -304,11 +338,11 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.MakeContexCurrent(Form form)
{
if (form.windowID == IntPtr.Zero)
if (form.WindowID == IntPtr.Zero)
{
return;
}
InternalIO.glfwMakeContextCurrent(form.windowID);
InternalIO.glfwMakeContextCurrent(form.id);
}
void IglFunc.SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
@@ -370,14 +404,8 @@ namespace StgSharp.Graphics
frameOpBuffer.MethodEnqueue(ViewPortPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.frameworkHandleEnqueue(IntPtr methodHandle, params M128[] param)
{
foreach (M128 item in param)
{
frameOpBuffer.ParamEnqueue(item);
}
frameOpBuffer.ParamEnqueue(methodHandle);
}
GLcontext* IglFunc.Context
=> api;
}
}
@@ -1,28 +1,49 @@
using StgSharp.Logic;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GLonUpdateInternal.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.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
internal unsafe partial class GLonUpdate : IglFunc
{
private IntPtr ActiveTexturePtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalActiveTexture;
private IntPtr AttachShaderPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalAttachShader;
private IntPtr BindBufferPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalBindBuffer;
private IntPtr BindTexturePtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalBindTexture;
private IntPtr BindVertexArrayPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalBindVertexArray;
private IntPtr BufferDataPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalSetBufferData;
private IntPtr CanUpdatePtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalFrameCanUpdate;
private IntPtr ClearColorPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalClearColor;
private IntPtr ClearGraphicErrorPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalClearGraphicError;
private IntPtr ClearPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalClear;
@@ -35,7 +56,6 @@ namespace StgSharp.Graphics
private IntPtr DrawElementsPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalDrawElements;
private IntPtr GenBufferPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalGenBuffers;
private IntPtr GenTexturesPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalGenTextures;
private IntPtr GenVertexArraysPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalGenVertexArrays;
private IntPtr GetUniformLocationPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalGetUniformLocation;
private IntPtr SetVertexArrayPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalSetVertexAttribute;
private IntPtr ShaderSourcePtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalShaderSource;
@@ -147,7 +167,7 @@ namespace StgSharp.Graphics
activatedContext->glDeleteBuffers(m.Read<uint>(2), (uint*)m.Read<ulong>(0));
for (int i = 0; i < m.Read<uint>(2); i++)
{
*((uint*)m.Read<ulong>(0) + i) = 0;
*(((uint*)m.Read<ulong>(0)) + i) = 0;
}
}
@@ -167,13 +187,6 @@ namespace StgSharp.Graphics
activatedContext->glDrawElements(mode, count, type, (void*)ptr);
}
private static void InternalFrameCanUpdate(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
IntPtr ptr;
frameBuffer.TryDequeue(out ptr);
Interlocked.Add(ref *(int*)ptr, -1);
}
private static void InternalGenBuffers(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
M128 m = default;
@@ -188,13 +201,6 @@ namespace StgSharp.Graphics
activatedContext->glGenTextures(m.Read<uint>(2), (uint*)m.Read<ulong>(0));
}
private static void InternalGenVertexArrays(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameBuffer.TryDequeue(out m);
activatedContext->glGenVertexArrays(m.Read<uint>(2), (uint*)m.Read<ulong>(0));
}
private static void InternalGetUniformLocation(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
IntPtr programHandle = default, nameHandle = default, targetHandle = default;
@@ -265,14 +271,5 @@ namespace StgSharp.Graphics
activatedContext->glViewport(m.Read<int>(0), m.Read<int>(1), m.Read<uint>(2), m.Read<uint>(3));
}
private void InternalMakeContexCurrent(Form form)
{
throw new NotImplementedException();
}
private void InternalSwitchContext()
{
throw new NotImplementedException();
}
}
}
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -9,6 +39,7 @@ namespace StgSharp.Graphics
{
public partial class Form
{
/// <summary>
/// Create a set of <see cref="ElementBuffer"/>.
/// </summary>
@@ -20,17 +51,6 @@ namespace StgSharp.Graphics
return new ElementBuffer(count, this.gl);
}
/// <summary>
/// Create a set of <see cref="VertexArray"/>.
/// </summary>
/// <param name="count">Amount of VAO to be crated.</param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected VertexArray CreateVertexArray(int count)
{
return new VertexArray(count, gl);
}
/// <summary>
/// Create a sets of <see cref="Texture"/>
/// </summary>
@@ -42,6 +62,17 @@ namespace StgSharp.Graphics
return new Texture(count, this.GL);
}
/// <summary>
/// Create a set of <see cref="VertexArray"/>.
/// </summary>
/// <param name="count">Amount of VAO to be crated.</param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected VertexArray CreateVertexArray(int count)
{
return new VertexArray(count, gl);
}
/// <summary>
/// Create aset of <see cref="VertexBuffer"/>.
/// </summary>
@@ -52,5 +83,6 @@ namespace StgSharp.Graphics
{
return new VertexBuffer(count, gl);
}
}
}
@@ -1,4 +1,34 @@
using StgSharp;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 System;
using System.Collections.Generic;
@@ -10,6 +40,12 @@ namespace StgSharp.Graphics
{
public partial class Form
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected Shader CreateShader(ShaderType type, int count)
{
return new Shader(this.gl, gl.CreateShaderSet(count, type), type);
}
/// <summary>
/// Create an instance of <see cref="Shader"/> program
/// </summary>
@@ -20,18 +56,14 @@ namespace StgSharp.Graphics
return new ShaderProgram(GL);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected Shader CreateShader(ShaderType type, int count)
{
return new Shader(this.gl, gl.CreateShaderSet(count, type), type);
}
}
public class Shader
{
private readonly IglFunc GL;
internal readonly glHandleSet handle;
public readonly ShaderType type;
private readonly IglFunc GL;
internal Shader(IglFunc gl, glHandleSet handle, ShaderType usage)
{
@@ -40,17 +72,6 @@ namespace StgSharp.Graphics
type = usage;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Compile(int index, string code)
{
if (code == null)
{
throw new ArgumentNullException("Must provide enough code");
}
GL.LoadShaderSource(handle[index], code + '\0');
GL.CompileShader(handle[index]);
}
//TODO:写链接着色器的文档注释
/// <summary>
///
@@ -63,16 +84,29 @@ namespace StgSharp.Graphics
GL.AttachShader(target.handle, handle[index]);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Compile(int index, string code)
{
if (code == null)
{
throw new ArgumentNullException("Must provide enough code");
}
GL.LoadShaderSource(handle[index], $"{code}\0");
GL.CompileShader(handle[index]);
}
public override string ToString()
{
return $"This is a {type} shader, its shader handles are {handle.ToString()}.";
}
}
public class ShaderProgram
{
internal readonly glHandle handle;
private readonly IglFunc GL;
internal readonly glHandle handle;
/// <summary>
/// Inti a shader with no program attached.
@@ -83,29 +117,6 @@ namespace StgSharp.Graphics
handle = GL.CreateProgram();
}
/// <summary>
/// Link the shader to current context.
/// </summary>
public unsafe void Link()
{
if (InternalIO.InternalLinkShaderProgram(GL.Context, 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", "");
InternalIO.InternalWriteLog(log, LogType.Error);
}
catch (Exception ex)
{
InternalIO.InternalWriteLog(ex.Message, LogType.Error);
}
}
}
/// <summary>
/// Get a uniform form current shader,
/// the value type of the uniform should be provided.
@@ -145,6 +156,29 @@ namespace StgSharp.Graphics
return new Uniform<T, U, V>(this, name, GL);
}
/// <summary>
/// Link the shader to current context.
/// </summary>
public unsafe void Link()
{
if (InternalIO.InternalLinkShaderProgram(GL.Context, 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>
@@ -153,5 +187,6 @@ namespace StgSharp.Graphics
{
GL.UseProgram(handle);
}
}
}
@@ -1,4 +1,34 @@
using StgSharp.Graphics;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 System;
using System.Collections.Generic;
@@ -11,6 +41,7 @@ namespace StgSharp.Graphics.GL.ShaderEdit
{
public class ShaderGenerator
{
private List<string> codeList;
private List<ShaderFunction> usedShaderFunctions;
@@ -18,19 +49,18 @@ namespace StgSharp.Graphics.GL.ShaderEdit
{
throw new NotImplementedException();
}
}
public class ShaderFunction
{
private string name;
private List<string> codeList;
private List<ShaderParameter> inputList;
private string name;
private ShaderParameter outPut;
public int ParameterCount
{
get { return inputList.Count; }
}
public int ParameterCount => inputList.Count;
public void EmitCall(ShaderFunction function, ShaderParameter outPut, params ShaderParameter[] inputParams)
{
@@ -52,7 +82,7 @@ namespace StgSharp.Graphics.GL.ShaderEdit
throw new Exception("Provided parameters does not match function's parameter list.");
}
}
string codeLine = ""; // adding a line like " outvalue = Func(input1, input2,...); "
string codeLine = string.Empty; // adding a line like " outvalue = Func(input1, input2,...); "
if (outPut != ShaderParameter.Void)
{
codeLine += $"{outPut.name} = ";
@@ -65,13 +95,16 @@ namespace StgSharp.Graphics.GL.ShaderEdit
codeLine += ");\n";
codeList.Add(codeLine);
}
}
public class ShaderParameter
{
internal readonly InternalShaderType type;
internal readonly string name;
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)
{
@@ -80,8 +113,6 @@ namespace StgSharp.Graphics.GL.ShaderEdit
isReadOnly = false;
}
public static readonly ShaderParameter Void = new ShaderParameter("", InternalShaderType.Void);
public static bool IsSameType(ShaderParameter param1, ShaderParameter param2)
{
if (param1.type != InternalShaderType.Struct)
@@ -93,6 +124,7 @@ namespace StgSharp.Graphics.GL.ShaderEdit
throw new Exception("Struct is currently not supported.");
}
}
}
public enum InternalShaderType
@@ -1,4 +1,34 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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.Math;
using System;
using System.Collections.Generic;
@@ -11,8 +41,14 @@ namespace StgSharp.Graphics
{
public class Uniform<T> where T : struct
{
internal glSHandle id;
private IglFunc GL;
internal glSHandle id;
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
internal unsafe Uniform(
ShaderProgram program, string name, IglFunc gl)
@@ -21,18 +57,20 @@ namespace StgSharp.Graphics
id = GL.GetUniformLocation(program.handle, name);
}
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
}
public class Uniform<T, U>
where T : struct
where U : struct
{
internal glSHandle id;
private IglFunc GL;
internal glSHandle id;
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
internal unsafe Uniform(
ShaderProgram program, string name, IglFunc gl)
@@ -41,10 +79,6 @@ namespace StgSharp.Graphics
id = GL.GetUniformLocation(program.handle, name);
}
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
}
public class Uniform<T, U, V>
@@ -52,8 +86,14 @@ namespace StgSharp.Graphics
where U : struct
where V : struct
{
internal glSHandle id;
private IglFunc GL;
internal glSHandle id;
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
public unsafe Uniform(ShaderProgram program, string name, IglFunc gl)
{
@@ -61,10 +101,6 @@ namespace StgSharp.Graphics
id = GL.GetUniformLocation(program.handle, name);
}
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
}
public class Uniform<T, U, V, W>
@@ -73,8 +109,14 @@ namespace StgSharp.Graphics
where V : struct
where W : struct
{
internal glSHandle id;
private IglFunc GL;
internal glSHandle id;
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
internal unsafe Uniform(ShaderProgram program, string name, IglFunc gl)
{
@@ -82,14 +124,23 @@ namespace StgSharp.Graphics
id = GL.GetUniformLocation(program.handle, name);
}
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
}
internal partial class GLonRender : IglFunc
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
{
api->glUniform1fv(uniform.id.DirectValue, 4, &vec);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void SetValue(Uniform<Vec4d> uniform, Vec4d vec)
{
api->glUniform1fv(uniform.id.DirectValue, 4, &vec);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.SetValue(Uniform<float> uniform, float v0)
{
@@ -120,21 +171,11 @@ namespace StgSharp.Graphics
api->glUniform4f(uniform.id.DirectValue, v0, v1, v2, v3);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
{
api->glUniform1fv(uniform.id.DirectValue, 4, &vec);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void SetValue(Uniform<Vec4d> uniform, Vec4d vec)
{
api->glUniform1fv(uniform.id.DirectValue, 4, &vec);
}
}
internal unsafe partial class GLonUpdate
{
private IntPtr UniformVal1fPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal1f;
private IntPtr UniformVal1fvPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal1fv;
private IntPtr UniformVal1iPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal1i;
@@ -142,6 +183,53 @@ namespace StgSharp.Graphics
private IntPtr UniformVal3fPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal3f;
private IntPtr UniformVal4fPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal4f;
private static void UniformVal1f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform1f(*(int*)m.Read<ulong>(0), m.Read<uint>(2));
}
private static unsafe void UniformVal1fv(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default, v = default;
frameOpBuffer.TryDequeue(out m);
frameOpBuffer.TryDequeue(out v);
activatedContext->glUniform1fv(*(int*)m.Read<ulong>(0), 4, (Vec4d*)&v);
}
private static void UniformVal1i(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform1i(*(int*)m.Read<ulong>(0), m.Read<int>(2));
}
private static void UniformVal2f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform2f(*(int*)m.Read<ulong>(0), m.Read<float>(2), m.Read<float>(3));
}
private static void UniformVal3f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
IntPtr handle = IntPtr.Zero;
M128 m = default;
frameOpBuffer.TryDequeue(out handle);
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform3f(*(int*)handle, m.Read<float>(0), m.Read<float>(1), m.Read<float>(2));
}
private static void UniformVal4f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
IntPtr handle = IntPtr.Zero;
M128 m = default;
frameOpBuffer.TryDequeue(out handle);
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform4f(*(int*)handle, m.Read<float>(0), m.Read<float>(1), m.Read<float>(2), m.Read<float>(3));
}
unsafe void IglFunc.SetValue(Uniform<float, float, float> uniform, float f0, float f1, float f2)
{
frameOpBuffer.ParamEnqueue((IntPtr)uniform.id.valuePtr);
@@ -194,55 +282,9 @@ namespace StgSharp.Graphics
unsafe void IglFunc.SetValue(Uniform<Vec4d> uniform, Vec4d vec)
{
Vec4d m = vec;
frameOpBuffer.ParamEnqueue((IntPtr)uniform.id.valuePtr, (IntPtr)(Vec4d*)&m);
frameOpBuffer.ParamEnqueue((IntPtr)uniform.id.valuePtr, (IntPtr)(&m));
frameOpBuffer.MethodEnqueue(UniformVal1fvPtr);
}
private static void UniformVal1f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform1f(*(int*)m.Read<ulong>(0), m.Read<uint>(2));
}
private static unsafe void UniformVal1fv(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default, v = default;
frameOpBuffer.TryDequeue(out m);
frameOpBuffer.TryDequeue(out v);
activatedContext->glUniform1fv(*(int*)m.Read<ulong>(0), 4, (Vec4d*)&v);
}
private static void UniformVal1i(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform1i(*(int*)m.Read<ulong>(0), m.Read<int>(2));
}
private static void UniformVal2f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform2f(*(int*)m.Read<ulong>(0), m.Read<float>(2), m.Read<float>(3));
}
private static void UniformVal3f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
IntPtr handle = IntPtr.Zero;
M128 m = default;
frameOpBuffer.TryDequeue(out handle);
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform3f(*(int*)handle, m.Read<float>(0), m.Read<float>(1), m.Read<float>(2));
}
private static void UniformVal4f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
IntPtr handle = IntPtr.Zero;
M128 m = default;
frameOpBuffer.TryDequeue(out handle);
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform4f(*(int*)handle, m.Read<float>(0), m.Read<float>(1), m.Read<float>(2), m.Read<float>(3));
}
}
}
+90 -60
View File
@@ -1,4 +1,34 @@
using StgSharp.Graphics;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -67,83 +97,83 @@ namespace StgSharp
[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 = "glfwCreateWindow")] internal static extern unsafe IntPtr glfwCreateWindow(int width, int height, byte[] title, IntPtr monitor, GLFWwindow* share);
[DllImport(SSC_libname, EntryPoint = "glfwDestroyWindow")] internal static extern unsafe void glfwDestroyWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwDestroyWindow")] internal static extern unsafe void glfwDestroyWindow(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwWindowShouldClose")] internal static extern unsafe int glfwWindowShouldClose(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwWindowShouldClose")] internal static extern unsafe int glfwWindowShouldClose(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowShouldClose")] internal static extern unsafe void glfwSetWindowShouldClose(IntPtr window, int value);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowShouldClose")] internal static extern unsafe void glfwSetWindowShouldClose(GLFWwindow* window, int value);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowTitle")] internal static extern unsafe void glfwSetWindowTitle(IntPtr window, byte* title);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowTitle")] internal static extern unsafe void glfwSetWindowTitle(GLFWwindow* window, byte* title);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowIcon")] internal static extern unsafe void glfwSetWindowIcon(IntPtr window, int count, GLFWimage* images);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowIcon")] internal static extern unsafe void glfwSetWindowIcon(GLFWwindow* 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 = "glfwGetWindowPos")] internal static extern unsafe void glfwGetWindowPos(GLFWwindow* 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 = "glfwSetWindowPos")] internal static extern unsafe void glfwSetWindowPos(GLFWwindow* 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 = "glfwGetWindowSize")] internal static extern unsafe void glfwGetWindowSize(GLFWwindow* 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 = "glfwSetWindowSizeLimits")] internal static extern unsafe void glfwSetWindowSizeLimits(GLFWwindow* 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 = "glfwSetWindowAspectRatio")] internal static extern unsafe void glfwSetWindowAspectRatio(GLFWwindow* 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 = "glfwSetWindowSize")] internal static extern unsafe void glfwSetWindowSize(GLFWwindow* 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 = "glfwGetFramebufferSize")] internal static extern unsafe void glfwGetFramebufferSize(GLFWwindow* 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 = "glfwGetWindowFrameSize")] internal static extern unsafe void glfwGetWindowFrameSize(GLFWwindow* 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 = "glfwGetWindowContentScale")] internal static extern unsafe void glfwGetWindowContentScale(GLFWwindow* window, float* xscale, float* yscale);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowOpacity")] internal static extern unsafe float glfwGetWindowOpacity(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowOpacity")] internal static extern unsafe float glfwGetWindowOpacity(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowOpacity")] internal static extern unsafe void glfwSetWindowOpacity(IntPtr window, float opacity);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowOpacity")] internal static extern unsafe void glfwSetWindowOpacity(GLFWwindow* window, float opacity);
[DllImport(SSC_libname, EntryPoint = "glfwIconifyWindow")] internal static extern unsafe void glfwIconifyWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwIconifyWindow")] internal static extern unsafe void glfwIconifyWindow(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwRestoreWindow")] internal static extern unsafe void glfwRestoreWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwRestoreWindow")] internal static extern unsafe void glfwRestoreWindow(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwMaximizeWindow")] internal static extern unsafe void glfwMaximizeWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwMaximizeWindow")] internal static extern unsafe void glfwMaximizeWindow(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwShowWindow")] internal static extern unsafe void glfwShowWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwShowWindow")] internal static extern unsafe void glfwShowWindow(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwHideWindow")] internal static extern unsafe void glfwHideWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwHideWindow")] internal static extern unsafe void glfwHideWindow(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwFocusWindow")] internal static extern unsafe void glfwFocusWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwFocusWindow")] internal static extern unsafe void glfwFocusWindow(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwRequestWindowAttention")] internal static extern unsafe void glfwRequestWindowAttention(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwRequestWindowAttention")] internal static extern unsafe void glfwRequestWindowAttention(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowMonitor")] internal static extern unsafe IntPtr glfwGetWindowMonitor(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowMonitor")] internal static extern unsafe IntPtr glfwGetWindowMonitor(GLFWwindow* 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 = "glfwSetWindowMonitor")] internal static extern unsafe void glfwSetWindowMonitor(GLFWwindow* 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 = "glfwGetWindowAttrib")] internal static extern unsafe int glfwGetWindowAttrib(GLFWwindow* window, int attrib);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowAttrib")] internal static extern unsafe void glfwSetWindowAttrib(IntPtr window, int attrib, int value);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowAttrib")] internal static extern unsafe void glfwSetWindowAttrib(GLFWwindow* window, int attrib, int value);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowUserPointer")] internal static extern unsafe void glfwSetWindowUserPointer(IntPtr window, void* pointer);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowUserPointer")] internal static extern unsafe void glfwSetWindowUserPointer(GLFWwindow* window, void* pointer);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowUserPointer")] internal static extern unsafe void* glfwGetWindowUserPointer(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowUserPointer")] internal static extern unsafe void* glfwGetWindowUserPointer(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowPosCallback")] internal static extern unsafe GLFWwindowposfun glfwSetWindowPosCallback(IntPtr window, GLFWwindowposfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowPosCallback")] internal static extern unsafe GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* window, GLFWwindowposfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowSizeCallback")] internal static extern unsafe GLFWwindowsizefun glfwSetWindowSizeCallback(IntPtr window, GLFWwindowsizefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowSizeCallback")] internal static extern unsafe GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwindowsizefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowCloseCallback")] internal static extern unsafe GLFWwindowclosefun glfwSetWindowCloseCallback(IntPtr window, GLFWwindowclosefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowCloseCallback")] internal static extern unsafe GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* window, GLFWwindowclosefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowRefreshCallback")] internal static extern unsafe GLFWwindowrefreshfun glfwSetWindowRefreshCallback(IntPtr window, GLFWwindowrefreshfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowRefreshCallback")] internal static extern unsafe GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* window, GLFWwindowrefreshfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowFocusCallback")] internal static extern unsafe GLFWwindowfocusfun glfwSetWindowFocusCallback(IntPtr window, GLFWwindowfocusfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowFocusCallback")] internal static extern unsafe GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* window, GLFWwindowfocusfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowIconifyCallback")] internal static extern unsafe GLFWwindowiconifyfun glfwSetWindowIconifyCallback(IntPtr window, GLFWwindowiconifyfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowIconifyCallback")] internal static extern unsafe GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* window, GLFWwindowiconifyfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowMaximizeCallback")] internal static extern unsafe GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(IntPtr window, GLFWwindowmaximizefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowMaximizeCallback")] internal static extern unsafe GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(GLFWwindow* window, GLFWwindowmaximizefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetFramebufferSizeCallback")] internal static extern unsafe FramebuffersizeHandler glfwSetFramebufferSizeCallback(IntPtr window, IntPtr callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetFramebufferSizeCallback")] internal static extern unsafe FramebuffersizeHandler glfwSetFramebufferSizeCallback(GLFWwindow* window, IntPtr callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowContentScaleCallback")] internal static extern unsafe GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(IntPtr window, GLFWwindowcontentscalefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowContentScaleCallback")] internal static extern unsafe GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(GLFWwindow* window, GLFWwindowcontentscalefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwPollEvents")] internal static extern unsafe void glfwPollEvents();
@@ -153,9 +183,9 @@ namespace StgSharp
[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 = "glfwGetInputMode")] internal static extern unsafe int glfwGetInputMode(GLFWwindow* window, int mode);
[DllImport(SSC_libname, EntryPoint = "glfwSetInputMode")] internal static extern unsafe void glfwSetInputMode(IntPtr window, int mode, int value);
[DllImport(SSC_libname, EntryPoint = "glfwSetInputMode")] internal static extern unsafe void glfwSetInputMode(GLFWwindow* window, int mode, int value);
[DllImport(SSC_libname, EntryPoint = "glfwRawMouseMotionSupported")] internal static extern unsafe int glfwRawMouseMotionSupported();
@@ -163,13 +193,13 @@ namespace StgSharp
[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 = "glfwGetKey")] internal static extern unsafe KeyStatus glfwGetKey(GLFWwindow* window, int key);
[DllImport(SSC_libname, EntryPoint = "glfwGetMouseButton")] internal static extern unsafe int glfwGetMouseButton(IntPtr window, int button);
[DllImport(SSC_libname, EntryPoint = "glfwGetMouseButton")] internal static extern unsafe int glfwGetMouseButton(GLFWwindow* window, int button);
[DllImport(SSC_libname, EntryPoint = "glfwGetCursorPos")] internal static extern unsafe void glfwGetCursorPos(IntPtr window, double* xpos, double* ypos);
[DllImport(SSC_libname, EntryPoint = "glfwGetCursorPos")] internal static extern unsafe void glfwGetCursorPos(GLFWwindow* 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 = "glfwSetCursorPos")] internal static extern unsafe void glfwSetCursorPos(GLFWwindow* window, double xpos, double ypos);
[DllImport(SSC_libname, EntryPoint = "glfwCreateCursor")] internal static extern unsafe GLFWcursor* glfwCreateCursor(GLFWimage* image, int xhot, int yhot);
@@ -177,23 +207,23 @@ namespace StgSharp
[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 = "glfwSetCursor")] internal static extern unsafe void glfwSetCursor(GLFWwindow* window, GLFWcursor* cursor);
[DllImport(SSC_libname, EntryPoint = "glfwSetKeyCallback")] internal static extern unsafe GLFWkeyfun glfwSetKeyCallback(IntPtr window, GLFWkeyfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetKeyCallback")] internal static extern unsafe GLFWkeyfun glfwSetKeyCallback(GLFWwindow* window, GLFWkeyfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCharCallback")] internal static extern unsafe GLFWcharfun glfwSetCharCallback(IntPtr window, GLFWcharfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCharCallback")] internal static extern unsafe GLFWcharfun glfwSetCharCallback(GLFWwindow* window, GLFWcharfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCharModsCallback")] internal static extern unsafe GLFWcharmodsfun glfwSetCharModsCallback(IntPtr window, GLFWcharmodsfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCharModsCallback")] internal static extern unsafe GLFWcharmodsfun glfwSetCharModsCallback(GLFWwindow* window, GLFWcharmodsfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetMouseButtonCallback")] internal static extern unsafe GLFWmousebuttonfun glfwSetMouseButtonCallback(IntPtr window, GLFWmousebuttonfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetMouseButtonCallback")] internal static extern unsafe GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCursorPosCallback")] internal static extern unsafe GLFWcursorposfun glfwSetCursorPosCallback(IntPtr window, GLFWcursorposfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCursorPosCallback")] internal static extern unsafe GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* window, GLFWcursorposfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCursorEnterCallback")] internal static extern unsafe GLFWcursorenterfun glfwSetCursorEnterCallback(IntPtr window, GLFWcursorenterfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCursorEnterCallback")] internal static extern unsafe GLFWcursorenterfun glfwSetCursorEnterCallback(GLFWwindow* window, GLFWcursorenterfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetScrollCallback")] internal static extern unsafe GLFWscrollfun glfwSetScrollCallback(IntPtr window, GLFWscrollfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetScrollCallback")] internal static extern unsafe GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetDropCallback")] internal static extern unsafe GLFWdropfun glfwSetDropCallback(IntPtr window, GLFWdropfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetDropCallback")] internal static extern unsafe GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwJoystickPresent")] internal static extern unsafe int glfwJoystickPresent(int jid);
@@ -221,9 +251,9 @@ namespace StgSharp
[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 = "glfwSetClipboardString")] internal static extern unsafe void glfwSetClipboardString(GLFWwindow* window, byte* str);
[DllImport(SSC_libname, EntryPoint = "glfwGetClipboardString")] internal static extern unsafe byte* glfwGetClipboardString(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwGetClipboardString")] internal static extern unsafe byte* glfwGetClipboardString(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwGetTime")] internal static extern unsafe double glfwGetTime();
@@ -233,11 +263,11 @@ namespace StgSharp
[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 = "glfwMakeContextCurrent")] internal static extern unsafe void glfwMakeContextCurrent(GLFWwindow* 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 = "glfwSwapBuffers")] internal static extern unsafe void glfwSwapBuffers(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwSwapInterval")] internal static extern unsafe void glfwSwapInterval(int interval);
@@ -251,7 +281,7 @@ namespace StgSharp
//[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, IntPtr window, VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
//[DllImport(InternalIO.SSC_libname, EntryPoint = "glfwCreateWindowSurface")] internal extern unsafe static VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window, VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
#endregion api call
}
+211 -25
View File
@@ -1,4 +1,34 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glApiManager.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;
@@ -11,6 +41,7 @@ namespace StgSharp.Graphics
{
public static partial class glManager
{
private const int glExtension = 0x1f03;
private const int glVersion = 0x1f02;
@@ -63,7 +94,7 @@ namespace StgSharp.Graphics
{
if (coreVersion.Contains(branch))
{
coreVersion.Replace(branch, "");
coreVersion.Replace(branch, string.Empty);
}
}
string[] versionSep = coreVersion.Split('.');
@@ -99,7 +130,10 @@ namespace StgSharp.Graphics
}
catch (Exception ex)
{
if (ex.Message != "Final Version") throw;
if (ex.Message != "Final Version")
{
throw;
}
}
IntPtr strPtr = context->glGetString(glExtension);
@@ -763,27 +797,178 @@ namespace StgSharp.Graphics
internal static void CheckCoreVersion(int majorVersion, int minorVersion)
{
if ((majorVersion >= 1) || (majorVersion == 1 && minorVersion == 0)) core10 = true; else goto log;
if ((majorVersion >= 1) || (majorVersion == 1 && minorVersion == 1)) core11 = true; else goto log;
if ((majorVersion >= 1) || (majorVersion == 1 && minorVersion == 2)) core12 = true; else goto log;
if ((majorVersion >= 1) || (majorVersion == 1 && minorVersion == 3)) core13 = true; else goto log;
if ((majorVersion >= 1) || (majorVersion == 1 && minorVersion == 4)) core14 = true; else goto log;
if ((majorVersion >= 1) || (majorVersion == 1 && minorVersion == 5)) core15 = true; else goto log;
if ((majorVersion >= 2) || (majorVersion == 2 && minorVersion == 0)) core20 = true; else goto log;
if ((majorVersion >= 2) || (majorVersion == 2 && minorVersion == 1)) core21 = true; else goto log;
if ((majorVersion >= 3) || (majorVersion == 3 && minorVersion == 0)) core30 = true; else goto log;
if ((majorVersion >= 3) || (majorVersion == 3 && minorVersion == 1)) core31 = true; else goto log;
if ((majorVersion >= 3) || (majorVersion == 3 && minorVersion == 2)) core32 = true; else goto log;
if ((majorVersion >= 3) || (majorVersion == 3 && minorVersion == 3)) core33 = true; else goto log;
if ((majorVersion >= 4) || (majorVersion == 4 && minorVersion == 0)) core40 = true; else goto log;
if ((majorVersion >= 4) || (majorVersion == 4 && minorVersion == 1)) core41 = true; else goto log;
if ((majorVersion >= 4) || (majorVersion == 4 && minorVersion == 2)) core42 = true; else goto log;
if ((majorVersion >= 4) || (majorVersion == 4 && minorVersion == 3)) core43 = true; else goto log;
if ((majorVersion >= 4) || (majorVersion == 4 && minorVersion == 4)) core44 = true; else goto log;
if ((majorVersion >= 4) || (majorVersion == 4 && minorVersion == 5)) core45 = true; else goto log;
if ((majorVersion >= 4) || (majorVersion == 4 && minorVersion == 6)) core46 = true; else goto log;
if ((majorVersion >= 1) || ((majorVersion == 1) && (minorVersion == 0)))
{
core10 = true;
}
else
{
goto log;
}
log:
if ((majorVersion >= 1) || ((majorVersion == 1) && (minorVersion == 1)))
{
core11 = true;
}
else
{
goto log;
}
if ((majorVersion >= 1) || ((majorVersion == 1) && (minorVersion == 2)))
{
core12 = true;
}
else
{
goto log;
}
if ((majorVersion >= 1) || ((majorVersion == 1) && (minorVersion == 3)))
{
core13 = true;
}
else
{
goto log;
}
if ((majorVersion >= 1) || ((majorVersion == 1) && (minorVersion == 4)))
{
core14 = true;
}
else
{
goto log;
}
if ((majorVersion >= 1) || ((majorVersion == 1) && (minorVersion == 5)))
{
core15 = true;
}
else
{
goto log;
}
if ((majorVersion >= 2) || ((majorVersion == 2) && (minorVersion == 0)))
{
core20 = true;
}
else
{
goto log;
}
if ((majorVersion >= 2) || ((majorVersion == 2) && (minorVersion == 1)))
{
core21 = true;
}
else
{
goto log;
}
if ((majorVersion >= 3) || ((majorVersion == 3) && (minorVersion == 0)))
{
core30 = true;
}
else
{
goto log;
}
if ((majorVersion >= 3) || ((majorVersion == 3) && (minorVersion == 1)))
{
core31 = true;
}
else
{
goto log;
}
if ((majorVersion >= 3) || ((majorVersion == 3) && (minorVersion == 2)))
{
core32 = true;
}
else
{
goto log;
}
if ((majorVersion >= 3) || ((majorVersion == 3) && (minorVersion == 3)))
{
core33 = true;
}
else
{
goto log;
}
if ((majorVersion >= 4) || ((majorVersion == 4) && (minorVersion == 0)))
{
core40 = true;
}
else
{
goto log;
}
if ((majorVersion >= 4) || ((majorVersion == 4) && (minorVersion == 1)))
{
core41 = true;
}
else
{
goto log;
}
if ((majorVersion >= 4) || ((majorVersion == 4) && (minorVersion == 2)))
{
core42 = true;
}
else
{
goto log;
}
if ((majorVersion >= 4) || ((majorVersion == 4) && (minorVersion == 3)))
{
core43 = true;
}
else
{
goto log;
}
if ((majorVersion >= 4) || ((majorVersion == 4) && (minorVersion == 4)))
{
core44 = true;
}
else
{
goto log;
}
if ((majorVersion >= 4) || ((majorVersion == 4) && (minorVersion == 5)))
{
core45 = true;
}
else
{
goto log;
}
if ((majorVersion >= 4) || ((majorVersion == 4) && (minorVersion == 6)))
{
core46 = true;
}
else
{
goto log;
}
log:
{
InternalIO.InternalWriteLog("Find core OpenGL version.", LogType.Info);
return;
@@ -794,7 +979,7 @@ namespace StgSharp.Graphics
{
if (context.glGetString == null)
{
return "";
return string.Empty;
}
return Marshal.PtrToStringAnsi(
context.glGetString(glExtension));
@@ -812,7 +997,7 @@ namespace StgSharp.Graphics
catch (Exception ex)
{
InternalIO.InternalWriteLog(
$"Failed to convert the api {typeof(T).Name}.\n" + ex.Message, LogType.Warning);
$"{($"Failed to convert the api {typeof(T).Name}.\n")}{ex.Message}", LogType.Warning);
return default;
}
}
@@ -1781,5 +1966,6 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.6 APIs");
}
}
}
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
+75 -43
View File
@@ -1,4 +1,34 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IglFunc.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.Concurrent;
@@ -8,6 +38,12 @@ namespace StgSharp.Graphics
{
public interface IglFunc
{
internal unsafe GLcontext* Context
{
get;
}
/// <summary>
/// Same function as OpenGL api glActiveTexture
/// </summary>
@@ -86,18 +122,14 @@ namespace StgSharp.Graphics
void ClearGraphicError();
void CompileShader(glHandle shaderhandle);
/// <summary>
/// Same function as OpenGL api, glCreateProgram
/// </summary>
/// <returns>A handle representing a single shader program</returns>
glHandle CreateProgram();
glHandleSet CreateShaderSet(int count, ShaderType type);
void LoadShaderSource(glHandle shaderHandle, string codeStream);
void CompileShader(glHandle shaderhandle);
/// <summary>
/// Same function as OpenGL api, glCreateProgram.
/// Used for creating multiple shader program.
@@ -105,6 +137,8 @@ namespace StgSharp.Graphics
/// <returns>A handle representing all shader programs</returns>
glHandleSet CreateProgram(int count);
glHandleSet CreateShaderSet(int count, ShaderType type);
/// <summary>
/// Creates a form and its associated
/// </summary>
@@ -174,6 +208,8 @@ namespace StgSharp.Graphics
bool GetWindowShouldClose(Form form);
void LoadShaderSource(glHandle shaderHandle, string codeStream);
/// <summary>
/// Make the OpenGL context of a certain <see cref="Form"/> as the activated OpenGL context.
/// </summary>
@@ -184,17 +220,6 @@ namespace StgSharp.Graphics
void SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage) where T : struct, IConvertible;
/// <summary>
/// Set data value to a float <see cref="Uniform{T,U,V,W}"/>,
/// all types of parameters are float.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T,U,V,W}"/> target</param>
/// <param name="v0">The first value to be set</param>
/// <param name="v1">The second value to be set</param>
/// <param name="v2">The third value to be set</param>
/// <param name="v3">The forth value to be set</param>
void SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3);
/// <summary>
/// Set data value to a float <see cref="Uniform{T,U,V,W}"/>,
/// all types of parameters are float.
@@ -203,25 +228,6 @@ namespace StgSharp.Graphics
/// <param name="vec">A <see cref="Vec4d"/> packing four parameters of the uniform </param>
void SetValue(Uniform<float, float, float, float> uniform, Vec4d vec);
/// <summary>
/// Set data value to a float <see cref="Uniform{T,U,V}"/>,
/// all types of parameters are float.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T,U,V}"/> target</param>
/// <param name="v0">The first value to be set</param>
/// <param name="v1">The second value to be set</param>
/// <param name="v2">The third value to be set</param>
void SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2);
/// <summary>
/// Set data value to a float <see cref="Uniform{T,U}"/>,
/// all types of parameters are float.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T,U}"/> target</param>
/// <param name="v0">The first value to be set</param>
/// <param name="v1">The second value to be set</param>
void SetValue(Uniform<float, float> uniform, float v0, float v1);
/// <summary>
/// Set data value to a float <see cref="Uniform{T}"/>,
/// all types of parameters are float.
@@ -246,6 +252,36 @@ namespace StgSharp.Graphics
/// <param name="vec">A <see cref="Vec4d"/> value of the uniform </param>
void SetValue(Uniform<Vec4d> uniform, Vec4d vec);
/// <summary>
/// Set data value to a float <see cref="Uniform{T,U}"/>,
/// all types of parameters are float.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T,U}"/> target</param>
/// <param name="v0">The first value to be set</param>
/// <param name="v1">The second value to be set</param>
void SetValue(Uniform<float, float> uniform, float v0, float v1);
/// <summary>
/// Set data value to a float <see cref="Uniform{T,U,V}"/>,
/// all types of parameters are float.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T,U,V}"/> target</param>
/// <param name="v0">The first value to be set</param>
/// <param name="v1">The second value to be set</param>
/// <param name="v2">The third value to be set</param>
void SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2);
/// <summary>
/// Set data value to a float <see cref="Uniform{T,U,V,W}"/>,
/// all types of parameters are float.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T,U,V,W}"/> target</param>
/// <param name="v0">The first value to be set</param>
/// <param name="v1">The second value to be set</param>
/// <param name="v2">The third value to be set</param>
/// <param name="v3">The forth value to be set</param>
void SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3);
/// <summary>
/// Set how a shader parameter read data from a VBO.
/// </summary>
@@ -293,13 +329,9 @@ namespace StgSharp.Graphics
/// <param name="height"></param>
void Viewport(int x, int y, uint width, uint height);
internal void frameworkHandleEnqueue(IntPtr handle, params M128[] param);
internal void SwitchContext();
internal unsafe GLcontext* Context
{
get;
}
internal void frameworkHandleEnqueue(IntPtr handle, params M128[] param);
}
}
+49 -13
View File
@@ -1,4 +1,34 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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.Math;
using System;
using System.Collections.Generic;
@@ -12,21 +42,10 @@ namespace StgSharp.Graphics
{
public class Image
{
[StructLayout(LayoutKind.Sequential)]
internal struct ImageInfo
{
internal int width;
internal int height;
internal int channel;
internal IntPtr pixelPtr;
}
internal glHandle pixelArrayHandle;
internal ImageInfo info;
public int Width { get => info.width; }
public int Height { get => info.height; }
public int Channel { get => info.channel; }
internal glHandle pixelArrayHandle;
internal Image(ImageInfo information)
{
@@ -40,9 +59,26 @@ namespace StgSharp.Graphics
info = new ImageInfo();
}
public int Channel => info.channel;
public int Height => info.height;
public int Width => info.width;
~Image()
{
Marshal.FreeHGlobal(info.pixelPtr);
}
[StructLayout(LayoutKind.Sequential)]
internal struct ImageInfo
{
internal int width;
internal int height;
internal int channel;
internal IntPtr pixelPtr;
}
}
}