瀏覽代碼

Fixed how floats are printed to the GLSL shader, closes #19803

Juan Linietsky 7 年之前
父節點
當前提交
78eae047c6
共有 2 個文件被更改,包括 11 次插入9 次删除
  1. 5 4
      drivers/gles2/shader_compiler_gles2.cpp
  2. 6 5
      drivers/gles3/shader_compiler_gles3.cpp

+ 5 - 4
drivers/gles2/shader_compiler_gles2.cpp

@@ -86,10 +86,11 @@ static String _mkid(const String &p_id) {
 
 static String f2sp0(float p_float) {
 
-	if (int(p_float) == p_float)
-		return itos(p_float) + ".0";
-	else
-		return rtoss(p_float);
+	String num = rtoss(p_float);
+	if (num.find(".") == -1 && num.find("e") == -1) {
+		num += ".0";
+	}
+	return num;
 }
 
 static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNode::Value> &p_values) {

+ 6 - 5
drivers/gles3/shader_compiler_gles3.cpp

@@ -173,10 +173,11 @@ static String _mkid(const String &p_id) {
 
 static String f2sp0(float p_float) {
 
-	if (int(p_float) == p_float)
-		return itos(p_float) + ".0";
-	else
-		return rtoss(p_float);
+	String num = rtoss(p_float);
+	if (num.find(".") == -1 && num.find("e") == -1) {
+		num += ".0";
+	}
+	return num;
 }
 
 static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNode::Value> &p_values) {
@@ -229,7 +230,7 @@ static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNo
 			text += ")";
 			return text;
 		} break;
-		case SL::TYPE_FLOAT: return f2sp0(p_values[0].real) + "f";
+		case SL::TYPE_FLOAT: return f2sp0(p_values[0].real);
 		case SL::TYPE_VEC2:
 		case SL::TYPE_VEC3:
 		case SL::TYPE_VEC4: {