Skip to content

Instantly share code, notes, and snippets.

Last active May 6, 2023 14:51
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Resolve includes for GLSL, HLSL and metal on Python
import re
from os.path import join, abspath, dirname, basename
def load_source( folder: str, filename: str, dependencies = []):
path = abspath( join(folder, filename) )
if path in dependencies:
return ""
dependencies.append( path )
source = ""
lines = open( path ).readlines()
for line in lines:
if match :='#include\s*["|<](.*.[glsl|hlsl|metal])["|>]' ,line, re.IGNORECASE):
new_folder = join(folder, dirname( ))
new_dep = basename( )
source += load_source(new_folder, new_dep, dependencies)
source += line
return source
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment