diff libgui/graphics/GLCanvas.cc @ 25862:e5a73a8c116c

use wrapper class to call OpenGL functions The motivation for this change is to allow calling OpenGL functions through the Qt wrapper classes (QOpenGLFunctions and related classes) so that we can fall back to a software implementation of OpenGL (at least on Windows systems when using Qt) as described here http://doc.qt.io/qt-5/windows-requirements.html in the section "Dynamically Loading Graphics Drivers". However, we can't use the Qt wrappers directly since we also need to use OpenGL functions from the FLTK graphics widget. The new opengl_functions base class and the qopengl_functions class derived from it allows both the Qt and FLTK graphics widgets do continue using a common set of classes (opengl_render, etc.) for most OpenGL rendering. * oct-opengl.h (opengl_functions): New class. Forward calls to OpenGL functions. Don't define anything unless HAVE_OPENGL is defined. * gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h, gl-select.cc, gl-select.h: Fix constructors to accept opengl_functions object. Change all uses. Store reference to opengl_functions in all classes that call OpenGL functions. Use opengl_functions wrapper object to call all OpenGL functions. * gl-render.h, gl-render.cc (opengl_renderer::get_opengl_functions): New function. (opengl_renderer::m__max_lights): New data member. (opengl_renderer::init_maxlights): New member function to replace static function get_maxlights. (opengl_renderer::get_string): New member function to replace static function gl_get_string. * __init_fltk__.cc (OpenGL_fltk::m_glfcns): New opengl_functions data member. Use wrapper object to call all OpenGL functions. * libgui/graphics/qopengl-functions.h: New file. * libgui/graphics/module.mk: Update. * acinclude.m4 (OCTAVE_CHECK_QT_OPENGL_OK): Check for QGLFunctions_1_1 header file. * GLCanvas.cc, GLCanvas.h (GLCanvas::m_glfcns): New qopengl_functions data member. Use wrapper object to call all OpenGL functions. (GLCanvas::initializeGL): Initialize qopengl_functions object. (GLCanvas::drawZoomRect): New member function to replace static function glDrawZoomBox. Change all uses.
author John W. Eaton <jwe@octave.org>
date Thu, 06 Sep 2018 16:29:56 -0400
parents 078b795c5219
children 8a6bf76abf31
line wrap: on
line diff
--- a/libgui/graphics/GLCanvas.cc	Fri Sep 07 09:48:33 2018 -0700
+++ b/libgui/graphics/GLCanvas.cc	Thu Sep 06 16:29:56 2018 -0400
@@ -49,7 +49,7 @@
 
   GLCanvas::GLCanvas (QWidget *xparent, const graphics_handle& gh)
     : OCTAVE_QT_OPENGL_WIDGET (OCTAVE_QT_OPENGL_WIDGET_FORMAT_ARGS xparent),
-      Canvas (gh)
+      Canvas (gh), m_glfcns ()
   {
     setFocusPolicy (Qt::ClickFocus);
     setFocus ();
@@ -59,6 +59,12 @@
   { }
 
   void
+  GLCanvas::initializeGL (void)
+  {
+    m_glfcns.init ();
+  }
+
+  void
   GLCanvas::draw (const graphics_handle& gh)
   {
     gh_manager::auto_lock lock;
@@ -66,7 +72,7 @@
 
     if (go)
       {
-        octave::opengl_renderer r;
+        octave::opengl_renderer r (m_glfcns);
 
         r.set_viewport (width (), height ());
         r.draw (go);
@@ -98,7 +104,7 @@
 
             fbo.bind ();
 
-            octave::opengl_renderer r;
+            octave::opengl_renderer r (m_glfcns);
             r.set_viewport (pos(2), pos(3));
             r.draw (go);
             retval = r.get_pixels (pos(2), pos(3));
@@ -107,7 +113,7 @@
           }
         else
           {
-            octave::opengl_renderer r;
+            octave::opengl_renderer r (m_glfcns);
             r.set_viewport (pos(2), pos(3));
             r.draw (go);
             retval = r.get_pixels (pos(2), pos(3));
@@ -135,7 +141,7 @@
             if (! begin_rendering ())
               error ("print: no valid OpenGL offscreen context");
 
-            octave::gl2ps_print (figObj, file_cmd.toStdString (),
+            octave::gl2ps_print (m_glfcns, figObj, file_cmd.toStdString (),
                                  term.toStdString ());
           }
         catch (octave::execution_exception& e)
@@ -171,7 +177,7 @@
 
     if (ax)
       {
-        octave::opengl_selector s;
+        octave::opengl_selector s (m_glfcns);
 
         s.set_viewport (width (), height ());
         return s.select (ax, pt.x (), height () - pt.y (),
@@ -181,49 +187,49 @@
     return graphics_object ();
   }
 
-  inline void
-  glDrawZoomBox (const QPoint& p1, const QPoint& p2)
+  void
+  GLCanvas::drawZoomRect (const QPoint& p1, const QPoint& p2)
   {
-    glVertex2d (p1.x (), p1.y ());
-    glVertex2d (p2.x (), p1.y ());
-    glVertex2d (p2.x (), p2.y ());
-    glVertex2d (p1.x (), p2.y ());
-    glVertex2d (p1.x (), p1.y ());
+    m_glfcns.glVertex2d (p1.x (), p1.y ());
+    m_glfcns.glVertex2d (p2.x (), p1.y ());
+    m_glfcns.glVertex2d (p2.x (), p2.y ());
+    m_glfcns.glVertex2d (p1.x (), p2.y ());
+    m_glfcns.glVertex2d (p1.x (), p1.y ());
   }
 
   void
   GLCanvas::drawZoomBox (const QPoint& p1, const QPoint& p2)
   {
-    glMatrixMode (GL_MODELVIEW);
-    glPushMatrix ();
-    glLoadIdentity ();
+    m_glfcns.glMatrixMode (GL_MODELVIEW);
+    m_glfcns.glPushMatrix ();
+    m_glfcns.glLoadIdentity ();
 
-    glMatrixMode (GL_PROJECTION);
-    glPushMatrix ();
-    glLoadIdentity ();
-    glOrtho (0, width (), height (), 0, 1, -1);
+    m_glfcns.glMatrixMode (GL_PROJECTION);
+    m_glfcns.glPushMatrix ();
+    m_glfcns.glLoadIdentity ();
+    m_glfcns.glOrtho (0, width (), height (), 0, 1, -1);
 
-    glPushAttrib (GL_DEPTH_BUFFER_BIT | GL_CURRENT_BIT);
-    glDisable (GL_DEPTH_TEST);
+    m_glfcns.glPushAttrib (GL_DEPTH_BUFFER_BIT | GL_CURRENT_BIT);
+    m_glfcns.glDisable (GL_DEPTH_TEST);
 
-    glBegin (GL_POLYGON);
-    glColor4f (0.45, 0.62, 0.81, 0.1);
-    glDrawZoomBox (p1, p2);
-    glEnd ();
+    m_glfcns.glBegin (GL_POLYGON);
+    m_glfcns.glColor4f (0.45, 0.62, 0.81, 0.1);
+    drawZoomRect (p1, p2);
+    m_glfcns.glEnd ();
 
-    glLineWidth (1.5);
-    glBegin (GL_LINE_STRIP);
-    glColor4f (0.45, 0.62, 0.81, 0.9);
-    glDrawZoomBox (p1, p2);
-    glEnd ();
+    m_glfcns.glLineWidth (1.5);
+    m_glfcns.glBegin (GL_LINE_STRIP);
+    m_glfcns.glColor4f (0.45, 0.62, 0.81, 0.9);
+    drawZoomRect (p1, p2);
+    m_glfcns.glEnd ();
 
-    glPopAttrib ();
+    m_glfcns.glPopAttrib ();
 
-    glMatrixMode (GL_MODELVIEW);
-    glPopMatrix ();
+    m_glfcns.glMatrixMode (GL_MODELVIEW);
+    m_glfcns.glPopMatrix ();
 
-    glMatrixMode (GL_PROJECTION);
-    glPopMatrix ();
+    m_glfcns.glMatrixMode (GL_PROJECTION);
+    m_glfcns.glPopMatrix ();
   }
 
   void