浏览代码

Merge pull request #84197 from bruvzg/opengl_utf8

Parse OpenGL and Vulkan strings as UTF-8.
Rémi Verschelde 1 年之前
父节点
当前提交
dcbee437f7

+ 6 - 6
drivers/gles3/shader_gles3.cpp

@@ -141,12 +141,12 @@ void ShaderGLES3::_setup(const char *p_vertex_code, const char *p_fragment_code,
 	tohash.append(p_fragment_code ? p_fragment_code : "");
 
 	tohash.append("[gl_implementation]");
-	const char *vendor = (const char *)glGetString(GL_VENDOR);
-	tohash.append(vendor ? vendor : "unknown");
-	const char *renderer = (const char *)glGetString(GL_RENDERER);
-	tohash.append(renderer ? renderer : "unknown");
-	const char *version = (const char *)glGetString(GL_VERSION);
-	tohash.append(version ? version : "unknown");
+	const String &vendor = String::utf8((const char *)glGetString(GL_VENDOR));
+	tohash.append(vendor.is_empty() ? "unknown" : vendor);
+	const String &renderer = String::utf8((const char *)glGetString(GL_RENDERER));
+	tohash.append(renderer.is_empty() ? "unknown" : renderer);
+	const String &version = String::utf8((const char *)glGetString(GL_VERSION));
+	tohash.append(version.is_empty() ? "unknown" : version);
 
 	base_sha256 = tohash.as_string().sha256_text();
 }

+ 1 - 1
drivers/gles3/storage/config.cpp

@@ -109,7 +109,7 @@ Config::Config() {
 	if (use_depth_prepass) {
 		String vendors = GLOBAL_GET("rendering/driver/depth_prepass/disable_for_vendors");
 		Vector<String> vendor_match = vendors.split(",");
-		String renderer = (const char *)glGetString(GL_RENDERER);
+		const String &renderer = String::utf8((const char *)glGetString(GL_RENDERER));
 		for (int i = 0; i < vendor_match.size(); i++) {
 			String v = vendor_match[i].strip_edges();
 			if (v == String()) {

+ 3 - 3
drivers/gles3/storage/utilities.cpp

@@ -372,13 +372,13 @@ uint64_t Utilities::get_rendering_info(RS::RenderingInfo p_info) {
 }
 
 String Utilities::get_video_adapter_name() const {
-	const String rendering_device_name = (const char *)glGetString(GL_RENDERER);
+	const String rendering_device_name = String::utf8((const char *)glGetString(GL_RENDERER));
 	// NVIDIA suffixes all GPU model names with "/PCIe/SSE2" in OpenGL (but not Vulkan). This isn't necessary to display nowadays, so it can be trimmed.
 	return rendering_device_name.trim_suffix("/PCIe/SSE2");
 }
 
 String Utilities::get_video_adapter_vendor() const {
-	const String rendering_device_vendor = (const char *)glGetString(GL_VENDOR);
+	const String rendering_device_vendor = String::utf8((const char *)glGetString(GL_VENDOR));
 	// NVIDIA suffixes its vendor name with " Corporation". This is neither necessary to process nor display.
 	return rendering_device_vendor.trim_suffix(" Corporation");
 }
@@ -388,7 +388,7 @@ RenderingDevice::DeviceType Utilities::get_video_adapter_type() const {
 }
 
 String Utilities::get_video_adapter_api_version() const {
-	return (const char *)glGetString(GL_VERSION);
+	return String::utf8((const char *)glGetString(GL_VERSION));
 }
 
 Size2i Utilities::get_maximum_viewport_size() const {

+ 8 - 8
drivers/vulkan/vulkan_context.cpp

@@ -448,7 +448,7 @@ Error VulkanContext::_initialize_instance_extensions() {
 	}
 #ifdef DEV_ENABLED
 	for (uint32_t i = 0; i < instance_extension_count; i++) {
-		print_verbose(String("VULKAN: Found instance extension ") + String(instance_extensions[i].extensionName));
+		print_verbose(String("VULKAN: Found instance extension ") + String::utf8(instance_extensions[i].extensionName));
 	}
 #endif
 
@@ -465,9 +465,9 @@ Error VulkanContext::_initialize_instance_extensions() {
 		if (!enabled_instance_extension_names.has(requested_extension.key)) {
 			if (requested_extension.value) {
 				free(instance_extensions);
-				ERR_FAIL_V_MSG(ERR_BUG, String("Required extension ") + String(requested_extension.key) + String(" not found, is a driver installed?"));
+				ERR_FAIL_V_MSG(ERR_BUG, String("Required extension ") + String::utf8(requested_extension.key) + String(" not found, is a driver installed?"));
 			} else {
-				print_verbose(String("Optional extension ") + String(requested_extension.key) + String(" not found"));
+				print_verbose(String("Optional extension ") + String::utf8(requested_extension.key) + String(" not found"));
 			}
 		}
 	}
@@ -546,7 +546,7 @@ Error VulkanContext::_initialize_device_extensions() {
 
 #ifdef DEV_ENABLED
 	for (uint32_t i = 0; i < device_extension_count; i++) {
-		print_verbose(String("VULKAN: Found device extension ") + String(device_extensions[i].extensionName));
+		print_verbose(String("VULKAN: Found device extension ") + String::utf8(device_extensions[i].extensionName));
 	}
 #endif
 
@@ -564,9 +564,9 @@ Error VulkanContext::_initialize_device_extensions() {
 			if (requested_extension.value) {
 				free(device_extensions);
 				ERR_FAIL_V_MSG(ERR_BUG,
-						String("vkEnumerateDeviceExtensionProperties failed to find the ") + String(requested_extension.key) + String(" extension.\n\nDo you have a compatible Vulkan installable client driver (ICD) installed?\nvkCreateInstance Failure"));
+						String("vkEnumerateDeviceExtensionProperties failed to find the ") + String::utf8(requested_extension.key) + String(" extension.\n\nDo you have a compatible Vulkan installable client driver (ICD) installed?\nvkCreateInstance Failure"));
 			} else {
-				print_verbose(String("Optional extension ") + String(requested_extension.key) + String(" not found"));
+				print_verbose(String("Optional extension ") + String::utf8(requested_extension.key) + String(" not found"));
 			}
 		}
 	}
@@ -1248,7 +1248,7 @@ Error VulkanContext::_create_physical_device(VkSurfaceKHR p_surface) {
 					}
 				}
 			}
-			String name = props.deviceName;
+			String name = String::utf8(props.deviceName);
 			String vendor = "Unknown";
 			String dev_type;
 			switch (props.deviceType) {
@@ -1330,7 +1330,7 @@ Error VulkanContext::_create_physical_device(VkSurfaceKHR p_surface) {
 	// Get identifier properties.
 	vkGetPhysicalDeviceProperties(gpu, &gpu_props);
 
-	device_name = gpu_props.deviceName;
+	device_name = String::utf8(gpu_props.deviceName);
 	device_type = gpu_props.deviceType;
 	pipeline_cache_id = String::hex_encode_buffer(gpu_props.pipelineCacheUUID, VK_UUID_SIZE);
 	pipeline_cache_id += "-driver-" + itos(gpu_props.driverVersion);