daily update on 20230911 by nitload youmu, uncertain bug of gl api loading
This commit is contained in:
@@ -17,7 +17,7 @@ namespace StgSharp.Graphics
|
||||
public unsafe class Form
|
||||
{
|
||||
|
||||
internal long windowID; //pointer to the form
|
||||
internal IntPtr windowID; //pointer to the form
|
||||
internal formInfo info = new formInfo() ;
|
||||
internal IntPtr shader;
|
||||
internal LinkedList<Pool> allControl;
|
||||
|
||||
@@ -354,7 +354,7 @@ namespace StgSharp.Graphics
|
||||
internal const uint _GLFW_POLL_BUTTONS = 2;
|
||||
internal const uint _GLFW_POLL_ALL = (_GLFW_POLL_AXES | _GLFW_POLL_BUTTONS);
|
||||
internal const uint _GLFW_MESSAGE_SIZE = 1024;
|
||||
internal const uint GL_VERSION = 0x1f02;
|
||||
internal const int GL_VERSION = 0x1f02;
|
||||
internal const uint GL_NONE = 0;
|
||||
internal const uint GL_COLOR_BUFFER_BIT = 0x00004000;
|
||||
internal const uint GL_UNSIGNED_BYTE = 0x1401;
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace StgSharp.Graphics
|
||||
using GLFWbool = Boolean;
|
||||
|
||||
//strucs defined in glfw3.h
|
||||
#region glfw3 struct
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public unsafe struct GLFWcontext
|
||||
@@ -31,8 +32,8 @@ namespace StgSharp.Graphics
|
||||
void (* makeCurrent) (_GLFWwindow*);
|
||||
void (* swapBuffers) (_GLFWwindow*);
|
||||
void (* swapInterval) (int);
|
||||
int (* extensionSupported) (const char*);
|
||||
GLFWglproc(*getProcAddress)(const char*);
|
||||
int (* extensionSupported) (const byte*);
|
||||
GLFWglproc(*getProcAddress)(const byte*);
|
||||
void (* destroy) (_GLFWwindow*);
|
||||
*/
|
||||
|
||||
@@ -159,7 +160,7 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWmonitor
|
||||
{
|
||||
|
||||
char[] name = new char[128];
|
||||
byte[] name = new byte[128];
|
||||
void* userPointer;
|
||||
|
||||
// Physical dimensions in millimeters.
|
||||
@@ -210,8 +211,10 @@ namespace StgSharp.Graphics
|
||||
public bool stickyMouseButtons = false;
|
||||
public bool lockKeyMods = false;
|
||||
public int cursorMode = 0;
|
||||
public char[] mouseButtons = new char[8];
|
||||
public char[] keys = new char[349];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
||||
public byte[] mouseButtons = new byte[8];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 349)]
|
||||
public byte[] keys = new byte[349];
|
||||
// Virtual cursor position when cursor is disabled
|
||||
public double virtualCursorPosX = 0, virtualCursorPosY = 0;
|
||||
public bool rawMouseMotion = false;
|
||||
@@ -242,7 +245,8 @@ namespace StgSharp.Graphics
|
||||
//_GLFWerror* next;
|
||||
IntPtr next;
|
||||
int code;
|
||||
char[] description = new char[GLFW._GLFW_MESSAGE_SIZE];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)GLFW._GLFW_MESSAGE_SIZE)]
|
||||
byte[] description = new byte[GLFW._GLFW_MESSAGE_SIZE];
|
||||
|
||||
public GLFWerror()
|
||||
{
|
||||
@@ -281,7 +285,7 @@ namespace StgSharp.Graphics
|
||||
int ypos;
|
||||
int width;
|
||||
int height;
|
||||
char* title;
|
||||
byte* title;
|
||||
GLFWbool resizable;
|
||||
GLFWbool visible;
|
||||
GLFWbool decorated;
|
||||
@@ -296,7 +300,8 @@ namespace StgSharp.Graphics
|
||||
internal struct Ns
|
||||
{
|
||||
GLFWbool retina = false;
|
||||
char[] frameName = new char[256];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
|
||||
byte[] frameName = new byte[256];
|
||||
|
||||
public Ns()
|
||||
{
|
||||
@@ -306,8 +311,10 @@ namespace StgSharp.Graphics
|
||||
|
||||
internal struct X11
|
||||
{
|
||||
char[] className = new char[256];
|
||||
char[] instanceName = new char[256];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
|
||||
byte[] className = new byte[256];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
|
||||
byte[] instanceName = new byte[256];
|
||||
|
||||
public X11()
|
||||
{
|
||||
@@ -323,7 +330,8 @@ namespace StgSharp.Graphics
|
||||
|
||||
internal struct Wl
|
||||
{
|
||||
char[] appId = new char[256];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
|
||||
byte[] appId = new byte[256];
|
||||
|
||||
public Wl()
|
||||
{
|
||||
@@ -416,6 +424,7 @@ namespace StgSharp.Graphics
|
||||
|
||||
|
||||
GLFWbool joysticksInitialized;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = GLFW.GLFW_JOYSTICK_LAST + 1)]
|
||||
_GLFWjoystick[] joysticks = new _GLFWjoystick[GLFW.GLFW_JOYSTICK_LAST + 1];
|
||||
//_GLFWmapping* mappings;
|
||||
IntPtr mappings;
|
||||
@@ -501,7 +510,8 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
GLFWbool available;
|
||||
void* handle;
|
||||
char*[] extensions = new char*[2];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
|
||||
byte*[] extensions = new byte*[2];
|
||||
IntPtr GetInstanceProcAddr;
|
||||
GLFWbool KHR_surface;
|
||||
GLFWbool KHR_win32_surface;
|
||||
@@ -543,9 +553,13 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct _GLFWmapping
|
||||
{
|
||||
|
||||
char[] name = new char[128];
|
||||
char[] guid = new char[33];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
|
||||
byte[] name = new byte[128];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 33)]
|
||||
byte[] guid = new byte[33];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)]
|
||||
_GLFWmapelement[] buttons = new _GLFWmapelement[15];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
|
||||
_GLFWmapelement[] axes = new _GLFWmapelement[6];
|
||||
|
||||
public _GLFWmapping() { }
|
||||
@@ -563,9 +577,11 @@ namespace StgSharp.Graphics
|
||||
int buttonCount;
|
||||
byte* hats;
|
||||
int hatCount;
|
||||
char[] name = new char[128];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
|
||||
byte[] name = new byte[128];
|
||||
void* userPointer;
|
||||
char[] guid = new char[33];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 33)]
|
||||
byte[] guid = new byte[33];
|
||||
//_GLFWmapping* mapping;
|
||||
IntPtr mapping;
|
||||
|
||||
@@ -605,15 +621,15 @@ namespace StgSharp.Graphics
|
||||
GLFWbool(*createStandardCursor)(_GLFWcursor*, int);
|
||||
void (* destroyCursor) (_GLFWcursor*);
|
||||
void (* setCursor) (_GLFWwindow*, _GLFWcursor*);
|
||||
const char* (*getScancodeName)(int);
|
||||
const byte* (*getScancodeName)(int);
|
||||
int (* getKeyScancode) (int);
|
||||
void (* setClipboardString) (const char*);
|
||||
const char* (*getClipboardString)(void);
|
||||
void (* setClipboardString) (const byte*);
|
||||
const byte* (*getClipboardString)(void);
|
||||
GLFWbool(*initJoysticks)(void);
|
||||
void (* terminateJoysticks) (void);
|
||||
GLFWbool(*pollJoystick)(_GLFWjoystick*, int);
|
||||
const char* (*getMappingName)(void);
|
||||
void (* updateGamepadGUID) (char*);
|
||||
const byte* (*getMappingName)(void);
|
||||
void (* updateGamepadGUID) (byte*);
|
||||
// monitor
|
||||
void (* freeMonitor) (_GLFWmonitor*);
|
||||
void (* getMonitorPos) (_GLFWmonitor*, int*, int*);
|
||||
@@ -626,7 +642,7 @@ namespace StgSharp.Graphics
|
||||
// window
|
||||
GLFWbool(*createWindow)(_GLFWwindow*,const _GLFWwndconfig*,const _GLFWctxconfig*,const _GLFWfbconfig*);
|
||||
void (* destroyWindow) (_GLFWwindow*);
|
||||
void (* setWindowTitle) (_GLFWwindow*,const char*);
|
||||
void (* setWindowTitle) (_GLFWwindow*,const byte*);
|
||||
void (* setWindowIcon) (_GLFWwindow*, int,const GLFWimage*);
|
||||
void (* getWindowPos) (_GLFWwindow*, int*, int*);
|
||||
void (* setWindowPos) (_GLFWwindow*, int, int);
|
||||
@@ -739,7 +755,7 @@ namespace StgSharp.Graphics
|
||||
|
||||
|
||||
// vulkan
|
||||
//void (* getRequiredInstanceExtensions) (char**);
|
||||
//void (* getRequiredInstanceExtensions) (byte**);
|
||||
//GLFWbool(*getPhysicalDevicePresentationSupport)(VkInstance, VkPhysicalDevice, uint32_t);
|
||||
//VkResult(*createWindowSurface)(VkInstance, _GLFWwindow*,const VkAllocationCallbacks*, VkSurfaceKHR*);
|
||||
internal IntPtr getRequiredInstanceExtensions;
|
||||
@@ -760,7 +776,8 @@ namespace StgSharp.Graphics
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal unsafe struct VkExtensionProperties
|
||||
{
|
||||
char[] extensionName = new char[256];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
|
||||
byte[] extensionName = new byte[256];
|
||||
uint specVersion;
|
||||
|
||||
public VkExtensionProperties()
|
||||
@@ -773,7 +790,8 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
IntPtr next;
|
||||
int code;
|
||||
char[] description = new char[1024];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]
|
||||
byte[] description = new byte[1024];
|
||||
|
||||
public _GLFWerror()
|
||||
{
|
||||
@@ -789,8 +807,17 @@ namespace StgSharp.Graphics
|
||||
[FieldOffset(8)]
|
||||
long part2;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region glad struct
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct GLsync
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using StgSharp.Control;
|
||||
using StgSharp.Controlling;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp
|
||||
@@ -21,22 +22,24 @@ namespace StgSharp
|
||||
/// <param name="share"></param>
|
||||
/// <returns>The instance of created form</returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public static unsafe Form GLcreateWindow(int width, int height, byte[] tittle, IntPtr monitor, Form share)
|
||||
public static unsafe Form GLcreateWindow(
|
||||
int width, int height, string tittle, IntPtr monitor, Form share)
|
||||
{
|
||||
byte[] tittleBytes = Encoding.UTF8.GetBytes(tittle);
|
||||
IntPtr windowPtr;
|
||||
if (share == null)
|
||||
{
|
||||
windowPtr = glIO.internalGLcreateWindow(
|
||||
width, height, tittle, monitor, (IntPtr)0);
|
||||
windowPtr = internalIO.glfwCreateWindow(
|
||||
800, 600, tittleBytes, monitor, IntPtr.Zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
windowPtr = glIO.internalGLcreateWindow(
|
||||
width, height, tittle, monitor, (IntPtr)share.windowID);
|
||||
windowPtr = internalIO.glfwCreateWindow(
|
||||
width, height, tittleBytes, monitor, share.windowID);
|
||||
}
|
||||
|
||||
|
||||
if ((int)windowPtr == -1 || (int)windowPtr == -2)
|
||||
if ((long)windowPtr == -1 || (long)windowPtr == -2)
|
||||
{
|
||||
throw new Exception("Cannot create window instance!");
|
||||
}
|
||||
@@ -44,7 +47,7 @@ namespace StgSharp
|
||||
{
|
||||
Form form = new Form();
|
||||
form.Size = new Vec2d(width, height);
|
||||
form.windowID = (long)windowPtr;
|
||||
form.windowID = windowPtr;
|
||||
return form;
|
||||
}
|
||||
}
|
||||
@@ -62,7 +65,7 @@ namespace StgSharp
|
||||
public static unsafe Form GLcreateWindow(int width, int height, string tittle, IntPtr monitor, IntPtr share)
|
||||
{
|
||||
byte[] tittleCharArray = System.Text.Encoding.UTF8.GetBytes(tittle);
|
||||
long windowPtr = (long)glIO.internalGLcreateWindow
|
||||
IntPtr windowPtr = internalIO.glfwCreateWindow
|
||||
(width, height, tittleCharArray, monitor, share);
|
||||
|
||||
if ((int)windowPtr == -1 || (int)windowPtr == -2)
|
||||
@@ -81,20 +84,38 @@ namespace StgSharp
|
||||
|
||||
public static unsafe void GLmakeContexCurrent(Form form)
|
||||
{
|
||||
glIO.internalGLmakeContextCurrent((IntPtr)form.windowID);
|
||||
internalIO.glfwMakeContextCurrent(form.windowID);
|
||||
}
|
||||
|
||||
|
||||
public static unsafe bool GLwindowShouldClose(Form form)
|
||||
{
|
||||
int a = glIO.internalGLwindowShouldClose((IntPtr)form.windowID);
|
||||
int a = internalIO.glfwWindowShouldClose(form.windowID);
|
||||
return a != 0;
|
||||
}
|
||||
|
||||
|
||||
public static unsafe void GLswapBuffers(Form form)
|
||||
{
|
||||
glIO.internalGLswapBuffers((IntPtr)form.windowID);
|
||||
internalIO.glfwSwapBuffers(form.windowID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static IntPtr GetProcAddress(string name)
|
||||
{
|
||||
IntPtr ret = internalIO.glfwGetProcAddress(name);
|
||||
if (ret == IntPtr.Zero)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine(name);
|
||||
#endif
|
||||
return (IntPtr)0b1111111111;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2677
-5
File diff suppressed because it is too large
Load Diff
@@ -1,33 +1,16 @@
|
||||
using StgSharp.Control;
|
||||
using StgSharp.Controlling;
|
||||
using StgSharp.Graphics;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public static unsafe partial class Graphic
|
||||
{
|
||||
internal static GraphicIOPack glIO;
|
||||
private static bool isGLSet = false;
|
||||
private static bool isGLADset = false;
|
||||
private static bool isGLready = false;
|
||||
|
||||
/// <summary>
|
||||
/// Load OpenGL API to StgSharp core programm,
|
||||
/// please call this method before call any other
|
||||
/// graphic APIs in StgSharp.
|
||||
/// </summary>
|
||||
/// <exception cref="Exception">If run this method twice, will throw exception</exception>
|
||||
public static unsafe void LoadGL()
|
||||
{
|
||||
if (!isGLADset)
|
||||
{
|
||||
glIO = internalIO.InternalInitGraphicApi();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Do not load GL api twice.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -35,11 +18,11 @@ namespace StgSharp
|
||||
/// This method should be called before other
|
||||
/// graphic methods, after LoadGL method.
|
||||
/// </summary>
|
||||
public static void InitGL()
|
||||
public static void InitGL(int majorVersion, int minorVersion)
|
||||
{
|
||||
if (!isGLSet)
|
||||
{
|
||||
internalIO.InternalInitGL();
|
||||
internalIO.InternalInitGL(majorVersion, minorVersion);
|
||||
isGLready = isGLSet && isGLADset;
|
||||
}
|
||||
else
|
||||
@@ -48,7 +31,7 @@ namespace StgSharp
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Attach GLFW API to GLAD,
|
||||
@@ -56,19 +39,22 @@ namespace StgSharp
|
||||
/// and before other graphic method.
|
||||
/// </summary>
|
||||
/// <exception cref="Exception">The accident that program cannot attach GLFW to GLAD</exception>
|
||||
public static unsafe void InitGLAD()
|
||||
public static unsafe void InitGLAD(glLoader loader)
|
||||
{
|
||||
|
||||
|
||||
if (!isGLADset)
|
||||
{
|
||||
int a = internalIO.InternalInitGLAD();
|
||||
if (a != 0)
|
||||
if (a == 0)
|
||||
{
|
||||
throw new Exception("Cannot attach GLFW to GLAD!");
|
||||
}
|
||||
else
|
||||
{
|
||||
isGLready = isGLSet && isGLADset;
|
||||
|
||||
LoadGLLoader(loader);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -110,7 +96,7 @@ namespace StgSharp
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user