mirror of https://github.com/godotengine/godot
Fix orphan strings in shader preprocessor
This commit is contained in:
parent
9aed9eca40
commit
5a48e527b2
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
#define HAS_WARNING(flag) (warning_flags & flag)
|
#define HAS_WARNING(flag) (warning_flags & flag)
|
||||||
|
|
||||||
int ShaderLanguage::instance_counter = 0;
|
SafeNumeric<int> ShaderLanguage::instance_counter;
|
||||||
|
|
||||||
String ShaderLanguage::get_operator_text(Operator p_op) {
|
String ShaderLanguage::get_operator_text(Operator p_op) {
|
||||||
static const char *op_names[OP_MAX] = { "==",
|
static const char *op_names[OP_MAX] = { "==",
|
||||||
|
|
@ -11597,7 +11597,7 @@ ShaderLanguage::ShaderLanguage() {
|
||||||
nodes = nullptr;
|
nodes = nullptr;
|
||||||
completion_class = TAG_GLOBAL;
|
completion_class = TAG_GLOBAL;
|
||||||
|
|
||||||
if (instance_counter == 0) {
|
if (instance_counter.get() == 0) {
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
while (builtin_func_defs[idx].name) {
|
while (builtin_func_defs[idx].name) {
|
||||||
if (builtin_func_defs[idx].tag == SubClassTag::TAG_GLOBAL) {
|
if (builtin_func_defs[idx].tag == SubClassTag::TAG_GLOBAL) {
|
||||||
|
|
@ -11606,7 +11606,7 @@ ShaderLanguage::ShaderLanguage() {
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
instance_counter++;
|
instance_counter.increment();
|
||||||
|
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
warnings_check_map.insert(ShaderWarning::UNUSED_CONSTANT, &used_constants);
|
warnings_check_map.insert(ShaderWarning::UNUSED_CONSTANT, &used_constants);
|
||||||
|
|
@ -11621,8 +11621,8 @@ ShaderLanguage::ShaderLanguage() {
|
||||||
|
|
||||||
ShaderLanguage::~ShaderLanguage() {
|
ShaderLanguage::~ShaderLanguage() {
|
||||||
clear();
|
clear();
|
||||||
instance_counter--;
|
instance_counter.decrement();
|
||||||
if (instance_counter == 0) {
|
if (instance_counter.get() == 0) {
|
||||||
global_func_set.clear();
|
global_func_set.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@
|
||||||
#include "core/string/ustring.h"
|
#include "core/string/ustring.h"
|
||||||
#include "core/templates/list.h"
|
#include "core/templates/list.h"
|
||||||
#include "core/templates/rb_map.h"
|
#include "core/templates/rb_map.h"
|
||||||
|
#include "core/templates/safe_refcount.h"
|
||||||
#include "core/typedefs.h"
|
#include "core/typedefs.h"
|
||||||
#include "core/variant/variant.h"
|
#include "core/variant/variant.h"
|
||||||
#include "scene/resources/shader_include.h"
|
#include "scene/resources/shader_include.h"
|
||||||
|
|
@ -833,7 +834,7 @@ public:
|
||||||
static bool is_control_flow_keyword(String p_keyword);
|
static bool is_control_flow_keyword(String p_keyword);
|
||||||
static void get_builtin_funcs(List<String> *r_keywords);
|
static void get_builtin_funcs(List<String> *r_keywords);
|
||||||
|
|
||||||
static int instance_counter;
|
static SafeNumeric<int> instance_counter;
|
||||||
|
|
||||||
struct BuiltInInfo {
|
struct BuiltInInfo {
|
||||||
DataType type = TYPE_VOID;
|
DataType type = TYPE_VOID;
|
||||||
|
|
|
||||||
|
|
@ -1236,6 +1236,13 @@ ShaderPreprocessor::Define *ShaderPreprocessor::create_define(const String &p_bo
|
||||||
return define;
|
return define;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShaderPreprocessor::insert_builtin_define(String p_name, String p_value, State &p_state) {
|
||||||
|
Define *define = memnew(Define);
|
||||||
|
define->is_builtin = true;
|
||||||
|
define->body = p_value;
|
||||||
|
p_state.defines[p_name] = define;
|
||||||
|
}
|
||||||
|
|
||||||
void ShaderPreprocessor::clear_state() {
|
void ShaderPreprocessor::clear_state() {
|
||||||
if (state != nullptr) {
|
if (state != nullptr) {
|
||||||
for (const RBMap<String, Define *>::Element *E = state->defines.front(); E; E = E->next()) {
|
for (const RBMap<String, Define *>::Element *E = state->defines.front(); E; E = E->next()) {
|
||||||
|
|
@ -1332,30 +1339,19 @@ Error ShaderPreprocessor::preprocess(const String &p_code, const String &p_filen
|
||||||
|
|
||||||
// Built-in defines.
|
// Built-in defines.
|
||||||
{
|
{
|
||||||
static HashMap<StringName, String> defines;
|
|
||||||
|
|
||||||
if (defines.is_empty()) {
|
|
||||||
const String rendering_method = OS::get_singleton()->get_current_rendering_method();
|
const String rendering_method = OS::get_singleton()->get_current_rendering_method();
|
||||||
|
|
||||||
if (rendering_method == "forward_plus") {
|
if (rendering_method == "forward_plus") {
|
||||||
defines["CURRENT_RENDERER"] = _MKSTR(2);
|
insert_builtin_define("CURRENT_RENDERER", _MKSTR(2), pp_state);
|
||||||
} else if (rendering_method == "mobile") {
|
} else if (rendering_method == "mobile") {
|
||||||
defines["CURRENT_RENDERER"] = _MKSTR(1);
|
insert_builtin_define("CURRENT_RENDERER", _MKSTR(1), pp_state);
|
||||||
} else { // gl_compatibility
|
} else { // gl_compatibility
|
||||||
defines["CURRENT_RENDERER"] = _MKSTR(0);
|
insert_builtin_define("CURRENT_RENDERER", _MKSTR(0), pp_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
defines["RENDERER_COMPATIBILITY"] = _MKSTR(0);
|
insert_builtin_define("RENDERER_COMPATIBILITY", _MKSTR(0), pp_state);
|
||||||
defines["RENDERER_MOBILE"] = _MKSTR(1);
|
insert_builtin_define("RENDERER_MOBILE", _MKSTR(1), pp_state);
|
||||||
defines["RENDERER_FORWARD_PLUS"] = _MKSTR(2);
|
insert_builtin_define("RENDERER_FORWARD_PLUS", _MKSTR(2), pp_state);
|
||||||
}
|
|
||||||
|
|
||||||
for (const KeyValue<StringName, String> &E : defines) {
|
|
||||||
Define *define = memnew(Define);
|
|
||||||
define->is_builtin = true;
|
|
||||||
define->body = E.value;
|
|
||||||
pp_state.defines[E.key] = define;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Error err = preprocess(&pp_state, p_code, r_result);
|
Error err = preprocess(&pp_state, p_code, r_result);
|
||||||
|
|
|
||||||
|
|
@ -215,6 +215,7 @@ private:
|
||||||
void set_error(const String &p_error, int p_line);
|
void set_error(const String &p_error, int p_line);
|
||||||
|
|
||||||
static Define *create_define(const String &p_body);
|
static Define *create_define(const String &p_body);
|
||||||
|
void insert_builtin_define(String p_name, String p_value, State &p_state);
|
||||||
|
|
||||||
void clear_state();
|
void clear_state();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue