diff libinterp/corefcn/gl2ps-print.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 d19dfcc862d4
children 2da65009cc7f
line wrap: on
line diff
--- a/libinterp/corefcn/gl2ps-print.cc	Fri Sep 07 09:48:33 2018 -0700
+++ b/libinterp/corefcn/gl2ps-print.cc	Thu Sep 06 16:29:56 2018 -0400
@@ -71,9 +71,10 @@
   {
   public:
 
-    gl2ps_renderer (FILE *_fp, const std::string& _term)
-      : opengl_renderer () , fp (_fp), term (_term), fontsize (),
-        fontname (), buffer_overflow (false)
+    gl2ps_renderer (opengl_functions& glfcns, FILE *_fp,
+                    const std::string& _term)
+      : opengl_renderer (glfcns), fp (_fp), term (_term),
+        fontsize (), fontname (), buffer_overflow (false)
     { }
 
     ~gl2ps_renderer (void) = default;
@@ -128,7 +129,7 @@
     {
       // Initialize a sorting tree (viewport) in gl2ps for each axes
       GLint vp[4];
-      glGetIntegerv (GL_VIEWPORT, vp);
+      m_glfcns.glGetIntegerv (GL_VIEWPORT, vp);
       gl2psBeginViewport (vp);
 
 
@@ -274,6 +275,7 @@
                                std::list<text_renderer::string>& lst);
 
     int alignment_to_mode (int ha, int va) const;
+
     FILE *fp;
     caseless_str term;
     double fontsize;
@@ -409,7 +411,7 @@
             const figure::properties& fprop
               = dynamic_cast<const figure::properties&> (go.get_properties ());
             Matrix c = fprop.get_color_rgb ();
-            glClearColor (c(0), c(1), c(2), 1);
+            m_glfcns.glClearColor (c(0), c(1), c(2), 1);
 
             // GL2PS_SILENT was removed to allow gl2ps to print errors on stderr
             GLint ret = gl2psBeginPage ("gl2ps_renderer figure", "Octave",
@@ -561,7 +563,7 @@
                         + (txtobj.get_x () + box(0))*sin (rot);
 
         GLint vp[4];
-        glGetIntegerv (GL_VIEWPORT, vp);
+        m_glfcns.glGetIntegerv (GL_VIEWPORT, vp);
 
         txtobj.set_x (coord_pix(0));
         txtobj.set_y (vp[3] - coord_pix(1));
@@ -976,7 +978,7 @@
     std::list<text_renderer::string> lst;
 
     text_to_strlist (str, lst, bbox, ha, va, rotation);
-    glRasterPos3d (x, y, z);
+    m_glfcns.glRasterPos3d (x, y, z);
 
     // For svg/eps directly dump a preformated text element into gl2ps output
     if (term.find ("svg") != std::string::npos)
@@ -1114,8 +1116,8 @@
   // named by the rest of the string.  Otherwise, write to the named file.
 
   void
-  gl2ps_print (const graphics_object& fig, const std::string& stream,
-               const std::string& term)
+  gl2ps_print (opengl_functions& glfcns, const graphics_object& fig,
+               const std::string& stream, const std::string& term)
   {
 #if defined (HAVE_GL2PS_H) && defined (HAVE_OPENGL)
 
@@ -1153,7 +1155,7 @@
         frame.add_fcn (safe_fclose, fp);
       }
 
-    gl2ps_renderer rend (fp, term);
+    gl2ps_renderer rend (glfcns, fp, term);
 
     Matrix pos = fig.get ("position").matrix_value ();
     rend.set_viewport (pos(2), pos(3));
@@ -1163,11 +1165,14 @@
     rend.finish ();
 
 #else
+
+    octave_unused_parameter (glfcns);
     octave_unused_parameter (fig);
     octave_unused_parameter (stream);
     octave_unused_parameter (term);
 
     err_disabled_feature ("gl2ps_print", "gl2ps");
+
 #endif
   }
 }