Extract edit menu and Windows/bootstrap preview seams

This commit is contained in:
2026-06-16 12:53:49 +02:00
parent 184f662493
commit cb9d06c6dc
12 changed files with 493 additions and 409 deletions

View File

@@ -1,7 +1,11 @@
#include "pch.h"
#include "platform_windows/windows_bootstrap_helpers.h"
#include "app.h"
#include "legacy_gl_runtime_dispatch.h"
#include "legacy_preference_storage.h"
#include "log.h"
#include "renderer_gl/opengl_capabilities.h"
#include <shellscalingapi.h>
#include <string>
@@ -11,6 +15,14 @@
#define USE_RENDERDOC
#endif
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);
namespace pp::platform::windows {
void set_async_render_context(HDC hdc, HGLRC hrc);
}
namespace pp::platform::windows {
#ifdef USE_RENDERDOC
RENDERDOC_API_1_4_0* rdoc_api = NULL;
@@ -75,6 +87,213 @@ std::string GetLastErrorAsString()
return message;
}
void ensure_runtime_data_directory()
{
FILE* fp_check = fopen("data\\layout.xml", "rb");
if (!fp_check)
{
LOG("data files not found");
static char path[MAX_PATH];
GetModuleFileNameA(NULL, path, MAX_PATH);
LOG("current dir %s", path);
PathRemoveFileSpecA(path);
SetCurrentDirectoryA(path);
LOG("change dir to %s", path);
return;
}
fclose(fp_check);
LOG("data files ok");
}
MainWindowStartupState initialize_main_window_startup_state()
{
auto startup = MainWindowStartupState {};
const auto hInst = GetModuleHandle(NULL);
const auto className = L"EngineMain";
startup.window_class.hInstance = hInst;
startup.window_class.lpfnWndProc = (WNDPROC)WndProc;
startup.window_class.lpszClassName = className;
startup.window_class.hbrBackground = (HBRUSH)COLOR_WINDOW;
startup.window_class.hCursor = LoadCursor(NULL, IDC_ARROW);
RegisterClass(&startup.window_class);
auto monitor = MonitorFromWindow(0, MONITOR_DEFAULTTOPRIMARY);
auto x = unsigned{ 96 };
auto y = unsigned{ 96 };
if (GetDpiForMonitor_fn)
GetDpiForMonitor_fn(monitor, MDT_EFFECTIVE_DPI, &x, &y);
App::I->display_density = (float)x / 96.f;
const auto window_preferences = pp::panopainter::read_legacy_window_preferences(SW_NORMAL);
if (window_preferences.has_ui_scale)
App::I->zoom = window_preferences.ui_scale;
else
App::I->zoom = (float)x / 96.f;
startup.show_command = window_preferences.show_command;
startup.client_rect = {
0,
0,
static_cast<LONG>(App::I->width * App::I->zoom),
static_cast<LONG>(App::I->height * App::I->zoom),
};
if (window_preferences.has_window_rect)
{
auto wnd_rect = window_preferences.window_rect;
App::I->width = wnd_rect.z - wnd_rect.x;
App::I->height = wnd_rect.w - wnd_rect.y;
startup.client_rect = { wnd_rect.x, wnd_rect.y, wnd_rect.z, wnd_rect.w };
startup.client_pos = { wnd_rect.x, wnd_rect.y };
}
else
{
AdjustWindowRect(&startup.client_rect, startup.window_style, false);
}
return startup;
}
void create_main_window(const MainWindowStartupState& startup, HWND& hWnd, HINSTANCE hInst, const wchar_t* window_title)
{
const int window_width = startup.client_rect.right - startup.client_rect.left;
const int window_height = startup.client_rect.bottom - startup.client_rect.top;
hWnd = CreateWindow(
startup.window_class.lpszClassName,
window_title,
startup.window_style,
startup.client_pos.x,
startup.client_pos.y,
window_width,
window_height,
0,
0,
hInst,
0);
}
void initialize_pixel_format_descriptor(PIXELFORMATDESCRIPTOR& pixel_format)
{
pixel_format.nSize = sizeof(pixel_format);
pixel_format.nVersion = 1;
pixel_format.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pixel_format.iPixelType = PFD_TYPE_RGBA;
pixel_format.cColorBits = 32;
pixel_format.cDepthBits = 24;
pixel_format.iLayerType = PFD_MAIN_PLANE;
}
bool load_glad_entry_points(HDC device_context)
{
if (!gladLoadGL())
{
LOG("gladLoadGL() failed");
return false;
}
if (!gladLoadWGL(device_context))
{
LOG("gladLoadWGL() failed");
return false;
}
return true;
}
pp::renderer::gl::OpenGlRuntimeInfo log_runtime_info()
{
auto runtime_info = pp::renderer::gl::OpenGlRuntimeInfo {};
const auto runtime_info_result = pp::renderer::gl::query_opengl_runtime_info(
pp::legacy::gl_runtime::runtime_info_dispatch());
if (runtime_info_result.ok())
{
runtime_info = runtime_info_result.value();
LOG("GL version: %s", runtime_info.version);
LOG("GL vendor: %s", runtime_info.vendor);
LOG("GL renderer: %s", runtime_info.renderer);
}
else
{
LOG("OpenGL runtime info query failed: %s", runtime_info_result.status().message);
}
return runtime_info;
}
bool upgrade_to_core_gl_context(const MainWindowStartupState& startup, HWND& hWnd, HINSTANCE hInst, const wchar_t* window_title, OpenGlWindowContext& context)
{
if (!GLAD_WGL_ARB_create_context)
{
LOG("WGL_ARB_create_context not supported");
// If not supported, go fuck yourself we are not gonna support your shitty device
return false;
}
const auto wgl_config = pp::renderer::gl::windows_wgl_core_context_3_3_config();
UINT num_format = 0;
wglMakeCurrent(NULL, NULL);
wglDeleteContext(context.render_context);
DestroyWindow(hWnd);
create_main_window(startup, hWnd, hInst, window_title);
context.device_context = GetDC(hWnd);
int pixel_format = 0;
wglChoosePixelFormatARB(
context.device_context,
wgl_config.pixel_format_attributes.data(),
nullptr,
1,
&pixel_format,
&num_format);
SetPixelFormat(context.device_context, pixel_format, &startup.pixel_format);
context.render_context = wglCreateContextAttribsARB(
context.device_context,
NULL,
wgl_config.context_attributes.data());
wglMakeCurrent(context.device_context, context.render_context);
set_async_render_context(context.device_context, context.render_context);
return true;
}
MainStartupResult initialize_main_window_and_gl(MainWindowStartupState& startup, HWND& hWnd, HINSTANCE hInst, wchar_t* window_title, OpenGlWindowContext& context)
{
create_main_window(startup, hWnd, hInst, L"PanoPainter");
initialize_pixel_format_descriptor(startup.pixel_format);
context.device_context = GetDC(hWnd);
const int pixel_format = ChoosePixelFormat(context.device_context, &startup.pixel_format);
SetPixelFormat(context.device_context, pixel_format, &startup.pixel_format);
context.render_context = wglCreateContext(context.device_context);
wglMakeCurrent(context.device_context, context.render_context);
set_async_render_context(context.device_context, context.render_context);
if (!load_glad_entry_points(context.device_context))
return MainStartupResult::GladLoadFailure;
context.runtime_info = log_runtime_info();
#ifdef USE_RENDERDOC
if (!win32_renderdoc_init())
LOG("Renderdoc not started");
#endif
const auto renderer_name = std::string(context.runtime_info.renderer != nullptr ? context.runtime_info.renderer : "");
swprintf_s(
window_title,
512,
L"PanoPainter %s (%s)",
g_version_number_w,
str2wstr(renderer_name).c_str());
if (!upgrade_to_core_gl_context(startup, hWnd, hInst, window_title, context))
return MainStartupResult::MissingCoreContextSupport;
return MainStartupResult::Ok;
}
BOOL UnadjustWindowRectEx(LPRECT prc, DWORD dwStyle, BOOL fMenu, DWORD dwExStyle)
{
RECT rc;
@@ -104,3 +323,5 @@ void _post_call_callback(const char* name, void* funcptr, int len_args, ...)
LOG("ERROR %d in %s\n", error_code, name);
}
}
}

View File

@@ -0,0 +1,57 @@
#pragma once
#include <Windows.h>
#include <shellscalingapi.h>
#include <string>
#include "renderer_gl/opengl_capabilities.h"
namespace pp::platform::windows {
bool win32_renderdoc_init();
void win32_renderdoc_frame_start();
void win32_renderdoc_frame_end();
extern HRESULT (*GetDpiForMonitor_fn)(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT* dpiX, UINT* dpiY);
extern HRESULT (*SetProcessDpiAwareness_fn)(PROCESS_DPI_AWARENESS value);
void init_shcore_API();
std::string GetLastErrorAsString();
void _pre_call_callback(const char* name, void* funcptr, int len_args, ...);
void _post_call_callback(const char* name, void* funcptr, int len_args, ...);
struct MainWindowStartupState
{
WNDCLASS window_class{};
PIXELFORMATDESCRIPTOR pixel_format{};
DWORD window_style = WS_OVERLAPPEDWINDOW;
RECT client_rect{ 0, 0, 0, 0 };
POINT client_pos{ CW_USEDEFAULT, CW_USEDEFAULT };
int show_command = SW_NORMAL;
};
struct OpenGlWindowContext
{
HDC device_context{};
HGLRC render_context{};
pp::renderer::gl::OpenGlRuntimeInfo runtime_info{};
};
enum class MainStartupResult
{
Ok = 0,
GladLoadFailure = 1,
MissingCoreContextSupport = 2,
};
void ensure_runtime_data_directory();
MainWindowStartupState initialize_main_window_startup_state();
void create_main_window(const MainWindowStartupState& startup, HWND& hWnd, HINSTANCE hInst, const wchar_t* window_title);
void initialize_pixel_format_descriptor(PIXELFORMATDESCRIPTOR& pixel_format);
bool load_glad_entry_points(HDC device_context);
pp::renderer::gl::OpenGlRuntimeInfo log_runtime_info();
bool upgrade_to_core_gl_context(const MainWindowStartupState& startup, HWND& hWnd, HINSTANCE hInst, const wchar_t* window_title, OpenGlWindowContext& context);
MainStartupResult initialize_main_window_and_gl(MainWindowStartupState& startup, HWND& hWnd, HINSTANCE hInst, wchar_t* window_title, OpenGlWindowContext& context);
}

View File

@@ -1,4 +1,5 @@
#include "pch.h"
#include "platform_windows/windows_bootstrap_helpers.h"
#include "platform_windows/windows_platform_services.h"
#include "log.h"
@@ -15,19 +16,15 @@ void destroy_window();
void async_lock();
void async_unlock();
void win32_async_swap();
void win32_renderdoc_frame_start();
void win32_renderdoc_frame_end();
void win32_update_fps(int frames);
void win32_update_stylus(float dt);
void win32_save_window_state();
bool win32_vr_start();
void win32_vr_stop();
std::string GetLastErrorAsString();
HWND pp_windows_main_window_handle();
void pp_windows_enqueue_main_task(std::packaged_task<void()> task);
namespace pp::platform::windows {
namespace {
struct RetainedWin32AsyncRenderContextState final {
@@ -43,8 +40,7 @@ struct RetainedWin32AsyncRenderContextState final {
static RetainedWin32AsyncRenderContextState state;
return state;
}
}
} // namespace
void set_async_render_context(HDC hdc, HGLRC hrc)
{
@@ -63,7 +59,7 @@ void lock_async_render_context()
state.gl_mutex.lock();
const bool ret = wglMakeCurrent(state.hdc, state.hrc);
if (!ret)
LOG("FAILED wglMakeCurrent: %s", GetLastErrorAsString().c_str());
LOG("FAILED wglMakeCurrent: %s", pp::platform::windows::GetLastErrorAsString().c_str());
state.gl_thread = std::this_thread::get_id();
}
state.gl_count++;
@@ -78,7 +74,7 @@ bool try_lock_async_render_context()
return false;
const bool ret = wglMakeCurrent(state.hdc, state.hrc);
if (!ret)
LOG("FAILED wglMakeCurrent: %s", GetLastErrorAsString().c_str());
LOG("FAILED wglMakeCurrent: %s", pp::platform::windows::GetLastErrorAsString().c_str());
state.gl_thread = std::this_thread::get_id();
}
state.gl_count++;
@@ -100,8 +96,7 @@ void swap_async_render_context()
{
SwapBuffers(retained_win32_async_render_context_state().hdc);
}
}
} // namespace pp::platform::windows
namespace {
@@ -438,12 +433,12 @@ public:
void begin_render_capture_frame() override
{
win32_renderdoc_frame_start();
pp::platform::windows::win32_renderdoc_frame_start();
}
void end_render_capture_frame() override
{
win32_renderdoc_frame_end();
pp::platform::windows::win32_renderdoc_frame_end();
}
[[nodiscard]] bool deletes_recorded_files_on_clear() override

View File

@@ -1,5 +1,6 @@
#include "pch.h"
#include "platform_windows/windows_splash.h"
#include "platform_windows/windows_bootstrap_helpers.h"
#include "app.h"
#include "image.h"
@@ -13,8 +14,6 @@
#include <string>
#include <stop_token>
extern HRESULT(*GetDpiForMonitor_fn)(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT* dpiX, UINT* dpiY);
namespace {
constexpr UINT kSplashCloseMessage = WM_USER + 1;
@@ -42,8 +41,8 @@ LRESULT CALLBACK splash_proc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lPara
auto monitor = MonitorFromWindow(0, MONITOR_DEFAULTTOPRIMARY);
auto x = unsigned{ 96 };
auto y = unsigned{ 96 };
if (GetDpiForMonitor_fn)
GetDpiForMonitor_fn(monitor, MDT_EFFECTIVE_DPI, &x, &y);
if (pp::platform::windows::GetDpiForMonitor_fn)
pp::platform::windows::GetDpiForMonitor_fn(monitor, MDT_EFFECTIVE_DPI, &x, &y);
float z = (float)x / 96.f;
static char base_path[MAX_PATH];