Add header builders script for env.GLSL_HEADER
and SVG icons
#1789
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sometimes it is desired to have non-C++ files compiled into C++ code and available for use there. For example, you may want GLSL files available as Strings to be used at runtime. For example, you may want SVG files available as Strings to allow generating multiple sizes at runtime (important for the editor to be able to display things at any scale).
Each of these functionalities is already available when using a Godot engine module:
glsl_builders.py
to generate these. This is exposed withenv.GLSL_HEADER
, meaning you call into it in a SConscript or SCsub likeenv.GLSL_HEADER("path/to/some_file.glsl")
and it will generate a filesome_file.glsl.gen.h
withinline constexpr const char *some_file_shader_glsl = ...
in it.[icons]
in the.gdextension
file provides icons for classes. This fulfills the most common use case, however...This PR adds a new file to the
tools
folder calledheader_builders.py
which mimics the basic functionality of Godot's functions for GLSL header builders and SVG icon header builders. The GLSL header is used exactly like it is in the engine, withenv.GLSL_HEADER("path/to/some_file.glsl")
. This is registered ingodotcpp.py
with"GLSL_HEADER": Builder(
.As for the SVG icon builders, the engine does not provide an API for modules because it's supposed to be handled automatically, and so the function isn't needed in modules. Therefore, if the user needs non-class resizable SVG icons at runtime, calling into this function can be left as a godot-cpp-specific part of a user's buildsystem code, like this:
Note that the code in this PR cannot simply be an exact copy of the engine functions. Those functions have many dependencies on other functions which are not necessary in GDExtension, such as the code to generate the copyright headers. The code in this PR is a lot simpler. Also, the code in this PR is much more generalized. The GLSL code in Godot is hard-coded for GLSL, but the function in this PR can be used for non-GLSL as well. As for the SVG icons, the code in the engine is duplicated for editor icons and default theme icons, and each is hard-coded for each of those, while the code in this PR will work with any destination file.
The motivation behind this PR is the needs of the Godot 4D module/extension, but this benefits all extensions.