glfw: add glfw.extensionSupported
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
17fc430766
commit
10225ecd44
1 changed files with 48 additions and 35 deletions
|
@ -90,40 +90,36 @@ pub inline fn swapInterval(interval: isize) Error!void {
|
||||||
try getError();
|
try getError();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(opengl):
|
/// Returns whether the specified extension is available.
|
||||||
|
///
|
||||||
// /// Returns whether the specified extension is available.
|
/// This function returns whether the specified API extension (see context_glext) is supported by
|
||||||
// ///
|
/// the current OpenGL or OpenGL ES context. It searches both for client API extension and context
|
||||||
// /// This function returns whether the specified
|
/// creation API extensions.
|
||||||
// /// [API extension](@ref context_glext) is supported by the current OpenGL or
|
///
|
||||||
// /// OpenGL ES context. It searches both for client API extension and context
|
/// A context must be current on the calling thread. Calling this function without a current
|
||||||
// /// creation API extensions.
|
/// context will cause Error.NoCurrentContext.
|
||||||
// ///
|
///
|
||||||
// /// A context must be current on the calling thread. Calling this function
|
/// As this functions retrieves and searches one or more extension strings each call, it is
|
||||||
// /// without a current context will cause a @ref GLFW_NO_CURRENT_CONTEXT error.
|
/// 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.
|
||||||
// /// 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
|
/// This function does not apply to Vulkan. If you are using Vulkan, see glfw.getRequiredInstanceExtensions,
|
||||||
// /// frequently. The extension strings will not change during the lifetime of
|
/// `vkEnumerateInstanceExtensionProperties` and `vkEnumerateDeviceExtensionProperties` instead.
|
||||||
// /// a context, so there is no danger in doing this.
|
///
|
||||||
// ///
|
/// @param[in] extension The ASCII encoded name of the extension.
|
||||||
// /// This function does not apply to Vulkan. If you are using Vulkan, see @ref
|
/// @return `true` if the extension is available, or `false` otherwise.
|
||||||
// /// glfw.getRequiredInstanceExtensions, `vkEnumerateInstanceExtensionProperties`
|
///
|
||||||
// /// and `vkEnumerateDeviceExtensionProperties` instead.
|
/// Possible errors include glfw.Error.NotInitialized, glfw.Error.NoCurrentContext, glfw.Error.InvalidValue
|
||||||
// ///
|
/// and glfw.Error.PlatformError.
|
||||||
// /// @param[in] extension The ASCII encoded name of the extension.
|
///
|
||||||
// /// @return `GLFW_TRUE` if the extension is available, or `GLFW_FALSE`
|
/// @thread_safety This function may be called from any thread.
|
||||||
// /// otherwise.
|
///
|
||||||
// ///
|
/// see also: context_glext, glfw.getProcAddress
|
||||||
// /// Possible errors include glfw.Error.NotInitialized, glfw.Error.NoCurrentContext, glfw.Error.InvalidValue and glfw.Error.PlatformError.
|
pub inline fn extensionSupported(extension: [*c]const u8) Error!bool {
|
||||||
// ///
|
const supported = c.glfwExtensionSupported(extension);
|
||||||
// /// @thread_safety This function may be called from any thread.
|
try getError();
|
||||||
// ///
|
return supported == c.GLFW_TRUE;
|
||||||
// /// see also: context_glext, glfwGetProcAddress
|
}
|
||||||
// ///
|
|
||||||
// ///
|
|
||||||
// /// @ingroup context
|
|
||||||
// GLFWAPI int glfwExtensionSupported(const char* extension);
|
|
||||||
|
|
||||||
/// Client API function pointer type.
|
/// Client API function pointer type.
|
||||||
///
|
///
|
||||||
|
@ -160,7 +156,7 @@ pub const GLProc = fn () callconv(.C) void;
|
||||||
///
|
///
|
||||||
/// see also: context_glext, glfwExtensionSupported
|
/// see also: context_glext, glfwExtensionSupported
|
||||||
pub inline fn getProcAddress(proc_name: [*c]const u8) Error!?GLProc {
|
pub inline fn getProcAddress(proc_name: [*c]const u8) Error!?GLProc {
|
||||||
const proc_address = c.glfwGetProcAddress(&proc_name[0]);
|
const proc_address = c.glfwGetProcAddress(proc_name);
|
||||||
try getError();
|
try getError();
|
||||||
if (proc_address) |addr| return addr;
|
if (proc_address) |addr| return addr;
|
||||||
return null;
|
return null;
|
||||||
|
@ -227,3 +223,20 @@ test "getProcAddress" {
|
||||||
try glfw.makeContextCurrent(window);
|
try glfw.makeContextCurrent(window);
|
||||||
_ = glfw.getProcAddress("foobar") catch |err| std.debug.print("failed to get proc address, error={}\n", .{err});
|
_ = glfw.getProcAddress("foobar") catch |err| std.debug.print("failed to get proc address, error={}\n", .{err});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "extensionSupported" {
|
||||||
|
const glfw = @import("main.zig");
|
||||||
|
try glfw.init();
|
||||||
|
defer glfw.terminate();
|
||||||
|
|
||||||
|
const window = glfw.Window.create(640, 480, "Hello, Zig!", null, null) catch |err| {
|
||||||
|
// return without fail, because most of our CI environments are headless / we cannot open
|
||||||
|
// windows on them.
|
||||||
|
std.debug.print("note: failed to create window: {}\n", .{err});
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
defer window.destroy();
|
||||||
|
|
||||||
|
try glfw.makeContextCurrent(window);
|
||||||
|
_ = glfw.extensionSupported("foobar") catch |err| std.debug.print("failed to check if extension supported, error={}\n", .{err});
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue