From f577f91d25071f5ad1a9fdb6ed7c6dd3aa4c1008 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Fri, 9 Dec 2011 03:43:06 +0100 Subject: Better warnings and GL info related to OpenCSG capabilities and OpenGL 1.x diff --git a/openscad.pro b/openscad.pro index e88a94b..31c1e15 100644 --- a/openscad.pro +++ b/openscad.pro @@ -159,7 +159,8 @@ include(boost.pri) FORMS += src/MainWindow.ui \ - src/Preferences.ui + src/Preferences.ui \ + src/OpenCSGWarningDialog.ui HEADERS += src/renderer.h \ src/ThrownTogetherRenderer.h \ @@ -168,6 +169,7 @@ HEADERS += src/renderer.h \ src/GLView.h \ src/MainWindow.h \ src/Preferences.h \ + src/OpenCSGWarningDialog.h \ src/builtin.h \ src/context.h \ src/csgterm.h \ @@ -247,6 +249,7 @@ SOURCES += src/openscad.cc \ src/highlighter.cc \ src/printutils.cc \ src/Preferences.cc \ + src/OpenCSGWarningDialog.cc \ src/progress.cc \ src/editor.cc \ src/traverser.cc \ diff --git a/src/GLView.h b/src/GLView.h index c31e7af..5552e4b 100644 --- a/src/GLView.h +++ b/src/GLView.h @@ -32,7 +32,8 @@ public: void setShowCrosshairs(bool enabled) { this->showcrosshairs = enabled; } bool orthoMode() const { return this->orthomode; } void setOrthoMode(bool enabled) { this->orthomode = enabled; } - + const QString &getRendererInfo() const { return this->rendererInfo; } + public: QLabel *statusLabel; double object_rot_x; @@ -52,6 +53,8 @@ private: void init(); Renderer *renderer; + QString rendererInfo; + bool showfaces; bool showedges; bool showaxes; diff --git a/src/MainWindow.h b/src/MainWindow.h index b2d0f60..0f2a922 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -86,6 +86,8 @@ private: void loadViewSettings(); void loadDesignSettings(); + class QMessageBox *openglbox; + private slots: void actionNew(); void actionOpen(); @@ -156,6 +158,7 @@ public slots: void helpAbout(); void helpHomepage(); void helpManual(); + void helpOpenGL(); void quit(); void actionReloadCompile(); void checkAutoReload(); diff --git a/src/MainWindow.ui b/src/MainWindow.ui index dc73c05..d1bdb00 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -218,6 +218,7 @@ + @@ -666,6 +667,11 @@ Export as CSG... + + + OpenGL info + + diff --git a/src/OpenCSGWarningDialog.cc b/src/OpenCSGWarningDialog.cc new file mode 100644 index 0000000..fdaaa50 --- /dev/null +++ b/src/OpenCSGWarningDialog.cc @@ -0,0 +1,23 @@ +#include "OpenCSGWarningDialog.h" +#include "Preferences.h" + +OpenCSGWarningDialog::OpenCSGWarningDialog(QWidget *parent) +{ + setupUi(this); + + connect(this->showBox, SIGNAL(toggled(bool)), + Preferences::inst()->openCSGWarningBox, SLOT(setChecked(bool))); + connect(this->showBox, SIGNAL(toggled(bool)), + Preferences::inst(), SLOT(openCSGWarningChanged(bool))); + + connect(this->enableOpenCSGBox, SIGNAL(toggled(bool)), + Preferences::inst()->enableOpenCSGBox, SLOT(setChecked(bool))); + connect(this->enableOpenCSGBox, SIGNAL(toggled(bool)), + Preferences::inst(), SLOT(enableOpenCSGChanged(bool))); +} + +void OpenCSGWarningDialog::setText(const QString &text) +{ + this->warningText->setPlainText(text); +} + diff --git a/src/OpenCSGWarningDialog.h b/src/OpenCSGWarningDialog.h new file mode 100644 index 0000000..5d9c8fa --- /dev/null +++ b/src/OpenCSGWarningDialog.h @@ -0,0 +1,16 @@ +#ifndef OPENCSGWARNINGDIALOG_H_ +#define OPENCSGWARNINGDIALOG_H_ + +#include "ui_OpenCSGWarningDialog.h" + +class OpenCSGWarningDialog : public QDialog, public Ui::OpenCSGWarningDialog +{ + Q_OBJECT; +public: + OpenCSGWarningDialog(QWidget *parent); + +public slots: + void setText(const QString &text); +}; + +#endif diff --git a/src/OpenCSGWarningDialog.ui b/src/OpenCSGWarningDialog.ui new file mode 100644 index 0000000..f902521 --- /dev/null +++ b/src/OpenCSGWarningDialog.ui @@ -0,0 +1,93 @@ + + + OpenCSGWarningDialog + + + + 0 + 0 + 412 + 275 + + + + OpenGL Warning + + + + + + true + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Lucida Grande'; font-size:13pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p></body></html> + + + + + + + Enable OpenCSG + + + + + + + + + Show this message again + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Close + + + + + + + + + + + closeButton + clicked() + OpenCSGWarningDialog + accept() + + + 361 + 246 + + + 205 + 137 + + + + + diff --git a/src/Preferences.cc b/src/Preferences.cc index d240a9f..577ed4a 100644 --- a/src/Preferences.cc +++ b/src/Preferences.cc @@ -40,7 +40,8 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent) this->defaultmap["3dview/colorscheme"] = this->colorSchemeChooser->currentItem()->text(); this->defaultmap["editor/fontfamily"] = this->fontChooser->currentText(); this->defaultmap["editor/fontsize"] = this->fontSize->currentText().toUInt(); - this->defaultmap["editor/opengl20_warning_show"] = true; + this->defaultmap["advanced/opencsg_show_warning"] = true; + this->defaultmap["advanced/enable_opencsg_opengl1x"] = false; // Toolbar QActionGroup *group = new QActionGroup(this); @@ -98,7 +99,7 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent) this, SLOT(fontFamilyChanged(const QString &))); connect(this->fontSize, SIGNAL(editTextChanged(const QString &)), this, SLOT(fontSizeChanged(const QString &))); - connect(this->openCSGWarningBox, SIGNAL(clicked(bool)), + connect(this->openCSGWarningBox, SIGNAL(toggled(bool)), this, SLOT(openCSGWarningChanged(bool))); updateGUI(); } @@ -154,7 +155,14 @@ void Preferences::openCSGWarningChanged(bool state) { QSettings settings; - settings.setValue("editor/opengl20_warning_show",state); + settings.setValue("advanced/opencsg_show_warning",state); +} + +void +Preferences::enableOpenCSGChanged(bool state) +{ + QSettings settings; + settings.setValue("advanced/enable_opencsg_opengl1x", state); } void Preferences::keyPressEvent(QKeyEvent *e) @@ -215,7 +223,8 @@ void Preferences::updateGUI() this->fontSize->setEditText(fontsize); } - this->openCSGWarningBox->setChecked(getValue("editor/opengl20_warning_show").toBool()); + this->openCSGWarningBox->setChecked(getValue("advanced/opencsg_show_warning").toBool()); + this->enableOpenCSGBox->setChecked(getValue("advanced/enable_opencsg_opengl1x").toBool()); } void Preferences::apply() const diff --git a/src/Preferences.h b/src/Preferences.h index bdc707d..add1a11 100644 --- a/src/Preferences.h +++ b/src/Preferences.h @@ -35,6 +35,7 @@ public slots: void fontFamilyChanged(const QString &); void fontSizeChanged(const QString &); void openCSGWarningChanged(bool); + void enableOpenCSGChanged(bool); signals: void requestRedraw() const; diff --git a/src/Preferences.ui b/src/Preferences.ui index 556172c..6b80674 100644 --- a/src/Preferences.ui +++ b/src/Preferences.ui @@ -185,6 +185,16 @@ Show OpenCSG capability warning + + true + + + + + + + Enable OpenCSG for OpenGL 1.x + @@ -239,7 +249,7 @@ true - + :/icons/prefs3DView.png:/icons/prefs3DView.png @@ -251,7 +261,7 @@ true - + :/icons/prefsAdvanced.png:/icons/prefsAdvanced.png @@ -263,7 +273,7 @@ true - + :/icons/prefsEditor.png:/icons/prefsEditor.png @@ -272,7 +282,7 @@ - + diff --git a/src/glview.cc b/src/glview.cc index bc287b5..bd53b1b 100644 --- a/src/glview.cc +++ b/src/glview.cc @@ -39,6 +39,9 @@ #include #include #include +#include +#include "OpenCSGWarningDialog.h" + #include "mathc99.h" #include @@ -133,31 +136,45 @@ void GLView::initializeGL() fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err)); } + this->rendererInfo.sprintf("GLEW version %s\n" + "OpenGL version %s\n" + "%s (%s)\n\n" + "Extensions:\n" + "%s\n", + glewGetString(GLEW_VERSION), + glGetString(GL_RENDERER), + glGetString(GL_VENDOR), + glGetString(GL_VERSION), + glGetString(GL_EXTENSIONS)); + + const char *openscad_disable_gl20_env = getenv("OPENSCAD_DISABLE_GL20"); if (openscad_disable_gl20_env && !strcmp(openscad_disable_gl20_env, "0")) { openscad_disable_gl20_env = NULL; } // All OpenGL 2 contexts are OpenCSG capable - if (GLEW_VERSION_2_0 && !openscad_disable_gl20_env) this->is_opencsg_capable = true; - // If OpenGL < 2, check for extensions - else if (GLEW_ARB_framebuffer_object) this->is_opencsg_capable = true; - else if (GLEW_EXT_framebuffer_object && GLEW_EXT_packed_depth_stencil) { - this->is_opencsg_capable = true; + if (GLEW_VERSION_2_0) { + if (!openscad_disable_gl20_env) { + this->is_opencsg_capable = true; + this->has_shaders = true; + } } + // If OpenGL < 2, check for extensions + else { + if (GLEW_ARB_framebuffer_object) this->is_opencsg_capable = true; + else if (GLEW_EXT_framebuffer_object && GLEW_EXT_packed_depth_stencil) { + this->is_opencsg_capable = true; + } #ifdef WIN32 - else if (WGLEW_ARB_pbuffer && WGLEW_ARB_pixel_format) this->is_opencsg_capable = true; + else if (WGLEW_ARB_pbuffer && WGLEW_ARB_pixel_format) this->is_opencsg_capable = true; #elif !defined(__APPLE__) - else if (GLXEW_SGIX_pbuffer && GLXEW_SGIX_fbconfig) this->is_opencsg_capable = true; + else if (GLXEW_SGIX_pbuffer && GLXEW_SGIX_fbconfig) this->is_opencsg_capable = true; #endif + } - if (GLEW_VERSION_2_0 && !openscad_disable_gl20_env) this->has_shaders = true; - - if (!this->is_opencsg_capable) { - opencsg_support = false; - QSettings settings; - // FIXME: This should be an OpenCSG capability warning, not an OpenGL 2 warning - if (settings.value("editor/opengl20_warning_show",true).toBool()) { + if (!GLEW_VERSION_2_0 || !this->is_opencsg_capable) { + if (Preferences::inst()->getValue("advanced/opencsg_show_warning").toBool()) { QTimer::singleShot(0, this, SLOT(display_opencsg_warning())); } } @@ -252,9 +269,19 @@ void GLView::initializeGL() #ifdef ENABLE_OPENCSG void GLView::display_opencsg_warning() { - // data - QString title = QString("OpenGL context is not OpenCSG capable"); + OpenCSGWarningDialog *dialog = new OpenCSGWarningDialog(this); + QString message; + if (this->is_opencsg_capable) { + message += "Warning: You may experience OpenCSG rendering errors.\n\n"; + } + else { + message += "Warning: Missing OpenGL capabilities for OpenCSG - OpenCSG has been disabled.\n\n"; + dialog->enableOpenCSGBox->hide(); + } + message += "It is highly recommended to use OpenSCAD on a system with " + "OpenGL 2.0 or later.\n" + "Your renderer information is as follows:\n"; QString rendererinfo; rendererinfo.sprintf("GLEW version %s\n" "%s (%s)\n" @@ -262,44 +289,13 @@ void GLView::display_opencsg_warning() glewGetString(GLEW_VERSION), glGetString(GL_RENDERER), glGetString(GL_VENDOR), glGetString(GL_VERSION)); + message += rendererinfo; - QString message = QString("Warning: Missing OpenGL capabilities for OpenCSG - OpenCSG has been disabled.\n\n" - "It is highly recommended to use OpenSCAD on a system with OpenGL 2.0, " - "or support for the framebuffer_object or pbuffer extensions. " - "Your renderer information is as follows:\n\n%1").arg(rendererinfo); - - QString note = QString("Uncheck to hide this message in the future"); - - // presentation - QDialog *dialog = new QDialog(this); - dialog->setSizeGripEnabled(true); - dialog->setWindowTitle(title); - dialog->resize(500,300); - - QVBoxLayout *layout = new QVBoxLayout(dialog); - dialog->setLayout(layout); - - QTextEdit *textEdit = new QTextEdit(dialog); - textEdit->setPlainText(message); - layout->addWidget(textEdit); - - QCheckBox *checkbox = new QCheckBox(note,dialog); - checkbox->setCheckState(Qt::Checked); - layout->addWidget(checkbox); - - QDialogButtonBox *buttonbox = - new QDialogButtonBox( QDialogButtonBox::Ok, Qt::Horizontal,dialog); - layout->addWidget(buttonbox); - buttonbox->button(QDialogButtonBox::Ok)->setFocus(); - buttonbox->button(QDialogButtonBox::Ok)->setDefault(true); - - // action - connect(buttonbox, SIGNAL(accepted()), dialog, SLOT(accept())); - connect(checkbox, SIGNAL(clicked(bool)), - Preferences::inst()->openCSGWarningBox, SLOT(setChecked(bool))); - connect(checkbox, SIGNAL(clicked(bool)), - Preferences::inst(), SLOT(openCSGWarningChanged(bool))); + dialog->setText(message); + dialog->enableOpenCSGBox->setChecked(Preferences::inst()->getValue("advanced/enable_opencsg_opengl1x").toBool()); dialog->exec(); + + opencsg_support = this->is_opencsg_capable && Preferences::inst()->getValue("advanced/enable_opencsg_opengl1x").toBool(); } #endif diff --git a/src/mainwin.cc b/src/mainwin.cc index c81f2f2..4b4321d 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -312,6 +312,7 @@ MainWindow::MainWindow(const QString &filename) connect(this->helpActionAbout, SIGNAL(triggered()), this, SLOT(helpAbout())); connect(this->helpActionHomepage, SIGNAL(triggered()), this, SLOT(helpHomepage())); connect(this->helpActionManual, SIGNAL(triggered()), this, SLOT(helpManual())); + connect(this->helpActionOpenGLInfo, SIGNAL(triggered()), this, SLOT(helpOpenGL())); console->setReadOnly(true); @@ -1752,6 +1753,18 @@ MainWindow::helpManual() QDesktopServices::openUrl(QUrl("http://en.wikibooks.org/wiki/OpenSCAD_User_Manual")); } +void MainWindow::helpOpenGL() +{ + if (!this->openglbox) { + this->openglbox = new QMessageBox(QMessageBox::Information, + "OpenGL Info", "Detailed OpenGL Info", + QMessageBox::Ok, this); + + } + this->openglbox->setDetailedText(this->glview->getRendererInfo()); + this->openglbox->show(); +} + /*! FIXME: In MDI mode, should this be called on both reload functions? */ @@ -1822,3 +1835,4 @@ void MainWindow::clearCurrentOutput() { set_output_handler(NULL, NULL); } + -- cgit v0.10.1