Use a single gl context created in c++
This commit is contained in:
parent
a02ea39525
commit
44220530cb
@ -145,7 +145,7 @@ sub new {
|
||||
#==============================================================================================================================
|
||||
|
||||
#==============================================================================================================================
|
||||
Slic3r::GUI::_3DScene::add_canvas($self, $self->GetContext);
|
||||
Slic3r::GUI::_3DScene::add_canvas($self);
|
||||
Slic3r::GUI::_3DScene::allow_multisample($self, $can_multisample);
|
||||
# my $context = $self->GetContext;
|
||||
# $self->SetCurrent($context);
|
||||
@ -1078,19 +1078,17 @@ sub Destroy {
|
||||
# my @projected = gluUnProject_p($x, $y, $z, @mview, @proj, @viewport);
|
||||
# return Slic3r::Pointf3->new(@projected);
|
||||
#}
|
||||
#==============================================================================================================================
|
||||
|
||||
sub GetContext {
|
||||
my ($self) = @_;
|
||||
return $self->{context} ||= Wx::GLContext->new($self);
|
||||
}
|
||||
|
||||
sub SetCurrent {
|
||||
my ($self, $context) = @_;
|
||||
return $self->SUPER::SetCurrent($context);
|
||||
}
|
||||
|
||||
#==============================================================================================================================
|
||||
#
|
||||
#sub GetContext {
|
||||
# my ($self) = @_;
|
||||
# return $self->{context} ||= Wx::GLContext->new($self);
|
||||
#}
|
||||
#
|
||||
#sub SetCurrent {
|
||||
# my ($self, $context) = @_;
|
||||
# return $self->SUPER::SetCurrent($context);
|
||||
#}
|
||||
#
|
||||
#sub UseVBOs {
|
||||
# my ($self) = @_;
|
||||
#
|
||||
|
@ -1773,10 +1773,10 @@ bool _3DScene::use_VBOs()
|
||||
return s_canvas_mgr.use_VBOs();
|
||||
}
|
||||
|
||||
bool _3DScene::add_canvas(wxGLCanvas* canvas, wxGLContext* context)
|
||||
bool _3DScene::add_canvas(wxGLCanvas* canvas)
|
||||
{
|
||||
std::cout << "_3DScene::add_canvas()" << std::endl;
|
||||
return s_canvas_mgr.add(canvas, context);
|
||||
return s_canvas_mgr.add(canvas);
|
||||
}
|
||||
|
||||
bool _3DScene::remove_canvas(wxGLCanvas* canvas)
|
||||
|
@ -550,7 +550,7 @@ public:
|
||||
static std::string get_gl_info(bool format_as_html, bool extensions);
|
||||
static bool use_VBOs();
|
||||
|
||||
static bool add_canvas(wxGLCanvas* canvas, wxGLContext* context);
|
||||
static bool add_canvas(wxGLCanvas* canvas);
|
||||
static bool remove_canvas(wxGLCanvas* canvas);
|
||||
static void remove_all_canvases();
|
||||
|
||||
|
@ -1348,7 +1348,7 @@ void GLCanvas3D::update_volumes_selection(const std::vector<int>& selections)
|
||||
|
||||
for (unsigned int obj_idx = 0; obj_idx < (unsigned int)m_model->objects.size(); ++obj_idx)
|
||||
{
|
||||
if (selections[obj_idx] == 1)
|
||||
if ((selections[obj_idx] == 1) && (obj_idx < (unsigned int)m_objects_volumes_idxs.size()))
|
||||
{
|
||||
const std::vector<int>& volume_idxs = m_objects_volumes_idxs[obj_idx];
|
||||
for (int v : volume_idxs)
|
||||
|
@ -124,18 +124,35 @@ std::string GLCanvas3DManager::GLInfo::to_string(bool format_as_html, bool exten
|
||||
}
|
||||
|
||||
GLCanvas3DManager::GLCanvas3DManager()
|
||||
: m_gl_initialized(false)
|
||||
: m_context(nullptr)
|
||||
, m_gl_initialized(false)
|
||||
, m_use_legacy_opengl(false)
|
||||
, m_use_VBOs(false)
|
||||
{
|
||||
}
|
||||
|
||||
bool GLCanvas3DManager::add(wxGLCanvas* canvas, wxGLContext* context)
|
||||
GLCanvas3DManager::~GLCanvas3DManager()
|
||||
{
|
||||
if (m_context != nullptr)
|
||||
delete m_context;
|
||||
}
|
||||
|
||||
bool GLCanvas3DManager::add(wxGLCanvas* canvas)
|
||||
{
|
||||
if (canvas == nullptr)
|
||||
return false;
|
||||
|
||||
if (_get_canvas(canvas) != m_canvases.end())
|
||||
return false;
|
||||
|
||||
GLCanvas3D* canvas3D = new GLCanvas3D(canvas, context);
|
||||
if (m_context == nullptr)
|
||||
{
|
||||
m_context = new wxGLContext(canvas);
|
||||
if (m_context == nullptr)
|
||||
return false;
|
||||
}
|
||||
|
||||
GLCanvas3D* canvas3D = new GLCanvas3D(canvas, m_context);
|
||||
if (canvas3D == nullptr)
|
||||
return false;
|
||||
|
||||
|
@ -43,6 +43,7 @@ class GLCanvas3DManager
|
||||
|
||||
typedef std::map<wxGLCanvas*, GLCanvas3D*> CanvasesMap;
|
||||
|
||||
wxGLContext* m_context;
|
||||
CanvasesMap m_canvases;
|
||||
GLInfo m_gl_info;
|
||||
bool m_gl_initialized;
|
||||
@ -51,8 +52,9 @@ class GLCanvas3DManager
|
||||
|
||||
public:
|
||||
GLCanvas3DManager();
|
||||
~GLCanvas3DManager();
|
||||
|
||||
bool add(wxGLCanvas* canvas, wxGLContext* context);
|
||||
bool add(wxGLCanvas* canvas);
|
||||
bool remove(wxGLCanvas* canvas);
|
||||
|
||||
void remove_all();
|
||||
|
@ -168,13 +168,12 @@ use_VBOs()
|
||||
RETVAL = _3DScene::use_VBOs();
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
|
||||
bool
|
||||
add_canvas(canvas, context)
|
||||
add_canvas(canvas)
|
||||
SV *canvas;
|
||||
SV *context;
|
||||
CODE:
|
||||
RETVAL = _3DScene::add_canvas((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (wxGLContext*)wxPli_sv_2_object(aTHX_ context, "Wx::GLContext"));
|
||||
RETVAL = _3DScene::add_canvas((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"));
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user