diff libinterp/corefcn/gl-render.cc @ 26862:ea4a36fd48b6

Warn when image can't be rendered due to OpenGL library limitation (bug #54680) * gl-render.cc (opengl_texture::create): Return empty texture if the width or height of the image is larger than the OpenGL implementation can handle.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Fri, 15 Feb 2019 13:25:11 +0100
parents 0adb232f93b9
children ab5bfee22d18
line wrap: on
line diff
--- a/libinterp/corefcn/gl-render.cc	Thu Mar 07 16:31:51 2019 +0100
+++ b/libinterp/corefcn/gl-render.cc	Fri Feb 15 13:25:11 2019 +0100
@@ -191,6 +191,25 @@
         //        Should we check for dimensions larger than intmax?
         int h, w, tw, th;
         h = dv(0), w = dv(1);
+
+        // Return early if the image data are larger than the texture
+        // can hold
+        int max_size;
+        glGetIntegerv (GL_MAX_TEXTURE_SIZE, &max_size);
+        static bool warned = false;
+        if (h > max_size || w > max_size)
+          {
+            if (! warned)
+              {
+                warning ("opengl_texture::create: the opengl library in use "
+                         "doesn't support images with either dimension larger "
+                         "than %d. Not rendering.", max_size);
+                warned = true;
+              }
+            
+            return opengl_texture (glfcns);
+          }
+        
         GLuint id;
         bool ok = true;
 
@@ -3894,34 +3913,34 @@
     // Expect RGB data
     if (dv.ndims () == 3 && dv(2) == 3)
       {
-        opengl_texture tex (m_glfcns);
-        tex = opengl_texture::create (m_glfcns, cdata);
-        m_glfcns.glColor4d (1.0, 1.0, 1.0, 1.0);
-
-        m_glfcns.glEnable (GL_TEXTURE_2D);
-
-        m_glfcns.glBegin (GL_QUADS);
-
-        tex.tex_coord (0.0, 0.0);
-        m_glfcns.glVertex3d (x0, y0, 0.0);
-
-        tex.tex_coord (1.0, 0.0);
-        m_glfcns.glVertex3d (x1, y0, 0.0);
-
-        tex.tex_coord (1.0, 1.0);
-        m_glfcns.glVertex3d (x1, y1, 0.0);
-
-        tex.tex_coord (0.0, 1.0);
-        m_glfcns.glVertex3d (x0, y1, 0.0);
-
-        m_glfcns.glEnd ();
-        m_glfcns.glDisable (GL_TEXTURE_2D);
+        opengl_texture tex  = opengl_texture::create (m_glfcns, cdata);
+        if (tex.is_valid ())
+          {
+            m_glfcns.glColor4d (1.0, 1.0, 1.0, 1.0);
+
+            m_glfcns.glEnable (GL_TEXTURE_2D);
+
+            m_glfcns.glBegin (GL_QUADS);
+
+            tex.tex_coord (0.0, 0.0);
+            m_glfcns.glVertex3d (x0, y0, 0.0);
+
+            tex.tex_coord (1.0, 0.0);
+            m_glfcns.glVertex3d (x1, y0, 0.0);
+
+            tex.tex_coord (1.0, 1.0);
+            m_glfcns.glVertex3d (x1, y1, 0.0);
+
+            tex.tex_coord (0.0, 1.0);
+            m_glfcns.glVertex3d (x0, y1, 0.0);
+
+            m_glfcns.glEnd ();
+            m_glfcns.glDisable (GL_TEXTURE_2D);
+          }
       }
     else
       warning ("opengl_renderer: invalid image size (expected MxNx3 or MxN)");
 
-    m_glfcns.glPixelZoom (1, 1);
-
 #else
 
     octave_unused_parameter (props);