Prechádzať zdrojové kódy

Redirect all print-like calls to our built-in logger

Michael Ragazzon 1 rok pred
rodič
commit
5a27590067

+ 5 - 4
Backends/RmlUi_Backend_GLFW_VK.cpp

@@ -26,14 +26,15 @@
  *
  */
 
-#include "RmlUi/Config/Config.h"
 #include "RmlUi_Backend.h"
 #include "RmlUi_Renderer_VK.h"
 // This space is intentional to prevent autoformat from reordering RmlUi_Renderer_VK behind RmlUi_Platform_GLFW
 #include "RmlUi_Platform_GLFW.h"
+#include <RmlUi/Config/Config.h>
 #include <RmlUi/Core/Context.h>
 #include <RmlUi/Core/Core.h>
 #include <RmlUi/Core/FileInterface.h>
+#include <RmlUi/Core/Log.h>
 #include <GLFW/glfw3.h>
 #include <stdint.h>
 #include <thread>
@@ -84,7 +85,7 @@ bool Backend::Initialize(const char* window_name, int width, int height, bool al
 
 	if (!window)
 	{
-		fprintf(stderr, "[GLFW] error can't create window!");
+		Rml::Log::Message(Rml::Log::LT_ERROR, "GLFW failed to create window");
 		return false;
 	}
 
@@ -93,7 +94,7 @@ bool Backend::Initialize(const char* window_name, int width, int height, bool al
 
 	uint32_t count;
 	const char** extensions = glfwGetRequiredInstanceExtensions(&count);
-	RMLUI_VK_ASSERTMSG(extensions != nullptr, "Failed to query glfw vulkan extensions");
+	RMLUI_VK_ASSERTMSG(extensions != nullptr, "Failed to query GLFW Vulkan extensions");
 	if (!data->render_interface.Initialize(Rml::Vector<const char*>(extensions, extensions + count),
 			[](VkInstance instance, VkSurfaceKHR* out_surface) {
 				return glfwCreateWindowSurface(instance, data->window, nullptr, out_surface) == VkResult::VK_SUCCESS;
@@ -101,7 +102,7 @@ bool Backend::Initialize(const char* window_name, int width, int height, bool al
 			}))
 	{
 		data.reset();
-		fprintf(stderr, "Could not initialize Vulkan render interface.");
+		Rml::Log::Message(Rml::Log::LT_ERROR, "Failed to initialize Vulkan render interface");
 		return false;
 	}
 

+ 3 - 2
Backends/RmlUi_Backend_SDL_GL2.cpp

@@ -32,6 +32,7 @@
 #include <RmlUi/Core/Context.h>
 #include <RmlUi/Core/Core.h>
 #include <RmlUi/Core/FileInterface.h>
+#include <RmlUi/Core/Log.h>
 #include <GL/glew.h>
 #include <SDL.h>
 #include <SDL_image.h>
@@ -195,7 +196,7 @@ bool Backend::Initialize(const char* window_name, int width, int height, bool al
 		window = SDL_CreateWindow(window_name, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, window_flags);
 		if (!window)
 		{
-			fprintf(stderr, "SDL error on create window: %s\n", SDL_GetError());
+			Rml::Log::Message(Rml::Log::LT_ERROR, "SDL error on create window: %s", SDL_GetError());
 			return false;
 		}
 	}
@@ -220,7 +221,7 @@ bool Backend::Initialize(const char* window_name, int width, int height, bool al
 	GLenum err = glewInit();
 	if (err != GLEW_OK)
 	{
-		fprintf(stderr, "GLEW error: %s\n", glewGetErrorString(err));
+		Rml::Log::Message(Rml::Log::LT_ERROR, "GLEW error: %s", glewGetErrorString(err));
 		return false;
 	}
 

+ 4 - 3
Backends/RmlUi_Backend_SDL_GL3.cpp

@@ -32,6 +32,7 @@
 #include <RmlUi/Core/Context.h>
 #include <RmlUi/Core/Core.h>
 #include <RmlUi/Core/FileInterface.h>
+#include <RmlUi/Core/Log.h>
 #include <SDL.h>
 #include <SDL_image.h>
 
@@ -154,7 +155,7 @@ bool Backend::Initialize(const char* window_name, int width, int height, bool al
 	SDL_Window* window = SDL_CreateWindow(window_name, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, window_flags);
 	if (!window)
 	{
-		fprintf(stderr, "SDL error on create window: %s\n", SDL_GetError());
+		Rml::Log::Message(Rml::Log::LT_ERROR, "SDL error on create window: %s", SDL_GetError());
 		return false;
 	}
 
@@ -164,7 +165,7 @@ bool Backend::Initialize(const char* window_name, int width, int height, bool al
 
 	if (!RmlGL3::Initialize())
 	{
-		fprintf(stderr, "Could not initialize OpenGL");
+		Rml::Log::Message(Rml::Log::LT_ERROR, "Failed to initialize OpenGL renderer");
 		return false;
 	}
 
@@ -173,7 +174,7 @@ bool Backend::Initialize(const char* window_name, int width, int height, bool al
 	if (!data->render_interface)
 	{
 		data.reset();
-		fprintf(stderr, "Could not initialize OpenGL3 render interface.");
+		Rml::Log::Message(Rml::Log::LT_ERROR, "Failed to initialize OpenGL3 render interface");
 		return false;
 	}
 

+ 5 - 4
Backends/RmlUi_Backend_SDL_VK.cpp

@@ -32,6 +32,7 @@
 #include <RmlUi/Core/Context.h>
 #include <RmlUi/Core/Core.h>
 #include <RmlUi/Core/FileInterface.h>
+#include <RmlUi/Core/Log.h>
 #include <SDL2/SDL.h>
 #include <SDL2/SDL_vulkan.h>
 
@@ -69,7 +70,7 @@ bool Backend::Initialize(const char* window_name, int width, int height, bool al
 	SDL_Window* window = SDL_CreateWindow(window_name, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, window_flags);
 	if (!window)
 	{
-		fprintf(stderr, "SDL error on create window: %s\n", SDL_GetError());
+		Rml::Log::Message(Rml::Log::LT_ERROR, "SDL error on create window: %s", SDL_GetError());
 		return false;
 	}
 
@@ -82,14 +83,14 @@ bool Backend::Initialize(const char* window_name, int width, int height, bool al
 		if (!SDL_Vulkan_GetInstanceExtensions(window, &count, nullptr))
 		{
 			data.reset();
-			fprintf(stderr, "Could not get required vulkan extensions");
+			Rml::Log::Message(Rml::Log::LT_ERROR, "Failed to get required vulkan extensions");
 			return false;
 		}
 		extensions.resize(count);
 		if (!SDL_Vulkan_GetInstanceExtensions(window, &count, extensions.data()))
 		{
 			data.reset();
-			fprintf(stderr, "Could not get required vulkan extensions");
+			Rml::Log::Message(Rml::Log::LT_ERROR, "Failed to get required vulkan extensions");
 			return false;
 		}
 	}
@@ -98,7 +99,7 @@ bool Backend::Initialize(const char* window_name, int width, int height, bool al
 			[](VkInstance instance, VkSurfaceKHR* out_surface) { return (bool)SDL_Vulkan_CreateSurface(data->window, instance, out_surface); }))
 	{
 		data.reset();
-		fprintf(stderr, "Could not initialize Vulkan render interface.");
+		Rml::Log::Message(Rml::Log::LT_ERROR, "Failed to initialize Vulkan render interface");
 		return false;
 	}
 

+ 8 - 12
Backends/RmlUi_Backend_Win32_GL2.cpp

@@ -33,6 +33,7 @@
 #include <RmlUi/Core/Context.h>
 #include <RmlUi/Core/Core.h>
 #include <RmlUi/Core/Input.h>
+#include <RmlUi/Core/Log.h>
 #include <RmlUi/Core/Profiling.h>
 
 /**
@@ -91,11 +92,6 @@ static float GetDensityIndependentPixelRatio(HWND window_handle)
 	return float(GetWindowDpi(window_handle)) / float(USER_DEFAULT_SCREEN_DPI);
 }
 
-static void DisplayError(HWND window_handle, const Rml::String& msg)
-{
-	MessageBoxW(window_handle, RmlWin32::ConvertToUTF16(msg).c_str(), L"Backend Error", MB_OK);
-}
-
 // Create the window but don't show it yet. Returns the pixel size of the window, which may be different than the passed size due to DPI settings.
 static HWND InitializeWindow(HINSTANCE instance_handle, const std::wstring& name, int& inout_width, int& inout_height, bool allow_resize);
 // Attach the OpenGL context.
@@ -349,7 +345,7 @@ static HWND InitializeWindow(HINSTANCE instance_handle, const std::wstring& name
 
 	if (!RegisterClassW(&window_class))
 	{
-		DisplayError(NULL, "Could not register window class.");
+		Rml::Log::Message(Rml::Log::LT_ERROR, "Failed to register window class");
 		return nullptr;
 	}
 
@@ -361,7 +357,7 @@ static HWND InitializeWindow(HINSTANCE instance_handle, const std::wstring& name
 
 	if (!window_handle)
 	{
-		DisplayError(NULL, "Could not create window.");
+		Rml::Log::Message(Rml::Log::LT_ERROR, "Failed to create window");
 		return nullptr;
 	}
 
@@ -398,7 +394,7 @@ static bool AttachToNative(HWND window_handle, HDC& out_device_context, HGLRC& o
 
 	if (!device_context)
 	{
-		DisplayError(window_handle, "Could not get device context.");
+		Rml::Log::Message(Rml::Log::LT_ERROR, "Failed to get device context");
 		return false;
 	}
 
@@ -418,27 +414,27 @@ static bool AttachToNative(HWND window_handle, HDC& out_device_context, HGLRC& o
 	int pixel_format = ChoosePixelFormat(device_context, &pixel_format_descriptor);
 	if (!pixel_format)
 	{
-		DisplayError(window_handle, "Could not choose 32-bit pixel format.");
+		Rml::Log::Message(Rml::Log::LT_ERROR, "Failed to choose 32-bit pixel format");
 		return false;
 	}
 
 	if (!SetPixelFormat(device_context, pixel_format, &pixel_format_descriptor))
 	{
-		DisplayError(window_handle, "Could not set pixel format.");
+		Rml::Log::Message(Rml::Log::LT_ERROR, "Failed to set pixel format");
 		return false;
 	}
 
 	HGLRC render_context = wglCreateContext(device_context);
 	if (!render_context)
 	{
-		DisplayError(window_handle, "Could not create OpenGL rendering context.");
+		Rml::Log::Message(Rml::Log::LT_ERROR, "Failed to create OpenGL rendering context");
 		return false;
 	}
 
 	// Activate the rendering context.
 	if (!wglMakeCurrent(device_context, render_context))
 	{
-		DisplayError(window_handle, "Unable to make rendering context current.");
+		Rml::Log::Message(Rml::Log::LT_ERROR, "Failed to make rendering context current");
 		return false;
 	}
 

+ 5 - 9
Backends/RmlUi_Backend_Win32_VK.cpp

@@ -26,14 +26,15 @@
  *
  */
 
-#include "RmlUi/Config/Config.h"
 #include "RmlUi_Backend.h"
 #include "RmlUi_Include_Windows.h"
 #include "RmlUi_Platform_Win32.h"
 #include "RmlUi_Renderer_VK.h"
+#include <RmlUi/Config/Config.h>
 #include <RmlUi/Core/Context.h>
 #include <RmlUi/Core/Core.h>
 #include <RmlUi/Core/Input.h>
+#include <RmlUi/Core/Log.h>
 #include <RmlUi/Core/Profiling.h>
 
 /**
@@ -92,11 +93,6 @@ static float GetDensityIndependentPixelRatio(HWND window_handle)
 	return float(GetWindowDpi(window_handle)) / float(USER_DEFAULT_SCREEN_DPI);
 }
 
-static void DisplayError(HWND window_handle, const Rml::String& msg)
-{
-	MessageBoxW(window_handle, RmlWin32::ConvertToUTF16(msg).c_str(), L"Backend Error", MB_OK);
-}
-
 // Create the window but don't show it yet. Returns the pixel size of the window, which may be different than the passed size due to DPI settings.
 static HWND InitializeWindow(HINSTANCE instance_handle, const std::wstring& name, int& inout_width, int& inout_height, bool allow_resize);
 // Create the Win32 Vulkan surface.
@@ -150,7 +146,7 @@ bool Backend::Initialize(const char* window_name, int width, int height, bool al
 	extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
 	if (!data->render_interface.Initialize(std::move(extensions), CreateVulkanSurface))
 	{
-		DisplayError(window_handle, "Could not initialize Vulkan render interface.");
+		Rml::Log::Message(Rml::Log::LT_ERROR, "Failed to initialize Vulkan render interface");
 		::CloseWindow(window_handle);
 		data.reset();
 		return false;
@@ -357,7 +353,7 @@ static HWND InitializeWindow(HINSTANCE instance_handle, const std::wstring& name
 
 	if (!RegisterClassW(&window_class))
 	{
-		DisplayError(NULL, "Could not register window class.");
+		Rml::Log::Message(Rml::Log::LT_ERROR, "Failed to register window class");
 		return nullptr;
 	}
 
@@ -369,7 +365,7 @@ static HWND InitializeWindow(HINSTANCE instance_handle, const std::wstring& name
 
 	if (!window_handle)
 	{
-		DisplayError(NULL, "Could not create window.");
+		Rml::Log::Message(Rml::Log::LT_ERROR, "Failed to create window");
 		return nullptr;
 	}
 

+ 4 - 3
Backends/RmlUi_Backend_X11_GL2.cpp

@@ -26,12 +26,13 @@
  *
  */
 
-#include "RmlUi/Core/Debug.h"
 #include "RmlUi_Backend.h"
 #include "RmlUi_Include_Xlib.h"
 #include "RmlUi_Platform_X11.h"
 #include "RmlUi_Renderer_GL2.h"
 #include <RmlUi/Core/Context.h>
+#include <RmlUi/Core/Debug.h>
+#include <RmlUi/Core/Log.h>
 #include <GL/gl.h>
 #include <GL/glext.h>
 #include <GL/glu.h>
@@ -61,7 +62,7 @@ static bool AttachToNative(GLXContext& out_gl_context, Display* display, Window
 		return false;
 
 	if (!glXIsDirect(display, gl_context))
-		puts("OpenGL context does not support direct rendering; performance is likely to be poor.");
+		Rml::Log::Message(Rml::Log::LT_INFO, "OpenGL context does not support direct rendering; performance is likely to be poor.");
 
 	out_gl_context = gl_context;
 
@@ -142,7 +143,7 @@ bool Backend::Initialize(const char* window_name, int width, int height, bool al
 		XSizeHints* win_size_hints = XAllocSizeHints(); // Allocate a size hint structure
 		if (!win_size_hints)
 		{
-			fprintf(stderr, "XAllocSizeHints - out of memory\n");
+			Rml::Log::Message(Rml::Log::LT_ERROR, "XAllocSizeHints - out of memory");
 		}
 		else
 		{

+ 3 - 2
Samples/shell/src/PlatformExtensions.cpp

@@ -27,6 +27,7 @@
  */
 
 #include "../include/PlatformExtensions.h"
+#include <RmlUi/Core/Log.h>
 #include <RmlUi/Core/Platform.h>
 
 #if defined RMLUI_PLATFORM_WIN32
@@ -118,7 +119,7 @@ Rml::String PlatformExtensions::FindSamplesRoot()
 	ssize_t len = readlink("/proc/self/exe", executable_file_name, PATH_MAX);
 	if (len == -1)
 	{
-		printf("Unable to determine the executable path!\n");
+		Rml::Log::Message(Rml::Log::LT_ERROR, "Failed to determine the executable path");
 		executable_file_name[0] = 0;
 	}
 	else
@@ -153,7 +154,7 @@ Rml::String PlatformExtensions::FindSamplesRoot()
 		}
 	}
 
-	printf("Unable to find the path to the samples root!\n");
+	Rml::Log::Message(Rml::Log::LT_ERROR, "Failed to find the path to the samples root");
 
 	return Rml::String();