-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathSokolShader.py
62 lines (58 loc) · 2.29 KB
/
SokolShader.py
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
#-------------------------------------------------------------------------------
# SokolShader.py
#
# Fips code-generator script for invoking sokol-shdc during the build.
#
# Use the cmake macro 'sokol_shader([glsl-file] [shader-dialects])' inside a
# fips target (fips_begin_* / fips_end_*) to hook the code-generation
# build job into the build process.
#-------------------------------------------------------------------------------
Version = 5
import os, platform, subprocess
import genutil as util
from mod import log
#-------------------------------------------------------------------------------
def find_shdc():
shdc_path = os.path.dirname(os.path.abspath(__file__))
shdc_path += '/../../bin/'
if platform.system() == 'Windows':
shdc_path += 'win32/'
elif platform.system() == 'Darwin':
if platform.machine() == 'arm64':
shdc_path += 'osx_arm64/'
else:
shdc_path += 'osx/'
elif platform.system() == 'Linux':
if os.uname()[1] == 'raspberrypi':
shdc_path += 'raspi/'
else:
shdc_path += 'linux/'
else:
log.error('Unknown host system {}'.format(platform.system()))
return shdc_path + 'sokol-shdc'
#-------------------------------------------------------------------------------
def generate(input, out_src, out_hdr, args):
errfmt = 'msvc' if args['compiler']=='MSVC' else 'gcc'
if util.isDirty(Version, [input], [out_hdr]):
print('## sokol-shdc: {} {} {}'.format(input, out_hdr, str(args)))
cmd = [find_shdc(),
'--input', input,
'--output', out_hdr,
'--slang', args['slang'],
'--genver', str(Version),
'--errfmt', errfmt,
'--format', 'sokol']
if 'defines' in args:
cmd.extend(['--defines', args['defines']])
if 'module' in args:
cmd.extend(['--module', args['module']])
if 'reflection' in args:
if args['reflection']:
cmd.extend(['--reflection'])
if 'debuggable' in args and args['debuggable']:
pass
else:
cmd.extend(['--bytecode'])
res = subprocess.call(cmd)
if res != 0:
log.error('sokol-shdc returned with error code {}'.format(res))