You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Adding ability to include build-in include files (precursor to custom shader templates)
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#include "core/version.h"
|
||||
#include "renderer_compositor_rd.h"
|
||||
#include "servers/rendering/rendering_device.h"
|
||||
#include "servers/rendering/shader_include_db.h"
|
||||
#include "thirdparty/misc/smolv.h"
|
||||
|
||||
#define ENABLE_SHADER_CACHE 1
|
||||
@@ -46,7 +47,8 @@ void ShaderRD::_add_stage(const char *p_code, StageType p_stage_type) {
|
||||
|
||||
String text;
|
||||
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
int line_count = lines.size();
|
||||
for (int i = 0; i < line_count; i++) {
|
||||
const String &l = lines[i];
|
||||
bool push_chunk = false;
|
||||
|
||||
@@ -78,6 +80,35 @@ void ShaderRD::_add_stage(const char *p_code, StageType p_stage_type) {
|
||||
chunk.type = StageTemplate::Chunk::TYPE_CODE;
|
||||
push_chunk = true;
|
||||
chunk.code = l.replace_first("#CODE", String()).replace(":", "").strip_edges().to_upper();
|
||||
} else if (l.begins_with("#include ")) {
|
||||
String include_file = l.replace("#include ", "").strip_edges();
|
||||
if (include_file[0] == '"') {
|
||||
int end_pos = include_file.find_char('"', 1);
|
||||
if (end_pos >= 0) {
|
||||
include_file = include_file.substr(1, end_pos - 1);
|
||||
|
||||
String include_code = ShaderIncludeDB::get_built_in_include_file(include_file);
|
||||
if (!include_code.is_empty()) {
|
||||
// Add these lines into our parse list so we parse them as well.
|
||||
Vector<String> include_lines = include_code.split("\n");
|
||||
|
||||
for (int j = include_lines.size() - 1; j >= 0; j--) {
|
||||
lines.insert(i + 1, include_lines[j]);
|
||||
}
|
||||
|
||||
line_count = lines.size();
|
||||
} else {
|
||||
// Add it in as is.
|
||||
text += l + "\n";
|
||||
}
|
||||
} else {
|
||||
// Add it in as is.
|
||||
text += l + "\n";
|
||||
}
|
||||
} else {
|
||||
// Add it in as is.
|
||||
text += l + "\n";
|
||||
}
|
||||
} else {
|
||||
text += l + "\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user