diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Window.zig | 130 |
1 files changed, 117 insertions, 13 deletions
diff --git a/src/Window.zig b/src/Window.zig index 919ca9a..eba375c 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -32,26 +32,130 @@ const Options = struct { share: ?Window = null, }; +pub const Hints = struct { + pub const dont_care = GLFW_DONT_CARE; + + resizable: bool = true, + visible: bool = true, + decorated: bool = true, + focused: bool = true, + auto_iconify: bool = true, + floating: bool = false, + maximized: bool = false, + center_cursor: bool = true, + transparent_framebuffer: bool = false, + focus_on_show: bool = true, + scale_to_monitor: bool = false, + + bits: struct { + red: c_int = 8, + green: c_int = 8, + blue: c_int = 8, + alpha: c_int = 8, + depth: c_int = 24, + stencil: c_int = 8, + } = .{}, + accum_bits: struct { + red: c_int = 0, + green: c_int = 0, + blue: c_int = 0, + alpha: c_int = 0, + } = .{}, + aux_buffers: c_int = 0, + samples: c_int = 0, + refresh_rate: c_int = dont_care, + + stereo: bool = false, + srgb_capable: bool = false, + doublebuffer: bool = true, + + client_api: enum(c_int) { + opengl = GLFW_OPENGL_API, + opengl_es = GLFW_OPENGL_ES_API, + no = GLFW_NO_API, + } = .opengl, + context: struct { + creation_api: enum(c_int) { + native = GLFW_NATIVE_CONTEXT_API, + egl = GLFW_EGL_CONTEXT_API, + osmesa = GLFW_OSMESA_CONTEXT_API, + } = .native, + version: struct { + major: c_int = 1, + minor: c_int = 0, + } = .{}, + robustness: enum(c_int) { + no_robustness = GLFW_NO_ROBUSTNESS, + no_reset_notification = GLFW_NO_RESET_NOTIFICATION, + lose_context_on_reset = GLFW_LOSE_CONTEXT_ON_RESET, + } = .no_robustness, + release_behavior: enum(c_int) { + any = GLFW_ANY_RELEASE_BEHAVIOR, + flush = GLFW_RELEASE_BEHAVIOR_FLUSH, + none = GLFW_RELEASE_BEHAVIOR_NONE, + } = .any, + } = .{}, + + opengl: struct { + forward_compat: bool = false, + debug_context: bool = false, + profile: enum(c_int) { + any = GLFW_OPENGL_ANY_PROFILE, + compat = GLFW_OPENGL_COMPAT_PROFILE, + core = GLFW_OPENGL_CORE_PROFILE, + } = .any, + } = .{}, +}; + /// Set the specified window hint to the desired value. fn setHint(hint: c_int, value: anytype) Error!void { - switch (@TypeOf(value)) { - c_int, comptime_int => glfwWindowHint(hint, value), - bool => glfwWindowHint(hint, if (value) GLFW_TRUE else GLFW_FALSE), - else => unreachable, - } + glfwWindowHint(hint, switch (@TypeOf(value)) { + c_int, comptime_int => value, + bool => if (value) GLFW_TRUE else GLFW_FALSE, + else => @enumToInt(value), + }); try checkError(); } /// Create a window and its associated context. pub fn create(width: c_int, height: c_int, title: [:0]const u8, - options: Options, hints: anytype) Error!Window { - const Hints = @TypeOf(hints); - // TODO: Add all supported GLFW window hints: - // https://www.glfw.org/docs/latest/window_guide.html#window_hints_values - if (@hasField(Hints, "depth_bits")) - try setHint(GLFW_DEPTH_BITS, hints.depth_bits); - if (@hasField(Hints, "double_buffer")) - try setHint(GLFW_DOUBLEBUFFER, hints.double_buffer); + options: Options, hints: Hints) Error!Window { + try setHint(GLFW_RESIZABLE, hints.resizable); + try setHint(GLFW_VISIBLE, hints.visible); + try setHint(GLFW_DECORATED, hints.decorated); + try setHint(GLFW_FOCUSED, hints.focused); + try setHint(GLFW_AUTO_ICONIFY, hints.auto_iconify); + try setHint(GLFW_FLOATING, hints.floating); + try setHint(GLFW_MAXIMIZED, hints.maximized); + try setHint(GLFW_CENTER_CURSOR, hints.center_cursor); + try setHint(GLFW_TRANSPARENT_FRAMEBUFFER, hints.transparent_framebuffer); + try setHint(GLFW_FOCUS_ON_SHOW, hints.focus_on_show); + try setHint(GLFW_SCALE_TO_MONITOR, hints.scale_to_monitor); + try setHint(GLFW_RED_BITS, hints.bits.red); + try setHint(GLFW_GREEN_BITS, hints.bits.green); + try setHint(GLFW_BLUE_BITS, hints.bits.blue); + try setHint(GLFW_ALPHA_BITS, hints.bits.alpha); + try setHint(GLFW_DEPTH_BITS, hints.bits.depth); + try setHint(GLFW_STENCIL_BITS, hints.bits.stencil); + try setHint(GLFW_ACCUM_RED_BITS, hints.accum_bits.red); + try setHint(GLFW_ACCUM_GREEN_BITS, hints.accum_bits.green); + try setHint(GLFW_ACCUM_BLUE_BITS, hints.accum_bits.blue); + try setHint(GLFW_ACCUM_ALPHA_BITS, hints.accum_bits.alpha); + try setHint(GLFW_AUX_BUFFERS, hints.aux_buffers); + try setHint(GLFW_SAMPLES, hints.samples); + try setHint(GLFW_REFRESH_RATE, hints.refresh_rate); + try setHint(GLFW_STEREO, hints.stereo); + try setHint(GLFW_SRGB_CAPABLE, hints.srgb_capable); + try setHint(GLFW_DOUBLEBUFFER, hints.doublebuffer); + try setHint(GLFW_CLIENT_API, hints.client_api); + try setHint(GLFW_CONTEXT_CREATION_API, hints.context.creation_api); + try setHint(GLFW_CONTEXT_VERSION_MAJOR, hints.context.version.major); + try setHint(GLFW_CONTEXT_VERSION_MINOR, hints.context.version.minor); + try setHint(GLFW_CONTEXT_ROBUSTNESS, hints.context.robustness); + try setHint(GLFW_CONTEXT_RELEASE_BEHAVIOR, hints.context.release_behavior); + try setHint(GLFW_OPENGL_FORWARD_COMPAT, hints.opengl.forward_compat); + try setHint(GLFW_OPENGL_DEBUG_CONTEXT, hints.opengl.debug_context); + try setHint(GLFW_OPENGL_PROFILE, hints.opengl.profile); const monitor = if (options.fullscreen) |box| box.pimpl else null; const share = if (options.share) |box| box.pimpl else null; |