Made iwa compile as an S++ library.

This commit is contained in:
2024-04-12 21:07:53 +02:00
parent 1d44ecc0ee
commit ddb4f67735
5 changed files with 49 additions and 6 deletions

12
data/config/iwa_enums.yml Normal file
View File

@@ -0,0 +1,12 @@
# Data source for enums that are shared between CPP and GLSL
vertex_input_semantic:
cpp_type_name: VertexAttributeSemantic
glsl_prefix: IWA_VAS_
entries:
CUSTOM: 0
POSITION: 1
NORMAL: 2
TANGENT: 3
BITANGENT: 4
TEXCOORDS: 5
COLOR: 6

View File

@@ -0,0 +1,26 @@
{%- set enum_config = 'iwa_enums' | load_config -%}
{% macro cpp_enum(name) -%}
enum class {{ enum_config[name].cpp_type_name }}
{
{%- for key, value in enum_config[name].entries.items(): %}
{{ key }} = {{ value }},
{%- endfor %}
};
inline mijin::Optional<{{ enum_config[name].cpp_type_name }}> {{ enum_config[name].cpp_type_name[0] | lower }}{{ enum_config[name].cpp_type_name[1:] }}FromString(std::string_view name)
{
{%- for key in enum_config[name].entries.keys(): %}
if (name == "{{ key | lower }}") {
return {{ enum_config[name].cpp_type_name }}::{{ key }};
}
{%- endfor %}
return mijin::NULL_OPTIONAL;
}
{%- endmacro %}
{% macro glsl_enum(name) -%}
{%- for key, value in enum_config[name].entries.items(): -%}
const int {{ enum_config[name].glsl_prefix }}{{ key }} = {{ value }};
{% endfor -%}
{%- endmacro %}