forked from valeriog-crytek/glad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·129 lines (101 loc) · 4.04 KB
/
main.py
File metadata and controls
executable file
·129 lines (101 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env python2
'''Uses the offcial Khronos-XML specs to generate a
GL/GLES/EGL/GLX/WGL Loader made for your needs. Glad currently supports
the languages C, D and Volt.'''
from glad.gl import OpenGLSpec
from glad.egl import EGLSpec
from glad.glx import GLXSpec
from glad.wgl import WGLSpec
from glad.generator import get_generator
from glad.loader import NullLoader, get_loader
from collections import namedtuple
SPECS = {
'gl' : OpenGLSpec,
'egl' : EGLSpec,
'glx' : GLXSpec,
'wgl' : WGLSpec
}
Version = namedtuple('Version', ['major', 'minor'])
def main():
import os.path
import argparse
from argparse import ArgumentParser
def get_spec(value):
if not value in SPECS:
raise argparse.ArgumentTypeError('Unknown spec')
Spec = SPECS[value]
if os.path.exists(value + '.xml'):
print 'Using local spec: {}.xml'.format(value)
return Spec.from_file(value + '.xml')
print 'Downloading latest spec from svn...'
return Spec.from_svn()
def ext_file(value):
msg = 'Invalid extensions argument'
if os.path.exists(value):
msg = 'Invalid extensions file'
try:
with open(value, 'r') as f:
return f.read().split()
except:
pass
else:
return [v.strip() for v in value.split(',') if v]
raise argparse.ArgumentTypeError(msg)
def version(value):
if value is None or len(value.strip()) == 0:
return None
if not '.' in value:
value = '{}.0'.format(value)
try:
v = Version(*map(int, value.split('.')))
return v
except Exception, e:
pass
raise argparse.ArgumentTypeError('Invalid version: "{}"'.format(value))
def cmdapi(value):
try:
return dict((p[0], version(p[1])) for p in
(map(str.strip, e.split('=')) for e in
filter(bool, map(str.strip, value.split(',')))))
except Exception:
pass
raise argparse.ArgumentTypeError('Invalid api-string: "{}"'.format(value))
description = __doc__
parser = ArgumentParser(description=description)
parser.add_argument('--profile', dest='profile',
choices=['core', 'compatibility'], default='compatibility',
help='OpenGL profile (defaults to compatibility)')
parser.add_argument('--out-path', dest='out', required=True,
help='Output path for loader')
parser.add_argument('--api', dest='api', type=cmdapi,
help='API type/version pairs, like "gl=3.2,gles=", '
'no version means latest')
parser.add_argument('--generator', dest='generator', default='d',
choices=['c', 'd', 'volt'], help='Language (defaults to d)')
parser.add_argument('--extensions', dest='extensions', default=None,
type=ext_file, help='Path to extensions file or comma '
'separated list of extensions')
parser.add_argument('--spec', dest='spec', default='gl',
choices=['gl', 'egl', 'glx', 'wgl'], help='Name of spec')
parser.add_argument('--no-loader', dest='no_loader', action='store_true')
ns = parser.parse_args()
spec = get_spec(ns.spec)
if spec.NAME == 'gl':
spec.profile = ns.profile
api = ns.api
if api is None or len(api.keys()) == 0:
api = {spec.NAME : None}
try:
loader = get_loader(ns.generator, spec.NAME)
loader.disabled = ns.no_loader
except KeyError:
return parser.error('API/Spec not yet supported')
Generator = get_generator(ns.generator)
print 'Generating {spec} bindings...'.format(spec=spec.NAME)
with Generator(ns.out, spec, api, loader) as generator:
#try:
generator.generate(ns.extensions)
#except Exception, e:
#parser.error(e.message)
if __name__ == '__main__':
main()