//
// GLFW.cs
//
// Copyright (C) 2018 OpenTK
//
// This software may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
//
using System;
using System.Runtime.InteropServices;
using static OpenToolkit.GraphicsLibraryFramework.GLFWNative;
using static Robust.Shared.Utility.MarshalHelper;
namespace OpenToolkit.GraphicsLibraryFramework
{
///
/// Provides access to the GLFW API.
///
public static class GLFW
{
// XML-documentation is from https://www.glfw.org/docs/latest/
// Still missing in documentation
///
/// Gets an integer equal to GLFW_DONT_CARE. This can be used for several window hints to use the platform default.
///
public const int DontCare = -1;
///
///
/// This function initialwizes the GLFW library. Before most GLFW functions can be used,
/// GLFW must be initialized, and before an application terminates GLFW should be terminated in order to
/// free any resources allocated during or after initialization.
///
///
/// If this function fails, it calls before returning.
///
///
/// If it succeeds, you should call before the application exits.
///
///
/// Additional calls to this function after successful initialization
/// but before termination will return true immediately.
///
///
/// true if successful, or false if an error occurred.
///
///
/// OS X: This function will change the current directory of the application
/// to the Contents/Resources subdirectory of the application's bundle, if present.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static bool Init() => glfwInit() == GLFW_TRUE;
///
///
/// This function destroys all remaining windows and cursors, restores any modified gamma ramps
/// and frees any other allocated resources. Once this function is called,
/// you must again call successfully before you will be able to use most GLFW functions.
///
///
/// If GLFW has been successfully initialized, this function should be called before the application exits.
///
///
/// If initialization fails, there is no need to call this function,
/// as it is called by before it returns failure.
///
///
///
///
/// The contexts of any remaining windows must not be current on any other thread when this function is called.
///
///
/// This function may be called before .
///
///
/// This function must not be called from a callback.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static void Terminate() => glfwTerminate();
///
///
/// This function sets hints for the next initialization of GLFW.
///
///
/// The values you set hints to are never reset by GLFW, but they only take effect during initialization.
///
///
/// Once GLFW has been initialized,
/// any values you set will be ignored until the library is terminated and initialized again.
///
/// Some hints are platform specific.
/// These may be set on any platform but they will only affect their specific platform.
/// Other platforms will ignore them. Setting these hints requires no platform specific headers or functions.
///
///
/// The to set.
/// The new value of the .
///
///
/// This function may be called before .
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static void InitHint(InitHintBool hintBool, bool value) =>
glfwInitHint((int)hintBool, value ? GLFW_TRUE : GLFW_FALSE);
///
///
/// This function sets hints for the next initialization of GLFW.
///
///
/// The values you set hints to are never reset by GLFW, but they only take effect during initialization.
///
///
/// Once GLFW has been initialized,
/// any values you set will be ignored until the library is terminated and initialized again.
///
/// Some hints are platform specific.
/// These may be set on any platform but they will only affect their specific platform.
/// Other platforms will ignore them. Setting these hints requires no platform specific headers or functions.
///
///
/// The to set.
/// The new value of the .
///
///
/// This function may be called before .
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static void InitHint(InitHintInt hintInt, int value) => glfwInitHint((int)hintInt, value);
///
///
/// This function retrieves the major, minor and revision numbers of the GLFW library.
/// It is intended for when you are using GLFW
/// as a shared library and want to ensure that you are using the minimum required version.
///
///
/// Any or all of the version arguments may be out _.
///
///
/// Where to store the major version number, or out _.
/// Where to store the minor version number, or out _.
/// Where to store the revision number, or out _.
///
///
/// This function may be called before .
///
///
/// This function may be called from any thread.
///
///
public static unsafe void GetVersion(out int major, out int minor, out int revision)
{
int localMajor, localMinor, localRevision;
glfwGetVersion(&localMajor, &localMinor, &localRevision);
major = localMajor;
minor = localMinor;
revision = localRevision;
}
///
///
/// This function returns the compile-time generated version string of the GLFW library binary.
/// It describes the version, platform, compiler and any platform-specific compile-time options.
/// It should not be confused with the OpenGL or OpenGL ES version string, queried with glGetString.
///
///
/// Do not use the version string to parse the GLFW library version.
/// The function provides the version of the running library binary in numerical format.
///
///
/// The ASCII-encoded GLFW version string.
///
///
/// This function may be called before .
///
///
/// The returned string is static and compile-time generated.
///
///
/// This function may be called from any thread.
///
///
///
public static unsafe string GetVersionString()
{
return PtrToStringUTF8(glfwGetVersionString());
}
///
///
/// This function returns the compile-time generated version string of the GLFW library binary.
/// It describes the version, platform, compiler and any platform-specific compile-time options.
/// It should not be confused with the OpenGL or OpenGL ES version string, queried with glGetString.
///
///
/// Do not use the version string to parse the GLFW library version.
/// The function provides the version of the running library binary in numerical format.
///
///
/// The ASCII-encoded GLFW version string.
///
///
/// This function may be called before .
///
///
/// The returned string is static and compile-time generated.
///
///
/// This function may be called from any thread.
///
///
///
public static unsafe byte* GetVersionStringRaw()
{
return glfwGetVersionString();
}
///
///
/// This function returns and clears the error code of the last error that occurred on the calling thread,
/// and optionally a UTF-8 encoded human-readable description of it.
///
///
/// If no error has occurred since the last call,
/// it returns (zero) and the description pointer is set to null.
///
///
/// Where to store the error description pointer, or out _"/>.
/// The last error code for the calling thread, or (zero).
///
///
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
/// It is only guaranteed to be valid until the next error occurs or the library is terminated.
///
///
/// This function may be called before .
///
///
/// This function may be called from any thread.
///
///
///
public static unsafe ErrorCode GetError(out string description)
{
byte* desc;
var code = glfwGetError(&desc);
description = PtrToStringUTF8(desc);
return code;
}
///
///
/// This function returns and clears the error code of the last error that occurred on the calling thread,
/// and optionally a UTF-8 encoded human-readable description of it.
///
///
/// If no error has occurred since the last call,
/// it returns (zero) and the description pointer is set to null.
///
///
/// Where to store the error description pointer, or out _"/>.
/// The last error code for the calling thread, or (zero).
///
///
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
/// It is only guaranteed to be valid until the next error occurs or the library is terminated.
///
///
/// This function may be called before .
///
///
/// This function may be called from any thread.
///
///
///
public static unsafe ErrorCode GetErrorRaw(out byte* description)
{
byte* desc;
var code = glfwGetError(&desc);
description = desc;
return code;
}
///
///
/// This function returns an array of handles for all currently connected monitors.
/// The primary monitor is always first in the returned array.
///
///
/// If no monitors were found, this function returns null.
///
///
///
/// Where to store the number of monitors in the returned array. This is set to zero if an error occurred.
///
///
/// An array of monitor handles, or null if no monitors were found or if an error occurred.
///
///
///
/// The returned array is allocated and freed by GLFW. You should not free it yourself.
/// It is only guaranteed to be valid until the monitor configuration changes or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
///
public static unsafe Monitor** GetMonitorsRaw(out int count)
{
fixed (int* ptr = &count)
{
return glfwGetMonitors(ptr);
}
}
///
///
/// This function returns an array of handles for all currently connected monitors.
/// The primary monitor is always first in the returned array.
///
///
/// If no monitors were found, this function returns null.
///
///
///
/// Where to store the number of monitors in the returned array. This is set to zero if an error occurred.
///
///
/// An array of monitor handles, or null if no monitors were found or if an error occurred.
///
///
///
/// The returned array is allocated and freed by GLFW. You should not free it yourself.
/// It is only guaranteed to be valid until the monitor configuration changes or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
///
public static unsafe Monitor** GetMonitorsRaw(int* count)
{
return glfwGetMonitors(count);
}
///
///
/// This function returns an array of handles for all currently connected monitors.
/// The primary monitor is always first in the returned array.
///
///
/// If no monitors were found, this function returns null.
///
///
///
/// An array of monitor handles, or null if no monitors were found or if an error occurred.
///
///
///
/// The returned array is allocated and freed by GLFW. You should not free it yourself.
/// It is only guaranteed to be valid until the monitor configuration changes or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
///
public static unsafe Monitor*[] GetMonitors()
{
var ptr = GetMonitorsRaw(out var count);
if (ptr == null)
{
return null;
}
var array = new Monitor*[count];
for (var i = 0; i < count; i++)
{
array[i] = ptr[i];
}
return array;
}
///
///
/// This function returns the position, in screen coordinates, of the upper-left corner of the specified monitor.
///
///
/// The monitor to query.
/// Where to store the monitor x-coordinate, or out _.
/// Where to store the monitor y-coordinate, or out _.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe void GetMonitorPos(Monitor* monitor, out int x, out int y)
{
int localX, localY;
glfwGetMonitorPos(monitor, &localX, &localY);
x = localX;
y = localY;
}
///
///
/// This function returns the position, in screen coordinates, of the upper-left corner of the specified monitor.
///
///
/// The monitor to query.
/// Where to store the monitor x-coordinate.
/// Where to store the monitor y-coordinate.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe void GetMonitorPos(Monitor* monitor, int* x, int* y)
{
glfwGetMonitorPos(monitor, x, y);
}
///
///
/// This function returns the size, in millimetres, of the display area of the specified monitor.
///
///
/// Some systems do not provide accurate monitor size information,
/// either because the monitor EDID(Extended Display Identification Data) data is incorrect
/// or because the driver does not report it accurately.
///
///
/// Any or all of the size arguments may be out _.
/// If an error occurs, all non-out _ size arguments will be set to zero.
///
///
/// The monitor to query.
///
/// Where to store the width, in millimetres, of the monitor's display area, or out _.
///
///
/// Where to store the height, in millimetres, of the monitor's display area, or out _.
///
///
///
/// Windows: calculates the returned physical size from the current resolution
/// and system DPI instead of querying the monitor EDID data.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static unsafe void GetMonitorPhysicalSize(Monitor* monitor, out int width, out int height)
{
int localWidth, localHeight;
glfwGetMonitorPhysicalSize(monitor, &localWidth, &localHeight);
width = localWidth;
height = localHeight;
}
///
///
/// This function retrieves the content scale for the specified monitor.
///
///
/// The content scale is the ratio between the current DPI and the platform's default DPI.
///
///
/// If you scale all pixel dimensions by this scale then your content should appear at an appropriate size.
/// This is especially important for text and any UI elements.
///
///
///
/// The content scale may depend on both the monitor resolution and pixel density and on user settings.
/// It may be very different from the raw DPI calculated from the physical size and current resolution.
///
///
/// The monitor to query.
/// Where to store the x-axis content scale, or out _.
/// Where to store the y-axis content scale, or out _.
public static unsafe void GetMonitorContentScale(Monitor* monitor, out float xScale, out float yScale)
{
float localX, localY;
glfwGetMonitorContentScale(monitor, &localX, &localY);
xScale = localX;
yScale = localY;
}
///
///
/// This function retrieves the content scale for the specified monitor.
///
///
/// The content scale is the ratio between the current DPI and the platform's default DPI.
///
///
/// If you scale all pixel dimensions by this scale then your content should appear at an appropriate size.
/// This is especially important for text and any UI elements.
///
///
///
/// The content scale may depend on both the monitor resolution and pixel density and on user settings.
/// It may be very different from the raw DPI calculated from the physical size and current resolution.
///
///
/// The monitor to query.
/// Where to store the x-axis content scale, or out _.
/// Where to store the y-axis content scale, or out _.
public static unsafe void GetMonitorContentScaleRaw(Monitor* monitor, float* xScale, float* yScale)
{
glfwGetMonitorContentScale(monitor, xScale, yScale);
}
///
///
/// This function returns a human-readable name, encoded as UTF-8, of the specified monitor.
/// The name typically reflects the make and model of the monitor
/// and is not guaranteed to be unique among the connected monitors.
///
///
/// The monitor to query.
/// The UTF-8 encoded name of the monitor, or null if an error occurred.
///
///
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified monitor is disconnected or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static unsafe string GetMonitorName(Monitor* monitor)
{
return PtrToStringUTF8(glfwGetMonitorName(monitor));
}
///
///
/// This function returns a human-readable name, encoded as UTF-8, of the specified monitor.
/// The name typically reflects the make and model of the monitor
/// and is not guaranteed to be unique among the connected monitors.
///
///
/// The monitor to query.
/// The UTF-8 encoded name of the monitor, or null if an error occurred.
///
///
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified monitor is disconnected or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static unsafe byte* GetMonitorNameRaw(Monitor* monitor)
{
return glfwGetMonitorName(monitor);
}
///
///
/// This function sets the user-defined pointer of the specified monitor.
/// The current value is retained until the monitor is disconnected.
/// The initial value is .
///
///
/// This function may be called from the monitor callback, even for a monitor that is being disconnected.
///
///
/// The monitor whose pointer to set.
/// The new value.
///
///
/// This function may be called from any thread. Access is not synchronized.
///
///
/// Possible errors include .
///
///
public static unsafe void SetMonitorUserPointer(Monitor* monitor, void* pointer)
{
glfwSetMonitorUserPointer(monitor, pointer);
}
///
///
/// This function returns the current value of the user-defined pointer of the specified monitor.
/// The initial value is .
///
///
/// This function may be called from the monitor callback, even for a monitor that is being disconnected.
///
///
/// The monitor whose pointer to return.
/// The user-defined pointer of the given .
///
///
/// This function may be called from any thread. Access is not synchronized.
///
///
/// Possible errors include .
///
///
public static unsafe void* GetMonitorUserPointer(Monitor* monitor)
{
return glfwGetMonitorUserPointer(monitor);
}
///
///
/// This function returns an array of all video modes supported by the specified monitor.
/// The returned array is sorted in ascending order, first by color bit depth (the sum of all channel depths)
/// and then by resolution area (the product of width and height).
///
///
/// The monitor to query.
///
/// Where to store the number of video modes in the returned array.
/// This is set to zero if an error occurred.
///
/// An array of video modes, or null if an error occurred.
///
///
/// The returned array is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified monitor is disconnected,
/// this function is called again for that monitor, or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static unsafe VideoMode* GetVideoModesRaw(Monitor* monitor, out int count)
{
fixed (int* ptr = &count)
{
return glfwGetVideoModes(monitor, ptr);
}
}
///
///
/// This function returns an array of all video modes supported by the specified monitor.
/// The returned array is sorted in ascending order, first by color bit depth (the sum of all channel depths)
/// and then by resolution area (the product of width and height).
///
///
/// The monitor to query.
///
/// Where to store the number of video modes in the returned array.
/// This is set to zero if an error occurred.
///
/// An array of video modes, or null if an error occurred.
///
///
/// The returned array is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified monitor is disconnected,
/// this function is called again for that monitor, or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static unsafe VideoMode* GetVideoModesRaw(Monitor* monitor, int* count)
{
return glfwGetVideoModes(monitor, count);
}
///
///
/// This function returns an array of all video modes supported by the specified monitor.
/// The returned array is sorted in ascending order, first by color bit depth (the sum of all channel depths)
/// and then by resolution area (the product of width and height).
///
///
/// The monitor to query.
/// An array of video modes, or null if an error occurred.
///
///
/// The returned array is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified monitor is disconnected,
/// this function is called again for that monitor, or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static unsafe VideoMode[] GetVideoModes(Monitor* monitor)
{
var ptr = GetVideoModesRaw(monitor, out var count);
if (ptr == null)
{
return null;
}
var array = new VideoMode[count];
for (var i = 0; i < count; i++)
{
array[i] = ptr[i];
}
return array;
}
///
///
/// This function generates a 256-element gamma ramp from the specified exponent and then calls
/// with it. The value must be a finite number greater than zero.
///
///
/// The monitor whose gamma ramp to set.
/// The desired exponent.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe void SetGamma(Monitor* monitor, float gamma)
{
glfwSetGamma(monitor, gamma);
}
///
///
/// This function returns the current gamma ramp of the specified monitor.
///
///
/// The monitor to query.
/// The current gamma ramp, or null if an error occurred.
///
///
/// The returned structure and its arrays are allocated and freed by GLFW.
/// You should not free them yourself. They are valid until the specified monitor is disconnected,
/// this function is called again for that monitor or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe GammaRamp* GetGammaRamp(Monitor* monitor)
{
return glfwGetGammaRamp(monitor);
}
///
///
/// This function sets the current gamma ramp for the specified monitor.
///
///
/// The original gamma ramp for that monitor
/// is saved by GLFW the first time this function is called and is restored by .
///
///
/// The monitor whose gamma ramp to set.
/// The gamma ramp to use.
///
///
/// Gamma ramp sizes other than 256 are not supported by all platforms or graphics hardware.
///
///
/// Windows: The gamma ramp size must be 256.
///
///
/// The specified gamma ramp is copied before this function returns.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe void SetGammaRamp(Monitor* monitor, GammaRamp* ramp)
{
glfwSetGammaRamp(monitor, ramp);
}
///
///
/// This function resets all window hints to their default values.
///
///
///
///
/// This function must only be called from the main thread.
///
///
public static void DefaultWindowHints() => glfwDefaultWindowHints();
///
///
/// Sets the specified window hint to the desired value.
///
///
/// This function sets hints for the next call to @ref glfwCreateWindow. The
/// hints, once set, retain their values until changed by a call to this
/// function or , or until the library is terminated.
///
///
/// This function does not check whether the specified hint values are valid.
/// If you set hints to invalid values this will instead be reported by the next
/// call to .
///
///
/// Some hints are platform specific. These may be set on any platform but they
/// will only affect their specific platform. Other platforms will ignore them.
/// Setting these hints requires no platform specific headers or functions.
///
///
/// The window hint to set.
/// The new value of the set hint.
///
///
/// Possible errors include .
///
///
/// The string is copied before this function returns.
///
///
/// This function must only be called from the main thread.
///
///
public static unsafe void WindowHint(WindowHintString hint, string value)
{
var ptr = StringToCoTaskMemUTF8(value);
try
{
glfwWindowHintString((int)hint, (byte*)ptr);
}
finally
{
Marshal.FreeCoTaskMem(ptr);
}
}
///
///
/// Sets the specified window hint to the desired value.
///
///
/// This function sets hints for the next call to @ref glfwCreateWindow. The
/// hints, once set, retain their values until changed by a call to this
/// function or , or until the library is terminated.
///
///
/// This function does not check whether the specified hint values are valid.
/// If you set hints to invalid values this will instead be reported by the next
/// call to .
///
///
/// Some hints are platform specific. These may be set on any platform but they
/// will only affect their specific platform. Other platforms will ignore them.
/// Setting these hints requires no platform specific headers or functions.
///
///
/// The window hint to set.
/// The new value of the set hint.
///
///
/// Possible errors include .
///
///
/// The string is copied before this function returns.
///
///
/// This function must only be called from the main thread.
///
///
public static unsafe void WindowHintRaw(WindowHintString hint, byte* value)
{
glfwWindowHintString((int)hint, value);
}
///
///
/// This function sets the size limits of the client area of the specified window.
///
///
/// If the window is full screen, the size limits only take effect once it is made windowed.
///
///
/// If the window is not resizable, this function does nothing.
///
///
/// The size limits are applied immediately to a windowed mode window and may cause it to be resized.
///
///
/// The maximum dimensions must be greater than or equal to the minimum dimensions
/// and all must be greater than or equal to zero.
///
///
/// The window to set limits for.
///
/// The minimum width, in screen coordinates, of the client area, or .
///
///
/// The minimum height, in screen coordinates, of the client area, or .
///
///
/// The maximum width, in screen coordinates, of the client area, or .
///
///
/// The maximum height, in screen coordinates, of the client area, or .
///
///
///
/// If you set size limits and an aspect ratio that conflict, the results are undefined.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe void SetWindowSizeLimits(
Window* window,
int minWidth,
int minHeight,
int maxWidth,
int maxHeight)
{
glfwSetWindowSizeLimits(window, minWidth, minHeight, maxWidth, maxHeight);
}
///
///
/// This function sets the required aspect ratio of the client area of the specified window.
///
///
/// If the window is full screen, the aspect ratio only takes effect once it is made windowed.
///
///
/// If the window is not resizable, this function does nothing.
///
///
/// The aspect ratio is specified as a numerator and a denominator and both values must be greater than zero.
/// For example, the common 16:9 aspect ratio is specified as 16 and 9, respectively.
///
///
/// If the numerator and denominator is set to then the aspect ratio limit is disabled.
///
///
/// The aspect ratio is applied immediately to a windowed mode window and may cause it to be resized.
///
///
/// The window to set limits for.
/// The numerator of the desired aspect ratio, or .
/// The denominator of the desired aspect ratio, or .
///
///
/// If you set size limits and an aspect ratio that conflict, the results are undefined.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe void SetWindowAspectRatio(Window* window, int numer, int denom)
{
glfwSetWindowAspectRatio(window, numer, denom);
}
///
///
/// This function retrieves the size, in screen coordinates, of each edge of the frame of the specified window.
///
///
/// This size includes the title bar, if the window has one.
/// The size of the frame may vary depending on the window-related hints used to create it.
///
///
///
/// Because this function retrieves the size of each window frame edge
/// and not the offset along a particular coordinate axis, the retrieved values will always be zero or positive.
///
///
///
/// Any or all of the size arguments may be out _.
/// If an error occurs, all non-out _ size arguments will be set to zero.
///
///
/// The window whose frame size to query.
///
/// Where to store the size, in screen coordinates, of the left edge of the window frame, or out _.
///
///
/// Where to store the size, in screen coordinates, of the top edge of the window frame, or out _.
///
///
/// Where to store the size, in screen coordinates, of the right edge of the window frame, or out _.
///
///
/// Where to store the size, in screen coordinates, of the bottom edge of the window frame, or out _.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe void GetWindowFrameSize(
Window* window,
out int left,
out int top,
out int right,
out int bottom)
{
int l, t, r, b;
glfwGetWindowFrameSize(window, &l, &t, &r, &b);
left = l;
top = t;
right = r;
bottom = b;
}
///
///
/// This function retrieves the content scale for the specified window.
///
///
/// The content scale is the ratio between the current DPI and the platform's default DPI.
/// This is especially important for text and any UI elements.
/// If the pixel dimensions of your UI scaled by this look appropriate on your machine then it should
/// appear at a reasonable size on other machines regardless of their DPI and scaling settings.
/// This relies on the system DPI and scaling settings being somewhat correct.
///
///
///
/// On systems where each monitors can have its own content scale,
/// the window content scale will depend on which monitor the system considers the window to be on.
///
///
/// The window to query.
///
/// Where to store the x-axis content scale, or out _.
///
///
/// Where to store the y-axis content scale, or out _.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe void GetWindowContentScale(
Window* window,
out float xScale,
out float yScale)
{
float x, y;
glfwGetWindowContentScale(window, &x, &y);
xScale = x;
yScale = y;
}
///
///
/// This function returns the opacity of the window, including any decorations.
///
///
/// The opacity (or alpha) value is a positive finite number between zero and one,
/// where zero is fully transparent and one is fully opaque.
///
///
/// If the system does not support whole window transparency, this function always returns one.
///
///
/// The initial opacity value for newly created windows is one.
///
///
/// The window to query.
/// The opacity value of the specified window.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static unsafe float GetWindowOpacity(Window* window) => glfwGetWindowOpacity(window);
///
///
/// This function sets the opacity of the window, including any decorations.
///
///
/// The opacity (or alpha) value is a positive finite number between zero and one,
/// where zero is fully transparent and one is fully opaque.
///
///
/// The initial opacity value for newly created windows is one.
///
///
/// A window created with framebuffer transparency may not use whole window transparency.
/// The results of doing this are undefined.
///
///
/// The window to set the opacity for.
/// The desired opacity of the specified window.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static unsafe void SetWindowOpacity(Window* window, float opacity)
{
glfwSetWindowOpacity(window, opacity);
}
///
///
/// This function requests user attention to the specified window.
/// On platforms where this is not supported, attention is requested to the application as a whole.
///
///
/// Once the user has given attention, usually by focusing the window or application,
/// the system will end the request automatically.
///
///
/// The window to request attention to.
///
///
/// macOS: Attention is requested to the application as a whole, not the specific window.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe void RequestWindowAttention(Window* window) => glfwRequestWindowAttention(window);
///
///
/// This function sets the value of an attribute of the specified window.
///
///
/// The supported attributes are ,
/// , ,
/// and .
///
///
/// Some of these attributes are ignored for full screen windows.
/// The new value will take effect if the window is later made windowed.
///
///
/// Some of these attributes are ignored for windowed mode windows.
/// The new value will take effect if the window is later made full screen.
///
///
/// The window to set the attribute for.
/// A supported window attribute.
/// true or false.
///
///
/// Calling will always return the latest value,
/// even if that value is ignored by the current mode of the window.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , , and .
///
///
public static unsafe void SetWindowAttrib(Window* window, WindowAttributeSetter attribute, bool value)
{
glfwSetWindowAttrib(window, attribute, value ? GLFW_TRUE : GLFW_FALSE);
}
///
///
/// This function returns whether raw mouse motion is supported on the current system.
/// This status does not change after GLFW has been initialized so you only need to check this once.
/// If you attempt to enable raw motion on a system that does not support it,
/// will be emitted.
///
///
/// Raw mouse motion is closer to the actual motion of the mouse across a surface.
/// It is not affected by the scaling and acceleration applied to the motion of the desktop cursor.
/// That processing is suitable for a cursor while raw motion is better for controlling for example a 3D camera.
/// Because of this, raw mouse motion is only provided when the cursor is disabled.
///
///
///
/// true if raw mouse motion is supported on the current machine, or false otherwise.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static bool RawMouseMotionSupported()
{
return glfwRawMouseMotionSupported() == GLFW_TRUE;
}
///
///
/// This function returns the name of the specified printable key, encoded as UTF-8.
/// This is typically the character that key would produce without any modifier keys,
/// intended for displaying key bindings to the user.
///
///
/// For dead keys, it is typically the diacritic it would add to a character.
///
///
/// Do not use this function for text input.
/// You will break text input for many languages even if it happens to work for yours.
///
///
/// If the key is , the scancode is used to identify the key, otherwise the scancode is ignored.
/// If you specify a non-printable key, or and a scancode that maps to a non-printable key,
/// this function returns null but does not emit an error.
///
///
/// This behavior allows you to always pass in the arguments in the key callback without modification.
///
///
/// The printable keys are:
///
///
///
///
///
///
///
///
///
///
///
///
///
/// - to
/// - to
/// - to
///
///
///
///
///
///
///
///
///
/// Names for printable keys depend on keyboard layout,
/// while names for non-printable keys are the same across layouts but depend on the application language
/// and should be localized along with other user interface text.
///
///
/// The key to query, or .
/// The scancode of the key to query.
/// The UTF-8 encoded, layout-specific name of the key, or null.
///
///
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the next call to , or until the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe string GetKeyName(Keys key, int scanCode)
{
return PtrToStringUTF8(glfwGetKeyName(key, scanCode));
}
///
///
/// This function returns the name of the specified printable key, encoded as UTF-8.
/// This is typically the character that key would produce without any modifier keys,
/// intended for displaying key bindings to the user.
///
///
/// For dead keys, it is typically the diacritic it would add to a character.
///
///
/// Do not use this function for text input.
/// You will break text input for many languages even if it happens to work for yours.
///
///
/// If the key is , the scancode is used to identify the key, otherwise the scancode is ignored.
/// If you specify a non-printable key, or and a scancode that maps to a non-printable key,
/// this function returns null but does not emit an error.
///
///
/// This behavior allows you to always pass in the arguments in the key callback without modification.
///
///
/// The printable keys are:
///
///
///
///
///
///
///
///
///
///
///
///
///
/// - to
/// - to
/// - to
///
///
///
///
///
///
///
///
///
/// Names for printable keys depend on keyboard layout,
/// while names for non-printable keys are the same across layouts but depend on the application language
/// and should be localized along with other user interface text.
///
///
/// The key to query, or .
/// The scancode of the key to query.
/// The UTF-8 encoded, layout-specific name of the key, or null.
///
///
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the next call to , or until the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe byte* GetKeyNameRaw(Keys key, int scancode)
{
return glfwGetKeyName(key, scancode);
}
///
///
/// This function returns the platform-specific scancode of the specified key.
///
///
/// If the key is or does not exist on the keyboard this method will return -1.
///
///
/// Any named key.
/// The platform-specific scancode for the key, or -1 if an error occurred.
///
///
/// This function may be called from any thread.
///
///
/// Possible errors include , and .
///
///
public static int GetKeyScancode(Keys key)
{
return glfwGetKeyScancode(key);
}
///
///
/// This function returns the last state reported for the specified key to the specified window.
/// The returned state is one of or .
/// The higher-level action is only reported to the key callback.
///
///
/// If the input mode is enabled, this function returns
/// the first time you call it for a key that was pressed,
/// even if that key has already been released.
///
///
/// The key functions deal with physical keys,
/// with key tokens named after their use on the standard US keyboard layout.
/// If you want to input text, use the Unicode character callback instead.
///
///
/// The modifier key bit masks are not key tokens and cannot be used with this function.
///
///
/// Do not use this function to implement text input.
///
///
/// The desired window.
///
/// The desired keyboard key. is not a valid key for this function.
///
/// One of or .
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe InputAction GetKey(Window* window, Keys key)
{
return glfwGetKey(window, key);
}
///
///
/// This function returns the last state reported for the specified mouse button to the specified window.
/// The returned state is one of or .
///
///
/// If the input mode is enabled, this function returns
/// the first time you call it for a mouse button that was pressed,
/// even if that mouse button has already been released.
///
///
/// The desired window.
/// The desired mouse button.
/// One of or .
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe InputAction GetMouseButton(Window* window, MouseButton button)
{
return glfwGetMouseButton(window, button);
}
///
///
/// This function returns the position of the cursor,
/// in screen coordinates, relative to the upper-left corner of the client area of the specified window.
///
///
/// If the cursor is disabled (with ) then the cursor position
/// is unbounded and limited only by the minimum and maximum values of a double.
///
///
/// The coordinate can be converted to their integer equivalents with the floor function.
/// Casting directly to an integer type works for positive coordinates, but fails for negative ones.
///
///
/// Any or all of the position arguments may be out _.
/// If an error occurs, all non-out _ position arguments will be set to zero.
///
///
/// The desired window.
///
/// Where to store the cursor x-coordinate, relative to the left edge of the client area, or out _.
///
///
/// Where to store the cursor y-coordinate, relative to the to top edge of the client area, or out _.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe void GetCursorPos(Window* window, out double xPos, out double yPos)
{
double x, y;
glfwGetCursorPos(window, &x, &y);
xPos = x;
yPos = y;
}
///
///
/// This function returns the position of the cursor,
/// in screen coordinates, relative to the upper-left corner of the client area of the specified window.
///
///
/// If the cursor is disabled (with ) then the cursor position
/// is unbounded and limited only by the minimum and maximum values of a double.
///
///
/// The coordinate can be converted to their integer equivalents with the floor function.
/// Casting directly to an integer type works for positive coordinates, but fails for negative ones.
///
///
/// Any or all of the position arguments may be out _.
/// If an error occurs, all non-out _ position arguments will be set to zero.
///
///
/// The desired window.
///
/// Where to store the cursor x-coordinate, relative to the left edge of the client area, or out _.
///
///
/// Where to store the cursor y-coordinate, relative to the to top edge of the client area, or out _.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe void GetCursorPosRaw(Window* window, double* xPos, double* yPos)
{
glfwGetCursorPos(window, xPos, yPos);
}
///
///
/// This function sets the position, in screen coordinates,
/// of the cursor relative to the upper-left corner of the client area of the specified window.
///
///
/// The window must have input focus.
/// If the window does not have input focus when this function is called, it fails silently.
///
///
/// Do not use this function to implement things like camera controls.
/// GLFW already provides the cursor mode that hides the cursor,
/// transparently re-centers it and provides unconstrained cursor motion.
/// See for more information.
///
///
/// If the cursor mode is then the cursor position is unconstrained
/// and limited only by the minimum and maximum values of a double.
///
///
/// The desired window.
/// The desired x-coordinate, relative to the left edge of the client area.
/// The desired y-coordinate, relative to the top edge of the client area.
///
///
/// Wayland: This function will only work when the cursor mode is ,
/// otherwise it will do nothing.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe void SetCursorPos(Window* window, double xPos, double yPos)
{
glfwSetCursorPos(window, xPos, yPos);
}
///
///
/// Creates a new custom cursor image that can be set for a window with .
///
///
/// The cursor can be destroyed with .
/// Any remaining cursors are destroyed by .
///
///
/// The pixels are 32-bit, little-endian, non-premultiplied RGBA,
/// i.e. eight bits per channel with the red channel first.
/// They are arranged canonically as packed sequential rows, starting from the top-left corner.
///
///
/// The cursor hotspot is specified in pixels, relative to the upper-left corner of the cursor image.
/// Like all other coordinate systems in GLFW, the X-axis points to the right and the Y-axis points down.
///
///
/// The desired cursor image.
/// The desired x-coordinate, in pixels, of the cursor hotspot.
/// The desired y-coordinate, in pixels, of the cursor hotspot.
/// The handle of the created cursor, or null if an error occurred.
///
///
/// The specified image data is copied before this function returns.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe Cursor* CreateCursor(in Image image, int xHot, int yHot)
{
fixed (Image* ptr = &image)
{
return CreateCursorRaw(ptr, xHot, yHot);
}
}
///
///
/// Creates a new custom cursor image that can be set for a window with .
///
///
/// The cursor can be destroyed with .
/// Any remaining cursors are destroyed by .
///
///
/// The pixels are 32-bit, little-endian, non-premultiplied RGBA,
/// i.e. eight bits per channel with the red channel first.
/// They are arranged canonically as packed sequential rows, starting from the top-left corner.
///
///
/// The cursor hotspot is specified in pixels, relative to the upper-left corner of the cursor image.
/// Like all other coordinate systems in GLFW, the X-axis points to the right and the Y-axis points down.
///
///
/// The desired cursor image.
/// The desired x-coordinate, in pixels, of the cursor hotspot.
/// The desired y-coordinate, in pixels, of the cursor hotspot.
/// The handle of the created cursor, or null if an error occurred.
///
///
/// The specified image data is copied before this function returns.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe Cursor* CreateCursorRaw(Image* image, int xHot, int yHot)
{
return glfwCreateCursor(image, xHot, yHot);
}
///
///
/// Returns a cursor with a standard shape, that can be set for a window with .
///
///
/// One of the standard shapes.
/// A new cursor ready to use or null if an error occurred.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe Cursor* CreateStandardCursor(CursorShape shape)
{
return glfwCreateStandardCursor(shape);
}
///
///
/// This function destroys a cursor previously created with .
/// Any remaining cursors will be destroyed by .
///
///
/// If the specified cursor is current for any window, that window will be reverted to the default cursor.
/// This does not affect the cursor mode.
///
///
/// The cursor object to destroy.
///
///
/// This function must not be called from a callback.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe void DestroyCursor(Cursor* cursor) => glfwDestroyCursor(cursor);
///
///
/// This function sets the cursor image to be used when the cursor is over the client area
/// of the specified window.
///
///
/// The set cursor will only be visible
/// when the cursor mode of the window is .
///
///
/// On some platforms, the set cursor may not be visible unless the window also has input focus.
///
///
/// The window to set the cursor for.
/// The cursor to set, or null to switch back to the default arrow cursor.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe void SetCursor(Window* window, Cursor* cursor)
{
glfwSetCursor(window, cursor);
}
///
///
/// This function returns whether the specified joystick is present.
///
///
/// There is no need to call this function before other functions that accept a joystick ID,
/// as they all check for presence before performing any other work.
///
///
/// The joystick to query.
/// true if the joystick is present, or false otherwise.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static bool JoystickPresent(int jid)
{
return glfwJoystickPresent(jid) == GLFW_TRUE;
}
///
///
/// This function returns the values of all axes of the specified joystick.
/// Each element in the array is a value between -1.0 and 1.0.
///
///
/// If the specified joystick is not present
/// this function will return null but will not generate an error.
/// This can be used instead of first calling .
///
///
/// The joystick to query.
///
/// An array of axis values, or null if the joystick is not present or an error occurred.
///
///
///
/// The returned array is allocated and freed by GLFW.
/// You should not free it yourself.
/// It is valid until the specified joystick is disconnected or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe float[] GetJoystickAxes(int jid)
{
var ptr = GetJoystickAxesRaw(jid, out var count);
if (ptr == null)
{
return null;
}
var array = new float[count];
for (var i = 0; i < count; i++)
{
array[i] = ptr[i];
}
return array;
}
///
///
/// This function returns the values of all axes of the specified joystick.
/// Each element in the array is a value between -1.0 and 1.0.
///
///
/// If the specified joystick is not present
/// this function will return null but will not generate an error.
/// This can be used instead of first calling .
///
///
/// The joystick to query.
///
/// Where to store the number of axis values in the returned array.
/// This is set to zero if the joystick is not present or an error occurred.
///
///
/// An array of axis values, or null if the joystick is not present or an error occurred.
///
///
///
/// The returned array is allocated and freed by GLFW.
/// You should not free it yourself.
/// It is valid until the specified joystick is disconnected or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe float* GetJoystickAxesRaw(int jid, out int count)
{
fixed (int* ptr = &count)
{
return GetJoystickAxesRaw(jid, ptr);
}
}
///
///
/// This function returns the values of all axes of the specified joystick.
/// Each element in the array is a value between -1.0 and 1.0.
///
///
/// If the specified joystick is not present
/// this function will return null but will not generate an error.
/// This can be used instead of first calling .
///
///
/// The joystick to query.
///
/// Where to store the number of axis values in the returned array.
/// This is set to zero if the joystick is not present or an error occurred.
///
///
/// An array of axis values, or null if the joystick is not present or an error occurred.
///
///
///
/// The returned array is allocated and freed by GLFW.
/// You should not free it yourself.
/// It is valid until the specified joystick is disconnected or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe float* GetJoystickAxesRaw(int jid, int* count)
{
return glfwGetJoystickAxes(jid, count);
}
///
///
/// This function returns the state of all buttons of the specified joystick.
/// Each element in the array is either or .
///
///
/// For backward compatibility with earlier versions that did not have ,
/// the button array also includes all hats, each represented as four buttons.
///
///
/// The hats are in the same order as returned by and are in the order
/// up, right, down and left.
///
///
/// To disable these extra buttons, set the
/// init hint before initialization.
///
///
/// If the specified joystick is not present this function will return null but will not generate an error.
/// This can be used instead of first calling .
///
///
/// The joystick to query.
///
/// An array of button states, or null if the joystick is not present or an error occurred.
///
///
///
/// The returned array is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified joystick is disconnected or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe InputAction[] GetJoystickButtons(int jid)
{
var ptr = GetJoystickButtonsRaw(jid, out var count);
if (ptr == null)
{
return null;
}
var array = new InputAction[count];
for (var i = 0; i < count; i++)
{
array[i] = ptr[i];
}
return array;
}
///
///
/// This function returns the state of all buttons of the specified joystick.
/// Each element in the array is either or .
///
///
/// For backward compatibility with earlier versions that did not have ,
/// the button array also includes all hats, each represented as four buttons.
///
///
/// The hats are in the same order as returned by and are in the order
/// up, right, down and left.
///
///
/// To disable these extra buttons, set the
/// init hint before initialization.
///
///
/// If the specified joystick is not present this function will return null but will not generate an error.
/// This can be used instead of first calling .
///
///
/// The joystick to query.
///
/// Where to store the number of button states in the returned array.
/// This is set to zero if the joystick is not present or an error occurred.
///
///
/// An array of button states, or null if the joystick is not present or an error occurred.
///
///
///
/// The returned array is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified joystick is disconnected or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe InputAction* GetJoystickButtonsRaw(int jid, out int count)
{
fixed (int* ptr = &count)
{
return GetJoystickButtonsRaw(jid, ptr);
}
}
///
///
/// This function returns the state of all buttons of the specified joystick.
/// Each element in the array is either or .
///
///
/// For backward compatibility with earlier versions that did not have ,
/// the button array also includes all hats, each represented as four buttons.
///
///
/// The hats are in the same order as returned by and are in the order
/// up, right, down and left.
///
///
/// To disable these extra buttons, set the
/// init hint before initialization.
///
///
/// If the specified joystick is not present this function will return null but will not generate an error.
/// This can be used instead of first calling .
///
///
/// The joystick to query.
///
/// Where to store the number of button states in the returned array.
/// This is set to zero if the joystick is not present or an error occurred.
///
///
/// An array of button states, or null if the joystick is not present or an error occurred.
///
///
///
/// The returned array is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified joystick is disconnected or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe InputAction* GetJoystickButtonsRaw(int jid, int* count)
{
return glfwGetJoystickButtons(jid, count);
}
///
///
/// This function returns the state of all hats of the specified joystick.
/// Each element in the array is one of the .
///
///
/// The diagonal directions are bitwise combinations of the primary (up, right, down and left) directions
/// and you can test for these individually by ANDing it with the corresponding direction.
///
/// if (hats[2].HasFlag(JoystickHats.Right))
/// {
/// // State of hat 2 could be right-up, right or right-down
/// }
///
///
///
/// If the specified joystick is not present, this function will return NULL but will not generate an error.
/// This can be used instead of first calling .
///
///
/// The joystick to query.
///
/// An array of hat states, or null if the joystick is not present or an error occurred.
///
///
///
/// The returned array is allocated and freed by GLFW. You should not free it yourself
/// It is valid until the specified joystick is disconnected,
/// this function is called again for that joystick or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe JoystickHats[] GetJoystickHats(int jid)
{
var ptr = GetJoystickHatsRaw(jid, out var count);
if (ptr == null)
{
return null;
}
var array = new JoystickHats[count];
for (var i = 0; i < count; i++)
{
array[i] = ptr[i];
}
return array;
}
///
///
/// This function returns the state of all hats of the specified joystick.
/// Each element in the array is one of the .
///
///
/// The diagonal directions are bitwise combinations of the primary (up, right, down and left) directions
/// and you can test for these individually by ANDing it with the corresponding direction.
///
/// if (hats[2].HasFlag(JoystickHats.Right))
/// {
/// // State of hat 2 could be right-up, right or right-down
/// }
///
///
///
/// If the specified joystick is not present, this function will return NULL but will not generate an error.
/// This can be used instead of first calling .
///
///
/// The joystick to query.
///
/// Where to store the number of hat states in the returned array.
/// This is set to zero if the joystick is not present or an error occurred.
///
///
/// An array of hat states, or null if the joystick is not present or an error occurred.
///
///
///
/// The returned array is allocated and freed by GLFW. You should not free it yourself
/// It is valid until the specified joystick is disconnected,
/// this function is called again for that joystick or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe JoystickHats* GetJoystickHatsRaw(int jid, out int count)
{
fixed (int* ptr = &count)
{
return glfwGetJoystickHats(jid, ptr);
}
}
///
///
/// This function returns the state of all hats of the specified joystick.
/// Each element in the array is one of the .
///
///
/// The diagonal directions are bitwise combinations of the primary (up, right, down and left) directions
/// and you can test for these individually by ANDing it with the corresponding direction.
///
/// if (hats[2].HasFlag(JoystickHats.Right))
/// {
/// // State of hat 2 could be right-up, right or right-down
/// }
///
///
///
/// If the specified joystick is not present, this function will return NULL but will not generate an error.
/// This can be used instead of first calling .
///
///
/// The joystick to query.
///
/// Where to store the number of hat states in the returned array.
/// This is set to zero if the joystick is not present or an error occurred.
///
///
/// An array of hat states, or null if the joystick is not present or an error occurred.
///
///
///
/// The returned array is allocated and freed by GLFW. You should not free it yourself
/// It is valid until the specified joystick is disconnected,
/// this function is called again for that joystick or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe JoystickHats* GetJoystickHatsRaw(int jid, int* count)
{
return glfwGetJoystickHats(jid, count);
}
///
///
/// This function returns the name, encoded as UTF-8, of the specified joystick.
///
///
/// If the specified joystick is not present this function will return null but will not generate an error.
/// This can be used instead of first calling .
///
///
/// The joystick to query.
///
/// The UTF-8 encoded name of the joystick, or null if the joystick is not present or an error occurred.
///
///
///
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified joystick is disconnected or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe string GetJoystickName(int jid)
{
return PtrToStringUTF8(glfwGetJoystickName(jid));
}
///
///
/// This function returns the name, encoded as UTF-8, of the specified joystick.
///
///
/// If the specified joystick is not present this function will return null but will not generate an error.
/// This can be used instead of first calling .
///
///
/// The joystick to query.
///
/// The UTF-8 encoded name of the joystick, or null if the joystick is not present or an error occurred.
///
///
///
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified joystick is disconnected or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe byte* GetJoystickNameRaw(int jid)
{
return glfwGetJoystickName(jid);
}
///
///
/// This function returns the SDL compatible GUID, as a UTF-8 encoded hexadecimal string,
/// of the specified joystick.
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
///
///
/// The GUID is what connects a joystick to a gamepad mapping.
/// A connected joystick will always have a GUID even if there is no gamepad mapping assigned to it.
///
///
/// If the specified joystick is not present this function will return null but will not generate an error.
/// This can be used instead of first calling .
///
///
/// The GUID uses the format introduced in SDL 2.0.5.
/// This GUID tries to uniquely identify the make and model of a joystick but does not identify a specific unit,
/// e.g. all wired Xbox 360 controllers will have the same GUID on that platform.
/// The GUID for a unit may vary between platforms
/// depending on what hardware information the platform specific APIs provide.
///
///
/// The joystick to query.
///
/// The UTF-8 encoded GUID of the joystick, or null if the joystick is not present or an error occurred.
///
///
///
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified joystick is disconnected or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe string GetJoystickGUID(int jid)
{
return PtrToStringUTF8(glfwGetJoystickGUID(jid));
}
///
///
/// This function returns the SDL compatible GUID, as a UTF-8 encoded hexadecimal string,
/// of the specified joystick.
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
///
///
/// The GUID is what connects a joystick to a gamepad mapping.
/// A connected joystick will always have a GUID even if there is no gamepad mapping assigned to it.
///
///
/// If the specified joystick is not present this function will return null but will not generate an error.
/// This can be used instead of first calling .
///
///
/// The GUID uses the format introduced in SDL 2.0.5.
/// This GUID tries to uniquely identify the make and model of a joystick but does not identify a specific unit,
/// e.g. all wired Xbox 360 controllers will have the same GUID on that platform.
/// The GUID for a unit may vary between platforms
/// depending on what hardware information the platform specific APIs provide.
///
///
/// The joystick to query.
///
/// The UTF-8 encoded GUID of the joystick, or null if the joystick is not present or an error occurred.
///
///
///
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified joystick is disconnected or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe byte* GetJoystickGUIDRaw(int jid)
{
return glfwGetJoystickGUID(jid);
}
///
///
/// This function sets the user-defined pointer of the specified joystick.
/// The current value is retained until the joystick is disconnected.
/// The initial value is .
///
///
/// This function may be called from the joystick callback, even for a joystick that is being disconnected.
///
///
/// The joystick whose pointer to set.
/// The new value.
///
///
/// This function may be called from any thread. Access is not synchronized.
///
///
/// Possible errors include .
///
///
public static unsafe void SetJoystickUserPointer(int jid, void* ptr)
{
glfwSetJoystickUserPointer(jid, ptr);
}
///
///
/// This function returns the current value of the user-defined pointer of the specified joystick.
/// The initial value is .
///
///
/// This function may be called from the joystick callback, even for a joystick that is being disconnected.
///
///
/// The joystick whose pointer to return.
/// The user-defined pointer of the given .
///
///
/// This function may be called from any thread. Access is not synchronized.
///
///
/// Possible errors include .
///
///
public static unsafe void* GetJoystickUserPointer(int jid)
{
return glfwGetJoystickUserPointer(jid);
}
///
///
/// This function returns whether the specified joystick is both present and has a gamepad mapping.
///
///
/// If the specified joystick is present but does not have a gamepad mapping
/// this function will return false but will not generate an error.
///
///
/// The joystick to query.
///
/// true if a joystick is both present and has a gamepad mapping, or false otherwise.
///
///
///
/// Call to check if a joystick is present regardless of whether it has a mapping.
///
///
/// This function must only be called from the main thread.
///
///
///
/// Possible errors include and .
///
///
///
public static bool JoystickIsGamepad(int jid)
{
return glfwJoystickIsGamepad(jid) == GLFW_TRUE;
}
///
///
/// This function parses the specified ASCII encoded string
/// and updates the internal list with any gamepad mappings it finds.
///
///
/// This string may contain either a single gamepad mapping or many mappings separated by newlines.
///
///
/// The parser supports the full format of the gamecontrollerdb.txt source file
/// including empty lines and comments.
///
///
/// See Gamepad mappings
/// for a description of the format.
///
///
/// If there is already a gamepad mapping for a given GUID in the internal list, it will be replaced by the one passed to this function. If the library is terminated and re-initialized the internal list will revert to the built-in default.
///
///
/// The string containing the gamepad mappings.
/// true if successful, or false if an error occurred.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe bool UpdateGamepadMappings(string newMapping)
{
var ptr = StringToCoTaskMemUTF8(newMapping);
try
{
return glfwUpdateGamepadMappings((byte*)ptr) == GLFW_TRUE;
}
finally
{
Marshal.FreeCoTaskMem(ptr);
}
}
///
///
/// This function parses the specified ASCII encoded string
/// and updates the internal list with any gamepad mappings it finds.
///
///
/// This string may contain either a single gamepad mapping or many mappings separated by newlines.
///
///
/// The parser supports the full format of the gamecontrollerdb.txt source file
/// including empty lines and comments.
///
///
/// See Gamepad mappings
/// for a description of the format.
///
///
/// If there is already a gamepad mapping for a given GUID in the internal list, it will be replaced by the one passed to this function. If the library is terminated and re-initialized the internal list will revert to the built-in default.
///
///
/// The string containing the gamepad mappings.
/// true if successful, or false if an error occurred.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe bool UpdateGamepadMappingsRaw(byte* newMapping)
{
return glfwUpdateGamepadMappings(newMapping) == GLFW_TRUE;
}
///
///
/// This function returns the human-readable name of the gamepad
/// from the gamepad mapping assigned to the specified joystick.
///
///
/// If the specified joystick is not present or does not have a gamepad mapping
/// this function will return null but will not generate an error.
///
///
/// The joystick to query.
///
/// The UTF-8 encoded name of the gamepad, or null if the joystick is not present,
/// does not have a mapping or an error occurred.
///
///
///
/// Call to check whether it is present regardless of whether it has a mapping.
///
///
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified joystick is disconnected,
/// the gamepad mappings are updated or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
public static unsafe string GetGamepadName(int jid)
{
return PtrToStringUTF8(glfwGetGamepadName(jid));
}
///
///
/// This function returns the human-readable name of the gamepad
/// from the gamepad mapping assigned to the specified joystick.
///
///
/// If the specified joystick is not present or does not have a gamepad mapping
/// this function will return null but will not generate an error.
///
///
/// The joystick to query.
///
/// The UTF-8 encoded name of the gamepad, or null if the joystick is not present,
/// does not have a mapping or an error occurred.
///
///
///
/// Call to check whether it is present regardless of whether it has a mapping.
///
///
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified joystick is disconnected,
/// the gamepad mappings are updated or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
public static unsafe byte* GetGamepadNameRaw(int jid)
{
return glfwGetGamepadName(jid);
}
///
///
/// This function retrieves the state of the specified joystick remapped to an Xbox-like gamepad.
///
///
/// If the specified joystick is not present or does not have a gamepad mapping
/// this function will return false but will not generate an error.
/// Call to check whether it is present regardless of whether it has a mapping.
///
///
/// The Guide button may not be available for input as it is often hooked by the system or the Steam client.
///
///
/// Not all devices have all the buttons or axes provided by .
/// Unavailable buttons and axes will always report and 0.0 respectively.
///
///
/// The joystick to query.
/// The gamepad input state of the joystick.
///
/// true if successful, or false if no joystick is connected,
/// it has no gamepad mapping or an error occurred.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe bool GetGamepadState(int jid, out GamepadState state)
{
fixed (GamepadState* ptr = &state)
{
return glfwGetGamepadState(jid, ptr) == GLFW_TRUE;
}
}
///
///
/// This function retrieves the state of the specified joystick remapped to an Xbox-like gamepad.
///
///
/// If the specified joystick is not present or does not have a gamepad mapping
/// this function will return false but will not generate an error.
/// Call to check whether it is present regardless of whether it has a mapping.
///
///
/// The Guide button may not be available for input as it is often hooked by the system or the Steam client.
///
///
/// Not all devices have all the buttons or axes provided by .
/// Unavailable buttons and axes will always report and 0.0 respectively.
///
///
/// The joystick to query.
/// The gamepad input state of the joystick.
///
/// true if successful, or false if no joystick is connected,
/// it has no gamepad mapping or an error occurred.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe bool GetGamepadStateRaw(int jid, GamepadState* state)
{
return glfwGetGamepadState(jid, state) == GLFW_TRUE;
}
///
///
/// This function returns the value of the GLFW timer.
///
///
/// Unless the timer has been set using ,
/// the timer measures time elapsed since GLFW was initialized.
///
///
/// The resolution of the timer is system dependent, but is usually on the order of a few micro- or nanoseconds.
/// It uses the highest-resolution monotonic time source on each supported platform.
///
///
/// The current value, in seconds, or zero if an error occurred.
///
///
/// This function may be called from any thread.
///
///
/// Reading and writing of the internal timer offset is not atomic,
/// so it needs to be externally synchronized with calls to .
///
///
///
/// Possible errors include .
///
///
public static double GetTime() => glfwGetTime();
///
///
/// This function sets the value of the GLFW timer. It then continues to count up from that value.
/// The value must be a positive finite number less than or equal to 18446744073.0,
/// which is approximately 584.5 years.
///
///
/// The new value, in seconds.
///
///
/// The upper limit of the timer is calculated as floor((2^64 - 1) / 109) and is due to implementations
/// storing nanoseconds in 64 bits. The limit may be increased in the future.
///
///
/// This function may be called from any thread.
/// Reading and writing of the internal timer offset is not atomic,
/// so it needs to be externally synchronized with calls to .
///
///
/// Possible errors include and .
///
///
public static void SetTime(double time) => glfwSetTime(time);
///
///
/// This function returns the current value of the raw timer, measured in 1 / frequency seconds.
/// To get the frequency, call .
///
///
/// The value of the timer, or zero if an error occurred.
///
///
/// This function may be called from any thread.
///
///
/// Possible errors include .
///
///
public static long GetTimerValue() => glfwGetTimerValue();
///
///
/// This function returns the frequency, in Hz, of the raw timer.
///
///
/// he frequency of the timer, in Hz, or zero if an error occurred.
///
///
/// This function may be called from any thread.
///
///
/// Possible errors include .
///
///
public static long GetTimerFrequency() => glfwGetTimerFrequency();
///
///
/// This function returns the window whose OpenGL or OpenGL ES context is current on the calling thread.
///
///
/// The window whose context is current, or null if no window's context is current.
///
///
/// This function may be called from any thread.
///
///
/// Possible errors include .
///
///
public static unsafe Window* GetCurrentContext() => glfwGetCurrentContext();
///
///
/// This function swaps the front and back buffers of the specified window
/// when rendering with OpenGL or OpenGL ES.
///
///
/// If the swap interval is greater than zero,
/// the GPU driver waits the specified number of screen updates before swapping the buffers.
///
///
/// The specified window must have an OpenGL or OpenGL ES context.
/// Specifying a window without a context will generate a error.
///
///
/// The window whose buffers to swap.
///
///
/// EGL: The context of the specified window must be current on the calling thread.
///
///
/// This function may be called from any thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe void SwapBuffers(Window* window) => glfwSwapBuffers(window);
///
///
/// This function returns whether the specified API extension is supported
/// by the current OpenGL or OpenGL ES context.
/// It searches both for client API extension and context creation API extensions.
///
///
/// A context must be current on the calling thread.
/// Calling this function without a current context will cause a error.
///
///
/// As this functions retrieves and searches one or more extension strings each call,
/// it is recommended that you cache its results if it is going to be used frequently.
/// The extension strings will not change during the lifetime of a context, so there is no danger in doing this.
///
///
/// The ASCII encoded name of the extension.
/// true if the extension is available, or false otherwise.
///
///
/// This function may be called from any thread.
///
///
/// Possible errors include , , and .
///
///
public static unsafe bool ExtensionSupported(string extensionName)
{
var ptr = StringToCoTaskMemUTF8(extensionName);
try
{
return glfwExtensionSupported((byte*)ptr) == GLFW_TRUE;
}
finally
{
Marshal.FreeCoTaskMem(ptr);
}
}
///
/// This function returns the address of the specified OpenGL or OpenGL ES core or extension function, if it is supported by the current context.
/// A context must be current on the calling thread. Calling this function without a current context will cause a error.
///
///
///
/// This function does not apply to Vulkan. If you are rendering with Vulkan, see , vkGetInstanceProcAddr and vkGetDeviceProcAddr instead.
///
///
/// Possible errors include , and .
///
///
/// The address of a given function is not guaranteed to be the same between contexts.
/// This function may return a non-null address despite the associated version or extension not being available. Always check the context version or extension string first.
///
///
/// The returned function pointer is valid until the context is destroyed or the library is terminated.
///
///
/// This function may be called from any thread.
///
///
/// The name of the function.
/// The address of the function, or null if an error occurred.
///
public static unsafe IntPtr GetProcAddress(string procName)
{
var ptr = StringToCoTaskMemUTF8(procName);
try
{
return glfwGetProcAddress((byte*)ptr);
}
finally
{
Marshal.FreeCoTaskMem(ptr);
}
}
///
/// This function returns the address of the specified OpenGL or OpenGL ES core or extension function, if it is supported by the current context.
/// A context must be current on the calling thread. Calling this function without a current context will cause a error.
///
///
///
/// This function does not apply to Vulkan. If you are rendering with Vulkan, see , vkGetInstanceProcAddr and vkGetDeviceProcAddr instead.
///
///
/// Possible errors include , and .
///
///
/// The address of a given function is not guaranteed to be the same between contexts.
/// This function may return a non-null address despite the associated version or extension not being available. Always check the context version or extension string first.
///
///
/// The returned function pointer is valid until the context is destroyed or the library is terminated.
///
///
/// This function may be called from any thread.
///
///
/// The ASCII-encoded name of the function.
/// The address of the function, or null if an error occurred.
///
public static unsafe IntPtr GetProcAddressRaw(byte* procName)
{
return glfwGetProcAddress(procName);
}
///
///
/// This function returns whether the specified API extension is supported
/// by the current OpenGL or OpenGL ES context.
/// It searches both for client API extension and context creation API extensions.
///
///
/// A context must be current on the calling thread.
/// Calling this function without a current context will cause a error.
///
///
/// As this functions retrieves and searches one or more extension strings each call,
/// it is recommended that you cache its results if it is going to be used frequently.
/// The extension strings will not change during the lifetime of a context, so there is no danger in doing this.
///
///
/// The ASCII encoded name of the extension.
/// true if the extension is available, or false otherwise.
///
///
/// This function may be called from any thread.
///
///
/// Possible errors include , , and .
///
///
public static unsafe bool ExtensionSupportedRaw(byte* extensionName)
{
return glfwExtensionSupported(extensionName) == GLFW_TRUE;
}
///
///
/// This function creates a window and its associated OpenGL or OpenGL ES context.
/// Most of the options controlling how the window and its context should be created
/// are specified with window hints.
///
///
/// Successful creation does not change which context is current.
/// Before you can use the newly created context, you need to make it current.
/// For information about the share parameter, see
/// Context object sharing.
///
///
/// The created window, framebuffer and context may differ from what you requested,
/// as not all parameters and hints are
/// hard constraints.
/// This includes the size of the window, especially for full screen windows.
/// To query the actual attributes of the created window, framebuffer and context,
/// see , and .
///
///
/// To create a full screen window, you need to specify the monitor the window will cover.
/// If no monitor is specified, the window will be windowed mode.
/// Unless you have a way for the user to choose a specific monitor,
/// it is recommended that you pick the primary monitor.
/// For more information on how to query connected monitors, see
/// Retrieving monitors.
///
///
/// For full screen windows, the specified size becomes the resolution of the window's desired video mode.
/// As long as a full screen window is not iconified,
/// the supported video mode most closely matching the desired video mode is set for the specified monitor.
/// For more information about full screen windows, including the creation of so called windowed full screen
/// or borderless full screen windows, see
///
/// "Windowed full screen" windows
/// .
///
///
/// Once you have created the window, you can switch it between windowed and full screen mode
/// with . If the window has an OpenGL or OpenGL ES context, it will be unaffected.
///
///
/// By default, newly created windows use the placement recommended by the window system.
/// To create the window at a specific position,
/// make it initially invisible using the window hint,
/// set its position(see ) and then show it
/// (see ).
///
///
/// As long as at least one full screen window is not iconified, the screensaver is prohibited from starting.
///
///
/// Window systems put limits on window sizes.
/// Very large or very small window dimensions may be overridden by the window system on creation.
/// Check the actual size after creation(see or .
///
///
/// The swap interval
/// is not set during window creation and the initial value may vary
/// depending on driver settings and defaults.
///
///
///
/// The desired width, in screen coordinates, of the window. This must be greater than zero.
///
///
/// The desired height, in screen coordinates, of the window. This must be greater than zero.
///
/// The initial, UTF-8 encoded window title.
/// The monitor to use for full screen mode, or null for windowed mode.
///
/// The window whose context to share resources with, or null to not share resources.
///
/// The handle of the created window, or null if an error occurred.
///
///
/// Windows: Window creation will fail if the Microsoft GDI software OpenGL implementation is the only one available.
///
///
/// Windows: If the executable has an icon resource named GLFW_ICON, it will be set as the initial icon for the window.
/// If no such icon is present, the IDI_WINLOGO icon will be used instead. To set a different icon, see .
///
///
/// Windows: The context to share resources with must not be current on any other thread.
///
///
/// OS X: The GLFW window has no icon, as it is not a document window, but the dock icon will be the same as the application bundle's icon.
/// For more information on bundles, see the Bundle Programming Guide in the Mac Developer Library.
///
///
/// OS X: The first time a window is created the menu bar is populated with common commands like Hide, Quit and About.
/// The About entry opens a minimal about dialog with information from the application's bundle.
/// The menu bar can be disabled with a compile-time option.
///
///
/// OS X: On OS X 10.10 and later the window frame will not be rendered at full resolution on Retina displays
/// unless the NSHighResolutionCapable key is enabled in the application bundle's Info.plist.
/// For more information, see High Resolution Guidelines for OS X in the Mac Developer Library.
/// The GLFW test and example programs use a custom Info.plist template for this, which can be found as CMake/MacOSXBundleInfo.plist.in in the source tree.
///
///
/// X11: Some window managers will not respect the placement of initially hidden windows.
/// X11: Due to the asynchronous nature of X11, it may take a moment for a window to reach its requested state.
/// This means you may not be able to query the final size, position or other attributes directly after window creation.
///
///
/// This function must not be called from a callback.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , , , ,
/// , and .
///
///
public static unsafe Window* CreateWindow(int width, int height, string title, Monitor* monitor, Window* share)
{
var ptr = StringToCoTaskMemUTF8(title);
try
{
return glfwCreateWindow(width, height, (byte*)ptr, monitor, share);
}
finally
{
if (ptr != IntPtr.Zero)
{
Marshal.FreeCoTaskMem(ptr);
}
}
}
///
///
/// This function creates a window and its associated OpenGL or OpenGL ES context.
/// Most of the options controlling how the window and its context should be created
/// are specified with window hints.
///
///
/// Successful creation does not change which context is current.
/// Before you can use the newly created context, you need to make it current.
/// For information about the share parameter, see
/// Context object sharing.
///
///
/// The created window, framebuffer and context may differ from what you requested,
/// as not all parameters and hints are
/// hard constraints.
/// This includes the size of the window, especially for full screen windows.
/// To query the actual attributes of the created window, framebuffer and context,
/// see , and .
///
///
/// To create a full screen window, you need to specify the monitor the window will cover.
/// If no monitor is specified, the window will be windowed mode.
/// Unless you have a way for the user to choose a specific monitor,
/// it is recommended that you pick the primary monitor.
/// For more information on how to query connected monitors, see
/// Retrieving monitors.
///
///
/// For full screen windows, the specified size becomes the resolution of the window's desired video mode.
/// As long as a full screen window is not iconified,
/// the supported video mode most closely matching the desired video mode is set for the specified monitor.
/// For more information about full screen windows, including the creation of so called windowed full screen
/// or borderless full screen windows, see
///
/// "Windowed full screen" windows
/// .
///
///
/// Once you have created the window, you can switch it between windowed and full screen mode
/// with . If the window has an OpenGL or OpenGL ES context, it will be unaffected.
///
///
/// By default, newly created windows use the placement recommended by the window system.
/// To create the window at a specific position,
/// make it initially invisible using the window hint,
/// set its position(see ) and then show it
/// (see ).
///
///
/// As long as at least one full screen window is not iconified, the screensaver is prohibited from starting.
///
///
/// Window systems put limits on window sizes.
/// Very large or very small window dimensions may be overridden by the window system on creation.
/// Check the actual size after creation(see or .
///
///
/// The swap interval
/// is not set during window creation and the initial value may vary
/// depending on driver settings and defaults.
///
///
///
/// The desired width, in screen coordinates, of the window. This must be greater than zero.
///
///
/// The desired height, in screen coordinates, of the window. This must be greater than zero.
///
/// The initial, UTF-8 encoded window title.
/// The monitor to use for full screen mode, or null for windowed mode.
///
/// The window whose context to share resources with, or null to not share resources.
///
/// The handle of the created window, or null if an error occurred.
///
///
/// Windows: Window creation will fail if the Microsoft GDI software OpenGL implementation is the only one available.
///
///
/// Windows: If the executable has an icon resource named GLFW_ICON, it will be set as the initial icon for the window.
/// If no such icon is present, the IDI_WINLOGO icon will be used instead. To set a different icon, see .
///
///
/// Windows: The context to share resources with must not be current on any other thread.
///
///
/// OS X: The GLFW window has no icon, as it is not a document window, but the dock icon will be the same as the application bundle's icon.
/// For more information on bundles, see the Bundle Programming Guide in the Mac Developer Library.
///
///
/// OS X: The first time a window is created the menu bar is populated with common commands like Hide, Quit and About.
/// The About entry opens a minimal about dialog with information from the application's bundle.
/// The menu bar can be disabled with a compile-time option.
///
///
/// OS X: On OS X 10.10 and later the window frame will not be rendered at full resolution on Retina displays
/// unless the NSHighResolutionCapable key is enabled in the application bundle's Info.plist.
/// For more information, see High Resolution Guidelines for OS X in the Mac Developer Library.
/// The GLFW test and example programs use a custom Info.plist template for this, which can be found as CMake/MacOSXBundleInfo.plist.in in the source tree.
///
///
/// X11: Some window managers will not respect the placement of initially hidden windows.
/// X11: Due to the asynchronous nature of X11, it may take a moment for a window to reach its requested state.
/// This means you may not be able to query the final size, position or other attributes directly after window creation.
///
///
/// This function must not be called from a callback.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , , , ,
/// , and .
///
///
public static unsafe Window* CreateWindowRaw(
int width,
int height,
byte* title,
Monitor* monitor,
Window* share)
{
return glfwCreateWindow(width, height, title, monitor, share);
}
///
///
/// This function destroys the specified window and its context. On calling this function,
/// no further callbacks will be called for that window.
///
///
/// If the context of the specified window is current on the main thread, it is detached before being destroyed.
///
///
/// The window to destroy.
///
///
/// The context of the specified window must not be current on any other thread when this function is called.
///
///
/// This function must not be called from a callback.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static unsafe void DestroyWindow(Window* window) => glfwDestroyWindow(window);
///
///
/// This function brings the specified window to front and sets input focus.
/// The window should already be visible and not iconified.
///
///
/// By default, both windowed and full screen mode windows are focused when initially created.
/// Set the to disable this behavior.
///
///
/// Do not use this function to steal focus from other applications unless you are certain
/// that is what the user wants.
/// Focus stealing can be extremely disruptive.
///
///
/// The window to give input focus.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe void FocusWindow(Window* window) => glfwFocusWindow(window);
///
///
/// This function returns the contents of the system clipboard,
/// if it contains or is convertible to a UTF-8 encoded string.
///
///
/// The window that will request the clipboard contents.
///
/// The contents of the clipboard as a UTF-8 encoded string, or null if an error occurred.
///
///
///
/// This function may only be called from the main thread.
///
///
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
/// The returned string is valid only until the next call to or
/// .
///
///
/// Possible errors include and .
///
///
///
public static unsafe string GetClipboardString(Window* window)
{
return PtrToStringUTF8(glfwGetClipboardString(window));
}
///
///
/// This function returns the contents of the system clipboard,
/// if it contains or is convertible to a UTF-8 encoded string.
///
///
/// The window that will request the clipboard contents.
///
/// The contents of the clipboard as a UTF-8 encoded string, or null if an error occurred.
///
///
///
/// This function may only be called from the main thread.
///
///
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
/// The returned string is valid only until the next call to or
/// .
///
///
/// Possible errors include and .
///
///
///
public static unsafe byte* GetClipboardStringRaw(Window* window)
{
return glfwGetClipboardString(window);
}
///
///
/// This function retrieves the size, in pixels, of the framebuffer of the specified window.
/// If you wish to retrieve the size of the window in screen coordinates, see .
///
///
/// Any or all of the size arguments may be out _.
/// If an error occurs, all non-out _ size arguments will be set to zero.
///
///
/// The window whose framebuffer to query.
/// Where to store the width, in pixels, of the framebuffer.
/// Where to store the height, in pixels, of the framebuffer.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe void GetFramebufferSize(Window* window, out int width, out int height)
{
int w, h;
glfwGetFramebufferSize(window, &w, &h);
width = w;
height = h;
}
///
///
/// This function retrieves the size, in pixels, of the framebuffer of the specified window.
/// If you wish to retrieve the size of the window in screen coordinates, see .
///
///
/// Any or all of the size arguments may be out _.
/// If an error occurs, all non-out _ size arguments will be set to zero.
///
///
/// The window whose framebuffer to query.
/// Where to store the width, in pixels, of the framebuffer.
/// Where to store the height, in pixels, of the framebuffer.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe void GetFramebufferSizeRaw(Window* window, int* width, int* height)
{
glfwGetFramebufferSize(window, width, height);
}
///
///
/// This function returns the value of an input option for the specified window.
/// The mode must be or .
///
///
/// The window to query.
///
/// Either or .
///
/// TODO: return value is either InputModeValue or bool dependant on .
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static unsafe bool GetInputMode(Window* window, StickyAttributes mode)
{
return glfwGetInputMode(window, mode) == GLFW_TRUE;
}
///
///
/// This function returns the value of an input option for the specified window.
/// The mode must be .
///
///
/// The window to query.
///
/// .
///
/// TODO: return value is either InputModeValue or bool dependant on .
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static unsafe CursorModeValue GetInputMode(Window* window, CursorStateAttribute mode)
{
return glfwGetInputMode(window, mode);
}
///
///
/// This function returns the primary monitor.
///
///
/// This is usually the monitor where elements like the task bar or global menu bar are located.
///
///
/// The primary monitor, or null if no monitors were found or if an error occurred.
///
///
/// This function must only be called from the main thread.
///
///
/// The primary monitor is always first in the array returned by .
///
///
/// Possible errors include .
///
///
public static unsafe Monitor* GetPrimaryMonitor() => glfwGetPrimaryMonitor();
///
///
/// This function returns the current video mode of the specified monitor.
///
///
/// If you have created a full screen window for that monitor,
/// the return value will depend on whether that window is iconified.
///
///
/// The monitor to query.
/// The current mode of the monitor, or null if an error occurred.
///
///
/// The returned array is allocated and freed by GLFW
/// You should not free it yourself.
/// It is valid until the specified monitor is disconnected or the library is terminated.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static unsafe VideoMode* GetVideoMode(Monitor* monitor) => glfwGetVideoMode(monitor);
///
///
/// This function returns the value of an attribute of the specified window or its OpenGL or OpenGL ES context.
///
///
/// The window to query.
/// The window attribute whose value to return.
/// The value of the attribute, or zero if an error occurred.
///
///
/// Framebuffer-related hints are not window attributes. See
///
/// Framebuffer related attributes
///
/// for more information.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe bool GetWindowAttrib(Window* window, WindowAttributeGetter attribute)
{
return glfwGetWindowAttrib(window, attribute) == GLFW_TRUE;
}
///
///
/// This function retrieves the size, in screen coordinates, of the client area of the specified window.
/// If you wish to retrieve the size of the framebuffer of the window in pixels, see .
///
///
/// Any or all of the size arguments may be out _.
/// If an error occurs, all non-out _ size arguments will be set to zero.
///
///
/// The window whose size to retrieve.
/// Where to store the width, in screen coordinates, of the client area.
/// Where to store the height, in screen coordinates, of the client area.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static unsafe void GetWindowSize(Window* window, out int width, out int height)
{
int w, h;
glfwGetWindowSize(window, &w, &h);
width = w;
height = h;
}
///
///
/// This function retrieves the size, in screen coordinates, of the client area of the specified window.
/// If you wish to retrieve the size of the framebuffer of the window in pixels, see .
///
///
/// Any or all of the size arguments may be out _.
/// If an error occurs, all non-out _ size arguments will be set to zero.
///
///
/// The window whose size to retrieve.
/// Where to store the width, in screen coordinates, of the client area.
/// Where to store the height, in screen coordinates, of the client area.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static unsafe void GetWindowSizeRaw(Window* window, int* width, int* height)
{
glfwGetWindowSize(window, width, height);
}
///
///
/// This function retrieves the position, in screen coordinates,
/// of the upper-left corner of the client area of the specified window.
///
///
/// Any or all of the position arguments may be out _.
/// If an error occurs, all non-out _ position arguments will be set to zero.
///
///
/// The window to query.
/// Where to store the x-coordinate of the upper-left corner of the client area.
/// Where to store the y-coordinate of the upper-left corner of the client area.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static unsafe void GetWindowPos(Window* window, out int x, out int y)
{
int lX, lY;
glfwGetWindowPos(window, &lX, &lY);
x = lX;
y = lY;
}
///
///
/// This function retrieves the position, in screen coordinates,
/// of the upper-left corner of the client area of the specified window.
///
///
/// Any or all of the position arguments may be out _.
/// If an error occurs, all non-out _ position arguments will be set to zero.
///
///
/// The window to query.
/// Where to store the x-coordinate of the upper-left corner of the client area.
/// Where to store the y-coordinate of the upper-left corner of the client area.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static unsafe void GetWindowPosRaw(Window* window, int* x, int* y)
{
glfwGetWindowPos(window, x, y);
}
///
///
/// This function returns the handle of the monitor that the specified window is in full screen on.
///
///
/// The window to query.
/// The monitor, or null if the window is in windowed mode or an error occurred.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
///
public static unsafe Monitor* GetWindowMonitor(Window* window) => glfwGetWindowMonitor(window);
///
///
/// This function hides the specified window if it was previously visible.
/// If the window is already hidden or is in full screen mode, this function does nothing.
///
///
/// The window to hide.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe void HideWindow(Window* window) => glfwHideWindow(window);
///
///
/// This function iconifies (minimizes) the specified window if it was previously restored.
/// If the window is already iconified, this function does nothing.
///
///
/// If the specified window is a full screen window,
/// the original monitor resolution is restored until the window is restored.
///
///
/// The window to iconify.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe void IconifyWindow(Window* window) => glfwIconifyWindow(window);
///
///
/// This function makes the OpenGL or OpenGL ES context of the specified window current on the calling thread.
///
///
/// A context can only be made current on a single thread at a time
/// and each thread can have only a single current context at a time.
///
///
/// By default, making a context non-current implicitly forces a pipeline flush.
///
///
/// On machines that support GL_KHR_context_flush_control,
/// you can control whether a context performs this flush
/// by setting the window hint.
///
///
/// The specified window must have an OpenGL or OpenGL ES context.
/// Specifying a window without a context will generate a error.
///
///
///
/// The window whose context to make current, or null to detach the current context.
///
///
///
/// This function may be called from any thread.
///
///
/// Possible errors include , and .
///
///
///
public static unsafe void MakeContextCurrent(Window* window) => glfwMakeContextCurrent(window);
///
///
/// This function maximizes the specified window if it was previously not maximized.
/// If the window is already maximized, this function does nothing.
///
///
/// If the specified window is a full screen window, this function does nothing.
///
///
/// The window to maximize.
///
///
/// This function may only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe void MaximizeWindow(Window* window) => glfwMaximizeWindow(window);
///
///
/// This function processes only those events that are already in the event queue and then returns immediately.
/// Processing events will cause the window and input callbacks associated with those events to be called.
///
///
/// On some platforms, a window move, resize or menu operation will cause event processing to block.
/// This is due to how event processing is designed on those platforms.
/// You can use the
/// window refresh callback
/// to redraw the contents of your window when necessary during such operations.
///
///
/// On some platforms, certain events are sent directly to the application without going through the event queue,
/// causing callbacks to be called outside of a call to one of the event processing functions.
///
///
/// Event processing is not required for joystick input to work.
///
///
///
///
/// This function must not be called from a callback.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static void PollEvents() => glfwPollEvents();
///
///
/// This function posts an empty event from the current thread to the event queue,
/// causing or to return.
///
///
/// If no windows exist, this function returns immediately.
/// For synchronization of threads in applications that do not create windows, use your threading library of choice.
///
///
///
///
/// This function may be called from any thread.
///
///
/// Possible errors include and .
///
///
public static void PostEmptyEvent() => glfwPostEmptyEvent();
///
///
/// This function restores the specified window if it was previously iconified (minimized) or maximized.
/// If the window is already restored, this function does nothing.
///
///
/// If the specified window is a full screen window, the resolution chosen for the window is restored on the selected monitor.
///
///
/// The window to restore.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
public static unsafe void RestoreWindow(Window* window) => glfwRestoreWindow(window);
///
///
/// This function sets the character callback of the specified window, which is called when a Unicode character is input.
///
///
/// The character callback is intended for Unicode text input. As it deals with characters,
/// it is keyboard layout dependent, whereas the key callback is not. Characters do not map 1:1 to physical keys
/// as a key may produce zero, one, or more characters.
///
///
/// If you want to know whether a specific physical key was pressed or released, see the key callback instead.
///
///
/// The character callback behaves as system text input normally does
/// and will not be called if modifier keys are held down that would prevent normal text input on that platform,
/// for example a Super (Command) key on OS X or Alt key on Windows.
///
///
/// There is a character with modifiers callback() that receives these events.
///
///
/// The window whose callback to set.
/// The new callback, or null to remove the currently set callback.
///
/// The previously set callback, or null if no callback was set or the library had not been initialized.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static unsafe IntPtr SetCharCallback(
Window* window,
GLFWCallbacks.CharCallback callback)
{
return glfwSetCharCallback(window, Marshal.GetFunctionPointerForDelegate(callback));
}
///
///
/// This function sets the character with modifiers callback of the specified window,
/// which is called when a Unicode character is input regardless of what modifier keys are used.
///
///
/// The character with modifiers callback is intended for implementing custom Unicode character input.
/// For regular Unicode text input, see the character callback.
///
///
/// Like the character callback(),
/// the character with modifiers callback deals with characters and is keyboard layout dependent.
/// Characters do not map 1:1 to physical keys, as a key may produce zero, one, or more characters.
///
///
/// If you want to know whether a specific physical key was pressed or released,
/// see the key callback() instead.
///
///
/// The window whose callback to set.
/// The new callback, or null to remove the currently set callback.
/// The previously set callback, or null if no callback was set or an error occurred.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static unsafe IntPtr SetCharModsCallback(
Window* window,
GLFWCallbacks.CharModsCallback callback)
{
return glfwSetCharCallback(window, Marshal.GetFunctionPointerForDelegate(callback));
}
///
///
/// This function sets the system clipboard to the specified, UTF-8 encoded string.
///
///
/// The window that will own the clipboard contents.
/// A UTF-8 encoded string.
///
///
/// The specified string is copied before this function returns.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static unsafe void SetClipboardString(Window* window, string data)
{
var ptr = StringToCoTaskMemUTF8(data);
try
{
glfwSetClipboardString(window, (byte*)ptr);
}
finally
{
Marshal.FreeCoTaskMem(ptr);
}
}
///
///
/// This function sets the system clipboard to the specified, UTF-8 encoded string.
///
///
/// The window that will own the clipboard contents.
/// A UTF-8 encoded string.
///
///
/// The specified string is copied before this function returns.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static unsafe void SetClipboardStringRaw(Window* window, byte* data)
{
glfwSetClipboardString(window, data);
}
///
///
/// This function sets the cursor boundary crossing callback of the specified window
/// which is called when the cursor enters or leaves the client area of the window.
///
///
/// The window whose callback to set.
/// The new callback, or null to remove the currently set callback.
///
/// The previously set callback, or null if no callback was set or the library had not been initialized.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static unsafe IntPtr SetCursorEnterCallback(
Window* window,
GLFWCallbacks.CursorEnterCallback callback)
{
return glfwSetCursorEnterCallback(window, Marshal.GetFunctionPointerForDelegate(callback));
}
///
///
/// This function sets the cursor position callback of the specified window,
/// which is called when the cursor is moved.
///
///
/// The callback is provided with the position, in screen coordinates,
/// relative to the upper-left corner of the client area of the window.
///
///
/// The window whose callback to set.
/// The new callback, or null to remove the currently set callback.
///
/// The previously set callback, or null if no callback was set or the library had not been initialized.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static unsafe IntPtr SetCursorPosCallback(
Window* window,
GLFWCallbacks.CursorPosCallback callback)
{
return glfwSetCursorPosCallback(window, Marshal.GetFunctionPointerForDelegate(callback));
}
///
///
/// This function sets the file drop callback of the specified window,
/// which is called when one or more dragged files are dropped on the window.
///
///
/// Because the path array and its strings may have been generated specifically for that event,
/// they are not guaranteed to be valid after the callback has returned.
/// If you wish to use them after the callback returns, you need to make a deep copy.
///
///
/// The window whose callback to set.
/// The new file drop callback, or null to remove the currently set callback.
///
/// The previously set callback, or null if no callback was set or the library had not been initialized.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static unsafe IntPtr SetDropCallback(
Window* window,
GLFWCallbacks.DropCallback callback)
{
return glfwSetDropCallback(window, Marshal.GetFunctionPointerForDelegate(callback));
}
///
///
/// This function sets the error callback, which is called with an error code
/// and a human-readable description each time a GLFW error occurs.
///
///
/// The error callback is called on the thread where the error occurred.
/// If you are using GLFW from multiple threads, your error callback needs to be written accordingly.
///
///
/// Because the description string may have been generated specifically for that error,
/// it is not guaranteed to be valid after the callback has returned.
/// If you wish to use it after the callback returns, you need to make a deep copy.
///
///
/// Once set, the error callback remains set even after the library has been terminated.
///
///
/// The new callback, or null to remove the currently set callback.
/// The previously set callback, or null if no callback was set.
///
///
/// This function may be called before .
///
///
/// This function must only be called from the main thread.
///
///
public static IntPtr SetErrorCallback(GLFWCallbacks.ErrorCallback callback)
{
return glfwSetErrorCallback(Marshal.GetFunctionPointerForDelegate(callback));
}
///
///
/// This function sets an input mode option for the specified window.
/// The mode must be .
///
///
/// If the mode is , the value must be one of the following cursor modes:
/// - makes the cursor visible and behaving normally.
/// - makes the cursor invisible when it is over the client area of
/// the window but does not restrict the cursor from leaving.
/// - hides and grabs the cursor, providing virtual
/// and unlimited cursor movement. This is useful for implementing for example 3D camera controls.
///
///
/// The window whose input mode to set.
/// .
/// The new value of the specified input mode.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe void SetInputMode(Window* window, CursorStateAttribute mode, CursorModeValue value)
{
glfwSetInputMode(window, mode, value);
}
///
///
/// This function sets an input mode option for the specified window.
/// The mode must be
/// or .
///
///
/// If the mode is , the value must be either true
/// to enable sticky keys, or false to disable it.
///
///
/// If sticky keys are enabled, a key press will ensure that
/// returns the next time it is called even if the key had been released before the call.
/// This is useful when you are only interested in whether keys have been pressed but not when or in which order.
///
///
/// If the mode is , the value must be either true
/// to enable sticky mouse buttons, or false to disable it.
/// If sticky mouse buttons are enabled, a mouse button press will ensure that
/// returns the next time it is called even if the mouse button had been released before the call.
/// This is useful when you are only interested in whether mouse buttons have been pressed but not when or in which order.
///
///
/// The window whose input mode to set.
///
/// Either or .
///
/// The new value of the specified input mode.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include , and .
///
///
public static unsafe void SetInputMode(Window* window, StickyAttributes mode, bool value)
{
glfwSetInputMode(window, mode, value ? GLFW_TRUE : GLFW_FALSE);
}
///
///
/// This function sets the joystick configuration callback, or removes the currently set callback.
/// This is called when a joystick is connected to or disconnected from the system.
///
///
/// The new callback, or null to remove the currently set callback.
///
/// The previously set callback, or null if no callback was set or the library had not been initialized.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static IntPtr SetJoystickCallback(GLFWCallbacks.JoystickCallback callback)
{
return glfwSetJoystickCallback(Marshal.GetFunctionPointerForDelegate(callback));
}
///
///
/// This function sets the key callback of the specified window, which is called when a key is pressed, repeated or released.
///
///
/// The key functions deal with physical keys, with layout independent
/// key tokens() named after their values in the standard US keyboard layout.
/// If you want to input text, use the character callback() instead.
///
///
/// When a window loses input focus, it will generate synthetic key release events for all pressed keys.
/// You can tell these events from user-generated events by the fact that the synthetic ones are generated
/// after the focus loss event has been processed,
/// i.e. after the window focus callback() has been called.
///
///
/// The scancode of a key is specific to that platform or sometimes even to that machine.
/// Scancodes are intended to allow users to bind keys that don't have a GLFW key token.
/// Such keys have key set to , their state is not saved
/// and so it cannot be queried with .
///
///
/// Sometimes GLFW needs to generate synthetic key events, in which case the scancode may be zero.
///
///
/// The window whose callback to set.
/// The new key callback, or null to remove the currently set callback.
///
/// The previously set callback, or null if no callback was set or the library had not been initialized.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static unsafe IntPtr SetKeyCallback(
Window* window,
GLFWCallbacks.KeyCallback callback)
{
return glfwSetKeyCallback(window, Marshal.GetFunctionPointerForDelegate(callback));
}
///
///
/// This function sets the scroll callback of the specified window,
/// which is called when a scrolling device is used, such as a mouse wheel or scrolling area of a touchpad.
///
///
/// The scroll callback receives all scrolling input, like that from a mouse wheel or a touchpad scrolling area.
///
///
/// The window whose callback to set.
/// The new scroll callback, or null to remove the currently set callback.
///
/// The previously set callback, or null if no callback was set or the library had not been initialized.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static unsafe IntPtr SetScrollCallback(
Window* window,
GLFWCallbacks.ScrollCallback callback)
{
return glfwSetScrollCallback(window, Marshal.GetFunctionPointerForDelegate(callback));
}
///
///
/// This function sets the monitor configuration callback, or removes the currently set callback.
/// This is called when a monitor is connected to or disconnected from the system.
///
///
/// The new callback, or null to remove the currently set callback.
///
/// The previously set callback, or null if no callback was set or the library had not been initialized.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static IntPtr SetMonitorCallback(GLFWCallbacks.MonitorCallback callback)
{
return glfwSetMonitorCallback(Marshal.GetFunctionPointerForDelegate(callback));
}
///
///
/// This function sets the mouse button callback of the specified window,
/// which is called when a mouse button is pressed or released.
///
///
/// When a window loses input focus,
/// it will generate synthetic mouse button release events for all pressed mouse buttons.
/// You can tell these events from user-generated events by the fact that the synthetic ones are generated after
/// the focus loss event has been processed,
/// i.e. after the window focus callback() has been called.
///
///
/// The window whose callback to set.
/// The new callback, or null to remove the currently set callback.
///
/// The previously set callback, or null if no callback was set or the library had not been initialized.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static unsafe IntPtr SetMouseButtonCallback(
Window* window,
GLFWCallbacks.MouseButtonCallback callback)
{
return glfwSetMouseButtonCallback(window, Marshal.GetFunctionPointerForDelegate(callback));
}
///
///
/// This function sets the close callback of the specified window,
/// which is called when the user attempts to close the window,
/// for example by clicking the close widget in the title bar.
///
///
/// The close flag is set before this callback is called,
/// but you can modify it at any time with .
///
///
/// The close callback is not triggered by .
///
///
/// The window whose callback to set.
/// The new callback, or null to remove the currently set callback.
///
/// The previously set callback, or null if no callback was set or the library had not been initialized.
///
///
///
/// This function must only be called from the main thread.
///
///
/// OS X: Selecting Quit from the application menu will trigger the close callback for all windows.
///
///
/// Possible errors include .
///
///
public static unsafe IntPtr SetWindowCloseCallback(
Window* window,
GLFWCallbacks.WindowCloseCallback callback)
{
return glfwSetWindowCloseCallback(window, Marshal.GetFunctionPointerForDelegate(callback));
}
///
///
/// This function sets the focus callback of the specified window,
/// which is called when the window gains or loses input focus.
///
///
/// After the focus callback is called for a window that lost input focus,
/// synthetic key and mouse button release events will be generated for all such that had been pressed.
/// For more information, see and .
///
///
/// The window whose callback to set.
/// The new callback, or null to remove the currently set callback.
///
/// The previously set callback, or null if no callback was set or the library had not been initialized.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static unsafe IntPtr SetWindowFocusCallback(
Window* window,
GLFWCallbacks.WindowFocusCallback callback)
{
return glfwSetWindowFocusCallback(window, Marshal.GetFunctionPointerForDelegate(callback));
}
///
///
/// This function sets the icon of the specified window.
///
///
/// If passed an array of candidate images, those of or closest to the sizes desired by the system are selected.
///
///
/// If no images are specified, the window reverts to its default icon.
///
///
/// The desired image sizes varies depending on platform and system settings.
/// The selected images will be rescaled as needed. Good sizes include 16x16, 32x32 and 48x48.
///
///
/// The window whose icon to set.
/// The images to create the icon from. If zero images are passed, the window is reset to the default icon.
///
///
/// This function must only be called from the main thread.
///
///
/// The specified image data is copied before this function returns.
///
///
/// OS X: The GLFW window has no icon, as it is not a document window, so this function does nothing.
/// The dock icon will be the same as the application bundle's icon. For more information on bundles,
/// see the Bundle Programming Guide in the Mac Developer Library.
///
///
public static unsafe void SetWindowIcon(Window* window, ReadOnlySpan images)
{
fixed (Image* ptr = images)
{
glfwSetWindowIcon(window, images.Length, ptr);
}
}
///
///
/// This function sets the icon of the specified window.
///
///
/// If passed an array of candidate images, those of or closest to the sizes desired by the system are selected.
///
///
/// If no images are specified, the window reverts to its default icon.
///
///
/// The desired image sizes varies depending on platform and system settings.
/// The selected images will be rescaled as needed. Good sizes include 16x16, 32x32 and 48x48.
///
///
/// The window whose icon to set.
/// The number of images in the specified array, or zero to revert to the default window icon.
/// The images to create the icon from. This is ignored if count is zero.
///
///
/// This function must only be called from the main thread.
///
///
/// The specified image data is copied before this function returns.
///
///
/// OS X: The GLFW window has no icon, as it is not a document window, so this function does nothing.
/// The dock icon will be the same as the application bundle's icon. For more information on bundles,
/// see the Bundle Programming Guide in the Mac Developer Library.
///
///
public static unsafe void SetWindowIconRaw(Window* window, int count, Image* images)
{
glfwSetWindowIcon(window, count, images);
}
///
///
/// This function sets the iconification callback of the specified window,
/// which is called when the window is iconified or restored.
///
///
/// The window whose callback to set.
/// The new callback, or null to remove the currently set callback.
///
/// The previously set callback, or null if no callback was set or the library had not been initialized.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static unsafe IntPtr SetWindowIconifyCallback(
Window* window,
GLFWCallbacks.WindowIconifyCallback callback)
{
return glfwSetWindowIconifyCallback(window, Marshal.GetFunctionPointerForDelegate(callback));
}
///
///
/// This function sets the window content scale callback of the specified window,
/// which is called when the content scale of the specified window changes.
///
///
/// The window whose content scale changed.
/// The new x-axis content scale of the window.
/// The new y-axis content scale of the window.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
///
public static unsafe IntPtr SetWindowContentScaleCallback(
Window* window,
GLFWCallbacks.WindowContentScaleCallback callback)
{
return glfwSetWindowContentScaleCallback(window, Marshal.GetFunctionPointerForDelegate(callback));
}
///
///
/// This function sets the monitor that the window uses for full screen mode or,
/// if the monitor is null, makes it windowed mode.
///
///
/// When setting a monitor, this function updates the width, height and refresh rate
/// of the desired video mode and switches to the video mode closest to it.
///
///
/// The window position is ignored when setting a monitor.
///
///
/// When the monitor is null, the position, width and height are used to place the window client area.
/// The refresh rate is ignored when no monitor is specified.
///
///
/// If you only wish to update the resolution of a full screen window or the size of a windowed mode window,
/// see .
///
///
/// When a window transitions from full screen to windowed mode,
/// this function restores any previous window settings such as whether it is decorated,
/// floating, resizable, has size or aspect ratio limits, etc..
///
///
/// The window whose monitor, size or video mode to set.
/// The desired monitor, or null to set windowed mode.
/// The desired x-coordinate of the upper-left corner of the client area.
/// The desired y-coordinate of the upper-left corner of the client area.
/// The desired with, in screen coordinates, of the client area or video mode.
/// The desired height, in screen coordinates, of the client area or video mode.
/// The desired refresh rate, in Hz, of the video mode, or .
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
///
public static unsafe void SetWindowMonitor(
Window* window,
Monitor* monitor,
int x,
int y,
int width,
int height,
int refreshRate)
{
glfwSetWindowMonitor(window, monitor, x, y, width, height, refreshRate);
}
///
///
/// This function sets the position, in screen coordinates,
/// of the upper-left corner of the client area of the specified windowed mode window.
///
///
/// If the window is a full screen window, this function does nothing.
///
///
/// Do not use this function to move an already visible window
/// unless you have very good reasons for doing so, as it will confuse and annoy the user.
///
///
/// The window manager may put limits on what positions are allowed.
/// GLFW cannot and should not override these limits.
///
///
/// The window to query.
/// The x-coordinate of the upper-left corner of the client area.
/// The y-coordinate of the upper-left corner of the client area.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static unsafe void SetWindowPos(Window* window, int x, int y)
{
glfwSetWindowPos(window, x, y);
}
///
///
/// This function sets the position callback of the specified window, which is called when the window is moved.
///
///
/// The callback is provided with the screen position of the upper-left corner of the client area of the window.
///
///
/// The window whose callback to set.
/// The new callback, or null to remove the currently set callback.
///
/// The previously set callback, or null if no callback was set or the library had not been initialized.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static unsafe IntPtr SetWindowPosCallback(
Window* window,
GLFWCallbacks.WindowPosCallback callback)
{
return glfwSetWindowPosCallback(window, Marshal.GetFunctionPointerForDelegate(callback));
}
///
///
/// Sets the refresh callback for the specified window.
///
///
/// This function sets the refresh callback of the specified window, which is
/// called when the content area of the window needs to be redrawn, for example
/// if the window has been exposed after having been covered by another window.
///
///
/// On compositing window systems such as Aero, Compiz, Aqua or Wayland, where
/// the window contents are saved off-screen, this callback may be called only
/// very infrequently or never at all.
///
///
/// The window whose callback to set.
/// The new callback, or null to remove the currently set callback.
///
/// The previously set callback, or null if no callback was set or the library had not been initialized.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static unsafe IntPtr SetWindowRefreshCallback(
Window* window,
GLFWCallbacks.WindowRefreshCallback callback)
{
return glfwSetWindowRefreshCallback(window, Marshal.GetFunctionPointerForDelegate(callback));
}
///
///
/// This function sets the size, in screen coordinates, of the client area of the specified window.
///
///
/// For full screen windows, this function updates the resolution of its desired video mode
/// and switches to the video mode closest to it, without affecting the window's context.
///
///
/// As the context is unaffected, the bit depths of the framebuffer remain unchanged.
///
///
/// If you wish to update the refresh rate of the desired video mode in addition to its resolution,
/// see .
///
///
/// The window manager may put limits on what sizes are allowed.
/// GLFW cannot and should not override these limits.
///
///
/// The window to resize.
/// The desired width, in screen coordinates, of the window client area.
/// The desired height, in screen coordinates, of the window client area.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
///
public static unsafe void SetWindowSize(Window* window, int width, int height)
{
glfwSetWindowSize(window, width, height);
}
///
///
/// This function sets the size callback of the specified window, which is called when the window is resized.
///
///
/// The callback is provided with the size, in screen coordinates, of the client area of the window.
///
///
/// The window whose callback to set.
/// The new callback, or null to remove the currently set callback.
///
/// The previously set callback, or null if no callback was set or the library had not been initialized.
///
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include .
///
///
public static unsafe IntPtr SetWindowSizeCallback(
Window* window,
GLFWCallbacks.WindowSizeCallback callback)
{
return glfwSetWindowSizeCallback(window, Marshal.GetFunctionPointerForDelegate(callback));
}
///
///
/// This function sets the value of the close flag of the specified window.
///
///
/// This can be used to override the user's attempt to close the window, or to signal that it should be closed.
///
///
/// The window whose flag to change.
/// The new value.
///
///
/// This function may be called from any thread. Access is not synchronized.
///
///
/// Possible errors include .
///
///
public static unsafe void SetWindowShouldClose(Window* window, bool value)
{
glfwSetWindowShouldClose(window, value ? GLFW_TRUE : GLFW_FALSE);
}
///
///
/// This function sets the window title, encoded as UTF-8, of the specified window.
///
///
/// The window whose title to change.
/// The UTF-8 encoded window title.
///
///
/// This function must only be called from the main thread.
///
///
/// OS X: The window title will not be updated until the next time you process events.
///
///
/// Possible errors include and .
///
///
public static unsafe void SetWindowTitle(Window* window, string title)
{
var ptr = StringToCoTaskMemUTF8(title);
try
{
glfwSetWindowTitle(window, (byte*)ptr);
}
finally
{
Marshal.FreeCoTaskMem(ptr);
}
}
///
///
/// This function sets the window title, encoded as UTF-8, of the specified window.
///
///
/// The window whose title to change.
/// The UTF-8 encoded window title.
///
///
/// This function must only be called from the main thread.
///
///
/// OS X: The window title will not be updated until the next time you process events.
///
///
/// Possible errors include and .
///
///
public static unsafe void SetWindowTitleRaw(Window* window, byte* title)
{
glfwSetWindowTitle(window, title);
}
///
///
/// This function makes the specified window visible if it was previously hidden.
///
///
/// If the window is already visible or is in full screen mode, this function does nothing.
///
///
/// The window to make visible.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static unsafe void ShowWindow(Window* window) => glfwShowWindow(window);
///
///
/// This function sets the swap interval for the current OpenGL or OpenGL ES context,
/// i.e. the number of screen updates to wait from the time was called
/// before swapping the buffers and returning.
/// This is sometimes called vertical synchronization, vertical retrace synchronization or just vsync.
///
///
/// A context that supports either of the WGL_EXT_swap_control_tear
/// and GLX_EXT_swap_control_tear extensions also accepts negative swap intervals,
/// which allows the driver to swap immediately even if a frame arrives a little bit late.
/// You can check for these extensions with .
///
///
/// A context must be current on the calling thread.
/// Calling this function without a current context will cause a error.
///
///
///
/// The minimum number of screen updates to wait for until the buffers are swapped by .
///
///
///
/// This function is not called during context creation,
/// leaving the swap interval set to whatever is the default on that platform.
/// This is done because some swap interval extensions used by GLFW
/// do not allow the swap interval to be reset to zero once it has been set to a non-zero value.
///
///
/// Some GPU drivers do not honor the requested swap interval,
/// either because of a user setting that overrides the application's request or due to bugs in the driver.
///
///
/// This function may be called from any thread.
///
///
/// Possible errors include , and .
///
///
///
public static void SwapInterval(int interval) => glfwSwapInterval(interval);
///
///
/// This function puts the calling thread to sleep until at least one event is available in the event queue.
///
///
/// Once one or more events are available, it behaves exactly like ,
/// i.e. the events in the queue are processed and the function then returns immediately.
///
///
/// Processing events will cause the window and input callbacks associated with those events to be called.
///
///
/// Since not all events are associated with callbacks,
/// this function may return without a callback having been called even if you are monitoring all callbacks.
///
///
/// On some platforms, a window move, resize or menu operation will cause event processing to block.
/// This is due to how event processing is designed on those platforms.
/// You can use the window refresh callback ()
/// to redraw the contents of your window when necessary during such operations.
///
///
/// On some platforms,
/// certain callbacks may be called outside of a call to one of the event processing functions.
///
///
/// If no windows exist, this function returns immediately.
/// For synchronization of threads in applications that do not create windows,
/// use your threading library of choice.
///
///
/// Event processing is not required for joystick input to work.
///
///
///
/// This function must only be called from the main thread.
///
/// This function must not be called from a callback.
///
/// Possible errors include and .
///
///
///
public static void WaitEvents() => glfwWaitEvents();
///
///
/// This function puts the calling thread to sleep until at least one event is available in the event queue,
/// or until the specified timeout is reached.
///
///
/// If one or more events are available, it behaves exactly like ,
/// i.e. the events in the queue are processed and the function then returns immediately.
///
///
/// Processing events will cause the window and input callbacks associated with those events to be called.
///
///
/// The timeout value must be a positive finite number.
///
///
/// Since not all events are associated with callbacks,
/// this function may return without a callback having been called even if you are monitoring all callbacks.
///
///
/// On some platforms, a window move, resize or menu operation will cause event processing to block.
/// This is due to how event processing is designed on those platforms.
///
///
/// You can use the window refresh callback ()
/// to redraw the contents of your window when necessary during such operations.
///
///
/// On some platforms,
/// certain callbacks may be called outside of a call to one of the event processing functions.
///
///
/// If no windows exist, this function returns immediately.
///
///
/// For synchronization of threads in applications that do not create windows,
/// use your threading library of choice.
///
///
/// Event processing is not required for joystick input to work.
///
///
/// The maximum amount of time, in seconds, to wait.
///
///
/// This function must only be called from the main thread.
///
///
/// This function must not be called from a callback.
///
///
///
///
public static void WaitEventsTimeout(double timeout) => glfwWaitEventsTimeout(timeout);
///
///
/// This function sets hints for the next call to .
/// The hints, once set, retain their values
/// until changed by a call to
/// or , or until the library is terminated.
///
///
/// This function does not check whether the specified hint values are valid.
/// If you set hints to invalid values this will instead be reported
/// by the next call to .
///
///
/// The to set.
/// The new value of the framebuffer attribute hint.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static void WindowHint(WindowHintInt hint, int value) => glfwWindowHint(hint, value);
///
///
/// This function sets hints for the next call to .
/// The hints, once set, retain their values
/// until changed by a call to
/// or , or until the library is terminated.
///
///
/// This function does not check whether the specified hint values are valid.
/// If you set hints to invalid values this will instead be reported
/// by the next call to .
///
///
/// The to set.
/// The new value of the framebuffer attribute hint.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static void WindowHint(WindowHintBool hint, bool value)
{
glfwWindowHint(hint, value ? GLFW_TRUE : GLFW_FALSE);
}
///
///
/// This function sets hints for the next call to .
/// The hints, once set, retain their values
/// until changed by a call to
/// or , or until the library is terminated.
///
///
/// This function does not check whether the specified hint values are valid.
/// If you set hints to invalid values this will instead be reported
/// by the next call to .
///
///
/// .
/// The new value of the window hint.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static void WindowHint(WindowHintClientApi hint, ClientApi value) => glfwWindowHint(hint, value);
///
///
/// This function sets hints for the next call to .
/// The hints, once set, retain their values
/// until changed by a call to
/// or , or until the library is terminated.
///
///
/// This function does not check whether the specified hint values are valid.
/// If you set hints to invalid values this will instead be reported
/// by the next call to .
///
///
/// .
/// The new value of the window hint.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static void WindowHint(WindowHintReleaseBehavior hint, ReleaseBehavior value)
{
glfwWindowHint(hint, value);
}
///
///
/// This function sets hints for the next call to .
/// The hints, once set, retain their values
/// until changed by a call to
/// or , or until the library is terminated.
///
///
/// This function does not check whether the specified hint values are valid.
/// If you set hints to invalid values this will instead be reported
/// by the next call to .
///
///
/// .
/// The new value of the window hint.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static void WindowHint(WindowHintContextApi hint, ContextApi value)
{
glfwWindowHint(hint, value);
}
///
///
/// This function sets hints for the next call to .
/// The hints, once set, retain their values
/// until changed by a call to
/// or , or until the library is terminated.
///
///
/// This function does not check whether the specified hint values are valid.
/// If you set hints to invalid values this will instead be reported
/// by the next call to .
///
///
/// .
/// The new value of the window hint.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static void WindowHint(WindowHintRobustness hint, Robustness value)
{
glfwWindowHint(hint, value);
}
///
///
/// This function sets hints for the next call to .
/// The hints, once set, retain their values
/// until changed by a call to
/// or , or until the library is terminated.
///
///
/// This function does not check whether the specified hint values are valid.
/// If you set hints to invalid values this will instead be reported
/// by the next call to .
///
///
/// .
/// The new value of the window hint.
///
///
/// This function must only be called from the main thread.
///
///
/// Possible errors include and .
///
///
///
public static void WindowHint(WindowHintOpenGlProfile hint, OpenGlProfile value)
{
glfwWindowHint(hint, value);
}
///
///
/// This function returns the value of the close flag of the specified window.
///
///
/// The window to query.
/// The value of the close flag.
///
///
/// This function may be called from any thread. Access is not synchronized.
///
///
/// Possible errors include .
///
///
public static unsafe bool WindowShouldClose(Window* window) => glfwWindowShouldClose(window) == GLFW_TRUE;
///
/// Returns whether the Vulkan loader and an ICD have been found.
///
///
///
/// This function returns whether the Vulkan loader and any minimally functional ICD have been found.
///
///
/// The availability of a Vulkan loader and even an ICD does not by itself
/// guarantee that surface creation or even instance creation is possible.
/// For example, on Fermi systems Nvidia will install an ICD that provides no actual Vulkan support.
/// Call to check whether the extensions necessary
/// for Vulkan surface creation are available and
/// to check whether a queue family of a physical device supports image presentation.
///
///
/// Possible errors include .
///
///
/// This function may be called from any thread.
///
///
///
/// true if Vulkan is minimally available, or false otherwise.
///
public static bool VulkanSupported() => glfwVulkanSupported() == GLFW_TRUE;
///
/// Returns the Vulkan instance extensions required by GLFW.
///
///
///
/// This function returns an array of names of Vulkan instance extensions required by GLFW for
/// creating Vulkan surfaces for GLFW windows. If successful, the list will always contains
/// VK_KHR_surface, so if you don't require any additional extensions you can
/// pass this list directly to the VkInstanceCreateInfo struct.
///
///
/// If Vulkan is not available on the machine, this function returns null and generates
/// a error. Call to check
/// whether Vulkan is at least minimally available.
///
///
/// If Vulkan is available but no set of extensions allowing window surface creation was found,
/// this function returns null. You may still use Vulkan for off-screen rendering and compute work.
///
///
/// Additional extensions may be required by future versions of GLFW.
/// You should check if any extensions you wish to enable are already in the returned array,
/// as it is an error to specify an extension more than once in the VkInstanceCreateInfo struct.
///
///
/// macOS: This function currently only supports the VK_MVK_macos_surface extension from MoltenVK.
///
///
/// Possible errors include and .
///
///
/// The returned array is allocated and freed by GLFW. You should not free it yourself.
/// It is guaranteed to be valid only until the library is terminated.
///
///
/// This function may be called from any thread.
///
///
///
/// Where to store the number of extensions in the returned array.
/// This is set to zero if an error occurred.
///
///
/// An array of ASCII encoded extension names, or null if an error occurred.
///
public static unsafe byte** GetRequiredInstanceExtensionsRaw(out uint count)
{
fixed (uint* ptr = &count)
{
return glfwGetRequiredInstanceExtensions(ptr);
}
}
///
/// Returns the Vulkan instance extensions required by GLFW.
///
///
///
/// This function returns an array of names of Vulkan instance extensions required by GLFW for
/// creating Vulkan surfaces for GLFW windows. If successful, the list will always contains
/// VK_KHR_surface, so if you don't require any additional extensions you can
/// pass this list directly to the VkInstanceCreateInfo struct.
///
///
/// If Vulkan is not available on the machine, this function returns null and generates
/// a error. Call to check
/// whether Vulkan is at least minimally available.
///
///
/// If Vulkan is available but no set of extensions allowing window surface creation was found,
/// this function returns null. You may still use Vulkan for off-screen rendering and compute work.
///
///
/// Additional extensions may be required by future versions of GLFW.
/// You should check if any extensions you wish to enable are already in the returned array,
/// as it is an error to specify an extension more than once in the VkInstanceCreateInfo struct.
///
///
/// macOS: This function currently only supports the VK_MVK_macos_surface extension from MoltenVK.
///
///
/// Possible errors include and .
///
///
/// The returned array is allocated and freed by GLFW. You should not free it yourself.
/// It is guaranteed to be valid only until the library is terminated.
///
///
/// This function may be called from any thread.
///
///
///
/// Where to store the number of extensions in the returned array.
/// This is set to zero if an error occurred.
///
///
/// An array of ASCII encoded extension names, or null if an error occurred.
///
public static unsafe byte** GetRequiredInstanceExtensionsRaw(uint* count)
{
return glfwGetRequiredInstanceExtensions(count);
}
///
/// Returns the Vulkan instance extensions required by GLFW.
///
///
///
/// This function returns an array of names of Vulkan instance extensions required by GLFW for
/// creating Vulkan surfaces for GLFW windows. If successful, the list will always contains
/// VK_KHR_surface, so if you don't require any additional extensions you can
/// pass this list directly to the VkInstanceCreateInfo struct.
///
///
/// If Vulkan is not available on the machine, this function returns null and generates
/// a error. Call to check
/// whether Vulkan is at least minimally available.
///
///
/// If Vulkan is available but no set of extensions allowing window surface creation was found,
/// this function returns null. You may still use Vulkan for off-screen rendering and compute work.
///
///
/// Additional extensions may be required by future versions of GLFW.
/// You should check if any extensions you wish to enable are already in the returned array,
/// as it is an error to specify an extension more than once in the VkInstanceCreateInfo struct.
///
///
/// macOS: This function currently only supports the VK_MVK_macos_surface extension from MoltenVK.
///
///
/// Possible errors include and .
///
///
/// The returned array is allocated and freed by GLFW. You should not free it yourself.
/// It is guaranteed to be valid only until the library is terminated.
///
///
/// This function may be called from any thread.
///
///
///
/// An array of ASCII encoded extension names, or null if an error occurred.
///
public static unsafe string[] GetRequiredInstanceExtensions()
{
var ptr = GetRequiredInstanceExtensionsRaw(out var count);
var array = new string[count];
for (var i = 0; i < count; i++)
{
array[i] = PtrToStringUTF8(ptr[i]);
}
return array;
}
///
/// Returns the address of the specified Vulkan instance function.
///
///
///
/// This function returns the address of the specified Vulkan core or extension function for
/// the specified instance. If instance is set to null it can return any function exported
/// from the Vulkan loader, including at least the following functions:
///
///
/// -
/// vkEnumerateInstanceExtensionProperties
/// vkEnumerateInstanceLayerProperties
/// vkCreateInstance
/// vkGetInstanceProcAddr
///
///
///
/// If Vulkan is not available on the machine, this function returns null and generates
/// a error. Call to check
/// whether Vulkan is at least minimally available.
///
///
/// This function is equivalent to calling vkGetInstanceProcAddr with a platform-specific
/// query of the Vulkan loader as a fallback.
///
///
/// Possible errors include and .
///
///
/// The returned function pointer is valid until the library is terminated.
///
///
///
/// The Vulkan instance to query, or null to retrieve functions related to instance creation.
///
/// The ASCII encoded name of the function.
/// The address of the function, or null if an error occurred.
public static unsafe IntPtr GetInstanceProcAddress(VkHandle instance, string procName)
{
var ptr = StringToCoTaskMemUTF8(procName);
try
{
return glfwGetInstanceProcAddress(instance, (byte*)ptr);
}
finally
{
Marshal.FreeCoTaskMem(ptr);
}
}
///
/// Returns the address of the specified Vulkan instance function.
///
///
///
/// This function returns the address of the specified Vulkan core or extension function for
/// the specified instance. If instance is set to null it can return any function exported
/// from the Vulkan loader, including at least the following functions:
///
///
/// -
/// vkEnumerateInstanceExtensionProperties
/// vkEnumerateInstanceLayerProperties
/// vkCreateInstance
/// vkGetInstanceProcAddr
///
///
///
/// If Vulkan is not available on the machine, this function returns null and generates
/// a error. Call to check
/// whether Vulkan is at least minimally available.
///
///
/// This function is equivalent to calling vkGetInstanceProcAddr with a platform-specific
/// query of the Vulkan loader as a fallback.
///
///
/// Possible errors include and .
///
///
/// The returned function pointer is valid until the library is terminated.
///
///
///
/// The Vulkan instance to query, or null to retrieve functions related to instance creation.
///
/// The ASCII encoded name of the function.
/// The address of the function, or null if an error occurred.
public static unsafe IntPtr GetInstanceProcAddressRaw(VkHandle instance, byte* procName)
{
return glfwGetInstanceProcAddress(instance, procName);
}
///
/// Returns whether the specified queue family can present images.
///
///
///
/// This function returns whether the specified queue family of the specified physical device
/// supports presentation to the platform GLFW was built for.
///
///
/// If Vulkan or the required window surface creation instance extensions are not available
/// on the machine, or if the specified instance was not created with the required extensions,
/// this function returns false and generates a error.
/// Call to check whether Vulkan is at least minimally available and
/// to check what instance extensions are required.
///
///
/// Possible errors include and .
///
///
/// macOS: This function currently always returns true, as the VK_MVK_macos_surface
/// extension does not provide a vkGetPhysicalDevice*PresentationSupport type function.
///
///
/// This function may be called from any thread.
/// For synchronization details of Vulkan objects, see the Vulkan specification.
///
///
/// The instance that the physical device belongs to.
/// The physical device that the queue family belongs to.
/// The index of the queue family to query.
/// true if the queue family supports presentation, or false otherwise.
public static bool GetPhysicalDevicePresentationSupport(VkHandle instance, VkHandle device, int queueFamily)
{
return glfwGetPhysicalDevicePresentationSupport(instance, device, queueFamily) == GLFW_TRUE;
}
///
/// Creates a Vulkan surface for the specified window.
///
///
///
/// This function creates a Vulkan surface for the specified window.
///
///
/// If the Vulkan loader or at least one minimally functional ICD were not found,
/// this function returns VK_ERROR_INITIALIZATION_FAILED and generates a
/// error.
/// Call to check whether Vulkan is at least minimally available.
///
///
/// If the required window surface creation instance extensions are not available or
/// if the specified instance was not created with these extensions enabled,
/// this function returns VK_ERROR_EXTENSION_NOT_PRESENT and generates a
/// error.
/// Call to check what instance extensions are required.
///
///
/// The window surface cannot be shared with another API so the window must have been created with
/// the client api hint set to otherwise it generates a
/// error and returns VK_ERROR_NATIVE_WINDOW_IN_USE_KHR.
///
///
/// The window surface must be destroyed before the specified Vulkan instance.
/// It is the responsibility of the caller to destroy the window surface.
/// GLFW does not destroy it for you. Call vkDestroySurfaceKHR to destroy the surface.
///
///
/// Possible errors include , ,
/// and .
///
///
/// If an error occurs before the creation call is made, GLFW returns the Vulkan error code most
/// appropriate for the error. Appropriate use of and
/// should eliminate almost all occurrences of these errors.
///
///
/// macOS: This function currently only supports the VK_MVK_macos_surface extension from MoltenVK.
///
///
/// macOS: This function creates and sets a CAMetalLayer instance for the window content view,
/// which is required for MoltenVK to function.
///
///
/// This function may be called from any thread.
/// For synchronization details of Vulkan objects, see the Vulkan specification.
///
///
/// The Vulkan instance to create the surface in.
/// The window to create the surface for.
/// The allocator to use, or null to use the default allocator.
///
/// Where to store the handle of the surface.
/// This is set to VK_NULL_HANDLE if an error occurred.
///
///
/// VK_SUCCESS if successful, or a Vulkan error code if an error occurred.
///
public static unsafe int CreateWindowSurface(
VkHandle instance,
Window* window,
void* allocator,
VkHandle surface)
{
return glfwCreateWindowSurface(instance, window, allocator, surface);
}
public static unsafe uint GetX11Window(Window* window)
{
return glfwGetX11Window(window);
}
public static unsafe IntPtr GetWin32Window(Window* window)
{
return glfwGetWin32Window(window);
}
}
}