diff --git a/Makefile b/Makefile index 941aec8..24bd7b5 100644 --- a/Makefile +++ b/Makefile @@ -86,7 +86,7 @@ uv-run-sample-%: .venv ## uv run (project) sample/(xxx) --sets sample/$*_sets.csv \ --sentences-input sample/$*_sentences.txt \ --functions \ - --forge-include \ + --includes \ .PHONY: ruff ruff: .venv ## ruff check diff --git a/README.md b/README.md index 6529084..841e485 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ ```txt usage: glsl-glyphs [-h] [-i INPUT_FILE] [-n NAME] [-o OUTPUT_FILE] [-g NAMES_FILE] [-s SETS_FILE] [-f | --functions | --no-functions] [--sentences-input SENTENCES_FILE] [--sentences-output OUTPUT_FILE] [--sentences-only | --no-sentences-only] - [-v | --verbose | --no-verbose] [-q | --quiet | --no-quiet] + [--includes | --no-includes] [-v | --verbose | --no-verbose] [-q | --quiet | --no-quiet] options: -h, --help show this help message and exit @@ -29,6 +29,8 @@ options: output sentences glsl file (default: build/{name}_sentences.glsl) --sentences-only, --no-sentences-only generate only sentences from names (does not read input image) + --includes, --no-includes + use #include preprocessor in GLSL (forge) -v, --verbose, --no-verbose more verbose logging -q, --quiet, --no-quiet diff --git a/src/glsl_glyphs/generator.py b/src/glsl_glyphs/generator.py index a593540..69e1697 100644 --- a/src/glsl_glyphs/generator.py +++ b/src/glsl_glyphs/generator.py @@ -27,13 +27,14 @@ class Generator: self.target_path = pathlib.Path("build") / f"{params.target_name}.glsl" else: self.target_path = pathlib.Path(params.target_path) - self.with_functions = params.functions if params.target_sentences_path is None: self.target_sentences_path = ( pathlib.Path("build") / f"{params.target_name}_sentences.glsl" ) else: self.target_sentences_path = pathlib.Path(params.target_sentences_path) + self.with_includes = params.includes + self.with_functions = params.functions self.log = logging.getLogger(__name__) def generate_glsl_glyphs(self, glyphs: list[Glyph], sets: list[GlyphSet]) -> None: @@ -75,7 +76,15 @@ class Generator: sys.exit(1) def generate_glsl_sentences(self, sentences: list[Sentence]) -> None: - lines = [ + lines = [] + + if self.with_includes and self.with_functions: + lines += [ + f"#include {self.target_path.name}", + "" + ] + + lines += [ GLSL_SENTENCES_PREFIX.format(self.target_name.upper()), "", *Sentence.export_glsl(self.target_name, sentences), diff --git a/src/glsl_glyphs/params.py b/src/glsl_glyphs/params.py index 7246af6..8c59be6 100644 --- a/src/glsl_glyphs/params.py +++ b/src/glsl_glyphs/params.py @@ -15,6 +15,7 @@ class Parameters: functions: bool = False source_sentences_path: str | None = None target_sentences_path: str | None = None + includes: bool = False sentences_only: bool = False verbose: bool = False quiet: bool = False @@ -91,6 +92,12 @@ def parse_parameters(args: typing.Sequence[str]) -> Parameters: default=default_values.verbose, help="generate only sentences from names (does not read input image)", ) + parser.add_argument( + "--includes", + action=argparse.BooleanOptionalAction, + default=default_values.verbose, + help="use #include preprocessor in GLSL (forge)", + ) parser.add_argument( "-v", "--verbose",