From 99b92c885f2c33c0fd6d85eaa463e8572dc034a1 Mon Sep 17 00:00:00 2001 From: Yuri Roubinsky Date: Sun, 29 Dec 2019 12:19:10 +0300 Subject: [PATCH] Support for hex numbers in shaders --- servers/visual/shader_language.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index 1aceb8dcd8d..29a20b86f1b 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -571,8 +571,10 @@ ShaderLanguage::Token ShaderLanguage::_get_token() { CharType last_char = str[str.length() - 1]; if (hexa_found) { - //hex integers eg."0xFF" or "0x12AB", etc - NOT supported yet - return _make_token(TK_ERROR, "Invalid (hexadecimal) numeric constant - Not supported"); + //integer(hex) + if (str.size() > 11 || !str.is_valid_hex_number(true)) { // > 0xFFFFFFFF + return _make_token(TK_ERROR, "Invalid (hexadecimal) numeric constant"); + } } else if (period_found || exponent_found || float_suffix_found) { //floats if (period_found) { @@ -621,7 +623,11 @@ ShaderLanguage::Token ShaderLanguage::_get_token() { else tk.type = TK_INT_CONSTANT; - tk.constant = str.to_double(); //won't work with hex + if (hexa_found) { + tk.constant = (double)str.hex_to_int64(true); + } else { + tk.constant = str.to_double(); + } tk.line = tk_line; return tk;