Unique OpenGL context set as default

This commit is contained in:
Enrico Turri 2019-01-21 12:20:53 +01:00
parent a8d407b27e
commit cceff0c519
5 changed files with 0 additions and 96 deletions

View file

@ -15,8 +15,6 @@
//====================
#define ENABLE_1_42_0_ALPHA1 1
// Uses a unique opengl context
#define ENABLE_USE_UNIQUE_GLCONTEXT (1 && ENABLE_1_42_0_ALPHA1)
// Disable synchronization of unselected instances
#define DISABLE_INSTANCES_SYNCH (0 && ENABLE_1_42_0_ALPHA1)
// Scene's GUI made using imgui library

View file

@ -3844,12 +3844,7 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas)
#endif // not ENABLE_IMGUI
{
if (m_canvas != nullptr)
{
#if !ENABLE_USE_UNIQUE_GLCONTEXT
m_context = new wxGLContext(m_canvas);
#endif // !ENABLE_USE_UNIQUE_GLCONTEXT
m_timer.SetOwner(m_canvas);
}
m_selection.set_volumes(&m_volumes.volumes);
}
@ -3857,14 +3852,6 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas)
GLCanvas3D::~GLCanvas3D()
{
reset_volumes();
#if !ENABLE_USE_UNIQUE_GLCONTEXT
if (m_context != nullptr)
{
delete m_context;
m_context = nullptr;
}
#endif // !ENABLE_USE_UNIQUE_GLCONTEXT
}
void GLCanvas3D::post_event(wxEvent &&event)
@ -3972,16 +3959,6 @@ bool GLCanvas3D::init(bool useVBOs, bool use_legacy_opengl)
return true;
}
#if !ENABLE_USE_UNIQUE_GLCONTEXT
bool GLCanvas3D::set_current()
{
if ((m_canvas != nullptr) && (m_context != nullptr))
return m_canvas->SetCurrent(*m_context);
return false;
}
#endif // !ENABLE_USE_UNIQUE_GLCONTEXT
void GLCanvas3D::set_as_dirty()
{
m_dirty = true;
@ -3996,12 +3973,6 @@ void GLCanvas3D::reset_volumes()
{
if (!m_volumes.empty())
{
#if !ENABLE_USE_UNIQUE_GLCONTEXT
// ensures this canvas is current
if (!set_current())
return;
#endif // !ENABLE_USE_UNIQUE_GLCONTEXT
m_selection.clear();
m_volumes.release_geometry();
m_volumes.clear();
@ -4278,11 +4249,7 @@ void GLCanvas3D::render()
return;
// ensures this canvas is current and initialized
#if ENABLE_USE_UNIQUE_GLCONTEXT
if (!_set_current() || !_3DScene::init(m_canvas))
#else
if (!set_current() || !_3DScene::init(m_canvas))
#endif // ENABLE_USE_UNIQUE_GLCONTEXT
return;
#if ENABLE_REWORKED_BED_SHAPE_CHANGE
@ -4466,11 +4433,6 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
{
if ((m_canvas == nullptr) || (m_config == nullptr) || (m_model == nullptr))
return;
#if !ENABLE_USE_UNIQUE_GLCONTEXT
// ensures this canvas is current
if (!set_current())
return;
#endif // !ENABLE_USE_UNIQUE_GLCONTEXT
struct ModelVolumeState {
ModelVolumeState(const GLVolume *volume) :
@ -4778,12 +4740,6 @@ void GLCanvas3D::load_gcode_preview(const GCodePreviewData& preview_data, const
const Print *print = this->fff_print();
if ((m_canvas != nullptr) && (print != nullptr))
{
#if !ENABLE_USE_UNIQUE_GLCONTEXT
// ensures that this canvas is current
if (!set_current())
return;
#endif // !ENABLE_USE_UNIQUE_GLCONTEXT
std::vector<float> tool_colors = _parse_colors(str_tool_colors);
if (m_volumes.empty())
@ -5523,11 +5479,6 @@ Point GLCanvas3D::get_local_mouse_position() const
void GLCanvas3D::reset_legend_texture()
{
#if !ENABLE_USE_UNIQUE_GLCONTEXT
if (!set_current())
return;
#endif // !ENABLE_USE_UNIQUE_GLCONTEXT
m_legend_texture.reset();
}
@ -5958,7 +5909,6 @@ bool GLCanvas3D::_init_toolbar()
return true;
}
#if ENABLE_USE_UNIQUE_GLCONTEXT
bool GLCanvas3D::_set_current()
{
if ((m_canvas != nullptr) && (m_context != nullptr))
@ -5966,7 +5916,6 @@ bool GLCanvas3D::_set_current()
return false;
}
#endif ENABLE_USE_UNIQUE_GLCONTEXT
void GLCanvas3D::_resize(unsigned int w, unsigned int h)
{
@ -5978,11 +5927,7 @@ void GLCanvas3D::_resize(unsigned int w, unsigned int h)
#endif // ENABLE_IMGUI
// ensures that this canvas is current
#if ENABLE_USE_UNIQUE_GLCONTEXT
_set_current();
#else
set_current();
#endif // ENABLE_USE_UNIQUE_GLCONTEXT
::glViewport(0, 0, w, h);
::glMatrixMode(GL_PROJECTION);
@ -6862,12 +6807,6 @@ void GLCanvas3D::_stop_timer()
void GLCanvas3D::_load_print_toolpaths()
{
#if !ENABLE_USE_UNIQUE_GLCONTEXT
// ensures this canvas is current
if (!set_current())
return;
#endif // !ENABLE_USE_UNIQUE_GLCONTEXT
const Print *print = this->fff_print();
if (print == nullptr)
return;
@ -8010,31 +7949,16 @@ std::vector<float> GLCanvas3D::_parse_colors(const std::vector<std::string>& col
void GLCanvas3D::_generate_legend_texture(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors)
{
#if !ENABLE_USE_UNIQUE_GLCONTEXT
if (!set_current())
return;
#endif // !ENABLE_USE_UNIQUE_GLCONTEXT
m_legend_texture.generate(preview_data, tool_colors, *this, m_dynamic_background_enabled && _is_any_volume_outside());
}
void GLCanvas3D::_generate_warning_texture(const std::string& msg)
{
#if !ENABLE_USE_UNIQUE_GLCONTEXT
if (!set_current())
return;
#endif // !ENABLE_USE_UNIQUE_GLCONTEXT
m_warning_texture.generate(msg);
}
void GLCanvas3D::_reset_warning_texture()
{
#if !ENABLE_USE_UNIQUE_GLCONTEXT
if (!set_current())
return;
#endif // !ENABLE_USE_UNIQUE_GLCONTEXT
m_warning_texture.reset();
}

View file

@ -894,9 +894,7 @@ public:
GLCanvas3D(wxGLCanvas* canvas);
~GLCanvas3D();
#if ENABLE_USE_UNIQUE_GLCONTEXT
void set_context(wxGLContext* context) { m_context = context; }
#endif // ENABLE_USE_UNIQUE_GLCONTEXT
wxGLCanvas* get_wxglcanvas() { return m_canvas; }
@ -905,10 +903,6 @@ public:
bool init(bool useVBOs, bool use_legacy_opengl);
void post_event(wxEvent &&event);
#if !ENABLE_USE_UNIQUE_GLCONTEXT
bool set_current();
#endif // !ENABLE_USE_UNIQUE_GLCONTEXT
void set_as_dirty();
unsigned int get_volumes_count() const;
@ -1047,9 +1041,7 @@ private:
bool _init_toolbar();
#if ENABLE_USE_UNIQUE_GLCONTEXT
bool _set_current();
#endif // ENABLE_USE_UNIQUE_GLCONTEXT
void _resize(unsigned int w, unsigned int h);
BoundingBoxf3 _max_bounding_box() const;

View file

@ -113,16 +113,13 @@ std::string GLCanvas3DManager::GLInfo::to_string(bool format_as_html, bool exten
GLCanvas3DManager::EMultisampleState GLCanvas3DManager::s_multisample = GLCanvas3DManager::MS_Unknown;
GLCanvas3DManager::GLCanvas3DManager()
#if ENABLE_USE_UNIQUE_GLCONTEXT
: m_context(nullptr)
#endif // ENABLE_USE_UNIQUE_GLCONTEXT
, m_gl_initialized(false)
, m_use_legacy_opengl(false)
, m_use_VBOs(false)
{
}
#if ENABLE_USE_UNIQUE_GLCONTEXT
GLCanvas3DManager::~GLCanvas3DManager()
{
if (m_context != nullptr)
@ -131,7 +128,6 @@ GLCanvas3DManager::~GLCanvas3DManager()
m_context = nullptr;
}
}
#endif // ENABLE_USE_UNIQUE_GLCONTEXT
bool GLCanvas3DManager::add(wxGLCanvas* canvas)
{
@ -147,7 +143,6 @@ bool GLCanvas3DManager::add(wxGLCanvas* canvas)
canvas3D->bind_event_handlers();
#if ENABLE_USE_UNIQUE_GLCONTEXT
if (m_context == nullptr)
{
m_context = new wxGLContext(canvas);
@ -156,7 +151,6 @@ bool GLCanvas3DManager::add(wxGLCanvas* canvas)
}
canvas3D->set_context(m_context);
#endif // ENABLE_USE_UNIQUE_GLCONTEXT
m_canvases.insert(CanvasesMap::value_type(canvas, canvas3D));

View file

@ -51,9 +51,7 @@ class GLCanvas3DManager
typedef std::map<wxGLCanvas*, GLCanvas3D*> CanvasesMap;
CanvasesMap m_canvases;
#if ENABLE_USE_UNIQUE_GLCONTEXT
wxGLContext* m_context;
#endif // ENABLE_USE_UNIQUE_GLCONTEXT
GLInfo m_gl_info;
bool m_gl_initialized;
bool m_use_legacy_opengl;
@ -62,9 +60,7 @@ class GLCanvas3DManager
public:
GLCanvas3DManager();
#if ENABLE_USE_UNIQUE_GLCONTEXT
~GLCanvas3DManager();
#endif // ENABLE_USE_UNIQUE_GLCONTEXT
bool add(wxGLCanvas* canvas);
bool remove(wxGLCanvas* canvas);