Skip to content

refactor(gui): migrate GLEW→GLAD for Linux/NVIDIA viewport (#351) - #8

Merged
aceRage merged 5 commits into
mainfrom
cursor/feat-glew-to-glad-linux-viewport-2ccf
Sep 4, 2026
Merged

refactor(gui): migrate GLEW→GLAD for Linux/NVIDIA viewport (#351)#8
aceRage merged 5 commits into
mainfrom
cursor/feat-glew-to-glad-linux-viewport-2ccf

Conversation

@aceRage

@aceRage aceRage commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Description

Hard upstream port of Snapmaker/OrcaSlicer#351 (OPEN, blocked): migrate OpenGL function loading from GLEW to GLAD so native Linux/NVIDIA OpenGL works, and make Zink opt-in.

This is a separate PR from #7 (Easy port of Snapmaker#713). #7 auto-enables Zink on Flatpak NVIDIA Wayland as a GLEW-era workaround. Once GLAD lands, native NVIDIA GL works and that auto-Zink path should not stay on by default.

Fixes (upstream): Snapmaker#264 (blank 3D viewport on Linux/NVIDIA — glewInit → "Missing GL version"), Snapmaker#275 (forced Zink "could not create swapchain").

Commit series

  1. build: vendor glad and CMake wiring (#351) — add src/glad/ (gl.c/gl.h/khrplatform.h), link glad instead of GLEW::GLEW in libslic3r_gui, wxUSE_GLCANVAS_EGL=OFF (GLX backend; also mirrored in the Flatpak wxWidgets recipe).
  2. refactor(gui): OpenGLManager glewInit → gladLoadGL (#351)gladLoaderLoadGL(), compatibility-profile wxGLContext, keep Ultra OpenGLManager::s_active.
  3. refactor(gui): replace GLEW includes/macros across GUI (#351)#include <glad/gl.h>, GLAD_GL_* macros, EXT framebuffer/renderbuffer → core; GLTexture::generate_from_text() null-loader guard.
  4. fix(linux): make AppImage Zink opt-in (#351) — enable Mesa/Zink only when ZINK_FORCE_OVERRIDE=1.
  5. chore(flatpak): align entrypoint Zink policy with GLAD (#351/#713) — prefer opt-in; keep Fix blank Flatpak canvas on NVIDIA Wayland Snapmaker/OrcaSlicer#713 auto-Zink only as a temporary fallback behind ZINK_AUTO_NVIDIA=1.

Zink policy (after this PR)

Flag AppImage Flatpak
default native GL (no Zink) native GL (no Zink)
ZINK_FORCE_OVERRIDE=1 force Zink force Zink
ZINK_DISABLE_OVERRIDE=1 n/a (already opt-in) skip Zink even if force/auto
ZINK_AUTO_NVIDIA=1 n/a temporary Snapmaker#713 fallback: NVIDIA Wayland, driver major >555

WebKit DMA-BUF remains disabled for all NVIDIA Flatpak sessions. Ultra binary path stays /app/bin/snapmaker-orca.

Rebase risk areas (Ultra-specific)

Expect conflicts if #7 or later Stream/camera/paint-depth work lands first:

  • OpenGLManager.cpp — Ultra still had glewInit() at ~247 plus s_active; this PR keeps s_active and switches the loader.
  • GLCanvas3D.cpp / .hpp — thumbnail + rectangular-picking offscreen FBOs sit next to Stream/camera work; EXT entry points converted to core.
  • 3DScene.cpp — Ultra outline/depth FBO path (paint/camera) used gl*FramebufferEXT; converted to core.
  • Gizmos/FacetPicker.cpp, GLGizmoPainterBase.* — paint-depth gizmos; include-only here, but high rebase care.
  • Camera.cpp, StreamPanel.* — Camera include swapped; StreamPanel had no GLEW include and was left untouched.
  • scripts/flatpak/entrypoint — will conflict with fix(flatpak): NVIDIA Wayland Zink override in entrypoint (#713) #7; this PR is the post-GLAD policy. Prefer merging this after or instead of auto-Zink-on-by-default.

No unrelated GUI refactors. GLEW remains in deps/ / sandboxes/OpenCSG only.

Screenshots/Recordings/Graphs

N/A in cloud — no NVIDIA Wayland session. Hardware verification is required on Linux/NVIDIA (Prepare + G-code preview).

Tests

Cloud smoke completed (no NVIDIA Wayland / no full slicer build):

  • gcc -c src/glad/src/gl.c -I src/glad/include — glad object compiles.
  • GUI path has no remaining glew.h / GLEW_* / glewInit (comment in OpenGLManager only). gladLoaderLoadGL(), s_active, and compatibility-profile context are present.
  • GLAD header exposes GLAD_GL_ARB_framebuffer_object, GLAD_GL_EXT_framebuffer_object, GLAD_GL_EXT_texture_compression_s3tc, GLAD_GL_EXT_texture_filter_anisotropic.
  • ShellCheck 0.9.0 (-s sh) on scripts/flatpak/entrypoint: clean. sh -n clean.
  • Extracted AppImage launcher block: ShellCheck (-s bash) and bash -n clean; Zink only when ZINK_FORCE_OVERRIDE=1.
  • POSIX Flatpak policy tests: driver-major extract 610 / 555 / 470; default NVIDIA Wayland = no Zink + WebKit DMA-BUF still disabled; Intel unchanged; ZINK_FORCE_OVERRIDE=1 enables; ZINK_DISABLE_OVERRIDE=1 wins; ZINK_AUTO_NVIDIA=1 only on Wayland with major >555; Ultra exec /app/bin/snapmaker-orca preserved.

Cloud cannot smoke NVIDIA Wayland. This environment has no NVIDIA driver, Wayland compositor, Flatpak runtime, or full slicer/deps build. Hardware checks remain:

  1. Linux/NVIDIA Wayland (driver >555): Prepare and Preview render with native GL (no Zink env).
  2. ZINK_FORCE_OVERRIDE=1 still routes through Mesa/Zink if needed.
  3. Flatpak: default native GL; ZINK_AUTO_NVIDIA=1 restores Fix blank Flatpak canvas on NVIDIA Wayland Snapmaker/OrcaSlicer#713 auto-Zink; ZINK_DISABLE_OVERRIDE=1 skips it.
  4. Win/macOS are expected to keep building (GLAD is cross-platform; compatibility-profile context falls back to new wxGLContext). Not verified in this cloud environment — no Windows/macOS toolchain here.

Breaking / dependency notes

  • GUI no longer links GLEW::GLEW; it links the vendored glad static library.
  • wxWidgets dep builds now pass -DwxUSE_GLCANVAS_EGL=OFF (rebuild deps on Linux if the wxGLCanvas backend was previously EGL).
  • Users who relied on automatic AppImage/Flatpak Zink must now set ZINK_FORCE_OVERRIDE=1 (or Flatpak ZINK_AUTO_NVIDIA=1).
Open in Web Open in Cursor 

cursoragent and others added 5 commits September 4, 2026 04:29
Add the GLAD OpenGL loader from Snapmaker#351 (ported from
OrcaSlicer) and link it into libslic3r_gui instead of GLEW::GLEW.
Keep GLEW discovery for sandboxes/OpenCSG. Build wxGLCanvas with the
GLX backend (wxUSE_GLCANVAS_EGL=OFF) so NVIDIA Linux presents reliably.

Co-authored-by: aceRage <aceRage@users.noreply.github.com>
Load GL via gladLoaderLoadGL() instead of glewInit(), which fails with
"Missing GL version" on modern NVIDIA contexts. Request an explicit
compatibility-profile wxGLContext, falling back to the default context.
Preserve Ultra's OpenGLManager::s_active hook.

Co-authored-by: aceRage <aceRage@users.noreply.github.com>
Replace every GL/glew.h include with glad/gl.h, GLEW_* extension macros
with GLAD_GL_*, and EXT framebuffer/renderbuffer entry points with their
core equivalents. Guard GLTexture::generate_from_text() when GLAD
pointers are still null during MainFrame construction.

Ultra-specific rebase care: FacetPicker, 3DScene outline depth FBO
(paint/camera path), and GLCanvas3D thumbnail/picking FBOs sit next to
Stream/paint-depth changes and needed the same EXT→core conversion.

Co-authored-by: aceRage <aceRage@users.noreply.github.com>
The AppImage launcher forced Mesa/Zink on NVIDIA + Wayland (driver >555)
to work around a blank 3D viewport. That blank viewport was GLEW failing
to initialise; GLAD restores native GL. Forcing Zink can fail with
"zink: could not create swapchain", so enable it only when
ZINK_FORCE_OVERRIDE=1 is set.

Co-authored-by: aceRage <aceRage@users.noreply.github.com>
…napmaker#713)

Prefer opt-in Zink (ZINK_FORCE_OVERRIDE=1) now that native NVIDIA GL
works via GLAD. Keep Snapmaker#713 auto-Zink only as a temporary fallback behind
ZINK_AUTO_NVIDIA=1 on NVIDIA Wayland (driver major >555).
ZINK_DISABLE_OVERRIDE=1 still skips Zink. Retain WebKit DMA-BUF disable
for all NVIDIA Flatpak sessions. Ultra exec path stays
/app/bin/snapmaker-orca.

Co-authored-by: aceRage <aceRage@users.noreply.github.com>
@aceRage
aceRage marked this pull request as ready for review September 4, 2026 04:32
@aceRage
aceRage merged commit 064506e into main Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants