mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-12-03 18:27:59 -05:00
* Don't Crash or Stay Silent When the OpenGL Context Can't Be Activated When the driver refuses to make the OpenGL context current, no ImGui frame ever runs and OpenGL is never initialized, so ImGui has no current font and the GL functions are never loaded. A notification that measures its text from an event handler (a validation warning, a job's progress, the slicing progress bar) then reads the null font and crashes, and once a slice completes, loading its G-code preview calls the unloaded GL functions and crashes too. Notifications now skip measuring until a frame has set up the font; they stay Unknown, and render() already measures them when it draws. The G-code preview is not loaded while OpenGL cannot be initialized; with OpenGL up, init_opengl() returns at once and nothing changes. On Windows, a shown canvas whose context cannot be made current is reported once: wx drops the wglMakeCurrent error in release builds, so the call is repeated to log GetLastError() with the canvas's pixel format and the display it is on. If OpenGL never came up in the session, the user gets one error dialog instead of an empty 3D view with no explanation. A GTK canvas can fail until its surface is mapped, so other platforms only get the crash fixes. * Name the Display Adapter Instead of Only Suggesting a Driver Upgrade When OpenGL Can't Be Activated A context that can't be made current has several causes: no OpenGL driver behind the display the window is on (a disabled adapter, or one running on the Microsoft Basic Display Adapter), a broken driver, or an overlay. The old advice to upgrade the driver covered only one of them. The dialog now names the adapter Windows reports for the window's display and lists the general checks, and the log line keeps the display device and adapter name.
124 lines
4.1 KiB
C++
124 lines
4.1 KiB
C++
#ifndef slic3r_OpenGLManager_hpp_
|
|
#define slic3r_OpenGLManager_hpp_
|
|
|
|
#include "GLShadersManager.hpp"
|
|
#include <string>
|
|
#include <utility>
|
|
#include "slic3r/GUI/GLShader.hpp"
|
|
|
|
class wxWindow;
|
|
class wxGLCanvas;
|
|
class wxGLContext;
|
|
|
|
namespace Slic3r {
|
|
namespace GUI {
|
|
|
|
|
|
class OpenGLManager
|
|
{
|
|
public:
|
|
enum class EFramebufferType : unsigned char
|
|
{
|
|
Unknown,
|
|
Arb,
|
|
Ext
|
|
};
|
|
|
|
class GLInfo
|
|
{
|
|
bool m_detected{ false };
|
|
bool m_core_profile{ false };
|
|
int m_max_tex_size{ 0 };
|
|
float m_max_anisotropy{ 0.0f };
|
|
#if ENABLE_OPENGL_AUTO_AA_SAMPLES
|
|
int m_samples{ 0 };
|
|
#endif // ENABLE_OPENGL_AUTO_AA_SAMPLES
|
|
|
|
std::string m_version;
|
|
std::string m_glsl_version;
|
|
std::string m_vendor;
|
|
std::string m_renderer;
|
|
|
|
public:
|
|
GLInfo() = default;
|
|
|
|
const std::string& get_version() const;
|
|
const std::string& get_glsl_version() const;
|
|
const std::string& get_vendor() const;
|
|
const std::string& get_renderer() const;
|
|
|
|
// False until a GL context has been made current and queried; the getters below detect
|
|
// on first use, which needs a current context.
|
|
bool is_detected() const { return m_detected; }
|
|
bool is_core_profile() const { return m_core_profile; }
|
|
|
|
bool is_mesa() const;
|
|
|
|
int get_max_tex_size() const;
|
|
float get_max_anisotropy() const;
|
|
|
|
bool is_version_greater_or_equal_to(unsigned int major, unsigned int minor) const;
|
|
bool is_glsl_version_greater_or_equal_to(unsigned int major, unsigned int minor) const;
|
|
|
|
// If formatted for github, plaintext with OpenGL extensions enclosed into <details>.
|
|
// Otherwise HTML formatted for the system info dialog.
|
|
std::string to_string(bool for_github) const;
|
|
|
|
private:
|
|
void detect() const;
|
|
};
|
|
|
|
private:
|
|
enum class EMultisampleState : unsigned char
|
|
{
|
|
Unknown,
|
|
Enabled,
|
|
Disabled
|
|
};
|
|
|
|
bool m_gl_initialized{ false };
|
|
bool m_make_current_failure_reported{ false };
|
|
wxGLContext* m_context{ nullptr };
|
|
GLShadersManager m_shaders_manager;
|
|
static GLInfo s_gl_info;
|
|
static bool s_compressed_textures_supported;
|
|
static bool s_force_power_of_two_textures;
|
|
|
|
static EMultisampleState s_multisample;
|
|
static EFramebufferType s_framebuffers_type;
|
|
|
|
public:
|
|
OpenGLManager() = default;
|
|
~OpenGLManager();
|
|
|
|
bool init_gl(bool popup_error = true);
|
|
wxGLContext* init_glcontext(wxGLCanvas& canvas, const std::pair<int, int>& required_opengl_version, bool enable_compatibility_profile, bool enable_debug);
|
|
// Called when the context cannot be made current on a shown canvas, which then stays empty.
|
|
// On Windows, logs why once per session and, if OpenGL never came up, tells the user. Elsewhere
|
|
// this does nothing: a GTK canvas can fail transiently until its surface is mapped.
|
|
void report_make_current_failure(const wxGLCanvas& canvas, const wxGLContext* context);
|
|
|
|
GLShaderProgram* get_shader(const std::string& shader_name) { return m_shaders_manager.get_shader(shader_name); }
|
|
GLShaderProgram* get_current_shader() { return m_shaders_manager.get_current_shader(); }
|
|
|
|
static bool are_compressed_textures_supported() { return s_compressed_textures_supported; }
|
|
static bool can_multisample() { return s_multisample == EMultisampleState::Enabled; }
|
|
static bool are_framebuffers_supported() { return (s_framebuffers_type != EFramebufferType::Unknown); }
|
|
static EFramebufferType get_framebuffers_type() { return s_framebuffers_type; }
|
|
static wxGLCanvas* create_wxglcanvas(wxWindow& parent);
|
|
// True for a canvas made by create_wxglcanvas(), the kind a GLCanvas3D draws its scene and ImGui into.
|
|
static bool is_scene_canvas(const wxWindow* window);
|
|
static const GLInfo& get_gl_info() { return s_gl_info; }
|
|
static bool force_power_of_two_textures() { return s_force_power_of_two_textures; }
|
|
// Of the bound draw framebuffer.
|
|
static int stencil_bits();
|
|
|
|
private:
|
|
static void detect_multisample(int* attribList);
|
|
};
|
|
|
|
} // namespace GUI
|
|
} // namespace Slic3r
|
|
|
|
#endif // slic3r_OpenGLManager_hpp_
|