Mercurial > octave
comparison scripts/plot/util/__opengl_info__.m @ 22205:8a456af24e6b
provide single function to get OpenGL renderer info
* scripts/plot/util/__opengl_info__.m: New file.
* scripts/plot/util/module.mk: Update.
author | John Donoghue <john.donoghue@ieee.org> |
---|---|
date | Sun, 17 Jul 2016 17:03:30 -0400 |
parents | |
children | fddc5604d1fa |
comparison
equal
deleted
inserted
replaced
22204:469c817eb256 | 22205:8a456af24e6b |
---|---|
1 ## Copyright (C) 2016 John Donoghue <john.donoghue@ieee.org> | |
2 ## | |
3 ## This program is free software; you can redistribute it and/or modify it | |
4 ## under the terms of the GNU General Public License as published by | |
5 ## the Free Software Foundation; either version 3 of the License, or | |
6 ## (at your option) any later version. | |
7 ## | |
8 ## This program is distributed in the hope that it will be useful, | |
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 ## GNU General Public License for more details. | |
12 ## | |
13 ## You should have received a copy of the GNU General Public License | |
14 ## along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | |
16 ## -*- texinfo -*- | |
17 ## @deftypefn {Function File} __opengl_info__ | |
18 ## @deftypefnx {Function File} {@var{retval} =} __opengl_info__ () | |
19 ## | |
20 ## Get OpenGL driver information. | |
21 ## | |
22 ## If no output values are requested, display information about the | |
23 ## OpenGL subsystem. If an output is requested, return the information | |
24 ## in a structure. | |
25 ## | |
26 ## Fields in the structure are: | |
27 ## @table @asis | |
28 ## @item version | |
29 ## OpenGL Driver version string | |
30 ## @item vendor | |
31 ## OpenGL Driver vendor string | |
32 ## @item renderer | |
33 ## OpenGL renderer string | |
34 ## @item extensions | |
35 ## List of enabled extensions for the OpenGL driver. | |
36 ## @end table | |
37 ## | |
38 ## @example | |
39 ## glinfo = __opengl_info__ (); | |
40 ## @end example | |
41 ## | |
42 ## @end deftypefn | |
43 | |
44 function retval = __opengl_info__ () | |
45 | |
46 # currently we only handle a single argument | |
47 if (nargin != 0) | |
48 print_usage (); | |
49 endif | |
50 | |
51 [info, msg] = gl_info (); | |
52 | |
53 if (isempty (msg)) | |
54 if (nargout == 0) | |
55 printf ("version = %s\n", info.version); | |
56 printf ("vendor = %s\n", info.vendor); | |
57 printf ("renderer = %s\n", info.renderer); | |
58 printf ("extensions =\n"); | |
59 printf (" %s\n", info.extensions{:}); | |
60 else | |
61 retval = info; | |
62 endif | |
63 else | |
64 warning (msg); | |
65 endif | |
66 | |
67 endfunction | |
68 | |
69 function info = fig_gl_info (h) | |
70 info = []; | |
71 if (ishandle (h) && strcmp (get (h, "renderer"), "opengl")) | |
72 vers = get (h, "__gl_version__"); | |
73 vend = get (h, "__gl_vendor__"); | |
74 rend = get (h, "__gl_renderer__"); | |
75 exts = get (h, "__gl_extensions__"); | |
76 if (! isempty (vend)) | |
77 info.version = vers; | |
78 info.vendor = vend; | |
79 info.renderer = rend; | |
80 info.extensions = strsplit (strtrim (exts)); | |
81 endif | |
82 endif | |
83 endfunction | |
84 | |
85 function [info, msg] = gl_info () | |
86 info = []; | |
87 msg = ""; | |
88 | |
89 ## If we have any open figures, take a look for any OpenGL info. | |
90 | |
91 figs = findall (0, "type", "figure"); | |
92 | |
93 for i = 1:numel (figs) | |
94 if (isempty (info)) | |
95 info = fig_gl_info (figs(i)); | |
96 if (! isempty (info)) | |
97 break | |
98 endif | |
99 endif | |
100 endfor | |
101 | |
102 ## If no info yet, try open a figure brifly to get the info. | |
103 | |
104 if (isempty (info)) | |
105 h = figure ("position", [0,0,1,1], "toolbar", "none", "menubar", "none"); | |
106 waitfor (h, "timeout", 1); | |
107 info = fig_gl_info (h); | |
108 close (h); | |
109 endif | |
110 | |
111 if (isempty (info)) | |
112 msg = "__opengl_info__: can not obtain OpenGL information"; | |
113 endif | |
114 | |
115 endfunction | |
116 | |
117 | |
118 %!xtest | |
119 %! a = __opengl_info__ (); | |
120 %! assert (! isempty (a)) | |
121 %! assert (isfield (a, "version")) |