Extract dialog workflow, bootstrap, and canvas tail helpers

This commit is contained in:
2026-06-16 12:09:53 +02:00
parent 01854f9b10
commit 3407daff08
8 changed files with 586 additions and 534 deletions

View File

@@ -0,0 +1,106 @@
#include "pch.h"
#include "app.h"
#include "log.h"
#include "renderer_gl/opengl_capabilities.h"
#include <shellscalingapi.h>
#include <string>
#if __has_include(<renderdoc_app.h>)
#include <renderdoc_app.h>
#define USE_RENDERDOC
#endif
#ifdef USE_RENDERDOC
RENDERDOC_API_1_4_0* rdoc_api = NULL;
bool win32_renderdoc_init()
{
// At init, on windows
if (HMODULE mod = GetModuleHandleA("renderdoc.dll"))
{
pRENDERDOC_GetAPI RENDERDOC_GetAPI =
(pRENDERDOC_GetAPI)GetProcAddress(mod, "RENDERDOC_GetAPI");
return RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_1_2, (void**)&rdoc_api);
}
return false;
}
void win32_renderdoc_frame_start()
{
if (rdoc_api)
rdoc_api->StartFrameCapture(NULL, NULL);
}
void win32_renderdoc_frame_end()
{
if (rdoc_api)
rdoc_api->EndFrameCapture(NULL, NULL);
}
#else
void win32_renderdoc_frame_start() { }
void win32_renderdoc_frame_end() { }
#endif
HRESULT(*GetDpiForMonitor_fn)(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT* dpiX, UINT* dpiY);
HRESULT(*SetProcessDpiAwareness_fn)(PROCESS_DPI_AWARENESS value);
void init_shcore_API()
{
HMODULE dll = LoadLibrary(L"Shcore.dll");
if (!dll)
{
LOG("cannot load Shcore.dll");
return;
}
LOG("loaded Shcore.dll");
GetDpiForMonitor_fn = (decltype(GetDpiForMonitor_fn))GetProcAddress(dll, "GetDpiForMonitor");
SetProcessDpiAwareness_fn = (decltype(SetProcessDpiAwareness_fn))GetProcAddress(dll, "SetProcessDpiAwareness");
}
// Returns the last Win32 error, in string format. Returns an empty string if there is no error.
std::string GetLastErrorAsString()
{
DWORD errorMessageID = ::GetLastError();
if (errorMessageID == 0)
return std::string();
LPSTR messageBuffer = nullptr;
size_t size = FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
std::string message(messageBuffer, size);
LocalFree(messageBuffer);
return message;
}
BOOL UnadjustWindowRectEx(LPRECT prc, DWORD dwStyle, BOOL fMenu, DWORD dwExStyle)
{
RECT rc;
SetRectEmpty(&rc);
BOOL fRc = AdjustWindowRectEx(&rc, dwStyle, fMenu, dwExStyle);
if (fRc) {
prc->left -= rc.left;
prc->top -= rc.top;
prc->right -= rc.right;
prc->bottom -= rc.bottom;
}
return fRc;
}
void _pre_call_callback(const char* name, void* funcptr, int len_args, ...)
{
assert(App::I->is_render_thread());
}
void _post_call_callback(const char* name, void* funcptr, int len_args, ...)
{
GLenum error_code;
error_code = glad_glGetError();
if (error_code != pp::renderer::gl::no_error_code())
{
LOG("ERROR %d in %s\n", error_code, name);
}
}