mirror of
https://github.com/encounter/aurora.git
synced 2025-07-05 12:46:00 +00:00
Merge branch 'main' into update
# Conflicts: # extern/dawn # lib/imgui.cpp
This commit is contained in:
commit
f6d63d7ed5
2
extern/imgui
vendored
2
extern/imgui
vendored
@ -1 +1 @@
|
||||
Subproject commit 9aae45eb4a05a5a1f96be1ef37eb503a12ceb889
|
||||
Subproject commit 1d8e48c161370c37628c4f37f3f87cb19fbcb723
|
@ -32,6 +32,11 @@ typedef enum {
|
||||
LOG_FATAL,
|
||||
} AuroraLogLevel;
|
||||
|
||||
typedef struct {
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
} AuroraWindowPos;
|
||||
|
||||
typedef struct {
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
@ -53,6 +58,9 @@ typedef struct {
|
||||
uint32_t msaa;
|
||||
uint16_t maxTextureAnisotropy;
|
||||
bool startFullscreen;
|
||||
bool allowJoystickBackgroundEvents;
|
||||
int32_t windowPosX;
|
||||
int32_t windowPosY;
|
||||
uint32_t windowWidth;
|
||||
uint32_t windowHeight;
|
||||
void* iconRGBA8;
|
||||
|
@ -17,6 +17,7 @@ typedef enum {
|
||||
AURORA_NONE,
|
||||
AURORA_EXIT,
|
||||
AURORA_SDL_EVENT,
|
||||
AURORA_WINDOW_MOVED,
|
||||
AURORA_WINDOW_RESIZED,
|
||||
AURORA_CONTROLLER_ADDED,
|
||||
AURORA_CONTROLLER_REMOVED,
|
||||
@ -28,6 +29,7 @@ struct AuroraEvent {
|
||||
AuroraEventType type;
|
||||
union {
|
||||
SDL_Event sdl;
|
||||
AuroraWindowPos windowPos;
|
||||
AuroraWindowSize windowSize;
|
||||
int32_t controller;
|
||||
};
|
||||
|
@ -23,7 +23,7 @@
|
||||
#define __has_builtin(x) 0
|
||||
#endif
|
||||
#if __has_attribute(vector_size)
|
||||
//#define USE_GCC_VECTOR_EXTENSIONS
|
||||
#define USE_GCC_VECTOR_EXTENSIONS
|
||||
#endif
|
||||
|
||||
namespace aurora {
|
||||
|
@ -7,8 +7,8 @@
|
||||
#include <SDL.h>
|
||||
#include <webgpu/webgpu.h>
|
||||
|
||||
#include "../imgui/backends/imgui_impl_sdl.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
#include "../imgui/backends/imgui_impl_sdlrenderer.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
#include "../imgui/backends/imgui_impl_sdl2.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)
|
||||
// TODO: Transition back to imgui-provided backend when it uses WGSL
|
||||
#include "imgui_impl_wgpu.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
@ -34,14 +34,14 @@ void create_context() noexcept {
|
||||
|
||||
void initialize() noexcept {
|
||||
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__
|
||||
// Disable MouseCanUseGlobalState for scaling purposes
|
||||
ImGui_ImplSDL2_GetBackendData()->MouseCanUseGlobalState = false;
|
||||
#endif
|
||||
g_useSdlRenderer = renderer != nullptr;
|
||||
if (g_useSdlRenderer) {
|
||||
ImGui_ImplSDLRenderer_Init(renderer);
|
||||
ImGui_ImplSDLRenderer2_Init(renderer);
|
||||
} else {
|
||||
const auto format = webgpu::g_graphicsConfig.swapChainDescriptor.format;
|
||||
ImGui_ImplWGPU_Init(webgpu::g_device.Get(), 1, static_cast<WGPUTextureFormat>(format));
|
||||
@ -50,7 +50,7 @@ void initialize() noexcept {
|
||||
|
||||
void shutdown() noexcept {
|
||||
if (g_useSdlRenderer) {
|
||||
ImGui_ImplSDLRenderer_Shutdown();
|
||||
ImGui_ImplSDLRenderer2_Shutdown();
|
||||
} else {
|
||||
ImGui_ImplWGPU_Shutdown();
|
||||
}
|
||||
@ -77,7 +77,7 @@ void process_event(const SDL_Event& event) noexcept {
|
||||
|
||||
void new_frame(const AuroraWindowSize& size) noexcept {
|
||||
if (g_useSdlRenderer) {
|
||||
ImGui_ImplSDLRenderer_NewFrame();
|
||||
ImGui_ImplSDLRenderer2_NewFrame();
|
||||
g_scale = size.scale;
|
||||
} else {
|
||||
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
|
||||
data->FramebufferScale = {1.f, 1.f};
|
||||
if (g_useSdlRenderer) {
|
||||
SDL_Renderer* renderer = ImGui_ImplSDLRenderer_GetBackendData()->SDLRenderer;
|
||||
SDL_Renderer* renderer = ImGui_ImplSDLRenderer2_GetBackendData()->SDLRenderer;
|
||||
SDL_RenderClear(renderer);
|
||||
ImGui_ImplSDLRenderer_RenderDrawData(data);
|
||||
ImGui_ImplSDLRenderer2_RenderDrawData(data);
|
||||
SDL_RenderPresent(renderer);
|
||||
} else {
|
||||
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 {
|
||||
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_UpdateTexture(texture, nullptr, data, width * 4);
|
||||
SDL_SetTextureScaleMode(texture, SDL_ScaleModeLinear);
|
||||
|
@ -59,6 +59,13 @@ const AuroraEvent* poll_events() {
|
||||
});
|
||||
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: {
|
||||
resize_swapchain(false);
|
||||
g_events.push_back(AuroraEvent{
|
||||
@ -154,8 +161,16 @@ bool create_window(AuroraBackend backend) {
|
||||
width = 1280;
|
||||
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
|
||||
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) {
|
||||
Log.report(LOG_WARNING, FMT_STRING("Failed to create window: {}"), SDL_GetError());
|
||||
return false;
|
||||
@ -196,7 +211,8 @@ void show_window() {
|
||||
|
||||
bool initialize() {
|
||||
/* 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__)
|
||||
SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");
|
||||
@ -209,8 +225,9 @@ bool initialize() {
|
||||
#endif
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user