annotate libgui/graphics/GLCanvas.cc @ 31649:deb553ac2c54

maint: Merge stable to default.
author John W. Eaton <jwe@octave.org>
date Tue, 06 Dec 2022 15:45:27 -0500
parents 431f80aba37a 29d734430e5f
children 5f11de0e7440
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29992
diff changeset
3 // Copyright (C) 2011-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21692
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21203
diff changeset
27 # include "config.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #endif
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
27417
f844b1f03dcc update some header file lists in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27393
diff changeset
30 #include "GLCanvas.h"
f844b1f03dcc update some header file lists in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27393
diff changeset
31 #include "gl-select.h"
f844b1f03dcc update some header file lists in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27393
diff changeset
32
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #include "gl-render.h"
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
34 #include "gl2ps-print.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #include "graphics.h"
27647
2a506bc4a7af eliminate global access to Octave interpreter in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27645
diff changeset
36 #include "interpreter.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
31646
c6d54dd31a7e maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
38 OCTAVE_BEGIN_NAMESPACE(octave)
c6d54dd31a7e maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
39
24142
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
40 #if defined (HAVE_QOPENGLWIDGET)
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
41 # define OCTAVE_QT_OPENGL_WIDGET_FORMAT_ARGS
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
42 #else
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
43 # if defined (Q_OS_WIN32)
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
44 # define OCTAVE_QT_OPENGL_WIDGET_FORMAT_ARGS \
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
45 QGLFormat (QGL::SampleBuffers | QGL::AlphaChannel \
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
46 | QGL::IndirectRendering),
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
47 # else
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
48 # define OCTAVE_QT_OPENGL_WIDGET_FORMAT_ARGS \
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
49 QGLFormat (QGL::SampleBuffers | QGL::AlphaChannel),
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
50 # endif
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
51 #endif
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52
31639
ca7d58406f82 eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
53 GLCanvas::GLCanvas (octave::interpreter& interp,
27645
028205a91a07 eliminate global access to Octave resources in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27481
diff changeset
54 const graphics_handle& gh, QWidget *xparent)
24142
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
55 : OCTAVE_QT_OPENGL_WIDGET (OCTAVE_QT_OPENGL_WIDGET_FORMAT_ARGS xparent),
31639
ca7d58406f82 eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
56 Canvas (interp, gh), m_glfcns (), m_renderer (m_glfcns)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
57 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
58 setFocusPolicy (Qt::ClickFocus);
23070
bef714f45999 maint: Use space after function name/before parenthesis in libgui.
Rik <rik@octave.org>
parents: 22755
diff changeset
59 setFocus ();
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
60 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
62 GLCanvas::~GLCanvas (void)
22417
48c00363dc74 maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents: 22413
diff changeset
63 { }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
65 void
25862
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
66 GLCanvas::initializeGL (void)
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
67 {
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
68 m_glfcns.init ();
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
69 }
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
70
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
71 void
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
72 GLCanvas::draw (const graphics_handle& gh)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
73 {
27647
2a506bc4a7af eliminate global access to Octave interpreter in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27645
diff changeset
74 gh_manager& gh_mgr = m_interpreter.get_gh_manager ();
27335
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
75
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
76 octave::autolock guard (gh_mgr.graphics_lock ());
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
77
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
78 graphics_object go = gh_mgr.get_object (gh);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
80 if (go)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
81 {
25884
4e108574385c Improve OpenGL rendering on high resolution screens with Qt 5 (bug #49053)
John Swensen <jpswensen@gmail.com>
parents: 25863
diff changeset
82 graphics_object fig = go.get_ancestor ("figure");
4e108574385c Improve OpenGL rendering on high resolution screens with Qt 5 (bug #49053)
John Swensen <jpswensen@gmail.com>
parents: 25863
diff changeset
83 double dpr = fig.get ("__device_pixel_ratio__").double_value ();
4e108574385c Improve OpenGL rendering on high resolution screens with Qt 5 (bug #49053)
John Swensen <jpswensen@gmail.com>
parents: 25863
diff changeset
84 m_renderer.set_viewport (dpr * width (), dpr * height ());
25889
2da65009cc7f Fix graphics object selection on high resolution screens (bug #49053)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25884
diff changeset
85 m_renderer.set_device_pixel_ratio (dpr);
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
86 m_renderer.draw (go);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
87 }
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
88 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
90 uint8NDArray
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
91 GLCanvas::do_getPixels (const graphics_handle& gh)
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
92 {
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
93 uint8NDArray retval;
27335
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
94
27647
2a506bc4a7af eliminate global access to Octave interpreter in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27645
diff changeset
95 gh_manager& gh_mgr = m_interpreter.get_gh_manager ();
27335
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
96
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
97 graphics_object go = gh_mgr.get_object (gh);
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
98
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
99 if (go && go.isa ("figure"))
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
100 {
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
101 Matrix pos = go.get ("position").matrix_value ();
25998
8d2b3e3ff182 print.m: Implement "-opengl", "-painters" and "-RGBImage" options (bug #52866)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25889
diff changeset
102 double dpr = go.get ("__device_pixel_ratio__").double_value ();
8d2b3e3ff182 print.m: Implement "-opengl", "-painters" and "-RGBImage" options (bug #52866)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25889
diff changeset
103 pos(2) *= dpr;
8d2b3e3ff182 print.m: Implement "-opengl", "-painters" and "-RGBImage" options (bug #52866)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25889
diff changeset
104 pos(3) *= dpr;
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
105
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
106 // Make sure we have a valid current context
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
107 if (! begin_rendering ())
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
108 return retval;
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
109
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
110 // When the figure is not visible or its size is frozen for printing,
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
111 // we use a framebuffer object to make sure we are rendering on a
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
112 // suitably large frame.
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
113 if (go.get ("visible").string_value () == "off"
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
114 || go.get ("__printing__").string_value () == "on")
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
115 {
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
116 OCTAVE_QT_OPENGL_FBO
25998
8d2b3e3ff182 print.m: Implement "-opengl", "-painters" and "-RGBImage" options (bug #52866)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25889
diff changeset
117 fbo (pos(2), pos(3),
8d2b3e3ff182 print.m: Implement "-opengl", "-painters" and "-RGBImage" options (bug #52866)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25889
diff changeset
118 OCTAVE_QT_OPENGL_FBO::Attachment::Depth);
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
119
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
120 fbo.bind ();
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
121
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
122 m_renderer.set_viewport (pos(2), pos(3));
25998
8d2b3e3ff182 print.m: Implement "-opengl", "-painters" and "-RGBImage" options (bug #52866)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25889
diff changeset
123 m_renderer.set_device_pixel_ratio (dpr);
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
124 m_renderer.draw (go);
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
125 retval = m_renderer.get_pixels (pos(2), pos(3));
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
126
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
127 fbo.release ();
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
128 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
129 else
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
130 {
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
131 m_renderer.set_viewport (pos(2), pos(3));
25998
8d2b3e3ff182 print.m: Implement "-opengl", "-painters" and "-RGBImage" options (bug #52866)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25889
diff changeset
132 m_renderer.set_device_pixel_ratio (dpr);
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
133 m_renderer.draw (go);
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
134 retval = m_renderer.get_pixels (pos(2), pos(3));
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
135 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
136
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
137 end_rendering ();
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
138 }
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
139
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
140 return retval;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
141 }
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
142
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
143 void
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
144 GLCanvas::do_print (const QString& file_cmd, const QString& term,
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
145 const graphics_handle& handle)
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
146 {
27647
2a506bc4a7af eliminate global access to Octave interpreter in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27645
diff changeset
147 gh_manager& gh_mgr = m_interpreter.get_gh_manager ();
27335
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
148
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
149 octave::autolock guard (gh_mgr.graphics_lock ());
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
150
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
151 graphics_object go = gh_mgr.get_object (handle);
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
152
27168
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
153 if (go.valid_object ())
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
154 {
27168
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
155 graphics_object fig (go.get_ancestor ("figure"));
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
156
26277
e92a44730a6e Rethrow exceptions from the GUI to the interpreter thread (bug #54920)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25998
diff changeset
157 // Make sure we have a valid current context
e92a44730a6e Rethrow exceptions from the GUI to the interpreter thread (bug #54920)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25998
diff changeset
158 if (! begin_rendering ())
e92a44730a6e Rethrow exceptions from the GUI to the interpreter thread (bug #54920)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25998
diff changeset
159 error ("print: no valid OpenGL offscreen context");
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
160
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
161 try
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
162 {
27168
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
163 if (fig.get ("visible").string_value () == "on")
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
164 octave::gl2ps_print (m_glfcns, fig, file_cmd.toStdString (),
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
165 term.toStdString ());
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
166 else
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
167 {
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
168 // When the figure is not visible, we use a framebuffer object
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
169 // to make sure we are rendering on a suitably large frame.
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
170 Matrix pos = fig.get ("position").matrix_value ();
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
171 double dpr = fig.get ("__device_pixel_ratio__").double_value ();
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
172 pos(2) *= dpr;
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
173 pos(3) *= dpr;
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
174
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
175 OCTAVE_QT_OPENGL_FBO
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
176 fbo (pos(2), pos(3),
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
177 OCTAVE_QT_OPENGL_FBO::Attachment::Depth);
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
178
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
179 fbo.bind ();
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
180
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
181 octave::gl2ps_print (m_glfcns, fig, file_cmd.toStdString (),
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
182 term.toStdString ());
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
183
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
184 fbo.release ();
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
185 }
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
186 }
27481
458adc344819 avoid possible crash due to execution_exception in GUI thread
John W. Eaton <jwe@octave.org>
parents: 27417
diff changeset
187 catch (octave::execution_exception& ee)
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
188 {
27303
07b330708e3c use Qt signals for interpreter callbacks in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27302
diff changeset
189 emit interpreter_event
28851
1ac5a76ae91d use [=] capture default specification where possible
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
190 ([=] (void)
27302
5f170ea12fa1 use Qt signals to pass interpreter callbacks to octave-qobject
John W. Eaton <jwe@octave.org>
parents: 27263
diff changeset
191 {
27393
efe72866b483 mark all interpreter_event lambda functions with special comment
John W. Eaton <jwe@octave.org>
parents: 27335
diff changeset
192 // INTERPRETER THREAD
27481
458adc344819 avoid possible crash due to execution_exception in GUI thread
John W. Eaton <jwe@octave.org>
parents: 27417
diff changeset
193 throw ee;
27302
5f170ea12fa1 use Qt signals to pass interpreter callbacks to octave-qobject
John W. Eaton <jwe@octave.org>
parents: 27263
diff changeset
194 });
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
195 }
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
196
26277
e92a44730a6e Rethrow exceptions from the GUI to the interpreter thread (bug #54920)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25998
diff changeset
197 end_rendering ();
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
198 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
199 }
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
200
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
201 graphics_object
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
202 GLCanvas::selectFromAxes (const graphics_object& ax, const QPoint& pt)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
203 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
204 makeCurrent ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
206 if (ax)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
207 {
25862
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
208 octave::opengl_selector s (m_glfcns);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209
25889
2da65009cc7f Fix graphics object selection on high resolution screens (bug #49053)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25884
diff changeset
210 s.set_viewport (width (), height ());
24691
b658e0fa0cb3 maint: Remove trailing whitespace from files.
Rik <rik@octave.org>
parents: 24636
diff changeset
211 return s.select (ax, pt.x (), height () - pt.y (),
24636
9d01ce02d5cb Make selection and "HitTest" compatible with Matlab (bug #52795).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24534
diff changeset
212 octave::select_ignore_hittest);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
213 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
214
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
215 return graphics_object ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
216 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217
25862
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
218 void
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
219 GLCanvas::drawZoomBox (const QPoint& p1, const QPoint& p2)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
220 {
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
221 Matrix overlaycolor (3, 1);
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
222 overlaycolor(0) = 0.45;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
223 overlaycolor(1) = 0.62;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
224 overlaycolor(2) = 0.81;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
225 double overlayalpha = 0.1;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
226 Matrix bordercolor = overlaycolor;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
227 double borderalpha = 0.9;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
228 double borderwidth = 1.5;
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
229
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
230 m_renderer.draw_zoom_box (width (), height (),
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
231 p1.x (), p1.y (), p2.x (), p2.y (),
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
232 overlaycolor, overlayalpha,
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
233 bordercolor, borderalpha, borderwidth);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
234 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
235
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
236 void
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
237 GLCanvas::paintGL (void)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
238 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
239 canvasPaintEvent ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
240 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
241
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
242 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
243 GLCanvas::mouseDoubleClickEvent (QMouseEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
244 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
245 canvasMouseDoubleClickEvent (xevent);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
246 }
19663
dfea01b3425f more mouse interaction features for Qt plotting widget
John W. Eaton <jwe@octave.org>
parents: 19642
diff changeset
247
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
248 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
249 GLCanvas::mouseMoveEvent (QMouseEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
250 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
251 canvasMouseMoveEvent (xevent);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
252 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
253
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
254 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
255 GLCanvas::mousePressEvent (QMouseEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
256 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
257 canvasMousePressEvent (xevent);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
258 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
259
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
260 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
261 GLCanvas::mouseReleaseEvent (QMouseEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
262 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
263 canvasMouseReleaseEvent (xevent);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
264 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
265
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
266 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
267 GLCanvas::wheelEvent (QWheelEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
268 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
269 canvasWheelEvent (xevent);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
270 }
19663
dfea01b3425f more mouse interaction features for Qt plotting widget
John W. Eaton <jwe@octave.org>
parents: 19642
diff changeset
271
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
272 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
273 GLCanvas::keyPressEvent (QKeyEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
274 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
275 if (! canvasKeyPressEvent (xevent))
24142
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
276 OCTAVE_QT_OPENGL_WIDGET::keyPressEvent (xevent);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
277 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
278
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
279 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
280 GLCanvas::keyReleaseEvent (QKeyEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
281 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
282 if (! canvasKeyReleaseEvent (xevent))
24142
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
283 OCTAVE_QT_OPENGL_WIDGET::keyReleaseEvent (xevent);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
284 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
285
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
286 bool
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
287 GLCanvas::begin_rendering (void)
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
288 {
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
289 bool retval = true;
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
290
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
291 if (! isValid ())
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
292 {
24837
ae6679369a80 Rely on QOffscreenSurface functionality rather than its presence (bug #53278)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24798
diff changeset
293 # if defined (HAVE_QT_OFFSCREEN)
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
294 static bool os_ctx_ok = true;
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
295 if (os_ctx_ok && ! m_os_context.isValid ())
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
296 {
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
297 // Try to initialize offscreen context
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
298 m_os_surface.create ();
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
299 if (! m_os_context.create ())
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
300 {
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
301 os_ctx_ok = false;
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
302 return false;
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
303 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
304 }
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
305
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
306 retval = m_os_context.makeCurrent (&m_os_surface);
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
307 # else
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
308 retval = false;
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
309 # endif
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
310 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
311 else
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
312 makeCurrent ();
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
313
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
314 return retval;
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
315 }
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
316
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
317 void
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
318 GLCanvas::end_rendering (void)
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
319 {
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
320 doneCurrent ();
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
321 }
31646
c6d54dd31a7e maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
322
c6d54dd31a7e maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
323 OCTAVE_END_NAMESPACE(octave)