glfw: add glfw.getCurrentContext
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
5d91cbbfbd
commit
9610b80699
1 changed files with 31 additions and 18 deletions
|
@ -33,6 +33,25 @@ pub inline fn makeContextCurrent(window: ?Window) Error!void {
|
||||||
if (window) |w| c.glfwMakeContextCurrent(w.handle) else c.glfwMakeContextCurrent(null);
|
if (window) |w| c.glfwMakeContextCurrent(w.handle) else c.glfwMakeContextCurrent(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the window whose context is current on the calling thread.
|
||||||
|
///
|
||||||
|
/// This function returns the window whose OpenGL or OpenGL ES context is current on the calling
|
||||||
|
/// thread.
|
||||||
|
///
|
||||||
|
/// Returns he window whose context is current, or null if no window's context is current.
|
||||||
|
///
|
||||||
|
/// Possible errors include glfw.Error.NotInitialized.
|
||||||
|
///
|
||||||
|
/// @thread_safety This function may be called from any thread.
|
||||||
|
///
|
||||||
|
/// see also: context_current, glfwMakeContextCurrent
|
||||||
|
pub inline fn getCurrentContext() Error!?Window {
|
||||||
|
const handle = c.glfwGetCurrentContext();
|
||||||
|
try getError();
|
||||||
|
if (handle) |h| return Window{ .handle = h };
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(opengl):
|
// TODO(opengl):
|
||||||
|
|
||||||
// /// Client API function pointer type.
|
// /// Client API function pointer type.
|
||||||
|
@ -46,24 +65,6 @@ pub inline fn makeContextCurrent(window: ?Window) Error!void {
|
||||||
// /// @ingroup context
|
// /// @ingroup context
|
||||||
// typedef void (*GLFWglproc)(void);
|
// typedef void (*GLFWglproc)(void);
|
||||||
|
|
||||||
// /// Returns the window whose context is current on the calling thread.
|
|
||||||
// ///
|
|
||||||
// /// This function returns the window whose OpenGL or OpenGL ES context is
|
|
||||||
// /// current on the calling thread.
|
|
||||||
// ///
|
|
||||||
// /// @return The window whose context is current, or null if no window's
|
|
||||||
// /// context is current.
|
|
||||||
// ///
|
|
||||||
// /// Possible errors include glfw.Error.NotInitialized.
|
|
||||||
// ///
|
|
||||||
// /// @thread_safety This function may be called from any thread.
|
|
||||||
// ///
|
|
||||||
// /// see also: context_current, glfwMakeContextCurrent
|
|
||||||
// ///
|
|
||||||
// ///
|
|
||||||
// /// @ingroup context
|
|
||||||
// GLFWAPI GLFWwindow* glfwGetCurrentContext(void);
|
|
||||||
|
|
||||||
// /// Sets the swap interval for the current context.
|
// /// Sets the swap interval for the current context.
|
||||||
// ///
|
// ///
|
||||||
// /// This function sets the swap interval for the current OpenGL or OpenGL ES
|
// /// This function sets the swap interval for the current OpenGL or OpenGL ES
|
||||||
|
@ -192,3 +193,15 @@ test "makeContextCurrent" {
|
||||||
|
|
||||||
glfw.makeContextCurrent(window) catch |err| std.debug.print("making context current, error={}\n", .{err});
|
glfw.makeContextCurrent(window) catch |err| std.debug.print("making context current, error={}\n", .{err});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "getCurrentContext" {
|
||||||
|
const glfw = @import("main.zig");
|
||||||
|
try glfw.init();
|
||||||
|
defer glfw.terminate();
|
||||||
|
|
||||||
|
const current_context = glfw.getCurrentContext() catch |err| {
|
||||||
|
std.debug.print("can't get current context, error={}\n", .{err});
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
std.debug.assert(current_context == null);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue