Fix OpenGL extension report in system info operator.
[blender.git] / release / scripts / modules / sys_info.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (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, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20
21 # classes for extracting info from blenders internal classes
22
23
24 def write_sysinfo(filepath):
25     import sys
26
27     import subprocess
28
29     import bpy
30     import bgl
31
32     # pretty repr
33     def prepr(v):
34         r = repr(v)
35         vt = type(v)
36         if vt is bytes:
37             r = r[2:-1]
38         elif vt is list or vt is tuple:
39             r = r[1:-1]
40         return r
41
42     with open(filepath, 'w', encoding="utf-8") as output:
43         try:
44             header = "= Blender %s System Information =\n" % bpy.app.version_string
45             lilies = "%s\n\n" % ((len(header) - 1) * "=")
46             output.write(lilies[:-1])
47             output.write(header)
48             output.write(lilies)
49
50             def title(text):
51                 return "\n%s:\n%s" % (text, lilies)
52
53             # build info
54             output.write(title("Blender"))
55             output.write(
56                 "version: %s, branch: %s, commit date: %s %s, hash: %s, type: %s\n" %
57                 (bpy.app.version_string,
58                  prepr(bpy.app.build_branch),
59                  prepr(bpy.app.build_commit_date),
60                  prepr(bpy.app.build_commit_time),
61                  prepr(bpy.app.build_hash),
62                  prepr(bpy.app.build_type),
63                  ))
64
65             output.write("build date: %s, %s\n" % (prepr(bpy.app.build_date), prepr(bpy.app.build_time)))
66             output.write("platform: %s\n" % prepr(bpy.app.build_platform))
67             output.write("binary path: %s\n" % prepr(bpy.app.binary_path))
68             output.write("build cflags: %s\n" % prepr(bpy.app.build_cflags))
69             output.write("build cxxflags: %s\n" % prepr(bpy.app.build_cxxflags))
70             output.write("build linkflags: %s\n" % prepr(bpy.app.build_linkflags))
71             output.write("build system: %s\n" % prepr(bpy.app.build_system))
72
73             # python info
74             output.write(title("Python"))
75             output.write("version: %s\n" % (sys.version))
76             output.write("paths:\n")
77             for p in sys.path:
78                 output.write("\t%r\n" % p)
79
80             output.write(title("Python (External Binary)"))
81             output.write("binary path: %s\n" % prepr(bpy.app.binary_path_python))
82             try:
83                 py_ver = prepr(subprocess.check_output([
84                     bpy.app.binary_path_python,
85                     "--version",
86                 ]).strip())
87             except Exception as e:
88                 py_ver = str(e)
89             output.write("version: %s\n" % py_ver)
90             del py_ver
91
92             output.write(title("Directories"))
93             output.write("scripts:\n")
94             for p in bpy.utils.script_paths():
95                 output.write("\t%r\n" % p)
96             output.write("user scripts: %r\n" % (bpy.utils.script_path_user()))
97             output.write("pref scripts: %r\n" % (bpy.utils.script_path_pref()))
98             output.write("datafiles: %r\n" % (bpy.utils.user_resource('DATAFILES')))
99             output.write("config: %r\n" % (bpy.utils.user_resource('CONFIG')))
100             output.write("scripts : %r\n" % (bpy.utils.user_resource('SCRIPTS')))
101             output.write("autosave: %r\n" % (bpy.utils.user_resource('AUTOSAVE')))
102             output.write("tempdir: %r\n" % (bpy.app.tempdir))
103
104             output.write(title("FFmpeg"))
105             ffmpeg = bpy.app.ffmpeg
106             if ffmpeg.supported:
107                 for lib in ("avcodec", "avdevice", "avformat", "avutil", "swscale"):
108                     output.write(
109                         "%s:%s%r\n" % (lib, " " * (10 - len(lib)),
110                                        getattr(ffmpeg, lib + "_version_string")))
111             else:
112                 output.write("Blender was built without FFmpeg support\n")
113
114             if bpy.app.build_options.sdl:
115                 output.write(title("SDL"))
116                 output.write("Version: %s\n" % bpy.app.sdl.version_string)
117                 output.write("Loading method: ")
118                 if bpy.app.build_options.sdl_dynload:
119                     output.write("dynamically loaded by Blender (WITH_SDL_DYNLOAD=ON)\n")
120                 else:
121                     output.write("linked (WITH_SDL_DYNLOAD=OFF)\n")
122                 if not bpy.app.sdl.available:
123                     output.write("WARNING: Blender could not load SDL library\n")
124
125             output.write(title("Other Libraries"))
126             ocio = bpy.app.ocio
127             output.write("OpenColorIO: ")
128             if ocio.supported:
129                 if ocio.version_string == "fallback":
130                     output.write("Blender was built with OpenColorIO, " +
131                                  "but it currently uses fallback color management.\n")
132                 else:
133                     output.write("%s\n" % (ocio.version_string))
134             else:
135                 output.write("Blender was built without OpenColorIO support\n")
136
137             oiio = bpy.app.oiio
138             output.write("OpenImageIO: ")
139             if ocio.supported:
140                 output.write("%s\n" % (oiio.version_string))
141             else:
142                 output.write("Blender was built without OpenImageIO support\n")
143
144             output.write("OpenShadingLanguage: ")
145             if bpy.app.build_options.cycles:
146                 if bpy.app.build_options.cycles_osl:
147                     from _cycles import osl_version_string
148                     output.write("%s\n" % (osl_version_string))
149                 else:
150                     output.write("Blender was built without OpenShadingLanguage support in Cycles\n")
151             else:
152                 output.write("Blender was built without Cycles support\n")
153
154             opensubdiv = bpy.app.opensubdiv
155             output.write("OpenSubdiv: ")
156             if opensubdiv.supported:
157                 output.write("%s\n" % opensubdiv.version_string)
158             else:
159                 output.write("Blender was built without OpenSubdiv support\n")
160
161             openvdb = bpy.app.openvdb
162             output.write("OpenVDB: ")
163             if openvdb.supported:
164                 output.write("%s\n" % openvdb.version_string)
165             else:
166                 output.write("Blender was built without OpenVDB support\n")
167
168             alembic = bpy.app.alembic
169             output.write("Alembic: ")
170             if alembic.supported:
171                 output.write("%s\n" % alembic.version_string)
172             else:
173                 output.write("Blender was built without Alembic support\n")
174
175             if not bpy.app.build_options.sdl:
176                 output.write("SDL: Blender was built without SDL support\n")
177
178             if bpy.app.background:
179                 output.write("\nOpenGL: missing, background mode\n")
180             else:
181                 output.write(title("OpenGL"))
182                 version = bgl.glGetString(bgl.GL_RENDERER)
183                 output.write("renderer:\t%r\n" % version)
184                 output.write("vendor:\t\t%r\n" % (bgl.glGetString(bgl.GL_VENDOR)))
185                 output.write("version:\t%r\n" % (bgl.glGetString(bgl.GL_VERSION)))
186                 output.write("extensions:\n")
187
188                 limit = bgl.Buffer(bgl.GL_INT, 1)
189                 bgl.glGetIntegerv(bgl.GL_NUM_EXTENSIONS, limit)
190
191                 glext = []
192                 for i in range(limit[0]):
193                     glext.append(bgl.glGetStringi(bgl.GL_EXTENSIONS, i))
194
195                 glext = sorted(glext)
196
197                 for l in glext:
198                     output.write("\t%s\n" % l)
199
200                 output.write(title("Implementation Dependent OpenGL Limits"))
201                 bgl.glGetIntegerv(bgl.GL_MAX_ELEMENTS_VERTICES, limit)
202                 output.write("Maximum DrawElements Vertices:\t%d\n" % limit[0])
203                 bgl.glGetIntegerv(bgl.GL_MAX_ELEMENTS_INDICES, limit)
204                 output.write("Maximum DrawElements Indices:\t%d\n" % limit[0])
205
206                 output.write("\nGLSL:\n")
207                 bgl.glGetIntegerv(bgl.GL_MAX_VARYING_FLOATS, limit)
208                 output.write("Maximum Varying Floats:\t%d\n" % limit[0])
209                 bgl.glGetIntegerv(bgl.GL_MAX_VERTEX_ATTRIBS, limit)
210                 output.write("Maximum Vertex Attributes:\t%d\n" % limit[0])
211                 bgl.glGetIntegerv(bgl.GL_MAX_VERTEX_UNIFORM_COMPONENTS, limit)
212                 output.write("Maximum Vertex Uniform Components:\t%d\n" % limit[0])
213                 bgl.glGetIntegerv(bgl.GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, limit)
214                 output.write("Maximum Fragment Uniform Components:\t%d\n" % limit[0])
215                 bgl.glGetIntegerv(bgl.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, limit)
216                 output.write("Maximum Vertex Image Units:\t%d\n" % limit[0])
217                 bgl.glGetIntegerv(bgl.GL_MAX_TEXTURE_IMAGE_UNITS, limit)
218                 output.write("Maximum Fragment Image Units:\t%d\n" % limit[0])
219                 bgl.glGetIntegerv(bgl.GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, limit)
220                 output.write("Maximum Pipeline Image Units:\t%d\n" % limit[0])
221
222             if bpy.app.build_options.cycles:
223                 import cycles
224                 output.write(title("Cycles"))
225                 output.write(cycles.engine.system_info())
226
227             import addon_utils
228             addon_utils.modules()
229             output.write(title("Enabled add-ons"))
230             for addon in bpy.context.user_preferences.addons.keys():
231                 addon_mod = addon_utils.addons_fake_modules.get(addon, None)
232                 if addon_mod is None:
233                     output.write("%s (MISSING)\n" % (addon))
234                 else:
235                     output.write("%s (version: %s, path: %s)\n" %
236                                  (addon, addon_mod.bl_info.get('version', "UNKNOWN"), addon_mod.__file__))
237         except Exception as e:
238             output.write("ERROR: %s\n" % e)