changeset 22494:3564b6b6b8d1

Query OpenGL errors on initialization of GL context (bug #45542). * gl-render.cc (init_gl_context): Add glGetError for features that fail on some (Windows) machines. Add generic warning if GL error is set after initialization of GL context. * gl-render.cc (draw): Add generic warning if GL error is set after drawing object.
author Markus Mützel <markus.muetzel@gmx.de>
date Thu, 15 Sep 2016 00:36:59 +0200
parents 09c0ee94b7ee
children ad815427f376
files libinterp/corefcn/gl-render.cc
diffstat 1 files changed, 25 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/gl-render.cc	Wed Sep 14 21:33:26 2016 -0700
+++ b/libinterp/corefcn/gl-render.cc	Thu Sep 15 00:36:59 2016 +0200
@@ -696,6 +696,11 @@
         warning ("opengl_renderer: cannot render object of type '%s'",
                  props.graphics_object_name ().c_str ());
       }
+
+    GLenum gl_error = glGetError ();
+    if (gl_error)
+      warning ("opengl_renderer: Error %d occurred drawing '%s' object",
+               gl_error, props.graphics_object_name ().c_str ());
   }
 
 #if defined (HAVE_OPENGL)
@@ -788,13 +793,24 @@
       {
         glEnable (GL_BLEND);
         glEnable (GL_MULTISAMPLE);
-        GLint iMultiSample, iNumSamples;
-        glGetIntegerv (GL_SAMPLE_BUFFERS, &iMultiSample);
-        glGetIntegerv (GL_SAMPLES, &iNumSamples);
-        if (iMultiSample != GL_TRUE || iNumSamples == 0)
+        bool has_multisample = false;
+        if (! glGetError ())
+          {
+            GLint iMultiSample, iNumSamples;
+            glGetIntegerv (GL_SAMPLE_BUFFERS, &iMultiSample);
+            glGetIntegerv (GL_SAMPLES, &iNumSamples);
+            if (iMultiSample == GL_TRUE && iNumSamples > 0)
+              has_multisample = true;
+          }
+
+        if (! has_multisample)
           {
             // MultiSample not implemented.  Use old-style anti-aliasing
             glDisable (GL_MULTISAMPLE);
+            // Disabling GL_MULTISAMPLE will raise a gl error if it is not
+            // implemented.  Thus, call glGetError to reset the error state.
+            glGetError ();
+
             glEnable (GL_LINE_SMOOTH);
             glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
           }
@@ -813,6 +829,11 @@
         glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
       }
 
+    GLenum gl_error = glGetError ();
+    if (gl_error)
+      warning ("opengl_renderer: Error %d occurred in init_gl_context",
+               gl_error);
+
 #else
 
     octave_unused_parameter (enhanced);