gtk,opengl: cleanup & fixes for #14052 (#14279)

Fixes most issues mentioned in #14243, #14254 and elsewhere e.g. on
Discord. Will add more fixes if they can be solidly reproduced.

Please review each commit individually.
This commit is contained in:
Mitchell Hashimoto
2026-09-18 06:28:05 -07:00
committed by GitHub
5 changed files with 30 additions and 26 deletions

4
passthrough.glsl Normal file
View File

@@ -0,0 +1,4 @@
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = fragCoord / iResolution.xy;
fragColor = vec4(texture(iChannel0, uv).rgb, 1.0);
}

View File

@@ -27,13 +27,22 @@ pub fn parameter(
comptime name: Texture.Parameter,
value: name.Type(),
) errors.Error!void {
switch (@TypeOf(value)) {
const T = name.Type();
switch (T) {
c.GLint => glad.context.SamplerParameteri.?(
self.id,
@intFromEnum(name),
value,
),
else => unreachable,
else => switch (@typeInfo(T)) {
.@"enum" => glad.context.SamplerParameteri.?(
self.id,
@intFromEnum(name),
@intFromEnum(value),
),
else => @compileLog("unsupported parameter type", T),
},
}
try errors.getError();
}

View File

@@ -3376,32 +3376,23 @@ const Action = struct {
fn setGtkEnv(config: *const CoreConfig) std.Io.Writer.Error!void {
assert(gtk.isInitialized() == 0);
var gdk_debug: struct {
/// output OpenGL debug information
const gdk_debug: struct {
/// Output OpenGL debug information,
/// `gtk-opengl-debug` dumps logs directly to stderr so both must be true
/// to enable OpenGL debugging.
opengl: bool = false,
// GTK's new renderer can cause blurry font when using fractional scaling.
@"gl-no-fractional": bool = false,
} = .{
// `gtk-opengl-debug` dumps logs directly to stderr so both must be true
// to enable OpenGL debugging.
.opengl = global.logging().stderr and config.@"gtk-opengl-debug",
};
var gdk_disable: struct {
/// current gtk implementation for color management is not good enough.
/// see: https://bugs.kde.org/show_bug.cgi?id=495647
/// gtk issue: https://gitlab.gnome.org/GNOME/gtk/-/issues/6864
@"color-mgmt": bool = true,
const gdk_disable: struct {
// Even though we don't use GTK's GL context anymore, there can still
// occasionally be conflicts when Vulkan and OpenGL are used together.
// Disabling Vulkan also saves hundreds of milliseconds of initialization
// time on certain systems.
vulkan: bool = true,
} = .{};
if (gtk_version.runtimeAtLeast(4, 18, 0)) {
gdk_disable.@"color-mgmt" = false;
}
if (gtk_version.runtimeUntil(4, 17, 5)) {
// Removed at GTK v4.17.5
gdk_debug.@"gl-no-fractional" = true;
}
{
var buf: [1024]u8 = undefined;
var writer: std.Io.Writer = .fixed(&buf);

View File

@@ -317,9 +317,6 @@ pub const ImguiWidget = extern struct {
cimgui.c.ImGui_Render();
}
// OpenGL final render
gl.clearColor(0x28 / 0xFF, 0x2C / 0xFF, 0x34 / 0xFF, 1.0);
gl.clear(gl.c.GL_COLOR_BUFFER_BIT);
cimgui.ImGui_ImplOpenGL3_RenderDrawData(cimgui.c.ImGui_GetDrawData());
return @intFromBool(true);

View File

@@ -59,12 +59,16 @@ pub fn init(alloc: Allocator, opts: rendererpkg.Options) !OpenGL {
// Choose a config. We need a config that is renderable with
// OpenGL and a RGBA8 color buffer.
const config = egl.Config.choose(display, &.{
// EGL_SURFACE_TYPE defaults to EGL_WINDOW_BIT even though
// we are rendering exclusively through surfaceless mode.
// This is no problem on Mesa but we need to specify this
// explicitly for proprietary Nvidia drivers.
egl.c.EGL_SURFACE_TYPE, 0,
egl.c.EGL_RENDERABLE_TYPE, egl.c.EGL_OPENGL_BIT,
egl.c.EGL_RED_SIZE, 8,
egl.c.EGL_GREEN_SIZE, 8,
egl.c.EGL_BLUE_SIZE, 8,
egl.c.EGL_ALPHA_SIZE, 8,
egl.c.EGL_NONE,
}) catch |err| {
log.warn("failed to choose config err={}", .{err});
return err;
@@ -75,7 +79,6 @@ pub fn init(alloc: Allocator, opts: rendererpkg.Options) !OpenGL {
egl.c.EGL_CONTEXT_MAJOR_VERSION, MIN_VERSION_MAJOR,
egl.c.EGL_CONTEXT_MINOR_VERSION, MIN_VERSION_MINOR,
egl.c.EGL_CONTEXT_OPENGL_PROFILE_MASK, egl.c.EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT,
egl.c.EGL_NONE,
}) catch |err| {
log.warn("failed to create EGL context err={}", .{err});
return err;