RI::Window¶
What it is¶
RI::Window describes a window as the operating system knows it: plain OS handles, never a
native graphics object. RI creates no windows and ships no window library. You
create the window with the library of your choice and fill in this struct;
createSwapchain and the swapchain query functions (surfaceFormats,
presentModeSupported, screenStorageSupported) take it to inspect or present to the window.
system |
display |
handle |
id |
|---|---|---|---|
WindowSystem::eWin32 |
HINSTANCE |
HWND |
unused |
WindowSystem::eXlib |
Display* |
unused | the X11 Window |
WindowSystem::eXcb |
xcb_connection_t* |
unused | the xcb_window_t |
WindowSystem::eWayland |
wl_display* |
wl_surface* |
unused |
Pointer-sized handles (HWND, wl_surface*) go in handle; integer window IDs (X11 Window,
xcb_window_t) go in id (uint64) so no pointer cast is needed.
Signature¶
// <RI/RI.hpp>, namespace RI
struct Window {
WindowSystem system = WindowSystem::eWin32;
void *display = nullptr;
void *handle = nullptr; // pointer-sized handles (HWND, wl_surface*)
uint64 id = 0; // integer ids (X11 Window, xcb_window_t)
};
| Field | Type | Default | Description |
|---|---|---|---|
system |
WindowSystem |
WindowSystem::eWin32 |
|
display |
void * |
nullptr |
|
handle |
void * |
nullptr |
pointer-sized handles (HWND, wl_surface*) |
id |
uint64 |
0 |
integer ids (X11 Window, xcb_window_t) |
// <RI/RI.hpp>, namespace RI
enum class WindowSystem : uint8 {
eWin32, // display: HINSTANCE, window: HWND
eXlib, // display: Display*, window: the X11 Window id
eXcb, // display: xcb_connection_t*, window: the xcb_window_t id
eWayland, // display: wl_display*, window: wl_surface*
};
| Value | Meaning |
|---|---|
eWin32 |
display: HINSTANCE, window: HWND |
eXlib |
display: Display*, window: the X11 Window id |
eXcb |
display: xcb_connection_t*, window: the xcb_window_t id |
eWayland |
display: wl_display, window: wl_surface |
Example¶
// Win32: the window you created with CreateWindowExW.
const RI::Window window{
.system = RI::WindowSystem::eWin32,
.display = GetModuleHandleW(nullptr),
.handle = hwnd,
};
From a GLFW window¶
To wrap a GLFW window, include glfw3native.h and read the OS handles shown below. Create the
GLFW window with GLFW_CLIENT_API set to GLFW_NO_API so GLFW does not create a graphics
context—RI talks to the GPU directly. RI's own tests and examples use this code, but GLFW is
not part of RI.
#include <GLFW/glfw3.h>
#if defined(_WIN32)
#define GLFW_EXPOSE_NATIVE_WIN32
#else
#define GLFW_EXPOSE_NATIVE_X11
#define GLFW_EXPOSE_NATIVE_WAYLAND
#endif
#include <GLFW/glfw3native.h>
// The OS handles of a GLFW window, on the platform GLFW runs on.
RI::Window windowOf(GLFWwindow *window) {
#if defined(_WIN32)
return {.system = RI::WindowSystem::eWin32, .display = GetModuleHandleW(nullptr), .handle = glfwGetWin32Window(window)};
#else
if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) {
return {.system = RI::WindowSystem::eWayland,
.display = glfwGetWaylandDisplay(),
.handle = glfwGetWaylandWindow(window)};
}
return {.system = RI::WindowSystem::eXlib, .display = glfwGetX11Display(), .id = glfwGetX11Window(window)};
#endif
}
Another window library (such as SDL, Qt, or your own Win32 code) fills the same fields from its native handles.
Rules / errors¶
- The handles must stay valid while a swapchain uses them.
- On D3D12, only
WindowSystem::eWin32with a non-nullhandle(HWND) is supported; other window systems or a nullhandlereportErrorCategory::eUnsupported. - On Vulkan, all four
WindowSystemvalues are supported if the Vulkan loader provides the corresponding surface creation function; otherwise RI reportsErrorCategory::eUnsupported.