Include SDL information in system info text.
[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 import bpy
24 import bgl
25
26 import sys
27
28
29 def cutPoint(text, length):
30     """Returns position of the last space found before 'length' chars"""
31     l = length
32     c = text[l]
33     while c != ' ':
34         l -= 1
35         if l == 0:
36             return length  # no space found
37         c = text[l]
38     return l
39
40
41 def textWrap(text, length=70):
42     lines = []
43     while len(text) > 70:
44         cpt = cutPoint(text, length)
45         line, text = text[:cpt], text[cpt + 1:]
46         lines.append(line)
47     lines.append(text)
48     return lines
49
50
51 def write_sysinfo(op):
52     output_filename = "system-info.txt"
53
54     output = bpy.data.texts.get(output_filename)
55     if output:
56         output.clear()
57     else:
58         output = bpy.data.texts.new(name=output_filename)
59
60     header = "= Blender %s System Information =\n" % bpy.app.version_string
61     lilies = "%s\n\n" % (len(header) * "=")
62     firstlilies = "%s\n" % (len(header) * "=")
63     output.write(firstlilies)
64     output.write(header)
65     output.write(lilies)
66
67     # build info
68     output.write("\nBlender:\n")
69     output.write(lilies)
70     if bpy.app.build_branch and bpy.app.build_branch != "Unknown":
71         output.write("version %s, branch %r, commit date %r %r, hash %r, %r\n" %
72             (bpy.app.version_string,
73              bpy.app.build_branch,
74              bpy.app.build_commit_date,
75              bpy.app.build_commit_time,
76              bpy.app.build_hash,
77              bpy.app.build_type))
78     else:
79         output.write("version %s, revision %r. %r\n" %
80             (bpy.app.version_string,
81              bpy.app.build_change,
82              bpy.app.build_type))
83
84     output.write("build date: %r, %r\n" % (bpy.app.build_date, bpy.app.build_time))
85     output.write("platform: %r\n" % (bpy.app.build_platform))
86     output.write("binary path: %r\n" % (bpy.app.binary_path))
87     output.write("build cflags: %r\n" % (bpy.app.build_cflags))
88     output.write("build cxxflags: %r\n" % (bpy.app.build_cxxflags))
89     output.write("build linkflags: %r\n" % (bpy.app.build_linkflags))
90     output.write("build system: %r\n" % (bpy.app.build_system))
91
92     # python info
93     output.write("\nPython:\n")
94     output.write(lilies)
95     output.write("version: %s\n" % (sys.version))
96     output.write("paths:\n")
97     for p in sys.path:
98         output.write("\t%r\n" % (p))
99
100     output.write("\nDirectories:\n")
101     output.write(lilies)
102     output.write("scripts: %r\n" % (bpy.utils.script_paths()))
103     output.write("user scripts: %r\n" % (bpy.utils.script_path_user()))
104     output.write("pref scripts: %r\n" % (bpy.utils.script_path_pref()))
105     output.write("datafiles: %r\n" % (bpy.utils.user_resource('DATAFILES')))
106     output.write("config: %r\n" % (bpy.utils.user_resource('CONFIG')))
107     output.write("scripts : %r\n" % (bpy.utils.user_resource('SCRIPTS')))
108     output.write("autosave: %r\n" % (bpy.utils.user_resource('AUTOSAVE')))
109     output.write("tempdir: %r\n" % (bpy.app.tempdir))
110
111     output.write("\nFFmpeg:\n")
112     output.write(lilies)
113     ffmpeg = bpy.app.ffmpeg
114     if ffmpeg.supported:
115         for lib in ("avcodec", "avdevice", "avformat", "avutil", "swscale"):
116             output.write("%r:%r%r\n" % (lib, " " * (10 - len(lib)),
117                          getattr(ffmpeg, lib + "_version_string")))
118     else:
119         output.write("Blender was built without FFmpeg support\n")
120
121     if bpy.app.build_options.sdl:
122         output.write("\nSDL\n")
123         output.write(lilies)
124         output.write("Version: %s\n" % bpy.app.sdl.version_string)
125         output.write("Loading method: ")
126         if bpy.app.build_options.sdl_dynload:
127             output.write("dynamically loaded by Blender (WITH_SDL_DYNLOAD=ON)\n")
128         else:
129             output.write("linked (WITH_SDL_DYNLOAD=OFF)\n")
130         if not bpy.app.sdl.available:
131             output.write("WARNING: Blender could not load SDL library\n")
132
133     output.write("\nOther Libraries:\n")
134     output.write(lilies)
135     ocio = bpy.app.ocio
136     output.write("OpenColorIO: ")
137     if ocio.supported:
138         if ocio.version_string == "fallback":
139             output.write("Blender was built with OpenColorIO, " +
140                          "but it currently uses fallback color management.\n")
141         else:
142             output.write("%s\n" % (ocio.version_string))
143     else:
144         output.write("Blender was built without OpenColorIO support\n")
145
146     oiio = bpy.app.oiio
147     output.write("OpenImageIO: ")
148     if ocio.supported:
149         output.write("%s\n" % (oiio.version_string))
150     else:
151         output.write("Blender was built without OpenImageIO support\n")
152
153     output.write("OpenShadingLanguage: ")
154     if bpy.app.build_options.cycles:
155         if bpy.app.build_options.cycles_osl:
156             from _cycles import osl_version_string
157             output.write("%s\n" % (osl_version_string))
158         else:
159             output.write("Blender was built without OpenShadingLanguage support in Cycles\n")
160     else:
161         output.write("Blender was built without Cycles support\n")
162
163     if not bpy.app.build_options.sdl:
164         output.write("SDL: Blender was built without SDL support\n")
165
166     if bpy.app.background:
167         output.write("\nOpenGL: missing, background mode\n")
168     else:
169         output.write("\nOpenGL\n")
170         output.write(lilies)
171         version = bgl.glGetString(bgl.GL_RENDERER)
172         output.write("renderer:\t%r\n" % version)
173         output.write("vendor:\t\t%r\n" % (bgl.glGetString(bgl.GL_VENDOR)))
174         output.write("version:\t%r\n" % (bgl.glGetString(bgl.GL_VERSION)))
175         output.write("extensions:\n")
176
177         glext = bgl.glGetString(bgl.GL_EXTENSIONS)
178         glext = textWrap(glext, 70)
179         for l in glext:
180             output.write("\t\t%r\n" % (l))
181
182         output.write("\nImplementation Dependent OpenGL Limits:\n")
183         output.write(lilies)
184         limit = bgl.Buffer(bgl.GL_INT, 1)
185         bgl.glGetIntegerv(bgl.GL_MAX_TEXTURE_UNITS, limit)
186         output.write("Maximum Fixed Function Texture Units:\t%d\n" % limit[0])
187
188         output.write("\nGLSL:\n")
189         if version[0] > '1':
190             bgl.glGetIntegerv(bgl.GL_MAX_VARYING_FLOATS, limit)
191             output.write("Maximum Varying Floats:\t%d\n" % limit[0])
192             bgl.glGetIntegerv(bgl.GL_MAX_VERTEX_ATTRIBS, limit)
193             output.write("Maximum Vertex Attributes:\t%d\n" % limit[0])
194             bgl.glGetIntegerv(bgl.GL_MAX_VERTEX_UNIFORM_COMPONENTS, limit)
195             output.write("Maximum Vertex Uniform Components:\t%d\n" % limit[0])
196             bgl.glGetIntegerv(bgl.GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, limit)
197             output.write("Maximum Fragment Uniform Components:\t%d\n" % limit[0])
198             bgl.glGetIntegerv(bgl.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, limit)
199             output.write("Maximum Vertex Image Units:\t%d\n" % limit[0])
200             bgl.glGetIntegerv(bgl.GL_MAX_TEXTURE_IMAGE_UNITS, limit)
201             output.write("Maximum Fragment Image Units:\t%d\n" % limit[0])
202             bgl.glGetIntegerv(bgl.GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, limit)
203             output.write("Maximum Pipeline Image Units:\t%d\n" % limit[0])
204
205     if bpy.app.build_options.cycles:
206         import cycles
207         output.write("\nCycles\n")
208         output.write(lilies)
209         output.write(cycles.engine.system_info())
210
211     output.current_line_index = 0
212
213     op.report({'INFO'}, "System information generated in 'system-info.txt'")