-
Notifications
You must be signed in to change notification settings - Fork 1
/
shader-compile.py
97 lines (70 loc) · 2.02 KB
/
shader-compile.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
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
import os
import re
import time
import tkinter.messagebox as tkbox
import tkinter as tk
compiler_path = 'Path to glslc'
with open('./glslcPath.txt', 'r') as f:
exec('compiler_path = ' + f.read())
flags = [
'-V',
'-I' + './shaderLib/'
]
folders = [
'./defaultVS/',
'./shaders/'
]
lastCompile = {}
template = './shaderLib/fragTemplate.stp'
tmp_file = './build-shader/.tmp.frag'
if not os.path.exists(tmp_file[:tmp_file.rfind('/')]):
os.mkdir(tmp_file[:tmp_file.rfind('/')])
def compile_it(path: f):
global compiler_path
global flags
if re.match('.*\\.spv$', path):
print('Skip binary file: {}\n'.format(path))
return
global lastCompile
if re.match('.*\\.glsl$', path):
print('Skip but mark include file: {}', format(path))
lastCompile[path] = os.path.getmtime(path)
return
output = path[:path.rfind('.')]
print('compile file: {}'.format(path))
command = '{} {} {} -o {}'.format(compiler_path, ' '.join(flags), path, output + '.spv')
print('run: ' + command)
lastCompile[path] = os.path.getmtime(path)
result = os.system(command)
if result != 0:
print('Failed to compile...')
top = tk.Tk()
top.attributes('-topmost', 1)
top.geometry('0x0+1000000+10000')
tkbox.showerror('Multi Stage', 'Shader compile error', )
top.destroy()
print('Done\n')
def compile_folder(dirname):
shader_sources = os.listdir(dirname)
for source in shader_sources:
path = os.path.join(dirname, source)
if os.path.isdir(path):
compile_folder(path)
continue
compile_it(path)
for dirn in folders:
compile_folder(dirn)
t = 60
while True:
time.sleep(1)
hasNew = False
for f in lastCompile:
if os.path.getmtime(f) > lastCompile[f]:
lastCompile[f] = os.path.getmtime(f)
hasNew = True
break
if hasNew or t <= 0:
for dirn in folders:
compile_folder(dirn)
t = 60
t -= 1