feat: forge #include in sentences glsl

This commit is contained in:
2026-11-08 00:26:05 +01:00
parent 4781a1b34f
commit 37b35353e6
4 changed files with 22 additions and 4 deletions
+1 -1
View File
@@ -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
+3 -1
View File
@@ -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
+11 -2
View File
@@ -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),
+7
View File
@@ -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",