Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux - Nvidia specific detection and fixes #5276

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 3 additions & 10 deletions deps/GLFW/GLFW.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,15 @@ else()
set(_build_static ON)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(_glfw_use_wayland "-DGLFW_USE_WAYLAND=ON")
else()
set(_glfw_use_wayland "-DGLFW_USE_WAYLAND=FF")
endif()

orcaslicer_add_cmake_project(GLFW
URL https://github.com/glfw/glfw/archive/refs/tags/3.3.7.zip
URL_HASH SHA256=e02d956935e5b9fb4abf90e2c2e07c9a0526d7eacae8ee5353484c69a2a76cd0
URL https://github.com/glfw/glfw/archive/refs/tags/3.4.zip
URL_HASH SHA256=a133ddc3d3c66143eba9035621db8e0bcf34dba1ee9514a9e23e96afd39fd57a
#DEPENDS dep_Boost
CMAKE_ARGS
-DBUILD_SHARED_LIBS=${_build_shared}
-DBUILD_SHARED_LIBS=${_build_shared}
-DGLFW_BUILD_DOCS=OFF
-DGLFW_BUILD_EXAMPLES=OFF
-DGLFW_BUILD_TESTS=OFF
${_glfw_use_wayland}
)

if (MSVC)
Expand Down
63 changes: 63 additions & 0 deletions src/OrcaSlicer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,63 @@ static int construct_assemble_list(std::vector<assemble_plate_info_t> &assemble_
return ret;
}

std::string get_glVender() {
int code;
const char* description;

int ret = glfwInit();
if (ret == GLFW_FALSE) {
code = glfwGetError(&description);
std::cerr << "Failed to initialize GLFW: " << code;
if (description)
std::cerr << ": " << description;
std::cerr << std::endl;
abort();
}
std::cout << "GLFW initialized." << std::endl;
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_RED_BITS, 8);
glfwWindowHint(GLFW_GREEN_BITS, 8);
glfwWindowHint(GLFW_BLUE_BITS, 8);
glfwWindowHint(GLFW_ALPHA_BITS, 8);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_NATIVE_CONTEXT_API);
std::cout << "GLFW window hints set." << std::endl;
GLFWwindow* window = glfwCreateWindow(640, 480, "base_window", NULL, NULL);
std::cout << "GLFW window created." << std::endl;
if (window == NULL)
{
code = glfwGetError(&description);
std::cerr << "Failed to create GLFW window: " << code;
if (description)
std::cerr << ": " << description;
std::cerr << std::endl;
abort();
}
glfwMakeContextCurrent(window);
std::cout << "GLFW context set." << std::endl;
// get gl vendor
const GLubyte* glVendor = glGetString(GL_VENDOR);
if (glVendor == NULL) {
code = glfwGetError(&description);
std::cerr << "Failed to get GL vendor, code: " << code << std::endl;
if (description)
std::cerr << ", description: " << description;
std::cerr << std::endl;
abort();
}
std::string glVendorString = reinterpret_cast<const char*>(glVendor);
std::cout << "glVendor: " << glVendorString << std::endl;
const char* glRenderer = reinterpret_cast<const char*>(glGetString(GL_RENDERER));
std::cout << "glRenderer: " << glRenderer << std::endl;
const char* glVersion = reinterpret_cast<const char*>(glGetString(GL_VERSION));
std::cout << "glVersion: " << glVersion << std::endl;
glfwDestroyWindow(window);
return glVendorString;
}

int CLI::run(int argc, char **argv)
{
// Mark the main thread for the debugger and for runtime checks.
Expand All @@ -892,6 +949,12 @@ int CLI::run(int argc, char **argv)
// instruct the window manager to fall back to X server mode.
::setenv("GDK_BACKEND", "x11", /* replace */ true);

std::string glvendor = get_glVender();
if (glvendor == "NVIDIA Corporation") {
// this is needed on nvidia systems to show the Home and Project tabs
::setenv("WEBKIT_DISABLE_DMABUF_RENDERER", "1", /* replace */ true);
}

// Also on Linux, we need to tell Xlib that we will be using threads,
// lest we crash when we fire up GStreamer.
XInitThreads();
Expand Down