WIP : trying to figure out why the items are not drawn.

This commit is contained in:
Maxime Gimeno 2018-09-03 10:51:01 +02:00
parent daac3e124d
commit 06ce5dddca
15 changed files with 127 additions and 46 deletions

View File

@ -79,8 +79,11 @@ class CGAL_QT_EXPORT QGLViewer : public QOpenGLWidget, public QOpenGLFunctions {
Q_OBJECT
public:
//todo check if this is used. If not remove it
explicit QGLViewer(QGLContext* context, QWidget *parent = 0,
::Qt::WindowFlags flags = 0);
explicit QGLViewer(QOpenGLContext* context, QWidget *parent = 0,
::Qt::WindowFlags flags = 0);
explicit QGLViewer(QWidget *parent = 0,
::Qt::WindowFlags flags = 0);
@ -1206,6 +1209,7 @@ protected:
//C o n t e x t
bool is_ogl_4_3;
bool is_sharing;
QOpenGLContext* shared_context;
public:
//! Is used to know if the openGL context is 4.3 or ES 2.0.
//! @returns `true` if the context is 4.3.

View File

@ -164,6 +164,8 @@ void CGAL::QGLViewer::defaultConstructor() {
_offset = CGAL::qglviewer::Vec(0,0,0);
stored_fbo = NULL;
is_sharing = false;
shared_context = nullptr;
}
CGAL_INLINE_FUNCTION
@ -172,6 +174,14 @@ CGAL::QGLViewer::QGLViewer(QWidget *parent,
: QOpenGLWidget(parent, flags) {
defaultConstructor();
}
CGAL_INLINE_FUNCTION
CGAL::QGLViewer::QGLViewer(QOpenGLContext* context, QWidget *parent,
::Qt::WindowFlags flags)
: QOpenGLWidget(parent, flags) {
defaultConstructor();
shared_context = context;
is_sharing = true;
}
/*! Virtual destructor.
@ -209,35 +219,44 @@ If a 4.3 context could not be set, a ES 2.0 context will be used instead.
*/
CGAL_INLINE_FUNCTION
void CGAL::QGLViewer::initializeGL() {
QSurfaceFormat format = context()->format();
context()->format().setOption(QSurfaceFormat::DebugContext);
if ( !context()->isValid()
|| format.majorVersion() != 4
|| QCoreApplication::arguments().contains(QStringLiteral("--old")))
if(!is_sharing)
{
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);
format.setVersion(2,0);
format.setRenderableType(QSurfaceFormat::OpenGLES);
format.setSamples(0);
format.setOption(QSurfaceFormat::DebugContext);
QSurfaceFormat::setDefaultFormat(format);
needNewContext();
qDebug()<<"GL 4.3 context initialization failed. ";
is_ogl_4_3 = false;
QSurfaceFormat format = context()->format();
context()->format().setOption(QSurfaceFormat::DebugContext);
if ( !context()->isValid()
|| format.majorVersion() != 4
|| QCoreApplication::arguments().contains(QStringLiteral("--old")))
{
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);
format.setVersion(2,0);
format.setRenderableType(QSurfaceFormat::OpenGLES);
format.setSamples(0);
format.setOption(QSurfaceFormat::DebugContext);
QSurfaceFormat::setDefaultFormat(format);
needNewContext();
qDebug()<<"GL 4.3 context initialization failed. ";
is_ogl_4_3 = false;
}
else
{
is_ogl_4_3 = true;
}
QSurfaceFormat cur_f = QOpenGLContext::currentContext()->format();
const char* rt =(cur_f.renderableType() == QSurfaceFormat::OpenGLES) ? "GLES" : "GL";
qDebug()<<"Using context "
<<cur_f.majorVersion()<<"."<<cur_f.minorVersion()
<< rt;
}
else
{
is_ogl_4_3 = true;
context()->setFormat(shared_context->format());
context()->create();
makeCurrent();
}
QSurfaceFormat cur_f = QOpenGLContext::currentContext()->format();
const char* rt =(cur_f.renderableType() == QSurfaceFormat::OpenGLES) ? "GLES" : "GL";
qDebug()<<"Using context "
<<cur_f.majorVersion()<<"."<<cur_f.minorVersion()
<< rt;
QOpenGLFunctions::initializeOpenGLFunctions();
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
// Default colors

View File

@ -2485,24 +2485,16 @@ void MainWindow::setupViewer(Viewer* viewer, SubViewer* subviewer=NULL)
this, SLOT(on_actionRecenterScene_triggered()));
connect(ui->actionLookAt, SIGNAL(triggered()),
this, SLOT(on_actionLookAt_triggered()));
connect(ui->actionSetBackgroundColor, SIGNAL(triggered()),
this, SLOT(on_actionSetBackgroundColor_triggered()));
connect(ui->actionDumpCamera, SIGNAL(triggered()),
this, SLOT(on_actionDumpCamera_triggered()));
connect(ui->actionCopyCamera, SIGNAL(triggered()),
this, SLOT(on_actionCopyCamera_triggered()));
connect(ui->actionPasteCamera, SIGNAL(triggered()),
this, SLOT(on_actionPasteCamera_triggered()));
connect(ui->actionAntiAliasing, SIGNAL(toggled(bool)),
viewer, SLOT(setAntiAliasing(bool)));
connect(ui->actionDrawTwoSides, SIGNAL(toggled(bool)),
viewer, SLOT(setTwoSides(bool)));
connect(ui->actionQuickCameraMode, SIGNAL(toggled(bool)),
viewer, SLOT(setFastDrawing(bool)));
connect(ui->actionSwitchProjection, SIGNAL(toggled(bool)),
viewer, SLOT(SetOrthoProjection(bool)));
connect(ui->actionSet_Transparency_Pass_Number, SIGNAL(triggered()),
viewer, SLOT(setTotalPass_clicked()));
}
else
{
@ -2547,9 +2539,6 @@ void MainWindow::setupViewer(Viewer* viewer, SubViewer* subviewer=NULL)
connect(action, SIGNAL(toggled(bool)),
viewer, SLOT(SetOrthoProjection(bool)));
action= subviewer->findChild<QAction*>("actionTotalPass");
connect(action, &QAction::triggered,
viewer, &Viewer::setTotalPass_clicked);
}

View File

@ -87,7 +87,9 @@ public:
* throws `std::logic_error` if loading does not succeed or
* `std::invalid_argument` if `fileinfo` specifies an invalid file*/
CGAL::Three::Scene_item* loadItem(QFileInfo fileinfo, CGAL::Three::Polyhedron_demo_io_plugin_interface*);
void computeViewerBBox(CGAL::qglviewer::Vec &min, CGAL::qglviewer::Vec &max);
void updateViewerBbox(Viewer* vi, bool recenter, CGAL::qglviewer::Vec min,
CGAL::qglviewer::Vec max);
Q_SIGNALS:
//! Is emitted when the Application is closed.
void on_closure();
@ -446,9 +448,6 @@ private:
QLineEdit operationSearchBar;
QWidgetAction* searchAction;
QString def_save_dir;
void computeViewerBBox(CGAL::qglviewer::Vec &min, CGAL::qglviewer::Vec &max);
void updateViewerBbox(Viewer* vi, bool recenter, CGAL::qglviewer::Vec min,
CGAL::qglviewer::Vec max);
private Q_SLOTS:
void on_actionAdd_Viewer_triggered();

View File

@ -1720,6 +1720,15 @@ void Scene::computeBbox()
last_bbox = bbox;
}
void Scene::newViewer(Viewer_interface *viewer)
{
initGL(viewer);
Q_FOREACH(Scene_item* item, m_entries)
{
item->newViewer(viewer);
}
}
void Scene::removeViewer(Viewer_interface *viewer)
{
vaos[viewer]->destroy();
@ -1735,3 +1744,25 @@ Scene::Bbox Scene::visibleBbox() const
{
return last_visible_bbox;
}
void Scene::initGL(Viewer_interface *viewer)
{
viewer->makeCurrent();
vaos[viewer] = new QOpenGLVertexArrayObject();
vaos[viewer]->create();
program.bind();
vaos[viewer]->bind();
vbo[0].bind();
vbo[0].allocate(points, 18 * sizeof(float));
program.enableAttributeArray("vertex");
program.setAttributeArray("vertex", GL_FLOAT, 0, 3);
vbo[0].release();
vbo[1].bind();
vbo[1].allocate(uvs, 12 * sizeof(float));
program.enableAttributeArray("v_texCoord");
program.setAttributeArray("v_texCoord", GL_FLOAT, 0, 2);
vbo[1].release();
vaos[viewer]->release();
program.release();
}

View File

@ -79,6 +79,7 @@ public:
int selectionAindex() const Q_DECL_OVERRIDE;
int selectionBindex() const Q_DECL_OVERRIDE;
void initializeGL(CGAL::Three::Viewer_interface*) Q_DECL_OVERRIDE;
void initGL(CGAL::Three::Viewer_interface* viewer);
void setPickedPixel(const QPoint &p) Q_DECL_OVERRIDE {picked_pixel = p;}
void draw(CGAL::Three::Viewer_interface*) Q_DECL_OVERRIDE;
void drawWithNames(CGAL::Three::Viewer_interface*) Q_DECL_OVERRIDE;
@ -211,7 +212,8 @@ public Q_SLOTS:
void setItemA(int i);
//!Sets the item_B as the item at index i .
void setItemB(int i);
void newViewer(CGAL::Three::Viewer_interface*);
void removeViewer(CGAL::Three::Viewer_interface*);
Q_SIGNALS:
//generated automatically by moc
//!Is emitted when the ids of the items are changed.
@ -285,8 +287,6 @@ private:
mutable QOpenGLBuffer vbo[2];
Bbox last_bbox;
Bbox last_visible_bbox;
public:
void removeViewer(CGAL::Three::Viewer_interface*);
}; // end class Scene
class QAbstractProxyModel;

View File

@ -258,3 +258,23 @@ void Scene_item_rendering_helper::removeViewer(Viewer_interface *viewer)
pc->removeViewer(viewer);
}
}
void Scene_item_rendering_helper::newViewer(Viewer_interface *viewer)
{
processData(ALL); //newViewer shouldn't be called when item is locked;
Q_FOREACH(Triangle_container* tc, priv->triangle_containers)
{
if(!tc->isGLInit(viewer))
tc->initGL(viewer);
}
Q_FOREACH(Edge_container* ec, priv->edge_containers)
{
if(!ec->isGLInit(viewer))
ec->initGL(viewer);
}
Q_FOREACH(Point_container* pc, priv->point_containers)
{
if(!pc->isGLInit(viewer))
pc->initGL(viewer);
}
}

View File

@ -115,6 +115,8 @@ protected:
public:
void zoomToPosition(const QPoint &, CGAL::Three::Viewer_interface *)const Q_DECL_OVERRIDE;
void newViewer(CGAL::Three::Viewer_interface* )Q_DECL_OVERRIDE {};
void removeViewer(CGAL::Three::Viewer_interface *)Q_DECL_OVERRIDE {};
}; // end class Scene_points_with_normal_item

View File

@ -151,7 +151,7 @@ public:
const Points& points() const;
const Polygons& polygons() const;
const Edges& non_manifold_edges() const;
void newViewer(CGAL::Three::Viewer_interface*)Q_DECL_OVERRIDE{}
void removeViewer(CGAL::Three::Viewer_interface*)Q_DECL_OVERRIDE{}
public Q_SLOTS:
void shuffle_orientations();

View File

@ -414,7 +414,6 @@ void Viewer::fastDraw()
void Viewer::init()
{
if(!isOpenGL_4_3())
{
std::cerr<<"The openGL context initialization failed "
@ -1674,5 +1673,10 @@ void Viewer::resetFov()
camera()->setHorizontalFieldOfView(ORIGINAL_FOV);
}
void Viewer::initializeGL()
{
QGLViewer::initializeGL();
doneInitGL(this);
}
#include "Viewer.moc"

View File

@ -50,6 +50,7 @@ public:
//! Deprecated. Does the same as draw().
void fastDraw()Q_DECL_OVERRIDE;
bool isExtensionFound()Q_DECL_OVERRIDE;
void initializeGL() Q_DECL_OVERRIDE;
//! Initializes the OpenGL functions and sets the backGround color.
void init()Q_DECL_OVERRIDE;
//! Draws the scene "with names" to allow picking.
@ -128,7 +129,6 @@ public Q_SLOTS:
void setLighting();
void messageLogged(QOpenGLDebugMessage);
void initializeGL()Q_DECL_OVERRIDE;
protected:
void paintEvent(QPaintEvent *)Q_DECL_OVERRIDE;

View File

@ -238,6 +238,7 @@ public :
//!Moves a child down in the list.
void moveDown(int);
void removeViewer(CGAL::Three::Viewer_interface* )Q_DECL_OVERRIDE;
void newViewer(CGAL::Three::Viewer_interface* )Q_DECL_OVERRIDE{};
public Q_SLOTS:
//!\brief Redraws children.
//!

View File

@ -302,6 +302,12 @@ public:
//!Contains the number of group and subgroups containing this item.
int has_group;
//!
//! \brief newViewer adds Vaos for `viewer`.
//!
//! Must be overriden;
//!
virtual void newViewer(CGAL::Three::Viewer_interface* viewer) = 0;
//!
//! \brief removeViewer removes the Vaos fo `viewer`.
//!
//! Must be overriden;

View File

@ -190,6 +190,11 @@ public:
//! @returns the item's bounding box's diagonal length.
//! @todo must replace the one from Scene_item eventually
virtual double diagonalBbox() const Q_DECL_OVERRIDE;
//!
//! \brief newViewer adds Vaos for `viewer`.
//! \param viewer the new viewer.
//!
void newViewer(Viewer_interface *viewer) Q_DECL_OVERRIDE;
//! \brief removeViewer removes the Vaos for `viewer`.
//! \param viewer the viewer to be removed.
void removeViewer(Viewer_interface *viewer) Q_DECL_OVERRIDE;

View File

@ -114,7 +114,8 @@ public:
//! \param sharedWidget the main viewer of the Application. This will share the
//! context and allow synchronized rendering of multiple views.
//!
Viewer_interface(QWidget* parent, QWidget*) : QGLViewer(parent){}
Viewer_interface(QWidget* parent, QOpenGLWidget* shared_widget)
: QGLViewer(shared_widget->context(),parent){}
virtual ~Viewer_interface() {}
//! \brief Sets the scene for the viewer.