summaryrefslogtreecommitdiffstats
path: root/tools/glsl_preproc/templates
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tools/glsl_preproc/templates.py14
-rw-r--r--tools/glsl_preproc/templates/call.c.j219
-rw-r--r--tools/glsl_preproc/templates/function.c.j219
-rw-r--r--tools/glsl_preproc/templates/glsl_block.c.j217
-rw-r--r--tools/glsl_preproc/templates/struct.c.j25
5 files changed, 74 insertions, 0 deletions
diff --git a/tools/glsl_preproc/templates.py b/tools/glsl_preproc/templates.py
new file mode 100644
index 0000000..b3b6c44
--- /dev/null
+++ b/tools/glsl_preproc/templates.py
@@ -0,0 +1,14 @@
+import jinja2
+import os.path
+
+TEMPLATEDIR = os.path.dirname(__file__) + '/templates'
+TEMPLATES = jinja2.Environment(
+ loader = jinja2.FileSystemLoader(searchpath=TEMPLATEDIR),
+ lstrip_blocks = True,
+ trim_blocks = True,
+)
+
+GLSL_BLOCK_TEMPLATE = TEMPLATES.get_template('glsl_block.c.j2')
+FUNCTION_TEMPLATE = TEMPLATES.get_template('function.c.j2')
+CALL_TEMPLATE = TEMPLATES.get_template('call.c.j2')
+STRUCT_TEMPLATE = TEMPLATES.get_template('struct.c.j2')
diff --git a/tools/glsl_preproc/templates/call.c.j2 b/tools/glsl_preproc/templates/call.c.j2
new file mode 100644
index 0000000..61ee6c0
--- /dev/null
+++ b/tools/glsl_preproc/templates/call.c.j2
@@ -0,0 +1,19 @@
+{
+{% if macro.vars %}
+ const {{ macro.render_struct() }} {{ macro.name }}_args = {
+ {% for var in macro.vars %}
+#line {{ var.linenr }}
+ .{{ var.name }} = {{ var.expr }},
+ {% endfor %}
+ };
+#line {{ macro.linenr }}
+{% endif %}
+ size_t {{ macro.name }}_fn(void *, pl_str *, const uint8_t *);
+{% if macro.vars %}
+ pl_str_builder_append(sh->buffers[{{ macro.buf }}], {{ macro.name }}_fn,
+ &{{ macro.name }}_args, sizeof({{ macro.name }}_args));
+{% else %}
+ pl_str_builder_append(sh->buffers[{{ macro.buf }}], {{ macro.name }}_fn, NULL, 0);
+{% endif %}
+}
+
diff --git a/tools/glsl_preproc/templates/function.c.j2 b/tools/glsl_preproc/templates/function.c.j2
new file mode 100644
index 0000000..9216472
--- /dev/null
+++ b/tools/glsl_preproc/templates/function.c.j2
@@ -0,0 +1,19 @@
+
+size_t {{ macro.name }}_fn(void *alloc, pl_str *buf, const uint8_t *ptr);
+size_t {{ macro.name }}_fn(void *alloc, pl_str *buf, const uint8_t *ptr)
+{
+{% if macro.vars %}
+{{ macro.render_struct() }} {{ Var.STRUCT_NAME }};
+memcpy(&{{ Var.STRUCT_NAME }}, ptr, sizeof({{ Var.STRUCT_NAME }}));
+{% endif %}
+
+{% for statement in macro.body %}
+{{ statement.render() }}
+{% endfor %}
+
+{% if macro.vars %}
+return sizeof({{ Var.STRUCT_NAME }});
+{% else %}
+return 0;
+{% endif %}
+}
diff --git a/tools/glsl_preproc/templates/glsl_block.c.j2 b/tools/glsl_preproc/templates/glsl_block.c.j2
new file mode 100644
index 0000000..aa8372d
--- /dev/null
+++ b/tools/glsl_preproc/templates/glsl_block.c.j2
@@ -0,0 +1,17 @@
+#line {{ block.linenr }}
+{% if block.refs %}
+ pl_str_append_asprintf_c(alloc, buf,
+ {% for line in block.lines %}
+ {{ line.fmtstr }}{{ ',' if loop.last }}
+ {% endfor %}
+ {% for ref in block.refs %}
+ {{ ref }}{{ ',' if not loop.last }}
+ {% endfor %}
+ );
+{% else %}
+ pl_str_append(alloc, buf, pl_str0(
+ {% for line in block.lines %}
+ {{ line.rawstr }}
+ {% endfor %}
+ ));
+{% endif %}
diff --git a/tools/glsl_preproc/templates/struct.c.j2 b/tools/glsl_preproc/templates/struct.c.j2
new file mode 100644
index 0000000..6a6a8fb
--- /dev/null
+++ b/tools/glsl_preproc/templates/struct.c.j2
@@ -0,0 +1,5 @@
+struct __attribute__((__packed__)) {
+{% for var in macro.vars %}
+ {{ var.ctype }} {{ var.name }};
+{% endfor %}
+}