changeset 24142:59cdf06c940e

use QOpenGLWidget if it is available * acinclude.m4 (OCTAVE_CHECK_QT_OPENGL_OK): Check for QOpenGlWidget. * GLCanvas.h, GLCanvas.cc (GLCanvas): Use QOpenGLWidget if it is available. Error both QOpenGLWidget and QGLWidget are missing.
author John W. Eaton <jwe@octave.org>
date Fri, 13 Oct 2017 13:22:09 -0400
parents af577de75e68
children 25ccc1f8092d
files libgui/graphics/GLCanvas.cc libgui/graphics/GLCanvas.h m4/acinclude.m4
diffstat 3 files changed, 41 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/graphics/GLCanvas.cc	Fri Oct 13 15:57:42 2017 +0200
+++ b/libgui/graphics/GLCanvas.cc	Fri Oct 13 13:22:09 2017 -0400
@@ -32,18 +32,22 @@
 
 namespace QtHandles
 {
+#if defined (HAVE_QOPENGLWIDGET)
+#  define OCTAVE_QT_OPENGL_WIDGET_FORMAT_ARGS
+#else
+#  if defined (Q_OS_WIN32)
+#    define OCTAVE_QT_OPENGL_WIDGET_FORMAT_ARGS         \
+  QGLFormat (QGL::SampleBuffers | QGL::AlphaChannel     \
+             | QGL::IndirectRendering),
+#  else
+#    define OCTAVE_QT_OPENGL_WIDGET_FORMAT_ARGS \
+  QGLFormat (QGL::SampleBuffers | QGL::AlphaChannel),
+#  endif
+#endif
 
   GLCanvas::GLCanvas (QWidget *xparent, const graphics_handle& gh)
-#if defined (Q_OS_WIN32)
-    : QGLWidget (QGLFormat (QGL::SampleBuffers | QGL::AlphaChannel |
-                            QGL::IndirectRendering),
-                 xparent),
+    : OCTAVE_QT_OPENGL_WIDGET (OCTAVE_QT_OPENGL_WIDGET_FORMAT_ARGS xparent),
       Canvas (gh)
-#else
-    : QGLWidget (QGLFormat (QGL::SampleBuffers | QGL::AlphaChannel),
-                 xparent),
-      Canvas (gh)
-#endif
   {
     setFocusPolicy (Qt::ClickFocus);
     setFocus ();
@@ -204,14 +208,14 @@
   GLCanvas::keyPressEvent (QKeyEvent *xevent)
   {
     if (! canvasKeyPressEvent (xevent))
-      QGLWidget::keyPressEvent (xevent);
+      OCTAVE_QT_OPENGL_WIDGET::keyPressEvent (xevent);
   }
 
   void
   GLCanvas::keyReleaseEvent (QKeyEvent *xevent)
   {
     if (! canvasKeyReleaseEvent (xevent))
-      QGLWidget::keyReleaseEvent (xevent);
+      OCTAVE_QT_OPENGL_WIDGET::keyReleaseEvent (xevent);
   }
 
 }
--- a/libgui/graphics/GLCanvas.h	Fri Oct 13 15:57:42 2017 +0200
+++ b/libgui/graphics/GLCanvas.h	Fri Oct 13 13:22:09 2017 -0400
@@ -23,14 +23,21 @@
 #if ! defined (octave_GLCanvas_h)
 #define octave_GLCanvas_h 1
 
-#include <QGLWidget>
+#if defined (HAVE_QOPENGLWIDGET)
+#  include <QOpenGLWidget>
+#  define OCTAVE_QT_OPENGL_WIDGET QOpenGLWidget
+#elif defined (HAVE_QGLWIDGET)
+#  include <QGLWidget>
+#  define OCTAVE_QT_OPENGL_WIDGET QGLWidget
+#else
+#  error "configuration error: must have <QOpenGLWidget> or <QGLWidget>."
+#endif
 
 #include "Canvas.h"
 
 namespace QtHandles
 {
-
-  class GLCanvas : public QGLWidget, public Canvas
+  class GLCanvas : public OCTAVE_QT_OPENGL_WIDGET, public Canvas
   {
   public:
     GLCanvas (QWidget *parent, const graphics_handle& handle);
--- a/m4/acinclude.m4	Fri Oct 13 15:57:42 2017 +0200
+++ b/m4/acinclude.m4	Fri Oct 13 13:22:09 2017 -0400
@@ -1342,25 +1342,33 @@
      ac_octave_save_CXXFLAGS="$CXXFLAGS"
      CPPFLAGS="$QT_CPPFLAGS $CXXPICFLAG $CPPFLAGS"
      CXXFLAGS="$CXXPICFLAG $CXXFLAGS"
+     AC_CHECK_HEADERS([QOpenGLWidget QGLWidget])
      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
          #if HAVE_WINDOWS_H
-         # include <windows.h>
+         #  include <windows.h>
          #endif
          #if defined (HAVE_GL_GL_H)
-         # include <GL/gl.h>
+         #  include <GL/gl.h>
          #elif defined (HAVE_OPENGL_GL_H)
-         # include <OpenGL/gl.h>
+         #  include <OpenGL/gl.h>
          #endif
          #if defined (HAVE_GL_GLU_H)
-         # include <GL/glu.h>
+         #  include <GL/glu.h>
          #elif defined HAVE_OPENGL_GLU_H || defined HAVE_FRAMEWORK_OPENGL
-         # include <OpenGL/glu.h>
+         #  include <OpenGL/glu.h>
          #endif
-         #include <QGLWidget>
-         class gl_widget : public QGLWidget
+         #if defined (HAVE_QOPENGLWIDGET)
+         #  include <QOpenGLWidget>
+         #  define OCTAVE_QT_OPENGL_WIDGET QOpenGLWidget
+         #elif defined (HAVE_QGLWIDGET)
+         #  include <QGLWidget>
+         #  define OCTAVE_QT_OPENGL_WIDGET QGLWidget
+         #endif
+         class gl_widget : public OCTAVE_QT_OPENGL_WIDGET
          {
          public:
-           gl_widget (QWidget *parent = 0) : QGLWidget (parent) {}
+           gl_widget (QWidget *parent = 0)
+             : OCTAVE_QT_OPENGL_WIDGET (parent) { }
            ~gl_widget () {}
          };
          ]], [[