Merge branch 'main' into update

# Conflicts:
#	extern/dawn
#	lib/imgui.cpp
This commit is contained in:
Luke Street 2025-04-02 16:15:30 -06:00
commit f6d63d7ed5
6 changed files with 42 additions and 15 deletions

2
extern/imgui vendored

@ -1 +1 @@
Subproject commit 9aae45eb4a05a5a1f96be1ef37eb503a12ceb889 Subproject commit 1d8e48c161370c37628c4f37f3f87cb19fbcb723

View File

@ -32,6 +32,11 @@ typedef enum {
LOG_FATAL, LOG_FATAL,
} AuroraLogLevel; } AuroraLogLevel;
typedef struct {
int32_t x;
int32_t y;
} AuroraWindowPos;
typedef struct { typedef struct {
uint32_t width; uint32_t width;
uint32_t height; uint32_t height;
@ -53,6 +58,9 @@ typedef struct {
uint32_t msaa; uint32_t msaa;
uint16_t maxTextureAnisotropy; uint16_t maxTextureAnisotropy;
bool startFullscreen; bool startFullscreen;
bool allowJoystickBackgroundEvents;
int32_t windowPosX;
int32_t windowPosY;
uint32_t windowWidth; uint32_t windowWidth;
uint32_t windowHeight; uint32_t windowHeight;
void* iconRGBA8; void* iconRGBA8;

View File

@ -17,6 +17,7 @@ typedef enum {
AURORA_NONE, AURORA_NONE,
AURORA_EXIT, AURORA_EXIT,
AURORA_SDL_EVENT, AURORA_SDL_EVENT,
AURORA_WINDOW_MOVED,
AURORA_WINDOW_RESIZED, AURORA_WINDOW_RESIZED,
AURORA_CONTROLLER_ADDED, AURORA_CONTROLLER_ADDED,
AURORA_CONTROLLER_REMOVED, AURORA_CONTROLLER_REMOVED,
@ -28,6 +29,7 @@ struct AuroraEvent {
AuroraEventType type; AuroraEventType type;
union { union {
SDL_Event sdl; SDL_Event sdl;
AuroraWindowPos windowPos;
AuroraWindowSize windowSize; AuroraWindowSize windowSize;
int32_t controller; int32_t controller;
}; };

View File

@ -23,7 +23,7 @@
#define __has_builtin(x) 0 #define __has_builtin(x) 0
#endif #endif
#if __has_attribute(vector_size) #if __has_attribute(vector_size)
//#define USE_GCC_VECTOR_EXTENSIONS #define USE_GCC_VECTOR_EXTENSIONS
#endif #endif
namespace aurora { namespace aurora {

View File

@ -7,8 +7,8 @@
#include <SDL.h> #include <SDL.h>
#include <webgpu/webgpu.h> #include <webgpu/webgpu.h>
#include "../imgui/backends/imgui_impl_sdl.cpp" // NOLINT(bugprone-suspicious-include) #include "../imgui/backends/imgui_impl_sdl2.cpp" // NOLINT(bugprone-suspicious-include)
#include "../imgui/backends/imgui_impl_sdlrenderer.cpp" // NOLINT(bugprone-suspicious-include) #include "../imgui/backends/imgui_impl_sdlrenderer2.cpp" // NOLINT(bugprone-suspicious-include)
// #include "../imgui/backends/imgui_impl_wgpu.cpp" // NOLINT(bugprone-suspicious-include) // #include "../imgui/backends/imgui_impl_wgpu.cpp" // NOLINT(bugprone-suspicious-include)
// TODO: Transition back to imgui-provided backend when it uses WGSL // TODO: Transition back to imgui-provided backend when it uses WGSL
#include "imgui_impl_wgpu.cpp" // NOLINT(bugprone-suspicious-include) #include "imgui_impl_wgpu.cpp" // NOLINT(bugprone-suspicious-include)
@ -34,14 +34,14 @@ void create_context() noexcept {
void initialize() noexcept { void initialize() noexcept {
SDL_Renderer* renderer = window::get_sdl_renderer(); SDL_Renderer* renderer = window::get_sdl_renderer();
ImGui_ImplSDL2_Init(window::get_sdl_window(), renderer); ImGui_ImplSDL2_Init(window::get_sdl_window(), renderer, NULL);
#ifdef __APPLE__ #ifdef __APPLE__
// Disable MouseCanUseGlobalState for scaling purposes // Disable MouseCanUseGlobalState for scaling purposes
ImGui_ImplSDL2_GetBackendData()->MouseCanUseGlobalState = false; ImGui_ImplSDL2_GetBackendData()->MouseCanUseGlobalState = false;
#endif #endif
g_useSdlRenderer = renderer != nullptr; g_useSdlRenderer = renderer != nullptr;
if (g_useSdlRenderer) { if (g_useSdlRenderer) {
ImGui_ImplSDLRenderer_Init(renderer); ImGui_ImplSDLRenderer2_Init(renderer);
} else { } else {
const auto format = webgpu::g_graphicsConfig.swapChainDescriptor.format; const auto format = webgpu::g_graphicsConfig.swapChainDescriptor.format;
ImGui_ImplWGPU_Init(webgpu::g_device.Get(), 1, static_cast<WGPUTextureFormat>(format)); ImGui_ImplWGPU_Init(webgpu::g_device.Get(), 1, static_cast<WGPUTextureFormat>(format));
@ -50,7 +50,7 @@ void initialize() noexcept {
void shutdown() noexcept { void shutdown() noexcept {
if (g_useSdlRenderer) { if (g_useSdlRenderer) {
ImGui_ImplSDLRenderer_Shutdown(); ImGui_ImplSDLRenderer2_Shutdown();
} else { } else {
ImGui_ImplWGPU_Shutdown(); ImGui_ImplWGPU_Shutdown();
} }
@ -77,7 +77,7 @@ void process_event(const SDL_Event& event) noexcept {
void new_frame(const AuroraWindowSize& size) noexcept { void new_frame(const AuroraWindowSize& size) noexcept {
if (g_useSdlRenderer) { if (g_useSdlRenderer) {
ImGui_ImplSDLRenderer_NewFrame(); ImGui_ImplSDLRenderer2_NewFrame();
g_scale = size.scale; g_scale = size.scale;
} else { } else {
if (g_scale != size.scale) { if (g_scale != size.scale) {
@ -107,9 +107,9 @@ void render(const wgpu::RenderPassEncoder& pass) noexcept {
// io.DisplayFramebufferScale is informational; we're rendering at full DPI // io.DisplayFramebufferScale is informational; we're rendering at full DPI
data->FramebufferScale = {1.f, 1.f}; data->FramebufferScale = {1.f, 1.f};
if (g_useSdlRenderer) { if (g_useSdlRenderer) {
SDL_Renderer* renderer = ImGui_ImplSDLRenderer_GetBackendData()->SDLRenderer; SDL_Renderer* renderer = ImGui_ImplSDLRenderer2_GetBackendData()->SDLRenderer;
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
ImGui_ImplSDLRenderer_RenderDrawData(data); ImGui_ImplSDLRenderer2_RenderDrawData(data);
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
} else { } else {
ImGui_ImplWGPU_RenderDrawData(data, pass.Get()); ImGui_ImplWGPU_RenderDrawData(data, pass.Get());
@ -118,7 +118,7 @@ void render(const wgpu::RenderPassEncoder& pass) noexcept {
ImTextureID add_texture(uint32_t width, uint32_t height, const uint8_t* data) noexcept { ImTextureID add_texture(uint32_t width, uint32_t height, const uint8_t* data) noexcept {
if (g_useSdlRenderer) { if (g_useSdlRenderer) {
SDL_Renderer* renderer = ImGui_ImplSDLRenderer_GetBackendData()->SDLRenderer; SDL_Renderer* renderer = ImGui_ImplSDLRenderer2_GetBackendData()->SDLRenderer;
SDL_Texture* texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STATIC, width, height); SDL_Texture* texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STATIC, width, height);
SDL_UpdateTexture(texture, nullptr, data, width * 4); SDL_UpdateTexture(texture, nullptr, data, width * 4);
SDL_SetTextureScaleMode(texture, SDL_ScaleModeLinear); SDL_SetTextureScaleMode(texture, SDL_ScaleModeLinear);

View File

@ -59,6 +59,13 @@ const AuroraEvent* poll_events() {
}); });
break; break;
} }
case SDL_WINDOWEVENT_MOVED: {
g_events.push_back(AuroraEvent{
.type = AURORA_WINDOW_MOVED,
.windowPos = {.x = event.window.data1, .y = event.window.data2},
});
break;
}
case SDL_WINDOWEVENT_SIZE_CHANGED: { case SDL_WINDOWEVENT_SIZE_CHANGED: {
resize_swapchain(false); resize_swapchain(false);
g_events.push_back(AuroraEvent{ g_events.push_back(AuroraEvent{
@ -154,8 +161,16 @@ bool create_window(AuroraBackend backend) {
width = 1280; width = 1280;
height = 960; height = 960;
} }
int32_t x = g_config.windowPosX;
int32_t y = g_config.windowPosY;
if (x < 0 || y < 0) {
x = SDL_WINDOWPOS_UNDEFINED;
y = SDL_WINDOWPOS_UNDEFINED;
}
#endif #endif
g_window = SDL_CreateWindow(g_config.appName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags); g_window = SDL_CreateWindow(g_config.appName, x, y, width, height, flags);
if (g_window == nullptr) { if (g_window == nullptr) {
Log.report(LOG_WARNING, FMT_STRING("Failed to create window: {}"), SDL_GetError()); Log.report(LOG_WARNING, FMT_STRING("Failed to create window: {}"), SDL_GetError());
return false; return false;
@ -196,7 +211,8 @@ void show_window() {
bool initialize() { bool initialize() {
/* We don't want to initialize anything input related here, otherwise the add events will get lost to the void */ /* We don't want to initialize anything input related here, otherwise the add events will get lost to the void */
ASSERT(SDL_Init(SDL_INIT_EVERYTHING & ~(SDL_INIT_HAPTIC | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER)) == 0, "Error initializing SDL: {}", SDL_GetError()); ASSERT(SDL_Init(SDL_INIT_EVERYTHING & ~(SDL_INIT_HAPTIC | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER)) == 0,
"Error initializing SDL: {}", SDL_GetError());
#if !defined(_WIN32) && !defined(__APPLE__) #if !defined(_WIN32) && !defined(__APPLE__)
SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0"); SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");
@ -209,8 +225,9 @@ bool initialize() {
#endif #endif
SDL_DisableScreenSaver(); SDL_DisableScreenSaver();
/* TODO: Make this an option rather than hard coding it */ if (g_config.allowJoystickBackgroundEvents) {
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
}
return true; return true;
} }