#!/usr/bin/python3 # # Copyright 2013 Ilia Mirkin. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. import sys import json import subprocess __author__ = "Ilia Mirkin " class GLInfo(object): def __init__(self, lines): self.profile = "compat" if "core profile" in lines[0]: self.profile = "core" if "ES profile" in lines[0]: self.profile = "es" for i, line in enumerate(lines): if "language version" in line: self.glsl = line.split(":")[-1].strip() elif "version" in line: version = line.split(":")[-1].strip() if " " in version: version, tail = version.split(" ", 1) if tail.startswith("("): tail = tail.split(")", 1)[-1] self.library = tail.strip() self.gl = version elif "extensions" in line: break else: assert False, "Extension list not found" self.extensions = [] self.limits = {} for i in range(i + 1, len(lines)): line = lines[i] if not line: continue if line.startswith(" "): line = line.strip() if line: self.extensions.append(line) elif "limits" in line: break else: assert False, "Unknown line in extension list: %r" % line else: if self.profile != "es": assert False, "Limit list not found" else: return for i in range(i + 1, len(lines)): line = lines[i] if not line: continue if not line.startswith(" "): assert False, "Unknown line in limit list" if " = " not in line: continue name, value = line.split(" = ", 1) self.limits[name.strip()] = value.strip() if len(sys.argv) > 1: glxinfo = open(sys.argv[1], "rb").read() else: glxinfo = subprocess.check_output(["glxinfo", "-l", "-s"]) infos = [] lines = [] vendor = None renderer = None for line in glxinfo.splitlines(): line = line.decode("utf-8") if line.startswith("OpenGL vendor"): vendor = line.split(":")[-1].strip() continue if line.startswith("OpenGL renderer"): renderer = line.split(":")[-1].strip() continue # We hit the GLX visuals list. No more. if "GLX Visuals" in line: infos.append(GLInfo(lines)) break if "OpenGL" in line: # The first version string line if not lines and "version string" in line: lines.append(line) continue # A new version string line. Must be the start of the compat profile elif "version string" in line and "shading" not in line: infos.append(GLInfo(lines)) lines = [line] continue # Another line after the version string if lines: lines.append(line) print("register({0}, {1}, {2})".format( json.dumps(vendor), json.dumps(renderer), json.dumps(infos, default=lambda x: x.__dict__, indent=4, sort_keys=True)))