Skip to content

Commit

Permalink
Redirect all print-like calls to our built-in logger
Browse files Browse the repository at this point in the history
  • Loading branch information
mikke89 committed Dec 30, 2023
1 parent f9f5a90 commit 87870c9
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 39 deletions.
9 changes: 5 additions & 4 deletions Backends/RmlUi_Backend_GLFW_VK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
}

Expand All @@ -93,15 +94,15 @@ 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;
;
}))
{
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;
}

Expand Down
5 changes: 3 additions & 2 deletions Backends/RmlUi_Backend_SDL_GL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}

Expand Down
7 changes: 4 additions & 3 deletions Backends/RmlUi_Backend_SDL_GL3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
9 changes: 5 additions & 4 deletions Backends/RmlUi_Backend_SDL_VK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
}
Expand All @@ -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;
}

Expand Down
20 changes: 8 additions & 12 deletions Backends/RmlUi_Backend_Win32_GL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

/**
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
14 changes: 5 additions & 9 deletions Backends/RmlUi_Backend_Win32_VK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

/**
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
7 changes: 4 additions & 3 deletions Backends/RmlUi_Backend_X11_GL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
{
Expand Down
5 changes: 3 additions & 2 deletions Samples/shell/src/PlatformExtensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/

#include "../include/PlatformExtensions.h"
#include <RmlUi/Core/Log.h>
#include <RmlUi/Core/Platform.h>

#if defined RMLUI_PLATFORM_WIN32
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 87870c9

Please sign in to comment.