glfw: add VideoMode type; add Monitor.getVideoModes
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
1c10b309b2
commit
74e2bddf93
2 changed files with 73 additions and 3 deletions
|
|
@ -172,8 +172,7 @@ pub inline fn setUserPointer(self: Monitor, comptime T: type, ptr: *T) Error!voi
|
|||
///
|
||||
/// Possible errors include glfw.Error.NotInitialized.
|
||||
///
|
||||
/// @thread_safety This function may be called from any thread. Access is not
|
||||
/// synchronized.
|
||||
/// @thread_safety This function may be called from any thread. Access is not synchronized.
|
||||
///
|
||||
/// see also: monitor_userptr, glfw.Monitor.setUserPointer
|
||||
pub inline fn getUserPointer(self: Monitor, comptime T: type) Error!?*T {
|
||||
|
|
@ -189,7 +188,7 @@ pub inline fn getUserPointer(self: Monitor, comptime T: type) Error!?*T {
|
|||
/// always first. If no monitors were found, this function returns an empty slice.
|
||||
///
|
||||
/// The returned slice memory is owned by the caller. The underlying handles are owned by GLFW, and
|
||||
/// are valid until the monitor configuration changes or the `glfw.terminate` is called.
|
||||
/// are valid until the monitor configuration changes or `glfw.terminate` is called.
|
||||
///
|
||||
/// @thread_safety This function must only be called from the main thread.
|
||||
///
|
||||
|
|
@ -274,6 +273,34 @@ pub inline fn setCallback(comptime Data: type, data: *Data, f: ?*const fn (monit
|
|||
try getError();
|
||||
}
|
||||
|
||||
/// Returns the available video modes for the specified monitor.
|
||||
///
|
||||
/// This function returns an array of all video modes supported by the monitor. The returned slice
|
||||
/// is sorted in ascending order, first by color bit depth (the sum of all channel depths) and
|
||||
/// then by resolution area (the product of width and height).
|
||||
///
|
||||
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
|
||||
///
|
||||
/// The returned slice memory is owned by the caller. The underlying handles are owned by GLFW, and
|
||||
/// are valid until the monitor is disconnected, this function is called again, or `glfw.terminate`
|
||||
/// is called.
|
||||
///
|
||||
/// @thread_safety This function must only be called from the main thread.
|
||||
///
|
||||
/// see also: monitor_modes, glfw.Monitor.getVideoMode
|
||||
pub inline fn getVideoModes(allocator: *mem.Allocator) ![]VideoMode {
|
||||
var count: c_int = 0;
|
||||
const modes = c.glfwGetVideoModes(&count);
|
||||
try getError();
|
||||
|
||||
const slice = try allocator.alloc(VideoMode, @intCast(usize, count));
|
||||
var i: usize = 0;
|
||||
while (i < count) : (i += 1) {
|
||||
slice[i] = VideoMode{ .handle = modes[i].? };
|
||||
}
|
||||
return slice;
|
||||
}
|
||||
|
||||
test "getAll" {
|
||||
const glfw = @import("main.zig");
|
||||
try glfw.init();
|
||||
|
|
|
|||
43
glfw/src/VideoMode.zig
Normal file
43
glfw/src/VideoMode.zig
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
//! Monitor video modes and related functions
|
||||
//!
|
||||
//! see also: glfw.Monitor.getVideoMode
|
||||
|
||||
const std = @import("std");
|
||||
const mem = std.mem;
|
||||
const testing = std.testing;
|
||||
const c = @cImport(@cInclude("GLFW/glfw3.h"));
|
||||
|
||||
pub const Error = @import("errors.zig").Error;
|
||||
const getError = @import("errors.zig").getError;
|
||||
|
||||
handle: *c.GLFWvidmode,
|
||||
|
||||
/// Returns the width of the video mode, in screen coordinates.
|
||||
pub inline fn getWidth(self: VideoMode) usize {
|
||||
return @intCast(usize, self.handle.width);
|
||||
}
|
||||
|
||||
/// Returns the height of the video mode, in screen coordinates.
|
||||
pub inline fn getHeight(self: VideoMode) usize {
|
||||
return @intCast(usize, self.handle.height);
|
||||
}
|
||||
|
||||
/// Returns the bit depth of the red channel of the video mode.
|
||||
pub inline fn getRedBits(self: VideoMode) usize {
|
||||
return @intCast(usize, self.handle.redBits);
|
||||
}
|
||||
|
||||
/// Returns the bit depth of the green channel of the video mode.
|
||||
pub inline fn getGreenBits(self: VideoMode) usize {
|
||||
return @intCast(usize, self.handle.greenBits);
|
||||
}
|
||||
|
||||
/// Returns the bit depth of the blue channel of the video mode.
|
||||
pub inline fn getBlueBits(self: VideoMode) usize {
|
||||
return @intCast(usize, self.handle.blueBits);
|
||||
}
|
||||
|
||||
/// Returns the refresh rate of the video mode, in Hz.
|
||||
pub inline fn getRefreshRate(self: VideoMode) usize {
|
||||
return @intCast(usize, self.handle.refreshRate);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue