From 9cffe5ac8bdccd6ec66c1426f5395c16d6662825 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sat, 30 Jul 2022 10:18:47 -0700 Subject: [PATCH] glfw: add assumeInitialized for external GLFW initialization Signed-off-by: Stephen Gutekanst --- glfw/src/internal_debug.zig | 3 +++ glfw/src/main.zig | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/glfw/src/internal_debug.zig b/glfw/src/internal_debug.zig index 74a085e6..248228f8 100644 --- a/glfw/src/internal_debug.zig +++ b/glfw/src/internal_debug.zig @@ -9,3 +9,6 @@ pub inline fn toggleInitialized() void { pub inline fn assertInitialized() void { if (debug_mode) std.debug.assert(glfw_initialized); } +pub inline fn assumeInitialized() void { + glfw_initialized = true; +} diff --git a/glfw/src/main.zig b/glfw/src/main.zig index bb10f3c7..b5daed9e 100644 --- a/glfw/src/main.zig +++ b/glfw/src/main.zig @@ -41,6 +41,14 @@ pub usingnamespace @import("mod.zig"); const internal_debug = @import("internal_debug.zig"); +/// If GLFW was already initialized in your program, e.g. you are embedding Zig code into an existing +/// program that has already called glfwInit via the C API for you - then you need to tell mach/glfw +/// that it has in fact been initialized already, otherwise when you call other methods mach/glfw +/// would panic thinking glfw.init has not been called yet. +pub fn assumeInitialized() void { + internal_debug.assumeInitialized(); +} + /// Initializes the GLFW library. /// /// This function initializes the GLFW library. Before most GLFW functions can be used, GLFW must