2024-02-13 19:45:29 +00:00
|
|
|
# Internal structure {#internals_guide}
|
2013-06-12 13:03:56 +00:00
|
|
|
|
2024-02-13 21:42:49 +00:00
|
|
|
[TOC]
|
2013-06-12 13:03:56 +00:00
|
|
|
|
|
|
|
There are several interfaces inside GLFW. Each interface has its own area of
|
|
|
|
responsibility and its own naming conventions.
|
|
|
|
|
|
|
|
|
2024-02-13 19:45:29 +00:00
|
|
|
## Public interface {#internals_public}
|
2013-06-12 13:03:56 +00:00
|
|
|
|
|
|
|
The most well-known is the public interface, described in the glfw3.h header
|
|
|
|
file. This is implemented in source files shared by all platforms and these
|
|
|
|
files contain no platform-specific code. This code usually ends up calling the
|
|
|
|
platform and internal interfaces to do the actual work.
|
|
|
|
|
|
|
|
The public interface uses the OpenGL naming conventions except with GLFW and
|
|
|
|
glfw instead of GL and gl. For struct members, where OpenGL sets no precedent,
|
|
|
|
it use headless camel case.
|
|
|
|
|
2018-01-17 10:25:32 +00:00
|
|
|
Examples: `glfwCreateWindow`, `GLFWwindow`, `GLFW_RED_BITS`
|
2013-06-12 13:03:56 +00:00
|
|
|
|
|
|
|
|
2024-02-13 19:45:29 +00:00
|
|
|
## Native interface {#internals_native}
|
2013-06-12 13:03:56 +00:00
|
|
|
|
|
|
|
The [native interface](@ref native) is a small set of publicly available
|
|
|
|
but platform-specific functions, described in the glfw3native.h header file and
|
|
|
|
used to gain access to the underlying window, context and (on some platforms)
|
|
|
|
display handles used by the platform interface.
|
|
|
|
|
|
|
|
The function names of the native interface are similar to those of the public
|
|
|
|
interface, but embeds the name of the interface that the returned handle is
|
|
|
|
from.
|
|
|
|
|
2018-01-17 10:25:32 +00:00
|
|
|
Examples: `glfwGetX11Window`, `glfwGetWGLContext`
|
2013-06-12 13:03:56 +00:00
|
|
|
|
|
|
|
|
2024-02-13 19:45:29 +00:00
|
|
|
## Internal interface {#internals_internal}
|
2013-06-12 13:03:56 +00:00
|
|
|
|
|
|
|
The internal interface consists of utility functions used by all other
|
|
|
|
interfaces. It is shared code implemented in the same shared source files as
|
|
|
|
the public and event interfaces. The internal interface is described in the
|
|
|
|
internal.h header file.
|
|
|
|
|
|
|
|
The internal interface is in charge of GLFW's global data, which it stores in
|
|
|
|
a `_GLFWlibrary` struct named `_glfw`.
|
|
|
|
|
|
|
|
The internal interface uses the same style as the public interface, except all
|
|
|
|
global names have a leading underscore.
|
|
|
|
|
2018-01-17 10:25:32 +00:00
|
|
|
Examples: `_glfwIsValidContextConfig`, `_GLFWwindow`, `_glfw.monitorCount`
|
2013-06-12 13:03:56 +00:00
|
|
|
|
|
|
|
|
2024-02-13 19:45:29 +00:00
|
|
|
## Platform interface {#internals_platform}
|
2013-06-12 13:03:56 +00:00
|
|
|
|
|
|
|
The platform interface implements all platform-specific operations as a service
|
|
|
|
to the public interface. This includes event processing. The platform
|
2014-04-23 11:30:11 +00:00
|
|
|
interface is never directly called by application code and never directly calls
|
|
|
|
application-provided callbacks. It is also prohibited from modifying the
|
|
|
|
platform-independent part of the internal structs. Instead, it calls the event
|
|
|
|
interface when events interesting to GLFW are received.
|
2013-06-12 13:03:56 +00:00
|
|
|
|
2021-07-13 19:50:09 +00:00
|
|
|
The platform interface mostly mirrors those parts of the public interface that needs to
|
|
|
|
perform platform-specific operations on some or all platforms.
|
2013-06-12 13:03:56 +00:00
|
|
|
|
2021-07-13 19:50:09 +00:00
|
|
|
The window system bits of the platform API is called through the `_GLFWplatform` struct of
|
|
|
|
function pointers, to allow runtime selection of platform. This includes the window and
|
|
|
|
context creation, input and event processing, monitor and Vulkan surface creation parts of
|
|
|
|
GLFW. This is located in the global `_glfw` struct.
|
|
|
|
|
|
|
|
Examples: `_glfw.platform.createWindow`
|
|
|
|
|
|
|
|
The timer, threading and module loading bits of the platform API are plain functions with
|
|
|
|
a `_glfwPlatform` prefix, as these things are independent of what window system is being
|
|
|
|
used.
|
|
|
|
|
|
|
|
Examples: `_glfwPlatformGetTimerValue`
|
2013-06-12 13:03:56 +00:00
|
|
|
|
|
|
|
The platform interface also defines structs that contain platform-specific
|
|
|
|
global and per-object state. Their names mirror those of the internal
|
|
|
|
interface, except that an interface-specific suffix is added.
|
|
|
|
|
|
|
|
Examples: `_GLFWwindowX11`, `_GLFWcontextWGL`
|
|
|
|
|
|
|
|
These structs are incorporated as members into the internal interface structs
|
|
|
|
using special macros that name them after the specific interface used. This
|
|
|
|
prevents shared code from accidentally using these members.
|
|
|
|
|
2018-01-17 10:25:32 +00:00
|
|
|
Examples: `window->win32.handle`, `_glfw.x11.display`
|
2013-06-12 13:03:56 +00:00
|
|
|
|
|
|
|
|
2024-02-13 19:45:29 +00:00
|
|
|
## Event interface {#internals_event}
|
2013-06-12 13:03:56 +00:00
|
|
|
|
|
|
|
The event interface is implemented in the same shared source files as the public
|
2014-04-23 11:30:11 +00:00
|
|
|
interface and is responsible for delivering the events it receives to the
|
|
|
|
application, either via callbacks, via window state changes or both.
|
2013-06-12 13:03:56 +00:00
|
|
|
|
|
|
|
The function names of the event interface use a `_glfwInput` prefix and the
|
|
|
|
ObjectEvent pattern.
|
|
|
|
|
2018-01-17 10:25:32 +00:00
|
|
|
Examples: `_glfwInputWindowFocus`, `_glfwInputCursorPos`
|
2013-06-12 13:03:56 +00:00
|
|
|
|
|
|
|
|
2024-02-13 19:45:29 +00:00
|
|
|
## Static functions {#internals_static}
|
2013-06-12 13:03:56 +00:00
|
|
|
|
|
|
|
Static functions may be used by any interface and have no prefixes or suffixes.
|
|
|
|
These use headless camel case.
|
|
|
|
|
2018-01-17 10:25:32 +00:00
|
|
|
Examples: `isValidElementForJoystick`
|
2013-06-12 13:03:56 +00:00
|
|
|
|
|
|
|
|
2024-02-13 19:45:29 +00:00
|
|
|
## Configuration macros {#internals_config}
|
2013-06-12 13:03:56 +00:00
|
|
|
|
|
|
|
GLFW uses a number of configuration macros to select at compile time which
|
2021-04-15 13:33:19 +00:00
|
|
|
interfaces and code paths to use. They are defined in the GLFW CMake target.
|
2013-06-12 13:03:56 +00:00
|
|
|
|
|
|
|
Configuration macros the same style as tokens in the public interface, except
|
|
|
|
with a leading underscore.
|
|
|
|
|
2018-01-17 10:25:32 +00:00
|
|
|
Examples: `_GLFW_WIN32`, `_GLFW_BUILD_DLL`
|
2013-06-12 13:03:56 +00:00
|
|
|
|